tide-commander 1.210.0 → 1.211.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/assets/{AudioPlayer-CElliTTR.js → AudioPlayer-BkW6rbHa.js} +1 -1
  3. package/dist/assets/{BossLogsModal-DO0Vs1lM.js → BossLogsModal-CWJfLRLA.js} +1 -1
  4. package/dist/assets/{BossSpawnModal-BuDifEmB.js → BossSpawnModal-DMxCXROC.js} +1 -1
  5. package/dist/assets/{ControlsModal-DPcrW0oK.js → ControlsModal-BaSSGPXP.js} +1 -1
  6. package/dist/assets/{DockerLogsModal-DaGU7BRb.js → DockerLogsModal-C_Nb5L_a.js} +1 -1
  7. package/dist/assets/{EmbeddedEditor-BFwoN_46.js → EmbeddedEditor-CG0ULJUZ.js} +1 -1
  8. package/dist/assets/{FcStdViewer-D0qXXGZb.js → FcStdViewer-BgEgrxaw.js} +1 -1
  9. package/dist/assets/{GcodeViewer-DqMtMidS.js → GcodeViewer-CTlX7eA7.js} +1 -1
  10. package/dist/assets/{GlbViewer-B3jqR181.js → GlbViewer-CKaX8cFI.js} +1 -1
  11. package/dist/assets/{GmailOAuthSetup-G3QuK-qX.js → GmailOAuthSetup-1AhXjBRc.js} +1 -1
  12. package/dist/assets/{GoogleOAuthSetup-dCjYnCta.js → GoogleOAuthSetup-DqPgZjOY.js} +1 -1
  13. package/dist/assets/{IframeModal-DYJCvfYE.js → IframeModal-ClN_kGcP.js} +1 -1
  14. package/dist/assets/{IntegrationsPanel-M73zpDQj.js → IntegrationsPanel-ckrmRwYi.js} +2 -2
  15. package/dist/assets/{LogViewerModal-IwhEcaYj.js → LogViewerModal-D_eGItAQ.js} +1 -1
  16. package/dist/assets/{MonitoringModal-k5DVlUx4.js → MonitoringModal-BrsQN8tD.js} +1 -1
  17. package/dist/assets/{PM2LogsModal-CK08IAnZ.js → PM2LogsModal-CKfdmFqw.js} +1 -1
  18. package/dist/assets/{PluginsPanel-DAmAgJvL.js → PluginsPanel-Bfqcnrsb.js} +1 -1
  19. package/dist/assets/{RestoreArchivedAreaModal-BCn-HylF.js → RestoreArchivedAreaModal-oZSTlXhf.js} +1 -1
  20. package/dist/assets/{Scene2DCanvas-DZ3LFW07.js → Scene2DCanvas-B2oTAqlK.js} +1 -1
  21. package/dist/assets/{SceneManager-aCcayL_T.js → SceneManager-pnDsJdS-.js} +1 -1
  22. package/dist/assets/{SkillsPanel-mr09RF0o.js → SkillsPanel-AQimvs-1.js} +1 -1
  23. package/dist/assets/{SlackMultiInstanceSetup-JSGJZGh6.js → SlackMultiInstanceSetup-U4d0XsWJ.js} +1 -1
  24. package/dist/assets/SpawnModal-DgKO0K6L.js +1 -0
  25. package/dist/assets/{StatisticsModal-DyUUvnxL.js → StatisticsModal-DDC8OYen.js} +1 -1
  26. package/dist/assets/{StlViewer-B0mqqtbi.js → StlViewer-DJZ7Qgp0.js} +1 -1
  27. package/dist/assets/{SubordinateAssignmentModal-C7XdTSBc.js → SubordinateAssignmentModal-DCM6PpB_.js} +1 -1
  28. package/dist/assets/{ThreeAreaSelector-Cxtggsnt.js → ThreeAreaSelector-CjEcL3Kh.js} +1 -1
  29. package/dist/assets/{ThreeViewShortcuts-BqvxjuDQ.js → ThreeViewShortcuts-UakjRD8w.js} +1 -1
  30. package/dist/assets/{TriggerManagerPanel-BnTWDT1K.js → TriggerManagerPanel-C42VLQu6.js} +1 -1
  31. package/dist/assets/{VideoPlayer-jknjvQg9.js → VideoPlayer-UW43AiLH.js} +1 -1
  32. package/dist/assets/{WorkflowEditorPanel-CvWwQ2Rk.js → WorkflowEditorPanel-DUvf5X0c.js} +1 -1
  33. package/dist/assets/{abnfDiagram-VRR7QNED-CUyx8tcg.js → abnfDiagram-VRR7QNED-KDmvD_Gi.js} +1 -1
  34. package/dist/assets/{arc-x9pqF0PL.js → arc-D8Dnwz7O.js} +1 -1
  35. package/dist/assets/{architectureDiagram-ZJ3FMSHR-BL9aDWOo.js → architectureDiagram-ZJ3FMSHR-DzHUfCXK.js} +1 -1
  36. package/dist/assets/{area-logos-Dr_ZUFxK.js → area-logos-JqUib9Ux.js} +1 -1
  37. package/dist/assets/{blockDiagram-677ZJIJ3-CaM55zZQ.js → blockDiagram-677ZJIJ3-CwOc3I3e.js} +1 -1
  38. package/dist/assets/{c4Diagram-LMCZKHZV-CCXnyLaP.js → c4Diagram-LMCZKHZV-ByDTz6Pi.js} +1 -1
  39. package/dist/assets/channel-C9DXs2xS.js +1 -0
  40. package/dist/assets/{chunk-2Q5K7J3B-CUBfQrLS.js → chunk-2Q5K7J3B-CJ-5lUjr.js} +1 -1
  41. package/dist/assets/{chunk-32BRIVSS-CBsYvxtB.js → chunk-32BRIVSS-ClxbX6JR.js} +1 -1
  42. package/dist/assets/{chunk-5VM5RSS4-D9K_iBqe.js → chunk-5VM5RSS4-D-B4g6BP.js} +1 -1
  43. package/dist/assets/{chunk-EX3LRPZG-BArv7wZg.js → chunk-EX3LRPZG-DE_ym6tm.js} +1 -1
  44. package/dist/assets/{chunk-JWPE2WC7-nqIaplf_.js → chunk-JWPE2WC7-DbFNU_Ef.js} +1 -1
  45. package/dist/assets/{chunk-MOJQB5TN-D9-EvsXA.js → chunk-MOJQB5TN-BonkkykU.js} +1 -1
  46. package/dist/assets/{chunk-RYQCIY6F-DhEtjvXf.js → chunk-RYQCIY6F-CqaRznBG.js} +1 -1
  47. package/dist/assets/{chunk-V7JOEXUC-CloPxFmQ.js → chunk-V7JOEXUC-DI5OpSJo.js} +1 -1
  48. package/dist/assets/{chunk-VR4S4FIN-B_gj6T5J.js → chunk-VR4S4FIN-DzHJs5bu.js} +1 -1
  49. package/dist/assets/{chunk-XXDRQBXY-CYQuP2YZ.js → chunk-XXDRQBXY-x9Zsg6mD.js} +1 -1
  50. package/dist/assets/classDiagram-OUVF2IWQ-apBPMHmB.js +1 -0
  51. package/dist/assets/classDiagram-v2-EOCWNBFH-apBPMHmB.js +1 -0
  52. package/dist/assets/{cose-bilkent-JH36ORCC-CnNLLImF.js → cose-bilkent-JH36ORCC-B4Gh0RgK.js} +1 -1
  53. package/dist/assets/{cynefin-VYW2F7L2-CIlHlZVD.js → cynefin-VYW2F7L2-1rocbocI.js} +1 -1
  54. package/dist/assets/{cynefinDiagram-TSTJHNR4-DhQrqCi2.js → cynefinDiagram-TSTJHNR4-BCbOrdTH.js} +1 -1
  55. package/dist/assets/{dagre-VKFMJZFB-XKh2Tzhw.js → dagre-VKFMJZFB-CquTDGCQ.js} +1 -1
  56. package/dist/assets/{diagram-FQU43EPY-C7LI8otY.js → diagram-FQU43EPY-CtRps2DK.js} +1 -1
  57. package/dist/assets/{diagram-G47NLZAW-BMBTikTC.js → diagram-G47NLZAW-C8uHzoun.js} +1 -1
  58. package/dist/assets/{diagram-NH7WQ7WH-BW_TXoVZ.js → diagram-NH7WQ7WH-BzGxTXmO.js} +1 -1
  59. package/dist/assets/{diagram-OA4YK3LP-PDlY_6C8.js → diagram-OA4YK3LP-BoUlY6He.js} +1 -1
  60. package/dist/assets/{diagram-WEI45ONY-svn0tX11.js → diagram-WEI45ONY-EewNkn4I.js} +1 -1
  61. package/dist/assets/{ebnfDiagram-CCIWWBDH-BUIULs-0.js → ebnfDiagram-CCIWWBDH-DAp0_rYI.js} +1 -1
  62. package/dist/assets/{erDiagram-Q63AITRT-BiLmEbtK.js → erDiagram-Q63AITRT-CIDiaIv_.js} +1 -1
  63. package/dist/assets/{flowDiagram-23GEKE2U-Mc6PRVJ8.js → flowDiagram-23GEKE2U-ZQudeco2.js} +1 -1
  64. package/dist/assets/{ganttDiagram-NO4QXBWP-BRUNbUed.js → ganttDiagram-NO4QXBWP-DDa9u7Kj.js} +1 -1
  65. package/dist/assets/{gitGraphDiagram-IHSO6WYX-ezzuOWgX.js → gitGraphDiagram-IHSO6WYX-D0LPqp_M.js} +1 -1
  66. package/dist/assets/{index-D_NWG6YH.js → index-BMILmzZt.js} +3 -3
  67. package/dist/assets/{index-CdgtzuJp.js → index-BuW-OFAQ.js} +1 -1
  68. package/dist/assets/{index-BfLoArjP.js → index-CM0wRsAP.js} +1 -1
  69. package/dist/assets/{index-DfYkUGiD.js → index-CbjaD3wY.js} +2 -2
  70. package/dist/assets/{index-D8VUtdAF.js → index-CgtrBMsu.js} +1 -1
  71. package/dist/assets/index-CmZ79Am7.js +2 -0
  72. package/dist/assets/{index-BhcdiVTj.js → index-D0O_xUmt.js} +1 -1
  73. package/dist/assets/{index-Y6_p8QBS.js → index-DjZWtEFJ.js} +1 -1
  74. package/dist/assets/{index-SspfO_Hv.js → index-tU947Zt1.js} +1 -1
  75. package/dist/assets/{infoDiagram-FWYZ7A6U-BlWhqgLQ.js → infoDiagram-FWYZ7A6U-CD4Ws76i.js} +1 -1
  76. package/dist/assets/{ishikawaDiagram-FXEZZL3T-C52xQkXn.js → ishikawaDiagram-FXEZZL3T-DSEmTd2f.js} +1 -1
  77. package/dist/assets/{journeyDiagram-5HDEW3XC-DyobJuKu.js → journeyDiagram-5HDEW3XC-3_c5LjHs.js} +1 -1
  78. package/dist/assets/{kanban-definition-HUTT4EX6-D3TWdW5B.js → kanban-definition-HUTT4EX6-24lijuGn.js} +1 -1
  79. package/dist/assets/{linear-kXdtPjWH.js → linear-B_K6Qcv3.js} +1 -1
  80. package/dist/assets/{main-BmGgLw1j.css → main-6EJsyrfW.css} +1 -1
  81. package/dist/assets/main-D0r07JA_.js +344 -0
  82. package/dist/assets/{mermaid.core-jkxx9VU-.js → mermaid.core-B6sgvfs-.js} +4 -4
  83. package/dist/assets/{mindmap-definition-LN4V7U3C-CbFsW2ye.js → mindmap-definition-LN4V7U3C-BsAOrAHj.js} +1 -1
  84. package/dist/assets/{pegDiagram-2B236MQR-D2nH_y6d.js → pegDiagram-2B236MQR-DdfupKz5.js} +1 -1
  85. package/dist/assets/{pieDiagram-ENE6RG2P-CaK3PEMJ.js → pieDiagram-ENE6RG2P-D1YBZYdK.js} +1 -1
  86. package/dist/assets/{quadrantDiagram-ABIIQ3AL-UgYM7N6C.js → quadrantDiagram-ABIIQ3AL-Bw-hoDGQ.js} +1 -1
  87. package/dist/assets/{railroadDiagram-RFXS5EU6-CC2ZEDL4.js → railroadDiagram-RFXS5EU6-CkmO-Wgv.js} +1 -1
  88. package/dist/assets/{requirementDiagram-TGXJPOKE-nlqWI7vA.js → requirementDiagram-TGXJPOKE-CSI19yqY.js} +1 -1
  89. package/dist/assets/{sankeyDiagram-HTMAVEWB-9uWggzcO.js → sankeyDiagram-HTMAVEWB-BvLYUk8J.js} +1 -1
  90. package/dist/assets/{sequenceDiagram-DBY2YBRQ-0p9VY0Wu.js → sequenceDiagram-DBY2YBRQ-DSQLX4Eb.js} +1 -1
  91. package/dist/assets/{sizeCapture-X5ZJPWSS-B2sHn0MG.js → sizeCapture-X5ZJPWSS-DfyzoJ-u.js} +1 -1
  92. package/dist/assets/{stateDiagram-2N3HPSRC-DpATBmQQ.js → stateDiagram-2N3HPSRC-G3bxzIPH.js} +1 -1
  93. package/dist/assets/stateDiagram-v2-6OUMAXLB-DCUADcVF.js +1 -0
  94. package/dist/assets/{swimlanes-5IMT3BWC-BPpym6MS.js → swimlanes-5IMT3BWC-CDZGonhF.js} +2 -2
  95. package/dist/assets/swimlanesDiagram-G3AALYLV-Ddwy1JnL.js +8 -0
  96. package/dist/assets/{timeline-definition-FHXFAJF6-SrMCxAjV.js → timeline-definition-FHXFAJF6-C5QDZq49.js} +1 -1
  97. package/dist/assets/{vennDiagram-L72KCM5P-_9HfkXQN.js → vennDiagram-L72KCM5P-0a1v0gi5.js} +1 -1
  98. package/dist/assets/{wardleyDiagram-EHGQE667-EnATDQOK.js → wardleyDiagram-EHGQE667-DArhtjvR.js} +1 -1
  99. package/dist/assets/{web-BkIE9AAN.js → web-BU7b4YVF.js} +1 -1
  100. package/dist/assets/{web-CB0hTO4y.js → web-BgCc_AGi.js} +1 -1
  101. package/dist/assets/{web-6vks_1wd.js → web-BiQ9JdSl.js} +1 -1
  102. package/dist/assets/{xychartDiagram-FW5EYKEG-DlMpFz7X.js → xychartDiagram-FW5EYKEG-BIZcXzGL.js} +1 -1
  103. package/dist/build-info.json +1 -1
  104. package/dist/index.html +2 -2
  105. package/dist/src/packages/server/data/builtin-skills/conversation-history.js +3 -2
  106. package/dist/src/packages/server/data/event-queries.js +16 -6
  107. package/dist/src/packages/server/data/migrations/009_whatsapp_participant_jid.sql +9 -0
  108. package/dist/src/packages/server/data/migrations/010_whatsapp_participant_alt_jid.sql +9 -0
  109. package/dist/src/packages/server/integrations/whatsapp/whatsapp-client.js +6 -2
  110. package/dist/src/packages/server/integrations/whatsapp/whatsapp-routes.js +103 -2
  111. package/dist/src/packages/server/integrations/whatsapp/whatsapp-skill.js +11 -0
  112. package/dist/src/packages/server/integrations/whatsapp/whatsapp-trigger-handler.js +48 -5
  113. package/dist/src/packages/server/routes/event-routes.js +2 -0
  114. package/dist/src/packages/server/routes/files.js +169 -0
  115. package/package.json +1 -1
  116. package/dist/assets/SpawnModal-Rduhhunw.js +0 -1
  117. package/dist/assets/channel-W4AeOLhF.js +0 -1
  118. package/dist/assets/classDiagram-OUVF2IWQ-39XSHTF2.js +0 -1
  119. package/dist/assets/classDiagram-v2-EOCWNBFH-39XSHTF2.js +0 -1
  120. package/dist/assets/index-C9Axek5A.js +0 -2
  121. package/dist/assets/main-Bt4E0_YW.js +0 -344
  122. package/dist/assets/stateDiagram-v2-6OUMAXLB-CQH1oSae.js +0 -1
  123. package/dist/assets/swimlanesDiagram-G3AALYLV-BhNebkPx.js +0 -8
@@ -1 +1 @@
1
- import{r as l,j as e,I as D,u as Z,c4 as js,ap as vs,c5 as Bs,c7 as Ms,s as j,d7 as Us,F as zs,d8 as Vs,_ as be,Q,aX as W,c as fe,d as xe,d9 as Ks,da as Hs,db as qs,dc as Ws,dd as Gs,de as Ys,df as Js,dg as Ns,dh as Xs,di as Zs,dj as Qs,aW as et,dk as st,dl as tt,dm as at,dn as nt,aC as ot,a5 as Ie,t as it,dp as ys,dq as lt,dr as Ze,ds as ct,dt as rt,du as dt,dv as ut,dw as pt,dx as ht,dy as mt,bm as gt,k as ft,m as xt,S as Pe,dz as bt,dA as jt,dB as vt,dC as qe,dD as Nt,dE as yt,B as wt,c9 as rs,dF as St,dG as kt,dH as Ct,dI as At,dJ as ws,dK as ds,dL as Ss,dM as Tt,dN as Et,dO as _e,dP as Pt,dQ as We,dR as us,dS as ps,c0 as Ge,z as Ue,y as _t,dT as Ye,dU as It,dV as hs,dW as Dt,dX as $t,dY as Lt,a1 as Ot,f as Ft,dZ as Rt,d_ as Bt,d$ as Mt}from"./main-Bt4E0_YW.js";import{g as Ut,d as zt,u as Vt}from"./area-logos-Dr_ZUFxK.js";import{s as Kt}from"./settingsSearch-DYr4vFyy.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-DYBBrXTx.js";const ks="tide-toolbox-collapse";function Ht(s,n){try{const t=localStorage.getItem(`${ks}-${s}`);if(t!==null)return t==="true"}catch{}return n}function qt(s,n){try{localStorage.setItem(`${ks}-${s}`,String(n))}catch{}}function H({title:s,storageKey:n,defaultOpen:t=!1,forceOpen:i=!1,children:d,headerExtra:r}){const[c,m]=l.useState(()=>n?Ht(n,t):t),h=()=>{const u=!c;m(u),n&&qt(n,u)},o=i||c;return e.jsxs("div",{className:`collapsible-section ${o?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:h,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[r,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(D,{name:o?"caret-down":"caret-right",size:10})})]})]}),o&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Wt({area:s,isSelected:n,onClick:t,onDelete:i}){const{t:d}=Z(["config","common"]),r=s.assignedAgentIds.length,c=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:[c," ",r>0&&`• ${r} ${r>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 Gt({building:s,isSelected:n,onClick:t,onEdit:i}){var m;const{t:d}=Z(["config"]),r=((m=s.pm2Status)==null?void 0:m.ports)||[],c=(h,o)=>{h.stopPropagation(),window.open(`http://${window.location.hostname}:${o}`,"_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(D,{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,r.length>0&&e.jsx("span",{className:"building-ports",children:r.map(h=>e.jsxs("a",{href:`http://${window.location.hostname}:${h}`,className:"building-port-link",onClick:o=>c(o,h),title:`Open :${h}`,children:[":",h]},h))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:h=>{h.stopPropagation(),i()},title:d("config:buildings.editBuilding"),children:e.jsx(D,{name:"gear",size:14})})]})}function Yt({building:s,onClose:n,onOpenModal:t}){var o,u,A,g,T,x,I,v;const{t:i}=Z(["config","common"]),r=Bs().get(s.id)||[],c=Ms[s.style||"server-rack"],m=p=>{j.sendBuildingCommand(s.id,p)},h=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(D,{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:c.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children: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:()=>m("start"),disabled:!((o=s.commands)!=null&&o.start)||s.status==="running",title:((u=s.commands)==null?void 0:u.start)||i("config:buildings.noStartCommand"),children:[e.jsx(D,{name:"play",size:12})," ",i("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>m("stop"),disabled:!((A=s.commands)!=null&&A.stop)||s.status==="stopped",title:((g=s.commands)==null?void 0:g.stop)||i("config:buildings.noStopCommand"),children:[e.jsx(D,{name:"stop",size:12,weight:"fill"})," ",i("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>m("restart"),disabled:!((T=s.commands)!=null&&T.restart),title:((x=s.commands)==null?void 0:x.restart)||i("config:buildings.noRestartCommand"),children:[e.jsx(D,{name:"refresh",size:12})," ",i("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>m("healthCheck"),disabled:!((I=s.commands)!=null&&I.healthCheck),title:((v=s.commands)==null?void 0:v.healthCheck)||i("config:buildings.noHealthCheck"),children:[e.jsx(D,{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,b)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>h(p.url),title:p.url,children:[e.jsx(D,{name:"link",size:12})," ",p.label||p.url]},b))})]}),r.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:()=>j.clearBuildingLogs(s.id),title:i("common:buttons.clear"),children:i("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:r.slice(-5).map((p,b)=>e.jsx("div",{className:"building-editor-log-entry",children:p},b))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(D,{name:"gear",size:12})," ",i("config:buildings.fullSettings")]})})]})}const Jt=[{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 Xt({area:s,onClose:n,onOpenFolder:t}){var ne;const{t:i}=Z(["config","common"]),[d,r]=l.useState(s.name),[c,m]=l.useState(s.prompt||""),[h,o]=l.useState(!1),[u,A]=l.useState(""),[g,T]=l.useState(!1),x=l.useRef(null);l.useEffect(()=>{r(s.name)},[s.id,s.name]),l.useEffect(()=>{m(s.prompt||"")},[s.id,s.prompt]);const I=N=>{const $=N.target.value;r($),j.updateArea(s.id,{name:$})},v=N=>{j.updateArea(s.id,{color:N})},p=N=>{const $=N.target.value;m($),j.updateArea(s.id,{prompt:$})},b=()=>{u.trim()&&(j.addDirectoryToArea(s.id,u.trim()),A(""),o(!1))},R=(N,$)=>{$.stopPropagation(),j.removeDirectoryFromArea(s.id,N)},M=()=>{j.bringAreaToFront(s.id)},G=()=>{j.sendAreaToBack(s.id)},q=l.useCallback(()=>{let N=2,$=2;s.type==="rectangle"&&s.width&&s.height?(N=s.width,$=s.height):s.type==="circle"&&s.radius&&(N=s.radius*1.414,$=s.radius*1.414);const z=Math.min(N,$)*.4;return{width:Math.round(z*10)/10,height:Math.round(z*10)/10}},[s.type,s.width,s.height,s.radius]),Y=async N=>{var z;const $=(z=N.target.files)==null?void 0:z[0];if($){T(!0);try{const w=await Vt(s.id,$),L=q();j.updateArea(s.id,{logo:{filename:w.filename,position:"center",width:L.width,height:L.height,keepAspectRatio:!0,opacity:.8}})}catch(w){console.error("Failed to upload logo:",w)}finally{T(!1),x.current&&(x.current.value="")}}},U=async()=>{try{await zt(s.id),j.updateArea(s.id,{logo:void 0})}catch(N){console.error("Failed to remove logo:",N)}},X=N=>{s.logo&&j.updateArea(s.id,{logo:{...s.logo,position:N}})},S=N=>{if(!s.logo)return;const $=parseFloat(N.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const z=s.logo.height/s.logo.width;j.updateArea(s.id,{logo:{...s.logo,width:$,height:Math.round($*z*10)/10}})}else j.updateArea(s.id,{logo:{...s.logo,width:$}})},B=N=>{if(!s.logo)return;const $=parseFloat(N.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const z=s.logo.width/s.logo.height;j.updateArea(s.id,{logo:{...s.logo,height:$,width:Math.round($*z*10)/10}})}else j.updateArea(s.id,{logo:{...s.logo,height:$}})},y=()=>{s.logo&&j.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},O=N=>{s.logo&&j.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(N.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children: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:I,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(N=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===N?"selected":""}`,style:{backgroundColor:N},onClick:()=>v(N),"aria-label":`Set area color ${N}`,"aria-pressed":s.color===N,title:N},N))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:M,title:i("config:areas.bringToFront"),children:[e.jsx(D,{name:"arrow-up",size:12})," ",i("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:G,title:i("config:areas.sendToBack"),children:[e.jsx(D,{name:"arrow-down",size:12})," ",i("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:i("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(ne=s.logo)!=null&&ne.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Ut(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 N;return(N=x.current)==null?void 0:N.click()},disabled:g,children:g?"...":e.jsx(D,{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:Jt.map(({key:N,labelKey:$})=>{var z;return e.jsx("button",{className:`area-logo-pos-btn ${((z=s.logo)==null?void 0:z.position)===N?"active":""}`,onClick:()=>X(N),children:i(`config:areas.${$}`)},N)})})]}),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:S,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:B,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:y}),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:O,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var N;return(N=x.current)==null?void 0:N.click()},disabled:g,children:g?"...":i("config:areas.uploadLogo")}),e.jsx("input",{ref:x,type:"file",accept:"image/*",style:{display:"none"},onChange:Y})]})]}),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(N=>e.jsxs("div",{className:"area-folder-item",title:N,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:i("config:areas.openFolder"),children:e.jsx(D,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:N.split("/").pop()||N}),e.jsx("button",{className:"area-folder-remove",onClick:$=>R(N,$),title:i("config:areas.removeFolder"),children:"×"})]},N)),h?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(zs,{value:u,onChange:A,onSubmit:b,placeholder:i("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:b,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>o(!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:c,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 Zt(){const{t:s}=Z(["config","common"]),n=Vs(),[t,i]=l.useState(!1),[d,r]=l.useState(null),[c,m]=l.useState({name:"",key:"",value:"",description:""}),[h,o]=l.useState(null),u=()=>{i(!0),r(null),m({name:"",key:"",value:"",description:""})},A=p=>{r(p.id),i(!1),m({name:p.name,key:p.key,value:p.value,description:p.description||""})},g=()=>{i(!1),r(null),m({name:"",key:"",value:"",description:""})},T=()=>{!c.name.trim()||!c.key.trim()||(d?j.updateSecret(d,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):j.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),g())},x=p=>{o(p)},I=()=>{h&&(j.deleteSecret(h),d===h&&g())},v=p=>{navigator.clipboard.writeText(`{{${p}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children: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:()=>v(p.key),title:s("config:secrets.copyPlaceholder"),children:`{{${p.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>A(p),title:s("common:buttons.edit"),children:e.jsx(D,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>x(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:c.name,onChange:p=>m({...c,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:c.key,onChange:p=>m({...c,key:p.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${c.key||"KEY"}}}`})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("config:secrets.secretValue")}),e.jsx("input",{type:"password",className:"secret-form-input",placeholder:s("config:secrets.valuePlaceholder"),value:c.value,onChange:p=>m({...c,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:c.description,onChange:p=>m({...c,description:p.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:g,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:T,disabled:!c.name.trim()||!c.key.trim(),children:s(d?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:u,children:s("config:secrets.addSecret")}),e.jsx(be,{isOpen:h!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:I,onClose:()=>o(null)})]})}async function Qt(){const s=Q(),n=await fetch(`${W()}/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 ea(s){const n=Q(),t=await fetch(`${W()}/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 sa(){const s=Q(),n=await fetch(`${W()}/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 ta(){const s=Q(),n=await fetch(`${W()}/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 aa(s){const n=Q(),t=await fetch(`${W()}/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 na(){const s=Q(),n=await fetch(`${W()}/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 oa(s){const n=Q(),t=await fetch(`${W()}/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 ia(){const s=Q(),n=await fetch(`${W()}/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 la(s){const n=Q(),t=await fetch(`${W()}/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 ca(){const s=Q(),n=await fetch(`${W()}/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 ra(s){const n=Q(),t=await fetch(`${W()}/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 da(){const s=Q(),n=await fetch(`${W()}/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 ua(s){const n=Q(),t=await fetch(`${W()}/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 pa(){const s=Q(),n=await fetch(`${W()}/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 ha(s){const n=Q(),t=await fetch(`${W()}/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 ma(){const s=Q(),n=await fetch(`${W()}/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 ga(s){const n=Q(),t=await fetch(`${W()}/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 fa(){const s=Q(),n=await fetch(`${W()}/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 xa(s){const n=Q(),t=await fetch(`${W()}/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 ba({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 ja(){const{t:s}=Z(["config","common"]),[n,t]=l.useState([]),[i,d]=l.useState(new Set),[r,c]=l.useState(new Set),[m,h]=l.useState(!1),[o,u]=l.useState(!1),[A,g]=l.useState(null),[T,x]=l.useState(null),[I,v]=l.useState(null),[p,b]=l.useState(null),[R,M]=l.useState(!1),[G,q]=l.useState(null);l.useEffect(()=>{fe(xe("/api/config/categories")).then(w=>w.json()).then(w=>{const L=Array.isArray(w)?w:[];t(L),d(new Set(L.map(F=>F.id)))}).catch(w=>console.error("Failed to fetch config categories:",w))},[]),l.useEffect(()=>{fa().then(b).catch(w=>{console.error("Failed to fetch backup status:",w),q(w.message||"Failed to fetch backup status")})},[]);const Y=async w=>{if(!R){M(!0),q(null);try{const L=await xa(w);b(L)}catch(L){q(L.message||"Failed to update backup setting")}finally{M(!1)}}},U=w=>{d(L=>{const F=new Set(L);return F.has(w)?F.delete(w):F.add(w),F})},X=w=>{c(L=>{const F=new Set(L);return F.has(w)?F.delete(w):F.add(w),F})},S=()=>d(new Set(n.map(w=>w.id))),B=()=>d(new Set),y=()=>{T&&c(new Set(T.categories.map(w=>w.id)))},O=()=>c(new Set),ne=async()=>{var w;if(i.size!==0){h(!0),v(null);try{const L=Array.from(i).join(","),F=await fe(xe(`/api/config/export?categories=${L}`));if(!F.ok)throw new Error("Export failed");const ae=await F.blob(),te=window.URL.createObjectURL(ae),P=document.createElement("a");P.href=te;const k=F.headers.get("Content-Disposition"),se=((w=k==null?void 0:k.match(/filename="(.+)"/))==null?void 0:w[1])||"tide-commander-config.zip";P.download=se,document.body.appendChild(P),P.click(),document.body.removeChild(P),window.URL.revokeObjectURL(te),v({type:"success",text:s("config:data.exportSuccess")})}catch(L){v({type:"error",text:L.message||"Export failed"})}finally{h(!1)}}},N=async w=>{var F;const L=(F=w.target.files)==null?void 0:F[0];if(L){g(L),v(null),x(null),c(new Set);try{const ae=await fe(xe("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await L.arrayBuffer()});if(!ae.ok){const k=await ae.json();throw new Error(k.error||"Failed to preview config file")}const te=await ae.json(),P=Array.isArray(te.categories)?te.categories:[];x({...te,categories:P}),c(new Set(P.map(k=>k.id)))}catch(ae){v({type:"error",text:ae.message||"Failed to read config file"}),g(null)}}},$=async()=>{if(!(!A||r.size===0)){u(!0),v(null);try{const w=Array.from(r).join(","),L=await fe(xe(`/api/config/import?categories=${w}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await A.arrayBuffer()}),F=await L.json();if(!L.ok)throw new Error(F.error||"Import failed");v({type:"success",text:F.message||s("config:data.importSuccess")}),g(null),x(null),c(new Set)}catch(w){v({type:"error",text:w.message||"Import failed"})}finally{u(!1)}}},z=()=>{g(null),x(null),c(new Set),v(null)};return e.jsxs("div",{className:"data-section",children:[I&&e.jsx("div",{className:`data-message data-message-${I.type}`,children:I.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(ba,{checked:!!(p!=null&&p.enabled),disabled:R||!p,onChange:Y})]}),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…"}),G&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:G})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:S,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:B,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:ne,disabled:m||i.size===0,children:m?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")})}),A?T?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:A.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(T.exportedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-subtitle",children:s("config:data.selectToImport")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:y,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:O,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:T.categories.map(w=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:r.has(w.id),onChange:()=>X(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:$,disabled:o||r.size===0,children:o?s("config:data.importing"):s("config:data.importCount",{count:r.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:N,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function va(){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 Na(){const{t:s}=Z(["config"]),{installInfo:n,phase:t,output:i,error:d,newVersion:r,autoRestart:c,refreshInstallInfo:m,runUpdate:h,reset:o}=Js(),[u,A]=l.useState(!1),g=l.useRef(null);l.useEffect(()=>{m()},[m]),l.useEffect(()=>{g.current&&(g.current.scrollTop=g.current.scrollHeight)},[i]);const T=l.useCallback(()=>{A(!0)},[]),x=l.useCallback(()=>{A(!1)},[]),I=l.useCallback(()=>{A(!1),h()},[h]),v=l.useCallback(()=>{o(),A(!1),m()},[o,m]),p=Ns.isNativePlatform(),b=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:b}),t==="idle"&&!u&&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:T,children:s("config:about.autoUpdateButton")})]}),t==="idle"&&u&&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:x,children:s("config:about.autoUpdateCancel")}),e.jsx("button",{className:"about-update-btn download",onClick:I,children:s("config:about.autoUpdateConfirm")})]})]}),(t==="running"||t==="success"||t==="failed")&&e.jsxs("div",{className:"about-autoupdate-stream",children:[e.jsxs("div",{className:"about-autoupdate-stream-title",children:[t==="running"&&s("config:about.autoUpdateRunning"),t==="success"&&s("config:about.autoUpdateSuccess"),t==="failed"&&s("config:about.autoUpdateFailed")]}),e.jsx("pre",{ref:g,className:"about-autoupdate-output",children:i||"..."}),t==="success"&&e.jsxs("div",{className:"about-autoupdate-success-hint",children:[r&&e.jsxs("div",{className:"about-autoupdate-newversion",children:["v",r]}),e.jsx("div",{children:s(c?"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:v,children:s("config:about.autoUpdateClose")})})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:b}),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:b}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdateDevMode")})]}):null}function ya(){const{t:s}=Z(["config"]),[n,t]=l.useState(null),[i,d]=l.useState(!1),[r,c]=l.useState(null);l.useEffect(()=>{Xs().then(t).catch(u=>c(u.message))},[]);const m=l.useCallback(async u=>{if(!i){d(!0),c(null);try{t(await Zs(u))}catch(A){c(A.message)}finally{d(!1)}}},[i]),h=Ns.isNativePlatform(),o=s(h?"config:about.unattendedServerTitle":"config:about.unattendedTitle");return!n&&!r?null:n?h&&!n.supported?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:o}),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:u=>void m(u.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}),r&&e.jsx("div",{className:"about-update-error",children:r})]}):h?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:o}),e.jsx("div",{className:"about-update-error",children:r})]})}function wa(){var R;const{t:s}=Z(["config"]),{isAndroid:n,supported:t,otaActive:i,bundleState:d,serverInfo:r,infoError:c,updateAvailable:m,phase:h,progress:o,error:u,autoSync:A,checkNow:g,syncNow:T,resetToBundled:x,setAutoSync:I}=Qs(),[v,p]=l.useState(null),b=l.useRef(g);return b.current=g,l.useEffect(()=>{n&&(b.current(!1),et.getInfo().then(M=>p(M.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:((R=d==null?void 0:d.hash)==null?void 0:R.slice(0,8))??"?"}):s("config:webBundle.sourceBundled"),v&&` · ${s("config:webBundle.apkVersion",{version:v})}`]}),r?e.jsxs("div",{className:"about-autoupdate-devnote",children:[s("config:webBundle.serverBundle",{version:r.version,hash:r.hash.slice(0,8)})," — ",s(m?"config:webBundle.updateAvailable":"config:webBundle.upToDate")]}):c&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:webBundle.serverUnavailable")}),u&&e.jsx("div",{className:"about-update-error",children:u}),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:A,onChange:M=>I(M.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn download",onClick:()=>void T(),disabled:h!=="idle"||!r,children:h==="syncing"?s("config:webBundle.syncingPct",{percent:o??0}):s("config:webBundle.syncNow")}),i&&e.jsx("button",{className:"about-update-btn changelog",onClick:()=>void x(),children:s("config:webBundle.reset")})]})]})}function Sa(){const{t:s}=Z(["config"]),[n,t]=l.useState(null),[i,d]=l.useState(!1),[r,c]=l.useState(null);l.useEffect(()=>{at().then(t).catch(()=>t(null))},[]);const m=l.useCallback(async h=>{if(!i){d(!0),c(null);try{await nt(h),t(h)}catch(o){c(o.message)}finally{d(!1)}}},[i]);return n===null?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:about.backgroundServiceTitle")}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:about.backgroundServiceDesc")}),e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:n,disabled:i,onChange:h=>void m(h.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),!n&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.backgroundServiceDisabledNote")}),r&&e.jsx("div",{className:"about-update-error",children:r})]})}function ka(){var p;const{t:s}=Z(["config"]),[n,t]=l.useState(null),[i,d]=l.useState(""),[r,c]=l.useState(!1),[m,h]=l.useState(!1),[o,u]=l.useState(null),[A,g]=l.useState(null),T=l.useCallback(()=>{st().then(t)},[]);l.useEffect(T,[T]);const x=l.useCallback(async()=>{if(!(m||!i.trim())){h(!0),u(null),g(null);try{const b=await fe(xe("/api/push/service-account"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({json:i})}),R=await b.json();if(!b.ok)throw new Error(R.error||"Invalid service account");d(""),c(!1),g(s("config:about.pushSaved",{project:R.projectId})),T()}catch(b){u(b.message)}finally{h(!1)}}},[m,i,T,s]),I=l.useCallback(async()=>{h(!0),u(null),g(null);const b=await tt();if(h(!1),!b){u(s("config:about.pushTestFailed"));return}g(s("config:about.pushTestSent",{count:b.sent})),T()},[T,s]);if(!n)return null;const v=((p=n.devices)==null?void 0:p.length)??0;return e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:about.pushTitle")}),e.jsx("div",{className:"about-autoupdate-row",children:e.jsx("span",{className:"about-autoupdate-devnote",children:n.configured?s("config:about.pushConfigured",{project:n.projectId,count:v}):s("config:about.pushNotConfigured")})}),r?e.jsxs(e.Fragment,{children:[e.jsx("textarea",{className:"about-push-credentials",value:i,onChange:b=>d(b.target.value),placeholder:s("config:about.pushCredentialsPlaceholder"),rows:4,spellCheck:!1}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn download",onClick:()=>void x(),disabled:m||!i.trim(),children:s("config:about.pushSaveCredentials")}),e.jsx("button",{className:"about-update-btn changelog",onClick:()=>c(!1),children:s("config:about.pushCancel")})]})]}):e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:()=>c(!0),children:n.configured?s("config:about.pushReplaceCredentials"):s("config:about.pushAddCredentials")}),n.configured&&v>0&&e.jsx("button",{className:"about-update-btn download",onClick:()=>void I(),disabled:m,children:s("config:about.pushTest")})]}),A&&e.jsx("div",{className:"about-autoupdate-devnote",children:A}),o&&e.jsx("div",{className:"about-update-error",children:o}),n.configured&&n.lastError&&!o&&e.jsx("div",{className:"about-update-error",children:n.lastError})]})}function Ca(){const{t:s}=Z(["config"]),{updateAvailable:n,updateInfo:t,recentReleases:i,isChecking:d,error:r,currentVersion:c,isAndroid:m,downloadPhase:h,downloadProgress:o,checkForUpdate:u,downloadAndInstall:A,openReleasePage:g}=qs(),[T,x]=l.useState(!1),I=p=>p?`${(p/(1024*1024)).toFixed(1)} MB`:"",v=p=>new Date(p).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:e.jsx(D,{name:"waves",size:24})}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:c}),n&&t?e.jsx("span",{className:"about-version-update-badge",onClick:g,title:`Update available: ${t.version}`,children:t.version}):e.jsxs("a",{href:"https://github.com/deivid11/tide-commander/releases",target:"_blank",rel:"noopener noreferrer",className:"about-version-status",children:["(",s("config:about.updated"),")"]})]})]}),e.jsx(Na,{}),e.jsx(ya,{}),e.jsx(wa,{}),e.jsx(ka,{}),e.jsx(Sa,{}),e.jsx("div",{className:"about-changelog-row",children:e.jsx("button",{className:"about-update-btn changelog",onClick:()=>x(!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"),": ",I(t.apkSize)]}),r&&e.jsx("div",{className:"about-update-error",children:r}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:g,children:s("config:about.changelog")}),m&&t.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:()=>void A(),disabled:h!=="idle",children:h==="downloading"?s("config:appUpdateBanner.downloadingPct",{percent:o??0}):s(h==="installing"?"config:appUpdateBanner.installHint":"config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:g,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(d?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>u(!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${c}`||p.version===c?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:p.version}),e.jsx("span",{className:"about-release-date",children:v(p.publishedAt)})]},p.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:e.jsx(D,{name:"package",size:14})}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]}),T&&e.jsx(Ws,{onClose:()=>x(!1)})]})}const Aa={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function Ta({onOpenModal:s}){const[n,t]=l.useState([]),[i,d]=l.useState(!0),r=l.useCallback(async()=>{try{const c=await fe(xe("/api/integrations"));if(!c.ok)return;const m=await c.json();t(m)}catch{}finally{d(!1)}},[]);return l.useEffect(()=>{r()},[r]),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(c=>{const m=Aa[c.id]||"🔌",h=!!c.status.error,o=c.status.connected,u=h?"#f38ba8":o?"#a6e3a1":"#fab387",A=h?"Error":o?"Connected":"Setup Required",g=h?"✗":o?"✓":"⚠";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:m}),e.jsx("span",{style:{flex:1,minWidth:0,color:"var(--text-primary, #cdd6f4)",fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c.name}),e.jsx("span",{style:{color:u,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:A,children:g}),e.jsx("button",{onClick:()=>s(c.id),title:`Configure ${c.name}`,style:{background:"none",border:"none",cursor:"pointer",padding:"1px 3px",fontSize:12,color:"var(--text-secondary, #a6adc8)",borderRadius:3,flexShrink:0,lineHeight:1},onMouseEnter:T=>{T.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:T=>{T.target.style.color="var(--text-secondary, #a6adc8)"},children:"⚙️"})]},c.id)}),e.jsx("button",{onClick:()=>s(),style:{background:"none",border:"1px dashed var(--border, #313244)",borderRadius:4,padding:"3px 8px",cursor:"pointer",color:"var(--text-secondary, #a6adc8)",fontSize:11,textAlign:"center",marginTop:2},onMouseEnter:c=>{c.target.style.borderColor="var(--accent, #89b4fa)",c.target.style.color="var(--accent, #89b4fa)"},onMouseLeave:c=>{c.target.style.borderColor="var(--border, #313244)",c.target.style.color="var(--text-secondary, #a6adc8)"},children:"Manage All Integrations"})]})}const ze="__global__";function Ea({isOpen:s,onClose:n,initialAgentId:t}){const{t:i}=Z(["config"]),d=ot(),[r,c]=l.useState(""),[m,h]=l.useState(""),[o,u]=l.useState(!1),[A,g]=l.useState(""),[T,x]=l.useState(""),[I,v]=l.useState(null),[p,b]=l.useState(null),[R,M]=l.useState(!1),[G,q]=l.useState(!1),[Y,U]=l.useState(!1),[X,S]=l.useState(null),B=l.useMemo(()=>[...d].sort((P,k)=>P.name.localeCompare(k.name)),[d]),y=l.useMemo(()=>d.find(P=>P.id===r),[d,r]),O=r===ze;l.useEffect(()=>{if(!s)return;const P=t&&d.some(k=>k.id===t)?t:ze;c(P),u(!1),Qt().then(k=>h(k)).catch(()=>h("")).finally(()=>u(!0))},[s]),l.useEffect(()=>{const P=r===ze?m:(y==null?void 0:y.customPrompt)??"";g(P),x(P),M(!1),v(null),b(null)},[r,o]);const ne=P=>{const k=P.target.value;g(k),M(k!==T),v(null),b(null)},N=async()=>{if(r)try{v(null),b(null),O?(await ea(A),h(A),b(i("config:systemPrompt.savedGlobal"))):(j.updateAgentProperties(r,{customPrompt:A}),b(i("config:systemPrompt.saved"))),x(A),M(!1)}catch(P){v(P instanceof Error?P.message:"Failed to save system prompt")}},$=()=>{q(!0)},z=async()=>{if(r)try{v(null),b(null),O?(await sa(),h(""),b(i("config:systemPrompt.clearedGlobal"))):(j.updateAgentProperties(r,{customPrompt:""}),b(i("config:systemPrompt.cleared"))),g(""),x(""),M(!1)}catch(P){v(P instanceof Error?P.message:"Failed to clear system prompt")}},w=()=>{g(T),M(!1),v(null),b(null)},L=P=>{if(P!==r){if(R){S(P),U(!0);return}c(P)}},F=()=>{if(R){S(null),U(!0);return}n()},ae=()=>{if(U(!1),X){const P=X;S(null),c(P)}else n()},te=P=>{P.key==="Escape"&&(P.preventDefault(),F())};return s?e.jsxs(Ie,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:F,children:e.jsxs("div",{className:"system-prompt-modal",onClick:P=>P.stopPropagation(),onKeyDown:te,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:i("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:F,"aria-label":"Close",children:e.jsx(D,{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:[O?e.jsx(D,{name:"globe",size:20,className:"agent-picker-icon"}):y&&e.jsx(it,{classId:y.class,size:20,className:"agent-picker-icon"}),e.jsxs("select",{id:"system-prompt-agent",className:"agent-picker-select",value:r,onChange:P=>L(P.target.value),children:[e.jsxs("option",{value:ze,children:[i("config:systemPrompt.globalOption"),m?" • ✦":""]}),B.map(P=>e.jsxs("option",{value:P.id,children:[P.name,P.customPrompt?" • ✦":""]},P.id))]})]})]}),I&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{name:"warn",size:14})}),I]}),p&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{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:[A.length," ",i("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:A,onChange:ne,placeholder:i("config:systemPrompt.placeholder"),rows:18,disabled:O&&!o,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:i(O?"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:$,disabled:!A||!r,children:i("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:F,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:w,disabled:!R,children:i("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:N,disabled:!R||!r,children:i("config:systemPrompt.save")})]})]})]})}),e.jsx(be,{isOpen:G,title:i("config:systemPrompt.clear"),message:i(O?"config:systemPrompt.confirmClearGlobal":"config:systemPrompt.confirmClear"),confirmLabel:i("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{z()},onClose:()=>q(!1)}),e.jsx(be,{isOpen:Y,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:ae,onClose:()=>{U(!1),S(null)}})]}):null}const ms={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},Pa=2500,_a=12e4;function gs(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function Ia(s,n){return s.enabled===n.enabled&&s.baseUrl===n.baseUrl&&s.defaultSessionId===n.defaultSessionId&&s.webhookVerifyToken===n.webhookVerifyToken&&s.showIncomingToasts===n.showIncomingToasts}function Da({isOpen:s,onClose:n}){const{t}=Z(["config"]),[i,d]=l.useState(ms),[r,c]=l.useState(ms),[m,h]=l.useState(!1),[o,u]=l.useState([]),[A,g]=l.useState(!0),[T,x]=l.useState(null),[I,v]=l.useState(null),[p,b]=l.useState(""),[R,M]=l.useState(!1),[G,q]=l.useState(""),[Y,U]=l.useState(null),[X,S]=l.useState(null),[B,y]=l.useState(null),O=l.useRef(null),ne=l.useRef(0),[N,$]=l.useState(""),[z,w]=l.useState(""),[L,F]=l.useState(null),[ae,te]=l.useState(!1),[P,k]=l.useState(!1),[se,ie]=l.useState(!1),[ce,le]=l.useState(!1),[he,Ae]=l.useState(null),Se=!Ia(i,r),pe=l.useCallback(()=>{O.current&&(clearTimeout(O.current),O.current=null)},[]),Te=l.useCallback(async()=>{try{g(!0),x(null),v(null);const[f,V]=await Promise.all([ys(),lt()]),re=gs(f);if(d(re),c(re),h(!!V.configured),V.configured)try{const Ne=await Ze();u(Array.isArray(Ne)?Ne:[])}catch{u([])}else u([])}catch(f){x(f instanceof Error?f.message:t("config:whatsapp.errors.loadFailed"))}finally{g(!1)}},[t]),je=l.useCallback(async()=>{try{const f=await Ze();u(Array.isArray(f)?f:[])}catch{}},[]);l.useEffect(()=>(s?Te():(pe(),U(null),S(null),y(null),b(""),M(!1),F(null)),()=>{pe()}),[s,Te,pe]);const me=(f,V)=>{d(re=>({...re,[f]:V})),x(null),v(null)},De=async()=>{try{x(null),v(null);const f=await pt({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),c(V),v(t("config:whatsapp.saved"))}catch(f){x(f instanceof Error?f.message:t("config:whatsapp.errors.saveFailed"))}},$e=()=>{d(r),x(null),v(null)},ve=()=>{if(Se){k(!0);return}n()},Le=f=>{f.key==="Escape"&&(f.preventDefault(),ve())},Ke=async()=>{const f=p.trim();if(f)try{x(null),v(null),await rt(f),b(""),M(!1),h(!0),v(t("config:whatsapp.apiKeySaved"))}catch(V){x(V instanceof Error?V.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},He=()=>{ie(!0)},Oe=async()=>{try{x(null),v(null),await ht(),h(!1),v(t("config:whatsapp.apiKeyCleared"))}catch(f){x(f instanceof Error?f.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},Fe=l.useCallback(async f=>{if(Date.now()>ne.current){y(t("config:whatsapp.pairingTimeout")),U(null),S(null),pe(),je();return}try{const V=await ct(f);if(V.status&&["connected","paired","open","ready"].includes(V.status.toLowerCase())){y(t("config:whatsapp.pairingSuccess")),U(null),S(null),pe(),je();return}const Ne=V.qrUrl??V.qr??null;Ne&&S(Ne)}catch(V){y(V instanceof Error?V.message:t("config:whatsapp.errors.qrFetchFailed"))}O.current=setTimeout(()=>{Fe(f)},Pa)},[je,pe,t]),Re=async()=>{const f=G.trim();if(f)try{x(null),v(null),y(null),S(null),pe(),await dt(f),q(""),U(f),ne.current=Date.now()+_a,Fe(f),je()}catch(V){x(V instanceof Error?V.message:t("config:whatsapp.errors.sessionCreateFailed"))}},Be=()=>{pe(),U(null),S(null),y(null)},ke=f=>{Ae(f),le(!0)},_=async()=>{if(he)try{x(null),v(null),await mt(he),Y===he&&Be(),je(),v(t("config:whatsapp.sessionDeleted"))}catch(f){x(f instanceof Error?f.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{Ae(null)}},ue=async()=>{const f=N.trim(),V=z.trim();if(!(!f||!V))try{te(!0),F(null);const re=i.defaultSessionId.trim()||void 0;await ut(f,V,re),F({kind:"success",text:t("config:whatsapp.testSent")})}catch(re){F({kind:"error",text:re instanceof Error?re.message:t("config:whatsapp.errors.testSendFailed")})}finally{te(!1)}};return s?e.jsxs(Ie,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:ve,children:e.jsxs("div",{className:"whatsapp-config-modal",onClick:f=>f.stopPropagation(),onKeyDown:Le,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsapp.title")}),e.jsx("button",{className:"modal-close",onClick:ve,"aria-label":"Close",children:e.jsx(D,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:A?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsapp.description")}),T&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{name:"warn",size:14})}),T]}),I&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{name:"check",size:14})}),I]}),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=>me("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=>me("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=>me("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=>me("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=>me("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:m?e.jsxs("span",{className:"wa-status wa-status-ok",children:[e.jsx(D,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(D,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:R?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:p,onChange:f=>b(f.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>M(f=>!f),title:t(R?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(D,{name:R?"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:He,disabled:!m,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(o)||o.length===0?e.jsx("div",{className:"wa-empty",children:t("config:whatsapp.noSessions")}):o.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:()=>ke(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:G,onChange:f=>q(f.target.value),onKeyDown:f=>{f.key==="Enter"&&Re()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Re,disabled:!G.trim()||Y!==null,children:t("config:whatsapp.addSession")})]}),Y&&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:Y})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Be,children:t("config:whatsapp.cancelPairing")})]}),X?e.jsx("div",{className:"wa-qr-image",children:e.jsx("img",{src:X,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")})]})]}),B&&!Y&&e.jsx("div",{className:"wa-pairing-message",children:B})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.testMessage")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-to",className:"wa-label",children:t("config:whatsapp.testTo")}),e.jsx("input",{id:"wa-test-to",type:"text",className:"wa-input",placeholder:t("config:whatsapp.testToPlaceholder"),value:N,onChange:f=>$(f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-message",className:"wa-label",children:t("config:whatsapp.testMessageBody")}),e.jsx("textarea",{id:"wa-test-message",className:"wa-textarea",rows:4,placeholder:t("config:whatsapp.testMessageBodyPlaceholder"),value: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:ue,disabled:!N.trim()||!z.trim()||ae,children:t(ae?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),L&&e.jsxs("div",{className:`alert ${L.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{name:L.kind==="success"?"check":"warn",size:14})}),L.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:ve,children:t("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:$e,disabled:!Se||A,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:De,disabled:!Se||A,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(be,{isOpen:P,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{k(!1),n()},onClose:()=>k(!1)}),e.jsx(be,{isOpen:se,title:t("config:whatsapp.clearKey"),message:t("config:whatsapp.confirmClearKey"),confirmLabel:t("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Oe()},onClose:()=>ie(!1)}),e.jsx(be,{isOpen:ce,title:t("config:whatsapp.deleteSession"),message:t("config:whatsapp.confirmDeleteSession",{id:he??""}),confirmLabel:t("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{_()},onClose:()=>{le(!1),Ae(null)}})]}):null}const Cs=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function Qe(s=!1){const n=Q(),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 $a(){const s=await fetch(`${W()}/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 La(s){const n=await fetch(`${W()}/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 Oa(){const s=await fetch(`${W()}/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 Ve={messages:!0,statusChanges:!0,taskComplete:!0,errors:!0,planReady:!0,agentSpawned:!0,agentStopped:!0},fs={filter:{...Ve},recipient:""};function Fa(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 Ra({isOpen:s,onClose:n}){const{t}=Z(["config"]),[i,d]=l.useState(fs),[r,c]=l.useState(fs),[m,h]=l.useState(!0),[o,u]=l.useState(null),[A,g]=l.useState(null),[T,x]=l.useState(!1),[I,v]=l.useState(!1),p=!Fa(i,r),b=l.useCallback(async()=>{try{h(!0),u(null),g(null);const S=await $a(),B={filter:{...Ve,...S.filter},recipient:S.recipient??""};d(B),c(B)}catch(S){u(S instanceof Error?S.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{h(!1)}},[t]);l.useEffect(()=>{s&&b()},[s,b]);const R=(S,B)=>{d(y=>({...y,filter:{...y.filter,[S]:B}})),u(null),g(null)},M=S=>{d(B=>({...B,recipient:S})),u(null),g(null)},G=async()=>{try{u(null),g(null);const S=await La({filter:i.filter,recipient:i.recipient.trim()}),B={filter:{...Ve,...S.filter},recipient:S.recipient??""};d(B),c(B),g(t("config:whatsappNotifications.saved"))}catch(S){u(S instanceof Error?S.message:t("config:whatsappNotifications.errors.saveFailed"))}},q=()=>{d(r),u(null),g(null)},Y=async()=>{try{u(null),g(null);const S=await Oa(),B={filter:{...Ve,...S.filter},recipient:S.recipient??""};d(B),c(B),g(t("config:whatsappNotifications.resetDone"))}catch(S){u(S instanceof Error?S.message:t("config:whatsappNotifications.errors.resetFailed"))}},U=()=>{if(p){x(!0);return}n()},X=S=>{S.key==="Escape"&&(S.preventDefault(),U())};return s?e.jsxs(Ie,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:U,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:S=>S.stopPropagation(),onKeyDown:X,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(D,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:m?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")}),o&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{name:"warn",size:14})}),o]}),A&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{name:"check",size:14})}),A]}),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:S=>M(S.target.value)}),e.jsx("span",{className:"wan-hint",children:t("config:whatsappNotifications.recipientHint")})]})]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.events")}),e.jsx("p",{className:"wan-section-hint",children:t("config:whatsappNotifications.eventsHint")}),Cs.map(S=>e.jsxs("div",{className:"wan-toggle-row",children:[e.jsxs("div",{className:"wan-toggle-info",children:[e.jsx("span",{className:"wan-toggle-title",children:t(`config:whatsappNotifications.events.${S}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${S}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:i.filter[S],onChange:B=>R(S,B.target.checked)}),e.jsx("span",{className:"wan-toggle-track",children:e.jsx("span",{className:"wan-toggle-thumb"})})]})]},S))]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:()=>v(!0),disabled:m,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:q,disabled:!p||m,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:G,disabled:!p||m,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(be,{isOpen:T,title:t("config:whatsappNotifications.unsavedTitle"),message:t("config:whatsappNotifications.unsavedMessage"),confirmLabel:t("config:whatsappNotifications.closeAnyway"),cancelLabel:t("config:whatsappNotifications.keepEditing"),variant:"danger",onConfirm:()=>{x(!1),n()},onClose:()=>x(!1)}),e.jsx(be,{isOpen:I,title:t("config:whatsappNotifications.resetToDefaults"),message:t("config:whatsappNotifications.confirmReset"),confirmLabel:t("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Y(),v(!1)},onClose:()=>v(!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 Ba(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 r=Math.floor(d/60);if(r<24)return`${r}h`;const c=Math.floor(r/24);return c===1?"yesterday":c<7?`${c}d`:xs(t)}function xs(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Ma(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 Ua(s,n){return s.length<=n?s:s.slice(0,Math.max(0,n-1)).trimEnd()+"…"}function za({chats:s,selectedChatId:n,loading:t,error:i,onSelect:d,onRefresh:r,now:c}){const{t:m}=Z(["config","common"]);return e.jsxs("div",{className:"whatsapp-history-chatlist",children:[e.jsxs("div",{className:"whatsapp-history-chatlist__header",children:[e.jsx("span",{className:"whatsapp-history-chatlist__title",children:m("config:whatsappHistory.chats")}),e.jsx("button",{type:"button",className:"whatsapp-history-chatlist__refresh",onClick:r,disabled:t,"aria-label":m("config:whatsappHistory.refresh"),title:m("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:m("config:whatsappHistory.loadingChats")})]}),!t&&!i&&s.length===0&&e.jsx("div",{className:"whatsapp-history-chatlist__empty",children:m("config:whatsappHistory.emptyChats")}),e.jsx("ul",{className:"whatsapp-history-chatlist__items",children:s.map(h=>{const o=Ts(h.lastMessageType),u=h.lastMessagePreview||`[${h.lastMessageType}]`,A=h.chatId===n,g=As(h.chatId),T=h.isGroup?h.groupName:h.fromName,x=T||g,I=!!T&&T!==g;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${A?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>d(h.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:h.chatId,children:x}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:Ba(h.lastTimestamp,c)})]}),I&&e.jsx("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--jid",children:e.jsx("span",{className:"whatsapp-history-chatlist__jid",children:g})}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[h.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),o&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[o," "]}),Ua(u,40)]}),h.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:h.unreadCount})]})]})},h.chatId)})})]})}function Va({message:s}){const n=s.direction==="outbound"?"outbound":"inbound",t=Ts(s.messageType),i=(s.body??"").trim(),d=i.length>0,r=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:r}),s.audioTranscription&&e.jsxs("span",{className:"whatsapp-history-bubble__transcription",children:["“",s.audioTranscription,"”"]}),s.mediaPath&&e.jsx("a",{className:"whatsapp-history-bubble__media-link",href:s.mediaPath,target:"_blank",rel:"noopener noreferrer",children:s.mediaFilename||"open media"}),e.jsx("span",{className:"whatsapp-history-bubble__time",children:Ma(s.timestamp)})]})})}const Ka=["all","inbound","outbound"],Ha=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function qa({direction:s,type:n,onDirectionChange:t,onTypeChange:i,disabled:d}){const{t:r}=Z(["config"]);return e.jsxs("div",{className:"whatsapp-history-filters",children:[e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:r("config:whatsappHistory.direction")}),e.jsx("select",{value:s,onChange:c=>t(c.target.value),disabled:d,children:Ka.map(c=>e.jsx("option",{value:c,children:r(`config:whatsappHistory.directionValues.${c}`)},c))})]}),e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:r("config:whatsappHistory.type")}),e.jsx("select",{value:n,onChange:c=>i(c.target.value),disabled:d,children:Ha.map(c=>e.jsx("option",{value:c,children:r(`config:whatsappHistory.typeValues.${c}`)},c))})]})]})}const Wa=80;function Ga({chatId:s,messages:n,loading:t,loadingMore:i,error:d,hasMore:r,direction:c,type:m,onDirectionChange:h,onTypeChange:o,onLoadMore:u}){const{t:A}=Z(["config"]),g=l.useRef(null),T=l.useRef(null),x=l.useRef(!1),I=l.useRef(null);l.useEffect(()=>{T.current!==s&&(T.current=s,x.current=!1)},[s]),l.useLayoutEffect(()=>{g.current&&(x.current||n.length!==0&&(g.current.scrollTop=g.current.scrollHeight,x.current=!0))},[s,n.length]),l.useLayoutEffect(()=>{if(!g.current||I.current===null)return;const b=g.current.scrollHeight-I.current;I.current=null,b>0&&(g.current.scrollTop+=b)},[n.length]);const v=l.useCallback(()=>{!r||i||t||(g.current&&(I.current=g.current.scrollHeight),u())},[r,i,t,u]),p=l.useCallback(b=>{if(!x.current)return;b.currentTarget.scrollTop<=Wa&&v()},[v]);return s?e.jsxs("div",{className:"whatsapp-history-messages",children:[e.jsxs("div",{className:"whatsapp-history-messages__header",children:[e.jsx("div",{className:"whatsapp-history-messages__title",children:As(s)}),e.jsx(qa,{direction:c,type:m,onDirectionChange:h,onTypeChange:o,disabled:t})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:g,onScroll:p,children:[r&&e.jsx("div",{className:"whatsapp-history-messages__load-more-row",children:e.jsx("button",{type:"button",className:"whatsapp-history-messages__load-more",onClick:v,disabled:i||t,children:A(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:A("config:whatsappHistory.loadingMessages")})]}),!t&&!d&&n.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:A("config:whatsappHistory.emptyMessages")}),n.map(b=>e.jsx(Va,{message:b},Ya(b)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:A("config:whatsappHistory.selectChat")})})}function Ya(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=Q(),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 Ja(s){const n=`${W()}/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(),r=`${W()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(n)}/messages${d?`?${d}`:""}`,c=await fetch(r,{headers:Es()});if(!c.ok)throw new Error(await Ps(c,"Failed to fetch WhatsApp messages"));return c.json()}const Xa=50;function Za({isOpen:s,onClose:n}){const{t}=Z(["config"]),[i,d]=l.useState([]),[r,c]=l.useState(null),[m,h]=l.useState(null),[o,u]=l.useState([]),[A,g]=l.useState(!1),[T,x]=l.useState(null),[I,v]=l.useState(null),[p,b]=l.useState([]),[R,M]=l.useState(!1),[G,q]=l.useState(!1),[Y,U]=l.useState(null),[X,S]=l.useState(null),[B,y]=l.useState("all"),[O,ne]=l.useState("all"),[N,$]=l.useState(()=>Date.now()),z=l.useRef(0);l.useEffect(()=>{if(!s)return;const k=window.setInterval(()=>$(Date.now()),6e4);return()=>window.clearInterval(k)},[s]),l.useEffect(()=>{if(!s)return;let k=!1;return(async()=>{var se;try{h(null);const[ie,ce]=await Promise.all([Ze().catch(()=>[]),ys().catch(()=>null)]);if(k)return;d(ie);const le=(ce==null?void 0:ce.defaultSessionId)||((se=ie[0])==null?void 0:se.id)||null;c(he=>he??le)}catch(ie){if(k)return;h(ie instanceof Error?ie.message:String(ie))}})(),()=>{k=!0}},[s]);const w=l.useCallback(async k=>{g(!0),x(null);try{const se=await Ja(k);u(se.chats)}catch(se){x(se instanceof Error?se.message:String(se))}finally{g(!1)}},[]);l.useEffect(()=>{!s||!r||(v(null),b([]),S(null),w(r))},[s,r,w]);const L=l.useMemo(()=>{const k={limit:Xa};return B!=="all"&&(k.direction=B),O!=="all"&&(k.type=O),k},[B,O]),F=l.useCallback(async(k,se,ie)=>{const ce=++z.current;M(!0),U(null),b([]),S(null);try{const le=await bs(k,se,ie);if(ce!==z.current)return;b([...le.messages].reverse()),S(le.nextCursor)}catch(le){if(ce!==z.current)return;U(le instanceof Error?le.message:String(le))}finally{ce===z.current&&M(!1)}},[]);l.useEffect(()=>{!s||!r||!I||F(r,I,L)},[s,r,I,L,F]);const ae=l.useCallback(async()=>{if(!(!r||!I||!X)){q(!0),U(null);try{const k=await bs(r,I,{...L,cursor:X});b(se=>[...[...k.messages].reverse(),...se]),S(k.nextCursor)}catch(k){U(k instanceof Error?k.message:String(k))}finally{q(!1)}}},[r,I,X,L]),te=l.useCallback(()=>{r&&w(r)},[r,w]),P=l.useCallback(k=>{k.key==="Escape"&&(k.preventDefault(),n())},[n]);return s?e.jsx(Ie,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:k=>k.stopPropagation(),onKeyDown:P,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappHistory.title")}),e.jsx("div",{className:"whatsapp-history-modal__session",children:e.jsxs("label",{children:[e.jsx("span",{children:t("config:whatsappHistory.session")}),e.jsxs("select",{value:r??"",onChange:k=>c(k.target.value||null),disabled:i.length===0,children:[i.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),i.map(k=>e.jsxs("option",{value:k.id,children:[k.id,k.pairedNumber?` (${k.pairedNumber})`:""]},k.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(D,{name:"close",size:16})})]}),m&&e.jsx("div",{className:"whatsapp-history-modal__alert",children:m}),e.jsxs("div",{className:"whatsapp-history-modal__body",children:[e.jsx(za,{chats:o,selectedChatId:I,loading:A,error:T,onSelect:v,onRefresh:te,now:N}),e.jsx(Ga,{chatId:I,messages:p,loading:R,loadingMore:G,error:Y,hasMore:X!==null,direction:B,type:O,onDirectionChange:y,onTypeChange:ne,onLoadMore:ae})]})]})})}):null}function Qa({isOpen:s,onClose:n,onOpenConfig:t,onOpenNotifications:i,onOpenHistory:d}){const{t:r}=Z(["config"]);if(l.useEffect(()=>{if(!s)return;const m=h=>{h.key==="Escape"&&(h.preventDefault(),n())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[s,n]),!s)return null;const c=m=>{n(),m()};return e.jsx(Ie,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-hub-modal",onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"whatsapp-hub-modal__icon",children:"📱"}),r("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(D,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"whatsapp-hub-modal__intro",children:r("config:whatsappHub.intro",{defaultValue:"Pick what you want to manage for the WhatsApp integration."})}),e.jsxs("div",{className:"whatsapp-hub-modal__options",children:[e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(t),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(D,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:r("config:whatsappHub.config",{defaultValue:"Integration config"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:r("config:whatsappHub.configDesc",{defaultValue:"Server URL, API key, sessions and pairing."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(i),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(D,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:r("config:whatsappHub.notifications",{defaultValue:"Notifications"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:r("config:whatsappHub.notificationsDesc",{defaultValue:"Which agent events get forwarded and to whom."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(d),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(D,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:r("config:whatsappHub.history",{defaultValue:"History"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:r("config:whatsappHub.historyDesc",{defaultValue:"Browse persisted chats and messages."})})]})]})]})]})]})})})}const 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:Ss},{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:ws},{kind:"completion",settingKey:"toneCompletion",label:"Agent finishes working",when:"An agent stops working and goes idle.",sound:"Gentle descending arpeggio",play:Tt}],en=[{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:"🌙"}],sn=[{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:"🔴"}],tn=[{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:"👎"}],an=[{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:"💜"}],nn=[{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"}],on=[{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"}],ln={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},cn={none:"grass","pokemon-stadium":"pokemon"},rn={"emote-yes":"yes","emote-no":"no"},dn={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function ee({checked:s,onChange:n}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:t=>n(t.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function Ce({options:s,value:n,onChange:t,iconOnly:i=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(d=>e.jsxs("button",{className:`chip ${n===d.value?"active":""}`,onClick:()=>t(d.value),title:d.label,children:[e.jsx("span",{className:"chip-icon",children:d.icon}),!i&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function C({text:s,query:n}){if(!n.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),i=n.toLowerCase(),d=t.indexOf(i);if(d===-1)return e.jsx(e.Fragment,{children:s});const r=s.slice(0,d),c=s.slice(d,d+n.length),m=s.slice(d+n.length);return e.jsxs(e.Fragment,{children:[r,e.jsx("mark",{className:"search-highlight",children:c}),m]})}const 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 un({config:s,onChange:n,searchQuery:t="",onOpenIntegrationsModal:i,onOpenPluginsModal:d,onOpenMonitoringModal:r,onOpenStatisticsModal:c,onOpenWorkflowEditor:m,onOpenTriggerManager:h}){var ls;const{t:o}=Z(["config","common"]),u=gt(),A=ft(),[g,T]=l.useState(()=>xt(Pe.DEFAULT_AGENT_CLASS)||"scout"),x=bt(),I=jt(),[v,p]=l.useState(()=>vt()),[b,R]=l.useState(null),[M,G]=l.useState(null),[q,Y]=l.useState("");l.useEffect(()=>{qe().then(p)},[]);const U=async(a,E)=>{G(null),R(a);try{const K=await fe(xe(`/api/custom-sounds/${a}`),{method:"POST",headers:{"Content-Type":E.type||"audio/mpeg"},body:E});if(!K.ok){const de=await K.json().catch(()=>({error:`Upload failed (${K.status})`}));throw new Error(de.error||`Upload failed (${K.status})`)}const oe=await qe();p({...oe});const ge=Je.find(de=>de.kind===a);ge&&j.updateSettings({[ge.settingKey]:_e}),We(_e,u.notificationSoundVolume,a)}catch(K){G(K instanceof Error?K.message:"Upload failed")}finally{R(null)}},X=async a=>{G(null);try{await fe(xe(`/api/custom-sounds/${a}`),{method:"DELETE"}),Dt({[a]:null});const E=await qe();p({...E});const K=Je.find(oe=>oe.kind===a);K&&j.getSettings()[K.settingKey]===_e&&j.updateSettings({[K.settingKey]:$t[a]})}catch(E){G(E instanceof Error?E.message:"Failed to reset sound")}},[S,B]=l.useState(u.historyLimit),[y,O]=l.useState(()=>Nt()),[ne,N]=l.useState(!1),[$,z]=l.useState(""),[w,L]=l.useState(()=>Q()),[F,ae]=l.useState(!1),[te,P]=l.useState(!1),[k,se]=l.useState(""),[ie,ce]=l.useState(!1),[le,he]=l.useState(!1),[Ae,Se]=l.useState(!1),[pe,Te]=l.useState(!1),[je,me]=l.useState(!1),[De,$e]=l.useState(""),[ve,Le]=l.useState(!1);l.useEffect(()=>{na().then($e).catch(()=>{})},[]),l.useEffect(()=>{ta().then(a=>{a!==u.experimentalEchoPrompt&&j.updateSettings({experimentalEchoPrompt:a})}).catch(()=>{})},[]),l.useEffect(()=>{ia().then(a=>{a!==u.tmuxMode&&j.updateSettings({tmuxMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{ca().then(a=>{a!==u.interactiveMode&&j.updateSettings({interactiveMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{da().then(a=>{a!==u.codexAppServerMode&&j.updateSettings({codexAppServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{pa().then(a=>{a!==u.opencodeServerMode&&j.updateSettings({opencodeServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{ma().then(a=>{a!==u.piRpcMode&&j.updateSettings({piRpcMode:a})}).catch(()=>{})},[]),l.useEffect(()=>yt(a=>{O(a),N(!1)}),[]);const Ke=en.map(a=>({...a,label:o(`config:time.${a.value}`)})),He=sn.map(a=>({...a,label:o(`config:floor.${cn[a.value]||a.value}`)})),Oe=tn.map(a=>({...a,label:o(`config:animation.${rn[a.value]||a.value}`)})),Fe=an.map(a=>({...a,label:o(`config:colorMode.${a.value}`)})),Re=nn.map(a=>({...a,label:o(`config:terrain.${ln[a.key]}`)})),Be=on.map(a=>({...a,label:o(`config:sky.${dn[a.value??""]}`)})),ke=t.trim()?Kt(t).map(a=>a.id):null,_=a=>ke?ke.includes(a):!0,ue=u.customAgentNames||[],f=ue.length>0?ue:wt,V=()=>{const a=k.trim();a&&!ue.includes(a)&&(j.updateSettings({customAgentNames:[...ue,a]}),se(""))},re=a=>{j.updateSettings({customAgentNames:ue.filter(E=>E!==a)})},Ne=()=>{j.updateSettings({customAgentNames:[]})},Me=u.fileSearchExcludeDirs??[...rs],ss=()=>{const a=q.trim();if(ps(a)){if(Me.includes(a)){Y("");return}j.updateSettings({fileSearchExcludeDirs:[...Me,a]}),Y("")}},_s=a=>{j.updateSettings({fileSearchExcludeDirs:Me.filter(E=>E!==a)})},Is=()=>{j.updateSettings({fileSearchExcludeDirs:[...rs]})},ts=()=>{const a=$.trim();if(a){if(y.includes(a)){z("");return}O([...y,a]),N(!0),z("")}},Ds=a=>{O(y.filter((E,K)=>K!==a)),N(!0)},as=(a,E)=>{const K=a+E;if(K<0||K>=y.length)return;const oe=y.slice();[oe[a],oe[K]]=[oe[K],oe[a]],O(oe),N(!0)},$s=()=>{Lt(y),N(!1),Ye()},Ls=a=>{L(a),ae(!0)},ns=()=>{Ue(Pe.AUTH_TOKEN,w),ae(!1),Ye()},Os=a=>{$e(a),Le(!0)},os=()=>{oa(De).catch(()=>{}),Le(!1)},ye=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=>{B(a),j.updateSettings({historyLimit:a})},Rs=a=>{const E=s.terrain[a];typeof E=="boolean"&&ye({[a]:!E})},J=t.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[ke&&ke.length===0&&e.jsx("div",{className:"config-no-results",children:o("config:noResults",{query:t})}),_("plugins")&&e.jsx(H,{title:"Plugins",storageKey:"plugins",defaultOpen:!0,forceOpen:J&&_("plugins"),children:e.jsxs("div",{className:"config-row config-row--plugins",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Install, enable, and disable trusted local UI plugins",query:t})}),e.jsx("button",{className:"config-button",onClick:()=>d==null?void 0:d(),children:"Manage Plugins"})]})}),_("general")&&e.jsxs(H,{title:o("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:J&&_("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:S,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(C,{text:o("config:general.hideCosts"),query:t})}),e.jsx(ee,{checked:u.hideCost,onChange:a=>j.updateSettings({hideCost:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.streamTextLiveTitle"),children:e.jsx(C,{text:o("config:general.streamTextLive"),query:t})}),e.jsx(ee,{checked:u.streamTextLive!==!1,onChange:a=>j.updateSettings({streamTextLive:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.toolHoverPreviewTitle"),children:e.jsx(C,{text:o("config:general.toolHoverPreview"),query:t})}),e.jsx(ee,{checked:u.toolHoverPreview===!0,onChange:a=>j.updateSettings({toolHoverPreview:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Where the strip of recently-active and currently-working agent thumbnails sits.",children:e.jsx(C,{text:"Agent activity dock",query:t})}),e.jsx("select",{className:"config-select",value:x,onChange:a=>Ct(a.target.value),children:St.map(a=>e.jsx("option",{value:a,children:kt[a]},a))})]}),x!=="hidden"&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"How many recently-active agents the dock shows alongside the ones working right now. 0 shows only working agents.",children:e.jsx(C,{text:"Recent agents in dock",query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:I,min:0,max:20,step:1,onChange:a=>At(parseInt(a.target.value,10)||0)})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.grid"),query:t})}),e.jsx(ee,{checked:s.gridVisible,onChange:a=>n({...s,gridVisible:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.showFPS"),query:t})}),e.jsx(ee,{checked:u.showFPS,onChange:a=>j.updateSettings({showFPS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.fpsLimit"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:a=>n({...s,fpsLimit:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.fpsLimit===0?"∞":s.fpsLimit})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: Reduce FPS when idle to save power",children:[e.jsx(C,{text:o("config:general.powerSaving"),query:t})," ",e.jsx(D,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.powerSaving,onChange:a=>j.updateSettings({powerSaving:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Battery saver for mobile: caps scene FPS (20 active / 5 idle), freezes decorative animations and disables word-by-word streaming. Off = normal mode.",children:[e.jsx(C,{text:o("config:general.lowPowerMode"),query:t})," ",e.jsx(D,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.lowPowerMode===!0,onChange:a=>j.updateSettings({lowPowerMode:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Wrap agent processes in tmux sessions so they survive server restarts (requires tmux installed)",children:e.jsx(C,{text:o("config:general.tmuxMode"),query:t})}),e.jsx(ee,{checked:u.tmuxMode,onChange:async a=>{j.updateSettings({tmuxMode:a});try{await la(a)}catch(E){console.error("Failed to sync tmux mode setting to server:",E)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Claude agents as the real interactive `claude` TUI inside tmux, reconstructing the conversation from the session transcript (requires tmux). Takes effect on server restart.",children:[e.jsx(C,{text:o("config:general.interactiveMode"),query:t})," ",e.jsx(D,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.interactiveMode,onChange:async a=>{j.updateSettings({interactiveMode:a});try{await ra(a)}catch(E){console.error("Failed to sync interactive mode setting to server:",E)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Codex agents through a persistent `codex app-server` so replies stream word-by-word (token deltas) instead of appearing as one block. The app-server runs detached and survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new Codex turns; no server restart needed to toggle.",children:[e.jsx(C,{text:o("config:general.codexAppServerMode"),query:t})," ",e.jsx(D,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.codexAppServerMode,onChange:async a=>{j.updateSettings({codexAppServerMode:a});try{await ua(a)}catch(E){console.error("Failed to sync codex app-server mode setting to server:",E)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run OpenCode agents through a persistent, detached `opencode serve` HTTP server so replies stream word-by-word (token deltas over SSE) instead of appearing as one block. The server survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new OpenCode turns; no server restart needed to toggle.",children:[e.jsx(C,{text:o("config:general.opencodeServerMode"),query:t})," ",e.jsx(D,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.opencodeServerMode,onChange:async a=>{j.updateSettings({opencodeServerMode:a});try{await ha(a)}catch(E){console.error("Failed to sync opencode server mode setting to server:",E)}}})]}),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(C,{text:o("config:general.piRpcMode"),query:t})," ",e.jsx(D,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.piRpcMode,onChange:async a=>{j.updateSettings({piRpcMode:a});try{await ga(a)}catch(E){console.error("Failed to sync pi RPC mode setting to server:",E)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.vibrationIntensity"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:u.vibrationIntensity,onChange:a=>j.updateSettings({vibrationIntensity:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:u.vibrationIntensity===0?o("config:vibrationValues.off"):u.vibrationIntensity===1?o("config:vibrationValues.ultraLight"):u.vibrationIntensity===2?o("config:vibrationValues.veryLight"):u.vibrationIntensity===3?o("config:vibrationValues.light"):u.vibrationIntensity===4?o("config:vibrationValues.medium"):o("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Play pleasant sounds: a chime for agent notifications, a distinctive rising cue when an agent asks you a question (repeats until answered), and a resolving cue when an agent finishes its work.",children:e.jsx(C,{text:"Notification sounds",query:t})}),e.jsx(ee,{checked:u.notificationSoundEnabled,onChange:a=>{j.updateSettings({notificationSoundEnabled:a}),a&&ws(u.notificationSoundVolume,u.toneNotification)}})]}),u.notificationSoundEnabled&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Notification sound volume",query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:ds,step:"1",value:u.notificationSoundVolume,onChange:a=>{const E=parseInt(a.target.value);j.updateSettings({notificationSoundVolume:E}),Ss(E,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(C,{text:"Sounds per event",query:t})}),e.jsx("div",{className:"config-sound-hint",children:'Pick a tone for each event — or upload your own file (mp3, wav, ogg, m4a — max 5MB), which is stored on the commander so every device hears it. "None" silences that event.'}),Je.map(a=>{var ge;const E=!!v[a.kind],K=u[a.settingKey],oe=E&&K===_e;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${oe?" custom":""}`,children:oe?"Your file":((ge=Et(K))==null?void 0:ge.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:K,onChange:de=>{const Ee=de.target.value;j.updateSettings({[a.settingKey]:Ee}),We(Ee,u.notificationSoundVolume,a.kind)},children:[E&&e.jsx("option",{value:_e,children:"Your uploaded file"}),Pt.map(de=>e.jsx("option",{value:de.id,children:de.label},de.id))]}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void We(K,u.notificationSoundVolume,a.kind),disabled:us(K),title:us(K)?"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:[b===a.kind?"Uploading…":"Upload",e.jsx("input",{type:"file",accept:"audio/*",style:{display:"none"},onChange:de=>{var cs;const Ee=(cs=de.target.files)==null?void 0:cs[0];de.target.value="",Ee&&U(a.kind,Ee)}})]}),E&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void X(a.kind),title:"Delete your file and go back to a built-in tone",children:"Reset"})]})]},a.kind)}),M&&e.jsx("div",{className:"config-sound-error",children:M})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.externalEditor"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.externalEditorPlaceholder"),value:u.externalEditorCommand||"",onChange:a=>j.updateSettings({externalEditorCommand:a.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.tabTitle"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.tabTitlePlaceholder"),value:u.tabTitle||"",onChange:a=>j.updateSettings({tabTitle:a.target.value})})]}),e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{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:q,onChange:a=>Y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&ss()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ss,disabled:!ps(q),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(C,{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 E;if(a==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const K=navigator.language,oe=((E=Xe.find(ge=>ge.value!=="auto"&&K.startsWith(ge.value.split("-")[0])))==null?void 0:E.value)||"en";Ge.changeLanguage(oe)}else localStorage.setItem("tide-commander-language-mode","manual"),Ge.changeLanguage(a)}})]})]}),_("agentNames")&&e.jsx(H,{title:o("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:J&&_("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:ue.length>0?o("config:agentNames.customConfigured",{count:ue.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:k,onChange:a=>se(a.target.value),onKeyDown:a=>{a.key==="Enter"&&V()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:V,disabled:!k.trim(),title:o("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:f.map((a,E)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:a}),ue.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>re(a),title:o("common:buttons.remove"),children:"x"})]},`${a}-${E}`))}),ue.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:Ne,children:o("common:buttons.resetToDefaults")})]})}),_("defaultClass")&&e.jsx(H,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:J&&_("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${g==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{T("random"),Ue(Pe.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(_t).map(([a,E])=>e.jsx("div",{className:`agent-name-chip${g===a?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{T(a),Ue(Pe.DEFAULT_AGENT_CLASS,a)},children:e.jsxs("span",{className:"agent-name-text",children:[E.icon," ",a.charAt(0).toUpperCase()+a.slice(1)]})},a)),A.map(a=>e.jsx("div",{className:`agent-name-chip${g===a.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{T(a.id),Ue(Pe.DEFAULT_AGENT_CLASS,a.id)},children:e.jsxs("span",{className:"agent-name-text",children:[a.icon," ",a.name]})},a.id))]})]})}),_("appearance")&&e.jsx(H,{title:o("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:J&&_("appearance"),children:e.jsx(va,{})}),_("connection")&&e.jsxs(H,{title:o("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:J&&_("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:y.map((a,E)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:o("config:connection.priorityLabel",{defaultValue:"Priority"}),children:E+1}),e.jsx("span",{className:"backend-url-text",title:a,children:a}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>as(E,-1),disabled:E===0,title:o("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>as(E,1),disabled:E===y.length-1,title:o("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ds(E),title:o("common:buttons.remove"),children:"x"})]},`${a}-${E}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:$,onChange:a=>z(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:!$.trim(),title:o("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),ne&&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(C,{text:o("config:connection.authToken"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:te?"text":"password",className:"config-input config-input-full",value:w,onChange:a=>Ls(a.target.value),placeholder:o("config:connection.tokenPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&F&&ns()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>P(!te),title:o(te?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(D,{name:te?"eye-closed":"eye",size:14})}),F&&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(C,{text:o("config:connection.codexBinaryPath"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:De,onChange:a=>Os(a.target.value),placeholder:o("config:connection.codexBinaryPathPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&ve&&os()}}),ve&&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(C,{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")})]})]}),_("scene")&&e.jsxs(H,{title:o("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:J&&_("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.characterSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"3.0",step:"0.1",value:s.characterScale,onChange:a=>n({...s,characterScale:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.characterScale.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.scale2d",{defaultValue:"2D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale2d,onChange:a=>n({...s,scale2d:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale2d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.scale3d",{defaultValue:"3D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale3d,onChange:a=>n({...s,scale3d:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale3d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:t})}),e.jsx(ee,{checked:s.show2DTaskLabels,onChange:a=>n({...s,show2DTaskLabels:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.time"),query:t})}),e.jsx(Ce,{options:Ke,value:s.timeMode,onChange:a=>n({...s,timeMode:a}),iconOnly:!0})]})]}),_("terrain")&&e.jsxs(H,{title:o("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:J&&_("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:t})}),e.jsx(ee,{checked:s.terrain.simpleMode??!1,onChange:a=>ye({simpleMode:a})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:Re.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(C,{text:o("config:terrainSettings.fog"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.terrain.fogDensity,onChange:a=>ye({fogDensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?o("config:fogValues.off"):s.terrain.fogDensity<=1?o("config:fogValues.low"):o("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.brightness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.2",max:"2",step:"0.1",value:s.terrain.brightness,onChange:a=>ye({brightness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?o("config:brightnessValues.dark"):s.terrain.brightness<=1.2?o("config:brightnessValues.normal"):o("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.floor"),query:t})}),e.jsx(Ce,{options:He,value:s.terrain.floorStyle,onChange:a=>ye({floorStyle:a}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.sky"),query:t})}),e.jsx("div",{className:"sky-color-selector",children:Be.map(a=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===a.value?"active":""}`,onClick:()=>ye({skyColor:a.value}),title:a.label,style:{background:a.color}},a.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.battlefieldSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:a=>ye({battlefieldSize:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),_("modelStyle")&&e.jsxs(H,{title:o("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:J&&_("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.saturation"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.modelStyle.saturation,onChange:a=>we({saturation:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?o("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?o("config:saturationValues.normal"):o("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.roughness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.roughness,onChange:a=>we({roughness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?o("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?o("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?o("config:roughnessValues.normal"):o("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.metalness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.metalness,onChange:a=>we({metalness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?o("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?o("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?o("config:metalnessValues.mixed"):o("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.glow"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"1",step:"0.05",value:s.modelStyle.emissiveBoost,onChange:a=>we({emissiveBoost:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?o("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?o("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?o("config:glowValues.med"):o("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.reflections"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"2",step:"0.1",value:s.modelStyle.envMapIntensity,onChange:a=>we({envMapIntensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?o("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?o("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?o("config:reflectionValues.normal"):o("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.wireframe"),query:t})}),e.jsx(ee,{checked:s.modelStyle.wireframe,onChange:a=>we({wireframe:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.colorMode"),query:t})}),e.jsx(Ce,{options:Fe,value:s.modelStyle.colorMode,onChange:a=>we({colorMode:a}),iconOnly:!0})]})]}),_("animations")&&e.jsxs(H,{title:o("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:J&&_("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:animationSettings.idle"),query:t})}),e.jsx(Ce,{options:Oe,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(C,{text:o("config:animationSettings.working"),query:t})}),e.jsx(Ce,{options:Oe,value:s.animations.workingAnimation,onChange:a=>is({workingAnimation:a}),iconOnly:!0})]})]}),_("secrets")&&e.jsx(H,{title:o("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:J&&_("secrets"),children:e.jsx(Zt,{})}),_("claudeAccounts")&&e.jsx(H,{title:o("config:sections.claudeAccounts",{defaultValue:"Claude Accounts"}),storageKey:"claudeAccounts",defaultOpen:!1,forceOpen:J&&_("claudeAccounts"),children:e.jsx(It,{})}),_("grokAccounts")&&e.jsx(H,{title:o("config:sections.grokAccounts",{defaultValue:"Grok Accounts"}),storageKey:"grokAccounts",defaultOpen:!1,forceOpen:J&&_("grokAccounts"),children:e.jsx(hs,{provider:"grok"})}),_("codexAccounts")&&e.jsx(H,{title:o("config:sections.codexAccounts",{defaultValue:"Codex Accounts"}),storageKey:"codexAccounts",defaultOpen:!1,forceOpen:J&&_("codexAccounts"),children:e.jsx(hs,{provider:"codex"})}),_("systemPrompt")&&e.jsx(H,{title:o("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:J&&_("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>ce(!0),children:o("config:systemPrompt.editPrompt")})]})}),_("data")&&e.jsx(H,{title:o("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:J&&_("data"),children:e.jsx(ja,{})}),_("integrations")&&e.jsx(H,{title:o("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:J&&_("integrations"),children:e.jsx(Ta,{onOpenModal:a=>{a==="whatsapp"?me(!0):i==null||i(a)}})}),_("workflows")&&e.jsxs(H,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:J&&_("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Create and manage automated workflow pipelines with visual state machine editor",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>m==null?void 0:m(),children:"Open Workflow Editor"})})]}),_("triggers")&&e.jsxs(H,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:J&&_("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Create and manage event-driven triggers that fire agents with templates",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>h==null?void 0:h(),children:"Open Trigger Manager"})})]}),_("monitoring")&&e.jsxs(H,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:J&&_("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"View event logs, trigger history, workflow traces, and system stats",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>r==null?void 0:r(),children:"Open Monitoring & Logs"})})]}),_("statistics")&&e.jsxs(H,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:J&&_("statistics"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"View token usage charts and system-wide agent statistics",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>c==null?void 0:c(),children:"Open Statistics"})})]}),_("experimental")&&e.jsxs(H,{title:o("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:J&&_("experimental"),children:[e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Lightweight 2D top-down view for better performance",children:[e.jsx(C,{text:o("config:experimental.2dView"),query:t})," ",e.jsx(D,{name:"map",size:12})]}),e.jsx(ee,{checked:u.experimental2DView,onChange:a=>j.updateSettings({experimental2DView:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(C,{text:o("config:experimental.voiceAssistant"),query:t})," ",e.jsx(D,{name:"microphone",size:12})]}),e.jsx(ee,{checked:u.experimentalVoiceAssistant,onChange:a=>j.updateSettings({experimentalVoiceAssistant:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(C,{text:o("config:experimental.tts"),query:t})," ",e.jsx(D,{name:"speaker-on",size:12})]}),e.jsx(ee,{checked:u.experimentalTTS,onChange:a=>j.updateSettings({experimentalTTS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Duplicate system prompt for improved LLM attention coverage. Increases input token usage.",children:e.jsx(C,{text:o("config:experimental.echoPrompt"),query:t})}),e.jsx(ee,{checked:u.experimentalEchoPrompt,onChange:async a=>{j.updateSettings({experimentalEchoPrompt:a});try{await aa(a)}catch(E){console.error("Failed to sync echo prompt setting to server:",E)}}})]}),e.jsx("span",{className:"config-hint",children:o("config:experimental.hint")})]}),_("about")&&e.jsx(H,{title:o("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:J&&_("about"),children:e.jsx(Ca,{})})]}),e.jsx(Ea,{isOpen:ie,onClose:()=>ce(!1)}),e.jsx(Da,{isOpen:le,onClose:()=>he(!1)}),e.jsx(Ra,{isOpen:Ae,onClose:()=>Se(!1)}),e.jsx(Za,{isOpen:pe,onClose:()=>Te(!1)}),e.jsx(Qa,{isOpen:je,onClose:()=>me(!1),onOpenConfig:()=>he(!0),onOpenNotifications:()=>Se(!0),onOpenHistory:()=>Te(!0)})]})}function xn({onConfigChange:s,onToolChange:n,config:t,isOpen:i,onClose:d,initialSearchQuery:r,onOpenBuildingModal:c,onOpenAreaExplorer:m,onOpenIntegrationsModal:h,onOpenPluginsModal:o,onOpenMonitoringModal:u,onOpenStatisticsModal:A,onOpenWorkflowEditor:g,onOpenTriggerManager:T}){const{t:x}=Z(["config","common"]),I=Ot(),v=Ft(),p=Rt(),b=Bt(),R=Mt(),M=Array.from(I.values()),G=Array.from(v.values()),[q,Y]=l.useState(""),U=l.useRef(null);if(l.useEffect(()=>{const y=O=>{O.key==="Escape"&&i&&d()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[i,d]),l.useEffect(()=>{i&&Y(r??"")},[i,r]),l.useEffect(()=>{if(i&&U.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const O=setTimeout(()=>{var ne;(ne=U.current)==null||ne.focus()},50);return()=>clearTimeout(O)}},[i]),!i)return null;const X=y=>{n(R===y?null:y)},S=y=>{j.selectArea(b===y?null:y),n("select")},B=(y,O)=>{y.stopPropagation(),j.deleteArea(O)};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:x("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:x("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:U,type:"text",placeholder:x("config:searchPlaceholder"),value:q,onChange:y=>Y(y.target.value),className:"toolbox-search-input"}),q&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>Y(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(H,{title:x("config:areas.title",{count:M.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${R==="select"?"active":""}`,onClick:()=>X("select"),title:x("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 ${R==="rectangle"?"active":""}`,onClick:()=>X("rectangle"),title:x("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 ${R==="circle"?"active":""}`,onClick:()=>X("circle"),title:x("config:tools.circle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("circle",{cx:"12",cy:"12",r:"9"})})})})]}),e.jsx("div",{className:"areas-list",children:M.length===0?e.jsx("div",{className:"areas-empty",children:x("config:areas.drawToCreate")}):M.map(y=>e.jsx(Wt,{area:y,isSelected:b===y.id,onClick:()=>S(y.id),onDelete:O=>B(O,y.id)},y.id))})]})}),b&&e.jsx(Xt,{area:I.get(b),onClose:()=>j.selectArea(null),onOpenFolder:m}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(H,{title:x("config:buildings.title",{count:G.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:y=>{y.stopPropagation(),c==null||c()},title:x("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:G.length===0?e.jsx("div",{className:"buildings-empty",children:x("config:buildings.clickToAdd")}):G.map(y=>e.jsx(Gt,{building:y,isSelected:p.has(y.id),onClick:()=>{j.selectBuilding(p.has(y.id)?null:y.id)},onEdit:()=>c==null?void 0:c(y.id)},y.id))})})}),p.size===1&&(()=>{const y=Array.from(p)[0],O=v.get(y);return O?e.jsx(Yt,{building:O,onClose:()=>j.selectBuilding(null),onOpenModal:()=>c==null?void 0:c(y)}):null})(),e.jsx(un,{config:t,onChange:s,searchQuery:q,onOpenIntegrationsModal:h,onOpenPluginsModal:o,onOpenMonitoringModal:u,onOpenStatisticsModal:A,onOpenWorkflowEditor:g,onOpenTriggerManager:T})]})]})]})}export{xn as Toolbox};
1
+ import{r as l,j as e,I as D,u as Z,c4 as js,ap as vs,c5 as Bs,c7 as Ms,s as j,d7 as Us,F as zs,d8 as Vs,_ as be,Q,aX as W,c as fe,d as xe,d9 as Ks,da as Hs,db as qs,dc as Ws,dd as Gs,de as Ys,df as Js,dg as Ns,dh as Xs,di as Zs,dj as Qs,aW as et,dk as st,dl as tt,dm as at,dn as nt,aC as ot,a5 as Ie,t as it,dp as ys,dq as lt,dr as Ze,ds as ct,dt as rt,du as dt,dv as ut,dw as pt,dx as ht,dy as mt,bm as gt,k as ft,m as xt,S as Pe,dz as bt,dA as jt,dB as vt,dC as qe,dD as Nt,dE as yt,B as wt,c9 as rs,dF as St,dG as kt,dH as Ct,dI as At,dJ as ws,dK as ds,dL as Ss,dM as Tt,dN as Et,dO as _e,dP as Pt,dQ as We,dR as us,dS as ps,c0 as Ge,z as Ue,y as _t,dT as Ye,dU as It,dV as hs,dW as Dt,dX as $t,dY as Lt,a1 as Ot,f as Ft,dZ as Rt,d_ as Bt,d$ as Mt}from"./main-D0r07JA_.js";import{g as Ut,d as zt,u as Vt}from"./area-logos-JqUib9Ux.js";import{s as Kt}from"./settingsSearch-DYr4vFyy.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-DYBBrXTx.js";const ks="tide-toolbox-collapse";function Ht(s,n){try{const t=localStorage.getItem(`${ks}-${s}`);if(t!==null)return t==="true"}catch{}return n}function qt(s,n){try{localStorage.setItem(`${ks}-${s}`,String(n))}catch{}}function H({title:s,storageKey:n,defaultOpen:t=!1,forceOpen:i=!1,children:d,headerExtra:r}){const[c,m]=l.useState(()=>n?Ht(n,t):t),h=()=>{const u=!c;m(u),n&&qt(n,u)},o=i||c;return e.jsxs("div",{className:`collapsible-section ${o?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:h,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[r,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(D,{name:o?"caret-down":"caret-right",size:10})})]})]}),o&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Wt({area:s,isSelected:n,onClick:t,onDelete:i}){const{t:d}=Z(["config","common"]),r=s.assignedAgentIds.length,c=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:[c," ",r>0&&`• ${r} ${r>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 Gt({building:s,isSelected:n,onClick:t,onEdit:i}){var m;const{t:d}=Z(["config"]),r=((m=s.pm2Status)==null?void 0:m.ports)||[],c=(h,o)=>{h.stopPropagation(),window.open(`http://${window.location.hostname}:${o}`,"_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(D,{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,r.length>0&&e.jsx("span",{className:"building-ports",children:r.map(h=>e.jsxs("a",{href:`http://${window.location.hostname}:${h}`,className:"building-port-link",onClick:o=>c(o,h),title:`Open :${h}`,children:[":",h]},h))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:h=>{h.stopPropagation(),i()},title:d("config:buildings.editBuilding"),children:e.jsx(D,{name:"gear",size:14})})]})}function Yt({building:s,onClose:n,onOpenModal:t}){var o,u,A,g,T,x,I,v;const{t:i}=Z(["config","common"]),r=Bs().get(s.id)||[],c=Ms[s.style||"server-rack"],m=p=>{j.sendBuildingCommand(s.id,p)},h=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(D,{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:c.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children: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:()=>m("start"),disabled:!((o=s.commands)!=null&&o.start)||s.status==="running",title:((u=s.commands)==null?void 0:u.start)||i("config:buildings.noStartCommand"),children:[e.jsx(D,{name:"play",size:12})," ",i("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>m("stop"),disabled:!((A=s.commands)!=null&&A.stop)||s.status==="stopped",title:((g=s.commands)==null?void 0:g.stop)||i("config:buildings.noStopCommand"),children:[e.jsx(D,{name:"stop",size:12,weight:"fill"})," ",i("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>m("restart"),disabled:!((T=s.commands)!=null&&T.restart),title:((x=s.commands)==null?void 0:x.restart)||i("config:buildings.noRestartCommand"),children:[e.jsx(D,{name:"refresh",size:12})," ",i("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>m("healthCheck"),disabled:!((I=s.commands)!=null&&I.healthCheck),title:((v=s.commands)==null?void 0:v.healthCheck)||i("config:buildings.noHealthCheck"),children:[e.jsx(D,{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,b)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>h(p.url),title:p.url,children:[e.jsx(D,{name:"link",size:12})," ",p.label||p.url]},b))})]}),r.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:()=>j.clearBuildingLogs(s.id),title:i("common:buttons.clear"),children:i("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:r.slice(-5).map((p,b)=>e.jsx("div",{className:"building-editor-log-entry",children:p},b))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(D,{name:"gear",size:12})," ",i("config:buildings.fullSettings")]})})]})}const Jt=[{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 Xt({area:s,onClose:n,onOpenFolder:t}){var ne;const{t:i}=Z(["config","common"]),[d,r]=l.useState(s.name),[c,m]=l.useState(s.prompt||""),[h,o]=l.useState(!1),[u,A]=l.useState(""),[g,T]=l.useState(!1),x=l.useRef(null);l.useEffect(()=>{r(s.name)},[s.id,s.name]),l.useEffect(()=>{m(s.prompt||"")},[s.id,s.prompt]);const I=N=>{const $=N.target.value;r($),j.updateArea(s.id,{name:$})},v=N=>{j.updateArea(s.id,{color:N})},p=N=>{const $=N.target.value;m($),j.updateArea(s.id,{prompt:$})},b=()=>{u.trim()&&(j.addDirectoryToArea(s.id,u.trim()),A(""),o(!1))},R=(N,$)=>{$.stopPropagation(),j.removeDirectoryFromArea(s.id,N)},M=()=>{j.bringAreaToFront(s.id)},G=()=>{j.sendAreaToBack(s.id)},q=l.useCallback(()=>{let N=2,$=2;s.type==="rectangle"&&s.width&&s.height?(N=s.width,$=s.height):s.type==="circle"&&s.radius&&(N=s.radius*1.414,$=s.radius*1.414);const z=Math.min(N,$)*.4;return{width:Math.round(z*10)/10,height:Math.round(z*10)/10}},[s.type,s.width,s.height,s.radius]),Y=async N=>{var z;const $=(z=N.target.files)==null?void 0:z[0];if($){T(!0);try{const w=await Vt(s.id,$),L=q();j.updateArea(s.id,{logo:{filename:w.filename,position:"center",width:L.width,height:L.height,keepAspectRatio:!0,opacity:.8}})}catch(w){console.error("Failed to upload logo:",w)}finally{T(!1),x.current&&(x.current.value="")}}},U=async()=>{try{await zt(s.id),j.updateArea(s.id,{logo:void 0})}catch(N){console.error("Failed to remove logo:",N)}},X=N=>{s.logo&&j.updateArea(s.id,{logo:{...s.logo,position:N}})},S=N=>{if(!s.logo)return;const $=parseFloat(N.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const z=s.logo.height/s.logo.width;j.updateArea(s.id,{logo:{...s.logo,width:$,height:Math.round($*z*10)/10}})}else j.updateArea(s.id,{logo:{...s.logo,width:$}})},B=N=>{if(!s.logo)return;const $=parseFloat(N.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const z=s.logo.width/s.logo.height;j.updateArea(s.id,{logo:{...s.logo,height:$,width:Math.round($*z*10)/10}})}else j.updateArea(s.id,{logo:{...s.logo,height:$}})},y=()=>{s.logo&&j.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},O=N=>{s.logo&&j.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(N.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children: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:I,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(N=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===N?"selected":""}`,style:{backgroundColor:N},onClick:()=>v(N),"aria-label":`Set area color ${N}`,"aria-pressed":s.color===N,title:N},N))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:M,title:i("config:areas.bringToFront"),children:[e.jsx(D,{name:"arrow-up",size:12})," ",i("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:G,title:i("config:areas.sendToBack"),children:[e.jsx(D,{name:"arrow-down",size:12})," ",i("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:i("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(ne=s.logo)!=null&&ne.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Ut(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 N;return(N=x.current)==null?void 0:N.click()},disabled:g,children:g?"...":e.jsx(D,{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:Jt.map(({key:N,labelKey:$})=>{var z;return e.jsx("button",{className:`area-logo-pos-btn ${((z=s.logo)==null?void 0:z.position)===N?"active":""}`,onClick:()=>X(N),children:i(`config:areas.${$}`)},N)})})]}),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:S,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:B,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:y}),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:O,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var N;return(N=x.current)==null?void 0:N.click()},disabled:g,children:g?"...":i("config:areas.uploadLogo")}),e.jsx("input",{ref:x,type:"file",accept:"image/*",style:{display:"none"},onChange:Y})]})]}),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(N=>e.jsxs("div",{className:"area-folder-item",title:N,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:i("config:areas.openFolder"),children:e.jsx(D,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:N.split("/").pop()||N}),e.jsx("button",{className:"area-folder-remove",onClick:$=>R(N,$),title:i("config:areas.removeFolder"),children:"×"})]},N)),h?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(zs,{value:u,onChange:A,onSubmit:b,placeholder:i("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:b,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>o(!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:c,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 Zt(){const{t:s}=Z(["config","common"]),n=Vs(),[t,i]=l.useState(!1),[d,r]=l.useState(null),[c,m]=l.useState({name:"",key:"",value:"",description:""}),[h,o]=l.useState(null),u=()=>{i(!0),r(null),m({name:"",key:"",value:"",description:""})},A=p=>{r(p.id),i(!1),m({name:p.name,key:p.key,value:p.value,description:p.description||""})},g=()=>{i(!1),r(null),m({name:"",key:"",value:"",description:""})},T=()=>{!c.name.trim()||!c.key.trim()||(d?j.updateSecret(d,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):j.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),g())},x=p=>{o(p)},I=()=>{h&&(j.deleteSecret(h),d===h&&g())},v=p=>{navigator.clipboard.writeText(`{{${p}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children: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:()=>v(p.key),title:s("config:secrets.copyPlaceholder"),children:`{{${p.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>A(p),title:s("common:buttons.edit"),children:e.jsx(D,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>x(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:c.name,onChange:p=>m({...c,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:c.key,onChange:p=>m({...c,key:p.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${c.key||"KEY"}}}`})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("config:secrets.secretValue")}),e.jsx("input",{type:"password",className:"secret-form-input",placeholder:s("config:secrets.valuePlaceholder"),value:c.value,onChange:p=>m({...c,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:c.description,onChange:p=>m({...c,description:p.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:g,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:T,disabled:!c.name.trim()||!c.key.trim(),children:s(d?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:u,children:s("config:secrets.addSecret")}),e.jsx(be,{isOpen:h!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:I,onClose:()=>o(null)})]})}async function Qt(){const s=Q(),n=await fetch(`${W()}/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 ea(s){const n=Q(),t=await fetch(`${W()}/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 sa(){const s=Q(),n=await fetch(`${W()}/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 ta(){const s=Q(),n=await fetch(`${W()}/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 aa(s){const n=Q(),t=await fetch(`${W()}/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 na(){const s=Q(),n=await fetch(`${W()}/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 oa(s){const n=Q(),t=await fetch(`${W()}/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 ia(){const s=Q(),n=await fetch(`${W()}/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 la(s){const n=Q(),t=await fetch(`${W()}/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 ca(){const s=Q(),n=await fetch(`${W()}/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 ra(s){const n=Q(),t=await fetch(`${W()}/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 da(){const s=Q(),n=await fetch(`${W()}/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 ua(s){const n=Q(),t=await fetch(`${W()}/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 pa(){const s=Q(),n=await fetch(`${W()}/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 ha(s){const n=Q(),t=await fetch(`${W()}/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 ma(){const s=Q(),n=await fetch(`${W()}/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 ga(s){const n=Q(),t=await fetch(`${W()}/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 fa(){const s=Q(),n=await fetch(`${W()}/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 xa(s){const n=Q(),t=await fetch(`${W()}/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 ba({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 ja(){const{t:s}=Z(["config","common"]),[n,t]=l.useState([]),[i,d]=l.useState(new Set),[r,c]=l.useState(new Set),[m,h]=l.useState(!1),[o,u]=l.useState(!1),[A,g]=l.useState(null),[T,x]=l.useState(null),[I,v]=l.useState(null),[p,b]=l.useState(null),[R,M]=l.useState(!1),[G,q]=l.useState(null);l.useEffect(()=>{fe(xe("/api/config/categories")).then(w=>w.json()).then(w=>{const L=Array.isArray(w)?w:[];t(L),d(new Set(L.map(F=>F.id)))}).catch(w=>console.error("Failed to fetch config categories:",w))},[]),l.useEffect(()=>{fa().then(b).catch(w=>{console.error("Failed to fetch backup status:",w),q(w.message||"Failed to fetch backup status")})},[]);const Y=async w=>{if(!R){M(!0),q(null);try{const L=await xa(w);b(L)}catch(L){q(L.message||"Failed to update backup setting")}finally{M(!1)}}},U=w=>{d(L=>{const F=new Set(L);return F.has(w)?F.delete(w):F.add(w),F})},X=w=>{c(L=>{const F=new Set(L);return F.has(w)?F.delete(w):F.add(w),F})},S=()=>d(new Set(n.map(w=>w.id))),B=()=>d(new Set),y=()=>{T&&c(new Set(T.categories.map(w=>w.id)))},O=()=>c(new Set),ne=async()=>{var w;if(i.size!==0){h(!0),v(null);try{const L=Array.from(i).join(","),F=await fe(xe(`/api/config/export?categories=${L}`));if(!F.ok)throw new Error("Export failed");const ae=await F.blob(),te=window.URL.createObjectURL(ae),P=document.createElement("a");P.href=te;const k=F.headers.get("Content-Disposition"),se=((w=k==null?void 0:k.match(/filename="(.+)"/))==null?void 0:w[1])||"tide-commander-config.zip";P.download=se,document.body.appendChild(P),P.click(),document.body.removeChild(P),window.URL.revokeObjectURL(te),v({type:"success",text:s("config:data.exportSuccess")})}catch(L){v({type:"error",text:L.message||"Export failed"})}finally{h(!1)}}},N=async w=>{var F;const L=(F=w.target.files)==null?void 0:F[0];if(L){g(L),v(null),x(null),c(new Set);try{const ae=await fe(xe("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await L.arrayBuffer()});if(!ae.ok){const k=await ae.json();throw new Error(k.error||"Failed to preview config file")}const te=await ae.json(),P=Array.isArray(te.categories)?te.categories:[];x({...te,categories:P}),c(new Set(P.map(k=>k.id)))}catch(ae){v({type:"error",text:ae.message||"Failed to read config file"}),g(null)}}},$=async()=>{if(!(!A||r.size===0)){u(!0),v(null);try{const w=Array.from(r).join(","),L=await fe(xe(`/api/config/import?categories=${w}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await A.arrayBuffer()}),F=await L.json();if(!L.ok)throw new Error(F.error||"Import failed");v({type:"success",text:F.message||s("config:data.importSuccess")}),g(null),x(null),c(new Set)}catch(w){v({type:"error",text:w.message||"Import failed"})}finally{u(!1)}}},z=()=>{g(null),x(null),c(new Set),v(null)};return e.jsxs("div",{className:"data-section",children:[I&&e.jsx("div",{className:`data-message data-message-${I.type}`,children:I.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(ba,{checked:!!(p!=null&&p.enabled),disabled:R||!p,onChange:Y})]}),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…"}),G&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:G})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:S,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:B,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:ne,disabled:m||i.size===0,children:m?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")})}),A?T?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:A.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(T.exportedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-subtitle",children:s("config:data.selectToImport")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:y,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:O,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:T.categories.map(w=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:r.has(w.id),onChange:()=>X(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:$,disabled:o||r.size===0,children:o?s("config:data.importing"):s("config:data.importCount",{count:r.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:N,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function va(){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 Na(){const{t:s}=Z(["config"]),{installInfo:n,phase:t,output:i,error:d,newVersion:r,autoRestart:c,refreshInstallInfo:m,runUpdate:h,reset:o}=Js(),[u,A]=l.useState(!1),g=l.useRef(null);l.useEffect(()=>{m()},[m]),l.useEffect(()=>{g.current&&(g.current.scrollTop=g.current.scrollHeight)},[i]);const T=l.useCallback(()=>{A(!0)},[]),x=l.useCallback(()=>{A(!1)},[]),I=l.useCallback(()=>{A(!1),h()},[h]),v=l.useCallback(()=>{o(),A(!1),m()},[o,m]),p=Ns.isNativePlatform(),b=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:b}),t==="idle"&&!u&&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:T,children:s("config:about.autoUpdateButton")})]}),t==="idle"&&u&&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:x,children:s("config:about.autoUpdateCancel")}),e.jsx("button",{className:"about-update-btn download",onClick:I,children:s("config:about.autoUpdateConfirm")})]})]}),(t==="running"||t==="success"||t==="failed")&&e.jsxs("div",{className:"about-autoupdate-stream",children:[e.jsxs("div",{className:"about-autoupdate-stream-title",children:[t==="running"&&s("config:about.autoUpdateRunning"),t==="success"&&s("config:about.autoUpdateSuccess"),t==="failed"&&s("config:about.autoUpdateFailed")]}),e.jsx("pre",{ref:g,className:"about-autoupdate-output",children:i||"..."}),t==="success"&&e.jsxs("div",{className:"about-autoupdate-success-hint",children:[r&&e.jsxs("div",{className:"about-autoupdate-newversion",children:["v",r]}),e.jsx("div",{children:s(c?"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:v,children:s("config:about.autoUpdateClose")})})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:b}),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:b}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdateDevMode")})]}):null}function ya(){const{t:s}=Z(["config"]),[n,t]=l.useState(null),[i,d]=l.useState(!1),[r,c]=l.useState(null);l.useEffect(()=>{Xs().then(t).catch(u=>c(u.message))},[]);const m=l.useCallback(async u=>{if(!i){d(!0),c(null);try{t(await Zs(u))}catch(A){c(A.message)}finally{d(!1)}}},[i]),h=Ns.isNativePlatform(),o=s(h?"config:about.unattendedServerTitle":"config:about.unattendedTitle");return!n&&!r?null:n?h&&!n.supported?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:o}),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:u=>void m(u.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}),r&&e.jsx("div",{className:"about-update-error",children:r})]}):h?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:o}),e.jsx("div",{className:"about-update-error",children:r})]})}function wa(){var R;const{t:s}=Z(["config"]),{isAndroid:n,supported:t,otaActive:i,bundleState:d,serverInfo:r,infoError:c,updateAvailable:m,phase:h,progress:o,error:u,autoSync:A,checkNow:g,syncNow:T,resetToBundled:x,setAutoSync:I}=Qs(),[v,p]=l.useState(null),b=l.useRef(g);return b.current=g,l.useEffect(()=>{n&&(b.current(!1),et.getInfo().then(M=>p(M.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:((R=d==null?void 0:d.hash)==null?void 0:R.slice(0,8))??"?"}):s("config:webBundle.sourceBundled"),v&&` · ${s("config:webBundle.apkVersion",{version:v})}`]}),r?e.jsxs("div",{className:"about-autoupdate-devnote",children:[s("config:webBundle.serverBundle",{version:r.version,hash:r.hash.slice(0,8)})," — ",s(m?"config:webBundle.updateAvailable":"config:webBundle.upToDate")]}):c&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:webBundle.serverUnavailable")}),u&&e.jsx("div",{className:"about-update-error",children:u}),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:A,onChange:M=>I(M.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn download",onClick:()=>void T(),disabled:h!=="idle"||!r,children:h==="syncing"?s("config:webBundle.syncingPct",{percent:o??0}):s("config:webBundle.syncNow")}),i&&e.jsx("button",{className:"about-update-btn changelog",onClick:()=>void x(),children:s("config:webBundle.reset")})]})]})}function Sa(){const{t:s}=Z(["config"]),[n,t]=l.useState(null),[i,d]=l.useState(!1),[r,c]=l.useState(null);l.useEffect(()=>{at().then(t).catch(()=>t(null))},[]);const m=l.useCallback(async h=>{if(!i){d(!0),c(null);try{await nt(h),t(h)}catch(o){c(o.message)}finally{d(!1)}}},[i]);return n===null?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:about.backgroundServiceTitle")}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:about.backgroundServiceDesc")}),e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:n,disabled:i,onChange:h=>void m(h.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),!n&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.backgroundServiceDisabledNote")}),r&&e.jsx("div",{className:"about-update-error",children:r})]})}function ka(){var p;const{t:s}=Z(["config"]),[n,t]=l.useState(null),[i,d]=l.useState(""),[r,c]=l.useState(!1),[m,h]=l.useState(!1),[o,u]=l.useState(null),[A,g]=l.useState(null),T=l.useCallback(()=>{st().then(t)},[]);l.useEffect(T,[T]);const x=l.useCallback(async()=>{if(!(m||!i.trim())){h(!0),u(null),g(null);try{const b=await fe(xe("/api/push/service-account"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({json:i})}),R=await b.json();if(!b.ok)throw new Error(R.error||"Invalid service account");d(""),c(!1),g(s("config:about.pushSaved",{project:R.projectId})),T()}catch(b){u(b.message)}finally{h(!1)}}},[m,i,T,s]),I=l.useCallback(async()=>{h(!0),u(null),g(null);const b=await tt();if(h(!1),!b){u(s("config:about.pushTestFailed"));return}g(s("config:about.pushTestSent",{count:b.sent})),T()},[T,s]);if(!n)return null;const v=((p=n.devices)==null?void 0:p.length)??0;return e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:about.pushTitle")}),e.jsx("div",{className:"about-autoupdate-row",children:e.jsx("span",{className:"about-autoupdate-devnote",children:n.configured?s("config:about.pushConfigured",{project:n.projectId,count:v}):s("config:about.pushNotConfigured")})}),r?e.jsxs(e.Fragment,{children:[e.jsx("textarea",{className:"about-push-credentials",value:i,onChange:b=>d(b.target.value),placeholder:s("config:about.pushCredentialsPlaceholder"),rows:4,spellCheck:!1}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn download",onClick:()=>void x(),disabled:m||!i.trim(),children:s("config:about.pushSaveCredentials")}),e.jsx("button",{className:"about-update-btn changelog",onClick:()=>c(!1),children:s("config:about.pushCancel")})]})]}):e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:()=>c(!0),children:n.configured?s("config:about.pushReplaceCredentials"):s("config:about.pushAddCredentials")}),n.configured&&v>0&&e.jsx("button",{className:"about-update-btn download",onClick:()=>void I(),disabled:m,children:s("config:about.pushTest")})]}),A&&e.jsx("div",{className:"about-autoupdate-devnote",children:A}),o&&e.jsx("div",{className:"about-update-error",children:o}),n.configured&&n.lastError&&!o&&e.jsx("div",{className:"about-update-error",children:n.lastError})]})}function Ca(){const{t:s}=Z(["config"]),{updateAvailable:n,updateInfo:t,recentReleases:i,isChecking:d,error:r,currentVersion:c,isAndroid:m,downloadPhase:h,downloadProgress:o,checkForUpdate:u,downloadAndInstall:A,openReleasePage:g}=qs(),[T,x]=l.useState(!1),I=p=>p?`${(p/(1024*1024)).toFixed(1)} MB`:"",v=p=>new Date(p).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:e.jsx(D,{name:"waves",size:24})}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:c}),n&&t?e.jsx("span",{className:"about-version-update-badge",onClick:g,title:`Update available: ${t.version}`,children:t.version}):e.jsxs("a",{href:"https://github.com/deivid11/tide-commander/releases",target:"_blank",rel:"noopener noreferrer",className:"about-version-status",children:["(",s("config:about.updated"),")"]})]})]}),e.jsx(Na,{}),e.jsx(ya,{}),e.jsx(wa,{}),e.jsx(ka,{}),e.jsx(Sa,{}),e.jsx("div",{className:"about-changelog-row",children:e.jsx("button",{className:"about-update-btn changelog",onClick:()=>x(!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"),": ",I(t.apkSize)]}),r&&e.jsx("div",{className:"about-update-error",children:r}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:g,children:s("config:about.changelog")}),m&&t.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:()=>void A(),disabled:h!=="idle",children:h==="downloading"?s("config:appUpdateBanner.downloadingPct",{percent:o??0}):s(h==="installing"?"config:appUpdateBanner.installHint":"config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:g,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(d?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>u(!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${c}`||p.version===c?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:p.version}),e.jsx("span",{className:"about-release-date",children:v(p.publishedAt)})]},p.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:e.jsx(D,{name:"package",size:14})}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]}),T&&e.jsx(Ws,{onClose:()=>x(!1)})]})}const Aa={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function Ta({onOpenModal:s}){const[n,t]=l.useState([]),[i,d]=l.useState(!0),r=l.useCallback(async()=>{try{const c=await fe(xe("/api/integrations"));if(!c.ok)return;const m=await c.json();t(m)}catch{}finally{d(!1)}},[]);return l.useEffect(()=>{r()},[r]),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(c=>{const m=Aa[c.id]||"🔌",h=!!c.status.error,o=c.status.connected,u=h?"#f38ba8":o?"#a6e3a1":"#fab387",A=h?"Error":o?"Connected":"Setup Required",g=h?"✗":o?"✓":"⚠";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:m}),e.jsx("span",{style:{flex:1,minWidth:0,color:"var(--text-primary, #cdd6f4)",fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c.name}),e.jsx("span",{style:{color:u,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:A,children:g}),e.jsx("button",{onClick:()=>s(c.id),title:`Configure ${c.name}`,style:{background:"none",border:"none",cursor:"pointer",padding:"1px 3px",fontSize:12,color:"var(--text-secondary, #a6adc8)",borderRadius:3,flexShrink:0,lineHeight:1},onMouseEnter:T=>{T.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:T=>{T.target.style.color="var(--text-secondary, #a6adc8)"},children:"⚙️"})]},c.id)}),e.jsx("button",{onClick:()=>s(),style:{background:"none",border:"1px dashed var(--border, #313244)",borderRadius:4,padding:"3px 8px",cursor:"pointer",color:"var(--text-secondary, #a6adc8)",fontSize:11,textAlign:"center",marginTop:2},onMouseEnter:c=>{c.target.style.borderColor="var(--accent, #89b4fa)",c.target.style.color="var(--accent, #89b4fa)"},onMouseLeave:c=>{c.target.style.borderColor="var(--border, #313244)",c.target.style.color="var(--text-secondary, #a6adc8)"},children:"Manage All Integrations"})]})}const ze="__global__";function Ea({isOpen:s,onClose:n,initialAgentId:t}){const{t:i}=Z(["config"]),d=ot(),[r,c]=l.useState(""),[m,h]=l.useState(""),[o,u]=l.useState(!1),[A,g]=l.useState(""),[T,x]=l.useState(""),[I,v]=l.useState(null),[p,b]=l.useState(null),[R,M]=l.useState(!1),[G,q]=l.useState(!1),[Y,U]=l.useState(!1),[X,S]=l.useState(null),B=l.useMemo(()=>[...d].sort((P,k)=>P.name.localeCompare(k.name)),[d]),y=l.useMemo(()=>d.find(P=>P.id===r),[d,r]),O=r===ze;l.useEffect(()=>{if(!s)return;const P=t&&d.some(k=>k.id===t)?t:ze;c(P),u(!1),Qt().then(k=>h(k)).catch(()=>h("")).finally(()=>u(!0))},[s]),l.useEffect(()=>{const P=r===ze?m:(y==null?void 0:y.customPrompt)??"";g(P),x(P),M(!1),v(null),b(null)},[r,o]);const ne=P=>{const k=P.target.value;g(k),M(k!==T),v(null),b(null)},N=async()=>{if(r)try{v(null),b(null),O?(await ea(A),h(A),b(i("config:systemPrompt.savedGlobal"))):(j.updateAgentProperties(r,{customPrompt:A}),b(i("config:systemPrompt.saved"))),x(A),M(!1)}catch(P){v(P instanceof Error?P.message:"Failed to save system prompt")}},$=()=>{q(!0)},z=async()=>{if(r)try{v(null),b(null),O?(await sa(),h(""),b(i("config:systemPrompt.clearedGlobal"))):(j.updateAgentProperties(r,{customPrompt:""}),b(i("config:systemPrompt.cleared"))),g(""),x(""),M(!1)}catch(P){v(P instanceof Error?P.message:"Failed to clear system prompt")}},w=()=>{g(T),M(!1),v(null),b(null)},L=P=>{if(P!==r){if(R){S(P),U(!0);return}c(P)}},F=()=>{if(R){S(null),U(!0);return}n()},ae=()=>{if(U(!1),X){const P=X;S(null),c(P)}else n()},te=P=>{P.key==="Escape"&&(P.preventDefault(),F())};return s?e.jsxs(Ie,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:F,children:e.jsxs("div",{className:"system-prompt-modal",onClick:P=>P.stopPropagation(),onKeyDown:te,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:i("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:F,"aria-label":"Close",children:e.jsx(D,{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:[O?e.jsx(D,{name:"globe",size:20,className:"agent-picker-icon"}):y&&e.jsx(it,{classId:y.class,size:20,className:"agent-picker-icon"}),e.jsxs("select",{id:"system-prompt-agent",className:"agent-picker-select",value:r,onChange:P=>L(P.target.value),children:[e.jsxs("option",{value:ze,children:[i("config:systemPrompt.globalOption"),m?" • ✦":""]}),B.map(P=>e.jsxs("option",{value:P.id,children:[P.name,P.customPrompt?" • ✦":""]},P.id))]})]})]}),I&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{name:"warn",size:14})}),I]}),p&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{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:[A.length," ",i("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:A,onChange:ne,placeholder:i("config:systemPrompt.placeholder"),rows:18,disabled:O&&!o,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:i(O?"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:$,disabled:!A||!r,children:i("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:F,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:w,disabled:!R,children:i("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:N,disabled:!R||!r,children:i("config:systemPrompt.save")})]})]})]})}),e.jsx(be,{isOpen:G,title:i("config:systemPrompt.clear"),message:i(O?"config:systemPrompt.confirmClearGlobal":"config:systemPrompt.confirmClear"),confirmLabel:i("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{z()},onClose:()=>q(!1)}),e.jsx(be,{isOpen:Y,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:ae,onClose:()=>{U(!1),S(null)}})]}):null}const ms={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},Pa=2500,_a=12e4;function gs(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function Ia(s,n){return s.enabled===n.enabled&&s.baseUrl===n.baseUrl&&s.defaultSessionId===n.defaultSessionId&&s.webhookVerifyToken===n.webhookVerifyToken&&s.showIncomingToasts===n.showIncomingToasts}function Da({isOpen:s,onClose:n}){const{t}=Z(["config"]),[i,d]=l.useState(ms),[r,c]=l.useState(ms),[m,h]=l.useState(!1),[o,u]=l.useState([]),[A,g]=l.useState(!0),[T,x]=l.useState(null),[I,v]=l.useState(null),[p,b]=l.useState(""),[R,M]=l.useState(!1),[G,q]=l.useState(""),[Y,U]=l.useState(null),[X,S]=l.useState(null),[B,y]=l.useState(null),O=l.useRef(null),ne=l.useRef(0),[N,$]=l.useState(""),[z,w]=l.useState(""),[L,F]=l.useState(null),[ae,te]=l.useState(!1),[P,k]=l.useState(!1),[se,ie]=l.useState(!1),[ce,le]=l.useState(!1),[he,Ae]=l.useState(null),Se=!Ia(i,r),pe=l.useCallback(()=>{O.current&&(clearTimeout(O.current),O.current=null)},[]),Te=l.useCallback(async()=>{try{g(!0),x(null),v(null);const[f,V]=await Promise.all([ys(),lt()]),re=gs(f);if(d(re),c(re),h(!!V.configured),V.configured)try{const Ne=await Ze();u(Array.isArray(Ne)?Ne:[])}catch{u([])}else u([])}catch(f){x(f instanceof Error?f.message:t("config:whatsapp.errors.loadFailed"))}finally{g(!1)}},[t]),je=l.useCallback(async()=>{try{const f=await Ze();u(Array.isArray(f)?f:[])}catch{}},[]);l.useEffect(()=>(s?Te():(pe(),U(null),S(null),y(null),b(""),M(!1),F(null)),()=>{pe()}),[s,Te,pe]);const me=(f,V)=>{d(re=>({...re,[f]:V})),x(null),v(null)},De=async()=>{try{x(null),v(null);const f=await pt({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),c(V),v(t("config:whatsapp.saved"))}catch(f){x(f instanceof Error?f.message:t("config:whatsapp.errors.saveFailed"))}},$e=()=>{d(r),x(null),v(null)},ve=()=>{if(Se){k(!0);return}n()},Le=f=>{f.key==="Escape"&&(f.preventDefault(),ve())},Ke=async()=>{const f=p.trim();if(f)try{x(null),v(null),await rt(f),b(""),M(!1),h(!0),v(t("config:whatsapp.apiKeySaved"))}catch(V){x(V instanceof Error?V.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},He=()=>{ie(!0)},Oe=async()=>{try{x(null),v(null),await ht(),h(!1),v(t("config:whatsapp.apiKeyCleared"))}catch(f){x(f instanceof Error?f.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},Fe=l.useCallback(async f=>{if(Date.now()>ne.current){y(t("config:whatsapp.pairingTimeout")),U(null),S(null),pe(),je();return}try{const V=await ct(f);if(V.status&&["connected","paired","open","ready"].includes(V.status.toLowerCase())){y(t("config:whatsapp.pairingSuccess")),U(null),S(null),pe(),je();return}const Ne=V.qrUrl??V.qr??null;Ne&&S(Ne)}catch(V){y(V instanceof Error?V.message:t("config:whatsapp.errors.qrFetchFailed"))}O.current=setTimeout(()=>{Fe(f)},Pa)},[je,pe,t]),Re=async()=>{const f=G.trim();if(f)try{x(null),v(null),y(null),S(null),pe(),await dt(f),q(""),U(f),ne.current=Date.now()+_a,Fe(f),je()}catch(V){x(V instanceof Error?V.message:t("config:whatsapp.errors.sessionCreateFailed"))}},Be=()=>{pe(),U(null),S(null),y(null)},ke=f=>{Ae(f),le(!0)},_=async()=>{if(he)try{x(null),v(null),await mt(he),Y===he&&Be(),je(),v(t("config:whatsapp.sessionDeleted"))}catch(f){x(f instanceof Error?f.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{Ae(null)}},ue=async()=>{const f=N.trim(),V=z.trim();if(!(!f||!V))try{te(!0),F(null);const re=i.defaultSessionId.trim()||void 0;await ut(f,V,re),F({kind:"success",text:t("config:whatsapp.testSent")})}catch(re){F({kind:"error",text:re instanceof Error?re.message:t("config:whatsapp.errors.testSendFailed")})}finally{te(!1)}};return s?e.jsxs(Ie,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:ve,children:e.jsxs("div",{className:"whatsapp-config-modal",onClick:f=>f.stopPropagation(),onKeyDown:Le,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsapp.title")}),e.jsx("button",{className:"modal-close",onClick:ve,"aria-label":"Close",children:e.jsx(D,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:A?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsapp.description")}),T&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{name:"warn",size:14})}),T]}),I&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{name:"check",size:14})}),I]}),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=>me("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=>me("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=>me("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=>me("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=>me("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:m?e.jsxs("span",{className:"wa-status wa-status-ok",children:[e.jsx(D,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(D,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:R?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:p,onChange:f=>b(f.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>M(f=>!f),title:t(R?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(D,{name:R?"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:He,disabled:!m,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(o)||o.length===0?e.jsx("div",{className:"wa-empty",children:t("config:whatsapp.noSessions")}):o.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:()=>ke(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:G,onChange:f=>q(f.target.value),onKeyDown:f=>{f.key==="Enter"&&Re()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Re,disabled:!G.trim()||Y!==null,children:t("config:whatsapp.addSession")})]}),Y&&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:Y})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Be,children:t("config:whatsapp.cancelPairing")})]}),X?e.jsx("div",{className:"wa-qr-image",children:e.jsx("img",{src:X,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")})]})]}),B&&!Y&&e.jsx("div",{className:"wa-pairing-message",children:B})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.testMessage")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-to",className:"wa-label",children:t("config:whatsapp.testTo")}),e.jsx("input",{id:"wa-test-to",type:"text",className:"wa-input",placeholder:t("config:whatsapp.testToPlaceholder"),value:N,onChange:f=>$(f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-message",className:"wa-label",children:t("config:whatsapp.testMessageBody")}),e.jsx("textarea",{id:"wa-test-message",className:"wa-textarea",rows:4,placeholder:t("config:whatsapp.testMessageBodyPlaceholder"),value: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:ue,disabled:!N.trim()||!z.trim()||ae,children:t(ae?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),L&&e.jsxs("div",{className:`alert ${L.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{name:L.kind==="success"?"check":"warn",size:14})}),L.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:ve,children:t("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:$e,disabled:!Se||A,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:De,disabled:!Se||A,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(be,{isOpen:P,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{k(!1),n()},onClose:()=>k(!1)}),e.jsx(be,{isOpen:se,title:t("config:whatsapp.clearKey"),message:t("config:whatsapp.confirmClearKey"),confirmLabel:t("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Oe()},onClose:()=>ie(!1)}),e.jsx(be,{isOpen:ce,title:t("config:whatsapp.deleteSession"),message:t("config:whatsapp.confirmDeleteSession",{id:he??""}),confirmLabel:t("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{_()},onClose:()=>{le(!1),Ae(null)}})]}):null}const Cs=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function Qe(s=!1){const n=Q(),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 $a(){const s=await fetch(`${W()}/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 La(s){const n=await fetch(`${W()}/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 Oa(){const s=await fetch(`${W()}/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 Ve={messages:!0,statusChanges:!0,taskComplete:!0,errors:!0,planReady:!0,agentSpawned:!0,agentStopped:!0},fs={filter:{...Ve},recipient:""};function Fa(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 Ra({isOpen:s,onClose:n}){const{t}=Z(["config"]),[i,d]=l.useState(fs),[r,c]=l.useState(fs),[m,h]=l.useState(!0),[o,u]=l.useState(null),[A,g]=l.useState(null),[T,x]=l.useState(!1),[I,v]=l.useState(!1),p=!Fa(i,r),b=l.useCallback(async()=>{try{h(!0),u(null),g(null);const S=await $a(),B={filter:{...Ve,...S.filter},recipient:S.recipient??""};d(B),c(B)}catch(S){u(S instanceof Error?S.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{h(!1)}},[t]);l.useEffect(()=>{s&&b()},[s,b]);const R=(S,B)=>{d(y=>({...y,filter:{...y.filter,[S]:B}})),u(null),g(null)},M=S=>{d(B=>({...B,recipient:S})),u(null),g(null)},G=async()=>{try{u(null),g(null);const S=await La({filter:i.filter,recipient:i.recipient.trim()}),B={filter:{...Ve,...S.filter},recipient:S.recipient??""};d(B),c(B),g(t("config:whatsappNotifications.saved"))}catch(S){u(S instanceof Error?S.message:t("config:whatsappNotifications.errors.saveFailed"))}},q=()=>{d(r),u(null),g(null)},Y=async()=>{try{u(null),g(null);const S=await Oa(),B={filter:{...Ve,...S.filter},recipient:S.recipient??""};d(B),c(B),g(t("config:whatsappNotifications.resetDone"))}catch(S){u(S instanceof Error?S.message:t("config:whatsappNotifications.errors.resetFailed"))}},U=()=>{if(p){x(!0);return}n()},X=S=>{S.key==="Escape"&&(S.preventDefault(),U())};return s?e.jsxs(Ie,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:U,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:S=>S.stopPropagation(),onKeyDown:X,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(D,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:m?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")}),o&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{name:"warn",size:14})}),o]}),A&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(D,{name:"check",size:14})}),A]}),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:S=>M(S.target.value)}),e.jsx("span",{className:"wan-hint",children:t("config:whatsappNotifications.recipientHint")})]})]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.events")}),e.jsx("p",{className:"wan-section-hint",children:t("config:whatsappNotifications.eventsHint")}),Cs.map(S=>e.jsxs("div",{className:"wan-toggle-row",children:[e.jsxs("div",{className:"wan-toggle-info",children:[e.jsx("span",{className:"wan-toggle-title",children:t(`config:whatsappNotifications.events.${S}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${S}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:i.filter[S],onChange:B=>R(S,B.target.checked)}),e.jsx("span",{className:"wan-toggle-track",children:e.jsx("span",{className:"wan-toggle-thumb"})})]})]},S))]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:()=>v(!0),disabled:m,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:q,disabled:!p||m,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:G,disabled:!p||m,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(be,{isOpen:T,title:t("config:whatsappNotifications.unsavedTitle"),message:t("config:whatsappNotifications.unsavedMessage"),confirmLabel:t("config:whatsappNotifications.closeAnyway"),cancelLabel:t("config:whatsappNotifications.keepEditing"),variant:"danger",onConfirm:()=>{x(!1),n()},onClose:()=>x(!1)}),e.jsx(be,{isOpen:I,title:t("config:whatsappNotifications.resetToDefaults"),message:t("config:whatsappNotifications.confirmReset"),confirmLabel:t("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Y(),v(!1)},onClose:()=>v(!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 Ba(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 r=Math.floor(d/60);if(r<24)return`${r}h`;const c=Math.floor(r/24);return c===1?"yesterday":c<7?`${c}d`:xs(t)}function xs(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Ma(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 Ua(s,n){return s.length<=n?s:s.slice(0,Math.max(0,n-1)).trimEnd()+"…"}function za({chats:s,selectedChatId:n,loading:t,error:i,onSelect:d,onRefresh:r,now:c}){const{t:m}=Z(["config","common"]);return e.jsxs("div",{className:"whatsapp-history-chatlist",children:[e.jsxs("div",{className:"whatsapp-history-chatlist__header",children:[e.jsx("span",{className:"whatsapp-history-chatlist__title",children:m("config:whatsappHistory.chats")}),e.jsx("button",{type:"button",className:"whatsapp-history-chatlist__refresh",onClick:r,disabled:t,"aria-label":m("config:whatsappHistory.refresh"),title:m("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:m("config:whatsappHistory.loadingChats")})]}),!t&&!i&&s.length===0&&e.jsx("div",{className:"whatsapp-history-chatlist__empty",children:m("config:whatsappHistory.emptyChats")}),e.jsx("ul",{className:"whatsapp-history-chatlist__items",children:s.map(h=>{const o=Ts(h.lastMessageType),u=h.lastMessagePreview||`[${h.lastMessageType}]`,A=h.chatId===n,g=As(h.chatId),T=h.isGroup?h.groupName:h.fromName,x=T||g,I=!!T&&T!==g;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${A?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>d(h.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:h.chatId,children:x}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:Ba(h.lastTimestamp,c)})]}),I&&e.jsx("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--jid",children:e.jsx("span",{className:"whatsapp-history-chatlist__jid",children:g})}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[h.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),o&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[o," "]}),Ua(u,40)]}),h.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:h.unreadCount})]})]})},h.chatId)})})]})}function Va({message:s}){const n=s.direction==="outbound"?"outbound":"inbound",t=Ts(s.messageType),i=(s.body??"").trim(),d=i.length>0,r=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:r}),s.audioTranscription&&e.jsxs("span",{className:"whatsapp-history-bubble__transcription",children:["“",s.audioTranscription,"”"]}),s.mediaPath&&e.jsx("a",{className:"whatsapp-history-bubble__media-link",href:s.mediaPath,target:"_blank",rel:"noopener noreferrer",children:s.mediaFilename||"open media"}),e.jsx("span",{className:"whatsapp-history-bubble__time",children:Ma(s.timestamp)})]})})}const Ka=["all","inbound","outbound"],Ha=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function qa({direction:s,type:n,onDirectionChange:t,onTypeChange:i,disabled:d}){const{t:r}=Z(["config"]);return e.jsxs("div",{className:"whatsapp-history-filters",children:[e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:r("config:whatsappHistory.direction")}),e.jsx("select",{value:s,onChange:c=>t(c.target.value),disabled:d,children:Ka.map(c=>e.jsx("option",{value:c,children:r(`config:whatsappHistory.directionValues.${c}`)},c))})]}),e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:r("config:whatsappHistory.type")}),e.jsx("select",{value:n,onChange:c=>i(c.target.value),disabled:d,children:Ha.map(c=>e.jsx("option",{value:c,children:r(`config:whatsappHistory.typeValues.${c}`)},c))})]})]})}const Wa=80;function Ga({chatId:s,messages:n,loading:t,loadingMore:i,error:d,hasMore:r,direction:c,type:m,onDirectionChange:h,onTypeChange:o,onLoadMore:u}){const{t:A}=Z(["config"]),g=l.useRef(null),T=l.useRef(null),x=l.useRef(!1),I=l.useRef(null);l.useEffect(()=>{T.current!==s&&(T.current=s,x.current=!1)},[s]),l.useLayoutEffect(()=>{g.current&&(x.current||n.length!==0&&(g.current.scrollTop=g.current.scrollHeight,x.current=!0))},[s,n.length]),l.useLayoutEffect(()=>{if(!g.current||I.current===null)return;const b=g.current.scrollHeight-I.current;I.current=null,b>0&&(g.current.scrollTop+=b)},[n.length]);const v=l.useCallback(()=>{!r||i||t||(g.current&&(I.current=g.current.scrollHeight),u())},[r,i,t,u]),p=l.useCallback(b=>{if(!x.current)return;b.currentTarget.scrollTop<=Wa&&v()},[v]);return s?e.jsxs("div",{className:"whatsapp-history-messages",children:[e.jsxs("div",{className:"whatsapp-history-messages__header",children:[e.jsx("div",{className:"whatsapp-history-messages__title",children:As(s)}),e.jsx(qa,{direction:c,type:m,onDirectionChange:h,onTypeChange:o,disabled:t})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:g,onScroll:p,children:[r&&e.jsx("div",{className:"whatsapp-history-messages__load-more-row",children:e.jsx("button",{type:"button",className:"whatsapp-history-messages__load-more",onClick:v,disabled:i||t,children:A(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:A("config:whatsappHistory.loadingMessages")})]}),!t&&!d&&n.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:A("config:whatsappHistory.emptyMessages")}),n.map(b=>e.jsx(Va,{message:b},Ya(b)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:A("config:whatsappHistory.selectChat")})})}function Ya(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=Q(),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 Ja(s){const n=`${W()}/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(),r=`${W()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(n)}/messages${d?`?${d}`:""}`,c=await fetch(r,{headers:Es()});if(!c.ok)throw new Error(await Ps(c,"Failed to fetch WhatsApp messages"));return c.json()}const Xa=50;function Za({isOpen:s,onClose:n}){const{t}=Z(["config"]),[i,d]=l.useState([]),[r,c]=l.useState(null),[m,h]=l.useState(null),[o,u]=l.useState([]),[A,g]=l.useState(!1),[T,x]=l.useState(null),[I,v]=l.useState(null),[p,b]=l.useState([]),[R,M]=l.useState(!1),[G,q]=l.useState(!1),[Y,U]=l.useState(null),[X,S]=l.useState(null),[B,y]=l.useState("all"),[O,ne]=l.useState("all"),[N,$]=l.useState(()=>Date.now()),z=l.useRef(0);l.useEffect(()=>{if(!s)return;const k=window.setInterval(()=>$(Date.now()),6e4);return()=>window.clearInterval(k)},[s]),l.useEffect(()=>{if(!s)return;let k=!1;return(async()=>{var se;try{h(null);const[ie,ce]=await Promise.all([Ze().catch(()=>[]),ys().catch(()=>null)]);if(k)return;d(ie);const le=(ce==null?void 0:ce.defaultSessionId)||((se=ie[0])==null?void 0:se.id)||null;c(he=>he??le)}catch(ie){if(k)return;h(ie instanceof Error?ie.message:String(ie))}})(),()=>{k=!0}},[s]);const w=l.useCallback(async k=>{g(!0),x(null);try{const se=await Ja(k);u(se.chats)}catch(se){x(se instanceof Error?se.message:String(se))}finally{g(!1)}},[]);l.useEffect(()=>{!s||!r||(v(null),b([]),S(null),w(r))},[s,r,w]);const L=l.useMemo(()=>{const k={limit:Xa};return B!=="all"&&(k.direction=B),O!=="all"&&(k.type=O),k},[B,O]),F=l.useCallback(async(k,se,ie)=>{const ce=++z.current;M(!0),U(null),b([]),S(null);try{const le=await bs(k,se,ie);if(ce!==z.current)return;b([...le.messages].reverse()),S(le.nextCursor)}catch(le){if(ce!==z.current)return;U(le instanceof Error?le.message:String(le))}finally{ce===z.current&&M(!1)}},[]);l.useEffect(()=>{!s||!r||!I||F(r,I,L)},[s,r,I,L,F]);const ae=l.useCallback(async()=>{if(!(!r||!I||!X)){q(!0),U(null);try{const k=await bs(r,I,{...L,cursor:X});b(se=>[...[...k.messages].reverse(),...se]),S(k.nextCursor)}catch(k){U(k instanceof Error?k.message:String(k))}finally{q(!1)}}},[r,I,X,L]),te=l.useCallback(()=>{r&&w(r)},[r,w]),P=l.useCallback(k=>{k.key==="Escape"&&(k.preventDefault(),n())},[n]);return s?e.jsx(Ie,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:k=>k.stopPropagation(),onKeyDown:P,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappHistory.title")}),e.jsx("div",{className:"whatsapp-history-modal__session",children:e.jsxs("label",{children:[e.jsx("span",{children:t("config:whatsappHistory.session")}),e.jsxs("select",{value:r??"",onChange:k=>c(k.target.value||null),disabled:i.length===0,children:[i.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),i.map(k=>e.jsxs("option",{value:k.id,children:[k.id,k.pairedNumber?` (${k.pairedNumber})`:""]},k.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(D,{name:"close",size:16})})]}),m&&e.jsx("div",{className:"whatsapp-history-modal__alert",children:m}),e.jsxs("div",{className:"whatsapp-history-modal__body",children:[e.jsx(za,{chats:o,selectedChatId:I,loading:A,error:T,onSelect:v,onRefresh:te,now:N}),e.jsx(Ga,{chatId:I,messages:p,loading:R,loadingMore:G,error:Y,hasMore:X!==null,direction:B,type:O,onDirectionChange:y,onTypeChange:ne,onLoadMore:ae})]})]})})}):null}function Qa({isOpen:s,onClose:n,onOpenConfig:t,onOpenNotifications:i,onOpenHistory:d}){const{t:r}=Z(["config"]);if(l.useEffect(()=>{if(!s)return;const m=h=>{h.key==="Escape"&&(h.preventDefault(),n())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[s,n]),!s)return null;const c=m=>{n(),m()};return e.jsx(Ie,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-hub-modal",onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"whatsapp-hub-modal__icon",children:"📱"}),r("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(D,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"whatsapp-hub-modal__intro",children:r("config:whatsappHub.intro",{defaultValue:"Pick what you want to manage for the WhatsApp integration."})}),e.jsxs("div",{className:"whatsapp-hub-modal__options",children:[e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(t),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(D,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:r("config:whatsappHub.config",{defaultValue:"Integration config"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:r("config:whatsappHub.configDesc",{defaultValue:"Server URL, API key, sessions and pairing."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(i),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(D,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:r("config:whatsappHub.notifications",{defaultValue:"Notifications"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:r("config:whatsappHub.notificationsDesc",{defaultValue:"Which agent events get forwarded and to whom."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(d),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(D,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:r("config:whatsappHub.history",{defaultValue:"History"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:r("config:whatsappHub.historyDesc",{defaultValue:"Browse persisted chats and messages."})})]})]})]})]})]})})})}const 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:Ss},{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:ws},{kind:"completion",settingKey:"toneCompletion",label:"Agent finishes working",when:"An agent stops working and goes idle.",sound:"Gentle descending arpeggio",play:Tt}],en=[{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:"🌙"}],sn=[{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:"🔴"}],tn=[{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:"👎"}],an=[{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:"💜"}],nn=[{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"}],on=[{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"}],ln={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},cn={none:"grass","pokemon-stadium":"pokemon"},rn={"emote-yes":"yes","emote-no":"no"},dn={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function ee({checked:s,onChange:n}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:t=>n(t.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function Ce({options:s,value:n,onChange:t,iconOnly:i=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(d=>e.jsxs("button",{className:`chip ${n===d.value?"active":""}`,onClick:()=>t(d.value),title:d.label,children:[e.jsx("span",{className:"chip-icon",children:d.icon}),!i&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function C({text:s,query:n}){if(!n.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),i=n.toLowerCase(),d=t.indexOf(i);if(d===-1)return e.jsx(e.Fragment,{children:s});const r=s.slice(0,d),c=s.slice(d,d+n.length),m=s.slice(d+n.length);return e.jsxs(e.Fragment,{children:[r,e.jsx("mark",{className:"search-highlight",children:c}),m]})}const 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 un({config:s,onChange:n,searchQuery:t="",onOpenIntegrationsModal:i,onOpenPluginsModal:d,onOpenMonitoringModal:r,onOpenStatisticsModal:c,onOpenWorkflowEditor:m,onOpenTriggerManager:h}){var ls;const{t:o}=Z(["config","common"]),u=gt(),A=ft(),[g,T]=l.useState(()=>xt(Pe.DEFAULT_AGENT_CLASS)||"scout"),x=bt(),I=jt(),[v,p]=l.useState(()=>vt()),[b,R]=l.useState(null),[M,G]=l.useState(null),[q,Y]=l.useState("");l.useEffect(()=>{qe().then(p)},[]);const U=async(a,E)=>{G(null),R(a);try{const K=await fe(xe(`/api/custom-sounds/${a}`),{method:"POST",headers:{"Content-Type":E.type||"audio/mpeg"},body:E});if(!K.ok){const de=await K.json().catch(()=>({error:`Upload failed (${K.status})`}));throw new Error(de.error||`Upload failed (${K.status})`)}const oe=await qe();p({...oe});const ge=Je.find(de=>de.kind===a);ge&&j.updateSettings({[ge.settingKey]:_e}),We(_e,u.notificationSoundVolume,a)}catch(K){G(K instanceof Error?K.message:"Upload failed")}finally{R(null)}},X=async a=>{G(null);try{await fe(xe(`/api/custom-sounds/${a}`),{method:"DELETE"}),Dt({[a]:null});const E=await qe();p({...E});const K=Je.find(oe=>oe.kind===a);K&&j.getSettings()[K.settingKey]===_e&&j.updateSettings({[K.settingKey]:$t[a]})}catch(E){G(E instanceof Error?E.message:"Failed to reset sound")}},[S,B]=l.useState(u.historyLimit),[y,O]=l.useState(()=>Nt()),[ne,N]=l.useState(!1),[$,z]=l.useState(""),[w,L]=l.useState(()=>Q()),[F,ae]=l.useState(!1),[te,P]=l.useState(!1),[k,se]=l.useState(""),[ie,ce]=l.useState(!1),[le,he]=l.useState(!1),[Ae,Se]=l.useState(!1),[pe,Te]=l.useState(!1),[je,me]=l.useState(!1),[De,$e]=l.useState(""),[ve,Le]=l.useState(!1);l.useEffect(()=>{na().then($e).catch(()=>{})},[]),l.useEffect(()=>{ta().then(a=>{a!==u.experimentalEchoPrompt&&j.updateSettings({experimentalEchoPrompt:a})}).catch(()=>{})},[]),l.useEffect(()=>{ia().then(a=>{a!==u.tmuxMode&&j.updateSettings({tmuxMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{ca().then(a=>{a!==u.interactiveMode&&j.updateSettings({interactiveMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{da().then(a=>{a!==u.codexAppServerMode&&j.updateSettings({codexAppServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{pa().then(a=>{a!==u.opencodeServerMode&&j.updateSettings({opencodeServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{ma().then(a=>{a!==u.piRpcMode&&j.updateSettings({piRpcMode:a})}).catch(()=>{})},[]),l.useEffect(()=>yt(a=>{O(a),N(!1)}),[]);const Ke=en.map(a=>({...a,label:o(`config:time.${a.value}`)})),He=sn.map(a=>({...a,label:o(`config:floor.${cn[a.value]||a.value}`)})),Oe=tn.map(a=>({...a,label:o(`config:animation.${rn[a.value]||a.value}`)})),Fe=an.map(a=>({...a,label:o(`config:colorMode.${a.value}`)})),Re=nn.map(a=>({...a,label:o(`config:terrain.${ln[a.key]}`)})),Be=on.map(a=>({...a,label:o(`config:sky.${dn[a.value??""]}`)})),ke=t.trim()?Kt(t).map(a=>a.id):null,_=a=>ke?ke.includes(a):!0,ue=u.customAgentNames||[],f=ue.length>0?ue:wt,V=()=>{const a=k.trim();a&&!ue.includes(a)&&(j.updateSettings({customAgentNames:[...ue,a]}),se(""))},re=a=>{j.updateSettings({customAgentNames:ue.filter(E=>E!==a)})},Ne=()=>{j.updateSettings({customAgentNames:[]})},Me=u.fileSearchExcludeDirs??[...rs],ss=()=>{const a=q.trim();if(ps(a)){if(Me.includes(a)){Y("");return}j.updateSettings({fileSearchExcludeDirs:[...Me,a]}),Y("")}},_s=a=>{j.updateSettings({fileSearchExcludeDirs:Me.filter(E=>E!==a)})},Is=()=>{j.updateSettings({fileSearchExcludeDirs:[...rs]})},ts=()=>{const a=$.trim();if(a){if(y.includes(a)){z("");return}O([...y,a]),N(!0),z("")}},Ds=a=>{O(y.filter((E,K)=>K!==a)),N(!0)},as=(a,E)=>{const K=a+E;if(K<0||K>=y.length)return;const oe=y.slice();[oe[a],oe[K]]=[oe[K],oe[a]],O(oe),N(!0)},$s=()=>{Lt(y),N(!1),Ye()},Ls=a=>{L(a),ae(!0)},ns=()=>{Ue(Pe.AUTH_TOKEN,w),ae(!1),Ye()},Os=a=>{$e(a),Le(!0)},os=()=>{oa(De).catch(()=>{}),Le(!1)},ye=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=>{B(a),j.updateSettings({historyLimit:a})},Rs=a=>{const E=s.terrain[a];typeof E=="boolean"&&ye({[a]:!E})},J=t.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[ke&&ke.length===0&&e.jsx("div",{className:"config-no-results",children:o("config:noResults",{query:t})}),_("plugins")&&e.jsx(H,{title:"Plugins",storageKey:"plugins",defaultOpen:!0,forceOpen:J&&_("plugins"),children:e.jsxs("div",{className:"config-row config-row--plugins",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Install, enable, and disable trusted local UI plugins",query:t})}),e.jsx("button",{className:"config-button",onClick:()=>d==null?void 0:d(),children:"Manage Plugins"})]})}),_("general")&&e.jsxs(H,{title:o("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:J&&_("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:S,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(C,{text:o("config:general.hideCosts"),query:t})}),e.jsx(ee,{checked:u.hideCost,onChange:a=>j.updateSettings({hideCost:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.streamTextLiveTitle"),children:e.jsx(C,{text:o("config:general.streamTextLive"),query:t})}),e.jsx(ee,{checked:u.streamTextLive!==!1,onChange:a=>j.updateSettings({streamTextLive:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.toolHoverPreviewTitle"),children:e.jsx(C,{text:o("config:general.toolHoverPreview"),query:t})}),e.jsx(ee,{checked:u.toolHoverPreview===!0,onChange:a=>j.updateSettings({toolHoverPreview:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Where the strip of recently-active and currently-working agent thumbnails sits.",children:e.jsx(C,{text:"Agent activity dock",query:t})}),e.jsx("select",{className:"config-select",value:x,onChange:a=>Ct(a.target.value),children:St.map(a=>e.jsx("option",{value:a,children:kt[a]},a))})]}),x!=="hidden"&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"How many recently-active agents the dock shows alongside the ones working right now. 0 shows only working agents.",children:e.jsx(C,{text:"Recent agents in dock",query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:I,min:0,max:20,step:1,onChange:a=>At(parseInt(a.target.value,10)||0)})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.grid"),query:t})}),e.jsx(ee,{checked:s.gridVisible,onChange:a=>n({...s,gridVisible:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.showFPS"),query:t})}),e.jsx(ee,{checked:u.showFPS,onChange:a=>j.updateSettings({showFPS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.fpsLimit"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:a=>n({...s,fpsLimit:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.fpsLimit===0?"∞":s.fpsLimit})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: Reduce FPS when idle to save power",children:[e.jsx(C,{text:o("config:general.powerSaving"),query:t})," ",e.jsx(D,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.powerSaving,onChange:a=>j.updateSettings({powerSaving:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Battery saver for mobile: caps scene FPS (20 active / 5 idle), freezes decorative animations and disables word-by-word streaming. Off = normal mode.",children:[e.jsx(C,{text:o("config:general.lowPowerMode"),query:t})," ",e.jsx(D,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.lowPowerMode===!0,onChange:a=>j.updateSettings({lowPowerMode:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Wrap agent processes in tmux sessions so they survive server restarts (requires tmux installed)",children:e.jsx(C,{text:o("config:general.tmuxMode"),query:t})}),e.jsx(ee,{checked:u.tmuxMode,onChange:async a=>{j.updateSettings({tmuxMode:a});try{await la(a)}catch(E){console.error("Failed to sync tmux mode setting to server:",E)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Claude agents as the real interactive `claude` TUI inside tmux, reconstructing the conversation from the session transcript (requires tmux). Takes effect on server restart.",children:[e.jsx(C,{text:o("config:general.interactiveMode"),query:t})," ",e.jsx(D,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.interactiveMode,onChange:async a=>{j.updateSettings({interactiveMode:a});try{await ra(a)}catch(E){console.error("Failed to sync interactive mode setting to server:",E)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Codex agents through a persistent `codex app-server` so replies stream word-by-word (token deltas) instead of appearing as one block. The app-server runs detached and survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new Codex turns; no server restart needed to toggle.",children:[e.jsx(C,{text:o("config:general.codexAppServerMode"),query:t})," ",e.jsx(D,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.codexAppServerMode,onChange:async a=>{j.updateSettings({codexAppServerMode:a});try{await ua(a)}catch(E){console.error("Failed to sync codex app-server mode setting to server:",E)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run OpenCode agents through a persistent, detached `opencode serve` HTTP server so replies stream word-by-word (token deltas over SSE) instead of appearing as one block. The server survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new OpenCode turns; no server restart needed to toggle.",children:[e.jsx(C,{text:o("config:general.opencodeServerMode"),query:t})," ",e.jsx(D,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.opencodeServerMode,onChange:async a=>{j.updateSettings({opencodeServerMode:a});try{await ha(a)}catch(E){console.error("Failed to sync opencode server mode setting to server:",E)}}})]}),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(C,{text:o("config:general.piRpcMode"),query:t})," ",e.jsx(D,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.piRpcMode,onChange:async a=>{j.updateSettings({piRpcMode:a});try{await ga(a)}catch(E){console.error("Failed to sync pi RPC mode setting to server:",E)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.vibrationIntensity"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:u.vibrationIntensity,onChange:a=>j.updateSettings({vibrationIntensity:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:u.vibrationIntensity===0?o("config:vibrationValues.off"):u.vibrationIntensity===1?o("config:vibrationValues.ultraLight"):u.vibrationIntensity===2?o("config:vibrationValues.veryLight"):u.vibrationIntensity===3?o("config:vibrationValues.light"):u.vibrationIntensity===4?o("config:vibrationValues.medium"):o("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Play pleasant sounds: a chime for agent notifications, a distinctive rising cue when an agent asks you a question (repeats until answered), and a resolving cue when an agent finishes its work.",children:e.jsx(C,{text:"Notification sounds",query:t})}),e.jsx(ee,{checked:u.notificationSoundEnabled,onChange:a=>{j.updateSettings({notificationSoundEnabled:a}),a&&ws(u.notificationSoundVolume,u.toneNotification)}})]}),u.notificationSoundEnabled&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Notification sound volume",query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:ds,step:"1",value:u.notificationSoundVolume,onChange:a=>{const E=parseInt(a.target.value);j.updateSettings({notificationSoundVolume:E}),Ss(E,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(C,{text:"Sounds per event",query:t})}),e.jsx("div",{className:"config-sound-hint",children:'Pick a tone for each event — or upload your own file (mp3, wav, ogg, m4a — max 5MB), which is stored on the commander so every device hears it. "None" silences that event.'}),Je.map(a=>{var ge;const E=!!v[a.kind],K=u[a.settingKey],oe=E&&K===_e;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${oe?" custom":""}`,children:oe?"Your file":((ge=Et(K))==null?void 0:ge.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:K,onChange:de=>{const Ee=de.target.value;j.updateSettings({[a.settingKey]:Ee}),We(Ee,u.notificationSoundVolume,a.kind)},children:[E&&e.jsx("option",{value:_e,children:"Your uploaded file"}),Pt.map(de=>e.jsx("option",{value:de.id,children:de.label},de.id))]}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void We(K,u.notificationSoundVolume,a.kind),disabled:us(K),title:us(K)?"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:[b===a.kind?"Uploading…":"Upload",e.jsx("input",{type:"file",accept:"audio/*",style:{display:"none"},onChange:de=>{var cs;const Ee=(cs=de.target.files)==null?void 0:cs[0];de.target.value="",Ee&&U(a.kind,Ee)}})]}),E&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void X(a.kind),title:"Delete your file and go back to a built-in tone",children:"Reset"})]})]},a.kind)}),M&&e.jsx("div",{className:"config-sound-error",children:M})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.externalEditor"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.externalEditorPlaceholder"),value:u.externalEditorCommand||"",onChange:a=>j.updateSettings({externalEditorCommand:a.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.tabTitle"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.tabTitlePlaceholder"),value:u.tabTitle||"",onChange:a=>j.updateSettings({tabTitle:a.target.value})})]}),e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{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:q,onChange:a=>Y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&ss()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ss,disabled:!ps(q),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(C,{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 E;if(a==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const K=navigator.language,oe=((E=Xe.find(ge=>ge.value!=="auto"&&K.startsWith(ge.value.split("-")[0])))==null?void 0:E.value)||"en";Ge.changeLanguage(oe)}else localStorage.setItem("tide-commander-language-mode","manual"),Ge.changeLanguage(a)}})]})]}),_("agentNames")&&e.jsx(H,{title:o("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:J&&_("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:ue.length>0?o("config:agentNames.customConfigured",{count:ue.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:k,onChange:a=>se(a.target.value),onKeyDown:a=>{a.key==="Enter"&&V()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:V,disabled:!k.trim(),title:o("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:f.map((a,E)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:a}),ue.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>re(a),title:o("common:buttons.remove"),children:"x"})]},`${a}-${E}`))}),ue.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:Ne,children:o("common:buttons.resetToDefaults")})]})}),_("defaultClass")&&e.jsx(H,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:J&&_("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${g==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{T("random"),Ue(Pe.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(_t).map(([a,E])=>e.jsx("div",{className:`agent-name-chip${g===a?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{T(a),Ue(Pe.DEFAULT_AGENT_CLASS,a)},children:e.jsxs("span",{className:"agent-name-text",children:[E.icon," ",a.charAt(0).toUpperCase()+a.slice(1)]})},a)),A.map(a=>e.jsx("div",{className:`agent-name-chip${g===a.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{T(a.id),Ue(Pe.DEFAULT_AGENT_CLASS,a.id)},children:e.jsxs("span",{className:"agent-name-text",children:[a.icon," ",a.name]})},a.id))]})]})}),_("appearance")&&e.jsx(H,{title:o("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:J&&_("appearance"),children:e.jsx(va,{})}),_("connection")&&e.jsxs(H,{title:o("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:J&&_("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:y.map((a,E)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:o("config:connection.priorityLabel",{defaultValue:"Priority"}),children:E+1}),e.jsx("span",{className:"backend-url-text",title:a,children:a}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>as(E,-1),disabled:E===0,title:o("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>as(E,1),disabled:E===y.length-1,title:o("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ds(E),title:o("common:buttons.remove"),children:"x"})]},`${a}-${E}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:$,onChange:a=>z(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:!$.trim(),title:o("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),ne&&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(C,{text:o("config:connection.authToken"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:te?"text":"password",className:"config-input config-input-full",value:w,onChange:a=>Ls(a.target.value),placeholder:o("config:connection.tokenPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&F&&ns()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>P(!te),title:o(te?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(D,{name:te?"eye-closed":"eye",size:14})}),F&&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(C,{text:o("config:connection.codexBinaryPath"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:De,onChange:a=>Os(a.target.value),placeholder:o("config:connection.codexBinaryPathPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&ve&&os()}}),ve&&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(C,{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")})]})]}),_("scene")&&e.jsxs(H,{title:o("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:J&&_("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.characterSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"3.0",step:"0.1",value:s.characterScale,onChange:a=>n({...s,characterScale:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.characterScale.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.scale2d",{defaultValue:"2D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale2d,onChange:a=>n({...s,scale2d:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale2d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.scale3d",{defaultValue:"3D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale3d,onChange:a=>n({...s,scale3d:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale3d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:t})}),e.jsx(ee,{checked:s.show2DTaskLabels,onChange:a=>n({...s,show2DTaskLabels:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.time"),query:t})}),e.jsx(Ce,{options:Ke,value:s.timeMode,onChange:a=>n({...s,timeMode:a}),iconOnly:!0})]})]}),_("terrain")&&e.jsxs(H,{title:o("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:J&&_("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:t})}),e.jsx(ee,{checked:s.terrain.simpleMode??!1,onChange:a=>ye({simpleMode:a})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:Re.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(C,{text:o("config:terrainSettings.fog"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.terrain.fogDensity,onChange:a=>ye({fogDensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?o("config:fogValues.off"):s.terrain.fogDensity<=1?o("config:fogValues.low"):o("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.brightness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.2",max:"2",step:"0.1",value:s.terrain.brightness,onChange:a=>ye({brightness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?o("config:brightnessValues.dark"):s.terrain.brightness<=1.2?o("config:brightnessValues.normal"):o("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.floor"),query:t})}),e.jsx(Ce,{options:He,value:s.terrain.floorStyle,onChange:a=>ye({floorStyle:a}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.sky"),query:t})}),e.jsx("div",{className:"sky-color-selector",children:Be.map(a=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===a.value?"active":""}`,onClick:()=>ye({skyColor:a.value}),title:a.label,style:{background:a.color}},a.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.battlefieldSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:a=>ye({battlefieldSize:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),_("modelStyle")&&e.jsxs(H,{title:o("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:J&&_("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.saturation"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.modelStyle.saturation,onChange:a=>we({saturation:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?o("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?o("config:saturationValues.normal"):o("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.roughness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.roughness,onChange:a=>we({roughness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?o("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?o("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?o("config:roughnessValues.normal"):o("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.metalness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.metalness,onChange:a=>we({metalness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?o("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?o("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?o("config:metalnessValues.mixed"):o("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.glow"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"1",step:"0.05",value:s.modelStyle.emissiveBoost,onChange:a=>we({emissiveBoost:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?o("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?o("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?o("config:glowValues.med"):o("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.reflections"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"2",step:"0.1",value:s.modelStyle.envMapIntensity,onChange:a=>we({envMapIntensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?o("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?o("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?o("config:reflectionValues.normal"):o("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.wireframe"),query:t})}),e.jsx(ee,{checked:s.modelStyle.wireframe,onChange:a=>we({wireframe:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.colorMode"),query:t})}),e.jsx(Ce,{options:Fe,value:s.modelStyle.colorMode,onChange:a=>we({colorMode:a}),iconOnly:!0})]})]}),_("animations")&&e.jsxs(H,{title:o("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:J&&_("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:animationSettings.idle"),query:t})}),e.jsx(Ce,{options:Oe,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(C,{text:o("config:animationSettings.working"),query:t})}),e.jsx(Ce,{options:Oe,value:s.animations.workingAnimation,onChange:a=>is({workingAnimation:a}),iconOnly:!0})]})]}),_("secrets")&&e.jsx(H,{title:o("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:J&&_("secrets"),children:e.jsx(Zt,{})}),_("claudeAccounts")&&e.jsx(H,{title:o("config:sections.claudeAccounts",{defaultValue:"Claude Accounts"}),storageKey:"claudeAccounts",defaultOpen:!1,forceOpen:J&&_("claudeAccounts"),children:e.jsx(It,{})}),_("grokAccounts")&&e.jsx(H,{title:o("config:sections.grokAccounts",{defaultValue:"Grok Accounts"}),storageKey:"grokAccounts",defaultOpen:!1,forceOpen:J&&_("grokAccounts"),children:e.jsx(hs,{provider:"grok"})}),_("codexAccounts")&&e.jsx(H,{title:o("config:sections.codexAccounts",{defaultValue:"Codex Accounts"}),storageKey:"codexAccounts",defaultOpen:!1,forceOpen:J&&_("codexAccounts"),children:e.jsx(hs,{provider:"codex"})}),_("systemPrompt")&&e.jsx(H,{title:o("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:J&&_("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>ce(!0),children:o("config:systemPrompt.editPrompt")})]})}),_("data")&&e.jsx(H,{title:o("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:J&&_("data"),children:e.jsx(ja,{})}),_("integrations")&&e.jsx(H,{title:o("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:J&&_("integrations"),children:e.jsx(Ta,{onOpenModal:a=>{a==="whatsapp"?me(!0):i==null||i(a)}})}),_("workflows")&&e.jsxs(H,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:J&&_("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Create and manage automated workflow pipelines with visual state machine editor",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>m==null?void 0:m(),children:"Open Workflow Editor"})})]}),_("triggers")&&e.jsxs(H,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:J&&_("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Create and manage event-driven triggers that fire agents with templates",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>h==null?void 0:h(),children:"Open Trigger Manager"})})]}),_("monitoring")&&e.jsxs(H,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:J&&_("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"View event logs, trigger history, workflow traces, and system stats",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>r==null?void 0:r(),children:"Open Monitoring & Logs"})})]}),_("statistics")&&e.jsxs(H,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:J&&_("statistics"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"View token usage charts and system-wide agent statistics",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>c==null?void 0:c(),children:"Open Statistics"})})]}),_("experimental")&&e.jsxs(H,{title:o("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:J&&_("experimental"),children:[e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Lightweight 2D top-down view for better performance",children:[e.jsx(C,{text:o("config:experimental.2dView"),query:t})," ",e.jsx(D,{name:"map",size:12})]}),e.jsx(ee,{checked:u.experimental2DView,onChange:a=>j.updateSettings({experimental2DView:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(C,{text:o("config:experimental.voiceAssistant"),query:t})," ",e.jsx(D,{name:"microphone",size:12})]}),e.jsx(ee,{checked:u.experimentalVoiceAssistant,onChange:a=>j.updateSettings({experimentalVoiceAssistant:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(C,{text:o("config:experimental.tts"),query:t})," ",e.jsx(D,{name:"speaker-on",size:12})]}),e.jsx(ee,{checked:u.experimentalTTS,onChange:a=>j.updateSettings({experimentalTTS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Duplicate system prompt for improved LLM attention coverage. Increases input token usage.",children:e.jsx(C,{text:o("config:experimental.echoPrompt"),query:t})}),e.jsx(ee,{checked:u.experimentalEchoPrompt,onChange:async a=>{j.updateSettings({experimentalEchoPrompt:a});try{await aa(a)}catch(E){console.error("Failed to sync echo prompt setting to server:",E)}}})]}),e.jsx("span",{className:"config-hint",children:o("config:experimental.hint")})]}),_("about")&&e.jsx(H,{title:o("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:J&&_("about"),children:e.jsx(Ca,{})})]}),e.jsx(Ea,{isOpen:ie,onClose:()=>ce(!1)}),e.jsx(Da,{isOpen:le,onClose:()=>he(!1)}),e.jsx(Ra,{isOpen:Ae,onClose:()=>Se(!1)}),e.jsx(Za,{isOpen:pe,onClose:()=>Te(!1)}),e.jsx(Qa,{isOpen:je,onClose:()=>me(!1),onOpenConfig:()=>he(!0),onOpenNotifications:()=>Se(!0),onOpenHistory:()=>Te(!0)})]})}function xn({onConfigChange:s,onToolChange:n,config:t,isOpen:i,onClose:d,initialSearchQuery:r,onOpenBuildingModal:c,onOpenAreaExplorer:m,onOpenIntegrationsModal:h,onOpenPluginsModal:o,onOpenMonitoringModal:u,onOpenStatisticsModal:A,onOpenWorkflowEditor:g,onOpenTriggerManager:T}){const{t:x}=Z(["config","common"]),I=Ot(),v=Ft(),p=Rt(),b=Bt(),R=Mt(),M=Array.from(I.values()),G=Array.from(v.values()),[q,Y]=l.useState(""),U=l.useRef(null);if(l.useEffect(()=>{const y=O=>{O.key==="Escape"&&i&&d()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[i,d]),l.useEffect(()=>{i&&Y(r??"")},[i,r]),l.useEffect(()=>{if(i&&U.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const O=setTimeout(()=>{var ne;(ne=U.current)==null||ne.focus()},50);return()=>clearTimeout(O)}},[i]),!i)return null;const X=y=>{n(R===y?null:y)},S=y=>{j.selectArea(b===y?null:y),n("select")},B=(y,O)=>{y.stopPropagation(),j.deleteArea(O)};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:x("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:x("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:U,type:"text",placeholder:x("config:searchPlaceholder"),value:q,onChange:y=>Y(y.target.value),className:"toolbox-search-input"}),q&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>Y(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(H,{title:x("config:areas.title",{count:M.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${R==="select"?"active":""}`,onClick:()=>X("select"),title:x("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 ${R==="rectangle"?"active":""}`,onClick:()=>X("rectangle"),title:x("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 ${R==="circle"?"active":""}`,onClick:()=>X("circle"),title:x("config:tools.circle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("circle",{cx:"12",cy:"12",r:"9"})})})})]}),e.jsx("div",{className:"areas-list",children:M.length===0?e.jsx("div",{className:"areas-empty",children:x("config:areas.drawToCreate")}):M.map(y=>e.jsx(Wt,{area:y,isSelected:b===y.id,onClick:()=>S(y.id),onDelete:O=>B(O,y.id)},y.id))})]})}),b&&e.jsx(Xt,{area:I.get(b),onClose:()=>j.selectArea(null),onOpenFolder:m}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(H,{title:x("config:buildings.title",{count:G.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:y=>{y.stopPropagation(),c==null||c()},title:x("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:G.length===0?e.jsx("div",{className:"buildings-empty",children:x("config:buildings.clickToAdd")}):G.map(y=>e.jsx(Gt,{building:y,isSelected:p.has(y.id),onClick:()=>{j.selectBuilding(p.has(y.id)?null:y.id)},onEdit:()=>c==null?void 0:c(y.id)},y.id))})})}),p.size===1&&(()=>{const y=Array.from(p)[0],O=v.get(y);return O?e.jsx(Yt,{building:O,onClose:()=>j.selectBuilding(null),onOpenModal:()=>c==null?void 0:c(y)}):null})(),e.jsx(un,{config:t,onChange:s,searchQuery:q,onOpenIntegrationsModal:h,onOpenPluginsModal:o,onOpenMonitoringModal:u,onOpenStatisticsModal:A,onOpenWorkflowEditor:g,onOpenTriggerManager:T})]})]})]})}export{xn as Toolbox};