tide-commander 1.110.2 → 1.110.3

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 (43) hide show
  1. package/dist/assets/{BossLogsModal-DBeMak5-.js → BossLogsModal-Dub95BCo.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-DDl6qgnq.js → BossSpawnModal-BXIZWAzn.js} +1 -1
  3. package/dist/assets/{ControlsModal-BBUukX-p.js → ControlsModal-MclobOaO.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-BWf3XDEI.js → DockerLogsModal-DRQ6YsEB.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-CIOdhnaW.js → EmbeddedEditor-B9iQHzhz.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-qG-_WeOb.js → GmailOAuthSetup-wEezv-Vt.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-BK3lzU4n.js → GoogleOAuthSetup-P_teBMn2.js} +1 -1
  8. package/dist/assets/{IframeModal-D_NEs_Ld.js → IframeModal-DEXm0UTA.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-yphWX1ZD.js → IntegrationsPanel-CgFuLL4S.js} +2 -2
  10. package/dist/assets/{LogViewerModal-B0h9NNRk.js → LogViewerModal-CSpbNMTp.js} +1 -1
  11. package/dist/assets/{MonitoringModal-Ciw7KnXH.js → MonitoringModal-Dv1lWqtZ.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-C1dYQaff.js → PM2LogsModal-qpjByXs_.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-DOwzfu-D.js → RestoreArchivedAreaModal-2O5SPxwQ.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-MHfv4Rzg.js → Scene2DCanvas-BJiXSOxB.js} +1 -1
  15. package/dist/assets/{SceneManager-cm1Kj0YD.js → SceneManager-D9NtdKQ1.js} +1 -1
  16. package/dist/assets/{SkillsPanel-DLwMkORc.js → SkillsPanel-B8_RPJzS.js} +1 -1
  17. package/dist/assets/{SlackMultiInstanceSetup-Dql_wPMX.js → SlackMultiInstanceSetup-VcCJhIhV.js} +1 -1
  18. package/dist/assets/{SpawnModal-DzPTSOKV.js → SpawnModal-gn1VV_xv.js} +1 -1
  19. package/dist/assets/StatisticsModal-DRvS2yB_.js +1 -0
  20. package/dist/assets/{SubordinateAssignmentModal-CoLzD3z2.js → SubordinateAssignmentModal-D9gpXqIB.js} +1 -1
  21. package/dist/assets/{TriggerManagerPanel-BOi2zr7N.js → TriggerManagerPanel-bBguUZCE.js} +1 -1
  22. package/dist/assets/{WorkflowEditorPanel-DB1ygPDS.js → WorkflowEditorPanel-BGcpM6uO.js} +1 -1
  23. package/dist/assets/{index-BZsQOteM.js → index-2NGIIydL.js} +1 -1
  24. package/dist/assets/{index-DKASWGtq.js → index-BLw57j0y.js} +1 -1
  25. package/dist/assets/index-Bg0YBtj9.js +11 -0
  26. package/dist/assets/{index-DKdZI-Ar.js → index-Bgcnlnvz.js} +1 -1
  27. package/dist/assets/{index-6Wak7CPm.js → index-BrdAbMM1.js} +1 -1
  28. package/dist/assets/{index-BXJSMT4a.js → index-CTfxfQqV.js} +3 -3
  29. package/dist/assets/{index-ThbMNdRp.js → index-Cy72l2Qo.js} +1 -1
  30. package/dist/assets/{index-D4XW6MSF.js → index-GpT5NHsq.js} +2 -2
  31. package/dist/assets/{index-C6EHHgC0.js → index-VYch6p3A.js} +1 -1
  32. package/dist/assets/{main-BxA3Bhkv.js → main-Brpf2Evy.js} +94 -94
  33. package/dist/assets/{main-BLrGoeQ_.css → main-VciFPjA1.css} +1 -1
  34. package/dist/assets/{web-BskC98UQ.js → web-DUdLOxoB.js} +1 -1
  35. package/dist/assets/{web-CSRmX8Ge.js → web-DjzK5qYd.js} +1 -1
  36. package/dist/assets/{web-zdygXcYu.js → web-IMi3bHab.js} +1 -1
  37. package/dist/index.html +2 -2
  38. package/dist/src/packages/server/data/builtin-skills/send-message-to-agent.js +31 -1
  39. package/dist/src/packages/server/routes/agents.js +30 -0
  40. package/dist/src/packages/server/services/runtime-service.js +24 -0
  41. package/dist/src/packages/server/websocket/handlers/agent-handler.js +18 -12
  42. package/package.json +1 -1
  43. package/dist/assets/index-BP6ukiYG.js +0 -11
@@ -0,0 +1,11 @@
1
+ import{r as l,aV as Re,aW as Ye,j as e,I as L,u as Y,aX as as,a3 as ns,f as Ve,s as E,aY as ms,k as is,l as he,aZ as Z,a_ as gs,aO as fs,a$ as xs,C as me,b0 as J,aL as we,b1 as bs,b2 as js,b3 as ws,b4 as ys,b5 as Se,b6 as os,b7 as Ns,b8 as Me,b9 as vs,ba as ks,bb as Ss,bc as Cs,bd as Ts,be as As,bf as _s,aH as Es,J as Is,S as ke,bg as Ps,bh as $s,aJ as Ls,bi as Ue,K as Ie,aS as Ds,bj as ze,bk as Fs}from"./main-Brpf2Evy.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ke="deivid11/tide-commander",Os=`https://api.github.com/repos/${Ke}/releases/latest`,Rs=`https://api.github.com/repos/${Ke}/releases?per_page=3`,Us=3600*1e3,Je="app_update_dismissed_version",Ze="1.110.3";function zs(){var w,C;const[s,a]=l.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:Ze}),t=((C=(w=Re)==null?void 0:w.getPlatform)==null?void 0:C.call(w))==="android"||!1,o=u=>u.replace(/^v/,"").split(".").map(m=>parseInt(m,10)||0),r=(u,p)=>{const m=o(u),j=o(p),b=Math.max(m.length,j.length);for(let h=0;h<b;h++){const k=m[h]||0,$=j[h]||0;if(k>$)return 1;if(k<$)return-1}return 0},d=async u=>{var m,j;if(Re&&Ye&&((j=(m=Re).isNativePlatform)==null?void 0:j.call(m))===!0){const b=await Ye.get({url:u,headers:{Accept:"application/vnd.github.v3+json"}});return{data:b.data,status:b.status}}else{const b=await fetch(u,{headers:{Accept:"application/vnd.github.v3+json"}});return b.ok?{data:await b.json(),status:b.status}:{data:null,status:b.status}}},c=l.useCallback(async(u=!1)=>{a(p=>({...p,isChecking:!0,error:null}));try{const[p,m]=await Promise.all([d(Os),d(Rs)]);if(p.status!==200)throw new Error(`GitHub API error: ${p.status}`);const j=p.data,b=j.tag_name;let h=[];m.status===200&&m.data&&(h=m.data.map(y=>({version:y.tag_name,name:y.name,publishedAt:y.published_at,releaseUrl:y.html_url})));const k=localStorage.getItem(Je);if(!u&&k===b)return a(y=>({...y,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;if(!(r(b,Ze)>0))return a(y=>({...y,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;const P=j.assets.find(y=>y.name.endsWith(".apk")&&y.content_type==="application/vnd.android.package-archive"),K={version:b,name:j.name,changelog:j.body,releaseUrl:j.html_url,apkUrl:(P==null?void 0:P.browser_download_url)||null,apkSize:(P==null?void 0:P.size)||null,publishedAt:j.published_at};return a(y=>({...y,isChecking:!1,updateAvailable:!0,updateInfo:K,recentReleases:h})),K}catch(p){const m=p instanceof Error?p.message:"Failed to check for updates";return a(j=>({...j,isChecking:!1,error:m})),null}},[]),g=l.useCallback(async()=>{var u,p,m;if(!((u=s.updateInfo)!=null&&u.apkUrl)){(p=s.updateInfo)!=null&&p.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!t){(m=s.updateInfo)!=null&&m.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),a(j=>({...j,error:null}))}catch(j){const b=j instanceof Error?j.message:"Failed to open download";a(h=>({...h,error:b}))}},[s.updateInfo,t]),n=l.useCallback(()=>{s.updateInfo&&localStorage.setItem(Je,s.updateInfo.version),a(u=>({...u,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),x=l.useCallback(()=>{var u;(u=s.updateInfo)!=null&&u.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${Ke}/releases`,"_blank")},[s.updateInfo]);return l.useEffect(()=>{if(!t)return;const u=setTimeout(()=>{c()},5e3),p=setInterval(()=>{c()},Us);return()=>{clearTimeout(u),clearInterval(p)}},[t,c]),{...s,isAndroid:t,checkForUpdate:c,downloadAndInstall:g,dismissUpdate:n,openReleasePage:x}}const ls="tide-toolbox-collapse";function Bs(s,a){try{const t=localStorage.getItem(`${ls}-${s}`);if(t!==null)return t==="true"}catch{}return a}function Ms(s,a){try{localStorage.setItem(`${ls}-${s}`,String(a))}catch{}}function W({title:s,storageKey:a,defaultOpen:t=!1,forceOpen:o=!1,children:r,headerExtra:d}){const[c,g]=l.useState(()=>a?Bs(a,t):t),n=()=>{const w=!c;g(w),a&&Ms(a,w)},x=o||c;return e.jsxs("div",{className:`collapsible-section ${x?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:n,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[d,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(L,{name:x?"caret-down":"caret-right",size:10})})]})]}),x&&e.jsx("div",{className:"collapsible-content",children:r})]})}function Vs({area:s,isSelected:a,onClick:t,onDelete:o}){const{t:r}=Y(["config","common"]),d=s.assignedAgentIds.length,c=s.type==="rectangle"?r("config:areas.rect"):r("config:areas.circle");return e.jsxs("div",{className:`area-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[c," ",d>0&&`• ${d} ${d>1?r("common:labels.agents").toLowerCase():r("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:r("config:areas.deleteArea"),children:"×"})]})}function Ks({building:s,isSelected:a,onClick:t,onEdit:o}){var g;const{t:r}=Y(["config"]),d=((g=s.pm2Status)==null?void 0:g.ports)||[],c=(n,x)=>{n.stopPropagation(),window.open(`http://${window.location.hostname}:${x}`,"_blank")};return e.jsxs("div",{className:`building-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:as[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(L,{name:ns(s.type),size:16})}),e.jsxs("div",{className:"building-info",children:[e.jsx("div",{className:"building-name",children:s.name}),e.jsxs("div",{className:"building-meta",children:[s.type,d.length>0&&e.jsx("span",{className:"building-ports",children:d.map(n=>e.jsxs("a",{href:`http://${window.location.hostname}:${n}`,className:"building-port-link",onClick:x=>c(x,n),title:`Open :${n}`,children:[":",n]},n))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:n=>{n.stopPropagation(),o()},title:r("config:buildings.editBuilding"),children:e.jsx(L,{name:"gear",size:14})})]})}function Hs({building:s,onClose:a,onOpenModal:t}){var x,w,C,u,p,m,j,b;const{t:o}=Y(["config","common"]),{buildingLogs:r}=Ve(),d=E.getBuildingLogs(s.id),c=ms[s.style||"server-rack"],g=h=>{E.sendBuildingCommand(s.id,h)},n=h=>{window.open(h,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx(L,{name:ns(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:as[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:a,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:c.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>g("start"),disabled:!((x=s.commands)!=null&&x.start)||s.status==="running",title:((w=s.commands)==null?void 0:w.start)||o("config:buildings.noStartCommand"),children:[e.jsx(L,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>g("stop"),disabled:!((C=s.commands)!=null&&C.stop)||s.status==="stopped",title:((u=s.commands)==null?void 0:u.stop)||o("config:buildings.noStopCommand"),children:[e.jsx(L,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>g("restart"),disabled:!((p=s.commands)!=null&&p.restart),title:((m=s.commands)==null?void 0:m.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx(L,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>g("healthCheck"),disabled:!((j=s.commands)!=null&&j.healthCheck),title:((b=s.commands)==null?void 0:b.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx(L,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((h,k)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>n(h.url),title:h.url,children:[e.jsx(L,{name:"link",size:12})," ",h.label||h.url]},k))})]}),d.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[o("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>E.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:d.slice(-5).map((h,k)=>e.jsx("div",{className:"building-editor-log-entry",children:h},k))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(L,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}async function Ws(s,a){const t=Z(),o=await fetch(he(`/api/areas/${s}/logo`),{method:"POST",headers:{"Content-Type":a.type||"image/png","X-Filename":encodeURIComponent(a.name),...t?{Authorization:`Bearer ${t}`}:{}},body:a});if(!o.ok){const r=await o.json().catch(()=>({error:o.statusText}));throw new Error(r.error||`Upload failed: ${o.statusText}`)}return o.json()}async function qs(s){const a=Z(),t=await fetch(he(`/api/areas/${s}/logo`),{method:"DELETE",headers:{...a?{Authorization:`Bearer ${a}`}:{}}});if(!t.ok)throw new Error(`Failed to delete logo: ${t.statusText}`)}function Gs(s){return is(he(`/api/areas/logos/${s}`))}const Ys=[{key:"center",labelKey:"posCenter"},{key:"top-left",labelKey:"posTopLeft"},{key:"top-right",labelKey:"posTopRight"},{key:"bottom-left",labelKey:"posBottomLeft"},{key:"bottom-right",labelKey:"posBottomRight"}];function Js({area:s,onClose:a,onOpenFolder:t}){var ie;const{t:o}=Y(["config","common"]),[r,d]=l.useState(s.name),[c,g]=l.useState(s.prompt||""),[n,x]=l.useState(!1),[w,C]=l.useState(""),[u,p]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{d(s.name)},[s.id,s.name]),l.useEffect(()=>{g(s.prompt||"")},[s.id,s.prompt]);const j=v=>{const F=v.target.value;d(F),E.updateArea(s.id,{name:F})},b=v=>{E.updateArea(s.id,{color:v})},h=v=>{const F=v.target.value;g(F),E.updateArea(s.id,{prompt:F})},k=()=>{w.trim()&&(E.addDirectoryToArea(s.id,w.trim()),C(""),x(!1))},$=(v,F)=>{F.stopPropagation(),E.removeDirectoryFromArea(s.id,v)},P=()=>{E.bringAreaToFront(s.id)},K=()=>{E.sendAreaToBack(s.id)},y=l.useCallback(()=>{let v=2,F=2;s.type==="rectangle"&&s.width&&s.height?(v=s.width,F=s.height):s.type==="circle"&&s.radius&&(v=s.radius*1.414,F=s.radius*1.414);const M=Math.min(v,F)*.4;return{width:Math.round(M*10)/10,height:Math.round(M*10)/10}},[s.type,s.width,s.height,s.radius]),U=async v=>{var M;const F=(M=v.target.files)==null?void 0:M[0];if(F){p(!0);try{const N=await Ws(s.id,F),D=y();E.updateArea(s.id,{logo:{filename:N.filename,position:"center",width:D.width,height:D.height,keepAspectRatio:!0,opacity:.8}})}catch(N){console.error("Failed to upload logo:",N)}finally{p(!1),m.current&&(m.current.value="")}}},B=async()=>{try{await qs(s.id),E.updateArea(s.id,{logo:void 0})}catch(v){console.error("Failed to remove logo:",v)}},V=v=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,position:v}})},S=v=>{if(!s.logo)return;const F=parseFloat(v.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const M=s.logo.height/s.logo.width;E.updateArea(s.id,{logo:{...s.logo,width:F,height:Math.round(F*M*10)/10}})}else E.updateArea(s.id,{logo:{...s.logo,width:F}})},T=v=>{if(!s.logo)return;const F=parseFloat(v.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const M=s.logo.width/s.logo.height;E.updateArea(s.id,{logo:{...s.logo,height:F,width:Math.round(F*M*10)/10}})}else E.updateArea(s.id,{logo:{...s.logo,height:F}})},H=()=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},X=v=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(v.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:o("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:a,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:r,onChange:j,placeholder:o("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:gs.map(v=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===v?"selected":""}`,style:{backgroundColor:v},onClick:()=>b(v),"aria-label":`Set area color ${v}`,"aria-pressed":s.color===v,title:v},v))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:P,title:o("config:areas.bringToFront"),children:[e.jsx(L,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:K,title:o("config:areas.sendToBack"),children:[e.jsx(L,{name:"arrow-down",size:12})," ",o("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(ie=s.logo)!=null&&ie.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Gs(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:B,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var v;return(v=m.current)==null?void 0:v.click()},disabled:u,children:u?"...":e.jsx(L,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:Ys.map(({key:v,labelKey:F})=>{var M;return e.jsx("button",{className:`area-logo-pos-btn ${((M=s.logo)==null?void 0:M.position)===v?"active":""}`,onClick:()=>V(v),children:o(`config:areas.${F}`)},v)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:S,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:T,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:o("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:H}),o("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoOpacity")}),e.jsxs("div",{className:"area-logo-opacity-row",children:[e.jsx("input",{type:"range",min:0,max:1,step:.05,value:s.logo.opacity??.8,onChange:X,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var v;return(v=m.current)==null?void 0:v.click()},disabled:u,children:u?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:m,type:"file",accept:"image/*",style:{display:"none"},onChange:U})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(v=>e.jsxs("div",{className:"area-folder-item",title:v,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:o("config:areas.openFolder"),children:e.jsx(L,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:v.split("/").pop()||v}),e.jsx("button",{className:"area-folder-remove",onClick:F=>$(v,F),title:o("config:areas.removeFolder"),children:"×"})]},v)),n?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(fs,{value:w,onChange:C,onSubmit:k,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:k,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>x(!0),children:o("config:areas.addFolder")})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:c,onChange:h,placeholder:o("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:o("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:o("config:areas.rightClickUnassign")})]})]})}function Zs(){const{t:s}=Y(["config","common"]),a=xs(),[t,o]=l.useState(!1),[r,d]=l.useState(null),[c,g]=l.useState({name:"",key:"",value:"",description:""}),[n,x]=l.useState(null),w=()=>{o(!0),d(null),g({name:"",key:"",value:"",description:""})},C=h=>{d(h.id),o(!1),g({name:h.name,key:h.key,value:h.value,description:h.description||""})},u=()=>{o(!1),d(null),g({name:"",key:"",value:"",description:""})},p=()=>{!c.name.trim()||!c.key.trim()||(r?E.updateSecret(r,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):E.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),u())},m=h=>{x(h)},j=()=>{n&&(E.deleteSecret(n),r===n&&u())},b=h=>{navigator.clipboard.writeText(`{{${h}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children:a.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):a.map(h=>e.jsxs("div",{className:`secret-item ${r===h.id?"editing":""}`,children:[e.jsxs("div",{className:"secret-item-header",children:[e.jsxs("div",{className:"secret-item-info",children:[e.jsx("span",{className:"secret-item-name",children:h.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>b(h.key),title:s("config:secrets.copyPlaceholder"),children:`{{${h.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>C(h),title:s("common:buttons.edit"),children:e.jsx(L,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>m(h.id),title:s("common:buttons.delete"),children:"×"})]})]}),h.description&&e.jsx("div",{className:"secret-item-description",children:h.description})]},h.id))}),(t||r)&&e.jsxs("div",{className:"secret-form",children:[e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.name")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.namePlaceholder"),value:c.name,onChange:h=>g({...c,name:h.target.value}),autoFocus:!0})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:"Key"}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.keyPlaceholder"),value:c.key,onChange:h=>g({...c,key:h.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${c.key||"KEY"}}}`})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("config:secrets.secretValue")}),e.jsx("input",{type:"password",className:"secret-form-input",placeholder:s("config:secrets.valuePlaceholder"),value:c.value,onChange:h=>g({...c,value:h.target.value})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.description")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.descriptionPlaceholder"),value:c.description,onChange:h=>g({...c,description:h.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:u,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:p,disabled:!c.name.trim()||!c.key.trim(),children:s(r?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!r&&e.jsx("button",{className:"secrets-add-btn",onClick:w,children:s("config:secrets.addSecret")}),e.jsx(me,{isOpen:n!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:j,onClose:()=>x(null)})]})}async function Xs(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch system prompt: ${a.statusText}`);return(await a.json()).prompt||""}async function Qs(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function et(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to clear system prompt: ${a.statusText}`)}async function st(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch echo prompt setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function tt(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function at(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch codex binary path: ${a.statusText}`);return(await a.json()).path||""}async function nt(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function it(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch tmux mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ot(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function lt(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch backup status: ${a.statusText}`);return a.json()}async function ct(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function rt({checked:s,onChange:a,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:o=>a(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function dt(){const{t:s}=Y(["config","common"]),[a,t]=l.useState([]),[o,r]=l.useState(new Set),[d,c]=l.useState(new Set),[g,n]=l.useState(!1),[x,w]=l.useState(!1),[C,u]=l.useState(null),[p,m]=l.useState(null),[j,b]=l.useState(null),[h,k]=l.useState(null),[$,P]=l.useState(!1),[K,y]=l.useState(null);l.useEffect(()=>{we(he("/api/config/categories")).then(N=>N.json()).then(N=>{const D=Array.isArray(N)?N:[];t(D),r(new Set(D.map(O=>O.id)))}).catch(N=>console.error("Failed to fetch config categories:",N))},[]),l.useEffect(()=>{lt().then(k).catch(N=>{console.error("Failed to fetch backup status:",N),y(N.message||"Failed to fetch backup status")})},[]);const U=async N=>{if(!$){P(!0),y(null);try{const D=await ct(N);k(D)}catch(D){y(D.message||"Failed to update backup setting")}finally{P(!1)}}},B=N=>{r(D=>{const O=new Set(D);return O.has(N)?O.delete(N):O.add(N),O})},V=N=>{c(D=>{const O=new Set(D);return O.has(N)?O.delete(N):O.add(N),O})},S=()=>r(new Set(a.map(N=>N.id))),T=()=>r(new Set),H=()=>{p&&c(new Set(p.categories.map(N=>N.id)))},X=()=>c(new Set),ie=async()=>{var N;if(o.size!==0){n(!0),b(null);try{const D=Array.from(o).join(","),O=await we(he(`/api/config/export?categories=${D}`));if(!O.ok)throw new Error("Export failed");const ee=await O.blob(),se=window.URL.createObjectURL(ee),Q=document.createElement("a");Q.href=se;const A=O.headers.get("Content-Disposition"),q=((N=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:N[1])||"tide-commander-config.zip";Q.download=q,document.body.appendChild(Q),Q.click(),document.body.removeChild(Q),window.URL.revokeObjectURL(se),b({type:"success",text:s("config:data.exportSuccess")})}catch(D){b({type:"error",text:D.message||"Export failed"})}finally{n(!1)}}},v=async N=>{var O;const D=(O=N.target.files)==null?void 0:O[0];if(D){u(D),b(null),m(null),c(new Set);try{const ee=await we(he("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await D.arrayBuffer()});if(!ee.ok){const A=await ee.json();throw new Error(A.error||"Failed to preview config file")}const se=await ee.json(),Q=Array.isArray(se.categories)?se.categories:[];m({...se,categories:Q}),c(new Set(Q.map(A=>A.id)))}catch(ee){b({type:"error",text:ee.message||"Failed to read config file"}),u(null)}}},F=async()=>{if(!(!C||d.size===0)){w(!0),b(null);try{const N=Array.from(d).join(","),D=await we(he(`/api/config/import?categories=${N}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await C.arrayBuffer()}),O=await D.json();if(!D.ok)throw new Error(O.error||"Import failed");b({type:"success",text:O.message||s("config:data.importSuccess")}),u(null),m(null),c(new Set)}catch(N){b({type:"error",text:N.message||"Import failed"})}finally{w(!1)}}},M=()=>{u(null),m(null),c(new Set),b(null)};return e.jsxs("div",{className:"data-section",children:[j&&e.jsx("div",{className:`data-message data-message-${j.type}`,children:j.text}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:"Hourly Backups"}),e.jsx(rt,{checked:!!(h!=null&&h.enabled),disabled:$||!h,onChange:U})]}),e.jsxs("div",{className:"data-backup-info",children:[h?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:h.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!h.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:h.scriptPath})]}),h.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(h.lastRunAt).toLocaleString(),h.lastRunOk===!0&&" — ok",h.lastRunOk===!1&&h.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",h.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),K&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:K})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:S,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:T,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:a.map(N=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(N.id),onChange:()=>B(N.id)}),e.jsx("span",{className:"data-category-name",children:N.name})]},N.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ie,disabled:g||o.size===0,children:g?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),C?p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:C.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(p.exportedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-subtitle",children:s("config:data.selectToImport")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:H,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:X,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:p.categories.map(N=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:d.has(N.id),onChange:()=>V(N.id)}),e.jsx("span",{className:"data-category-name",children:N.name}),N.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",N.fileCount," ",s("config:data.files"),")"]})]},N.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:M,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:F,disabled:x||d.size===0,children:x?s("config:data.importing"):s("config:data.importCount",{count:d.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:v,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}async function ut(){const s=await we(`${J()}/api/system/install-info`);if(!s.ok)throw new Error(`Failed to fetch install info: ${s.statusText}`);return s.json()}function pt(s,a){const t=new AbortController;return(async()=>{try{const o=await fetch(is(`${J()}/api/system/self-update`),{method:"POST",signal:t.signal,headers:{Accept:"text/event-stream"}});if(!o.ok||!o.body){const g=await o.text().catch(()=>"");let n=null;try{n=JSON.parse(g)}catch{}const x=n&&typeof n=="object"&&"error"in n&&typeof n.error=="string"?n.error:`Self-update failed: ${o.status} ${o.statusText}`;s({type:"error",message:x}),a(new Error(x));return}const r=o.body.getReader(),d=new TextDecoder("utf-8");let c="";for(;;){const{value:g,done:n}=await r.read();if(n)break;c+=d.decode(g,{stream:!0});let x=c.indexOf(`
2
+
3
+ `);for(;x!==-1;){const w=c.slice(0,x);c=c.slice(x+2);const C=w.split(`
4
+ `);let u="message",p="";for(const m of C)m.startsWith(":")||(m.startsWith("event:")?u=m.slice(6).trim():m.startsWith("data:")&&(p+=(p?`
5
+ `:"")+m.slice(5).trim()));if(p)try{const m=JSON.parse(p);s({type:u,...m})}catch{}x=c.indexOf(`
6
+
7
+ `)}}a()}catch(o){if(o.name==="AbortError"){a();return}a(o)}})(),()=>t.abort()}function ht(){const[s,a]=l.useState(()=>bs()),t=o=>{a(o);const r=ws(o);ys(r)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:js.map(o=>e.jsxs("button",{className:`theme-option ${s===o.id?"active":""}`,onClick:()=>t(o.id),title:o.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:o.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:o.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:o.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:o.name})]},o.id))})})}function mt(){const{t:s}=Y(["config"]),[a,t]=l.useState(null),[o,r]=l.useState("idle"),[d,c]=l.useState(""),[g,n]=l.useState(null),[x,w]=l.useState(null),C=l.useRef(null),u=l.useRef(null),p=l.useCallback(async()=>{try{const k=await ut();t(k)}catch{t(null)}},[]);l.useEffect(()=>{p()},[p]),l.useEffect(()=>{u.current&&(u.current.scrollTop=u.current.scrollHeight)},[d]);const m=l.useCallback(()=>{r("confirm")},[]),j=l.useCallback(()=>{r("idle")},[]),b=l.useCallback(()=>{r("running"),c(""),n(null),w(null);const k=pt($=>{switch($.type){case"start":c(P=>P+`${$.message}
8
+ `);break;case"stdout":c(P=>P+$.chunk);break;case"stderr":c(P=>P+$.chunk);break;case"error":n($.message),$.suggestedManualCommand&&c(P=>P+`
9
+
10
+ Suggested manual command: ${$.suggestedManualCommand}
11
+ `);break;case"done":$.success?(w($.newVersion),r("success")):r("failed");break}},$=>{$&&n(P=>P??$.message),r(P=>P==="running"?g?"failed":"success":P)});C.current=k},[g]),h=l.useCallback(()=>{var k;(k=C.current)==null||k.call(C),C.current=null,r("idle"),p()},[p]);return a?a.isGlobalInstall?a.autoUpdateSupported?!a.updateAvailable&&o==="idle"?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:about.autoUpdateTitle")}),o==="idle"&&a.updateAvailable&&e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsxs("span",{className:"about-autoupdate-versions",children:[e.jsx("span",{className:"about-autoupdate-current",children:a.currentVersion}),e.jsx("span",{className:"about-autoupdate-arrow",children:"→"}),e.jsx("span",{className:"about-autoupdate-latest",children:a.latestVersion})]}),e.jsx("button",{className:"about-update-btn download",onClick:m,children:s("config:about.autoUpdateButton")})]}),o==="confirm"&&e.jsxs("div",{className:"about-autoupdate-confirm",children:[e.jsx("div",{className:"about-autoupdate-confirm-title",children:s("config:about.autoUpdateConfirmTitle")}),e.jsx("div",{className:"about-autoupdate-confirm-body",children:s("config:about.autoUpdateConfirmBody")}),e.jsxs("div",{className:"about-autoupdate-confirm-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:j,children:s("config:about.autoUpdateCancel")}),e.jsx("button",{className:"about-update-btn download",onClick:b,children:s("config:about.autoUpdateConfirm")})]})]}),(o==="running"||o==="success"||o==="failed")&&e.jsxs("div",{className:"about-autoupdate-stream",children:[e.jsxs("div",{className:"about-autoupdate-stream-title",children:[o==="running"&&s("config:about.autoUpdateRunning"),o==="success"&&s("config:about.autoUpdateSuccess"),o==="failed"&&s("config:about.autoUpdateFailed")]}),e.jsx("pre",{ref:u,className:"about-autoupdate-output",children:d||"..."}),o==="success"&&e.jsxs("div",{className:"about-autoupdate-success-hint",children:[x&&e.jsxs("div",{className:"about-autoupdate-newversion",children:["v",x]}),e.jsx("div",{children:s("config:about.autoUpdateRestartHint")})]}),o==="failed"&&g&&e.jsx("div",{className:"about-update-error",children:g}),(o==="success"||o==="failed")&&e.jsx("div",{className:"about-autoupdate-stream-actions",children:e.jsx("button",{className:"about-update-btn changelog",onClick:h,children:s("config:about.autoUpdateClose")})})]})]}):e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:about.autoUpdateTitle")}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdatePackageManagerNotice",{pm:a.packageManager})}),a.suggestedManualCommand&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"about-autoupdate-manualhint",children:s("config:about.autoUpdateManualCommand")}),e.jsx("pre",{className:"about-autoupdate-manualcmd",children:a.suggestedManualCommand})]})]}):e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:about.autoUpdateTitle")}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdateDevMode")})]}):null}function gt(){const{t:s}=Y(["config"]),{updateAvailable:a,updateInfo:t,recentReleases:o,isChecking:r,error:d,currentVersion:c,isAndroid:g,checkForUpdate:n,downloadAndInstall:x,openReleasePage:w}=zs(),C=p=>p?`${(p/(1024*1024)).toFixed(1)} MB`:"",u=p=>new Date(p).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:e.jsx(L,{name:"waves",size:24})}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:c}),a&&t?e.jsx("span",{className:"about-version-update-badge",onClick:w,title:`Update available: ${t.version}`,children:t.version}):e.jsxs("a",{href:"https://github.com/deivid11/tide-commander/releases",target:"_blank",rel:"noopener noreferrer",className:"about-version-status",children:["(",s("config:about.updated"),")"]})]})]}),e.jsx(mt,{}),e.jsxs("div",{className:"about-update",children:[a&&t?e.jsxs("div",{className:"about-update-available",children:[e.jsxs("div",{className:"about-update-header",children:[e.jsx("span",{className:"about-update-badge",children:s("config:about.updateAvailable")}),e.jsx("span",{className:"about-update-version",children:t.version})]}),t.apkSize&&e.jsxs("div",{className:"about-update-size",children:[s("config:about.sizeLabel"),": ",C(t.apkSize)]}),d&&e.jsx("div",{className:"about-update-error",children:d}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:w,children:s("config:about.changelog")}),g&&t.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:x,children:s("config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:w,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(r?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>n(!0),disabled:r,children:r?"...":s("config:about.check")})]}),o.length>0&&e.jsxs("div",{className:"about-releases",children:[e.jsx("div",{className:"about-releases-title",children:s("config:about.recentReleases")}),e.jsx("div",{className:"about-releases-list",children:o.map(p=>e.jsxs("a",{href:p.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${p.version===`v${c}`||p.version===c?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:p.version}),e.jsx("span",{className:"about-release-date",children:u(p.publishedAt)})]},p.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:e.jsx(L,{name:"package",size:14})}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]})]})}const ft={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function xt({onOpenModal:s}){const[a,t]=l.useState([]),[o,r]=l.useState(!0),d=l.useCallback(async()=>{try{const c=await we(he("/api/integrations"));if(!c.ok)return;const g=await c.json();t(g)}catch{}finally{r(!1)}},[]);return l.useEffect(()=>{d()},[d]),o?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):a.length===0?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"No integrations available."}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[a.map(c=>{const g=ft[c.id]||"🔌",n=!!c.status.error,x=c.status.connected,w=n?"#f38ba8":x?"#a6e3a1":"#fab387",C=n?"Error":x?"Connected":"Setup Required",u=n?"✗":x?"✓":"⚠";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 8px",borderRadius:4,background:"var(--surface-1, #181825)",border:"1px solid var(--border, #313244)",fontSize:12,minHeight:26},children:[e.jsx("span",{style:{fontSize:13,flexShrink:0},children:g}),e.jsx("span",{style:{flex:1,minWidth:0,color:"var(--text-primary, #cdd6f4)",fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c.name}),e.jsx("span",{style:{color:w,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:C,children:u}),e.jsx("button",{onClick:()=>s(c.id),title:`Configure ${c.name}`,style:{background:"none",border:"none",cursor:"pointer",padding:"1px 3px",fontSize:12,color:"var(--text-secondary, #a6adc8)",borderRadius:3,flexShrink:0,lineHeight:1},onMouseEnter:p=>{p.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:p=>{p.target.style.color="var(--text-secondary, #a6adc8)"},children:"⚙️"})]},c.id)}),e.jsx("button",{onClick:()=>s(),style:{background:"none",border:"1px dashed var(--border, #313244)",borderRadius:4,padding:"3px 8px",cursor:"pointer",color:"var(--text-secondary, #a6adc8)",fontSize:11,textAlign:"center",marginTop:2},onMouseEnter:c=>{c.target.style.borderColor="var(--accent, #89b4fa)",c.target.style.color="var(--accent, #89b4fa)"},onMouseLeave:c=>{c.target.style.borderColor="var(--border, #313244)",c.target.style.color="var(--text-secondary, #a6adc8)"},children:"Manage All Integrations"})]})}function bt({isOpen:s,onClose:a}){const{t}=Y(["config"]),[o,r]=l.useState(""),[d,c]=l.useState(""),[g,n]=l.useState(!0),[x,w]=l.useState(null),[C,u]=l.useState(null),[p,m]=l.useState(!1),[j,b]=l.useState(!1),[h,k]=l.useState(!1);l.useEffect(()=>{s&&$()},[s]);const $=async()=>{try{n(!0),w(null),u(null);const T=await Xs();r(T),c(T),m(!1)}catch(T){w(T instanceof Error?T.message:"Failed to load system prompt")}finally{n(!1)}},P=T=>{const H=T.target.value;r(H),m(H!==d),w(null),u(null)},K=async()=>{try{w(null),u(null),await Qs(o),c(o),m(!1),u(t("config:systemPrompt.saved"))}catch(T){w(T instanceof Error?T.message:"Failed to save system prompt")}},y=()=>{b(!0)},U=async()=>{try{w(null),u(null),await et(),r(""),c(""),m(!1),u(t("config:systemPrompt.cleared"))}catch(T){w(T instanceof Error?T.message:"Failed to clear system prompt")}},B=()=>{r(d),m(!1),w(null),u(null)},V=()=>{if(p){k(!0);return}a()},S=T=>{T.key==="Escape"&&(T.preventDefault(),V())};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:V,children:e.jsxs("div",{className:"system-prompt-modal",onClick:T=>T.stopPropagation(),onKeyDown:S,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:V,"aria-label":"Close",children:e.jsx(L,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:g?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:"Loading system prompt..."})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:systemPrompt.description")}),x&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"warn",size:14})}),x]}),C&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"check",size:14})}),C]}),e.jsxs("div",{className:"editor-wrapper",children:[e.jsxs("div",{className:"editor-header",children:[e.jsx("label",{htmlFor:"prompt-input",className:"editor-label",children:t("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[o.length," ",t("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:o,onChange:P,placeholder:t("config:systemPrompt.placeholder"),rows:18,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:t("config:systemPrompt.hint")})]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:y,disabled:!o||g,children:t("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:V,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:B,disabled:!p||g,children:t("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:K,disabled:!p||g,children:t("config:systemPrompt.save")})]})]})]})}),e.jsx(me,{isOpen:j,title:t("config:systemPrompt.clear"),message:t("config:systemPrompt.confirmClear"),confirmLabel:t("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{U()},onClose:()=>b(!1)}),e.jsx(me,{isOpen:h,title:"Unsaved Changes",message:"You have unsaved changes. Close anyway?",confirmLabel:"Close anyway",cancelLabel:"Keep editing",variant:"danger",onConfirm:a,onClose:()=>k(!1)})]}):null}const Xe={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},jt=2500,wt=12e4;function Qe(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function yt(s,a){return s.enabled===a.enabled&&s.baseUrl===a.baseUrl&&s.defaultSessionId===a.defaultSessionId&&s.webhookVerifyToken===a.webhookVerifyToken&&s.showIncomingToasts===a.showIncomingToasts}function Nt({isOpen:s,onClose:a}){const{t}=Y(["config"]),[o,r]=l.useState(Xe),[d,c]=l.useState(Xe),[g,n]=l.useState(!1),[x,w]=l.useState([]),[C,u]=l.useState(!0),[p,m]=l.useState(null),[j,b]=l.useState(null),[h,k]=l.useState(""),[$,P]=l.useState(!1),[K,y]=l.useState(""),[U,B]=l.useState(null),[V,S]=l.useState(null),[T,H]=l.useState(null),X=l.useRef(null),ie=l.useRef(0),[v,F]=l.useState(""),[M,N]=l.useState(""),[D,O]=l.useState(null),[ee,se]=l.useState(!1),[Q,A]=l.useState(!1),[q,te]=l.useState(!1),[le,ae]=l.useState(!1),[ue,ye]=l.useState(null),Ne=!yt(o,d),re=l.useCallback(()=>{X.current&&(clearTimeout(X.current),X.current=null)},[]),ge=l.useCallback(async()=>{try{u(!0),m(null),b(null);const[f,R]=await Promise.all([os(),Ns()]),ne=Qe(f);if(r(ne),c(ne),n(!!R.configured),R.configured)try{const xe=await Me();w(Array.isArray(xe)?xe:[])}catch{w([])}else w([])}catch(f){m(f instanceof Error?f.message:t("config:whatsapp.errors.loadFailed"))}finally{u(!1)}},[t]),I=l.useCallback(async()=>{try{const f=await Me();w(Array.isArray(f)?f:[])}catch{}},[]);l.useEffect(()=>(s?ge():(re(),B(null),S(null),H(null),k(""),P(!1),O(null)),()=>{re()}),[s,ge,re]);const pe=(f,R)=>{r(ne=>({...ne,[f]:R})),m(null),b(null)},ce=async()=>{try{m(null),b(null);const f=await Ts({enabled:o.enabled,baseUrl:o.baseUrl.trim(),defaultSessionId:o.defaultSessionId.trim(),webhookVerifyToken:o.webhookVerifyToken,showIncomingToasts:o.showIncomingToasts});window.dispatchEvent(new CustomEvent("tide:whatsapp-config-updated"));const R=Qe(f);r(R),c(R),b(t("config:whatsapp.saved"))}catch(f){m(f instanceof Error?f.message:t("config:whatsapp.errors.saveFailed"))}},$e=()=>{r(d),m(null),b(null)},fe=()=>{if(Ne){A(!0);return}a()},Le=f=>{f.key==="Escape"&&(f.preventDefault(),fe())},De=async()=>{const f=h.trim();if(f)try{m(null),b(null),await ks(f),k(""),P(!1),n(!0),b(t("config:whatsapp.apiKeySaved"))}catch(R){m(R instanceof Error?R.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},Ce=()=>{te(!0)},Fe=async()=>{try{m(null),b(null),await As(),n(!1),b(t("config:whatsapp.apiKeyCleared"))}catch(f){m(f instanceof Error?f.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},ve=l.useCallback(async f=>{if(Date.now()>ie.current){H(t("config:whatsapp.pairingTimeout")),B(null),S(null),re(),I();return}try{const R=await vs(f);if(R.status&&["connected","paired","open","ready"].includes(R.status.toLowerCase())){H(t("config:whatsapp.pairingSuccess")),B(null),S(null),re(),I();return}const xe=R.qrUrl??R.qr??null;xe&&S(xe)}catch(R){H(R instanceof Error?R.message:t("config:whatsapp.errors.qrFetchFailed"))}X.current=setTimeout(()=>{ve(f)},jt)},[I,re,t]),Te=async()=>{const f=K.trim();if(f)try{m(null),b(null),H(null),S(null),re(),await Ss(f),y(""),B(f),ie.current=Date.now()+wt,ve(f),I()}catch(R){m(R instanceof Error?R.message:t("config:whatsapp.errors.sessionCreateFailed"))}},Ae=()=>{re(),B(null),S(null),H(null)},_e=f=>{ye(f),ae(!0)},Oe=async()=>{if(ue)try{m(null),b(null),await _s(ue),U===ue&&Ae(),I(),b(t("config:whatsapp.sessionDeleted"))}catch(f){m(f instanceof Error?f.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{ye(null)}},Ee=async()=>{const f=v.trim(),R=M.trim();if(!(!f||!R))try{se(!0),O(null);const ne=o.defaultSessionId.trim()||void 0;await Cs(f,R,ne),O({kind:"success",text:t("config:whatsapp.testSent")})}catch(ne){O({kind:"error",text:ne instanceof Error?ne.message:t("config:whatsapp.errors.testSendFailed")})}finally{se(!1)}};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:fe,children:e.jsxs("div",{className:"whatsapp-config-modal",onClick:f=>f.stopPropagation(),onKeyDown:Le,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsapp.title")}),e.jsx("button",{className:"modal-close",onClick:fe,"aria-label":"Close",children:e.jsx(L,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:C?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsapp.description")}),p&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"warn",size:14})}),p]}),j&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"check",size:14})}),j]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.general")}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-enabled",className:"wa-label",children:t("config:whatsapp.enabled")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-enabled",type:"checkbox",checked:o.enabled,onChange:f=>pe("enabled",f.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-show-toasts",className:"wa-label",children:t("config:whatsapp.showIncomingToasts")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-show-toasts",type:"checkbox",checked:o.showIncomingToasts,onChange:f=>pe("showIncomingToasts",f.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.showIncomingToastsHelp")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-base-url",className:"wa-label",children:t("config:whatsapp.baseUrl")}),e.jsx("input",{id:"wa-base-url",type:"text",className:"wa-input",placeholder:"http://localhost:3007",value:o.baseUrl,onChange:f=>pe("baseUrl",f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-default-session",className:"wa-label",children:t("config:whatsapp.defaultSessionId")}),e.jsx("input",{id:"wa-default-session",type:"text",className:"wa-input",placeholder:t("config:whatsapp.defaultSessionIdPlaceholder"),value:o.defaultSessionId,onChange:f=>pe("defaultSessionId",f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-webhook-token",className:"wa-label",children:t("config:whatsapp.webhookVerifyToken")}),e.jsx("input",{id:"wa-webhook-token",type:"text",className:"wa-input",placeholder:t("config:whatsapp.webhookVerifyTokenPlaceholder"),value:o.webhookVerifyToken,onChange:f=>pe("webhookVerifyToken",f.target.value)})]})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.apiKey")}),e.jsx("div",{className:"wa-key-status",children:g?e.jsxs("span",{className:"wa-status wa-status-ok",children:[e.jsx(L,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(L,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:$?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:h,onChange:f=>k(f.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>P(f=>!f),title:t($?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(L,{name:$?"eye-closed":"eye",size:14})}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:De,disabled:!h.trim(),children:t("config:whatsapp.saveKey")}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:Ce,disabled:!g,children:t("config:whatsapp.clearKey")})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.apiKeyHint")})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.sessions")}),e.jsx("div",{className:"wa-sessions-list",children:!Array.isArray(x)||x.length===0?e.jsx("div",{className:"wa-empty",children:t("config:whatsapp.noSessions")}):x.map(f=>e.jsxs("div",{className:"wa-session-row",children:[e.jsxs("div",{className:"wa-session-info",children:[e.jsx("span",{className:"wa-session-id",children:f.id}),e.jsx("span",{className:`wa-session-status status-${(f.status??"unknown").toLowerCase()}`,children:f.status||"—"}),f.pairedNumber&&e.jsx("span",{className:"wa-session-paired",children:f.pairedNumber})]}),e.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:()=>_e(f.id),children:t("config:whatsapp.deleteSession")})]},f.id))}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:"text",className:"wa-input",placeholder:t("config:whatsapp.addSessionPlaceholder"),value:K,onChange:f=>y(f.target.value),onKeyDown:f=>{f.key==="Enter"&&Te()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Te,disabled:!K.trim()||U!==null,children:t("config:whatsapp.addSession")})]}),U&&e.jsxs("div",{className:"wa-qr-panel",children:[e.jsxs("div",{className:"wa-qr-header",children:[e.jsx("span",{children:t("config:whatsapp.qrPrompt",{id:U})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Ae,children:t("config:whatsapp.cancelPairing")})]}),V?e.jsx("div",{className:"wa-qr-image",children:e.jsx("img",{src:V,alt:"WhatsApp pairing QR code"})}):e.jsxs("div",{className:"wa-qr-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.waitingForQr")})]})]}),T&&!U&&e.jsx("div",{className:"wa-pairing-message",children:T})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.testMessage")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-to",className:"wa-label",children:t("config:whatsapp.testTo")}),e.jsx("input",{id:"wa-test-to",type:"text",className:"wa-input",placeholder:t("config:whatsapp.testToPlaceholder"),value:v,onChange:f=>F(f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-message",className:"wa-label",children:t("config:whatsapp.testMessageBody")}),e.jsx("textarea",{id:"wa-test-message",className:"wa-textarea",rows:4,placeholder:t("config:whatsapp.testMessageBodyPlaceholder"),value:M,onChange:f=>N(f.target.value)})]}),e.jsx("div",{className:"wa-field-inline wa-field-end",children:e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ee,disabled:!v.trim()||!M.trim()||ee,children:t(ee?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),D&&e.jsxs("div",{className:`alert ${D.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:D.kind==="success"?"check":"warn",size:14})}),D.text]})]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left"}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:fe,children:t("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:$e,disabled:!Ne||C,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:ce,disabled:!Ne||C,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(me,{isOpen:Q,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{A(!1),a()},onClose:()=>A(!1)}),e.jsx(me,{isOpen:q,title:t("config:whatsapp.clearKey"),message:t("config:whatsapp.confirmClearKey"),confirmLabel:t("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Fe()},onClose:()=>te(!1)}),e.jsx(me,{isOpen:le,title:t("config:whatsapp.deleteSession"),message:t("config:whatsapp.confirmDeleteSession",{id:ue??""}),confirmLabel:t("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Oe()},onClose:()=>{ae(!1),ye(null)}})]}):null}const cs=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function He(s=!1){const a=Z(),t={};return a&&(t.Authorization=`Bearer ${a}`),s&&(t["Content-Type"]="application/json"),t}async function We(s,a){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${a}: ${s.statusText}`}async function vt(){const s=await fetch(`${J()}/api/whatsapp/notification-config`,{headers:He()});if(!s.ok)throw new Error(await We(s,"Failed to fetch WhatsApp notification config"));return s.json()}async function kt(s){const a=await fetch(`${J()}/api/whatsapp/notification-config`,{method:"PATCH",headers:He(!0),body:JSON.stringify(s)});if(!a.ok)throw new Error(await We(a,"Failed to update WhatsApp notification config"));return a.json()}async function St(){const s=await fetch(`${J()}/api/whatsapp/notification-config`,{method:"DELETE",headers:He()});if(!s.ok)throw new Error(await We(s,"Failed to reset WhatsApp notification config"));return s.json()}const Pe={messages:!0,statusChanges:!0,taskComplete:!0,errors:!0,planReady:!0,agentSpawned:!0,agentStopped:!0},es={filter:{...Pe},recipient:""};function Ct(s,a){if(s.recipient!==a.recipient)return!1;for(const t of cs)if(s.filter[t]!==a.filter[t])return!1;return!0}function Tt({isOpen:s,onClose:a}){const{t}=Y(["config"]),[o,r]=l.useState(es),[d,c]=l.useState(es),[g,n]=l.useState(!0),[x,w]=l.useState(null),[C,u]=l.useState(null),[p,m]=l.useState(!1),[j,b]=l.useState(!1),h=!Ct(o,d),k=l.useCallback(async()=>{try{n(!0),w(null),u(null);const S=await vt(),T={filter:{...Pe,...S.filter},recipient:S.recipient??""};r(T),c(T)}catch(S){w(S instanceof Error?S.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{n(!1)}},[t]);l.useEffect(()=>{s&&k()},[s,k]);const $=(S,T)=>{r(H=>({...H,filter:{...H.filter,[S]:T}})),w(null),u(null)},P=S=>{r(T=>({...T,recipient:S})),w(null),u(null)},K=async()=>{try{w(null),u(null);const S=await kt({filter:o.filter,recipient:o.recipient.trim()}),T={filter:{...Pe,...S.filter},recipient:S.recipient??""};r(T),c(T),u(t("config:whatsappNotifications.saved"))}catch(S){w(S instanceof Error?S.message:t("config:whatsappNotifications.errors.saveFailed"))}},y=()=>{r(d),w(null),u(null)},U=async()=>{try{w(null),u(null);const S=await St(),T={filter:{...Pe,...S.filter},recipient:S.recipient??""};r(T),c(T),u(t("config:whatsappNotifications.resetDone"))}catch(S){w(S instanceof Error?S.message:t("config:whatsappNotifications.errors.resetFailed"))}},B=()=>{if(h){m(!0);return}a()},V=S=>{S.key==="Escape"&&(S.preventDefault(),B())};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:B,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:S=>S.stopPropagation(),onKeyDown:V,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappNotifications.title")}),e.jsx("button",{className:"modal-close",onClick:B,"aria-label":"Close",children:e.jsx(L,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:g?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsappNotifications.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsappNotifications.description")}),x&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"warn",size:14})}),x]}),C&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"check",size:14})}),C]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.recipient")}),e.jsxs("div",{className:"wan-field",children:[e.jsx("label",{htmlFor:"wan-recipient",className:"wan-label",children:t("config:whatsappNotifications.recipientLabel")}),e.jsx("input",{id:"wan-recipient",type:"text",className:"wan-input",placeholder:t("config:whatsappNotifications.recipientPlaceholder"),value:o.recipient,onChange:S=>P(S.target.value)}),e.jsx("span",{className:"wan-hint",children:t("config:whatsappNotifications.recipientHint")})]})]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.events")}),e.jsx("p",{className:"wan-section-hint",children:t("config:whatsappNotifications.eventsHint")}),cs.map(S=>e.jsxs("div",{className:"wan-toggle-row",children:[e.jsxs("div",{className:"wan-toggle-info",children:[e.jsx("span",{className:"wan-toggle-title",children:t(`config:whatsappNotifications.events.${S}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${S}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:o.filter[S],onChange:T=>$(S,T.target.checked)}),e.jsx("span",{className:"wan-toggle-track",children:e.jsx("span",{className:"wan-toggle-thumb"})})]})]},S))]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:()=>b(!0),disabled:g,children:t("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:B,children:t("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:y,disabled:!h||g,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:K,disabled:!h||g,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(me,{isOpen:p,title:t("config:whatsappNotifications.unsavedTitle"),message:t("config:whatsappNotifications.unsavedMessage"),confirmLabel:t("config:whatsappNotifications.closeAnyway"),cancelLabel:t("config:whatsappNotifications.keepEditing"),variant:"danger",onConfirm:()=>{m(!1),a()},onClose:()=>m(!1)}),e.jsx(me,{isOpen:j,title:t("config:whatsappNotifications.resetToDefaults"),message:t("config:whatsappNotifications.confirmReset"),confirmLabel:t("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{U(),b(!1)},onClose:()=>b(!1)})]}):null}function rs(s){const a=s.replace(/@.*$/,"");return/^\d{10,15}$/.test(a)?a.startsWith("521")&&a.length===13?`+52 1 ${a.slice(3,5)} ${a.slice(5,9)} ${a.slice(9)}`:a.startsWith("52")&&a.length===12?`+52 ${a.slice(2,4)} ${a.slice(4,8)} ${a.slice(8)}`:a.startsWith("1")&&a.length===11?`+1 ${a.slice(1,4)} ${a.slice(4,7)} ${a.slice(7)}`:`+${a}`:s}function At(s,a=Date.now()){const t=s*1e3,o=a-t;if(o<0)return ss(t);const r=Math.floor(o/6e4);if(r<1)return"now";if(r<60)return`${r}m`;const d=Math.floor(r/60);if(d<24)return`${d}h`;const c=Math.floor(d/24);return c===1?"yesterday":c<7?`${c}d`:ss(t)}function ss(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function _t(s){const a=s*1e3;return new Date(a).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function ds(s){switch(s){case"image":return"📷";case"audio":return"🎤";case"video":return"📹";case"document":return"📎";case"location":return"📍";case"contact":return"👤";case"sticker":return"🌟";case"reaction":return"👍";case"unknown":return"❓";case"text":default:return null}}function Et(s,a){return s.length<=a?s:s.slice(0,Math.max(0,a-1)).trimEnd()+"…"}function It({chats:s,selectedChatId:a,loading:t,error:o,onSelect:r,onRefresh:d,now:c}){const{t:g}=Y(["config","common"]);return e.jsxs("div",{className:"whatsapp-history-chatlist",children:[e.jsxs("div",{className:"whatsapp-history-chatlist__header",children:[e.jsx("span",{className:"whatsapp-history-chatlist__title",children:g("config:whatsappHistory.chats")}),e.jsx("button",{type:"button",className:"whatsapp-history-chatlist__refresh",onClick:d,disabled:t,"aria-label":g("config:whatsappHistory.refresh"),title:g("config:whatsappHistory.refresh"),children:"⟳"})]}),o&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:o}),t&&s.length===0&&e.jsxs("div",{className:"whatsapp-history-chatlist__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:g("config:whatsappHistory.loadingChats")})]}),!t&&!o&&s.length===0&&e.jsx("div",{className:"whatsapp-history-chatlist__empty",children:g("config:whatsappHistory.emptyChats")}),e.jsx("ul",{className:"whatsapp-history-chatlist__items",children:s.map(n=>{const x=ds(n.lastMessageType),w=n.lastMessagePreview||`[${n.lastMessageType}]`,C=n.chatId===a,u=rs(n.chatId),p=n.isGroup?n.groupName:n.fromName,m=p||u,j=!!p&&p!==u;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${C?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>r(n.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:n.chatId,children:m}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:At(n.lastTimestamp,c)})]}),j&&e.jsx("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--jid",children:e.jsx("span",{className:"whatsapp-history-chatlist__jid",children:u})}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[n.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),x&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[x," "]}),Et(w,40)]}),n.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:n.unreadCount})]})]})},n.chatId)})})]})}function Pt({message:s}){const a=s.direction==="outbound"?"outbound":"inbound",t=ds(s.messageType),o=(s.body??"").trim(),r=o.length>0,d=r?null:`[${s.messageType}]`;return e.jsx("div",{className:`whatsapp-history-bubble whatsapp-history-bubble--${a}`,children:e.jsxs("div",{className:"whatsapp-history-bubble__inner",children:[t&&e.jsx("span",{className:"whatsapp-history-bubble__type-icon",title:s.messageType,children:t}),r?e.jsx("span",{className:"whatsapp-history-bubble__body",children:o}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:d}),s.audioTranscription&&e.jsxs("span",{className:"whatsapp-history-bubble__transcription",children:["“",s.audioTranscription,"”"]}),s.mediaPath&&e.jsx("a",{className:"whatsapp-history-bubble__media-link",href:s.mediaPath,target:"_blank",rel:"noopener noreferrer",children:s.mediaFilename||"open media"}),e.jsx("span",{className:"whatsapp-history-bubble__time",children:_t(s.timestamp)})]})})}const $t=["all","inbound","outbound"],Lt=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function Dt({direction:s,type:a,onDirectionChange:t,onTypeChange:o,disabled:r}){const{t:d}=Y(["config"]);return e.jsxs("div",{className:"whatsapp-history-filters",children:[e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:d("config:whatsappHistory.direction")}),e.jsx("select",{value:s,onChange:c=>t(c.target.value),disabled:r,children:$t.map(c=>e.jsx("option",{value:c,children:d(`config:whatsappHistory.directionValues.${c}`)},c))})]}),e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:d("config:whatsappHistory.type")}),e.jsx("select",{value:a,onChange:c=>o(c.target.value),disabled:r,children:Lt.map(c=>e.jsx("option",{value:c,children:d(`config:whatsappHistory.typeValues.${c}`)},c))})]})]})}const Ft=80;function Ot({chatId:s,messages:a,loading:t,loadingMore:o,error:r,hasMore:d,direction:c,type:g,onDirectionChange:n,onTypeChange:x,onLoadMore:w}){const{t:C}=Y(["config"]),u=l.useRef(null),p=l.useRef(null),m=l.useRef(!1),j=l.useRef(null);l.useEffect(()=>{p.current!==s&&(p.current=s,m.current=!1)},[s]),l.useLayoutEffect(()=>{u.current&&(m.current||a.length!==0&&(u.current.scrollTop=u.current.scrollHeight,m.current=!0))},[s,a.length]),l.useLayoutEffect(()=>{if(!u.current||j.current===null)return;const k=u.current.scrollHeight-j.current;j.current=null,k>0&&(u.current.scrollTop+=k)},[a.length]);const b=l.useCallback(()=>{!d||o||t||(u.current&&(j.current=u.current.scrollHeight),w())},[d,o,t,w]),h=l.useCallback(k=>{if(!m.current)return;k.currentTarget.scrollTop<=Ft&&b()},[b]);return s?e.jsxs("div",{className:"whatsapp-history-messages",children:[e.jsxs("div",{className:"whatsapp-history-messages__header",children:[e.jsx("div",{className:"whatsapp-history-messages__title",children:rs(s)}),e.jsx(Dt,{direction:c,type:g,onDirectionChange:n,onTypeChange:x,disabled:t})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:u,onScroll:h,children:[d&&e.jsx("div",{className:"whatsapp-history-messages__load-more-row",children:e.jsx("button",{type:"button",className:"whatsapp-history-messages__load-more",onClick:b,disabled:o||t,children:C(o?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),r&&e.jsx("div",{className:"whatsapp-history-messages__error",children:r}),t&&a.length===0&&e.jsxs("div",{className:"whatsapp-history-messages__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:C("config:whatsappHistory.loadingMessages")})]}),!t&&!r&&a.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:C("config:whatsappHistory.emptyMessages")}),a.map(k=>e.jsx(Pt,{message:k},Rt(k)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:C("config:whatsappHistory.selectChat")})})}function Rt(s){return typeof s.id=="number"?`id:${s.id}`:s.messageId?`mid:${s.messageId}`:`t:${s.timestamp}:${s.fromJid}:${(s.body??"").slice(0,16)}`}function us(){const s=Z(),a={};return s&&(a.Authorization=`Bearer ${s}`),a}async function ps(s,a){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${a}: ${s.statusText}`}async function Ut(s){const a=`${J()}/api/whatsapp/chats/${encodeURIComponent(s)}`,t=await fetch(a,{headers:us()});if(!t.ok)throw new Error(await ps(t,"Failed to fetch WhatsApp chats"));return t.json()}async function ts(s,a,t={}){const o=new URLSearchParams;t.cursor&&o.set("cursor",t.cursor),typeof t.limit=="number"&&o.set("limit",String(t.limit)),t.direction&&o.set("direction",t.direction),t.type&&o.set("type",t.type);const r=o.toString(),d=`${J()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(a)}/messages${r?`?${r}`:""}`,c=await fetch(d,{headers:us()});if(!c.ok)throw new Error(await ps(c,"Failed to fetch WhatsApp messages"));return c.json()}const zt=50;function Bt({isOpen:s,onClose:a}){const{t}=Y(["config"]),[o,r]=l.useState([]),[d,c]=l.useState(null),[g,n]=l.useState(null),[x,w]=l.useState([]),[C,u]=l.useState(!1),[p,m]=l.useState(null),[j,b]=l.useState(null),[h,k]=l.useState([]),[$,P]=l.useState(!1),[K,y]=l.useState(!1),[U,B]=l.useState(null),[V,S]=l.useState(null),[T,H]=l.useState("all"),[X,ie]=l.useState("all"),[v,F]=l.useState(()=>Date.now()),M=l.useRef(0);l.useEffect(()=>{if(!s)return;const A=window.setInterval(()=>F(Date.now()),6e4);return()=>window.clearInterval(A)},[s]),l.useEffect(()=>{if(!s)return;let A=!1;return(async()=>{var q;try{n(null);const[te,le]=await Promise.all([Me().catch(()=>[]),os().catch(()=>null)]);if(A)return;r(te);const ae=(le==null?void 0:le.defaultSessionId)||((q=te[0])==null?void 0:q.id)||null;c(ue=>ue??ae)}catch(te){if(A)return;n(te instanceof Error?te.message:String(te))}})(),()=>{A=!0}},[s]);const N=l.useCallback(async A=>{u(!0),m(null);try{const q=await Ut(A);w(q.chats)}catch(q){m(q instanceof Error?q.message:String(q))}finally{u(!1)}},[]);l.useEffect(()=>{!s||!d||(b(null),k([]),S(null),N(d))},[s,d,N]);const D=l.useMemo(()=>{const A={limit:zt};return T!=="all"&&(A.direction=T),X!=="all"&&(A.type=X),A},[T,X]),O=l.useCallback(async(A,q,te)=>{const le=++M.current;P(!0),B(null),k([]),S(null);try{const ae=await ts(A,q,te);if(le!==M.current)return;k([...ae.messages].reverse()),S(ae.nextCursor)}catch(ae){if(le!==M.current)return;B(ae instanceof Error?ae.message:String(ae))}finally{le===M.current&&P(!1)}},[]);l.useEffect(()=>{!s||!d||!j||O(d,j,D)},[s,d,j,D,O]);const ee=l.useCallback(async()=>{if(!(!d||!j||!V)){y(!0),B(null);try{const A=await ts(d,j,{...D,cursor:V});k(q=>[...[...A.messages].reverse(),...q]),S(A.nextCursor)}catch(A){B(A instanceof Error?A.message:String(A))}finally{y(!1)}}},[d,j,V,D]),se=l.useCallback(()=>{d&&N(d)},[d,N]),Q=l.useCallback(A=>{A.key==="Escape"&&(A.preventDefault(),a())},[a]);return s?e.jsx(Se,{children:e.jsx("div",{className:"modal-overlay visible",onClick:a,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:A=>A.stopPropagation(),onKeyDown:Q,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappHistory.title")}),e.jsx("div",{className:"whatsapp-history-modal__session",children:e.jsxs("label",{children:[e.jsx("span",{children:t("config:whatsappHistory.session")}),e.jsxs("select",{value:d??"",onChange:A=>c(A.target.value||null),disabled:o.length===0,children:[o.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),o.map(A=>e.jsxs("option",{value:A.id,children:[A.id,A.pairedNumber?` (${A.pairedNumber})`:""]},A.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:a,"aria-label":"Close",children:e.jsx(L,{name:"close",size:16})})]}),g&&e.jsx("div",{className:"whatsapp-history-modal__alert",children:g}),e.jsxs("div",{className:"whatsapp-history-modal__body",children:[e.jsx(It,{chats:x,selectedChatId:j,loading:C,error:p,onSelect:b,onRefresh:se,now:v}),e.jsx(Ot,{chatId:j,messages:h,loading:$,loadingMore:K,error:U,hasMore:V!==null,direction:T,type:X,onDirectionChange:H,onTypeChange:ie,onLoadMore:ee})]})]})})}):null}function Mt({isOpen:s,onClose:a,onOpenConfig:t,onOpenNotifications:o,onOpenHistory:r}){const{t:d}=Y(["config"]);if(l.useEffect(()=>{if(!s)return;const g=n=>{n.key==="Escape"&&(n.preventDefault(),a())};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[s,a]),!s)return null;const c=g=>{a(),g()};return e.jsx(Se,{children:e.jsx("div",{className:"modal-overlay visible",onClick:a,children:e.jsxs("div",{className:"whatsapp-hub-modal",onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"whatsapp-hub-modal__icon",children:"📱"}),d("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:a,"aria-label":"Close",children:e.jsx(L,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"whatsapp-hub-modal__intro",children:d("config:whatsappHub.intro",{defaultValue:"Pick what you want to manage for the WhatsApp integration."})}),e.jsxs("div",{className:"whatsapp-hub-modal__options",children:[e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(t),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(L,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:d("config:whatsappHub.config",{defaultValue:"Integration config"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:d("config:whatsappHub.configDesc",{defaultValue:"Server URL, API key, sessions and pairing."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(o),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(L,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:d("config:whatsappHub.notifications",{defaultValue:"Notifications"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:d("config:whatsappHub.notificationsDesc",{defaultValue:"Which agent events get forwarded and to whom."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(r),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(L,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:d("config:whatsappHub.history",{defaultValue:"History"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:d("config:whatsappHub.historyDesc",{defaultValue:"Browse persisted chats and messages."})})]})]})]})]})]})})})}const Vt=[{value:"auto",label:"Auto",icon:"🕐"},{value:"dawn",label:"Dawn",icon:"🌅"},{value:"day",label:"Day",icon:"☀️"},{value:"dusk",label:"Dusk",icon:"🌇"},{value:"night",label:"Night",icon:"🌙"}],Kt=[{value:"none",label:"Grass",icon:"🌱"},{value:"concrete",label:"Concrete",icon:"🏗️"},{value:"galactic",label:"Galactic",icon:"🌌"},{value:"metal",label:"Metal",icon:"⚙️"},{value:"hex",label:"Hex",icon:"⬡"},{value:"circuit",label:"Circuit",icon:"🔌"},{value:"pokemon-stadium",label:"Pokemon",icon:"🔴"}],Ht=[{value:"static",label:"Static",icon:"🧍"},{value:"idle",label:"Idle",icon:"🚶"},{value:"walk",label:"Walk",icon:"🚶‍♂️"},{value:"sprint",label:"Sprint",icon:"🏃"},{value:"jump",label:"Jump",icon:"⬆️"},{value:"fall",label:"Fall",icon:"⬇️"},{value:"crouch",label:"Crouch",icon:"🧎"},{value:"sit",label:"Sit",icon:"🪑"},{value:"die",label:"Die",icon:"💀"},{value:"emote-yes",label:"Yes",icon:"👍"},{value:"emote-no",label:"No",icon:"👎"}],Wt=[{value:"normal",label:"Normal",icon:"🎨"},{value:"bw",label:"B&W",icon:"⬛"},{value:"sepia",label:"Sepia",icon:"🟤"},{value:"cool",label:"Cool",icon:"❄️"},{value:"warm",label:"Warm",icon:"🔥"},{value:"neon",label:"Neon",icon:"💜"}],qt=[{key:"showTrees",icon:"🌳",label:"Trees"},{key:"showBushes",icon:"🌿",label:"Bushes"},{key:"showHouse",icon:"🏠",label:"House"},{key:"showLamps",icon:"💡",label:"Lamps"},{key:"showGrass",icon:"🟩",label:"Grass"},{key:"showClouds",icon:"☁️",label:"Clouds"}],Gt=[{value:null,label:"Auto",color:"linear-gradient(135deg, #4a90d9 0%, #0a1a2a 100%)"},{value:"#4a90d9",label:"Day Blue",color:"#4a90d9"},{value:"#0a1a2a",label:"Night",color:"#0a1a2a"},{value:"#ff6b35",label:"Sunset",color:"#ff6b35"},{value:"#1a0a2e",label:"Purple",color:"#1a0a2e"},{value:"#2d5a27",label:"Matrix",color:"#2d5a27"},{value:"#8b0000",label:"Blood",color:"#8b0000"},{value:"#000000",label:"Void",color:"#000000"}],Yt={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},Jt={none:"grass","pokemon-stadium":"pokemon"},Zt={"emote-yes":"yes","emote-no":"no"},Xt={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function oe({checked:s,onChange:a}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:t=>a(t.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function je({options:s,value:a,onChange:t,iconOnly:o=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(r=>e.jsxs("button",{className:`chip ${a===r.value?"active":""}`,onClick:()=>t(r.value),title:r.label,children:[e.jsx("span",{className:"chip-icon",children:r.icon}),!o&&e.jsx("span",{className:"chip-label",children:r.label})]},r.value))})}function _({text:s,query:a}){if(!a.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),o=a.toLowerCase(),r=t.indexOf(o);if(r===-1)return e.jsx(e.Fragment,{children:s});const d=s.slice(0,r),c=s.slice(r,r+a.length),g=s.slice(r+a.length);return e.jsxs(e.Fragment,{children:[d,e.jsx("mark",{className:"search-highlight",children:c}),g]})}const Qt=[{id:"general",title:"General",keywords:["history","hide costs","grid","fps","power saving","performance","limit","editor","external editor","language","idioma","语言","vibration","haptic","intensity","tab title","tmux","process persistence"]},{id:"agentNames",title:"Agent Names",keywords:["agent","names","custom","characters","rename"]},{id:"defaultClass",title:"Default Spawn Class",keywords:["default","class","spawn","agent","scout","builder","random"]},{id:"appearance",title:"Appearance",keywords:["theme","appearance","color","dark","light","style","look"]},{id:"connection",title:"Connection",keywords:["backend","url","auth","token","reconnect","server","api","connect","codex","opencode","binary","path"]},{id:"scene",title:"Scene",keywords:["character","size","indicator","scale","time","dawn","day","dusk","night","auto"]},{id:"terrain",title:"Terrain",keywords:["trees","bushes","house","lamps","grass","clouds","fog","brightness","floor","sky","color","environment","battlefield","size","grid","simple","minimal","dark","clean"]},{id:"modelStyle",title:"Agent Model Style",keywords:["saturation","roughness","metalness","glow","emissive","reflections","wireframe","color mode","material","shader"]},{id:"animations",title:"Animations",keywords:["idle","working","animation","walk","run","sprint","jump","sit","crouch"]},{id:"secrets",title:"Secrets",keywords:["secrets","api","key","password","credentials","env","environment"]},{id:"systemPrompt",title:"System Prompt",keywords:["system","prompt","global","instructions","ai","agent","rules","guidelines"]},{id:"data",title:"Data",keywords:["export","import","backup","restore","save","load","json"]},{id:"integrations",title:"Integrations",keywords:["integrations","integraciones","plugins","gmail","slack","jira","calendar","docx","email","whatsapp","notifications","notification","baileys","history","historial","chat","messages","inbox","config","setup"]},{id:"workflows",title:"Workflows",keywords:["workflow","automation","state machine","editor","actions","transitions","pipeline"]},{id:"triggers",title:"Triggers",keywords:["trigger","event","webhook","cron","slack","email","jira","matching","fire"]},{id:"monitoring",title:"Monitoring",keywords:["monitoring","logs","triggers","events","history","workflow","traces","audit","timeline"]},{id:"statistics",title:"Statistics",keywords:["statistics","stats","usage","tokens","token","claude","chart","graph","pie","cost"]},{id:"experimental",title:"Experimental",keywords:["experimental","2d","view","voice","assistant","speech","tts","text to speech","echo","prompt","duplicate"]},{id:"about",title:"About",keywords:["about","version","update","credits","github","releases"]}],Be=[{value:"auto",label:"Auto",icon:"🌐"},{value:"en",label:"English",icon:"🇺🇸"},{value:"zh-CN",label:"中文",icon:"🇨🇳"},{value:"es",label:"Español",icon:"🇪🇸"},{value:"hi",label:"हिन्दी",icon:"🇮🇳"},{value:"pt",label:"Português",icon:"🇧🇷"},{value:"ru",label:"Русский",icon:"🇷🇺"},{value:"ja",label:"日本語",icon:"🇯🇵"},{value:"de",label:"Deutsch",icon:"🇩🇪"},{value:"fr",label:"Français",icon:"🇫🇷"},{value:"it",label:"Italiano",icon:"🇮🇹"}];function ea({config:s,onChange:a,searchQuery:t="",onOpenIntegrationsModal:o,onOpenMonitoringModal:r,onOpenStatisticsModal:d,onOpenWorkflowEditor:c,onOpenTriggerManager:g}){var qe;const{t:n}=Y(["config","common"]),x=Ve(),w=Es(),[C,u]=l.useState(()=>Is(ke.DEFAULT_AGENT_CLASS)||"scout"),[p,m]=l.useState(x.settings.historyLimit),[j,b]=l.useState(()=>Ps()),[h,k]=l.useState(!1),[$,P]=l.useState(""),[K,y]=l.useState(()=>Z()),[U,B]=l.useState(!1),[V,S]=l.useState(!1),[T,H]=l.useState(""),[X,ie]=l.useState(!1),[v,F]=l.useState(!1),[M,N]=l.useState(!1),[D,O]=l.useState(!1),[ee,se]=l.useState(!1),[Q,A]=l.useState(""),[q,te]=l.useState(!1);l.useEffect(()=>{at().then(A).catch(()=>{})},[]),l.useEffect(()=>{st().then(i=>{i!==x.settings.experimentalEchoPrompt&&E.updateSettings({experimentalEchoPrompt:i})}).catch(()=>{})},[]),l.useEffect(()=>{it().then(i=>{i!==x.settings.tmuxMode&&E.updateSettings({tmuxMode:i})}).catch(()=>{})},[]),l.useEffect(()=>$s(i=>{b(i),k(!1)}),[]);const le=Vt.map(i=>({...i,label:n(`config:time.${i.value}`)})),ae=Kt.map(i=>({...i,label:n(`config:floor.${Jt[i.value]||i.value}`)})),ue=Ht.map(i=>({...i,label:n(`config:animation.${Zt[i.value]||i.value}`)})),ye=Wt.map(i=>({...i,label:n(`config:colorMode.${i.value}`)})),Ne=qt.map(i=>({...i,label:n(`config:terrain.${Yt[i.key]}`)})),re=Gt.map(i=>({...i,label:n(`config:sky.${Xt[i.value??""]}`)})),ge=t.trim()?Qt.filter(i=>{const z=t.toLowerCase();return i.title.toLowerCase().includes(z)||i.keywords.some(de=>de.toLowerCase().includes(z))}).map(i=>i.id):null,I=i=>ge?ge.includes(i):!0,pe=I("integrations"),ce=x.settings.customAgentNames||[],$e=ce.length>0?ce:Ls,fe=()=>{const i=T.trim();i&&!ce.includes(i)&&(E.updateSettings({customAgentNames:[...ce,i]}),H(""))},Le=i=>{E.updateSettings({customAgentNames:ce.filter(z=>z!==i)})},De=()=>{E.updateSettings({customAgentNames:[]})},Ce=()=>{const i=$.trim();if(i){if(j.includes(i)){P("");return}b([...j,i]),k(!0),P("")}},Fe=i=>{b(j.filter((z,de)=>de!==i)),k(!0)},ve=(i,z)=>{const de=i+z;if(de<0||de>=j.length)return;const be=j.slice();[be[i],be[de]]=[be[de],be[i]],b(be),k(!0)},Te=()=>{Fs(j),k(!1),ze()},Ae=i=>{y(i),B(!0)},_e=()=>{Ie(ke.AUTH_TOKEN,K),B(!1),ze()},Oe=i=>{A(i),te(!0)},Ee=()=>{nt(Q).catch(()=>{}),te(!1)},f=i=>{a({...s,terrain:{...s.terrain,...i}})},R=i=>{a({...s,modelStyle:{...s.modelStyle,...i}})},ne=i=>{a({...s,animations:{...s.animations,...i}})},xe=i=>{m(i),E.updateSettings({historyLimit:i})},hs=i=>{const z=s.terrain[i];typeof z=="boolean"&&f({[i]:!z})},G=t.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[ge&&ge.length===0&&e.jsx("div",{className:"config-no-results",children:n("config:noResults",{query:t})}),I("general")&&e.jsxs(W,{title:n("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:G&&I("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:p,onChange:i=>xe(parseInt(i.target.value)||100),min:50,max:2e3,step:50})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:general.hideCosts"),query:t})}),e.jsx(oe,{checked:x.settings.hideCost,onChange:i=>E.updateSettings({hideCost:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:general.grid"),query:t})}),e.jsx(oe,{checked:s.gridVisible,onChange:i=>a({...s,gridVisible:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:general.showFPS"),query:t})}),e.jsx(oe,{checked:x.settings.showFPS,onChange:i=>E.updateSettings({showFPS:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:general.fpsLimit"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:i=>a({...s,fpsLimit:parseInt(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.fpsLimit===0?"∞":s.fpsLimit})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: Reduce FPS when idle to save power",children:[e.jsx(_,{text:n("config:general.powerSaving"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(oe,{checked:x.settings.powerSaving,onChange:i=>E.updateSettings({powerSaving:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Wrap agent processes in tmux sessions so they survive server restarts (requires tmux installed)",children:e.jsx(_,{text:n("config:general.tmuxMode"),query:t})}),e.jsx(oe,{checked:x.settings.tmuxMode,onChange:async i=>{E.updateSettings({tmuxMode:i});try{await ot(i)}catch(z){console.error("Failed to sync tmux mode setting to server:",z)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:general.vibrationIntensity"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:x.settings.vibrationIntensity,onChange:i=>E.updateSettings({vibrationIntensity:parseInt(i.target.value)})}),e.jsx("span",{className:"config-value",children:x.settings.vibrationIntensity===0?n("config:vibrationValues.off"):x.settings.vibrationIntensity===1?n("config:vibrationValues.ultraLight"):x.settings.vibrationIntensity===2?n("config:vibrationValues.veryLight"):x.settings.vibrationIntensity===3?n("config:vibrationValues.light"):x.settings.vibrationIntensity===4?n("config:vibrationValues.medium"):n("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:general.externalEditor"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:n("config:general.externalEditorPlaceholder"),value:x.settings.externalEditorCommand||"",onChange:i=>E.updateSettings({externalEditorCommand:i.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:general.tabTitle"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:n("config:general.tabTitlePlaceholder"),value:x.settings.tabTitle||"",onChange:i=>E.updateSettings({tabTitle:i.target.value})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:general.language"),query:t})}),e.jsx(je,{options:Be,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((qe=Be.find(i=>i.value!=="auto"&&Ue.language.startsWith(i.value.split("-")[0])))==null?void 0:qe.value)||"en":"auto",onChange:i=>{var z;if(i==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const de=navigator.language,be=((z=Be.find(Ge=>Ge.value!=="auto"&&de.startsWith(Ge.value.split("-")[0])))==null?void 0:z.value)||"en";Ue.changeLanguage(be)}else localStorage.setItem("tide-commander-language-mode","manual"),Ue.changeLanguage(i)}})]})]}),I("agentNames")&&e.jsx(W,{title:n("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:G&&I("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:ce.length>0?n("config:agentNames.customConfigured",{count:ce.length}):n("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:n("config:agentNames.addPlaceholder"),value:T,onChange:i=>H(i.target.value),onKeyDown:i=>{i.key==="Enter"&&fe()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:fe,disabled:!T.trim(),title:n("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:$e.map((i,z)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:i}),ce.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>Le(i),title:n("common:buttons.remove"),children:"x"})]},`${i}-${z}`))}),ce.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:De,children:n("common:buttons.resetToDefaults")})]})}),I("defaultClass")&&e.jsx(W,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:G&&I("defaultClass"),children:e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-hint",children:'Class pre-selected when the spawn modal opens. "Random" picks a different class each time.'}),e.jsxs("div",{className:"agent-names-list",style:{flexWrap:"wrap",gap:"6px",marginTop:"8px"},children:[e.jsx("div",{className:`agent-name-chip${C==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{u("random"),Ie(ke.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(Ds).map(([i,z])=>e.jsx("div",{className:`agent-name-chip${C===i?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{u(i),Ie(ke.DEFAULT_AGENT_CLASS,i)},children:e.jsxs("span",{className:"agent-name-text",children:[z.icon," ",i.charAt(0).toUpperCase()+i.slice(1)]})},i)),w.map(i=>e.jsx("div",{className:`agent-name-chip${C===i.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{u(i.id),Ie(ke.DEFAULT_AGENT_CLASS,i.id)},children:e.jsxs("span",{className:"agent-name-text",children:[i.icon," ",i.name]})},i.id))]})]})}),I("appearance")&&e.jsx(W,{title:n("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:G&&I("appearance"),children:e.jsx(ht,{})}),I("connection")&&e.jsxs(W,{title:n("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:G&&I("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:j.map((i,z)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:n("config:connection.priorityLabel",{defaultValue:"Priority"}),children:z+1}),e.jsx("span",{className:"backend-url-text",title:i,children:i}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>ve(z,-1),disabled:z===0,title:n("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>ve(z,1),disabled:z===j.length-1,title:n("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Fe(z),title:n("common:buttons.remove"),children:"x"})]},`${i}-${z}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:$,onChange:i=>P(i.target.value),placeholder:n("config:connection.addUrlPlaceholder",{defaultValue:"http://host:port"}),onKeyDown:i=>{i.key==="Enter"&&Ce()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ce,disabled:!$.trim(),title:n("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),h&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Te,title:n("config:connection.saveAndReconnect"),children:n("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:n("config:connection.urlsHint",{defaultValue:"Tried in order on connect; the first reachable host wins. Leave empty for auto-detect."})})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:connection.authToken"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:V?"text":"password",className:"config-input config-input-full",value:K,onChange:i=>Ae(i.target.value),placeholder:n("config:connection.tokenPlaceholder"),onKeyDown:i=>{i.key==="Enter"&&U&&_e()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>S(!V),title:n(V?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(L,{name:V?"eye-closed":"eye",size:14})}),U&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:_e,title:n("config:connection.saveAndReconnect"),children:n("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:n("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:connection.codexBinaryPath"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:Q,onChange:i=>Oe(i.target.value),placeholder:n("config:connection.codexBinaryPathPlaceholder"),onKeyDown:i=>{i.key==="Enter"&&q&&Ee()}}),q&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ee,children:n("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:n("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("common:buttons.reconnect"),query:t})}),e.jsx("button",{className:"config-btn",onClick:()=>ze(),title:"Force reconnect to server",children:n("common:buttons.reconnect")})]})]}),I("scene")&&e.jsxs(W,{title:n("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:G&&I("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:scene.characterSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"3.0",step:"0.1",value:s.characterScale,onChange:i=>a({...s,characterScale:parseFloat(i.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.characterScale.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:scene.scale2d",{defaultValue:"2D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale2d,onChange:i=>a({...s,scale2d:parseFloat(i.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale2d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:scene.scale3d",{defaultValue:"3D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale3d,onChange:i=>a({...s,scale3d:parseFloat(i.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale3d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:t})}),e.jsx(oe,{checked:s.show2DTaskLabels,onChange:i=>a({...s,show2DTaskLabels:i})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:scene.time"),query:t})}),e.jsx(je,{options:le,value:s.timeMode,onChange:i=>a({...s,timeMode:i}),iconOnly:!0})]})]}),I("terrain")&&e.jsxs(W,{title:n("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:G&&I("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:t})}),e.jsx(oe,{checked:s.terrain.simpleMode??!1,onChange:i=>f({simpleMode:i})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:Ne.map(i=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[i.key]?"active":""}`,onClick:()=>hs(i.key),title:i.label,children:i.icon},i.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:terrainSettings.fog"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.terrain.fogDensity,onChange:i=>f({fogDensity:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?n("config:fogValues.off"):s.terrain.fogDensity<=1?n("config:fogValues.low"):n("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:terrainSettings.brightness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.2",max:"2",step:"0.1",value:s.terrain.brightness,onChange:i=>f({brightness:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?n("config:brightnessValues.dark"):s.terrain.brightness<=1.2?n("config:brightnessValues.normal"):n("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:terrainSettings.floor"),query:t})}),e.jsx(je,{options:ae,value:s.terrain.floorStyle,onChange:i=>f({floorStyle:i}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:terrainSettings.sky"),query:t})}),e.jsx("div",{className:"sky-color-selector",children:re.map(i=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===i.value?"active":""}`,onClick:()=>f({skyColor:i.value}),title:i.label,style:{background:i.color}},i.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:terrainSettings.battlefieldSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:i=>f({battlefieldSize:parseInt(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),I("modelStyle")&&e.jsxs(W,{title:n("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:G&&I("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:modelStyleSettings.saturation"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.modelStyle.saturation,onChange:i=>R({saturation:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?n("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?n("config:saturationValues.normal"):n("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:modelStyleSettings.roughness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.roughness,onChange:i=>R({roughness:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?n("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?n("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?n("config:roughnessValues.normal"):n("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:modelStyleSettings.metalness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.metalness,onChange:i=>R({metalness:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?n("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?n("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?n("config:metalnessValues.mixed"):n("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:modelStyleSettings.glow"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"1",step:"0.05",value:s.modelStyle.emissiveBoost,onChange:i=>R({emissiveBoost:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?n("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?n("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?n("config:glowValues.med"):n("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:modelStyleSettings.reflections"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"2",step:"0.1",value:s.modelStyle.envMapIntensity,onChange:i=>R({envMapIntensity:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?n("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?n("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?n("config:reflectionValues.normal"):n("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:modelStyleSettings.wireframe"),query:t})}),e.jsx(oe,{checked:s.modelStyle.wireframe,onChange:i=>R({wireframe:i})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:modelStyleSettings.colorMode"),query:t})}),e.jsx(je,{options:ye,value:s.modelStyle.colorMode,onChange:i=>R({colorMode:i}),iconOnly:!0})]})]}),I("animations")&&e.jsxs(W,{title:n("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:G&&I("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:animationSettings.idle"),query:t})}),e.jsx(je,{options:ue,value:s.animations.idleAnimation,onChange:i=>ne({idleAnimation:i}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:animationSettings.working"),query:t})}),e.jsx(je,{options:ue,value:s.animations.workingAnimation,onChange:i=>ne({workingAnimation:i}),iconOnly:!0})]})]}),I("secrets")&&e.jsx(W,{title:n("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:G&&I("secrets"),children:e.jsx(Zs,{})}),I("systemPrompt")&&e.jsx(W,{title:n("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:G&&I("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:n("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>ie(!0),children:n("config:systemPrompt.editPrompt")})]})}),I("data")&&e.jsx(W,{title:n("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:G&&I("data"),children:e.jsx(dt,{})}),pe&&e.jsx(W,{title:n("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:G&&pe,children:e.jsx(xt,{onOpenModal:i=>{i==="whatsapp"?se(!0):o==null||o(i)}})}),I("workflows")&&e.jsxs(W,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:G&&I("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(_,{text:"Create and manage automated workflow pipelines with visual state machine editor",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>c==null?void 0:c(),children:"Open Workflow Editor"})})]}),I("triggers")&&e.jsxs(W,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:G&&I("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(_,{text:"Create and manage event-driven triggers that fire agents with templates",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>g==null?void 0:g(),children:"Open Trigger Manager"})})]}),I("monitoring")&&e.jsxs(W,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:G&&I("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(_,{text:"View event logs, trigger history, workflow traces, and system stats",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>r==null?void 0:r(),children:"Open Monitoring & Logs"})})]}),I("statistics")&&e.jsxs(W,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:G&&I("statistics"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(_,{text:"View token usage charts and system-wide agent statistics",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>d==null?void 0:d(),children:"Open Statistics"})})]}),I("experimental")&&e.jsxs(W,{title:n("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:G&&I("experimental"),children:[e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Lightweight 2D top-down view for better performance",children:[e.jsx(_,{text:n("config:experimental.2dView"),query:t})," ",e.jsx(L,{name:"map",size:12})]}),e.jsx(oe,{checked:x.settings.experimental2DView,onChange:i=>E.updateSettings({experimental2DView:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(_,{text:n("config:experimental.voiceAssistant"),query:t})," ",e.jsx(L,{name:"microphone",size:12})]}),e.jsx(oe,{checked:x.settings.experimentalVoiceAssistant,onChange:i=>E.updateSettings({experimentalVoiceAssistant:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(_,{text:n("config:experimental.tts"),query:t})," ",e.jsx(L,{name:"speaker-on",size:12})]}),e.jsx(oe,{checked:x.settings.experimentalTTS,onChange:i=>E.updateSettings({experimentalTTS:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Duplicate system prompt for improved LLM attention coverage. Increases input token usage.",children:e.jsx(_,{text:n("config:experimental.echoPrompt"),query:t})}),e.jsx(oe,{checked:x.settings.experimentalEchoPrompt,onChange:async i=>{E.updateSettings({experimentalEchoPrompt:i});try{await tt(i)}catch(z){console.error("Failed to sync echo prompt setting to server:",z)}}})]}),e.jsx("span",{className:"config-hint",children:n("config:experimental.hint")})]}),I("about")&&e.jsx(W,{title:n("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:G&&I("about"),children:e.jsx(gt,{})})]}),e.jsx(bt,{isOpen:X,onClose:()=>ie(!1)}),e.jsx(Nt,{isOpen:v,onClose:()=>F(!1)}),e.jsx(Tt,{isOpen:M,onClose:()=>N(!1)}),e.jsx(Bt,{isOpen:D,onClose:()=>O(!1)}),e.jsx(Mt,{isOpen:ee,onClose:()=>se(!1),onOpenConfig:()=>F(!0),onOpenNotifications:()=>N(!0),onOpenHistory:()=>O(!0)})]})}function na({onConfigChange:s,onToolChange:a,config:t,isOpen:o,onClose:r,onOpenBuildingModal:d,onOpenAreaExplorer:c,onOpenIntegrationsModal:g,onOpenMonitoringModal:n,onOpenStatisticsModal:x,onOpenWorkflowEditor:w,onOpenTriggerManager:C}){const{t:u}=Y(["config","common"]),p=Ve(),m=Array.from(p.areas.values()),j=Array.from(p.buildings.values()),[b,h]=l.useState(""),k=l.useRef(null);if(l.useEffect(()=>{const y=U=>{U.key==="Escape"&&o&&r()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[o,r]),l.useEffect(()=>{if(o&&k.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const U=setTimeout(()=>{var B;(B=k.current)==null||B.focus()},50);return()=>clearTimeout(U)}},[o]),!o)return null;const $=y=>{const U=p.activeTool===y?null:y;a(U)},P=y=>{E.selectArea(p.selectedAreaId===y?null:y),a("select")},K=(y,U)=>{y.stopPropagation(),E.deleteArea(U)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:r}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:u("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:r,title:u("common:buttons.close"),children:"×"})]}),e.jsxs("div",{className:"toolbox-search",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{ref:k,type:"text",placeholder:u("config:searchPlaceholder"),value:b,onChange:y=>h(y.target.value),className:"toolbox-search-input"}),b&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>h(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(W,{title:u("config:areas.title",{count:m.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${p.activeTool==="select"?"active":""}`,onClick:()=>$("select"),title:u("config:tools.select"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"})})})}),e.jsx("button",{className:`tool-btn ${p.activeTool==="rectangle"?"active":""}`,onClick:()=>$("rectangle"),title:u("config:tools.rectangle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",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("button",{className:`tool-btn ${p.activeTool==="circle"?"active":""}`,onClick:()=>$("circle"),title:u("config:tools.circle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("circle",{cx:"12",cy:"12",r:"9"})})})})]}),e.jsx("div",{className:"areas-list",children:m.length===0?e.jsx("div",{className:"areas-empty",children:u("config:areas.drawToCreate")}):m.map(y=>e.jsx(Vs,{area:y,isSelected:p.selectedAreaId===y.id,onClick:()=>P(y.id),onDelete:U=>K(U,y.id)},y.id))})]})}),p.selectedAreaId&&e.jsx(Js,{area:p.areas.get(p.selectedAreaId),onClose:()=>E.selectArea(null),onOpenFolder:c}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(W,{title:u("config:buildings.title",{count:j.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:y=>{y.stopPropagation(),d==null||d()},title:u("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:j.length===0?e.jsx("div",{className:"buildings-empty",children:u("config:buildings.clickToAdd")}):j.map(y=>e.jsx(Ks,{building:y,isSelected:p.selectedBuildingIds.has(y.id),onClick:()=>{E.selectBuilding(p.selectedBuildingIds.has(y.id)?null:y.id)},onEdit:()=>d==null?void 0:d(y.id)},y.id))})})}),p.selectedBuildingIds.size===1&&(()=>{const y=Array.from(p.selectedBuildingIds)[0],U=p.buildings.get(y);return U?e.jsx(Hs,{building:U,onClose:()=>E.selectBuilding(null),onOpenModal:()=>d==null?void 0:d(y)}):null})(),e.jsx(ea,{config:t,onChange:s,searchQuery:b,onOpenIntegrationsModal:g,onOpenMonitoringModal:n,onOpenStatisticsModal:x,onOpenWorkflowEditor:w,onOpenTriggerManager:C})]})]})]})}export{na as Toolbox};
@@ -1 +1 @@
1
- import{j as d,I as J,aj as Ge,U as He,W as Je,bY as Xe,r as y,s as te,bZ as ve,_ as Ze,ad as de,u as Ee}from"./main-BxA3Bhkv.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function ee(t){return Array.isArray?Array.isArray(t):Te(t)==="[object Array]"}function qe(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function et(t){return t==null?"":qe(t)}function Z(t){return typeof t=="string"}function $e(t){return typeof t=="number"}function tt(t){return t===!0||t===!1||st(t)&&Te(t)=="[object Boolean]"}function Le(t){return typeof t=="object"}function st(t){return Le(t)&&t!==null}function O(t){return t!=null}function fe(t){return!t.trim().length}function Te(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const nt="Incorrect 'index' type",rt=t=>`Invalid value for key ${t}`,it=t=>`Pattern length exceeds max of ${t}.`,ct=t=>`Missing ${t} property in key`,ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Se=Object.prototype.hasOwnProperty;class at{constructor(e){this._keys=[],this._keyMap={};let s=0;e.forEach(n=>{let r=Pe(n);this._keys.push(r),this._keyMap[r.id]=r,s+=r.weight}),this._keys.forEach(n=>{n.weight/=s})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function Pe(t){let e=null,s=null,n=null,r=1,c=null;if(Z(t)||ee(t))n=t,e=be(t),s=me(t);else{if(!Se.call(t,"name"))throw new Error(ct("name"));const o=t.name;if(n=o,Se.call(t,"weight")&&(r=t.weight,r<=0))throw new Error(ot(o));e=be(o),s=me(o),c=t.getFn}return{path:e,id:s,weight:r,src:n,getFn:c}}function be(t){return ee(t)?t:t.split(".")}function me(t){return ee(t)?t.join("."):t}function ut(t,e){let s=[],n=!1;const r=(c,o,a)=>{if(O(c))if(!o[a])s.push(c);else{let u=o[a];const l=c[u];if(!O(l))return;if(a===o.length-1&&(Z(l)||$e(l)||tt(l)))s.push(et(l));else if(ee(l)){n=!0;for(let h=0,f=l.length;h<f;h+=1)r(l[h],o,a+1)}else o.length&&r(l,o,a+1)}};return r(t,Z(e)?e.split("."):e,0),n?s:s[0]}const lt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},ht={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},dt={location:0,threshold:.6,distance:100},ft={useExtendedSearch:!1,getFn:ut,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var p={...ht,...lt,...dt,...ft};const mt=/[^ ]+/g;function pt(t=1,e=3){const s=new Map,n=Math.pow(10,e);return{get(r){const c=r.match(mt).length;if(s.has(c))return s.get(c);const o=1/Math.pow(c,.5*t),a=parseFloat(Math.round(o*n)/n);return s.set(c,a),a},clear(){s.clear()}}}class Ce{constructor({getFn:e=p.getFn,fieldNormWeight:s=p.fieldNormWeight}={}){this.norm=pt(s,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((s,n)=>{this._keysMap[s.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,Z(this.docs[0])?this.docs.forEach((e,s)=>{this._addString(e,s)}):this.docs.forEach((e,s)=>{this._addObject(e,s)}),this.norm.clear())}add(e){const s=this.size();Z(e)?this._addString(e,s):this._addObject(e,s)}removeAt(e){this.records.splice(e,1);for(let s=e,n=this.size();s<n;s+=1)this.records[s].i-=1}getValueForItemAtKeyId(e,s){return e[this._keysMap[s]]}size(){return this.records.length}_addString(e,s){if(!O(e)||fe(e))return;let n={v:e,i:s,n:this.norm.get(e)};this.records.push(n)}_addObject(e,s){let n={i:s,$:{}};this.keys.forEach((r,c)=>{let o=r.getFn?r.getFn(e):this.getFn(e,r.path);if(O(o)){if(ee(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(O(h))if(Z(h)&&!fe(h)){let f={v:h,i:l,n:this.norm.get(h)};a.push(f)}else ee(h)&&h.forEach((f,m)=>{u.push({nestedArrIndex:m,value:f})})}n.$[c]=a}else if(Z(o)&&!fe(o)){let a={v:o,n:this.norm.get(o)};n.$[c]=a}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function Ke(t,e,{getFn:s=p.getFn,fieldNormWeight:n=p.fieldNormWeight}={}){const r=new Ce({getFn:s,fieldNormWeight:n});return r.setKeys(t.map(Pe)),r.setSources(e),r.create(),r}function gt(t,{getFn:e=p.getFn,fieldNormWeight:s=p.fieldNormWeight}={}){const{keys:n,records:r}=t,c=new Ce({getFn:e,fieldNormWeight:s});return c.setKeys(n),c.setIndexRecords(r),c}function ue(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:r=p.distance,ignoreLocation:c=p.ignoreLocation}={}){const o=e/t.length;if(c)return o;const a=Math.abs(n-s);return r?o+a/r:a?1:o}function At(t=[],e=p.minMatchCharLength){let s=[],n=-1,r=-1,c=0;for(let o=t.length;c<o;c+=1){let a=t[c];a&&n===-1?n=c:!a&&n!==-1&&(r=c-1,r-n+1>=e&&s.push([n,r]),n=-1)}return t[c-1]&&c-n>=e&&s.push([n,c-1]),s}const re=32;function yt(t,e,s,{location:n=p.location,distance:r=p.distance,threshold:c=p.threshold,findAllMatches:o=p.findAllMatches,minMatchCharLength:a=p.minMatchCharLength,includeMatches:u=p.includeMatches,ignoreLocation:l=p.ignoreLocation}={}){if(e.length>re)throw new Error(it(re));const h=e.length,f=t.length,m=Math.max(0,Math.min(n,f));let g=c,x=m;const S=a>1||u,N=S?Array(f):[];let j;for(;(j=t.indexOf(e,x))>-1;){let E=ue(e,{currentLocation:j,expectedLocation:m,distance:r,ignoreLocation:l});if(g=Math.min(E,g),x=j+h,S){let C=0;for(;C<h;)N[j+C]=1,C+=1}}x=-1;let L=[],Q=1,z=h+f;const ie=1<<h-1;for(let E=0;E<h;E+=1){let C=0,B=z;for(;C<B;)ue(e,{errors:E,currentLocation:m+B,expectedLocation:m,distance:r,ignoreLocation:l})<=g?C=B:z=B,B=Math.floor((z-C)/2+C);z=B;let P=Math.max(1,m-B+1),K=o?f:Math.min(m+B,f)+h,W=Array(K+2);W[K+1]=(1<<E)-1;for(let _=K;_>=P;_-=1){let q=_-1,ae=s[t.charAt(q)];if(S&&(N[q]=+!!ae),W[_]=(W[_+1]<<1|1)&ae,E&&(W[_]|=(L[_+1]|L[_])<<1|1|L[_+1]),W[_]&ie&&(Q=ue(e,{errors:E,currentLocation:q,expectedLocation:m,distance:r,ignoreLocation:l}),Q<=g)){if(g=Q,x=q,x<=m)break;P=Math.max(1,2*m-x)}}if(ue(e,{errors:E+1,currentLocation:m,expectedLocation:m,distance:r,ignoreLocation:l})>g)break;L=W}const U={isMatch:x>=0,score:Math.max(.001,Q)};if(S){const E=At(N,a);E.length?u&&(U.indices=E):U.isMatch=!1}return U}function xt(t){let e={};for(let s=0,n=t.length;s<n;s+=1){const r=t.charAt(s);e[r]=(e[r]||0)|1<<n-s-1}return e}const le=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class Oe{constructor(e,{location:s=p.location,threshold:n=p.threshold,distance:r=p.distance,includeMatches:c=p.includeMatches,findAllMatches:o=p.findAllMatches,minMatchCharLength:a=p.minMatchCharLength,isCaseSensitive:u=p.isCaseSensitive,ignoreDiacritics:l=p.ignoreDiacritics,ignoreLocation:h=p.ignoreLocation}={}){if(this.options={location:s,threshold:n,distance:r,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?le(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const f=(g,x)=>{this.chunks.push({pattern:g,alphabet:xt(g),startIndex:x})},m=this.pattern.length;if(m>re){let g=0;const x=m%re,S=m-x;for(;g<S;)f(this.pattern.substr(g,re),g),g+=re;if(x){const N=m-re;f(this.pattern.substr(N),N)}}else f(this.pattern,0)}searchIn(e){const{isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=s?e:e.toLowerCase(),e=n?le(e):e,this.pattern===e){let S={isMatch:!0,score:0};return r&&(S.indices=[[0,e.length-1]]),S}const{location:c,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let f=[],m=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:N,startIndex:j})=>{const{isMatch:L,score:Q,indices:z}=yt(e,S,N,{location:c+j,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:r,ignoreLocation:h});L&&(g=!0),m+=Q,L&&z&&(f=[...f,...z])});let x={isMatch:g,score:g?m/this.chunks.length:1};return g&&r&&(x.indices=f),x}}class se{constructor(e){this.pattern=e}static isMultiMatch(e){return ke(e,this.multiRegex)}static isSingleMatch(e){return ke(e,this.singleRegex)}search(){}}function ke(t,e){const s=t.match(e);return s?s[1]:null}class Et extends se{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const s=e===this.pattern;return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class Ct extends se{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const n=e.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class wt extends se{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const s=e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class Ft extends se{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const s=!e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class Mt extends se{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const s=e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class It extends se{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const s=!e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class ze extends se{constructor(e,{location:s=p.location,threshold:n=p.threshold,distance:r=p.distance,includeMatches:c=p.includeMatches,findAllMatches:o=p.findAllMatches,minMatchCharLength:a=p.minMatchCharLength,isCaseSensitive:u=p.isCaseSensitive,ignoreDiacritics:l=p.ignoreDiacritics,ignoreLocation:h=p.ignoreLocation}={}){super(e),this._bitapSearch=new Oe(e,{location:s,threshold:n,distance:r,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class Qe extends se{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let s=0,n;const r=[],c=this.pattern.length;for(;(n=e.indexOf(this.pattern,s))>-1;)s=n+c,r.push([n,s-1]);const o=!!r.length;return{isMatch:o,score:o?0:1,indices:r}}}const pe=[Et,Qe,wt,Ft,It,Mt,Ct,ze],je=pe.length,Dt=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Bt="|";function vt(t,e={}){return t.split(Bt).map(s=>{let n=s.trim().split(Dt).filter(c=>c&&!!c.trim()),r=[];for(let c=0,o=n.length;c<o;c+=1){const a=n[c];let u=!1,l=-1;for(;!u&&++l<je;){const h=pe[l];let f=h.isMultiMatch(a);f&&(r.push(new h(f,e)),u=!0)}if(!u)for(l=-1;++l<je;){const h=pe[l];let f=h.isSingleMatch(a);if(f){r.push(new h(f,e));break}}}return r})}const St=new Set([ze.type,Qe.type]);class bt{constructor(e,{isCaseSensitive:s=p.isCaseSensitive,ignoreDiacritics:n=p.ignoreDiacritics,includeMatches:r=p.includeMatches,minMatchCharLength:c=p.minMatchCharLength,ignoreLocation:o=p.ignoreLocation,findAllMatches:a=p.findAllMatches,location:u=p.location,threshold:l=p.threshold,distance:h=p.distance}={}){this.query=null,this.options={isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:c,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=s?e:e.toLowerCase(),e=n?le(e):e,this.pattern=e,this.query=vt(this.pattern,this.options)}static condition(e,s){return s.useExtendedSearch}searchIn(e){const s=this.query;if(!s)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:c}=this.options;e=r?e:e.toLowerCase(),e=c?le(e):e;let o=0,a=[],u=0;for(let l=0,h=s.length;l<h;l+=1){const f=s[l];a.length=0,o=0;for(let m=0,g=f.length;m<g;m+=1){const x=f[m],{isMatch:S,indices:N,score:j}=x.search(e);if(S){if(o+=1,u+=j,n){const L=x.constructor.type;St.has(L)?a=[...a,...N]:a.push(N)}}else{u=0,o=0,a.length=0;break}}if(o){let m={isMatch:!0,score:u/o};return n&&(m.indices=a),m}}return{isMatch:!1,score:1}}}const ge=[];function kt(...t){ge.push(...t)}function Ae(t,e){for(let s=0,n=ge.length;s<n;s+=1){let r=ge[s];if(r.condition(t,e))return new r(t,e)}return new Oe(t,e)}const he={AND:"$and",OR:"$or"},ye={PATH:"$path",PATTERN:"$val"},xe=t=>!!(t[he.AND]||t[he.OR]),jt=t=>!!t[ye.PATH],Nt=t=>!ee(t)&&Le(t)&&!xe(t),Ne=t=>({[he.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function We(t,e,{auto:s=!0}={}){const n=r=>{let c=Object.keys(r);const o=jt(r);if(!o&&c.length>1&&!xe(r))return n(Ne(r));if(Nt(r)){const u=o?r[ye.PATH]:c[0],l=o?r[ye.PATTERN]:r[u];if(!Z(l))throw new Error(rt(u));const h={keyId:me(u),pattern:l};return s&&(h.searcher=Ae(l,e)),h}let a={children:[],operator:c[0]};return c.forEach(u=>{const l=r[u];ee(l)&&l.forEach(h=>{a.children.push(n(h))})}),a};return xe(t)||(t=Ne(t)),n(t)}function _t(t,{ignoreFieldNorm:e=p.ignoreFieldNorm}){t.forEach(s=>{let n=1;s.matches.forEach(({key:r,norm:c,score:o})=>{const a=r?r.weight:null;n*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:c))}),s.score=n})}function Rt(t,e){const s=t.matches;e.matches=[],O(s)&&s.forEach(n=>{if(!O(n.indices)||!n.indices.length)return;const{indices:r,value:c}=n;let o={indices:r,value:c};n.key&&(o.key=n.key.src),n.idx>-1&&(o.refIndex=n.idx),e.matches.push(o)})}function $t(t,e){e.score=t.score}function Lt(t,e,{includeMatches:s=p.includeMatches,includeScore:n=p.includeScore}={}){const r=[];return s&&r.push(Rt),n&&r.push($t),t.map(c=>{const{idx:o}=c,a={item:e[o],refIndex:o};return r.length&&r.forEach(u=>{u(c,a)}),a})}class X{constructor(e,s={},n){this.options={...p,...s},this.options.useExtendedSearch,this._keyStore=new at(this.options.keys),this.setCollection(e,n)}setCollection(e,s){if(this._docs=e,s&&!(s instanceof Ce))throw new Error(nt);this._myIndex=s||Ke(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){O(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const s=[];for(let n=0,r=this._docs.length;n<r;n+=1){const c=this._docs[n];e(c,n)&&(this.removeAt(n),n-=1,r-=1,s.push(c))}return s}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:s=-1}={}){const{includeMatches:n,includeScore:r,shouldSort:c,sortFn:o,ignoreFieldNorm:a}=this.options;let u=Z(e)?Z(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return _t(u,{ignoreFieldNorm:a}),c&&u.sort(o),$e(s)&&s>-1&&(u=u.slice(0,s)),Lt(u,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(e){const s=Ae(e,this.options),{records:n}=this._myIndex,r=[];return n.forEach(({v:c,i:o,n:a})=>{if(!O(c))return;const{isMatch:u,score:l,indices:h}=s.searchIn(c);u&&r.push({item:c,idx:o,matches:[{score:l,value:c,norm:a,indices:h}]})}),r}_searchLogical(e){const s=We(e,this.options),n=(a,u,l)=>{if(!a.children){const{keyId:f,searcher:m}=a,g=this._findMatches({key:this._keyStore.get(f),value:this._myIndex.getValueForItemAtKeyId(u,f),searcher:m});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let f=0,m=a.children.length;f<m;f+=1){const g=a.children[f],x=n(g,u,l);if(x.length)h.push(...x);else if(a.operator===he.AND)return[]}return h},r=this._myIndex.records,c={},o=[];return r.forEach(({$:a,i:u})=>{if(O(a)){let l=n(s,a,u);l.length&&(c[u]||(c[u]={idx:u,item:a,matches:[]},o.push(c[u])),l.forEach(({matches:h})=>{c[u].matches.push(...h)}))}}),o}_searchObjectList(e){const s=Ae(e,this.options),{keys:n,records:r}=this._myIndex,c=[];return r.forEach(({$:o,i:a})=>{if(!O(o))return;let u=[];n.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:s}))}),u.length&&c.push({idx:a,item:o,matches:u})}),c}_findMatches({key:e,value:s,searcher:n}){if(!O(s))return[];let r=[];if(ee(s))s.forEach(({v:c,i:o,n:a})=>{if(!O(c))return;const{isMatch:u,score:l,indices:h}=n.searchIn(c);u&&r.push({score:l,key:e,value:c,idx:o,norm:a,indices:h})});else{const{v:c,n:o}=s,{isMatch:a,score:u,indices:l}=n.searchIn(c);a&&r.push({score:u,key:e,value:c,norm:o,indices:l})}return r}}X.version="7.1.0";X.createIndex=Ke;X.parseIndex=gt;X.config=p;X.parseQuery=We;kt(bt);const _e={".ts":"file-code",".tsx":"atom",".js":"file-code",".jsx":"atom",".py":"file-code",".rs":"file-code",".go":"file-code",".md":"file-text",".json":"clipboard",".yaml":"gear",".yml":"gear",".css":"palette",".scss":"palette",".html":"globe",".sql":"database",".sh":"terminal",".env":"lock",".toml":"gear",".lock":"lock",default:"file-text"};function Tt(t){switch(t){case"scout":return"class-scout";case"builder":return"class-builder";case"debugger":return"class-debugger";case"architect":return"class-architect";case"warrior":return"class-warrior";case"support":return"class-support";case"boss":return"class-boss";default:return"class-default"}}function Pt(t,e=16){var r;const s="."+(((r=t.split(".").pop())==null?void 0:r.toLowerCase())??""),n=_e[s]||_e.default;return d.jsx(J,{name:n,size:e})}function Jt(t,e=16){return d.jsx(J,{name:Tt(t),size:e,weight:"fill"})}function Ve(t){const e=Math.floor(t/1e3),s=Math.floor(e/60),n=Math.floor(s/60),r=Math.floor(n/24);return r>0?`${r}d ${n%24}h ago`:n>0?`${n}h ${s%60}m ago`:s>0?`${s}m ago`:"just now"}function Xt(t){const s=Date.now()-t;return Ve(s)}function Re(t){switch(t){case"agent":return"Agent";case"command":return"Command";case"area":return"Area";case"modified-file":return"Changed";case"building":return"Server";default:return t}}const Kt=["command","agent","building","area","modified-file"];function Ot({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Ge(),f=He(),m=Je(),g=Xe(),x=y.useRef(e);x.current=e;const S=y.useRef(s);S.current=s;const N=y.useRef(n);N.current=n;const j=y.useRef(r);j.current=r;const L=y.useRef(c);L.current=c;const Q=y.useRef(o);Q.current=o;const z=y.useRef(a);z.current=a;const ie=y.useRef(u);ie.current=u;const U=y.useRef(l);U.current=l;const[E,C]=y.useState(""),[B,P]=y.useState(0);y.useEffect(()=>{t&&(C(""),P(0))},[t]);const K=te.getShortcuts(),W=y.useMemo(()=>{if(!t)return[];const i=K.find(I=>I.id==="spawn-agent"),M=K.find(I=>I.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:i?ve(i):"Alt+N",icon:d.jsx(J,{name:"plus",size:16}),action:()=>{x.current(),S.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:M?ve(M):"Ctrl+K",icon:d.jsx(J,{name:"dashboard",size:16}),action:()=>{x.current(),N.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:d.jsx(J,{name:"gear",size:16}),action:()=>{x.current(),j.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:d.jsx(J,{name:"chart-line",size:16}),action:()=>{var I;x.current(),(I=U.current)==null||I.call(U)}}]},[t,K]),oe=y.useMemo(()=>t?Array.from(h.values()).map(i=>{const M=(g||[]).filter(T=>T.agentId===i.id).map(T=>T.filePath),I=[...new Set(M)],D=I.map(T=>T.split("/").pop()||T),b=[];i.lastAssignedTask&&b.push(i.lastAssignedTask);const R=`${i.class} • ${i.status} • ${i.cwd}`;let k=`${i.name} ${R}`;D.length>0&&(k+=` ${D.join(" ")} ${I.join(" ")}`),b.length>0&&(k+=` ${b.join(" ")}`);const Y=Date.now()-i.lastActivity;let G;return i.lastAssignedTask&&(i.lastAssignedTask.length>150?G=i.lastAssignedTask.slice(0,150)+"...":G=i.lastAssignedTask),{id:`agent-${i.id}`,type:"agent",title:i.name,subtitle:R,lastUserInput:G,timeAway:Y,icon:d.jsx(Ze,{agent:i,size:20}),_searchText:k,_modifiedFiles:I,_userQueries:b,action:()=>{x.current(),te.selectAgent(i.id),te.getState().viewMode!=="flat"&&te.requestTerminalExpand()}}}):[],[t,h,g]),_=y.useMemo(()=>t?Array.from(f.values()).map(i=>{var M;return{id:`area-${i.id}`,type:"area",title:i.name,subtitle:`${i.assignedAgentIds.length} agents • ${((M=i.directories)==null?void 0:M.length)||0} folders`,icon:d.jsx(J,{name:"map",size:16}),action:()=>{x.current(),te.selectArea(i.id)}}}):[],[t,f]),q=y.useMemo(()=>t?Array.from(m.values()).filter(i=>i.type==="server"||i.type==="boss"||i.type==="database").map(i=>{var k,Y,G,T;const M=i.status==="running"?"#4ade80":i.status==="stopped"?"#f87171":"#facc15",I=i.type==="boss"?"crown":i.type==="database"?"database":"desktop";let b=`${i.type==="boss"?"Boss":i.type==="database"?"Database":"Server"} • ${i.status}`;if(i.type==="database"&&((Y=(k=i.database)==null?void 0:k.connections)!=null&&Y.length)){const $=i.database.connections[0];b+=` • ${$.engine} @ ${$.host}`}else i.cwd&&(b+=` • ${i.cwd}`);let R=`${i.name} ${i.type} ${i.status} ${i.cwd||""} ${((G=i.pm2)==null?void 0:G.name)||""}`;if(i.type==="database"&&((T=i.database)!=null&&T.connections))for(const $ of i.database.connections)R+=` ${$.name} ${$.engine} ${$.host} ${$.database||""} mysql postgresql sql`;return{id:`building-${i.id}`,type:"building",title:i.name,subtitle:b,icon:d.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[d.jsx(J,{name:"status-pending",size:10,weight:"fill",color:M}),d.jsx(J,{name:I,size:16})]}),_searchText:R,action:()=>{var $;x.current(),i.type==="boss"?z.current(i.id):i.type==="database"?ie.current(i.id):($=i.pm2)!=null&&$.enabled&&Q.current(i.id)}}}):[],[t,m]),ae=y.useMemo(()=>{if(!t)return[];const i=g||[],M=new Set,I=[];for(const D of i){if(M.has(D.filePath))continue;M.add(D.filePath);const b=D.filePath.split("/").pop()||D.filePath,R=D.action==="created"?"Created":D.action==="modified"?"Modified":D.action==="deleted"?"Deleted":"Read";if(I.push({id:`modified-${D.filePath}-${D.timestamp}`,type:"modified-file",title:b,subtitle:`${R} by ${D.agentName} • ${D.filePath}`,matchedText:D.filePath,icon:D.action==="deleted"?d.jsx(J,{name:"trash",size:16}):Pt(D.filePath),action:()=>{x.current();const k=Array.from(te.getState().areas.values());for(const Y of k)for(const G of Y.directories||[])if(D.filePath.startsWith(G)){te.setFileViewerPath(D.filePath),L.current(Y.id);return}te.selectAgent(D.agentId)}}),I.length>=50)break}return I},[t,g]),we=y.useMemo(()=>new X(oe,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[oe]),Fe=y.useMemo(()=>new X(W,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[W]),Me=y.useMemo(()=>new X(_,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[_]),Ie=y.useMemo(()=>new X(ae,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ae]),De=y.useMemo(()=>new X(q,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[q]),V=y.useMemo(()=>{if(!E.trim()){const A=[];A.push(...q);const w=[...oe].sort((v,H)=>{const ce=v.timeAway??0,ne=H.timeAway??0;return ce-ne});A.push(...w),A.push(...W.slice(0,2)),A.push(..._.slice(0,2));const F={};return Kt.forEach((v,H)=>{F[v]=H}),A.sort((v,H)=>(F[v.type]??999)-(F[H.type]??999)),A}const i=E.trim().toLowerCase(),M=we.search(E).slice(0,8),I=Fe.search(E).slice(0,3),D=Me.search(E).slice(0,2),b=Ie.search(E).slice(0,3),R=De.search(E).filter(A=>{const w=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(i)||w<=.2}).slice(0,4),k={agent:5,building:4,command:3,area:2,"modified-file":1},Y=A=>{if(!i)return 1;const w=A.title.toLowerCase();return w===i?6:w.startsWith(i)?5:w.split(/[^a-z0-9]+/i).includes(i)?4:w.includes(i)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(i)?2:1},G=(A,w)=>{const F=(1-Math.min(1,w??1))*4;return Y(A)*100+(k[A.type]??0)*5+F},T=new Map,$=(A,w)=>{const F=T.get(A.type),v={item:A,score:G(A,w)};F?F.push(v):T.set(A.type,[v])};for(const A of M){const w={...A.item};if(w._modifiedFiles&&w._modifiedFiles.length>0){const F=w._modifiedFiles.filter(v=>{var ne;const H=((ne=v.split("/").pop())==null?void 0:ne.toLowerCase())||"",ce=v.toLowerCase();return H.includes(i)||ce.includes(i)});F.length>0&&(w.matchedFiles=F)}if(w._userQueries&&w._userQueries.length>0){const F=w._userQueries.find(v=>v.toLowerCase().includes(i));if(F)if(F.length>200){const H=F.toLowerCase().indexOf(i),ce=Math.max(0,H-60),ne=Math.min(F.length,H+i.length+100);w.matchedQuery=(ce>0?"...":"")+F.slice(ce,ne)+(ne<F.length?"...":"")}else w.matchedQuery=F}$(w,A.score)}for(const A of R)$(A.item,A.score);for(const A of I)$(A.item,A.score);for(const A of D)$(A.item,A.score);for(const A of b)$(A.item,A.score);for(const[A,w]of T)w.sort((F,v)=>v.score!==F.score?v.score-F.score:A==="agent"?(F.item.timeAway??Number.POSITIVE_INFINITY)-(v.item.timeAway??Number.POSITIVE_INFINITY):0);const Be=[];return Array.from(T.values()).sort((A,w)=>{var F,v;return(((F=w[0])==null?void 0:F.score)??-1)-(((v=A[0])==null?void 0:v.score)??-1)}).forEach(A=>{for(const w of A)Be.push(w.item)}),Be},[E,we,Fe,Me,Ie,De,W,oe,_,q]);y.useEffect(()=>{B>=V.length&&P(Math.max(0,V.length-1))},[V.length,B]);const Ye=y.useCallback(i=>{if(i.altKey&&!i.ctrlKey&&!i.metaKey&&(i.key==="p"||i.key==="n"||i.key==="P"||i.key==="N")){i.preventDefault(),i.stopPropagation(),i.nativeEvent.stopImmediatePropagation();const M=i.key.toLowerCase();P(M==="p"?I=>I>0?I-1:V.length-1:I=>I<V.length-1?I+1:0);return}switch(i.key){case"Escape":i.preventDefault(),x.current();break;case"ArrowUp":i.preventDefault(),P(M=>M>0?M-1:V.length-1);break;case"ArrowDown":i.preventDefault(),P(M=>M<V.length-1?M+1:0);break;case"Enter":i.preventDefault(),V[B]&&V[B].action();break}},[V,B]),Ue=y.useCallback((i,M)=>{if(!M||!i)return i;const I=i.toLowerCase(),D=M.toLowerCase(),b=[];let R=0,k=I.indexOf(D),Y=0;for(;k!==-1;)k>R&&b.push(i.slice(R,k)),b.push(de.createElement("mark",{key:Y++,className:"spotlight-highlight"},i.slice(k,k+M.length))),R=k+M.length,k=I.indexOf(D,R);return R<i.length&&b.push(i.slice(R)),b.length>0?de.createElement(de.Fragment,null,...b):i},[]);return{query:E,setQuery:C,selectedIndex:B,setSelectedIndex:P,results:V,handleKeyDown:Ye,highlightMatch:Ue}}const zt=y.forwardRef(function({query:e,onQueryChange:s,onKeyDown:n,onResetSelection:r},c){const{t:o}=Ee(["common"]);return d.jsxs("div",{className:"spotlight-input-wrapper",children:[d.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),d.jsx("input",{ref:c,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{s(a.target.value),r()},onKeyDown:n,autoFocus:!0,spellCheck:!1}),d.jsxs("div",{className:"spotlight-input-hints",children:[d.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Qt=y.memo(function({result:e,isSelected:s,query:n,highlightMatch:r,onClick:c,onMouseEnter:o}){const a=e.activityText||e.matchedFiles&&e.matchedFiles.length>0||e.matchedQuery;return d.jsxs("div",{className:`spotlight-item ${s?"selected":""} ${e.activityText?"has-activity":""}`,onClick:c,onMouseEnter:o,role:"option","aria-selected":s,children:[d.jsx("span",{className:"spotlight-item-icon","aria-hidden":"true",children:e.icon}),d.jsxs("div",{className:"spotlight-item-content",children:[d.jsxs("div",{className:"spotlight-item-header",children:[d.jsx("span",{className:"spotlight-item-title",children:r(e.title,n)}),d.jsx("span",{className:`spotlight-item-type ${e.type}`,"aria-label":Re(e.type),children:Re(e.type)})]}),e.subtitle&&d.jsx("span",{className:"spotlight-item-subtitle",children:r(e.subtitle,n)}),e.activityText&&d.jsx("span",{className:"spotlight-item-activity",children:r(e.activityText,n)}),a&&d.jsxs("div",{className:"spotlight-item-details",children:[e.matchedFiles&&e.matchedFiles.length>0&&d.jsx("span",{className:"spotlight-item-files",children:e.matchedFiles.map((u,l)=>d.jsxs("span",{className:"file-badge",children:[l>0&&d.jsx("span",{className:"file-separator",children:"•"}),r(u.split("/").pop()||u,n)]},u))}),e.matchedQuery&&d.jsx("span",{className:"spotlight-item-query",children:r(e.matchedQuery,n)})]}),e.timeAway!==void 0&&d.jsx("span",{className:"spotlight-item-time",children:d.jsxs("span",{className:"spotlight-time-away",children:["Idle: ",Ve(e.timeAway)]})}),e.lastUserInput&&!e.matchedQuery&&d.jsxs("span",{className:"spotlight-item-last-input",children:['"',r(e.lastUserInput,n),'"']})]})]})}),Wt=y.forwardRef(function({results:e,selectedIndex:s,query:n,highlightMatch:r,onSelectIndex:c},o){const{t:a}=Ee(["terminal"]),u=y.useRef(!1);y.useEffect(()=>{u.current=!1},[e]),y.useEffect(()=>{const f=typeof o=="function"?null:o==null?void 0:o.current;if(!f)return;const m=()=>{u.current=!0};return f.addEventListener("mousemove",m),()=>{f.removeEventListener("mousemove",m)}},[o,e]);const l={command:a("terminal:spotlight.categories.commands"),agent:a("terminal:spotlight.categories.agents"),building:a("terminal:spotlight.categories.infrastructure"),area:a("terminal:spotlight.categories.areas"),"modified-file":a("terminal:spotlight.categories.modifiedFiles")},h=y.useMemo(()=>{const f=[];let m=null,g=[];return e.forEach((x,S)=>{x.type!==m&&(m!==null&&g.length>0&&f.push([m,g]),m=x.type,g=[]),g.push({result:x,index:S})}),m!==null&&g.length>0&&f.push([m,g]),f},[e]);return y.useEffect(()=>{if(!o||typeof o=="function")return;const f=o.current;if(!f)return;const m=f.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[s,o]),e.length===0?d.jsx("div",{className:"spotlight-results",ref:o,children:d.jsx("div",{className:"spotlight-empty",children:a("terminal:spotlight.noResults")})}):d.jsx("div",{className:"spotlight-results",ref:o,children:h.map(([f,m])=>d.jsxs("div",{children:[h.length>1&&d.jsx("div",{className:"spotlight-category-header",children:l[f]||f}),m.map(({result:g,index:x})=>d.jsx(Qt,{result:g,isSelected:x===s,query:n,highlightMatch:r,onClick:()=>g.action(),onMouseEnter:()=>{u.current&&c(x)}},g.id))]},f))})}),Vt=y.memo(function(){const{t:e}=Ee(["terminal"]);return d.jsxs("div",{className:"spotlight-footer",children:[d.jsxs("div",{className:"spotlight-footer-left",children:[d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"↑"}),d.jsx("kbd",{children:"↓"})," ",d.jsx("kbd",{children:"Alt+N"}),d.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]})]}),d.jsx("div",{className:"spotlight-footer-right",children:d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Yt=768;function Zt({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=y.useRef(null),f=y.useRef(null),m=y.useRef(null),g=y.useRef(0),{query:x,setQuery:S,selectedIndex:N,setSelectedIndex:j,results:L,handleKeyDown:Q,highlightMatch:z}=Ot({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=L.length,y.useEffect(()=>{t&&setTimeout(()=>{var E;(E=h.current)==null||E.focus()},50)},[t]),y.useEffect(()=>{if(!t)return;const E=window.visualViewport;if(!E||window.innerWidth>Yt)return;const C=()=>{const B=f.current;B&&(B.style.height=`${E.height}px`,B.style.top=`${E.offsetTop}px`)};return C(),E.addEventListener("resize",C),E.addEventListener("scroll",C),()=>{E.removeEventListener("resize",C),E.removeEventListener("scroll",C);const B=f.current;B&&(B.style.height="",B.style.top="")}},[t]),y.useEffect(()=>{if(!t)return;const E=C=>{if(C.key==="Escape"){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation(),e();return}if(C.altKey&&!C.ctrlKey&&!C.metaKey&&(C.key==="n"||C.key==="p"||C.key==="N"||C.key==="P")){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation();const B=C.key.toLowerCase(),P=g.current;j(B==="p"?K=>K>0?K-1:P-1:K=>K<P-1?K+1:0);return}};return window.addEventListener("keydown",E,{capture:!0}),()=>{window.removeEventListener("keydown",E,{capture:!0})}},[t,e]);const ie=y.useCallback(E=>{E.target===E.currentTarget&&e()},[e]),U=y.useCallback(()=>{j(0)},[j]);return t?d.jsx("div",{ref:f,className:"spotlight-overlay",onClick:ie,children:d.jsxs("div",{className:"spotlight-modal",children:[d.jsx(zt,{ref:h,query:x,onQueryChange:S,onKeyDown:Q,onResetSelection:U}),d.jsx(Wt,{ref:m,results:L,selectedIndex:N,query:x,highlightMatch:z,onSelectIndex:j}),d.jsx(Vt,{})]})}):null}export{_e as FILE_ICON_NAMES,Zt as Spotlight,Vt as SpotlightFooter,zt as SpotlightInput,Qt as SpotlightItem,Wt as SpotlightResults,Ve as formatDuration,Xt as formatRelativeTime,Jt as getAgentIcon,Pt as getFileIconFromPath,Re as getTypeLabel,Ot as useSpotlightSearch};
1
+ import{j as d,I as J,aj as Ge,U as He,W as Je,bY as Xe,r as y,s as te,bZ as ve,_ as Ze,ad as de,u as Ee}from"./main-Brpf2Evy.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function ee(t){return Array.isArray?Array.isArray(t):Te(t)==="[object Array]"}function qe(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function et(t){return t==null?"":qe(t)}function Z(t){return typeof t=="string"}function $e(t){return typeof t=="number"}function tt(t){return t===!0||t===!1||st(t)&&Te(t)=="[object Boolean]"}function Le(t){return typeof t=="object"}function st(t){return Le(t)&&t!==null}function O(t){return t!=null}function fe(t){return!t.trim().length}function Te(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const nt="Incorrect 'index' type",rt=t=>`Invalid value for key ${t}`,it=t=>`Pattern length exceeds max of ${t}.`,ct=t=>`Missing ${t} property in key`,ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Se=Object.prototype.hasOwnProperty;class at{constructor(e){this._keys=[],this._keyMap={};let s=0;e.forEach(n=>{let r=Pe(n);this._keys.push(r),this._keyMap[r.id]=r,s+=r.weight}),this._keys.forEach(n=>{n.weight/=s})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function Pe(t){let e=null,s=null,n=null,r=1,c=null;if(Z(t)||ee(t))n=t,e=be(t),s=me(t);else{if(!Se.call(t,"name"))throw new Error(ct("name"));const o=t.name;if(n=o,Se.call(t,"weight")&&(r=t.weight,r<=0))throw new Error(ot(o));e=be(o),s=me(o),c=t.getFn}return{path:e,id:s,weight:r,src:n,getFn:c}}function be(t){return ee(t)?t:t.split(".")}function me(t){return ee(t)?t.join("."):t}function ut(t,e){let s=[],n=!1;const r=(c,o,a)=>{if(O(c))if(!o[a])s.push(c);else{let u=o[a];const l=c[u];if(!O(l))return;if(a===o.length-1&&(Z(l)||$e(l)||tt(l)))s.push(et(l));else if(ee(l)){n=!0;for(let h=0,f=l.length;h<f;h+=1)r(l[h],o,a+1)}else o.length&&r(l,o,a+1)}};return r(t,Z(e)?e.split("."):e,0),n?s:s[0]}const lt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},ht={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},dt={location:0,threshold:.6,distance:100},ft={useExtendedSearch:!1,getFn:ut,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var p={...ht,...lt,...dt,...ft};const mt=/[^ ]+/g;function pt(t=1,e=3){const s=new Map,n=Math.pow(10,e);return{get(r){const c=r.match(mt).length;if(s.has(c))return s.get(c);const o=1/Math.pow(c,.5*t),a=parseFloat(Math.round(o*n)/n);return s.set(c,a),a},clear(){s.clear()}}}class Ce{constructor({getFn:e=p.getFn,fieldNormWeight:s=p.fieldNormWeight}={}){this.norm=pt(s,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((s,n)=>{this._keysMap[s.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,Z(this.docs[0])?this.docs.forEach((e,s)=>{this._addString(e,s)}):this.docs.forEach((e,s)=>{this._addObject(e,s)}),this.norm.clear())}add(e){const s=this.size();Z(e)?this._addString(e,s):this._addObject(e,s)}removeAt(e){this.records.splice(e,1);for(let s=e,n=this.size();s<n;s+=1)this.records[s].i-=1}getValueForItemAtKeyId(e,s){return e[this._keysMap[s]]}size(){return this.records.length}_addString(e,s){if(!O(e)||fe(e))return;let n={v:e,i:s,n:this.norm.get(e)};this.records.push(n)}_addObject(e,s){let n={i:s,$:{}};this.keys.forEach((r,c)=>{let o=r.getFn?r.getFn(e):this.getFn(e,r.path);if(O(o)){if(ee(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(O(h))if(Z(h)&&!fe(h)){let f={v:h,i:l,n:this.norm.get(h)};a.push(f)}else ee(h)&&h.forEach((f,m)=>{u.push({nestedArrIndex:m,value:f})})}n.$[c]=a}else if(Z(o)&&!fe(o)){let a={v:o,n:this.norm.get(o)};n.$[c]=a}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function Ke(t,e,{getFn:s=p.getFn,fieldNormWeight:n=p.fieldNormWeight}={}){const r=new Ce({getFn:s,fieldNormWeight:n});return r.setKeys(t.map(Pe)),r.setSources(e),r.create(),r}function gt(t,{getFn:e=p.getFn,fieldNormWeight:s=p.fieldNormWeight}={}){const{keys:n,records:r}=t,c=new Ce({getFn:e,fieldNormWeight:s});return c.setKeys(n),c.setIndexRecords(r),c}function ue(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:r=p.distance,ignoreLocation:c=p.ignoreLocation}={}){const o=e/t.length;if(c)return o;const a=Math.abs(n-s);return r?o+a/r:a?1:o}function At(t=[],e=p.minMatchCharLength){let s=[],n=-1,r=-1,c=0;for(let o=t.length;c<o;c+=1){let a=t[c];a&&n===-1?n=c:!a&&n!==-1&&(r=c-1,r-n+1>=e&&s.push([n,r]),n=-1)}return t[c-1]&&c-n>=e&&s.push([n,c-1]),s}const re=32;function yt(t,e,s,{location:n=p.location,distance:r=p.distance,threshold:c=p.threshold,findAllMatches:o=p.findAllMatches,minMatchCharLength:a=p.minMatchCharLength,includeMatches:u=p.includeMatches,ignoreLocation:l=p.ignoreLocation}={}){if(e.length>re)throw new Error(it(re));const h=e.length,f=t.length,m=Math.max(0,Math.min(n,f));let g=c,x=m;const S=a>1||u,N=S?Array(f):[];let j;for(;(j=t.indexOf(e,x))>-1;){let E=ue(e,{currentLocation:j,expectedLocation:m,distance:r,ignoreLocation:l});if(g=Math.min(E,g),x=j+h,S){let C=0;for(;C<h;)N[j+C]=1,C+=1}}x=-1;let L=[],Q=1,z=h+f;const ie=1<<h-1;for(let E=0;E<h;E+=1){let C=0,B=z;for(;C<B;)ue(e,{errors:E,currentLocation:m+B,expectedLocation:m,distance:r,ignoreLocation:l})<=g?C=B:z=B,B=Math.floor((z-C)/2+C);z=B;let P=Math.max(1,m-B+1),K=o?f:Math.min(m+B,f)+h,W=Array(K+2);W[K+1]=(1<<E)-1;for(let _=K;_>=P;_-=1){let q=_-1,ae=s[t.charAt(q)];if(S&&(N[q]=+!!ae),W[_]=(W[_+1]<<1|1)&ae,E&&(W[_]|=(L[_+1]|L[_])<<1|1|L[_+1]),W[_]&ie&&(Q=ue(e,{errors:E,currentLocation:q,expectedLocation:m,distance:r,ignoreLocation:l}),Q<=g)){if(g=Q,x=q,x<=m)break;P=Math.max(1,2*m-x)}}if(ue(e,{errors:E+1,currentLocation:m,expectedLocation:m,distance:r,ignoreLocation:l})>g)break;L=W}const U={isMatch:x>=0,score:Math.max(.001,Q)};if(S){const E=At(N,a);E.length?u&&(U.indices=E):U.isMatch=!1}return U}function xt(t){let e={};for(let s=0,n=t.length;s<n;s+=1){const r=t.charAt(s);e[r]=(e[r]||0)|1<<n-s-1}return e}const le=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class Oe{constructor(e,{location:s=p.location,threshold:n=p.threshold,distance:r=p.distance,includeMatches:c=p.includeMatches,findAllMatches:o=p.findAllMatches,minMatchCharLength:a=p.minMatchCharLength,isCaseSensitive:u=p.isCaseSensitive,ignoreDiacritics:l=p.ignoreDiacritics,ignoreLocation:h=p.ignoreLocation}={}){if(this.options={location:s,threshold:n,distance:r,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?le(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const f=(g,x)=>{this.chunks.push({pattern:g,alphabet:xt(g),startIndex:x})},m=this.pattern.length;if(m>re){let g=0;const x=m%re,S=m-x;for(;g<S;)f(this.pattern.substr(g,re),g),g+=re;if(x){const N=m-re;f(this.pattern.substr(N),N)}}else f(this.pattern,0)}searchIn(e){const{isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=s?e:e.toLowerCase(),e=n?le(e):e,this.pattern===e){let S={isMatch:!0,score:0};return r&&(S.indices=[[0,e.length-1]]),S}const{location:c,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let f=[],m=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:N,startIndex:j})=>{const{isMatch:L,score:Q,indices:z}=yt(e,S,N,{location:c+j,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:r,ignoreLocation:h});L&&(g=!0),m+=Q,L&&z&&(f=[...f,...z])});let x={isMatch:g,score:g?m/this.chunks.length:1};return g&&r&&(x.indices=f),x}}class se{constructor(e){this.pattern=e}static isMultiMatch(e){return ke(e,this.multiRegex)}static isSingleMatch(e){return ke(e,this.singleRegex)}search(){}}function ke(t,e){const s=t.match(e);return s?s[1]:null}class Et extends se{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const s=e===this.pattern;return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class Ct extends se{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const n=e.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class wt extends se{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const s=e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class Ft extends se{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const s=!e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class Mt extends se{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const s=e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class It extends se{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const s=!e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class ze extends se{constructor(e,{location:s=p.location,threshold:n=p.threshold,distance:r=p.distance,includeMatches:c=p.includeMatches,findAllMatches:o=p.findAllMatches,minMatchCharLength:a=p.minMatchCharLength,isCaseSensitive:u=p.isCaseSensitive,ignoreDiacritics:l=p.ignoreDiacritics,ignoreLocation:h=p.ignoreLocation}={}){super(e),this._bitapSearch=new Oe(e,{location:s,threshold:n,distance:r,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class Qe extends se{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let s=0,n;const r=[],c=this.pattern.length;for(;(n=e.indexOf(this.pattern,s))>-1;)s=n+c,r.push([n,s-1]);const o=!!r.length;return{isMatch:o,score:o?0:1,indices:r}}}const pe=[Et,Qe,wt,Ft,It,Mt,Ct,ze],je=pe.length,Dt=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Bt="|";function vt(t,e={}){return t.split(Bt).map(s=>{let n=s.trim().split(Dt).filter(c=>c&&!!c.trim()),r=[];for(let c=0,o=n.length;c<o;c+=1){const a=n[c];let u=!1,l=-1;for(;!u&&++l<je;){const h=pe[l];let f=h.isMultiMatch(a);f&&(r.push(new h(f,e)),u=!0)}if(!u)for(l=-1;++l<je;){const h=pe[l];let f=h.isSingleMatch(a);if(f){r.push(new h(f,e));break}}}return r})}const St=new Set([ze.type,Qe.type]);class bt{constructor(e,{isCaseSensitive:s=p.isCaseSensitive,ignoreDiacritics:n=p.ignoreDiacritics,includeMatches:r=p.includeMatches,minMatchCharLength:c=p.minMatchCharLength,ignoreLocation:o=p.ignoreLocation,findAllMatches:a=p.findAllMatches,location:u=p.location,threshold:l=p.threshold,distance:h=p.distance}={}){this.query=null,this.options={isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:c,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=s?e:e.toLowerCase(),e=n?le(e):e,this.pattern=e,this.query=vt(this.pattern,this.options)}static condition(e,s){return s.useExtendedSearch}searchIn(e){const s=this.query;if(!s)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:c}=this.options;e=r?e:e.toLowerCase(),e=c?le(e):e;let o=0,a=[],u=0;for(let l=0,h=s.length;l<h;l+=1){const f=s[l];a.length=0,o=0;for(let m=0,g=f.length;m<g;m+=1){const x=f[m],{isMatch:S,indices:N,score:j}=x.search(e);if(S){if(o+=1,u+=j,n){const L=x.constructor.type;St.has(L)?a=[...a,...N]:a.push(N)}}else{u=0,o=0,a.length=0;break}}if(o){let m={isMatch:!0,score:u/o};return n&&(m.indices=a),m}}return{isMatch:!1,score:1}}}const ge=[];function kt(...t){ge.push(...t)}function Ae(t,e){for(let s=0,n=ge.length;s<n;s+=1){let r=ge[s];if(r.condition(t,e))return new r(t,e)}return new Oe(t,e)}const he={AND:"$and",OR:"$or"},ye={PATH:"$path",PATTERN:"$val"},xe=t=>!!(t[he.AND]||t[he.OR]),jt=t=>!!t[ye.PATH],Nt=t=>!ee(t)&&Le(t)&&!xe(t),Ne=t=>({[he.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function We(t,e,{auto:s=!0}={}){const n=r=>{let c=Object.keys(r);const o=jt(r);if(!o&&c.length>1&&!xe(r))return n(Ne(r));if(Nt(r)){const u=o?r[ye.PATH]:c[0],l=o?r[ye.PATTERN]:r[u];if(!Z(l))throw new Error(rt(u));const h={keyId:me(u),pattern:l};return s&&(h.searcher=Ae(l,e)),h}let a={children:[],operator:c[0]};return c.forEach(u=>{const l=r[u];ee(l)&&l.forEach(h=>{a.children.push(n(h))})}),a};return xe(t)||(t=Ne(t)),n(t)}function _t(t,{ignoreFieldNorm:e=p.ignoreFieldNorm}){t.forEach(s=>{let n=1;s.matches.forEach(({key:r,norm:c,score:o})=>{const a=r?r.weight:null;n*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:c))}),s.score=n})}function Rt(t,e){const s=t.matches;e.matches=[],O(s)&&s.forEach(n=>{if(!O(n.indices)||!n.indices.length)return;const{indices:r,value:c}=n;let o={indices:r,value:c};n.key&&(o.key=n.key.src),n.idx>-1&&(o.refIndex=n.idx),e.matches.push(o)})}function $t(t,e){e.score=t.score}function Lt(t,e,{includeMatches:s=p.includeMatches,includeScore:n=p.includeScore}={}){const r=[];return s&&r.push(Rt),n&&r.push($t),t.map(c=>{const{idx:o}=c,a={item:e[o],refIndex:o};return r.length&&r.forEach(u=>{u(c,a)}),a})}class X{constructor(e,s={},n){this.options={...p,...s},this.options.useExtendedSearch,this._keyStore=new at(this.options.keys),this.setCollection(e,n)}setCollection(e,s){if(this._docs=e,s&&!(s instanceof Ce))throw new Error(nt);this._myIndex=s||Ke(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){O(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const s=[];for(let n=0,r=this._docs.length;n<r;n+=1){const c=this._docs[n];e(c,n)&&(this.removeAt(n),n-=1,r-=1,s.push(c))}return s}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:s=-1}={}){const{includeMatches:n,includeScore:r,shouldSort:c,sortFn:o,ignoreFieldNorm:a}=this.options;let u=Z(e)?Z(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return _t(u,{ignoreFieldNorm:a}),c&&u.sort(o),$e(s)&&s>-1&&(u=u.slice(0,s)),Lt(u,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(e){const s=Ae(e,this.options),{records:n}=this._myIndex,r=[];return n.forEach(({v:c,i:o,n:a})=>{if(!O(c))return;const{isMatch:u,score:l,indices:h}=s.searchIn(c);u&&r.push({item:c,idx:o,matches:[{score:l,value:c,norm:a,indices:h}]})}),r}_searchLogical(e){const s=We(e,this.options),n=(a,u,l)=>{if(!a.children){const{keyId:f,searcher:m}=a,g=this._findMatches({key:this._keyStore.get(f),value:this._myIndex.getValueForItemAtKeyId(u,f),searcher:m});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let f=0,m=a.children.length;f<m;f+=1){const g=a.children[f],x=n(g,u,l);if(x.length)h.push(...x);else if(a.operator===he.AND)return[]}return h},r=this._myIndex.records,c={},o=[];return r.forEach(({$:a,i:u})=>{if(O(a)){let l=n(s,a,u);l.length&&(c[u]||(c[u]={idx:u,item:a,matches:[]},o.push(c[u])),l.forEach(({matches:h})=>{c[u].matches.push(...h)}))}}),o}_searchObjectList(e){const s=Ae(e,this.options),{keys:n,records:r}=this._myIndex,c=[];return r.forEach(({$:o,i:a})=>{if(!O(o))return;let u=[];n.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:s}))}),u.length&&c.push({idx:a,item:o,matches:u})}),c}_findMatches({key:e,value:s,searcher:n}){if(!O(s))return[];let r=[];if(ee(s))s.forEach(({v:c,i:o,n:a})=>{if(!O(c))return;const{isMatch:u,score:l,indices:h}=n.searchIn(c);u&&r.push({score:l,key:e,value:c,idx:o,norm:a,indices:h})});else{const{v:c,n:o}=s,{isMatch:a,score:u,indices:l}=n.searchIn(c);a&&r.push({score:u,key:e,value:c,norm:o,indices:l})}return r}}X.version="7.1.0";X.createIndex=Ke;X.parseIndex=gt;X.config=p;X.parseQuery=We;kt(bt);const _e={".ts":"file-code",".tsx":"atom",".js":"file-code",".jsx":"atom",".py":"file-code",".rs":"file-code",".go":"file-code",".md":"file-text",".json":"clipboard",".yaml":"gear",".yml":"gear",".css":"palette",".scss":"palette",".html":"globe",".sql":"database",".sh":"terminal",".env":"lock",".toml":"gear",".lock":"lock",default:"file-text"};function Tt(t){switch(t){case"scout":return"class-scout";case"builder":return"class-builder";case"debugger":return"class-debugger";case"architect":return"class-architect";case"warrior":return"class-warrior";case"support":return"class-support";case"boss":return"class-boss";default:return"class-default"}}function Pt(t,e=16){var r;const s="."+(((r=t.split(".").pop())==null?void 0:r.toLowerCase())??""),n=_e[s]||_e.default;return d.jsx(J,{name:n,size:e})}function Jt(t,e=16){return d.jsx(J,{name:Tt(t),size:e,weight:"fill"})}function Ve(t){const e=Math.floor(t/1e3),s=Math.floor(e/60),n=Math.floor(s/60),r=Math.floor(n/24);return r>0?`${r}d ${n%24}h ago`:n>0?`${n}h ${s%60}m ago`:s>0?`${s}m ago`:"just now"}function Xt(t){const s=Date.now()-t;return Ve(s)}function Re(t){switch(t){case"agent":return"Agent";case"command":return"Command";case"area":return"Area";case"modified-file":return"Changed";case"building":return"Server";default:return t}}const Kt=["command","agent","building","area","modified-file"];function Ot({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Ge(),f=He(),m=Je(),g=Xe(),x=y.useRef(e);x.current=e;const S=y.useRef(s);S.current=s;const N=y.useRef(n);N.current=n;const j=y.useRef(r);j.current=r;const L=y.useRef(c);L.current=c;const Q=y.useRef(o);Q.current=o;const z=y.useRef(a);z.current=a;const ie=y.useRef(u);ie.current=u;const U=y.useRef(l);U.current=l;const[E,C]=y.useState(""),[B,P]=y.useState(0);y.useEffect(()=>{t&&(C(""),P(0))},[t]);const K=te.getShortcuts(),W=y.useMemo(()=>{if(!t)return[];const i=K.find(I=>I.id==="spawn-agent"),M=K.find(I=>I.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:i?ve(i):"Alt+N",icon:d.jsx(J,{name:"plus",size:16}),action:()=>{x.current(),S.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:M?ve(M):"Ctrl+K",icon:d.jsx(J,{name:"dashboard",size:16}),action:()=>{x.current(),N.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:d.jsx(J,{name:"gear",size:16}),action:()=>{x.current(),j.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:d.jsx(J,{name:"chart-line",size:16}),action:()=>{var I;x.current(),(I=U.current)==null||I.call(U)}}]},[t,K]),oe=y.useMemo(()=>t?Array.from(h.values()).map(i=>{const M=(g||[]).filter(T=>T.agentId===i.id).map(T=>T.filePath),I=[...new Set(M)],D=I.map(T=>T.split("/").pop()||T),b=[];i.lastAssignedTask&&b.push(i.lastAssignedTask);const R=`${i.class} • ${i.status} • ${i.cwd}`;let k=`${i.name} ${R}`;D.length>0&&(k+=` ${D.join(" ")} ${I.join(" ")}`),b.length>0&&(k+=` ${b.join(" ")}`);const Y=Date.now()-i.lastActivity;let G;return i.lastAssignedTask&&(i.lastAssignedTask.length>150?G=i.lastAssignedTask.slice(0,150)+"...":G=i.lastAssignedTask),{id:`agent-${i.id}`,type:"agent",title:i.name,subtitle:R,lastUserInput:G,timeAway:Y,icon:d.jsx(Ze,{agent:i,size:20}),_searchText:k,_modifiedFiles:I,_userQueries:b,action:()=>{x.current(),te.selectAgent(i.id),te.getState().viewMode!=="flat"&&te.requestTerminalExpand()}}}):[],[t,h,g]),_=y.useMemo(()=>t?Array.from(f.values()).map(i=>{var M;return{id:`area-${i.id}`,type:"area",title:i.name,subtitle:`${i.assignedAgentIds.length} agents • ${((M=i.directories)==null?void 0:M.length)||0} folders`,icon:d.jsx(J,{name:"map",size:16}),action:()=>{x.current(),te.selectArea(i.id)}}}):[],[t,f]),q=y.useMemo(()=>t?Array.from(m.values()).filter(i=>i.type==="server"||i.type==="boss"||i.type==="database").map(i=>{var k,Y,G,T;const M=i.status==="running"?"#4ade80":i.status==="stopped"?"#f87171":"#facc15",I=i.type==="boss"?"crown":i.type==="database"?"database":"desktop";let b=`${i.type==="boss"?"Boss":i.type==="database"?"Database":"Server"} • ${i.status}`;if(i.type==="database"&&((Y=(k=i.database)==null?void 0:k.connections)!=null&&Y.length)){const $=i.database.connections[0];b+=` • ${$.engine} @ ${$.host}`}else i.cwd&&(b+=` • ${i.cwd}`);let R=`${i.name} ${i.type} ${i.status} ${i.cwd||""} ${((G=i.pm2)==null?void 0:G.name)||""}`;if(i.type==="database"&&((T=i.database)!=null&&T.connections))for(const $ of i.database.connections)R+=` ${$.name} ${$.engine} ${$.host} ${$.database||""} mysql postgresql sql`;return{id:`building-${i.id}`,type:"building",title:i.name,subtitle:b,icon:d.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[d.jsx(J,{name:"status-pending",size:10,weight:"fill",color:M}),d.jsx(J,{name:I,size:16})]}),_searchText:R,action:()=>{var $;x.current(),i.type==="boss"?z.current(i.id):i.type==="database"?ie.current(i.id):($=i.pm2)!=null&&$.enabled&&Q.current(i.id)}}}):[],[t,m]),ae=y.useMemo(()=>{if(!t)return[];const i=g||[],M=new Set,I=[];for(const D of i){if(M.has(D.filePath))continue;M.add(D.filePath);const b=D.filePath.split("/").pop()||D.filePath,R=D.action==="created"?"Created":D.action==="modified"?"Modified":D.action==="deleted"?"Deleted":"Read";if(I.push({id:`modified-${D.filePath}-${D.timestamp}`,type:"modified-file",title:b,subtitle:`${R} by ${D.agentName} • ${D.filePath}`,matchedText:D.filePath,icon:D.action==="deleted"?d.jsx(J,{name:"trash",size:16}):Pt(D.filePath),action:()=>{x.current();const k=Array.from(te.getState().areas.values());for(const Y of k)for(const G of Y.directories||[])if(D.filePath.startsWith(G)){te.setFileViewerPath(D.filePath),L.current(Y.id);return}te.selectAgent(D.agentId)}}),I.length>=50)break}return I},[t,g]),we=y.useMemo(()=>new X(oe,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[oe]),Fe=y.useMemo(()=>new X(W,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[W]),Me=y.useMemo(()=>new X(_,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[_]),Ie=y.useMemo(()=>new X(ae,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ae]),De=y.useMemo(()=>new X(q,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[q]),V=y.useMemo(()=>{if(!E.trim()){const A=[];A.push(...q);const w=[...oe].sort((v,H)=>{const ce=v.timeAway??0,ne=H.timeAway??0;return ce-ne});A.push(...w),A.push(...W.slice(0,2)),A.push(..._.slice(0,2));const F={};return Kt.forEach((v,H)=>{F[v]=H}),A.sort((v,H)=>(F[v.type]??999)-(F[H.type]??999)),A}const i=E.trim().toLowerCase(),M=we.search(E).slice(0,8),I=Fe.search(E).slice(0,3),D=Me.search(E).slice(0,2),b=Ie.search(E).slice(0,3),R=De.search(E).filter(A=>{const w=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(i)||w<=.2}).slice(0,4),k={agent:5,building:4,command:3,area:2,"modified-file":1},Y=A=>{if(!i)return 1;const w=A.title.toLowerCase();return w===i?6:w.startsWith(i)?5:w.split(/[^a-z0-9]+/i).includes(i)?4:w.includes(i)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(i)?2:1},G=(A,w)=>{const F=(1-Math.min(1,w??1))*4;return Y(A)*100+(k[A.type]??0)*5+F},T=new Map,$=(A,w)=>{const F=T.get(A.type),v={item:A,score:G(A,w)};F?F.push(v):T.set(A.type,[v])};for(const A of M){const w={...A.item};if(w._modifiedFiles&&w._modifiedFiles.length>0){const F=w._modifiedFiles.filter(v=>{var ne;const H=((ne=v.split("/").pop())==null?void 0:ne.toLowerCase())||"",ce=v.toLowerCase();return H.includes(i)||ce.includes(i)});F.length>0&&(w.matchedFiles=F)}if(w._userQueries&&w._userQueries.length>0){const F=w._userQueries.find(v=>v.toLowerCase().includes(i));if(F)if(F.length>200){const H=F.toLowerCase().indexOf(i),ce=Math.max(0,H-60),ne=Math.min(F.length,H+i.length+100);w.matchedQuery=(ce>0?"...":"")+F.slice(ce,ne)+(ne<F.length?"...":"")}else w.matchedQuery=F}$(w,A.score)}for(const A of R)$(A.item,A.score);for(const A of I)$(A.item,A.score);for(const A of D)$(A.item,A.score);for(const A of b)$(A.item,A.score);for(const[A,w]of T)w.sort((F,v)=>v.score!==F.score?v.score-F.score:A==="agent"?(F.item.timeAway??Number.POSITIVE_INFINITY)-(v.item.timeAway??Number.POSITIVE_INFINITY):0);const Be=[];return Array.from(T.values()).sort((A,w)=>{var F,v;return(((F=w[0])==null?void 0:F.score)??-1)-(((v=A[0])==null?void 0:v.score)??-1)}).forEach(A=>{for(const w of A)Be.push(w.item)}),Be},[E,we,Fe,Me,Ie,De,W,oe,_,q]);y.useEffect(()=>{B>=V.length&&P(Math.max(0,V.length-1))},[V.length,B]);const Ye=y.useCallback(i=>{if(i.altKey&&!i.ctrlKey&&!i.metaKey&&(i.key==="p"||i.key==="n"||i.key==="P"||i.key==="N")){i.preventDefault(),i.stopPropagation(),i.nativeEvent.stopImmediatePropagation();const M=i.key.toLowerCase();P(M==="p"?I=>I>0?I-1:V.length-1:I=>I<V.length-1?I+1:0);return}switch(i.key){case"Escape":i.preventDefault(),x.current();break;case"ArrowUp":i.preventDefault(),P(M=>M>0?M-1:V.length-1);break;case"ArrowDown":i.preventDefault(),P(M=>M<V.length-1?M+1:0);break;case"Enter":i.preventDefault(),V[B]&&V[B].action();break}},[V,B]),Ue=y.useCallback((i,M)=>{if(!M||!i)return i;const I=i.toLowerCase(),D=M.toLowerCase(),b=[];let R=0,k=I.indexOf(D),Y=0;for(;k!==-1;)k>R&&b.push(i.slice(R,k)),b.push(de.createElement("mark",{key:Y++,className:"spotlight-highlight"},i.slice(k,k+M.length))),R=k+M.length,k=I.indexOf(D,R);return R<i.length&&b.push(i.slice(R)),b.length>0?de.createElement(de.Fragment,null,...b):i},[]);return{query:E,setQuery:C,selectedIndex:B,setSelectedIndex:P,results:V,handleKeyDown:Ye,highlightMatch:Ue}}const zt=y.forwardRef(function({query:e,onQueryChange:s,onKeyDown:n,onResetSelection:r},c){const{t:o}=Ee(["common"]);return d.jsxs("div",{className:"spotlight-input-wrapper",children:[d.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),d.jsx("input",{ref:c,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{s(a.target.value),r()},onKeyDown:n,autoFocus:!0,spellCheck:!1}),d.jsxs("div",{className:"spotlight-input-hints",children:[d.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Qt=y.memo(function({result:e,isSelected:s,query:n,highlightMatch:r,onClick:c,onMouseEnter:o}){const a=e.activityText||e.matchedFiles&&e.matchedFiles.length>0||e.matchedQuery;return d.jsxs("div",{className:`spotlight-item ${s?"selected":""} ${e.activityText?"has-activity":""}`,onClick:c,onMouseEnter:o,role:"option","aria-selected":s,children:[d.jsx("span",{className:"spotlight-item-icon","aria-hidden":"true",children:e.icon}),d.jsxs("div",{className:"spotlight-item-content",children:[d.jsxs("div",{className:"spotlight-item-header",children:[d.jsx("span",{className:"spotlight-item-title",children:r(e.title,n)}),d.jsx("span",{className:`spotlight-item-type ${e.type}`,"aria-label":Re(e.type),children:Re(e.type)})]}),e.subtitle&&d.jsx("span",{className:"spotlight-item-subtitle",children:r(e.subtitle,n)}),e.activityText&&d.jsx("span",{className:"spotlight-item-activity",children:r(e.activityText,n)}),a&&d.jsxs("div",{className:"spotlight-item-details",children:[e.matchedFiles&&e.matchedFiles.length>0&&d.jsx("span",{className:"spotlight-item-files",children:e.matchedFiles.map((u,l)=>d.jsxs("span",{className:"file-badge",children:[l>0&&d.jsx("span",{className:"file-separator",children:"•"}),r(u.split("/").pop()||u,n)]},u))}),e.matchedQuery&&d.jsx("span",{className:"spotlight-item-query",children:r(e.matchedQuery,n)})]}),e.timeAway!==void 0&&d.jsx("span",{className:"spotlight-item-time",children:d.jsxs("span",{className:"spotlight-time-away",children:["Idle: ",Ve(e.timeAway)]})}),e.lastUserInput&&!e.matchedQuery&&d.jsxs("span",{className:"spotlight-item-last-input",children:['"',r(e.lastUserInput,n),'"']})]})]})}),Wt=y.forwardRef(function({results:e,selectedIndex:s,query:n,highlightMatch:r,onSelectIndex:c},o){const{t:a}=Ee(["terminal"]),u=y.useRef(!1);y.useEffect(()=>{u.current=!1},[e]),y.useEffect(()=>{const f=typeof o=="function"?null:o==null?void 0:o.current;if(!f)return;const m=()=>{u.current=!0};return f.addEventListener("mousemove",m),()=>{f.removeEventListener("mousemove",m)}},[o,e]);const l={command:a("terminal:spotlight.categories.commands"),agent:a("terminal:spotlight.categories.agents"),building:a("terminal:spotlight.categories.infrastructure"),area:a("terminal:spotlight.categories.areas"),"modified-file":a("terminal:spotlight.categories.modifiedFiles")},h=y.useMemo(()=>{const f=[];let m=null,g=[];return e.forEach((x,S)=>{x.type!==m&&(m!==null&&g.length>0&&f.push([m,g]),m=x.type,g=[]),g.push({result:x,index:S})}),m!==null&&g.length>0&&f.push([m,g]),f},[e]);return y.useEffect(()=>{if(!o||typeof o=="function")return;const f=o.current;if(!f)return;const m=f.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[s,o]),e.length===0?d.jsx("div",{className:"spotlight-results",ref:o,children:d.jsx("div",{className:"spotlight-empty",children:a("terminal:spotlight.noResults")})}):d.jsx("div",{className:"spotlight-results",ref:o,children:h.map(([f,m])=>d.jsxs("div",{children:[h.length>1&&d.jsx("div",{className:"spotlight-category-header",children:l[f]||f}),m.map(({result:g,index:x})=>d.jsx(Qt,{result:g,isSelected:x===s,query:n,highlightMatch:r,onClick:()=>g.action(),onMouseEnter:()=>{u.current&&c(x)}},g.id))]},f))})}),Vt=y.memo(function(){const{t:e}=Ee(["terminal"]);return d.jsxs("div",{className:"spotlight-footer",children:[d.jsxs("div",{className:"spotlight-footer-left",children:[d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"↑"}),d.jsx("kbd",{children:"↓"})," ",d.jsx("kbd",{children:"Alt+N"}),d.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]})]}),d.jsx("div",{className:"spotlight-footer-right",children:d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Yt=768;function Zt({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=y.useRef(null),f=y.useRef(null),m=y.useRef(null),g=y.useRef(0),{query:x,setQuery:S,selectedIndex:N,setSelectedIndex:j,results:L,handleKeyDown:Q,highlightMatch:z}=Ot({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=L.length,y.useEffect(()=>{t&&setTimeout(()=>{var E;(E=h.current)==null||E.focus()},50)},[t]),y.useEffect(()=>{if(!t)return;const E=window.visualViewport;if(!E||window.innerWidth>Yt)return;const C=()=>{const B=f.current;B&&(B.style.height=`${E.height}px`,B.style.top=`${E.offsetTop}px`)};return C(),E.addEventListener("resize",C),E.addEventListener("scroll",C),()=>{E.removeEventListener("resize",C),E.removeEventListener("scroll",C);const B=f.current;B&&(B.style.height="",B.style.top="")}},[t]),y.useEffect(()=>{if(!t)return;const E=C=>{if(C.key==="Escape"){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation(),e();return}if(C.altKey&&!C.ctrlKey&&!C.metaKey&&(C.key==="n"||C.key==="p"||C.key==="N"||C.key==="P")){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation();const B=C.key.toLowerCase(),P=g.current;j(B==="p"?K=>K>0?K-1:P-1:K=>K<P-1?K+1:0);return}};return window.addEventListener("keydown",E,{capture:!0}),()=>{window.removeEventListener("keydown",E,{capture:!0})}},[t,e]);const ie=y.useCallback(E=>{E.target===E.currentTarget&&e()},[e]),U=y.useCallback(()=>{j(0)},[j]);return t?d.jsx("div",{ref:f,className:"spotlight-overlay",onClick:ie,children:d.jsxs("div",{className:"spotlight-modal",children:[d.jsx(zt,{ref:h,query:x,onQueryChange:S,onKeyDown:Q,onResetSelection:U}),d.jsx(Wt,{ref:m,results:L,selectedIndex:N,query:x,highlightMatch:z,onSelectIndex:j}),d.jsx(Vt,{})]})}):null}export{_e as FILE_ICON_NAMES,Zt as Spotlight,Vt as SpotlightFooter,zt as SpotlightInput,Qt as SpotlightItem,Wt as SpotlightResults,Ve as formatDuration,Xt as formatRelativeTime,Jt as getAgentIcon,Pt as getFileIconFromPath,Re as getTypeLabel,Ot as useSpotlightSearch};