tide-commander 1.148.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.
Files changed (89) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +6 -3
  3. package/dist/assets/{BossLogsModal-CZMHgMBE.js → BossLogsModal-DvczRUvP.js} +1 -1
  4. package/dist/assets/BossSpawnModal-B2autFKk.js +1 -0
  5. package/dist/assets/{ControlsModal-DJ8Scm16.js → ControlsModal-BaREMQxc.js} +1 -1
  6. package/dist/assets/{DockerLogsModal-Vb4gqdFz.js → DockerLogsModal-DZ0udMCo.js} +1 -1
  7. package/dist/assets/{EmbeddedEditor-D4sHERAj.js → EmbeddedEditor-CEjr0ZSZ.js} +1 -1
  8. package/dist/assets/{GmailOAuthSetup-COIYIbJS.js → GmailOAuthSetup-76BP8J8C.js} +1 -1
  9. package/dist/assets/{GoogleOAuthSetup-DJS59Soi.js → GoogleOAuthSetup-D45GImPI.js} +1 -1
  10. package/dist/assets/{IframeModal-CFysTkn9.js → IframeModal-De63RfJZ.js} +1 -1
  11. package/dist/assets/{IntegrationsPanel-BK8g9ceY.js → IntegrationsPanel-DYrw1Sqk.js} +2 -2
  12. package/dist/assets/{LogViewerModal-DRxR0HYq.js → LogViewerModal-DW-2lpln.js} +1 -1
  13. package/dist/assets/{MonitoringModal-CL7UMOdX.js → MonitoringModal-B0-XXyd3.js} +1 -1
  14. package/dist/assets/{PM2LogsModal-I3aouUlw.js → PM2LogsModal-DOfOhkCY.js} +1 -1
  15. package/dist/assets/{RestoreArchivedAreaModal-PWAg6w6b.js → RestoreArchivedAreaModal-DNGmIJmM.js} +1 -1
  16. package/dist/assets/Scene2DCanvas-BW1E76CQ.js +1 -0
  17. package/dist/assets/SceneManager-DAvc9-Wp.js +104 -0
  18. package/dist/assets/{SkillsPanel-EQ74sIa6.js → SkillsPanel-Br-gLCLA.js} +3 -3
  19. package/dist/assets/{SlackMultiInstanceSetup-CLMUteI0.js → SlackMultiInstanceSetup-DG_bIfDu.js} +1 -1
  20. package/dist/assets/SpawnModal-lWM8OuZW.js +1 -0
  21. package/dist/assets/{StatisticsModal-D6MgA_o0.js → StatisticsModal-LvA0Fcvn.js} +1 -1
  22. package/dist/assets/{SubordinateAssignmentModal-C6n0pMn3.js → SubordinateAssignmentModal-8YxNXcR3.js} +1 -1
  23. package/dist/assets/{TriggerManagerPanel-Umd8iUg1.js → TriggerManagerPanel-DftIuKUG.js} +1 -1
  24. package/dist/assets/{WorkflowEditorPanel-CxjBxs9O.js → WorkflowEditorPanel-oLwyO_C6.js} +1 -1
  25. package/dist/assets/{area-logos-CThPeqIM.js → area-logos-mcpQqUMZ.js} +1 -1
  26. package/dist/assets/grok.ico +0 -0
  27. package/dist/assets/grok.png +0 -0
  28. package/dist/assets/index-Ay7dKyeR.js +1 -0
  29. package/dist/assets/index-BMw7AAAK.js +5 -0
  30. package/dist/assets/{index-Cz-ypmob.js → index-BQpd34Mc.js} +1 -1
  31. package/dist/assets/{index-BUN7MVf5.js → index-C6-68CXL.js} +3 -3
  32. package/dist/assets/index-CIon0DLf.js +2 -0
  33. package/dist/assets/{index-maZSt2YW.js → index-Cwt-E2td.js} +5 -5
  34. package/dist/assets/{index-DelocTaH.js → index-DFVroqA5.js} +1 -1
  35. package/dist/assets/index-DR6_WeF_.js +1 -0
  36. package/dist/assets/{index-h3Cuh2Zn.js → index-O0t07OB_.js} +2 -2
  37. package/dist/assets/main-D5sqeuwB.js +286 -0
  38. package/dist/assets/main-JBkwGXfE.css +1 -0
  39. package/dist/assets/{web-CfvEypdU.js → web-BkrshujV.js} +1 -1
  40. package/dist/assets/{web-CNjTPilF.js → web-DPETNqOf.js} +1 -1
  41. package/dist/assets/{web-bcYaAwP6.js → web-vG1Smf_N.js} +1 -1
  42. package/dist/index.html +2 -2
  43. package/dist/locales/de/config.json +3 -1
  44. package/dist/locales/en/config.json +2 -0
  45. package/dist/locales/en/terminal.json +6 -0
  46. package/dist/locales/en/tools.json +4 -2
  47. package/dist/locales/es/config.json +2 -0
  48. package/dist/locales/fr/config.json +3 -1
  49. package/dist/locales/hi/config.json +3 -1
  50. package/dist/locales/it/config.json +3 -1
  51. package/dist/locales/ja/config.json +3 -1
  52. package/dist/locales/pt/config.json +3 -1
  53. package/dist/locales/ru/config.json +3 -1
  54. package/dist/locales/zh-CN/config.json +3 -1
  55. package/dist/src/packages/server/claude/backend.js +114 -10
  56. package/dist/src/packages/server/claude/runner/process-lifecycle.js +62 -0
  57. package/dist/src/packages/server/claude/runner/stdout-pipeline.js +148 -7
  58. package/dist/src/packages/server/claude/runner/watchdog.js +12 -0
  59. package/dist/src/packages/server/claude/session-loader.js +295 -0
  60. package/dist/src/packages/server/codex/json-event-parser.js +149 -4
  61. package/dist/src/packages/server/data/index.js +1 -0
  62. package/dist/src/packages/server/grok/backend.js +235 -0
  63. package/dist/src/packages/server/grok/index.js +4 -0
  64. package/dist/src/packages/server/grok/json-event-parser.js +153 -0
  65. package/dist/src/packages/server/grok/session-watcher.js +493 -0
  66. package/dist/src/packages/server/opencode/json-event-parser.js +184 -15
  67. package/dist/src/packages/server/routes/agents.js +19 -11
  68. package/dist/src/packages/server/runtime/grok-runtime-provider.js +11 -0
  69. package/dist/src/packages/server/runtime/index.js +1 -0
  70. package/dist/src/packages/server/services/agent-service.js +26 -5
  71. package/dist/src/packages/server/services/grok-usage-service.js +374 -0
  72. package/dist/src/packages/server/services/runtime-command-execution.js +4 -2
  73. package/dist/src/packages/server/services/runtime-events.js +46 -7
  74. package/dist/src/packages/server/services/runtime-service.js +19 -3
  75. package/dist/src/packages/server/utils/tool-formatting.js +40 -12
  76. package/dist/src/packages/server/websocket/handlers/agent-handler.js +70 -17
  77. package/dist/src/packages/server/websocket/listeners/runtime-listeners.js +73 -14
  78. package/dist/src/packages/shared/agent-types.js +10 -0
  79. package/package.json +1 -1
  80. package/dist/assets/BossSpawnModal-C6DxqtKP.js +0 -1
  81. package/dist/assets/Scene2DCanvas-DYPHkU3i.js +0 -1
  82. package/dist/assets/SceneManager-QqKygyaw.js +0 -104
  83. package/dist/assets/SpawnModal-BOeStihN.js +0 -1
  84. package/dist/assets/index-DOzFBkSH.js +0 -1
  85. package/dist/assets/index-DP7kd91h.js +0 -1
  86. package/dist/assets/index-DRyMARFk.js +0 -5
  87. package/dist/assets/index-DuWmOZdY.js +0 -2
  88. package/dist/assets/main-C2zgPci-.js +0 -256
  89. package/dist/assets/main-C3JO2TRI.css +0 -1
@@ -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&&lt(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,8 +1,8 @@
1
- import{bI as ta,u as A,j as e,b8 as j,bO as Ms,bP as Fs,b9 as X,s as D,bQ as $s,r as m,D as Z,I as F,ae as Us,bi as qe,m as na,bj as la,l as ia,bR as ra,_ as oa,S as ca,n as da,ad as Ks,bk as Ue}from"./main-C2zgPci-.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(r){return ta.t(r)}function Ve(r){if(r===0)return"0 B";const p=1024,u=["B","KB","MB","GB"],x=Math.floor(Math.log(r)/Math.log(p));return parseFloat((r/Math.pow(p,x)).toFixed(1))+" "+u[x]}function pa(r){const u=Date.now()-r,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(r){const p=[],u=/\x1B\[([0-9;]*)m/g;let x=0,n=null,y;for(;(y=u.exec(r))!==null;){if(y.index>x){const g=r.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<r.length){const C=r.slice(x);n?p.push(e.jsx("span",{style:{color:n},children:C},p.length)):p.push(C)}return p.length>0?p:[r]}function ha({buildingName:r,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:r})}),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:r,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:r,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:r,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 r?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:r})]}),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
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
- 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:r,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 ${r==="container"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"container",checked:r==="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 ${r==="compose"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"compose",checked:r==="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 ${r==="existing"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"existing",checked:r==="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"})]})]}),r==="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))})]})]}),r==="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)"})]})]}),r==="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:r==="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."})]}),r!=="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
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://...
5
- NODE_ENV=production`,rows:3})]})]}),V&&(k==null?void 0:k.dockerStatus)&&e.jsxs("div",{className:"docker-status-display",children:[e.jsxs("div",{className:"docker-status-row",children:[e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"ID"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.containerId||"-"})]}),e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"Status"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.status||"-"})]}),k.dockerStatus.health&&k.dockerStatus.health!=="none"&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"Health"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.health})]}),k.dockerStatus.cpu!==void 0&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"CPU"}),e.jsxs("span",{className:"docker-metric-value",children:[k.dockerStatus.cpu.toFixed(1),"%"]})]}),k.dockerStatus.memory!==void 0&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"MEM"}),e.jsxs("span",{className:"docker-metric-value",children:[Ve(k.dockerStatus.memory),k.dockerStatus.memoryLimit?` / ${Ve(k.dockerStatus.memoryLimit)}`:""]})]})]}),k.dockerStatus.ports&&k.dockerStatus.ports.length>0&&e.jsxs("div",{className:"docker-ports-row",children:[e.jsx("span",{className:"docker-metric-label",children:"Ports:"}),k.dockerStatus.ports.map((l,S)=>e.jsxs("a",{href:`http://${window.location.hostname}:${l.host}`,target:"_blank",rel:"noopener noreferrer",className:"docker-port-link",children:[l.host,":",l.container,"/",l.protocol]},S))]}),k.dockerStatus.services&&k.dockerStatus.services.length>0&&e.jsxs("div",{className:"docker-services-status",children:[e.jsx("span",{className:"docker-metric-label",children:"Services:"}),e.jsx("div",{className:"docker-services-grid",children:k.dockerStatus.services.map((l,S)=>e.jsxs("div",{className:"docker-service-item",children:[e.jsx("span",{className:"docker-service-indicator",style:{backgroundColor:l.status==="running"?"#4ade80":"#f87171"}}),e.jsx("span",{className:"docker-service-name",children:l.name}),e.jsx("span",{className:"docker-service-status",children:l.status})]},S))})]})]}),V&&e.jsxs("div",{className:"docker-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>_("start"),children:"Start"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>_("stop"),children:"Stop"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>_("restart"),children:"Restart"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_("logs"),children:"Logs"})]})]})}const ga={enabled:!1,host:"",port:22,username:"",authMethod:"password"};function va({dbConnections:r,setDbConnections:p,activeDbConnectionId:u,setActiveDbConnectionId:x}){const{t:n}=A(["terminal","common"]),[y,C]=m.useState({}),g=m.useRef(new Map);m.useEffect(()=>{const a=t=>{const c=t.detail;if(!c||!c.requestId)return;const i=g.current.get(c.requestId);i&&(g.current.delete(c.requestId),C(f=>({...f,[i]:c.success?{status:"success",serverVersion:c.serverVersion}:{status:"error",error:c.error||"Connection failed"}})))};return window.addEventListener("tide:db-test-result",a),()=>window.removeEventListener("tide:db-test-result",a)},[]);const v=(a,t)=>{const c=[...r];c[a]={...c[a],...t},p(c)},s=(a,t)=>{const i={...r[a].ssh??ga,...t};v(a,{ssh:i})},h=a=>{const t=`test_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;g.current.set(t,a.id),C(c=>({...c,[a.id]:{status:"testing"}})),D.testDatabaseConnectionTransient(t,a),window.setTimeout(()=>{g.current.has(t)&&(g.current.delete(t),C(c=>{const i=c[a.id];return(i==null?void 0:i.status)!=="testing"?c:{...c,[a.id]:{status:"error",error:"Test connection timed out after 30s"}}}))},3e4)};return e.jsxs("div",{className:"form-section database-config-section",children:[e.jsxs("label",{className:"form-label",children:[n("terminal:building.dbConnections"),e.jsx(j,{text:n("terminal:building.helpDbConnections"),title:n("terminal:building.dbConnections"),position:"top",size:"sm"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>{const a={id:`conn_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,name:`Connection ${r.length+1}`,engine:"mysql",host:"localhost",port:3306,username:"root"};p([...r,a]),u||x(a.id)},children:n("terminal:database.addConnection")})]}),r.length===0&&e.jsx("div",{className:"form-hint",children:n("terminal:building.dbGetStarted")}),r.map((a,t)=>{var f,b,z,T,B,$,R,K,I,H,O;const c=y[a.id]??{status:"idle"},i=((f=a.ssh)==null?void 0:f.enabled)===!0;return e.jsxs("div",{className:"db-connection-card",children:[e.jsxs("div",{className:"db-connection-header",children:[e.jsxs("label",{className:"db-connection-active",children:[e.jsx("input",{type:"radio",name:"activeConnection",checked:u===a.id,onChange:()=>x(a.id)}),n("common:labels.default"),e.jsx(j,{text:n("terminal:building.helpDbDefault"),position:"top",size:"sm"})]}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>{const d=r.filter(L=>L.id!==a.id);p(d),u===a.id&&d.length>0?x(d[0].id):d.length===0&&x(void 0)},children:n("common:buttons.remove")})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("common:labels.name")}),e.jsx("input",{type:"text",className:"form-input",value:a.name,onChange:d=>v(t,{name:d.target.value}),placeholder:"My Database"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:n("terminal:building.dbEngine")}),e.jsx("select",{className:"form-input form-select",value:a.engine,onChange:d=>{const L=d.target.value;v(t,{engine:L,port:Z[L].defaultPort})},children:Object.keys(Z).map(d=>e.jsxs("option",{value:d,children:[Z[d].icon," ",Z[d].label]},d))})]})]}),a.engine==="sqlite"?e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:n("terminal:building.dbFilepath")}),e.jsx("input",{type:"text",className:"form-input",value:a.filepath||"",onChange:d=>v(t,{filepath:d.target.value||void 0}),placeholder:"/path/to/database.db"})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:[n("terminal:building.dbHost"),i&&e.jsx(j,{text:"Host as seen FROM the SSH server (often 'localhost' or 127.0.0.1).",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:a.host,onChange:d=>v(t,{host:d.target.value}),placeholder:i?"127.0.0.1":"localhost"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:n("terminal:building.dbPort")}),e.jsx("input",{type:"number",className:"form-input",value:a.port,onChange:d=>v(t,{port:parseInt(d.target.value)||Z[a.engine].defaultPort})})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("terminal:building.dbUsername")}),e.jsx("input",{type:"text",className:"form-input",value:a.username,onChange:d=>v(t,{username:d.target.value}),placeholder:"root"})]}),e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("terminal:building.dbPassword")}),e.jsx("input",{type:"password",className:"form-input",value:a.password||"",onChange:d=>v(t,{password:d.target.value||void 0}),placeholder:"Optional",autoComplete:"off"})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:n("terminal:building.dbDefaultDatabase")}),e.jsx("input",{type:"text",className:"form-input",value:a.database||"",onChange:d=>v(t,{database:d.target.value||void 0}),placeholder:"Optional - select after connecting"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsxs("label",{children:["SSL",e.jsx(j,{text:n("terminal:building.helpDbSsl"),position:"top",size:"sm"})]}),e.jsxs("label",{className:"toggle-switch toggle-switch--small",children:[e.jsx("input",{type:"checkbox",checked:a.ssl||!1,onChange:d=>v(t,{ssl:d.target.checked})}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})})]})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsx("div",{className:"db-field db-field--grow",children:e.jsxs("label",{children:["SSH Tunnel",e.jsx(j,{text:"Forward DB traffic through an SSH jump host. Required when the DB is only reachable from inside a private network.",position:"top",size:"sm"})]})}),e.jsx("div",{className:"db-field db-field--small",children:e.jsxs("label",{className:"toggle-switch toggle-switch--small",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:d=>s(t,{enabled:d.target.checked})}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})})]})})]}),i&&e.jsxs("div",{className:"db-ssh-subsection",children:[e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Host"}),e.jsx("input",{type:"text",className:"form-input",value:((b=a.ssh)==null?void 0:b.host)||"",onChange:d=>s(t,{host:d.target.value}),placeholder:"bastion.example.com"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:"SSH Port"}),e.jsx("input",{type:"number",className:"form-input",value:((z=a.ssh)==null?void 0:z.port)||22,onChange:d=>s(t,{port:parseInt(d.target.value)||22})})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Username"}),e.jsx("input",{type:"text",className:"form-input",value:((T=a.ssh)==null?void 0:T.username)||"",onChange:d=>s(t,{username:d.target.value}),placeholder:"ubuntu"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:"Auth Method"}),e.jsxs("select",{className:"form-input form-select",value:((B=a.ssh)==null?void 0:B.authMethod)||"password",onChange:d=>s(t,{authMethod:d.target.value}),children:[e.jsx("option",{value:"password",children:"Password"}),e.jsx("option",{value:"privateKey",children:"Private Key"})]})]})]}),((($=a.ssh)==null?void 0:$.authMethod)||"password")==="password"?e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Password"}),e.jsx("input",{type:"password",className:"form-input",value:((R=a.ssh)==null?void 0:R.password)||"",onChange:d=>s(t,{password:d.target.value||void 0}),placeholder:"SSH password",autoComplete:"off"})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:["Private Key Path",e.jsx(j,{text:"Path to a private key file on the server, e.g. ~/.ssh/id_rsa. Use this OR paste the key contents below.",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:((K=a.ssh)==null?void 0:K.privateKeyPath)||"",onChange:d=>s(t,{privateKeyPath:d.target.value||void 0}),placeholder:"/home/user/.ssh/id_rsa"})]})}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:["Private Key Contents (PEM)",e.jsx(j,{text:"Paste the full private key contents inline. Encrypted at rest.",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input",value:((I=a.ssh)==null?void 0:I.privateKey)||"",onChange:d=>s(t,{privateKey:d.target.value||void 0}),placeholder:"-----BEGIN OPENSSH PRIVATE KEY-----\\n...",rows:4,style:{fontFamily:"monospace",fontSize:12}})]})}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"Key Passphrase (optional)"}),e.jsx("input",{type:"password",className:"form-input",value:((H=a.ssh)==null?void 0:H.passphrase)||"",onChange:d=>s(t,{passphrase:d.target.value||void 0}),placeholder:"If your key is encrypted",autoComplete:"off"})]})})]}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--small",children:[e.jsxs("label",{children:["Local Port",e.jsx(j,{text:"Optional fixed local forwarded port. Leave blank to auto-assign.",position:"top",size:"sm"})]}),e.jsx("input",{type:"number",className:"form-input",value:((O=a.ssh)==null?void 0:O.localPort)??"",onChange:d=>{const L=d.target.value.trim();s(t,{localPort:L?parseInt(L):void 0})},placeholder:"auto"})]})})]}),e.jsxs("div",{className:"db-connection-row",style:{alignItems:"center",gap:8},children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-primary",disabled:c.status==="testing",onClick:()=>h(a),children:c.status==="testing"?"Testing…":"Test Connection"}),c.status==="success"&&e.jsxs("span",{style:{color:"#4aff9e",fontSize:12},children:["✓ Connected",c.serverVersion?` — ${c.serverVersion}`:""]}),c.status==="error"&&e.jsxs("span",{style:{color:"#ff6b6b",fontSize:12},title:c.error,children:["✗ ",c.error]})]})]})]},a.id)}),r.length>0&&e.jsx("div",{className:"form-hint",children:n("terminal:building.dbAfterSaving")})]})}function fa({buildings:r,buildingId:p,subordinateBuildingIds:u,setSubordinateBuildingIds:x,isEditMode:n,showBossLogs:y,setShowBossLogs:C,currentBossLogs:g,bossLogsContainerRef:v}){const{t:s}=A(["terminal","common"]);return e.jsxs("div",{className:"form-section boss-building-section",children:[e.jsxs("label",{className:"form-label",children:[s("terminal:building.managedBuildings"),e.jsx(j,{text:s("terminal:building.helpManagedBuildings"),title:s("terminal:building.managedBuildings"),position:"top",size:"sm"})]}),e.jsx("div",{className:"form-hint",children:s("terminal:building.managedBuildingsHint")}),e.jsxs("div",{className:"subordinate-buildings-list",children:[Array.from(r.values()).filter(h=>h.id!==p&&h.type!=="boss"&&h.type!=="link"&&h.type!=="folder").map(h=>e.jsxs("label",{className:"subordinate-building-item",children:[e.jsx("input",{type:"checkbox",checked:u.includes(h.id),onChange:a=>{a.target.checked?x([...u,h.id]):x(u.filter(t=>t!==h.id))}}),e.jsx("span",{className:"subordinate-building-icon",children:e.jsx(F,{name:Us(h.type),size:14})}),e.jsx("span",{className:"subordinate-building-name",children:h.name}),e.jsx("span",{className:"subordinate-building-status",style:{backgroundColor:qe[h.status]}})]},h.id)),Array.from(r.values()).filter(h=>h.id!==p&&h.type!=="boss"&&h.type!=="link"&&h.type!=="folder").length===0&&e.jsx("div",{className:"form-hint no-buildings-hint",children:s("terminal:building.noManageableBuildings")})]}),n&&u.length>0&&e.jsxs("div",{className:"boss-building-actions",children:[e.jsxs("div",{className:"boss-actions-header",children:[s("terminal:building.bulkActions"),e.jsx(j,{text:s("terminal:building.helpBulkActions"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"boss-actions-row",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>D.sendBossBuildingCommand(p,"start_all"),children:s("terminal:building.startAll")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>D.sendBossBuildingCommand(p,"stop_all"),children:s("terminal:building.stopAll")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>D.sendBossBuildingCommand(p,"restart_all"),children:s("terminal:building.restartAll")}),e.jsx("button",{type:"button",className:`btn btn-sm ${y?"btn-primary":""}`,onClick:()=>{y?(D.stopBossLogStreaming(p),C(!1)):(D.startBossLogStreaming(p),C(!0))},children:s(y?"terminal:building.hideLogs":"terminal:building.unifiedLogs")})]}),e.jsxs("div",{className:"boss-subordinates-status",children:[e.jsx("div",{className:"boss-status-header",children:s("terminal:building.statusOverview")}),e.jsx("div",{className:"boss-status-grid",children:u.map(h=>{const a=r.get(h);return a?e.jsxs("div",{className:"boss-status-item",children:[e.jsx("span",{className:"boss-status-indicator",style:{backgroundColor:qe[a.status]}}),e.jsx("span",{className:"boss-status-name",children:a.name}),e.jsx("span",{className:"boss-status-label",children:a.status})]},h):null})})]})]}),n&&y&&e.jsxs("div",{className:"form-section boss-logs-section",children:[e.jsxs("label",{className:"form-label",children:[s("terminal:building.unifiedLogs"),e.jsx(j,{text:s("terminal:building.helpUnifiedLogs"),position:"top",size:"sm"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.clearBossStreamingLogs(p),children:s("common:buttons.clear")})]}),e.jsxs("div",{className:"boss-logs-container",ref:v,children:[g.map((h,a)=>e.jsxs("div",{className:"boss-log-entry",children:[e.jsxs("span",{className:"boss-log-source",children:["[",h.subordinateName,"]"]}),e.jsx("span",{className:"boss-log-content",children:qs(h.chunk)})]},a)),g.length===0&&e.jsx("div",{className:"boss-logs-empty",children:s("terminal:building.waitingForLogs")})]})]})]})}function Na({startCmd:r,setStartCmd:p,stopCmd:u,setStopCmd:x,restartCmd:n,setRestartCmd:y,healthCheckCmd:C,setHealthCheckCmd:g,logsCmd:v,setLogsCmd:s,isEditMode:h,handleCommand:a}){const{t}=A(["terminal","common"]);return e.jsxs("div",{className:"form-section commands-section",children:[e.jsxs("label",{className:"form-label",children:[t("terminal:building.commands"),e.jsx(j,{text:t("terminal:building.helpCommands"),title:t("terminal:building.commands"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"command-inputs",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdStart"),e.jsx(j,{text:t("terminal:building.helpCmdStart"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:r,onChange:c=>p(c.target.value),placeholder:"npm run dev"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>a("start"),disabled:!r,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdStop"),e.jsx(j,{text:t("terminal:building.helpCmdStop"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:c=>x(c.target.value),placeholder:"pkill -f 'npm run dev'"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a("stop"),disabled:!u,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdRestart"),e.jsx(j,{text:t("terminal:building.helpCmdRestart"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:c=>y(c.target.value),placeholder:"npm run restart"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>a("restart"),disabled:!n,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdHealthCheck"),e.jsx(j,{text:t("terminal:building.helpCmdHealthCheck"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:c=>g(c.target.value),placeholder:"curl -s http://localhost:3000/health"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>a("healthCheck"),disabled:!C,children:t("terminal:building.check")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdLogs"),e.jsx(j,{text:t("terminal:building.helpCmdLogs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:v,onChange:c=>s(c.target.value),placeholder:"tail -n 100 /var/log/app.log"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>a("logs"),children:t("terminal:building.fetch")})]})]})]})}const ka=[{value:"",label:"Default ($SHELL)"},{value:"/bin/bash",label:"Bash"},{value:"/bin/zsh",label:"Zsh"},{value:"/usr/bin/fish",label:"Fish"},{value:"/bin/sh",label:"sh"}];function ya({terminalShell:r,setTerminalShell:p,terminalPort:u,setTerminalPort:x,terminalSaveSession:n,setTerminalSaveSession:y,terminalArgs:C,setTerminalArgs:g,isEditMode:v,building:s,handleCommand:h,onOpenTerminal:a,onOpenBelow:t}){const{t:c}=A(["config"]),i=(s==null?void 0:s.status)==="running",f=s==null?void 0:s.terminalStatus;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:c("config:buildings.terminalConfig",{defaultValue:"Terminal Configuration"})}),e.jsxs("div",{className:"form-row",children:[e.jsxs("div",{className:"form-field",children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalShell",{defaultValue:"Shell"})}),e.jsx("select",{className:"form-input",value:r,onChange:b=>p(b.target.value),children:ka.map(b=>e.jsx("option",{value:b.value,children:b.label},b.value))})]}),e.jsxs("div",{className:"form-field",children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalPort",{defaultValue:"Port"})}),e.jsx("input",{type:"number",className:"form-input",value:u,onChange:b=>x(b.target.value),placeholder:"Auto",min:1024,max:65535})]})]}),e.jsx("div",{className:"form-row",style:{marginTop:"8px"},children:e.jsxs("label",{className:"form-checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:b=>y(b.target.checked)}),e.jsx("span",{children:c("config:buildings.terminalSaveSession",{defaultValue:"Persist session (tmux)"})})]})}),e.jsxs("div",{style:{marginTop:"8px"},children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalArgs",{defaultValue:"Extra ttyd args"})}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:b=>g(b.target.value),placeholder:"--client-option titleFixed=Terminal"}),e.jsx("div",{className:"form-hint",children:"Additional command-line arguments passed to ttyd"})]})]}),v&&s&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:c("config:buildings.terminalControls",{defaultValue:"Terminal Controls"})}),f&&e.jsxs("div",{className:"building-runtime-info",children:[e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Proxy"}),e.jsx("span",{className:"runtime-value",style:{color:"#4a9eff"},children:f.url})]}),e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"PID"}),e.jsx("span",{className:"runtime-value",children:f.pid})]}),e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Port"}),e.jsx("span",{className:"runtime-value",children:f.port})]}),f.tmuxSession&&e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Session"}),e.jsx("span",{className:"runtime-value",children:f.tmuxSession})]})]}),e.jsxs("div",{className:"building-actions",style:{marginTop:"8px"},children:[!i&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>h("start"),children:[e.jsx(F,{name:"play",size:12})," Start"]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>h("restart"),children:[e.jsx(F,{name:"refresh",size:12})," Restart"]}),e.jsxs("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>h("stop"),children:[e.jsx(F,{name:"stop",size:12})," Stop"]}),(f==null?void 0:f.url)&&e.jsxs(e.Fragment,{children:[a&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-primary",onClick:()=>a(f.url),children:[e.jsx(F,{name:"desktop",size:12})," Modal"]}),t&&s&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-primary",onClick:()=>t(s.id),children:[e.jsx(F,{name:"arrow-down",size:12})," Below"]})]})]})]})]})]})}function Ca({logs:r,buildingId:p,logsContainerRef:u}){return e.jsxs("div",{className:"form-section logs-section",children:[e.jsxs("label",{className:"form-label",children:["Logs",e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.clearBuildingLogs(p),children:"Clear"})]}),e.jsx("div",{className:"logs-container",ref:u,children:r.map((x,n)=>e.jsx("pre",{className:"log-entry",children:qs(x)},n))})]})}function Da({isOpen:r,onClose:p,buildingId:u,initialPosition:x}){const{t:n}=A(["config","common"]),y=na(),C=la(),g=ia(),v=ra(),s=u?y.get(u):null,h=u?g.get(u)||[]:[],a=!!s,[t,c]=m.useState(""),[i,f]=m.useState("server"),[b,z]=m.useState("server-rack"),[T,B]=m.useState(""),[$,R]=m.useState(""),[K,I]=m.useState(""),[H,O]=m.useState(""),[d,L]=m.useState(""),[q,V]=m.useState(""),[k,_]=m.useState(""),[M,l]=m.useState([]),[S,U]=m.useState(!1),[E,J]=m.useState(""),[W,ee]=m.useState(1),[Q,te]=m.useState(!1),[Ge,ne]=m.useState(""),[Ye,le]=m.useState(""),[Je,ie]=m.useState(""),[We,re]=m.useState(""),[Qe,oe]=m.useState(""),[Vs,ce]=m.useState(!1),[P,de]=m.useState("container"),[me,ue]=m.useState(""),[Ze,pe]=m.useState(""),[he,xe]=m.useState(""),[be,je]=m.useState([]),[ge,ve]=m.useState([]),[Xe,fe]=m.useState(""),[Ne,ke]=m.useState(""),[ye,Ce]=m.useState(""),[es,Se]=m.useState("unless-stopped"),[ss,we]=m.useState("missing"),[Pe,De]=m.useState(""),[Ee,Le]=m.useState(""),[ze,Be]=m.useState(""),[Ae,Te]=m.useState([]),[Gs,Ys]=m.useState(!1),[Re,Ie]=m.useState([]),[as,Oe]=m.useState(void 0),[ts,_e]=m.useState(""),[Me,Fe]=m.useState(""),[ns,$e]=m.useState(!1),[ls,Ke]=m.useState(""),is=m.useRef(null),Js=m.useRef(null),se=m.useRef(null);m.useEffect(()=>{var o,N,w,G,ds,ms,us,ps,hs,xs,bs,js,gs,vs,fs,Ns,ks,ys,Cs,Ss,ws,Ps,Ds,Es,Ls,zs,Bs,As,Ts,Rs,Is,Os,_s;r&&(s?(c(s.name),f(s.type),z(s.style||"server-rack"),B(s.color||""),R(s.cwd||""),I(((o=s.commands)==null?void 0:o.start)||""),O(((N=s.commands)==null?void 0:N.stop)||""),L(((w=s.commands)==null?void 0:w.restart)||""),V(((G=s.commands)==null?void 0:G.healthCheck)||""),_(((ds=s.commands)==null?void 0:ds.logs)||""),l(s.urls||[]),J(s.folderPath||""),ee(s.scale||1),te(((ms=s.pm2)==null?void 0:ms.enabled)||!1),ne(((us=s.pm2)==null?void 0:us.script)||""),le(((ps=s.pm2)==null?void 0:ps.args)||""),ie(((hs=s.pm2)==null?void 0:hs.interpreter)||""),re(((xs=s.pm2)==null?void 0:xs.interpreterArgs)||""),oe((bs=s.pm2)!=null&&bs.env?Object.entries(s.pm2.env).map(([Y,He])=>`${Y}=${He}`).join(`
5
+ NODE_ENV=production`,rows:3})]})]}),V&&(k==null?void 0:k.dockerStatus)&&e.jsxs("div",{className:"docker-status-display",children:[e.jsxs("div",{className:"docker-status-row",children:[e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"ID"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.containerId||"-"})]}),e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"Status"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.status||"-"})]}),k.dockerStatus.health&&k.dockerStatus.health!=="none"&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"Health"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.health})]}),k.dockerStatus.cpu!==void 0&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"CPU"}),e.jsxs("span",{className:"docker-metric-value",children:[k.dockerStatus.cpu.toFixed(1),"%"]})]}),k.dockerStatus.memory!==void 0&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"MEM"}),e.jsxs("span",{className:"docker-metric-value",children:[Ve(k.dockerStatus.memory),k.dockerStatus.memoryLimit?` / ${Ve(k.dockerStatus.memoryLimit)}`:""]})]})]}),k.dockerStatus.ports&&k.dockerStatus.ports.length>0&&e.jsxs("div",{className:"docker-ports-row",children:[e.jsx("span",{className:"docker-metric-label",children:"Ports:"}),k.dockerStatus.ports.map((l,S)=>e.jsxs("a",{href:`http://${window.location.hostname}:${l.host}`,target:"_blank",rel:"noopener noreferrer",className:"docker-port-link",children:[l.host,":",l.container,"/",l.protocol]},S))]}),k.dockerStatus.services&&k.dockerStatus.services.length>0&&e.jsxs("div",{className:"docker-services-status",children:[e.jsx("span",{className:"docker-metric-label",children:"Services:"}),e.jsx("div",{className:"docker-services-grid",children:k.dockerStatus.services.map((l,S)=>e.jsxs("div",{className:"docker-service-item",children:[e.jsx("span",{className:"docker-service-indicator",style:{backgroundColor:l.status==="running"?"#4ade80":"#f87171"}}),e.jsx("span",{className:"docker-service-name",children:l.name}),e.jsx("span",{className:"docker-service-status",children:l.status})]},S))})]})]}),V&&e.jsxs("div",{className:"docker-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>_("start"),children:"Start"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>_("stop"),children:"Stop"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>_("restart"),children:"Restart"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_("logs"),children:"Logs"})]})]})}const ga={enabled:!1,host:"",port:22,username:"",authMethod:"password"};function va({dbConnections:o,setDbConnections:p,activeDbConnectionId:u,setActiveDbConnectionId:x}){const{t:n}=A(["terminal","common"]),[y,C]=m.useState({}),g=m.useRef(new Map);m.useEffect(()=>{const a=t=>{const c=t.detail;if(!c||!c.requestId)return;const i=g.current.get(c.requestId);i&&(g.current.delete(c.requestId),C(f=>({...f,[i]:c.success?{status:"success",serverVersion:c.serverVersion}:{status:"error",error:c.error||"Connection failed"}})))};return window.addEventListener("tide:db-test-result",a),()=>window.removeEventListener("tide:db-test-result",a)},[]);const v=(a,t)=>{const c=[...o];c[a]={...c[a],...t},p(c)},s=(a,t)=>{const i={...o[a].ssh??ga,...t};v(a,{ssh:i})},h=a=>{const t=`test_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;g.current.set(t,a.id),C(c=>({...c,[a.id]:{status:"testing"}})),D.testDatabaseConnectionTransient(t,a),window.setTimeout(()=>{g.current.has(t)&&(g.current.delete(t),C(c=>{const i=c[a.id];return(i==null?void 0:i.status)!=="testing"?c:{...c,[a.id]:{status:"error",error:"Test connection timed out after 30s"}}}))},3e4)};return e.jsxs("div",{className:"form-section database-config-section",children:[e.jsxs("label",{className:"form-label",children:[n("terminal:building.dbConnections"),e.jsx(j,{text:n("terminal:building.helpDbConnections"),title:n("terminal:building.dbConnections"),position:"top",size:"sm"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>{const a={id:`conn_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,name:`Connection ${o.length+1}`,engine:"mysql",host:"localhost",port:3306,username:"root"};p([...o,a]),u||x(a.id)},children:n("terminal:database.addConnection")})]}),o.length===0&&e.jsx("div",{className:"form-hint",children:n("terminal:building.dbGetStarted")}),o.map((a,t)=>{var f,b,z,T,B,$,R,K,I,H,O;const c=y[a.id]??{status:"idle"},i=((f=a.ssh)==null?void 0:f.enabled)===!0;return e.jsxs("div",{className:"db-connection-card",children:[e.jsxs("div",{className:"db-connection-header",children:[e.jsxs("label",{className:"db-connection-active",children:[e.jsx("input",{type:"radio",name:"activeConnection",checked:u===a.id,onChange:()=>x(a.id)}),n("common:labels.default"),e.jsx(j,{text:n("terminal:building.helpDbDefault"),position:"top",size:"sm"})]}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>{const d=o.filter(L=>L.id!==a.id);p(d),u===a.id&&d.length>0?x(d[0].id):d.length===0&&x(void 0)},children:n("common:buttons.remove")})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("common:labels.name")}),e.jsx("input",{type:"text",className:"form-input",value:a.name,onChange:d=>v(t,{name:d.target.value}),placeholder:"My Database"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:n("terminal:building.dbEngine")}),e.jsx("select",{className:"form-input form-select",value:a.engine,onChange:d=>{const L=d.target.value;v(t,{engine:L,port:Q[L].defaultPort})},children:Object.keys(Q).map(d=>e.jsxs("option",{value:d,children:[Q[d].icon," ",Q[d].label]},d))})]})]}),a.engine==="sqlite"?e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:n("terminal:building.dbFilepath")}),e.jsx("input",{type:"text",className:"form-input",value:a.filepath||"",onChange:d=>v(t,{filepath:d.target.value||void 0}),placeholder:"/path/to/database.db"})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:[n("terminal:building.dbHost"),i&&e.jsx(j,{text:"Host as seen FROM the SSH server (often 'localhost' or 127.0.0.1).",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:a.host,onChange:d=>v(t,{host:d.target.value}),placeholder:i?"127.0.0.1":"localhost"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:n("terminal:building.dbPort")}),e.jsx("input",{type:"number",className:"form-input",value:a.port,onChange:d=>v(t,{port:parseInt(d.target.value)||Q[a.engine].defaultPort})})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("terminal:building.dbUsername")}),e.jsx("input",{type:"text",className:"form-input",value:a.username,onChange:d=>v(t,{username:d.target.value}),placeholder:"root"})]}),e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("terminal:building.dbPassword")}),e.jsx("input",{type:"password",className:"form-input",value:a.password||"",onChange:d=>v(t,{password:d.target.value||void 0}),placeholder:"Optional",autoComplete:"off"})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:n("terminal:building.dbDefaultDatabase")}),e.jsx("input",{type:"text",className:"form-input",value:a.database||"",onChange:d=>v(t,{database:d.target.value||void 0}),placeholder:"Optional - select after connecting"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsxs("label",{children:["SSL",e.jsx(j,{text:n("terminal:building.helpDbSsl"),position:"top",size:"sm"})]}),e.jsxs("label",{className:"toggle-switch toggle-switch--small",children:[e.jsx("input",{type:"checkbox",checked:a.ssl||!1,onChange:d=>v(t,{ssl:d.target.checked})}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})})]})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsx("div",{className:"db-field db-field--grow",children:e.jsxs("label",{children:["SSH Tunnel",e.jsx(j,{text:"Forward DB traffic through an SSH jump host. Required when the DB is only reachable from inside a private network.",position:"top",size:"sm"})]})}),e.jsx("div",{className:"db-field db-field--small",children:e.jsxs("label",{className:"toggle-switch toggle-switch--small",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:d=>s(t,{enabled:d.target.checked})}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})})]})})]}),i&&e.jsxs("div",{className:"db-ssh-subsection",children:[e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Host"}),e.jsx("input",{type:"text",className:"form-input",value:((b=a.ssh)==null?void 0:b.host)||"",onChange:d=>s(t,{host:d.target.value}),placeholder:"bastion.example.com"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:"SSH Port"}),e.jsx("input",{type:"number",className:"form-input",value:((z=a.ssh)==null?void 0:z.port)||22,onChange:d=>s(t,{port:parseInt(d.target.value)||22})})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Username"}),e.jsx("input",{type:"text",className:"form-input",value:((T=a.ssh)==null?void 0:T.username)||"",onChange:d=>s(t,{username:d.target.value}),placeholder:"ubuntu"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:"Auth Method"}),e.jsxs("select",{className:"form-input form-select",value:((B=a.ssh)==null?void 0:B.authMethod)||"password",onChange:d=>s(t,{authMethod:d.target.value}),children:[e.jsx("option",{value:"password",children:"Password"}),e.jsx("option",{value:"privateKey",children:"Private Key"})]})]})]}),((($=a.ssh)==null?void 0:$.authMethod)||"password")==="password"?e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Password"}),e.jsx("input",{type:"password",className:"form-input",value:((R=a.ssh)==null?void 0:R.password)||"",onChange:d=>s(t,{password:d.target.value||void 0}),placeholder:"SSH password",autoComplete:"off"})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:["Private Key Path",e.jsx(j,{text:"Path to a private key file on the server, e.g. ~/.ssh/id_rsa. Use this OR paste the key contents below.",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:((K=a.ssh)==null?void 0:K.privateKeyPath)||"",onChange:d=>s(t,{privateKeyPath:d.target.value||void 0}),placeholder:"/home/user/.ssh/id_rsa"})]})}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:["Private Key Contents (PEM)",e.jsx(j,{text:"Paste the full private key contents inline. Encrypted at rest.",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input",value:((I=a.ssh)==null?void 0:I.privateKey)||"",onChange:d=>s(t,{privateKey:d.target.value||void 0}),placeholder:"-----BEGIN OPENSSH PRIVATE KEY-----\\n...",rows:4,style:{fontFamily:"monospace",fontSize:12}})]})}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"Key Passphrase (optional)"}),e.jsx("input",{type:"password",className:"form-input",value:((H=a.ssh)==null?void 0:H.passphrase)||"",onChange:d=>s(t,{passphrase:d.target.value||void 0}),placeholder:"If your key is encrypted",autoComplete:"off"})]})})]}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--small",children:[e.jsxs("label",{children:["Local Port",e.jsx(j,{text:"Optional fixed local forwarded port. Leave blank to auto-assign.",position:"top",size:"sm"})]}),e.jsx("input",{type:"number",className:"form-input",value:((O=a.ssh)==null?void 0:O.localPort)??"",onChange:d=>{const L=d.target.value.trim();s(t,{localPort:L?parseInt(L):void 0})},placeholder:"auto"})]})})]}),e.jsxs("div",{className:"db-connection-row",style:{alignItems:"center",gap:8},children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-primary",disabled:c.status==="testing",onClick:()=>h(a),children:c.status==="testing"?"Testing…":"Test Connection"}),c.status==="success"&&e.jsxs("span",{style:{color:"#4aff9e",fontSize:12},children:["✓ Connected",c.serverVersion?` — ${c.serverVersion}`:""]}),c.status==="error"&&e.jsxs("span",{style:{color:"#ff6b6b",fontSize:12},title:c.error,children:["✗ ",c.error]})]})]})]},a.id)}),o.length>0&&e.jsx("div",{className:"form-hint",children:n("terminal:building.dbAfterSaving")})]})}function fa({buildings:o,buildingId:p,subordinateBuildingIds:u,setSubordinateBuildingIds:x,isEditMode:n,showBossLogs:y,setShowBossLogs:C,currentBossLogs:g,bossLogsContainerRef:v}){const{t:s}=A(["terminal","common"]);return e.jsxs("div",{className:"form-section boss-building-section",children:[e.jsxs("label",{className:"form-label",children:[s("terminal:building.managedBuildings"),e.jsx(j,{text:s("terminal:building.helpManagedBuildings"),title:s("terminal:building.managedBuildings"),position:"top",size:"sm"})]}),e.jsx("div",{className:"form-hint",children:s("terminal:building.managedBuildingsHint")}),e.jsxs("div",{className:"subordinate-buildings-list",children:[Array.from(o.values()).filter(h=>h.id!==p&&h.type!=="boss"&&h.type!=="link"&&h.type!=="folder").map(h=>e.jsxs("label",{className:"subordinate-building-item",children:[e.jsx("input",{type:"checkbox",checked:u.includes(h.id),onChange:a=>{a.target.checked?x([...u,h.id]):x(u.filter(t=>t!==h.id))}}),e.jsx("span",{className:"subordinate-building-icon",children:e.jsx(F,{name:Us(h.type),size:14})}),e.jsx("span",{className:"subordinate-building-name",children:h.name}),e.jsx("span",{className:"subordinate-building-status",style:{backgroundColor:qe[h.status]}})]},h.id)),Array.from(o.values()).filter(h=>h.id!==p&&h.type!=="boss"&&h.type!=="link"&&h.type!=="folder").length===0&&e.jsx("div",{className:"form-hint no-buildings-hint",children:s("terminal:building.noManageableBuildings")})]}),n&&u.length>0&&e.jsxs("div",{className:"boss-building-actions",children:[e.jsxs("div",{className:"boss-actions-header",children:[s("terminal:building.bulkActions"),e.jsx(j,{text:s("terminal:building.helpBulkActions"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"boss-actions-row",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>D.sendBossBuildingCommand(p,"start_all"),children:s("terminal:building.startAll")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>D.sendBossBuildingCommand(p,"stop_all"),children:s("terminal:building.stopAll")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>D.sendBossBuildingCommand(p,"restart_all"),children:s("terminal:building.restartAll")}),e.jsx("button",{type:"button",className:`btn btn-sm ${y?"btn-primary":""}`,onClick:()=>{y?(D.stopBossLogStreaming(p),C(!1)):(D.startBossLogStreaming(p),C(!0))},children:s(y?"terminal:building.hideLogs":"terminal:building.unifiedLogs")})]}),e.jsxs("div",{className:"boss-subordinates-status",children:[e.jsx("div",{className:"boss-status-header",children:s("terminal:building.statusOverview")}),e.jsx("div",{className:"boss-status-grid",children:u.map(h=>{const a=o.get(h);return a?e.jsxs("div",{className:"boss-status-item",children:[e.jsx("span",{className:"boss-status-indicator",style:{backgroundColor:qe[a.status]}}),e.jsx("span",{className:"boss-status-name",children:a.name}),e.jsx("span",{className:"boss-status-label",children:a.status})]},h):null})})]})]}),n&&y&&e.jsxs("div",{className:"form-section boss-logs-section",children:[e.jsxs("label",{className:"form-label",children:[s("terminal:building.unifiedLogs"),e.jsx(j,{text:s("terminal:building.helpUnifiedLogs"),position:"top",size:"sm"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.clearBossStreamingLogs(p),children:s("common:buttons.clear")})]}),e.jsxs("div",{className:"boss-logs-container",ref:v,children:[g.map((h,a)=>e.jsxs("div",{className:"boss-log-entry",children:[e.jsxs("span",{className:"boss-log-source",children:["[",h.subordinateName,"]"]}),e.jsx("span",{className:"boss-log-content",children:qs(h.chunk)})]},a)),g.length===0&&e.jsx("div",{className:"boss-logs-empty",children:s("terminal:building.waitingForLogs")})]})]})]})}function Na({startCmd:o,setStartCmd:p,stopCmd:u,setStopCmd:x,restartCmd:n,setRestartCmd:y,healthCheckCmd:C,setHealthCheckCmd:g,logsCmd:v,setLogsCmd:s,isEditMode:h,handleCommand:a}){const{t}=A(["terminal","common"]);return e.jsxs("div",{className:"form-section commands-section",children:[e.jsxs("label",{className:"form-label",children:[t("terminal:building.commands"),e.jsx(j,{text:t("terminal:building.helpCommands"),title:t("terminal:building.commands"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"command-inputs",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdStart"),e.jsx(j,{text:t("terminal:building.helpCmdStart"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:o,onChange:c=>p(c.target.value),placeholder:"npm run dev"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>a("start"),disabled:!o,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdStop"),e.jsx(j,{text:t("terminal:building.helpCmdStop"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:c=>x(c.target.value),placeholder:"pkill -f 'npm run dev'"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a("stop"),disabled:!u,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdRestart"),e.jsx(j,{text:t("terminal:building.helpCmdRestart"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:c=>y(c.target.value),placeholder:"npm run restart"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>a("restart"),disabled:!n,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdHealthCheck"),e.jsx(j,{text:t("terminal:building.helpCmdHealthCheck"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:c=>g(c.target.value),placeholder:"curl -s http://localhost:3000/health"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>a("healthCheck"),disabled:!C,children:t("terminal:building.check")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdLogs"),e.jsx(j,{text:t("terminal:building.helpCmdLogs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:v,onChange:c=>s(c.target.value),placeholder:"tail -n 100 /var/log/app.log"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>a("logs"),children:t("terminal:building.fetch")})]})]})]})}const ka=[{value:"",label:"Default ($SHELL)"},{value:"/bin/bash",label:"Bash"},{value:"/bin/zsh",label:"Zsh"},{value:"/usr/bin/fish",label:"Fish"},{value:"/bin/sh",label:"sh"}];function ya({terminalShell:o,setTerminalShell:p,terminalPort:u,setTerminalPort:x,terminalSaveSession:n,setTerminalSaveSession:y,terminalArgs:C,setTerminalArgs:g,isEditMode:v,building:s,handleCommand:h,onOpenTerminal:a,onOpenBelow:t}){const{t:c}=A(["config"]),i=(s==null?void 0:s.status)==="running",f=s==null?void 0:s.terminalStatus;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:c("config:buildings.terminalConfig",{defaultValue:"Terminal Configuration"})}),e.jsxs("div",{className:"form-row",children:[e.jsxs("div",{className:"form-field",children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalShell",{defaultValue:"Shell"})}),e.jsx("select",{className:"form-input",value:o,onChange:b=>p(b.target.value),children:ka.map(b=>e.jsx("option",{value:b.value,children:b.label},b.value))})]}),e.jsxs("div",{className:"form-field",children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalPort",{defaultValue:"Port"})}),e.jsx("input",{type:"number",className:"form-input",value:u,onChange:b=>x(b.target.value),placeholder:"Auto",min:1024,max:65535})]})]}),e.jsx("div",{className:"form-row",style:{marginTop:"8px"},children:e.jsxs("label",{className:"form-checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:b=>y(b.target.checked)}),e.jsx("span",{children:c("config:buildings.terminalSaveSession",{defaultValue:"Persist session (tmux)"})})]})}),e.jsxs("div",{style:{marginTop:"8px"},children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalArgs",{defaultValue:"Extra ttyd args"})}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:b=>g(b.target.value),placeholder:"--client-option titleFixed=Terminal"}),e.jsx("div",{className:"form-hint",children:"Additional command-line arguments passed to ttyd"})]})]}),v&&s&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:c("config:buildings.terminalControls",{defaultValue:"Terminal Controls"})}),f&&e.jsxs("div",{className:"building-runtime-info",children:[e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Proxy"}),e.jsx("span",{className:"runtime-value",style:{color:"#4a9eff"},children:f.url})]}),e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"PID"}),e.jsx("span",{className:"runtime-value",children:f.pid})]}),e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Port"}),e.jsx("span",{className:"runtime-value",children:f.port})]}),f.tmuxSession&&e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Session"}),e.jsx("span",{className:"runtime-value",children:f.tmuxSession})]})]}),e.jsxs("div",{className:"building-actions",style:{marginTop:"8px"},children:[!i&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>h("start"),children:[e.jsx(F,{name:"play",size:12})," Start"]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>h("restart"),children:[e.jsx(F,{name:"refresh",size:12})," Restart"]}),e.jsxs("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>h("stop"),children:[e.jsx(F,{name:"stop",size:12})," Stop"]}),(f==null?void 0:f.url)&&e.jsxs(e.Fragment,{children:[a&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-primary",onClick:()=>a(f.url),children:[e.jsx(F,{name:"desktop",size:12})," Modal"]}),t&&s&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-primary",onClick:()=>t(s.id),children:[e.jsx(F,{name:"arrow-down",size:12})," Below"]})]})]})]})]})]})}function Ca({logs:o,buildingId:p,logsContainerRef:u}){return e.jsxs("div",{className:"form-section logs-section",children:[e.jsxs("label",{className:"form-label",children:["Logs",e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.clearBuildingLogs(p),children:"Clear"})]}),e.jsx("div",{className:"logs-container",ref:u,children:o.map((x,n)=>e.jsx("pre",{className:"log-entry",children:qs(x)},n))})]})}function Da({isOpen:o,onClose:p,buildingId:u,initialPosition:x}){const{t:n}=A(["config","common"]),y=na(),C=la(),g=ia(),v=oa(),s=u?y.get(u):null,h=u?g.get(u)||[]:[],a=!!s,[t,c]=m.useState(""),[i,f]=m.useState("server"),[b,z]=m.useState("server-rack"),[T,B]=m.useState(""),[$,R]=m.useState(""),[K,I]=m.useState(""),[H,O]=m.useState(""),[d,L]=m.useState(""),[q,V]=m.useState(""),[k,_]=m.useState(""),[M,l]=m.useState([]),[S,U]=m.useState(!1),[E,J]=m.useState(""),[W,ee]=m.useState(1),[Z,te]=m.useState(!1),[Ge,ne]=m.useState(""),[Ye,le]=m.useState(""),[Je,ie]=m.useState(""),[We,oe]=m.useState(""),[Ze,re]=m.useState(""),[Vs,ce]=m.useState(!1),[P,de]=m.useState("container"),[me,ue]=m.useState(""),[Qe,pe]=m.useState(""),[he,xe]=m.useState(""),[be,je]=m.useState([]),[ge,ve]=m.useState([]),[Xe,fe]=m.useState(""),[Ne,ke]=m.useState(""),[ye,Ce]=m.useState(""),[es,Se]=m.useState("unless-stopped"),[ss,we]=m.useState("missing"),[Pe,De]=m.useState(""),[Ee,Le]=m.useState(""),[ze,Be]=m.useState(""),[Ae,Te]=m.useState([]),[Gs,Ys]=m.useState(!1),[Re,Ie]=m.useState([]),[as,Oe]=m.useState(void 0),[ts,_e]=m.useState(""),[Me,Fe]=m.useState(""),[ns,$e]=m.useState(!1),[ls,Ke]=m.useState(""),is=m.useRef(null),Js=m.useRef(null),se=m.useRef(null);m.useEffect(()=>{var r,N,w,G,ds,ms,us,ps,hs,xs,bs,js,gs,vs,fs,Ns,ks,ys,Cs,Ss,ws,Ps,Ds,Es,Ls,zs,Bs,As,Ts,Rs,Is,Os,_s;o&&(s?(c(s.name),f(s.type),z(s.style||"server-rack"),B(s.color||""),R(s.cwd||""),I(((r=s.commands)==null?void 0:r.start)||""),O(((N=s.commands)==null?void 0:N.stop)||""),L(((w=s.commands)==null?void 0:w.restart)||""),V(((G=s.commands)==null?void 0:G.healthCheck)||""),_(((ds=s.commands)==null?void 0:ds.logs)||""),l(s.urls||[]),J(s.folderPath||""),ee(s.scale||1),te(((ms=s.pm2)==null?void 0:ms.enabled)||!1),ne(((us=s.pm2)==null?void 0:us.script)||""),le(((ps=s.pm2)==null?void 0:ps.args)||""),ie(((hs=s.pm2)==null?void 0:hs.interpreter)||""),oe(((xs=s.pm2)==null?void 0:xs.interpreterArgs)||""),re((bs=s.pm2)!=null&&bs.env?Object.entries(s.pm2.env).map(([Y,He])=>`${Y}=${He}`).join(`
6
6
  `):""),de(((js=s.docker)==null?void 0:js.mode)||"container"),ue(((gs=s.docker)==null?void 0:gs.mode)==="existing"&&((vs=s.docker)==null?void 0:vs.containerName)||""),pe(((fs=s.docker)==null?void 0:fs.image)||""),xe(((Ns=s.docker)==null?void 0:Ns.containerName)||""),je(((ks=s.docker)==null?void 0:ks.ports)||[]),ve(((ys=s.docker)==null?void 0:ys.volumes)||[]),fe((Cs=s.docker)!=null&&Cs.env?Object.entries(s.docker.env).map(([Y,He])=>`${Y}=${He}`).join(`
7
- `):""),ke(((Ss=s.docker)==null?void 0:Ss.network)||""),Ce(((ws=s.docker)==null?void 0:ws.command)||""),Se(((Ps=s.docker)==null?void 0:Ps.restart)||"unless-stopped"),we(((Ds=s.docker)==null?void 0:Ds.pull)||"missing"),De(((Es=s.docker)==null?void 0:Es.composePath)||""),Le(((Ls=s.docker)==null?void 0:Ls.composeProject)||""),Be(((Bs=(zs=s.docker)==null?void 0:zs.services)==null?void 0:Bs.join(", "))||""),Te(s.subordinateBuildingIds||[]),Ie(((As=s.database)==null?void 0:As.connections)||[]),Oe((Ts=s.database)==null?void 0:Ts.activeConnectionId),_e(((Rs=s.terminal)==null?void 0:Rs.shell)||""),Fe((Is=s.terminal)!=null&&Is.port?String(s.terminal.port):""),$e(((Os=s.terminal)==null?void 0:Os.saveSession)||!1),Ke(((_s=s.terminal)==null?void 0:_s.args)||"")):(c("New Server"),f("server"),z("server-rack"),B(""),R(oa(ca.LAST_CWD)),I(""),O(""),L(""),V(""),_(""),l([]),J(""),ee(1),te(!1),ne(""),le(""),ie(""),re(""),oe(""),de("container"),ue(""),pe(""),xe(""),je([]),ve([]),fe(""),ke(""),Ce(""),Se("unless-stopped"),we("missing"),De(""),Le(""),Be(""),Te([]),Ie([]),Oe(void 0),_e(""),Fe(""),$e(!1),Ke("")),setTimeout(()=>{var Y;return(Y=is.current)==null?void 0:Y.focus()},100))},[r,s]),m.useEffect(()=>{se.current&&(se.current.scrollTop=se.current.scrollHeight)},[C]),m.useEffect(()=>{i==="docker"&&P==="existing"&&D.requestDockerContainersList()},[i,P]);const rs=o=>{if(o.trim())return Object.fromEntries(o.trim().split(`
8
- `).map(N=>N.trim()).filter(N=>N&&N.includes("=")).map(N=>{const w=N.indexOf("=");return[N.slice(0,w),N.slice(w+1)]}))},Ws=o=>{o.preventDefault();const N={name:t,type:i,style:b,color:T||void 0,position:x||(s==null?void 0:s.position)||{x:0,z:0},cwd:$||void 0,folderPath:E||void 0,commands:Q?void 0:{start:K||void 0,stop:H||void 0,restart:d||void 0,healthCheck:q||void 0,logs:k||void 0},pm2:Q?{enabled:!0,script:Ge,args:Ye||void 0,interpreter:Je||void 0,interpreterArgs:We||void 0,env:rs(Qe)}:void 0,docker:i==="docker"?{enabled:!0,mode:P,image:P==="container"?Ze:void 0,containerName:P==="container"&&he?he:P==="existing"&&me?me:void 0,ports:P==="container"&&be.length>0?be:void 0,volumes:P==="container"&&ge.length>0?ge:void 0,env:rs(Xe),network:P==="container"&&Ne?Ne:void 0,command:P==="container"&&ye?ye:void 0,restart:P==="container"?es:void 0,pull:P!=="existing"?ss:void 0,composePath:P==="compose"&&Pe?Pe:void 0,composeProject:P==="compose"&&Ee?Ee:void 0,services:P==="compose"&&ze?ze.split(",").map(w=>w.trim()).filter(w=>w):void 0}:void 0,urls:M.length>0?M:void 0,scale:W!==1?W:void 0,subordinateBuildingIds:i==="boss"&&Ae.length>0?Ae:void 0,database:i==="database"&&Re.length>0?{connections:Re,activeConnectionId:as}:void 0,terminal:i==="terminal"?{enabled:!0,shell:ts||void 0,port:Me?parseInt(Me,10):void 0,saveSession:ns||void 0,args:ls||void 0}:void 0};a&&u?D.updateBuilding(u,N):D.createBuilding(N),p()},Qs=()=>{ce(!0)},Zs=()=>{u&&(D.deleteBuilding(u),ce(!1),p())},ae=o=>{u&&(D.sendBuildingCommand(u,o),o==="logs"&&U(!0))},Xs=()=>{l([...M,{label:"",url:""}])},ea=o=>{l(M.filter((N,w)=>w!==o))},os=(o,N,w)=>{const G=[...M];G[o]={...G[o],[N]:w},l(G)},{handleMouseDown:sa,handleClick:aa}=da(p);if(!r)return null;const cs=u?D.getBuildingLogs(u):[];return e.jsxs("div",{className:"modal-overlay visible",onMouseDown:sa,onClick:aa,children:[e.jsxs("div",{className:"modal building-config-modal",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("span",{children:n(a?"config:buildings.editBuilding":"config:buildings.addBuilding")}),a&&s&&e.jsx("span",{className:"building-status-badge",style:{backgroundColor:qe[s.status]},children:s.status})]}),e.jsxs("form",{onSubmit:Ws,children:[e.jsxs("div",{className:"modal-body",children:[e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.name")}),e.jsx("input",{ref:is,type:"text",className:"form-input",value:t,onChange:o=>c(o.target.value),placeholder:n("config:buildings.namePlaceholder"),required:!0})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.type")}),e.jsx("div",{className:"building-type-selector",children:Object.keys(Ks).map(o=>e.jsxs("button",{type:"button",className:`building-type-btn ${i===o?"active":""}`,onClick:()=>{f(o),o==="database"&&b==="server-rack"&&z("filing-cabinet"),o==="tests"&&b==="server-rack"&&z("dome"),o==="http"&&b==="server-rack"&&z("satellite")},title:Ks[o].description,children:[e.jsx("span",{className:"building-type-icon",children:e.jsx(F,{name:Us(o),size:16})}),e.jsx("span",{className:"building-type-name",children:o})]},o))})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("config:buildings.style")}),e.jsx("div",{className:"building-style-selector",children:Object.keys(Ue).map(o=>e.jsxs("button",{type:"button",className:`building-style-btn ${b===o?"active":""}`,onClick:()=>z(o),title:Ue[o].description,children:[e.jsx("span",{className:"building-style-preview","data-style":o}),e.jsx("span",{className:"building-style-name",children:Ue[o].label})]},o))})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.color")}),e.jsxs("div",{className:"building-color-selector",children:[ma.map(o=>e.jsx("button",{type:"button",className:`building-color-btn ${T===o.value?"active":""}`,onClick:()=>B(o.value),title:ua(o.labelKey),style:o.value?{backgroundColor:o.value}:void 0,children:!o.value&&e.jsx("span",{className:"color-default-icon",children:e.jsx(F,{name:"gear",size:12})})},o.value||"default")),e.jsx("input",{type:"color",className:"building-color-picker",value:T||"#2a2a3a",onChange:o=>B(o.target.value),title:"Custom color"})]})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.size")}),e.jsxs("div",{className:"building-size-control",children:[e.jsxs("div",{className:"size-slider-row",children:[e.jsx("input",{type:"range",className:"size-slider",min:"0",max:"100",step:"1",value:Math.log(W/.1)/Math.log(100)*100,onChange:o=>{const N=parseFloat(o.target.value),w=.1*Math.pow(100,N/100);ee(Math.round(w*100)/100)}}),e.jsxs("span",{className:"size-value",children:[W.toFixed(2),"x"]})]}),e.jsx("div",{className:"size-presets",children:[.5,.75,1,1.25,1.5,2].map(o=>e.jsxs("button",{type:"button",className:`size-preset-btn ${W===o?"active":""}`,onClick:()=>ee(o),children:[o,"x"]},o))})]})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("config:buildings.directory")}),e.jsx(X,{value:$,onChange:R,placeholder:"/path/to/project",className:"form-input",directoriesOnly:!0})]}),i==="folder"&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("config:buildings.folderPath")}),e.jsx(X,{value:E,onChange:J,placeholder:"/path/to/folder",className:"form-input",directoriesOnly:!0}),e.jsx("div",{className:"form-hint",children:"Click this building to open the file explorer at this path"})]}),i==="tests"&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:"Tests Folder"}),e.jsx(X,{value:E,onChange:J,placeholder:"/path/to/project/src/test",className:"form-input",directoriesOnly:!0}),e.jsx("div",{className:"form-hint",children:"Click this building to browse, search and run the tests of this folder (any folder inside a Maven module works)"})]}),i==="http"&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:"Requests Folder"}),e.jsx(X,{value:E,onChange:J,placeholder:"/path/to/project/http-requests",className:"form-input",directoriesOnly:!0}),e.jsx("div",{className:"form-hint",children:"Click this building to browse and fire the .http request files of this folder (IntelliJ HTTP Client style; http-client.env.json environments supported)"})]}),i==="boss"&&e.jsx(fa,{buildings:y,buildingId:u,subordinateBuildingIds:Ae,setSubordinateBuildingIds:Te,isEditMode:a,showBossLogs:Gs,setShowBossLogs:Ys,currentBossLogs:h,bossLogsContainerRef:Js}),i==="database"&&e.jsx(va,{dbConnections:Re,setDbConnections:Ie,activeDbConnectionId:as,setActiveDbConnectionId:Oe}),i==="server"&&e.jsx(xa,{usePM2:Q,setUsePM2:te}),i==="server"&&e.jsx(ba,{usePM2:Q,pm2Script:Ge,setPm2Script:ne,pm2Args:Ye,setPm2Args:le,pm2Interpreter:Je,setPm2Interpreter:ie,pm2InterpreterArgs:We,setPm2InterpreterArgs:re,pm2Env:Qe,setPm2Env:oe,isEditMode:a,building:s??null,handleCommand:ae}),i==="docker"&&e.jsx(ja,{dockerMode:P,setDockerMode:de,dockerImage:Ze,setDockerImage:pe,dockerContainerName:he,setDockerContainerName:xe,dockerCommand:ye,setDockerCommand:Ce,dockerPorts:be,setDockerPorts:je,dockerVolumes:ge,setDockerVolumes:ve,dockerNetwork:Ne,setDockerNetwork:ke,dockerRestart:es,setDockerRestart:Se,dockerPull:ss,setDockerPull:we,dockerEnv:Xe,setDockerEnv:fe,dockerComposePath:Pe,setDockerComposePath:De,dockerComposeProject:Ee,setDockerComposeProject:Le,dockerComposeServices:ze,setDockerComposeServices:Be,selectedExistingContainer:me,setSelectedExistingContainer:ue,dockerContainersList:v,isEditMode:a,building:s??null,handleCommand:ae}),i==="terminal"&&e.jsx(ya,{terminalShell:ts,setTerminalShell:_e,terminalPort:Me,setTerminalPort:Fe,terminalSaveSession:ns,setTerminalSaveSession:$e,terminalArgs:ls,setTerminalArgs:Ke,isEditMode:a,building:s??null,handleCommand:ae,onOpenTerminal:()=>{s!=null&&s.id&&window.dispatchEvent(new CustomEvent("tide:open-iframe-modal",{detail:{buildingId:s.id}}))},onOpenBelow:o=>{window.dispatchEvent(new CustomEvent("tide:open-bottom-terminal",{detail:{buildingId:o}}))}}),i==="server"&&!Q&&e.jsx(Na,{startCmd:K,setStartCmd:I,stopCmd:H,setStopCmd:O,restartCmd:d,setRestartCmd:L,healthCheckCmd:q,setHealthCheckCmd:V,logsCmd:k,setLogsCmd:_,isEditMode:a,handleCommand:ae}),e.jsxs("div",{className:"form-section",children:[e.jsxs("label",{className:"form-label",children:[n("config:buildings.links"),e.jsxs("button",{type:"button",className:"btn btn-sm btn-add",onClick:Xs,children:["+ ",n("common:buttons.add")]})]}),M.map((o,N)=>e.jsxs("div",{className:"url-row",children:[e.jsx("input",{type:"text",className:"form-input url-label",value:o.label,onChange:w=>os(N,"label",w.target.value),placeholder:"Label"}),e.jsx("input",{type:"text",className:"form-input url-value",value:o.url,onChange:w=>os(N,"url",w.target.value),placeholder:"https://..."}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>ea(N),children:"x"})]},N))]}),a&&S&&cs.length>0&&e.jsx(Ca,{logs:cs,buildingId:u,logsContainerRef:se})]}),e.jsxs("div",{className:"modal-footer",children:[a&&e.jsx("button",{type:"button",className:"btn btn-danger",onClick:Qs,children:n("common:buttons.delete")}),e.jsx("div",{className:"footer-spacer"}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:p,children:n("common:buttons.cancel")}),e.jsx("button",{type:"submit",className:"btn btn-primary",children:n(a?"common:buttons.save":"common:buttons.create")})]})]})]}),Vs&&s&&e.jsx(ha,{buildingName:s.name,onClose:()=>ce(!1),onConfirm:Zs})]})}export{Da as BuildingConfigModal};
7
+ `):""),ke(((Ss=s.docker)==null?void 0:Ss.network)||""),Ce(((ws=s.docker)==null?void 0:ws.command)||""),Se(((Ps=s.docker)==null?void 0:Ps.restart)||"unless-stopped"),we(((Ds=s.docker)==null?void 0:Ds.pull)||"missing"),De(((Es=s.docker)==null?void 0:Es.composePath)||""),Le(((Ls=s.docker)==null?void 0:Ls.composeProject)||""),Be(((Bs=(zs=s.docker)==null?void 0:zs.services)==null?void 0:Bs.join(", "))||""),Te(s.subordinateBuildingIds||[]),Ie(((As=s.database)==null?void 0:As.connections)||[]),Oe((Ts=s.database)==null?void 0:Ts.activeConnectionId),_e(((Rs=s.terminal)==null?void 0:Rs.shell)||""),Fe((Is=s.terminal)!=null&&Is.port?String(s.terminal.port):""),$e(((Os=s.terminal)==null?void 0:Os.saveSession)||!1),Ke(((_s=s.terminal)==null?void 0:_s.args)||"")):(c("New Server"),f("server"),z("server-rack"),B(""),R(ra(ca.LAST_CWD)),I(""),O(""),L(""),V(""),_(""),l([]),J(""),ee(1),te(!1),ne(""),le(""),ie(""),oe(""),re(""),de("container"),ue(""),pe(""),xe(""),je([]),ve([]),fe(""),ke(""),Ce(""),Se("unless-stopped"),we("missing"),De(""),Le(""),Be(""),Te([]),Ie([]),Oe(void 0),_e(""),Fe(""),$e(!1),Ke("")),setTimeout(()=>{var Y;return(Y=is.current)==null?void 0:Y.focus()},100))},[o,s]),m.useEffect(()=>{se.current&&(se.current.scrollTop=se.current.scrollHeight)},[C]),m.useEffect(()=>{i==="docker"&&P==="existing"&&D.requestDockerContainersList()},[i,P]);const os=r=>{if(r.trim())return Object.fromEntries(r.trim().split(`
8
+ `).map(N=>N.trim()).filter(N=>N&&N.includes("=")).map(N=>{const w=N.indexOf("=");return[N.slice(0,w),N.slice(w+1)]}))},Ws=r=>{r.preventDefault();const N={name:t,type:i,style:b,color:T||void 0,position:x||(s==null?void 0:s.position)||{x:0,z:0},cwd:$||void 0,folderPath:E||void 0,commands:Z?void 0:{start:K||void 0,stop:H||void 0,restart:d||void 0,healthCheck:q||void 0,logs:k||void 0},pm2:Z?{enabled:!0,script:Ge,args:Ye||void 0,interpreter:Je||void 0,interpreterArgs:We||void 0,env:os(Ze)}:void 0,docker:i==="docker"?{enabled:!0,mode:P,image:P==="container"?Qe:void 0,containerName:P==="container"&&he?he:P==="existing"&&me?me:void 0,ports:P==="container"&&be.length>0?be:void 0,volumes:P==="container"&&ge.length>0?ge:void 0,env:os(Xe),network:P==="container"&&Ne?Ne:void 0,command:P==="container"&&ye?ye:void 0,restart:P==="container"?es:void 0,pull:P!=="existing"?ss:void 0,composePath:P==="compose"&&Pe?Pe:void 0,composeProject:P==="compose"&&Ee?Ee:void 0,services:P==="compose"&&ze?ze.split(",").map(w=>w.trim()).filter(w=>w):void 0}:void 0,urls:M.length>0?M:void 0,scale:W!==1?W:void 0,subordinateBuildingIds:i==="boss"&&Ae.length>0?Ae:void 0,database:i==="database"&&Re.length>0?{connections:Re,activeConnectionId:as}:void 0,terminal:i==="terminal"?{enabled:!0,shell:ts||void 0,port:Me?parseInt(Me,10):void 0,saveSession:ns||void 0,args:ls||void 0}:void 0};a&&u?D.updateBuilding(u,N):D.createBuilding(N),p()},Zs=()=>{ce(!0)},Qs=()=>{u&&(D.deleteBuilding(u),ce(!1),p())},ae=r=>{u&&(D.sendBuildingCommand(u,r),r==="logs"&&U(!0))},Xs=()=>{l([...M,{label:"",url:""}])},ea=r=>{l(M.filter((N,w)=>w!==r))},rs=(r,N,w)=>{const G=[...M];G[r]={...G[r],[N]:w},l(G)},{handleMouseDown:sa,handleClick:aa}=da(p);if(!o)return null;const cs=u?D.getBuildingLogs(u):[];return e.jsxs("div",{className:"modal-overlay visible",onMouseDown:sa,onClick:aa,children:[e.jsxs("div",{className:"modal building-config-modal",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("span",{children:n(a?"config:buildings.editBuilding":"config:buildings.addBuilding")}),a&&s&&e.jsx("span",{className:"building-status-badge",style:{backgroundColor:qe[s.status]},children:s.status})]}),e.jsxs("form",{onSubmit:Ws,children:[e.jsxs("div",{className:"modal-body",children:[e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.name")}),e.jsx("input",{ref:is,type:"text",className:"form-input",value:t,onChange:r=>c(r.target.value),placeholder:n("config:buildings.namePlaceholder"),required:!0})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.type")}),e.jsx("div",{className:"building-type-selector",children:Object.keys(Ks).map(r=>e.jsxs("button",{type:"button",className:`building-type-btn ${i===r?"active":""}`,onClick:()=>{f(r),r==="database"&&b==="server-rack"&&z("filing-cabinet"),r==="tests"&&b==="server-rack"&&z("dome"),r==="http"&&b==="server-rack"&&z("satellite")},title:Ks[r].description,children:[e.jsx("span",{className:"building-type-icon",children:e.jsx(F,{name:Us(r),size:16})}),e.jsx("span",{className:"building-type-name",children:r})]},r))})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("config:buildings.style")}),e.jsx("div",{className:"building-style-selector",children:Object.keys(Ue).map(r=>e.jsxs("button",{type:"button",className:`building-style-btn ${b===r?"active":""}`,onClick:()=>z(r),title:Ue[r].description,children:[e.jsx("span",{className:"building-style-preview","data-style":r}),e.jsx("span",{className:"building-style-name",children:Ue[r].label})]},r))})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.color")}),e.jsxs("div",{className:"building-color-selector",children:[ma.map(r=>e.jsx("button",{type:"button",className:`building-color-btn ${T===r.value?"active":""}`,onClick:()=>B(r.value),title:ua(r.labelKey),style:r.value?{backgroundColor:r.value}:void 0,children:!r.value&&e.jsx("span",{className:"color-default-icon",children:e.jsx(F,{name:"gear",size:12})})},r.value||"default")),e.jsx("input",{type:"color",className:"building-color-picker",value:T||"#2a2a3a",onChange:r=>B(r.target.value),title:"Custom color"})]})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.size")}),e.jsxs("div",{className:"building-size-control",children:[e.jsxs("div",{className:"size-slider-row",children:[e.jsx("input",{type:"range",className:"size-slider",min:"0",max:"100",step:"1",value:Math.log(W/.1)/Math.log(100)*100,onChange:r=>{const N=parseFloat(r.target.value),w=.1*Math.pow(100,N/100);ee(Math.round(w*100)/100)}}),e.jsxs("span",{className:"size-value",children:[W.toFixed(2),"x"]})]}),e.jsx("div",{className:"size-presets",children:[.5,.75,1,1.25,1.5,2].map(r=>e.jsxs("button",{type:"button",className:`size-preset-btn ${W===r?"active":""}`,onClick:()=>ee(r),children:[r,"x"]},r))})]})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("config:buildings.directory")}),e.jsx(X,{value:$,onChange:R,placeholder:"/path/to/project",className:"form-input",directoriesOnly:!0})]}),i==="folder"&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("config:buildings.folderPath")}),e.jsx(X,{value:E,onChange:J,placeholder:"/path/to/folder",className:"form-input",directoriesOnly:!0}),e.jsx("div",{className:"form-hint",children:"Click this building to open the file explorer at this path"})]}),i==="tests"&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:"Tests Folder"}),e.jsx(X,{value:E,onChange:J,placeholder:"/path/to/project/src/test",className:"form-input",directoriesOnly:!0}),e.jsx("div",{className:"form-hint",children:"Click this building to browse, search and run the tests of this folder (any folder inside a Maven module works)"})]}),i==="http"&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:"Requests Folder"}),e.jsx(X,{value:E,onChange:J,placeholder:"/path/to/project/http-requests",className:"form-input",directoriesOnly:!0}),e.jsx("div",{className:"form-hint",children:"Click this building to browse and fire the .http request files of this folder (IntelliJ HTTP Client style; http-client.env.json environments supported)"})]}),i==="boss"&&e.jsx(fa,{buildings:y,buildingId:u,subordinateBuildingIds:Ae,setSubordinateBuildingIds:Te,isEditMode:a,showBossLogs:Gs,setShowBossLogs:Ys,currentBossLogs:h,bossLogsContainerRef:Js}),i==="database"&&e.jsx(va,{dbConnections:Re,setDbConnections:Ie,activeDbConnectionId:as,setActiveDbConnectionId:Oe}),i==="server"&&e.jsx(xa,{usePM2:Z,setUsePM2:te}),i==="server"&&e.jsx(ba,{usePM2:Z,pm2Script:Ge,setPm2Script:ne,pm2Args:Ye,setPm2Args:le,pm2Interpreter:Je,setPm2Interpreter:ie,pm2InterpreterArgs:We,setPm2InterpreterArgs:oe,pm2Env:Ze,setPm2Env:re,isEditMode:a,building:s??null,handleCommand:ae}),i==="docker"&&e.jsx(ja,{dockerMode:P,setDockerMode:de,dockerImage:Qe,setDockerImage:pe,dockerContainerName:he,setDockerContainerName:xe,dockerCommand:ye,setDockerCommand:Ce,dockerPorts:be,setDockerPorts:je,dockerVolumes:ge,setDockerVolumes:ve,dockerNetwork:Ne,setDockerNetwork:ke,dockerRestart:es,setDockerRestart:Se,dockerPull:ss,setDockerPull:we,dockerEnv:Xe,setDockerEnv:fe,dockerComposePath:Pe,setDockerComposePath:De,dockerComposeProject:Ee,setDockerComposeProject:Le,dockerComposeServices:ze,setDockerComposeServices:Be,selectedExistingContainer:me,setSelectedExistingContainer:ue,dockerContainersList:v,isEditMode:a,building:s??null,handleCommand:ae}),i==="terminal"&&e.jsx(ya,{terminalShell:ts,setTerminalShell:_e,terminalPort:Me,setTerminalPort:Fe,terminalSaveSession:ns,setTerminalSaveSession:$e,terminalArgs:ls,setTerminalArgs:Ke,isEditMode:a,building:s??null,handleCommand:ae,onOpenTerminal:()=>{s!=null&&s.id&&window.dispatchEvent(new CustomEvent("tide:open-iframe-modal",{detail:{buildingId:s.id}}))},onOpenBelow:r=>{window.dispatchEvent(new CustomEvent("tide:open-bottom-terminal",{detail:{buildingId:r}}))}}),i==="server"&&!Z&&e.jsx(Na,{startCmd:K,setStartCmd:I,stopCmd:H,setStopCmd:O,restartCmd:d,setRestartCmd:L,healthCheckCmd:q,setHealthCheckCmd:V,logsCmd:k,setLogsCmd:_,isEditMode:a,handleCommand:ae}),e.jsxs("div",{className:"form-section",children:[e.jsxs("label",{className:"form-label",children:[n("config:buildings.links"),e.jsxs("button",{type:"button",className:"btn btn-sm btn-add",onClick:Xs,children:["+ ",n("common:buttons.add")]})]}),M.map((r,N)=>e.jsxs("div",{className:"url-row",children:[e.jsx("input",{type:"text",className:"form-input url-label",value:r.label,onChange:w=>rs(N,"label",w.target.value),placeholder:"Label"}),e.jsx("input",{type:"text",className:"form-input url-value",value:r.url,onChange:w=>rs(N,"url",w.target.value),placeholder:"https://..."}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>ea(N),children:"x"})]},N))]}),a&&S&&cs.length>0&&e.jsx(Ca,{logs:cs,buildingId:u,logsContainerRef:se})]}),e.jsxs("div",{className:"modal-footer",children:[a&&e.jsx("button",{type:"button",className:"btn btn-danger",onClick:Zs,children:n("common:buttons.delete")}),e.jsx("div",{className:"footer-spacer"}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:p,children:n("common:buttons.cancel")}),e.jsx("button",{type:"submit",className:"btn btn-primary",children:n(a?"common:buttons.save":"common:buttons.create")})]})]})]}),Vs&&s&&e.jsx(ha,{buildingName:s.name,onClose:()=>ce(!1),onConfirm:Qs})]})}export{Da as BuildingConfigModal};