tide-commander 1.149.0 → 1.150.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/assets/{BossLogsModal-Cs4kWugD.js → BossLogsModal-DvczRUvP.js} +1 -1
- package/dist/assets/{BossSpawnModal-BudMgJqj.js → BossSpawnModal-B2autFKk.js} +1 -1
- package/dist/assets/{ControlsModal-Bh6_3qtH.js → ControlsModal-BaREMQxc.js} +1 -1
- package/dist/assets/{DockerLogsModal-Nf4wQFfz.js → DockerLogsModal-DZ0udMCo.js} +1 -1
- package/dist/assets/{EmbeddedEditor-BfRXRX50.js → EmbeddedEditor-CEjr0ZSZ.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-CXUtjA0r.js → GmailOAuthSetup-76BP8J8C.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-D-_rwicD.js → GoogleOAuthSetup-D45GImPI.js} +1 -1
- package/dist/assets/{IframeModal-CdaXsQK0.js → IframeModal-De63RfJZ.js} +1 -1
- package/dist/assets/{IntegrationsPanel-ZsSVxcWr.js → IntegrationsPanel-DYrw1Sqk.js} +2 -2
- package/dist/assets/{LogViewerModal-BAf-klB2.js → LogViewerModal-DW-2lpln.js} +1 -1
- package/dist/assets/{MonitoringModal-BjRbh5z4.js → MonitoringModal-B0-XXyd3.js} +1 -1
- package/dist/assets/{PM2LogsModal-SaywDZVL.js → PM2LogsModal-DOfOhkCY.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-jru2Ez9a.js → RestoreArchivedAreaModal-DNGmIJmM.js} +1 -1
- package/dist/assets/{Scene2DCanvas-NJHoe2Qg.js → Scene2DCanvas-BW1E76CQ.js} +1 -1
- package/dist/assets/{SceneManager-i9wVMa_V.js → SceneManager-DAvc9-Wp.js} +1 -1
- package/dist/assets/{SkillsPanel-BHfKLzWe.js → SkillsPanel-Br-gLCLA.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-BfVevCSo.js → SlackMultiInstanceSetup-DG_bIfDu.js} +1 -1
- package/dist/assets/{SpawnModal-29x5z53B.js → SpawnModal-lWM8OuZW.js} +1 -1
- package/dist/assets/{StatisticsModal-MbIByjWD.js → StatisticsModal-LvA0Fcvn.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-DF0vYaM6.js → SubordinateAssignmentModal-8YxNXcR3.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-EGcKS1Pt.js → TriggerManagerPanel-DftIuKUG.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-BLmejfqe.js → WorkflowEditorPanel-oLwyO_C6.js} +1 -1
- package/dist/assets/{area-logos-C4fgpLgO.js → area-logos-mcpQqUMZ.js} +1 -1
- package/dist/assets/{index-BiiLWTXJ.js → index-Ay7dKyeR.js} +1 -1
- package/dist/assets/{index-DThK5_yS.js → index-BMw7AAAK.js} +3 -3
- package/dist/assets/{index-C8CGfmXP.js → index-BQpd34Mc.js} +1 -1
- package/dist/assets/{index-BZ4wZwRu.js → index-C6-68CXL.js} +3 -3
- package/dist/assets/index-CIon0DLf.js +2 -0
- package/dist/assets/{index-C6Kf4ewu.js → index-Cwt-E2td.js} +1 -1
- package/dist/assets/{index-B9xpLAcH.js → index-DFVroqA5.js} +1 -1
- package/dist/assets/index-DR6_WeF_.js +1 -0
- package/dist/assets/{index-B-2H7O_Y.js → index-O0t07OB_.js} +2 -2
- package/dist/assets/{main-B0UlZnfk.js → main-D5sqeuwB.js} +151 -125
- package/dist/assets/main-JBkwGXfE.css +1 -0
- package/dist/assets/{web-CXC8P25z.js → web-BkrshujV.js} +1 -1
- package/dist/assets/{web-LGEDa25c.js → web-DPETNqOf.js} +1 -1
- package/dist/assets/{web-NM4dUqWg.js → web-vG1Smf_N.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/locales/de/config.json +3 -1
- package/dist/locales/en/config.json +2 -0
- package/dist/locales/en/terminal.json +6 -0
- package/dist/locales/es/config.json +2 -0
- package/dist/locales/fr/config.json +3 -1
- package/dist/locales/hi/config.json +3 -1
- package/dist/locales/it/config.json +3 -1
- package/dist/locales/ja/config.json +3 -1
- package/dist/locales/pt/config.json +3 -1
- package/dist/locales/ru/config.json +3 -1
- package/dist/locales/zh-CN/config.json +3 -1
- package/dist/src/packages/server/claude/backend.js +114 -10
- package/dist/src/packages/server/claude/runner/process-lifecycle.js +9 -0
- package/dist/src/packages/server/claude/runner/stdout-pipeline.js +24 -4
- package/dist/src/packages/server/claude/session-loader.js +20 -5
- package/dist/src/packages/server/codex/json-event-parser.js +149 -4
- package/dist/src/packages/server/grok/backend.js +4 -0
- package/dist/src/packages/server/grok/json-event-parser.js +29 -14
- package/dist/src/packages/server/grok/session-watcher.js +67 -34
- package/dist/src/packages/server/opencode/json-event-parser.js +184 -15
- package/dist/src/packages/server/routes/agents.js +12 -9
- package/dist/src/packages/server/services/grok-usage-service.js +374 -0
- package/dist/src/packages/server/websocket/listeners/runtime-listeners.js +10 -7
- package/package.json +1 -1
- package/dist/assets/index-DYgVP0G3.js +0 -2
- package/dist/assets/index-DhD3m2Qx.js +0 -1
- package/dist/assets/main-DeiAIdzy.css +0 -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,i as W,k as V,K as Qt,a1 as Js,S as zt,a2 as Ys,s as _e,u as oe,j as e,I as M,c4 as At,as as Bn,c5 as Xs,c6 as _n,c7 as Qs,c8 as Zs,c9 as Kn,ca as Vn,cb as Lt,cc as Wn,cd as qn,ce as Jn,cf as ns,cg as Yn,ch as en,ci as $t,cj as Ht,ap as it,ck as gt,cl as xt,cm as zs,cn as Xn,bz as Qn,co as ss,a5 as Zn,cp as ea,cq as ta,cr as Pt,cs as sa,ct as na,cu as aa,cv as ra,cw as ia,cx as As,C as la,t as oa}from"./main-B0UlZnfk.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function ca(s){const[n,l]=t.useState(null),[c,r]=t.useState(!1),i=t.useCallback(async()=>{if(s){r(!0);try{const h=await W(V(`/api/files/git-status?path=${encodeURIComponent(s)}`)),o=await h.json();h.ok?l(o):l({isGitRepo:!1,files:[]})}catch(h){console.error("[FileExplorer] Failed to load git status:",h),l({isGitRepo:!1,files:[]})}finally{r(!1)}}},[s]);return{gitStatus:n,loading:c,loadGitStatus:i}}async function da(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 ua=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",""]),ha=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),ma=new Set([".pdf"]),fa=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 pa(s){const n=s.toLowerCase();return ha.has(n)?"image":ma.has(n)?"pdf":fa.has(n)?"binary":(ua.has(n),"text")}function ga(){const[s,n]=t.useState(null),[l,c]=t.useState(!1),[r,i]=t.useState(null),h=t.useCallback(async u=>{var p,b;c(!0),i(null);try{const f=u.substring(u.lastIndexOf(".")).toLowerCase(),v=pa(f),N=u.substring(u.lastIndexOf("/")+1);if(v==="image"){const k=await W(V(`/api/files/binary?path=${encodeURIComponent(u)}`));if(!k.ok){const w=await k.json().catch(()=>({error:"Failed to load image"}));i(w.error||"Failed to load image"),n(null);return}const g=await k.blob(),j=URL.createObjectURL(g);n({path:u,filename:N,extension:f,content:"",size:g.size,modified:new Date().toISOString(),fileType:"image",dataUrl:j});return}if(v==="pdf"){const k=await W(V(`/api/files/info?path=${encodeURIComponent(u)}`)),g=await k.json();if(!k.ok){i(g.error||"Failed to load PDF info"),n(null);return}n({path:u,filename:N,extension:f,content:"",size:g.size,modified:g.modified,fileType:"pdf",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(u)}&token=${encodeURIComponent(Qt())}`)});return}if(v==="binary"){const k=await W(V(`/api/files/info?path=${encodeURIComponent(u)}`)),g=await k.json();if(!k.ok){i(g.error||"Failed to load file info"),n(null);return}n({path:u,filename:N,extension:f,content:"",size:g.size,modified:g.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Qt())}`)});return}const R=await W(V(`/api/files/read?path=${encodeURIComponent(u)}`)),y=await R.json();if(!R.ok){if((p=y.error)!=null&&p.includes("too large")||(b=y.error)!=null&&b.includes("binary")){const k=await W(V(`/api/files/info?path=${encodeURIComponent(u)}`)),g=await k.json();if(k.ok){n({path:u,filename:N,extension:f,content:"",size:g.size,modified:g.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Qt())}`)});return}}i(y.error||"Failed to load file"),n(null);return}n({...y,fileType:"text"})}catch(f){const v=f instanceof Error?f.message:"Failed to load file";i(v),n(null)}finally{c(!1)}},[]),o=t.useCallback(()=>{n(u=>(u!=null&&u.dataUrl&&u.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(u.dataUrl),null)),i(null)},[]);return{file:s,loading:l,error:r,loadFile:h,clearFile:o,setFile:n}}const xa="file-explorer-state",Os="file-explorer-recent-projects",ya=10080*60*1e3,ba=12;function Zt(s){return`${xa}-folder-${s}`}async function ja(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 va(){const s=t.useCallback(async r=>{if(!r)return null;try{const i=localStorage.getItem(Zt(r));if(!i)return null;const h=JSON.parse(i);if(Date.now()-h.timestamp>ya)return localStorage.removeItem(Zt(r)),null;const u=(await Promise.all((h.tabs||[]).map(async b=>({tab:b,exists:await ja(b.path)})))).filter(({exists:b})=>b).map(({tab:b})=>b);let p=h.activeTabPath;return p&&!u.some(b=>b.path===p)&&(p=u.length>0?u[0].path:null),{tabs:u,activeTabPath:p,viewMode:h.viewMode||"files",expandedPaths:new Set(h.expandedPaths||[])}}catch(i){return console.error("[FileExplorerStorage] Failed to load project state:",i),null}},[]),n=t.useCallback((r,i)=>{if(r)try{const h={tabs:i.tabs,activeTabPath:i.activeTabPath,viewMode:i.viewMode,expandedPaths:Array.from(i.expandedPaths),timestamp:Date.now()};localStorage.setItem(Zt(r),JSON.stringify(h))}catch(h){console.error("[FileExplorerStorage] Failed to save project state:",h)}},[]),l=t.useCallback(()=>{try{const r=localStorage.getItem(Os);if(!r)return[];const i=JSON.parse(r);return Array.isArray(i)?i.filter(h=>typeof h=="string"):[]}catch{return[]}},[]),c=t.useCallback(r=>{if(!r)return l();const i=[r,...l().filter(h=>h!==r)].slice(0,ba);try{localStorage.setItem(Os,JSON.stringify(i))}catch{}return i},[l]);return{loadProjectState:s,saveProjectState:n,loadRecentProjects:l,pushRecentProject:c}}const Gs=280,Us=150,Bs=1200;function wa(){const[s,n]=t.useState(()=>{const p=Js(zt.TREE_PANEL_WIDTH,Gs);return p>=Us&&p<=Bs?p:Gs}),l=t.useRef(!1),[c,r]=t.useState(!1),i=t.useRef(0),h=t.useRef(0),o=t.useRef(s);o.current=s;const u=t.useCallback(p=>{p.preventDefault(),l.current=!0,r(!0),i.current=p.clientX,h.current=s,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[s]);return t.useEffect(()=>{const p=f=>{if(!l.current)return;const v=f.clientX-i.current,N=Math.min(Bs,Math.max(Us,h.current+v));n(N)},b=()=>{l.current&&(l.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",Ys(zt.TREE_PANEL_WIDTH,o.current))};return document.addEventListener("mousemove",p),document.addEventListener("mouseup",b),()=>{document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",b)}},[]),{treePanelWidth:s,handleResizeStart:u,isResizing:c}}const Ca=100,Na=.65,ka=36;function Ea(){const[s,n]=t.useState(()=>Js(zt.MOBILE_TREE_PANEL_HEIGHT,0)),l=t.useRef(s);l.current=s;const c=t.useRef(0),r=t.useRef(0),i=()=>Math.floor((window.innerHeight-ka)*Na),h=f=>Math.min(i(),Math.max(Ca,f)),o=t.useCallback(f=>{n(f);const v=document.querySelector(".file-explorer-main");v&&v.style.setProperty("--fe-mobile-tree-height",`${f}px`)},[]),u=t.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",Ys(zt.MOBILE_TREE_PANEL_HEIGHT,l.current),_e.setTerminalResizing(!1)},[]),p=t.useCallback(f=>{f.preventDefault();const v=document.querySelector(".file-explorer-tree-panel"),N=l.current>0?l.current:(v==null?void 0:v.getBoundingClientRect().height)??240;c.current=f.clientY,r.current=N,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",_e.setTerminalResizing(!0);const R=k=>{const g=k.clientY-c.current;o(h(r.current+g))},y=()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",y),u()};document.addEventListener("mousemove",R),document.addEventListener("mouseup",y)},[o,u]),b=t.useCallback(f=>{if(f.touches.length!==1)return;const v=document.querySelector(".file-explorer-tree-panel"),N=l.current>0?l.current:(v==null?void 0:v.getBoundingClientRect().height)??240;c.current=f.touches[0].clientY,r.current=N,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",_e.setTerminalResizing(!0);const R=k=>{if(k.touches.length!==1)return;k.preventDefault();const g=k.touches[0].clientY-c.current;o(h(r.current+g))},y=()=>{document.removeEventListener("touchmove",R),document.removeEventListener("touchend",y),document.removeEventListener("touchcancel",y),u()};document.addEventListener("touchmove",R,{passive:!1}),document.addEventListener("touchend",y),document.addEventListener("touchcancel",y)},[o,u]);return{mobileTreeHeight:s,handleResizeMouseDown:p,handleResizeTouchStart:b}}function as(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[r,i]=t.useState(null),[h,o]=t.useState(null),u=t.useCallback(async k=>{c(!0),i(null);try{const g=await W(V(`/api/files/git-branches?path=${encodeURIComponent(k)}`)),j=await g.json();g.ok?n(j.branches||[]):(i(j.error||"Failed to load branches"),n([]))}catch(g){console.error("[GitBranches] Failed to load branches:",g),i("Failed to load branches"),n([])}finally{c(!1)}},[]),p=t.useCallback(async(k,g)=>{o("checkout"),i(null);try{const j=await W(V("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:g})}),w=await j.json();return j.ok||i(w.error||"Checkout failed"),w}catch(j){console.error("[GitBranches] Checkout failed:",j);const w={success:!1,error:"Checkout failed"};return i(w.error),w}finally{o(null)}},[]),b=t.useCallback(async(k,g,j)=>{o("create"),i(null);try{const w=await W(V("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,name:g,startPoint:j})}),T=await w.json();return w.ok||i(T.error||"Failed to create branch"),T}catch(w){console.error("[GitBranches] Create branch failed:",w);const T={success:!1,error:"Failed to create branch"};return i(T.error),T}finally{o(null)}},[]),f=t.useCallback(async k=>{o("pull"),i(null);try{const g=await W(V("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return!g.ok&&!j.conflicts&&i(j.error||"Pull failed"),j}catch(g){console.error("[GitBranches] Pull failed:",g);const j={success:!1,error:"Pull failed"};return i(j.error),j}finally{o(null)}},[]),v=t.useCallback(async k=>{o("push"),i(null);try{const g=await W(V("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return g.ok||i(j.error||"Push failed"),j}catch(g){console.error("[GitBranches] Push failed:",g);const j={success:!1,error:"Push failed"};return i(j.error),j}finally{o(null)}},[]),N=t.useCallback(async(k,g)=>{o("merge"),i(null);try{const j=await W(V("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:g})}),w=await j.json();return!j.ok&&!w.conflicts&&i(w.error||"Merge failed"),w}catch(j){console.error("[GitBranches] Merge failed:",j);const w={success:!1,error:"Merge failed"};return i(w.error),w}finally{o(null)}},[]),R=t.useCallback(async k=>{o("merge-abort"),i(null);try{const g=await W(V("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return g.ok||i(j.error||"Merge abort failed"),j}catch(g){console.error("[GitBranches] Merge abort failed:",g);const j={success:!1,error:"Merge abort failed"};return i(j.error),j}finally{o(null)}},[]),y=t.useCallback(async k=>{o("merge-continue"),i(null);try{const g=await W(V("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return g.ok||i(j.error||"Merge continue failed"),j}catch(g){console.error("[GitBranches] Merge continue failed:",g);const j={success:!1,error:"Merge continue failed"};return i(j.error),j}finally{o(null)}},[]);return{branches:s,loading:l,error:r,operationInProgress:h,loadBranches:u,checkoutBranch:p,createBranch:b,pullFromRemote:f,pushToRemote:v,mergeBranch:N,mergeAbort:R,mergeContinue:y}}const Sa=50,Ta=400,_s={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function Ma(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[r,i]=t.useState(!1),[h,o]=t.useState(null),[u,p]=t.useState(!1),[b,f]=t.useState(0),[v,N]=t.useState({..._s}),[R,y]=t.useState(null),[k,g]=t.useState([]),[j,w]=t.useState(!1),[T,A]=t.useState([]),[O,C]=t.useState(!1),G=t.useRef(null),ae=t.useRef(""),Y=t.useCallback((B,Z,P)=>{const U=P||v,I=new URLSearchParams;return I.set("path",B),I.set("limit",String(Sa)),I.set("offset",String(Z)),U.branch&&I.set("branch",U.branch),U.author&&I.set("author",U.author),U.since&&I.set("since",U.since),U.until&&I.set("until",U.until),U.searchPath&&I.set("searchPath",U.searchPath),U.search&&I.set("search",U.search),I.toString()},[v]),D=t.useCallback(async B=>{ae.current=B,c(!0),o(null),y(null),g([]);try{const Z=Y(B,0),P=await W(V(`/api/files/git-log?${Z}`)),U=await P.json();P.ok?(n(U.commits||[]),f(U.total||0),p(U.hasMore||!1)):(o(U.error||"Failed to load git history"),n([]))}catch(Z){console.error("[useGitHistory] loadHistory error:",Z),o("Failed to load git history"),n([])}finally{c(!1)}},[Y]),F=t.useCallback(async B=>{if(!(r||!u)){i(!0);try{const Z=Y(B,s.length),P=await W(V(`/api/files/git-log?${Z}`)),U=await P.json();P.ok&&(n(I=>[...I,...U.commits||[]]),f(U.total||0),p(U.hasMore||!1))}catch(Z){console.error("[useGitHistory] loadMore error:",Z)}finally{i(!1)}}},[Y,s.length,u,r]),K=t.useCallback(async B=>{if(y(B),!B){g([]);return}w(!0);try{const Z=ae.current,P=new URLSearchParams({path:Z,hash:B.hash}),U=await W(V(`/api/files/git-commit-files?${P}`)),I=await U.json();U.ok?g(I.files||[]):g([])}catch(Z){console.error("[useGitHistory] selectCommit files error:",Z),g([])}finally{w(!1)}},[]),ne=t.useCallback((B,Z)=>{N(P=>({...P,[B]:Z}))},[]),re=t.useCallback(()=>{N({..._s})},[]);t.useEffect(()=>{const B=ae.current;if(B)return G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{D(B)},Ta),()=>{G.current&&clearTimeout(G.current)}},[v]);const je=t.useCallback(async B=>{C(!0);try{const Z=new URLSearchParams({path:B}),P=await W(V(`/api/files/git-authors?${Z}`)),U=await P.json();P.ok&&A(U.authors||[])}catch(Z){console.error("[useGitHistory] loadAuthors error:",Z)}finally{C(!1)}},[]);return{commits:s,loading:l,loadingMore:r,error:h,hasMore:u,total:b,filters:v,setFilter:ne,resetFilters:re,selectedCommit:R,selectCommit:K,commitFiles:k,commitFilesLoading:j,loadHistory:D,loadMore:F,authors:T,authorsLoading:O,loadAuthors:je}}function Da(s){if(!s.current)return null;const n=[".file-viewer-code-with-lines",".file-viewer-markdown-wrapper",".file-viewer-code-wrapper",".file-viewer-diagram-wrapper",".file-viewer-image-wrapper",".file-viewer-pdf-wrapper"];for(const l of n){const c=s.current.querySelector(l);if(c&&Ks(c))return c}return Ks(s.current)?s.current:null}function Ks(s){const n=["auto","scroll"].includes(getComputedStyle(s).overflowY),l=s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth;return n&&l}function tn(s){if(!s)return 19.5;const n=parseFloat(getComputedStyle(s).lineHeight);return isNaN(n)?19.5:n}function es(s,n=!0){const l=n?s.scrollHeight:0;s.scrollTo({top:l,behavior:"smooth"})}function Ra(s){const{scrollTop:n,scrollHeight:l,clientHeight:c}=s;return l<=c?100:Math.round(n/(l-c)*100)}function Fa(s,n){const l=tn(s),c=s.scrollTop,r=Math.floor(c/l)+1,i=n.split(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor-CEjr0ZSZ.js","assets/main-D5sqeuwB.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-JBkwGXfE.css","assets/EmbeddedEditor-O_u2UVA4.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as t,i as W,k as V,K as Qt,a1 as Js,S as zt,a2 as Ys,s as _e,u as oe,j as e,I as M,c5 as At,as as Bn,c6 as Xs,c7 as _n,c8 as Qs,c9 as Zs,ca as Kn,cb as Vn,cc as Lt,cd as Wn,ce as qn,cf as Jn,cg as ns,ch as Yn,ci as en,cj as $t,ck as Ht,ap as it,cl as gt,cm as xt,cn as zs,co as Xn,bA as Qn,cp as ss,a5 as Zn,cq as ea,cr as ta,cs as Pt,ct as sa,cu as na,cv as aa,cw as ra,cx as ia,cy as As,C as la,t as oa}from"./main-D5sqeuwB.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function ca(s){const[n,l]=t.useState(null),[c,r]=t.useState(!1),i=t.useCallback(async()=>{if(s){r(!0);try{const h=await W(V(`/api/files/git-status?path=${encodeURIComponent(s)}`)),o=await h.json();h.ok?l(o):l({isGitRepo:!1,files:[]})}catch(h){console.error("[FileExplorer] Failed to load git status:",h),l({isGitRepo:!1,files:[]})}finally{r(!1)}}},[s]);return{gitStatus:n,loading:c,loadGitStatus:i}}async function da(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 ua=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",""]),ha=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),ma=new Set([".pdf"]),fa=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 pa(s){const n=s.toLowerCase();return ha.has(n)?"image":ma.has(n)?"pdf":fa.has(n)?"binary":(ua.has(n),"text")}function ga(){const[s,n]=t.useState(null),[l,c]=t.useState(!1),[r,i]=t.useState(null),h=t.useCallback(async u=>{var p,b;c(!0),i(null);try{const f=u.substring(u.lastIndexOf(".")).toLowerCase(),v=pa(f),N=u.substring(u.lastIndexOf("/")+1);if(v==="image"){const k=await W(V(`/api/files/binary?path=${encodeURIComponent(u)}`));if(!k.ok){const w=await k.json().catch(()=>({error:"Failed to load image"}));i(w.error||"Failed to load image"),n(null);return}const g=await k.blob(),j=URL.createObjectURL(g);n({path:u,filename:N,extension:f,content:"",size:g.size,modified:new Date().toISOString(),fileType:"image",dataUrl:j});return}if(v==="pdf"){const k=await W(V(`/api/files/info?path=${encodeURIComponent(u)}`)),g=await k.json();if(!k.ok){i(g.error||"Failed to load PDF info"),n(null);return}n({path:u,filename:N,extension:f,content:"",size:g.size,modified:g.modified,fileType:"pdf",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(u)}&token=${encodeURIComponent(Qt())}`)});return}if(v==="binary"){const k=await W(V(`/api/files/info?path=${encodeURIComponent(u)}`)),g=await k.json();if(!k.ok){i(g.error||"Failed to load file info"),n(null);return}n({path:u,filename:N,extension:f,content:"",size:g.size,modified:g.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Qt())}`)});return}const R=await W(V(`/api/files/read?path=${encodeURIComponent(u)}`)),y=await R.json();if(!R.ok){if((p=y.error)!=null&&p.includes("too large")||(b=y.error)!=null&&b.includes("binary")){const k=await W(V(`/api/files/info?path=${encodeURIComponent(u)}`)),g=await k.json();if(k.ok){n({path:u,filename:N,extension:f,content:"",size:g.size,modified:g.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Qt())}`)});return}}i(y.error||"Failed to load file"),n(null);return}n({...y,fileType:"text"})}catch(f){const v=f instanceof Error?f.message:"Failed to load file";i(v),n(null)}finally{c(!1)}},[]),o=t.useCallback(()=>{n(u=>(u!=null&&u.dataUrl&&u.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(u.dataUrl),null)),i(null)},[]);return{file:s,loading:l,error:r,loadFile:h,clearFile:o,setFile:n}}const xa="file-explorer-state",Os="file-explorer-recent-projects",ya=10080*60*1e3,ba=12;function Zt(s){return`${xa}-folder-${s}`}async function ja(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 va(){const s=t.useCallback(async r=>{if(!r)return null;try{const i=localStorage.getItem(Zt(r));if(!i)return null;const h=JSON.parse(i);if(Date.now()-h.timestamp>ya)return localStorage.removeItem(Zt(r)),null;const u=(await Promise.all((h.tabs||[]).map(async b=>({tab:b,exists:await ja(b.path)})))).filter(({exists:b})=>b).map(({tab:b})=>b);let p=h.activeTabPath;return p&&!u.some(b=>b.path===p)&&(p=u.length>0?u[0].path:null),{tabs:u,activeTabPath:p,viewMode:h.viewMode||"files",expandedPaths:new Set(h.expandedPaths||[])}}catch(i){return console.error("[FileExplorerStorage] Failed to load project state:",i),null}},[]),n=t.useCallback((r,i)=>{if(r)try{const h={tabs:i.tabs,activeTabPath:i.activeTabPath,viewMode:i.viewMode,expandedPaths:Array.from(i.expandedPaths),timestamp:Date.now()};localStorage.setItem(Zt(r),JSON.stringify(h))}catch(h){console.error("[FileExplorerStorage] Failed to save project state:",h)}},[]),l=t.useCallback(()=>{try{const r=localStorage.getItem(Os);if(!r)return[];const i=JSON.parse(r);return Array.isArray(i)?i.filter(h=>typeof h=="string"):[]}catch{return[]}},[]),c=t.useCallback(r=>{if(!r)return l();const i=[r,...l().filter(h=>h!==r)].slice(0,ba);try{localStorage.setItem(Os,JSON.stringify(i))}catch{}return i},[l]);return{loadProjectState:s,saveProjectState:n,loadRecentProjects:l,pushRecentProject:c}}const Gs=280,Us=150,Bs=1200;function wa(){const[s,n]=t.useState(()=>{const p=Js(zt.TREE_PANEL_WIDTH,Gs);return p>=Us&&p<=Bs?p:Gs}),l=t.useRef(!1),[c,r]=t.useState(!1),i=t.useRef(0),h=t.useRef(0),o=t.useRef(s);o.current=s;const u=t.useCallback(p=>{p.preventDefault(),l.current=!0,r(!0),i.current=p.clientX,h.current=s,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[s]);return t.useEffect(()=>{const p=f=>{if(!l.current)return;const v=f.clientX-i.current,N=Math.min(Bs,Math.max(Us,h.current+v));n(N)},b=()=>{l.current&&(l.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",Ys(zt.TREE_PANEL_WIDTH,o.current))};return document.addEventListener("mousemove",p),document.addEventListener("mouseup",b),()=>{document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",b)}},[]),{treePanelWidth:s,handleResizeStart:u,isResizing:c}}const Ca=100,Na=.65,ka=36;function Ea(){const[s,n]=t.useState(()=>Js(zt.MOBILE_TREE_PANEL_HEIGHT,0)),l=t.useRef(s);l.current=s;const c=t.useRef(0),r=t.useRef(0),i=()=>Math.floor((window.innerHeight-ka)*Na),h=f=>Math.min(i(),Math.max(Ca,f)),o=t.useCallback(f=>{n(f);const v=document.querySelector(".file-explorer-main");v&&v.style.setProperty("--fe-mobile-tree-height",`${f}px`)},[]),u=t.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",Ys(zt.MOBILE_TREE_PANEL_HEIGHT,l.current),_e.setTerminalResizing(!1)},[]),p=t.useCallback(f=>{f.preventDefault();const v=document.querySelector(".file-explorer-tree-panel"),N=l.current>0?l.current:(v==null?void 0:v.getBoundingClientRect().height)??240;c.current=f.clientY,r.current=N,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",_e.setTerminalResizing(!0);const R=k=>{const g=k.clientY-c.current;o(h(r.current+g))},y=()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",y),u()};document.addEventListener("mousemove",R),document.addEventListener("mouseup",y)},[o,u]),b=t.useCallback(f=>{if(f.touches.length!==1)return;const v=document.querySelector(".file-explorer-tree-panel"),N=l.current>0?l.current:(v==null?void 0:v.getBoundingClientRect().height)??240;c.current=f.touches[0].clientY,r.current=N,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",_e.setTerminalResizing(!0);const R=k=>{if(k.touches.length!==1)return;k.preventDefault();const g=k.touches[0].clientY-c.current;o(h(r.current+g))},y=()=>{document.removeEventListener("touchmove",R),document.removeEventListener("touchend",y),document.removeEventListener("touchcancel",y),u()};document.addEventListener("touchmove",R,{passive:!1}),document.addEventListener("touchend",y),document.addEventListener("touchcancel",y)},[o,u]);return{mobileTreeHeight:s,handleResizeMouseDown:p,handleResizeTouchStart:b}}function as(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[r,i]=t.useState(null),[h,o]=t.useState(null),u=t.useCallback(async k=>{c(!0),i(null);try{const g=await W(V(`/api/files/git-branches?path=${encodeURIComponent(k)}`)),j=await g.json();g.ok?n(j.branches||[]):(i(j.error||"Failed to load branches"),n([]))}catch(g){console.error("[GitBranches] Failed to load branches:",g),i("Failed to load branches"),n([])}finally{c(!1)}},[]),p=t.useCallback(async(k,g)=>{o("checkout"),i(null);try{const j=await W(V("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:g})}),w=await j.json();return j.ok||i(w.error||"Checkout failed"),w}catch(j){console.error("[GitBranches] Checkout failed:",j);const w={success:!1,error:"Checkout failed"};return i(w.error),w}finally{o(null)}},[]),b=t.useCallback(async(k,g,j)=>{o("create"),i(null);try{const w=await W(V("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,name:g,startPoint:j})}),T=await w.json();return w.ok||i(T.error||"Failed to create branch"),T}catch(w){console.error("[GitBranches] Create branch failed:",w);const T={success:!1,error:"Failed to create branch"};return i(T.error),T}finally{o(null)}},[]),f=t.useCallback(async k=>{o("pull"),i(null);try{const g=await W(V("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return!g.ok&&!j.conflicts&&i(j.error||"Pull failed"),j}catch(g){console.error("[GitBranches] Pull failed:",g);const j={success:!1,error:"Pull failed"};return i(j.error),j}finally{o(null)}},[]),v=t.useCallback(async k=>{o("push"),i(null);try{const g=await W(V("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return g.ok||i(j.error||"Push failed"),j}catch(g){console.error("[GitBranches] Push failed:",g);const j={success:!1,error:"Push failed"};return i(j.error),j}finally{o(null)}},[]),N=t.useCallback(async(k,g)=>{o("merge"),i(null);try{const j=await W(V("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:g})}),w=await j.json();return!j.ok&&!w.conflicts&&i(w.error||"Merge failed"),w}catch(j){console.error("[GitBranches] Merge failed:",j);const w={success:!1,error:"Merge failed"};return i(w.error),w}finally{o(null)}},[]),R=t.useCallback(async k=>{o("merge-abort"),i(null);try{const g=await W(V("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return g.ok||i(j.error||"Merge abort failed"),j}catch(g){console.error("[GitBranches] Merge abort failed:",g);const j={success:!1,error:"Merge abort failed"};return i(j.error),j}finally{o(null)}},[]),y=t.useCallback(async k=>{o("merge-continue"),i(null);try{const g=await W(V("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return g.ok||i(j.error||"Merge continue failed"),j}catch(g){console.error("[GitBranches] Merge continue failed:",g);const j={success:!1,error:"Merge continue failed"};return i(j.error),j}finally{o(null)}},[]);return{branches:s,loading:l,error:r,operationInProgress:h,loadBranches:u,checkoutBranch:p,createBranch:b,pullFromRemote:f,pushToRemote:v,mergeBranch:N,mergeAbort:R,mergeContinue:y}}const Sa=50,Ta=400,_s={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function Ma(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[r,i]=t.useState(!1),[h,o]=t.useState(null),[u,p]=t.useState(!1),[b,f]=t.useState(0),[v,N]=t.useState({..._s}),[R,y]=t.useState(null),[k,g]=t.useState([]),[j,w]=t.useState(!1),[T,A]=t.useState([]),[O,C]=t.useState(!1),G=t.useRef(null),ae=t.useRef(""),Y=t.useCallback((B,Z,P)=>{const U=P||v,I=new URLSearchParams;return I.set("path",B),I.set("limit",String(Sa)),I.set("offset",String(Z)),U.branch&&I.set("branch",U.branch),U.author&&I.set("author",U.author),U.since&&I.set("since",U.since),U.until&&I.set("until",U.until),U.searchPath&&I.set("searchPath",U.searchPath),U.search&&I.set("search",U.search),I.toString()},[v]),D=t.useCallback(async B=>{ae.current=B,c(!0),o(null),y(null),g([]);try{const Z=Y(B,0),P=await W(V(`/api/files/git-log?${Z}`)),U=await P.json();P.ok?(n(U.commits||[]),f(U.total||0),p(U.hasMore||!1)):(o(U.error||"Failed to load git history"),n([]))}catch(Z){console.error("[useGitHistory] loadHistory error:",Z),o("Failed to load git history"),n([])}finally{c(!1)}},[Y]),F=t.useCallback(async B=>{if(!(r||!u)){i(!0);try{const Z=Y(B,s.length),P=await W(V(`/api/files/git-log?${Z}`)),U=await P.json();P.ok&&(n(I=>[...I,...U.commits||[]]),f(U.total||0),p(U.hasMore||!1))}catch(Z){console.error("[useGitHistory] loadMore error:",Z)}finally{i(!1)}}},[Y,s.length,u,r]),K=t.useCallback(async B=>{if(y(B),!B){g([]);return}w(!0);try{const Z=ae.current,P=new URLSearchParams({path:Z,hash:B.hash}),U=await W(V(`/api/files/git-commit-files?${P}`)),I=await U.json();U.ok?g(I.files||[]):g([])}catch(Z){console.error("[useGitHistory] selectCommit files error:",Z),g([])}finally{w(!1)}},[]),ne=t.useCallback((B,Z)=>{N(P=>({...P,[B]:Z}))},[]),re=t.useCallback(()=>{N({..._s})},[]);t.useEffect(()=>{const B=ae.current;if(B)return G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{D(B)},Ta),()=>{G.current&&clearTimeout(G.current)}},[v]);const je=t.useCallback(async B=>{C(!0);try{const Z=new URLSearchParams({path:B}),P=await W(V(`/api/files/git-authors?${Z}`)),U=await P.json();P.ok&&A(U.authors||[])}catch(Z){console.error("[useGitHistory] loadAuthors error:",Z)}finally{C(!1)}},[]);return{commits:s,loading:l,loadingMore:r,error:h,hasMore:u,total:b,filters:v,setFilter:ne,resetFilters:re,selectedCommit:R,selectCommit:K,commitFiles:k,commitFilesLoading:j,loadHistory:D,loadMore:F,authors:T,authorsLoading:O,loadAuthors:je}}function Da(s){if(!s.current)return null;const n=[".file-viewer-code-with-lines",".file-viewer-markdown-wrapper",".file-viewer-code-wrapper",".file-viewer-diagram-wrapper",".file-viewer-image-wrapper",".file-viewer-pdf-wrapper"];for(const l of n){const c=s.current.querySelector(l);if(c&&Ks(c))return c}return Ks(s.current)?s.current:null}function Ks(s){const n=["auto","scroll"].includes(getComputedStyle(s).overflowY),l=s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth;return n&&l}function tn(s){if(!s)return 19.5;const n=parseFloat(getComputedStyle(s).lineHeight);return isNaN(n)?19.5:n}function es(s,n=!0){const l=n?s.scrollHeight:0;s.scrollTo({top:l,behavior:"smooth"})}function Ra(s){const{scrollTop:n,scrollHeight:l,clientHeight:c}=s;return l<=c?100:Math.round(n/(l-c)*100)}function Fa(s,n){const l=tn(s),c=s.scrollTop,r=Math.floor(c/l)+1,i=n.split(`
|
|
3
3
|
`).length;return Math.min(r,i)}function Pa(s,n,l=!1){if(!n)return[];l||s.toLowerCase();const c=l?n:n.toLowerCase(),r=[];let i=0;const h=s.split(`
|
|
4
4
|
`);let o=0;for(let u=0;u<h.length;u++){const p=h[u],b=l?p:p.toLowerCase();let f=0,v=b.indexOf(c);for(;v!==-1;){const N=o+v;r.push({index:i++,line:u+1,column:v,length:c.length,charIndex:N}),f=v+c.length,v=b.indexOf(c,f)}o+=p.length+1}return r}function lt(s){return/[\w]/.test(s)}function Ke(s){return/\s/.test(s)}function Ia(s,n,l){let c=n-1,r=l;const i=s.length,h=s[c]||"";if(r<h.length){const p=lt(h[r]);if(!Ke(h[r]))for(;r<h.length&&!Ke(h[r])&<(h[r])===p;)r++}for(;c<i;){const p=s[c]||"";for(;r<p.length&&Ke(p[r]);)r++;if(r<p.length)return{line:c+1,col:r};c++,r=0}const o=i,u=Math.max(0,(s[i-1]||"").length-1);return{line:o,col:u}}function La(s,n,l){let c=n-1,r=l+1;const i=s.length;for(;c<i;){const u=s[c]||"";for(;r<u.length&&Ke(u[r]);)r++;if(r<u.length)break;c++,r=0}if(c>=i)return{line:i,col:Math.max(0,(s[i-1]||"").length-1)};const h=s[c]||"",o=lt(h[r]);for(;r+1<h.length&&!Ke(h[r+1])&<(h[r+1])===o;)r++;return{line:c+1,col:r}}function $a(s,n,l){let c=n-1,r=l-1;for(;c>=0;){const o=s[c]||"";for(;r>=0&&Ke(o[r]);)r--;if(r>=0)break;c--,c>=0&&(r=(s[c]||"").length-1)}if(c<0)return{line:1,col:0};const i=s[c]||"",h=lt(i[r]);for(;r>0&&!Ke(i[r-1])&<(i[r-1])===h;)r--;return{line:c+1,col:r}}function Ha(s,n,l,c){if(c==="none")return"";const{anchorLine:r,anchorCol:i,headLine:h,headCol:o}=l;if(c==="line"){const N=Math.min(r,h),R=Math.max(r,h);return n.slice(N-1,R).join(`
|
|
5
5
|
`)}let u,p,b,f;if(r<h||r===h&&i<=o?(u=r,p=i,b=h,f=o):(u=h,p=o,b=r,f=i),u===b)return(n[u-1]||"").substring(p,f+1);const v=[];v.push((n[u-1]||"").substring(p));for(let N=u;N<b-1;N++)v.push(n[N]||"");return v.push((n[b-1]||"").substring(0,f+1)),v.join(`
|
|
6
6
|
`)}function sn(s){const{containerRef:n,isEnabled:l=!0,content:c="",onClose:r,onSearchOpen:i}=s,h=t.useRef({percentage:0,line:1,column:1}),o=t.useRef(null),u=t.useRef(19.5),p=t.useMemo(()=>c.split(`
|
|
7
|
-
`),[c]),b=p.length,[f,v]=t.useState(1),[N,R]=t.useState(0),[y,k]=t.useState(!1),[g,j]=t.useState("none"),[w,T]=t.useState(null),[A,O]=t.useState(!1),[C,G]=t.useState(""),[ae,Y]=t.useState(0),[D,F]=t.useState(!1),K=t.useMemo(()=>Pa(c,C,!1),[c,C]),ne=t.useCallback(()=>{const m=o.current;if(!m)return;const X=Ra(m),le=Fa(m,c),$=Math.max(1,Math.round(m.scrollLeft/7.8)+1);h.current={percentage:X,line:le,column:$}},[c]),re=t.useCallback(()=>{O(!0),G(""),Y(0),i==null||i()},[i]),je=t.useCallback(()=>{O(!1),G(""),Y(0)},[]),B=t.useCallback(()=>{F(m=>!m)},[]),Z=t.useCallback(m=>{const X=o.current;if(!X)return;const le=X.querySelector(".file-viewer-pre"),z=le&&parseFloat(getComputedStyle(le).lineHeight)||u.current,$=le&&parseFloat(getComputedStyle(le).paddingTop)||0,te=(le?le.offsetTop:0)+$+(m-1)*z,Q=z*3;X.scrollTo({top:Math.max(0,te-Q),behavior:"smooth"})},[]);t.useEffect(()=>{!A||K.length===0||Y(0)},[K,A]),t.useEffect(()=>{if(!A||K.length===0)return;const m=K[ae];m&&(v(m.line),R(m.column),Z(m.line))},[A,K,ae,Z]);const P=t.useCallback(()=>{K.length!==0&&Y(m=>(m+1)%K.length)},[K]),U=t.useCallback(()=>{K.length!==0&&Y(m=>(m-1+K.length)%K.length)},[K]),I=t.useCallback(m=>{const X=o.current;if(!X)return;const le=X.querySelector(".file-viewer-pre");if(!le)return;const z=parseFloat(getComputedStyle(le).lineHeight),$=isNaN(z)?u.current:z,S=parseFloat(getComputedStyle(le).paddingTop)||0,Q=le.offsetTop+S+(m-1)*$,de=Q+$,pe=X.scrollTop,se=pe+X.clientHeight;Q<pe?X.scrollTo({top:Math.max(0,Q),behavior:"auto"}):de>se&&X.scrollTo({top:de-X.clientHeight,behavior:"auto"})},[]),ie=t.useCallback((m,X)=>{v(m),R(X),I(m),g!=="none"&&T(le=>le?{...le,headLine:m,headCol:X}:null)},[g,I]),ee=t.useCallback(()=>{if(g==="none"||!w)return;const m=Ha(c,p,w,g);m&&navigator.clipboard.writeText(m).catch(()=>{const X=document.createElement("textarea");X.value=m,X.style.position="fixed",X.style.left="-9999px",document.body.appendChild(X),X.select(),document.execCommand("copy"),document.body.removeChild(X)}),j("none"),T(null)},[g,w,c,p]),ve=t.useCallback(m=>{const X=m.target;if((X.tagName==="INPUT"||X.tagName==="TEXTAREA")&&m.key!=="Escape")return;const z=o.current;if(!z)return;let $=!1;const S=u.current,te=Math.max(1,Math.floor(z.clientHeight/S)),Q=Math.max(1,Math.floor(te/2)),de=(se,we)=>{const Ge=Math.max(0,(p[se-1]||"").length-1);return Math.min(we,Math.max(0,Ge))},pe=(se,we)=>{const Ge=de(se,we);ie(se,Ge)};if(m.key==="v"&&!m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),g==="char"?(j("none"),T(null)):(j("char"),T({anchorLine:f,anchorCol:N,headLine:f,headCol:N})),$=!0;else if(m.key==="V"&&m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),g==="line"?(j("none"),T(null)):(j("line"),T({anchorLine:f,anchorCol:0,headLine:f,headCol:0})),$=!0;else if(m.key==="y"&&!m.ctrlKey&&g!=="none")m.preventDefault(),m.stopPropagation(),ee(),$=!0;else if(m.key==="j"||m.key==="ArrowDown"){m.preventDefault(),m.stopPropagation();const se=Math.min(f+1,b);pe(se,N),$=!0}else if(m.key==="k"||m.key==="ArrowUp"){m.preventDefault(),m.stopPropagation();const se=Math.max(f-1,1);pe(se,N),$=!0}else if(m.key==="d"&&m.ctrlKey||m.key==="d"&&g==="none"&&!A){m.preventDefault(),m.stopPropagation();const se=Math.min(f+Q,b);pe(se,N),$=!0}else if(m.key==="u"&&m.ctrlKey||m.key==="u"&&g==="none"&&!A){m.preventDefault(),m.stopPropagation();const se=Math.max(f-Q,1);pe(se,N),$=!0}else if((m.ctrlKey||m.metaKey)&&m.key==="f")m.preventDefault(),m.stopPropagation(),re(),$=!0;else if(m.key==="f"&&!m.ctrlKey&&!m.metaKey&&g==="none"&&!A){m.preventDefault(),m.stopPropagation();const se=Math.min(f+te,b);pe(se,N),$=!0}else if(m.key===" "||m.key==="PageDown"){m.preventDefault(),m.stopPropagation();const se=Math.min(f+te,b);pe(se,N),$=!0}else if(m.key==="b"&&!y&&g==="none"&&!A||m.key==="PageUp"){m.preventDefault(),m.stopPropagation();const se=Math.max(f-te,1);pe(se,N),$=!0}else if(m.key==="g"&&!m.shiftKey&&g==="none"&&!A)m.preventDefault(),m.stopPropagation(),ie(1,0),es(z,!1),$=!0;else if(m.key==="Home")m.preventDefault(),m.stopPropagation(),ie(1,0),es(z,!1),$=!0;else if(m.key==="G"&&m.shiftKey||m.key==="End")m.preventDefault(),m.stopPropagation(),ie(b,0),es(z,!0),$=!0;else if(m.key==="h"||m.key==="ArrowLeft")m.preventDefault(),m.stopPropagation(),ie(f,Math.max(0,N-1)),$=!0;else if(m.key==="l"||m.key==="ArrowRight"){m.preventDefault(),m.stopPropagation();const se=(p[f-1]||"").length;ie(f,Math.min(N+1,Math.max(0,se-1))),$=!0}else if(m.key==="w"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const se=Ia(p,f,N);ie(se.line,se.col),$=!0}else if(m.key==="e"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const se=La(p,f,N);ie(se.line,se.col),$=!0}else if(m.key==="b"&&!A){m.preventDefault(),m.stopPropagation();const se=$a(p,f,N);ie(se.line,se.col),$=!0}else if(m.key==="0")m.preventDefault(),m.stopPropagation(),ie(f,0),$=!0;else if(m.key==="$")m.preventDefault(),m.stopPropagation(),ie(f,Math.max(0,(p[f-1]||"").length-1)),$=!0;else if(m.key==="^"){m.preventDefault(),m.stopPropagation();const we=(p[f-1]||"").search(/\S/);ie(f,we>=0?we:0),$=!0}else m.key==="/"?(m.preventDefault(),m.stopPropagation(),re(),$=!0):m.key==="n"&&!A?(m.preventDefault(),m.stopPropagation(),P(),$=!0):m.key==="N"&&m.shiftKey&&!A?(m.preventDefault(),m.stopPropagation(),U(),$=!0):m.key==="?"&&g==="none"?(m.preventDefault(),m.stopPropagation(),B(),$=!0):m.key==="q"&&g==="none"?(m.preventDefault(),m.stopPropagation(),r==null||r(),$=!0):m.key==="Escape"&&(g!=="none"?(m.preventDefault(),m.stopPropagation(),j("none"),T(null),$=!0):A?(m.preventDefault(),m.stopPropagation(),je(),$=!0):y&&(m.preventDefault(),m.stopPropagation(),k(!1),$=!0));$&&(m.key!=="Escape"&&!y&&k(!0),requestAnimationFrame(ne))},[r,ne,b,p,f,N,I,A,je,g,y,ie,ee,re,P,U,B]);return t.useEffect(()=>{if(!l)return;const m=Da(n);if(o.current=m,!m){console.warn("[useLessNavigation] Could not find scrollable container");return}u.current=tn(m);const X=()=>{ne()};return window.addEventListener("keydown",ve,{capture:!0}),m.addEventListener("scroll",X,{passive:!0}),ne(),()=>{window.removeEventListener("keydown",ve,{capture:!0}),m.removeEventListener("scroll",X)}},[l,ve,ne]),{scrollPercentage:h.current.percentage,currentLine:h.current.line,currentColumn:h.current.column,totalLines:b,cursorLine:f,cursorCol:N,cursorModeActive:y,visualMode:g,selection:w,searchActive:A,searchQuery:C,searchMatches:K,currentMatchIndex:ae,startSearch:re,setSearchQuery:G,nextMatch:P,prevMatch:U,clearSearch:je,helpActive:D,toggleHelp:B}}const rs=({query:s,onQueryChange:n,matchCount:l,currentIndex:c,onNext:r,onPrev:i,onClose:h})=>{const{t:o}=oe(["terminal"]),u=t.useRef(null);t.useEffect(()=>{var f;(f=u.current)==null||f.focus()},[]);const p=t.useCallback(f=>{f.stopPropagation(),f.key==="Enter"||f.key==="ArrowDown"?(f.preventDefault(),r()):f.key==="ArrowUp"&&(f.preventDefault(),i())},[r,i]),b=l===0&&s?o("terminal:fileExplorer.noMatches"):l>0?`${c+1}/${l}`:"";return e.jsxs("div",{className:"file-viewer-search-bar",children:[e.jsxs("div",{className:"file-viewer-search-input-wrapper",children:[e.jsx("span",{className:"file-viewer-search-prefix",children:"/"}),e.jsx("input",{ref:u,type:"text",className:"file-viewer-search-input",placeholder:o("terminal:fileExplorer.searchInFile"),value:s,onChange:f=>n(f.target.value),onKeyDown:p,autoComplete:"off",spellCheck:"false"})]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-viewer-search-counter",children:b}),e.jsxs("div",{className:"file-viewer-search-nav",children:[e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-prev",onClick: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:h,title:o("terminal:fileExplorer.closeSearch"),"aria-label":o("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};rs.displayName="SearchBar";const za=[{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"}],is=({onClose:s})=>{const{t:n}=oe(["terminal"]),l=t.useCallback(i=>{i.target===i.currentTarget&&s()},[s]),c=t.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),s())},[s]),r=za.reduce((i,h)=>(i[h.category]||(i[h.category]=[]),i[h.category].push(h),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:l,onKeyDown:c,tabIndex:0,role:"dialog","aria-label":n("terminal:fileExplorer.keybindingsHelp"),children:e.jsxs("div",{className:"keybindings-help-content",children:[e.jsx("button",{className:"keybindings-help-close",onClick:s,"aria-label":n("terminal:fileExplorer.closeHelp"),title:n("terminal:fileExplorer.pressEscapeToClose"),children:e.jsx(M,{name:"close",size:14})}),e.jsx("h2",{className:"keybindings-help-title",children:n("terminal:fileExplorer.keybindingsHelp")}),e.jsx("p",{className:"keybindings-help-subtitle",children:n("terminal:fileExplorer.keybindingsSubtitle")}),e.jsx("div",{className:"keybindings-help-categories",children:Object.entries(r).map(([i,h])=>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:h.map((o,u)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:o.keys.map((p,b)=>e.jsx("kbd",{className:"keybindings-help-key",children:p},b))}),e.jsx("div",{className:"keybindings-help-description",children:o.description})]},u))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};is.displayName="KeybindingsHelp";const Vs=t.lazy(()=>_n(()=>import("./EmbeddedEditor-BfRXRX50.js"),__vite__mapDeps([0,1,2,3,4,5])).then(s=>({default:s.EmbeddedEditor}))),Aa=[".md",".mdx",".markdown"],Ws="file-viewer-markdown-render",Oa=[".puml",".plantuml",".iuml",".pu"],qs="file-viewer-plantuml-render",Ga="https://kroki.io/plantuml/svg";function Ua(s){return Aa.includes(s.toLowerCase())}function Ba(s){return Oa.includes(s.toLowerCase())}function _a(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(Ws);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ws,String(r))}catch{}return r})},[]);return[s,l]}function Ka(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(qs);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(qs,String(r))}catch{}return r})},[]);return[s,l]}function Va(s){const n=new TextEncoder().encode(s);let l="";for(const c of n)l+=String.fromCharCode(c);return`data:image/svg+xml;base64,${window.btoa(l)}`}function Ve({file:s,rightContent:n,onRevealInTree:l,editMode:c,onToggleEdit:r}){const{t:i}=oe(["terminal","common"]),[h,o]=t.useState("idle"),[u,p]=t.useState("idle"),[b,f]=t.useState("idle"),v=s.fileType==="text"?At(s.extension):s.extension.slice(1).toUpperCase(),N=s.fileType==="text"&&s.content!=null,R=Bn(),y=async()=>{try{await Lt(s.content),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},k=()=>{const T=new Blob([s.content],{type:"text/plain;charset=utf-8"}),A=URL.createObjectURL(T),O=document.createElement("a");O.href=A,O.download=s.filename,document.body.appendChild(O),O.click(),O.remove(),setTimeout(()=>URL.revokeObjectURL(A),1e3)},g=async()=>{o("loading");try{const T=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(!T.ok){const A=await T.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",A),o("error"),setTimeout(()=>o("idle"),2e3);return}o("success"),setTimeout(()=>o("idle"),2e3)}catch(T){console.error("Error opening file in editor:",T),o("error"),setTimeout(()=>o("idle"),2e3)}},j=async()=>{if(s.path)try{await Jn(s.path),p("success"),setTimeout(()=>p("idle"),2e3)}catch(T){console.error("Error opening file explorer:",T),p("error"),setTimeout(()=>p("idle"),2e3)}},w=i("terminal:fileExplorer.openInFileExplorer");return e.jsxs("div",{className:"file-viewer-header",children:[e.jsxs("div",{className:"file-viewer-header-left",children:[e.jsx("span",{className:"file-viewer-filename",children:s.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[Xs(s.size)," • ",v,s.content&&` • ${s.content.split(`
|
|
7
|
+
`),[c]),b=p.length,[f,v]=t.useState(1),[N,R]=t.useState(0),[y,k]=t.useState(!1),[g,j]=t.useState("none"),[w,T]=t.useState(null),[A,O]=t.useState(!1),[C,G]=t.useState(""),[ae,Y]=t.useState(0),[D,F]=t.useState(!1),K=t.useMemo(()=>Pa(c,C,!1),[c,C]),ne=t.useCallback(()=>{const m=o.current;if(!m)return;const X=Ra(m),le=Fa(m,c),$=Math.max(1,Math.round(m.scrollLeft/7.8)+1);h.current={percentage:X,line:le,column:$}},[c]),re=t.useCallback(()=>{O(!0),G(""),Y(0),i==null||i()},[i]),je=t.useCallback(()=>{O(!1),G(""),Y(0)},[]),B=t.useCallback(()=>{F(m=>!m)},[]),Z=t.useCallback(m=>{const X=o.current;if(!X)return;const le=X.querySelector(".file-viewer-pre"),z=le&&parseFloat(getComputedStyle(le).lineHeight)||u.current,$=le&&parseFloat(getComputedStyle(le).paddingTop)||0,te=(le?le.offsetTop:0)+$+(m-1)*z,Q=z*3;X.scrollTo({top:Math.max(0,te-Q),behavior:"smooth"})},[]);t.useEffect(()=>{!A||K.length===0||Y(0)},[K,A]),t.useEffect(()=>{if(!A||K.length===0)return;const m=K[ae];m&&(v(m.line),R(m.column),Z(m.line))},[A,K,ae,Z]);const P=t.useCallback(()=>{K.length!==0&&Y(m=>(m+1)%K.length)},[K]),U=t.useCallback(()=>{K.length!==0&&Y(m=>(m-1+K.length)%K.length)},[K]),I=t.useCallback(m=>{const X=o.current;if(!X)return;const le=X.querySelector(".file-viewer-pre");if(!le)return;const z=parseFloat(getComputedStyle(le).lineHeight),$=isNaN(z)?u.current:z,S=parseFloat(getComputedStyle(le).paddingTop)||0,Q=le.offsetTop+S+(m-1)*$,de=Q+$,pe=X.scrollTop,se=pe+X.clientHeight;Q<pe?X.scrollTo({top:Math.max(0,Q),behavior:"auto"}):de>se&&X.scrollTo({top:de-X.clientHeight,behavior:"auto"})},[]),ie=t.useCallback((m,X)=>{v(m),R(X),I(m),g!=="none"&&T(le=>le?{...le,headLine:m,headCol:X}:null)},[g,I]),ee=t.useCallback(()=>{if(g==="none"||!w)return;const m=Ha(c,p,w,g);m&&navigator.clipboard.writeText(m).catch(()=>{const X=document.createElement("textarea");X.value=m,X.style.position="fixed",X.style.left="-9999px",document.body.appendChild(X),X.select(),document.execCommand("copy"),document.body.removeChild(X)}),j("none"),T(null)},[g,w,c,p]),ve=t.useCallback(m=>{const X=m.target;if((X.tagName==="INPUT"||X.tagName==="TEXTAREA")&&m.key!=="Escape")return;const z=o.current;if(!z)return;let $=!1;const S=u.current,te=Math.max(1,Math.floor(z.clientHeight/S)),Q=Math.max(1,Math.floor(te/2)),de=(se,we)=>{const Ge=Math.max(0,(p[se-1]||"").length-1);return Math.min(we,Math.max(0,Ge))},pe=(se,we)=>{const Ge=de(se,we);ie(se,Ge)};if(m.key==="v"&&!m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),g==="char"?(j("none"),T(null)):(j("char"),T({anchorLine:f,anchorCol:N,headLine:f,headCol:N})),$=!0;else if(m.key==="V"&&m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),g==="line"?(j("none"),T(null)):(j("line"),T({anchorLine:f,anchorCol:0,headLine:f,headCol:0})),$=!0;else if(m.key==="y"&&!m.ctrlKey&&g!=="none")m.preventDefault(),m.stopPropagation(),ee(),$=!0;else if(m.key==="j"||m.key==="ArrowDown"){m.preventDefault(),m.stopPropagation();const se=Math.min(f+1,b);pe(se,N),$=!0}else if(m.key==="k"||m.key==="ArrowUp"){m.preventDefault(),m.stopPropagation();const se=Math.max(f-1,1);pe(se,N),$=!0}else if(m.key==="d"&&m.ctrlKey||m.key==="d"&&g==="none"&&!A){m.preventDefault(),m.stopPropagation();const se=Math.min(f+Q,b);pe(se,N),$=!0}else if(m.key==="u"&&m.ctrlKey||m.key==="u"&&g==="none"&&!A){m.preventDefault(),m.stopPropagation();const se=Math.max(f-Q,1);pe(se,N),$=!0}else if((m.ctrlKey||m.metaKey)&&m.key==="f")m.preventDefault(),m.stopPropagation(),re(),$=!0;else if(m.key==="f"&&!m.ctrlKey&&!m.metaKey&&g==="none"&&!A){m.preventDefault(),m.stopPropagation();const se=Math.min(f+te,b);pe(se,N),$=!0}else if(m.key===" "||m.key==="PageDown"){m.preventDefault(),m.stopPropagation();const se=Math.min(f+te,b);pe(se,N),$=!0}else if(m.key==="b"&&!y&&g==="none"&&!A||m.key==="PageUp"){m.preventDefault(),m.stopPropagation();const se=Math.max(f-te,1);pe(se,N),$=!0}else if(m.key==="g"&&!m.shiftKey&&g==="none"&&!A)m.preventDefault(),m.stopPropagation(),ie(1,0),es(z,!1),$=!0;else if(m.key==="Home")m.preventDefault(),m.stopPropagation(),ie(1,0),es(z,!1),$=!0;else if(m.key==="G"&&m.shiftKey||m.key==="End")m.preventDefault(),m.stopPropagation(),ie(b,0),es(z,!0),$=!0;else if(m.key==="h"||m.key==="ArrowLeft")m.preventDefault(),m.stopPropagation(),ie(f,Math.max(0,N-1)),$=!0;else if(m.key==="l"||m.key==="ArrowRight"){m.preventDefault(),m.stopPropagation();const se=(p[f-1]||"").length;ie(f,Math.min(N+1,Math.max(0,se-1))),$=!0}else if(m.key==="w"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const se=Ia(p,f,N);ie(se.line,se.col),$=!0}else if(m.key==="e"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const se=La(p,f,N);ie(se.line,se.col),$=!0}else if(m.key==="b"&&!A){m.preventDefault(),m.stopPropagation();const se=$a(p,f,N);ie(se.line,se.col),$=!0}else if(m.key==="0")m.preventDefault(),m.stopPropagation(),ie(f,0),$=!0;else if(m.key==="$")m.preventDefault(),m.stopPropagation(),ie(f,Math.max(0,(p[f-1]||"").length-1)),$=!0;else if(m.key==="^"){m.preventDefault(),m.stopPropagation();const we=(p[f-1]||"").search(/\S/);ie(f,we>=0?we:0),$=!0}else m.key==="/"?(m.preventDefault(),m.stopPropagation(),re(),$=!0):m.key==="n"&&!A?(m.preventDefault(),m.stopPropagation(),P(),$=!0):m.key==="N"&&m.shiftKey&&!A?(m.preventDefault(),m.stopPropagation(),U(),$=!0):m.key==="?"&&g==="none"?(m.preventDefault(),m.stopPropagation(),B(),$=!0):m.key==="q"&&g==="none"?(m.preventDefault(),m.stopPropagation(),r==null||r(),$=!0):m.key==="Escape"&&(g!=="none"?(m.preventDefault(),m.stopPropagation(),j("none"),T(null),$=!0):A?(m.preventDefault(),m.stopPropagation(),je(),$=!0):y&&(m.preventDefault(),m.stopPropagation(),k(!1),$=!0));$&&(m.key!=="Escape"&&!y&&k(!0),requestAnimationFrame(ne))},[r,ne,b,p,f,N,I,A,je,g,y,ie,ee,re,P,U,B]);return t.useEffect(()=>{if(!l)return;const m=Da(n);if(o.current=m,!m){console.warn("[useLessNavigation] Could not find scrollable container");return}u.current=tn(m);const X=()=>{ne()};return window.addEventListener("keydown",ve,{capture:!0}),m.addEventListener("scroll",X,{passive:!0}),ne(),()=>{window.removeEventListener("keydown",ve,{capture:!0}),m.removeEventListener("scroll",X)}},[l,ve,ne]),{scrollPercentage:h.current.percentage,currentLine:h.current.line,currentColumn:h.current.column,totalLines:b,cursorLine:f,cursorCol:N,cursorModeActive:y,visualMode:g,selection:w,searchActive:A,searchQuery:C,searchMatches:K,currentMatchIndex:ae,startSearch:re,setSearchQuery:G,nextMatch:P,prevMatch:U,clearSearch:je,helpActive:D,toggleHelp:B}}const rs=({query:s,onQueryChange:n,matchCount:l,currentIndex:c,onNext:r,onPrev:i,onClose:h})=>{const{t:o}=oe(["terminal"]),u=t.useRef(null);t.useEffect(()=>{var f;(f=u.current)==null||f.focus()},[]);const p=t.useCallback(f=>{f.stopPropagation(),f.key==="Enter"||f.key==="ArrowDown"?(f.preventDefault(),r()):f.key==="ArrowUp"&&(f.preventDefault(),i())},[r,i]),b=l===0&&s?o("terminal:fileExplorer.noMatches"):l>0?`${c+1}/${l}`:"";return e.jsxs("div",{className:"file-viewer-search-bar",children:[e.jsxs("div",{className:"file-viewer-search-input-wrapper",children:[e.jsx("span",{className:"file-viewer-search-prefix",children:"/"}),e.jsx("input",{ref:u,type:"text",className:"file-viewer-search-input",placeholder:o("terminal:fileExplorer.searchInFile"),value:s,onChange:f=>n(f.target.value),onKeyDown:p,autoComplete:"off",spellCheck:"false"})]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-viewer-search-counter",children:b}),e.jsxs("div",{className:"file-viewer-search-nav",children:[e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-prev",onClick: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:h,title:o("terminal:fileExplorer.closeSearch"),"aria-label":o("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};rs.displayName="SearchBar";const za=[{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"}],is=({onClose:s})=>{const{t:n}=oe(["terminal"]),l=t.useCallback(i=>{i.target===i.currentTarget&&s()},[s]),c=t.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),s())},[s]),r=za.reduce((i,h)=>(i[h.category]||(i[h.category]=[]),i[h.category].push(h),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:l,onKeyDown:c,tabIndex:0,role:"dialog","aria-label":n("terminal:fileExplorer.keybindingsHelp"),children:e.jsxs("div",{className:"keybindings-help-content",children:[e.jsx("button",{className:"keybindings-help-close",onClick:s,"aria-label":n("terminal:fileExplorer.closeHelp"),title:n("terminal:fileExplorer.pressEscapeToClose"),children:e.jsx(M,{name:"close",size:14})}),e.jsx("h2",{className:"keybindings-help-title",children:n("terminal:fileExplorer.keybindingsHelp")}),e.jsx("p",{className:"keybindings-help-subtitle",children:n("terminal:fileExplorer.keybindingsSubtitle")}),e.jsx("div",{className:"keybindings-help-categories",children:Object.entries(r).map(([i,h])=>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:h.map((o,u)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:o.keys.map((p,b)=>e.jsx("kbd",{className:"keybindings-help-key",children:p},b))}),e.jsx("div",{className:"keybindings-help-description",children:o.description})]},u))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};is.displayName="KeybindingsHelp";const Vs=t.lazy(()=>_n(()=>import("./EmbeddedEditor-CEjr0ZSZ.js"),__vite__mapDeps([0,1,2,3,4,5])).then(s=>({default:s.EmbeddedEditor}))),Aa=[".md",".mdx",".markdown"],Ws="file-viewer-markdown-render",Oa=[".puml",".plantuml",".iuml",".pu"],qs="file-viewer-plantuml-render",Ga="https://kroki.io/plantuml/svg";function Ua(s){return Aa.includes(s.toLowerCase())}function Ba(s){return Oa.includes(s.toLowerCase())}function _a(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(Ws);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ws,String(r))}catch{}return r})},[]);return[s,l]}function Ka(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(qs);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(qs,String(r))}catch{}return r})},[]);return[s,l]}function Va(s){const n=new TextEncoder().encode(s);let l="";for(const c of n)l+=String.fromCharCode(c);return`data:image/svg+xml;base64,${window.btoa(l)}`}function Ve({file:s,rightContent:n,onRevealInTree:l,editMode:c,onToggleEdit:r}){const{t:i}=oe(["terminal","common"]),[h,o]=t.useState("idle"),[u,p]=t.useState("idle"),[b,f]=t.useState("idle"),v=s.fileType==="text"?At(s.extension):s.extension.slice(1).toUpperCase(),N=s.fileType==="text"&&s.content!=null,R=Bn(),y=async()=>{try{await Lt(s.content),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},k=()=>{const T=new Blob([s.content],{type:"text/plain;charset=utf-8"}),A=URL.createObjectURL(T),O=document.createElement("a");O.href=A,O.download=s.filename,document.body.appendChild(O),O.click(),O.remove(),setTimeout(()=>URL.revokeObjectURL(A),1e3)},g=async()=>{o("loading");try{const T=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(!T.ok){const A=await T.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",A),o("error"),setTimeout(()=>o("idle"),2e3);return}o("success"),setTimeout(()=>o("idle"),2e3)}catch(T){console.error("Error opening file in editor:",T),o("error"),setTimeout(()=>o("idle"),2e3)}},j=async()=>{if(s.path)try{await Jn(s.path),p("success"),setTimeout(()=>p("idle"),2e3)}catch(T){console.error("Error opening file explorer:",T),p("error"),setTimeout(()=>p("idle"),2e3)}},w=i("terminal:fileExplorer.openInFileExplorer");return e.jsxs("div",{className:"file-viewer-header",children:[e.jsxs("div",{className:"file-viewer-header-left",children:[e.jsx("span",{className:"file-viewer-filename",children:s.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[Xs(s.size)," • ",v,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${c?" active":""}`,onClick:r,title:i(c?"terminal:fileExplorer.exitEdit":"terminal:fileExplorer.editFile"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L3.463 11.1a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.25.25 0 00.108-.064l8.61-8.61a.25.25 0 000-.354l-1.086-1.086z"})})}),N&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:y,title:i("terminal:fileExplorer.copyAllTitle"),children:i(b==="copied"?"terminal:fileExplorer.copied":b==="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 ${u}`,onClick:j,disabled:!s.path,title:w,"aria-label":w,children:u==="success"?e.jsx(M,{name:"check",size:14}):u==="error"?e.jsx(M,{name:"cross",size:14}):e.jsx(M,{name:"folder-open",size:14})}),e.jsx("button",{className:`file-viewer-open-editor-btn ${h}`,onClick:g,disabled:h==="loading",title:i(h==="error"?"terminal:fileExplorer.failedToOpenEditor":h==="success"?"terminal:fileExplorer.openingInEditor":"terminal:fileExplorer.openInEditor"),children:h==="success"?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 11-1.06-1.06l7.25-7.25a.75.75 0 011.06 0z"})}):h==="error"?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"})}):e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M1.5 1h6v1.5h-5v11h11v-5H15v6.5H0V1h1.5zm8 0H15v5.5h-1.5V3.56L7.28 9.78l-1.06-1.06L12.44 2.5H9.5V1z"})})}),l&&e.jsx("button",{className:"file-viewer-locate-btn",onClick:()=>l(s.path),title:i("terminal:fileExplorer.locateInTree"),children:e.jsx(M,{name:"target",size:14})}),n]})]})}function Wa({file:s,onRevealInTree:n,renderMarkdown:l,onToggleRender:c,editMode:r,onToggleEdit:i}){const h=t.useRef(null),o=t.useRef(null),u=t.useRef(null),{t:p}=oe(["terminal","common"]),[b,f]=t.useState("idle"),[v,N]=t.useState("idle"),[R,y]=t.useState("idle"),[k,g]=t.useState("idle"),j=sn({containerRef:u,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&h.current){const G=At(s.extension);Qs(G).then(()=>{h.current&&Zs(h.current)})}},[s,l]);const w=t.useCallback(async()=>{if(!o.current){f("error"),setTimeout(()=>f("idle"),2e3);return}try{const G=o.current.innerHTML,ae=Kn(G),Y=o.current.innerText;await Vn(ae,Y),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},[]),T=t.useCallback(async()=>{if(!o.current){N("error"),setTimeout(()=>N("idle"),2e3);return}try{const G=o.current.innerHTML;await Lt(G),N("copied"),setTimeout(()=>N("idle"),2e3)}catch{N("error"),setTimeout(()=>N("idle"),2e3)}},[]),A=t.useCallback(async()=>{try{await Lt(s.content),y("copied"),setTimeout(()=>y("idle"),2e3)}catch{y("error"),setTimeout(()=>y("idle"),2e3)}},[s.content]),O=t.useCallback(async()=>{try{await Lt(s.content),g("copied"),setTimeout(()=>g("idle"),2e3)}catch{g("error"),setTimeout(()=>g("idle"),2e3)}},[s.content]),C=e.jsxs("div",{className:"file-viewer-header-buttons",children:[l&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:w,title:p("terminal:fileExplorer.copyRichTextTitle"),children:p(b==="copied"?"terminal:fileExplorer.copied":b==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyRichText")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${v}`,onClick:T,title:p("terminal:fileExplorer.copyHtmlTitle"),children:p(v==="copied"?"terminal:fileExplorer.copied":v==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyHtml")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${R}`,onClick:A,title:p("terminal:fileExplorer.copyMarkdownTitle"),children:p(R==="copied"?"terminal:fileExplorer.copied":R==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyMarkdown")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${k}`,onClick:O,title:p("terminal:fileExplorer.copyOriginalTitle"),children:p(k==="copied"?"terminal:fileExplorer.copied":k==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyOriginal")})]}),e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:c,title:p(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderMarkdown"),children:l?"</>":"Aa"})]});return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:C,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:u,children:[l?e.jsx("div",{className:"file-viewer-markdown-wrapper",children:e.jsx("div",{className:"markdown-content",ref:o,children:e.jsx(Wn,{remarkPlugins:[qn],children:s.content})})}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:h,className:"language-markdown",children:s.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${j.currentLine}/${j.totalLines}`,children:j.scrollPercentage===100?"END":j.scrollPercentage===0?"TOP":`${j.scrollPercentage}%`}),j.searchActive&&e.jsx(rs,{query:j.searchQuery,onQueryChange:j.setSearchQuery,matchCount:j.searchMatches.length,currentIndex:j.currentMatchIndex,onNext:j.nextMatch,onPrev:j.prevMatch,onClose:j.clearSearch})]}),j.helpActive&&e.jsx(is,{onClose:j.toggleHelp})]})}function qa({file:s,onRevealInTree:n,renderPlantUml:l,onToggleRender:c,editMode:r,onToggleEdit:i}){const{t:h}=oe(["terminal"]),o=t.useRef(null),u=t.useRef(null),[p,b]=t.useState(null),[f,v]=t.useState(!1),[N,R]=t.useState(null),y=sn({containerRef:u,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&o.current){const g=At(s.extension);Qs(g).then(()=>{o.current&&Zs(o.current)})}},[s,l]),t.useEffect(()=>{if(!l)return;if(!s.content.trim()){b(null),R("Diagram is empty");return}const g=new AbortController;return v(!0),R(null),(async()=>{try{const w=await fetch(Ga,{method:"POST",headers:{"Content-Type":"text/plain; charset=utf-8",Accept:"image/svg+xml"},body:s.content,signal:g.signal});if(!w.ok)throw new Error(`Render failed (${w.status})`);const T=await w.text();if(!T.includes("<svg"))throw new Error("Invalid SVG output");b(Va(T))}catch(w){if(g.signal.aborted)return;const T=w instanceof Error?w.message:"Failed to render diagram";R(T),b(null)}finally{g.signal.aborted||v(!1)}})(),()=>g.abort()},[s.path,s.content,l]);const k=e.jsx("div",{className:"file-viewer-header-buttons",children:e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:c,title:h(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderDiagram"),children:l?"</>":h("terminal:fileExplorer.diagram")})});return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:k,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:u,children:[l?e.jsxs("div",{className:"file-viewer-diagram-wrapper",children:[f&&e.jsx("div",{className:"file-viewer-placeholder",children:h("terminal:fileExplorer.renderingDiagram")}),!f&&p&&e.jsx("img",{src:p,alt:s.filename,className:"file-viewer-diagram-image"}),!f&&N&&e.jsxs("div",{className:"file-viewer-diagram-error",children:[e.jsxs("div",{children:[h("terminal:fileExplorer.couldNotRender"),": ",N]}),e.jsx("button",{className:"file-viewer-render-toggle",onClick:c,children:h("terminal:fileExplorer.showSource")})]})]}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:o,className:"language-plaintext",children:s.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${y.currentLine}/${y.totalLines}`,children:y.scrollPercentage===100?"END":y.scrollPercentage===0?"TOP":`${y.scrollPercentage}%`}),y.searchActive&&e.jsx(rs,{query:y.searchQuery,onQueryChange:y.setSearchQuery,matchCount:y.searchMatches.length,currentIndex:y.currentMatchIndex,onNext:y.nextMatch,onPrev:y.prevMatch,onClose:y.clearSearch})]}),y.helpActive&&e.jsx(is,{onClose:y.toggleHelp})]})}function Ja({file:s,onRevealInTree:n}){const{t:l}=oe(["common","terminal"]),c=()=>{if(s.dataUrl){const r=document.createElement("a");r.href=s.dataUrl,r.download=s.filename,r.click()}};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-image-wrapper",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 Ya({file:s,onRevealInTree:n}){const{t:l}=oe(["common","terminal"]),c=()=>{if(s.dataUrl){const r=document.createElement("a");r.href=s.dataUrl,r.download=s.filename,r.click()}};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-pdf-wrapper",children:s.dataUrl?e.jsx("iframe",{src:s.dataUrl,title:s.filename,className:"file-viewer-pdf"}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadPdf")})})]})}function Xa({file:s,onRevealInTree:n}){const{t:l}=oe(["terminal","common"]),c=()=>{if(s.dataUrl){const i=document.createElement("a");i.href=s.dataUrl,i.download=s.filename,i.click()}},r=()=>{const i=s.extension.toLowerCase();return[".xlsx",".xls"].includes(i)?e.jsx(M,{name:"dashboard",size:48}):[".docx",".doc"].includes(i)?e.jsx(M,{name:"edit",size:48}):[".pptx",".ppt"].includes(i)?e.jsx(M,{name:"film",size:48}):[".zip",".tar",".gz",".rar",".7z"].includes(i)?e.jsx(M,{name:"file-zip",size:48}):[".mp3",".wav",".flac",".ogg"].includes(i)?e.jsx(M,{name:"music-note",size:48}):[".mp4",".avi",".mov",".mkv",".webm"].includes(i)?e.jsx(M,{name:"film",size:48}):[".exe",".dmg",".app",".msi"].includes(i)?e.jsx(M,{name:"gear",size:48}):[".apk",".aab",".ipa"].includes(i)?e.jsx(M,{name:"mobile",size:48}):[".jar",".war",".ear"].includes(i)?e.jsx(M,{name:"coffee",size:48}):[".iso",".img"].includes(i)?e.jsx(M,{name:"disc",size:48}):[".so",".dll",".dylib"].includes(i)?e.jsx(M,{name:"wrench",size:48}):e.jsx(M,{name:"folder",size:48})};return e.jsxs(e.Fragment,{children:[e.jsx(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:Xs(s.size)}),e.jsx("div",{className:"file-viewer-binary-message",children:l("terminal:fileExplorer.cannotPreview")}),e.jsx("button",{className:"file-viewer-download-btn large",onClick:c,children:l("terminal:fileExplorer.downloadFile")})]})]})}function Qa({file:s,loading:n,error:l,onRevealInTree:c,onFileEdited:r}){const{t:i}=oe(["terminal","common"]),[h,o]=_a(),[u,p]=Ka(),[b,f]=t.useState(!1);t.useEffect(()=>{f(!1)},[s==null?void 0:s.path]);const v=t.useCallback(async w=>{if(!s)return;const T=await W(V("/api/files/write"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,content:w})});if(!T.ok){const A=await T.json().catch(()=>({error:"Save failed"}));throw new Error(A.error||"Save failed")}},[s]),N=t.useCallback(()=>{f(w=>(w&&s&&(r==null||r(s.path)),!w))},[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 y=s.fileType||"text",k=y==="text"&&Ua(s.extension),g=y==="text"&&Ba(s.extension),j=k||g;return j&&b&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ve,{file:s,onRevealInTree:c,editMode:!0,onToggleEdit:N}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(Vs,{content:s.content,extension:s.extension,onSave:v,onCancel:N},s.path)})]}):y==="text"&&!j&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ve,{file:s,onRevealInTree:c}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(Vs,{content:s.content,extension:s.extension,onSave:v,onCancel:R},s.path)})]}):e.jsxs("div",{className:"file-viewer-content",children:[k&&e.jsx(Wa,{file:s,onRevealInTree:c,renderMarkdown:h,onToggleRender:o,editMode:b,onToggleEdit:N}),g&&!k&&e.jsx(qa,{file:s,onRevealInTree:c,renderPlantUml:u,onToggleRender:p,editMode:b,onToggleEdit:N}),y==="image"&&e.jsx(Ja,{file:s,onRevealInTree:c}),y==="pdf"&&e.jsx(Ya,{file:s,onRevealInTree:c}),y==="binary"&&e.jsx(Xa,{file:s,onRevealInTree:c})]})}const nn=t.memo(Qa,(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);nn.displayName="FileViewer";function an({text:s,query:n}){if(!n)return e.jsx(e.Fragment,{children:s});const l=Yn(s,n);if(l)return e.jsxs(e.Fragment,{children:[s.slice(0,l.start),e.jsx("mark",{className:"search-highlight",children:s.slice(l.start,l.end)}),s.slice(l.end)]});const c=n.toLowerCase(),i=s.toLowerCase().indexOf(c);return i===-1?e.jsx(e.Fragment,{children:s}):e.jsxs(e.Fragment,{children:[s.slice(0,i),e.jsx("mark",{className:"search-highlight",children:s.slice(i,i+n.length)}),s.slice(i+n.length)]})}const Za=t.memo(function({node:n,query:l,isSelected:c,onSelect:r,lineNumber:i}){const h=n.isDirectory?null:ns(n),o=n.path.split("/");o[o.length-1];const u=o.slice(0,-1).join("/");return e.jsxs("div",{className:`search-result-item ${c?"selected":""}`,onClick:()=>r(n),children:[n.isDirectory?e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"folder",size:14})}):h?e.jsx("span",{className:"search-result-icon",style:{backgroundImage:`url('${h}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsxs("div",{className:"search-result-info",children:[e.jsxs("span",{className:"search-result-name",children:[e.jsx(an,{text:n.name,query:l}),i&&e.jsxs("span",{className:"search-result-line-badge",children:[":",i]})]}),e.jsx("span",{className:"search-result-path",children:u})]})]})}),er=t.memo(function({match:n,query:l,isSelected:c,onSelect:r}){const{t:i}=oe(["terminal"]),h={name:n.name,path:n.path,isDirectory:!1,extension:n.extension},o=ns(h),u=n.path.split("/"),p=u[u.length-1],b=u.slice(0,-1).join("/");return e.jsxs("div",{className:`content-search-item ${c?"selected":""}`,children:[e.jsxs("div",{className:`content-search-header ${c?"selected":""}`,onClick:()=>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:b})]}),e.jsx("span",{className:"content-search-count",children:n.matches.length})]}),e.jsxs("div",{className:"content-search-matches",children:[n.matches.slice(0,5).map((f,v)=>e.jsxs("div",{className:"content-search-match",onClick:()=>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(an,{text:f.content.trim(),query:l})})]},`${n.path}-${f.line}-${v}`)),n.matches.length>5&&e.jsxs("div",{className:"content-search-match",style:{opacity:.6,cursor:"default"},children:[e.jsx("span",{className:"content-search-line-num",children:"..."}),e.jsx("span",{className:"content-search-line-content",children:i("terminal:fileExplorer.moreMatches",{count:n.matches.length-5})})]})]})]})});function tr({filenameResults:s,contentResults:n,onSelectFile:l,onSelectContent:c,selectedPath:r,query:i,lineNumber:h}){const{t:o}=oe(["terminal"]),u=s.length>0,p=n.length>0;return!u&&!p?e.jsx("div",{className:"search-no-results",children:o("terminal:fileExplorer.noMatchesFound")}):e.jsxs("div",{className:"unified-search-results",children:[u&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.files")}),e.jsx("span",{className:"unified-search-section-count",children:s.length})]}),e.jsx("div",{className:"unified-search-section-content",children:s.map(b=>e.jsx(Za,{node:b,query:i,isSelected:r===b.path,onSelect:l,lineNumber:h},b.path))})]}),p&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(M,{name:"edit",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.content")}),e.jsx("span",{className:"unified-search-section-count",children:o("terminal:fileExplorer.matchesInFiles",{matches:n.reduce((b,f)=>b+f.matches.length,0),files:n.length})})]}),e.jsx("div",{className:"unified-search-section-content",children:n.map(b=>e.jsx(er,{match:b,query:i,isSelected:r===b.path,onSelect:c},b.path))})]})]})}const rn=t.memo(tr,(s,n)=>!(s.query!==n.query||s.selectedPath!==n.selectedPath||s.filenameResults.length!==n.filenameResults.length||s.contentResults.length!==n.contentResults.length));rn.displayName="UnifiedSearchResults";const sr=t.memo(function({file:n,isSelected:l,onSelect:c,onStage:r,isStaging:i,showDirPath:h,isChecked:o,onToggleCheck:u,onContextMenu:p,onDiscard:b}){const{t:f}=oe(["terminal"]),v=n.status,N=xt[v],R=v==="deleted",y=v==="untracked"&&r,k=n.name.includes(".")?"."+n.name.split(".").pop():"",g=h&&n.path.includes("/")?n.path.slice(0,n.path.lastIndexOf("/")):"";return e.jsxs("div",{className:`git-file-item ${l?"selected":""}`,onClick:()=>!R&&c(n.path,v),onContextMenu:j=>{j.preventDefault(),p==null||p(j,n,v)},style:{cursor:R?"not-allowed":"pointer"},title:n.path,children:[u&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:o||!1,onChange:j=>{j.stopPropagation(),u(n.path)},onClick:j=>j.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:gt(k),alt:"file"}),e.jsxs("span",{className:"git-file-name",children:[n.name,g&&e.jsx("span",{className:"git-file-dir",children:g})]}),e.jsx("span",{className:"git-file-status",style:{color:N.color},children:N.icon}),n.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:[e.jsx(M,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.oldPath.split("/").pop()]}),y&&e.jsx("button",{className:`git-stage-btn ${i?"staging":""}`,onClick:j=>{j.stopPropagation(),i||r(n.path)},title:f("terminal:fileExplorer.stageFile"),disabled:i,children:i?"...":"+"}),b&&e.jsx("button",{className:"git-discard-btn",onClick:j=>{j.stopPropagation(),b(n,v)},title:v==="untracked"||v==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}),nr=16,ar=22,rr=t.memo(function s({node:n,depth:l,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:h,onStage:o,stagingPaths:u,checkedFiles:p,onToggleCheck:b,onContextMenu:f,onDirContextMenu:v,onDiscard:N}){const{t:R}=oe(["terminal"]),y=l*nr;if(!n.isDirectory){const g=n.file.status,j=xt[g];return e.jsxs("div",{className:`git-file-item ${i===n.path?"selected":""}`,onClick:()=>g!=="deleted"&&h(n.file.path,g),onContextMenu:w=>{w.preventDefault(),f==null||f(w,n.file,g)},style:{paddingLeft:`${y+ar}px`,cursor:g==="deleted"?"not-allowed":"pointer"},title:n.file.path,children:[b&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:(p==null?void 0:p.has(n.file.path))||!1,onChange:w=>{w.stopPropagation(),b(n.file.path)},onClick:w=>w.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:gt(n.file.name.includes(".")?"."+n.file.name.split(".").pop():""),alt:"file"}),e.jsx("span",{className:"git-file-name",children:n.file.name}),e.jsx("span",{className:"git-file-status",style:{color:j.color},children:j.icon}),n.file.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:[e.jsx(M,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.file.oldPath.split("/").pop()]}),g==="untracked"&&o&&e.jsx("button",{className:`git-stage-btn ${u!=null&&u.has(n.path)?"staging":""}`,onClick:w=>{w.stopPropagation(),u!=null&&u.has(n.path)||o(n.file.path)},title:R("terminal:fileExplorer.stageFile"),disabled:u==null?void 0:u.has(n.path),children:u!=null&&u.has(n.path)?"...":"+"}),N&&e.jsx("button",{className:"git-discard-btn",onClick:w=>{w.stopPropagation(),N(n.file,g)},title:g==="untracked"||g==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}const k=c.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${k?"expanded":""}`,style:{paddingLeft:`${y}px`},onClick:()=>r(n.path),onContextMenu:g=>{g.preventDefault(),g.stopPropagation(),v==null||v(g,n)},children:[e.jsx("span",{className:`tree-arrow ${k?"expanded":""}`,children:e.jsx(M,{name:"caret-right",size:10})}),e.jsx("img",{className:"tree-folder-icon",src:k?"/assets/vscode-icons/default_folder_opened.svg":"/assets/vscode-icons/default_folder.svg",alt:"folder"}),e.jsx("span",{className:"tree-name",children:n.name}),e.jsx("span",{className:"git-tree-file-count",children:R("terminal:fileExplorer.fileCount",{count:n.fileCount})})]}),k&&e.jsx("div",{className:"tree-children",children:n.children.map(g=>e.jsx(s,{node:g,depth:l+1,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:h,onStage:o,stagingPaths:u,checkedFiles:p,onToggleCheck:b,onContextMenu:f,onDirContextMenu:v,onDiscard:N},g.path))})]})}),ts=t.memo(function({groupLabel:n,groupIcon:l,groupColor:c,files:r,treeNodes:i,viewMode:h,selectedPath:o,expandedDirs:u,onToggleDir:p,onFileSelect:b,onStageFile:f,onStageAll:v,stagingPaths:N,checkedFiles:R,onToggleCheck:y,onContextMenu:k,onDirContextMenu:g,onDiscardFile:j,onDiscardAll:w}){const{t:T}=oe(["terminal"]);if(r.length===0)return null;const A=r.some(G=>G.status==="untracked"),O=A&&v&&r.length>0,C=N?r.every(G=>N.has(G.path)):!1;return e.jsxs("div",{className:"git-status-group",children:[e.jsxs("div",{className:"git-status-group-header",style:{color:c},children:[e.jsx("span",{className:"git-status-badge",style:{background:c},children:l}),n," (",r.length,")",O&&e.jsx("button",{className:`git-stage-all-btn ${C?"staging":""}`,onClick:G=>{G.stopPropagation(),C||v()},title:T("terminal:fileExplorer.stageAllUntracked"),disabled:C,children:C?"...":T("terminal:fileExplorer.stageAll")}),w&&e.jsxs("button",{className:"git-discard-all-btn",onClick:G=>{G.stopPropagation(),w()},title:A?`Delete all ${r.length} files`:`Discard all ${r.length} changes`,children:[e.jsx(M,{name:"revert",size:12})," All"]})]}),h==="tree"?e.jsx("div",{className:"git-tree-content",children:i.map(G=>e.jsx(rr,{node:G,depth:0,expandedDirs:u,onToggleDir:p,selectedPath:o,onSelect:b,onStage:f,stagingPaths:N,checkedFiles:R,onToggleCheck:y,onContextMenu:k,onDirContextMenu:g,onDiscard:j},G.path))}):e.jsx("div",{className:"git-flat-content",children:r.map(G=>e.jsx(sr,{file:G,isSelected:o===G.path,onSelect:b,onStage:G.status==="untracked"?f:void 0,isStaging:N==null?void 0:N.has(G.path),showDirPath:!0,isChecked:R==null?void 0:R.has(G.path),onToggleCheck:y,onContextMenu:k,onDiscard:j},G.path))})]})});function ir({gitStatus:s,loading:n,onFileSelect:l,selectedPath:c,onRefresh:r,onStageFiles:i,stagingPaths:h,currentFolder:o,onCommitComplete:u,mergeInProgress:p,mergingBranch:b,onMergeContinue:f,onMergeAbort:v,onConflictOpen:N,onRevealInTree:R}){const{t:y}=oe(["terminal","common"]),[k,g]=t.useState("tree"),[j,w]=t.useState(new Set),[T,A]=t.useState(""),[O,C]=t.useState(""),[G,ae]=t.useState(!1),[Y,D]=t.useState(new Set),[F,K]=t.useState(!1),[ne,re]=t.useState(null),je=t.useRef(null),{showToast:B}=en(),[Z,P]=t.useState(null),[U,I]=t.useState(null),[ie,ee]=t.useState(null),ve=t.useCallback((E,L)=>{ee({files:[E],label:E.name})},[]),m=t.useCallback(async()=>{if(!(!ie||!o))try{const E=await W(V("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:ie.files.map(_=>({path:_.path,status:_.status})),directory:o})}),L=await E.json();E.ok&&L.success?(B("success","Discarded",`Reverted ${ie.files.length} file(s)`),r()):B("error","Discard Failed",L.error||"Could not discard changes")}catch{B("error","Discard Failed","Network error")}finally{ee(null)}},[ie,o,r,B]),X=t.useCallback((E,L,_)=>{E.preventDefault(),E.stopPropagation(),P({isOpen:!0,position:{x:E.clientX,y:E.clientY},file:L,status:_})},[]),le=t.useCallback(async(E,L)=>{if(o)try{const _=await W(V("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:E.path,status:L}],directory:o})}),be=await _.json();_.ok&&be.success?(B("success","Discarded",`Restored ${E.name}`),r()):B("error","Discard Failed",be.error||"Could not discard changes")}catch{B("error","Discard Failed","Network error")}},[o,r,B]),z=t.useCallback(async E=>{try{await navigator.clipboard.writeText(E),B("success","Copied","Full path copied")}catch{B("error","Copy Failed","Could not copy path")}},[B]),$=t.useCallback(async E=>{const L=o&&E.startsWith(o+"/")?E.slice(o.length+1):E;try{await navigator.clipboard.writeText(L),B("success","Copied","Relative path copied")}catch{B("error","Copy Failed","Could not copy path")}},[o,B]),S=t.useMemo(()=>{if(!Z)return[];const{file:E,status:L}=Z,_=[];return L==="conflict"&&N?_.push({id:"open-conflict",label:y("terminal:fileExplorer.gitContextMenu.openConflictResolver"),icon:e.jsx(M,{name:"warn",size:14}),onClick:()=>N(E.path)}):L!=="deleted"&&_.push({id:"open-file",label:y("terminal:fileExplorer.gitContextMenu.openFile"),icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>l(E.path,L)}),L!=="conflict"&&_.push({id:"stage-file",label:y("terminal:fileExplorer.gitContextMenu.stageFile"),icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i([E.path])}}),_.push({id:"divider-1",label:"",divider:!0,onClick:()=>{}}),(L==="modified"||L==="deleted"||L==="renamed"||L==="conflict")&&_.push({id:"discard-changes",label:y("terminal:fileExplorer.gitContextMenu.discardChanges"),icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{le(E,L)}}),(L==="untracked"||L==="added")&&_.push({id:"delete-file",label:y("terminal:fileExplorer.gitContextMenu.deleteFile"),icon:e.jsx(M,{name:"trash",size:14}),danger:!0,onClick:()=>{le(E,L)}}),_.push({id:"divider-2",label:"",divider:!0,onClick:()=>{}}),_.push({id:"copy-full-path",label:y("terminal:fileExplorer.gitContextMenu.copyFullPath"),icon:e.jsx(M,{name:"pin",size:14}),onClick:()=>{z(E.path)}}),_.push({id:"copy-relative-path",label:y("terminal:fileExplorer.gitContextMenu.copyRelativePath"),icon:e.jsx(M,{name:"clipboard",size:14}),onClick:()=>{$(E.path)}}),R&&L!=="deleted"&&_.push({id:"reveal-in-tree",label:y("terminal:fileExplorer.gitContextMenu.revealInTree"),icon:e.jsx(M,{name:"target",size:14}),onClick:()=>R(E.path)}),_},[Z,l,i,N,R,le,z,$,y]),te=t.useCallback((E,L)=>{E.preventDefault(),E.stopPropagation(),I({isOpen:!0,position:{x:E.clientX,y:E.clientY},node:L})},[]),Q=t.useCallback(E=>!E.isDirectory&&E.file?[E.file]:E.children.flatMap(L=>Q(L)),[]),de=t.useCallback(async E=>{if(!o)return;const L=Q(E);if(L.length!==0)try{const _=await W(V("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:L.map(Me=>({path:Me.path,status:Me.status})),directory:o})}),be=await _.json();_.ok&&be.success?(B("success","Discarded",`Reverted ${L.length} file(s) in ${E.name}`),r()):B("error","Discard Failed",be.error||"Could not discard changes")}catch{B("error","Discard Failed","Network error")}},[o,Q,r,B]),pe=t.useMemo(()=>{if(!U)return[];const{node:E}=U,L=Q(E);return[{id:"discard-dir",label:`Discard Changes (${L.length} files)`,icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{de(E)}},{id:"stage-dir",label:`Stage All (${L.length} files)`,icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i(L.map(_=>_.path))}}]},[U,Q,de,i]),se=t.useCallback(E=>{w(L=>{const _=new Set(L);return _.has(E)?_.delete(E):_.add(E),_})},[]),{conflictFiles:we,conflictTree:Ge,changesFiles:He,changesTree:Ot,untrackedFiles:ze,untrackedTree:yt,allDirPaths:Ue}=t.useMemo(()=>{if(!s||!s.isGitRepo||s.files.length===0)return{conflictFiles:[],conflictTree:[],changesFiles:[],changesTree:[],untrackedFiles:[],untrackedTree:[],allDirPaths:new Set};const E=new Set,L=s.files.filter(me=>me.status==="conflict"),_=$t(L);Ht(_,E);const be=s.files.filter(me=>me.status==="modified"||me.status==="added"||me.status==="deleted"||me.status==="renamed"),Me=$t(be);Ht(Me,E);const qe=s.files.filter(me=>me.status==="untracked"),ct=$t(qe);return Ht(ct,E),{conflictFiles:L,conflictTree:_,changesFiles:be,changesTree:Me,untrackedFiles:qe,untrackedTree:ct,allDirPaths:E}},[s]);t.useEffect(()=>{w(Ue)},[Ue]),t.useEffect(()=>{s!=null&&s.files&&D(new Set(s.files.map(E=>E.path)))},[s==null?void 0:s.files]);const ot=t.useCallback(()=>{He.length!==0&&ee({files:He,label:`${He.length} changed files`})},[He]),bt=t.useCallback(()=>{ze.length!==0&&ee({files:ze,label:`${ze.length} unversioned files`})},[ze]),jt=t.useCallback(()=>{we.length!==0&&ee({files:we,label:`${we.length} conflicted files`})},[we]),vt=we.length>0;t.useEffect(()=>{if(ne){const E=ne.type==="error"?8e3:4e3,L=setTimeout(()=>re(null),E);return()=>clearTimeout(L)}},[ne]);const wt=t.useCallback(async()=>{const E=!G;if(ae(E),E&&o){C(T);try{const _=await(await W(V(`/api/files/git-log-message?path=${encodeURIComponent(o)}`))).json();_.message&&A(_.message)}catch{}}else A(O)},[G,o,T,O]),ye=t.useCallback(E=>{D(L=>{const _=new Set(L);return _.has(E)?_.delete(E):_.add(E),_})},[]),ue=t.useCallback(()=>{if(!(s!=null&&s.files))return;const E=s.files.map(_=>_.path),L=E.every(_=>Y.has(_));D(L?new Set:new Set(E))},[s==null?void 0:s.files,Y]),xe=t.useCallback(async E=>{if(!(!o||!T.trim()||Y.size===0||F)){K(!0),re(null);try{const L=await W(V("/api/files/git-commit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o,message:T.trim(),amend:G,paths:Array.from(Y)})}),_=await L.json();if(!L.ok||!_.success){re({type:"error",text:_.error||"Commit failed"}),K(!1);return}if(E)try{const be=await W(V("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o})}),Me=await be.json();be.ok&&Me.success?re({type:"success",text:y("terminal:fileExplorer.committedAndPushed")}):re({type:"error",text:y("terminal:fileExplorer.committedButPushFailed",{error:Me.error||"Unknown error"})})}catch{re({type:"error",text:y("terminal:fileExplorer.committedButPushFailed",{error:"Network error"})})}else re({type:"success",text:y("terminal:fileExplorer.committedSuccessfully")});A(""),C(""),ae(!1),r(),u==null||u()}catch(L){re({type:"error",text:L.message||"Commit failed"})}finally{K(!1)}}},[o,T,G,Y,F,r,u]);if(n)return e.jsx("div",{className:"git-changes-loading",children:y("terminal:fileExplorer.loadingGitStatus")});if(!s||!s.isGitRepo)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(M,{name:"package",size:32})}),e.jsx("div",{className:"git-empty-text",children:y("terminal:fileExplorer.notGitRepo")})]});if(s.files.length===0)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(M,{name:"sparkle",size:32})}),e.jsx("div",{className:"git-empty-text",children:y("terminal:fileExplorer.workingTreeClean")}),e.jsx("div",{className:"git-empty-branch",children:y("terminal:fileExplorer.onBranch",{branch:s.branch})})]});const ke=E=>{i([E])},We=()=>{const E=ze.map(L=>L.path);E.length>0&&i(E)},Re=(E,L)=>{L==="conflict"&&N?N(E):l(E,L)};return e.jsxs("div",{className:"git-changes",children:[e.jsxs("div",{className:"git-changes-header",children:[e.jsxs("span",{className:"git-branch",children:[e.jsx("span",{className:"git-branch-icon",children:e.jsx(M,{name:"git-branch",size:12})}),s.branch]}),s.counts&&e.jsxs("div",{className:"git-changes-summary",children:[(s.counts.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[s.counts.conflict,"C"]}),s.counts.modified>0&&e.jsxs("span",{className:"git-count modified",children:[s.counts.modified,"M"]}),s.counts.added>0&&e.jsxs("span",{className:"git-count added",children:[s.counts.added,"A"]}),s.counts.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[s.counts.deleted,"D"]}),s.counts.untracked>0&&e.jsxs("span",{className:"git-count untracked",children:[s.counts.untracked,"?"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${k==="flat"?"active":""}`,onClick:()=>g("flat"),title:y("terminal:fileExplorer.flatList"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"2",y:"3",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"7",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"11",width:"12",height:"1.5",rx:"0.5"})]})}),e.jsx("button",{className:`git-view-toggle-btn ${k==="tree"?"active":""}`,onClick:()=>g("tree"),title:y("terminal:fileExplorer.directoryTree"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"5.5",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"9",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"7",y:"12.5",width:"7",height:"1.5",rx:"0.5"})]})})]}),e.jsx("button",{className:"git-refresh-btn",onClick:r,title:y("common:buttons.refresh"),children:e.jsx(M,{name:"refresh",size:12})})]}),p&&e.jsxs("div",{className:"git-merge-banner",children:[e.jsx("span",{className:"git-merge-banner-icon",children:"⚠"}),e.jsx("span",{className:"git-merge-banner-text",children:y("terminal:fileExplorer.mergeInProgress",{branch:b?` (${b})`:""})}),e.jsxs("div",{className:"git-merge-actions",children:[e.jsx("button",{className:"git-merge-continue-btn",onClick:f,disabled:vt,title:y(vt?"terminal:fileExplorer.resolveAllConflictsFirst":"terminal:fileExplorer.continueMerge"),children:y("terminal:fileExplorer.continue")}),e.jsx("button",{className:"git-merge-abort-btn",onClick:v,title:y("terminal:fileExplorer.abortMerge"),children:y("terminal:fileExplorer.abort")})]})]}),e.jsxs("div",{className:"git-changes-list",children:[e.jsx(ts,{groupLabel:y("terminal:fileExplorer.gitGroups.conflicts"),groupIcon:"C",groupColor:"#ff5555",files:we,treeNodes:Ge,viewMode:k,selectedPath:c,expandedDirs:j,onToggleDir:se,onFileSelect:Re,checkedFiles:Y,onToggleCheck:ye,onContextMenu:X,onDirContextMenu:te,onDiscardFile:ve,onDiscardAll:jt}),e.jsx(ts,{groupLabel:y("terminal:fileExplorer.gitGroups.changes"),groupIcon:"~",groupColor:"#c89a5a",files:He,treeNodes:Ot,viewMode:k,selectedPath:c,expandedDirs:j,onToggleDir:se,onFileSelect:Re,checkedFiles:Y,onToggleCheck:ye,onContextMenu:X,onDirContextMenu:te,onDiscardFile:ve,onDiscardAll:ot}),e.jsx(ts,{groupLabel:y("terminal:fileExplorer.gitGroups.unversioned"),groupIcon:"?",groupColor:"#6ab8c8",files:ze,treeNodes:yt,viewMode:k,selectedPath:c,expandedDirs:j,onToggleDir:se,onFileSelect:Re,onStageFile:ke,onStageAll:We,stagingPaths:h,checkedFiles:Y,onToggleCheck:ye,onContextMenu:X,onDirContextMenu:te,onDiscardFile:ve,onDiscardAll:bt})]}),e.jsxs("div",{className:"git-commit-panel",children:[e.jsxs("div",{className:"git-commit-options",children:[e.jsxs("label",{className:"git-commit-amend-label",children:[e.jsx("input",{type:"checkbox",className:"git-commit-amend-checkbox",checked:G,onChange:wt}),y("terminal:fileExplorer.amend")]}),e.jsx("span",{className:"git-commit-file-count",children:y("terminal:fileExplorer.fileCount",{count:Y.size})}),e.jsx("button",{className:"git-commit-select-toggle",onClick:ue,title:Y.size===s.files.length?y("terminal:fileExplorer.deselectAll"):y("terminal:fileExplorer.selectAll"),children:Y.size===s.files.length?y("terminal:fileExplorer.deselectAll"):y("terminal:fileExplorer.selectAll")})]}),e.jsx("textarea",{ref:je,className:"git-commit-message",placeholder:y("terminal:fileExplorer.commitMessagePlaceholder"),value:T,onChange:E=>A(E.target.value),onKeyDown:E=>{(E.metaKey||E.ctrlKey)&&E.key==="Enter"&&(E.preventDefault(),xe(!1)),(E.metaKey||E.ctrlKey)&&E.shiftKey&&E.key==="Enter"&&(E.preventDefault(),xe(!0)),E.stopPropagation()},rows:3,disabled:F}),ne&&e.jsx("div",{className:`git-commit-status ${ne.type}`,children:ne.text}),e.jsxs("div",{className:"git-commit-actions",children:[e.jsx("button",{className:"git-commit-btn",onClick:()=>xe(!1),disabled:!T.trim()||Y.size===0||F,title:y("terminal:fileExplorer.commitCtrlEnter"),children:y(F?"terminal:fileExplorer.committing":"terminal:fileExplorer.commitAction")}),e.jsx("button",{className:"git-commit-push-btn",onClick:()=>xe(!0),disabled:!T.trim()||Y.size===0||F,title:y("terminal:fileExplorer.commitAndPushCtrlShiftEnter"),children:F?"...":y("terminal:fileExplorer.commitAndPush")})]})]}),Z&&e.jsx(it,{isOpen:Z.isOpen,position:Z.position,worldPosition:{x:0,z:0},actions:S,onClose:()=>P(null)}),U&&e.jsx(it,{isOpen:U.isOpen,position:U.position,worldPosition:{x:0,z:0},actions:pe,onClose:()=>I(null)}),ie&&e.jsx("div",{className:"git-discard-confirm-overlay",onClick:()=>ee(null),children:e.jsxs("div",{className:"git-discard-confirm",onClick:E=>E.stopPropagation(),children:[e.jsx("p",{children:ie.files.some(E=>E.status==="untracked"||E.status==="added")?e.jsxs(e.Fragment,{children:["Delete ",e.jsx("strong",{children:ie.label}),"?"]}):e.jsxs(e.Fragment,{children:["Discard changes to ",e.jsx("strong",{children:ie.label}),"?"]})}),e.jsx("p",{className:"git-discard-confirm-hint",children:"This cannot be undone."}),e.jsxs("div",{className:"git-discard-confirm-actions",children:[e.jsx("button",{className:"git-discard-confirm-cancel",onClick:()=>ee(null),children:"Cancel"}),e.jsx("button",{className:"git-discard-confirm-btn",onClick:m,children:ie.files.some(E=>E.status==="untracked"||E.status==="added")?"Delete":"Discard"})]})]})})]})}const ln=t.memo(ir,(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));ln.displayName="GitChanges";const lr=t.memo(function({tab:n,isActive:l,onSelect:c,onClose:r,onContextMenu:i}){const{t:h}=oe(["terminal"]),o={name:n.filename,path:n.path,isDirectory:!1,extension:n.extension},u=t.useCallback(()=>{c(n.path)},[c,n.path]),p=t.useCallback(v=>{v.button===1&&(v.preventDefault(),v.stopPropagation(),r(n.path))},[r,n.path]),b=t.useCallback(v=>{v.preventDefault(),v.stopPropagation(),r(n.path)},[r,n.path]),f=t.useCallback(v=>{v.preventDefault(),v.stopPropagation(),i(v,n)},[i,n]);return e.jsxs("div",{className:`file-tab ${l?"active":""}`,onClick:u,onMouseDown:p,onContextMenu:f,title:n.path,children:[e.jsx("img",{className:"file-tab-icon",src:ns(o),alt:"file"}),e.jsx("span",{className:"file-tab-name",children:n.filename}),e.jsx("button",{className:"file-tab-close",onClick:b,title:h("terminal:fileExplorer.closeMiddleClick"),children:"×"})]})});function or(s){return typeof s.path=="string"&&s.path.startsWith("/")}function cr({tabs:s,activeTabPath:n,onSelectTab:l,onCloseTab:c,onCloseAllTabs:r,onShowGitHistory:i}){const{t:h}=oe(["terminal"]),[o,u]=t.useState(null),p=t.useCallback((v,N)=>{u({isOpen:!0,position:{x:v.clientX,y:v.clientY},tab:N})},[]),b=t.useCallback(()=>u(null),[]),f=t.useMemo(()=>{if(!o)return[];const v=o.tab,N=!!i&&or(v),R=[{id:"git-history",label:h("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),disabled:!N,onClick:()=>{N&&i(v.path)}}];return r&&R.push({id:"divider-close-all",label:"",divider:!0,onClick:()=>{}},{id:"close-all-tabs",label:h("terminal:fileExplorer.closeAllTabs")??"Close all tabs",icon:e.jsx(M,{name:"cross",size:14}),danger:!0,onClick:()=>r()}),R},[o,i,r,h]);return s.length===0?null:e.jsxs("div",{className:"file-tabs-bar",children:[e.jsx("div",{className:"file-tabs-container",children:s.map(v=>e.jsx(lr,{tab:v,isActive:n===v.path,onSelect:l,onClose:c,onContextMenu:p},v.path))}),o&&e.jsx(it,{isOpen:o.isOpen,position:o.position,worldPosition:{x:0,z:0},actions:f,onClose:b})]})}const on=t.memo(cr,(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});on.displayName="FileTabs";const dr=t.memo(function({currentFolder:n,gitStatus:l,onBranchChanged:c,onMerge:r,onCompare:i,onPullConflicts:h}){const{t:o}=oe(["terminal","common"]),[u,p]=t.useState(!1),[b,f]=t.useState(""),[v,N]=t.useState(!1),[R,y]=t.useState(""),[k,g]=t.useState(!1),[j,w]=t.useState(null),[T,A]=t.useState(null),O=t.useRef(null),C=t.useRef(null),G=t.useRef(null),{branches:ae,loading:Y,operationInProgress:D,loadBranches:F,checkoutBranch:K,createBranch:ne,pullFromRemote:re,pushToRemote:je}=as();t.useEffect(()=>{u&&n&&(F(n),setTimeout(()=>{var S;return(S=C.current)==null?void 0:S.focus()},50)),u||(f(""),N(!1),y(""),w(null))},[u,n,F]),t.useEffect(()=>{if(j){const S=j.type==="error"?8e3:3e3,te=setTimeout(()=>w(null),S);return()=>clearTimeout(te)}},[j]),t.useEffect(()=>{v&&setTimeout(()=>{var S;return(S=G.current)==null?void 0:S.focus()},50)},[v]),t.useEffect(()=>{if(!u)return;const S=Q=>{const de=Q.target;!de.closest(".branch-widget-selector")&&!de.closest(".branch-widget-dropdown")&&p(!1)},te=Q=>{Q.key==="Escape"&&(Q.preventDefault(),Q.stopPropagation(),p(!1))};return document.addEventListener("click",S),document.addEventListener("keydown",te,!0),()=>{document.removeEventListener("click",S),document.removeEventListener("keydown",te,!0)}},[u]);const B=t.useCallback(async S=>{if(!n||D||S.isCurrent)return;const te=await K(n,S.name);te.success?(w({type:"success",text:o("terminal:fileExplorer.switchedToBranch",{branch:te.branch||S.name})}),c(),F(n)):w({type:"error",text:te.error||o("terminal:fileExplorer.checkoutFailed")})},[n,D,K,c,F]),Z=t.useCallback(async()=>{if(!n||!R.trim()||D)return;const S=await ne(n,R.trim());S.success?(w({type:"success",text:o("terminal:fileExplorer.createdBranch",{branch:S.branch})}),N(!1),y(""),c(),F(n)):w({type:"error",text:S.error||o("terminal:fileExplorer.createBranchFailed")})},[n,R,D,ne,c,F]),P=t.useCallback(async()=>{if(!n||D)return;const S=await re(n);S.success?(S.stashConflicts&&S.stashConflicts.length>0?(w({type:"error",text:`Pull succeeded but stash pop had conflicts: ${S.stashConflicts.length} file(s). Resolve manually.`}),h==null||h(S.stashConflicts),p(!1)):S.stashed?w({type:"success",text:"Pull complete. Local changes were auto-stashed and restored."}):w({type:"success",text:o("terminal:fileExplorer.pullComplete")}),c(),F(n)):S.conflicts&&S.conflicts.length>0?(w({type:"error",text:`Pull conflicts: ${S.conflicts.length} file(s)`}),h==null||h(S.conflicts),p(!1)):w({type:"error",text:S.error||o("terminal:fileExplorer.pullFailed")})},[n,D,re,c,F,h]),U=t.useCallback(async()=>{if(!n||D)return;const S=await je(n);S.success?w({type:"success",text:o("terminal:fileExplorer.pushComplete")}):w({type:"error",text:S.error||o("terminal:fileExplorer.pushFailed")})},[n,D,je]),[I,ie]=t.useState(!1),ee=t.useCallback(async()=>{if(!(!n||D||I)){ie(!0);try{const S=await W(V("/api/files/git-fetch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(S.ok)w({type:"success",text:"Fetch complete"}),c(),F(n);else{const te=await S.json().catch(()=>({error:"Fetch failed"}));w({type:"error",text:te.error||"Fetch failed"})}}catch{w({type:"error",text:"Fetch failed"})}finally{ie(!1)}}},[n,D,I,c,F]),ve=(l==null?void 0:l.branch)||"unknown",m=!!D,X=t.useCallback((S,te)=>{te.isCurrent||(S.preventDefault(),S.stopPropagation(),A({isOpen:!0,position:{x:S.clientX,y:S.clientY},branch:te.name}))},[]),le=t.useMemo(()=>{if(!T)return[];const S=!!D||(l==null?void 0:l.mergeInProgress);return[{id:"compare",label:o("terminal:fileExplorer.showDiffWith",{branch:T.branch}),icon:e.jsx(M,{name:"arrows-horizontal",size:14}),disabled:!!D,onClick:()=>{i==null||i(T.branch),p(!1)}},{id:"merge",label:o("terminal:fileExplorer.mergeInto",{source:T.branch,target:ve}),icon:"⤵",disabled:!!S,onClick:()=>{r&&r(T.branch),p(!1)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"checkout",label:o("terminal:fileExplorer.checkoutBranch",{branch:T.branch}),icon:e.jsx(M,{name:"git-branch",size:14}),disabled:!!D,onClick:()=>{const te=ae.find(Q=>Q.name===T.branch);te&&B(te)}}]},[T,D,l==null?void 0:l.mergeInProgress,ve,r,i,ae,B]),z=t.useMemo(()=>{const S=ae.filter(Q=>!Q.isRemote);if(!b)return S;const te=b.toLowerCase();return S.filter(Q=>Q.name.toLowerCase().includes(te))},[ae,b]),$=t.useMemo(()=>{const S=ae.filter(Q=>Q.isRemote);if(!b)return S;const te=b.toLowerCase();return S.filter(Q=>Q.name.toLowerCase().includes(te))},[ae,b]);return e.jsxs("div",{className:"branch-widget",style:{position:"relative"},children:[e.jsxs("div",{className:"branch-widget-selector",onClick:S=>{S.stopPropagation(),p(!u)},title:`Branch: ${ve}`,children:[e.jsx("svg",{className:"branch-widget-icon",width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M5 3.25a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0Zm0 2.122a2.25 2.25 0 1 0-1 0v1.836A2.25 2.25 0 0 0 5.75 9.5h1.378a2.251 2.251 0 1 0 0-1H5.75a1.25 1.25 0 0 1-1.25-1.25V5.372Zm7.75 4.878a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3-8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"})}),e.jsx("span",{className:"branch-widget-name",children:ve}),e.jsx("span",{className:"branch-widget-arrow",children:"▼"})]}),u&&e.jsxs("div",{className:"branch-widget-dropdown",ref:O,children:[e.jsx("div",{className:"branch-widget-search",children:e.jsx("input",{ref:C,type:"text",className:"branch-widget-search-input",placeholder:o("terminal:fileExplorer.searchBranches"),value:b,onChange:S=>f(S.target.value),onKeyDown:S=>S.stopPropagation()})}),j&&e.jsx("div",{className:`branch-widget-status ${j.type}`,children:j.text}),e.jsx("div",{className:"branch-widget-section-header",children:o("terminal:fileExplorer.actions")}),e.jsxs("div",{className:"branch-widget-actions",children:[e.jsxs("div",{className:`branch-widget-action-item ${m||I?"disabled":""}`,onClick:ee,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 13l-3-3h2V6h2v4h2l-3 3zM8 3l3 3h-2v4H7V6H5l3-3z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:I?"Fetching...":"Fetch"})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:P,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 12l-4-4h2.5V3h3v5H12L8 12z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(D==="pull"?"terminal:fileExplorer.pulling":"terminal:fileExplorer.pull")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:U,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 4l4 4h-2.5v5h-3V8H4l4-4z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(D==="push"?"terminal:fileExplorer.pushing":"terminal:fileExplorer.push")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:()=>{m||N(!v)},children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 2v5H3v2h5v5h2V9h5V7H10V2H8z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o("terminal:fileExplorer.newBranch")})]})]}),v&&e.jsxs("div",{className:"branch-widget-new-branch",children:[e.jsx("input",{ref:G,type:"text",className:"branch-widget-new-branch-input",placeholder:o("terminal:fileExplorer.branchNamePlaceholder"),value:R,onChange:S=>y(S.target.value),onKeyDown:S=>{S.stopPropagation(),S.key==="Enter"&&Z(),S.key==="Escape"&&(N(!1),y(""))}}),e.jsx("button",{className:"branch-widget-new-branch-confirm",onClick:Z,disabled:!R.trim()||m,children:D==="create"?"...":o("common:buttons.create")})]}),e.jsxs("div",{className:"branch-widget-section-header",children:[o("terminal:fileExplorer.localBranches"),Y&&e.jsxs("span",{className:"branch-widget-loading-hint",children:[" ",o("terminal:fileExplorer.loading")]})]}),e.jsxs("div",{className:"branch-widget-branch-list",children:[z.length===0&&!Y&&e.jsx("div",{className:"branch-widget-empty",children:o("terminal:fileExplorer.noBranchesFound")}),z.map(S=>e.jsxs("div",{className:`branch-widget-branch-item ${S.isCurrent?"current":""} ${m?"disabled":""}`,onClick:()=>B(S),onContextMenu:te=>X(te,S),title:S.lastMessage||S.name,children:[e.jsxs("span",{className:"branch-widget-branch-name",children:[S.isCurrent&&e.jsx("span",{className:"branch-widget-current-marker",children:"*"}),S.name]}),S.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:S.lastCommit})]},S.name))]}),$.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"branch-widget-section-header clickable",onClick:()=>g(!k),children:[e.jsx("span",{className:"branch-widget-section-toggle",children:k?"▾":"▸"}),o("terminal:fileExplorer.remoteBranches",{count:$.length})]}),k&&e.jsx("div",{className:"branch-widget-branch-list",children:$.map(S=>e.jsxs("div",{className:`branch-widget-branch-item remote ${m?"disabled":""}`,onClick:()=>B(S),onContextMenu:te=>X(te,S),title:S.lastMessage||S.name,children:[e.jsx("span",{className:"branch-widget-branch-name",children:S.name}),S.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:S.lastCommit})]},S.name))})]})]}),T&&e.jsx(it,{isOpen:T.isOpen,position:T.position,worldPosition:{x:0,z:0},actions:le,onClose:()=>A(null)})]})});function ur(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function It(s,n){if(!s)return"";const l=zs.languages[n];return l?zs.highlight(s,l,n):ur(s)}function hr(s){const n=[],l=s.split(`
|
|
9
9
|
`);let c=[],r=!1,i=[],h=[],o=!1;for(const u of l)u.startsWith("<<<<<<<")?(c.length>0&&(n.push({type:"unchanged",content:c.join(`
|
|
10
10
|
`)}),c=[]),r=!0,o=!1,i=[],h=[]):u.startsWith("=======")&&r?o=!0:u.startsWith(">>>>>>>")&&r?(n.push({type:"conflict",ours:i.join(`
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as a,H as yn,J as Yt,K as cn,L as dn,j as e,M as un,N as Nn,u as Vt,O as Sn,P as An,U as En,V as In,W as Mn,X as Tn,Y as Ln,Z as Pn,_ as Kt,S as A,$ as Zt,a0 as Ut,a1 as Jt,a2 as yt,a3 as ge,a4 as Rn,s as g,a5 as pn,m as mn,a6 as Dn,z as Qt,B as en,I as m,a7 as $n,q as zn,a8 as On,a9 as fn,aa as hn,ab as gn,ac as xn,ad as Bn,ae as Fn,af as Wn,ag as Hn,ah as Un,ai as Vn,aj as Xn,ak as Gn,al as qn,am as Yn,an as Kn,ao as Zn,ap as tn,C as Jn,aq as Qn,ar as nn,as as ea,at as ta,au as na,av as aa,aw as sa,ax as ia,ay as la,az as ra,aA as oa,aB as ca,aC as da,aD as ua,aE as pa,aF as ma,aG as fa,aH as Je,aI as ha,aJ as ga,aK as xa,aL as ba,aM as lt,aN as _a,aO as wa,aP as va,aQ as ja,aR as Ca,aS as an,aT as ka}from"./main-D5sqeuwB.js";import{g as ya}from"./area-logos-mcpQqUMZ.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Na(c){const r=a.useRef(c);r.current=c,a.useEffect(()=>{if(!yn())return;let p=null,h=!1;return Yt.addListener("backButton",()=>{r.current()==="exit"&&Yt.exitApp()}).then(k=>{h?k.remove():p=k}),()=>{h=!0,p&&(p.remove(),p=null)}},[])}async function Sa(c){const r=cn(),p=await fetch(`${dn()}/api/agents/${c}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!p.ok){const h=await p.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${p.status})`)}return p.json()}async function Aa(c){const r=cn();await fetch(`${dn()}/api/agents/${c}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const rt=new Map;function Ea({agentId:c}){const[r,p]=a.useState(null),[h,k]=a.useState(null);return a.useEffect(()=>{let T=!1;const S=rt.get(c);return S&&(clearTimeout(S),rt.delete(c)),p(null),k(null),Sa(c).then(y=>{T||p(y.url)}).catch(y=>{T||k(y instanceof Error?y.message:"Failed to start terminal")}),()=>{T=!0;const y=rt.get(c);y&&clearTimeout(y),rt.set(c,setTimeout(()=>{rt.delete(c),Aa(c)},2500))}},[c]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(un,{terminalUrl:r,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Ft=new Map,Ia=6e4;function sn(c){return Number.isFinite(c)?Math.abs(c)>=1e3?c.toLocaleString(void 0,{maximumFractionDigits:0}):c.toLocaleString(void 0,{maximumFractionDigits:2}):String(c)}function Ma(c,r){var k,T,S;const p=[];if(!c.rateLimits)return p;if(c.provider==="claude"){const y=c,Y=[{key:"fiveHour",label:r("terminal:usage.currentSession"),window:y.rateLimits.fiveHour},{key:"sevenDay",label:r("terminal:usage.currentWeekAll"),window:y.rateLimits.sevenDay},{key:"sevenDayOpus",label:r("terminal:usage.currentWeekOpus"),window:y.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:r("terminal:usage.currentWeekSonnet"),window:y.rateLimits.sevenDaySonnet}];for(const _ of Y)_.window&&p.push({..._,window:_.window});return p}const h=c;return(k=h.rateLimits)!=null&&k.weekly&&p.push({key:"weekly",label:r("terminal:usage.weeklyLimit"),window:h.rateLimits.weekly}),(T=h.rateLimits)!=null&&T.monthly&&p.push({key:"monthly",label:r("terminal:usage.monthlyLimit"),window:h.rateLimits.monthly}),(S=h.rateLimits)!=null&&S.onDemand&&p.push({key:"onDemand",label:r("terminal:usage.onDemandLimit"),window:h.rateLimits.onDemand}),p}function Ta({agentId:c,contextSummary:r}){const{t:p}=Vt(["terminal","common"]),[h,k]=a.useState(()=>{var H;return((H=Ft.get(c))==null?void 0:H.snapshot)??null}),[T,S]=a.useState(!1),[y,Y]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const H=Ft.get(c);if(H&&Date.now()-H.fetchedAt<Ia){k(H.snapshot);return}const re=++_.current;S(!0),Y(null),Sn(c).then(P=>{re===_.current&&(Ft.set(c,{snapshot:P,fetchedAt:Date.now()}),k(P),S(!1))}).catch(P=>{re===_.current&&(Y(P.message||"Failed to load plan limits"),S(!1))})},[c]);const W=h?Ma(h,p):[];return e.jsxs("div",{className:"plan-limits-tooltip",children:[r&&e.jsx("div",{className:"plan-limits-tooltip__context",children:r}),e.jsx("div",{className:"plan-limits-tooltip__title",children:p("terminal:usage.limits")}),T&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[p("common:status.loading"),"…"]}),!T&&y&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:p("terminal:usage.limitsError",{message:y})}),W.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:W.map(({key:H,label:re,window:P})=>{const Ee=Math.max(0,Math.min(100,P.utilization)),oe=En(Ee),ce=typeof P.used=="number"&&typeof P.limit=="number"&&Number.isFinite(P.used)&&Number.isFinite(P.limit);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:re}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:oe},children:p("terminal:usage.percentUsed",{percent:Math.round(Ee)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${Ee}%`,background:oe}})}),e.jsxs("div",{className:"plan-limits-tooltip__reset",children:[p("terminal:usage.resets",{time:An(P.resetsAt)}),ce&&e.jsx("span",{style:{marginLeft:8},children:p("terminal:usage.creditsUsed",{used:sn(P.used),limit:sn(P.limit)})})]})]},H)})}):h&&!T&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?p("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function La({agentId:c,disabled:r,contextSummary:p,children:h}){return e.jsx(Nn,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(Ta,{agentId:c,contextSummary:p}),children:h})}const Pa=a.memo(function({className:r=""}){const{t:p}=Vt(["common"]),[h,k]=In(),T=a.useRef(null),[S,y]=a.useState(null);a.useLayoutEffect(()=>{const _=T.current;if(!_)return;const W=_.querySelector(".view-mode-toggle__btn--active");W&&y({left:W.offsetLeft,width:W.offsetWidth})},[h]);const Y=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>k(_));return}k(_)}},[h,k]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:T,children:[S&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:S.left,width:S.width}}),Mn.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>Y(_),title:p(`common:viewMode.descriptions.${_}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[_==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),_==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),_==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),_==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:p(`common:viewMode.labels.${_}`)})]},_))]})}),Nt=3,St=280,ln=320,Wt=240,rn=64,Ra=["simple","chat","advanced"],Da={simple:"Simple",chat:"Chat",advanced:"Advanced"},$a={simple:"○",chat:"◐",advanced:"◉"},za={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},on="flat-clear-context",bn="tide:flat-embedded-panels";function _n(){try{const c=localStorage.getItem(bn),r=c?JSON.parse(c):{};return r&&typeof r=="object"?r:{}}catch{return{}}}function Ht(c,r){try{const p=_n();r?p[c]=r:delete p[c],localStorage.setItem(bn,JSON.stringify(p))}catch{}}function Oa(c){const r=c.split("/").filter(Boolean);return r.length===0?c:r.slice(-2).join("/")}function Ba(c){if(c.provider==="codex"){const T=c.codexModel||"gpt-5.6-luna",S=Ca[T];return{model:(S==null?void 0:S.label)||T}}if(c.provider==="opencode")return{model:c.opencodeModel||"opencode"};if(c.provider==="grok"){const T=c.grokModel||"grok-4.5",S=c.effort,y=S?an[S]:void 0;return{model:T,effort:y==null?void 0:y.label}}const r=c.model||"sonnet",p=ka[r],h=c.effort,k=h?an[h]:void 0;return{model:(p==null?void 0:p.label)||r,effort:k==null?void 0:k.label}}function Fa(c,r){if(r.type==="rectangle"&&r.width&&r.height){const p=r.width/2,h=r.height/2;return c.x>=r.center.x-p&&c.x<=r.center.x+p&&c.z>=r.center.z-h&&c.z<=r.center.z+h}if(r.type==="circle"&&r.radius){const p=c.x-r.center.x,h=c.z-r.center.z;return p*p+h*h<=r.radius*r.radius}return!1}const Wa=Qn.memo(function({agentId:r,terminalViewMode:p,onTerminalViewModeChange:h,inspectorOpen:k,onToggleInspector:T,onShowTaskBoard:S,onImageClick:y,onFileClick:Y,onBashClick:_,onViewMarkdown:W,onRequestClearSubordinates:H,keyboard:re,canNavigateBack:P,canNavigateForward:Ee,onNavigateBack:oe,onNavigateForward:ce,agentInfoOpen:$e,onToggleAgentInfo:ot,onHeaderContextMenu:xe,onBuildingContextMenu:be}){var st,_t;const f=nn(r),O=mn(),Ie=ea(),ze=a.useRef(null),We=a.useRef(null),{displayedAgentId:Me,fadingOut:At}=ta(r),ct=nn(Me),He=!!Ie.interactiveMode&&((f==null?void 0:f.provider)??"claude")==="claude"&&!!(f!=null&&f.sessionId),[de,Ue]=a.useState(!1);a.useEffect(()=>{Ue(!1)},[r]),a.useEffect(()=>{!He&&de&&Ue(!1)},[He,de]),a.useEffect(()=>{const n=We.current;if(!n)return;const o=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),oe()):d.button===4&&(d.preventDefault(),d.stopPropagation(),ce())},i=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return n.addEventListener("mouseup",o),n.addEventListener("mousedown",i),()=>{n.removeEventListener("mouseup",o),n.removeEventListener("mousedown",i)}},[oe,ce]),a.useEffect(()=>{const n=We.current;if(!n)return;let o=0,i=0,d=0;const z=250,le=600,R=80,De=1.5,Ze=D=>{let U=D instanceof HTMLElement?D:null;for(;U&&U!==n;){const vt=window.getComputedStyle(U).overflowX;if((vt==="auto"||vt==="scroll")&&U.scrollWidth>U.clientWidth)return!0;U=U.parentElement}return!1},wt=D=>{const U=Date.now();if(U<d){D.preventDefault();return}if(Math.abs(D.deltaX)<=Math.abs(D.deltaY)*De){o=0;return}if(Ze(D.target)){o=0;return}U-i>z&&(o=0),i=U,o+=D.deltaX,o<=-R?(o=0,d=U+le,D.preventDefault(),oe()):o>=R&&(o=0,d=U+le,D.preventDefault(),ce())};return n.addEventListener("wheel",wt,{passive:!1}),()=>n.removeEventListener("wheel",wt)},[oe,ce]);const Te=pn(),ue=a.useMemo(()=>{if(!f)return null;const n=new Set,o=[];for(const i of Te.values())i.archived||i.directories.length===0||i.assignedAgentIds.includes(r)&&(n.add(i.id),o.push(i));for(const i of Te.values())i.archived||i.directories.length===0||n.has(i.id)||Fa({x:f.position.x,z:f.position.z},i)&&(n.add(i.id),o.push(i));return o.length===0?null:o.flatMap(i=>i.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:i.id,areaName:i.name,dir:d})))},[f,r,Te]),{branches:_e,fetchRemote:we,fetchingDirs:dt}=na(ue),Ve=a.useMemo(()=>{var i;const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const d of O.values())d.type==="terminal"&&g.isPositionInArea(d.position,n)&&o.push({id:d.id,name:d.name,hasUrl:!!((i=d.terminalStatus)!=null&&i.url)});return o},[r,O]),ve=a.useMemo(()=>{var i;const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const d of O.values())d.type==="server"&&((i=d.pm2)!=null&&i.enabled)&&g.isPositionInArea(d.position,n)&&o.push({id:d.id,name:d.name});return o},[r,O]),pe=a.useMemo(()=>{const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const i of O.values())i.type==="database"&&i.database&&g.isPositionInArea(i.position,n)&&o.push({id:i.id,name:i.name});return o},[r,O]),Le=aa(),je=a.useMemo(()=>{const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const i of O.values())if(i.type==="tests"&&g.isPositionInArea(i.position,n)){const d=!!i.folderPath&&Le.some(z=>sa(z,i.folderPath));o.push({id:i.id,name:i.name,working:d})}return o},[r,O,Le]),K=a.useMemo(()=>{const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const i of O.values())i.type==="http"&&g.isPositionInArea(i.position,n)&&o.push({id:i.id,name:i.name});return o},[r,O]),[,Xe]=a.useReducer(n=>n+1,0),te=((st=ze.current)==null?void 0:st.search.searchMode)??!1,Pe=a.useCallback(()=>{var n;(n=ze.current)==null||n.search.toggleSearch(),Xe()},[]),ut=ia(),Qe=ut.isPending(on),[j,ne]=a.useState(null),Z=j?O.get(j.buildingId):null,[pt,Q]=a.useState(""),[et,Ge]=a.useState(()=>la()),B=a.useMemo(()=>{var n;return((n=g.getAreaForAgent(r))==null?void 0:n.id)??null},[r,O]),Ce=a.useCallback((n,o)=>{Q(""),ne(i=>{const d=(i==null?void 0:i.buildingId)===o?null:{type:n,buildingId:o};return B&&Ht(B,d),d})},[B]),ke=a.useCallback(()=>{Q(""),ne(null),B&&Ht(B,null)},[B]);a.useEffect(()=>{if((j==null?void 0:j.type)!=="pm2-logs")return;const n=j.buildingId;return g.startLogStreaming(n,200),()=>g.stopLogStreaming(n)},[j]);const{height:Et,onResizeStart:It}=ra(),{sidePanelWidth:Mt,handleSidePanelResizeStart:Tt}=oa(),[Oe,mt]=a.useState(()=>Ut(A.GIT_PANEL_OPEN,!1)),[ye,w]=a.useState(()=>Ut(A.BUILDINGS_PANEL_OPEN,!1)),[Be,ft]=a.useState(!1),Ne=a.useCallback(()=>{ft(n=>{const o=!n;return o&&ca.setEnabled(!0),o})},[]),ae=a.useCallback(()=>ft(!1),[]),qe=a.useCallback(()=>{mt(n=>{const o=!n;return ge(A.GIT_PANEL_OPEN,o),o})},[]),ht=a.useCallback(()=>{w(n=>{const o=!n;return ge(A.BUILDINGS_PANEL_OPEN,o),o})},[]),Lt=a.useCallback(()=>{mt(!1),ge(A.GIT_PANEL_OPEN,!1)},[]),Pt=a.useCallback(()=>{w(!1),ge(A.BUILDINGS_PANEL_OPEN,!1)},[]),Rt=da(),Re=a.useMemo(()=>({terminal:Ve,"pm2-logs":ve,database:pe,tests:je,http:K}),[Ve,ve,pe,je,K]);a.useEffect(()=>{if(!j)return;Re[j.type].some(o=>o.id===j.buildingId)||(Q(""),ne(null))},[j,Re]);const Ye=a.useRef(void 0);a.useEffect(()=>{var o;if(Ye.current===B)return;Ye.current=B;const n=B?_n()[B]:void 0;Q(""),n&&((o=Re[n.type])!=null&&o.some(i=>i.id===n.buildingId))?ne(n):ne(null)},[B,Re]),a.useEffect(()=>{const n=o=>{var z;const i=o.detail;if(!(i!=null&&i.buildingId)||!(i!=null&&i.type)||!((z=Re[i.type])!=null&&z.some(le=>le.id===i.buildingId)))return;i.handled=!0,Q("");const d={type:i.type,buildingId:i.buildingId};ne(d),B&&Ht(B,d)};return window.addEventListener("tide:dock-building-flat",n),()=>window.removeEventListener("tide:dock-building-flat",n)},[Re,B]);const[se,me]=a.useState(!1),fe=a.useRef(null);if(a.useEffect(()=>{if(!se)return;const n=o=>{fe.current&&!fe.current.contains(o.target)&&me(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[se]),!f)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const Se=f.contextStats,J=!!Se,Ae=Se?Se.totalTokens:f.contextUsed||0,gt=Se?Se.contextWindow:f.contextLimit||(f.provider==="grok"?5e5:2e5),Dt=Se?Se.usedPercent:Math.round(Ae/gt*100),he=Math.max(0,Math.min(100,Dt)),tt=Math.round(he*10)/10,$t=Math.round((100-he)*10)/10,xt=he>=80?"#ff4a4a":he>=60?"#ff9e4a":he>=40?"#ffd700":"#4aff9e",nt=(Ae/1e3).toFixed(1),ee=(gt/1e3).toFixed(1),ie=f.cwd,at=ie?Oa(ie):null,Ke=((_t=f.subordinateIds)==null?void 0:_t.length)||0,bt=Ke>0;return e.jsxs("div",{ref:We,className:`flat-terminal-wrapper ${Oe||ye||Be?"flat-terminal-wrapper--with-side-panel":""} ${At?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${Mt}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${$e?"flat-terminal-wrapper__header-main--active":""}`,onClick:ot,onContextMenu:n=>{n.preventDefault(),n.stopPropagation(),xe({x:n.clientX,y:n.clientY})},title:$e?"Hide agent info":"Show agent info","aria-pressed":$e,children:[e.jsx(fn,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:xn(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:gn(f.provider,"/"),alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:hn(f.provider)}),(()=>{const{model:n,effort:o}=Ba(f);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:o?`Model: ${n} · Effort: ${o}`:`Model: ${n}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:n}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:o})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[Ra.map(n=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!de&&p===n?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ue(!1),h(n)},title:za[n],"aria-pressed":!de&&p===n,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:$a[n]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Da[n]})]},n)),He&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${de?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Ue(n=>!n),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":de,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(m,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:oe,disabled:!P,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(m,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:ce,disabled:!Ee,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(m,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${te?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Pe,title:te?"Close search":"Search messages","aria-pressed":te,children:e.jsx(m,{name:te?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Qe?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>ut.handleClick(on,()=>{var n;g.clearContext(r),(n=ze.current)==null||n.historyLoader.clearHistory()}),title:Qe?"Click again to confirm clear context":"Clear context",children:e.jsx(m,{name:Qe?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Oe?"flat-terminal-wrapper__action-btn--active":""}`,onClick:qe,title:Oe?"Hide git panel":"Show git changes","aria-pressed":Oe,children:e.jsx(m,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ye?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ht,title:ye?"Hide buildings panel":"Show area buildings","aria-pressed":ye,children:e.jsx(m,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:fe,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${se?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>me(n=>!n),title:"More actions","aria-expanded":se,children:"⋮"}),se&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${Be?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Ne(),me(!1)},title:Be?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(m,{name:"bug",size:14}),e.jsx("span",{children:Be?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{g.collapseContext(r),me(!1)},disabled:f.status!=="idle",title:f.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(m,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),bt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{H(r,Ke),me(!1)},children:[e.jsx(m,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Ke," subordinate",Ke===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{g.killAgent(r),me(!1)},children:[e.jsx(m,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${k?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:T,title:k?"Hide inspector panel":"Show inspector panel","aria-label":k?"Hide inspector panel":"Show inspector panel","aria-pressed":k,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>g.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(m,{name:"cross",size:14})})]})]}),e.jsx(ua,{agent:f,onClick:S}),de&&He?e.jsx(Ea,{agentId:r}):Me&&ct?e.jsx(pa,{ref:ze,agentId:Me,agent:ct,viewMode:p,isOpen:!0,onImageClick:y,onFileClick:Y,onBashClick:_,onViewMarkdown:W,keyboard:re,hasModalOpen:!1},Me):null,j&&Z&&(()=>{var z,le;const n=j.type,o={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},i=n==="terminal"&&!((z=Z.terminalStatus)!=null&&z.url),d=!i;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:It,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded panel"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`${Z.name} panel`,style:{height:Et},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(m,{name:o[n],size:12}),e.jsx("span",{children:Z.name}),i&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsxs("span",{className:"flat-bottom-panel__header-actions",children:[n==="pm2-logs"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:"guake-bottom-terminal-filter",value:pt,onChange:R=>Q(R.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${Z.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:et===null?"unlimited":String(et),onChange:R=>{const De=R.target.value==="unlimited"?null:Number(R.target.value);Ge(De),fa(De)},"aria-label":`Max log retention for ${Z.name}`,children:ma.map(R=>e.jsx("option",{value:R===null?"unlimited":String(R),children:R===null?"Unlimited":`${R.toLocaleString()} lines`},R===null?"unlimited":R))}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>g.clearStreamingLogs(j.buildingId),title:"Clear logs",children:e.jsx(m,{name:"trash",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>g.sendBuildingCommand(j.buildingId,"restart"),title:"Restart",children:e.jsx(m,{name:"restart",size:12})})]}),d&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{ke(),Je(j.buildingId)},title:"Maximize — open as modal","aria-label":"Open as modal",children:e.jsx(m,{name:"fullscreen",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:ke,title:"Close panel","aria-label":"Close panel",children:e.jsx(m,{name:"cross",size:12})})]})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:n==="terminal"?(le=Z.terminalStatus)!=null&&le.url?e.jsx(un,{terminalUrl:Z.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."}):n==="pm2-logs"?e.jsx(ha,{buildingId:j.buildingId,filterText:pt,maxRetention:et}):n==="database"?e.jsx(ga,{building:Z}):n==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(xa,{building:Z,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(ba,{building:Z,autoFocusSearch:!1})})})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(m,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),ie&&at&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${ie}`,"aria-label":`Open ${ie} in file explorer`,role:"button",tabIndex:0,onClick:()=>g.openFileExplorer(ie),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),g.openFileExplorer(ie))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(m,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:at})]}),ue&&ue.map(({areaId:n,areaName:o,dir:i})=>{const d=_e.get(i),z=dt.has(i),le=i.split("/").filter(Boolean).pop()||i;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${o}: ${i}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>g.openFileExplorerForAreaFolder(n,i),children:[e.jsx(m,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:le}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(m,{name:"git-branch",size:10})," ",d.branch]}),d.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${d.ahead} ahead`,children:[e.jsx(m,{name:"arrow-up",size:9}),d.ahead]}),d.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${d.behind} behind`,children:[e.jsx(m,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${z?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:R=>{R.stopPropagation(),we(i)},children:e.jsx(m,{name:z?"hourglass":"download",size:12})})]})]},`${n}:${i}`)}),e.jsx(La,{agentId:r,disabled:((f==null?void 0:f.provider)??"claude")!=="claude"&&((f==null?void 0:f.provider)??"claude")!=="grok",contextSummary:J?`Context: ${nt}k / ${ee}k tokens (${tt}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>g.setContextModalAgentId(r),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),g.setContextModalAgentId(r))},title:((f==null?void 0:f.provider)??"claude")!=="claude"&&((f==null?void 0:f.provider)??"claude")!=="grok"?J?`Context usage: ${nt}k / ${ee}k tokens (${tt}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(m,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${he}%`,backgroundColor:xt}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:xt},children:[nt,"k/",ee,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",$t,"% free)"]}),!J&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(m,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),Ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Ve.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""} ${n.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${o?"Hide":"Show"} terminal: ${n.name}${n.hasUrl?"":" (starting...)"}`,onClick:()=>{if(o){ke();return}if(n.hasUrl&<(n.id)==="modal"){Je(n.id);return}n.hasUrl||g.sendBuildingCommand(n.id,"start"),Ce("terminal",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(m,{name:"terminal",size:14})},n.id)})}),ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:ve.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} logs: ${n.name}`,onClick:()=>{o?ke():lt(n.id)==="modal"?Je(n.id):Ce("pm2-logs",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(m,{name:"scroll",size:14})},n.id)})}),pe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:pe.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} database: ${n.name}`,onClick:()=>{o?ke():lt(n.id)==="modal"?Je(n.id):Ce("database",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(m,{name:"hard-drives",size:14})},n.id)})}),je.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:je.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""} ${n.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:n.working?`Running tests: ${n.name}`:`${o?"Hide":"Show"} tests: ${n.name}`,onClick:()=>{o?ke():lt(n.id)==="modal"?Je(n.id):Ce("tests",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(m,{name:"flask",size:14})},n.id)})}),K.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:K.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} HTTP requests: ${n.name}`,onClick:()=>{o?ke():lt(n.id)==="modal"?Je(n.id):Ce("http",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(m,{name:"globe",size:14})},n.id)})}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(_a,{})})]}),Oe&&e.jsx(wa,{agentId:r,agents:Rt,onClose:Lt,branchInfoMap:_e,fetchRemote:we,fetchingDirs:dt,onResizeStart:n=>Tt(n,"right")}),ye&&e.jsx(va,{agentId:r,onClose:Pt}),Be&&e.jsx(ja,{agentId:r,onClose:ae})]})}),Ha={groups:[],gridCols:1,gridRows:1,positions:new Map};function qa({onAgentClick:c,onBuildingClick:r,onBuildingDoubleClick:p,onBuildingPopup:h,onAreaContextMenu:k,onOpenSpawnModal:T,onOpenBossSpawnModal:S,onOpenAreaModal:y}){const{t:Y}=Vt(["common"]),_=Tn(),W=Ln(),[H,re]=a.useState(null),[P,Ee]=a.useState(null),[oe,ce]=a.useState(null);Pn("flatview-image-modal",H!==null,()=>re(null));const[$e,ot]=a.useState(null),[xe,be]=a.useState(null),[f,O]=a.useState(null),[Ie,ze]=a.useState(null),[We,Me]=a.useState(!1),At=a.useCallback(()=>{Me(t=>!t)},[]),ct=a.useCallback(()=>{Me(!1)},[]),[He,de]=a.useState(()=>{const t=Kt(A.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ue=a.useCallback(t=>{de(t),Zt(A.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=s=>{if(s.key!==A.VIEW_MODE)return;const l=s.newValue;(l==="simple"||l==="chat"||l==="advanced")&&de(l)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Te,ue]=a.useState(()=>Ut(A.FLAT_INSPECTOR_OPEN,!1)),[_e,we]=a.useState(!1),dt=a.useCallback(()=>we(t=>!t),[]),Ve=a.useCallback(()=>we(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:_e}}))},[_e]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Te}}))},[Te]),a.useEffect(()=>{const t=()=>we(C=>!C),s=()=>{ue(C=>{const E=!C;return ge(A.FLAT_INSPECTOR_OPEN,E),E})},l=()=>{we(!1),ue(!1),ge(A.FLAT_INSPECTOR_OPEN,!1)},x=()=>we(!1),b=()=>{ue(!1),ge(A.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",s),window.addEventListener("tide-close-flat-side-views",l),window.addEventListener("tide-close-flat-agents-drawer-only",x),window.addEventListener("tide-close-flat-inspector-only",b),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",s),window.removeEventListener("tide-close-flat-side-views",l),window.removeEventListener("tide-close-flat-agents-drawer-only",x),window.removeEventListener("tide-close-flat-inspector-only",b)}},[]);const ve=a.useRef(null),pe=a.useRef(null),[Le,je]=a.useState(()=>{const t=Jt(A.FLAT_MIDDLE_WIDTH,0);return t>=St?t:null}),[K,Xe]=a.useState(()=>{const t=Jt(A.FLAT_INSPECTOR_WIDTH,0);return t>=Wt?t:null}),te=a.useCallback(t=>{if(typeof window>"u")return t;const s=K!==null?Nt+K:0,l=window.innerWidth-rn-Nt-ln-s;return Math.max(St,Math.min(Math.max(l,St),t))},[K]),Pe=a.useCallback(t=>{var b;if(typeof window>"u")return t;const s=(b=ve.current)==null?void 0:b.querySelector(".flat-middle"),l=(s==null?void 0:s.getBoundingClientRect().width)??St,x=window.innerWidth-rn-l-Nt-ln-Nt;return Math.max(Wt,Math.min(Math.max(x,Wt),t))},[]);a.useEffect(()=>{if(Le===null&&K===null)return;const t=()=>{je(s=>{if(s===null)return s;const l=te(s);return l===s?s:l}),Xe(s=>{if(s===null)return s;const l=Pe(s);return l===s?s:l})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[Le,K,te,Pe]);const ut=a.useCallback(t=>{var l;if(t.button!==0)return;const s=(l=ve.current)==null?void 0:l.querySelector(".flat-middle");s&&(t.currentTarget.setPointerCapture(t.pointerId),pe.current={kind:"middle",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Qe=a.useCallback(t=>{var l;if(t.button!==0)return;const s=(l=ve.current)==null?void 0:l.querySelector(".flat-inspector");s&&(t.currentTarget.setPointerCapture(t.pointerId),pe.current={kind:"inspector",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),j=a.useCallback(t=>{const s=pe.current;if(!s||t.pointerId!==s.pointerId)return;const l=t.clientX-s.startX;s.kind==="middle"?je(te(s.startWidth+l)):Xe(Pe(s.startWidth-l))},[te,Pe]),ne=a.useCallback(t=>{const s=pe.current;if(!s||t.pointerId!==s.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(pe.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-s.startX)>2))return;const x=t.clientX-s.startX;if(s.kind==="middle"){const b=te(s.startWidth+x);je(b),yt(A.FLAT_MIDDLE_WIDTH,b)}else{const b=Pe(s.startWidth-x);Xe(b),yt(A.FLAT_INSPECTOR_WIDTH,b)}},[te,Pe]),Z=a.useCallback(()=>{je(null),yt(A.FLAT_MIDDLE_WIDTH,0)},[]),pt=a.useCallback(()=>{Xe(null),yt(A.FLAT_INSPECTOR_WIDTH,0)},[]),[Q,et]=a.useState(()=>Kt(A.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ge=a.useCallback(t=>{et(t),Zt(A.FLAT_INSPECTOR_VIEW,t)},[]),B=a.useCallback(()=>{ue(t=>{const s=!t;return ge(A.FLAT_INSPECTOR_OPEN,s),s})},[]),Ce=a.useCallback(()=>{ue(!1),ge(A.FLAT_INSPECTOR_OPEN,!1)},[]),ke=a.useCallback(()=>{Ge("tracking"),ue(!0),ge(A.FLAT_INSPECTOR_OPEN,!0)},[Ge]),Et=Rn(),It=a.useCallback((t,s)=>{re({url:t,name:s})},[]),Mt=a.useCallback((t,s)=>{Ee({command:t,output:s,isLive:!1})},[]),Tt=a.useCallback((t,s)=>{var b;const l=W.size>0?Array.from(W)[0]:null,x=l?(b=g.getState().agents.get(l))==null?void 0:b.cwd:void 0;g.setFileViewerPath(t,s,x)},[W]),Oe=a.useCallback(t=>{ce(t)},[]),mt=a.useCallback((t,s)=>{ot({agentId:t,count:s})},[]),ye=a.useCallback(t=>{p?p(t):r(t)},[r,p]),w=a.useMemo(()=>W.size>0?Array.from(W)[0]:null,[W]),Be=a.useCallback(t=>{w&&be({agentId:w,position:t})},[w]),ft=a.useCallback((t,s)=>{O({buildingId:t,position:s})},[]);a.useEffect(()=>{Me(!1)},[w]);const Ne=a.useRef([]),ae=a.useRef(-1),qe=a.useRef(!1),ht=a.useRef(null),[Lt,Pt]=a.useState(!1),[Rt,Re]=a.useState(!1),Ye=a.useRef(!1),se=a.useRef(null),me=a.useRef(!1),fe=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),Se=a.useMemo(()=>{const t=new Map(_.map(l=>[l.id,l])),s=new Map;for(const l of _)if((l.isBoss||l.class==="boss")&&l.subordinateIds&&l.subordinateIds.length>0){const x=l.subordinateIds.map(b=>t.get(b)).filter(b=>b!==void 0);x.length>0&&s.set(l.id,x)}return s},[_]),J=a.useCallback(()=>{const t=Ne.current,s=ae.current;Pt(s>0),Re(s>=0&&s<t.length-1)},[]),Ae=a.useCallback(t=>{const s=Ne.current;if(s.length===0)return;let l=ae.current+t;for(;l>=0&&l<s.length;){const x=s[l];if(fe.has(x)){qe.current=!0,ae.current=l,J(),g.selectAgent(x);return}l+=t}},[fe,J]),gt=a.useCallback(()=>Ae(-1),[Ae]),Dt=a.useCallback(()=>Ae(1),[Ae]);Na(a.useCallback(()=>{const t=Ne.current,s=ae.current;return t.length>0&&s>0?(Ae(-1),"handled"):"exit"},[Ae]));const he=a.useCallback((t,s)=>{if(typeof window>"u")return;const l=window.history.state,b={...typeof l=="object"&&l!==null?l:{},__flatAgentNav:{agentId:t}};s==="replace"?window.history.replaceState(b,"",window.location.href):window.history.pushState(b,"",window.location.href)},[]);a.useEffect(()=>{if(!w){Ye.current=!1,se.current=null;return}if(!Ye.current){he(w,"replace"),Ye.current=!0,se.current=w;return}if(me.current){me.current=!1,se.current=w;return}se.current!==w&&(he(w,"push"),se.current=w)},[w,he]),a.useEffect(()=>{const t=s=>{var C,E;const l=(E=(C=s.state)==null?void 0:C.__flatAgentNav)==null?void 0:E.agentId;if(!l||typeof l!="string"||!fe.has(l)||l===w)return;me.current=!0,qe.current=!0;const x=Ne.current,b=x.lastIndexOf(l);b>=0?ae.current=b:(x.push(l),ae.current=x.length-1),J(),g.selectAgent(l)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[fe,w,J]),a.useEffect(()=>{if(!w){Ne.current=[],ae.current=-1,J();return}if(ht.current=w,qe.current){qe.current=!1,J();return}const t=Ne.current,s=ae.current;if(s>=0&&t[s]===w){J();return}const l=s<t.length-1?t.slice(0,s+1):t.slice();l.push(w),l.length>100&&l.shift(),Ne.current=l,ae.current=l.length-1,J()},[w,J]);const tt=a.useCallback(t=>{c(t),we(!1)},[c]),$t=w??"",xt=a.useCallback(()=>{},[]),nt=a.useCallback(t=>{tt(t)},[tt]),ee=Te,[ie,at]=a.useState(ee),[Ke,bt]=a.useState(ee);a.useEffect(()=>{if(ee){at(!0);return}bt(!1);const t=setTimeout(()=>at(!1),240);return()=>clearTimeout(t)},[ee]),a.useEffect(()=>{if(!ie||!ee)return;let t=0;const s=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>bt(!0))});return()=>{cancelAnimationFrame(s),cancelAnimationFrame(t)}},[ie,ee]);const st=a.useRef(null);a.useEffect(()=>{if(w)return;const t=s=>{if(s.key!==" "&&s.key!=="Backspace")return;const l=s.target;if(l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.isContentEditable)return;const x=ht.current;!x||!fe.has(x)||(s.preventDefault(),g.selectAgent(x))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[w,fe]);const[_t,n]=a.useState(new Set),o=a.useCallback(t=>{n(s=>{const l=new Set(s);return l.has(t)?l.delete(t):l.add(t),l})},[]),[i,d]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),s=l=>d(l.matches);return t.addEventListener("change",s),()=>t.removeEventListener("change",s)},[]);const[z,le]=a.useState(null),R=a.useCallback(t=>{le(s=>s===t?null:t)},[]),De=pn(),Ze=mn(),[wt]=Dn(),D=a.useMemo(()=>{if(w)return Ha;const t=new Map,s=[];for(const v of _){const M=g.getAreaForAgent(v.id);if(!Qt((M==null?void 0:M.id)??null))continue;if(!M||M.archived){s.push(v);continue}const L=t.get(M.id);L?L.push(v):t.set(M.id,[v])}const l=new Map,x=[];for(const v of Ze.values()){let M=!1;for(const L of De.values())if(!L.archived&&en(L.id)&&g.isPositionInArea(v.position,L)){const X=l.get(L.id);X?X.push(v):l.set(L.id,[v]),M=!0;break}!M&&Qt(null)&&x.push(v)}const b=[];for(const[,v]of De){if(v.archived||!en(v.id))continue;const M=t.get(v.id),L=l.get(v.id)??[];(M&&M.length>0||L.length>0)&&b.push({area:v,agents:M??[],buildings:L})}(s.length>0||x.length>0)&&b.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:s,buildings:x});const C=b.filter(v=>v.area.id!=="__unassigned__"),E=b.filter(v=>v.area.id==="__unassigned__");let u=1,I=1;const V=new Map;if(C.length>1){let v=1/0,M=-1/0,L=1/0,X=-1/0;for(const G of C)v=Math.min(v,G.area.center.x),M=Math.max(M,G.area.center.x),L=Math.min(L,G.area.center.z),X=Math.max(X,G.area.center.z);const jt=M-v||1,Ct=X-L||1;if(C.length<=4){u=C.length,I=1;const G=[...C].sort((q,zt)=>q.area.center.x-zt.area.center.x);for(let q=0;q<G.length;q++)V.set(G[q].area.id,{row:1,col:q+1})}else{const G=[...C].sort((N,F)=>N.area.center.x-F.area.center.x),q=[];for(let N=1;N<G.length;N++)q.push(G[N].area.center.x-G[N-1].area.center.x);const zt=q.reduce((N,F)=>N+F,0)/q.length||1;let Xt=1;for(const N of q)N>zt*1.3&&Xt++;u=Math.max(2,Math.min(Xt,C.length));const Ot=[...C].sort((N,F)=>N.area.center.z-F.area.center.z),kt=[];for(let N=1;N<Ot.length;N++)kt.push(Ot[N].area.center.z-Ot[N-1].area.center.z);const vn=kt.reduce((N,F)=>N+F,0)/kt.length||1;let Gt=1;for(const N of kt)N>vn*1.3&&Gt++;I=Math.max(2,Math.min(Gt,C.length)),u=Math.max(u,Math.ceil(C.length/I)),I=Math.max(I,Math.ceil(C.length/u));const jn=jt/u,Cn=Ct/I,Bt=new Set;for(const N of C){let F=Math.min(u-1,Math.max(0,Math.floor((N.area.center.x-v)/jn))),Fe=Math.min(I-1,Math.max(0,Math.floor((N.area.center.z-L)/Cn))),it=`${Fe},${F}`,qt=0;const kn=I*u;for(;Bt.has(it)&&qt<kn;)F++,F>=u&&(F=0,Fe=(Fe+1)%I),it=`${Fe},${F}`,qt++;Bt.has(it)&&(Fe=I,F=0,it=`${Fe},${F}`,I++),Bt.add(it),V.set(N.area.id,{row:Fe+1,col:F+1})}}}const $=v=>{v.sort((M,L)=>{var jt,Ct,G,q;const X=(((jt=M.position)==null?void 0:jt.z)??0)-(((Ct=L.position)==null?void 0:Ct.z)??0);return X!==0?X:(((G=M.position)==null?void 0:G.x)??0)-(((q=L.position)==null?void 0:q.x)??0)})};for(const v of C)$(v.agents);for(const v of E)$(v.agents);return{groups:[...C,...E],gridCols:u,gridRows:I,positions:V}},[_,De,Ze,wt,w]),U=a.useMemo(()=>{if(!xe)return[];const t=_.find(s=>s.id===xe.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(m,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(m,{name:"chat",size:14}),onClick:()=>c(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(m,{name:"clipboard",size:14}),onClick:()=>g.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(m,{name:"git-branch",size:14}),onClick:()=>g.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(m,{name:"trash",size:14}),danger:!0,onClick:()=>{ze({agentId:t.id,name:t.name})}}]:[]},[xe,_,c]),vt=a.useMemo(()=>{var C;if(!f)return[];const t=Ze.get(f.buildingId);if(!t)return[];const s=[],l=t.type==="server"||t.type==="docker"||t.type==="terminal",x=t.status==="running",b=t.type==="boss";if(s.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="http"?"Open Requests":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((C=t.pm2)!=null&&C.enabled)?"View PM2 Logs":"Open",icon:e.jsx(m,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="tests"?"flask":t.type==="http"?"globe":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>ye(t.id)}),l&&(x||s.push({id:"start",label:"Start",icon:e.jsx(m,{name:"play",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"start")}),x&&(s.push({id:"restart",label:"Restart",icon:e.jsx(m,{name:"refresh",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"restart")}),s.push({id:"stop",label:"Stop",icon:e.jsx(m,{name:"stop",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"stop")}))),b&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(s.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(m,{name:"launch",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)g.sendBuildingCommand(E,"start")}}),s.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(m,{name:"pause",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)g.sendBuildingCommand(E,"stop")}}),s.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(m,{name:"restart",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)g.sendBuildingCommand(E,"restart")}})),l&&s.push({id:"health-check",label:"Health Check",icon:e.jsx(m,{name:"health",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"healthCheck")}),s.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),s.push({id:"edit",label:"Edit Building",icon:e.jsx(m,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),s.push({id:"clone",label:"Clone Building",icon:e.jsx(m,{name:"copy",size:14}),onClick:()=>{g.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const E of t.urls)s.push({id:`url-${E.label}`,label:E.label,icon:e.jsx(m,{name:"link",size:14}),onClick:()=>window.open(E.url,"_blank","noopener,noreferrer")});return s.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),s.push({id:"delete",label:"Delete Building",icon:e.jsx(m,{name:"trash",size:14}),danger:!0,onClick:()=>g.deleteBuilding(t.id)}),s},[f,Ze,ye]),wn=a.useCallback(t=>{const s=new Set(D.groups.map(l=>l.area.id));s.delete(t),n(s),requestAnimationFrame(()=>{const l=st.current;if(!l)return;const x=l.querySelector(`[data-area-id="${t}"]`);if(!x)return;const b=l.getBoundingClientRect(),E=x.getBoundingClientRect().top-b.top+l.scrollTop-8;l.scrollTo({top:Math.max(0,E),behavior:"smooth"})})},[D]);return e.jsxs("div",{ref:ve,className:`flat-view ${ee?"flat-view--with-inspector":""} ${w?"flat-view--has-chat":""} ${_e?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(Le===null&&K===null)return;const t={};return Le!==null&&(t["--flat-middle-width"]=`${Le}px`),K!==null&&(t["--flat-inspector-width"]=`${K}px`),t})(),children:[_e&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ve,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:T,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:S,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:y,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx($n,{activeAgentId:$t,onClose:xt,onSelectAgent:nt,collapsedAreas:_t,onToggleArea:o,agentListRef:st})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:ut,onPointerMove:j,onPointerUp:ne,onPointerCancel:ne,onDoubleClick:Z}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":_e?"Close agents sidebar":"Open agents sidebar","aria-expanded":_e,onClick:dt,children:[e.jsx(m,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),w?e.jsx(Wa,{agentId:w,terminalViewMode:He,onTerminalViewModeChange:Ue,inspectorOpen:Te,onToggleInspector:B,onShowTaskBoard:ke,onImageClick:It,onFileClick:Tt,onBashClick:Mt,onViewMarkdown:Oe,onRequestClearSubordinates:mt,keyboard:Et,canNavigateBack:Lt,canNavigateForward:Rt,onNavigateBack:gt,onNavigateForward:Dt,agentInfoOpen:We,onToggleAgentInfo:At,onHeaderContextMenu:Be,onBuildingContextMenu:ft}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(Pa,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${D.gridCols}, 1fr)`},children:D.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var s;const t=i&&z?((s=D.positions.get(z))==null?void 0:s.row)??null:null;return D.groups.map(l=>{var E;const x=l.area.id,b=D.positions.get(x),C=i&&z!==x;return i&&t!=null&&(b==null?void 0:b.row)===t&&x!==z?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":l.area.color,gridRow:b==null?void 0:b.row,gridColumn:b==null?void 0:b.col},onContextMenu:u=>{k&&(u.preventDefault(),u.stopPropagation(),k(x,{x:u.clientX,y:u.clientY}))},children:[((E=l.area.logo)==null?void 0:E.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ya(l.area.logo.filename),alt:"","aria-hidden":"true",onError:u=>{u.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>i?R(x):wn(x),title:i?C?`Expand ${l.area.name}`:`Collapse ${l.area.name}`:`Focus ${l.area.name} in left panel`,"aria-expanded":i?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:l.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:l.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:l.agents.length}),i&&e.jsx(m,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:l.agents.map(u=>{const I=u.isBoss||u.class==="boss",V=I?Se.get(u.id):void 0,$=zn(u),v=$.usedPercent>=80?"#ff4a4a":$.usedPercent>=60?"#ff9e4a":$.usedPercent>=40?"#ffd700":"#4aff9e",M=`Context: ${($.totalTokens/1e3).toFixed(1)}k / ${($.contextWindow/1e3).toFixed(1)}k (${$.usedPercent}% used, ${$.freePercent}% free)`,L=u.latestTodos&&u.latestTodos.length>0||V&&V.length>0;return e.jsx(On,{todos:u.latestTodos,subordinates:V,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${u.status}`,onClick:()=>c(u.id),onContextMenu:X=>{X.preventDefault(),X.stopPropagation(),be({agentId:u.id,position:{x:X.clientX,y:X.clientY}})},title:L?void 0:`${I?"Boss · ":""}Open chat with ${u.name}
|
|
2
|
+
${M}`,children:[e.jsx(fn,{agent:u,size:16}),I&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(m,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:u.name}),e.jsx("img",{src:gn(u.provider,"/"),alt:u.provider,className:"flat-map-agent-chip__provider-icon",title:hn(u.provider)}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:xn(u.status)}}),u.latestTodos&&u.latestTodos.length>0&&e.jsx(Bn,{todos:u.latestTodos,maxDots:6}),I&&V&&V.length>0&&e.jsx(Fn,{subordinates:V,maxDots:6}),e.jsx("span",{className:"flat-map-agent-chip__context-bar","aria-hidden":"true",children:e.jsx("span",{className:"flat-map-agent-chip__context-bar-fill",style:{width:`${$.usedPercent}%`,backgroundColor:v}})})]})},u.id)})}),l.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${l.area.name} folders`,children:l.area.directories.map(u=>{const I=u.split("/").filter(Boolean).pop()||u;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:V=>{V.stopPropagation(),g.openFileExplorerForAreaFolder(x,u)},title:`Open in file explorer: ${u}`,children:[e.jsx(m,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:I})]},u)})}),l.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:l.buildings.map(u=>{var V;const I=(V=Wn[u.type])==null?void 0:V.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${u.status}`,style:I?{"--building-type-color":I}:void 0,onClick:$=>{if(h){const v=$.currentTarget.getBoundingClientRect();h(u.id,{x:v.right,y:v.top+v.height/2})}else ye(u.id)},onContextMenu:$=>{$.preventDefault(),$.stopPropagation(),O({buildingId:u.id,position:{x:$.clientX,y:$.clientY}})},title:`${u.name} · ${u.type} · ${u.status}`,children:[e.jsx(m,{name:Hn(u.type),size:12,color:I}),e.jsx("span",{className:"flat-map-building-chip__name",children:u.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:Un(u.status)}})]},u.id)})})]},x)})})()})]})})]}),ee&&e.jsx("div",{className:"flat-splitter flat-splitter--inspector",role:"separator","aria-orientation":"vertical","aria-label":"Resize inspector panel",title:"Drag to resize · Double-click to reset",onPointerDown:Qe,onPointerMove:j,onPointerUp:ne,onPointerCancel:ne,onDoubleClick:pt}),ie&&e.jsxs("aside",{className:`flat-inspector ${Ke?"flat-inspector--open":"flat-inspector--closing"}`,"aria-label":"Inspector panel",children:[e.jsxs("div",{className:"flat-inspector__header",children:[e.jsxs("div",{className:"flat-inspector__tabs",role:"tablist","aria-label":"Inspector view",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":Q==="agent",className:`flat-inspector__tab ${Q==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>Ge("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":Q==="tracking",className:`flat-inspector__tab ${Q==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>Ge("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:Ce,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:Q==="tracking"?e.jsx(Vn,{activeAgentId:w??"",onSelectAgent:t=>{c(t),window.innerWidth<=768&&Ce()}}):(()=>{if(!w)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=_.find(s=>s.id===w);return t?e.jsx(Xn,{agent:t,onFocusAgent:s=>{c(s),window.innerWidth<=768&&Ce()},onKillAgent:s=>g.killAgent(s)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),H&&e.jsx(Gn,{url:H.url,name:H.name,onClose:()=>re(null)}),P&&e.jsx(qn,{state:P,onClose:()=>Ee(null)}),e.jsx(Yn,{agent:w?_.find(t=>t.id===w)??null:null,content:oe,onClose:()=>ce(null)}),$e&&e.jsx(Kn,{action:"clear-subordinates",selectedAgentId:$e.agentId,subordinateCount:$e.count,onClose:()=>ot(null),onClearHistory:()=>{}}),e.jsx(Zn,{agent:w?_.find(t=>t.id===w)??null:null,isOpen:We&&!!w,onClose:ct}),e.jsx(tn,{isOpen:xe!==null,position:(xe==null?void 0:xe.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:U,onClose:()=>be(null)}),e.jsx(tn,{isOpen:f!==null,position:(f==null?void 0:f.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:vt,onClose:()=>O(null)}),e.jsx(Jn,{isOpen:Ie!==null,title:Y("common:confirm.removeAgentTitle"),message:Y("common:confirm.removeAgentMessage",{name:(Ie==null?void 0:Ie.name)??""}),confirmLabel:Y("common:buttons.remove"),cancelLabel:Y("common:buttons.cancel"),variant:"danger",onConfirm:()=>{Ie&&g.removeAgentFromServer(Ie.agentId)},onClose:()=>ze(null)})]})}export{qa as FlatView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{bN as ta,u as A,j as e,bc as j,bT as Ms,bU as Fs,bd as X,s as D,bV as $s,r as m,D as Q,I as F,ag as Us,bn as qe,m as na,bo as la,l as ia,bW as oa,_ as ra,S as ca,n as da,af as Ks,bp as Ue}from"./main-D5sqeuwB.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ma=[{value:"",labelKey:"terminal:building.colorDefault"},{value:"#2a2a3a",labelKey:"terminal:building.colorDarkGray"},{value:"#3a2a2a",labelKey:"terminal:building.colorDarkRed"},{value:"#2a3a2a",labelKey:"terminal:building.colorDarkGreen"},{value:"#2a2a4a",labelKey:"terminal:building.colorDarkBlue"},{value:"#3a3a2a",labelKey:"terminal:building.colorDarkYellow"},{value:"#3a2a3a",labelKey:"terminal:building.colorDarkPurple"},{value:"#2a3a3a",labelKey:"terminal:building.colorDarkCyan"},{value:"#4a3a3a",labelKey:"terminal:building.colorWarmBrown"},{value:"#3a4a4a",labelKey:"terminal:building.colorCoolSteel"}];function ua(o){return ta.t(o)}function Ve(o){if(o===0)return"0 B";const p=1024,u=["B","KB","MB","GB"],x=Math.floor(Math.log(o)/Math.log(p));return parseFloat((o/Math.pow(p,x)).toFixed(1))+" "+u[x]}function pa(o){const u=Date.now()-o,x=Math.floor(u/(1e3*60*60)),n=Math.floor(u%(1e3*60*60)/(1e3*60));return x>0?`${x}h ${n}m`:`${n}m`}const Hs={30:"#1a1a1a",31:"#e74c3c",32:"#2ecc71",33:"#f39c12",34:"#3498db",35:"#9b59b6",36:"#00bcd4",37:"#ecf0f1",90:"#7f8c8d",91:"#ff6b6b",92:"#4ade80",93:"#fbbf24",94:"#60a5fa",95:"#c084fc",96:"#22d3ee",97:"#ffffff"};function qs(o){const p=[],u=/\x1B\[([0-9;]*)m/g;let x=0,n=null,y;for(;(y=u.exec(o))!==null;){if(y.index>x){const g=o.slice(x,y.index);n?p.push(e.jsx("span",{style:{color:n},children:g},p.length)):p.push(g)}const C=y[1].split(";").map(Number);for(const g of C)g===0||g===39?n=null:Hs[g]&&(n=Hs[g]);x=u.lastIndex}if(x<o.length){const C=o.slice(x);n?p.push(e.jsx("span",{style:{color:n},children:C},p.length)):p.push(C)}return p.length>0?p:[o]}function ha({buildingName:o,onClose:p,onConfirm:u}){const{t:x}=A(["terminal","common"]);return e.jsx("div",{className:"modal-overlay visible",onClick:p,children:e.jsxs("div",{className:"modal confirm-modal",onClick:n=>n.stopPropagation(),children:[e.jsx("div",{className:"modal-header",children:x("terminal:building.deleteBuilding")}),e.jsxs("div",{className:"modal-body confirm-modal-body",children:[e.jsx("p",{children:x("terminal:building.deleteConfirm",{name:o})}),e.jsx("p",{className:"confirm-modal-note",children:x("terminal:building.deleteNote")})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:p,children:x("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-danger",onClick:u,autoFocus:!0,children:x("common:buttons.delete")})]})]})})}function xa({usePM2:o,setUsePM2:p}){const{t:u}=A(["terminal"]);return e.jsxs("div",{className:"form-section pm2-toggle-section",children:[e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",className:"toggle-input",checked:o,onChange:x=>p(x.target.checked)}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})}),e.jsxs("span",{className:"toggle-label",children:[e.jsx("span",{className:"pm2-badge",children:"PM2"}),u("terminal:building.usePM2")]})]}),e.jsx("div",{className:"form-hint",children:u("terminal:building.pm2Hint")})]})}function ba({usePM2:o,pm2Script:p,setPm2Script:u,pm2Args:x,setPm2Args:n,pm2Interpreter:y,setPm2Interpreter:C,pm2InterpreterArgs:g,setPm2InterpreterArgs:v,pm2Env:s,setPm2Env:h,isEditMode:a,building:t,handleCommand:c}){var f;const{t:i}=A(["terminal","common"]);return o?e.jsxs("div",{className:"form-section pm2-config-section",children:[e.jsx("label",{className:"form-label",children:i("terminal:building.pm2Configuration")}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Script"),e.jsx(j,{text:i("terminal:building.helpPm2Script"),title:i("terminal:building.pm2Script"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:p,onChange:b=>u(b.target.value),placeholder:"npm, java, python, ./app.js",required:o})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Arguments"),e.jsx(j,{text:i("terminal:building.helpPm2Arguments"),title:i("terminal:building.pm2Arguments"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:x,onChange:b=>n(b.target.value),placeholder:"run dev, -jar app.jar, app.py"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Interpreter"),e.jsx(j,{text:i("terminal:building.helpPm2Interpreter"),title:i("terminal:building.pm2Interpreter"),position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:y,onChange:b=>C(b.target.value),children:Object.keys(Ms).map(b=>e.jsx("option",{value:b,children:Ms[b].label},b))})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2InterpArgs"),e.jsx(j,{text:i("terminal:building.helpPm2InterpArgs"),title:i("terminal:building.pm2InterpArgs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:g,onChange:b=>v(b.target.value),placeholder:"-jar (for Java)"})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Environment"),e.jsx(j,{text:i("terminal:building.helpPm2Environment"),title:i("terminal:building.pm2Environment"),position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:s,onChange:b=>h(b.target.value),placeholder:`KEY=value
|
|
2
2
|
SERVER_PORT=7201
|
|
3
3
|
NODE_ENV=production`,rows:3})]}),e.jsx("div",{className:"pm2-examples",children:e.jsxs("details",{children:[e.jsx("summary",{children:i("terminal:building.pm2Examples")}),e.jsxs("div",{className:"pm2-examples-content",children:[e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Node.js:"})," Script: ",e.jsx("code",{children:"npm"}),", Args: ",e.jsx("code",{children:"run dev"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Symfony:"})," Script: ",e.jsx("code",{children:"symfony"}),", Args: ",e.jsx("code",{children:"serve --no-daemon"}),", Interpreter: ",e.jsx("code",{children:"None"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Java JAR:"})," Script: ",e.jsx("code",{children:"app.jar"}),", Interpreter: ",e.jsx("code",{children:"Java"}),", Interp. Args: ",e.jsx("code",{children:"-jar"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Python:"})," Script: ",e.jsx("code",{children:"app.py"}),", Interpreter: ",e.jsx("code",{children:"Python 3"})]})]})]})}),a&&(t==null?void 0:t.pm2Status)&&e.jsx("div",{className:"pm2-status-display",children:e.jsxs("div",{className:"pm2-status-row",children:[e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"PID"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.pid||"-"})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"CPU"}),e.jsxs("span",{className:"pm2-metric-value",children:[((f=t.pm2Status.cpu)==null?void 0:f.toFixed(1))||"0","%"]})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"MEM"}),e.jsx("span",{className:"pm2-metric-value",children:Ve(t.pm2Status.memory||0)})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Restarts"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.restarts||0})]}),t.pm2Status.uptime&&e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Uptime"}),e.jsx("span",{className:"pm2-metric-value",children:pa(t.pm2Status.uptime)})]})]})}),a&&e.jsxs("div",{className:"pm2-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>c("start"),children:i("common:buttons.start")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>c("stop"),children:i("common:buttons.stop")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>c("restart"),children:i("terminal:buildingAction.restart")}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>c("logs"),children:i("terminal:logs.title")})]})]}):null}function ja({dockerMode:o,setDockerMode:p,dockerImage:u,setDockerImage:x,dockerContainerName:n,setDockerContainerName:y,dockerCommand:C,setDockerCommand:g,dockerPorts:v,setDockerPorts:s,dockerVolumes:h,setDockerVolumes:a,dockerNetwork:t,setDockerNetwork:c,dockerRestart:i,setDockerRestart:f,dockerPull:b,setDockerPull:z,dockerEnv:T,setDockerEnv:B,dockerComposePath:$,setDockerComposePath:R,dockerComposeProject:K,setDockerComposeProject:I,dockerComposeServices:H,setDockerComposeServices:O,selectedExistingContainer:d,setSelectedExistingContainer:L,dockerContainersList:q,isEditMode:V,building:k,handleCommand:_}){const{t:M}=A(["config","common"]);return e.jsxs("div",{className:"form-section docker-config-section",children:[e.jsx("label",{className:"form-label",children:M("config:buildings.dockerConfig")}),e.jsxs("div",{className:"docker-mode-selector",children:[e.jsxs("label",{className:`docker-mode-option ${o==="container"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"container",checked:o==="container",onChange:()=>p("container")}),e.jsx("span",{className:"docker-mode-icon",children:"📦"}),e.jsx("span",{className:"docker-mode-label",children:"Container"}),e.jsx("span",{className:"docker-mode-desc",children:"Create a new container"})]}),e.jsxs("label",{className:`docker-mode-option ${o==="compose"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"compose",checked:o==="compose",onChange:()=>p("compose")}),e.jsx("span",{className:"docker-mode-icon",children:"🛠"}),e.jsx("span",{className:"docker-mode-label",children:"Compose"}),e.jsx("span",{className:"docker-mode-desc",children:"Manage multiple services"})]}),e.jsxs("label",{className:`docker-mode-option ${o==="existing"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"existing",checked:o==="existing",onChange:()=>p("existing")}),e.jsx("span",{className:"docker-mode-icon",children:"🔎"}),e.jsx("span",{className:"docker-mode-label",children:"Existing"}),e.jsx("span",{className:"docker-mode-desc",children:"Adopt existing container"})]})]}),o==="container"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Image:",e.jsx(j,{text:"Docker image to run, e.g., nginx:latest, redis:alpine, my-app:v1",title:"Image",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:l=>x(l.target.value),placeholder:"nginx:latest",required:!0})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Container Name:",e.jsx(j,{text:"Custom name for the container. If empty, auto-generated based on building name.",title:"Container Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:l=>y(l.target.value),placeholder:"Auto-generated (tc-{name}-{id})"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Command:",e.jsx(j,{text:"Override the default container command. Leave empty to use image's CMD.",title:"Command Override",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:l=>g(l.target.value),placeholder:"Optional command override"})]}),e.jsxs("div",{className:"form-section docker-ports-section",children:[e.jsxs("label",{className:"form-label",children:["Port Mappings",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>s([...v,""]),children:"+ Add"})]}),v.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const E=[...v];E[S]=U.target.value,s(E)},placeholder:"8080:80 or 3000"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>s(v.filter((U,E)=>E!==S)),children:"x"})]},S)),v.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host:container (e.g., 8080:80) or same port (e.g., 3000)"})]}),e.jsxs("div",{className:"form-section docker-volumes-section",children:[e.jsxs("label",{className:"form-label",children:["Volume Mounts",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>a([...h,""]),children:"+ Add"})]}),h.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const E=[...h];E[S]=U.target.value,a(E)},placeholder:"./data:/app/data or /host/path:/container/path"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a(h.filter((U,E)=>E!==S)),children:"x"})]},S)),h.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host_path:container_path (relative paths resolved from working directory)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Network:",e.jsx(j,{text:"Docker network to connect to. Leave empty for default bridge network.",title:"Network",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:t,onChange:l=>c(l.target.value),placeholder:"bridge (default)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Restart Policy:",e.jsx(j,{text:"When should Docker restart the container automatically?",title:"Restart Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:i,onChange:l=>f(l.target.value),children:Object.keys(Fs).map(l=>e.jsx("option",{value:l,children:Fs[l].label},l))})]})]}),o==="compose"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Compose File:",e.jsx(j,{text:"Path to docker-compose.yml file, relative to working directory.",title:"Compose File",position:"top",size:"sm"})]}),e.jsx(X,{value:$,onChange:R,placeholder:"docker-compose.yml",className:"form-input",directoriesOnly:!1})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Project Name:",e.jsx(j,{text:"Override the compose project name. Leave empty for auto-generated name.",title:"Project Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:K,onChange:l=>I(l.target.value),placeholder:"Auto-generated"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Services:",e.jsx(j,{text:"Specific services to manage (comma-separated). Leave empty for all services.",title:"Services",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:H,onChange:l=>O(l.target.value),placeholder:"All services (or: api, db, redis)"})]})]}),o==="existing"&&e.jsxs("div",{className:"docker-existing-section",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Select Container:",e.jsx(j,{text:"Choose an existing Docker container to monitor and control. The container will not be deleted when removing the building.",title:"Existing Container",position:"top",size:"sm"})]}),e.jsxs("div",{className:"docker-existing-select-wrapper",children:[e.jsxs("select",{className:"form-input form-select",value:d,onChange:l=>L(l.target.value),required:o==="existing",children:[e.jsx("option",{value:"",children:"Select a container..."}),q.map(l=>e.jsxs("option",{value:l.name,children:[l.name," (",l.image,") - ",l.state]},l.id))]}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.requestDockerContainersList(),title:"Refresh container list",children:"↻"})]})]}),q.length===0&&e.jsx("div",{className:"form-hint docker-existing-hint",children:"No containers found. Make sure Docker is running and you have containers available."}),d&&e.jsx("div",{className:"docker-existing-info",children:(()=>{const l=q.find(S=>S.name===d);return l?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Image:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.image})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Status:"}),e.jsx("span",{className:`docker-existing-info-value docker-status-${l.status}`,children:l.state})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"ID:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.id.slice(0,12)})]}),l.ports.length>0&&e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Ports:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.ports.map(S=>`${S.host}:${S.container}/${S.protocol}`).join(", ")})]})]}):null})()}),e.jsx("div",{className:"form-hint",children:"Note: Existing containers will not be deleted when you remove this building."})]}),o!=="existing"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Pull Policy:",e.jsx(j,{text:"When to pull images: always, only if missing, or never.",title:"Pull Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:b,onChange:l=>z(l.target.value),children:Object.keys($s).map(l=>e.jsx("option",{value:l,children:$s[l].label},l))})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:["Environment:",e.jsx(j,{text:"Environment variables in KEY=value format, one per line.",title:"Environment Variables",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:T,onChange:l=>B(l.target.value),placeholder:`KEY=value
|
|
4
4
|
DATABASE_URL=postgres://...
|