tide-commander 1.172.1 → 1.174.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 (110) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/assets/{BossLogsModal-QsbzN4Kf.js → BossLogsModal-CsjhF9hQ.js} +1 -1
  3. package/dist/assets/{BossSpawnModal-DhwhZLhl.js → BossSpawnModal-DRgrZpYr.js} +1 -1
  4. package/dist/assets/{ControlsModal-aMgyNfN1.js → ControlsModal-zYwhMaaL.js} +1 -1
  5. package/dist/assets/{DockerLogsModal-BrpJ3mdr.js → DockerLogsModal-D7bewBqJ.js} +1 -1
  6. package/dist/assets/{EmbeddedEditor-KJESczMw.js → EmbeddedEditor-IxYwI5JV.js} +1 -1
  7. package/dist/assets/{GmailOAuthSetup-Bqll-wNA.js → GmailOAuthSetup-CfOuUZnu.js} +1 -1
  8. package/dist/assets/{GoogleOAuthSetup-D1-QMZ0M.js → GoogleOAuthSetup-Cw1tGSti.js} +1 -1
  9. package/dist/assets/{IframeModal-DTgAWYpT.js → IframeModal-Bi8MNGZY.js} +1 -1
  10. package/dist/assets/{IntegrationsPanel-DLOLI_B7.js → IntegrationsPanel-01iVXM-l.js} +2 -2
  11. package/dist/assets/{LogViewerModal-Drfk0Oeq.js → LogViewerModal-BXhxgz7Z.js} +1 -1
  12. package/dist/assets/{MonitoringModal-DFxN1iq7.js → MonitoringModal-Gf0AkCEl.js} +1 -1
  13. package/dist/assets/{PM2LogsModal-vr3C3Iwx.js → PM2LogsModal-BfoL_mEK.js} +1 -1
  14. package/dist/assets/{RestoreArchivedAreaModal-PfH31tum.js → RestoreArchivedAreaModal-Ctss__a9.js} +1 -1
  15. package/dist/assets/{Scene2DCanvas-DNZIgKRt.js → Scene2DCanvas-BuCW0Zaw.js} +1 -1
  16. package/dist/assets/{SceneManager-CfQzjU0Q.js → SceneManager-BFnKKU1I.js} +1 -1
  17. package/dist/assets/{SkillsPanel-CXgN7qvm.js → SkillsPanel-D7kJE7eT.js} +1 -1
  18. package/dist/assets/{SlackMultiInstanceSetup-CVXwTOcN.js → SlackMultiInstanceSetup-Hp7r3YK0.js} +1 -1
  19. package/dist/assets/{SpawnModal-CKSWGTkb.js → SpawnModal-Dq9P-FdI.js} +1 -1
  20. package/dist/assets/{StatisticsModal-BXQ4U5CD.js → StatisticsModal-BQOkmrmY.js} +1 -1
  21. package/dist/assets/{SubordinateAssignmentModal-CISUQILg.js → SubordinateAssignmentModal-D2-IpRLn.js} +1 -1
  22. package/dist/assets/{TriggerManagerPanel-DFyESe24.js → TriggerManagerPanel-BCZhLuoZ.js} +1 -1
  23. package/dist/assets/{WorkflowEditorPanel-CjtpyLPe.js → WorkflowEditorPanel-BEjublaK.js} +1 -1
  24. package/dist/assets/{abnfDiagram-VRR7QNED-CMoocadP.js → abnfDiagram-VRR7QNED-jjWEEISc.js} +1 -1
  25. package/dist/assets/{arc-Dl9yOoLr.js → arc-xqT5-bwQ.js} +1 -1
  26. package/dist/assets/{architectureDiagram-ZJ3FMSHR-CAYHzwiE.js → architectureDiagram-ZJ3FMSHR-BXEbOurL.js} +1 -1
  27. package/dist/assets/{area-logos-eA9M1wr9.js → area-logos-BH-HM2a-.js} +1 -1
  28. package/dist/assets/{blockDiagram-677ZJIJ3-BiHqoF5c.js → blockDiagram-677ZJIJ3-D-0HVLDv.js} +1 -1
  29. package/dist/assets/{c4Diagram-LMCZKHZV-Dl8sifqe.js → c4Diagram-LMCZKHZV-BK39PXfT.js} +1 -1
  30. package/dist/assets/channel-BgBFpxsT.js +1 -0
  31. package/dist/assets/{chunk-2Q5K7J3B-BTlBkCAr.js → chunk-2Q5K7J3B-CuW4NYbO.js} +1 -1
  32. package/dist/assets/{chunk-32BRIVSS-CNdTOM-g.js → chunk-32BRIVSS-eJLo7W-b.js} +1 -1
  33. package/dist/assets/{chunk-5VM5RSS4-CWNk7gDz.js → chunk-5VM5RSS4-E2Yaai0b.js} +1 -1
  34. package/dist/assets/{chunk-EX3LRPZG-YFeqF_nh.js → chunk-EX3LRPZG-9uAbQnMb.js} +1 -1
  35. package/dist/assets/{chunk-JWPE2WC7-DQHe11j4.js → chunk-JWPE2WC7-kKtXyMkv.js} +1 -1
  36. package/dist/assets/{chunk-MOJQB5TN-xfSSbB52.js → chunk-MOJQB5TN-DPN5ReJ7.js} +1 -1
  37. package/dist/assets/{chunk-RYQCIY6F--sw5O4hb.js → chunk-RYQCIY6F-d3yFo4Hu.js} +1 -1
  38. package/dist/assets/{chunk-V7JOEXUC-DCISYHxl.js → chunk-V7JOEXUC--3A8oVa7.js} +1 -1
  39. package/dist/assets/{chunk-VR4S4FIN-BT-BEUKi.js → chunk-VR4S4FIN-KpHuZy9_.js} +1 -1
  40. package/dist/assets/{chunk-XXDRQBXY-BC5LBfBr.js → chunk-XXDRQBXY-hpU30gZQ.js} +1 -1
  41. package/dist/assets/classDiagram-OUVF2IWQ-CXHgnAgF.js +1 -0
  42. package/dist/assets/classDiagram-v2-EOCWNBFH-CXHgnAgF.js +1 -0
  43. package/dist/assets/{cose-bilkent-JH36ORCC-CAA9BVJw.js → cose-bilkent-JH36ORCC-DOhYmYxe.js} +1 -1
  44. package/dist/assets/{cynefin-VYW2F7L2-B1EXJM3W.js → cynefin-VYW2F7L2-UDH0NYTi.js} +1 -1
  45. package/dist/assets/{cynefinDiagram-TSTJHNR4-CVPdO2-X.js → cynefinDiagram-TSTJHNR4-DnGUiXaD.js} +1 -1
  46. package/dist/assets/{dagre-VKFMJZFB-7DQFHpL-.js → dagre-VKFMJZFB-BQ6C_GWY.js} +1 -1
  47. package/dist/assets/{diagram-FQU43EPY-BjtiDNN3.js → diagram-FQU43EPY-CREz1035.js} +1 -1
  48. package/dist/assets/{diagram-G47NLZAW-DRPq9aYV.js → diagram-G47NLZAW-9Jr7GbsE.js} +1 -1
  49. package/dist/assets/{diagram-NH7WQ7WH-CKO9hg5d.js → diagram-NH7WQ7WH-DtN5x74X.js} +1 -1
  50. package/dist/assets/{diagram-OA4YK3LP-Ra81Kti3.js → diagram-OA4YK3LP-UuOi8FAP.js} +1 -1
  51. package/dist/assets/{diagram-WEI45ONY-CITyCdct.js → diagram-WEI45ONY-CWiUGHfM.js} +1 -1
  52. package/dist/assets/{ebnfDiagram-CCIWWBDH-uCGvhl6i.js → ebnfDiagram-CCIWWBDH-3eMfQx1G.js} +1 -1
  53. package/dist/assets/{erDiagram-Q63AITRT-CMhsDfB6.js → erDiagram-Q63AITRT-DYzSgp8n.js} +1 -1
  54. package/dist/assets/{flowDiagram-23GEKE2U-Czoe88ky.js → flowDiagram-23GEKE2U-DBLDGx8O.js} +1 -1
  55. package/dist/assets/{ganttDiagram-NO4QXBWP-BGW0lkZn.js → ganttDiagram-NO4QXBWP-Dv7Uyp2U.js} +1 -1
  56. package/dist/assets/{gitGraphDiagram-IHSO6WYX-BGL5LvXP.js → gitGraphDiagram-IHSO6WYX-leeHrOrC.js} +1 -1
  57. package/dist/assets/index-Bnk8mX62.js +2 -0
  58. package/dist/assets/{index-CzZ7zgVI.js → index-BrN1fSea.js} +1 -1
  59. package/dist/assets/{index-Dc06TGsb.js → index-CFiAyn9P.js} +3 -3
  60. package/dist/assets/{index-BKPwvgsm.js → index-Cpf2LUXa.js} +1 -1
  61. package/dist/assets/{index-BH5YVgOj.js → index-CtGcfchE.js} +1 -1
  62. package/dist/assets/{index-DndPvIH3.js → index-DY2LUL1D.js} +1 -1
  63. package/dist/assets/{index-Dpe8XNlP.js → index-fP8UTiVP.js} +2 -2
  64. package/dist/assets/index-jlRDILHc.js +1 -0
  65. package/dist/assets/{index-OOltFoDp.js → index-lHF2zw41.js} +1 -1
  66. package/dist/assets/{infoDiagram-FWYZ7A6U-BNL1Wsoh.js → infoDiagram-FWYZ7A6U-B23FL64X.js} +1 -1
  67. package/dist/assets/{ishikawaDiagram-FXEZZL3T-CpH1l4dh.js → ishikawaDiagram-FXEZZL3T-BPsjNXWV.js} +1 -1
  68. package/dist/assets/{journeyDiagram-5HDEW3XC-ElYAdw-X.js → journeyDiagram-5HDEW3XC-3jqJYemY.js} +1 -1
  69. package/dist/assets/{kanban-definition-HUTT4EX6-4JmbIjZ5.js → kanban-definition-HUTT4EX6-rHfIfWqi.js} +1 -1
  70. package/dist/assets/{linear-t_5G5KTB.js → linear-CvofFTBe.js} +1 -1
  71. package/dist/assets/main-CZA5Uyu6.css +1 -0
  72. package/dist/assets/main-ts-uUN3p.js +299 -0
  73. package/dist/assets/{mermaid.core-_Iqk-m82.js → mermaid.core-BuuQCwr7.js} +4 -4
  74. package/dist/assets/{mindmap-definition-LN4V7U3C-DAVAqGxu.js → mindmap-definition-LN4V7U3C-CdMbsouS.js} +1 -1
  75. package/dist/assets/{pegDiagram-2B236MQR-C_hkJRiS.js → pegDiagram-2B236MQR-Cl7drnf-.js} +1 -1
  76. package/dist/assets/{pieDiagram-ENE6RG2P-DW4eT-Bf.js → pieDiagram-ENE6RG2P-CrfvJw6b.js} +1 -1
  77. package/dist/assets/{quadrantDiagram-ABIIQ3AL-MHlY4RX3.js → quadrantDiagram-ABIIQ3AL-D6Z7VqX6.js} +1 -1
  78. package/dist/assets/{railroadDiagram-RFXS5EU6-UOYYtczg.js → railroadDiagram-RFXS5EU6-DBhqTpwY.js} +1 -1
  79. package/dist/assets/{requirementDiagram-TGXJPOKE-CoUb4-QX.js → requirementDiagram-TGXJPOKE-DjYygiNl.js} +1 -1
  80. package/dist/assets/{sankeyDiagram-HTMAVEWB-CAo4GEMz.js → sankeyDiagram-HTMAVEWB-Cb8su5H6.js} +1 -1
  81. package/dist/assets/{sequenceDiagram-DBY2YBRQ-DV-7J7Gm.js → sequenceDiagram-DBY2YBRQ-DH326uFa.js} +1 -1
  82. package/dist/assets/{sizeCapture-X5ZJPWSS-DrrCOhEN.js → sizeCapture-X5ZJPWSS-BA-8zei3.js} +1 -1
  83. package/dist/assets/{stateDiagram-2N3HPSRC-BpsPHUha.js → stateDiagram-2N3HPSRC-DM412fD5.js} +1 -1
  84. package/dist/assets/stateDiagram-v2-6OUMAXLB-BZJwjeVk.js +1 -0
  85. package/dist/assets/{swimlanes-5IMT3BWC-BwyLQeZ3.js → swimlanes-5IMT3BWC-BouPQ02z.js} +2 -2
  86. package/dist/assets/swimlanesDiagram-G3AALYLV-BRQaNmpd.js +8 -0
  87. package/dist/assets/{timeline-definition-FHXFAJF6-CclEvbuB.js → timeline-definition-FHXFAJF6-CHbeQn6a.js} +1 -1
  88. package/dist/assets/{vennDiagram-L72KCM5P-CiL_wzh1.js → vennDiagram-L72KCM5P-HSzYjTi7.js} +1 -1
  89. package/dist/assets/{wardleyDiagram-EHGQE667-DnOymUXX.js → wardleyDiagram-EHGQE667-DvrdmzxK.js} +1 -1
  90. package/dist/assets/{web-CMuYbvNC.js → web-BvtZvOK9.js} +1 -1
  91. package/dist/assets/{web-6aER7lOr.js → web-DT7q-yw_.js} +1 -1
  92. package/dist/assets/{web-DuP_2pSe.js → web-DwD7eqxR.js} +1 -1
  93. package/dist/assets/{xychartDiagram-FW5EYKEG-C9no0HxB.js → xychartDiagram-FW5EYKEG-DgSgkHvg.js} +1 -1
  94. package/dist/build-info.json +1 -1
  95. package/dist/index.html +2 -2
  96. package/dist/src/packages/server/claude/backend.js +75 -11
  97. package/dist/src/packages/server/routes/custom-sounds.js +170 -0
  98. package/dist/src/packages/server/routes/index.js +2 -0
  99. package/dist/src/packages/server/services/runtime-events.js +29 -1
  100. package/dist/src/packages/server/websocket/handlers/command-handler.js +13 -0
  101. package/package.json +1 -1
  102. package/dist/assets/channel-Do0ikKxE.js +0 -1
  103. package/dist/assets/classDiagram-OUVF2IWQ-uk12XVRi.js +0 -1
  104. package/dist/assets/classDiagram-v2-EOCWNBFH-uk12XVRi.js +0 -1
  105. package/dist/assets/index-BA7Q2Sle.js +0 -2
  106. package/dist/assets/index-BfYC8cZK.js +0 -1
  107. package/dist/assets/main-h6n299s0.css +0 -1
  108. package/dist/assets/main-vnfQDZqc.js +0 -299
  109. package/dist/assets/stateDiagram-v2-6OUMAXLB-BXrc6Zwm.js +0 -1
  110. package/dist/assets/swimlanesDiagram-G3AALYLV-DT5BZIav.js +0 -8
@@ -1 +0,0 @@
1
- import{r as l,j as e,I as _,u as J,b$ as ls,ad as cs,c0 as js,c2 as vs,s as C,cF as ys,F as ws,cG as Ns,X as be,K as Q,aR as X,c as he,d as ge,cH as ks,cI as Ss,cJ as Cs,cK as As,cL as Ts,cM as Es,cN as Ps,cO as rs,cP as _s,cQ as Is,cR as $s,aQ as Ls,an as Os,a2 as Ce,n as Ds,cS as ds,cT as Fs,cU as qe,cV as zs,cW as Rs,cX as Bs,cY as Ms,cZ as Us,c_ as Vs,c$ as Ks,bj as Hs,k as qs,m as Ws,S as Se,d0 as Gs,d1 as Ys,d2 as Js,d3 as Xs,B as Zs,d4 as Qs,d5 as et,d6 as st,d7 as tt,d8 as at,d9 as nt,da as it,db as Ze,dc as ot,bX as Ve,w as Le,v as lt,dd as Ke,de as ct,df as rt,_ as dt,f as ut,dg as pt,dh as mt,di as ht}from"./main-vnfQDZqc.js";import{g as gt,d as ft,u as xt}from"./area-logos-eA9M1wr9.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-3OKhI9bz.js";const us="tide-toolbox-collapse";function bt(s,a){try{const t=localStorage.getItem(`${us}-${s}`);if(t!==null)return t==="true"}catch{}return a}function jt(s,a){try{localStorage.setItem(`${us}-${s}`,String(a))}catch{}}function W({title:s,storageKey:a,defaultOpen:t=!1,forceOpen:o=!1,children:c,headerExtra:r}){const[d,f]=l.useState(()=>a?bt(a,t):t),i=()=>{const w=!d;f(w),a&&jt(a,w)},u=o||d;return e.jsxs("div",{className:`collapsible-section ${u?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:i,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[r,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(_,{name:u?"caret-down":"caret-right",size:10})})]})]}),u&&e.jsx("div",{className:"collapsible-content",children:c})]})}function vt({area:s,isSelected:a,onClick:t,onDelete:o}){const{t:c}=J(["config","common"]),r=s.assignedAgentIds.length,d=s.type==="rectangle"?c("config:areas.rect"):c("config:areas.circle");return e.jsxs("div",{className:`area-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[d," ",r>0&&`• ${r} ${r>1?c("common:labels.agents").toLowerCase():c("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:c("config:areas.deleteArea"),children:"×"})]})}function yt({building:s,isSelected:a,onClick:t,onEdit:o}){var f;const{t:c}=J(["config"]),r=((f=s.pm2Status)==null?void 0:f.ports)||[],d=(i,u)=>{i.stopPropagation(),window.open(`http://${window.location.hostname}:${u}`,"_blank")};return e.jsxs("div",{className:`building-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:ls[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(_,{name:cs(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,r.length>0&&e.jsx("span",{className:"building-ports",children:r.map(i=>e.jsxs("a",{href:`http://${window.location.hostname}:${i}`,className:"building-port-link",onClick:u=>d(u,i),title:`Open :${i}`,children:[":",i]},i))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:i=>{i.stopPropagation(),o()},title:c("config:buildings.editBuilding"),children:e.jsx(_,{name:"gear",size:14})})]})}function wt({building:s,onClose:a,onOpenModal:t}){var u,w,j,g,T,y,E,v;const{t:o}=J(["config","common"]),r=js().get(s.id)||[],d=vs[s.style||"server-rack"],f=p=>{C.sendBuildingCommand(s.id,p)},i=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(_,{name:cs(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:ls[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:a,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:d.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>f("start"),disabled:!((u=s.commands)!=null&&u.start)||s.status==="running",title:((w=s.commands)==null?void 0:w.start)||o("config:buildings.noStartCommand"),children:[e.jsx(_,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>f("stop"),disabled:!((j=s.commands)!=null&&j.stop)||s.status==="stopped",title:((g=s.commands)==null?void 0:g.stop)||o("config:buildings.noStopCommand"),children:[e.jsx(_,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>f("restart"),disabled:!((T=s.commands)!=null&&T.restart),title:((y=s.commands)==null?void 0:y.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx(_,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>f("healthCheck"),disabled:!((E=s.commands)!=null&&E.healthCheck),title:((v=s.commands)==null?void 0:v.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx(_,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((p,k)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>i(p.url),title:p.url,children:[e.jsx(_,{name:"link",size:12})," ",p.label||p.url]},k))})]}),r.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[o("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>C.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:r.slice(-5).map((p,k)=>e.jsx("div",{className:"building-editor-log-entry",children:p},k))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(_,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}const Nt=[{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 kt({area:s,onClose:a,onOpenFolder:t}){var ae;const{t:o}=J(["config","common"]),[c,r]=l.useState(s.name),[d,f]=l.useState(s.prompt||""),[i,u]=l.useState(!1),[w,j]=l.useState(""),[g,T]=l.useState(!1),y=l.useRef(null);l.useEffect(()=>{r(s.name)},[s.id,s.name]),l.useEffect(()=>{f(s.prompt||"")},[s.id,s.prompt]);const E=N=>{const O=N.target.value;r(O),C.updateArea(s.id,{name:O})},v=N=>{C.updateArea(s.id,{color:N})},p=N=>{const O=N.target.value;f(O),C.updateArea(s.id,{prompt:O})},k=()=>{w.trim()&&(C.addDirectoryToArea(s.id,w.trim()),j(""),u(!1))},z=(N,O)=>{O.stopPropagation(),C.removeDirectoryFromArea(s.id,N)},F=()=>{C.bringAreaToFront(s.id)},K=()=>{C.sendAreaToBack(s.id)},H=l.useCallback(()=>{let N=2,O=2;s.type==="rectangle"&&s.width&&s.height?(N=s.width,O=s.height):s.type==="circle"&&s.radius&&(N=s.radius*1.414,O=s.radius*1.414);const B=Math.min(N,O)*.4;return{width:Math.round(B*10)/10,height:Math.round(B*10)/10}},[s.type,s.width,s.height,s.radius]),q=async N=>{var B;const O=(B=N.target.files)==null?void 0:B[0];if(O){T(!0);try{const m=await xt(s.id,O),x=H();C.updateArea(s.id,{logo:{filename:m.filename,position:"center",width:x.width,height:x.height,keepAspectRatio:!0,opacity:.8}})}catch(m){console.error("Failed to upload logo:",m)}finally{T(!1),y.current&&(y.current.value="")}}},R=async()=>{try{await ft(s.id),C.updateArea(s.id,{logo:void 0})}catch(N){console.error("Failed to remove logo:",N)}},G=N=>{s.logo&&C.updateArea(s.id,{logo:{...s.logo,position:N}})},h=N=>{if(!s.logo)return;const O=parseFloat(N.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const B=s.logo.height/s.logo.width;C.updateArea(s.id,{logo:{...s.logo,width:O,height:Math.round(O*B*10)/10}})}else C.updateArea(s.id,{logo:{...s.logo,width:O}})},I=N=>{if(!s.logo)return;const O=parseFloat(N.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const B=s.logo.width/s.logo.height;C.updateArea(s.id,{logo:{...s.logo,height:O,width:Math.round(O*B*10)/10}})}else C.updateArea(s.id,{logo:{...s.logo,height:O}})},M=()=>{s.logo&&C.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},U=N=>{s.logo&&C.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(N.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:o("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:a,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:c,onChange:E,placeholder:o("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:ys.map(N=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===N?"selected":""}`,style:{backgroundColor:N},onClick:()=>v(N),"aria-label":`Set area color ${N}`,"aria-pressed":s.color===N,title:N},N))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:F,title:o("config:areas.bringToFront"),children:[e.jsx(_,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:K,title:o("config:areas.sendToBack"),children:[e.jsx(_,{name:"arrow-down",size:12})," ",o("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(ae=s.logo)!=null&&ae.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:gt(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:R,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var N;return(N=y.current)==null?void 0:N.click()},disabled:g,children:g?"...":e.jsx(_,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:Nt.map(({key:N,labelKey:O})=>{var B;return e.jsx("button",{className:`area-logo-pos-btn ${((B=s.logo)==null?void 0:B.position)===N?"active":""}`,onClick:()=>G(N),children:o(`config:areas.${O}`)},N)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:h,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:I,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:o("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:M}),o("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoOpacity")}),e.jsxs("div",{className:"area-logo-opacity-row",children:[e.jsx("input",{type:"range",min:0,max:1,step:.05,value:s.logo.opacity??.8,onChange:U,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 N;return(N=y.current)==null?void 0:N.click()},disabled:g,children:g?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:y,type:"file",accept:"image/*",style:{display:"none"},onChange:q})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(N=>e.jsxs("div",{className:"area-folder-item",title:N,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:o("config:areas.openFolder"),children:e.jsx(_,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:N.split("/").pop()||N}),e.jsx("button",{className:"area-folder-remove",onClick:O=>z(N,O),title:o("config:areas.removeFolder"),children:"×"})]},N)),i?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(ws,{value:w,onChange:j,onSubmit:k,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:k,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>u(!0),children:o("config:areas.addFolder")})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:d,onChange:p,placeholder:o("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:o("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:o("config:areas.rightClickUnassign")})]})]})}function St(){const{t:s}=J(["config","common"]),a=Ns(),[t,o]=l.useState(!1),[c,r]=l.useState(null),[d,f]=l.useState({name:"",key:"",value:"",description:""}),[i,u]=l.useState(null),w=()=>{o(!0),r(null),f({name:"",key:"",value:"",description:""})},j=p=>{r(p.id),o(!1),f({name:p.name,key:p.key,value:p.value,description:p.description||""})},g=()=>{o(!1),r(null),f({name:"",key:"",value:"",description:""})},T=()=>{!d.name.trim()||!d.key.trim()||(c?C.updateSecret(c,{name:d.name.trim(),key:d.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:d.value,description:d.description.trim()||void 0}):C.createSecret({name:d.name.trim(),key:d.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:d.value,description:d.description.trim()||void 0}),g())},y=p=>{u(p)},E=()=>{i&&(C.deleteSecret(i),c===i&&g())},v=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:a.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):a.map(p=>e.jsxs("div",{className:`secret-item ${c===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:()=>v(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:()=>j(p),title:s("common:buttons.edit"),children:e.jsx(_,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>y(p.id),title:s("common:buttons.delete"),children:"×"})]})]}),p.description&&e.jsx("div",{className:"secret-item-description",children:p.description})]},p.id))}),(t||c)&&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:d.name,onChange:p=>f({...d,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:d.key,onChange:p=>f({...d,key:p.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${d.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:d.value,onChange:p=>f({...d,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:d.description,onChange:p=>f({...d,description:p.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:g,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:T,disabled:!d.name.trim()||!d.key.trim(),children:s(c?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!c&&e.jsx("button",{className:"secrets-add-btn",onClick:w,children:s("config:secrets.addSecret")}),e.jsx(be,{isOpen:i!==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 Ct(){const s=Q(),a=await fetch(`${X()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch system prompt: ${a.statusText}`);return(await a.json()).prompt||""}async function At(s){const a=Q(),t=await fetch(`${X()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function Tt(){const s=Q(),a=await fetch(`${X()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to clear system prompt: ${a.statusText}`)}async function Et(){const s=Q(),a=await fetch(`${X()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch echo prompt setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function Pt(s){const a=Q(),t=await fetch(`${X()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function _t(){const s=Q(),a=await fetch(`${X()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch codex binary path: ${a.statusText}`);return(await a.json()).path||""}async function It(s){const a=Q(),t=await fetch(`${X()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function $t(){const s=Q(),a=await fetch(`${X()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch tmux mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function Lt(s){const a=Q(),t=await fetch(`${X()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function Ot(){const s=Q(),a=await fetch(`${X()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch interactive mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function Dt(s){const a=Q(),t=await fetch(`${X()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function Ft(){const s=Q(),a=await fetch(`${X()}/api/agents/system-settings/codex-app-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch codex app-server mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function zt(s){const a=Q(),t=await fetch(`${X()}/api/agents/system-settings/codex-app-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update codex app-server mode setting: ${t.statusText}`)}async function Rt(){const s=Q(),a=await fetch(`${X()}/api/agents/system-settings/opencode-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch opencode server mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function Bt(s){const a=Q(),t=await fetch(`${X()}/api/agents/system-settings/opencode-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update opencode server mode setting: ${t.statusText}`)}async function Mt(){const s=Q(),a=await fetch(`${X()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch backup status: ${a.statusText}`);return a.json()}async function Ut(s){const a=Q(),t=await fetch(`${X()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function Vt({checked:s,onChange:a,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:o=>a(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function Kt(){const{t:s}=J(["config","common"]),[a,t]=l.useState([]),[o,c]=l.useState(new Set),[r,d]=l.useState(new Set),[f,i]=l.useState(!1),[u,w]=l.useState(!1),[j,g]=l.useState(null),[T,y]=l.useState(null),[E,v]=l.useState(null),[p,k]=l.useState(null),[z,F]=l.useState(!1),[K,H]=l.useState(null);l.useEffect(()=>{he(ge("/api/config/categories")).then(m=>m.json()).then(m=>{const x=Array.isArray(m)?m:[];t(x),c(new Set(x.map(L=>L.id)))}).catch(m=>console.error("Failed to fetch config categories:",m))},[]),l.useEffect(()=>{Mt().then(k).catch(m=>{console.error("Failed to fetch backup status:",m),H(m.message||"Failed to fetch backup status")})},[]);const q=async m=>{if(!z){F(!0),H(null);try{const x=await Ut(m);k(x)}catch(x){H(x.message||"Failed to update backup setting")}finally{F(!1)}}},R=m=>{c(x=>{const L=new Set(x);return L.has(m)?L.delete(m):L.add(m),L})},G=m=>{d(x=>{const L=new Set(x);return L.has(m)?L.delete(m):L.add(m),L})},h=()=>c(new Set(a.map(m=>m.id))),I=()=>c(new Set),M=()=>{T&&d(new Set(T.categories.map(m=>m.id)))},U=()=>d(new Set),ae=async()=>{var m;if(o.size!==0){i(!0),v(null);try{const x=Array.from(o).join(","),L=await he(ge(`/api/config/export?categories=${x}`));if(!L.ok)throw new Error("Export failed");const Z=await L.blob(),ne=window.URL.createObjectURL(Z),P=document.createElement("a");P.href=ne;const S=L.headers.get("Content-Disposition"),ee=((m=S==null?void 0:S.match(/filename="(.+)"/))==null?void 0:m[1])||"tide-commander-config.zip";P.download=ee,document.body.appendChild(P),P.click(),document.body.removeChild(P),window.URL.revokeObjectURL(ne),v({type:"success",text:s("config:data.exportSuccess")})}catch(x){v({type:"error",text:x.message||"Export failed"})}finally{i(!1)}}},N=async m=>{var L;const x=(L=m.target.files)==null?void 0:L[0];if(x){g(x),v(null),y(null),d(new Set);try{const Z=await he(ge("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await x.arrayBuffer()});if(!Z.ok){const S=await Z.json();throw new Error(S.error||"Failed to preview config file")}const ne=await Z.json(),P=Array.isArray(ne.categories)?ne.categories:[];y({...ne,categories:P}),d(new Set(P.map(S=>S.id)))}catch(Z){v({type:"error",text:Z.message||"Failed to read config file"}),g(null)}}},O=async()=>{if(!(!j||r.size===0)){w(!0),v(null);try{const m=Array.from(r).join(","),x=await he(ge(`/api/config/import?categories=${m}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await j.arrayBuffer()}),L=await x.json();if(!x.ok)throw new Error(L.error||"Import failed");v({type:"success",text:L.message||s("config:data.importSuccess")}),g(null),y(null),d(new Set)}catch(m){v({type:"error",text:m.message||"Import failed"})}finally{w(!1)}}},B=()=>{g(null),y(null),d(new Set),v(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(Vt,{checked:!!(p!=null&&p.enabled),disabled:z||!p,onChange:q})]}),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…"}),K&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:K})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:h,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:I,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:a.map(m=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(m.id),onChange:()=>R(m.id)}),e.jsx("span",{className:"data-category-name",children:m.name})]},m.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ae,disabled:f||o.size===0,children:f?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),j?T?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:j.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(T.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:M,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:U,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:T.categories.map(m=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:r.has(m.id),onChange:()=>G(m.id)}),e.jsx("span",{className:"data-category-name",children:m.name}),m.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",m.fileCount," ",s("config:data.files"),")"]})]},m.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:B,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:O,disabled:u||r.size===0,children:u?s("config:data.importing"):s("config:data.importCount",{count:r.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:N,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function Ht(){const[s,a]=l.useState(()=>ks()),t=o=>{a(o);const c=Ts(o);Es(c)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:Ss.map(o=>e.jsxs("button",{className:`theme-option ${s===o.id?"active":""}`,onClick:()=>t(o.id),title:o.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:o.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:o.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:o.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:o.name})]},o.id))})})}function qt(){const{t:s}=J(["config"]),{installInfo:a,phase:t,output:o,error:c,newVersion:r,autoRestart:d,refreshInstallInfo:f,runUpdate:i,reset:u}=Ps(),[w,j]=l.useState(!1),g=l.useRef(null);l.useEffect(()=>{f()},[f]),l.useEffect(()=>{g.current&&(g.current.scrollTop=g.current.scrollHeight)},[o]);const T=l.useCallback(()=>{j(!0)},[]),y=l.useCallback(()=>{j(!1)},[]),E=l.useCallback(()=>{j(!1),i()},[i]),v=l.useCallback(()=>{u(),j(!1),f()},[u,f]),p=rs.isNativePlatform(),k=s(p?"config:about.autoUpdateServerTitle":"config:about.autoUpdateTitle");return a?a.isGlobalInstall?a.autoUpdateSupported?!a.updateAvailable&&t==="idle"?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:k}),t==="idle"&&!w&&a.updateAvailable&&e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsxs("span",{className:"about-autoupdate-versions",children:[e.jsx("span",{className:"about-autoupdate-current",children:a.currentVersion}),e.jsx("span",{className:"about-autoupdate-arrow",children:"→"}),e.jsx("span",{className:"about-autoupdate-latest",children:a.latestVersion})]}),e.jsx("button",{className:"about-update-btn download",onClick:T,children:s("config:about.autoUpdateButton")})]}),t==="idle"&&w&&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:y,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:g,className:"about-autoupdate-output",children:o||"..."}),t==="success"&&e.jsxs("div",{className:"about-autoupdate-success-hint",children:[r&&e.jsxs("div",{className:"about-autoupdate-newversion",children:["v",r]}),e.jsx("div",{children:s(d?"config:about.autoUpdateReconnectHint":"config:about.autoUpdateRestartHint")})]}),t==="failed"&&c&&e.jsx("div",{className:"about-update-error",children:c}),(t==="success"||t==="failed")&&e.jsx("div",{className:"about-autoupdate-stream-actions",children:e.jsx("button",{className:"about-update-btn changelog",onClick:v,children:s("config:about.autoUpdateClose")})})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:k}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdatePackageManagerNotice",{pm:a.packageManager})}),a.suggestedManualCommand&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"about-autoupdate-manualhint",children:s("config:about.autoUpdateManualCommand")}),e.jsx("pre",{className:"about-autoupdate-manualcmd",children:a.suggestedManualCommand})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:k}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdateDevMode")})]}):null}function Wt(){const{t:s}=J(["config"]),[a,t]=l.useState(null),[o,c]=l.useState(!1),[r,d]=l.useState(null);l.useEffect(()=>{_s().then(t).catch(w=>d(w.message))},[]);const f=l.useCallback(async w=>{if(!o){c(!0),d(null);try{t(await Is(w))}catch(j){d(j.message)}finally{c(!1)}}},[o]),i=rs.isNativePlatform(),u=s(i?"config:about.unattendedServerTitle":"config:about.unattendedTitle");return!a&&!r?null:a?i&&!a.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:a.supported?void 0:{opacity:.5},children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:a.enabled,disabled:o||!a.supported,onChange:w=>void f(w.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),!a.supported&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedUnsupported")}),a.supported&&a.enabled&&a.pendingRestartVersion&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedPendingRestart",{version:a.pendingRestartVersion})}),a.supported&&a.enabled&&!a.pendingRestartVersion&&a.lastResult&&e.jsx("div",{className:"about-autoupdate-devnote",children:a.lastResult}),r&&e.jsx("div",{className:"about-update-error",children:r})]}):i?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:r})]})}function Gt(){var z;const{t:s}=J(["config"]),{isAndroid:a,supported:t,otaActive:o,bundleState:c,serverInfo:r,infoError:d,updateAvailable:f,phase:i,progress:u,error:w,autoSync:j,checkNow:g,syncNow:T,resetToBundled:y,setAutoSync:E}=$s(),[v,p]=l.useState(null),k=l.useRef(g);return k.current=g,l.useEffect(()=>{a&&(k.current(!1),Ls.getInfo().then(F=>p(F.version)).catch(()=>{}))},[a]),!a||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:[o?s("config:webBundle.sourceOta",{hash:((z=c==null?void 0:c.hash)==null?void 0:z.slice(0,8))??"?"}):s("config:webBundle.sourceBundled"),v&&` · ${s("config:webBundle.apkVersion",{version:v})}`]}),r?e.jsxs("div",{className:"about-autoupdate-devnote",children:[s("config:webBundle.serverBundle",{version:r.version,hash:r.hash.slice(0,8)})," — ",s(f?"config:webBundle.updateAvailable":"config:webBundle.upToDate")]}):d&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:webBundle.serverUnavailable")}),w&&e.jsx("div",{className:"about-update-error",children:w}),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:j,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 T(),disabled:i!=="idle"||!r,children:i==="syncing"?s("config:webBundle.syncingPct",{percent:u??0}):s("config:webBundle.syncNow")}),o&&e.jsx("button",{className:"about-update-btn changelog",onClick:()=>void y(),children:s("config:webBundle.reset")})]})]})}function Yt(){const{t:s}=J(["config"]),{updateAvailable:a,updateInfo:t,recentReleases:o,isChecking:c,error:r,currentVersion:d,isAndroid:f,downloadPhase:i,downloadProgress:u,checkForUpdate:w,downloadAndInstall:j,openReleasePage:g}=Cs(),[T,y]=l.useState(!1),E=p=>p?`${(p/(1024*1024)).toFixed(1)} MB`:"",v=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(_,{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:d}),a&&t?e.jsx("span",{className:"about-version-update-badge",onClick:g,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(qt,{}),e.jsx(Wt,{}),e.jsx(Gt,{}),e.jsx("div",{className:"about-changelog-row",children:e.jsx("button",{className:"about-update-btn changelog",onClick:()=>y(!0),children:s("config:about.changelog")})}),e.jsxs("div",{className:"about-update",children:[a&&t?e.jsxs("div",{className:"about-update-available",children:[e.jsxs("div",{className:"about-update-header",children:[e.jsx("span",{className:"about-update-badge",children:s("config:about.updateAvailable")}),e.jsx("span",{className:"about-update-version",children:t.version})]}),t.apkSize&&e.jsxs("div",{className:"about-update-size",children:[s("config:about.sizeLabel"),": ",E(t.apkSize)]}),r&&e.jsx("div",{className:"about-update-error",children:r}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:g,children:s("config:about.changelog")}),f&&t.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:()=>void j(),disabled:i!=="idle",children:i==="downloading"?s("config:appUpdateBanner.downloadingPct",{percent:u??0}):s(i==="installing"?"config:appUpdateBanner.installHint":"config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:g,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(c?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>w(!0),disabled:c,children:c?"...":s("config:about.check")})]}),o.length>0&&e.jsxs("div",{className:"about-releases",children:[e.jsx("div",{className:"about-releases-title",children:s("config:about.recentReleases")}),e.jsx("div",{className:"about-releases-list",children:o.map(p=>e.jsxs("a",{href:p.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${p.version===`v${d}`||p.version===d?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:p.version}),e.jsx("span",{className:"about-release-date",children:v(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(_,{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")})]})]}),T&&e.jsx(As,{onClose:()=>y(!1)})]})}const Jt={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function Xt({onOpenModal:s}){const[a,t]=l.useState([]),[o,c]=l.useState(!0),r=l.useCallback(async()=>{try{const d=await he(ge("/api/integrations"));if(!d.ok)return;const f=await d.json();t(f)}catch{}finally{c(!1)}},[]);return l.useEffect(()=>{r()},[r]),o?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):a.length===0?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"No integrations available."}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[a.map(d=>{const f=Jt[d.id]||"🔌",i=!!d.status.error,u=d.status.connected,w=i?"#f38ba8":u?"#a6e3a1":"#fab387",j=i?"Error":u?"Connected":"Setup Required",g=i?"✗":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:f}),e.jsx("span",{style:{flex:1,minWidth:0,color:"var(--text-primary, #cdd6f4)",fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d.name}),e.jsx("span",{style:{color:w,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:j,children:g}),e.jsx("button",{onClick:()=>s(d.id),title:`Configure ${d.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:T=>{T.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:T=>{T.target.style.color="var(--text-secondary, #a6adc8)"},children:"⚙️"})]},d.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:d=>{d.target.style.borderColor="var(--accent, #89b4fa)",d.target.style.color="var(--accent, #89b4fa)"},onMouseLeave:d=>{d.target.style.borderColor="var(--border, #313244)",d.target.style.color="var(--text-secondary, #a6adc8)"},children:"Manage All Integrations"})]})}function Ae(s){return`/api/system/${s}-credentials`}async function Te(s,a){try{const t=await s.json();if(t!=null&&t.error&&typeof t.error=="string")return t.error}catch{}return a}async function Zt(s){const a=await he(ge(Ae(s)));if(!a.ok)throw new Error(await Te(a,`Failed to list ${s} credentials: ${a.status}`));return await a.json()}async function Qe(s,a,t={}){const o=await he(ge(`${Ae(s)}/switch`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:a,stashActiveAs:t.stashActiveAs})});if(!o.ok)throw new Error(await Te(o,`Failed to switch ${s} credentials: ${o.status}`));return await o.json()}async function es(s,a,t={}){const o=await he(ge(`${Ae(s)}/save`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:a,force:t.force})});if(!o.ok)throw new Error(await Te(o,`Failed to save ${s} credentials: ${o.status}`));return await o.json()}async function Qt(s,a,t){const o=await he(ge(`${Ae(s)}/rename`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:a,to:t})});if(!o.ok)throw new Error(await Te(o,`Failed to rename ${s} credentials: ${o.status}`));return await o.json()}async function ea(s,a){const t=await he(ge(`${Ae(s)}/${encodeURIComponent(a)}`),{method:"DELETE"});if(!t.ok)throw new Error(await Te(t,`Failed to delete ${s} credentials: ${t.status}`));return await t.json()}const Oe={grok:"Grok",codex:"Codex"};function sa(s){if(s==null||!Number.isFinite(s))return"—";const a=new Date(s);return Number.isNaN(a.getTime())?"—":a.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function ta({profile:s,busy:a,onUse:t,onRename:o,onDelete:c}){const{t:r}=J(["terminal","common"]),d=s.expiresAt!=null&&s.expiresAt<=Date.now(),f=[s.label,s.email].filter(Boolean).join(" · ");return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"8px 10px",background:s.isActive?"rgba(74, 158, 255, 0.1)":"var(--bg-tertiary, var(--bg-secondary))",border:s.isActive?"1px solid rgba(74, 158, 255, 0.45)":"1px solid var(--border-color)",borderRadius:"6px",marginBottom:"6px"},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontWeight:600,fontSize:"13px"},children:s.name}),s.isActive&&e.jsx("span",{style:{fontSize:"10px",textTransform:"uppercase",letterSpacing:"0.4px",color:"#4a9eff",border:"1px solid rgba(74, 158, 255, 0.5)",borderRadius:"4px",padding:"1px 6px"},children:r("terminal:credentials.activeBadge")}),!s.valid&&e.jsx("span",{style:{fontSize:"10px",color:"#ff8a8a"},children:r("terminal:credentials.invalid")})]}),e.jsxs("div",{style:{fontSize:"11px",color:"var(--text-secondary)",marginTop:"2px"},children:[f,s.expiresAt!=null&&e.jsxs("span",{style:{color:d?"#ff8a8a":void 0},children:[f?" · ":"",r("terminal:credentials.tokenExpires",{time:sa(s.expiresAt)})]})]})]}),e.jsxs("div",{style:{display:"flex",gap:"4px",flexShrink:0},children:[!s.isActive&&e.jsx("button",{type:"button",className:"btn btn-primary",disabled:a||!s.valid,onClick:()=>t(s.name),style:{padding:"4px 10px",fontSize:"11px"},title:r("terminal:credentials.useTitle"),children:r("terminal:credentials.use")}),e.jsx("button",{type:"button",className:"btn btn-secondary",disabled:a,onClick:()=>o(s.name),style:{padding:"4px 8px",fontSize:"11px"},title:r("terminal:credentials.rename"),children:e.jsx(_,{name:"edit",size:12})}),e.jsx("button",{type:"button",className:"btn btn-secondary",disabled:a,onClick:()=>c(s.name),style:{padding:"4px 8px",fontSize:"11px",color:"#ff8a8a"},title:r("terminal:credentials.delete"),children:e.jsx(_,{name:"trash",size:12})})]})]})}function ss({provider:s,onSwitched:a,compact:t}){var U,ae,N,O,B;const{t:o}=J(["terminal","common"]),[c,r]=l.useState(null),[d,f]=l.useState(!1),[i,u]=l.useState(!1),[w,j]=l.useState(null),[g,T]=l.useState(""),[y,E]=l.useState(""),[v,p]=l.useState(null),[k,z]=l.useState(null),F=l.useCallback(async()=>{f(!0),j(null);try{r(await Zt(s))}catch(m){j(m instanceof Error?m.message:String(m))}finally{f(!1)}},[s]);l.useEffect(()=>{F()},[F]);const K=m=>r(m),H=!!((U=c==null?void 0:c.active)!=null&&U.valid&&!c.active.matchesNamed),q=async m=>{if(j(null),z(null),H){p(m);return}u(!0);try{const x=await Qe(s,m);r({provider:s,dir:(c==null?void 0:c.dir)??"",active:x.active,profiles:x.profiles}),z(o("terminal:credentials.switched",{name:m})),p(null),a==null||a()}catch(x){j(x instanceof Error?x.message:String(x))}finally{u(!1)}},R=async()=>{if(!v)return;const m=y.trim();if(!m){j(o("terminal:credentials.stashRequired"));return}u(!0),j(null);try{const x=await Qe(s,v,{stashActiveAs:m});r({provider:s,dir:(c==null?void 0:c.dir)??"",active:x.active,profiles:x.profiles}),z(x.stashedAs?o("terminal:credentials.switchedWithStash",{name:v,stash:x.stashedAs}):o("terminal:credentials.switched",{name:v})),p(null),E(""),a==null||a()}catch(x){j(x instanceof Error?x.message:String(x))}finally{u(!1)}},G=async()=>{const m=g.trim();if(!m){j(o("terminal:credentials.nameRequired"));return}u(!0),j(null),z(null);try{K(await es(s,m)),T(""),z(o("terminal:credentials.saved",{name:m}))}catch(x){const L=x instanceof Error?x.message:String(x);if(/already exists/i.test(L)&&window.confirm(o("terminal:credentials.confirmOverwrite",{name:m})))try{K(await es(s,m,{force:!0})),T(""),z(o("terminal:credentials.saved",{name:m})),u(!1);return}catch(Z){j(Z instanceof Error?Z.message:String(Z)),u(!1);return}j(L)}finally{u(!1)}},h=async m=>{const x=window.prompt(o("terminal:credentials.renamePrompt",{name:m}),m);if(!(!x||x.trim()===m)){u(!0),j(null);try{K(await Qt(s,m,x.trim())),z(o("terminal:credentials.renamed",{from:m,to:x.trim()}))}catch(L){j(L instanceof Error?L.message:String(L))}finally{u(!1)}}},I=async m=>{if(window.confirm(o("terminal:credentials.confirmDelete",{name:m}))){u(!0),j(null);try{K(await ea(s,m)),z(o("terminal:credentials.deleted",{name:m}))}catch(x){j(x instanceof Error?x.message:String(x))}finally{u(!1)}}},M=c!=null&&c.active?c.active.matchesNamed?c.active.matchesNamed:o("terminal:credentials.unsavedActive"):o("terminal:credentials.noActive");return e.jsxs("div",{className:"claude-credentials-panel",style:{marginTop:t?"12px":"0",paddingTop:t?"12px":"0",borderTop:t?"1px solid var(--border-color)":void 0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"10px",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.5px"},children:o("terminal:credentials.providerTitle",{provider:Oe[s],defaultValue:`${Oe[s]} Accounts`})}),e.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:[o("terminal:credentials.current",{name:M}),((ae=c==null?void 0:c.active)==null?void 0:ae.email)&&e.jsxs("span",{style:{color:"var(--text-secondary)"},children:[" · ",c.active.email]}),((N=c==null?void 0:c.active)==null?void 0:N.label)&&e.jsxs("span",{style:{color:"var(--text-secondary)"},children:[" (",c.active.label,")"]})]})]}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>void F(),disabled:d||i,style:{padding:"4px 10px",fontSize:"11px",display:"inline-flex",gap:"6px",alignItems:"center"},title:o("common:buttons.refresh"),children:e.jsx("span",{style:{display:"inline-block",animation:d?"spin 1s linear infinite":"none"},children:e.jsx(_,{name:"refresh",size:12})})})]}),e.jsx("p",{style:{fontSize:"11px",color:"var(--text-secondary)",margin:"0 0 10px",lineHeight:1.45},children:o("terminal:credentials.providerHelp",{provider:Oe[s],dir:(c==null?void 0:c.dir)??`~/.${s}`,defaultValue:`Named copies of ${(c==null?void 0:c.dir)??`~/.${s}`}/auth.json. Switch the active ${Oe[s]} account when you hit rate limits — same as renaming the file manually.`})}),w&&e.jsx("div",{style:{padding:"8px 10px",marginBottom:"8px",background:"rgba(255, 74, 74, 0.08)",border:"1px solid rgba(255, 74, 74, 0.3)",borderRadius:"6px",color:"#ff8a8a",fontSize:"12px"},children:w}),k&&e.jsx("div",{style:{padding:"8px 10px",marginBottom:"8px",background:"rgba(74, 255, 158, 0.08)",border:"1px solid rgba(74, 255, 158, 0.3)",borderRadius:"6px",color:"#7dffb0",fontSize:"12px"},children:k}),v&&e.jsxs("div",{style:{padding:"10px 12px",marginBottom:"10px",background:"rgba(255, 158, 74, 0.08)",border:"1px solid rgba(255, 158, 74, 0.35)",borderRadius:"6px"},children:[e.jsx("div",{style:{fontSize:"12px",marginBottom:"8px",lineHeight:1.45},children:o("terminal:credentials.stashPrompt",{name:v})}),e.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap"},children:[e.jsx("input",{type:"text",value:y,onChange:m=>E(m.target.value),placeholder:o("terminal:credentials.stashPlaceholder"),disabled:i,style:{flex:1,minWidth:"120px",padding:"6px 8px",fontSize:"12px",borderRadius:"4px",border:"1px solid var(--border-color)",background:"var(--bg-primary)",color:"var(--text-primary)"}}),e.jsx("button",{type:"button",className:"btn btn-primary",disabled:i,onClick:()=>void R(),style:{padding:"6px 12px",fontSize:"12px"},children:o("terminal:credentials.confirmSwitch")}),e.jsx("button",{type:"button",className:"btn btn-secondary",disabled:i,onClick:()=>p(null),style:{padding:"6px 12px",fontSize:"12px"},children:o("common:buttons.cancel")})]})]}),d&&!c&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--text-secondary)",padding:"8px 0"},children:[o("common:status.loading"),"…"]}),c&&c.profiles.length===0&&e.jsx("div",{style:{fontSize:"12px",color:"var(--text-muted)",marginBottom:"10px"},children:o("terminal:credentials.noProfiles")}),c==null?void 0:c.profiles.map(m=>e.jsx(ta,{profile:m,busy:i,onUse:x=>void q(x),onRename:x=>void h(x),onDelete:x=>void I(x)},m.name)),e.jsxs("div",{style:{display:"flex",gap:"6px",marginTop:"10px",flexWrap:"wrap",alignItems:"center"},children:[e.jsx("input",{type:"text",value:g,onChange:m=>T(m.target.value),placeholder:o("terminal:credentials.savePlaceholder"),disabled:i||!((O=c==null?void 0:c.active)!=null&&O.valid),style:{flex:1,minWidth:"140px",padding:"6px 8px",fontSize:"12px",borderRadius:"4px",border:"1px solid var(--border-color)",background:"var(--bg-primary)",color:"var(--text-primary)"}}),e.jsx("button",{type:"button",className:"btn btn-secondary",disabled:i||!((B=c==null?void 0:c.active)!=null&&B.valid)||!g.trim(),onClick:()=>void G(),style:{padding:"6px 12px",fontSize:"12px"},children:o("terminal:credentials.saveActive")})]}),(c==null?void 0:c.dir)&&e.jsx("div",{style:{fontSize:"10px",color:"var(--text-muted)",marginTop:"8px",wordBreak:"break-all"},children:c.dir})]})}const De="__global__";function aa({isOpen:s,onClose:a,initialAgentId:t}){const{t:o}=J(["config"]),c=Os(),[r,d]=l.useState(""),[f,i]=l.useState(""),[u,w]=l.useState(!1),[j,g]=l.useState(""),[T,y]=l.useState(""),[E,v]=l.useState(null),[p,k]=l.useState(null),[z,F]=l.useState(!1),[K,H]=l.useState(!1),[q,R]=l.useState(!1),[G,h]=l.useState(null),I=l.useMemo(()=>[...c].sort((P,S)=>P.name.localeCompare(S.name)),[c]),M=l.useMemo(()=>c.find(P=>P.id===r),[c,r]),U=r===De;l.useEffect(()=>{if(!s)return;const P=t&&c.some(S=>S.id===t)?t:De;d(P),w(!1),Ct().then(S=>i(S)).catch(()=>i("")).finally(()=>w(!0))},[s]),l.useEffect(()=>{const P=r===De?f:(M==null?void 0:M.customPrompt)??"";g(P),y(P),F(!1),v(null),k(null)},[r,u]);const ae=P=>{const S=P.target.value;g(S),F(S!==T),v(null),k(null)},N=async()=>{if(r)try{v(null),k(null),U?(await At(j),i(j),k(o("config:systemPrompt.savedGlobal"))):(C.updateAgentProperties(r,{customPrompt:j}),k(o("config:systemPrompt.saved"))),y(j),F(!1)}catch(P){v(P instanceof Error?P.message:"Failed to save system prompt")}},O=()=>{H(!0)},B=async()=>{if(r)try{v(null),k(null),U?(await Tt(),i(""),k(o("config:systemPrompt.clearedGlobal"))):(C.updateAgentProperties(r,{customPrompt:""}),k(o("config:systemPrompt.cleared"))),g(""),y(""),F(!1)}catch(P){v(P instanceof Error?P.message:"Failed to clear system prompt")}},m=()=>{g(T),F(!1),v(null),k(null)},x=P=>{if(P!==r){if(z){h(P),R(!0);return}d(P)}},L=()=>{if(z){h(null),R(!0);return}a()},Z=()=>{if(R(!1),G){const P=G;h(null),d(P)}else a()},ne=P=>{P.key==="Escape"&&(P.preventDefault(),L())};return s?e.jsxs(Ce,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:L,children:e.jsxs("div",{className:"system-prompt-modal",onClick:P=>P.stopPropagation(),onKeyDown:ne,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:o("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:L,"aria-label":"Close",children:e.jsx(_,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"modal-description",children:o("config:systemPrompt.description")}),e.jsxs("div",{className:"agent-picker",children:[e.jsx("label",{htmlFor:"system-prompt-agent",className:"editor-label",children:o("config:systemPrompt.agentLabel")}),e.jsxs("div",{className:"agent-picker-row",children:[U?e.jsx(_,{name:"globe",size:20,className:"agent-picker-icon"}):M&&e.jsx(Ds,{classId:M.class,size:20,className:"agent-picker-icon"}),e.jsxs("select",{id:"system-prompt-agent",className:"agent-picker-select",value:r,onChange:P=>x(P.target.value),children:[e.jsxs("option",{value:De,children:[o("config:systemPrompt.globalOption"),f?" • ✦":""]}),I.map(P=>e.jsxs("option",{value:P.id,children:[P.name,P.customPrompt?" • ✦":""]},P.id))]})]})]}),E&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(_,{name:"warn",size:14})}),E]}),p&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(_,{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:o("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[j.length," ",o("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:j,onChange:ae,placeholder:o("config:systemPrompt.placeholder"),rows:18,disabled:U&&!u,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:o(U?"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:O,disabled:!j||!r,children:o("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:L,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:m,disabled:!z,children:o("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:N,disabled:!z||!r,children:o("config:systemPrompt.save")})]})]})]})}),e.jsx(be,{isOpen:K,title:o("config:systemPrompt.clear"),message:o(U?"config:systemPrompt.confirmClearGlobal":"config:systemPrompt.confirmClear"),confirmLabel:o("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{B()},onClose:()=>H(!1)}),e.jsx(be,{isOpen:q,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:Z,onClose:()=>{R(!1),h(null)}})]}):null}const ts={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},na=2500,ia=12e4;function as(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function oa(s,a){return s.enabled===a.enabled&&s.baseUrl===a.baseUrl&&s.defaultSessionId===a.defaultSessionId&&s.webhookVerifyToken===a.webhookVerifyToken&&s.showIncomingToasts===a.showIncomingToasts}function la({isOpen:s,onClose:a}){const{t}=J(["config"]),[o,c]=l.useState(ts),[r,d]=l.useState(ts),[f,i]=l.useState(!1),[u,w]=l.useState([]),[j,g]=l.useState(!0),[T,y]=l.useState(null),[E,v]=l.useState(null),[p,k]=l.useState(""),[z,F]=l.useState(!1),[K,H]=l.useState(""),[q,R]=l.useState(null),[G,h]=l.useState(null),[I,M]=l.useState(null),U=l.useRef(null),ae=l.useRef(0),[N,O]=l.useState(""),[B,m]=l.useState(""),[x,L]=l.useState(null),[Z,ne]=l.useState(!1),[P,S]=l.useState(!1),[ee,ie]=l.useState(!1),[re,oe]=l.useState(!1),[fe,we]=l.useState(null),ve=!oa(o,r),ue=l.useCallback(()=>{U.current&&(clearTimeout(U.current),U.current=null)},[]),Ee=l.useCallback(async()=>{try{g(!0),y(null),v(null);const[b,V]=await Promise.all([ds(),Fs()]),te=as(b);if(c(te),d(te),i(!!V.configured),V.configured)try{const ce=await qe();w(Array.isArray(ce)?ce:[])}catch{w([])}else w([])}catch(b){y(b instanceof Error?b.message:t("config:whatsapp.errors.loadFailed"))}finally{g(!1)}},[t]),je=l.useCallback(async()=>{try{const b=await qe();w(Array.isArray(b)?b:[])}catch{}},[]);l.useEffect(()=>(s?Ee():(ue(),R(null),h(null),M(null),k(""),F(!1),L(null)),()=>{ue()}),[s,Ee,ue]);const pe=(b,V)=>{c(te=>({...te,[b]:V})),y(null),v(null)},$=async()=>{try{y(null),v(null);const b=await Us({enabled:o.enabled,baseUrl:o.baseUrl.trim(),defaultSessionId:o.defaultSessionId.trim(),webhookVerifyToken:o.webhookVerifyToken,showIncomingToasts:o.showIncomingToasts});window.dispatchEvent(new CustomEvent("tide:whatsapp-config-updated"));const V=as(b);c(V),d(V),v(t("config:whatsapp.saved"))}catch(b){y(b instanceof Error?b.message:t("config:whatsapp.errors.saveFailed"))}},Pe=()=>{c(r),y(null),v(null)},le=()=>{if(ve){S(!0);return}a()},ze=b=>{b.key==="Escape"&&(b.preventDefault(),le())},_e=async()=>{const b=p.trim();if(b)try{y(null),v(null),await Rs(b),k(""),F(!1),i(!0),v(t("config:whatsapp.apiKeySaved"))}catch(V){y(V instanceof Error?V.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},Re=()=>{ie(!0)},Be=async()=>{try{y(null),v(null),await Vs(),i(!1),v(t("config:whatsapp.apiKeyCleared"))}catch(b){y(b instanceof Error?b.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},Ne=l.useCallback(async b=>{if(Date.now()>ae.current){M(t("config:whatsapp.pairingTimeout")),R(null),h(null),ue(),je();return}try{const V=await zs(b);if(V.status&&["connected","paired","open","ready"].includes(V.status.toLowerCase())){M(t("config:whatsapp.pairingSuccess")),R(null),h(null),ue(),je();return}const ce=V.qrUrl??V.qr??null;ce&&h(ce)}catch(V){M(V instanceof Error?V.message:t("config:whatsapp.errors.qrFetchFailed"))}U.current=setTimeout(()=>{Ne(b)},na)},[je,ue,t]),Ie=async()=>{const b=K.trim();if(b)try{y(null),v(null),M(null),h(null),ue(),await Bs(b),H(""),R(b),ae.current=Date.now()+ia,Ne(b),je()}catch(V){y(V instanceof Error?V.message:t("config:whatsapp.errors.sessionCreateFailed"))}},ke=()=>{ue(),R(null),h(null),M(null)},Me=b=>{we(b),oe(!0)},Ue=async()=>{if(fe)try{y(null),v(null),await Ks(fe),q===fe&&ke(),je(),v(t("config:whatsapp.sessionDeleted"))}catch(b){y(b instanceof Error?b.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{we(null)}},$e=async()=>{const b=N.trim(),V=B.trim();if(!(!b||!V))try{ne(!0),L(null);const te=o.defaultSessionId.trim()||void 0;await Ms(b,V,te),L({kind:"success",text:t("config:whatsapp.testSent")})}catch(te){L({kind:"error",text:te instanceof Error?te.message:t("config:whatsapp.errors.testSendFailed")})}finally{ne(!1)}};return s?e.jsxs(Ce,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:le,children:e.jsxs("div",{className:"whatsapp-config-modal",onClick:b=>b.stopPropagation(),onKeyDown:ze,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsapp.title")}),e.jsx("button",{className:"modal-close",onClick:le,"aria-label":"Close",children:e.jsx(_,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:j?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")}),T&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(_,{name:"warn",size:14})}),T]}),E&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(_,{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:o.enabled,onChange:b=>pe("enabled",b.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-show-toasts",className:"wa-label",children:t("config:whatsapp.showIncomingToasts")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-show-toasts",type:"checkbox",checked:o.showIncomingToasts,onChange:b=>pe("showIncomingToasts",b.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.showIncomingToastsHelp")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-base-url",className:"wa-label",children:t("config:whatsapp.baseUrl")}),e.jsx("input",{id:"wa-base-url",type:"text",className:"wa-input",placeholder:"http://localhost:3007",value:o.baseUrl,onChange:b=>pe("baseUrl",b.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-default-session",className:"wa-label",children:t("config:whatsapp.defaultSessionId")}),e.jsx("input",{id:"wa-default-session",type:"text",className:"wa-input",placeholder:t("config:whatsapp.defaultSessionIdPlaceholder"),value:o.defaultSessionId,onChange:b=>pe("defaultSessionId",b.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-webhook-token",className:"wa-label",children:t("config:whatsapp.webhookVerifyToken")}),e.jsx("input",{id:"wa-webhook-token",type:"text",className:"wa-input",placeholder:t("config:whatsapp.webhookVerifyTokenPlaceholder"),value:o.webhookVerifyToken,onChange:b=>pe("webhookVerifyToken",b.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:f?e.jsxs("span",{className:"wa-status wa-status-ok",children:[e.jsx(_,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(_,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:z?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:p,onChange:b=>k(b.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>F(b=>!b),title:t(z?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(_,{name:z?"eye-closed":"eye",size:14})}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:_e,disabled:!p.trim(),children:t("config:whatsapp.saveKey")}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:Re,disabled:!f,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(b=>e.jsxs("div",{className:"wa-session-row",children:[e.jsxs("div",{className:"wa-session-info",children:[e.jsx("span",{className:"wa-session-id",children:b.id}),e.jsx("span",{className:`wa-session-status status-${(b.status??"unknown").toLowerCase()}`,children:b.status||"—"}),b.pairedNumber&&e.jsx("span",{className:"wa-session-paired",children:b.pairedNumber})]}),e.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:()=>Me(b.id),children:t("config:whatsapp.deleteSession")})]},b.id))}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:"text",className:"wa-input",placeholder:t("config:whatsapp.addSessionPlaceholder"),value:K,onChange:b=>H(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Ie()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ie,disabled:!K.trim()||q!==null,children:t("config:whatsapp.addSession")})]}),q&&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:q})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:ke,children:t("config:whatsapp.cancelPairing")})]}),G?e.jsx("div",{className:"wa-qr-image",children:e.jsx("img",{src:G,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")})]})]}),I&&!q&&e.jsx("div",{className:"wa-pairing-message",children:I})]}),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:N,onChange:b=>O(b.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:B,onChange:b=>m(b.target.value)})]}),e.jsx("div",{className:"wa-field-inline wa-field-end",children:e.jsx("button",{type:"button",className:"btn btn-primary",onClick:$e,disabled:!N.trim()||!B.trim()||Z,children:t(Z?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),x&&e.jsxs("div",{className:`alert ${x.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(_,{name:x.kind==="success"?"check":"warn",size:14})}),x.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:le,children:t("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:Pe,disabled:!ve||j,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:$,disabled:!ve||j,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(be,{isOpen:P,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{S(!1),a()},onClose:()=>S(!1)}),e.jsx(be,{isOpen:ee,title:t("config:whatsapp.clearKey"),message:t("config:whatsapp.confirmClearKey"),confirmLabel:t("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Be()},onClose:()=>ie(!1)}),e.jsx(be,{isOpen:re,title:t("config:whatsapp.deleteSession"),message:t("config:whatsapp.confirmDeleteSession",{id:fe??""}),confirmLabel:t("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Ue()},onClose:()=>{oe(!1),we(null)}})]}):null}const ps=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function We(s=!1){const a=Q(),t={};return a&&(t.Authorization=`Bearer ${a}`),s&&(t["Content-Type"]="application/json"),t}async function Ge(s,a){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${a}: ${s.statusText}`}async function ca(){const s=await fetch(`${X()}/api/whatsapp/notification-config`,{headers:We()});if(!s.ok)throw new Error(await Ge(s,"Failed to fetch WhatsApp notification config"));return s.json()}async function ra(s){const a=await fetch(`${X()}/api/whatsapp/notification-config`,{method:"PATCH",headers:We(!0),body:JSON.stringify(s)});if(!a.ok)throw new Error(await Ge(a,"Failed to update WhatsApp notification config"));return a.json()}async function da(){const s=await fetch(`${X()}/api/whatsapp/notification-config`,{method:"DELETE",headers:We()});if(!s.ok)throw new Error(await Ge(s,"Failed to reset WhatsApp notification config"));return s.json()}const Fe={messages:!0,statusChanges:!0,taskComplete:!0,errors:!0,planReady:!0,agentSpawned:!0,agentStopped:!0},ns={filter:{...Fe},recipient:""};function ua(s,a){if(s.recipient!==a.recipient)return!1;for(const t of ps)if(s.filter[t]!==a.filter[t])return!1;return!0}function pa({isOpen:s,onClose:a}){const{t}=J(["config"]),[o,c]=l.useState(ns),[r,d]=l.useState(ns),[f,i]=l.useState(!0),[u,w]=l.useState(null),[j,g]=l.useState(null),[T,y]=l.useState(!1),[E,v]=l.useState(!1),p=!ua(o,r),k=l.useCallback(async()=>{try{i(!0),w(null),g(null);const h=await ca(),I={filter:{...Fe,...h.filter},recipient:h.recipient??""};c(I),d(I)}catch(h){w(h instanceof Error?h.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{i(!1)}},[t]);l.useEffect(()=>{s&&k()},[s,k]);const z=(h,I)=>{c(M=>({...M,filter:{...M.filter,[h]:I}})),w(null),g(null)},F=h=>{c(I=>({...I,recipient:h})),w(null),g(null)},K=async()=>{try{w(null),g(null);const h=await ra({filter:o.filter,recipient:o.recipient.trim()}),I={filter:{...Fe,...h.filter},recipient:h.recipient??""};c(I),d(I),g(t("config:whatsappNotifications.saved"))}catch(h){w(h instanceof Error?h.message:t("config:whatsappNotifications.errors.saveFailed"))}},H=()=>{c(r),w(null),g(null)},q=async()=>{try{w(null),g(null);const h=await da(),I={filter:{...Fe,...h.filter},recipient:h.recipient??""};c(I),d(I),g(t("config:whatsappNotifications.resetDone"))}catch(h){w(h instanceof Error?h.message:t("config:whatsappNotifications.errors.resetFailed"))}},R=()=>{if(p){y(!0);return}a()},G=h=>{h.key==="Escape"&&(h.preventDefault(),R())};return s?e.jsxs(Ce,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:R,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:h=>h.stopPropagation(),onKeyDown:G,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappNotifications.title")}),e.jsx("button",{className:"modal-close",onClick:R,"aria-label":"Close",children:e.jsx(_,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:f?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(_,{name:"warn",size:14})}),u]}),j&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(_,{name:"check",size:14})}),j]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.recipient")}),e.jsxs("div",{className:"wan-field",children:[e.jsx("label",{htmlFor:"wan-recipient",className:"wan-label",children:t("config:whatsappNotifications.recipientLabel")}),e.jsx("input",{id:"wan-recipient",type:"text",className:"wan-input",placeholder:t("config:whatsappNotifications.recipientPlaceholder"),value:o.recipient,onChange: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")}),ps.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:o.filter[h],onChange:I=>z(h,I.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:()=>v(!0),disabled:f,children:t("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:R,children:t("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:H,disabled:!p||f,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:K,disabled:!p||f,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(be,{isOpen:T,title:t("config:whatsappNotifications.unsavedTitle"),message:t("config:whatsappNotifications.unsavedMessage"),confirmLabel:t("config:whatsappNotifications.closeAnyway"),cancelLabel:t("config:whatsappNotifications.keepEditing"),variant:"danger",onConfirm:()=>{y(!1),a()},onClose:()=>y(!1)}),e.jsx(be,{isOpen:E,title:t("config:whatsappNotifications.resetToDefaults"),message:t("config:whatsappNotifications.confirmReset"),confirmLabel:t("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{q(),v(!1)},onClose:()=>v(!1)})]}):null}function ms(s){const a=s.replace(/@.*$/,"");return/^\d{10,15}$/.test(a)?a.startsWith("521")&&a.length===13?`+52 1 ${a.slice(3,5)} ${a.slice(5,9)} ${a.slice(9)}`:a.startsWith("52")&&a.length===12?`+52 ${a.slice(2,4)} ${a.slice(4,8)} ${a.slice(8)}`:a.startsWith("1")&&a.length===11?`+1 ${a.slice(1,4)} ${a.slice(4,7)} ${a.slice(7)}`:`+${a}`:s}function ma(s,a=Date.now()){const t=s*1e3,o=a-t;if(o<0)return is(t);const c=Math.floor(o/6e4);if(c<1)return"now";if(c<60)return`${c}m`;const r=Math.floor(c/60);if(r<24)return`${r}h`;const d=Math.floor(r/24);return d===1?"yesterday":d<7?`${d}d`:is(t)}function is(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function ha(s){const a=s*1e3;return new Date(a).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function hs(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 ga(s,a){return s.length<=a?s:s.slice(0,Math.max(0,a-1)).trimEnd()+"…"}function fa({chats:s,selectedChatId:a,loading:t,error:o,onSelect:c,onRefresh:r,now:d}){const{t:f}=J(["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:f("config:whatsappHistory.chats")}),e.jsx("button",{type:"button",className:"whatsapp-history-chatlist__refresh",onClick:r,disabled:t,"aria-label":f("config:whatsappHistory.refresh"),title:f("config:whatsappHistory.refresh"),children:"⟳"})]}),o&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:o}),t&&s.length===0&&e.jsxs("div",{className:"whatsapp-history-chatlist__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:f("config:whatsappHistory.loadingChats")})]}),!t&&!o&&s.length===0&&e.jsx("div",{className:"whatsapp-history-chatlist__empty",children:f("config:whatsappHistory.emptyChats")}),e.jsx("ul",{className:"whatsapp-history-chatlist__items",children:s.map(i=>{const u=hs(i.lastMessageType),w=i.lastMessagePreview||`[${i.lastMessageType}]`,j=i.chatId===a,g=ms(i.chatId),T=i.isGroup?i.groupName:i.fromName,y=T||g,E=!!T&&T!==g;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${j?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>c(i.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:i.chatId,children:y}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:ma(i.lastTimestamp,d)})]}),E&&e.jsx("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--jid",children:e.jsx("span",{className:"whatsapp-history-chatlist__jid",children:g})}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[i.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),u&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[u," "]}),ga(w,40)]}),i.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:i.unreadCount})]})]})},i.chatId)})})]})}function xa({message:s}){const a=s.direction==="outbound"?"outbound":"inbound",t=hs(s.messageType),o=(s.body??"").trim(),c=o.length>0,r=c?null:`[${s.messageType}]`;return e.jsx("div",{className:`whatsapp-history-bubble whatsapp-history-bubble--${a}`,children:e.jsxs("div",{className:"whatsapp-history-bubble__inner",children:[t&&e.jsx("span",{className:"whatsapp-history-bubble__type-icon",title:s.messageType,children:t}),c?e.jsx("span",{className:"whatsapp-history-bubble__body",children:o}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:r}),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:ha(s.timestamp)})]})})}const ba=["all","inbound","outbound"],ja=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function va({direction:s,type:a,onDirectionChange:t,onTypeChange:o,disabled:c}){const{t:r}=J(["config"]);return e.jsxs("div",{className:"whatsapp-history-filters",children:[e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:r("config:whatsappHistory.direction")}),e.jsx("select",{value:s,onChange:d=>t(d.target.value),disabled:c,children:ba.map(d=>e.jsx("option",{value:d,children:r(`config:whatsappHistory.directionValues.${d}`)},d))})]}),e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:r("config:whatsappHistory.type")}),e.jsx("select",{value:a,onChange:d=>o(d.target.value),disabled:c,children:ja.map(d=>e.jsx("option",{value:d,children:r(`config:whatsappHistory.typeValues.${d}`)},d))})]})]})}const ya=80;function wa({chatId:s,messages:a,loading:t,loadingMore:o,error:c,hasMore:r,direction:d,type:f,onDirectionChange:i,onTypeChange:u,onLoadMore:w}){const{t:j}=J(["config"]),g=l.useRef(null),T=l.useRef(null),y=l.useRef(!1),E=l.useRef(null);l.useEffect(()=>{T.current!==s&&(T.current=s,y.current=!1)},[s]),l.useLayoutEffect(()=>{g.current&&(y.current||a.length!==0&&(g.current.scrollTop=g.current.scrollHeight,y.current=!0))},[s,a.length]),l.useLayoutEffect(()=>{if(!g.current||E.current===null)return;const k=g.current.scrollHeight-E.current;E.current=null,k>0&&(g.current.scrollTop+=k)},[a.length]);const v=l.useCallback(()=>{!r||o||t||(g.current&&(E.current=g.current.scrollHeight),w())},[r,o,t,w]),p=l.useCallback(k=>{if(!y.current)return;k.currentTarget.scrollTop<=ya&&v()},[v]);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:ms(s)}),e.jsx(va,{direction:d,type:f,onDirectionChange:i,onTypeChange:u,disabled:t})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:g,onScroll:p,children:[r&&e.jsx("div",{className:"whatsapp-history-messages__load-more-row",children:e.jsx("button",{type:"button",className:"whatsapp-history-messages__load-more",onClick:v,disabled:o||t,children:j(o?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),c&&e.jsx("div",{className:"whatsapp-history-messages__error",children:c}),t&&a.length===0&&e.jsxs("div",{className:"whatsapp-history-messages__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:j("config:whatsappHistory.loadingMessages")})]}),!t&&!c&&a.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:j("config:whatsappHistory.emptyMessages")}),a.map(k=>e.jsx(xa,{message:k},Na(k)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:j("config:whatsappHistory.selectChat")})})}function Na(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 gs(){const s=Q(),a={};return s&&(a.Authorization=`Bearer ${s}`),a}async function fs(s,a){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${a}: ${s.statusText}`}async function ka(s){const a=`${X()}/api/whatsapp/chats/${encodeURIComponent(s)}`,t=await fetch(a,{headers:gs()});if(!t.ok)throw new Error(await fs(t,"Failed to fetch WhatsApp chats"));return t.json()}async function os(s,a,t={}){const o=new URLSearchParams;t.cursor&&o.set("cursor",t.cursor),typeof t.limit=="number"&&o.set("limit",String(t.limit)),t.direction&&o.set("direction",t.direction),t.type&&o.set("type",t.type);const c=o.toString(),r=`${X()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(a)}/messages${c?`?${c}`:""}`,d=await fetch(r,{headers:gs()});if(!d.ok)throw new Error(await fs(d,"Failed to fetch WhatsApp messages"));return d.json()}const Sa=50;function Ca({isOpen:s,onClose:a}){const{t}=J(["config"]),[o,c]=l.useState([]),[r,d]=l.useState(null),[f,i]=l.useState(null),[u,w]=l.useState([]),[j,g]=l.useState(!1),[T,y]=l.useState(null),[E,v]=l.useState(null),[p,k]=l.useState([]),[z,F]=l.useState(!1),[K,H]=l.useState(!1),[q,R]=l.useState(null),[G,h]=l.useState(null),[I,M]=l.useState("all"),[U,ae]=l.useState("all"),[N,O]=l.useState(()=>Date.now()),B=l.useRef(0);l.useEffect(()=>{if(!s)return;const S=window.setInterval(()=>O(Date.now()),6e4);return()=>window.clearInterval(S)},[s]),l.useEffect(()=>{if(!s)return;let S=!1;return(async()=>{var ee;try{i(null);const[ie,re]=await Promise.all([qe().catch(()=>[]),ds().catch(()=>null)]);if(S)return;c(ie);const oe=(re==null?void 0:re.defaultSessionId)||((ee=ie[0])==null?void 0:ee.id)||null;d(fe=>fe??oe)}catch(ie){if(S)return;i(ie instanceof Error?ie.message:String(ie))}})(),()=>{S=!0}},[s]);const m=l.useCallback(async S=>{g(!0),y(null);try{const ee=await ka(S);w(ee.chats)}catch(ee){y(ee instanceof Error?ee.message:String(ee))}finally{g(!1)}},[]);l.useEffect(()=>{!s||!r||(v(null),k([]),h(null),m(r))},[s,r,m]);const x=l.useMemo(()=>{const S={limit:Sa};return I!=="all"&&(S.direction=I),U!=="all"&&(S.type=U),S},[I,U]),L=l.useCallback(async(S,ee,ie)=>{const re=++B.current;F(!0),R(null),k([]),h(null);try{const oe=await os(S,ee,ie);if(re!==B.current)return;k([...oe.messages].reverse()),h(oe.nextCursor)}catch(oe){if(re!==B.current)return;R(oe instanceof Error?oe.message:String(oe))}finally{re===B.current&&F(!1)}},[]);l.useEffect(()=>{!s||!r||!E||L(r,E,x)},[s,r,E,x,L]);const Z=l.useCallback(async()=>{if(!(!r||!E||!G)){H(!0),R(null);try{const S=await os(r,E,{...x,cursor:G});k(ee=>[...[...S.messages].reverse(),...ee]),h(S.nextCursor)}catch(S){R(S instanceof Error?S.message:String(S))}finally{H(!1)}}},[r,E,G,x]),ne=l.useCallback(()=>{r&&m(r)},[r,m]),P=l.useCallback(S=>{S.key==="Escape"&&(S.preventDefault(),a())},[a]);return s?e.jsx(Ce,{children:e.jsx("div",{className:"modal-overlay visible",onClick:a,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:S=>S.stopPropagation(),onKeyDown:P,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:r??"",onChange:S=>d(S.target.value||null),disabled:o.length===0,children:[o.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),o.map(S=>e.jsxs("option",{value:S.id,children:[S.id,S.pairedNumber?` (${S.pairedNumber})`:""]},S.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:a,"aria-label":"Close",children:e.jsx(_,{name:"close",size:16})})]}),f&&e.jsx("div",{className:"whatsapp-history-modal__alert",children:f}),e.jsxs("div",{className:"whatsapp-history-modal__body",children:[e.jsx(fa,{chats:u,selectedChatId:E,loading:j,error:T,onSelect:v,onRefresh:ne,now:N}),e.jsx(wa,{chatId:E,messages:p,loading:z,loadingMore:K,error:q,hasMore:G!==null,direction:I,type:U,onDirectionChange:M,onTypeChange:ae,onLoadMore:Z})]})]})})}):null}function Aa({isOpen:s,onClose:a,onOpenConfig:t,onOpenNotifications:o,onOpenHistory:c}){const{t:r}=J(["config"]);if(l.useEffect(()=>{if(!s)return;const f=i=>{i.key==="Escape"&&(i.preventDefault(),a())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[s,a]),!s)return null;const d=f=>{a(),f()};return e.jsx(Ce,{children:e.jsx("div",{className:"modal-overlay visible",onClick:a,children:e.jsxs("div",{className:"whatsapp-hub-modal",onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"whatsapp-hub-modal__icon",children:"📱"}),r("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:a,"aria-label":"Close",children:e.jsx(_,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"whatsapp-hub-modal__intro",children:r("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:()=>d(t),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(_,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:r("config:whatsappHub.config",{defaultValue:"Integration config"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:r("config:whatsappHub.configDesc",{defaultValue:"Server URL, API key, sessions and pairing."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>d(o),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(_,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:r("config:whatsappHub.notifications",{defaultValue:"Notifications"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:r("config:whatsappHub.notificationsDesc",{defaultValue:"Which agent events get forwarded and to whom."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>d(c),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(_,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:r("config:whatsappHub.history",{defaultValue:"History"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:r("config:whatsappHub.historyDesc",{defaultValue:"Browse persisted chats and messages."})})]})]})]})]})]})})})}const Ta=[{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:"🌙"}],Ea=[{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:"🔴"}],Pa=[{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:"👎"}],_a=[{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:"💜"}],Ia=[{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"}],$a=[{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"}],La={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},Oa={none:"grass","pokemon-stadium":"pokemon"},Da={"emote-yes":"yes","emote-no":"no"},Fa={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function se({checked:s,onChange:a}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:t=>a(t.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function ye({options:s,value:a,onChange:t,iconOnly:o=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(c=>e.jsxs("button",{className:`chip ${a===c.value?"active":""}`,onClick:()=>t(c.value),title:c.label,children:[e.jsx("span",{className:"chip-icon",children:c.icon}),!o&&e.jsx("span",{className:"chip-label",children:c.label})]},c.value))})}function A({text:s,query:a}){if(!a.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),o=a.toLowerCase(),c=t.indexOf(o);if(c===-1)return e.jsx(e.Fragment,{children:s});const r=s.slice(0,c),d=s.slice(c,c+a.length),f=s.slice(c+a.length);return e.jsxs(e.Fragment,{children:[r,e.jsx("mark",{className:"search-highlight",children:d}),f]})}const za=[{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"]},{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"]}],He=[{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 Ra({config:s,onChange:a,searchQuery:t="",onOpenIntegrationsModal:o,onOpenMonitoringModal:c,onOpenStatisticsModal:r,onOpenWorkflowEditor:d,onOpenTriggerManager:f}){var Je;const{t:i}=J(["config","common"]),u=Hs(),w=qs(),[j,g]=l.useState(()=>Ws(Se.DEFAULT_AGENT_CLASS)||"scout"),T=Gs(),y=Ys(),[E,v]=l.useState(u.historyLimit),[p,k]=l.useState(()=>Js()),[z,F]=l.useState(!1),[K,H]=l.useState(""),[q,R]=l.useState(()=>Q()),[G,h]=l.useState(!1),[I,M]=l.useState(!1),[U,ae]=l.useState(""),[N,O]=l.useState(!1),[B,m]=l.useState(!1),[x,L]=l.useState(!1),[Z,ne]=l.useState(!1),[P,S]=l.useState(!1),[ee,ie]=l.useState(""),[re,oe]=l.useState(!1);l.useEffect(()=>{_t().then(ie).catch(()=>{})},[]),l.useEffect(()=>{Et().then(n=>{n!==u.experimentalEchoPrompt&&C.updateSettings({experimentalEchoPrompt:n})}).catch(()=>{})},[]),l.useEffect(()=>{$t().then(n=>{n!==u.tmuxMode&&C.updateSettings({tmuxMode:n})}).catch(()=>{})},[]),l.useEffect(()=>{Ot().then(n=>{n!==u.interactiveMode&&C.updateSettings({interactiveMode:n})}).catch(()=>{})},[]),l.useEffect(()=>{Ft().then(n=>{n!==u.codexAppServerMode&&C.updateSettings({codexAppServerMode:n})}).catch(()=>{})},[]),l.useEffect(()=>{Rt().then(n=>{n!==u.opencodeServerMode&&C.updateSettings({opencodeServerMode:n})}).catch(()=>{})},[]),l.useEffect(()=>Xs(n=>{k(n),F(!1)}),[]);const fe=Ta.map(n=>({...n,label:i(`config:time.${n.value}`)})),we=Ea.map(n=>({...n,label:i(`config:floor.${Oa[n.value]||n.value}`)})),ve=Pa.map(n=>({...n,label:i(`config:animation.${Da[n.value]||n.value}`)})),ue=_a.map(n=>({...n,label:i(`config:colorMode.${n.value}`)})),Ee=Ia.map(n=>({...n,label:i(`config:terrain.${La[n.key]}`)})),je=$a.map(n=>({...n,label:i(`config:sky.${Fa[n.value??""]}`)})),pe=t.trim()?za.filter(n=>{const D=t.toLowerCase();return n.title.toLowerCase().includes(D)||n.keywords.some(de=>de.toLowerCase().includes(D))}).map(n=>n.id):null,$=n=>pe?pe.includes(n):!0,Pe=$("integrations"),le=u.customAgentNames||[],ze=le.length>0?le:Zs,_e=()=>{const n=U.trim();n&&!le.includes(n)&&(C.updateSettings({customAgentNames:[...le,n]}),ae(""))},Re=n=>{C.updateSettings({customAgentNames:le.filter(D=>D!==n)})},Be=()=>{C.updateSettings({customAgentNames:[]})},Ne=()=>{const n=K.trim();if(n){if(p.includes(n)){H("");return}k([...p,n]),F(!0),H("")}},Ie=n=>{k(p.filter((D,de)=>de!==n)),F(!0)},ke=(n,D)=>{const de=n+D;if(de<0||de>=p.length)return;const me=p.slice();[me[n],me[de]]=[me[de],me[n]],k(me),F(!0)},Me=()=>{rt(p),F(!1),Ke()},Ue=n=>{R(n),h(!0)},$e=()=>{Le(Se.AUTH_TOKEN,q),h(!1),Ke()},b=n=>{ie(n),oe(!0)},V=()=>{It(ee).catch(()=>{}),oe(!1)},te=n=>{a({...s,terrain:{...s.terrain,...n}})},ce=n=>{a({...s,modelStyle:{...s.modelStyle,...n}})},Ye=n=>{a({...s,animations:{...s.animations,...n}})},xs=n=>{v(n),C.updateSettings({historyLimit:n})},bs=n=>{const D=s.terrain[n];typeof D=="boolean"&&te({[n]:!D})},Y=t.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[pe&&pe.length===0&&e.jsx("div",{className:"config-no-results",children:i("config:noResults",{query:t})}),$("general")&&e.jsxs(W,{title:i("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:Y&&$("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:E,onChange:n=>xs(parseInt(n.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(A,{text:i("config:general.hideCosts"),query:t})}),e.jsx(se,{checked:u.hideCost,onChange:n=>C.updateSettings({hideCost:n})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:i("config:general.streamTextLiveTitle"),children:e.jsx(A,{text:i("config:general.streamTextLive"),query:t})}),e.jsx(se,{checked:u.streamTextLive!==!1,onChange:n=>C.updateSettings({streamTextLive:n})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:i("config:general.toolHoverPreviewTitle"),children:e.jsx(A,{text:i("config:general.toolHoverPreview"),query:t})}),e.jsx(se,{checked:u.toolHoverPreview!==!1,onChange:n=>C.updateSettings({toolHoverPreview:n})})]}),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(A,{text:"Agent activity dock",query:t})}),e.jsx("select",{className:"config-select",value:T,onChange:n=>st(n.target.value),children:Qs.map(n=>e.jsx("option",{value:n,children:et[n]},n))})]}),T!=="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(A,{text:"Recent agents in dock",query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:y,min:0,max:20,step:1,onChange:n=>tt(parseInt(n.target.value,10)||0)})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:general.grid"),query:t})}),e.jsx(se,{checked:s.gridVisible,onChange:n=>a({...s,gridVisible:n})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:general.showFPS"),query:t})}),e.jsx(se,{checked:u.showFPS,onChange:n=>C.updateSettings({showFPS:n})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:general.fpsLimit"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:n=>a({...s,fpsLimit:parseInt(n.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(A,{text:i("config:general.powerSaving"),query:t})," ",e.jsx(_,{name:"bolt",size:12})]}),e.jsx(se,{checked:u.powerSaving,onChange:n=>C.updateSettings({powerSaving:n})})]}),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(A,{text:i("config:general.lowPowerMode"),query:t})," ",e.jsx(_,{name:"bolt",size:12})]}),e.jsx(se,{checked:u.lowPowerMode===!0,onChange:n=>C.updateSettings({lowPowerMode:n})})]}),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(A,{text:i("config:general.tmuxMode"),query:t})}),e.jsx(se,{checked:u.tmuxMode,onChange:async n=>{C.updateSettings({tmuxMode:n});try{await Lt(n)}catch(D){console.error("Failed to sync tmux mode setting to server:",D)}}})]}),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(A,{text:i("config:general.interactiveMode"),query:t})," ",e.jsx(_,{name:"bolt",size:12})]}),e.jsx(se,{checked:u.interactiveMode,onChange:async n=>{C.updateSettings({interactiveMode:n});try{await Dt(n)}catch(D){console.error("Failed to sync interactive mode setting to server:",D)}}})]}),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(A,{text:i("config:general.codexAppServerMode"),query:t})," ",e.jsx(_,{name:"bolt",size:12})]}),e.jsx(se,{checked:u.codexAppServerMode,onChange:async n=>{C.updateSettings({codexAppServerMode:n});try{await zt(n)}catch(D){console.error("Failed to sync codex app-server mode setting to server:",D)}}})]}),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(A,{text:i("config:general.opencodeServerMode"),query:t})," ",e.jsx(_,{name:"bolt",size:12})]}),e.jsx(se,{checked:u.opencodeServerMode,onChange:async n=>{C.updateSettings({opencodeServerMode:n});try{await Bt(n)}catch(D){console.error("Failed to sync opencode server mode setting to server:",D)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:general.vibrationIntensity"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:u.vibrationIntensity,onChange:n=>C.updateSettings({vibrationIntensity:parseInt(n.target.value)})}),e.jsx("span",{className:"config-value",children:u.vibrationIntensity===0?i("config:vibrationValues.off"):u.vibrationIntensity===1?i("config:vibrationValues.ultraLight"):u.vibrationIntensity===2?i("config:vibrationValues.veryLight"):u.vibrationIntensity===3?i("config:vibrationValues.light"):u.vibrationIntensity===4?i("config:vibrationValues.medium"):i("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(A,{text:"Notification sounds",query:t})}),e.jsx(se,{checked:u.notificationSoundEnabled,onChange:n=>{C.updateSettings({notificationSoundEnabled:n}),n&&at(u.notificationSoundVolume,u.toneNotification)}})]}),u.notificationSoundEnabled&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:"Notification sound volume",query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:u.notificationSoundVolume,onChange:n=>{const D=parseInt(n.target.value);C.updateSettings({notificationSoundVolume:D}),nt(D,u.toneQuestion)}}),e.jsx("span",{className:"config-value",children:u.notificationSoundVolume===0?i("config:vibrationValues.off"):String(u.notificationSoundVolume)})]}),u.notificationSoundEnabled&&u.notificationSoundVolume>0&&[{key:"toneNotification",label:"Notification tone",hint:"Played when an agent sends a notification"},{key:"toneQuestion",label:"Question tone",hint:"Played when an agent asks you something (repeats until answered)"},{key:"toneCompletion",label:"Agent finished tone",hint:"Played when an agent goes from working to idle"}].map(({key:n,label:D,hint:de})=>{var me;return e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:de,children:e.jsx(A,{text:D,query:t})}),e.jsx("select",{className:"config-select",value:u[n],onChange:xe=>{const Xe=xe.target.value;C.updateSettings({[n]:Xe}),Ze(Xe,u.notificationSoundVolume)},children:it.map(xe=>e.jsx("option",{value:xe.id,children:xe.label},xe.id))}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void Ze(u[n],u.notificationSoundVolume),title:`Preview: ${((me=ot(u[n]))==null?void 0:me.label)??u[n]}`,children:"▶"})]},n)}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:general.externalEditor"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:i("config:general.externalEditorPlaceholder"),value:u.externalEditorCommand||"",onChange:n=>C.updateSettings({externalEditorCommand:n.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:general.tabTitle"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:i("config:general.tabTitlePlaceholder"),value:u.tabTitle||"",onChange:n=>C.updateSettings({tabTitle:n.target.value})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:general.language"),query:t})}),e.jsx(ye,{options:He,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((Je=He.find(n=>n.value!=="auto"&&Ve.language.startsWith(n.value.split("-")[0])))==null?void 0:Je.value)||"en":"auto",onChange:n=>{var D;if(n==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const de=navigator.language,me=((D=He.find(xe=>xe.value!=="auto"&&de.startsWith(xe.value.split("-")[0])))==null?void 0:D.value)||"en";Ve.changeLanguage(me)}else localStorage.setItem("tide-commander-language-mode","manual"),Ve.changeLanguage(n)}})]})]}),$("agentNames")&&e.jsx(W,{title:i("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:Y&&$("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:le.length>0?i("config:agentNames.customConfigured",{count:le.length}):i("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:i("config:agentNames.addPlaceholder"),value:U,onChange:n=>ae(n.target.value),onKeyDown:n=>{n.key==="Enter"&&_e()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:_e,disabled:!U.trim(),title:i("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:ze.map((n,D)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:n}),le.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>Re(n),title:i("common:buttons.remove"),children:"x"})]},`${n}-${D}`))}),le.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:Be,children:i("common:buttons.resetToDefaults")})]})}),$("defaultClass")&&e.jsx(W,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:Y&&$("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${j==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{g("random"),Le(Se.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(lt).map(([n,D])=>e.jsx("div",{className:`agent-name-chip${j===n?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{g(n),Le(Se.DEFAULT_AGENT_CLASS,n)},children:e.jsxs("span",{className:"agent-name-text",children:[D.icon," ",n.charAt(0).toUpperCase()+n.slice(1)]})},n)),w.map(n=>e.jsx("div",{className:`agent-name-chip${j===n.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{g(n.id),Le(Se.DEFAULT_AGENT_CLASS,n.id)},children:e.jsxs("span",{className:"agent-name-text",children:[n.icon," ",n.name]})},n.id))]})]})}),$("appearance")&&e.jsx(W,{title:i("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:Y&&$("appearance"),children:e.jsx(Ht,{})}),$("connection")&&e.jsxs(W,{title:i("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:Y&&$("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:p.map((n,D)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:i("config:connection.priorityLabel",{defaultValue:"Priority"}),children:D+1}),e.jsx("span",{className:"backend-url-text",title:n,children:n}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>ke(D,-1),disabled:D===0,title:i("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>ke(D,1),disabled:D===p.length-1,title:i("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ie(D),title:i("common:buttons.remove"),children:"x"})]},`${n}-${D}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:K,onChange:n=>H(n.target.value),placeholder:i("config:connection.addUrlPlaceholder",{defaultValue:"http://host:port"}),onKeyDown:n=>{n.key==="Enter"&&Ne()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ne,disabled:!K.trim(),title:i("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),z&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Me,title:i("config:connection.saveAndReconnect"),children:i("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:i("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(A,{text:i("config:connection.authToken"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:I?"text":"password",className:"config-input config-input-full",value:q,onChange:n=>Ue(n.target.value),placeholder:i("config:connection.tokenPlaceholder"),onKeyDown:n=>{n.key==="Enter"&&G&&$e()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>M(!I),title:i(I?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(_,{name:I?"eye-closed":"eye",size:14})}),G&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:$e,title:i("config:connection.saveAndReconnect"),children:i("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:i("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("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:ee,onChange:n=>b(n.target.value),placeholder:i("config:connection.codexBinaryPathPlaceholder"),onKeyDown:n=>{n.key==="Enter"&&re&&V()}}),re&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:V,children:i("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:i("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("common:buttons.reconnect"),query:t})}),e.jsx("button",{className:"config-btn",onClick:()=>Ke(),title:"Force reconnect to server",children:i("common:buttons.reconnect")})]})]}),$("scene")&&e.jsxs(W,{title:i("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:Y&&$("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("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:n=>a({...s,characterScale:parseFloat(n.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(A,{text:i("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:n=>a({...s,scale2d:parseFloat(n.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(A,{text:i("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:n=>a({...s,scale3d:parseFloat(n.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(A,{text:i("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:t})}),e.jsx(se,{checked:s.show2DTaskLabels,onChange:n=>a({...s,show2DTaskLabels:n})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:scene.time"),query:t})}),e.jsx(ye,{options:fe,value:s.timeMode,onChange:n=>a({...s,timeMode:n}),iconOnly:!0})]})]}),$("terrain")&&e.jsxs(W,{title:i("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:Y&&$("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:t})}),e.jsx(se,{checked:s.terrain.simpleMode??!1,onChange:n=>te({simpleMode:n})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:Ee.map(n=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[n.key]?"active":""}`,onClick:()=>bs(n.key),title:n.label,children:n.icon},n.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("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:n=>te({fogDensity:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?i("config:fogValues.off"):s.terrain.fogDensity<=1?i("config:fogValues.low"):i("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("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:n=>te({brightness:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?i("config:brightnessValues.dark"):s.terrain.brightness<=1.2?i("config:brightnessValues.normal"):i("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:terrainSettings.floor"),query:t})}),e.jsx(ye,{options:we,value:s.terrain.floorStyle,onChange:n=>te({floorStyle:n}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:terrainSettings.sky"),query:t})}),e.jsx("div",{className:"sky-color-selector",children:je.map(n=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===n.value?"active":""}`,onClick:()=>te({skyColor:n.value}),title:n.label,style:{background:n.color}},n.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:terrainSettings.battlefieldSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:n=>te({battlefieldSize:parseInt(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),$("modelStyle")&&e.jsxs(W,{title:i("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:Y&&$("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("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:n=>ce({saturation:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?i("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?i("config:saturationValues.normal"):i("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("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:n=>ce({roughness:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?i("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?i("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?i("config:roughnessValues.normal"):i("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("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:n=>ce({metalness:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?i("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?i("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?i("config:metalnessValues.mixed"):i("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("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:n=>ce({emissiveBoost:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?i("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?i("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?i("config:glowValues.med"):i("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("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:n=>ce({envMapIntensity:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?i("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?i("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?i("config:reflectionValues.normal"):i("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:modelStyleSettings.wireframe"),query:t})}),e.jsx(se,{checked:s.modelStyle.wireframe,onChange:n=>ce({wireframe:n})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:modelStyleSettings.colorMode"),query:t})}),e.jsx(ye,{options:ue,value:s.modelStyle.colorMode,onChange:n=>ce({colorMode:n}),iconOnly:!0})]})]}),$("animations")&&e.jsxs(W,{title:i("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:Y&&$("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:animationSettings.idle"),query:t})}),e.jsx(ye,{options:ve,value:s.animations.idleAnimation,onChange:n=>Ye({idleAnimation:n}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:animationSettings.working"),query:t})}),e.jsx(ye,{options:ve,value:s.animations.workingAnimation,onChange:n=>Ye({workingAnimation:n}),iconOnly:!0})]})]}),$("secrets")&&e.jsx(W,{title:i("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:Y&&$("secrets"),children:e.jsx(St,{})}),$("claudeAccounts")&&e.jsx(W,{title:i("config:sections.claudeAccounts",{defaultValue:"Claude Accounts"}),storageKey:"claudeAccounts",defaultOpen:!1,forceOpen:Y&&$("claudeAccounts"),children:e.jsx(ct,{})}),$("grokAccounts")&&e.jsx(W,{title:i("config:sections.grokAccounts",{defaultValue:"Grok Accounts"}),storageKey:"grokAccounts",defaultOpen:!1,forceOpen:Y&&$("grokAccounts"),children:e.jsx(ss,{provider:"grok"})}),$("codexAccounts")&&e.jsx(W,{title:i("config:sections.codexAccounts",{defaultValue:"Codex Accounts"}),storageKey:"codexAccounts",defaultOpen:!1,forceOpen:Y&&$("codexAccounts"),children:e.jsx(ss,{provider:"codex"})}),$("systemPrompt")&&e.jsx(W,{title:i("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:Y&&$("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(A,{text:i("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>O(!0),children:i("config:systemPrompt.editPrompt")})]})}),$("data")&&e.jsx(W,{title:i("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:Y&&$("data"),children:e.jsx(Kt,{})}),Pe&&e.jsx(W,{title:i("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:Y&&Pe,children:e.jsx(Xt,{onOpenModal:n=>{n==="whatsapp"?S(!0):o==null||o(n)}})}),$("workflows")&&e.jsxs(W,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:Y&&$("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(A,{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:()=>d==null?void 0:d(),children:"Open Workflow Editor"})})]}),$("triggers")&&e.jsxs(W,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:Y&&$("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(A,{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:()=>f==null?void 0:f(),children:"Open Trigger Manager"})})]}),$("monitoring")&&e.jsxs(W,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:Y&&$("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(A,{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:()=>c==null?void 0:c(),children:"Open Monitoring & Logs"})})]}),$("statistics")&&e.jsxs(W,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:Y&&$("statistics"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(A,{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:()=>r==null?void 0:r(),children:"Open Statistics"})})]}),$("experimental")&&e.jsxs(W,{title:i("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:Y&&$("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(A,{text:i("config:experimental.2dView"),query:t})," ",e.jsx(_,{name:"map",size:12})]}),e.jsx(se,{checked:u.experimental2DView,onChange:n=>C.updateSettings({experimental2DView:n})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(A,{text:i("config:experimental.voiceAssistant"),query:t})," ",e.jsx(_,{name:"microphone",size:12})]}),e.jsx(se,{checked:u.experimentalVoiceAssistant,onChange:n=>C.updateSettings({experimentalVoiceAssistant:n})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(A,{text:i("config:experimental.tts"),query:t})," ",e.jsx(_,{name:"speaker-on",size:12})]}),e.jsx(se,{checked:u.experimentalTTS,onChange:n=>C.updateSettings({experimentalTTS:n})})]}),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(A,{text:i("config:experimental.echoPrompt"),query:t})}),e.jsx(se,{checked:u.experimentalEchoPrompt,onChange:async n=>{C.updateSettings({experimentalEchoPrompt:n});try{await Pt(n)}catch(D){console.error("Failed to sync echo prompt setting to server:",D)}}})]}),e.jsx("span",{className:"config-hint",children:i("config:experimental.hint")})]}),$("about")&&e.jsx(W,{title:i("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:Y&&$("about"),children:e.jsx(Yt,{})})]}),e.jsx(aa,{isOpen:N,onClose:()=>O(!1)}),e.jsx(la,{isOpen:B,onClose:()=>m(!1)}),e.jsx(pa,{isOpen:x,onClose:()=>L(!1)}),e.jsx(Ca,{isOpen:Z,onClose:()=>ne(!1)}),e.jsx(Aa,{isOpen:P,onClose:()=>S(!1),onOpenConfig:()=>m(!0),onOpenNotifications:()=>L(!0),onOpenHistory:()=>ne(!0)})]})}function Ka({onConfigChange:s,onToolChange:a,config:t,isOpen:o,onClose:c,onOpenBuildingModal:r,onOpenAreaExplorer:d,onOpenIntegrationsModal:f,onOpenMonitoringModal:i,onOpenStatisticsModal:u,onOpenWorkflowEditor:w,onOpenTriggerManager:j}){const{t:g}=J(["config","common"]),T=dt(),y=ut(),E=pt(),v=mt(),p=ht(),k=Array.from(T.values()),z=Array.from(y.values()),[F,K]=l.useState(""),H=l.useRef(null);if(l.useEffect(()=>{const h=I=>{I.key==="Escape"&&o&&c()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[o,c]),l.useEffect(()=>{if(o&&H.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const I=setTimeout(()=>{var M;(M=H.current)==null||M.focus()},50);return()=>clearTimeout(I)}},[o]),!o)return null;const q=h=>{a(p===h?null:h)},R=h=>{C.selectArea(v===h?null:h),a("select")},G=(h,I)=>{h.stopPropagation(),C.deleteArea(I)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:c}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:g("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:c,title:g("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:H,type:"text",placeholder:g("config:searchPlaceholder"),value:F,onChange:h=>K(h.target.value),className:"toolbox-search-input"}),F&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>K(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(W,{title:g("config:areas.title",{count:k.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${p==="select"?"active":""}`,onClick:()=>q("select"),title:g("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:()=>q("rectangle"),title:g("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:()=>q("circle"),title:g("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:k.length===0?e.jsx("div",{className:"areas-empty",children:g("config:areas.drawToCreate")}):k.map(h=>e.jsx(vt,{area:h,isSelected:v===h.id,onClick:()=>R(h.id),onDelete:I=>G(I,h.id)},h.id))})]})}),v&&e.jsx(kt,{area:T.get(v),onClose:()=>C.selectArea(null),onOpenFolder:d}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(W,{title:g("config:buildings.title",{count:z.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:h=>{h.stopPropagation(),r==null||r()},title:g("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:z.length===0?e.jsx("div",{className:"buildings-empty",children:g("config:buildings.clickToAdd")}):z.map(h=>e.jsx(yt,{building:h,isSelected:E.has(h.id),onClick:()=>{C.selectBuilding(E.has(h.id)?null:h.id)},onEdit:()=>r==null?void 0:r(h.id)},h.id))})})}),E.size===1&&(()=>{const h=Array.from(E)[0],I=y.get(h);return I?e.jsx(wt,{building:I,onClose:()=>C.selectBuilding(null),onOpenModal:()=>r==null?void 0:r(h)}):null})(),e.jsx(Ra,{config:t,onChange:s,searchQuery:F,onOpenIntegrationsModal:f,onOpenMonitoringModal:i,onOpenStatisticsModal:u,onOpenWorkflowEditor:w,onOpenTriggerManager:j})]})]})]})}export{Ka as Toolbox};