tide-commander 1.177.2 → 1.178.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/assets/{BossLogsModal-BJ85hhZB.js → BossLogsModal-CS4LIvSu.js} +1 -1
  3. package/dist/assets/{BossSpawnModal-iF7jBjoW.js → BossSpawnModal-DFqNOCaI.js} +1 -1
  4. package/dist/assets/{ControlsModal-C-Dlj2C2.js → ControlsModal-BTX5H6jw.js} +1 -1
  5. package/dist/assets/{DockerLogsModal-CPK49emd.js → DockerLogsModal-C8pdXuqO.js} +1 -1
  6. package/dist/assets/{EmbeddedEditor-CtM591W2.js → EmbeddedEditor--FuYpTIa.js} +1 -1
  7. package/dist/assets/FcStdViewer-DwgwMwrx.js +1 -0
  8. package/dist/assets/GcodeViewer-CynUwDmS.js +1 -0
  9. package/dist/assets/{GmailOAuthSetup-DBbZpNj4.js → GmailOAuthSetup-BwdW6138.js} +1 -1
  10. package/dist/assets/{GoogleOAuthSetup-BF233CPj.js → GoogleOAuthSetup-D1r3EeDF.js} +1 -1
  11. package/dist/assets/{IframeModal-DoLqp8i3.js → IframeModal-B9yOGPoP.js} +1 -1
  12. package/dist/assets/{IntegrationsPanel-Dpx2slxW.js → IntegrationsPanel-lF8DIGck.js} +2 -2
  13. package/dist/assets/{LogViewerModal-CI6NVsnn.js → LogViewerModal-QtEg0GoV.js} +1 -1
  14. package/dist/assets/{MonitoringModal-CGQjCKh8.js → MonitoringModal-zHaxFAy8.js} +1 -1
  15. package/dist/assets/OrbitControls-B1__nj_c.js +1 -0
  16. package/dist/assets/{PM2LogsModal-cprJemBk.js → PM2LogsModal-DPRGsqvu.js} +1 -1
  17. package/dist/assets/{RestoreArchivedAreaModal-CD-nkwHT.js → RestoreArchivedAreaModal-4Yp2K-Vg.js} +1 -1
  18. package/dist/assets/{Scene2DCanvas-C0d2NOZF.js → Scene2DCanvas-Cn672tbC.js} +1 -1
  19. package/dist/assets/SceneManager-CKaBryd4.js +104 -0
  20. package/dist/assets/{SkillsPanel-Bea0jqNk.js → SkillsPanel-BNSoS60S.js} +1 -1
  21. package/dist/assets/{SlackMultiInstanceSetup-BvYk2UWs.js → SlackMultiInstanceSetup-BsckrPs-.js} +1 -1
  22. package/dist/assets/{SpawnModal-EOdsRMsU.js → SpawnModal-BxdMXDMp.js} +1 -1
  23. package/dist/assets/{StatisticsModal-DMTuwOyD.js → StatisticsModal-FNbvlYGU.js} +1 -1
  24. package/dist/assets/StlViewer-CRt0aUAf.js +1 -0
  25. package/dist/assets/{SubordinateAssignmentModal-kaXTALIo.js → SubordinateAssignmentModal-DxUqNMOR.js} +1 -1
  26. package/dist/assets/ThreeAreaSelector-DkbNFeb4.js +2 -0
  27. package/dist/assets/ThreeViewShortcuts-C6XYQvVm.js +1 -0
  28. package/dist/assets/{TriggerManagerPanel-BwmFtZCh.js → TriggerManagerPanel-DcX4J5m7.js} +1 -1
  29. package/dist/assets/{WorkflowEditorPanel-2SLzQ_F7.js → WorkflowEditorPanel-5VPqFGzD.js} +1 -1
  30. package/dist/assets/{abnfDiagram-VRR7QNED-Bn16ZJvn.js → abnfDiagram-VRR7QNED-6F-3T6-Y.js} +1 -1
  31. package/dist/assets/{arc-BS1yGfg8.js → arc-NHzv0EA5.js} +1 -1
  32. package/dist/assets/{architectureDiagram-ZJ3FMSHR-BowAVE2g.js → architectureDiagram-ZJ3FMSHR-CsJhNPjv.js} +1 -1
  33. package/dist/assets/{area-logos-iPYyTqRS.js → area-logos-CYEXA4lp.js} +1 -1
  34. package/dist/assets/{blockDiagram-677ZJIJ3-ZcRTeACC.js → blockDiagram-677ZJIJ3-UT3b2Q12.js} +1 -1
  35. package/dist/assets/{c4Diagram-LMCZKHZV-DVyCmWLe.js → c4Diagram-LMCZKHZV-uMYRTZix.js} +1 -1
  36. package/dist/assets/channel-D4Oo3ZHk.js +1 -0
  37. package/dist/assets/{chunk-2Q5K7J3B-Do4loXOf.js → chunk-2Q5K7J3B-BwXKcNaP.js} +1 -1
  38. package/dist/assets/{chunk-32BRIVSS-BteUBJrm.js → chunk-32BRIVSS-C8dNk4Hn.js} +1 -1
  39. package/dist/assets/{chunk-5VM5RSS4-CCzvXqtX.js → chunk-5VM5RSS4-Z2pZcBbh.js} +1 -1
  40. package/dist/assets/{chunk-EX3LRPZG-CWfoK8TS.js → chunk-EX3LRPZG-dA9bU_uS.js} +1 -1
  41. package/dist/assets/{chunk-JWPE2WC7-T2EVEO7f.js → chunk-JWPE2WC7-CMkfDWfd.js} +1 -1
  42. package/dist/assets/{chunk-MOJQB5TN-Bms_j_vp.js → chunk-MOJQB5TN-CRQhypCf.js} +1 -1
  43. package/dist/assets/{chunk-RYQCIY6F-BHaTGeSM.js → chunk-RYQCIY6F-CPvbNKNZ.js} +1 -1
  44. package/dist/assets/{chunk-V7JOEXUC-CTk13LTh.js → chunk-V7JOEXUC-6JsV0G3U.js} +1 -1
  45. package/dist/assets/{chunk-VR4S4FIN-DbAzJVcf.js → chunk-VR4S4FIN-n0aWG4-j.js} +1 -1
  46. package/dist/assets/{chunk-XXDRQBXY--nHyvZQ6.js → chunk-XXDRQBXY-BLQ81Hhu.js} +1 -1
  47. package/dist/assets/classDiagram-OUVF2IWQ-ChKBeWCX.js +1 -0
  48. package/dist/assets/classDiagram-v2-EOCWNBFH-ChKBeWCX.js +1 -0
  49. package/dist/assets/{cose-bilkent-JH36ORCC-D4STnGjf.js → cose-bilkent-JH36ORCC-BSHuRRPa.js} +1 -1
  50. package/dist/assets/{cynefin-VYW2F7L2-C3bGlbuH.js → cynefin-VYW2F7L2-vKDum-r-.js} +1 -1
  51. package/dist/assets/{cynefinDiagram-TSTJHNR4-NtQ7fqyK.js → cynefinDiagram-TSTJHNR4-B7hlff7z.js} +1 -1
  52. package/dist/assets/{dagre-VKFMJZFB-4_7veLhL.js → dagre-VKFMJZFB-K2lW3A2u.js} +1 -1
  53. package/dist/assets/{diagram-FQU43EPY-BXSSs1Tt.js → diagram-FQU43EPY-gtpv6DY0.js} +1 -1
  54. package/dist/assets/{diagram-G47NLZAW-0IkpFOVq.js → diagram-G47NLZAW-D9yHOqQq.js} +1 -1
  55. package/dist/assets/{diagram-NH7WQ7WH-DdjwsYrQ.js → diagram-NH7WQ7WH-BzeJ_2nM.js} +1 -1
  56. package/dist/assets/{diagram-OA4YK3LP-DVlmCA6A.js → diagram-OA4YK3LP-CM0HWugE.js} +1 -1
  57. package/dist/assets/{diagram-WEI45ONY-COn2Rq3e.js → diagram-WEI45ONY-BMyBFCkS.js} +1 -1
  58. package/dist/assets/{ebnfDiagram-CCIWWBDH-BBrme_H-.js → ebnfDiagram-CCIWWBDH-8Kj0FCEb.js} +1 -1
  59. package/dist/assets/{erDiagram-Q63AITRT-Dued2fRQ.js → erDiagram-Q63AITRT-BWDV58w3.js} +1 -1
  60. package/dist/assets/fcstd.worker-BSFnALBZ.js +24 -0
  61. package/dist/assets/{flowDiagram-23GEKE2U-CI3IU-MQ.js → flowDiagram-23GEKE2U-Bvu7iKuy.js} +1 -1
  62. package/dist/assets/{ganttDiagram-NO4QXBWP-DjLcWub4.js → ganttDiagram-NO4QXBWP-oOnRqEGi.js} +1 -1
  63. package/dist/assets/gcode.worker-DayjyJb4.js +1 -0
  64. package/dist/assets/{gitGraphDiagram-IHSO6WYX-CDGs8fL2.js → gitGraphDiagram-IHSO6WYX-BLNHz3A1.js} +1 -1
  65. package/dist/assets/{index-Ds6C-5SZ.js → index-BALtikL3.js} +1 -1
  66. package/dist/assets/{index-e1--CClk.js → index-BYRIJxh3.js} +3 -3
  67. package/dist/assets/{index-BeFfmS97.js → index-BZge8Vqz.js} +1 -1
  68. package/dist/assets/{index-BcJI4Wf2.js → index-Bzpy8ZrM.js} +1 -1
  69. package/dist/assets/index-CGjogkgR.js +2 -0
  70. package/dist/assets/{index-CPT2yDF7.js → index-CQrwfFmj.js} +3 -3
  71. package/dist/assets/{index-BO9rcCxW.js → index-DaieR5TQ.js} +1 -1
  72. package/dist/assets/{index-DY0EdedI.js → index-DcPCPN6v.js} +6 -6
  73. package/dist/assets/index-DhnKpoWm.js +2 -0
  74. package/dist/assets/{infoDiagram-FWYZ7A6U-BR8lw-07.js → infoDiagram-FWYZ7A6U-CBoekTgL.js} +1 -1
  75. package/dist/assets/{ishikawaDiagram-FXEZZL3T-BvoUdvxM.js → ishikawaDiagram-FXEZZL3T-i92jYFyn.js} +1 -1
  76. package/dist/assets/{journeyDiagram-5HDEW3XC-5ZTKSL91.js → journeyDiagram-5HDEW3XC-Dlb8tdvI.js} +1 -1
  77. package/dist/assets/{kanban-definition-HUTT4EX6-Crw59w7d.js → kanban-definition-HUTT4EX6-C357GaQI.js} +1 -1
  78. package/dist/assets/{linear-BClkkbnW.js → linear-CIJgBkf3.js} +1 -1
  79. package/dist/assets/{main-anrHq8ki.js → main-DN8Eh8GZ.js} +144 -144
  80. package/dist/assets/main-ZtOMcfnf.css +1 -0
  81. package/dist/assets/{mermaid.core-BDhiHGyU.js → mermaid.core-DpoI2o0n.js} +4 -4
  82. package/dist/assets/{mindmap-definition-LN4V7U3C-kGtzuV8p.js → mindmap-definition-LN4V7U3C-C5jHYqmi.js} +1 -1
  83. package/dist/assets/occt-import-js-BhHfLpto.wasm +0 -0
  84. package/dist/assets/{pegDiagram-2B236MQR-DacPFZVr.js → pegDiagram-2B236MQR-CxZiEIc6.js} +1 -1
  85. package/dist/assets/{pieDiagram-ENE6RG2P-a7t3bV4m.js → pieDiagram-ENE6RG2P-DP--XMmv.js} +1 -1
  86. package/dist/assets/{quadrantDiagram-ABIIQ3AL-D1LJoytH.js → quadrantDiagram-ABIIQ3AL-SVVI0nj0.js} +1 -1
  87. package/dist/assets/{railroadDiagram-RFXS5EU6-DtgETCCu.js → railroadDiagram-RFXS5EU6-B96CUfFG.js} +1 -1
  88. package/dist/assets/{requirementDiagram-TGXJPOKE-B8ofroLn.js → requirementDiagram-TGXJPOKE-CY0Y9Spd.js} +1 -1
  89. package/dist/assets/{sankeyDiagram-HTMAVEWB-BLJxfQiX.js → sankeyDiagram-HTMAVEWB-DUwF25eW.js} +1 -1
  90. package/dist/assets/{sequenceDiagram-DBY2YBRQ-DkXTwgge.js → sequenceDiagram-DBY2YBRQ-B1BXiSWm.js} +1 -1
  91. package/dist/assets/{sizeCapture-X5ZJPWSS-Tu0vJw5U.js → sizeCapture-X5ZJPWSS-DOInCz7x.js} +1 -1
  92. package/dist/assets/{stateDiagram-2N3HPSRC-Y8r1KoB6.js → stateDiagram-2N3HPSRC-DbJfBNBw.js} +1 -1
  93. package/dist/assets/stateDiagram-v2-6OUMAXLB-Cw6k7KjM.js +1 -0
  94. package/dist/assets/{swimlanes-5IMT3BWC-BFl--h7F.js → swimlanes-5IMT3BWC-BiSKR-2-.js} +2 -2
  95. package/dist/assets/swimlanesDiagram-G3AALYLV-De7ovgag.js +8 -0
  96. package/dist/assets/{timeline-definition-FHXFAJF6-CVxVk8L_.js → timeline-definition-FHXFAJF6-CjofGPLC.js} +1 -1
  97. package/dist/assets/{vendor-three-3OKhI9bz.js → vendor-three-CpheMTQa.js} +169 -169
  98. package/dist/assets/{vennDiagram-L72KCM5P-BfIiqSop.js → vennDiagram-L72KCM5P-B_6UlK4t.js} +1 -1
  99. package/dist/assets/{wardleyDiagram-EHGQE667-K-vB1d_8.js → wardleyDiagram-EHGQE667-CdJsoBXi.js} +1 -1
  100. package/dist/assets/{web-BWzU4tbP.js → web-DEGVeF3E.js} +1 -1
  101. package/dist/assets/{web-sV6-seS-.js → web-DINOAJn_.js} +1 -1
  102. package/dist/assets/{web-e-nG7wcx.js → web-Dt2qR7v-.js} +1 -1
  103. package/dist/assets/{xychartDiagram-FW5EYKEG-D6q7J6Kr.js → xychartDiagram-FW5EYKEG-Cp2dbS-J.js} +1 -1
  104. package/dist/build-info.json +1 -1
  105. package/dist/index.html +3 -3
  106. package/dist/locales/en/terminal.json +90 -1
  107. package/dist/locales/es/terminal.json +92 -2
  108. package/dist/src/packages/server/codex/app-server/app-server-process.js +153 -12
  109. package/dist/src/packages/server/routes/files.js +80 -6
  110. package/dist/src/packages/server/routes/system.js +9 -2
  111. package/package.json +2 -1
  112. package/dist/assets/SceneManager-CtgRFnMf.js +0 -104
  113. package/dist/assets/channel-CohCoDiY.js +0 -1
  114. package/dist/assets/classDiagram-OUVF2IWQ-BxHRM6o6.js +0 -1
  115. package/dist/assets/classDiagram-v2-EOCWNBFH-BxHRM6o6.js +0 -1
  116. package/dist/assets/index-CD2Gv3oe.js +0 -2
  117. package/dist/assets/index-evqtZdbD.js +0 -2
  118. package/dist/assets/main-BNsRZCIt.css +0 -1
  119. package/dist/assets/stateDiagram-v2-6OUMAXLB-2qL1wJnY.js +0 -1
  120. package/dist/assets/swimlanesDiagram-G3AALYLV-CrYKOH_2.js +0 -8
@@ -1 +1 @@
1
- import{r as l,j as e,I,u as X,c0 as ms,ad as gs,c1 as _s,c3 as Is,s as w,cG as $s,F as Os,cH as Ls,X as xe,K as Z,aR as Y,c as Ne,d as ye,cI as Ds,cJ as Fs,cK as Rs,cL as Bs,cM as Ms,cN as Us,cO as zs,cP as fs,cQ as Vs,cR as Ks,cS as Hs,aQ as qs,an as Ws,a2 as $e,n as Gs,cT as xs,cU as Ys,cV as Xe,cW as Js,cX as Xs,cY as Zs,cZ as Qs,c_ as et,c$ as st,d0 as tt,bj as at,k as nt,m as ot,S as _e,d1 as it,d2 as lt,d3 as ct,d4 as He,d5 as rt,d6 as dt,B as ut,d7 as pt,d8 as ht,d9 as mt,da as gt,db as bs,dc as is,dd as js,de as ft,df as xt,dg as Ie,dh as bt,di as qe,dj as ls,bY as We,w as Fe,v as jt,dk as Ge,dl as vt,dm as cs,dn as wt,dp as Nt,dq as yt,_ as kt,f as St,dr as Ct,ds as At,dt as Tt}from"./main-anrHq8ki.js";import{g as Et,d as Pt,u as _t}from"./area-logos-iPYyTqRS.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-3OKhI9bz.js";const vs="tide-toolbox-collapse";function It(s,n){try{const t=localStorage.getItem(`${vs}-${s}`);if(t!==null)return t==="true"}catch{}return n}function $t(s,n){try{localStorage.setItem(`${vs}-${s}`,String(n))}catch{}}function q({title:s,storageKey:n,defaultOpen:t=!1,forceOpen:i=!1,children:d,headerExtra:c}){const[r,g]=l.useState(()=>n?It(n,t):t),o=()=>{const N=!r;g(N),n&&$t(n,N)},u=i||r;return e.jsxs("div",{className:`collapsible-section ${u?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:o,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[c,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(I,{name:u?"caret-down":"caret-right",size:10})})]})]}),u&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Ot({area:s,isSelected:n,onClick:t,onDelete:i}){const{t:d}=X(["config","common"]),c=s.assignedAgentIds.length,r=s.type==="rectangle"?d("config:areas.rect"):d("config:areas.circle");return e.jsxs("div",{className:`area-item ${n?"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:[r," ",c>0&&`• ${c} ${c>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:i,title:d("config:areas.deleteArea"),children:"×"})]})}function Lt({building:s,isSelected:n,onClick:t,onEdit:i}){var g;const{t:d}=X(["config"]),c=((g=s.pm2Status)==null?void 0:g.ports)||[],r=(o,u)=>{o.stopPropagation(),window.open(`http://${window.location.hostname}:${u}`,"_blank")};return e.jsxs("div",{className:`building-item ${n?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:ms[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(I,{name:gs(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,c.length>0&&e.jsx("span",{className:"building-ports",children:c.map(o=>e.jsxs("a",{href:`http://${window.location.hostname}:${o}`,className:"building-port-link",onClick:u=>r(u,o),title:`Open :${o}`,children:[":",o]},o))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:o=>{o.stopPropagation(),i()},title:d("config:buildings.editBuilding"),children:e.jsx(I,{name:"gear",size:14})})]})}function Dt({building:s,onClose:n,onOpenModal:t}){var u,N,k,m,P,b,E,x;const{t:i}=X(["config","common"]),c=_s().get(s.id)||[],r=Is[s.style||"server-rack"],g=p=>{w.sendBuildingCommand(s.id,p)},o=p=>{window.open(p,"_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(I,{name:gs(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:ms[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:n,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:i("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:i("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:r.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:i("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:i("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>g("start"),disabled:!((u=s.commands)!=null&&u.start)||s.status==="running",title:((N=s.commands)==null?void 0:N.start)||i("config:buildings.noStartCommand"),children:[e.jsx(I,{name:"play",size:12})," ",i("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>g("stop"),disabled:!((k=s.commands)!=null&&k.stop)||s.status==="stopped",title:((m=s.commands)==null?void 0:m.stop)||i("config:buildings.noStopCommand"),children:[e.jsx(I,{name:"stop",size:12,weight:"fill"})," ",i("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>g("restart"),disabled:!((P=s.commands)!=null&&P.restart),title:((b=s.commands)==null?void 0:b.restart)||i("config:buildings.noRestartCommand"),children:[e.jsx(I,{name:"refresh",size:12})," ",i("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>g("healthCheck"),disabled:!((E=s.commands)!=null&&E.healthCheck),title:((x=s.commands)==null?void 0:x.healthCheck)||i("config:buildings.noHealthCheck"),children:[e.jsx(I,{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:i("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((p,S)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>o(p.url),title:p.url,children:[e.jsx(I,{name:"link",size:12})," ",p.label||p.url]},S))})]}),c.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[i("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>w.clearBuildingLogs(s.id),title:i("common:buttons.clear"),children:i("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:c.slice(-5).map((p,S)=>e.jsx("div",{className:"building-editor-log-entry",children:p},S))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(I,{name:"gear",size:12})," ",i("config:buildings.fullSettings")]})})]})}const Ft=[{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 Rt({area:s,onClose:n,onOpenFolder:t}){var ne;const{t:i}=X(["config","common"]),[d,c]=l.useState(s.name),[r,g]=l.useState(s.prompt||""),[o,u]=l.useState(!1),[N,k]=l.useState(""),[m,P]=l.useState(!1),b=l.useRef(null);l.useEffect(()=>{c(s.name)},[s.id,s.name]),l.useEffect(()=>{g(s.prompt||"")},[s.id,s.prompt]);const E=j=>{const L=j.target.value;c(L),w.updateArea(s.id,{name:L})},x=j=>{w.updateArea(s.id,{color:j})},p=j=>{const L=j.target.value;g(L),w.updateArea(s.id,{prompt:L})},S=()=>{N.trim()&&(w.addDirectoryToArea(s.id,N.trim()),k(""),u(!1))},M=(j,L)=>{L.stopPropagation(),w.removeDirectoryFromArea(s.id,j)},F=()=>{w.bringAreaToFront(s.id)},Q=()=>{w.sendAreaToBack(s.id)},W=l.useCallback(()=>{let j=2,L=2;s.type==="rectangle"&&s.width&&s.height?(j=s.width,L=s.height):s.type==="circle"&&s.radius&&(j=s.radius*1.414,L=s.radius*1.414);const z=Math.min(j,L)*.4;return{width:Math.round(z*10)/10,height:Math.round(z*10)/10}},[s.type,s.width,s.height,s.radius]),J=async j=>{var z;const L=(z=j.target.files)==null?void 0:z[0];if(L){P(!0);try{const v=await _t(s.id,L),O=W();w.updateArea(s.id,{logo:{filename:v.filename,position:"center",width:O.width,height:O.height,keepAspectRatio:!0,opacity:.8}})}catch(v){console.error("Failed to upload logo:",v)}finally{P(!1),b.current&&(b.current.value="")}}},U=async()=>{try{await Pt(s.id),w.updateArea(s.id,{logo:void 0})}catch(j){console.error("Failed to remove logo:",j)}},V=j=>{s.logo&&w.updateArea(s.id,{logo:{...s.logo,position:j}})},h=j=>{if(!s.logo)return;const L=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const z=s.logo.height/s.logo.width;w.updateArea(s.id,{logo:{...s.logo,width:L,height:Math.round(L*z*10)/10}})}else w.updateArea(s.id,{logo:{...s.logo,width:L}})},$=j=>{if(!s.logo)return;const L=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const z=s.logo.width/s.logo.height;w.updateArea(s.id,{logo:{...s.logo,height:L,width:Math.round(L*z*10)/10}})}else w.updateArea(s.id,{logo:{...s.logo,height:L}})},R=()=>{s.logo&&w.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},H=j=>{s.logo&&w.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(j.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:i("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:n,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange:E,placeholder:i("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:$s.map(j=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===j?"selected":""}`,style:{backgroundColor:j},onClick:()=>x(j),"aria-label":`Set area color ${j}`,"aria-pressed":s.color===j,title:j},j))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:F,title:i("config:areas.bringToFront"),children:[e.jsx(I,{name:"arrow-up",size:12})," ",i("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:Q,title:i("config:areas.sendToBack"),children:[e.jsx(I,{name:"arrow-down",size:12})," ",i("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:i("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(ne=s.logo)!=null&&ne.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Et(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:U,children:i("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var j;return(j=b.current)==null?void 0:j.click()},disabled:m,children:m?"...":e.jsx(I,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:Ft.map(({key:j,labelKey:L})=>{var z;return e.jsx("button",{className:`area-logo-pos-btn ${((z=s.logo)==null?void 0:z.position)===j?"active":""}`,onClick:()=>V(j),children:i(`config:areas.${L}`)},j)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("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:i("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:h,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:i("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:$,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:i("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:R}),i("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("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:H,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 j;return(j=b.current)==null?void 0:j.click()},disabled:m,children:m?"...":i("config:areas.uploadLogo")}),e.jsx("input",{ref:b,type:"file",accept:"image/*",style:{display:"none"},onChange:J})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:i("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(j=>e.jsxs("div",{className:"area-folder-item",title:j,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:i("config:areas.openFolder"),children:e.jsx(I,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:j.split("/").pop()||j}),e.jsx("button",{className:"area-folder-remove",onClick:L=>M(j,L),title:i("config:areas.removeFolder"),children:"×"})]},j)),o?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(Os,{value:N,onChange:k,onSubmit:S,placeholder:i("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:S,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>u(!0),children:i("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:i("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:r,onChange:p,placeholder:i("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:i("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:i("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:i("config:areas.rightClickUnassign")})]})]})}function Bt(){const{t:s}=X(["config","common"]),n=Ls(),[t,i]=l.useState(!1),[d,c]=l.useState(null),[r,g]=l.useState({name:"",key:"",value:"",description:""}),[o,u]=l.useState(null),N=()=>{i(!0),c(null),g({name:"",key:"",value:"",description:""})},k=p=>{c(p.id),i(!1),g({name:p.name,key:p.key,value:p.value,description:p.description||""})},m=()=>{i(!1),c(null),g({name:"",key:"",value:"",description:""})},P=()=>{!r.name.trim()||!r.key.trim()||(d?w.updateSecret(d,{name:r.name.trim(),key:r.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:r.value,description:r.description.trim()||void 0}):w.createSecret({name:r.name.trim(),key:r.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:r.value,description:r.description.trim()||void 0}),m())},b=p=>{u(p)},E=()=>{o&&(w.deleteSecret(o),d===o&&m())},x=p=>{navigator.clipboard.writeText(`{{${p}}}`)};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:n.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):n.map(p=>e.jsxs("div",{className:`secret-item ${d===p.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:p.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>x(p.key),title:s("config:secrets.copyPlaceholder"),children:`{{${p.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>k(p),title:s("common:buttons.edit"),children:e.jsx(I,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>b(p.id),title:s("common:buttons.delete"),children:"×"})]})]}),p.description&&e.jsx("div",{className:"secret-item-description",children:p.description})]},p.id))}),(t||d)&&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:r.name,onChange:p=>g({...r,name:p.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:r.key,onChange:p=>g({...r,key:p.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${r.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:r.value,onChange:p=>g({...r,value:p.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:r.description,onChange:p=>g({...r,description:p.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:m,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:P,disabled:!r.name.trim()||!r.key.trim(),children:s(d?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:N,children:s("config:secrets.addSecret")}),e.jsx(xe,{isOpen:o!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:E,onClose:()=>u(null)})]})}async function Mt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch system prompt: ${n.statusText}`);return(await n.json()).prompt||""}async function Ut(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function zt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to clear system prompt: ${n.statusText}`)}async function Vt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch echo prompt setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Kt(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function Ht(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex binary path: ${n.statusText}`);return(await n.json()).path||""}async function qt(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function Wt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch tmux mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Gt(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function Yt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch interactive mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Jt(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function Xt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/codex-app-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex app-server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Zt(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/codex-app-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update codex app-server mode setting: ${t.statusText}`)}async function Qt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/opencode-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch opencode server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ea(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/opencode-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update opencode server mode setting: ${t.statusText}`)}async function sa(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch backup status: ${n.statusText}`);return n.json()}async function ta(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok){const i=await t.json().catch(()=>({}));throw new Error(i.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function aa({checked:s,onChange:n,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:i=>n(i.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function na(){const{t:s}=X(["config","common"]),[n,t]=l.useState([]),[i,d]=l.useState(new Set),[c,r]=l.useState(new Set),[g,o]=l.useState(!1),[u,N]=l.useState(!1),[k,m]=l.useState(null),[P,b]=l.useState(null),[E,x]=l.useState(null),[p,S]=l.useState(null),[M,F]=l.useState(!1),[Q,W]=l.useState(null);l.useEffect(()=>{Ne(ye("/api/config/categories")).then(v=>v.json()).then(v=>{const O=Array.isArray(v)?v:[];t(O),d(new Set(O.map(D=>D.id)))}).catch(v=>console.error("Failed to fetch config categories:",v))},[]),l.useEffect(()=>{sa().then(S).catch(v=>{console.error("Failed to fetch backup status:",v),W(v.message||"Failed to fetch backup status")})},[]);const J=async v=>{if(!M){F(!0),W(null);try{const O=await ta(v);S(O)}catch(O){W(O.message||"Failed to update backup setting")}finally{F(!1)}}},U=v=>{d(O=>{const D=new Set(O);return D.has(v)?D.delete(v):D.add(v),D})},V=v=>{r(O=>{const D=new Set(O);return D.has(v)?D.delete(v):D.add(v),D})},h=()=>d(new Set(n.map(v=>v.id))),$=()=>d(new Set),R=()=>{P&&r(new Set(P.categories.map(v=>v.id)))},H=()=>r(new Set),ne=async()=>{var v;if(i.size!==0){o(!0),x(null);try{const O=Array.from(i).join(","),D=await Ne(ye(`/api/config/export?categories=${O}`));if(!D.ok)throw new Error("Export failed");const se=await D.blob(),ae=window.URL.createObjectURL(se),T=document.createElement("a");T.href=ae;const y=D.headers.get("Content-Disposition"),te=((v=y==null?void 0:y.match(/filename="(.+)"/))==null?void 0:v[1])||"tide-commander-config.zip";T.download=te,document.body.appendChild(T),T.click(),document.body.removeChild(T),window.URL.revokeObjectURL(ae),x({type:"success",text:s("config:data.exportSuccess")})}catch(O){x({type:"error",text:O.message||"Export failed"})}finally{o(!1)}}},j=async v=>{var D;const O=(D=v.target.files)==null?void 0:D[0];if(O){m(O),x(null),b(null),r(new Set);try{const se=await Ne(ye("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await O.arrayBuffer()});if(!se.ok){const y=await se.json();throw new Error(y.error||"Failed to preview config file")}const ae=await se.json(),T=Array.isArray(ae.categories)?ae.categories:[];b({...ae,categories:T}),r(new Set(T.map(y=>y.id)))}catch(se){x({type:"error",text:se.message||"Failed to read config file"}),m(null)}}},L=async()=>{if(!(!k||c.size===0)){N(!0),x(null);try{const v=Array.from(c).join(","),O=await Ne(ye(`/api/config/import?categories=${v}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await k.arrayBuffer()}),D=await O.json();if(!O.ok)throw new Error(D.error||"Import failed");x({type:"success",text:D.message||s("config:data.importSuccess")}),m(null),b(null),r(new Set)}catch(v){x({type:"error",text:v.message||"Import failed"})}finally{N(!1)}}},z=()=>{m(null),b(null),r(new Set),x(null)};return e.jsxs("div",{className:"data-section",children:[E&&e.jsx("div",{className:`data-message data-message-${E.type}`,children:E.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(aa,{checked:!!(p!=null&&p.enabled),disabled:M||!p,onChange:J})]}),e.jsxs("div",{className:"data-backup-info",children:[p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:p.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!p.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:p.scriptPath})]}),p.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(p.lastRunAt).toLocaleString(),p.lastRunOk===!0&&" — ok",p.lastRunOk===!1&&p.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",p.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),Q&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:Q})]})]}),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:h,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:$,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:n.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:i.has(v.id),onChange:()=>U(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name})]},v.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ne,disabled:g||i.size===0,children:g?s("config:data.exporting"):s("config:data.exportCount",{count:i.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")})}),k?P?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:k.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:R,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:H,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:P.categories.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:c.has(v.id),onChange:()=>V(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name}),v.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",v.fileCount," ",s("config:data.files"),")"]})]},v.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:z,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:L,disabled:u||c.size===0,children:u?s("config:data.importing"):s("config:data.importCount",{count:c.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:j,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function oa(){const[s,n]=l.useState(()=>Ds()),t=i=>{n(i);const d=Ms(i);Us(d)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:Fs.map(i=>e.jsxs("button",{className:`theme-option ${s===i.id?"active":""}`,onClick:()=>t(i.id),title:i.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:i.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:i.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:i.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:i.name})]},i.id))})})}function ia(){const{t:s}=X(["config"]),{installInfo:n,phase:t,output:i,error:d,newVersion:c,autoRestart:r,refreshInstallInfo:g,runUpdate:o,reset:u}=zs(),[N,k]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{g()},[g]),l.useEffect(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)},[i]);const P=l.useCallback(()=>{k(!0)},[]),b=l.useCallback(()=>{k(!1)},[]),E=l.useCallback(()=>{k(!1),o()},[o]),x=l.useCallback(()=>{u(),k(!1),g()},[u,g]),p=fs.isNativePlatform(),S=s(p?"config:about.autoUpdateServerTitle":"config:about.autoUpdateTitle");return n?n.isGlobalInstall?n.autoUpdateSupported?!n.updateAvailable&&t==="idle"?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:S}),t==="idle"&&!N&&n.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:n.currentVersion}),e.jsx("span",{className:"about-autoupdate-arrow",children:"→"}),e.jsx("span",{className:"about-autoupdate-latest",children:n.latestVersion})]}),e.jsx("button",{className:"about-update-btn download",onClick:P,children:s("config:about.autoUpdateButton")})]}),t==="idle"&&N&&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:b,children:s("config:about.autoUpdateCancel")}),e.jsx("button",{className:"about-update-btn download",onClick:E,children:s("config:about.autoUpdateConfirm")})]})]}),(t==="running"||t==="success"||t==="failed")&&e.jsxs("div",{className:"about-autoupdate-stream",children:[e.jsxs("div",{className:"about-autoupdate-stream-title",children:[t==="running"&&s("config:about.autoUpdateRunning"),t==="success"&&s("config:about.autoUpdateSuccess"),t==="failed"&&s("config:about.autoUpdateFailed")]}),e.jsx("pre",{ref:m,className:"about-autoupdate-output",children:i||"..."}),t==="success"&&e.jsxs("div",{className:"about-autoupdate-success-hint",children:[c&&e.jsxs("div",{className:"about-autoupdate-newversion",children:["v",c]}),e.jsx("div",{children:s(r?"config:about.autoUpdateReconnectHint":"config:about.autoUpdateRestartHint")})]}),t==="failed"&&d&&e.jsx("div",{className:"about-update-error",children:d}),(t==="success"||t==="failed")&&e.jsx("div",{className:"about-autoupdate-stream-actions",children:e.jsx("button",{className:"about-update-btn changelog",onClick:x,children:s("config:about.autoUpdateClose")})})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:S}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdatePackageManagerNotice",{pm:n.packageManager})}),n.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:n.suggestedManualCommand})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:S}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdateDevMode")})]}):null}function la(){const{t:s}=X(["config"]),[n,t]=l.useState(null),[i,d]=l.useState(!1),[c,r]=l.useState(null);l.useEffect(()=>{Vs().then(t).catch(N=>r(N.message))},[]);const g=l.useCallback(async N=>{if(!i){d(!0),r(null);try{t(await Ks(N))}catch(k){r(k.message)}finally{d(!1)}}},[i]),o=fs.isNativePlatform(),u=s(o?"config:about.unattendedServerTitle":"config:about.unattendedTitle");return!n&&!c?null:n?o&&!n.supported?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:u}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:about.unattendedDesc")}),e.jsxs("label",{className:"config-toggle",style:n.supported?void 0:{opacity:.5},children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:n.enabled,disabled:i||!n.supported,onChange:N=>void g(N.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),!n.supported&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedUnsupported")}),n.supported&&n.enabled&&n.pendingRestartVersion&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedPendingRestart",{version:n.pendingRestartVersion})}),n.supported&&n.enabled&&!n.pendingRestartVersion&&n.lastResult&&e.jsx("div",{className:"about-autoupdate-devnote",children:n.lastResult}),c&&e.jsx("div",{className:"about-update-error",children:c})]}):o?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:u}),e.jsx("div",{className:"about-update-error",children:c})]})}function ca(){var M;const{t:s}=X(["config"]),{isAndroid:n,supported:t,otaActive:i,bundleState:d,serverInfo:c,infoError:r,updateAvailable:g,phase:o,progress:u,error:N,autoSync:k,checkNow:m,syncNow:P,resetToBundled:b,setAutoSync:E}=Hs(),[x,p]=l.useState(null),S=l.useRef(m);return S.current=m,l.useEffect(()=>{n&&(S.current(!1),qs.getInfo().then(F=>p(F.version)).catch(()=>{}))},[n]),!n||t===!1?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:webBundle.title")}),e.jsxs("div",{className:"about-autoupdate-devnote",children:[i?s("config:webBundle.sourceOta",{hash:((M=d==null?void 0:d.hash)==null?void 0:M.slice(0,8))??"?"}):s("config:webBundle.sourceBundled"),x&&` · ${s("config:webBundle.apkVersion",{version:x})}`]}),c?e.jsxs("div",{className:"about-autoupdate-devnote",children:[s("config:webBundle.serverBundle",{version:c.version,hash:c.hash.slice(0,8)})," — ",s(g?"config:webBundle.updateAvailable":"config:webBundle.upToDate")]}):r&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:webBundle.serverUnavailable")}),N&&e.jsx("div",{className:"about-update-error",children:N}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:webBundle.autoSync")}),e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:k,onChange:F=>E(F.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn download",onClick:()=>void P(),disabled:o!=="idle"||!c,children:o==="syncing"?s("config:webBundle.syncingPct",{percent:u??0}):s("config:webBundle.syncNow")}),i&&e.jsx("button",{className:"about-update-btn changelog",onClick:()=>void b(),children:s("config:webBundle.reset")})]})]})}function ra(){const{t:s}=X(["config"]),{updateAvailable:n,updateInfo:t,recentReleases:i,isChecking:d,error:c,currentVersion:r,isAndroid:g,downloadPhase:o,downloadProgress:u,checkForUpdate:N,downloadAndInstall:k,openReleasePage:m}=Rs(),[P,b]=l.useState(!1),E=p=>p?`${(p/(1024*1024)).toFixed(1)} MB`:"",x=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(I,{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:r}),n&&t?e.jsx("span",{className:"about-version-update-badge",onClick:m,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(ia,{}),e.jsx(la,{}),e.jsx(ca,{}),e.jsx("div",{className:"about-changelog-row",children:e.jsx("button",{className:"about-update-btn changelog",onClick:()=>b(!0),children:s("config:about.changelog")})}),e.jsxs("div",{className:"about-update",children:[n&&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"),": ",E(t.apkSize)]}),c&&e.jsx("div",{className:"about-update-error",children:c}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:m,children:s("config:about.changelog")}),g&&t.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:()=>void k(),disabled:o!=="idle",children:o==="downloading"?s("config:appUpdateBanner.downloadingPct",{percent:u??0}):s(o==="installing"?"config:appUpdateBanner.installHint":"config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:m,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(d?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>N(!0),disabled:d,children:d?"...":s("config:about.check")})]}),i.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:i.map(p=>e.jsxs("a",{href:p.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${p.version===`v${r}`||p.version===r?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:p.version}),e.jsx("span",{className:"about-release-date",children:x(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(I,{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")})]})]}),P&&e.jsx(Bs,{onClose:()=>b(!1)})]})}const da={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function ua({onOpenModal:s}){const[n,t]=l.useState([]),[i,d]=l.useState(!0),c=l.useCallback(async()=>{try{const r=await Ne(ye("/api/integrations"));if(!r.ok)return;const g=await r.json();t(g)}catch{}finally{d(!1)}},[]);return l.useEffect(()=>{c()},[c]),i?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):n.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:[n.map(r=>{const g=da[r.id]||"🔌",o=!!r.status.error,u=r.status.connected,N=o?"#f38ba8":u?"#a6e3a1":"#fab387",k=o?"Error":u?"Connected":"Setup Required",m=o?"✗":u?"✓":"⚠";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:r.name}),e.jsx("span",{style:{color:N,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:k,children:m}),e.jsx("button",{onClick:()=>s(r.id),title:`Configure ${r.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:"⚙️"})]},r.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:r=>{r.target.style.borderColor="var(--accent, #89b4fa)",r.target.style.color="var(--accent, #89b4fa)"},onMouseLeave:r=>{r.target.style.borderColor="var(--border, #313244)",r.target.style.color="var(--text-secondary, #a6adc8)"},children:"Manage All Integrations"})]})}const Re="__global__";function pa({isOpen:s,onClose:n,initialAgentId:t}){const{t:i}=X(["config"]),d=Ws(),[c,r]=l.useState(""),[g,o]=l.useState(""),[u,N]=l.useState(!1),[k,m]=l.useState(""),[P,b]=l.useState(""),[E,x]=l.useState(null),[p,S]=l.useState(null),[M,F]=l.useState(!1),[Q,W]=l.useState(!1),[J,U]=l.useState(!1),[V,h]=l.useState(null),$=l.useMemo(()=>[...d].sort((T,y)=>T.name.localeCompare(y.name)),[d]),R=l.useMemo(()=>d.find(T=>T.id===c),[d,c]),H=c===Re;l.useEffect(()=>{if(!s)return;const T=t&&d.some(y=>y.id===t)?t:Re;r(T),N(!1),Mt().then(y=>o(y)).catch(()=>o("")).finally(()=>N(!0))},[s]),l.useEffect(()=>{const T=c===Re?g:(R==null?void 0:R.customPrompt)??"";m(T),b(T),F(!1),x(null),S(null)},[c,u]);const ne=T=>{const y=T.target.value;m(y),F(y!==P),x(null),S(null)},j=async()=>{if(c)try{x(null),S(null),H?(await Ut(k),o(k),S(i("config:systemPrompt.savedGlobal"))):(w.updateAgentProperties(c,{customPrompt:k}),S(i("config:systemPrompt.saved"))),b(k),F(!1)}catch(T){x(T instanceof Error?T.message:"Failed to save system prompt")}},L=()=>{W(!0)},z=async()=>{if(c)try{x(null),S(null),H?(await zt(),o(""),S(i("config:systemPrompt.clearedGlobal"))):(w.updateAgentProperties(c,{customPrompt:""}),S(i("config:systemPrompt.cleared"))),m(""),b(""),F(!1)}catch(T){x(T instanceof Error?T.message:"Failed to clear system prompt")}},v=()=>{m(P),F(!1),x(null),S(null)},O=T=>{if(T!==c){if(M){h(T),U(!0);return}r(T)}},D=()=>{if(M){h(null),U(!0);return}n()},se=()=>{if(U(!1),V){const T=V;h(null),r(T)}else n()},ae=T=>{T.key==="Escape"&&(T.preventDefault(),D())};return s?e.jsxs($e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:D,children:e.jsxs("div",{className:"system-prompt-modal",onClick:T=>T.stopPropagation(),onKeyDown:ae,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:i("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:D,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"modal-description",children:i("config:systemPrompt.description")}),e.jsxs("div",{className:"agent-picker",children:[e.jsx("label",{htmlFor:"system-prompt-agent",className:"editor-label",children:i("config:systemPrompt.agentLabel")}),e.jsxs("div",{className:"agent-picker-row",children:[H?e.jsx(I,{name:"globe",size:20,className:"agent-picker-icon"}):R&&e.jsx(Gs,{classId:R.class,size:20,className:"agent-picker-icon"}),e.jsxs("select",{id:"system-prompt-agent",className:"agent-picker-select",value:c,onChange:T=>O(T.target.value),children:[e.jsxs("option",{value:Re,children:[i("config:systemPrompt.globalOption"),g?" • ✦":""]}),$.map(T=>e.jsxs("option",{value:T.id,children:[T.name,T.customPrompt?" • ✦":""]},T.id))]})]})]}),E&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),E]}),p&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),p]}),e.jsxs("div",{className:"editor-wrapper",children:[e.jsxs("div",{className:"editor-header",children:[e.jsx("label",{htmlFor:"prompt-input",className:"editor-label",children:i("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[k.length," ",i("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:k,onChange:ne,placeholder:i("config:systemPrompt.placeholder"),rows:18,disabled:H&&!u,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:i(H?"config:systemPrompt.hintGlobal":"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:L,disabled:!k||!c,children:i("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:D,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:v,disabled:!M,children:i("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:j,disabled:!M||!c,children:i("config:systemPrompt.save")})]})]})]})}),e.jsx(xe,{isOpen:Q,title:i("config:systemPrompt.clear"),message:i(H?"config:systemPrompt.confirmClearGlobal":"config:systemPrompt.confirmClear"),confirmLabel:i("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{z()},onClose:()=>W(!1)}),e.jsx(xe,{isOpen:J,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:se,onClose:()=>{U(!1),h(null)}})]}):null}const rs={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},ha=2500,ma=12e4;function ds(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function ga(s,n){return s.enabled===n.enabled&&s.baseUrl===n.baseUrl&&s.defaultSessionId===n.defaultSessionId&&s.webhookVerifyToken===n.webhookVerifyToken&&s.showIncomingToasts===n.showIncomingToasts}function fa({isOpen:s,onClose:n}){const{t}=X(["config"]),[i,d]=l.useState(rs),[c,r]=l.useState(rs),[g,o]=l.useState(!1),[u,N]=l.useState([]),[k,m]=l.useState(!0),[P,b]=l.useState(null),[E,x]=l.useState(null),[p,S]=l.useState(""),[M,F]=l.useState(!1),[Q,W]=l.useState(""),[J,U]=l.useState(null),[V,h]=l.useState(null),[$,R]=l.useState(null),H=l.useRef(null),ne=l.useRef(0),[j,L]=l.useState(""),[z,v]=l.useState(""),[O,D]=l.useState(null),[se,ae]=l.useState(!1),[T,y]=l.useState(!1),[te,oe]=l.useState(!1),[de,ie]=l.useState(!1),[he,ke]=l.useState(null),Ae=!ga(i,c),ue=l.useCallback(()=>{H.current&&(clearTimeout(H.current),H.current=null)},[]),Te=l.useCallback(async()=>{try{m(!0),b(null),x(null);const[f,K]=await Promise.all([xs(),Ys()]),ce=ds(f);if(d(ce),r(ce),o(!!K.configured),K.configured)try{const je=await Xe();N(Array.isArray(je)?je:[])}catch{N([])}else N([])}catch(f){b(f instanceof Error?f.message:t("config:whatsapp.errors.loadFailed"))}finally{m(!1)}},[t]),me=l.useCallback(async()=>{try{const f=await Xe();N(Array.isArray(f)?f:[])}catch{}},[]);l.useEffect(()=>(s?Te():(ue(),U(null),h(null),R(null),S(""),F(!1),D(null)),()=>{ue()}),[s,Te,ue]);const ge=(f,K)=>{d(ce=>({...ce,[f]:K})),b(null),x(null)},Oe=async()=>{try{b(null),x(null);const f=await et({enabled:i.enabled,baseUrl:i.baseUrl.trim(),defaultSessionId:i.defaultSessionId.trim(),webhookVerifyToken:i.webhookVerifyToken,showIncomingToasts:i.showIncomingToasts});window.dispatchEvent(new CustomEvent("tide:whatsapp-config-updated"));const K=ds(f);d(K),r(K),x(t("config:whatsapp.saved"))}catch(f){b(f instanceof Error?f.message:t("config:whatsapp.errors.saveFailed"))}},Me=()=>{d(c),b(null),x(null)},Se=()=>{if(Ae){y(!0);return}n()},Le=f=>{f.key==="Escape"&&(f.preventDefault(),Se())},Ue=async()=>{const f=p.trim();if(f)try{b(null),x(null),await Xs(f),S(""),F(!1),o(!0),x(t("config:whatsapp.apiKeySaved"))}catch(K){b(K instanceof Error?K.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},ze=()=>{oe(!0)},Ve=async()=>{try{b(null),x(null),await st(),o(!1),x(t("config:whatsapp.apiKeyCleared"))}catch(f){b(f instanceof Error?f.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},be=l.useCallback(async f=>{if(Date.now()>ne.current){R(t("config:whatsapp.pairingTimeout")),U(null),h(null),ue(),me();return}try{const K=await Js(f);if(K.status&&["connected","paired","open","ready"].includes(K.status.toLowerCase())){R(t("config:whatsapp.pairingSuccess")),U(null),h(null),ue(),me();return}const je=K.qrUrl??K.qr??null;je&&h(je)}catch(K){R(K instanceof Error?K.message:t("config:whatsapp.errors.qrFetchFailed"))}H.current=setTimeout(()=>{be(f)},ha)},[me,ue,t]),_=async()=>{const f=Q.trim();if(f)try{b(null),x(null),R(null),h(null),ue(),await Zs(f),W(""),U(f),ne.current=Date.now()+ma,be(f),me()}catch(K){b(K instanceof Error?K.message:t("config:whatsapp.errors.sessionCreateFailed"))}},Ee=()=>{ue(),U(null),h(null),R(null)},pe=f=>{ke(f),ie(!0)},Ke=async()=>{if(he)try{b(null),x(null),await tt(he),J===he&&Ee(),me(),x(t("config:whatsapp.sessionDeleted"))}catch(f){b(f instanceof Error?f.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{ke(null)}},De=async()=>{const f=j.trim(),K=z.trim();if(!(!f||!K))try{ae(!0),D(null);const ce=i.defaultSessionId.trim()||void 0;await Qs(f,K,ce),D({kind:"success",text:t("config:whatsapp.testSent")})}catch(ce){D({kind:"error",text:ce instanceof Error?ce.message:t("config:whatsapp.errors.testSendFailed")})}finally{ae(!1)}};return s?e.jsxs($e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:Se,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:Se,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:k?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(I,{name:"warn",size:14})}),P]}),E&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),E]}),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:i.enabled,onChange:f=>ge("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:i.showIncomingToasts,onChange:f=>ge("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:i.baseUrl,onChange:f=>ge("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:i.defaultSessionId,onChange:f=>ge("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:i.webhookVerifyToken,onChange:f=>ge("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(I,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(I,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:M?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:p,onChange:f=>S(f.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>F(f=>!f),title:t(M?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(I,{name:M?"eye-closed":"eye",size:14})}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ue,disabled:!p.trim(),children:t("config:whatsapp.saveKey")}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:ze,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(u)||u.length===0?e.jsx("div",{className:"wa-empty",children:t("config:whatsapp.noSessions")}):u.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:()=>pe(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:Q,onChange:f=>W(f.target.value),onKeyDown:f=>{f.key==="Enter"&&_()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:_,disabled:!Q.trim()||J!==null,children:t("config:whatsapp.addSession")})]}),J&&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:J})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Ee,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")})]})]}),$&&!J&&e.jsx("div",{className:"wa-pairing-message",children:$})]}),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:j,onChange:f=>L(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:z,onChange:f=>v(f.target.value)})]}),e.jsx("div",{className:"wa-field-inline wa-field-end",children:e.jsx("button",{type:"button",className:"btn btn-primary",onClick:De,disabled:!j.trim()||!z.trim()||se,children:t(se?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),O&&e.jsxs("div",{className:`alert ${O.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:O.kind==="success"?"check":"warn",size:14})}),O.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:Se,children:t("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:Me,disabled:!Ae||k,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:Oe,disabled:!Ae||k,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(xe,{isOpen:T,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{y(!1),n()},onClose:()=>y(!1)}),e.jsx(xe,{isOpen:te,title:t("config:whatsapp.clearKey"),message:t("config:whatsapp.confirmClearKey"),confirmLabel:t("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Ve()},onClose:()=>oe(!1)}),e.jsx(xe,{isOpen:de,title:t("config:whatsapp.deleteSession"),message:t("config:whatsapp.confirmDeleteSession",{id:he??""}),confirmLabel:t("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Ke()},onClose:()=>{ie(!1),ke(null)}})]}):null}const ws=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function Ze(s=!1){const n=Z(),t={};return n&&(t.Authorization=`Bearer ${n}`),s&&(t["Content-Type"]="application/json"),t}async function Qe(s,n){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`${n}: ${s.statusText}`}async function xa(){const s=await fetch(`${Y()}/api/whatsapp/notification-config`,{headers:Ze()});if(!s.ok)throw new Error(await Qe(s,"Failed to fetch WhatsApp notification config"));return s.json()}async function ba(s){const n=await fetch(`${Y()}/api/whatsapp/notification-config`,{method:"PATCH",headers:Ze(!0),body:JSON.stringify(s)});if(!n.ok)throw new Error(await Qe(n,"Failed to update WhatsApp notification config"));return n.json()}async function ja(){const s=await fetch(`${Y()}/api/whatsapp/notification-config`,{method:"DELETE",headers:Ze()});if(!s.ok)throw new Error(await Qe(s,"Failed to reset WhatsApp notification config"));return s.json()}const Be={messages:!0,statusChanges:!0,taskComplete:!0,errors:!0,planReady:!0,agentSpawned:!0,agentStopped:!0},us={filter:{...Be},recipient:""};function va(s,n){if(s.recipient!==n.recipient)return!1;for(const t of ws)if(s.filter[t]!==n.filter[t])return!1;return!0}function wa({isOpen:s,onClose:n}){const{t}=X(["config"]),[i,d]=l.useState(us),[c,r]=l.useState(us),[g,o]=l.useState(!0),[u,N]=l.useState(null),[k,m]=l.useState(null),[P,b]=l.useState(!1),[E,x]=l.useState(!1),p=!va(i,c),S=l.useCallback(async()=>{try{o(!0),N(null),m(null);const h=await xa(),$={filter:{...Be,...h.filter},recipient:h.recipient??""};d($),r($)}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{o(!1)}},[t]);l.useEffect(()=>{s&&S()},[s,S]);const M=(h,$)=>{d(R=>({...R,filter:{...R.filter,[h]:$}})),N(null),m(null)},F=h=>{d($=>({...$,recipient:h})),N(null),m(null)},Q=async()=>{try{N(null),m(null);const h=await ba({filter:i.filter,recipient:i.recipient.trim()}),$={filter:{...Be,...h.filter},recipient:h.recipient??""};d($),r($),m(t("config:whatsappNotifications.saved"))}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.saveFailed"))}},W=()=>{d(c),N(null),m(null)},J=async()=>{try{N(null),m(null);const h=await ja(),$={filter:{...Be,...h.filter},recipient:h.recipient??""};d($),r($),m(t("config:whatsappNotifications.resetDone"))}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.resetFailed"))}},U=()=>{if(p){b(!0);return}n()},V=h=>{h.key==="Escape"&&(h.preventDefault(),U())};return s?e.jsxs($e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:U,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:h=>h.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:U,"aria-label":"Close",children:e.jsx(I,{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")}),u&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),u]}),k&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),k]}),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:i.recipient,onChange:h=>F(h.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")}),ws.map(h=>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.${h}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${h}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:i.filter[h],onChange:$=>M(h,$.target.checked)}),e.jsx("span",{className:"wan-toggle-track",children:e.jsx("span",{className:"wan-toggle-thumb"})})]})]},h))]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:()=>x(!0),disabled:g,children:t("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:U,children:t("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:W,disabled:!p||g,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:Q,disabled:!p||g,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(xe,{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:()=>{b(!1),n()},onClose:()=>b(!1)}),e.jsx(xe,{isOpen:E,title:t("config:whatsappNotifications.resetToDefaults"),message:t("config:whatsappNotifications.confirmReset"),confirmLabel:t("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{J(),x(!1)},onClose:()=>x(!1)})]}):null}function Ns(s){const n=s.replace(/@.*$/,"");return/^\d{10,15}$/.test(n)?n.startsWith("521")&&n.length===13?`+52 1 ${n.slice(3,5)} ${n.slice(5,9)} ${n.slice(9)}`:n.startsWith("52")&&n.length===12?`+52 ${n.slice(2,4)} ${n.slice(4,8)} ${n.slice(8)}`:n.startsWith("1")&&n.length===11?`+1 ${n.slice(1,4)} ${n.slice(4,7)} ${n.slice(7)}`:`+${n}`:s}function Na(s,n=Date.now()){const t=s*1e3,i=n-t;if(i<0)return ps(t);const d=Math.floor(i/6e4);if(d<1)return"now";if(d<60)return`${d}m`;const c=Math.floor(d/60);if(c<24)return`${c}h`;const r=Math.floor(c/24);return r===1?"yesterday":r<7?`${r}d`:ps(t)}function ps(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function ya(s){const n=s*1e3;return new Date(n).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function ys(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 ka(s,n){return s.length<=n?s:s.slice(0,Math.max(0,n-1)).trimEnd()+"…"}function Sa({chats:s,selectedChatId:n,loading:t,error:i,onSelect:d,onRefresh:c,now:r}){const{t:g}=X(["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:c,disabled:t,"aria-label":g("config:whatsappHistory.refresh"),title:g("config:whatsappHistory.refresh"),children:"⟳"})]}),i&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:i}),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&&!i&&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(o=>{const u=ys(o.lastMessageType),N=o.lastMessagePreview||`[${o.lastMessageType}]`,k=o.chatId===n,m=Ns(o.chatId),P=o.isGroup?o.groupName:o.fromName,b=P||m,E=!!P&&P!==m;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${k?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>d(o.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:o.chatId,children:b}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:Na(o.lastTimestamp,r)})]}),E&&e.jsx("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--jid",children:e.jsx("span",{className:"whatsapp-history-chatlist__jid",children:m})}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[o.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),u&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[u," "]}),ka(N,40)]}),o.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:o.unreadCount})]})]})},o.chatId)})})]})}function Ca({message:s}){const n=s.direction==="outbound"?"outbound":"inbound",t=ys(s.messageType),i=(s.body??"").trim(),d=i.length>0,c=d?null:`[${s.messageType}]`;return e.jsx("div",{className:`whatsapp-history-bubble whatsapp-history-bubble--${n}`,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}),d?e.jsx("span",{className:"whatsapp-history-bubble__body",children:i}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:c}),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:ya(s.timestamp)})]})})}const Aa=["all","inbound","outbound"],Ta=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function Ea({direction:s,type:n,onDirectionChange:t,onTypeChange:i,disabled:d}){const{t:c}=X(["config"]);return e.jsxs("div",{className:"whatsapp-history-filters",children:[e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:c("config:whatsappHistory.direction")}),e.jsx("select",{value:s,onChange:r=>t(r.target.value),disabled:d,children:Aa.map(r=>e.jsx("option",{value:r,children:c(`config:whatsappHistory.directionValues.${r}`)},r))})]}),e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:c("config:whatsappHistory.type")}),e.jsx("select",{value:n,onChange:r=>i(r.target.value),disabled:d,children:Ta.map(r=>e.jsx("option",{value:r,children:c(`config:whatsappHistory.typeValues.${r}`)},r))})]})]})}const Pa=80;function _a({chatId:s,messages:n,loading:t,loadingMore:i,error:d,hasMore:c,direction:r,type:g,onDirectionChange:o,onTypeChange:u,onLoadMore:N}){const{t:k}=X(["config"]),m=l.useRef(null),P=l.useRef(null),b=l.useRef(!1),E=l.useRef(null);l.useEffect(()=>{P.current!==s&&(P.current=s,b.current=!1)},[s]),l.useLayoutEffect(()=>{m.current&&(b.current||n.length!==0&&(m.current.scrollTop=m.current.scrollHeight,b.current=!0))},[s,n.length]),l.useLayoutEffect(()=>{if(!m.current||E.current===null)return;const S=m.current.scrollHeight-E.current;E.current=null,S>0&&(m.current.scrollTop+=S)},[n.length]);const x=l.useCallback(()=>{!c||i||t||(m.current&&(E.current=m.current.scrollHeight),N())},[c,i,t,N]),p=l.useCallback(S=>{if(!b.current)return;S.currentTarget.scrollTop<=Pa&&x()},[x]);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:Ns(s)}),e.jsx(Ea,{direction:r,type:g,onDirectionChange:o,onTypeChange:u,disabled:t})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:m,onScroll:p,children:[c&&e.jsx("div",{className:"whatsapp-history-messages__load-more-row",children:e.jsx("button",{type:"button",className:"whatsapp-history-messages__load-more",onClick:x,disabled:i||t,children:k(i?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),d&&e.jsx("div",{className:"whatsapp-history-messages__error",children:d}),t&&n.length===0&&e.jsxs("div",{className:"whatsapp-history-messages__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:k("config:whatsappHistory.loadingMessages")})]}),!t&&!d&&n.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:k("config:whatsappHistory.emptyMessages")}),n.map(S=>e.jsx(Ca,{message:S},Ia(S)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:k("config:whatsappHistory.selectChat")})})}function Ia(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 ks(){const s=Z(),n={};return s&&(n.Authorization=`Bearer ${s}`),n}async function Ss(s,n){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`${n}: ${s.statusText}`}async function $a(s){const n=`${Y()}/api/whatsapp/chats/${encodeURIComponent(s)}`,t=await fetch(n,{headers:ks()});if(!t.ok)throw new Error(await Ss(t,"Failed to fetch WhatsApp chats"));return t.json()}async function hs(s,n,t={}){const i=new URLSearchParams;t.cursor&&i.set("cursor",t.cursor),typeof t.limit=="number"&&i.set("limit",String(t.limit)),t.direction&&i.set("direction",t.direction),t.type&&i.set("type",t.type);const d=i.toString(),c=`${Y()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(n)}/messages${d?`?${d}`:""}`,r=await fetch(c,{headers:ks()});if(!r.ok)throw new Error(await Ss(r,"Failed to fetch WhatsApp messages"));return r.json()}const Oa=50;function La({isOpen:s,onClose:n}){const{t}=X(["config"]),[i,d]=l.useState([]),[c,r]=l.useState(null),[g,o]=l.useState(null),[u,N]=l.useState([]),[k,m]=l.useState(!1),[P,b]=l.useState(null),[E,x]=l.useState(null),[p,S]=l.useState([]),[M,F]=l.useState(!1),[Q,W]=l.useState(!1),[J,U]=l.useState(null),[V,h]=l.useState(null),[$,R]=l.useState("all"),[H,ne]=l.useState("all"),[j,L]=l.useState(()=>Date.now()),z=l.useRef(0);l.useEffect(()=>{if(!s)return;const y=window.setInterval(()=>L(Date.now()),6e4);return()=>window.clearInterval(y)},[s]),l.useEffect(()=>{if(!s)return;let y=!1;return(async()=>{var te;try{o(null);const[oe,de]=await Promise.all([Xe().catch(()=>[]),xs().catch(()=>null)]);if(y)return;d(oe);const ie=(de==null?void 0:de.defaultSessionId)||((te=oe[0])==null?void 0:te.id)||null;r(he=>he??ie)}catch(oe){if(y)return;o(oe instanceof Error?oe.message:String(oe))}})(),()=>{y=!0}},[s]);const v=l.useCallback(async y=>{m(!0),b(null);try{const te=await $a(y);N(te.chats)}catch(te){b(te instanceof Error?te.message:String(te))}finally{m(!1)}},[]);l.useEffect(()=>{!s||!c||(x(null),S([]),h(null),v(c))},[s,c,v]);const O=l.useMemo(()=>{const y={limit:Oa};return $!=="all"&&(y.direction=$),H!=="all"&&(y.type=H),y},[$,H]),D=l.useCallback(async(y,te,oe)=>{const de=++z.current;F(!0),U(null),S([]),h(null);try{const ie=await hs(y,te,oe);if(de!==z.current)return;S([...ie.messages].reverse()),h(ie.nextCursor)}catch(ie){if(de!==z.current)return;U(ie instanceof Error?ie.message:String(ie))}finally{de===z.current&&F(!1)}},[]);l.useEffect(()=>{!s||!c||!E||D(c,E,O)},[s,c,E,O,D]);const se=l.useCallback(async()=>{if(!(!c||!E||!V)){W(!0),U(null);try{const y=await hs(c,E,{...O,cursor:V});S(te=>[...[...y.messages].reverse(),...te]),h(y.nextCursor)}catch(y){U(y instanceof Error?y.message:String(y))}finally{W(!1)}}},[c,E,V,O]),ae=l.useCallback(()=>{c&&v(c)},[c,v]),T=l.useCallback(y=>{y.key==="Escape"&&(y.preventDefault(),n())},[n]);return s?e.jsx($e,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:y=>y.stopPropagation(),onKeyDown:T,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:c??"",onChange:y=>r(y.target.value||null),disabled:i.length===0,children:[i.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),i.map(y=>e.jsxs("option",{value:y.id,children:[y.id,y.pairedNumber?` (${y.pairedNumber})`:""]},y.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(I,{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(Sa,{chats:u,selectedChatId:E,loading:k,error:P,onSelect:x,onRefresh:ae,now:j}),e.jsx(_a,{chatId:E,messages:p,loading:M,loadingMore:Q,error:J,hasMore:V!==null,direction:$,type:H,onDirectionChange:R,onTypeChange:ne,onLoadMore:se})]})]})})}):null}function Da({isOpen:s,onClose:n,onOpenConfig:t,onOpenNotifications:i,onOpenHistory:d}){const{t:c}=X(["config"]);if(l.useEffect(()=>{if(!s)return;const g=o=>{o.key==="Escape"&&(o.preventDefault(),n())};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[s,n]),!s)return null;const r=g=>{n(),g()};return e.jsx($e,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,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:"📱"}),c("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"whatsapp-hub-modal__intro",children:c("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:()=>r(t),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.config",{defaultValue:"Integration config"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.configDesc",{defaultValue:"Server URL, API key, sessions and pairing."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(i),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.notifications",{defaultValue:"Notifications"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.notificationsDesc",{defaultValue:"Which agent events get forwarded and to whom."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(d),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.history",{defaultValue:"History"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.historyDesc",{defaultValue:"Browse persisted chats and messages."})})]})]})]})]})]})})})}const Ye=[{kind:"question",settingKey:"toneQuestion",label:"Agent asks you something",when:"A question, a plan to approve, or a permission request. Repeats twice up front, then every 10s until you answer (stops after 2 min).",sound:"Two taps, then a rising bend",play:js},{kind:"notification",settingKey:"toneNotification",label:"Agent sends a notification",when:"Any agent notification: task complete, error, or a heads-up.",sound:"Soft two-note chime",play:bs},{kind:"completion",settingKey:"toneCompletion",label:"Agent finishes working",when:"An agent stops working and goes idle.",sound:"Gentle descending arpeggio",play:ft}],Fa=[{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:"🌙"}],Ra=[{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:"🔴"}],Ba=[{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:"👎"}],Ma=[{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:"💜"}],Ua=[{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"}],za=[{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"}],Va={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},Ka={none:"grass","pokemon-stadium":"pokemon"},Ha={"emote-yes":"yes","emote-no":"no"},qa={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function ee({checked:s,onChange:n}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:t=>n(t.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function Ce({options:s,value:n,onChange:t,iconOnly:i=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(d=>e.jsxs("button",{className:`chip ${n===d.value?"active":""}`,onClick:()=>t(d.value),title:d.label,children:[e.jsx("span",{className:"chip-icon",children:d.icon}),!i&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function C({text:s,query:n}){if(!n.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),i=n.toLowerCase(),d=t.indexOf(i);if(d===-1)return e.jsx(e.Fragment,{children:s});const c=s.slice(0,d),r=s.slice(d,d+n.length),g=s.slice(d+n.length);return e.jsxs(e.Fragment,{children:[c,e.jsx("mark",{className:"search-highlight",children:r}),g]})}const Wa=[{id:"general",title:"General",keywords:["history","hide costs","grid","fps","power saving","low power","battery","bajo consumo","performance","limit","editor","external editor","language","idioma","语言","vibration","haptic","intensity","tab title","tmux","process persistence","interactive","tui","terminal","experimental","claude","stream","streaming","word by word","live text","grok","codex","app-server","app server","opencode","serve","hover","preview","tooltip","ctrl","popup","vista previa","sound","sounds","sonido","sonidos","notification","notifications","notificacion","notificaciones","volume","volumen","tone","tones","tono","chime","alert","cue","audio","mute","silence","dock","activity","recent","notification sound","silenciar","custom sound","upload sound","alerta"]},{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:"claudeAccounts",title:"Claude Accounts",keywords:["claude","accounts","credentials","oauth","rate limit","session","david","profile","switch account","subscription"]},{id:"grokAccounts",title:"Grok Accounts",keywords:["grok","xai","x.ai","accounts","credentials","oauth","session","profile","switch account","subscription"]},{id:"codexAccounts",title:"Codex Accounts",keywords:["codex","openai","chatgpt","accounts","credentials","oauth","session","profile","switch account","subscription"]},{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"]}],Je=[{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 Ga({config:s,onChange:n,searchQuery:t="",onOpenIntegrationsModal:i,onOpenMonitoringModal:d,onOpenStatisticsModal:c,onOpenWorkflowEditor:r,onOpenTriggerManager:g}){var ns;const{t:o}=X(["config","common"]),u=at(),N=nt(),[k,m]=l.useState(()=>ot(_e.DEFAULT_AGENT_CLASS)||"scout"),P=it(),b=lt(),[E,x]=l.useState(()=>ct()),[p,S]=l.useState(null),[M,F]=l.useState(null);l.useEffect(()=>{He().then(x)},[]);const Q=async(a,A)=>{F(null),S(a);try{const B=await Ne(ye(`/api/custom-sounds/${a}`),{method:"POST",headers:{"Content-Type":A.type||"audio/mpeg"},body:A});if(!B.ok){const re=await B.json().catch(()=>({error:`Upload failed (${B.status})`}));throw new Error(re.error||`Upload failed (${B.status})`)}const le=await He();x({...le});const fe=Ye.find(re=>re.kind===a);fe&&w.updateSettings({[fe.settingKey]:Ie}),qe(Ie,u.notificationSoundVolume,a)}catch(B){F(B instanceof Error?B.message:"Upload failed")}finally{S(null)}},W=async a=>{F(null);try{await Ne(ye(`/api/custom-sounds/${a}`),{method:"DELETE"}),wt({[a]:null});const A=await He();x({...A});const B=Ye.find(le=>le.kind===a);B&&w.getSettings()[B.settingKey]===Ie&&w.updateSettings({[B.settingKey]:Nt[a]})}catch(A){F(A instanceof Error?A.message:"Failed to reset sound")}},[J,U]=l.useState(u.historyLimit),[V,h]=l.useState(()=>rt()),[$,R]=l.useState(!1),[H,ne]=l.useState(""),[j,L]=l.useState(()=>Z()),[z,v]=l.useState(!1),[O,D]=l.useState(!1),[se,ae]=l.useState(""),[T,y]=l.useState(!1),[te,oe]=l.useState(!1),[de,ie]=l.useState(!1),[he,ke]=l.useState(!1),[Ae,ue]=l.useState(!1),[Te,me]=l.useState(""),[ge,Oe]=l.useState(!1);l.useEffect(()=>{Ht().then(me).catch(()=>{})},[]),l.useEffect(()=>{Vt().then(a=>{a!==u.experimentalEchoPrompt&&w.updateSettings({experimentalEchoPrompt:a})}).catch(()=>{})},[]),l.useEffect(()=>{Wt().then(a=>{a!==u.tmuxMode&&w.updateSettings({tmuxMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{Yt().then(a=>{a!==u.interactiveMode&&w.updateSettings({interactiveMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{Xt().then(a=>{a!==u.codexAppServerMode&&w.updateSettings({codexAppServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{Qt().then(a=>{a!==u.opencodeServerMode&&w.updateSettings({opencodeServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>dt(a=>{h(a),R(!1)}),[]);const Me=Fa.map(a=>({...a,label:o(`config:time.${a.value}`)})),Se=Ra.map(a=>({...a,label:o(`config:floor.${Ka[a.value]||a.value}`)})),Le=Ba.map(a=>({...a,label:o(`config:animation.${Ha[a.value]||a.value}`)})),Ue=Ma.map(a=>({...a,label:o(`config:colorMode.${a.value}`)})),ze=Ua.map(a=>({...a,label:o(`config:terrain.${Va[a.key]}`)})),Ve=za.map(a=>({...a,label:o(`config:sky.${qa[a.value??""]}`)})),be=t.trim()?Wa.filter(a=>{const A=t.toLowerCase();return a.title.toLowerCase().includes(A)||a.keywords.some(B=>B.toLowerCase().includes(A))}).map(a=>a.id):null,_=a=>be?be.includes(a):!0,Ee=_("integrations"),pe=u.customAgentNames||[],Ke=pe.length>0?pe:ut,De=()=>{const a=se.trim();a&&!pe.includes(a)&&(w.updateSettings({customAgentNames:[...pe,a]}),ae(""))},f=a=>{w.updateSettings({customAgentNames:pe.filter(A=>A!==a)})},K=()=>{w.updateSettings({customAgentNames:[]})},ce=()=>{const a=H.trim();if(a){if(V.includes(a)){ne("");return}h([...V,a]),R(!0),ne("")}},je=a=>{h(V.filter((A,B)=>B!==a)),R(!0)},es=(a,A)=>{const B=a+A;if(B<0||B>=V.length)return;const le=V.slice();[le[a],le[B]]=[le[B],le[a]],h(le),R(!0)},Cs=()=>{yt(V),R(!1),Ge()},As=a=>{L(a),v(!0)},ss=()=>{Fe(_e.AUTH_TOKEN,j),v(!1),Ge()},Ts=a=>{me(a),Oe(!0)},ts=()=>{qt(Te).catch(()=>{}),Oe(!1)},ve=a=>{n({...s,terrain:{...s.terrain,...a}})},we=a=>{n({...s,modelStyle:{...s.modelStyle,...a}})},as=a=>{n({...s,animations:{...s.animations,...a}})},Es=a=>{U(a),w.updateSettings({historyLimit:a})},Ps=a=>{const A=s.terrain[a];typeof A=="boolean"&&ve({[a]:!A})},G=t.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[be&&be.length===0&&e.jsx("div",{className:"config-no-results",children:o("config:noResults",{query:t})}),_("general")&&e.jsxs(q,{title:o("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:G&&_("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:J,onChange:a=>Es(parseInt(a.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(C,{text:o("config:general.hideCosts"),query:t})}),e.jsx(ee,{checked:u.hideCost,onChange:a=>w.updateSettings({hideCost:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.streamTextLiveTitle"),children:e.jsx(C,{text:o("config:general.streamTextLive"),query:t})}),e.jsx(ee,{checked:u.streamTextLive!==!1,onChange:a=>w.updateSettings({streamTextLive:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.toolHoverPreviewTitle"),children:e.jsx(C,{text:o("config:general.toolHoverPreview"),query:t})}),e.jsx(ee,{checked:u.toolHoverPreview!==!1,onChange:a=>w.updateSettings({toolHoverPreview:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Where the strip of recently-active and currently-working agent thumbnails sits.",children:e.jsx(C,{text:"Agent activity dock",query:t})}),e.jsx("select",{className:"config-select",value:P,onChange:a=>mt(a.target.value),children:pt.map(a=>e.jsx("option",{value:a,children:ht[a]},a))})]}),P!=="hidden"&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"How many recently-active agents the dock shows alongside the ones working right now. 0 shows only working agents.",children:e.jsx(C,{text:"Recent agents in dock",query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:b,min:0,max:20,step:1,onChange:a=>gt(parseInt(a.target.value,10)||0)})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.grid"),query:t})}),e.jsx(ee,{checked:s.gridVisible,onChange:a=>n({...s,gridVisible:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.showFPS"),query:t})}),e.jsx(ee,{checked:u.showFPS,onChange:a=>w.updateSettings({showFPS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.fpsLimit"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:a=>n({...s,fpsLimit:parseInt(a.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(C,{text:o("config:general.powerSaving"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.powerSaving,onChange:a=>w.updateSettings({powerSaving:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Battery saver for mobile: caps scene FPS (20 active / 5 idle), freezes decorative animations and disables word-by-word streaming. Off = normal mode.",children:[e.jsx(C,{text:o("config:general.lowPowerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.lowPowerMode===!0,onChange:a=>w.updateSettings({lowPowerMode:a})})]}),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(C,{text:o("config:general.tmuxMode"),query:t})}),e.jsx(ee,{checked:u.tmuxMode,onChange:async a=>{w.updateSettings({tmuxMode:a});try{await Gt(a)}catch(A){console.error("Failed to sync tmux mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Claude agents as the real interactive `claude` TUI inside tmux, reconstructing the conversation from the session transcript (requires tmux). Takes effect on server restart.",children:[e.jsx(C,{text:o("config:general.interactiveMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.interactiveMode,onChange:async a=>{w.updateSettings({interactiveMode:a});try{await Jt(a)}catch(A){console.error("Failed to sync interactive mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Codex agents through a persistent `codex app-server` so replies stream word-by-word (token deltas) instead of appearing as one block. The app-server runs detached and survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new Codex turns; no server restart needed to toggle.",children:[e.jsx(C,{text:o("config:general.codexAppServerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.codexAppServerMode,onChange:async a=>{w.updateSettings({codexAppServerMode:a});try{await Zt(a)}catch(A){console.error("Failed to sync codex app-server mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run OpenCode agents through a persistent, detached `opencode serve` HTTP server so replies stream word-by-word (token deltas over SSE) instead of appearing as one block. The server survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new OpenCode turns; no server restart needed to toggle.",children:[e.jsx(C,{text:o("config:general.opencodeServerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.opencodeServerMode,onChange:async a=>{w.updateSettings({opencodeServerMode:a});try{await ea(a)}catch(A){console.error("Failed to sync opencode server mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.vibrationIntensity"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:u.vibrationIntensity,onChange:a=>w.updateSettings({vibrationIntensity:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:u.vibrationIntensity===0?o("config:vibrationValues.off"):u.vibrationIntensity===1?o("config:vibrationValues.ultraLight"):u.vibrationIntensity===2?o("config:vibrationValues.veryLight"):u.vibrationIntensity===3?o("config:vibrationValues.light"):u.vibrationIntensity===4?o("config:vibrationValues.medium"):o("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Play pleasant sounds: a chime for agent notifications, a distinctive rising cue when an agent asks you a question (repeats until answered), and a resolving cue when an agent finishes its work.",children:e.jsx(C,{text:"Notification sounds",query:t})}),e.jsx(ee,{checked:u.notificationSoundEnabled,onChange:a=>{w.updateSettings({notificationSoundEnabled:a}),a&&bs(u.notificationSoundVolume,u.toneNotification)}})]}),u.notificationSoundEnabled&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Notification sound volume",query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:is,step:"1",value:u.notificationSoundVolume,onChange:a=>{const A=parseInt(a.target.value);w.updateSettings({notificationSoundVolume:A}),js(A,u.toneQuestion)}}),e.jsx("span",{className:"config-value",children:u.notificationSoundVolume===0?o("config:vibrationValues.off"):`${u.notificationSoundVolume}/${is}`})]}),u.notificationSoundEnabled&&u.notificationSoundVolume>0&&e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Sounds per event",query:t})}),e.jsx("div",{className:"config-sound-hint",children:'Pick a tone for each event — or upload your own file (mp3, wav, ogg, m4a — max 5MB), which is stored on the commander so every device hears it. "None" silences that event.'}),Ye.map(a=>{var fe;const A=!!E[a.kind],B=u[a.settingKey],le=A&&B===Ie;return e.jsxs("div",{className:"config-sound-row",children:[e.jsxs("div",{className:"config-sound-info",children:[e.jsxs("div",{className:"config-sound-head",children:[e.jsx("span",{className:"config-sound-name",children:a.label}),e.jsx("span",{className:`config-sound-badge${le?" custom":""}`,children:le?"Your file":((fe=xt(B))==null?void 0:fe.label)??a.sound})]}),e.jsx("div",{className:"config-sound-when",children:a.when})]}),e.jsxs("div",{className:"config-sound-actions",children:[e.jsxs("select",{className:"config-select",value:B,onChange:re=>{const Pe=re.target.value;w.updateSettings({[a.settingKey]:Pe}),qe(Pe,u.notificationSoundVolume,a.kind)},children:[A&&e.jsx("option",{value:Ie,children:"Your uploaded file"}),bt.map(re=>e.jsx("option",{value:re.id,children:re.label},re.id))]}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void qe(B,u.notificationSoundVolume,a.kind),disabled:ls(B),title:ls(B)?"This event is silenced — pick a tone to hear it":"Hear the sound that plays for this event",children:"▶"}),e.jsxs("label",{className:"config-btn config-btn-sm config-sound-upload",title:"Replace this sound with your own audio file (mp3, wav, ogg, m4a — max 5MB)",children:[p===a.kind?"Uploading…":"Upload",e.jsx("input",{type:"file",accept:"audio/*",style:{display:"none"},onChange:re=>{var os;const Pe=(os=re.target.files)==null?void 0:os[0];re.target.value="",Pe&&Q(a.kind,Pe)}})]}),A&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void W(a.kind),title:"Delete your file and go back to a built-in tone",children:"Reset"})]})]},a.kind)}),M&&e.jsx("div",{className:"config-sound-error",children:M})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.externalEditor"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.externalEditorPlaceholder"),value:u.externalEditorCommand||"",onChange:a=>w.updateSettings({externalEditorCommand:a.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.tabTitle"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.tabTitlePlaceholder"),value:u.tabTitle||"",onChange:a=>w.updateSettings({tabTitle:a.target.value})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.language"),query:t})}),e.jsx(Ce,{options:Je,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((ns=Je.find(a=>a.value!=="auto"&&We.language.startsWith(a.value.split("-")[0])))==null?void 0:ns.value)||"en":"auto",onChange:a=>{var A;if(a==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const B=navigator.language,le=((A=Je.find(fe=>fe.value!=="auto"&&B.startsWith(fe.value.split("-")[0])))==null?void 0:A.value)||"en";We.changeLanguage(le)}else localStorage.setItem("tide-commander-language-mode","manual"),We.changeLanguage(a)}})]})]}),_("agentNames")&&e.jsx(q,{title:o("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:G&&_("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:pe.length>0?o("config:agentNames.customConfigured",{count:pe.length}):o("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:o("config:agentNames.addPlaceholder"),value:se,onChange:a=>ae(a.target.value),onKeyDown:a=>{a.key==="Enter"&&De()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:De,disabled:!se.trim(),title:o("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:Ke.map((a,A)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:a}),pe.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>f(a),title:o("common:buttons.remove"),children:"x"})]},`${a}-${A}`))}),pe.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:K,children:o("common:buttons.resetToDefaults")})]})}),_("defaultClass")&&e.jsx(q,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:G&&_("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${k==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m("random"),Fe(_e.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(jt).map(([a,A])=>e.jsx("div",{className:`agent-name-chip${k===a?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(a),Fe(_e.DEFAULT_AGENT_CLASS,a)},children:e.jsxs("span",{className:"agent-name-text",children:[A.icon," ",a.charAt(0).toUpperCase()+a.slice(1)]})},a)),N.map(a=>e.jsx("div",{className:`agent-name-chip${k===a.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(a.id),Fe(_e.DEFAULT_AGENT_CLASS,a.id)},children:e.jsxs("span",{className:"agent-name-text",children:[a.icon," ",a.name]})},a.id))]})]})}),_("appearance")&&e.jsx(q,{title:o("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:G&&_("appearance"),children:e.jsx(oa,{})}),_("connection")&&e.jsxs(q,{title:o("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:G&&_("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:V.map((a,A)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:o("config:connection.priorityLabel",{defaultValue:"Priority"}),children:A+1}),e.jsx("span",{className:"backend-url-text",title:a,children:a}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>es(A,-1),disabled:A===0,title:o("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>es(A,1),disabled:A===V.length-1,title:o("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>je(A),title:o("common:buttons.remove"),children:"x"})]},`${a}-${A}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:H,onChange:a=>ne(a.target.value),placeholder:o("config:connection.addUrlPlaceholder",{defaultValue:"http://host:port"}),onKeyDown:a=>{a.key==="Enter"&&ce()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ce,disabled:!H.trim(),title:o("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),$&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Cs,title:o("config:connection.saveAndReconnect"),children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("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(C,{text:o("config:connection.authToken"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:O?"text":"password",className:"config-input config-input-full",value:j,onChange:a=>As(a.target.value),placeholder:o("config:connection.tokenPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&z&&ss()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>D(!O),title:o(O?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(I,{name:O?"eye-closed":"eye",size:14})}),z&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:ss,title:o("config:connection.saveAndReconnect"),children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:Te,onChange:a=>Ts(a.target.value),placeholder:o("config:connection.codexBinaryPathPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&ge&&ts()}}),ge&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:ts,children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("common:buttons.reconnect"),query:t})}),e.jsx("button",{className:"config-btn",onClick:()=>Ge(),title:"Force reconnect to server",children:o("common:buttons.reconnect")})]})]}),_("scene")&&e.jsxs(q,{title:o("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:G&&_("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>n({...s,characterScale:parseFloat(a.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(C,{text:o("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:a=>n({...s,scale2d:parseFloat(a.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(C,{text:o("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:a=>n({...s,scale3d:parseFloat(a.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(C,{text:o("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:t})}),e.jsx(ee,{checked:s.show2DTaskLabels,onChange:a=>n({...s,show2DTaskLabels:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.time"),query:t})}),e.jsx(Ce,{options:Me,value:s.timeMode,onChange:a=>n({...s,timeMode:a}),iconOnly:!0})]})]}),_("terrain")&&e.jsxs(q,{title:o("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:G&&_("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:t})}),e.jsx(ee,{checked:s.terrain.simpleMode??!1,onChange:a=>ve({simpleMode:a})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:ze.map(a=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[a.key]?"active":""}`,onClick:()=>Ps(a.key),title:a.label,children:a.icon},a.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>ve({fogDensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?o("config:fogValues.off"):s.terrain.fogDensity<=1?o("config:fogValues.low"):o("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>ve({brightness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?o("config:brightnessValues.dark"):s.terrain.brightness<=1.2?o("config:brightnessValues.normal"):o("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.floor"),query:t})}),e.jsx(Ce,{options:Se,value:s.terrain.floorStyle,onChange:a=>ve({floorStyle:a}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.sky"),query:t})}),e.jsx("div",{className:"sky-color-selector",children:Ve.map(a=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===a.value?"active":""}`,onClick:()=>ve({skyColor:a.value}),title:a.label,style:{background:a.color}},a.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.battlefieldSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:a=>ve({battlefieldSize:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),_("modelStyle")&&e.jsxs(q,{title:o("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:G&&_("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>we({saturation:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?o("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?o("config:saturationValues.normal"):o("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>we({roughness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?o("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?o("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?o("config:roughnessValues.normal"):o("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>we({metalness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?o("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?o("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?o("config:metalnessValues.mixed"):o("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>we({emissiveBoost:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?o("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?o("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?o("config:glowValues.med"):o("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>we({envMapIntensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?o("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?o("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?o("config:reflectionValues.normal"):o("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.wireframe"),query:t})}),e.jsx(ee,{checked:s.modelStyle.wireframe,onChange:a=>we({wireframe:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.colorMode"),query:t})}),e.jsx(Ce,{options:Ue,value:s.modelStyle.colorMode,onChange:a=>we({colorMode:a}),iconOnly:!0})]})]}),_("animations")&&e.jsxs(q,{title:o("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:G&&_("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:animationSettings.idle"),query:t})}),e.jsx(Ce,{options:Le,value:s.animations.idleAnimation,onChange:a=>as({idleAnimation:a}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:animationSettings.working"),query:t})}),e.jsx(Ce,{options:Le,value:s.animations.workingAnimation,onChange:a=>as({workingAnimation:a}),iconOnly:!0})]})]}),_("secrets")&&e.jsx(q,{title:o("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:G&&_("secrets"),children:e.jsx(Bt,{})}),_("claudeAccounts")&&e.jsx(q,{title:o("config:sections.claudeAccounts",{defaultValue:"Claude Accounts"}),storageKey:"claudeAccounts",defaultOpen:!1,forceOpen:G&&_("claudeAccounts"),children:e.jsx(vt,{})}),_("grokAccounts")&&e.jsx(q,{title:o("config:sections.grokAccounts",{defaultValue:"Grok Accounts"}),storageKey:"grokAccounts",defaultOpen:!1,forceOpen:G&&_("grokAccounts"),children:e.jsx(cs,{provider:"grok"})}),_("codexAccounts")&&e.jsx(q,{title:o("config:sections.codexAccounts",{defaultValue:"Codex Accounts"}),storageKey:"codexAccounts",defaultOpen:!1,forceOpen:G&&_("codexAccounts"),children:e.jsx(cs,{provider:"codex"})}),_("systemPrompt")&&e.jsx(q,{title:o("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:G&&_("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>y(!0),children:o("config:systemPrompt.editPrompt")})]})}),_("data")&&e.jsx(q,{title:o("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:G&&_("data"),children:e.jsx(na,{})}),Ee&&e.jsx(q,{title:o("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:G&&Ee,children:e.jsx(ua,{onOpenModal:a=>{a==="whatsapp"?ue(!0):i==null||i(a)}})}),_("workflows")&&e.jsxs(q,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:G&&_("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{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:()=>r==null?void 0:r(),children:"Open Workflow Editor"})})]}),_("triggers")&&e.jsxs(q,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:G&&_("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{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"})})]}),_("monitoring")&&e.jsxs(q,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:G&&_("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{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:()=>d==null?void 0:d(),children:"Open Monitoring & Logs"})})]}),_("statistics")&&e.jsxs(q,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:G&&_("statistics"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{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:()=>c==null?void 0:c(),children:"Open Statistics"})})]}),_("experimental")&&e.jsxs(q,{title:o("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:G&&_("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(C,{text:o("config:experimental.2dView"),query:t})," ",e.jsx(I,{name:"map",size:12})]}),e.jsx(ee,{checked:u.experimental2DView,onChange:a=>w.updateSettings({experimental2DView:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(C,{text:o("config:experimental.voiceAssistant"),query:t})," ",e.jsx(I,{name:"microphone",size:12})]}),e.jsx(ee,{checked:u.experimentalVoiceAssistant,onChange:a=>w.updateSettings({experimentalVoiceAssistant:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(C,{text:o("config:experimental.tts"),query:t})," ",e.jsx(I,{name:"speaker-on",size:12})]}),e.jsx(ee,{checked:u.experimentalTTS,onChange:a=>w.updateSettings({experimentalTTS:a})})]}),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(C,{text:o("config:experimental.echoPrompt"),query:t})}),e.jsx(ee,{checked:u.experimentalEchoPrompt,onChange:async a=>{w.updateSettings({experimentalEchoPrompt:a});try{await Kt(a)}catch(A){console.error("Failed to sync echo prompt setting to server:",A)}}})]}),e.jsx("span",{className:"config-hint",children:o("config:experimental.hint")})]}),_("about")&&e.jsx(q,{title:o("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:G&&_("about"),children:e.jsx(ra,{})})]}),e.jsx(pa,{isOpen:T,onClose:()=>y(!1)}),e.jsx(fa,{isOpen:te,onClose:()=>oe(!1)}),e.jsx(wa,{isOpen:de,onClose:()=>ie(!1)}),e.jsx(La,{isOpen:he,onClose:()=>ke(!1)}),e.jsx(Da,{isOpen:Ae,onClose:()=>ue(!1),onOpenConfig:()=>oe(!0),onOpenNotifications:()=>ie(!0),onOpenHistory:()=>ke(!0)})]})}function Qa({onConfigChange:s,onToolChange:n,config:t,isOpen:i,onClose:d,onOpenBuildingModal:c,onOpenAreaExplorer:r,onOpenIntegrationsModal:g,onOpenMonitoringModal:o,onOpenStatisticsModal:u,onOpenWorkflowEditor:N,onOpenTriggerManager:k}){const{t:m}=X(["config","common"]),P=kt(),b=St(),E=Ct(),x=At(),p=Tt(),S=Array.from(P.values()),M=Array.from(b.values()),[F,Q]=l.useState(""),W=l.useRef(null);if(l.useEffect(()=>{const h=$=>{$.key==="Escape"&&i&&d()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[i,d]),l.useEffect(()=>{if(i&&W.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const $=setTimeout(()=>{var R;(R=W.current)==null||R.focus()},50);return()=>clearTimeout($)}},[i]),!i)return null;const J=h=>{n(p===h?null:h)},U=h=>{w.selectArea(x===h?null:h),n("select")},V=(h,$)=>{h.stopPropagation(),w.deleteArea($)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:d}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:m("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:m("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:W,type:"text",placeholder:m("config:searchPlaceholder"),value:F,onChange:h=>Q(h.target.value),className:"toolbox-search-input"}),F&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>Q(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(q,{title:m("config:areas.title",{count:S.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${p==="select"?"active":""}`,onClick:()=>J("select"),title:m("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==="rectangle"?"active":""}`,onClick:()=>J("rectangle"),title:m("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==="circle"?"active":""}`,onClick:()=>J("circle"),title:m("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:S.length===0?e.jsx("div",{className:"areas-empty",children:m("config:areas.drawToCreate")}):S.map(h=>e.jsx(Ot,{area:h,isSelected:x===h.id,onClick:()=>U(h.id),onDelete:$=>V($,h.id)},h.id))})]})}),x&&e.jsx(Rt,{area:P.get(x),onClose:()=>w.selectArea(null),onOpenFolder:r}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(q,{title:m("config:buildings.title",{count:M.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:h=>{h.stopPropagation(),c==null||c()},title:m("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:M.length===0?e.jsx("div",{className:"buildings-empty",children:m("config:buildings.clickToAdd")}):M.map(h=>e.jsx(Lt,{building:h,isSelected:E.has(h.id),onClick:()=>{w.selectBuilding(E.has(h.id)?null:h.id)},onEdit:()=>c==null?void 0:c(h.id)},h.id))})})}),E.size===1&&(()=>{const h=Array.from(E)[0],$=b.get(h);return $?e.jsx(Dt,{building:$,onClose:()=>w.selectBuilding(null),onOpenModal:()=>c==null?void 0:c(h)}):null})(),e.jsx(Ga,{config:t,onChange:s,searchQuery:F,onOpenIntegrationsModal:g,onOpenMonitoringModal:o,onOpenStatisticsModal:u,onOpenWorkflowEditor:N,onOpenTriggerManager:k})]})]})]})}export{Qa as Toolbox};
1
+ import{r as l,j as e,I,u as Z,c1 as ms,ad as gs,c2 as _s,c4 as Is,s as w,cG as $s,F as Os,cH as Ls,X as xe,K as X,aU as Y,c as Ne,d as ye,cI as Ds,cJ as Fs,cK as Rs,cL as Bs,cM as Ms,cN as Us,cO as zs,cP as fs,cQ as Vs,cR as Ks,cS as Hs,aT as qs,aq as Ws,a2 as $e,n as Gs,cT as xs,cU as Ys,cV as Ze,cW as Js,cX as Zs,cY as Xs,cZ as Qs,c_ as et,c$ as st,d0 as tt,bm as at,k as nt,m as ot,S as _e,d1 as it,d2 as lt,d3 as ct,d4 as He,d5 as rt,d6 as dt,B as ut,d7 as pt,d8 as ht,d9 as mt,da as gt,db as bs,dc as is,dd as js,de as ft,df as xt,dg as Ie,dh as bt,di as qe,dj as ls,bZ as We,w as Fe,v as jt,dk as Ge,dl as vt,dm as cs,dn as wt,dp as Nt,dq as yt,_ as kt,f as St,dr as Ct,ds as At,dt as Tt}from"./main-DN8Eh8GZ.js";import{g as Et,d as Pt,u as _t}from"./area-logos-CYEXA4lp.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-CpheMTQa.js";const vs="tide-toolbox-collapse";function It(s,n){try{const t=localStorage.getItem(`${vs}-${s}`);if(t!==null)return t==="true"}catch{}return n}function $t(s,n){try{localStorage.setItem(`${vs}-${s}`,String(n))}catch{}}function q({title:s,storageKey:n,defaultOpen:t=!1,forceOpen:i=!1,children:d,headerExtra:c}){const[r,g]=l.useState(()=>n?It(n,t):t),o=()=>{const N=!r;g(N),n&&$t(n,N)},u=i||r;return e.jsxs("div",{className:`collapsible-section ${u?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:o,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[c,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(I,{name:u?"caret-down":"caret-right",size:10})})]})]}),u&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Ot({area:s,isSelected:n,onClick:t,onDelete:i}){const{t:d}=Z(["config","common"]),c=s.assignedAgentIds.length,r=s.type==="rectangle"?d("config:areas.rect"):d("config:areas.circle");return e.jsxs("div",{className:`area-item ${n?"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:[r," ",c>0&&`• ${c} ${c>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:i,title:d("config:areas.deleteArea"),children:"×"})]})}function Lt({building:s,isSelected:n,onClick:t,onEdit:i}){var g;const{t:d}=Z(["config"]),c=((g=s.pm2Status)==null?void 0:g.ports)||[],r=(o,u)=>{o.stopPropagation(),window.open(`http://${window.location.hostname}:${u}`,"_blank")};return e.jsxs("div",{className:`building-item ${n?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:ms[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(I,{name:gs(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,c.length>0&&e.jsx("span",{className:"building-ports",children:c.map(o=>e.jsxs("a",{href:`http://${window.location.hostname}:${o}`,className:"building-port-link",onClick:u=>r(u,o),title:`Open :${o}`,children:[":",o]},o))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:o=>{o.stopPropagation(),i()},title:d("config:buildings.editBuilding"),children:e.jsx(I,{name:"gear",size:14})})]})}function Dt({building:s,onClose:n,onOpenModal:t}){var u,N,k,m,P,b,E,x;const{t:i}=Z(["config","common"]),c=_s().get(s.id)||[],r=Is[s.style||"server-rack"],g=p=>{w.sendBuildingCommand(s.id,p)},o=p=>{window.open(p,"_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(I,{name:gs(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:ms[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:n,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:i("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:i("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:r.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:i("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:i("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>g("start"),disabled:!((u=s.commands)!=null&&u.start)||s.status==="running",title:((N=s.commands)==null?void 0:N.start)||i("config:buildings.noStartCommand"),children:[e.jsx(I,{name:"play",size:12})," ",i("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>g("stop"),disabled:!((k=s.commands)!=null&&k.stop)||s.status==="stopped",title:((m=s.commands)==null?void 0:m.stop)||i("config:buildings.noStopCommand"),children:[e.jsx(I,{name:"stop",size:12,weight:"fill"})," ",i("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>g("restart"),disabled:!((P=s.commands)!=null&&P.restart),title:((b=s.commands)==null?void 0:b.restart)||i("config:buildings.noRestartCommand"),children:[e.jsx(I,{name:"refresh",size:12})," ",i("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>g("healthCheck"),disabled:!((E=s.commands)!=null&&E.healthCheck),title:((x=s.commands)==null?void 0:x.healthCheck)||i("config:buildings.noHealthCheck"),children:[e.jsx(I,{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:i("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((p,S)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>o(p.url),title:p.url,children:[e.jsx(I,{name:"link",size:12})," ",p.label||p.url]},S))})]}),c.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[i("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>w.clearBuildingLogs(s.id),title:i("common:buttons.clear"),children:i("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:c.slice(-5).map((p,S)=>e.jsx("div",{className:"building-editor-log-entry",children:p},S))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(I,{name:"gear",size:12})," ",i("config:buildings.fullSettings")]})})]})}const Ft=[{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 Rt({area:s,onClose:n,onOpenFolder:t}){var ne;const{t:i}=Z(["config","common"]),[d,c]=l.useState(s.name),[r,g]=l.useState(s.prompt||""),[o,u]=l.useState(!1),[N,k]=l.useState(""),[m,P]=l.useState(!1),b=l.useRef(null);l.useEffect(()=>{c(s.name)},[s.id,s.name]),l.useEffect(()=>{g(s.prompt||"")},[s.id,s.prompt]);const E=j=>{const L=j.target.value;c(L),w.updateArea(s.id,{name:L})},x=j=>{w.updateArea(s.id,{color:j})},p=j=>{const L=j.target.value;g(L),w.updateArea(s.id,{prompt:L})},S=()=>{N.trim()&&(w.addDirectoryToArea(s.id,N.trim()),k(""),u(!1))},M=(j,L)=>{L.stopPropagation(),w.removeDirectoryFromArea(s.id,j)},F=()=>{w.bringAreaToFront(s.id)},Q=()=>{w.sendAreaToBack(s.id)},W=l.useCallback(()=>{let j=2,L=2;s.type==="rectangle"&&s.width&&s.height?(j=s.width,L=s.height):s.type==="circle"&&s.radius&&(j=s.radius*1.414,L=s.radius*1.414);const z=Math.min(j,L)*.4;return{width:Math.round(z*10)/10,height:Math.round(z*10)/10}},[s.type,s.width,s.height,s.radius]),J=async j=>{var z;const L=(z=j.target.files)==null?void 0:z[0];if(L){P(!0);try{const v=await _t(s.id,L),O=W();w.updateArea(s.id,{logo:{filename:v.filename,position:"center",width:O.width,height:O.height,keepAspectRatio:!0,opacity:.8}})}catch(v){console.error("Failed to upload logo:",v)}finally{P(!1),b.current&&(b.current.value="")}}},U=async()=>{try{await Pt(s.id),w.updateArea(s.id,{logo:void 0})}catch(j){console.error("Failed to remove logo:",j)}},V=j=>{s.logo&&w.updateArea(s.id,{logo:{...s.logo,position:j}})},h=j=>{if(!s.logo)return;const L=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const z=s.logo.height/s.logo.width;w.updateArea(s.id,{logo:{...s.logo,width:L,height:Math.round(L*z*10)/10}})}else w.updateArea(s.id,{logo:{...s.logo,width:L}})},$=j=>{if(!s.logo)return;const L=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const z=s.logo.width/s.logo.height;w.updateArea(s.id,{logo:{...s.logo,height:L,width:Math.round(L*z*10)/10}})}else w.updateArea(s.id,{logo:{...s.logo,height:L}})},R=()=>{s.logo&&w.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},H=j=>{s.logo&&w.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(j.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:i("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:n,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange:E,placeholder:i("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:$s.map(j=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===j?"selected":""}`,style:{backgroundColor:j},onClick:()=>x(j),"aria-label":`Set area color ${j}`,"aria-pressed":s.color===j,title:j},j))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:F,title:i("config:areas.bringToFront"),children:[e.jsx(I,{name:"arrow-up",size:12})," ",i("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:Q,title:i("config:areas.sendToBack"),children:[e.jsx(I,{name:"arrow-down",size:12})," ",i("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:i("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(ne=s.logo)!=null&&ne.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Et(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:U,children:i("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var j;return(j=b.current)==null?void 0:j.click()},disabled:m,children:m?"...":e.jsx(I,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:Ft.map(({key:j,labelKey:L})=>{var z;return e.jsx("button",{className:`area-logo-pos-btn ${((z=s.logo)==null?void 0:z.position)===j?"active":""}`,onClick:()=>V(j),children:i(`config:areas.${L}`)},j)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("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:i("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:h,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:i("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:$,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:i("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:R}),i("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("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:H,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 j;return(j=b.current)==null?void 0:j.click()},disabled:m,children:m?"...":i("config:areas.uploadLogo")}),e.jsx("input",{ref:b,type:"file",accept:"image/*",style:{display:"none"},onChange:J})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:i("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(j=>e.jsxs("div",{className:"area-folder-item",title:j,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:i("config:areas.openFolder"),children:e.jsx(I,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:j.split("/").pop()||j}),e.jsx("button",{className:"area-folder-remove",onClick:L=>M(j,L),title:i("config:areas.removeFolder"),children:"×"})]},j)),o?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(Os,{value:N,onChange:k,onSubmit:S,placeholder:i("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:S,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>u(!0),children:i("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:i("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:r,onChange:p,placeholder:i("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:i("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:i("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:i("config:areas.rightClickUnassign")})]})]})}function Bt(){const{t:s}=Z(["config","common"]),n=Ls(),[t,i]=l.useState(!1),[d,c]=l.useState(null),[r,g]=l.useState({name:"",key:"",value:"",description:""}),[o,u]=l.useState(null),N=()=>{i(!0),c(null),g({name:"",key:"",value:"",description:""})},k=p=>{c(p.id),i(!1),g({name:p.name,key:p.key,value:p.value,description:p.description||""})},m=()=>{i(!1),c(null),g({name:"",key:"",value:"",description:""})},P=()=>{!r.name.trim()||!r.key.trim()||(d?w.updateSecret(d,{name:r.name.trim(),key:r.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:r.value,description:r.description.trim()||void 0}):w.createSecret({name:r.name.trim(),key:r.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:r.value,description:r.description.trim()||void 0}),m())},b=p=>{u(p)},E=()=>{o&&(w.deleteSecret(o),d===o&&m())},x=p=>{navigator.clipboard.writeText(`{{${p}}}`)};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:n.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):n.map(p=>e.jsxs("div",{className:`secret-item ${d===p.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:p.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>x(p.key),title:s("config:secrets.copyPlaceholder"),children:`{{${p.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>k(p),title:s("common:buttons.edit"),children:e.jsx(I,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>b(p.id),title:s("common:buttons.delete"),children:"×"})]})]}),p.description&&e.jsx("div",{className:"secret-item-description",children:p.description})]},p.id))}),(t||d)&&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:r.name,onChange:p=>g({...r,name:p.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:r.key,onChange:p=>g({...r,key:p.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${r.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:r.value,onChange:p=>g({...r,value:p.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:r.description,onChange:p=>g({...r,description:p.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:m,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:P,disabled:!r.name.trim()||!r.key.trim(),children:s(d?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:N,children:s("config:secrets.addSecret")}),e.jsx(xe,{isOpen:o!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:E,onClose:()=>u(null)})]})}async function Mt(){const s=X(),n=await fetch(`${Y()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch system prompt: ${n.statusText}`);return(await n.json()).prompt||""}async function Ut(s){const n=X(),t=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function zt(){const s=X(),n=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to clear system prompt: ${n.statusText}`)}async function Vt(){const s=X(),n=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch echo prompt setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Kt(s){const n=X(),t=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function Ht(){const s=X(),n=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex binary path: ${n.statusText}`);return(await n.json()).path||""}async function qt(s){const n=X(),t=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function Wt(){const s=X(),n=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch tmux mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Gt(s){const n=X(),t=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function Yt(){const s=X(),n=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch interactive mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Jt(s){const n=X(),t=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function Zt(){const s=X(),n=await fetch(`${Y()}/api/agents/system-settings/codex-app-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex app-server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Xt(s){const n=X(),t=await fetch(`${Y()}/api/agents/system-settings/codex-app-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update codex app-server mode setting: ${t.statusText}`)}async function Qt(){const s=X(),n=await fetch(`${Y()}/api/agents/system-settings/opencode-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch opencode server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ea(s){const n=X(),t=await fetch(`${Y()}/api/agents/system-settings/opencode-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update opencode server mode setting: ${t.statusText}`)}async function sa(){const s=X(),n=await fetch(`${Y()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch backup status: ${n.statusText}`);return n.json()}async function ta(s){const n=X(),t=await fetch(`${Y()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok){const i=await t.json().catch(()=>({}));throw new Error(i.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function aa({checked:s,onChange:n,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:i=>n(i.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function na(){const{t:s}=Z(["config","common"]),[n,t]=l.useState([]),[i,d]=l.useState(new Set),[c,r]=l.useState(new Set),[g,o]=l.useState(!1),[u,N]=l.useState(!1),[k,m]=l.useState(null),[P,b]=l.useState(null),[E,x]=l.useState(null),[p,S]=l.useState(null),[M,F]=l.useState(!1),[Q,W]=l.useState(null);l.useEffect(()=>{Ne(ye("/api/config/categories")).then(v=>v.json()).then(v=>{const O=Array.isArray(v)?v:[];t(O),d(new Set(O.map(D=>D.id)))}).catch(v=>console.error("Failed to fetch config categories:",v))},[]),l.useEffect(()=>{sa().then(S).catch(v=>{console.error("Failed to fetch backup status:",v),W(v.message||"Failed to fetch backup status")})},[]);const J=async v=>{if(!M){F(!0),W(null);try{const O=await ta(v);S(O)}catch(O){W(O.message||"Failed to update backup setting")}finally{F(!1)}}},U=v=>{d(O=>{const D=new Set(O);return D.has(v)?D.delete(v):D.add(v),D})},V=v=>{r(O=>{const D=new Set(O);return D.has(v)?D.delete(v):D.add(v),D})},h=()=>d(new Set(n.map(v=>v.id))),$=()=>d(new Set),R=()=>{P&&r(new Set(P.categories.map(v=>v.id)))},H=()=>r(new Set),ne=async()=>{var v;if(i.size!==0){o(!0),x(null);try{const O=Array.from(i).join(","),D=await Ne(ye(`/api/config/export?categories=${O}`));if(!D.ok)throw new Error("Export failed");const se=await D.blob(),ae=window.URL.createObjectURL(se),T=document.createElement("a");T.href=ae;const y=D.headers.get("Content-Disposition"),te=((v=y==null?void 0:y.match(/filename="(.+)"/))==null?void 0:v[1])||"tide-commander-config.zip";T.download=te,document.body.appendChild(T),T.click(),document.body.removeChild(T),window.URL.revokeObjectURL(ae),x({type:"success",text:s("config:data.exportSuccess")})}catch(O){x({type:"error",text:O.message||"Export failed"})}finally{o(!1)}}},j=async v=>{var D;const O=(D=v.target.files)==null?void 0:D[0];if(O){m(O),x(null),b(null),r(new Set);try{const se=await Ne(ye("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await O.arrayBuffer()});if(!se.ok){const y=await se.json();throw new Error(y.error||"Failed to preview config file")}const ae=await se.json(),T=Array.isArray(ae.categories)?ae.categories:[];b({...ae,categories:T}),r(new Set(T.map(y=>y.id)))}catch(se){x({type:"error",text:se.message||"Failed to read config file"}),m(null)}}},L=async()=>{if(!(!k||c.size===0)){N(!0),x(null);try{const v=Array.from(c).join(","),O=await Ne(ye(`/api/config/import?categories=${v}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await k.arrayBuffer()}),D=await O.json();if(!O.ok)throw new Error(D.error||"Import failed");x({type:"success",text:D.message||s("config:data.importSuccess")}),m(null),b(null),r(new Set)}catch(v){x({type:"error",text:v.message||"Import failed"})}finally{N(!1)}}},z=()=>{m(null),b(null),r(new Set),x(null)};return e.jsxs("div",{className:"data-section",children:[E&&e.jsx("div",{className:`data-message data-message-${E.type}`,children:E.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(aa,{checked:!!(p!=null&&p.enabled),disabled:M||!p,onChange:J})]}),e.jsxs("div",{className:"data-backup-info",children:[p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:p.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!p.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:p.scriptPath})]}),p.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(p.lastRunAt).toLocaleString(),p.lastRunOk===!0&&" — ok",p.lastRunOk===!1&&p.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",p.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),Q&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:Q})]})]}),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:h,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:$,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:n.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:i.has(v.id),onChange:()=>U(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name})]},v.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ne,disabled:g||i.size===0,children:g?s("config:data.exporting"):s("config:data.exportCount",{count:i.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")})}),k?P?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:k.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:R,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:H,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:P.categories.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:c.has(v.id),onChange:()=>V(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name}),v.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",v.fileCount," ",s("config:data.files"),")"]})]},v.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:z,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:L,disabled:u||c.size===0,children:u?s("config:data.importing"):s("config:data.importCount",{count:c.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:j,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function oa(){const[s,n]=l.useState(()=>Ds()),t=i=>{n(i);const d=Ms(i);Us(d)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:Fs.map(i=>e.jsxs("button",{className:`theme-option ${s===i.id?"active":""}`,onClick:()=>t(i.id),title:i.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:i.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:i.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:i.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:i.name})]},i.id))})})}function ia(){const{t:s}=Z(["config"]),{installInfo:n,phase:t,output:i,error:d,newVersion:c,autoRestart:r,refreshInstallInfo:g,runUpdate:o,reset:u}=zs(),[N,k]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{g()},[g]),l.useEffect(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)},[i]);const P=l.useCallback(()=>{k(!0)},[]),b=l.useCallback(()=>{k(!1)},[]),E=l.useCallback(()=>{k(!1),o()},[o]),x=l.useCallback(()=>{u(),k(!1),g()},[u,g]),p=fs.isNativePlatform(),S=s(p?"config:about.autoUpdateServerTitle":"config:about.autoUpdateTitle");return n?n.isGlobalInstall?n.autoUpdateSupported?!n.updateAvailable&&t==="idle"?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:S}),t==="idle"&&!N&&n.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:n.currentVersion}),e.jsx("span",{className:"about-autoupdate-arrow",children:"→"}),e.jsx("span",{className:"about-autoupdate-latest",children:n.latestVersion})]}),e.jsx("button",{className:"about-update-btn download",onClick:P,children:s("config:about.autoUpdateButton")})]}),t==="idle"&&N&&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:b,children:s("config:about.autoUpdateCancel")}),e.jsx("button",{className:"about-update-btn download",onClick:E,children:s("config:about.autoUpdateConfirm")})]})]}),(t==="running"||t==="success"||t==="failed")&&e.jsxs("div",{className:"about-autoupdate-stream",children:[e.jsxs("div",{className:"about-autoupdate-stream-title",children:[t==="running"&&s("config:about.autoUpdateRunning"),t==="success"&&s("config:about.autoUpdateSuccess"),t==="failed"&&s("config:about.autoUpdateFailed")]}),e.jsx("pre",{ref:m,className:"about-autoupdate-output",children:i||"..."}),t==="success"&&e.jsxs("div",{className:"about-autoupdate-success-hint",children:[c&&e.jsxs("div",{className:"about-autoupdate-newversion",children:["v",c]}),e.jsx("div",{children:s(r?"config:about.autoUpdateReconnectHint":"config:about.autoUpdateRestartHint")})]}),t==="failed"&&d&&e.jsx("div",{className:"about-update-error",children:d}),(t==="success"||t==="failed")&&e.jsx("div",{className:"about-autoupdate-stream-actions",children:e.jsx("button",{className:"about-update-btn changelog",onClick:x,children:s("config:about.autoUpdateClose")})})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:S}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdatePackageManagerNotice",{pm:n.packageManager})}),n.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:n.suggestedManualCommand})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:S}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdateDevMode")})]}):null}function la(){const{t:s}=Z(["config"]),[n,t]=l.useState(null),[i,d]=l.useState(!1),[c,r]=l.useState(null);l.useEffect(()=>{Vs().then(t).catch(N=>r(N.message))},[]);const g=l.useCallback(async N=>{if(!i){d(!0),r(null);try{t(await Ks(N))}catch(k){r(k.message)}finally{d(!1)}}},[i]),o=fs.isNativePlatform(),u=s(o?"config:about.unattendedServerTitle":"config:about.unattendedTitle");return!n&&!c?null:n?o&&!n.supported?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:u}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:about.unattendedDesc")}),e.jsxs("label",{className:"config-toggle",style:n.supported?void 0:{opacity:.5},children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:n.enabled,disabled:i||!n.supported,onChange:N=>void g(N.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),!n.supported&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedUnsupported")}),n.supported&&n.enabled&&n.pendingRestartVersion&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedPendingRestart",{version:n.pendingRestartVersion})}),n.supported&&n.enabled&&!n.pendingRestartVersion&&n.lastResult&&e.jsx("div",{className:"about-autoupdate-devnote",children:n.lastResult}),c&&e.jsx("div",{className:"about-update-error",children:c})]}):o?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:u}),e.jsx("div",{className:"about-update-error",children:c})]})}function ca(){var M;const{t:s}=Z(["config"]),{isAndroid:n,supported:t,otaActive:i,bundleState:d,serverInfo:c,infoError:r,updateAvailable:g,phase:o,progress:u,error:N,autoSync:k,checkNow:m,syncNow:P,resetToBundled:b,setAutoSync:E}=Hs(),[x,p]=l.useState(null),S=l.useRef(m);return S.current=m,l.useEffect(()=>{n&&(S.current(!1),qs.getInfo().then(F=>p(F.version)).catch(()=>{}))},[n]),!n||t===!1?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:webBundle.title")}),e.jsxs("div",{className:"about-autoupdate-devnote",children:[i?s("config:webBundle.sourceOta",{hash:((M=d==null?void 0:d.hash)==null?void 0:M.slice(0,8))??"?"}):s("config:webBundle.sourceBundled"),x&&` · ${s("config:webBundle.apkVersion",{version:x})}`]}),c?e.jsxs("div",{className:"about-autoupdate-devnote",children:[s("config:webBundle.serverBundle",{version:c.version,hash:c.hash.slice(0,8)})," — ",s(g?"config:webBundle.updateAvailable":"config:webBundle.upToDate")]}):r&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:webBundle.serverUnavailable")}),N&&e.jsx("div",{className:"about-update-error",children:N}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:webBundle.autoSync")}),e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:k,onChange:F=>E(F.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn download",onClick:()=>void P(),disabled:o!=="idle"||!c,children:o==="syncing"?s("config:webBundle.syncingPct",{percent:u??0}):s("config:webBundle.syncNow")}),i&&e.jsx("button",{className:"about-update-btn changelog",onClick:()=>void b(),children:s("config:webBundle.reset")})]})]})}function ra(){const{t:s}=Z(["config"]),{updateAvailable:n,updateInfo:t,recentReleases:i,isChecking:d,error:c,currentVersion:r,isAndroid:g,downloadPhase:o,downloadProgress:u,checkForUpdate:N,downloadAndInstall:k,openReleasePage:m}=Rs(),[P,b]=l.useState(!1),E=p=>p?`${(p/(1024*1024)).toFixed(1)} MB`:"",x=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(I,{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:r}),n&&t?e.jsx("span",{className:"about-version-update-badge",onClick:m,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(ia,{}),e.jsx(la,{}),e.jsx(ca,{}),e.jsx("div",{className:"about-changelog-row",children:e.jsx("button",{className:"about-update-btn changelog",onClick:()=>b(!0),children:s("config:about.changelog")})}),e.jsxs("div",{className:"about-update",children:[n&&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"),": ",E(t.apkSize)]}),c&&e.jsx("div",{className:"about-update-error",children:c}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:m,children:s("config:about.changelog")}),g&&t.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:()=>void k(),disabled:o!=="idle",children:o==="downloading"?s("config:appUpdateBanner.downloadingPct",{percent:u??0}):s(o==="installing"?"config:appUpdateBanner.installHint":"config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:m,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(d?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>N(!0),disabled:d,children:d?"...":s("config:about.check")})]}),i.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:i.map(p=>e.jsxs("a",{href:p.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${p.version===`v${r}`||p.version===r?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:p.version}),e.jsx("span",{className:"about-release-date",children:x(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(I,{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")})]})]}),P&&e.jsx(Bs,{onClose:()=>b(!1)})]})}const da={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function ua({onOpenModal:s}){const[n,t]=l.useState([]),[i,d]=l.useState(!0),c=l.useCallback(async()=>{try{const r=await Ne(ye("/api/integrations"));if(!r.ok)return;const g=await r.json();t(g)}catch{}finally{d(!1)}},[]);return l.useEffect(()=>{c()},[c]),i?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):n.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:[n.map(r=>{const g=da[r.id]||"🔌",o=!!r.status.error,u=r.status.connected,N=o?"#f38ba8":u?"#a6e3a1":"#fab387",k=o?"Error":u?"Connected":"Setup Required",m=o?"✗":u?"✓":"⚠";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:r.name}),e.jsx("span",{style:{color:N,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:k,children:m}),e.jsx("button",{onClick:()=>s(r.id),title:`Configure ${r.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:"⚙️"})]},r.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:r=>{r.target.style.borderColor="var(--accent, #89b4fa)",r.target.style.color="var(--accent, #89b4fa)"},onMouseLeave:r=>{r.target.style.borderColor="var(--border, #313244)",r.target.style.color="var(--text-secondary, #a6adc8)"},children:"Manage All Integrations"})]})}const Re="__global__";function pa({isOpen:s,onClose:n,initialAgentId:t}){const{t:i}=Z(["config"]),d=Ws(),[c,r]=l.useState(""),[g,o]=l.useState(""),[u,N]=l.useState(!1),[k,m]=l.useState(""),[P,b]=l.useState(""),[E,x]=l.useState(null),[p,S]=l.useState(null),[M,F]=l.useState(!1),[Q,W]=l.useState(!1),[J,U]=l.useState(!1),[V,h]=l.useState(null),$=l.useMemo(()=>[...d].sort((T,y)=>T.name.localeCompare(y.name)),[d]),R=l.useMemo(()=>d.find(T=>T.id===c),[d,c]),H=c===Re;l.useEffect(()=>{if(!s)return;const T=t&&d.some(y=>y.id===t)?t:Re;r(T),N(!1),Mt().then(y=>o(y)).catch(()=>o("")).finally(()=>N(!0))},[s]),l.useEffect(()=>{const T=c===Re?g:(R==null?void 0:R.customPrompt)??"";m(T),b(T),F(!1),x(null),S(null)},[c,u]);const ne=T=>{const y=T.target.value;m(y),F(y!==P),x(null),S(null)},j=async()=>{if(c)try{x(null),S(null),H?(await Ut(k),o(k),S(i("config:systemPrompt.savedGlobal"))):(w.updateAgentProperties(c,{customPrompt:k}),S(i("config:systemPrompt.saved"))),b(k),F(!1)}catch(T){x(T instanceof Error?T.message:"Failed to save system prompt")}},L=()=>{W(!0)},z=async()=>{if(c)try{x(null),S(null),H?(await zt(),o(""),S(i("config:systemPrompt.clearedGlobal"))):(w.updateAgentProperties(c,{customPrompt:""}),S(i("config:systemPrompt.cleared"))),m(""),b(""),F(!1)}catch(T){x(T instanceof Error?T.message:"Failed to clear system prompt")}},v=()=>{m(P),F(!1),x(null),S(null)},O=T=>{if(T!==c){if(M){h(T),U(!0);return}r(T)}},D=()=>{if(M){h(null),U(!0);return}n()},se=()=>{if(U(!1),V){const T=V;h(null),r(T)}else n()},ae=T=>{T.key==="Escape"&&(T.preventDefault(),D())};return s?e.jsxs($e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:D,children:e.jsxs("div",{className:"system-prompt-modal",onClick:T=>T.stopPropagation(),onKeyDown:ae,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:i("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:D,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"modal-description",children:i("config:systemPrompt.description")}),e.jsxs("div",{className:"agent-picker",children:[e.jsx("label",{htmlFor:"system-prompt-agent",className:"editor-label",children:i("config:systemPrompt.agentLabel")}),e.jsxs("div",{className:"agent-picker-row",children:[H?e.jsx(I,{name:"globe",size:20,className:"agent-picker-icon"}):R&&e.jsx(Gs,{classId:R.class,size:20,className:"agent-picker-icon"}),e.jsxs("select",{id:"system-prompt-agent",className:"agent-picker-select",value:c,onChange:T=>O(T.target.value),children:[e.jsxs("option",{value:Re,children:[i("config:systemPrompt.globalOption"),g?" • ✦":""]}),$.map(T=>e.jsxs("option",{value:T.id,children:[T.name,T.customPrompt?" • ✦":""]},T.id))]})]})]}),E&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),E]}),p&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),p]}),e.jsxs("div",{className:"editor-wrapper",children:[e.jsxs("div",{className:"editor-header",children:[e.jsx("label",{htmlFor:"prompt-input",className:"editor-label",children:i("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[k.length," ",i("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:k,onChange:ne,placeholder:i("config:systemPrompt.placeholder"),rows:18,disabled:H&&!u,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:i(H?"config:systemPrompt.hintGlobal":"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:L,disabled:!k||!c,children:i("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:D,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:v,disabled:!M,children:i("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:j,disabled:!M||!c,children:i("config:systemPrompt.save")})]})]})]})}),e.jsx(xe,{isOpen:Q,title:i("config:systemPrompt.clear"),message:i(H?"config:systemPrompt.confirmClearGlobal":"config:systemPrompt.confirmClear"),confirmLabel:i("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{z()},onClose:()=>W(!1)}),e.jsx(xe,{isOpen:J,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:se,onClose:()=>{U(!1),h(null)}})]}):null}const rs={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},ha=2500,ma=12e4;function ds(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function ga(s,n){return s.enabled===n.enabled&&s.baseUrl===n.baseUrl&&s.defaultSessionId===n.defaultSessionId&&s.webhookVerifyToken===n.webhookVerifyToken&&s.showIncomingToasts===n.showIncomingToasts}function fa({isOpen:s,onClose:n}){const{t}=Z(["config"]),[i,d]=l.useState(rs),[c,r]=l.useState(rs),[g,o]=l.useState(!1),[u,N]=l.useState([]),[k,m]=l.useState(!0),[P,b]=l.useState(null),[E,x]=l.useState(null),[p,S]=l.useState(""),[M,F]=l.useState(!1),[Q,W]=l.useState(""),[J,U]=l.useState(null),[V,h]=l.useState(null),[$,R]=l.useState(null),H=l.useRef(null),ne=l.useRef(0),[j,L]=l.useState(""),[z,v]=l.useState(""),[O,D]=l.useState(null),[se,ae]=l.useState(!1),[T,y]=l.useState(!1),[te,oe]=l.useState(!1),[de,ie]=l.useState(!1),[he,ke]=l.useState(null),Ae=!ga(i,c),ue=l.useCallback(()=>{H.current&&(clearTimeout(H.current),H.current=null)},[]),Te=l.useCallback(async()=>{try{m(!0),b(null),x(null);const[f,K]=await Promise.all([xs(),Ys()]),ce=ds(f);if(d(ce),r(ce),o(!!K.configured),K.configured)try{const je=await Ze();N(Array.isArray(je)?je:[])}catch{N([])}else N([])}catch(f){b(f instanceof Error?f.message:t("config:whatsapp.errors.loadFailed"))}finally{m(!1)}},[t]),me=l.useCallback(async()=>{try{const f=await Ze();N(Array.isArray(f)?f:[])}catch{}},[]);l.useEffect(()=>(s?Te():(ue(),U(null),h(null),R(null),S(""),F(!1),D(null)),()=>{ue()}),[s,Te,ue]);const ge=(f,K)=>{d(ce=>({...ce,[f]:K})),b(null),x(null)},Oe=async()=>{try{b(null),x(null);const f=await et({enabled:i.enabled,baseUrl:i.baseUrl.trim(),defaultSessionId:i.defaultSessionId.trim(),webhookVerifyToken:i.webhookVerifyToken,showIncomingToasts:i.showIncomingToasts});window.dispatchEvent(new CustomEvent("tide:whatsapp-config-updated"));const K=ds(f);d(K),r(K),x(t("config:whatsapp.saved"))}catch(f){b(f instanceof Error?f.message:t("config:whatsapp.errors.saveFailed"))}},Me=()=>{d(c),b(null),x(null)},Se=()=>{if(Ae){y(!0);return}n()},Le=f=>{f.key==="Escape"&&(f.preventDefault(),Se())},Ue=async()=>{const f=p.trim();if(f)try{b(null),x(null),await Zs(f),S(""),F(!1),o(!0),x(t("config:whatsapp.apiKeySaved"))}catch(K){b(K instanceof Error?K.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},ze=()=>{oe(!0)},Ve=async()=>{try{b(null),x(null),await st(),o(!1),x(t("config:whatsapp.apiKeyCleared"))}catch(f){b(f instanceof Error?f.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},be=l.useCallback(async f=>{if(Date.now()>ne.current){R(t("config:whatsapp.pairingTimeout")),U(null),h(null),ue(),me();return}try{const K=await Js(f);if(K.status&&["connected","paired","open","ready"].includes(K.status.toLowerCase())){R(t("config:whatsapp.pairingSuccess")),U(null),h(null),ue(),me();return}const je=K.qrUrl??K.qr??null;je&&h(je)}catch(K){R(K instanceof Error?K.message:t("config:whatsapp.errors.qrFetchFailed"))}H.current=setTimeout(()=>{be(f)},ha)},[me,ue,t]),_=async()=>{const f=Q.trim();if(f)try{b(null),x(null),R(null),h(null),ue(),await Xs(f),W(""),U(f),ne.current=Date.now()+ma,be(f),me()}catch(K){b(K instanceof Error?K.message:t("config:whatsapp.errors.sessionCreateFailed"))}},Ee=()=>{ue(),U(null),h(null),R(null)},pe=f=>{ke(f),ie(!0)},Ke=async()=>{if(he)try{b(null),x(null),await tt(he),J===he&&Ee(),me(),x(t("config:whatsapp.sessionDeleted"))}catch(f){b(f instanceof Error?f.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{ke(null)}},De=async()=>{const f=j.trim(),K=z.trim();if(!(!f||!K))try{ae(!0),D(null);const ce=i.defaultSessionId.trim()||void 0;await Qs(f,K,ce),D({kind:"success",text:t("config:whatsapp.testSent")})}catch(ce){D({kind:"error",text:ce instanceof Error?ce.message:t("config:whatsapp.errors.testSendFailed")})}finally{ae(!1)}};return s?e.jsxs($e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:Se,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:Se,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:k?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(I,{name:"warn",size:14})}),P]}),E&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),E]}),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:i.enabled,onChange:f=>ge("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:i.showIncomingToasts,onChange:f=>ge("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:i.baseUrl,onChange:f=>ge("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:i.defaultSessionId,onChange:f=>ge("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:i.webhookVerifyToken,onChange:f=>ge("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(I,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(I,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:M?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:p,onChange:f=>S(f.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>F(f=>!f),title:t(M?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(I,{name:M?"eye-closed":"eye",size:14})}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ue,disabled:!p.trim(),children:t("config:whatsapp.saveKey")}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:ze,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(u)||u.length===0?e.jsx("div",{className:"wa-empty",children:t("config:whatsapp.noSessions")}):u.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:()=>pe(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:Q,onChange:f=>W(f.target.value),onKeyDown:f=>{f.key==="Enter"&&_()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:_,disabled:!Q.trim()||J!==null,children:t("config:whatsapp.addSession")})]}),J&&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:J})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Ee,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")})]})]}),$&&!J&&e.jsx("div",{className:"wa-pairing-message",children:$})]}),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:j,onChange:f=>L(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:z,onChange:f=>v(f.target.value)})]}),e.jsx("div",{className:"wa-field-inline wa-field-end",children:e.jsx("button",{type:"button",className:"btn btn-primary",onClick:De,disabled:!j.trim()||!z.trim()||se,children:t(se?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),O&&e.jsxs("div",{className:`alert ${O.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:O.kind==="success"?"check":"warn",size:14})}),O.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:Se,children:t("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:Me,disabled:!Ae||k,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:Oe,disabled:!Ae||k,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(xe,{isOpen:T,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{y(!1),n()},onClose:()=>y(!1)}),e.jsx(xe,{isOpen:te,title:t("config:whatsapp.clearKey"),message:t("config:whatsapp.confirmClearKey"),confirmLabel:t("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Ve()},onClose:()=>oe(!1)}),e.jsx(xe,{isOpen:de,title:t("config:whatsapp.deleteSession"),message:t("config:whatsapp.confirmDeleteSession",{id:he??""}),confirmLabel:t("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Ke()},onClose:()=>{ie(!1),ke(null)}})]}):null}const ws=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function Xe(s=!1){const n=X(),t={};return n&&(t.Authorization=`Bearer ${n}`),s&&(t["Content-Type"]="application/json"),t}async function Qe(s,n){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`${n}: ${s.statusText}`}async function xa(){const s=await fetch(`${Y()}/api/whatsapp/notification-config`,{headers:Xe()});if(!s.ok)throw new Error(await Qe(s,"Failed to fetch WhatsApp notification config"));return s.json()}async function ba(s){const n=await fetch(`${Y()}/api/whatsapp/notification-config`,{method:"PATCH",headers:Xe(!0),body:JSON.stringify(s)});if(!n.ok)throw new Error(await Qe(n,"Failed to update WhatsApp notification config"));return n.json()}async function ja(){const s=await fetch(`${Y()}/api/whatsapp/notification-config`,{method:"DELETE",headers:Xe()});if(!s.ok)throw new Error(await Qe(s,"Failed to reset WhatsApp notification config"));return s.json()}const Be={messages:!0,statusChanges:!0,taskComplete:!0,errors:!0,planReady:!0,agentSpawned:!0,agentStopped:!0},us={filter:{...Be},recipient:""};function va(s,n){if(s.recipient!==n.recipient)return!1;for(const t of ws)if(s.filter[t]!==n.filter[t])return!1;return!0}function wa({isOpen:s,onClose:n}){const{t}=Z(["config"]),[i,d]=l.useState(us),[c,r]=l.useState(us),[g,o]=l.useState(!0),[u,N]=l.useState(null),[k,m]=l.useState(null),[P,b]=l.useState(!1),[E,x]=l.useState(!1),p=!va(i,c),S=l.useCallback(async()=>{try{o(!0),N(null),m(null);const h=await xa(),$={filter:{...Be,...h.filter},recipient:h.recipient??""};d($),r($)}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{o(!1)}},[t]);l.useEffect(()=>{s&&S()},[s,S]);const M=(h,$)=>{d(R=>({...R,filter:{...R.filter,[h]:$}})),N(null),m(null)},F=h=>{d($=>({...$,recipient:h})),N(null),m(null)},Q=async()=>{try{N(null),m(null);const h=await ba({filter:i.filter,recipient:i.recipient.trim()}),$={filter:{...Be,...h.filter},recipient:h.recipient??""};d($),r($),m(t("config:whatsappNotifications.saved"))}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.saveFailed"))}},W=()=>{d(c),N(null),m(null)},J=async()=>{try{N(null),m(null);const h=await ja(),$={filter:{...Be,...h.filter},recipient:h.recipient??""};d($),r($),m(t("config:whatsappNotifications.resetDone"))}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.resetFailed"))}},U=()=>{if(p){b(!0);return}n()},V=h=>{h.key==="Escape"&&(h.preventDefault(),U())};return s?e.jsxs($e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:U,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:h=>h.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:U,"aria-label":"Close",children:e.jsx(I,{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")}),u&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),u]}),k&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),k]}),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:i.recipient,onChange:h=>F(h.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")}),ws.map(h=>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.${h}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${h}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:i.filter[h],onChange:$=>M(h,$.target.checked)}),e.jsx("span",{className:"wan-toggle-track",children:e.jsx("span",{className:"wan-toggle-thumb"})})]})]},h))]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:()=>x(!0),disabled:g,children:t("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:U,children:t("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:W,disabled:!p||g,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:Q,disabled:!p||g,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(xe,{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:()=>{b(!1),n()},onClose:()=>b(!1)}),e.jsx(xe,{isOpen:E,title:t("config:whatsappNotifications.resetToDefaults"),message:t("config:whatsappNotifications.confirmReset"),confirmLabel:t("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{J(),x(!1)},onClose:()=>x(!1)})]}):null}function Ns(s){const n=s.replace(/@.*$/,"");return/^\d{10,15}$/.test(n)?n.startsWith("521")&&n.length===13?`+52 1 ${n.slice(3,5)} ${n.slice(5,9)} ${n.slice(9)}`:n.startsWith("52")&&n.length===12?`+52 ${n.slice(2,4)} ${n.slice(4,8)} ${n.slice(8)}`:n.startsWith("1")&&n.length===11?`+1 ${n.slice(1,4)} ${n.slice(4,7)} ${n.slice(7)}`:`+${n}`:s}function Na(s,n=Date.now()){const t=s*1e3,i=n-t;if(i<0)return ps(t);const d=Math.floor(i/6e4);if(d<1)return"now";if(d<60)return`${d}m`;const c=Math.floor(d/60);if(c<24)return`${c}h`;const r=Math.floor(c/24);return r===1?"yesterday":r<7?`${r}d`:ps(t)}function ps(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function ya(s){const n=s*1e3;return new Date(n).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function ys(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 ka(s,n){return s.length<=n?s:s.slice(0,Math.max(0,n-1)).trimEnd()+"…"}function Sa({chats:s,selectedChatId:n,loading:t,error:i,onSelect:d,onRefresh:c,now:r}){const{t:g}=Z(["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:c,disabled:t,"aria-label":g("config:whatsappHistory.refresh"),title:g("config:whatsappHistory.refresh"),children:"⟳"})]}),i&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:i}),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&&!i&&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(o=>{const u=ys(o.lastMessageType),N=o.lastMessagePreview||`[${o.lastMessageType}]`,k=o.chatId===n,m=Ns(o.chatId),P=o.isGroup?o.groupName:o.fromName,b=P||m,E=!!P&&P!==m;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${k?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>d(o.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:o.chatId,children:b}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:Na(o.lastTimestamp,r)})]}),E&&e.jsx("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--jid",children:e.jsx("span",{className:"whatsapp-history-chatlist__jid",children:m})}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[o.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),u&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[u," "]}),ka(N,40)]}),o.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:o.unreadCount})]})]})},o.chatId)})})]})}function Ca({message:s}){const n=s.direction==="outbound"?"outbound":"inbound",t=ys(s.messageType),i=(s.body??"").trim(),d=i.length>0,c=d?null:`[${s.messageType}]`;return e.jsx("div",{className:`whatsapp-history-bubble whatsapp-history-bubble--${n}`,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}),d?e.jsx("span",{className:"whatsapp-history-bubble__body",children:i}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:c}),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:ya(s.timestamp)})]})})}const Aa=["all","inbound","outbound"],Ta=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function Ea({direction:s,type:n,onDirectionChange:t,onTypeChange:i,disabled:d}){const{t:c}=Z(["config"]);return e.jsxs("div",{className:"whatsapp-history-filters",children:[e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:c("config:whatsappHistory.direction")}),e.jsx("select",{value:s,onChange:r=>t(r.target.value),disabled:d,children:Aa.map(r=>e.jsx("option",{value:r,children:c(`config:whatsappHistory.directionValues.${r}`)},r))})]}),e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:c("config:whatsappHistory.type")}),e.jsx("select",{value:n,onChange:r=>i(r.target.value),disabled:d,children:Ta.map(r=>e.jsx("option",{value:r,children:c(`config:whatsappHistory.typeValues.${r}`)},r))})]})]})}const Pa=80;function _a({chatId:s,messages:n,loading:t,loadingMore:i,error:d,hasMore:c,direction:r,type:g,onDirectionChange:o,onTypeChange:u,onLoadMore:N}){const{t:k}=Z(["config"]),m=l.useRef(null),P=l.useRef(null),b=l.useRef(!1),E=l.useRef(null);l.useEffect(()=>{P.current!==s&&(P.current=s,b.current=!1)},[s]),l.useLayoutEffect(()=>{m.current&&(b.current||n.length!==0&&(m.current.scrollTop=m.current.scrollHeight,b.current=!0))},[s,n.length]),l.useLayoutEffect(()=>{if(!m.current||E.current===null)return;const S=m.current.scrollHeight-E.current;E.current=null,S>0&&(m.current.scrollTop+=S)},[n.length]);const x=l.useCallback(()=>{!c||i||t||(m.current&&(E.current=m.current.scrollHeight),N())},[c,i,t,N]),p=l.useCallback(S=>{if(!b.current)return;S.currentTarget.scrollTop<=Pa&&x()},[x]);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:Ns(s)}),e.jsx(Ea,{direction:r,type:g,onDirectionChange:o,onTypeChange:u,disabled:t})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:m,onScroll:p,children:[c&&e.jsx("div",{className:"whatsapp-history-messages__load-more-row",children:e.jsx("button",{type:"button",className:"whatsapp-history-messages__load-more",onClick:x,disabled:i||t,children:k(i?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),d&&e.jsx("div",{className:"whatsapp-history-messages__error",children:d}),t&&n.length===0&&e.jsxs("div",{className:"whatsapp-history-messages__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:k("config:whatsappHistory.loadingMessages")})]}),!t&&!d&&n.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:k("config:whatsappHistory.emptyMessages")}),n.map(S=>e.jsx(Ca,{message:S},Ia(S)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:k("config:whatsappHistory.selectChat")})})}function Ia(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 ks(){const s=X(),n={};return s&&(n.Authorization=`Bearer ${s}`),n}async function Ss(s,n){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`${n}: ${s.statusText}`}async function $a(s){const n=`${Y()}/api/whatsapp/chats/${encodeURIComponent(s)}`,t=await fetch(n,{headers:ks()});if(!t.ok)throw new Error(await Ss(t,"Failed to fetch WhatsApp chats"));return t.json()}async function hs(s,n,t={}){const i=new URLSearchParams;t.cursor&&i.set("cursor",t.cursor),typeof t.limit=="number"&&i.set("limit",String(t.limit)),t.direction&&i.set("direction",t.direction),t.type&&i.set("type",t.type);const d=i.toString(),c=`${Y()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(n)}/messages${d?`?${d}`:""}`,r=await fetch(c,{headers:ks()});if(!r.ok)throw new Error(await Ss(r,"Failed to fetch WhatsApp messages"));return r.json()}const Oa=50;function La({isOpen:s,onClose:n}){const{t}=Z(["config"]),[i,d]=l.useState([]),[c,r]=l.useState(null),[g,o]=l.useState(null),[u,N]=l.useState([]),[k,m]=l.useState(!1),[P,b]=l.useState(null),[E,x]=l.useState(null),[p,S]=l.useState([]),[M,F]=l.useState(!1),[Q,W]=l.useState(!1),[J,U]=l.useState(null),[V,h]=l.useState(null),[$,R]=l.useState("all"),[H,ne]=l.useState("all"),[j,L]=l.useState(()=>Date.now()),z=l.useRef(0);l.useEffect(()=>{if(!s)return;const y=window.setInterval(()=>L(Date.now()),6e4);return()=>window.clearInterval(y)},[s]),l.useEffect(()=>{if(!s)return;let y=!1;return(async()=>{var te;try{o(null);const[oe,de]=await Promise.all([Ze().catch(()=>[]),xs().catch(()=>null)]);if(y)return;d(oe);const ie=(de==null?void 0:de.defaultSessionId)||((te=oe[0])==null?void 0:te.id)||null;r(he=>he??ie)}catch(oe){if(y)return;o(oe instanceof Error?oe.message:String(oe))}})(),()=>{y=!0}},[s]);const v=l.useCallback(async y=>{m(!0),b(null);try{const te=await $a(y);N(te.chats)}catch(te){b(te instanceof Error?te.message:String(te))}finally{m(!1)}},[]);l.useEffect(()=>{!s||!c||(x(null),S([]),h(null),v(c))},[s,c,v]);const O=l.useMemo(()=>{const y={limit:Oa};return $!=="all"&&(y.direction=$),H!=="all"&&(y.type=H),y},[$,H]),D=l.useCallback(async(y,te,oe)=>{const de=++z.current;F(!0),U(null),S([]),h(null);try{const ie=await hs(y,te,oe);if(de!==z.current)return;S([...ie.messages].reverse()),h(ie.nextCursor)}catch(ie){if(de!==z.current)return;U(ie instanceof Error?ie.message:String(ie))}finally{de===z.current&&F(!1)}},[]);l.useEffect(()=>{!s||!c||!E||D(c,E,O)},[s,c,E,O,D]);const se=l.useCallback(async()=>{if(!(!c||!E||!V)){W(!0),U(null);try{const y=await hs(c,E,{...O,cursor:V});S(te=>[...[...y.messages].reverse(),...te]),h(y.nextCursor)}catch(y){U(y instanceof Error?y.message:String(y))}finally{W(!1)}}},[c,E,V,O]),ae=l.useCallback(()=>{c&&v(c)},[c,v]),T=l.useCallback(y=>{y.key==="Escape"&&(y.preventDefault(),n())},[n]);return s?e.jsx($e,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:y=>y.stopPropagation(),onKeyDown:T,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:c??"",onChange:y=>r(y.target.value||null),disabled:i.length===0,children:[i.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),i.map(y=>e.jsxs("option",{value:y.id,children:[y.id,y.pairedNumber?` (${y.pairedNumber})`:""]},y.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(I,{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(Sa,{chats:u,selectedChatId:E,loading:k,error:P,onSelect:x,onRefresh:ae,now:j}),e.jsx(_a,{chatId:E,messages:p,loading:M,loadingMore:Q,error:J,hasMore:V!==null,direction:$,type:H,onDirectionChange:R,onTypeChange:ne,onLoadMore:se})]})]})})}):null}function Da({isOpen:s,onClose:n,onOpenConfig:t,onOpenNotifications:i,onOpenHistory:d}){const{t:c}=Z(["config"]);if(l.useEffect(()=>{if(!s)return;const g=o=>{o.key==="Escape"&&(o.preventDefault(),n())};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[s,n]),!s)return null;const r=g=>{n(),g()};return e.jsx($e,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,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:"📱"}),c("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"whatsapp-hub-modal__intro",children:c("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:()=>r(t),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.config",{defaultValue:"Integration config"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.configDesc",{defaultValue:"Server URL, API key, sessions and pairing."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(i),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.notifications",{defaultValue:"Notifications"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.notificationsDesc",{defaultValue:"Which agent events get forwarded and to whom."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(d),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.history",{defaultValue:"History"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.historyDesc",{defaultValue:"Browse persisted chats and messages."})})]})]})]})]})]})})})}const Ye=[{kind:"question",settingKey:"toneQuestion",label:"Agent asks you something",when:"A question, a plan to approve, or a permission request. Repeats twice up front, then every 10s until you answer (stops after 2 min).",sound:"Two taps, then a rising bend",play:js},{kind:"notification",settingKey:"toneNotification",label:"Agent sends a notification",when:"Any agent notification: task complete, error, or a heads-up.",sound:"Soft two-note chime",play:bs},{kind:"completion",settingKey:"toneCompletion",label:"Agent finishes working",when:"An agent stops working and goes idle.",sound:"Gentle descending arpeggio",play:ft}],Fa=[{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:"🌙"}],Ra=[{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:"🔴"}],Ba=[{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:"👎"}],Ma=[{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:"💜"}],Ua=[{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"}],za=[{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"}],Va={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},Ka={none:"grass","pokemon-stadium":"pokemon"},Ha={"emote-yes":"yes","emote-no":"no"},qa={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function ee({checked:s,onChange:n}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:t=>n(t.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function Ce({options:s,value:n,onChange:t,iconOnly:i=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(d=>e.jsxs("button",{className:`chip ${n===d.value?"active":""}`,onClick:()=>t(d.value),title:d.label,children:[e.jsx("span",{className:"chip-icon",children:d.icon}),!i&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function C({text:s,query:n}){if(!n.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),i=n.toLowerCase(),d=t.indexOf(i);if(d===-1)return e.jsx(e.Fragment,{children:s});const c=s.slice(0,d),r=s.slice(d,d+n.length),g=s.slice(d+n.length);return e.jsxs(e.Fragment,{children:[c,e.jsx("mark",{className:"search-highlight",children:r}),g]})}const Wa=[{id:"general",title:"General",keywords:["history","hide costs","grid","fps","power saving","low power","battery","bajo consumo","performance","limit","editor","external editor","language","idioma","语言","vibration","haptic","intensity","tab title","tmux","process persistence","interactive","tui","terminal","experimental","claude","stream","streaming","word by word","live text","grok","codex","app-server","app server","opencode","serve","hover","preview","tooltip","ctrl","popup","vista previa","sound","sounds","sonido","sonidos","notification","notifications","notificacion","notificaciones","volume","volumen","tone","tones","tono","chime","alert","cue","audio","mute","silence","dock","activity","recent","notification sound","silenciar","custom sound","upload sound","alerta"]},{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:"claudeAccounts",title:"Claude Accounts",keywords:["claude","accounts","credentials","oauth","rate limit","session","david","profile","switch account","subscription"]},{id:"grokAccounts",title:"Grok Accounts",keywords:["grok","xai","x.ai","accounts","credentials","oauth","session","profile","switch account","subscription"]},{id:"codexAccounts",title:"Codex Accounts",keywords:["codex","openai","chatgpt","accounts","credentials","oauth","session","profile","switch account","subscription"]},{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"]}],Je=[{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 Ga({config:s,onChange:n,searchQuery:t="",onOpenIntegrationsModal:i,onOpenMonitoringModal:d,onOpenStatisticsModal:c,onOpenWorkflowEditor:r,onOpenTriggerManager:g}){var ns;const{t:o}=Z(["config","common"]),u=at(),N=nt(),[k,m]=l.useState(()=>ot(_e.DEFAULT_AGENT_CLASS)||"scout"),P=it(),b=lt(),[E,x]=l.useState(()=>ct()),[p,S]=l.useState(null),[M,F]=l.useState(null);l.useEffect(()=>{He().then(x)},[]);const Q=async(a,A)=>{F(null),S(a);try{const B=await Ne(ye(`/api/custom-sounds/${a}`),{method:"POST",headers:{"Content-Type":A.type||"audio/mpeg"},body:A});if(!B.ok){const re=await B.json().catch(()=>({error:`Upload failed (${B.status})`}));throw new Error(re.error||`Upload failed (${B.status})`)}const le=await He();x({...le});const fe=Ye.find(re=>re.kind===a);fe&&w.updateSettings({[fe.settingKey]:Ie}),qe(Ie,u.notificationSoundVolume,a)}catch(B){F(B instanceof Error?B.message:"Upload failed")}finally{S(null)}},W=async a=>{F(null);try{await Ne(ye(`/api/custom-sounds/${a}`),{method:"DELETE"}),wt({[a]:null});const A=await He();x({...A});const B=Ye.find(le=>le.kind===a);B&&w.getSettings()[B.settingKey]===Ie&&w.updateSettings({[B.settingKey]:Nt[a]})}catch(A){F(A instanceof Error?A.message:"Failed to reset sound")}},[J,U]=l.useState(u.historyLimit),[V,h]=l.useState(()=>rt()),[$,R]=l.useState(!1),[H,ne]=l.useState(""),[j,L]=l.useState(()=>X()),[z,v]=l.useState(!1),[O,D]=l.useState(!1),[se,ae]=l.useState(""),[T,y]=l.useState(!1),[te,oe]=l.useState(!1),[de,ie]=l.useState(!1),[he,ke]=l.useState(!1),[Ae,ue]=l.useState(!1),[Te,me]=l.useState(""),[ge,Oe]=l.useState(!1);l.useEffect(()=>{Ht().then(me).catch(()=>{})},[]),l.useEffect(()=>{Vt().then(a=>{a!==u.experimentalEchoPrompt&&w.updateSettings({experimentalEchoPrompt:a})}).catch(()=>{})},[]),l.useEffect(()=>{Wt().then(a=>{a!==u.tmuxMode&&w.updateSettings({tmuxMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{Yt().then(a=>{a!==u.interactiveMode&&w.updateSettings({interactiveMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{Zt().then(a=>{a!==u.codexAppServerMode&&w.updateSettings({codexAppServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{Qt().then(a=>{a!==u.opencodeServerMode&&w.updateSettings({opencodeServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>dt(a=>{h(a),R(!1)}),[]);const Me=Fa.map(a=>({...a,label:o(`config:time.${a.value}`)})),Se=Ra.map(a=>({...a,label:o(`config:floor.${Ka[a.value]||a.value}`)})),Le=Ba.map(a=>({...a,label:o(`config:animation.${Ha[a.value]||a.value}`)})),Ue=Ma.map(a=>({...a,label:o(`config:colorMode.${a.value}`)})),ze=Ua.map(a=>({...a,label:o(`config:terrain.${Va[a.key]}`)})),Ve=za.map(a=>({...a,label:o(`config:sky.${qa[a.value??""]}`)})),be=t.trim()?Wa.filter(a=>{const A=t.toLowerCase();return a.title.toLowerCase().includes(A)||a.keywords.some(B=>B.toLowerCase().includes(A))}).map(a=>a.id):null,_=a=>be?be.includes(a):!0,Ee=_("integrations"),pe=u.customAgentNames||[],Ke=pe.length>0?pe:ut,De=()=>{const a=se.trim();a&&!pe.includes(a)&&(w.updateSettings({customAgentNames:[...pe,a]}),ae(""))},f=a=>{w.updateSettings({customAgentNames:pe.filter(A=>A!==a)})},K=()=>{w.updateSettings({customAgentNames:[]})},ce=()=>{const a=H.trim();if(a){if(V.includes(a)){ne("");return}h([...V,a]),R(!0),ne("")}},je=a=>{h(V.filter((A,B)=>B!==a)),R(!0)},es=(a,A)=>{const B=a+A;if(B<0||B>=V.length)return;const le=V.slice();[le[a],le[B]]=[le[B],le[a]],h(le),R(!0)},Cs=()=>{yt(V),R(!1),Ge()},As=a=>{L(a),v(!0)},ss=()=>{Fe(_e.AUTH_TOKEN,j),v(!1),Ge()},Ts=a=>{me(a),Oe(!0)},ts=()=>{qt(Te).catch(()=>{}),Oe(!1)},ve=a=>{n({...s,terrain:{...s.terrain,...a}})},we=a=>{n({...s,modelStyle:{...s.modelStyle,...a}})},as=a=>{n({...s,animations:{...s.animations,...a}})},Es=a=>{U(a),w.updateSettings({historyLimit:a})},Ps=a=>{const A=s.terrain[a];typeof A=="boolean"&&ve({[a]:!A})},G=t.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[be&&be.length===0&&e.jsx("div",{className:"config-no-results",children:o("config:noResults",{query:t})}),_("general")&&e.jsxs(q,{title:o("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:G&&_("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:J,onChange:a=>Es(parseInt(a.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(C,{text:o("config:general.hideCosts"),query:t})}),e.jsx(ee,{checked:u.hideCost,onChange:a=>w.updateSettings({hideCost:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.streamTextLiveTitle"),children:e.jsx(C,{text:o("config:general.streamTextLive"),query:t})}),e.jsx(ee,{checked:u.streamTextLive!==!1,onChange:a=>w.updateSettings({streamTextLive:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.toolHoverPreviewTitle"),children:e.jsx(C,{text:o("config:general.toolHoverPreview"),query:t})}),e.jsx(ee,{checked:u.toolHoverPreview!==!1,onChange:a=>w.updateSettings({toolHoverPreview:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Where the strip of recently-active and currently-working agent thumbnails sits.",children:e.jsx(C,{text:"Agent activity dock",query:t})}),e.jsx("select",{className:"config-select",value:P,onChange:a=>mt(a.target.value),children:pt.map(a=>e.jsx("option",{value:a,children:ht[a]},a))})]}),P!=="hidden"&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"How many recently-active agents the dock shows alongside the ones working right now. 0 shows only working agents.",children:e.jsx(C,{text:"Recent agents in dock",query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:b,min:0,max:20,step:1,onChange:a=>gt(parseInt(a.target.value,10)||0)})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.grid"),query:t})}),e.jsx(ee,{checked:s.gridVisible,onChange:a=>n({...s,gridVisible:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.showFPS"),query:t})}),e.jsx(ee,{checked:u.showFPS,onChange:a=>w.updateSettings({showFPS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.fpsLimit"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:a=>n({...s,fpsLimit:parseInt(a.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(C,{text:o("config:general.powerSaving"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.powerSaving,onChange:a=>w.updateSettings({powerSaving:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Battery saver for mobile: caps scene FPS (20 active / 5 idle), freezes decorative animations and disables word-by-word streaming. Off = normal mode.",children:[e.jsx(C,{text:o("config:general.lowPowerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.lowPowerMode===!0,onChange:a=>w.updateSettings({lowPowerMode:a})})]}),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(C,{text:o("config:general.tmuxMode"),query:t})}),e.jsx(ee,{checked:u.tmuxMode,onChange:async a=>{w.updateSettings({tmuxMode:a});try{await Gt(a)}catch(A){console.error("Failed to sync tmux mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Claude agents as the real interactive `claude` TUI inside tmux, reconstructing the conversation from the session transcript (requires tmux). Takes effect on server restart.",children:[e.jsx(C,{text:o("config:general.interactiveMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.interactiveMode,onChange:async a=>{w.updateSettings({interactiveMode:a});try{await Jt(a)}catch(A){console.error("Failed to sync interactive mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Codex agents through a persistent `codex app-server` so replies stream word-by-word (token deltas) instead of appearing as one block. The app-server runs detached and survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new Codex turns; no server restart needed to toggle.",children:[e.jsx(C,{text:o("config:general.codexAppServerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.codexAppServerMode,onChange:async a=>{w.updateSettings({codexAppServerMode:a});try{await Xt(a)}catch(A){console.error("Failed to sync codex app-server mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run OpenCode agents through a persistent, detached `opencode serve` HTTP server so replies stream word-by-word (token deltas over SSE) instead of appearing as one block. The server survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new OpenCode turns; no server restart needed to toggle.",children:[e.jsx(C,{text:o("config:general.opencodeServerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.opencodeServerMode,onChange:async a=>{w.updateSettings({opencodeServerMode:a});try{await ea(a)}catch(A){console.error("Failed to sync opencode server mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.vibrationIntensity"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:u.vibrationIntensity,onChange:a=>w.updateSettings({vibrationIntensity:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:u.vibrationIntensity===0?o("config:vibrationValues.off"):u.vibrationIntensity===1?o("config:vibrationValues.ultraLight"):u.vibrationIntensity===2?o("config:vibrationValues.veryLight"):u.vibrationIntensity===3?o("config:vibrationValues.light"):u.vibrationIntensity===4?o("config:vibrationValues.medium"):o("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Play pleasant sounds: a chime for agent notifications, a distinctive rising cue when an agent asks you a question (repeats until answered), and a resolving cue when an agent finishes its work.",children:e.jsx(C,{text:"Notification sounds",query:t})}),e.jsx(ee,{checked:u.notificationSoundEnabled,onChange:a=>{w.updateSettings({notificationSoundEnabled:a}),a&&bs(u.notificationSoundVolume,u.toneNotification)}})]}),u.notificationSoundEnabled&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Notification sound volume",query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:is,step:"1",value:u.notificationSoundVolume,onChange:a=>{const A=parseInt(a.target.value);w.updateSettings({notificationSoundVolume:A}),js(A,u.toneQuestion)}}),e.jsx("span",{className:"config-value",children:u.notificationSoundVolume===0?o("config:vibrationValues.off"):`${u.notificationSoundVolume}/${is}`})]}),u.notificationSoundEnabled&&u.notificationSoundVolume>0&&e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Sounds per event",query:t})}),e.jsx("div",{className:"config-sound-hint",children:'Pick a tone for each event — or upload your own file (mp3, wav, ogg, m4a — max 5MB), which is stored on the commander so every device hears it. "None" silences that event.'}),Ye.map(a=>{var fe;const A=!!E[a.kind],B=u[a.settingKey],le=A&&B===Ie;return e.jsxs("div",{className:"config-sound-row",children:[e.jsxs("div",{className:"config-sound-info",children:[e.jsxs("div",{className:"config-sound-head",children:[e.jsx("span",{className:"config-sound-name",children:a.label}),e.jsx("span",{className:`config-sound-badge${le?" custom":""}`,children:le?"Your file":((fe=xt(B))==null?void 0:fe.label)??a.sound})]}),e.jsx("div",{className:"config-sound-when",children:a.when})]}),e.jsxs("div",{className:"config-sound-actions",children:[e.jsxs("select",{className:"config-select",value:B,onChange:re=>{const Pe=re.target.value;w.updateSettings({[a.settingKey]:Pe}),qe(Pe,u.notificationSoundVolume,a.kind)},children:[A&&e.jsx("option",{value:Ie,children:"Your uploaded file"}),bt.map(re=>e.jsx("option",{value:re.id,children:re.label},re.id))]}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void qe(B,u.notificationSoundVolume,a.kind),disabled:ls(B),title:ls(B)?"This event is silenced — pick a tone to hear it":"Hear the sound that plays for this event",children:"▶"}),e.jsxs("label",{className:"config-btn config-btn-sm config-sound-upload",title:"Replace this sound with your own audio file (mp3, wav, ogg, m4a — max 5MB)",children:[p===a.kind?"Uploading…":"Upload",e.jsx("input",{type:"file",accept:"audio/*",style:{display:"none"},onChange:re=>{var os;const Pe=(os=re.target.files)==null?void 0:os[0];re.target.value="",Pe&&Q(a.kind,Pe)}})]}),A&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void W(a.kind),title:"Delete your file and go back to a built-in tone",children:"Reset"})]})]},a.kind)}),M&&e.jsx("div",{className:"config-sound-error",children:M})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.externalEditor"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.externalEditorPlaceholder"),value:u.externalEditorCommand||"",onChange:a=>w.updateSettings({externalEditorCommand:a.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.tabTitle"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.tabTitlePlaceholder"),value:u.tabTitle||"",onChange:a=>w.updateSettings({tabTitle:a.target.value})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.language"),query:t})}),e.jsx(Ce,{options:Je,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((ns=Je.find(a=>a.value!=="auto"&&We.language.startsWith(a.value.split("-")[0])))==null?void 0:ns.value)||"en":"auto",onChange:a=>{var A;if(a==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const B=navigator.language,le=((A=Je.find(fe=>fe.value!=="auto"&&B.startsWith(fe.value.split("-")[0])))==null?void 0:A.value)||"en";We.changeLanguage(le)}else localStorage.setItem("tide-commander-language-mode","manual"),We.changeLanguage(a)}})]})]}),_("agentNames")&&e.jsx(q,{title:o("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:G&&_("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:pe.length>0?o("config:agentNames.customConfigured",{count:pe.length}):o("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:o("config:agentNames.addPlaceholder"),value:se,onChange:a=>ae(a.target.value),onKeyDown:a=>{a.key==="Enter"&&De()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:De,disabled:!se.trim(),title:o("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:Ke.map((a,A)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:a}),pe.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>f(a),title:o("common:buttons.remove"),children:"x"})]},`${a}-${A}`))}),pe.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:K,children:o("common:buttons.resetToDefaults")})]})}),_("defaultClass")&&e.jsx(q,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:G&&_("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${k==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m("random"),Fe(_e.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(jt).map(([a,A])=>e.jsx("div",{className:`agent-name-chip${k===a?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(a),Fe(_e.DEFAULT_AGENT_CLASS,a)},children:e.jsxs("span",{className:"agent-name-text",children:[A.icon," ",a.charAt(0).toUpperCase()+a.slice(1)]})},a)),N.map(a=>e.jsx("div",{className:`agent-name-chip${k===a.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(a.id),Fe(_e.DEFAULT_AGENT_CLASS,a.id)},children:e.jsxs("span",{className:"agent-name-text",children:[a.icon," ",a.name]})},a.id))]})]})}),_("appearance")&&e.jsx(q,{title:o("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:G&&_("appearance"),children:e.jsx(oa,{})}),_("connection")&&e.jsxs(q,{title:o("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:G&&_("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:V.map((a,A)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:o("config:connection.priorityLabel",{defaultValue:"Priority"}),children:A+1}),e.jsx("span",{className:"backend-url-text",title:a,children:a}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>es(A,-1),disabled:A===0,title:o("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>es(A,1),disabled:A===V.length-1,title:o("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>je(A),title:o("common:buttons.remove"),children:"x"})]},`${a}-${A}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:H,onChange:a=>ne(a.target.value),placeholder:o("config:connection.addUrlPlaceholder",{defaultValue:"http://host:port"}),onKeyDown:a=>{a.key==="Enter"&&ce()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ce,disabled:!H.trim(),title:o("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),$&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Cs,title:o("config:connection.saveAndReconnect"),children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("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(C,{text:o("config:connection.authToken"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:O?"text":"password",className:"config-input config-input-full",value:j,onChange:a=>As(a.target.value),placeholder:o("config:connection.tokenPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&z&&ss()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>D(!O),title:o(O?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(I,{name:O?"eye-closed":"eye",size:14})}),z&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:ss,title:o("config:connection.saveAndReconnect"),children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:Te,onChange:a=>Ts(a.target.value),placeholder:o("config:connection.codexBinaryPathPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&ge&&ts()}}),ge&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:ts,children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("common:buttons.reconnect"),query:t})}),e.jsx("button",{className:"config-btn",onClick:()=>Ge(),title:"Force reconnect to server",children:o("common:buttons.reconnect")})]})]}),_("scene")&&e.jsxs(q,{title:o("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:G&&_("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>n({...s,characterScale:parseFloat(a.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(C,{text:o("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:a=>n({...s,scale2d:parseFloat(a.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(C,{text:o("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:a=>n({...s,scale3d:parseFloat(a.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(C,{text:o("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:t})}),e.jsx(ee,{checked:s.show2DTaskLabels,onChange:a=>n({...s,show2DTaskLabels:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.time"),query:t})}),e.jsx(Ce,{options:Me,value:s.timeMode,onChange:a=>n({...s,timeMode:a}),iconOnly:!0})]})]}),_("terrain")&&e.jsxs(q,{title:o("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:G&&_("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:t})}),e.jsx(ee,{checked:s.terrain.simpleMode??!1,onChange:a=>ve({simpleMode:a})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:ze.map(a=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[a.key]?"active":""}`,onClick:()=>Ps(a.key),title:a.label,children:a.icon},a.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>ve({fogDensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?o("config:fogValues.off"):s.terrain.fogDensity<=1?o("config:fogValues.low"):o("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>ve({brightness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?o("config:brightnessValues.dark"):s.terrain.brightness<=1.2?o("config:brightnessValues.normal"):o("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.floor"),query:t})}),e.jsx(Ce,{options:Se,value:s.terrain.floorStyle,onChange:a=>ve({floorStyle:a}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.sky"),query:t})}),e.jsx("div",{className:"sky-color-selector",children:Ve.map(a=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===a.value?"active":""}`,onClick:()=>ve({skyColor:a.value}),title:a.label,style:{background:a.color}},a.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.battlefieldSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:a=>ve({battlefieldSize:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),_("modelStyle")&&e.jsxs(q,{title:o("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:G&&_("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>we({saturation:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?o("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?o("config:saturationValues.normal"):o("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>we({roughness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?o("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?o("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?o("config:roughnessValues.normal"):o("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>we({metalness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?o("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?o("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?o("config:metalnessValues.mixed"):o("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>we({emissiveBoost:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?o("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?o("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?o("config:glowValues.med"):o("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("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:a=>we({envMapIntensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?o("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?o("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?o("config:reflectionValues.normal"):o("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.wireframe"),query:t})}),e.jsx(ee,{checked:s.modelStyle.wireframe,onChange:a=>we({wireframe:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.colorMode"),query:t})}),e.jsx(Ce,{options:Ue,value:s.modelStyle.colorMode,onChange:a=>we({colorMode:a}),iconOnly:!0})]})]}),_("animations")&&e.jsxs(q,{title:o("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:G&&_("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:animationSettings.idle"),query:t})}),e.jsx(Ce,{options:Le,value:s.animations.idleAnimation,onChange:a=>as({idleAnimation:a}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:animationSettings.working"),query:t})}),e.jsx(Ce,{options:Le,value:s.animations.workingAnimation,onChange:a=>as({workingAnimation:a}),iconOnly:!0})]})]}),_("secrets")&&e.jsx(q,{title:o("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:G&&_("secrets"),children:e.jsx(Bt,{})}),_("claudeAccounts")&&e.jsx(q,{title:o("config:sections.claudeAccounts",{defaultValue:"Claude Accounts"}),storageKey:"claudeAccounts",defaultOpen:!1,forceOpen:G&&_("claudeAccounts"),children:e.jsx(vt,{})}),_("grokAccounts")&&e.jsx(q,{title:o("config:sections.grokAccounts",{defaultValue:"Grok Accounts"}),storageKey:"grokAccounts",defaultOpen:!1,forceOpen:G&&_("grokAccounts"),children:e.jsx(cs,{provider:"grok"})}),_("codexAccounts")&&e.jsx(q,{title:o("config:sections.codexAccounts",{defaultValue:"Codex Accounts"}),storageKey:"codexAccounts",defaultOpen:!1,forceOpen:G&&_("codexAccounts"),children:e.jsx(cs,{provider:"codex"})}),_("systemPrompt")&&e.jsx(q,{title:o("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:G&&_("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>y(!0),children:o("config:systemPrompt.editPrompt")})]})}),_("data")&&e.jsx(q,{title:o("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:G&&_("data"),children:e.jsx(na,{})}),Ee&&e.jsx(q,{title:o("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:G&&Ee,children:e.jsx(ua,{onOpenModal:a=>{a==="whatsapp"?ue(!0):i==null||i(a)}})}),_("workflows")&&e.jsxs(q,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:G&&_("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{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:()=>r==null?void 0:r(),children:"Open Workflow Editor"})})]}),_("triggers")&&e.jsxs(q,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:G&&_("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{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"})})]}),_("monitoring")&&e.jsxs(q,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:G&&_("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{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:()=>d==null?void 0:d(),children:"Open Monitoring & Logs"})})]}),_("statistics")&&e.jsxs(q,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:G&&_("statistics"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{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:()=>c==null?void 0:c(),children:"Open Statistics"})})]}),_("experimental")&&e.jsxs(q,{title:o("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:G&&_("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(C,{text:o("config:experimental.2dView"),query:t})," ",e.jsx(I,{name:"map",size:12})]}),e.jsx(ee,{checked:u.experimental2DView,onChange:a=>w.updateSettings({experimental2DView:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(C,{text:o("config:experimental.voiceAssistant"),query:t})," ",e.jsx(I,{name:"microphone",size:12})]}),e.jsx(ee,{checked:u.experimentalVoiceAssistant,onChange:a=>w.updateSettings({experimentalVoiceAssistant:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(C,{text:o("config:experimental.tts"),query:t})," ",e.jsx(I,{name:"speaker-on",size:12})]}),e.jsx(ee,{checked:u.experimentalTTS,onChange:a=>w.updateSettings({experimentalTTS:a})})]}),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(C,{text:o("config:experimental.echoPrompt"),query:t})}),e.jsx(ee,{checked:u.experimentalEchoPrompt,onChange:async a=>{w.updateSettings({experimentalEchoPrompt:a});try{await Kt(a)}catch(A){console.error("Failed to sync echo prompt setting to server:",A)}}})]}),e.jsx("span",{className:"config-hint",children:o("config:experimental.hint")})]}),_("about")&&e.jsx(q,{title:o("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:G&&_("about"),children:e.jsx(ra,{})})]}),e.jsx(pa,{isOpen:T,onClose:()=>y(!1)}),e.jsx(fa,{isOpen:te,onClose:()=>oe(!1)}),e.jsx(wa,{isOpen:de,onClose:()=>ie(!1)}),e.jsx(La,{isOpen:he,onClose:()=>ke(!1)}),e.jsx(Da,{isOpen:Ae,onClose:()=>ue(!1),onOpenConfig:()=>oe(!0),onOpenNotifications:()=>ie(!0),onOpenHistory:()=>ke(!0)})]})}function Qa({onConfigChange:s,onToolChange:n,config:t,isOpen:i,onClose:d,onOpenBuildingModal:c,onOpenAreaExplorer:r,onOpenIntegrationsModal:g,onOpenMonitoringModal:o,onOpenStatisticsModal:u,onOpenWorkflowEditor:N,onOpenTriggerManager:k}){const{t:m}=Z(["config","common"]),P=kt(),b=St(),E=Ct(),x=At(),p=Tt(),S=Array.from(P.values()),M=Array.from(b.values()),[F,Q]=l.useState(""),W=l.useRef(null);if(l.useEffect(()=>{const h=$=>{$.key==="Escape"&&i&&d()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[i,d]),l.useEffect(()=>{if(i&&W.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const $=setTimeout(()=>{var R;(R=W.current)==null||R.focus()},50);return()=>clearTimeout($)}},[i]),!i)return null;const J=h=>{n(p===h?null:h)},U=h=>{w.selectArea(x===h?null:h),n("select")},V=(h,$)=>{h.stopPropagation(),w.deleteArea($)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:d}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:m("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:m("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:W,type:"text",placeholder:m("config:searchPlaceholder"),value:F,onChange:h=>Q(h.target.value),className:"toolbox-search-input"}),F&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>Q(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(q,{title:m("config:areas.title",{count:S.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${p==="select"?"active":""}`,onClick:()=>J("select"),title:m("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==="rectangle"?"active":""}`,onClick:()=>J("rectangle"),title:m("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==="circle"?"active":""}`,onClick:()=>J("circle"),title:m("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:S.length===0?e.jsx("div",{className:"areas-empty",children:m("config:areas.drawToCreate")}):S.map(h=>e.jsx(Ot,{area:h,isSelected:x===h.id,onClick:()=>U(h.id),onDelete:$=>V($,h.id)},h.id))})]})}),x&&e.jsx(Rt,{area:P.get(x),onClose:()=>w.selectArea(null),onOpenFolder:r}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(q,{title:m("config:buildings.title",{count:M.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:h=>{h.stopPropagation(),c==null||c()},title:m("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:M.length===0?e.jsx("div",{className:"buildings-empty",children:m("config:buildings.clickToAdd")}):M.map(h=>e.jsx(Lt,{building:h,isSelected:E.has(h.id),onClick:()=>{w.selectBuilding(E.has(h.id)?null:h.id)},onEdit:()=>c==null?void 0:c(h.id)},h.id))})})}),E.size===1&&(()=>{const h=Array.from(E)[0],$=b.get(h);return $?e.jsx(Dt,{building:$,onClose:()=>w.selectBuilding(null),onOpenModal:()=>c==null?void 0:c(h)}):null})(),e.jsx(Ga,{config:t,onChange:s,searchQuery:F,onOpenIntegrationsModal:g,onOpenMonitoringModal:o,onOpenStatisticsModal:u,onOpenWorkflowEditor:N,onOpenTriggerManager:k})]})]})]})}export{Qa as Toolbox};