tide-commander 1.199.2 → 1.199.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/assets/{AudioPlayer-XaWiU7f4.js → AudioPlayer-A_DNcPYr.js} +1 -1
  3. package/dist/assets/{BossLogsModal-1tI-leZQ.js → BossLogsModal-7i0Dfzei.js} +1 -1
  4. package/dist/assets/{BossSpawnModal-CRoChH0J.js → BossSpawnModal-fBYj1bCx.js} +1 -1
  5. package/dist/assets/{ControlsModal-Cu7kwhct.js → ControlsModal-CUQiPa2F.js} +1 -1
  6. package/dist/assets/{DockerLogsModal-DFAiOsWH.js → DockerLogsModal--VKfyjl3.js} +1 -1
  7. package/dist/assets/{EmbeddedEditor-hnSknX5L.js → EmbeddedEditor-hNl7brYP.js} +1 -1
  8. package/dist/assets/{FcStdViewer-B_cbRz1w.js → FcStdViewer-B8y6Kf36.js} +1 -1
  9. package/dist/assets/{GcodeViewer-CFgwEZ6g.js → GcodeViewer-COcNJnpt.js} +1 -1
  10. package/dist/assets/{GlbViewer-14WSSXX7.js → GlbViewer-C0Xzz1eH.js} +1 -1
  11. package/dist/assets/{GmailOAuthSetup-waw2142C.js → GmailOAuthSetup-DUIzQ8J7.js} +1 -1
  12. package/dist/assets/{GoogleOAuthSetup-Bo59grtp.js → GoogleOAuthSetup-BTWZ_aJr.js} +1 -1
  13. package/dist/assets/{IframeModal-B3M77grB.js → IframeModal-B6PC5QX4.js} +1 -1
  14. package/dist/assets/{IntegrationsPanel-BLHrC0GX.js → IntegrationsPanel-DgYST-q4.js} +2 -2
  15. package/dist/assets/{LogViewerModal-CitlmDgQ.js → LogViewerModal-DmH5JCwc.js} +1 -1
  16. package/dist/assets/{MonitoringModal-BcKOCSRM.js → MonitoringModal-CSB6I7HA.js} +1 -1
  17. package/dist/assets/{PM2LogsModal-DrHpuMNf.js → PM2LogsModal-jT7I4Nrj.js} +1 -1
  18. package/dist/assets/{RestoreArchivedAreaModal-DcD3vdUJ.js → RestoreArchivedAreaModal-jp5Xsv_D.js} +1 -1
  19. package/dist/assets/{Scene2DCanvas-DKUcFYZW.js → Scene2DCanvas-BJf7xjcI.js} +1 -1
  20. package/dist/assets/{SceneManager-DPojKMM-.js → SceneManager-CjhMmFGP.js} +1 -1
  21. package/dist/assets/{SkillsPanel-CUW0prbh.js → SkillsPanel-CzLEygqp.js} +1 -1
  22. package/dist/assets/{SlackMultiInstanceSetup-YFYeZ94t.js → SlackMultiInstanceSetup-kIMTq331.js} +1 -1
  23. package/dist/assets/{SpawnModal-DPvq-R5b.js → SpawnModal-DeuiK-ft.js} +1 -1
  24. package/dist/assets/{StatisticsModal-Dt-Hof51.js → StatisticsModal-BbFqat0A.js} +1 -1
  25. package/dist/assets/{StlViewer-GyyomEax.js → StlViewer-CykV3bDr.js} +1 -1
  26. package/dist/assets/{SubordinateAssignmentModal-ahzGBjr4.js → SubordinateAssignmentModal-BEhgvADS.js} +1 -1
  27. package/dist/assets/{ThreeAreaSelector-Bj_mL6NG.js → ThreeAreaSelector-61KRvl6V.js} +1 -1
  28. package/dist/assets/{ThreeViewShortcuts-CKtE3yZV.js → ThreeViewShortcuts-BsuRkJQ3.js} +1 -1
  29. package/dist/assets/{TriggerManagerPanel-DtdbOk9B.js → TriggerManagerPanel-BUbAL2Mb.js} +1 -1
  30. package/dist/assets/{VideoPlayer-Crq-MwPS.js → VideoPlayer-Bow0E8JN.js} +1 -1
  31. package/dist/assets/{WorkflowEditorPanel-CitR9Em3.js → WorkflowEditorPanel-D5sSWYl7.js} +1 -1
  32. package/dist/assets/{abnfDiagram-VRR7QNED-QFcuJYPe.js → abnfDiagram-VRR7QNED-C2HvJaIu.js} +1 -1
  33. package/dist/assets/{arc-CLuSzQ4E.js → arc-DIfPSJnG.js} +1 -1
  34. package/dist/assets/{architectureDiagram-ZJ3FMSHR-DlhVck93.js → architectureDiagram-ZJ3FMSHR-JwB01V03.js} +1 -1
  35. package/dist/assets/{area-logos-DYARiYqI.js → area-logos-CzRaMbh2.js} +1 -1
  36. package/dist/assets/{blockDiagram-677ZJIJ3-CJwOmsfj.js → blockDiagram-677ZJIJ3-Zr1rRoej.js} +1 -1
  37. package/dist/assets/{c4Diagram-LMCZKHZV-OsgCNPWJ.js → c4Diagram-LMCZKHZV-D1bI4OAN.js} +1 -1
  38. package/dist/assets/channel-D875PBiW.js +1 -0
  39. package/dist/assets/{chunk-2Q5K7J3B-KG-L7vvm.js → chunk-2Q5K7J3B-IBPe4Q7q.js} +1 -1
  40. package/dist/assets/{chunk-32BRIVSS-BXGbqO9v.js → chunk-32BRIVSS-rQSWhcb_.js} +1 -1
  41. package/dist/assets/{chunk-5VM5RSS4-BWXkm8f0.js → chunk-5VM5RSS4-Dmv7dmVy.js} +1 -1
  42. package/dist/assets/{chunk-EX3LRPZG-7-8ulJ19.js → chunk-EX3LRPZG-TDT_cQou.js} +1 -1
  43. package/dist/assets/{chunk-JWPE2WC7-mkwFN5xu.js → chunk-JWPE2WC7-C0GVNe-V.js} +1 -1
  44. package/dist/assets/{chunk-MOJQB5TN-WEfWznKE.js → chunk-MOJQB5TN-__mP_faY.js} +1 -1
  45. package/dist/assets/{chunk-RYQCIY6F-ByP5odu4.js → chunk-RYQCIY6F-ecSBBPze.js} +1 -1
  46. package/dist/assets/{chunk-V7JOEXUC-yWHmp1L1.js → chunk-V7JOEXUC-BC56iR05.js} +1 -1
  47. package/dist/assets/{chunk-VR4S4FIN-DHbZaHzt.js → chunk-VR4S4FIN-DERvXVps.js} +1 -1
  48. package/dist/assets/{chunk-XXDRQBXY-SNa-Wh3U.js → chunk-XXDRQBXY-BVn84nw2.js} +1 -1
  49. package/dist/assets/classDiagram-OUVF2IWQ-EG57DD_l.js +1 -0
  50. package/dist/assets/classDiagram-v2-EOCWNBFH-EG57DD_l.js +1 -0
  51. package/dist/assets/{cose-bilkent-JH36ORCC-CyxHYUhP.js → cose-bilkent-JH36ORCC-mg3hjIh0.js} +1 -1
  52. package/dist/assets/{cynefin-VYW2F7L2-BvwjSDiQ.js → cynefin-VYW2F7L2-BMZ4knrn.js} +1 -1
  53. package/dist/assets/{cynefinDiagram-TSTJHNR4-C8doInhn.js → cynefinDiagram-TSTJHNR4-CnOuLqXO.js} +1 -1
  54. package/dist/assets/{dagre-VKFMJZFB-BNDcupek.js → dagre-VKFMJZFB-BqmESFSV.js} +1 -1
  55. package/dist/assets/{diagram-FQU43EPY-Bst0bBnQ.js → diagram-FQU43EPY-BO4mTTgt.js} +1 -1
  56. package/dist/assets/{diagram-G47NLZAW-CfEv0aTY.js → diagram-G47NLZAW-txAn-X18.js} +1 -1
  57. package/dist/assets/{diagram-NH7WQ7WH-B7MYvWXL.js → diagram-NH7WQ7WH-BpGKYTxX.js} +1 -1
  58. package/dist/assets/{diagram-OA4YK3LP-BIzII0d2.js → diagram-OA4YK3LP-BWgk4USe.js} +1 -1
  59. package/dist/assets/{diagram-WEI45ONY-D5yd1HWr.js → diagram-WEI45ONY-CgqpLIRx.js} +1 -1
  60. package/dist/assets/{ebnfDiagram-CCIWWBDH-gyhVYUos.js → ebnfDiagram-CCIWWBDH-CJXyC9CG.js} +1 -1
  61. package/dist/assets/{erDiagram-Q63AITRT-Duz-DwfE.js → erDiagram-Q63AITRT-B419ak6F.js} +1 -1
  62. package/dist/assets/{flowDiagram-23GEKE2U-CrnARkmw.js → flowDiagram-23GEKE2U-CaoVLCFn.js} +1 -1
  63. package/dist/assets/{ganttDiagram-NO4QXBWP-D6cBteIN.js → ganttDiagram-NO4QXBWP-DzKf09RL.js} +1 -1
  64. package/dist/assets/{gitGraphDiagram-IHSO6WYX-CMHfr_lR.js → gitGraphDiagram-IHSO6WYX-BcJSGanA.js} +1 -1
  65. package/dist/assets/{index-D5O_0aq9.js → index-BTxaN45Z.js} +1 -1
  66. package/dist/assets/{index-DeqoOoo6.js → index-Bf7yerGj.js} +1 -1
  67. package/dist/assets/{index-fiC5OXgR.js → index-Bhl4oi94.js} +1 -1
  68. package/dist/assets/{index-2427ATYD.js → index-CNMfqZTR.js} +3 -3
  69. package/dist/assets/{index-DJKuwqJG.js → index-D-T-XZwp.js} +2 -2
  70. package/dist/assets/{index-B1vOCcI-.js → index-D4h5z3h7.js} +1 -1
  71. package/dist/assets/{index-D5pIRxFm.js → index-DGC0uvv8.js} +1 -1
  72. package/dist/assets/{index-CbMtvQTH.js → index-DKJGKvx6.js} +1 -1
  73. package/dist/assets/{index-B5wHDczA.js → index-DdXT34nf.js} +1 -1
  74. package/dist/assets/{infoDiagram-FWYZ7A6U-Mvk2Mpp3.js → infoDiagram-FWYZ7A6U-DmSCjl-a.js} +1 -1
  75. package/dist/assets/{ishikawaDiagram-FXEZZL3T-DXsaNDYg.js → ishikawaDiagram-FXEZZL3T-C2aoYMOy.js} +1 -1
  76. package/dist/assets/{journeyDiagram-5HDEW3XC-6QlK8xHN.js → journeyDiagram-5HDEW3XC-C-GVB1KY.js} +1 -1
  77. package/dist/assets/{kanban-definition-HUTT4EX6-D5EeRs07.js → kanban-definition-HUTT4EX6-IWOTfPcO.js} +1 -1
  78. package/dist/assets/{linear-D_aP9MD5.js → linear-BjaKb-fM.js} +1 -1
  79. package/dist/assets/{main-Dk3qq80S.js → main-BTH4eRQ6.js} +97 -97
  80. package/dist/assets/main-Dzc0Sg9A.css +1 -0
  81. package/dist/assets/{mermaid.core-CEculPxD.js → mermaid.core-CAEdJZ_w.js} +4 -4
  82. package/dist/assets/{mindmap-definition-LN4V7U3C-Vjj9vgEN.js → mindmap-definition-LN4V7U3C-BkCFpMNJ.js} +1 -1
  83. package/dist/assets/{pegDiagram-2B236MQR-B-AwbaoO.js → pegDiagram-2B236MQR-BKiRmui-.js} +1 -1
  84. package/dist/assets/{pieDiagram-ENE6RG2P-D5o1UYPK.js → pieDiagram-ENE6RG2P-BP8J15I1.js} +1 -1
  85. package/dist/assets/{quadrantDiagram-ABIIQ3AL-Bl_Rbmz-.js → quadrantDiagram-ABIIQ3AL-BM_bLOrJ.js} +1 -1
  86. package/dist/assets/{railroadDiagram-RFXS5EU6-CW-qy1dp.js → railroadDiagram-RFXS5EU6-BuzJbVwQ.js} +1 -1
  87. package/dist/assets/{requirementDiagram-TGXJPOKE-DGUQpy3K.js → requirementDiagram-TGXJPOKE-BFH7PfsI.js} +1 -1
  88. package/dist/assets/{sankeyDiagram-HTMAVEWB-CUlWZH9G.js → sankeyDiagram-HTMAVEWB-B_LNgbZM.js} +1 -1
  89. package/dist/assets/{sequenceDiagram-DBY2YBRQ-CeDVJrbJ.js → sequenceDiagram-DBY2YBRQ-Dpx20yKk.js} +1 -1
  90. package/dist/assets/{sizeCapture-X5ZJPWSS-BGSL3ofq.js → sizeCapture-X5ZJPWSS-DozwVBxi.js} +1 -1
  91. package/dist/assets/{stateDiagram-2N3HPSRC-9A8tAPIu.js → stateDiagram-2N3HPSRC-Dz7I61Z2.js} +1 -1
  92. package/dist/assets/stateDiagram-v2-6OUMAXLB-BFOToQX1.js +1 -0
  93. package/dist/assets/{swimlanes-5IMT3BWC-CipRR1uk.js → swimlanes-5IMT3BWC-IF3gQbtc.js} +2 -2
  94. package/dist/assets/swimlanesDiagram-G3AALYLV-CF7hL7qo.js +8 -0
  95. package/dist/assets/{timeline-definition-FHXFAJF6-IgrCsFe-.js → timeline-definition-FHXFAJF6-72sDxnmY.js} +1 -1
  96. package/dist/assets/{vennDiagram-L72KCM5P-okSGsDy3.js → vennDiagram-L72KCM5P-nfw568sB.js} +1 -1
  97. package/dist/assets/{wardleyDiagram-EHGQE667-G0RLggUt.js → wardleyDiagram-EHGQE667-DoF1Ii5p.js} +1 -1
  98. package/dist/assets/{web-BPOqvnJL.js → web-C8qAHcxt.js} +1 -1
  99. package/dist/assets/{web-B5BfOO5C.js → web-D97lBSvE.js} +1 -1
  100. package/dist/assets/{web-Q8DwQW0W.js → web-DlKkI5gM.js} +1 -1
  101. package/dist/assets/{xychartDiagram-FW5EYKEG-DtVJEFyI.js → xychartDiagram-FW5EYKEG-gGwkb3hj.js} +1 -1
  102. package/dist/build-info.json +1 -1
  103. package/dist/index.html +2 -2
  104. package/package.json +1 -1
  105. package/dist/assets/channel-cpl_NpAy.js +0 -1
  106. package/dist/assets/classDiagram-OUVF2IWQ-D_lsO4mm.js +0 -1
  107. package/dist/assets/classDiagram-v2-EOCWNBFH-D_lsO4mm.js +0 -1
  108. package/dist/assets/main-B2ZLroL1.css +0 -1
  109. package/dist/assets/stateDiagram-v2-6OUMAXLB-DzVFFq0g.js +0 -1
  110. package/dist/assets/swimlanesDiagram-G3AALYLV-XDQw-C4e.js +0 -8
@@ -1 +1 @@
1
- import{r as l,j as e,I,u as ee,bV as js,ai as vs,bW as Ms,bY as Bs,s as x,cS as Us,F as zs,cT as Vs,Z as xe,N as Y,aY as q,c as ye,d as ke,cU as Ks,cV as Hs,cW as qs,cX as Ws,cY as Gs,cZ as Ys,c_ as Js,c$ as Ns,d0 as Xs,d1 as Zs,d2 as Qs,aX as et,av as st,a4 as _e,n as tt,d3 as ws,d4 as at,d5 as Ze,d6 as nt,d7 as ot,d8 as it,d9 as lt,da as ct,db as rt,dc as dt,br as ut,k as pt,m as ht,S as Ee,dd as mt,de as gt,df as ft,dg as qe,dh as xt,di as bt,B as jt,b_ as rs,dj as vt,dk as Nt,dl as wt,dm as yt,dn as ys,dp as ds,dq as ks,dr as kt,ds as St,dt as Pe,du as Ct,dv as We,dw as us,dx as ps,bR as Ge,y as Be,x as At,dy as Ye,dz as Tt,dA as hs,dB as Et,dC as Pt,dD as _t,a0 as It,f as Dt,dE as $t,dF as Lt,dG as Ot}from"./main-Dk3qq80S.js";import{g as Ft,d as Rt,u as Mt}from"./area-logos-DYARiYqI.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-DYBBrXTx.js";const Ss="tide-toolbox-collapse";function Bt(s,n){try{const t=localStorage.getItem(`${Ss}-${s}`);if(t!==null)return t==="true"}catch{}return n}function Ut(s,n){try{localStorage.setItem(`${Ss}-${s}`,String(n))}catch{}}function H({title:s,storageKey:n,defaultOpen:t=!1,forceOpen:i=!1,children:d,headerExtra:c}){const[r,g]=l.useState(()=>n?Bt(n,t):t),o=()=>{const N=!r;g(N),n&&Ut(n,N)},u=i||r;return e.jsxs("div",{className:`collapsible-section ${u?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:o,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[c,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(I,{name:u?"caret-down":"caret-right",size:10})})]})]}),u&&e.jsx("div",{className:"collapsible-content",children:d})]})}function zt({area:s,isSelected:n,onClick:t,onDelete:i}){const{t:d}=ee(["config","common"]),c=s.assignedAgentIds.length,r=s.type==="rectangle"?d("config:areas.rect"):d("config:areas.circle");return e.jsxs("div",{className:`area-item ${n?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[r," ",c>0&&`• ${c} ${c>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:i,title:d("config:areas.deleteArea"),children:"×"})]})}function Vt({building:s,isSelected:n,onClick:t,onEdit:i}){var g;const{t:d}=ee(["config"]),c=((g=s.pm2Status)==null?void 0:g.ports)||[],r=(o,u)=>{o.stopPropagation(),window.open(`http://${window.location.hostname}:${u}`,"_blank")};return e.jsxs("div",{className:`building-item ${n?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:js[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(I,{name:vs(s.type),size:16})}),e.jsxs("div",{className:"building-info",children:[e.jsx("div",{className:"building-name",children:s.name}),e.jsxs("div",{className:"building-meta",children:[s.type,c.length>0&&e.jsx("span",{className:"building-ports",children:c.map(o=>e.jsxs("a",{href:`http://${window.location.hostname}:${o}`,className:"building-port-link",onClick:u=>r(u,o),title:`Open :${o}`,children:[":",o]},o))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:o=>{o.stopPropagation(),i()},title:d("config:buildings.editBuilding"),children:e.jsx(I,{name:"gear",size:14})})]})}function Kt({building:s,onClose:n,onOpenModal:t}){var u,N,S,m,_,v,P,b;const{t:i}=ee(["config","common"]),c=Ms().get(s.id)||[],r=Bs[s.style||"server-rack"],g=p=>{x.sendBuildingCommand(s.id,p)},o=p=>{window.open(p,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx(I,{name:vs(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:js[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:n,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:i("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:i("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:r.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children:i("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:i("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>g("start"),disabled:!((u=s.commands)!=null&&u.start)||s.status==="running",title:((N=s.commands)==null?void 0:N.start)||i("config:buildings.noStartCommand"),children:[e.jsx(I,{name:"play",size:12})," ",i("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>g("stop"),disabled:!((S=s.commands)!=null&&S.stop)||s.status==="stopped",title:((m=s.commands)==null?void 0:m.stop)||i("config:buildings.noStopCommand"),children:[e.jsx(I,{name:"stop",size:12,weight:"fill"})," ",i("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>g("restart"),disabled:!((_=s.commands)!=null&&_.restart),title:((v=s.commands)==null?void 0:v.restart)||i("config:buildings.noRestartCommand"),children:[e.jsx(I,{name:"refresh",size:12})," ",i("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>g("healthCheck"),disabled:!((P=s.commands)!=null&&P.healthCheck),title:((b=s.commands)==null?void 0:b.healthCheck)||i("config:buildings.noHealthCheck"),children:[e.jsx(I,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:i("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((p,C)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>o(p.url),title:p.url,children:[e.jsx(I,{name:"link",size:12})," ",p.label||p.url]},C))})]}),c.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[i("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>x.clearBuildingLogs(s.id),title:i("common:buttons.clear"),children:i("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:c.slice(-5).map((p,C)=>e.jsx("div",{className:"building-editor-log-entry",children:p},C))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(I,{name:"gear",size:12})," ",i("config:buildings.fullSettings")]})})]})}const Ht=[{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 qt({area:s,onClose:n,onOpenFolder:t}){var ae;const{t:i}=ee(["config","common"]),[d,c]=l.useState(s.name),[r,g]=l.useState(s.prompt||""),[o,u]=l.useState(!1),[N,S]=l.useState(""),[m,_]=l.useState(!1),v=l.useRef(null);l.useEffect(()=>{c(s.name)},[s.id,s.name]),l.useEffect(()=>{g(s.prompt||"")},[s.id,s.prompt]);const P=j=>{const L=j.target.value;c(L),x.updateArea(s.id,{name:L})},b=j=>{x.updateArea(s.id,{color:j})},p=j=>{const L=j.target.value;g(L),x.updateArea(s.id,{prompt:L})},C=()=>{N.trim()&&(x.addDirectoryToArea(s.id,N.trim()),S(""),u(!1))},B=(j,L)=>{L.stopPropagation(),x.removeDirectoryFromArea(s.id,j)},F=()=>{x.bringAreaToFront(s.id)},J=()=>{x.sendAreaToBack(s.id)},K=l.useCallback(()=>{let j=2,L=2;s.type==="rectangle"&&s.width&&s.height?(j=s.width,L=s.height):s.type==="circle"&&s.radius&&(j=s.radius*1.414,L=s.radius*1.414);const z=Math.min(j,L)*.4;return{width:Math.round(z*10)/10,height:Math.round(z*10)/10}},[s.type,s.width,s.height,s.radius]),X=async j=>{var z;const L=(z=j.target.files)==null?void 0:z[0];if(L){_(!0);try{const w=await Mt(s.id,L),$=K();x.updateArea(s.id,{logo:{filename:w.filename,position:"center",width:$.width,height:$.height,keepAspectRatio:!0,opacity:.8}})}catch(w){console.error("Failed to upload logo:",w)}finally{_(!1),v.current&&(v.current.value="")}}},U=async()=>{try{await Rt(s.id),x.updateArea(s.id,{logo:void 0})}catch(j){console.error("Failed to remove logo:",j)}},Z=j=>{s.logo&&x.updateArea(s.id,{logo:{...s.logo,position:j}})},h=j=>{if(!s.logo)return;const L=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const z=s.logo.height/s.logo.width;x.updateArea(s.id,{logo:{...s.logo,width:L,height:Math.round(L*z*10)/10}})}else x.updateArea(s.id,{logo:{...s.logo,width:L}})},E=j=>{if(!s.logo)return;const L=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const z=s.logo.width/s.logo.height;x.updateArea(s.id,{logo:{...s.logo,height:L,width:Math.round(L*z*10)/10}})}else x.updateArea(s.id,{logo:{...s.logo,height:L}})},R=()=>{s.logo&&x.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},W=j=>{s.logo&&x.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(j.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:i("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:n,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange:P,placeholder:i("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:Us.map(j=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===j?"selected":""}`,style:{backgroundColor:j},onClick:()=>b(j),"aria-label":`Set area color ${j}`,"aria-pressed":s.color===j,title:j},j))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:F,title:i("config:areas.bringToFront"),children:[e.jsx(I,{name:"arrow-up",size:12})," ",i("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:J,title:i("config:areas.sendToBack"),children:[e.jsx(I,{name:"arrow-down",size:12})," ",i("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:i("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(ae=s.logo)!=null&&ae.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Ft(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:U,children:i("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var j;return(j=v.current)==null?void 0:j.click()},disabled:m,children:m?"...":e.jsx(I,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:Ht.map(({key:j,labelKey:L})=>{var z;return e.jsx("button",{className:`area-logo-pos-btn ${((z=s.logo)==null?void 0:z.position)===j?"active":""}`,onClick:()=>Z(j),children:i(`config:areas.${L}`)},j)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:i("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:h,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:i("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:E,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:i("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:R}),i("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("config:areas.logoOpacity")}),e.jsxs("div",{className:"area-logo-opacity-row",children:[e.jsx("input",{type:"range",min:0,max:1,step:.05,value:s.logo.opacity??.8,onChange:W,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var j;return(j=v.current)==null?void 0:j.click()},disabled:m,children:m?"...":i("config:areas.uploadLogo")}),e.jsx("input",{ref:v,type:"file",accept:"image/*",style:{display:"none"},onChange:X})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:i("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(j=>e.jsxs("div",{className:"area-folder-item",title:j,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:i("config:areas.openFolder"),children:e.jsx(I,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:j.split("/").pop()||j}),e.jsx("button",{className:"area-folder-remove",onClick:L=>B(j,L),title:i("config:areas.removeFolder"),children:"×"})]},j)),o?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(zs,{value:N,onChange:S,onSubmit:C,placeholder:i("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:C,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>u(!0),children:i("config:areas.addFolder")})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:i("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:r,onChange:p,placeholder:i("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:i("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:i("config:areas.rightClickUnassign")})]})]})}function Wt(){const{t:s}=ee(["config","common"]),n=Vs(),[t,i]=l.useState(!1),[d,c]=l.useState(null),[r,g]=l.useState({name:"",key:"",value:"",description:""}),[o,u]=l.useState(null),N=()=>{i(!0),c(null),g({name:"",key:"",value:"",description:""})},S=p=>{c(p.id),i(!1),g({name:p.name,key:p.key,value:p.value,description:p.description||""})},m=()=>{i(!1),c(null),g({name:"",key:"",value:"",description:""})},_=()=>{!r.name.trim()||!r.key.trim()||(d?x.updateSecret(d,{name:r.name.trim(),key:r.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:r.value,description:r.description.trim()||void 0}):x.createSecret({name:r.name.trim(),key:r.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:r.value,description:r.description.trim()||void 0}),m())},v=p=>{u(p)},P=()=>{o&&(x.deleteSecret(o),d===o&&m())},b=p=>{navigator.clipboard.writeText(`{{${p}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children:n.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):n.map(p=>e.jsxs("div",{className:`secret-item ${d===p.id?"editing":""}`,children:[e.jsxs("div",{className:"secret-item-header",children:[e.jsxs("div",{className:"secret-item-info",children:[e.jsx("span",{className:"secret-item-name",children:p.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>b(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:()=>S(p),title:s("common:buttons.edit"),children:e.jsx(I,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>v(p.id),title:s("common:buttons.delete"),children:"×"})]})]}),p.description&&e.jsx("div",{className:"secret-item-description",children:p.description})]},p.id))}),(t||d)&&e.jsxs("div",{className:"secret-form",children:[e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.name")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.namePlaceholder"),value:r.name,onChange:p=>g({...r,name:p.target.value}),autoFocus:!0})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:"Key"}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.keyPlaceholder"),value:r.key,onChange:p=>g({...r,key:p.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${r.key||"KEY"}}}`})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("config:secrets.secretValue")}),e.jsx("input",{type:"password",className:"secret-form-input",placeholder:s("config:secrets.valuePlaceholder"),value:r.value,onChange:p=>g({...r,value:p.target.value})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.description")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.descriptionPlaceholder"),value:r.description,onChange:p=>g({...r,description:p.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:m,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:_,disabled:!r.name.trim()||!r.key.trim(),children:s(d?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:N,children:s("config:secrets.addSecret")}),e.jsx(xe,{isOpen:o!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:P,onClose:()=>u(null)})]})}async function Gt(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch system prompt: ${n.statusText}`);return(await n.json()).prompt||""}async function Yt(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function Jt(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to clear system prompt: ${n.statusText}`)}async function Xt(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch echo prompt setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Zt(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function Qt(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex binary path: ${n.statusText}`);return(await n.json()).path||""}async function ea(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function sa(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch tmux mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ta(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function aa(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch interactive mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function na(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function oa(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/codex-app-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex app-server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ia(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/codex-app-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update codex app-server mode setting: ${t.statusText}`)}async function la(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/opencode-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch opencode server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ca(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/opencode-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update opencode server mode setting: ${t.statusText}`)}async function ra(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/pi-rpc-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch pi RPC mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function da(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/pi-rpc-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update pi RPC mode setting: ${t.statusText}`)}async function ua(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch backup status: ${n.statusText}`);return n.json()}async function pa(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok){const i=await t.json().catch(()=>({}));throw new Error(i.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function ha({checked:s,onChange:n,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:i=>n(i.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function ma(){const{t:s}=ee(["config","common"]),[n,t]=l.useState([]),[i,d]=l.useState(new Set),[c,r]=l.useState(new Set),[g,o]=l.useState(!1),[u,N]=l.useState(!1),[S,m]=l.useState(null),[_,v]=l.useState(null),[P,b]=l.useState(null),[p,C]=l.useState(null),[B,F]=l.useState(!1),[J,K]=l.useState(null);l.useEffect(()=>{ye(ke("/api/config/categories")).then(w=>w.json()).then(w=>{const $=Array.isArray(w)?w:[];t($),d(new Set($.map(O=>O.id)))}).catch(w=>console.error("Failed to fetch config categories:",w))},[]),l.useEffect(()=>{ua().then(C).catch(w=>{console.error("Failed to fetch backup status:",w),K(w.message||"Failed to fetch backup status")})},[]);const X=async w=>{if(!B){F(!0),K(null);try{const $=await pa(w);C($)}catch($){K($.message||"Failed to update backup setting")}finally{F(!1)}}},U=w=>{d($=>{const O=new Set($);return O.has(w)?O.delete(w):O.add(w),O})},Z=w=>{r($=>{const O=new Set($);return O.has(w)?O.delete(w):O.add(w),O})},h=()=>d(new Set(n.map(w=>w.id))),E=()=>d(new Set),R=()=>{_&&r(new Set(_.categories.map(w=>w.id)))},W=()=>r(new Set),ae=async()=>{var w;if(i.size!==0){o(!0),b(null);try{const $=Array.from(i).join(","),O=await ye(ke(`/api/config/export?categories=${$}`));if(!O.ok)throw new Error("Export failed");const se=await O.blob(),ne=window.URL.createObjectURL(se),T=document.createElement("a");T.href=ne;const y=O.headers.get("Content-Disposition"),te=((w=y==null?void 0:y.match(/filename="(.+)"/))==null?void 0:w[1])||"tide-commander-config.zip";T.download=te,document.body.appendChild(T),T.click(),document.body.removeChild(T),window.URL.revokeObjectURL(ne),b({type:"success",text:s("config:data.exportSuccess")})}catch($){b({type:"error",text:$.message||"Export failed"})}finally{o(!1)}}},j=async w=>{var O;const $=(O=w.target.files)==null?void 0:O[0];if($){m($),b(null),v(null),r(new Set);try{const se=await ye(ke("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await $.arrayBuffer()});if(!se.ok){const y=await se.json();throw new Error(y.error||"Failed to preview config file")}const ne=await se.json(),T=Array.isArray(ne.categories)?ne.categories:[];v({...ne,categories:T}),r(new Set(T.map(y=>y.id)))}catch(se){b({type:"error",text:se.message||"Failed to read config file"}),m(null)}}},L=async()=>{if(!(!S||c.size===0)){N(!0),b(null);try{const w=Array.from(c).join(","),$=await ye(ke(`/api/config/import?categories=${w}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await S.arrayBuffer()}),O=await $.json();if(!$.ok)throw new Error(O.error||"Import failed");b({type:"success",text:O.message||s("config:data.importSuccess")}),m(null),v(null),r(new Set)}catch(w){b({type:"error",text:w.message||"Import failed"})}finally{N(!1)}}},z=()=>{m(null),v(null),r(new Set),b(null)};return e.jsxs("div",{className:"data-section",children:[P&&e.jsx("div",{className:`data-message data-message-${P.type}`,children:P.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(ha,{checked:!!(p!=null&&p.enabled),disabled:B||!p,onChange:X})]}),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…"}),J&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:J})]})]}),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:E,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:n.map(w=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:i.has(w.id),onChange:()=>U(w.id)}),e.jsx("span",{className:"data-category-name",children:w.name})]},w.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ae,disabled:g||i.size===0,children:g?s("config:data.exporting"):s("config:data.exportCount",{count:i.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),S?_?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:S.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(_.exportedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-subtitle",children:s("config:data.selectToImport")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:R,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:W,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:_.categories.map(w=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:c.has(w.id),onChange:()=>Z(w.id)}),e.jsx("span",{className:"data-category-name",children:w.name}),w.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",w.fileCount," ",s("config:data.files"),")"]})]},w.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:z,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:L,disabled:u||c.size===0,children:u?s("config:data.importing"):s("config:data.importCount",{count:c.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:j,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function ga(){const[s,n]=l.useState(()=>Ks()),t=i=>{n(i);const d=Gs(i);Ys(d)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:Hs.map(i=>e.jsxs("button",{className:`theme-option ${s===i.id?"active":""}`,onClick:()=>t(i.id),title:i.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:i.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:i.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:i.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:i.name})]},i.id))})})}function fa(){const{t:s}=ee(["config"]),{installInfo:n,phase:t,output:i,error:d,newVersion:c,autoRestart:r,refreshInstallInfo:g,runUpdate:o,reset:u}=Js(),[N,S]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{g()},[g]),l.useEffect(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)},[i]);const _=l.useCallback(()=>{S(!0)},[]),v=l.useCallback(()=>{S(!1)},[]),P=l.useCallback(()=>{S(!1),o()},[o]),b=l.useCallback(()=>{u(),S(!1),g()},[u,g]),p=Ns.isNativePlatform(),C=s(p?"config:about.autoUpdateServerTitle":"config:about.autoUpdateTitle");return n?n.isGlobalInstall?n.autoUpdateSupported?!n.updateAvailable&&t==="idle"?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:C}),t==="idle"&&!N&&n.updateAvailable&&e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsxs("span",{className:"about-autoupdate-versions",children:[e.jsx("span",{className:"about-autoupdate-current",children:n.currentVersion}),e.jsx("span",{className:"about-autoupdate-arrow",children:"→"}),e.jsx("span",{className:"about-autoupdate-latest",children:n.latestVersion})]}),e.jsx("button",{className:"about-update-btn download",onClick:_,children:s("config:about.autoUpdateButton")})]}),t==="idle"&&N&&e.jsxs("div",{className:"about-autoupdate-confirm",children:[e.jsx("div",{className:"about-autoupdate-confirm-title",children:s("config:about.autoUpdateConfirmTitle")}),e.jsx("div",{className:"about-autoupdate-confirm-body",children:s("config:about.autoUpdateConfirmBody")}),e.jsxs("div",{className:"about-autoupdate-confirm-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:v,children:s("config:about.autoUpdateCancel")}),e.jsx("button",{className:"about-update-btn download",onClick:P,children:s("config:about.autoUpdateConfirm")})]})]}),(t==="running"||t==="success"||t==="failed")&&e.jsxs("div",{className:"about-autoupdate-stream",children:[e.jsxs("div",{className:"about-autoupdate-stream-title",children:[t==="running"&&s("config:about.autoUpdateRunning"),t==="success"&&s("config:about.autoUpdateSuccess"),t==="failed"&&s("config:about.autoUpdateFailed")]}),e.jsx("pre",{ref:m,className:"about-autoupdate-output",children:i||"..."}),t==="success"&&e.jsxs("div",{className:"about-autoupdate-success-hint",children:[c&&e.jsxs("div",{className:"about-autoupdate-newversion",children:["v",c]}),e.jsx("div",{children:s(r?"config:about.autoUpdateReconnectHint":"config:about.autoUpdateRestartHint")})]}),t==="failed"&&d&&e.jsx("div",{className:"about-update-error",children:d}),(t==="success"||t==="failed")&&e.jsx("div",{className:"about-autoupdate-stream-actions",children:e.jsx("button",{className:"about-update-btn changelog",onClick:b,children:s("config:about.autoUpdateClose")})})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:C}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdatePackageManagerNotice",{pm:n.packageManager})}),n.suggestedManualCommand&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"about-autoupdate-manualhint",children:s("config:about.autoUpdateManualCommand")}),e.jsx("pre",{className:"about-autoupdate-manualcmd",children:n.suggestedManualCommand})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:C}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdateDevMode")})]}):null}function xa(){const{t:s}=ee(["config"]),[n,t]=l.useState(null),[i,d]=l.useState(!1),[c,r]=l.useState(null);l.useEffect(()=>{Xs().then(t).catch(N=>r(N.message))},[]);const g=l.useCallback(async N=>{if(!i){d(!0),r(null);try{t(await Zs(N))}catch(S){r(S.message)}finally{d(!1)}}},[i]),o=Ns.isNativePlatform(),u=s(o?"config:about.unattendedServerTitle":"config:about.unattendedTitle");return!n&&!c?null:n?o&&!n.supported?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:u}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:about.unattendedDesc")}),e.jsxs("label",{className:"config-toggle",style:n.supported?void 0:{opacity:.5},children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:n.enabled,disabled:i||!n.supported,onChange:N=>void g(N.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),!n.supported&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedUnsupported")}),n.supported&&n.enabled&&n.pendingRestartVersion&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedPendingRestart",{version:n.pendingRestartVersion})}),n.supported&&n.enabled&&!n.pendingRestartVersion&&n.lastResult&&e.jsx("div",{className:"about-autoupdate-devnote",children:n.lastResult}),c&&e.jsx("div",{className:"about-update-error",children:c})]}):o?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:u}),e.jsx("div",{className:"about-update-error",children:c})]})}function ba(){var B;const{t:s}=ee(["config"]),{isAndroid:n,supported:t,otaActive:i,bundleState:d,serverInfo:c,infoError:r,updateAvailable:g,phase:o,progress:u,error:N,autoSync:S,checkNow:m,syncNow:_,resetToBundled:v,setAutoSync:P}=Qs(),[b,p]=l.useState(null),C=l.useRef(m);return C.current=m,l.useEffect(()=>{n&&(C.current(!1),et.getInfo().then(F=>p(F.version)).catch(()=>{}))},[n]),!n||t===!1?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:webBundle.title")}),e.jsxs("div",{className:"about-autoupdate-devnote",children:[i?s("config:webBundle.sourceOta",{hash:((B=d==null?void 0:d.hash)==null?void 0:B.slice(0,8))??"?"}):s("config:webBundle.sourceBundled"),b&&` · ${s("config:webBundle.apkVersion",{version:b})}`]}),c?e.jsxs("div",{className:"about-autoupdate-devnote",children:[s("config:webBundle.serverBundle",{version:c.version,hash:c.hash.slice(0,8)})," — ",s(g?"config:webBundle.updateAvailable":"config:webBundle.upToDate")]}):r&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:webBundle.serverUnavailable")}),N&&e.jsx("div",{className:"about-update-error",children:N}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:webBundle.autoSync")}),e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:S,onChange:F=>P(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 _(),disabled:o!=="idle"||!c,children:o==="syncing"?s("config:webBundle.syncingPct",{percent:u??0}):s("config:webBundle.syncNow")}),i&&e.jsx("button",{className:"about-update-btn changelog",onClick:()=>void v(),children:s("config:webBundle.reset")})]})]})}function ja(){const{t:s}=ee(["config"]),{updateAvailable:n,updateInfo:t,recentReleases:i,isChecking:d,error:c,currentVersion:r,isAndroid:g,downloadPhase:o,downloadProgress:u,checkForUpdate:N,downloadAndInstall:S,openReleasePage:m}=qs(),[_,v]=l.useState(!1),P=p=>p?`${(p/(1024*1024)).toFixed(1)} MB`:"",b=p=>new Date(p).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:e.jsx(I,{name:"waves",size:24})}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:r}),n&&t?e.jsx("span",{className:"about-version-update-badge",onClick:m,title:`Update available: ${t.version}`,children:t.version}):e.jsxs("a",{href:"https://github.com/deivid11/tide-commander/releases",target:"_blank",rel:"noopener noreferrer",className:"about-version-status",children:["(",s("config:about.updated"),")"]})]})]}),e.jsx(fa,{}),e.jsx(xa,{}),e.jsx(ba,{}),e.jsx("div",{className:"about-changelog-row",children:e.jsx("button",{className:"about-update-btn changelog",onClick:()=>v(!0),children:s("config:about.changelog")})}),e.jsxs("div",{className:"about-update",children:[n&&t?e.jsxs("div",{className:"about-update-available",children:[e.jsxs("div",{className:"about-update-header",children:[e.jsx("span",{className:"about-update-badge",children:s("config:about.updateAvailable")}),e.jsx("span",{className:"about-update-version",children:t.version})]}),t.apkSize&&e.jsxs("div",{className:"about-update-size",children:[s("config:about.sizeLabel"),": ",P(t.apkSize)]}),c&&e.jsx("div",{className:"about-update-error",children:c}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:m,children:s("config:about.changelog")}),g&&t.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:()=>void S(),disabled:o!=="idle",children:o==="downloading"?s("config:appUpdateBanner.downloadingPct",{percent:u??0}):s(o==="installing"?"config:appUpdateBanner.installHint":"config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:m,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(d?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>N(!0),disabled:d,children:d?"...":s("config:about.check")})]}),i.length>0&&e.jsxs("div",{className:"about-releases",children:[e.jsx("div",{className:"about-releases-title",children:s("config:about.recentReleases")}),e.jsx("div",{className:"about-releases-list",children:i.map(p=>e.jsxs("a",{href:p.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${p.version===`v${r}`||p.version===r?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:p.version}),e.jsx("span",{className:"about-release-date",children:b(p.publishedAt)})]},p.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:e.jsx(I,{name:"package",size:14})}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]}),_&&e.jsx(Ws,{onClose:()=>v(!1)})]})}const va={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function Na({onOpenModal:s}){const[n,t]=l.useState([]),[i,d]=l.useState(!0),c=l.useCallback(async()=>{try{const r=await ye(ke("/api/integrations"));if(!r.ok)return;const g=await r.json();t(g)}catch{}finally{d(!1)}},[]);return l.useEffect(()=>{c()},[c]),i?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):n.length===0?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"No integrations available."}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[n.map(r=>{const g=va[r.id]||"🔌",o=!!r.status.error,u=r.status.connected,N=o?"#f38ba8":u?"#a6e3a1":"#fab387",S=o?"Error":u?"Connected":"Setup Required",m=o?"✗":u?"✓":"⚠";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 8px",borderRadius:4,background:"var(--surface-1, #181825)",border:"1px solid var(--border, #313244)",fontSize:12,minHeight:26},children:[e.jsx("span",{style:{fontSize:13,flexShrink:0},children:g}),e.jsx("span",{style:{flex:1,minWidth:0,color:"var(--text-primary, #cdd6f4)",fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r.name}),e.jsx("span",{style:{color:N,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:S,children:m}),e.jsx("button",{onClick:()=>s(r.id),title:`Configure ${r.name}`,style:{background:"none",border:"none",cursor:"pointer",padding:"1px 3px",fontSize:12,color:"var(--text-secondary, #a6adc8)",borderRadius:3,flexShrink:0,lineHeight:1},onMouseEnter:_=>{_.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:_=>{_.target.style.color="var(--text-secondary, #a6adc8)"},children:"⚙️"})]},r.id)}),e.jsx("button",{onClick:()=>s(),style:{background:"none",border:"1px dashed var(--border, #313244)",borderRadius:4,padding:"3px 8px",cursor:"pointer",color:"var(--text-secondary, #a6adc8)",fontSize:11,textAlign:"center",marginTop:2},onMouseEnter:r=>{r.target.style.borderColor="var(--accent, #89b4fa)",r.target.style.color="var(--accent, #89b4fa)"},onMouseLeave:r=>{r.target.style.borderColor="var(--border, #313244)",r.target.style.color="var(--text-secondary, #a6adc8)"},children:"Manage All Integrations"})]})}const Ue="__global__";function wa({isOpen:s,onClose:n,initialAgentId:t}){const{t:i}=ee(["config"]),d=st(),[c,r]=l.useState(""),[g,o]=l.useState(""),[u,N]=l.useState(!1),[S,m]=l.useState(""),[_,v]=l.useState(""),[P,b]=l.useState(null),[p,C]=l.useState(null),[B,F]=l.useState(!1),[J,K]=l.useState(!1),[X,U]=l.useState(!1),[Z,h]=l.useState(null),E=l.useMemo(()=>[...d].sort((T,y)=>T.name.localeCompare(y.name)),[d]),R=l.useMemo(()=>d.find(T=>T.id===c),[d,c]),W=c===Ue;l.useEffect(()=>{if(!s)return;const T=t&&d.some(y=>y.id===t)?t:Ue;r(T),N(!1),Gt().then(y=>o(y)).catch(()=>o("")).finally(()=>N(!0))},[s]),l.useEffect(()=>{const T=c===Ue?g:(R==null?void 0:R.customPrompt)??"";m(T),v(T),F(!1),b(null),C(null)},[c,u]);const ae=T=>{const y=T.target.value;m(y),F(y!==_),b(null),C(null)},j=async()=>{if(c)try{b(null),C(null),W?(await Yt(S),o(S),C(i("config:systemPrompt.savedGlobal"))):(x.updateAgentProperties(c,{customPrompt:S}),C(i("config:systemPrompt.saved"))),v(S),F(!1)}catch(T){b(T instanceof Error?T.message:"Failed to save system prompt")}},L=()=>{K(!0)},z=async()=>{if(c)try{b(null),C(null),W?(await Jt(),o(""),C(i("config:systemPrompt.clearedGlobal"))):(x.updateAgentProperties(c,{customPrompt:""}),C(i("config:systemPrompt.cleared"))),m(""),v(""),F(!1)}catch(T){b(T instanceof Error?T.message:"Failed to clear system prompt")}},w=()=>{m(_),F(!1),b(null),C(null)},$=T=>{if(T!==c){if(B){h(T),U(!0);return}r(T)}},O=()=>{if(B){h(null),U(!0);return}n()},se=()=>{if(U(!1),Z){const T=Z;h(null),r(T)}else n()},ne=T=>{T.key==="Escape"&&(T.preventDefault(),O())};return s?e.jsxs(_e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:O,children:e.jsxs("div",{className:"system-prompt-modal",onClick:T=>T.stopPropagation(),onKeyDown:ne,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:i("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:O,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"modal-description",children:i("config:systemPrompt.description")}),e.jsxs("div",{className:"agent-picker",children:[e.jsx("label",{htmlFor:"system-prompt-agent",className:"editor-label",children:i("config:systemPrompt.agentLabel")}),e.jsxs("div",{className:"agent-picker-row",children:[W?e.jsx(I,{name:"globe",size:20,className:"agent-picker-icon"}):R&&e.jsx(tt,{classId:R.class,size:20,className:"agent-picker-icon"}),e.jsxs("select",{id:"system-prompt-agent",className:"agent-picker-select",value:c,onChange:T=>$(T.target.value),children:[e.jsxs("option",{value:Ue,children:[i("config:systemPrompt.globalOption"),g?" • ✦":""]}),E.map(T=>e.jsxs("option",{value:T.id,children:[T.name,T.customPrompt?" • ✦":""]},T.id))]})]})]}),P&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),P]}),p&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),p]}),e.jsxs("div",{className:"editor-wrapper",children:[e.jsxs("div",{className:"editor-header",children:[e.jsx("label",{htmlFor:"prompt-input",className:"editor-label",children:i("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[S.length," ",i("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:S,onChange:ae,placeholder:i("config:systemPrompt.placeholder"),rows:18,disabled:W&&!u,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:i(W?"config:systemPrompt.hintGlobal":"config:systemPrompt.hint")})]})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:L,disabled:!S||!c,children:i("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:O,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:w,disabled:!B,children:i("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:j,disabled:!B||!c,children:i("config:systemPrompt.save")})]})]})]})}),e.jsx(xe,{isOpen:J,title:i("config:systemPrompt.clear"),message:i(W?"config:systemPrompt.confirmClearGlobal":"config:systemPrompt.confirmClear"),confirmLabel:i("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{z()},onClose:()=>K(!1)}),e.jsx(xe,{isOpen:X,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:se,onClose:()=>{U(!1),h(null)}})]}):null}const ms={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},ya=2500,ka=12e4;function gs(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function Sa(s,n){return s.enabled===n.enabled&&s.baseUrl===n.baseUrl&&s.defaultSessionId===n.defaultSessionId&&s.webhookVerifyToken===n.webhookVerifyToken&&s.showIncomingToasts===n.showIncomingToasts}function Ca({isOpen:s,onClose:n}){const{t}=ee(["config"]),[i,d]=l.useState(ms),[c,r]=l.useState(ms),[g,o]=l.useState(!1),[u,N]=l.useState([]),[S,m]=l.useState(!0),[_,v]=l.useState(null),[P,b]=l.useState(null),[p,C]=l.useState(""),[B,F]=l.useState(!1),[J,K]=l.useState(""),[X,U]=l.useState(null),[Z,h]=l.useState(null),[E,R]=l.useState(null),W=l.useRef(null),ae=l.useRef(0),[j,L]=l.useState(""),[z,w]=l.useState(""),[$,O]=l.useState(null),[se,ne]=l.useState(!1),[T,y]=l.useState(!1),[te,oe]=l.useState(!1),[de,ie]=l.useState(!1),[he,Se]=l.useState(null),Ae=!Sa(i,c),ue=l.useCallback(()=>{W.current&&(clearTimeout(W.current),W.current=null)},[]),Ie=l.useCallback(async()=>{try{m(!0),v(null),b(null);const[f,V]=await Promise.all([ws(),at()]),ce=gs(f);if(d(ce),r(ce),o(!!V.configured),V.configured)try{const ve=await Ze();N(Array.isArray(ve)?ve:[])}catch{N([])}else N([])}catch(f){v(f instanceof Error?f.message:t("config:whatsapp.errors.loadFailed"))}finally{m(!1)}},[t]),me=l.useCallback(async()=>{try{const f=await Ze();N(Array.isArray(f)?f:[])}catch{}},[]);l.useEffect(()=>(s?Ie():(ue(),U(null),h(null),R(null),C(""),F(!1),O(null)),()=>{ue()}),[s,Ie,ue]);const ge=(f,V)=>{d(ce=>({...ce,[f]:V})),v(null),b(null)},De=async()=>{try{v(null),b(null);const f=await ct({enabled:i.enabled,baseUrl:i.baseUrl.trim(),defaultSessionId:i.defaultSessionId.trim(),webhookVerifyToken:i.webhookVerifyToken,showIncomingToasts:i.showIncomingToasts});window.dispatchEvent(new CustomEvent("tide:whatsapp-config-updated"));const V=gs(f);d(V),r(V),b(t("config:whatsapp.saved"))}catch(f){v(f instanceof Error?f.message:t("config:whatsapp.errors.saveFailed"))}},$e=()=>{d(c),v(null),b(null)},be=()=>{if(Ae){y(!0);return}n()},Ve=f=>{f.key==="Escape"&&(f.preventDefault(),be())},Ke=async()=>{const f=p.trim();if(f)try{v(null),b(null),await ot(f),C(""),F(!1),o(!0),b(t("config:whatsapp.apiKeySaved"))}catch(V){v(V instanceof Error?V.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},Le=()=>{oe(!0)},He=async()=>{try{v(null),b(null),await rt(),o(!1),b(t("config:whatsapp.apiKeyCleared"))}catch(f){v(f instanceof Error?f.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},Oe=l.useCallback(async f=>{if(Date.now()>ae.current){R(t("config:whatsapp.pairingTimeout")),U(null),h(null),ue(),me();return}try{const V=await nt(f);if(V.status&&["connected","paired","open","ready"].includes(V.status.toLowerCase())){R(t("config:whatsapp.pairingSuccess")),U(null),h(null),ue(),me();return}const ve=V.qrUrl??V.qr??null;ve&&h(ve)}catch(V){R(V instanceof Error?V.message:t("config:whatsapp.errors.qrFetchFailed"))}W.current=setTimeout(()=>{Oe(f)},ya)},[me,ue,t]),Fe=async()=>{const f=J.trim();if(f)try{v(null),b(null),R(null),h(null),ue(),await it(f),K(""),U(f),ae.current=Date.now()+ka,Oe(f),me()}catch(V){v(V instanceof Error?V.message:t("config:whatsapp.errors.sessionCreateFailed"))}},je=()=>{ue(),U(null),h(null),R(null)},D=f=>{Se(f),ie(!0)},Re=async()=>{if(he)try{v(null),b(null),await dt(he),X===he&&je(),me(),b(t("config:whatsapp.sessionDeleted"))}catch(f){v(f instanceof Error?f.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{Se(null)}},pe=async()=>{const f=j.trim(),V=z.trim();if(!(!f||!V))try{ne(!0),O(null);const ce=i.defaultSessionId.trim()||void 0;await lt(f,V,ce),O({kind:"success",text:t("config:whatsapp.testSent")})}catch(ce){O({kind:"error",text:ce instanceof Error?ce.message:t("config:whatsapp.errors.testSendFailed")})}finally{ne(!1)}};return s?e.jsxs(_e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:be,children:e.jsxs("div",{className:"whatsapp-config-modal",onClick:f=>f.stopPropagation(),onKeyDown:Ve,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsapp.title")}),e.jsx("button",{className:"modal-close",onClick:be,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:S?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")}),_&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),_]}),P&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),P]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.general")}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-enabled",className:"wa-label",children:t("config:whatsapp.enabled")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-enabled",type:"checkbox",checked:i.enabled,onChange:f=>ge("enabled",f.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-show-toasts",className:"wa-label",children:t("config:whatsapp.showIncomingToasts")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-show-toasts",type:"checkbox",checked:i.showIncomingToasts,onChange:f=>ge("showIncomingToasts",f.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.showIncomingToastsHelp")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-base-url",className:"wa-label",children:t("config:whatsapp.baseUrl")}),e.jsx("input",{id:"wa-base-url",type:"text",className:"wa-input",placeholder:"http://localhost:3007",value:i.baseUrl,onChange:f=>ge("baseUrl",f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-default-session",className:"wa-label",children:t("config:whatsapp.defaultSessionId")}),e.jsx("input",{id:"wa-default-session",type:"text",className:"wa-input",placeholder:t("config:whatsapp.defaultSessionIdPlaceholder"),value:i.defaultSessionId,onChange:f=>ge("defaultSessionId",f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-webhook-token",className:"wa-label",children:t("config:whatsapp.webhookVerifyToken")}),e.jsx("input",{id:"wa-webhook-token",type:"text",className:"wa-input",placeholder:t("config:whatsapp.webhookVerifyTokenPlaceholder"),value:i.webhookVerifyToken,onChange:f=>ge("webhookVerifyToken",f.target.value)})]})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.apiKey")}),e.jsx("div",{className:"wa-key-status",children:g?e.jsxs("span",{className:"wa-status wa-status-ok",children:[e.jsx(I,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(I,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:B?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:p,onChange:f=>C(f.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>F(f=>!f),title:t(B?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(I,{name:B?"eye-closed":"eye",size:14})}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ke,disabled:!p.trim(),children:t("config:whatsapp.saveKey")}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:Le,disabled:!g,children:t("config:whatsapp.clearKey")})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.apiKeyHint")})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.sessions")}),e.jsx("div",{className:"wa-sessions-list",children:!Array.isArray(u)||u.length===0?e.jsx("div",{className:"wa-empty",children:t("config:whatsapp.noSessions")}):u.map(f=>e.jsxs("div",{className:"wa-session-row",children:[e.jsxs("div",{className:"wa-session-info",children:[e.jsx("span",{className:"wa-session-id",children:f.id}),e.jsx("span",{className:`wa-session-status status-${(f.status??"unknown").toLowerCase()}`,children:f.status||"—"}),f.pairedNumber&&e.jsx("span",{className:"wa-session-paired",children:f.pairedNumber})]}),e.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:()=>D(f.id),children:t("config:whatsapp.deleteSession")})]},f.id))}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:"text",className:"wa-input",placeholder:t("config:whatsapp.addSessionPlaceholder"),value:J,onChange:f=>K(f.target.value),onKeyDown:f=>{f.key==="Enter"&&Fe()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Fe,disabled:!J.trim()||X!==null,children:t("config:whatsapp.addSession")})]}),X&&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:X})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:je,children:t("config:whatsapp.cancelPairing")})]}),Z?e.jsx("div",{className:"wa-qr-image",children:e.jsx("img",{src:Z,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")})]})]}),E&&!X&&e.jsx("div",{className:"wa-pairing-message",children:E})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.testMessage")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-to",className:"wa-label",children:t("config:whatsapp.testTo")}),e.jsx("input",{id:"wa-test-to",type:"text",className:"wa-input",placeholder:t("config:whatsapp.testToPlaceholder"),value:j,onChange:f=>L(f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-message",className:"wa-label",children:t("config:whatsapp.testMessageBody")}),e.jsx("textarea",{id:"wa-test-message",className:"wa-textarea",rows:4,placeholder:t("config:whatsapp.testMessageBodyPlaceholder"),value:z,onChange:f=>w(f.target.value)})]}),e.jsx("div",{className:"wa-field-inline wa-field-end",children:e.jsx("button",{type:"button",className:"btn btn-primary",onClick:pe,disabled:!j.trim()||!z.trim()||se,children:t(se?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),$&&e.jsxs("div",{className:`alert ${$.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:$.kind==="success"?"check":"warn",size:14})}),$.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:be,children:t("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:$e,disabled:!Ae||S,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:De,disabled:!Ae||S,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(xe,{isOpen:T,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{y(!1),n()},onClose:()=>y(!1)}),e.jsx(xe,{isOpen:te,title:t("config:whatsapp.clearKey"),message:t("config:whatsapp.confirmClearKey"),confirmLabel:t("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{He()},onClose:()=>oe(!1)}),e.jsx(xe,{isOpen:de,title:t("config:whatsapp.deleteSession"),message:t("config:whatsapp.confirmDeleteSession",{id:he??""}),confirmLabel:t("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Re()},onClose:()=>{ie(!1),Se(null)}})]}):null}const Cs=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function Qe(s=!1){const n=Y(),t={};return n&&(t.Authorization=`Bearer ${n}`),s&&(t["Content-Type"]="application/json"),t}async function es(s,n){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${n}: ${s.statusText}`}async function Aa(){const s=await fetch(`${q()}/api/whatsapp/notification-config`,{headers:Qe()});if(!s.ok)throw new Error(await es(s,"Failed to fetch WhatsApp notification config"));return s.json()}async function Ta(s){const n=await fetch(`${q()}/api/whatsapp/notification-config`,{method:"PATCH",headers:Qe(!0),body:JSON.stringify(s)});if(!n.ok)throw new Error(await es(n,"Failed to update WhatsApp notification config"));return n.json()}async function Ea(){const s=await fetch(`${q()}/api/whatsapp/notification-config`,{method:"DELETE",headers:Qe()});if(!s.ok)throw new Error(await es(s,"Failed to reset WhatsApp notification config"));return s.json()}const ze={messages:!0,statusChanges:!0,taskComplete:!0,errors:!0,planReady:!0,agentSpawned:!0,agentStopped:!0},fs={filter:{...ze},recipient:""};function Pa(s,n){if(s.recipient!==n.recipient)return!1;for(const t of Cs)if(s.filter[t]!==n.filter[t])return!1;return!0}function _a({isOpen:s,onClose:n}){const{t}=ee(["config"]),[i,d]=l.useState(fs),[c,r]=l.useState(fs),[g,o]=l.useState(!0),[u,N]=l.useState(null),[S,m]=l.useState(null),[_,v]=l.useState(!1),[P,b]=l.useState(!1),p=!Pa(i,c),C=l.useCallback(async()=>{try{o(!0),N(null),m(null);const h=await Aa(),E={filter:{...ze,...h.filter},recipient:h.recipient??""};d(E),r(E)}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{o(!1)}},[t]);l.useEffect(()=>{s&&C()},[s,C]);const B=(h,E)=>{d(R=>({...R,filter:{...R.filter,[h]:E}})),N(null),m(null)},F=h=>{d(E=>({...E,recipient:h})),N(null),m(null)},J=async()=>{try{N(null),m(null);const h=await Ta({filter:i.filter,recipient:i.recipient.trim()}),E={filter:{...ze,...h.filter},recipient:h.recipient??""};d(E),r(E),m(t("config:whatsappNotifications.saved"))}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.saveFailed"))}},K=()=>{d(c),N(null),m(null)},X=async()=>{try{N(null),m(null);const h=await Ea(),E={filter:{...ze,...h.filter},recipient:h.recipient??""};d(E),r(E),m(t("config:whatsappNotifications.resetDone"))}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.resetFailed"))}},U=()=>{if(p){v(!0);return}n()},Z=h=>{h.key==="Escape"&&(h.preventDefault(),U())};return s?e.jsxs(_e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:U,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:h=>h.stopPropagation(),onKeyDown:Z,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappNotifications.title")}),e.jsx("button",{className:"modal-close",onClick:U,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:g?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsappNotifications.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsappNotifications.description")}),u&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),u]}),S&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),S]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.recipient")}),e.jsxs("div",{className:"wan-field",children:[e.jsx("label",{htmlFor:"wan-recipient",className:"wan-label",children:t("config:whatsappNotifications.recipientLabel")}),e.jsx("input",{id:"wan-recipient",type:"text",className:"wan-input",placeholder:t("config:whatsappNotifications.recipientPlaceholder"),value:i.recipient,onChange:h=>F(h.target.value)}),e.jsx("span",{className:"wan-hint",children:t("config:whatsappNotifications.recipientHint")})]})]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.events")}),e.jsx("p",{className:"wan-section-hint",children:t("config:whatsappNotifications.eventsHint")}),Cs.map(h=>e.jsxs("div",{className:"wan-toggle-row",children:[e.jsxs("div",{className:"wan-toggle-info",children:[e.jsx("span",{className:"wan-toggle-title",children:t(`config:whatsappNotifications.events.${h}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${h}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:i.filter[h],onChange:E=>B(h,E.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:()=>b(!0),disabled:g,children:t("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:U,children:t("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:K,disabled:!p||g,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:J,disabled:!p||g,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(xe,{isOpen:_,title:t("config:whatsappNotifications.unsavedTitle"),message:t("config:whatsappNotifications.unsavedMessage"),confirmLabel:t("config:whatsappNotifications.closeAnyway"),cancelLabel:t("config:whatsappNotifications.keepEditing"),variant:"danger",onConfirm:()=>{v(!1),n()},onClose:()=>v(!1)}),e.jsx(xe,{isOpen:P,title:t("config:whatsappNotifications.resetToDefaults"),message:t("config:whatsappNotifications.confirmReset"),confirmLabel:t("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{X(),b(!1)},onClose:()=>b(!1)})]}):null}function As(s){const n=s.replace(/@.*$/,"");return/^\d{10,15}$/.test(n)?n.startsWith("521")&&n.length===13?`+52 1 ${n.slice(3,5)} ${n.slice(5,9)} ${n.slice(9)}`:n.startsWith("52")&&n.length===12?`+52 ${n.slice(2,4)} ${n.slice(4,8)} ${n.slice(8)}`:n.startsWith("1")&&n.length===11?`+1 ${n.slice(1,4)} ${n.slice(4,7)} ${n.slice(7)}`:`+${n}`:s}function Ia(s,n=Date.now()){const t=s*1e3,i=n-t;if(i<0)return xs(t);const d=Math.floor(i/6e4);if(d<1)return"now";if(d<60)return`${d}m`;const c=Math.floor(d/60);if(c<24)return`${c}h`;const r=Math.floor(c/24);return r===1?"yesterday":r<7?`${r}d`:xs(t)}function xs(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Da(s){const n=s*1e3;return new Date(n).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function Ts(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 $a(s,n){return s.length<=n?s:s.slice(0,Math.max(0,n-1)).trimEnd()+"…"}function La({chats:s,selectedChatId:n,loading:t,error:i,onSelect:d,onRefresh:c,now:r}){const{t:g}=ee(["config","common"]);return e.jsxs("div",{className:"whatsapp-history-chatlist",children:[e.jsxs("div",{className:"whatsapp-history-chatlist__header",children:[e.jsx("span",{className:"whatsapp-history-chatlist__title",children:g("config:whatsappHistory.chats")}),e.jsx("button",{type:"button",className:"whatsapp-history-chatlist__refresh",onClick:c,disabled:t,"aria-label":g("config:whatsappHistory.refresh"),title:g("config:whatsappHistory.refresh"),children:"⟳"})]}),i&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:i}),t&&s.length===0&&e.jsxs("div",{className:"whatsapp-history-chatlist__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:g("config:whatsappHistory.loadingChats")})]}),!t&&!i&&s.length===0&&e.jsx("div",{className:"whatsapp-history-chatlist__empty",children:g("config:whatsappHistory.emptyChats")}),e.jsx("ul",{className:"whatsapp-history-chatlist__items",children:s.map(o=>{const u=Ts(o.lastMessageType),N=o.lastMessagePreview||`[${o.lastMessageType}]`,S=o.chatId===n,m=As(o.chatId),_=o.isGroup?o.groupName:o.fromName,v=_||m,P=!!_&&_!==m;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${S?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>d(o.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:o.chatId,children:v}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:Ia(o.lastTimestamp,r)})]}),P&&e.jsx("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--jid",children:e.jsx("span",{className:"whatsapp-history-chatlist__jid",children:m})}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[o.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),u&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[u," "]}),$a(N,40)]}),o.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:o.unreadCount})]})]})},o.chatId)})})]})}function Oa({message:s}){const n=s.direction==="outbound"?"outbound":"inbound",t=Ts(s.messageType),i=(s.body??"").trim(),d=i.length>0,c=d?null:`[${s.messageType}]`;return e.jsx("div",{className:`whatsapp-history-bubble whatsapp-history-bubble--${n}`,children:e.jsxs("div",{className:"whatsapp-history-bubble__inner",children:[t&&e.jsx("span",{className:"whatsapp-history-bubble__type-icon",title:s.messageType,children:t}),d?e.jsx("span",{className:"whatsapp-history-bubble__body",children:i}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:c}),s.audioTranscription&&e.jsxs("span",{className:"whatsapp-history-bubble__transcription",children:["“",s.audioTranscription,"”"]}),s.mediaPath&&e.jsx("a",{className:"whatsapp-history-bubble__media-link",href:s.mediaPath,target:"_blank",rel:"noopener noreferrer",children:s.mediaFilename||"open media"}),e.jsx("span",{className:"whatsapp-history-bubble__time",children:Da(s.timestamp)})]})})}const Fa=["all","inbound","outbound"],Ra=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function Ma({direction:s,type:n,onDirectionChange:t,onTypeChange:i,disabled:d}){const{t:c}=ee(["config"]);return e.jsxs("div",{className:"whatsapp-history-filters",children:[e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:c("config:whatsappHistory.direction")}),e.jsx("select",{value:s,onChange:r=>t(r.target.value),disabled:d,children:Fa.map(r=>e.jsx("option",{value:r,children:c(`config:whatsappHistory.directionValues.${r}`)},r))})]}),e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:c("config:whatsappHistory.type")}),e.jsx("select",{value:n,onChange:r=>i(r.target.value),disabled:d,children:Ra.map(r=>e.jsx("option",{value:r,children:c(`config:whatsappHistory.typeValues.${r}`)},r))})]})]})}const Ba=80;function Ua({chatId:s,messages:n,loading:t,loadingMore:i,error:d,hasMore:c,direction:r,type:g,onDirectionChange:o,onTypeChange:u,onLoadMore:N}){const{t:S}=ee(["config"]),m=l.useRef(null),_=l.useRef(null),v=l.useRef(!1),P=l.useRef(null);l.useEffect(()=>{_.current!==s&&(_.current=s,v.current=!1)},[s]),l.useLayoutEffect(()=>{m.current&&(v.current||n.length!==0&&(m.current.scrollTop=m.current.scrollHeight,v.current=!0))},[s,n.length]),l.useLayoutEffect(()=>{if(!m.current||P.current===null)return;const C=m.current.scrollHeight-P.current;P.current=null,C>0&&(m.current.scrollTop+=C)},[n.length]);const b=l.useCallback(()=>{!c||i||t||(m.current&&(P.current=m.current.scrollHeight),N())},[c,i,t,N]),p=l.useCallback(C=>{if(!v.current)return;C.currentTarget.scrollTop<=Ba&&b()},[b]);return s?e.jsxs("div",{className:"whatsapp-history-messages",children:[e.jsxs("div",{className:"whatsapp-history-messages__header",children:[e.jsx("div",{className:"whatsapp-history-messages__title",children:As(s)}),e.jsx(Ma,{direction:r,type:g,onDirectionChange:o,onTypeChange:u,disabled:t})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:m,onScroll:p,children:[c&&e.jsx("div",{className:"whatsapp-history-messages__load-more-row",children:e.jsx("button",{type:"button",className:"whatsapp-history-messages__load-more",onClick:b,disabled:i||t,children:S(i?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),d&&e.jsx("div",{className:"whatsapp-history-messages__error",children:d}),t&&n.length===0&&e.jsxs("div",{className:"whatsapp-history-messages__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:S("config:whatsappHistory.loadingMessages")})]}),!t&&!d&&n.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:S("config:whatsappHistory.emptyMessages")}),n.map(C=>e.jsx(Oa,{message:C},za(C)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:S("config:whatsappHistory.selectChat")})})}function za(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 Es(){const s=Y(),n={};return s&&(n.Authorization=`Bearer ${s}`),n}async function Ps(s,n){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${n}: ${s.statusText}`}async function Va(s){const n=`${q()}/api/whatsapp/chats/${encodeURIComponent(s)}`,t=await fetch(n,{headers:Es()});if(!t.ok)throw new Error(await Ps(t,"Failed to fetch WhatsApp chats"));return t.json()}async function bs(s,n,t={}){const i=new URLSearchParams;t.cursor&&i.set("cursor",t.cursor),typeof t.limit=="number"&&i.set("limit",String(t.limit)),t.direction&&i.set("direction",t.direction),t.type&&i.set("type",t.type);const d=i.toString(),c=`${q()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(n)}/messages${d?`?${d}`:""}`,r=await fetch(c,{headers:Es()});if(!r.ok)throw new Error(await Ps(r,"Failed to fetch WhatsApp messages"));return r.json()}const Ka=50;function Ha({isOpen:s,onClose:n}){const{t}=ee(["config"]),[i,d]=l.useState([]),[c,r]=l.useState(null),[g,o]=l.useState(null),[u,N]=l.useState([]),[S,m]=l.useState(!1),[_,v]=l.useState(null),[P,b]=l.useState(null),[p,C]=l.useState([]),[B,F]=l.useState(!1),[J,K]=l.useState(!1),[X,U]=l.useState(null),[Z,h]=l.useState(null),[E,R]=l.useState("all"),[W,ae]=l.useState("all"),[j,L]=l.useState(()=>Date.now()),z=l.useRef(0);l.useEffect(()=>{if(!s)return;const y=window.setInterval(()=>L(Date.now()),6e4);return()=>window.clearInterval(y)},[s]),l.useEffect(()=>{if(!s)return;let y=!1;return(async()=>{var te;try{o(null);const[oe,de]=await Promise.all([Ze().catch(()=>[]),ws().catch(()=>null)]);if(y)return;d(oe);const ie=(de==null?void 0:de.defaultSessionId)||((te=oe[0])==null?void 0:te.id)||null;r(he=>he??ie)}catch(oe){if(y)return;o(oe instanceof Error?oe.message:String(oe))}})(),()=>{y=!0}},[s]);const w=l.useCallback(async y=>{m(!0),v(null);try{const te=await Va(y);N(te.chats)}catch(te){v(te instanceof Error?te.message:String(te))}finally{m(!1)}},[]);l.useEffect(()=>{!s||!c||(b(null),C([]),h(null),w(c))},[s,c,w]);const $=l.useMemo(()=>{const y={limit:Ka};return E!=="all"&&(y.direction=E),W!=="all"&&(y.type=W),y},[E,W]),O=l.useCallback(async(y,te,oe)=>{const de=++z.current;F(!0),U(null),C([]),h(null);try{const ie=await bs(y,te,oe);if(de!==z.current)return;C([...ie.messages].reverse()),h(ie.nextCursor)}catch(ie){if(de!==z.current)return;U(ie instanceof Error?ie.message:String(ie))}finally{de===z.current&&F(!1)}},[]);l.useEffect(()=>{!s||!c||!P||O(c,P,$)},[s,c,P,$,O]);const se=l.useCallback(async()=>{if(!(!c||!P||!Z)){K(!0),U(null);try{const y=await bs(c,P,{...$,cursor:Z});C(te=>[...[...y.messages].reverse(),...te]),h(y.nextCursor)}catch(y){U(y instanceof Error?y.message:String(y))}finally{K(!1)}}},[c,P,Z,$]),ne=l.useCallback(()=>{c&&w(c)},[c,w]),T=l.useCallback(y=>{y.key==="Escape"&&(y.preventDefault(),n())},[n]);return s?e.jsx(_e,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:y=>y.stopPropagation(),onKeyDown:T,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappHistory.title")}),e.jsx("div",{className:"whatsapp-history-modal__session",children:e.jsxs("label",{children:[e.jsx("span",{children:t("config:whatsappHistory.session")}),e.jsxs("select",{value:c??"",onChange:y=>r(y.target.value||null),disabled:i.length===0,children:[i.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),i.map(y=>e.jsxs("option",{value:y.id,children:[y.id,y.pairedNumber?` (${y.pairedNumber})`:""]},y.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),g&&e.jsx("div",{className:"whatsapp-history-modal__alert",children:g}),e.jsxs("div",{className:"whatsapp-history-modal__body",children:[e.jsx(La,{chats:u,selectedChatId:P,loading:S,error:_,onSelect:b,onRefresh:ne,now:j}),e.jsx(Ua,{chatId:P,messages:p,loading:B,loadingMore:J,error:X,hasMore:Z!==null,direction:E,type:W,onDirectionChange:R,onTypeChange:ae,onLoadMore:se})]})]})})}):null}function qa({isOpen:s,onClose:n,onOpenConfig:t,onOpenNotifications:i,onOpenHistory:d}){const{t:c}=ee(["config"]);if(l.useEffect(()=>{if(!s)return;const g=o=>{o.key==="Escape"&&(o.preventDefault(),n())};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[s,n]),!s)return null;const r=g=>{n(),g()};return e.jsx(_e,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-hub-modal",onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"whatsapp-hub-modal__icon",children:"📱"}),c("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"whatsapp-hub-modal__intro",children:c("config:whatsappHub.intro",{defaultValue:"Pick what you want to manage for the WhatsApp integration."})}),e.jsxs("div",{className:"whatsapp-hub-modal__options",children:[e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(t),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.config",{defaultValue:"Integration config"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.configDesc",{defaultValue:"Server URL, API key, sessions and pairing."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(i),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.notifications",{defaultValue:"Notifications"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.notificationsDesc",{defaultValue:"Which agent events get forwarded and to whom."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(d),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.history",{defaultValue:"History"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.historyDesc",{defaultValue:"Browse persisted chats and messages."})})]})]})]})]})]})})})}const Je=[{kind:"question",settingKey:"toneQuestion",label:"Agent asks you something",when:"A question, a plan to approve, or a permission request. Repeats twice up front, then every 10s until you answer (stops after 2 min).",sound:"Two taps, then a rising bend",play:ks},{kind:"notification",settingKey:"toneNotification",label:"Agent sends a notification",when:"Any agent notification: task complete, error, or a heads-up.",sound:"Soft two-note chime",play:ys},{kind:"completion",settingKey:"toneCompletion",label:"Agent finishes working",when:"An agent stops working and goes idle.",sound:"Gentle descending arpeggio",play:kt}],Wa=[{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:"🌙"}],Ga=[{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:"🔴"}],Ya=[{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:"👎"}],Ja=[{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:"💜"}],Xa=[{key:"showTrees",icon:"🌳",label:"Trees"},{key:"showBushes",icon:"🌿",label:"Bushes"},{key:"showHouse",icon:"🏠",label:"House"},{key:"showLamps",icon:"💡",label:"Lamps"},{key:"showGrass",icon:"🟩",label:"Grass"},{key:"showClouds",icon:"☁️",label:"Clouds"}],Za=[{value:null,label:"Auto",color:"linear-gradient(135deg, #4a90d9 0%, #0a1a2a 100%)"},{value:"#4a90d9",label:"Day Blue",color:"#4a90d9"},{value:"#0a1a2a",label:"Night",color:"#0a1a2a"},{value:"#ff6b35",label:"Sunset",color:"#ff6b35"},{value:"#1a0a2e",label:"Purple",color:"#1a0a2e"},{value:"#2d5a27",label:"Matrix",color:"#2d5a27"},{value:"#8b0000",label:"Blood",color:"#8b0000"},{value:"#000000",label:"Void",color:"#000000"}],Qa={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},en={none:"grass","pokemon-stadium":"pokemon"},sn={"emote-yes":"yes","emote-no":"no"},tn={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function Q({checked:s,onChange:n}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:t=>n(t.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function Ce({options:s,value:n,onChange:t,iconOnly:i=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(d=>e.jsxs("button",{className:`chip ${n===d.value?"active":""}`,onClick:()=>t(d.value),title:d.label,children:[e.jsx("span",{className:"chip-icon",children:d.icon}),!i&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function k({text:s,query:n}){if(!n.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),i=n.toLowerCase(),d=t.indexOf(i);if(d===-1)return e.jsx(e.Fragment,{children:s});const c=s.slice(0,d),r=s.slice(d,d+n.length),g=s.slice(d+n.length);return e.jsxs(e.Fragment,{children:[c,e.jsx("mark",{className:"search-highlight",children:r}),g]})}const an=[{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","pi","rpc","steer","steering","mid-turn","mid turn","hover","preview","tooltip","ctrl","popup","vista previa","sound","sounds","sonido","sonidos","notification","notifications","notificacion","notificaciones","volume","volumen","tone","tones","tono","chime","alert","cue","audio","mute","silence","dock","activity","recent","notification sound","silenciar","custom sound","upload sound","alerta","file search","excluded folders","node_modules","vendor","git","spotlight","ignore"]},{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"]}],Xe=[{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 nn({config:s,onChange:n,searchQuery:t="",onOpenIntegrationsModal:i,onOpenMonitoringModal:d,onOpenStatisticsModal:c,onOpenWorkflowEditor:r,onOpenTriggerManager:g}){var ls;const{t:o}=ee(["config","common"]),u=ut(),N=pt(),[S,m]=l.useState(()=>ht(Ee.DEFAULT_AGENT_CLASS)||"scout"),_=mt(),v=gt(),[P,b]=l.useState(()=>ft()),[p,C]=l.useState(null),[B,F]=l.useState(null),[J,K]=l.useState("");l.useEffect(()=>{qe().then(b)},[]);const X=async(a,A)=>{F(null),C(a);try{const M=await ye(ke(`/api/custom-sounds/${a}`),{method:"POST",headers:{"Content-Type":A.type||"audio/mpeg"},body:A});if(!M.ok){const re=await M.json().catch(()=>({error:`Upload failed (${M.status})`}));throw new Error(re.error||`Upload failed (${M.status})`)}const le=await qe();b({...le});const fe=Je.find(re=>re.kind===a);fe&&x.updateSettings({[fe.settingKey]:Pe}),We(Pe,u.notificationSoundVolume,a)}catch(M){F(M instanceof Error?M.message:"Upload failed")}finally{C(null)}},U=async a=>{F(null);try{await ye(ke(`/api/custom-sounds/${a}`),{method:"DELETE"}),Et({[a]:null});const A=await qe();b({...A});const M=Je.find(le=>le.kind===a);M&&x.getSettings()[M.settingKey]===Pe&&x.updateSettings({[M.settingKey]:Pt[a]})}catch(A){F(A instanceof Error?A.message:"Failed to reset sound")}},[Z,h]=l.useState(u.historyLimit),[E,R]=l.useState(()=>xt()),[W,ae]=l.useState(!1),[j,L]=l.useState(""),[z,w]=l.useState(()=>Y()),[$,O]=l.useState(!1),[se,ne]=l.useState(!1),[T,y]=l.useState(""),[te,oe]=l.useState(!1),[de,ie]=l.useState(!1),[he,Se]=l.useState(!1),[Ae,ue]=l.useState(!1),[Ie,me]=l.useState(!1),[ge,De]=l.useState(""),[$e,be]=l.useState(!1);l.useEffect(()=>{Qt().then(De).catch(()=>{})},[]),l.useEffect(()=>{Xt().then(a=>{a!==u.experimentalEchoPrompt&&x.updateSettings({experimentalEchoPrompt:a})}).catch(()=>{})},[]),l.useEffect(()=>{sa().then(a=>{a!==u.tmuxMode&&x.updateSettings({tmuxMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{aa().then(a=>{a!==u.interactiveMode&&x.updateSettings({interactiveMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{oa().then(a=>{a!==u.codexAppServerMode&&x.updateSettings({codexAppServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{la().then(a=>{a!==u.opencodeServerMode&&x.updateSettings({opencodeServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{ra().then(a=>{a!==u.piRpcMode&&x.updateSettings({piRpcMode:a})}).catch(()=>{})},[]),l.useEffect(()=>bt(a=>{R(a),ae(!1)}),[]);const Ve=Wa.map(a=>({...a,label:o(`config:time.${a.value}`)})),Ke=Ga.map(a=>({...a,label:o(`config:floor.${en[a.value]||a.value}`)})),Le=Ya.map(a=>({...a,label:o(`config:animation.${sn[a.value]||a.value}`)})),He=Ja.map(a=>({...a,label:o(`config:colorMode.${a.value}`)})),Oe=Xa.map(a=>({...a,label:o(`config:terrain.${Qa[a.key]}`)})),Fe=Za.map(a=>({...a,label:o(`config:sky.${tn[a.value??""]}`)})),je=t.trim()?an.filter(a=>{const A=t.toLowerCase();return a.title.toLowerCase().includes(A)||a.keywords.some(M=>M.toLowerCase().includes(A))}).map(a=>a.id):null,D=a=>je?je.includes(a):!0,Re=D("integrations"),pe=u.customAgentNames||[],f=pe.length>0?pe:jt,V=()=>{const a=T.trim();a&&!pe.includes(a)&&(x.updateSettings({customAgentNames:[...pe,a]}),y(""))},ce=a=>{x.updateSettings({customAgentNames:pe.filter(A=>A!==a)})},ve=()=>{x.updateSettings({customAgentNames:[]})},Me=u.fileSearchExcludeDirs??[...rs],ss=()=>{const a=J.trim();if(ps(a)){if(Me.includes(a)){K("");return}x.updateSettings({fileSearchExcludeDirs:[...Me,a]}),K("")}},_s=a=>{x.updateSettings({fileSearchExcludeDirs:Me.filter(A=>A!==a)})},Is=()=>{x.updateSettings({fileSearchExcludeDirs:[...rs]})},ts=()=>{const a=j.trim();if(a){if(E.includes(a)){L("");return}R([...E,a]),ae(!0),L("")}},Ds=a=>{R(E.filter((A,M)=>M!==a)),ae(!0)},as=(a,A)=>{const M=a+A;if(M<0||M>=E.length)return;const le=E.slice();[le[a],le[M]]=[le[M],le[a]],R(le),ae(!0)},$s=()=>{_t(E),ae(!1),Ye()},Ls=a=>{w(a),O(!0)},ns=()=>{Be(Ee.AUTH_TOKEN,z),O(!1),Ye()},Os=a=>{De(a),be(!0)},os=()=>{ea(ge).catch(()=>{}),be(!1)},Ne=a=>{n({...s,terrain:{...s.terrain,...a}})},we=a=>{n({...s,modelStyle:{...s.modelStyle,...a}})},is=a=>{n({...s,animations:{...s.animations,...a}})},Fs=a=>{h(a),x.updateSettings({historyLimit:a})},Rs=a=>{const A=s.terrain[a];typeof A=="boolean"&&Ne({[a]:!A})},G=t.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[je&&je.length===0&&e.jsx("div",{className:"config-no-results",children:o("config:noResults",{query:t})}),D("general")&&e.jsxs(H,{title:o("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:G&&D("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:Z,onChange:a=>Fs(parseInt(a.target.value)||100),min:50,max:2e3,step:50})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.hideCosts"),query:t})}),e.jsx(Q,{checked:u.hideCost,onChange:a=>x.updateSettings({hideCost:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.streamTextLiveTitle"),children:e.jsx(k,{text:o("config:general.streamTextLive"),query:t})}),e.jsx(Q,{checked:u.streamTextLive!==!1,onChange:a=>x.updateSettings({streamTextLive:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.toolHoverPreviewTitle"),children:e.jsx(k,{text:o("config:general.toolHoverPreview"),query:t})}),e.jsx(Q,{checked:u.toolHoverPreview===!0,onChange:a=>x.updateSettings({toolHoverPreview:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Where the strip of recently-active and currently-working agent thumbnails sits.",children:e.jsx(k,{text:"Agent activity dock",query:t})}),e.jsx("select",{className:"config-select",value:_,onChange:a=>wt(a.target.value),children:vt.map(a=>e.jsx("option",{value:a,children:Nt[a]},a))})]}),_!=="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(k,{text:"Recent agents in dock",query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:v,min:0,max:20,step:1,onChange:a=>yt(parseInt(a.target.value,10)||0)})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.grid"),query:t})}),e.jsx(Q,{checked:s.gridVisible,onChange:a=>n({...s,gridVisible:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.showFPS"),query:t})}),e.jsx(Q,{checked:u.showFPS,onChange:a=>x.updateSettings({showFPS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.fpsLimit"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:a=>n({...s,fpsLimit:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.fpsLimit===0?"∞":s.fpsLimit})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: Reduce FPS when idle to save power",children:[e.jsx(k,{text:o("config:general.powerSaving"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(Q,{checked:u.powerSaving,onChange:a=>x.updateSettings({powerSaving:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Battery saver for mobile: caps scene FPS (20 active / 5 idle), freezes decorative animations and disables word-by-word streaming. Off = normal mode.",children:[e.jsx(k,{text:o("config:general.lowPowerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(Q,{checked:u.lowPowerMode===!0,onChange:a=>x.updateSettings({lowPowerMode:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Wrap agent processes in tmux sessions so they survive server restarts (requires tmux installed)",children:e.jsx(k,{text:o("config:general.tmuxMode"),query:t})}),e.jsx(Q,{checked:u.tmuxMode,onChange:async a=>{x.updateSettings({tmuxMode:a});try{await ta(a)}catch(A){console.error("Failed to sync tmux mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Claude agents as the real interactive `claude` TUI inside tmux, reconstructing the conversation from the session transcript (requires tmux). Takes effect on server restart.",children:[e.jsx(k,{text:o("config:general.interactiveMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(Q,{checked:u.interactiveMode,onChange:async a=>{x.updateSettings({interactiveMode:a});try{await na(a)}catch(A){console.error("Failed to sync interactive mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Codex agents through a persistent `codex app-server` so replies stream word-by-word (token deltas) instead of appearing as one block. The app-server runs detached and survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new Codex turns; no server restart needed to toggle.",children:[e.jsx(k,{text:o("config:general.codexAppServerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(Q,{checked:u.codexAppServerMode,onChange:async a=>{x.updateSettings({codexAppServerMode:a});try{await ia(a)}catch(A){console.error("Failed to sync codex app-server mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run OpenCode agents through a persistent, detached `opencode serve` HTTP server so replies stream word-by-word (token deltas over SSE) instead of appearing as one block. The server survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new OpenCode turns; no server restart needed to toggle.",children:[e.jsx(k,{text:o("config:general.opencodeServerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(Q,{checked:u.opencodeServerMode,onChange:async a=>{x.updateSettings({opencodeServerMode:a});try{await ca(a)}catch(A){console.error("Failed to sync opencode server mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Run Pi agents through a persistent `pi --mode rpc` process per agent. Messages sent mid-turn STEER the live run (delivered after the current tool round, before the next model call) instead of queueing until the turn ends. With tmux mode enabled, live RPC turns survive Commander restarts and reconnect automatically; otherwise sessions resume on the next message. Applies to new Pi turns; no server restart needed to toggle.",children:[e.jsx(k,{text:o("config:general.piRpcMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(Q,{checked:u.piRpcMode,onChange:async a=>{x.updateSettings({piRpcMode:a});try{await da(a)}catch(A){console.error("Failed to sync pi RPC mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.vibrationIntensity"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:u.vibrationIntensity,onChange:a=>x.updateSettings({vibrationIntensity:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:u.vibrationIntensity===0?o("config:vibrationValues.off"):u.vibrationIntensity===1?o("config:vibrationValues.ultraLight"):u.vibrationIntensity===2?o("config:vibrationValues.veryLight"):u.vibrationIntensity===3?o("config:vibrationValues.light"):u.vibrationIntensity===4?o("config:vibrationValues.medium"):o("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Play pleasant sounds: a chime for agent notifications, a distinctive rising cue when an agent asks you a question (repeats until answered), and a resolving cue when an agent finishes its work.",children:e.jsx(k,{text:"Notification sounds",query:t})}),e.jsx(Q,{checked:u.notificationSoundEnabled,onChange:a=>{x.updateSettings({notificationSoundEnabled:a}),a&&ys(u.notificationSoundVolume,u.toneNotification)}})]}),u.notificationSoundEnabled&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:"Notification sound volume",query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:ds,step:"1",value:u.notificationSoundVolume,onChange:a=>{const A=parseInt(a.target.value);x.updateSettings({notificationSoundVolume:A}),ks(A,u.toneQuestion)}}),e.jsx("span",{className:"config-value",children:u.notificationSoundVolume===0?o("config:vibrationValues.off"):`${u.notificationSoundVolume}/${ds}`})]}),u.notificationSoundEnabled&&u.notificationSoundVolume>0&&e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:"Sounds per event",query:t})}),e.jsx("div",{className:"config-sound-hint",children:'Pick a tone for each event — or upload your own file (mp3, wav, ogg, m4a — max 5MB), which is stored on the commander so every device hears it. "None" silences that event.'}),Je.map(a=>{var fe;const A=!!P[a.kind],M=u[a.settingKey],le=A&&M===Pe;return e.jsxs("div",{className:"config-sound-row",children:[e.jsxs("div",{className:"config-sound-info",children:[e.jsxs("div",{className:"config-sound-head",children:[e.jsx("span",{className:"config-sound-name",children:a.label}),e.jsx("span",{className:`config-sound-badge${le?" custom":""}`,children:le?"Your file":((fe=St(M))==null?void 0:fe.label)??a.sound})]}),e.jsx("div",{className:"config-sound-when",children:a.when})]}),e.jsxs("div",{className:"config-sound-actions",children:[e.jsxs("select",{className:"config-select",value:M,onChange:re=>{const Te=re.target.value;x.updateSettings({[a.settingKey]:Te}),We(Te,u.notificationSoundVolume,a.kind)},children:[A&&e.jsx("option",{value:Pe,children:"Your uploaded file"}),Ct.map(re=>e.jsx("option",{value:re.id,children:re.label},re.id))]}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void We(M,u.notificationSoundVolume,a.kind),disabled:us(M),title:us(M)?"This event is silenced — pick a tone to hear it":"Hear the sound that plays for this event",children:"▶"}),e.jsxs("label",{className:"config-btn config-btn-sm config-sound-upload",title:"Replace this sound with your own audio file (mp3, wav, ogg, m4a — max 5MB)",children:[p===a.kind?"Uploading…":"Upload",e.jsx("input",{type:"file",accept:"audio/*",style:{display:"none"},onChange:re=>{var cs;const Te=(cs=re.target.files)==null?void 0:cs[0];re.target.value="",Te&&X(a.kind,Te)}})]}),A&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void U(a.kind),title:"Delete your file and go back to a built-in tone",children:"Reset"})]})]},a.kind)}),B&&e.jsx("div",{className:"config-sound-error",children:B})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.externalEditor"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.externalEditorPlaceholder"),value:u.externalEditorCommand||"",onChange:a=>x.updateSettings({externalEditorCommand:a.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.tabTitle"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.tabTitlePlaceholder"),value:u.tabTitle||"",onChange:a=>x.updateSettings({tabTitle:a.target.value})})]}),e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.fileSearchExcludeDirs"),query:t})}),e.jsx("span",{className:"config-hint",children:o("config:general.fileSearchExcludeDirsHint")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:o("config:general.fileSearchExcludeDirsPlaceholder"),value:J,onChange:a=>K(a.target.value),onKeyDown:a=>{a.key==="Enter"&&ss()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ss,disabled:!ps(J),title:o("config:general.fileSearchExcludeDirsAdd"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:Me.map(a=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:a}),e.jsx("button",{className:"agent-name-remove",onClick:()=>_s(a),title:o("common:buttons.remove"),children:"x"})]},a))}),e.jsx("button",{className:"config-btn config-btn-link",onClick:Is,children:o("config:general.fileSearchExcludeDirsReset")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.language"),query:t})}),e.jsx(Ce,{options:Xe,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((ls=Xe.find(a=>a.value!=="auto"&&Ge.language.startsWith(a.value.split("-")[0])))==null?void 0:ls.value)||"en":"auto",onChange:a=>{var A;if(a==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const M=navigator.language,le=((A=Xe.find(fe=>fe.value!=="auto"&&M.startsWith(fe.value.split("-")[0])))==null?void 0:A.value)||"en";Ge.changeLanguage(le)}else localStorage.setItem("tide-commander-language-mode","manual"),Ge.changeLanguage(a)}})]})]}),D("agentNames")&&e.jsx(H,{title:o("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:G&&D("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:pe.length>0?o("config:agentNames.customConfigured",{count:pe.length}):o("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:o("config:agentNames.addPlaceholder"),value:T,onChange:a=>y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&V()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:V,disabled:!T.trim(),title:o("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:f.map((a,A)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:a}),pe.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>ce(a),title:o("common:buttons.remove"),children:"x"})]},`${a}-${A}`))}),pe.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:ve,children:o("common:buttons.resetToDefaults")})]})}),D("defaultClass")&&e.jsx(H,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:G&&D("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${S==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m("random"),Be(Ee.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(At).map(([a,A])=>e.jsx("div",{className:`agent-name-chip${S===a?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(a),Be(Ee.DEFAULT_AGENT_CLASS,a)},children:e.jsxs("span",{className:"agent-name-text",children:[A.icon," ",a.charAt(0).toUpperCase()+a.slice(1)]})},a)),N.map(a=>e.jsx("div",{className:`agent-name-chip${S===a.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(a.id),Be(Ee.DEFAULT_AGENT_CLASS,a.id)},children:e.jsxs("span",{className:"agent-name-text",children:[a.icon," ",a.name]})},a.id))]})]})}),D("appearance")&&e.jsx(H,{title:o("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:G&&D("appearance"),children:e.jsx(ga,{})}),D("connection")&&e.jsxs(H,{title:o("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:G&&D("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:E.map((a,A)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:o("config:connection.priorityLabel",{defaultValue:"Priority"}),children:A+1}),e.jsx("span",{className:"backend-url-text",title:a,children:a}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>as(A,-1),disabled:A===0,title:o("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>as(A,1),disabled:A===E.length-1,title:o("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ds(A),title:o("common:buttons.remove"),children:"x"})]},`${a}-${A}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:j,onChange:a=>L(a.target.value),placeholder:o("config:connection.addUrlPlaceholder",{defaultValue:"http://host:port"}),onKeyDown:a=>{a.key==="Enter"&&ts()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ts,disabled:!j.trim(),title:o("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),W&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:$s,title:o("config:connection.saveAndReconnect"),children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.urlsHint",{defaultValue:"Tried in order on connect; the first reachable host wins. Leave empty for auto-detect."})})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:connection.authToken"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:se?"text":"password",className:"config-input config-input-full",value:z,onChange:a=>Ls(a.target.value),placeholder:o("config:connection.tokenPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&$&&ns()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>ne(!se),title:o(se?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(I,{name:se?"eye-closed":"eye",size:14})}),$&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:ns,title:o("config:connection.saveAndReconnect"),children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:connection.codexBinaryPath"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:ge,onChange:a=>Os(a.target.value),placeholder:o("config:connection.codexBinaryPathPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&$e&&os()}}),$e&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:os,children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("common:buttons.reconnect"),query:t})}),e.jsx("button",{className:"config-btn",onClick:()=>Ye(),title:"Force reconnect to server",children:o("common:buttons.reconnect")})]})]}),D("scene")&&e.jsxs(H,{title:o("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:G&&D("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:scene.characterSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"3.0",step:"0.1",value:s.characterScale,onChange:a=>n({...s,characterScale:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.characterScale.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:scene.scale2d",{defaultValue:"2D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale2d,onChange:a=>n({...s,scale2d:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale2d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:scene.scale3d",{defaultValue:"3D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale3d,onChange:a=>n({...s,scale3d:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale3d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:t})}),e.jsx(Q,{checked:s.show2DTaskLabels,onChange:a=>n({...s,show2DTaskLabels:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:scene.time"),query:t})}),e.jsx(Ce,{options:Ve,value:s.timeMode,onChange:a=>n({...s,timeMode:a}),iconOnly:!0})]})]}),D("terrain")&&e.jsxs(H,{title:o("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:G&&D("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:t})}),e.jsx(Q,{checked:s.terrain.simpleMode??!1,onChange:a=>Ne({simpleMode:a})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:Oe.map(a=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[a.key]?"active":""}`,onClick:()=>Rs(a.key),title:a.label,children:a.icon},a.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:terrainSettings.fog"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.terrain.fogDensity,onChange:a=>Ne({fogDensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?o("config:fogValues.off"):s.terrain.fogDensity<=1?o("config:fogValues.low"):o("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:terrainSettings.brightness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.2",max:"2",step:"0.1",value:s.terrain.brightness,onChange:a=>Ne({brightness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?o("config:brightnessValues.dark"):s.terrain.brightness<=1.2?o("config:brightnessValues.normal"):o("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:terrainSettings.floor"),query:t})}),e.jsx(Ce,{options:Ke,value:s.terrain.floorStyle,onChange:a=>Ne({floorStyle:a}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:terrainSettings.sky"),query:t})}),e.jsx("div",{className:"sky-color-selector",children:Fe.map(a=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===a.value?"active":""}`,onClick:()=>Ne({skyColor:a.value}),title:a.label,style:{background:a.color}},a.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:terrainSettings.battlefieldSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:a=>Ne({battlefieldSize:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),D("modelStyle")&&e.jsxs(H,{title:o("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:G&&D("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.saturation"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.modelStyle.saturation,onChange:a=>we({saturation:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?o("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?o("config:saturationValues.normal"):o("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.roughness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.roughness,onChange:a=>we({roughness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?o("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?o("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?o("config:roughnessValues.normal"):o("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.metalness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.metalness,onChange:a=>we({metalness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?o("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?o("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?o("config:metalnessValues.mixed"):o("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.glow"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"1",step:"0.05",value:s.modelStyle.emissiveBoost,onChange:a=>we({emissiveBoost:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?o("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?o("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?o("config:glowValues.med"):o("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.reflections"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"2",step:"0.1",value:s.modelStyle.envMapIntensity,onChange:a=>we({envMapIntensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?o("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?o("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?o("config:reflectionValues.normal"):o("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.wireframe"),query:t})}),e.jsx(Q,{checked:s.modelStyle.wireframe,onChange:a=>we({wireframe:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.colorMode"),query:t})}),e.jsx(Ce,{options:He,value:s.modelStyle.colorMode,onChange:a=>we({colorMode:a}),iconOnly:!0})]})]}),D("animations")&&e.jsxs(H,{title:o("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:G&&D("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:animationSettings.idle"),query:t})}),e.jsx(Ce,{options:Le,value:s.animations.idleAnimation,onChange:a=>is({idleAnimation:a}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:animationSettings.working"),query:t})}),e.jsx(Ce,{options:Le,value:s.animations.workingAnimation,onChange:a=>is({workingAnimation:a}),iconOnly:!0})]})]}),D("secrets")&&e.jsx(H,{title:o("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:G&&D("secrets"),children:e.jsx(Wt,{})}),D("claudeAccounts")&&e.jsx(H,{title:o("config:sections.claudeAccounts",{defaultValue:"Claude Accounts"}),storageKey:"claudeAccounts",defaultOpen:!1,forceOpen:G&&D("claudeAccounts"),children:e.jsx(Tt,{})}),D("grokAccounts")&&e.jsx(H,{title:o("config:sections.grokAccounts",{defaultValue:"Grok Accounts"}),storageKey:"grokAccounts",defaultOpen:!1,forceOpen:G&&D("grokAccounts"),children:e.jsx(hs,{provider:"grok"})}),D("codexAccounts")&&e.jsx(H,{title:o("config:sections.codexAccounts",{defaultValue:"Codex Accounts"}),storageKey:"codexAccounts",defaultOpen:!1,forceOpen:G&&D("codexAccounts"),children:e.jsx(hs,{provider:"codex"})}),D("systemPrompt")&&e.jsx(H,{title:o("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:G&&D("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>oe(!0),children:o("config:systemPrompt.editPrompt")})]})}),D("data")&&e.jsx(H,{title:o("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:G&&D("data"),children:e.jsx(ma,{})}),Re&&e.jsx(H,{title:o("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:G&&Re,children:e.jsx(Na,{onOpenModal:a=>{a==="whatsapp"?me(!0):i==null||i(a)}})}),D("workflows")&&e.jsxs(H,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:G&&D("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(k,{text:"Create and manage automated workflow pipelines with visual state machine editor",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>r==null?void 0:r(),children:"Open Workflow Editor"})})]}),D("triggers")&&e.jsxs(H,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:G&&D("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(k,{text:"Create and manage event-driven triggers that fire agents with templates",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>g==null?void 0:g(),children:"Open Trigger Manager"})})]}),D("monitoring")&&e.jsxs(H,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:G&&D("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(k,{text:"View event logs, trigger history, workflow traces, and system stats",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>d==null?void 0:d(),children:"Open Monitoring & Logs"})})]}),D("statistics")&&e.jsxs(H,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:G&&D("statistics"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(k,{text:"View token usage charts and system-wide agent statistics",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>c==null?void 0:c(),children:"Open Statistics"})})]}),D("experimental")&&e.jsxs(H,{title:o("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:G&&D("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(k,{text:o("config:experimental.2dView"),query:t})," ",e.jsx(I,{name:"map",size:12})]}),e.jsx(Q,{checked:u.experimental2DView,onChange:a=>x.updateSettings({experimental2DView:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(k,{text:o("config:experimental.voiceAssistant"),query:t})," ",e.jsx(I,{name:"microphone",size:12})]}),e.jsx(Q,{checked:u.experimentalVoiceAssistant,onChange:a=>x.updateSettings({experimentalVoiceAssistant:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(k,{text:o("config:experimental.tts"),query:t})," ",e.jsx(I,{name:"speaker-on",size:12})]}),e.jsx(Q,{checked:u.experimentalTTS,onChange:a=>x.updateSettings({experimentalTTS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Duplicate system prompt for improved LLM attention coverage. Increases input token usage.",children:e.jsx(k,{text:o("config:experimental.echoPrompt"),query:t})}),e.jsx(Q,{checked:u.experimentalEchoPrompt,onChange:async a=>{x.updateSettings({experimentalEchoPrompt:a});try{await Zt(a)}catch(A){console.error("Failed to sync echo prompt setting to server:",A)}}})]}),e.jsx("span",{className:"config-hint",children:o("config:experimental.hint")})]}),D("about")&&e.jsx(H,{title:o("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:G&&D("about"),children:e.jsx(ja,{})})]}),e.jsx(wa,{isOpen:te,onClose:()=>oe(!1)}),e.jsx(Ca,{isOpen:de,onClose:()=>ie(!1)}),e.jsx(_a,{isOpen:he,onClose:()=>Se(!1)}),e.jsx(Ha,{isOpen:Ae,onClose:()=>ue(!1)}),e.jsx(qa,{isOpen:Ie,onClose:()=>me(!1),onOpenConfig:()=>ie(!0),onOpenNotifications:()=>Se(!0),onOpenHistory:()=>ue(!0)})]})}function dn({onConfigChange:s,onToolChange:n,config:t,isOpen:i,onClose:d,onOpenBuildingModal:c,onOpenAreaExplorer:r,onOpenIntegrationsModal:g,onOpenMonitoringModal:o,onOpenStatisticsModal:u,onOpenWorkflowEditor:N,onOpenTriggerManager:S}){const{t:m}=ee(["config","common"]),_=It(),v=Dt(),P=$t(),b=Lt(),p=Ot(),C=Array.from(_.values()),B=Array.from(v.values()),[F,J]=l.useState(""),K=l.useRef(null);if(l.useEffect(()=>{const h=E=>{E.key==="Escape"&&i&&d()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[i,d]),l.useEffect(()=>{if(i&&K.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const E=setTimeout(()=>{var R;(R=K.current)==null||R.focus()},50);return()=>clearTimeout(E)}},[i]),!i)return null;const X=h=>{n(p===h?null:h)},U=h=>{x.selectArea(b===h?null:h),n("select")},Z=(h,E)=>{h.stopPropagation(),x.deleteArea(E)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:d}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:m("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:m("common:buttons.close"),children:"×"})]}),e.jsxs("div",{className:"toolbox-search",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{ref:K,type:"text",placeholder:m("config:searchPlaceholder"),value:F,onChange:h=>J(h.target.value),className:"toolbox-search-input"}),F&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>J(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(H,{title:m("config:areas.title",{count:C.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${p==="select"?"active":""}`,onClick:()=>X("select"),title:m("config:tools.select"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"})})})}),e.jsx("button",{className:`tool-btn ${p==="rectangle"?"active":""}`,onClick:()=>X("rectangle"),title:m("config:tools.rectangle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"})})})}),e.jsx("button",{className:`tool-btn ${p==="circle"?"active":""}`,onClick:()=>X("circle"),title:m("config:tools.circle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("circle",{cx:"12",cy:"12",r:"9"})})})})]}),e.jsx("div",{className:"areas-list",children:C.length===0?e.jsx("div",{className:"areas-empty",children:m("config:areas.drawToCreate")}):C.map(h=>e.jsx(zt,{area:h,isSelected:b===h.id,onClick:()=>U(h.id),onDelete:E=>Z(E,h.id)},h.id))})]})}),b&&e.jsx(qt,{area:_.get(b),onClose:()=>x.selectArea(null),onOpenFolder:r}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(H,{title:m("config:buildings.title",{count:B.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:h=>{h.stopPropagation(),c==null||c()},title:m("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:B.length===0?e.jsx("div",{className:"buildings-empty",children:m("config:buildings.clickToAdd")}):B.map(h=>e.jsx(Vt,{building:h,isSelected:P.has(h.id),onClick:()=>{x.selectBuilding(P.has(h.id)?null:h.id)},onEdit:()=>c==null?void 0:c(h.id)},h.id))})})}),P.size===1&&(()=>{const h=Array.from(P)[0],E=v.get(h);return E?e.jsx(Kt,{building:E,onClose:()=>x.selectBuilding(null),onOpenModal:()=>c==null?void 0:c(h)}):null})(),e.jsx(nn,{config:t,onChange:s,searchQuery:F,onOpenIntegrationsModal:g,onOpenMonitoringModal:o,onOpenStatisticsModal:u,onOpenWorkflowEditor:N,onOpenTriggerManager:S})]})]})]})}export{dn as Toolbox};
1
+ import{r as l,j as e,I,u as ee,bV as js,ai as vs,bW as Ms,bY as Bs,s as x,cS as Us,F as zs,cT as Vs,Z as xe,N as Y,aY as q,c as ye,d as ke,cU as Ks,cV as Hs,cW as qs,cX as Ws,cY as Gs,cZ as Ys,c_ as Js,c$ as Ns,d0 as Xs,d1 as Zs,d2 as Qs,aX as et,av as st,a4 as _e,n as tt,d3 as ws,d4 as at,d5 as Ze,d6 as nt,d7 as ot,d8 as it,d9 as lt,da as ct,db as rt,dc as dt,br as ut,k as pt,m as ht,S as Ee,dd as mt,de as gt,df as ft,dg as qe,dh as xt,di as bt,B as jt,b_ as rs,dj as vt,dk as Nt,dl as wt,dm as yt,dn as ys,dp as ds,dq as ks,dr as kt,ds as St,dt as Pe,du as Ct,dv as We,dw as us,dx as ps,bR as Ge,y as Be,x as At,dy as Ye,dz as Tt,dA as hs,dB as Et,dC as Pt,dD as _t,a0 as It,f as Dt,dE as $t,dF as Lt,dG as Ot}from"./main-BTH4eRQ6.js";import{g as Ft,d as Rt,u as Mt}from"./area-logos-CzRaMbh2.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-DYBBrXTx.js";const Ss="tide-toolbox-collapse";function Bt(s,n){try{const t=localStorage.getItem(`${Ss}-${s}`);if(t!==null)return t==="true"}catch{}return n}function Ut(s,n){try{localStorage.setItem(`${Ss}-${s}`,String(n))}catch{}}function H({title:s,storageKey:n,defaultOpen:t=!1,forceOpen:i=!1,children:d,headerExtra:c}){const[r,g]=l.useState(()=>n?Bt(n,t):t),o=()=>{const N=!r;g(N),n&&Ut(n,N)},u=i||r;return e.jsxs("div",{className:`collapsible-section ${u?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:o,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[c,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(I,{name:u?"caret-down":"caret-right",size:10})})]})]}),u&&e.jsx("div",{className:"collapsible-content",children:d})]})}function zt({area:s,isSelected:n,onClick:t,onDelete:i}){const{t:d}=ee(["config","common"]),c=s.assignedAgentIds.length,r=s.type==="rectangle"?d("config:areas.rect"):d("config:areas.circle");return e.jsxs("div",{className:`area-item ${n?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[r," ",c>0&&`• ${c} ${c>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:i,title:d("config:areas.deleteArea"),children:"×"})]})}function Vt({building:s,isSelected:n,onClick:t,onEdit:i}){var g;const{t:d}=ee(["config"]),c=((g=s.pm2Status)==null?void 0:g.ports)||[],r=(o,u)=>{o.stopPropagation(),window.open(`http://${window.location.hostname}:${u}`,"_blank")};return e.jsxs("div",{className:`building-item ${n?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:js[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(I,{name:vs(s.type),size:16})}),e.jsxs("div",{className:"building-info",children:[e.jsx("div",{className:"building-name",children:s.name}),e.jsxs("div",{className:"building-meta",children:[s.type,c.length>0&&e.jsx("span",{className:"building-ports",children:c.map(o=>e.jsxs("a",{href:`http://${window.location.hostname}:${o}`,className:"building-port-link",onClick:u=>r(u,o),title:`Open :${o}`,children:[":",o]},o))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:o=>{o.stopPropagation(),i()},title:d("config:buildings.editBuilding"),children:e.jsx(I,{name:"gear",size:14})})]})}function Kt({building:s,onClose:n,onOpenModal:t}){var u,N,S,m,_,v,P,b;const{t:i}=ee(["config","common"]),c=Ms().get(s.id)||[],r=Bs[s.style||"server-rack"],g=p=>{x.sendBuildingCommand(s.id,p)},o=p=>{window.open(p,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx(I,{name:vs(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:js[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:n,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:i("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:i("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:r.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children:i("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:i("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>g("start"),disabled:!((u=s.commands)!=null&&u.start)||s.status==="running",title:((N=s.commands)==null?void 0:N.start)||i("config:buildings.noStartCommand"),children:[e.jsx(I,{name:"play",size:12})," ",i("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>g("stop"),disabled:!((S=s.commands)!=null&&S.stop)||s.status==="stopped",title:((m=s.commands)==null?void 0:m.stop)||i("config:buildings.noStopCommand"),children:[e.jsx(I,{name:"stop",size:12,weight:"fill"})," ",i("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>g("restart"),disabled:!((_=s.commands)!=null&&_.restart),title:((v=s.commands)==null?void 0:v.restart)||i("config:buildings.noRestartCommand"),children:[e.jsx(I,{name:"refresh",size:12})," ",i("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>g("healthCheck"),disabled:!((P=s.commands)!=null&&P.healthCheck),title:((b=s.commands)==null?void 0:b.healthCheck)||i("config:buildings.noHealthCheck"),children:[e.jsx(I,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:i("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((p,C)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>o(p.url),title:p.url,children:[e.jsx(I,{name:"link",size:12})," ",p.label||p.url]},C))})]}),c.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[i("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>x.clearBuildingLogs(s.id),title:i("common:buttons.clear"),children:i("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:c.slice(-5).map((p,C)=>e.jsx("div",{className:"building-editor-log-entry",children:p},C))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(I,{name:"gear",size:12})," ",i("config:buildings.fullSettings")]})})]})}const Ht=[{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 qt({area:s,onClose:n,onOpenFolder:t}){var ae;const{t:i}=ee(["config","common"]),[d,c]=l.useState(s.name),[r,g]=l.useState(s.prompt||""),[o,u]=l.useState(!1),[N,S]=l.useState(""),[m,_]=l.useState(!1),v=l.useRef(null);l.useEffect(()=>{c(s.name)},[s.id,s.name]),l.useEffect(()=>{g(s.prompt||"")},[s.id,s.prompt]);const P=j=>{const L=j.target.value;c(L),x.updateArea(s.id,{name:L})},b=j=>{x.updateArea(s.id,{color:j})},p=j=>{const L=j.target.value;g(L),x.updateArea(s.id,{prompt:L})},C=()=>{N.trim()&&(x.addDirectoryToArea(s.id,N.trim()),S(""),u(!1))},B=(j,L)=>{L.stopPropagation(),x.removeDirectoryFromArea(s.id,j)},F=()=>{x.bringAreaToFront(s.id)},J=()=>{x.sendAreaToBack(s.id)},K=l.useCallback(()=>{let j=2,L=2;s.type==="rectangle"&&s.width&&s.height?(j=s.width,L=s.height):s.type==="circle"&&s.radius&&(j=s.radius*1.414,L=s.radius*1.414);const z=Math.min(j,L)*.4;return{width:Math.round(z*10)/10,height:Math.round(z*10)/10}},[s.type,s.width,s.height,s.radius]),X=async j=>{var z;const L=(z=j.target.files)==null?void 0:z[0];if(L){_(!0);try{const w=await Mt(s.id,L),$=K();x.updateArea(s.id,{logo:{filename:w.filename,position:"center",width:$.width,height:$.height,keepAspectRatio:!0,opacity:.8}})}catch(w){console.error("Failed to upload logo:",w)}finally{_(!1),v.current&&(v.current.value="")}}},U=async()=>{try{await Rt(s.id),x.updateArea(s.id,{logo:void 0})}catch(j){console.error("Failed to remove logo:",j)}},Z=j=>{s.logo&&x.updateArea(s.id,{logo:{...s.logo,position:j}})},h=j=>{if(!s.logo)return;const L=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const z=s.logo.height/s.logo.width;x.updateArea(s.id,{logo:{...s.logo,width:L,height:Math.round(L*z*10)/10}})}else x.updateArea(s.id,{logo:{...s.logo,width:L}})},E=j=>{if(!s.logo)return;const L=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const z=s.logo.width/s.logo.height;x.updateArea(s.id,{logo:{...s.logo,height:L,width:Math.round(L*z*10)/10}})}else x.updateArea(s.id,{logo:{...s.logo,height:L}})},R=()=>{s.logo&&x.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},W=j=>{s.logo&&x.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(j.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:i("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:n,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange:P,placeholder:i("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:Us.map(j=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===j?"selected":""}`,style:{backgroundColor:j},onClick:()=>b(j),"aria-label":`Set area color ${j}`,"aria-pressed":s.color===j,title:j},j))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:F,title:i("config:areas.bringToFront"),children:[e.jsx(I,{name:"arrow-up",size:12})," ",i("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:J,title:i("config:areas.sendToBack"),children:[e.jsx(I,{name:"arrow-down",size:12})," ",i("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:i("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(ae=s.logo)!=null&&ae.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Ft(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:U,children:i("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var j;return(j=v.current)==null?void 0:j.click()},disabled:m,children:m?"...":e.jsx(I,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:Ht.map(({key:j,labelKey:L})=>{var z;return e.jsx("button",{className:`area-logo-pos-btn ${((z=s.logo)==null?void 0:z.position)===j?"active":""}`,onClick:()=>Z(j),children:i(`config:areas.${L}`)},j)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:i("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:h,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:i("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:E,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:i("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:R}),i("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("config:areas.logoOpacity")}),e.jsxs("div",{className:"area-logo-opacity-row",children:[e.jsx("input",{type:"range",min:0,max:1,step:.05,value:s.logo.opacity??.8,onChange:W,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var j;return(j=v.current)==null?void 0:j.click()},disabled:m,children:m?"...":i("config:areas.uploadLogo")}),e.jsx("input",{ref:v,type:"file",accept:"image/*",style:{display:"none"},onChange:X})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:i("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(j=>e.jsxs("div",{className:"area-folder-item",title:j,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:i("config:areas.openFolder"),children:e.jsx(I,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:j.split("/").pop()||j}),e.jsx("button",{className:"area-folder-remove",onClick:L=>B(j,L),title:i("config:areas.removeFolder"),children:"×"})]},j)),o?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(zs,{value:N,onChange:S,onSubmit:C,placeholder:i("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:C,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>u(!0),children:i("config:areas.addFolder")})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:i("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:r,onChange:p,placeholder:i("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:i("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:i("config:areas.rightClickUnassign")})]})]})}function Wt(){const{t:s}=ee(["config","common"]),n=Vs(),[t,i]=l.useState(!1),[d,c]=l.useState(null),[r,g]=l.useState({name:"",key:"",value:"",description:""}),[o,u]=l.useState(null),N=()=>{i(!0),c(null),g({name:"",key:"",value:"",description:""})},S=p=>{c(p.id),i(!1),g({name:p.name,key:p.key,value:p.value,description:p.description||""})},m=()=>{i(!1),c(null),g({name:"",key:"",value:"",description:""})},_=()=>{!r.name.trim()||!r.key.trim()||(d?x.updateSecret(d,{name:r.name.trim(),key:r.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:r.value,description:r.description.trim()||void 0}):x.createSecret({name:r.name.trim(),key:r.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:r.value,description:r.description.trim()||void 0}),m())},v=p=>{u(p)},P=()=>{o&&(x.deleteSecret(o),d===o&&m())},b=p=>{navigator.clipboard.writeText(`{{${p}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children:n.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):n.map(p=>e.jsxs("div",{className:`secret-item ${d===p.id?"editing":""}`,children:[e.jsxs("div",{className:"secret-item-header",children:[e.jsxs("div",{className:"secret-item-info",children:[e.jsx("span",{className:"secret-item-name",children:p.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>b(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:()=>S(p),title:s("common:buttons.edit"),children:e.jsx(I,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>v(p.id),title:s("common:buttons.delete"),children:"×"})]})]}),p.description&&e.jsx("div",{className:"secret-item-description",children:p.description})]},p.id))}),(t||d)&&e.jsxs("div",{className:"secret-form",children:[e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.name")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.namePlaceholder"),value:r.name,onChange:p=>g({...r,name:p.target.value}),autoFocus:!0})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:"Key"}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.keyPlaceholder"),value:r.key,onChange:p=>g({...r,key:p.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${r.key||"KEY"}}}`})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("config:secrets.secretValue")}),e.jsx("input",{type:"password",className:"secret-form-input",placeholder:s("config:secrets.valuePlaceholder"),value:r.value,onChange:p=>g({...r,value:p.target.value})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.description")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.descriptionPlaceholder"),value:r.description,onChange:p=>g({...r,description:p.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:m,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:_,disabled:!r.name.trim()||!r.key.trim(),children:s(d?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:N,children:s("config:secrets.addSecret")}),e.jsx(xe,{isOpen:o!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:P,onClose:()=>u(null)})]})}async function Gt(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch system prompt: ${n.statusText}`);return(await n.json()).prompt||""}async function Yt(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function Jt(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to clear system prompt: ${n.statusText}`)}async function Xt(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch echo prompt setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Zt(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function Qt(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex binary path: ${n.statusText}`);return(await n.json()).path||""}async function ea(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function sa(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch tmux mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ta(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function aa(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch interactive mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function na(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function oa(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/codex-app-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex app-server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ia(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/codex-app-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update codex app-server mode setting: ${t.statusText}`)}async function la(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/opencode-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch opencode server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ca(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/opencode-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update opencode server mode setting: ${t.statusText}`)}async function ra(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/pi-rpc-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch pi RPC mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function da(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/pi-rpc-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update pi RPC mode setting: ${t.statusText}`)}async function ua(){const s=Y(),n=await fetch(`${q()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch backup status: ${n.statusText}`);return n.json()}async function pa(s){const n=Y(),t=await fetch(`${q()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok){const i=await t.json().catch(()=>({}));throw new Error(i.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function ha({checked:s,onChange:n,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:i=>n(i.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function ma(){const{t:s}=ee(["config","common"]),[n,t]=l.useState([]),[i,d]=l.useState(new Set),[c,r]=l.useState(new Set),[g,o]=l.useState(!1),[u,N]=l.useState(!1),[S,m]=l.useState(null),[_,v]=l.useState(null),[P,b]=l.useState(null),[p,C]=l.useState(null),[B,F]=l.useState(!1),[J,K]=l.useState(null);l.useEffect(()=>{ye(ke("/api/config/categories")).then(w=>w.json()).then(w=>{const $=Array.isArray(w)?w:[];t($),d(new Set($.map(O=>O.id)))}).catch(w=>console.error("Failed to fetch config categories:",w))},[]),l.useEffect(()=>{ua().then(C).catch(w=>{console.error("Failed to fetch backup status:",w),K(w.message||"Failed to fetch backup status")})},[]);const X=async w=>{if(!B){F(!0),K(null);try{const $=await pa(w);C($)}catch($){K($.message||"Failed to update backup setting")}finally{F(!1)}}},U=w=>{d($=>{const O=new Set($);return O.has(w)?O.delete(w):O.add(w),O})},Z=w=>{r($=>{const O=new Set($);return O.has(w)?O.delete(w):O.add(w),O})},h=()=>d(new Set(n.map(w=>w.id))),E=()=>d(new Set),R=()=>{_&&r(new Set(_.categories.map(w=>w.id)))},W=()=>r(new Set),ae=async()=>{var w;if(i.size!==0){o(!0),b(null);try{const $=Array.from(i).join(","),O=await ye(ke(`/api/config/export?categories=${$}`));if(!O.ok)throw new Error("Export failed");const se=await O.blob(),ne=window.URL.createObjectURL(se),T=document.createElement("a");T.href=ne;const y=O.headers.get("Content-Disposition"),te=((w=y==null?void 0:y.match(/filename="(.+)"/))==null?void 0:w[1])||"tide-commander-config.zip";T.download=te,document.body.appendChild(T),T.click(),document.body.removeChild(T),window.URL.revokeObjectURL(ne),b({type:"success",text:s("config:data.exportSuccess")})}catch($){b({type:"error",text:$.message||"Export failed"})}finally{o(!1)}}},j=async w=>{var O;const $=(O=w.target.files)==null?void 0:O[0];if($){m($),b(null),v(null),r(new Set);try{const se=await ye(ke("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await $.arrayBuffer()});if(!se.ok){const y=await se.json();throw new Error(y.error||"Failed to preview config file")}const ne=await se.json(),T=Array.isArray(ne.categories)?ne.categories:[];v({...ne,categories:T}),r(new Set(T.map(y=>y.id)))}catch(se){b({type:"error",text:se.message||"Failed to read config file"}),m(null)}}},L=async()=>{if(!(!S||c.size===0)){N(!0),b(null);try{const w=Array.from(c).join(","),$=await ye(ke(`/api/config/import?categories=${w}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await S.arrayBuffer()}),O=await $.json();if(!$.ok)throw new Error(O.error||"Import failed");b({type:"success",text:O.message||s("config:data.importSuccess")}),m(null),v(null),r(new Set)}catch(w){b({type:"error",text:w.message||"Import failed"})}finally{N(!1)}}},z=()=>{m(null),v(null),r(new Set),b(null)};return e.jsxs("div",{className:"data-section",children:[P&&e.jsx("div",{className:`data-message data-message-${P.type}`,children:P.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(ha,{checked:!!(p!=null&&p.enabled),disabled:B||!p,onChange:X})]}),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…"}),J&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:J})]})]}),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:E,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:n.map(w=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:i.has(w.id),onChange:()=>U(w.id)}),e.jsx("span",{className:"data-category-name",children:w.name})]},w.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ae,disabled:g||i.size===0,children:g?s("config:data.exporting"):s("config:data.exportCount",{count:i.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),S?_?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:S.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(_.exportedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-subtitle",children:s("config:data.selectToImport")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:R,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:W,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:_.categories.map(w=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:c.has(w.id),onChange:()=>Z(w.id)}),e.jsx("span",{className:"data-category-name",children:w.name}),w.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",w.fileCount," ",s("config:data.files"),")"]})]},w.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:z,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:L,disabled:u||c.size===0,children:u?s("config:data.importing"):s("config:data.importCount",{count:c.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:j,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function ga(){const[s,n]=l.useState(()=>Ks()),t=i=>{n(i);const d=Gs(i);Ys(d)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:Hs.map(i=>e.jsxs("button",{className:`theme-option ${s===i.id?"active":""}`,onClick:()=>t(i.id),title:i.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:i.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:i.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:i.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:i.name})]},i.id))})})}function fa(){const{t:s}=ee(["config"]),{installInfo:n,phase:t,output:i,error:d,newVersion:c,autoRestart:r,refreshInstallInfo:g,runUpdate:o,reset:u}=Js(),[N,S]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{g()},[g]),l.useEffect(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)},[i]);const _=l.useCallback(()=>{S(!0)},[]),v=l.useCallback(()=>{S(!1)},[]),P=l.useCallback(()=>{S(!1),o()},[o]),b=l.useCallback(()=>{u(),S(!1),g()},[u,g]),p=Ns.isNativePlatform(),C=s(p?"config:about.autoUpdateServerTitle":"config:about.autoUpdateTitle");return n?n.isGlobalInstall?n.autoUpdateSupported?!n.updateAvailable&&t==="idle"?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:C}),t==="idle"&&!N&&n.updateAvailable&&e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsxs("span",{className:"about-autoupdate-versions",children:[e.jsx("span",{className:"about-autoupdate-current",children:n.currentVersion}),e.jsx("span",{className:"about-autoupdate-arrow",children:"→"}),e.jsx("span",{className:"about-autoupdate-latest",children:n.latestVersion})]}),e.jsx("button",{className:"about-update-btn download",onClick:_,children:s("config:about.autoUpdateButton")})]}),t==="idle"&&N&&e.jsxs("div",{className:"about-autoupdate-confirm",children:[e.jsx("div",{className:"about-autoupdate-confirm-title",children:s("config:about.autoUpdateConfirmTitle")}),e.jsx("div",{className:"about-autoupdate-confirm-body",children:s("config:about.autoUpdateConfirmBody")}),e.jsxs("div",{className:"about-autoupdate-confirm-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:v,children:s("config:about.autoUpdateCancel")}),e.jsx("button",{className:"about-update-btn download",onClick:P,children:s("config:about.autoUpdateConfirm")})]})]}),(t==="running"||t==="success"||t==="failed")&&e.jsxs("div",{className:"about-autoupdate-stream",children:[e.jsxs("div",{className:"about-autoupdate-stream-title",children:[t==="running"&&s("config:about.autoUpdateRunning"),t==="success"&&s("config:about.autoUpdateSuccess"),t==="failed"&&s("config:about.autoUpdateFailed")]}),e.jsx("pre",{ref:m,className:"about-autoupdate-output",children:i||"..."}),t==="success"&&e.jsxs("div",{className:"about-autoupdate-success-hint",children:[c&&e.jsxs("div",{className:"about-autoupdate-newversion",children:["v",c]}),e.jsx("div",{children:s(r?"config:about.autoUpdateReconnectHint":"config:about.autoUpdateRestartHint")})]}),t==="failed"&&d&&e.jsx("div",{className:"about-update-error",children:d}),(t==="success"||t==="failed")&&e.jsx("div",{className:"about-autoupdate-stream-actions",children:e.jsx("button",{className:"about-update-btn changelog",onClick:b,children:s("config:about.autoUpdateClose")})})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:C}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdatePackageManagerNotice",{pm:n.packageManager})}),n.suggestedManualCommand&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"about-autoupdate-manualhint",children:s("config:about.autoUpdateManualCommand")}),e.jsx("pre",{className:"about-autoupdate-manualcmd",children:n.suggestedManualCommand})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:C}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdateDevMode")})]}):null}function xa(){const{t:s}=ee(["config"]),[n,t]=l.useState(null),[i,d]=l.useState(!1),[c,r]=l.useState(null);l.useEffect(()=>{Xs().then(t).catch(N=>r(N.message))},[]);const g=l.useCallback(async N=>{if(!i){d(!0),r(null);try{t(await Zs(N))}catch(S){r(S.message)}finally{d(!1)}}},[i]),o=Ns.isNativePlatform(),u=s(o?"config:about.unattendedServerTitle":"config:about.unattendedTitle");return!n&&!c?null:n?o&&!n.supported?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:u}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:about.unattendedDesc")}),e.jsxs("label",{className:"config-toggle",style:n.supported?void 0:{opacity:.5},children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:n.enabled,disabled:i||!n.supported,onChange:N=>void g(N.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),!n.supported&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedUnsupported")}),n.supported&&n.enabled&&n.pendingRestartVersion&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedPendingRestart",{version:n.pendingRestartVersion})}),n.supported&&n.enabled&&!n.pendingRestartVersion&&n.lastResult&&e.jsx("div",{className:"about-autoupdate-devnote",children:n.lastResult}),c&&e.jsx("div",{className:"about-update-error",children:c})]}):o?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:u}),e.jsx("div",{className:"about-update-error",children:c})]})}function ba(){var B;const{t:s}=ee(["config"]),{isAndroid:n,supported:t,otaActive:i,bundleState:d,serverInfo:c,infoError:r,updateAvailable:g,phase:o,progress:u,error:N,autoSync:S,checkNow:m,syncNow:_,resetToBundled:v,setAutoSync:P}=Qs(),[b,p]=l.useState(null),C=l.useRef(m);return C.current=m,l.useEffect(()=>{n&&(C.current(!1),et.getInfo().then(F=>p(F.version)).catch(()=>{}))},[n]),!n||t===!1?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:webBundle.title")}),e.jsxs("div",{className:"about-autoupdate-devnote",children:[i?s("config:webBundle.sourceOta",{hash:((B=d==null?void 0:d.hash)==null?void 0:B.slice(0,8))??"?"}):s("config:webBundle.sourceBundled"),b&&` · ${s("config:webBundle.apkVersion",{version:b})}`]}),c?e.jsxs("div",{className:"about-autoupdate-devnote",children:[s("config:webBundle.serverBundle",{version:c.version,hash:c.hash.slice(0,8)})," — ",s(g?"config:webBundle.updateAvailable":"config:webBundle.upToDate")]}):r&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:webBundle.serverUnavailable")}),N&&e.jsx("div",{className:"about-update-error",children:N}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:webBundle.autoSync")}),e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:S,onChange:F=>P(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 _(),disabled:o!=="idle"||!c,children:o==="syncing"?s("config:webBundle.syncingPct",{percent:u??0}):s("config:webBundle.syncNow")}),i&&e.jsx("button",{className:"about-update-btn changelog",onClick:()=>void v(),children:s("config:webBundle.reset")})]})]})}function ja(){const{t:s}=ee(["config"]),{updateAvailable:n,updateInfo:t,recentReleases:i,isChecking:d,error:c,currentVersion:r,isAndroid:g,downloadPhase:o,downloadProgress:u,checkForUpdate:N,downloadAndInstall:S,openReleasePage:m}=qs(),[_,v]=l.useState(!1),P=p=>p?`${(p/(1024*1024)).toFixed(1)} MB`:"",b=p=>new Date(p).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:e.jsx(I,{name:"waves",size:24})}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:r}),n&&t?e.jsx("span",{className:"about-version-update-badge",onClick:m,title:`Update available: ${t.version}`,children:t.version}):e.jsxs("a",{href:"https://github.com/deivid11/tide-commander/releases",target:"_blank",rel:"noopener noreferrer",className:"about-version-status",children:["(",s("config:about.updated"),")"]})]})]}),e.jsx(fa,{}),e.jsx(xa,{}),e.jsx(ba,{}),e.jsx("div",{className:"about-changelog-row",children:e.jsx("button",{className:"about-update-btn changelog",onClick:()=>v(!0),children:s("config:about.changelog")})}),e.jsxs("div",{className:"about-update",children:[n&&t?e.jsxs("div",{className:"about-update-available",children:[e.jsxs("div",{className:"about-update-header",children:[e.jsx("span",{className:"about-update-badge",children:s("config:about.updateAvailable")}),e.jsx("span",{className:"about-update-version",children:t.version})]}),t.apkSize&&e.jsxs("div",{className:"about-update-size",children:[s("config:about.sizeLabel"),": ",P(t.apkSize)]}),c&&e.jsx("div",{className:"about-update-error",children:c}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:m,children:s("config:about.changelog")}),g&&t.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:()=>void S(),disabled:o!=="idle",children:o==="downloading"?s("config:appUpdateBanner.downloadingPct",{percent:u??0}):s(o==="installing"?"config:appUpdateBanner.installHint":"config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:m,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(d?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>N(!0),disabled:d,children:d?"...":s("config:about.check")})]}),i.length>0&&e.jsxs("div",{className:"about-releases",children:[e.jsx("div",{className:"about-releases-title",children:s("config:about.recentReleases")}),e.jsx("div",{className:"about-releases-list",children:i.map(p=>e.jsxs("a",{href:p.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${p.version===`v${r}`||p.version===r?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:p.version}),e.jsx("span",{className:"about-release-date",children:b(p.publishedAt)})]},p.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:e.jsx(I,{name:"package",size:14})}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]}),_&&e.jsx(Ws,{onClose:()=>v(!1)})]})}const va={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function Na({onOpenModal:s}){const[n,t]=l.useState([]),[i,d]=l.useState(!0),c=l.useCallback(async()=>{try{const r=await ye(ke("/api/integrations"));if(!r.ok)return;const g=await r.json();t(g)}catch{}finally{d(!1)}},[]);return l.useEffect(()=>{c()},[c]),i?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):n.length===0?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"No integrations available."}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[n.map(r=>{const g=va[r.id]||"🔌",o=!!r.status.error,u=r.status.connected,N=o?"#f38ba8":u?"#a6e3a1":"#fab387",S=o?"Error":u?"Connected":"Setup Required",m=o?"✗":u?"✓":"⚠";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 8px",borderRadius:4,background:"var(--surface-1, #181825)",border:"1px solid var(--border, #313244)",fontSize:12,minHeight:26},children:[e.jsx("span",{style:{fontSize:13,flexShrink:0},children:g}),e.jsx("span",{style:{flex:1,minWidth:0,color:"var(--text-primary, #cdd6f4)",fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r.name}),e.jsx("span",{style:{color:N,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:S,children:m}),e.jsx("button",{onClick:()=>s(r.id),title:`Configure ${r.name}`,style:{background:"none",border:"none",cursor:"pointer",padding:"1px 3px",fontSize:12,color:"var(--text-secondary, #a6adc8)",borderRadius:3,flexShrink:0,lineHeight:1},onMouseEnter:_=>{_.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:_=>{_.target.style.color="var(--text-secondary, #a6adc8)"},children:"⚙️"})]},r.id)}),e.jsx("button",{onClick:()=>s(),style:{background:"none",border:"1px dashed var(--border, #313244)",borderRadius:4,padding:"3px 8px",cursor:"pointer",color:"var(--text-secondary, #a6adc8)",fontSize:11,textAlign:"center",marginTop:2},onMouseEnter:r=>{r.target.style.borderColor="var(--accent, #89b4fa)",r.target.style.color="var(--accent, #89b4fa)"},onMouseLeave:r=>{r.target.style.borderColor="var(--border, #313244)",r.target.style.color="var(--text-secondary, #a6adc8)"},children:"Manage All Integrations"})]})}const Ue="__global__";function wa({isOpen:s,onClose:n,initialAgentId:t}){const{t:i}=ee(["config"]),d=st(),[c,r]=l.useState(""),[g,o]=l.useState(""),[u,N]=l.useState(!1),[S,m]=l.useState(""),[_,v]=l.useState(""),[P,b]=l.useState(null),[p,C]=l.useState(null),[B,F]=l.useState(!1),[J,K]=l.useState(!1),[X,U]=l.useState(!1),[Z,h]=l.useState(null),E=l.useMemo(()=>[...d].sort((T,y)=>T.name.localeCompare(y.name)),[d]),R=l.useMemo(()=>d.find(T=>T.id===c),[d,c]),W=c===Ue;l.useEffect(()=>{if(!s)return;const T=t&&d.some(y=>y.id===t)?t:Ue;r(T),N(!1),Gt().then(y=>o(y)).catch(()=>o("")).finally(()=>N(!0))},[s]),l.useEffect(()=>{const T=c===Ue?g:(R==null?void 0:R.customPrompt)??"";m(T),v(T),F(!1),b(null),C(null)},[c,u]);const ae=T=>{const y=T.target.value;m(y),F(y!==_),b(null),C(null)},j=async()=>{if(c)try{b(null),C(null),W?(await Yt(S),o(S),C(i("config:systemPrompt.savedGlobal"))):(x.updateAgentProperties(c,{customPrompt:S}),C(i("config:systemPrompt.saved"))),v(S),F(!1)}catch(T){b(T instanceof Error?T.message:"Failed to save system prompt")}},L=()=>{K(!0)},z=async()=>{if(c)try{b(null),C(null),W?(await Jt(),o(""),C(i("config:systemPrompt.clearedGlobal"))):(x.updateAgentProperties(c,{customPrompt:""}),C(i("config:systemPrompt.cleared"))),m(""),v(""),F(!1)}catch(T){b(T instanceof Error?T.message:"Failed to clear system prompt")}},w=()=>{m(_),F(!1),b(null),C(null)},$=T=>{if(T!==c){if(B){h(T),U(!0);return}r(T)}},O=()=>{if(B){h(null),U(!0);return}n()},se=()=>{if(U(!1),Z){const T=Z;h(null),r(T)}else n()},ne=T=>{T.key==="Escape"&&(T.preventDefault(),O())};return s?e.jsxs(_e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:O,children:e.jsxs("div",{className:"system-prompt-modal",onClick:T=>T.stopPropagation(),onKeyDown:ne,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:i("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:O,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"modal-description",children:i("config:systemPrompt.description")}),e.jsxs("div",{className:"agent-picker",children:[e.jsx("label",{htmlFor:"system-prompt-agent",className:"editor-label",children:i("config:systemPrompt.agentLabel")}),e.jsxs("div",{className:"agent-picker-row",children:[W?e.jsx(I,{name:"globe",size:20,className:"agent-picker-icon"}):R&&e.jsx(tt,{classId:R.class,size:20,className:"agent-picker-icon"}),e.jsxs("select",{id:"system-prompt-agent",className:"agent-picker-select",value:c,onChange:T=>$(T.target.value),children:[e.jsxs("option",{value:Ue,children:[i("config:systemPrompt.globalOption"),g?" • ✦":""]}),E.map(T=>e.jsxs("option",{value:T.id,children:[T.name,T.customPrompt?" • ✦":""]},T.id))]})]})]}),P&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),P]}),p&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),p]}),e.jsxs("div",{className:"editor-wrapper",children:[e.jsxs("div",{className:"editor-header",children:[e.jsx("label",{htmlFor:"prompt-input",className:"editor-label",children:i("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[S.length," ",i("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:S,onChange:ae,placeholder:i("config:systemPrompt.placeholder"),rows:18,disabled:W&&!u,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:i(W?"config:systemPrompt.hintGlobal":"config:systemPrompt.hint")})]})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:L,disabled:!S||!c,children:i("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:O,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:w,disabled:!B,children:i("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:j,disabled:!B||!c,children:i("config:systemPrompt.save")})]})]})]})}),e.jsx(xe,{isOpen:J,title:i("config:systemPrompt.clear"),message:i(W?"config:systemPrompt.confirmClearGlobal":"config:systemPrompt.confirmClear"),confirmLabel:i("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{z()},onClose:()=>K(!1)}),e.jsx(xe,{isOpen:X,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:se,onClose:()=>{U(!1),h(null)}})]}):null}const ms={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},ya=2500,ka=12e4;function gs(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function Sa(s,n){return s.enabled===n.enabled&&s.baseUrl===n.baseUrl&&s.defaultSessionId===n.defaultSessionId&&s.webhookVerifyToken===n.webhookVerifyToken&&s.showIncomingToasts===n.showIncomingToasts}function Ca({isOpen:s,onClose:n}){const{t}=ee(["config"]),[i,d]=l.useState(ms),[c,r]=l.useState(ms),[g,o]=l.useState(!1),[u,N]=l.useState([]),[S,m]=l.useState(!0),[_,v]=l.useState(null),[P,b]=l.useState(null),[p,C]=l.useState(""),[B,F]=l.useState(!1),[J,K]=l.useState(""),[X,U]=l.useState(null),[Z,h]=l.useState(null),[E,R]=l.useState(null),W=l.useRef(null),ae=l.useRef(0),[j,L]=l.useState(""),[z,w]=l.useState(""),[$,O]=l.useState(null),[se,ne]=l.useState(!1),[T,y]=l.useState(!1),[te,oe]=l.useState(!1),[de,ie]=l.useState(!1),[he,Se]=l.useState(null),Ae=!Sa(i,c),ue=l.useCallback(()=>{W.current&&(clearTimeout(W.current),W.current=null)},[]),Ie=l.useCallback(async()=>{try{m(!0),v(null),b(null);const[f,V]=await Promise.all([ws(),at()]),ce=gs(f);if(d(ce),r(ce),o(!!V.configured),V.configured)try{const ve=await Ze();N(Array.isArray(ve)?ve:[])}catch{N([])}else N([])}catch(f){v(f instanceof Error?f.message:t("config:whatsapp.errors.loadFailed"))}finally{m(!1)}},[t]),me=l.useCallback(async()=>{try{const f=await Ze();N(Array.isArray(f)?f:[])}catch{}},[]);l.useEffect(()=>(s?Ie():(ue(),U(null),h(null),R(null),C(""),F(!1),O(null)),()=>{ue()}),[s,Ie,ue]);const ge=(f,V)=>{d(ce=>({...ce,[f]:V})),v(null),b(null)},De=async()=>{try{v(null),b(null);const f=await ct({enabled:i.enabled,baseUrl:i.baseUrl.trim(),defaultSessionId:i.defaultSessionId.trim(),webhookVerifyToken:i.webhookVerifyToken,showIncomingToasts:i.showIncomingToasts});window.dispatchEvent(new CustomEvent("tide:whatsapp-config-updated"));const V=gs(f);d(V),r(V),b(t("config:whatsapp.saved"))}catch(f){v(f instanceof Error?f.message:t("config:whatsapp.errors.saveFailed"))}},$e=()=>{d(c),v(null),b(null)},be=()=>{if(Ae){y(!0);return}n()},Ve=f=>{f.key==="Escape"&&(f.preventDefault(),be())},Ke=async()=>{const f=p.trim();if(f)try{v(null),b(null),await ot(f),C(""),F(!1),o(!0),b(t("config:whatsapp.apiKeySaved"))}catch(V){v(V instanceof Error?V.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},Le=()=>{oe(!0)},He=async()=>{try{v(null),b(null),await rt(),o(!1),b(t("config:whatsapp.apiKeyCleared"))}catch(f){v(f instanceof Error?f.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},Oe=l.useCallback(async f=>{if(Date.now()>ae.current){R(t("config:whatsapp.pairingTimeout")),U(null),h(null),ue(),me();return}try{const V=await nt(f);if(V.status&&["connected","paired","open","ready"].includes(V.status.toLowerCase())){R(t("config:whatsapp.pairingSuccess")),U(null),h(null),ue(),me();return}const ve=V.qrUrl??V.qr??null;ve&&h(ve)}catch(V){R(V instanceof Error?V.message:t("config:whatsapp.errors.qrFetchFailed"))}W.current=setTimeout(()=>{Oe(f)},ya)},[me,ue,t]),Fe=async()=>{const f=J.trim();if(f)try{v(null),b(null),R(null),h(null),ue(),await it(f),K(""),U(f),ae.current=Date.now()+ka,Oe(f),me()}catch(V){v(V instanceof Error?V.message:t("config:whatsapp.errors.sessionCreateFailed"))}},je=()=>{ue(),U(null),h(null),R(null)},D=f=>{Se(f),ie(!0)},Re=async()=>{if(he)try{v(null),b(null),await dt(he),X===he&&je(),me(),b(t("config:whatsapp.sessionDeleted"))}catch(f){v(f instanceof Error?f.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{Se(null)}},pe=async()=>{const f=j.trim(),V=z.trim();if(!(!f||!V))try{ne(!0),O(null);const ce=i.defaultSessionId.trim()||void 0;await lt(f,V,ce),O({kind:"success",text:t("config:whatsapp.testSent")})}catch(ce){O({kind:"error",text:ce instanceof Error?ce.message:t("config:whatsapp.errors.testSendFailed")})}finally{ne(!1)}};return s?e.jsxs(_e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:be,children:e.jsxs("div",{className:"whatsapp-config-modal",onClick:f=>f.stopPropagation(),onKeyDown:Ve,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsapp.title")}),e.jsx("button",{className:"modal-close",onClick:be,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:S?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")}),_&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),_]}),P&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),P]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.general")}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-enabled",className:"wa-label",children:t("config:whatsapp.enabled")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-enabled",type:"checkbox",checked:i.enabled,onChange:f=>ge("enabled",f.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-show-toasts",className:"wa-label",children:t("config:whatsapp.showIncomingToasts")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-show-toasts",type:"checkbox",checked:i.showIncomingToasts,onChange:f=>ge("showIncomingToasts",f.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.showIncomingToastsHelp")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-base-url",className:"wa-label",children:t("config:whatsapp.baseUrl")}),e.jsx("input",{id:"wa-base-url",type:"text",className:"wa-input",placeholder:"http://localhost:3007",value:i.baseUrl,onChange:f=>ge("baseUrl",f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-default-session",className:"wa-label",children:t("config:whatsapp.defaultSessionId")}),e.jsx("input",{id:"wa-default-session",type:"text",className:"wa-input",placeholder:t("config:whatsapp.defaultSessionIdPlaceholder"),value:i.defaultSessionId,onChange:f=>ge("defaultSessionId",f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-webhook-token",className:"wa-label",children:t("config:whatsapp.webhookVerifyToken")}),e.jsx("input",{id:"wa-webhook-token",type:"text",className:"wa-input",placeholder:t("config:whatsapp.webhookVerifyTokenPlaceholder"),value:i.webhookVerifyToken,onChange:f=>ge("webhookVerifyToken",f.target.value)})]})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.apiKey")}),e.jsx("div",{className:"wa-key-status",children:g?e.jsxs("span",{className:"wa-status wa-status-ok",children:[e.jsx(I,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(I,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:B?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:p,onChange:f=>C(f.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>F(f=>!f),title:t(B?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(I,{name:B?"eye-closed":"eye",size:14})}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ke,disabled:!p.trim(),children:t("config:whatsapp.saveKey")}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:Le,disabled:!g,children:t("config:whatsapp.clearKey")})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.apiKeyHint")})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.sessions")}),e.jsx("div",{className:"wa-sessions-list",children:!Array.isArray(u)||u.length===0?e.jsx("div",{className:"wa-empty",children:t("config:whatsapp.noSessions")}):u.map(f=>e.jsxs("div",{className:"wa-session-row",children:[e.jsxs("div",{className:"wa-session-info",children:[e.jsx("span",{className:"wa-session-id",children:f.id}),e.jsx("span",{className:`wa-session-status status-${(f.status??"unknown").toLowerCase()}`,children:f.status||"—"}),f.pairedNumber&&e.jsx("span",{className:"wa-session-paired",children:f.pairedNumber})]}),e.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:()=>D(f.id),children:t("config:whatsapp.deleteSession")})]},f.id))}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:"text",className:"wa-input",placeholder:t("config:whatsapp.addSessionPlaceholder"),value:J,onChange:f=>K(f.target.value),onKeyDown:f=>{f.key==="Enter"&&Fe()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Fe,disabled:!J.trim()||X!==null,children:t("config:whatsapp.addSession")})]}),X&&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:X})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:je,children:t("config:whatsapp.cancelPairing")})]}),Z?e.jsx("div",{className:"wa-qr-image",children:e.jsx("img",{src:Z,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")})]})]}),E&&!X&&e.jsx("div",{className:"wa-pairing-message",children:E})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.testMessage")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-to",className:"wa-label",children:t("config:whatsapp.testTo")}),e.jsx("input",{id:"wa-test-to",type:"text",className:"wa-input",placeholder:t("config:whatsapp.testToPlaceholder"),value:j,onChange:f=>L(f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-message",className:"wa-label",children:t("config:whatsapp.testMessageBody")}),e.jsx("textarea",{id:"wa-test-message",className:"wa-textarea",rows:4,placeholder:t("config:whatsapp.testMessageBodyPlaceholder"),value:z,onChange:f=>w(f.target.value)})]}),e.jsx("div",{className:"wa-field-inline wa-field-end",children:e.jsx("button",{type:"button",className:"btn btn-primary",onClick:pe,disabled:!j.trim()||!z.trim()||se,children:t(se?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),$&&e.jsxs("div",{className:`alert ${$.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:$.kind==="success"?"check":"warn",size:14})}),$.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:be,children:t("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:$e,disabled:!Ae||S,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:De,disabled:!Ae||S,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(xe,{isOpen:T,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{y(!1),n()},onClose:()=>y(!1)}),e.jsx(xe,{isOpen:te,title:t("config:whatsapp.clearKey"),message:t("config:whatsapp.confirmClearKey"),confirmLabel:t("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{He()},onClose:()=>oe(!1)}),e.jsx(xe,{isOpen:de,title:t("config:whatsapp.deleteSession"),message:t("config:whatsapp.confirmDeleteSession",{id:he??""}),confirmLabel:t("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Re()},onClose:()=>{ie(!1),Se(null)}})]}):null}const Cs=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function Qe(s=!1){const n=Y(),t={};return n&&(t.Authorization=`Bearer ${n}`),s&&(t["Content-Type"]="application/json"),t}async function es(s,n){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${n}: ${s.statusText}`}async function Aa(){const s=await fetch(`${q()}/api/whatsapp/notification-config`,{headers:Qe()});if(!s.ok)throw new Error(await es(s,"Failed to fetch WhatsApp notification config"));return s.json()}async function Ta(s){const n=await fetch(`${q()}/api/whatsapp/notification-config`,{method:"PATCH",headers:Qe(!0),body:JSON.stringify(s)});if(!n.ok)throw new Error(await es(n,"Failed to update WhatsApp notification config"));return n.json()}async function Ea(){const s=await fetch(`${q()}/api/whatsapp/notification-config`,{method:"DELETE",headers:Qe()});if(!s.ok)throw new Error(await es(s,"Failed to reset WhatsApp notification config"));return s.json()}const ze={messages:!0,statusChanges:!0,taskComplete:!0,errors:!0,planReady:!0,agentSpawned:!0,agentStopped:!0},fs={filter:{...ze},recipient:""};function Pa(s,n){if(s.recipient!==n.recipient)return!1;for(const t of Cs)if(s.filter[t]!==n.filter[t])return!1;return!0}function _a({isOpen:s,onClose:n}){const{t}=ee(["config"]),[i,d]=l.useState(fs),[c,r]=l.useState(fs),[g,o]=l.useState(!0),[u,N]=l.useState(null),[S,m]=l.useState(null),[_,v]=l.useState(!1),[P,b]=l.useState(!1),p=!Pa(i,c),C=l.useCallback(async()=>{try{o(!0),N(null),m(null);const h=await Aa(),E={filter:{...ze,...h.filter},recipient:h.recipient??""};d(E),r(E)}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{o(!1)}},[t]);l.useEffect(()=>{s&&C()},[s,C]);const B=(h,E)=>{d(R=>({...R,filter:{...R.filter,[h]:E}})),N(null),m(null)},F=h=>{d(E=>({...E,recipient:h})),N(null),m(null)},J=async()=>{try{N(null),m(null);const h=await Ta({filter:i.filter,recipient:i.recipient.trim()}),E={filter:{...ze,...h.filter},recipient:h.recipient??""};d(E),r(E),m(t("config:whatsappNotifications.saved"))}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.saveFailed"))}},K=()=>{d(c),N(null),m(null)},X=async()=>{try{N(null),m(null);const h=await Ea(),E={filter:{...ze,...h.filter},recipient:h.recipient??""};d(E),r(E),m(t("config:whatsappNotifications.resetDone"))}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.resetFailed"))}},U=()=>{if(p){v(!0);return}n()},Z=h=>{h.key==="Escape"&&(h.preventDefault(),U())};return s?e.jsxs(_e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:U,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:h=>h.stopPropagation(),onKeyDown:Z,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappNotifications.title")}),e.jsx("button",{className:"modal-close",onClick:U,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:g?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsappNotifications.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsappNotifications.description")}),u&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),u]}),S&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),S]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.recipient")}),e.jsxs("div",{className:"wan-field",children:[e.jsx("label",{htmlFor:"wan-recipient",className:"wan-label",children:t("config:whatsappNotifications.recipientLabel")}),e.jsx("input",{id:"wan-recipient",type:"text",className:"wan-input",placeholder:t("config:whatsappNotifications.recipientPlaceholder"),value:i.recipient,onChange:h=>F(h.target.value)}),e.jsx("span",{className:"wan-hint",children:t("config:whatsappNotifications.recipientHint")})]})]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.events")}),e.jsx("p",{className:"wan-section-hint",children:t("config:whatsappNotifications.eventsHint")}),Cs.map(h=>e.jsxs("div",{className:"wan-toggle-row",children:[e.jsxs("div",{className:"wan-toggle-info",children:[e.jsx("span",{className:"wan-toggle-title",children:t(`config:whatsappNotifications.events.${h}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${h}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:i.filter[h],onChange:E=>B(h,E.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:()=>b(!0),disabled:g,children:t("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:U,children:t("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:K,disabled:!p||g,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:J,disabled:!p||g,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(xe,{isOpen:_,title:t("config:whatsappNotifications.unsavedTitle"),message:t("config:whatsappNotifications.unsavedMessage"),confirmLabel:t("config:whatsappNotifications.closeAnyway"),cancelLabel:t("config:whatsappNotifications.keepEditing"),variant:"danger",onConfirm:()=>{v(!1),n()},onClose:()=>v(!1)}),e.jsx(xe,{isOpen:P,title:t("config:whatsappNotifications.resetToDefaults"),message:t("config:whatsappNotifications.confirmReset"),confirmLabel:t("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{X(),b(!1)},onClose:()=>b(!1)})]}):null}function As(s){const n=s.replace(/@.*$/,"");return/^\d{10,15}$/.test(n)?n.startsWith("521")&&n.length===13?`+52 1 ${n.slice(3,5)} ${n.slice(5,9)} ${n.slice(9)}`:n.startsWith("52")&&n.length===12?`+52 ${n.slice(2,4)} ${n.slice(4,8)} ${n.slice(8)}`:n.startsWith("1")&&n.length===11?`+1 ${n.slice(1,4)} ${n.slice(4,7)} ${n.slice(7)}`:`+${n}`:s}function Ia(s,n=Date.now()){const t=s*1e3,i=n-t;if(i<0)return xs(t);const d=Math.floor(i/6e4);if(d<1)return"now";if(d<60)return`${d}m`;const c=Math.floor(d/60);if(c<24)return`${c}h`;const r=Math.floor(c/24);return r===1?"yesterday":r<7?`${r}d`:xs(t)}function xs(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Da(s){const n=s*1e3;return new Date(n).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function Ts(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 $a(s,n){return s.length<=n?s:s.slice(0,Math.max(0,n-1)).trimEnd()+"…"}function La({chats:s,selectedChatId:n,loading:t,error:i,onSelect:d,onRefresh:c,now:r}){const{t:g}=ee(["config","common"]);return e.jsxs("div",{className:"whatsapp-history-chatlist",children:[e.jsxs("div",{className:"whatsapp-history-chatlist__header",children:[e.jsx("span",{className:"whatsapp-history-chatlist__title",children:g("config:whatsappHistory.chats")}),e.jsx("button",{type:"button",className:"whatsapp-history-chatlist__refresh",onClick:c,disabled:t,"aria-label":g("config:whatsappHistory.refresh"),title:g("config:whatsappHistory.refresh"),children:"⟳"})]}),i&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:i}),t&&s.length===0&&e.jsxs("div",{className:"whatsapp-history-chatlist__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:g("config:whatsappHistory.loadingChats")})]}),!t&&!i&&s.length===0&&e.jsx("div",{className:"whatsapp-history-chatlist__empty",children:g("config:whatsappHistory.emptyChats")}),e.jsx("ul",{className:"whatsapp-history-chatlist__items",children:s.map(o=>{const u=Ts(o.lastMessageType),N=o.lastMessagePreview||`[${o.lastMessageType}]`,S=o.chatId===n,m=As(o.chatId),_=o.isGroup?o.groupName:o.fromName,v=_||m,P=!!_&&_!==m;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${S?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>d(o.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:o.chatId,children:v}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:Ia(o.lastTimestamp,r)})]}),P&&e.jsx("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--jid",children:e.jsx("span",{className:"whatsapp-history-chatlist__jid",children:m})}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[o.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),u&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[u," "]}),$a(N,40)]}),o.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:o.unreadCount})]})]})},o.chatId)})})]})}function Oa({message:s}){const n=s.direction==="outbound"?"outbound":"inbound",t=Ts(s.messageType),i=(s.body??"").trim(),d=i.length>0,c=d?null:`[${s.messageType}]`;return e.jsx("div",{className:`whatsapp-history-bubble whatsapp-history-bubble--${n}`,children:e.jsxs("div",{className:"whatsapp-history-bubble__inner",children:[t&&e.jsx("span",{className:"whatsapp-history-bubble__type-icon",title:s.messageType,children:t}),d?e.jsx("span",{className:"whatsapp-history-bubble__body",children:i}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:c}),s.audioTranscription&&e.jsxs("span",{className:"whatsapp-history-bubble__transcription",children:["“",s.audioTranscription,"”"]}),s.mediaPath&&e.jsx("a",{className:"whatsapp-history-bubble__media-link",href:s.mediaPath,target:"_blank",rel:"noopener noreferrer",children:s.mediaFilename||"open media"}),e.jsx("span",{className:"whatsapp-history-bubble__time",children:Da(s.timestamp)})]})})}const Fa=["all","inbound","outbound"],Ra=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function Ma({direction:s,type:n,onDirectionChange:t,onTypeChange:i,disabled:d}){const{t:c}=ee(["config"]);return e.jsxs("div",{className:"whatsapp-history-filters",children:[e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:c("config:whatsappHistory.direction")}),e.jsx("select",{value:s,onChange:r=>t(r.target.value),disabled:d,children:Fa.map(r=>e.jsx("option",{value:r,children:c(`config:whatsappHistory.directionValues.${r}`)},r))})]}),e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:c("config:whatsappHistory.type")}),e.jsx("select",{value:n,onChange:r=>i(r.target.value),disabled:d,children:Ra.map(r=>e.jsx("option",{value:r,children:c(`config:whatsappHistory.typeValues.${r}`)},r))})]})]})}const Ba=80;function Ua({chatId:s,messages:n,loading:t,loadingMore:i,error:d,hasMore:c,direction:r,type:g,onDirectionChange:o,onTypeChange:u,onLoadMore:N}){const{t:S}=ee(["config"]),m=l.useRef(null),_=l.useRef(null),v=l.useRef(!1),P=l.useRef(null);l.useEffect(()=>{_.current!==s&&(_.current=s,v.current=!1)},[s]),l.useLayoutEffect(()=>{m.current&&(v.current||n.length!==0&&(m.current.scrollTop=m.current.scrollHeight,v.current=!0))},[s,n.length]),l.useLayoutEffect(()=>{if(!m.current||P.current===null)return;const C=m.current.scrollHeight-P.current;P.current=null,C>0&&(m.current.scrollTop+=C)},[n.length]);const b=l.useCallback(()=>{!c||i||t||(m.current&&(P.current=m.current.scrollHeight),N())},[c,i,t,N]),p=l.useCallback(C=>{if(!v.current)return;C.currentTarget.scrollTop<=Ba&&b()},[b]);return s?e.jsxs("div",{className:"whatsapp-history-messages",children:[e.jsxs("div",{className:"whatsapp-history-messages__header",children:[e.jsx("div",{className:"whatsapp-history-messages__title",children:As(s)}),e.jsx(Ma,{direction:r,type:g,onDirectionChange:o,onTypeChange:u,disabled:t})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:m,onScroll:p,children:[c&&e.jsx("div",{className:"whatsapp-history-messages__load-more-row",children:e.jsx("button",{type:"button",className:"whatsapp-history-messages__load-more",onClick:b,disabled:i||t,children:S(i?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),d&&e.jsx("div",{className:"whatsapp-history-messages__error",children:d}),t&&n.length===0&&e.jsxs("div",{className:"whatsapp-history-messages__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:S("config:whatsappHistory.loadingMessages")})]}),!t&&!d&&n.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:S("config:whatsappHistory.emptyMessages")}),n.map(C=>e.jsx(Oa,{message:C},za(C)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:S("config:whatsappHistory.selectChat")})})}function za(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 Es(){const s=Y(),n={};return s&&(n.Authorization=`Bearer ${s}`),n}async function Ps(s,n){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${n}: ${s.statusText}`}async function Va(s){const n=`${q()}/api/whatsapp/chats/${encodeURIComponent(s)}`,t=await fetch(n,{headers:Es()});if(!t.ok)throw new Error(await Ps(t,"Failed to fetch WhatsApp chats"));return t.json()}async function bs(s,n,t={}){const i=new URLSearchParams;t.cursor&&i.set("cursor",t.cursor),typeof t.limit=="number"&&i.set("limit",String(t.limit)),t.direction&&i.set("direction",t.direction),t.type&&i.set("type",t.type);const d=i.toString(),c=`${q()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(n)}/messages${d?`?${d}`:""}`,r=await fetch(c,{headers:Es()});if(!r.ok)throw new Error(await Ps(r,"Failed to fetch WhatsApp messages"));return r.json()}const Ka=50;function Ha({isOpen:s,onClose:n}){const{t}=ee(["config"]),[i,d]=l.useState([]),[c,r]=l.useState(null),[g,o]=l.useState(null),[u,N]=l.useState([]),[S,m]=l.useState(!1),[_,v]=l.useState(null),[P,b]=l.useState(null),[p,C]=l.useState([]),[B,F]=l.useState(!1),[J,K]=l.useState(!1),[X,U]=l.useState(null),[Z,h]=l.useState(null),[E,R]=l.useState("all"),[W,ae]=l.useState("all"),[j,L]=l.useState(()=>Date.now()),z=l.useRef(0);l.useEffect(()=>{if(!s)return;const y=window.setInterval(()=>L(Date.now()),6e4);return()=>window.clearInterval(y)},[s]),l.useEffect(()=>{if(!s)return;let y=!1;return(async()=>{var te;try{o(null);const[oe,de]=await Promise.all([Ze().catch(()=>[]),ws().catch(()=>null)]);if(y)return;d(oe);const ie=(de==null?void 0:de.defaultSessionId)||((te=oe[0])==null?void 0:te.id)||null;r(he=>he??ie)}catch(oe){if(y)return;o(oe instanceof Error?oe.message:String(oe))}})(),()=>{y=!0}},[s]);const w=l.useCallback(async y=>{m(!0),v(null);try{const te=await Va(y);N(te.chats)}catch(te){v(te instanceof Error?te.message:String(te))}finally{m(!1)}},[]);l.useEffect(()=>{!s||!c||(b(null),C([]),h(null),w(c))},[s,c,w]);const $=l.useMemo(()=>{const y={limit:Ka};return E!=="all"&&(y.direction=E),W!=="all"&&(y.type=W),y},[E,W]),O=l.useCallback(async(y,te,oe)=>{const de=++z.current;F(!0),U(null),C([]),h(null);try{const ie=await bs(y,te,oe);if(de!==z.current)return;C([...ie.messages].reverse()),h(ie.nextCursor)}catch(ie){if(de!==z.current)return;U(ie instanceof Error?ie.message:String(ie))}finally{de===z.current&&F(!1)}},[]);l.useEffect(()=>{!s||!c||!P||O(c,P,$)},[s,c,P,$,O]);const se=l.useCallback(async()=>{if(!(!c||!P||!Z)){K(!0),U(null);try{const y=await bs(c,P,{...$,cursor:Z});C(te=>[...[...y.messages].reverse(),...te]),h(y.nextCursor)}catch(y){U(y instanceof Error?y.message:String(y))}finally{K(!1)}}},[c,P,Z,$]),ne=l.useCallback(()=>{c&&w(c)},[c,w]),T=l.useCallback(y=>{y.key==="Escape"&&(y.preventDefault(),n())},[n]);return s?e.jsx(_e,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:y=>y.stopPropagation(),onKeyDown:T,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappHistory.title")}),e.jsx("div",{className:"whatsapp-history-modal__session",children:e.jsxs("label",{children:[e.jsx("span",{children:t("config:whatsappHistory.session")}),e.jsxs("select",{value:c??"",onChange:y=>r(y.target.value||null),disabled:i.length===0,children:[i.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),i.map(y=>e.jsxs("option",{value:y.id,children:[y.id,y.pairedNumber?` (${y.pairedNumber})`:""]},y.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),g&&e.jsx("div",{className:"whatsapp-history-modal__alert",children:g}),e.jsxs("div",{className:"whatsapp-history-modal__body",children:[e.jsx(La,{chats:u,selectedChatId:P,loading:S,error:_,onSelect:b,onRefresh:ne,now:j}),e.jsx(Ua,{chatId:P,messages:p,loading:B,loadingMore:J,error:X,hasMore:Z!==null,direction:E,type:W,onDirectionChange:R,onTypeChange:ae,onLoadMore:se})]})]})})}):null}function qa({isOpen:s,onClose:n,onOpenConfig:t,onOpenNotifications:i,onOpenHistory:d}){const{t:c}=ee(["config"]);if(l.useEffect(()=>{if(!s)return;const g=o=>{o.key==="Escape"&&(o.preventDefault(),n())};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[s,n]),!s)return null;const r=g=>{n(),g()};return e.jsx(_e,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-hub-modal",onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"whatsapp-hub-modal__icon",children:"📱"}),c("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"whatsapp-hub-modal__intro",children:c("config:whatsappHub.intro",{defaultValue:"Pick what you want to manage for the WhatsApp integration."})}),e.jsxs("div",{className:"whatsapp-hub-modal__options",children:[e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(t),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.config",{defaultValue:"Integration config"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.configDesc",{defaultValue:"Server URL, API key, sessions and pairing."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(i),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.notifications",{defaultValue:"Notifications"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.notificationsDesc",{defaultValue:"Which agent events get forwarded and to whom."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(d),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.history",{defaultValue:"History"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.historyDesc",{defaultValue:"Browse persisted chats and messages."})})]})]})]})]})]})})})}const Je=[{kind:"question",settingKey:"toneQuestion",label:"Agent asks you something",when:"A question, a plan to approve, or a permission request. Repeats twice up front, then every 10s until you answer (stops after 2 min).",sound:"Two taps, then a rising bend",play:ks},{kind:"notification",settingKey:"toneNotification",label:"Agent sends a notification",when:"Any agent notification: task complete, error, or a heads-up.",sound:"Soft two-note chime",play:ys},{kind:"completion",settingKey:"toneCompletion",label:"Agent finishes working",when:"An agent stops working and goes idle.",sound:"Gentle descending arpeggio",play:kt}],Wa=[{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:"🌙"}],Ga=[{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:"🔴"}],Ya=[{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:"👎"}],Ja=[{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:"💜"}],Xa=[{key:"showTrees",icon:"🌳",label:"Trees"},{key:"showBushes",icon:"🌿",label:"Bushes"},{key:"showHouse",icon:"🏠",label:"House"},{key:"showLamps",icon:"💡",label:"Lamps"},{key:"showGrass",icon:"🟩",label:"Grass"},{key:"showClouds",icon:"☁️",label:"Clouds"}],Za=[{value:null,label:"Auto",color:"linear-gradient(135deg, #4a90d9 0%, #0a1a2a 100%)"},{value:"#4a90d9",label:"Day Blue",color:"#4a90d9"},{value:"#0a1a2a",label:"Night",color:"#0a1a2a"},{value:"#ff6b35",label:"Sunset",color:"#ff6b35"},{value:"#1a0a2e",label:"Purple",color:"#1a0a2e"},{value:"#2d5a27",label:"Matrix",color:"#2d5a27"},{value:"#8b0000",label:"Blood",color:"#8b0000"},{value:"#000000",label:"Void",color:"#000000"}],Qa={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},en={none:"grass","pokemon-stadium":"pokemon"},sn={"emote-yes":"yes","emote-no":"no"},tn={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function Q({checked:s,onChange:n}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:t=>n(t.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function Ce({options:s,value:n,onChange:t,iconOnly:i=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(d=>e.jsxs("button",{className:`chip ${n===d.value?"active":""}`,onClick:()=>t(d.value),title:d.label,children:[e.jsx("span",{className:"chip-icon",children:d.icon}),!i&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function k({text:s,query:n}){if(!n.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),i=n.toLowerCase(),d=t.indexOf(i);if(d===-1)return e.jsx(e.Fragment,{children:s});const c=s.slice(0,d),r=s.slice(d,d+n.length),g=s.slice(d+n.length);return e.jsxs(e.Fragment,{children:[c,e.jsx("mark",{className:"search-highlight",children:r}),g]})}const an=[{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","pi","rpc","steer","steering","mid-turn","mid turn","hover","preview","tooltip","ctrl","popup","vista previa","sound","sounds","sonido","sonidos","notification","notifications","notificacion","notificaciones","volume","volumen","tone","tones","tono","chime","alert","cue","audio","mute","silence","dock","activity","recent","notification sound","silenciar","custom sound","upload sound","alerta","file search","excluded folders","node_modules","vendor","git","spotlight","ignore"]},{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"]}],Xe=[{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 nn({config:s,onChange:n,searchQuery:t="",onOpenIntegrationsModal:i,onOpenMonitoringModal:d,onOpenStatisticsModal:c,onOpenWorkflowEditor:r,onOpenTriggerManager:g}){var ls;const{t:o}=ee(["config","common"]),u=ut(),N=pt(),[S,m]=l.useState(()=>ht(Ee.DEFAULT_AGENT_CLASS)||"scout"),_=mt(),v=gt(),[P,b]=l.useState(()=>ft()),[p,C]=l.useState(null),[B,F]=l.useState(null),[J,K]=l.useState("");l.useEffect(()=>{qe().then(b)},[]);const X=async(a,A)=>{F(null),C(a);try{const M=await ye(ke(`/api/custom-sounds/${a}`),{method:"POST",headers:{"Content-Type":A.type||"audio/mpeg"},body:A});if(!M.ok){const re=await M.json().catch(()=>({error:`Upload failed (${M.status})`}));throw new Error(re.error||`Upload failed (${M.status})`)}const le=await qe();b({...le});const fe=Je.find(re=>re.kind===a);fe&&x.updateSettings({[fe.settingKey]:Pe}),We(Pe,u.notificationSoundVolume,a)}catch(M){F(M instanceof Error?M.message:"Upload failed")}finally{C(null)}},U=async a=>{F(null);try{await ye(ke(`/api/custom-sounds/${a}`),{method:"DELETE"}),Et({[a]:null});const A=await qe();b({...A});const M=Je.find(le=>le.kind===a);M&&x.getSettings()[M.settingKey]===Pe&&x.updateSettings({[M.settingKey]:Pt[a]})}catch(A){F(A instanceof Error?A.message:"Failed to reset sound")}},[Z,h]=l.useState(u.historyLimit),[E,R]=l.useState(()=>xt()),[W,ae]=l.useState(!1),[j,L]=l.useState(""),[z,w]=l.useState(()=>Y()),[$,O]=l.useState(!1),[se,ne]=l.useState(!1),[T,y]=l.useState(""),[te,oe]=l.useState(!1),[de,ie]=l.useState(!1),[he,Se]=l.useState(!1),[Ae,ue]=l.useState(!1),[Ie,me]=l.useState(!1),[ge,De]=l.useState(""),[$e,be]=l.useState(!1);l.useEffect(()=>{Qt().then(De).catch(()=>{})},[]),l.useEffect(()=>{Xt().then(a=>{a!==u.experimentalEchoPrompt&&x.updateSettings({experimentalEchoPrompt:a})}).catch(()=>{})},[]),l.useEffect(()=>{sa().then(a=>{a!==u.tmuxMode&&x.updateSettings({tmuxMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{aa().then(a=>{a!==u.interactiveMode&&x.updateSettings({interactiveMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{oa().then(a=>{a!==u.codexAppServerMode&&x.updateSettings({codexAppServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{la().then(a=>{a!==u.opencodeServerMode&&x.updateSettings({opencodeServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{ra().then(a=>{a!==u.piRpcMode&&x.updateSettings({piRpcMode:a})}).catch(()=>{})},[]),l.useEffect(()=>bt(a=>{R(a),ae(!1)}),[]);const Ve=Wa.map(a=>({...a,label:o(`config:time.${a.value}`)})),Ke=Ga.map(a=>({...a,label:o(`config:floor.${en[a.value]||a.value}`)})),Le=Ya.map(a=>({...a,label:o(`config:animation.${sn[a.value]||a.value}`)})),He=Ja.map(a=>({...a,label:o(`config:colorMode.${a.value}`)})),Oe=Xa.map(a=>({...a,label:o(`config:terrain.${Qa[a.key]}`)})),Fe=Za.map(a=>({...a,label:o(`config:sky.${tn[a.value??""]}`)})),je=t.trim()?an.filter(a=>{const A=t.toLowerCase();return a.title.toLowerCase().includes(A)||a.keywords.some(M=>M.toLowerCase().includes(A))}).map(a=>a.id):null,D=a=>je?je.includes(a):!0,Re=D("integrations"),pe=u.customAgentNames||[],f=pe.length>0?pe:jt,V=()=>{const a=T.trim();a&&!pe.includes(a)&&(x.updateSettings({customAgentNames:[...pe,a]}),y(""))},ce=a=>{x.updateSettings({customAgentNames:pe.filter(A=>A!==a)})},ve=()=>{x.updateSettings({customAgentNames:[]})},Me=u.fileSearchExcludeDirs??[...rs],ss=()=>{const a=J.trim();if(ps(a)){if(Me.includes(a)){K("");return}x.updateSettings({fileSearchExcludeDirs:[...Me,a]}),K("")}},_s=a=>{x.updateSettings({fileSearchExcludeDirs:Me.filter(A=>A!==a)})},Is=()=>{x.updateSettings({fileSearchExcludeDirs:[...rs]})},ts=()=>{const a=j.trim();if(a){if(E.includes(a)){L("");return}R([...E,a]),ae(!0),L("")}},Ds=a=>{R(E.filter((A,M)=>M!==a)),ae(!0)},as=(a,A)=>{const M=a+A;if(M<0||M>=E.length)return;const le=E.slice();[le[a],le[M]]=[le[M],le[a]],R(le),ae(!0)},$s=()=>{_t(E),ae(!1),Ye()},Ls=a=>{w(a),O(!0)},ns=()=>{Be(Ee.AUTH_TOKEN,z),O(!1),Ye()},Os=a=>{De(a),be(!0)},os=()=>{ea(ge).catch(()=>{}),be(!1)},Ne=a=>{n({...s,terrain:{...s.terrain,...a}})},we=a=>{n({...s,modelStyle:{...s.modelStyle,...a}})},is=a=>{n({...s,animations:{...s.animations,...a}})},Fs=a=>{h(a),x.updateSettings({historyLimit:a})},Rs=a=>{const A=s.terrain[a];typeof A=="boolean"&&Ne({[a]:!A})},G=t.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[je&&je.length===0&&e.jsx("div",{className:"config-no-results",children:o("config:noResults",{query:t})}),D("general")&&e.jsxs(H,{title:o("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:G&&D("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:Z,onChange:a=>Fs(parseInt(a.target.value)||100),min:50,max:2e3,step:50})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.hideCosts"),query:t})}),e.jsx(Q,{checked:u.hideCost,onChange:a=>x.updateSettings({hideCost:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.streamTextLiveTitle"),children:e.jsx(k,{text:o("config:general.streamTextLive"),query:t})}),e.jsx(Q,{checked:u.streamTextLive!==!1,onChange:a=>x.updateSettings({streamTextLive:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.toolHoverPreviewTitle"),children:e.jsx(k,{text:o("config:general.toolHoverPreview"),query:t})}),e.jsx(Q,{checked:u.toolHoverPreview===!0,onChange:a=>x.updateSettings({toolHoverPreview:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Where the strip of recently-active and currently-working agent thumbnails sits.",children:e.jsx(k,{text:"Agent activity dock",query:t})}),e.jsx("select",{className:"config-select",value:_,onChange:a=>wt(a.target.value),children:vt.map(a=>e.jsx("option",{value:a,children:Nt[a]},a))})]}),_!=="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(k,{text:"Recent agents in dock",query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:v,min:0,max:20,step:1,onChange:a=>yt(parseInt(a.target.value,10)||0)})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.grid"),query:t})}),e.jsx(Q,{checked:s.gridVisible,onChange:a=>n({...s,gridVisible:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.showFPS"),query:t})}),e.jsx(Q,{checked:u.showFPS,onChange:a=>x.updateSettings({showFPS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.fpsLimit"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:a=>n({...s,fpsLimit:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.fpsLimit===0?"∞":s.fpsLimit})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: Reduce FPS when idle to save power",children:[e.jsx(k,{text:o("config:general.powerSaving"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(Q,{checked:u.powerSaving,onChange:a=>x.updateSettings({powerSaving:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Battery saver for mobile: caps scene FPS (20 active / 5 idle), freezes decorative animations and disables word-by-word streaming. Off = normal mode.",children:[e.jsx(k,{text:o("config:general.lowPowerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(Q,{checked:u.lowPowerMode===!0,onChange:a=>x.updateSettings({lowPowerMode:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Wrap agent processes in tmux sessions so they survive server restarts (requires tmux installed)",children:e.jsx(k,{text:o("config:general.tmuxMode"),query:t})}),e.jsx(Q,{checked:u.tmuxMode,onChange:async a=>{x.updateSettings({tmuxMode:a});try{await ta(a)}catch(A){console.error("Failed to sync tmux mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Claude agents as the real interactive `claude` TUI inside tmux, reconstructing the conversation from the session transcript (requires tmux). Takes effect on server restart.",children:[e.jsx(k,{text:o("config:general.interactiveMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(Q,{checked:u.interactiveMode,onChange:async a=>{x.updateSettings({interactiveMode:a});try{await na(a)}catch(A){console.error("Failed to sync interactive mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Codex agents through a persistent `codex app-server` so replies stream word-by-word (token deltas) instead of appearing as one block. The app-server runs detached and survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new Codex turns; no server restart needed to toggle.",children:[e.jsx(k,{text:o("config:general.codexAppServerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(Q,{checked:u.codexAppServerMode,onChange:async a=>{x.updateSettings({codexAppServerMode:a});try{await ia(a)}catch(A){console.error("Failed to sync codex app-server mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run OpenCode agents through a persistent, detached `opencode serve` HTTP server so replies stream word-by-word (token deltas over SSE) instead of appearing as one block. The server survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new OpenCode turns; no server restart needed to toggle.",children:[e.jsx(k,{text:o("config:general.opencodeServerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(Q,{checked:u.opencodeServerMode,onChange:async a=>{x.updateSettings({opencodeServerMode:a});try{await ca(a)}catch(A){console.error("Failed to sync opencode server mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Run Pi agents through a persistent `pi --mode rpc` process per agent. Messages sent mid-turn STEER the live run (delivered after the current tool round, before the next model call) instead of queueing until the turn ends. With tmux mode enabled, live RPC turns survive Commander restarts and reconnect automatically; otherwise sessions resume on the next message. Applies to new Pi turns; no server restart needed to toggle.",children:[e.jsx(k,{text:o("config:general.piRpcMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(Q,{checked:u.piRpcMode,onChange:async a=>{x.updateSettings({piRpcMode:a});try{await da(a)}catch(A){console.error("Failed to sync pi RPC mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.vibrationIntensity"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:u.vibrationIntensity,onChange:a=>x.updateSettings({vibrationIntensity:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:u.vibrationIntensity===0?o("config:vibrationValues.off"):u.vibrationIntensity===1?o("config:vibrationValues.ultraLight"):u.vibrationIntensity===2?o("config:vibrationValues.veryLight"):u.vibrationIntensity===3?o("config:vibrationValues.light"):u.vibrationIntensity===4?o("config:vibrationValues.medium"):o("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Play pleasant sounds: a chime for agent notifications, a distinctive rising cue when an agent asks you a question (repeats until answered), and a resolving cue when an agent finishes its work.",children:e.jsx(k,{text:"Notification sounds",query:t})}),e.jsx(Q,{checked:u.notificationSoundEnabled,onChange:a=>{x.updateSettings({notificationSoundEnabled:a}),a&&ys(u.notificationSoundVolume,u.toneNotification)}})]}),u.notificationSoundEnabled&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:"Notification sound volume",query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:ds,step:"1",value:u.notificationSoundVolume,onChange:a=>{const A=parseInt(a.target.value);x.updateSettings({notificationSoundVolume:A}),ks(A,u.toneQuestion)}}),e.jsx("span",{className:"config-value",children:u.notificationSoundVolume===0?o("config:vibrationValues.off"):`${u.notificationSoundVolume}/${ds}`})]}),u.notificationSoundEnabled&&u.notificationSoundVolume>0&&e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:"Sounds per event",query:t})}),e.jsx("div",{className:"config-sound-hint",children:'Pick a tone for each event — or upload your own file (mp3, wav, ogg, m4a — max 5MB), which is stored on the commander so every device hears it. "None" silences that event.'}),Je.map(a=>{var fe;const A=!!P[a.kind],M=u[a.settingKey],le=A&&M===Pe;return e.jsxs("div",{className:"config-sound-row",children:[e.jsxs("div",{className:"config-sound-info",children:[e.jsxs("div",{className:"config-sound-head",children:[e.jsx("span",{className:"config-sound-name",children:a.label}),e.jsx("span",{className:`config-sound-badge${le?" custom":""}`,children:le?"Your file":((fe=St(M))==null?void 0:fe.label)??a.sound})]}),e.jsx("div",{className:"config-sound-when",children:a.when})]}),e.jsxs("div",{className:"config-sound-actions",children:[e.jsxs("select",{className:"config-select",value:M,onChange:re=>{const Te=re.target.value;x.updateSettings({[a.settingKey]:Te}),We(Te,u.notificationSoundVolume,a.kind)},children:[A&&e.jsx("option",{value:Pe,children:"Your uploaded file"}),Ct.map(re=>e.jsx("option",{value:re.id,children:re.label},re.id))]}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void We(M,u.notificationSoundVolume,a.kind),disabled:us(M),title:us(M)?"This event is silenced — pick a tone to hear it":"Hear the sound that plays for this event",children:"▶"}),e.jsxs("label",{className:"config-btn config-btn-sm config-sound-upload",title:"Replace this sound with your own audio file (mp3, wav, ogg, m4a — max 5MB)",children:[p===a.kind?"Uploading…":"Upload",e.jsx("input",{type:"file",accept:"audio/*",style:{display:"none"},onChange:re=>{var cs;const Te=(cs=re.target.files)==null?void 0:cs[0];re.target.value="",Te&&X(a.kind,Te)}})]}),A&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void U(a.kind),title:"Delete your file and go back to a built-in tone",children:"Reset"})]})]},a.kind)}),B&&e.jsx("div",{className:"config-sound-error",children:B})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.externalEditor"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.externalEditorPlaceholder"),value:u.externalEditorCommand||"",onChange:a=>x.updateSettings({externalEditorCommand:a.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.tabTitle"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.tabTitlePlaceholder"),value:u.tabTitle||"",onChange:a=>x.updateSettings({tabTitle:a.target.value})})]}),e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.fileSearchExcludeDirs"),query:t})}),e.jsx("span",{className:"config-hint",children:o("config:general.fileSearchExcludeDirsHint")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:o("config:general.fileSearchExcludeDirsPlaceholder"),value:J,onChange:a=>K(a.target.value),onKeyDown:a=>{a.key==="Enter"&&ss()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ss,disabled:!ps(J),title:o("config:general.fileSearchExcludeDirsAdd"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:Me.map(a=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:a}),e.jsx("button",{className:"agent-name-remove",onClick:()=>_s(a),title:o("common:buttons.remove"),children:"x"})]},a))}),e.jsx("button",{className:"config-btn config-btn-link",onClick:Is,children:o("config:general.fileSearchExcludeDirsReset")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:general.language"),query:t})}),e.jsx(Ce,{options:Xe,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((ls=Xe.find(a=>a.value!=="auto"&&Ge.language.startsWith(a.value.split("-")[0])))==null?void 0:ls.value)||"en":"auto",onChange:a=>{var A;if(a==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const M=navigator.language,le=((A=Xe.find(fe=>fe.value!=="auto"&&M.startsWith(fe.value.split("-")[0])))==null?void 0:A.value)||"en";Ge.changeLanguage(le)}else localStorage.setItem("tide-commander-language-mode","manual"),Ge.changeLanguage(a)}})]})]}),D("agentNames")&&e.jsx(H,{title:o("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:G&&D("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:pe.length>0?o("config:agentNames.customConfigured",{count:pe.length}):o("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:o("config:agentNames.addPlaceholder"),value:T,onChange:a=>y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&V()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:V,disabled:!T.trim(),title:o("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:f.map((a,A)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:a}),pe.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>ce(a),title:o("common:buttons.remove"),children:"x"})]},`${a}-${A}`))}),pe.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:ve,children:o("common:buttons.resetToDefaults")})]})}),D("defaultClass")&&e.jsx(H,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:G&&D("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${S==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m("random"),Be(Ee.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(At).map(([a,A])=>e.jsx("div",{className:`agent-name-chip${S===a?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(a),Be(Ee.DEFAULT_AGENT_CLASS,a)},children:e.jsxs("span",{className:"agent-name-text",children:[A.icon," ",a.charAt(0).toUpperCase()+a.slice(1)]})},a)),N.map(a=>e.jsx("div",{className:`agent-name-chip${S===a.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(a.id),Be(Ee.DEFAULT_AGENT_CLASS,a.id)},children:e.jsxs("span",{className:"agent-name-text",children:[a.icon," ",a.name]})},a.id))]})]})}),D("appearance")&&e.jsx(H,{title:o("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:G&&D("appearance"),children:e.jsx(ga,{})}),D("connection")&&e.jsxs(H,{title:o("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:G&&D("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:E.map((a,A)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:o("config:connection.priorityLabel",{defaultValue:"Priority"}),children:A+1}),e.jsx("span",{className:"backend-url-text",title:a,children:a}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>as(A,-1),disabled:A===0,title:o("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>as(A,1),disabled:A===E.length-1,title:o("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ds(A),title:o("common:buttons.remove"),children:"x"})]},`${a}-${A}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:j,onChange:a=>L(a.target.value),placeholder:o("config:connection.addUrlPlaceholder",{defaultValue:"http://host:port"}),onKeyDown:a=>{a.key==="Enter"&&ts()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ts,disabled:!j.trim(),title:o("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),W&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:$s,title:o("config:connection.saveAndReconnect"),children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.urlsHint",{defaultValue:"Tried in order on connect; the first reachable host wins. Leave empty for auto-detect."})})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:connection.authToken"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:se?"text":"password",className:"config-input config-input-full",value:z,onChange:a=>Ls(a.target.value),placeholder:o("config:connection.tokenPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&$&&ns()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>ne(!se),title:o(se?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(I,{name:se?"eye-closed":"eye",size:14})}),$&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:ns,title:o("config:connection.saveAndReconnect"),children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:connection.codexBinaryPath"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:ge,onChange:a=>Os(a.target.value),placeholder:o("config:connection.codexBinaryPathPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&$e&&os()}}),$e&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:os,children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("common:buttons.reconnect"),query:t})}),e.jsx("button",{className:"config-btn",onClick:()=>Ye(),title:"Force reconnect to server",children:o("common:buttons.reconnect")})]})]}),D("scene")&&e.jsxs(H,{title:o("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:G&&D("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:scene.characterSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"3.0",step:"0.1",value:s.characterScale,onChange:a=>n({...s,characterScale:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.characterScale.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:scene.scale2d",{defaultValue:"2D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale2d,onChange:a=>n({...s,scale2d:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale2d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:scene.scale3d",{defaultValue:"3D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale3d,onChange:a=>n({...s,scale3d:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale3d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:t})}),e.jsx(Q,{checked:s.show2DTaskLabels,onChange:a=>n({...s,show2DTaskLabels:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:scene.time"),query:t})}),e.jsx(Ce,{options:Ve,value:s.timeMode,onChange:a=>n({...s,timeMode:a}),iconOnly:!0})]})]}),D("terrain")&&e.jsxs(H,{title:o("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:G&&D("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:t})}),e.jsx(Q,{checked:s.terrain.simpleMode??!1,onChange:a=>Ne({simpleMode:a})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:Oe.map(a=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[a.key]?"active":""}`,onClick:()=>Rs(a.key),title:a.label,children:a.icon},a.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:terrainSettings.fog"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.terrain.fogDensity,onChange:a=>Ne({fogDensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?o("config:fogValues.off"):s.terrain.fogDensity<=1?o("config:fogValues.low"):o("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:terrainSettings.brightness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.2",max:"2",step:"0.1",value:s.terrain.brightness,onChange:a=>Ne({brightness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?o("config:brightnessValues.dark"):s.terrain.brightness<=1.2?o("config:brightnessValues.normal"):o("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:terrainSettings.floor"),query:t})}),e.jsx(Ce,{options:Ke,value:s.terrain.floorStyle,onChange:a=>Ne({floorStyle:a}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:terrainSettings.sky"),query:t})}),e.jsx("div",{className:"sky-color-selector",children:Fe.map(a=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===a.value?"active":""}`,onClick:()=>Ne({skyColor:a.value}),title:a.label,style:{background:a.color}},a.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:terrainSettings.battlefieldSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:a=>Ne({battlefieldSize:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),D("modelStyle")&&e.jsxs(H,{title:o("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:G&&D("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.saturation"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.modelStyle.saturation,onChange:a=>we({saturation:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?o("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?o("config:saturationValues.normal"):o("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.roughness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.roughness,onChange:a=>we({roughness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?o("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?o("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?o("config:roughnessValues.normal"):o("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.metalness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.metalness,onChange:a=>we({metalness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?o("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?o("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?o("config:metalnessValues.mixed"):o("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.glow"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"1",step:"0.05",value:s.modelStyle.emissiveBoost,onChange:a=>we({emissiveBoost:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?o("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?o("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?o("config:glowValues.med"):o("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.reflections"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"2",step:"0.1",value:s.modelStyle.envMapIntensity,onChange:a=>we({envMapIntensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?o("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?o("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?o("config:reflectionValues.normal"):o("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.wireframe"),query:t})}),e.jsx(Q,{checked:s.modelStyle.wireframe,onChange:a=>we({wireframe:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:modelStyleSettings.colorMode"),query:t})}),e.jsx(Ce,{options:He,value:s.modelStyle.colorMode,onChange:a=>we({colorMode:a}),iconOnly:!0})]})]}),D("animations")&&e.jsxs(H,{title:o("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:G&&D("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:animationSettings.idle"),query:t})}),e.jsx(Ce,{options:Le,value:s.animations.idleAnimation,onChange:a=>is({idleAnimation:a}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:animationSettings.working"),query:t})}),e.jsx(Ce,{options:Le,value:s.animations.workingAnimation,onChange:a=>is({workingAnimation:a}),iconOnly:!0})]})]}),D("secrets")&&e.jsx(H,{title:o("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:G&&D("secrets"),children:e.jsx(Wt,{})}),D("claudeAccounts")&&e.jsx(H,{title:o("config:sections.claudeAccounts",{defaultValue:"Claude Accounts"}),storageKey:"claudeAccounts",defaultOpen:!1,forceOpen:G&&D("claudeAccounts"),children:e.jsx(Tt,{})}),D("grokAccounts")&&e.jsx(H,{title:o("config:sections.grokAccounts",{defaultValue:"Grok Accounts"}),storageKey:"grokAccounts",defaultOpen:!1,forceOpen:G&&D("grokAccounts"),children:e.jsx(hs,{provider:"grok"})}),D("codexAccounts")&&e.jsx(H,{title:o("config:sections.codexAccounts",{defaultValue:"Codex Accounts"}),storageKey:"codexAccounts",defaultOpen:!1,forceOpen:G&&D("codexAccounts"),children:e.jsx(hs,{provider:"codex"})}),D("systemPrompt")&&e.jsx(H,{title:o("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:G&&D("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(k,{text:o("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>oe(!0),children:o("config:systemPrompt.editPrompt")})]})}),D("data")&&e.jsx(H,{title:o("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:G&&D("data"),children:e.jsx(ma,{})}),Re&&e.jsx(H,{title:o("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:G&&Re,children:e.jsx(Na,{onOpenModal:a=>{a==="whatsapp"?me(!0):i==null||i(a)}})}),D("workflows")&&e.jsxs(H,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:G&&D("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(k,{text:"Create and manage automated workflow pipelines with visual state machine editor",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>r==null?void 0:r(),children:"Open Workflow Editor"})})]}),D("triggers")&&e.jsxs(H,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:G&&D("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(k,{text:"Create and manage event-driven triggers that fire agents with templates",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>g==null?void 0:g(),children:"Open Trigger Manager"})})]}),D("monitoring")&&e.jsxs(H,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:G&&D("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(k,{text:"View event logs, trigger history, workflow traces, and system stats",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>d==null?void 0:d(),children:"Open Monitoring & Logs"})})]}),D("statistics")&&e.jsxs(H,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:G&&D("statistics"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(k,{text:"View token usage charts and system-wide agent statistics",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>c==null?void 0:c(),children:"Open Statistics"})})]}),D("experimental")&&e.jsxs(H,{title:o("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:G&&D("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(k,{text:o("config:experimental.2dView"),query:t})," ",e.jsx(I,{name:"map",size:12})]}),e.jsx(Q,{checked:u.experimental2DView,onChange:a=>x.updateSettings({experimental2DView:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(k,{text:o("config:experimental.voiceAssistant"),query:t})," ",e.jsx(I,{name:"microphone",size:12})]}),e.jsx(Q,{checked:u.experimentalVoiceAssistant,onChange:a=>x.updateSettings({experimentalVoiceAssistant:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(k,{text:o("config:experimental.tts"),query:t})," ",e.jsx(I,{name:"speaker-on",size:12})]}),e.jsx(Q,{checked:u.experimentalTTS,onChange:a=>x.updateSettings({experimentalTTS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Duplicate system prompt for improved LLM attention coverage. Increases input token usage.",children:e.jsx(k,{text:o("config:experimental.echoPrompt"),query:t})}),e.jsx(Q,{checked:u.experimentalEchoPrompt,onChange:async a=>{x.updateSettings({experimentalEchoPrompt:a});try{await Zt(a)}catch(A){console.error("Failed to sync echo prompt setting to server:",A)}}})]}),e.jsx("span",{className:"config-hint",children:o("config:experimental.hint")})]}),D("about")&&e.jsx(H,{title:o("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:G&&D("about"),children:e.jsx(ja,{})})]}),e.jsx(wa,{isOpen:te,onClose:()=>oe(!1)}),e.jsx(Ca,{isOpen:de,onClose:()=>ie(!1)}),e.jsx(_a,{isOpen:he,onClose:()=>Se(!1)}),e.jsx(Ha,{isOpen:Ae,onClose:()=>ue(!1)}),e.jsx(qa,{isOpen:Ie,onClose:()=>me(!1),onOpenConfig:()=>ie(!0),onOpenNotifications:()=>Se(!0),onOpenHistory:()=>ue(!0)})]})}function dn({onConfigChange:s,onToolChange:n,config:t,isOpen:i,onClose:d,onOpenBuildingModal:c,onOpenAreaExplorer:r,onOpenIntegrationsModal:g,onOpenMonitoringModal:o,onOpenStatisticsModal:u,onOpenWorkflowEditor:N,onOpenTriggerManager:S}){const{t:m}=ee(["config","common"]),_=It(),v=Dt(),P=$t(),b=Lt(),p=Ot(),C=Array.from(_.values()),B=Array.from(v.values()),[F,J]=l.useState(""),K=l.useRef(null);if(l.useEffect(()=>{const h=E=>{E.key==="Escape"&&i&&d()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[i,d]),l.useEffect(()=>{if(i&&K.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const E=setTimeout(()=>{var R;(R=K.current)==null||R.focus()},50);return()=>clearTimeout(E)}},[i]),!i)return null;const X=h=>{n(p===h?null:h)},U=h=>{x.selectArea(b===h?null:h),n("select")},Z=(h,E)=>{h.stopPropagation(),x.deleteArea(E)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:d}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:m("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:m("common:buttons.close"),children:"×"})]}),e.jsxs("div",{className:"toolbox-search",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{ref:K,type:"text",placeholder:m("config:searchPlaceholder"),value:F,onChange:h=>J(h.target.value),className:"toolbox-search-input"}),F&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>J(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(H,{title:m("config:areas.title",{count:C.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${p==="select"?"active":""}`,onClick:()=>X("select"),title:m("config:tools.select"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"})})})}),e.jsx("button",{className:`tool-btn ${p==="rectangle"?"active":""}`,onClick:()=>X("rectangle"),title:m("config:tools.rectangle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"})})})}),e.jsx("button",{className:`tool-btn ${p==="circle"?"active":""}`,onClick:()=>X("circle"),title:m("config:tools.circle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("circle",{cx:"12",cy:"12",r:"9"})})})})]}),e.jsx("div",{className:"areas-list",children:C.length===0?e.jsx("div",{className:"areas-empty",children:m("config:areas.drawToCreate")}):C.map(h=>e.jsx(zt,{area:h,isSelected:b===h.id,onClick:()=>U(h.id),onDelete:E=>Z(E,h.id)},h.id))})]})}),b&&e.jsx(qt,{area:_.get(b),onClose:()=>x.selectArea(null),onOpenFolder:r}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(H,{title:m("config:buildings.title",{count:B.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:h=>{h.stopPropagation(),c==null||c()},title:m("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:B.length===0?e.jsx("div",{className:"buildings-empty",children:m("config:buildings.clickToAdd")}):B.map(h=>e.jsx(Vt,{building:h,isSelected:P.has(h.id),onClick:()=>{x.selectBuilding(P.has(h.id)?null:h.id)},onEdit:()=>c==null?void 0:c(h.id)},h.id))})})}),P.size===1&&(()=>{const h=Array.from(P)[0],E=v.get(h);return E?e.jsx(Kt,{building:E,onClose:()=>x.selectBuilding(null),onOpenModal:()=>c==null?void 0:c(h)}):null})(),e.jsx(nn,{config:t,onChange:s,searchQuery:F,onOpenIntegrationsModal:g,onOpenMonitoringModal:o,onOpenStatisticsModal:u,onOpenWorkflowEditor:N,onOpenTriggerManager:S})]})]})]})}export{dn as Toolbox};