tide-commander 1.223.0 → 1.224.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 +22 -0
  2. package/dist/assets/{AudioPlayer-CjX0NnDG.js → AudioPlayer-CS32DiiF.js} +1 -1
  3. package/dist/assets/{BossLogsModal-neHd1jxq.js → BossLogsModal-CuiASPjO.js} +1 -1
  4. package/dist/assets/{BossSpawnModal-Bb5bU6M8.js → BossSpawnModal-BFG6WMHP.js} +1 -1
  5. package/dist/assets/{ControlsModal-BEKZK4fK.js → ControlsModal-suKdgBAJ.js} +1 -1
  6. package/dist/assets/{DockerLogsModal-C1ZIanzC.js → DockerLogsModal-CIY242F2.js} +1 -1
  7. package/dist/assets/{EmbeddedEditor-DWgHQwj1.js → EmbeddedEditor-Bu-NinV4.js} +1 -1
  8. package/dist/assets/{FcStdViewer-CvFBDWIv.js → FcStdViewer-B_ZUSI2J.js} +1 -1
  9. package/dist/assets/{GcodeViewer-CcVaZxR7.js → GcodeViewer-BUz7zxIl.js} +1 -1
  10. package/dist/assets/{GlbViewer-kF1-oHLk.js → GlbViewer-CNR1g2NS.js} +1 -1
  11. package/dist/assets/{GmailOAuthSetup-CeMu3b9k.js → GmailOAuthSetup-Dj81j7pf.js} +1 -1
  12. package/dist/assets/{GoogleOAuthSetup-CW7ov3JO.js → GoogleOAuthSetup-vbnnwez5.js} +1 -1
  13. package/dist/assets/{IframeModal-DhbsVRJn.js → IframeModal-BCC6ZdKx.js} +1 -1
  14. package/dist/assets/{IntegrationsPanel-DKMStfuq.js → IntegrationsPanel-CY3lUNI1.js} +2 -2
  15. package/dist/assets/{LogViewerModal-Dk3KmPRY.js → LogViewerModal-CW81dfO6.js} +1 -1
  16. package/dist/assets/{MonitoringModal-BSYKhukp.js → MonitoringModal-CwS3yQ7M.js} +1 -1
  17. package/dist/assets/{PM2LogsModal-CJ8Cn9t8.js → PM2LogsModal-MvDxO2TF.js} +1 -1
  18. package/dist/assets/{PluginsPanel-DQv9Xrsn.js → PluginsPanel-Br7cw4J1.js} +1 -1
  19. package/dist/assets/{RestoreArchivedAreaModal-wn8YPSY7.js → RestoreArchivedAreaModal-DEuz0Tmk.js} +1 -1
  20. package/dist/assets/{Scene2DCanvas-DBs2O0PC.js → Scene2DCanvas-46rDN8dN.js} +1 -1
  21. package/dist/assets/{SceneManager-WRjeyaRk.js → SceneManager-CDr5_lQH.js} +1 -1
  22. package/dist/assets/{SkillsPanel-DimvGKrN.js → SkillsPanel-DIeRNRtF.js} +1 -1
  23. package/dist/assets/{SlackMultiInstanceSetup-cTN3v2At.js → SlackMultiInstanceSetup-C8U0OpPi.js} +1 -1
  24. package/dist/assets/{SpawnModal-BgdP5LBE.js → SpawnModal-BMmCif0b.js} +1 -1
  25. package/dist/assets/{StatisticsModal-jyA2UpM-.js → StatisticsModal-BBcwwM9a.js} +1 -1
  26. package/dist/assets/{StlViewer-BTQCSdFg.js → StlViewer-Y6Q9LV4g.js} +1 -1
  27. package/dist/assets/{SubordinateAssignmentModal-BJCTarDM.js → SubordinateAssignmentModal-CxBrkrsy.js} +1 -1
  28. package/dist/assets/{ThreeAreaSelector-Bz_OPTco.js → ThreeAreaSelector-jdePYE0s.js} +1 -1
  29. package/dist/assets/{ThreeViewShortcuts-aC84L8xB.js → ThreeViewShortcuts-fQ1LZj-k.js} +1 -1
  30. package/dist/assets/{TriggerManagerPanel-CRy8hS_2.js → TriggerManagerPanel-DFijjhCA.js} +1 -1
  31. package/dist/assets/{VideoPlayer-BB4cSwPZ.js → VideoPlayer--W7gA51W.js} +1 -1
  32. package/dist/assets/{WorkflowEditorPanel-JG3EfQ-c.js → WorkflowEditorPanel-B5AhOJD7.js} +1 -1
  33. package/dist/assets/{abnfDiagram-VRR7QNED-BIymdJ82.js → abnfDiagram-VRR7QNED-BaTbSF7k.js} +1 -1
  34. package/dist/assets/{arc--DARpxJq.js → arc-BST2bg1n.js} +1 -1
  35. package/dist/assets/{architectureDiagram-ZJ3FMSHR-Ur0IHTuT.js → architectureDiagram-ZJ3FMSHR-Cg4xwkXg.js} +1 -1
  36. package/dist/assets/{area-logos-CVOcCaKt.js → area-logos-BFSIooyB.js} +1 -1
  37. package/dist/assets/{blockDiagram-677ZJIJ3-CmNjZc5F.js → blockDiagram-677ZJIJ3-Cv21hNY1.js} +1 -1
  38. package/dist/assets/{c4Diagram-LMCZKHZV-B4GHw6__.js → c4Diagram-LMCZKHZV-DRMk82uY.js} +1 -1
  39. package/dist/assets/channel-oEvwVeL5.js +1 -0
  40. package/dist/assets/{chunk-2Q5K7J3B-BBErXFBl.js → chunk-2Q5K7J3B-Cino9QTV.js} +1 -1
  41. package/dist/assets/{chunk-32BRIVSS-C2qUOlfT.js → chunk-32BRIVSS-K9CkGCF3.js} +1 -1
  42. package/dist/assets/{chunk-5VM5RSS4-r9xckJVE.js → chunk-5VM5RSS4-wSG2aCSB.js} +1 -1
  43. package/dist/assets/{chunk-EX3LRPZG-DYUFM6Kx.js → chunk-EX3LRPZG-DiP8GRRE.js} +1 -1
  44. package/dist/assets/{chunk-JWPE2WC7-BUC08AKL.js → chunk-JWPE2WC7-C2T4HdGo.js} +1 -1
  45. package/dist/assets/{chunk-MOJQB5TN-C0yNMKSS.js → chunk-MOJQB5TN-K6VUUce6.js} +1 -1
  46. package/dist/assets/{chunk-RYQCIY6F-DF0DipHM.js → chunk-RYQCIY6F-CwUKwfrO.js} +1 -1
  47. package/dist/assets/{chunk-V7JOEXUC-B48QcHmS.js → chunk-V7JOEXUC-Do7m7In-.js} +1 -1
  48. package/dist/assets/{chunk-VR4S4FIN-Cah567yW.js → chunk-VR4S4FIN-C3sjuCSc.js} +1 -1
  49. package/dist/assets/{chunk-XXDRQBXY-Cyo-LR80.js → chunk-XXDRQBXY-aWtL9GIN.js} +1 -1
  50. package/dist/assets/classDiagram-OUVF2IWQ-3O7V3aga.js +1 -0
  51. package/dist/assets/classDiagram-v2-EOCWNBFH-3O7V3aga.js +1 -0
  52. package/dist/assets/{cose-bilkent-JH36ORCC-BoyB947B.js → cose-bilkent-JH36ORCC-DPZ-w5xz.js} +1 -1
  53. package/dist/assets/{cynefin-VYW2F7L2-DFPaQ9Zf.js → cynefin-VYW2F7L2-BIsWEfjH.js} +1 -1
  54. package/dist/assets/{cynefinDiagram-TSTJHNR4-B2MZ8ySp.js → cynefinDiagram-TSTJHNR4-DQc1SjqU.js} +1 -1
  55. package/dist/assets/{dagre-VKFMJZFB-NwVkWGfv.js → dagre-VKFMJZFB-CSQALpAg.js} +1 -1
  56. package/dist/assets/{default-agent-skills-B6BhakPb.js → default-agent-skills-hW2YTtT1.js} +1 -1
  57. package/dist/assets/{diagram-FQU43EPY-5f6e6NP-.js → diagram-FQU43EPY-Co8RC7NC.js} +1 -1
  58. package/dist/assets/{diagram-G47NLZAW-C-OBe1ja.js → diagram-G47NLZAW-C1h1rqbG.js} +1 -1
  59. package/dist/assets/{diagram-NH7WQ7WH-GLMOuSN-.js → diagram-NH7WQ7WH-DzStYMvA.js} +1 -1
  60. package/dist/assets/{diagram-OA4YK3LP-BwhAYhbr.js → diagram-OA4YK3LP-Bnga2eI1.js} +1 -1
  61. package/dist/assets/{diagram-WEI45ONY-n4IRaNvB.js → diagram-WEI45ONY-DtML0qBL.js} +1 -1
  62. package/dist/assets/{ebnfDiagram-CCIWWBDH-BRSu16Iy.js → ebnfDiagram-CCIWWBDH-srK1jz3r.js} +1 -1
  63. package/dist/assets/{erDiagram-Q63AITRT-qsCMupOZ.js → erDiagram-Q63AITRT-BYnoRg9S.js} +1 -1
  64. package/dist/assets/{flowDiagram-23GEKE2U-C8Jfgc5Q.js → flowDiagram-23GEKE2U-COT9xZWU.js} +1 -1
  65. package/dist/assets/{ganttDiagram-NO4QXBWP-CT9Xx98f.js → ganttDiagram-NO4QXBWP-DNHD_H8t.js} +1 -1
  66. package/dist/assets/{gitGraphDiagram-IHSO6WYX-Coi5KukC.js → gitGraphDiagram-IHSO6WYX-BWLh25rZ.js} +1 -1
  67. package/dist/assets/{index-CZItdiJG.js → index-BDMDSPRK.js} +1 -1
  68. package/dist/assets/{index-BP5FFBEx.js → index-BlH_HQ25.js} +1 -1
  69. package/dist/assets/{index-vi6NXwpa.js → index-BxVyMj4V.js} +1 -1
  70. package/dist/assets/{index-XRPTKib1.js → index-C2-8cspl.js} +1 -1
  71. package/dist/assets/{index-CIu--mJr.js → index-DZ7ozYBG.js} +1 -1
  72. package/dist/assets/{index-Xt8XgRzK.js → index-Dvs3ntB2.js} +1 -1
  73. package/dist/assets/{index-DUDeXZ0I.js → index-FV2om2lX.js} +2 -2
  74. package/dist/assets/index-NEWtG02D.js +1 -0
  75. package/dist/assets/{index-GbqO5CFI.js → index-cGbqyuV8.js} +3 -3
  76. package/dist/assets/{infoDiagram-FWYZ7A6U-DwRsLIbg.js → infoDiagram-FWYZ7A6U-CwYFYRFg.js} +1 -1
  77. package/dist/assets/{ishikawaDiagram-FXEZZL3T-BJHzTkEA.js → ishikawaDiagram-FXEZZL3T-BwkPIKzg.js} +1 -1
  78. package/dist/assets/{journeyDiagram-5HDEW3XC-DSbYpqKW.js → journeyDiagram-5HDEW3XC-C9arAZ8y.js} +1 -1
  79. package/dist/assets/{kanban-definition-HUTT4EX6-095PTicj.js → kanban-definition-HUTT4EX6-6wTmayoj.js} +1 -1
  80. package/dist/assets/{linear-CfqVr0Ja.js → linear-Dj4zYq3h.js} +1 -1
  81. package/dist/assets/main-sBSI_4k0.js +372 -0
  82. package/dist/assets/{mermaid.core-Cd-X-VQG.js → mermaid.core-Bq0L11_-.js} +4 -4
  83. package/dist/assets/{mindmap-definition-LN4V7U3C-BKaq73lx.js → mindmap-definition-LN4V7U3C-CxIXLa8F.js} +1 -1
  84. package/dist/assets/{pegDiagram-2B236MQR-D8G4w9gD.js → pegDiagram-2B236MQR-CrPAdYQD.js} +1 -1
  85. package/dist/assets/{pieDiagram-ENE6RG2P-COmE0H9d.js → pieDiagram-ENE6RG2P-D3EP1YJI.js} +1 -1
  86. package/dist/assets/{quadrantDiagram-ABIIQ3AL-ZN6VYk1I.js → quadrantDiagram-ABIIQ3AL-CWkbCwdX.js} +1 -1
  87. package/dist/assets/{railroadDiagram-RFXS5EU6-BE9p17T6.js → railroadDiagram-RFXS5EU6-z0g5DBHp.js} +1 -1
  88. package/dist/assets/{requirementDiagram-TGXJPOKE-YeG4gM4-.js → requirementDiagram-TGXJPOKE-CiMiX_JJ.js} +1 -1
  89. package/dist/assets/{sankeyDiagram-HTMAVEWB-x0VZ9b3K.js → sankeyDiagram-HTMAVEWB-BmOS9QdD.js} +1 -1
  90. package/dist/assets/{sequenceDiagram-DBY2YBRQ-D1kkFLHj.js → sequenceDiagram-DBY2YBRQ-C7RoHZtD.js} +1 -1
  91. package/dist/assets/{sizeCapture-X5ZJPWSS-CCOED7Lw.js → sizeCapture-X5ZJPWSS-Caj9tBBH.js} +1 -1
  92. package/dist/assets/{stateDiagram-2N3HPSRC-BVqCnbwf.js → stateDiagram-2N3HPSRC-DWIQWBNS.js} +1 -1
  93. package/dist/assets/stateDiagram-v2-6OUMAXLB-Q7zbcB30.js +1 -0
  94. package/dist/assets/{swimlanes-5IMT3BWC-BASSCXvz.js → swimlanes-5IMT3BWC-Cb4faLOv.js} +2 -2
  95. package/dist/assets/swimlanesDiagram-G3AALYLV-DZKxmgt5.js +8 -0
  96. package/dist/assets/{timeline-definition-FHXFAJF6-uL1WYIPG.js → timeline-definition-FHXFAJF6-CVizZxxU.js} +1 -1
  97. package/dist/assets/{vennDiagram-L72KCM5P-DtbBUscM.js → vennDiagram-L72KCM5P-DadCc6f6.js} +1 -1
  98. package/dist/assets/{wardleyDiagram-EHGQE667-TvRREmtU.js → wardleyDiagram-EHGQE667-l7-xE64R.js} +1 -1
  99. package/dist/assets/{web-DEnNRcGv.js → web-CSVD8nk7.js} +1 -1
  100. package/dist/assets/{web-D7rM8t54.js → web-CnZQAYa5.js} +1 -1
  101. package/dist/assets/{web-DbGcg2p6.js → web-DIdAF8p4.js} +1 -1
  102. package/dist/assets/{xychartDiagram-FW5EYKEG-CdXxeP-q.js → xychartDiagram-FW5EYKEG-CFZA5bRS.js} +1 -1
  103. package/dist/build-info.json +1 -1
  104. package/dist/index.html +1 -1
  105. package/dist/src/packages/server/claude/backend.js +21 -0
  106. package/dist/src/packages/server/claude/interactive/interactive-backend-args.js +6 -0
  107. package/dist/src/packages/server/claude/runner.js +73 -6
  108. package/dist/src/packages/server/claude/session-recovery.js +56 -0
  109. package/dist/src/packages/server/data/builtin-skills/boss-instructions.js +1 -1
  110. package/dist/src/packages/server/routes/notifications.js +11 -53
  111. package/dist/src/packages/server/services/agent-notifications.js +67 -0
  112. package/dist/src/packages/server/services/llm-matcher-service.js +4 -1
  113. package/dist/src/packages/server/services/runtime-events.js +72 -0
  114. package/dist/src/packages/shared/agent-types.js +8 -2
  115. package/dist/src/packages/shared/model-freshness.js +9 -7
  116. package/package.json +1 -1
  117. package/dist/assets/channel-DE7sZiOX.js +0 -1
  118. package/dist/assets/classDiagram-OUVF2IWQ-DEZtwip7.js +0 -1
  119. package/dist/assets/classDiagram-v2-EOCWNBFH-DEZtwip7.js +0 -1
  120. package/dist/assets/index-dwe7nfIh.js +0 -1
  121. package/dist/assets/main-C661hDwF.js +0 -372
  122. package/dist/assets/stateDiagram-v2-6OUMAXLB-DKzYyGyb.js +0 -1
  123. package/dist/assets/swimlanesDiagram-G3AALYLV-1ocner1k.js +0 -8
@@ -1 +1 @@
1
- import{r as i,j as e,I as L,u as Z,cg as js,ax as vs,ch as Bs,cj as Ms,s as v,dj as Us,F as zs,dk as Vs,a5 as be,Y as Q,ah as Y,c as fe,d as xe,i as Ks,dl as Hs,dm as qs,dn as Ws,dp as Gs,dq as Ys,dr as Js,ds as Xs,dt as Ns,du as Zs,dv as Qs,dw as et,b6 as st,dx as tt,dy as at,dz as nt,dA as ot,aK as it,ac as Ie,E as lt,dB as ys,dC as ct,dD as Ze,dE as rt,dF as dt,dG as ut,dH as pt,dI as ht,dJ as mt,dK as gt,bx as ft,k as xt,m as bt,S as Pe,dL as jt,dM as vt,dN as Nt,dO as qe,dP as yt,dQ as wt,B as St,cl as rs,dR as kt,dS as Ct,dT as At,dU as Tt,dV as ws,dW as ds,dX as Ss,dY as Et,dZ as Pt,d_ as _e,d$ as _t,e0 as We,e1 as us,e2 as ps,cc as Ge,R as Ue,Q as It,e3 as Ye,e4 as Dt,e5 as hs,e6 as $t,e7 as Lt,e8 as Ot,a8 as Ft,f as Rt,e9 as Bt,ea as Mt,eb as Ut}from"./main-C661hDwF.js";import{g as zt,d as Vt,u as Kt}from"./area-logos-CVOcCaKt.js";import{u as Ht,a as qt,b as Wt}from"./default-agent-skills-B6BhakPb.js";import{s as Gt}from"./settingsSearch-Cv7ya9n1.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-GtkNAxzd.js";const ks="tide-toolbox-collapse";function Yt(s,n){try{const t=localStorage.getItem(`${ks}-${s}`);if(t!==null)return t==="true"}catch{}return n}function Jt(s,n){try{localStorage.setItem(`${ks}-${s}`,String(n))}catch{}}function W({title:s,storageKey:n,defaultOpen:t=!1,forceOpen:l=!1,children:d,headerExtra:r}){const[c,m]=i.useState(()=>n?Yt(n,t):t),h=()=>{const u=!c;m(u),n&&Jt(n,u)},o=l||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(L,{name:o?"caret-down":"caret-right",size:10})})]})]}),o&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Xt({area:s,isSelected:n,onClick:t,onDelete:l}){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:l,title:d("config:areas.deleteArea"),children:"×"})]})}function Zt({building:s,isSelected:n,onClick:t,onEdit:l}){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(L,{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(),l()},title:d("config:buildings.editBuilding"),children:e.jsx(L,{name:"gear",size:14})})]})}function Qt({building:s,onClose:n,onOpenModal:t}){var o,u,k,g,E,f,I,j;const{t:l}=Z(["config","common"]),r=Bs().get(s.id)||[],c=Ms[s.style||"server-rack"],m=p=>{v.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(L,{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:l("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:l("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:l("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:l("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)||l("config:buildings.noStartCommand"),children:[e.jsx(L,{name:"play",size:12})," ",l("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>m("stop"),disabled:!((k=s.commands)!=null&&k.stop)||s.status==="stopped",title:((g=s.commands)==null?void 0:g.stop)||l("config:buildings.noStopCommand"),children:[e.jsx(L,{name:"stop",size:12,weight:"fill"})," ",l("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>m("restart"),disabled:!((E=s.commands)!=null&&E.restart),title:((f=s.commands)==null?void 0:f.restart)||l("config:buildings.noRestartCommand"),children:[e.jsx(L,{name:"refresh",size:12})," ",l("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>m("healthCheck"),disabled:!((I=s.commands)!=null&&I.healthCheck),title:((j=s.commands)==null?void 0:j.healthCheck)||l("config:buildings.noHealthCheck"),children:[e.jsx(L,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:l("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(L,{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:[l("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>v.clearBuildingLogs(s.id),title:l("common:buttons.clear"),children:l("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(L,{name:"gear",size:12})," ",l("config:buildings.fullSettings")]})})]})}const ea=[{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 sa({area:s,onClose:n,onOpenFolder:t}){var ne;const{t:l}=Z(["config","common"]),[d,r]=i.useState(s.name),[c,m]=i.useState(s.prompt||""),[h,o]=i.useState(!1),[u,k]=i.useState(""),[g,E]=i.useState(!1),f=i.useRef(null);i.useEffect(()=>{r(s.name)},[s.id,s.name]),i.useEffect(()=>{m(s.prompt||"")},[s.id,s.prompt]);const I=y=>{const O=y.target.value;r(O),v.updateArea(s.id,{name:O})},j=y=>{v.updateArea(s.id,{color:y})},p=y=>{const O=y.target.value;m(O),v.updateArea(s.id,{prompt:O})},b=()=>{u.trim()&&(v.addDirectoryToArea(s.id,u.trim()),k(""),o(!1))},N=(y,O)=>{O.stopPropagation(),v.removeDirectoryFromArea(s.id,y)},$=()=>{v.bringAreaToFront(s.id)},U=()=>{v.sendAreaToBack(s.id)},K=i.useCallback(()=>{let y=2,O=2;s.type==="rectangle"&&s.width&&s.height?(y=s.width,O=s.height):s.type==="circle"&&s.radius&&(y=s.radius*1.414,O=s.radius*1.414);const V=Math.min(y,O)*.4;return{width:Math.round(V*10)/10,height:Math.round(V*10)/10}},[s.type,s.width,s.height,s.radius]),J=async y=>{var V;const O=(V=y.target.files)==null?void 0:V[0];if(O){E(!0);try{const S=await Kt(s.id,O),F=K();v.updateArea(s.id,{logo:{filename:S.filename,position:"center",width:F.width,height:F.height,keepAspectRatio:!0,opacity:.8}})}catch(S){console.error("Failed to upload logo:",S)}finally{E(!1),f.current&&(f.current.value="")}}},z=async()=>{try{await Vt(s.id),v.updateArea(s.id,{logo:void 0})}catch(y){console.error("Failed to remove logo:",y)}},X=y=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,position:y}})},C=y=>{if(!s.logo)return;const O=parseFloat(y.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const V=s.logo.height/s.logo.width;v.updateArea(s.id,{logo:{...s.logo,width:O,height:Math.round(O*V*10)/10}})}else v.updateArea(s.id,{logo:{...s.logo,width:O}})},M=y=>{if(!s.logo)return;const O=parseFloat(y.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const V=s.logo.width/s.logo.height;v.updateArea(s.id,{logo:{...s.logo,height:O,width:Math.round(O*V*10)/10}})}else v.updateArea(s.id,{logo:{...s.logo,height:O}})},w=()=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},R=y=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(y.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:l("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:l("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange:I,placeholder:l("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:l("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:Us.map(y=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===y?"selected":""}`,style:{backgroundColor:y},onClick:()=>j(y),"aria-label":`Set area color ${y}`,"aria-pressed":s.color===y,title:y},y))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:l("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:$,title:l("config:areas.bringToFront"),children:[e.jsx(L,{name:"arrow-up",size:12})," ",l("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:U,title:l("config:areas.sendToBack"),children:[e.jsx(L,{name:"arrow-down",size:12})," ",l("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:l("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:zt(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:z,children:l("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var y;return(y=f.current)==null?void 0:y.click()},disabled:g,children:g?"...":e.jsx(L,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:l("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:ea.map(({key:y,labelKey:O})=>{var V;return e.jsx("button",{className:`area-logo-pos-btn ${((V=s.logo)==null?void 0:V.position)===y?"active":""}`,onClick:()=>X(y),children:l(`config:areas.${O}`)},y)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:l("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:l("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:C,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:l("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:M,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:l("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:w}),l("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:l("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:R,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 y;return(y=f.current)==null?void 0:y.click()},disabled:g,children:g?"...":l("config:areas.uploadLogo")}),e.jsx("input",{ref:f,type:"file",accept:"image/*",style:{display:"none"},onChange:J})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:l("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(y=>e.jsxs("div",{className:"area-folder-item",title:y,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:l("config:areas.openFolder"),children:e.jsx(L,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:y.split("/").pop()||y}),e.jsx("button",{className:"area-folder-remove",onClick:O=>N(y,O),title:l("config:areas.removeFolder"),children:"×"})]},y)),h?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(zs,{value:u,onChange:k,onSubmit:b,placeholder:l("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:l("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:l("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:c,onChange:p,placeholder:l("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:l("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:l("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:l("config:areas.rightClickUnassign")})]})]})}function ta(){const{t:s}=Z(["config","common"]),n=Vs(),[t,l]=i.useState(!1),[d,r]=i.useState(null),[c,m]=i.useState({name:"",key:"",value:"",description:""}),[h,o]=i.useState(null),u=()=>{l(!0),r(null),m({name:"",key:"",value:"",description:""})},k=p=>{r(p.id),l(!1),m({name:p.name,key:p.key,value:p.value,description:p.description||""})},g=()=>{l(!1),r(null),m({name:"",key:"",value:"",description:""})},E=()=>{!c.name.trim()||!c.key.trim()||(d?v.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}):v.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())},f=p=>{o(p)},I=()=>{h&&(v.deleteSecret(h),d===h&&g())},j=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:()=>j(p.key),title:s("config:secrets.copyPlaceholder"),children:`{{${p.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>k(p),title:s("common:buttons.edit"),children:e.jsx(L,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>f(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:E,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 aa(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch system prompt: ${n.statusText}`);return(await n.json()).prompt||""}async function na(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function oa(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to clear system prompt: ${n.statusText}`)}async function ia(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch echo prompt setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function la(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function ca(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex binary path: ${n.statusText}`);return(await n.json()).path||""}async function ra(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function da(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch tmux mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ua(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function pa(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch interactive mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ha(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function ma(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/codex-app-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex app-server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ga(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/codex-app-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update codex app-server mode setting: ${t.statusText}`)}async function fa(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/opencode-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch opencode server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function xa(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/opencode-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update opencode server mode setting: ${t.statusText}`)}async function ba(){const s=Q(),n=await fetch(`${Y()}/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 ja(s){const n=Q(),t=await fetch(`${Y()}/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 va(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch backup status: ${n.statusText}`);return n.json()}async function Na(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok){const l=await t.json().catch(()=>({}));throw new Error(l.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function ya({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:l=>n(l.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function wa(){const{t:s}=Z(["config","common"]),[n,t]=i.useState([]),[l,d]=i.useState(new Set),[r,c]=i.useState(new Set),[m,h]=i.useState(!1),[o,u]=i.useState(!1),[k,g]=i.useState(null),[E,f]=i.useState(null),[I,j]=i.useState(null),[p,b]=i.useState(null),[N,$]=i.useState(!1),[U,K]=i.useState(null);i.useEffect(()=>{fe(xe("/api/config/categories")).then(S=>S.json()).then(S=>{const F=Array.isArray(S)?S:[];t(F),d(new Set(F.map(B=>B.id)))}).catch(S=>console.error("Failed to fetch config categories:",S))},[]),i.useEffect(()=>{va().then(b).catch(S=>{console.error("Failed to fetch backup status:",S),K(S.message||"Failed to fetch backup status")})},[]);const J=async S=>{if(!N){$(!0),K(null);try{const F=await Na(S);b(F)}catch(F){K(F.message||"Failed to update backup setting")}finally{$(!1)}}},z=S=>{d(F=>{const B=new Set(F);return B.has(S)?B.delete(S):B.add(S),B})},X=S=>{c(F=>{const B=new Set(F);return B.has(S)?B.delete(S):B.add(S),B})},C=()=>d(new Set(n.map(S=>S.id))),M=()=>d(new Set),w=()=>{E&&c(new Set(E.categories.map(S=>S.id)))},R=()=>c(new Set),ne=async()=>{var S;if(l.size!==0){h(!0),j(null);try{const F=Array.from(l).join(","),B=await fe(xe(`/api/config/export?categories=${F}`));if(!B.ok)throw new Error("Export failed");const ae=await B.blob(),te=window.URL.createObjectURL(ae),D=document.createElement("a");D.href=te;const A=B.headers.get("Content-Disposition"),se=((S=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:S[1])||"tide-commander-config.zip";D.download=se,document.body.appendChild(D),D.click(),document.body.removeChild(D),window.URL.revokeObjectURL(te),j({type:"success",text:s("config:data.exportSuccess")})}catch(F){j({type:"error",text:F.message||"Export failed"})}finally{h(!1)}}},y=async S=>{var B;const F=(B=S.target.files)==null?void 0:B[0];if(F){g(F),j(null),f(null),c(new Set);try{const ae=await fe(xe("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await F.arrayBuffer()});if(!ae.ok){const A=await ae.json();throw new Error(A.error||"Failed to preview config file")}const te=await ae.json(),D=Array.isArray(te.categories)?te.categories:[];f({...te,categories:D}),c(new Set(D.map(A=>A.id)))}catch(ae){j({type:"error",text:ae.message||"Failed to read config file"}),g(null)}}},O=async()=>{if(!(!k||r.size===0)){u(!0),j(null);try{const S=Array.from(r).join(","),F=await fe(xe(`/api/config/import?categories=${S}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await k.arrayBuffer()}),B=await F.json();if(!F.ok)throw new Error(B.error||"Import failed");j({type:"success",text:B.message||s("config:data.importSuccess")}),g(null),f(null),c(new Set)}catch(S){j({type:"error",text:S.message||"Import failed"})}finally{u(!1)}}},V=()=>{g(null),f(null),c(new Set),j(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(ya,{checked:!!(p!=null&&p.enabled),disabled:N||!p,onChange:J})]}),e.jsxs("div",{className:"data-backup-info",children:[p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:p.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!p.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:p.scriptPath})]}),p.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(p.lastRunAt).toLocaleString(),p.lastRunOk===!0&&" — ok",p.lastRunOk===!1&&p.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",p.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),U&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:U})]})]}),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:C,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:M,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:n.map(S=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:l.has(S.id),onChange:()=>z(S.id)}),e.jsx("span",{className:"data-category-name",children:S.name})]},S.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ne,disabled:m||l.size===0,children:m?s("config:data.exporting"):s("config:data.exportCount",{count:l.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),k?E?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:k.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(E.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:w,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:R,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:E.categories.map(S=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:r.has(S.id),onChange:()=>X(S.id)}),e.jsx("span",{className:"data-category-name",children:S.name}),S.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",S.fileCount," ",s("config:data.files"),")"]})]},S.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:V,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:O,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:y,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function Sa(){const s=Ks(),n=Ht(),[t,l]=i.useState(n.slugs),[d,r]=i.useState(!1),[c,m]=i.useState(null),[h,o]=i.useState("");i.useEffect(()=>{l(n.slugs)},[n.slugs]);const[u,k]=i.useState(null);i.useEffect(()=>{n.loaded&&k(N=>N??new Set(n.slugs))},[n.loaded,n.slugs]);const g=i.useMemo(()=>{const N=u??new Set(n.slugs);return s.filter($=>$.enabled).sort(($,U)=>{const K=Number(N.has(U.slug))-Number(N.has($.slug));return K!==0?K:$.name.localeCompare(U.name)})},[s,u,n.slugs]),E=i.useMemo(()=>{const N=h.trim().toLowerCase();return N?g.filter($=>$.name.toLowerCase().includes(N)||$.slug.toLowerCase().includes(N)||$.description.toLowerCase().includes(N)):g},[g,h]),f=i.useCallback(async N=>{const $=t;l(N),r(!0),m(null);try{await qt(N)}catch(U){l($),m((U==null?void 0:U.message)||"Failed to save default skills")}finally{r(!1)}},[t]),I=i.useCallback(N=>{f(t.includes(N)?t.filter($=>$!==N):[...t,N])},[f,t]),j=i.useCallback(async()=>{r(!0),m(null);try{await Wt()}catch(N){m((N==null?void 0:N.message)||"Failed to reset default skills")}finally{r(!1)}},[]),p=t.length,b=i.useMemo(()=>{const N=new Set(s.map($=>$.slug));return t.filter($=>!N.has($))},[s,t]);return e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-hint",children:"Skills pre-selected when you create an agent. You can still change them per agent, and agents that already exist are not affected. Each selected skill is added to every new agent's prompt, so fewer means more room for the actual work."}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"8px",flexWrap:"wrap"},children:[e.jsx("input",{type:"text",className:"config-input",placeholder:"Search skills...",value:h,onChange:N=>o(N.target.value),style:{flex:"1 1 160px",minWidth:0}}),e.jsxs("span",{className:"config-hint",style:{whiteSpace:"nowrap"},children:[p," selected"]}),e.jsx("button",{type:"button",className:"config-button",onClick:()=>void j(),disabled:d||!n.configured,title:n.configured?"Go back to the skills Tide Commander ships with":"Already using the shipped defaults",children:"Reset"})]}),c&&e.jsx("span",{className:"config-hint",style:{color:"var(--color-danger, #e5534b)",marginTop:"6px"},children:c}),b.length>0&&e.jsxs("span",{className:"config-hint",style:{marginTop:"6px"},children:["Not installed here, ignored when spawning: ",b.join(", ")]}),e.jsxs("div",{className:"agent-names-list",style:{flexWrap:"wrap",gap:"6px",marginTop:"8px"},children:[E.map(N=>e.jsx("div",{className:`agent-name-chip${t.includes(N.slug)?" agent-name-chip--selected":""}`,style:{cursor:d?"wait":"pointer",userSelect:"none"},title:N.description,onClick:()=>{d||I(N.slug)},children:e.jsx("span",{className:"agent-name-text",children:N.name})},N.id)),E.length===0&&e.jsxs("span",{className:"config-hint",children:['No skills match "',h,'".']})]})]})}function ka(){const[s,n]=i.useState(()=>Hs()),t=l=>{n(l);const d=Ys(l);Js(d)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:qs.map(l=>e.jsxs("button",{className:`theme-option ${s===l.id?"active":""}`,onClick:()=>t(l.id),title:l.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:l.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:l.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:l.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:l.name})]},l.id))})})}function Ca(){const{t:s}=Z(["config"]),{installInfo:n,phase:t,output:l,error:d,newVersion:r,autoRestart:c,refreshInstallInfo:m,runUpdate:h,reset:o}=Xs(),[u,k]=i.useState(!1),g=i.useRef(null);i.useEffect(()=>{m()},[m]),i.useEffect(()=>{g.current&&(g.current.scrollTop=g.current.scrollHeight)},[l]);const E=i.useCallback(()=>{k(!0)},[]),f=i.useCallback(()=>{k(!1)},[]),I=i.useCallback(()=>{k(!1),h()},[h]),j=i.useCallback(()=>{o(),k(!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:E,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:f,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:l||"..."}),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:j,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 Aa(){const{t:s}=Z(["config"]),[n,t]=i.useState(null),[l,d]=i.useState(!1),[r,c]=i.useState(null);i.useEffect(()=>{Zs().then(t).catch(u=>c(u.message))},[]);const m=i.useCallback(async u=>{if(!l){d(!0),c(null);try{t(await Qs(u))}catch(k){c(k.message)}finally{d(!1)}}},[l]),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:l||!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 Ta(){var N;const{t:s}=Z(["config"]),{isAndroid:n,supported:t,otaActive:l,bundleState:d,serverInfo:r,infoError:c,updateAvailable:m,phase:h,progress:o,error:u,autoSync:k,checkNow:g,syncNow:E,resetToBundled:f,setAutoSync:I}=et(),[j,p]=i.useState(null),b=i.useRef(g);return b.current=g,i.useEffect(()=>{n&&(b.current(!1),st.getInfo().then($=>p($.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:[l?s("config:webBundle.sourceOta",{hash:((N=d==null?void 0:d.hash)==null?void 0:N.slice(0,8))??"?"}):s("config:webBundle.sourceBundled"),j&&` · ${s("config:webBundle.apkVersion",{version:j})}`]}),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:k,onChange:$=>I($.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 E(),disabled:h!=="idle"||!r,children:h==="syncing"?s("config:webBundle.syncingPct",{percent:o??0}):s("config:webBundle.syncNow")}),l&&e.jsx("button",{className:"about-update-btn changelog",onClick:()=>void f(),children:s("config:webBundle.reset")})]})]})}function Ea(){const{t:s}=Z(["config"]),[n,t]=i.useState(null),[l,d]=i.useState(!1),[r,c]=i.useState(null);i.useEffect(()=>{nt().then(t).catch(()=>t(null))},[]);const m=i.useCallback(async h=>{if(!l){d(!0),c(null);try{await ot(h),t(h)}catch(o){c(o.message)}finally{d(!1)}}},[l]);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:l,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 Pa(){var p;const{t:s}=Z(["config"]),[n,t]=i.useState(null),[l,d]=i.useState(""),[r,c]=i.useState(!1),[m,h]=i.useState(!1),[o,u]=i.useState(null),[k,g]=i.useState(null),E=i.useCallback(()=>{tt().then(t)},[]);i.useEffect(E,[E]);const f=i.useCallback(async()=>{if(!(m||!l.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:l})}),N=await b.json();if(!b.ok)throw new Error(N.error||"Invalid service account");d(""),c(!1),g(s("config:about.pushSaved",{project:N.projectId})),E()}catch(b){u(b.message)}finally{h(!1)}}},[m,l,E,s]),I=i.useCallback(async()=>{h(!0),u(null),g(null);const b=await at();if(h(!1),!b){u(s("config:about.pushTestFailed"));return}g(s("config:about.pushTestSent",{count:b.sent})),E()},[E,s]);if(!n)return null;const j=((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:j}):s("config:about.pushNotConfigured")})}),r?e.jsxs(e.Fragment,{children:[e.jsx("textarea",{className:"about-push-credentials",value:l,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 f(),disabled:m||!l.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&&j>0&&e.jsx("button",{className:"about-update-btn download",onClick:()=>void I(),disabled:m,children:s("config:about.pushTest")})]}),k&&e.jsx("div",{className:"about-autoupdate-devnote",children:k}),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 _a(){const{t:s}=Z(["config"]),{updateAvailable:n,updateInfo:t,recentReleases:l,isChecking:d,error:r,currentVersion:c,isAndroid:m,downloadPhase:h,downloadProgress:o,checkForUpdate:u,downloadAndInstall:k,openReleasePage:g}=Ws(),[E,f]=i.useState(!1),I=p=>p?`${(p/(1024*1024)).toFixed(1)} MB`:"",j=p=>new Date(p).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:e.jsx(L,{name:"waves",size:24})}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:c}),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(Ca,{}),e.jsx(Aa,{}),e.jsx(Ta,{}),e.jsx(Pa,{}),e.jsx(Ea,{}),e.jsx("div",{className:"about-changelog-row",children:e.jsx("button",{className:"about-update-btn changelog",onClick:()=>f(!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 k(),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")})]}),l.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:l.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:j(p.publishedAt)})]},p.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:e.jsx(L,{name:"package",size:14})}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]}),E&&e.jsx(Gs,{onClose:()=>f(!1)})]})}const Ia={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function Da({onOpenModal:s}){const[n,t]=i.useState([]),[l,d]=i.useState(!0),r=i.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 i.useEffect(()=>{r()},[r]),l?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=Ia[c.id]||"🔌",h=!!c.status.error,o=c.status.connected,u=h?"#f38ba8":o?"#a6e3a1":"#fab387",k=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:k,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:E=>{E.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:E=>{E.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 $a({isOpen:s,onClose:n,initialAgentId:t}){const{t:l}=Z(["config"]),d=it(),[r,c]=i.useState(""),[m,h]=i.useState(""),[o,u]=i.useState(!1),[k,g]=i.useState(""),[E,f]=i.useState(""),[I,j]=i.useState(null),[p,b]=i.useState(null),[N,$]=i.useState(!1),[U,K]=i.useState(!1),[J,z]=i.useState(!1),[X,C]=i.useState(null),M=i.useMemo(()=>[...d].sort((D,A)=>D.name.localeCompare(A.name)),[d]),w=i.useMemo(()=>d.find(D=>D.id===r),[d,r]),R=r===ze;i.useEffect(()=>{if(!s)return;const D=t&&d.some(A=>A.id===t)?t:ze;c(D),u(!1),aa().then(A=>h(A)).catch(()=>h("")).finally(()=>u(!0))},[s]),i.useEffect(()=>{const D=r===ze?m:(w==null?void 0:w.customPrompt)??"";g(D),f(D),$(!1),j(null),b(null)},[r,o]);const ne=D=>{const A=D.target.value;g(A),$(A!==E),j(null),b(null)},y=async()=>{if(r)try{j(null),b(null),R?(await na(k),h(k),b(l("config:systemPrompt.savedGlobal"))):(v.updateAgentProperties(r,{customPrompt:k}),b(l("config:systemPrompt.saved"))),f(k),$(!1)}catch(D){j(D instanceof Error?D.message:"Failed to save system prompt")}},O=()=>{K(!0)},V=async()=>{if(r)try{j(null),b(null),R?(await oa(),h(""),b(l("config:systemPrompt.clearedGlobal"))):(v.updateAgentProperties(r,{customPrompt:""}),b(l("config:systemPrompt.cleared"))),g(""),f(""),$(!1)}catch(D){j(D instanceof Error?D.message:"Failed to clear system prompt")}},S=()=>{g(E),$(!1),j(null),b(null)},F=D=>{if(D!==r){if(N){C(D),z(!0);return}c(D)}},B=()=>{if(N){C(null),z(!0);return}n()},ae=()=>{if(z(!1),X){const D=X;C(null),c(D)}else n()},te=D=>{D.key==="Escape"&&(D.preventDefault(),B())};return s?e.jsxs(Ie,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:B,children:e.jsxs("div",{className:"system-prompt-modal",onClick:D=>D.stopPropagation(),onKeyDown:te,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:l("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:B,"aria-label":"Close",children:e.jsx(L,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"modal-description",children:l("config:systemPrompt.description")}),e.jsxs("div",{className:"agent-picker",children:[e.jsx("label",{htmlFor:"system-prompt-agent",className:"editor-label",children:l("config:systemPrompt.agentLabel")}),e.jsxs("div",{className:"agent-picker-row",children:[R?e.jsx(L,{name:"globe",size:20,className:"agent-picker-icon"}):w&&e.jsx(lt,{classId:w.class,size:20,className:"agent-picker-icon"}),e.jsxs("select",{id:"system-prompt-agent",className:"agent-picker-select",value:r,onChange:D=>F(D.target.value),children:[e.jsxs("option",{value:ze,children:[l("config:systemPrompt.globalOption"),m?" • ✦":""]}),M.map(D=>e.jsxs("option",{value:D.id,children:[D.name,D.customPrompt?" • ✦":""]},D.id))]})]})]}),I&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"warn",size:14})}),I]}),p&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{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:l("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[k.length," ",l("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:k,onChange:ne,placeholder:l("config:systemPrompt.placeholder"),rows:18,disabled:R&&!o,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:l(R?"config:systemPrompt.hintGlobal":"config:systemPrompt.hint")})]})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:O,disabled:!k||!r,children:l("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:B,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:S,disabled:!N,children:l("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:y,disabled:!N||!r,children:l("config:systemPrompt.save")})]})]})]})}),e.jsx(be,{isOpen:U,title:l("config:systemPrompt.clear"),message:l(R?"config:systemPrompt.confirmClearGlobal":"config:systemPrompt.confirmClear"),confirmLabel:l("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{V()},onClose:()=>K(!1)}),e.jsx(be,{isOpen:J,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:ae,onClose:()=>{z(!1),C(null)}})]}):null}const ms={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},La=2500,Oa=12e4;function gs(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function Fa(s,n){return s.enabled===n.enabled&&s.baseUrl===n.baseUrl&&s.defaultSessionId===n.defaultSessionId&&s.webhookVerifyToken===n.webhookVerifyToken&&s.showIncomingToasts===n.showIncomingToasts}function Ra({isOpen:s,onClose:n}){const{t}=Z(["config"]),[l,d]=i.useState(ms),[r,c]=i.useState(ms),[m,h]=i.useState(!1),[o,u]=i.useState([]),[k,g]=i.useState(!0),[E,f]=i.useState(null),[I,j]=i.useState(null),[p,b]=i.useState(""),[N,$]=i.useState(!1),[U,K]=i.useState(""),[J,z]=i.useState(null),[X,C]=i.useState(null),[M,w]=i.useState(null),R=i.useRef(null),ne=i.useRef(0),[y,O]=i.useState(""),[V,S]=i.useState(""),[F,B]=i.useState(null),[ae,te]=i.useState(!1),[D,A]=i.useState(!1),[se,ie]=i.useState(!1),[ce,le]=i.useState(!1),[he,Ae]=i.useState(null),Se=!Fa(l,r),pe=i.useCallback(()=>{R.current&&(clearTimeout(R.current),R.current=null)},[]),Te=i.useCallback(async()=>{try{g(!0),f(null),j(null);const[x,H]=await Promise.all([ys(),ct()]),re=gs(x);if(d(re),c(re),h(!!H.configured),H.configured)try{const Ne=await Ze();u(Array.isArray(Ne)?Ne:[])}catch{u([])}else u([])}catch(x){f(x instanceof Error?x.message:t("config:whatsapp.errors.loadFailed"))}finally{g(!1)}},[t]),je=i.useCallback(async()=>{try{const x=await Ze();u(Array.isArray(x)?x:[])}catch{}},[]);i.useEffect(()=>(s?Te():(pe(),z(null),C(null),w(null),b(""),$(!1),B(null)),()=>{pe()}),[s,Te,pe]);const me=(x,H)=>{d(re=>({...re,[x]:H})),f(null),j(null)},De=async()=>{try{f(null),j(null);const x=await ht({enabled:l.enabled,baseUrl:l.baseUrl.trim(),defaultSessionId:l.defaultSessionId.trim(),webhookVerifyToken:l.webhookVerifyToken,showIncomingToasts:l.showIncomingToasts});window.dispatchEvent(new CustomEvent("tide:whatsapp-config-updated"));const H=gs(x);d(H),c(H),j(t("config:whatsapp.saved"))}catch(x){f(x instanceof Error?x.message:t("config:whatsapp.errors.saveFailed"))}},$e=()=>{d(r),f(null),j(null)},ve=()=>{if(Se){A(!0);return}n()},Le=x=>{x.key==="Escape"&&(x.preventDefault(),ve())},Ke=async()=>{const x=p.trim();if(x)try{f(null),j(null),await dt(x),b(""),$(!1),h(!0),j(t("config:whatsapp.apiKeySaved"))}catch(H){f(H instanceof Error?H.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},He=()=>{ie(!0)},Oe=async()=>{try{f(null),j(null),await mt(),h(!1),j(t("config:whatsapp.apiKeyCleared"))}catch(x){f(x instanceof Error?x.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},Fe=i.useCallback(async x=>{if(Date.now()>ne.current){w(t("config:whatsapp.pairingTimeout")),z(null),C(null),pe(),je();return}try{const H=await rt(x);if(H.status&&["connected","paired","open","ready"].includes(H.status.toLowerCase())){w(t("config:whatsapp.pairingSuccess")),z(null),C(null),pe(),je();return}const Ne=H.qrUrl??H.qr??null;Ne&&C(Ne)}catch(H){w(H instanceof Error?H.message:t("config:whatsapp.errors.qrFetchFailed"))}R.current=setTimeout(()=>{Fe(x)},La)},[je,pe,t]),Re=async()=>{const x=U.trim();if(x)try{f(null),j(null),w(null),C(null),pe(),await ut(x),K(""),z(x),ne.current=Date.now()+Oa,Fe(x),je()}catch(H){f(H instanceof Error?H.message:t("config:whatsapp.errors.sessionCreateFailed"))}},Be=()=>{pe(),z(null),C(null),w(null)},ke=x=>{Ae(x),le(!0)},_=async()=>{if(he)try{f(null),j(null),await gt(he),J===he&&Be(),je(),j(t("config:whatsapp.sessionDeleted"))}catch(x){f(x instanceof Error?x.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{Ae(null)}},ue=async()=>{const x=y.trim(),H=V.trim();if(!(!x||!H))try{te(!0),B(null);const re=l.defaultSessionId.trim()||void 0;await pt(x,H,re),B({kind:"success",text:t("config:whatsapp.testSent")})}catch(re){B({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:x=>x.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(L,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:k?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsapp.description")}),E&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"warn",size:14})}),E]}),I&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{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:l.enabled,onChange:x=>me("enabled",x.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:l.showIncomingToasts,onChange:x=>me("showIncomingToasts",x.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:l.baseUrl,onChange:x=>me("baseUrl",x.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:l.defaultSessionId,onChange:x=>me("defaultSessionId",x.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:l.webhookVerifyToken,onChange:x=>me("webhookVerifyToken",x.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(L,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(L,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:N?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:p,onChange:x=>b(x.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>$(x=>!x),title:t(N?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(L,{name:N?"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(x=>e.jsxs("div",{className:"wa-session-row",children:[e.jsxs("div",{className:"wa-session-info",children:[e.jsx("span",{className:"wa-session-id",children:x.id}),e.jsx("span",{className:`wa-session-status status-${(x.status??"unknown").toLowerCase()}`,children:x.status||"—"}),x.pairedNumber&&e.jsx("span",{className:"wa-session-paired",children:x.pairedNumber})]}),e.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:()=>ke(x.id),children:t("config:whatsapp.deleteSession")})]},x.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:U,onChange:x=>K(x.target.value),onKeyDown:x=>{x.key==="Enter"&&Re()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Re,disabled:!U.trim()||J!==null,children:t("config:whatsapp.addSession")})]}),J&&e.jsxs("div",{className:"wa-qr-panel",children:[e.jsxs("div",{className:"wa-qr-header",children:[e.jsx("span",{children:t("config:whatsapp.qrPrompt",{id:J})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick: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")})]})]}),M&&!J&&e.jsx("div",{className:"wa-pairing-message",children:M})]}),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:y,onChange:x=>O(x.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:V,onChange:x=>S(x.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:!y.trim()||!V.trim()||ae,children:t(ae?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),F&&e.jsxs("div",{className:`alert ${F.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:F.kind==="success"?"check":"warn",size:14})}),F.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||k,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:De,disabled:!Se||k,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(be,{isOpen:D,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{A(!1),n()},onClose:()=>A(!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 Ba(){const s=await fetch(`${Y()}/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 Ma(s){const n=await fetch(`${Y()}/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 Ua(){const s=await fetch(`${Y()}/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 za(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 Va({isOpen:s,onClose:n}){const{t}=Z(["config"]),[l,d]=i.useState(fs),[r,c]=i.useState(fs),[m,h]=i.useState(!0),[o,u]=i.useState(null),[k,g]=i.useState(null),[E,f]=i.useState(!1),[I,j]=i.useState(!1),p=!za(l,r),b=i.useCallback(async()=>{try{h(!0),u(null),g(null);const C=await Ba(),M={filter:{...Ve,...C.filter},recipient:C.recipient??""};d(M),c(M)}catch(C){u(C instanceof Error?C.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{h(!1)}},[t]);i.useEffect(()=>{s&&b()},[s,b]);const N=(C,M)=>{d(w=>({...w,filter:{...w.filter,[C]:M}})),u(null),g(null)},$=C=>{d(M=>({...M,recipient:C})),u(null),g(null)},U=async()=>{try{u(null),g(null);const C=await Ma({filter:l.filter,recipient:l.recipient.trim()}),M={filter:{...Ve,...C.filter},recipient:C.recipient??""};d(M),c(M),g(t("config:whatsappNotifications.saved"))}catch(C){u(C instanceof Error?C.message:t("config:whatsappNotifications.errors.saveFailed"))}},K=()=>{d(r),u(null),g(null)},J=async()=>{try{u(null),g(null);const C=await Ua(),M={filter:{...Ve,...C.filter},recipient:C.recipient??""};d(M),c(M),g(t("config:whatsappNotifications.resetDone"))}catch(C){u(C instanceof Error?C.message:t("config:whatsappNotifications.errors.resetFailed"))}},z=()=>{if(p){f(!0);return}n()},X=C=>{C.key==="Escape"&&(C.preventDefault(),z())};return s?e.jsxs(Ie,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:z,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:C=>C.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:z,"aria-label":"Close",children:e.jsx(L,{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(L,{name:"warn",size:14})}),o]}),k&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"check",size:14})}),k]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.recipient")}),e.jsxs("div",{className:"wan-field",children:[e.jsx("label",{htmlFor:"wan-recipient",className:"wan-label",children:t("config:whatsappNotifications.recipientLabel")}),e.jsx("input",{id:"wan-recipient",type:"text",className:"wan-input",placeholder:t("config:whatsappNotifications.recipientPlaceholder"),value:l.recipient,onChange:C=>$(C.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(C=>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.${C}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${C}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:l.filter[C],onChange:M=>N(C,M.target.checked)}),e.jsx("span",{className:"wan-toggle-track",children:e.jsx("span",{className:"wan-toggle-thumb"})})]})]},C))]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:()=>j(!0),disabled:m,children:t("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:z,children:t("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:K,disabled:!p||m,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:U,disabled:!p||m,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(be,{isOpen:E,title:t("config:whatsappNotifications.unsavedTitle"),message:t("config:whatsappNotifications.unsavedMessage"),confirmLabel:t("config:whatsappNotifications.closeAnyway"),cancelLabel:t("config:whatsappNotifications.keepEditing"),variant:"danger",onConfirm:()=>{f(!1),n()},onClose:()=>f(!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:()=>{J(),j(!1)},onClose:()=>j(!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 Ka(s,n=Date.now()){const t=s*1e3,l=n-t;if(l<0)return xs(t);const d=Math.floor(l/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 Ha(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 qa(s,n){return s.length<=n?s:s.slice(0,Math.max(0,n-1)).trimEnd()+"…"}function Wa({chats:s,selectedChatId:n,loading:t,error:l,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:"⟳"})]}),l&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:l}),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&&!l&&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}]`,k=h.chatId===n,g=As(h.chatId),E=h.isGroup?h.groupName:h.fromName,f=E||g,I=!!E&&E!==g;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${k?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>d(h.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:h.chatId,children:f}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:Ka(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," "]}),qa(u,40)]}),h.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:h.unreadCount})]})]})},h.chatId)})})]})}function Ga({message:s}){const n=s.direction==="outbound"?"outbound":"inbound",t=Ts(s.messageType),l=(s.body??"").trim(),d=l.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:l}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:r}),s.audioTranscription&&e.jsxs("span",{className:"whatsapp-history-bubble__transcription",children:["“",s.audioTranscription,"”"]}),s.mediaPath&&e.jsx("a",{className:"whatsapp-history-bubble__media-link",href:s.mediaPath,target:"_blank",rel:"noopener noreferrer",children:s.mediaFilename||"open media"}),e.jsx("span",{className:"whatsapp-history-bubble__time",children:Ha(s.timestamp)})]})})}const Ya=["all","inbound","outbound"],Ja=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function Xa({direction:s,type:n,onDirectionChange:t,onTypeChange:l,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:Ya.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=>l(c.target.value),disabled:d,children:Ja.map(c=>e.jsx("option",{value:c,children:r(`config:whatsappHistory.typeValues.${c}`)},c))})]})]})}const Za=80;function Qa({chatId:s,messages:n,loading:t,loadingMore:l,error:d,hasMore:r,direction:c,type:m,onDirectionChange:h,onTypeChange:o,onLoadMore:u}){const{t:k}=Z(["config"]),g=i.useRef(null),E=i.useRef(null),f=i.useRef(!1),I=i.useRef(null);i.useEffect(()=>{E.current!==s&&(E.current=s,f.current=!1)},[s]),i.useLayoutEffect(()=>{g.current&&(f.current||n.length!==0&&(g.current.scrollTop=g.current.scrollHeight,f.current=!0))},[s,n.length]),i.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 j=i.useCallback(()=>{!r||l||t||(g.current&&(I.current=g.current.scrollHeight),u())},[r,l,t,u]),p=i.useCallback(b=>{if(!f.current)return;b.currentTarget.scrollTop<=Za&&j()},[j]);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(Xa,{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:j,disabled:l||t,children:k(l?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),d&&e.jsx("div",{className:"whatsapp-history-messages__error",children:d}),t&&n.length===0&&e.jsxs("div",{className:"whatsapp-history-messages__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:k("config:whatsappHistory.loadingMessages")})]}),!t&&!d&&n.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:k("config:whatsappHistory.emptyMessages")}),n.map(b=>e.jsx(Ga,{message:b},en(b)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:k("config:whatsappHistory.selectChat")})})}function en(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 sn(s){const n=`${Y()}/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 l=new URLSearchParams;t.cursor&&l.set("cursor",t.cursor),typeof t.limit=="number"&&l.set("limit",String(t.limit)),t.direction&&l.set("direction",t.direction),t.type&&l.set("type",t.type);const d=l.toString(),r=`${Y()}/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 tn=50;function an({isOpen:s,onClose:n}){const{t}=Z(["config"]),[l,d]=i.useState([]),[r,c]=i.useState(null),[m,h]=i.useState(null),[o,u]=i.useState([]),[k,g]=i.useState(!1),[E,f]=i.useState(null),[I,j]=i.useState(null),[p,b]=i.useState([]),[N,$]=i.useState(!1),[U,K]=i.useState(!1),[J,z]=i.useState(null),[X,C]=i.useState(null),[M,w]=i.useState("all"),[R,ne]=i.useState("all"),[y,O]=i.useState(()=>Date.now()),V=i.useRef(0);i.useEffect(()=>{if(!s)return;const A=window.setInterval(()=>O(Date.now()),6e4);return()=>window.clearInterval(A)},[s]),i.useEffect(()=>{if(!s)return;let A=!1;return(async()=>{var se;try{h(null);const[ie,ce]=await Promise.all([Ze().catch(()=>[]),ys().catch(()=>null)]);if(A)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(A)return;h(ie instanceof Error?ie.message:String(ie))}})(),()=>{A=!0}},[s]);const S=i.useCallback(async A=>{g(!0),f(null);try{const se=await sn(A);u(se.chats)}catch(se){f(se instanceof Error?se.message:String(se))}finally{g(!1)}},[]);i.useEffect(()=>{!s||!r||(j(null),b([]),C(null),S(r))},[s,r,S]);const F=i.useMemo(()=>{const A={limit:tn};return M!=="all"&&(A.direction=M),R!=="all"&&(A.type=R),A},[M,R]),B=i.useCallback(async(A,se,ie)=>{const ce=++V.current;$(!0),z(null),b([]),C(null);try{const le=await bs(A,se,ie);if(ce!==V.current)return;b([...le.messages].reverse()),C(le.nextCursor)}catch(le){if(ce!==V.current)return;z(le instanceof Error?le.message:String(le))}finally{ce===V.current&&$(!1)}},[]);i.useEffect(()=>{!s||!r||!I||B(r,I,F)},[s,r,I,F,B]);const ae=i.useCallback(async()=>{if(!(!r||!I||!X)){K(!0),z(null);try{const A=await bs(r,I,{...F,cursor:X});b(se=>[...[...A.messages].reverse(),...se]),C(A.nextCursor)}catch(A){z(A instanceof Error?A.message:String(A))}finally{K(!1)}}},[r,I,X,F]),te=i.useCallback(()=>{r&&S(r)},[r,S]),D=i.useCallback(A=>{A.key==="Escape"&&(A.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:A=>A.stopPropagation(),onKeyDown:D,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:A=>c(A.target.value||null),disabled:l.length===0,children:[l.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),l.map(A=>e.jsxs("option",{value:A.id,children:[A.id,A.pairedNumber?` (${A.pairedNumber})`:""]},A.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(L,{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(Wa,{chats:o,selectedChatId:I,loading:k,error:E,onSelect:j,onRefresh:te,now:y}),e.jsx(Qa,{chatId:I,messages:p,loading:N,loadingMore:U,error:J,hasMore:X!==null,direction:M,type:R,onDirectionChange:w,onTypeChange:ne,onLoadMore:ae})]})]})})}):null}function nn({isOpen:s,onClose:n,onOpenConfig:t,onOpenNotifications:l,onOpenHistory:d}){const{t:r}=Z(["config"]);if(i.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(L,{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(L,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children: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(l),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(L,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children: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(L,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children: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:Et}],on=[{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:"🌙"}],ln=[{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:"🔴"}],cn=[{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:"👎"}],rn=[{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:"💜"}],dn=[{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"}],un=[{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"}],pn={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},hn={none:"grass","pokemon-stadium":"pokemon"},mn={"emote-yes":"yes","emote-no":"no"},gn={"":"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:l=!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}),!l&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function T({text:s,query:n}){if(!n.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),l=n.toLowerCase(),d=t.indexOf(l);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 fn({config:s,onChange:n,searchQuery:t="",onOpenIntegrationsModal:l,onOpenPluginsModal:d,onOpenMonitoringModal:r,onOpenStatisticsModal:c,onOpenWorkflowEditor:m,onOpenTriggerManager:h}){var ls;const{t:o}=Z(["config","common"]),u=ft(),k=xt(),[g,E]=i.useState(()=>bt(Pe.DEFAULT_AGENT_CLASS)||"scout"),f=jt(),I=vt(),[j,p]=i.useState(()=>Nt()),[b,N]=i.useState(null),[$,U]=i.useState(null),[K,J]=i.useState("");i.useEffect(()=>{qe().then(p)},[]);const z=async(a,P)=>{U(null),N(a);try{const q=await fe(xe(`/api/custom-sounds/${a}`),{method:"POST",headers:{"Content-Type":P.type||"audio/mpeg"},body:P});if(!q.ok){const de=await q.json().catch(()=>({error:`Upload failed (${q.status})`}));throw new Error(de.error||`Upload failed (${q.status})`)}const oe=await qe();p({...oe});const ge=Je.find(de=>de.kind===a);ge&&v.updateSettings({[ge.settingKey]:_e}),We(_e,u.notificationSoundVolume,a)}catch(q){U(q instanceof Error?q.message:"Upload failed")}finally{N(null)}},X=async a=>{U(null);try{await fe(xe(`/api/custom-sounds/${a}`),{method:"DELETE"}),$t({[a]:null});const P=await qe();p({...P});const q=Je.find(oe=>oe.kind===a);q&&v.getSettings()[q.settingKey]===_e&&v.updateSettings({[q.settingKey]:Lt[a]})}catch(P){U(P instanceof Error?P.message:"Failed to reset sound")}},[C,M]=i.useState(u.historyLimit),[w,R]=i.useState(()=>yt()),[ne,y]=i.useState(!1),[O,V]=i.useState(""),[S,F]=i.useState(()=>Q()),[B,ae]=i.useState(!1),[te,D]=i.useState(!1),[A,se]=i.useState(""),[ie,ce]=i.useState(!1),[le,he]=i.useState(!1),[Ae,Se]=i.useState(!1),[pe,Te]=i.useState(!1),[je,me]=i.useState(!1),[De,$e]=i.useState(""),[ve,Le]=i.useState(!1);i.useEffect(()=>{ca().then($e).catch(()=>{})},[]),i.useEffect(()=>{ia().then(a=>{a!==u.experimentalEchoPrompt&&v.updateSettings({experimentalEchoPrompt:a})}).catch(()=>{})},[]),i.useEffect(()=>{da().then(a=>{a!==u.tmuxMode&&v.updateSettings({tmuxMode:a})}).catch(()=>{})},[]),i.useEffect(()=>{pa().then(a=>{a!==u.interactiveMode&&v.updateSettings({interactiveMode:a})}).catch(()=>{})},[]),i.useEffect(()=>{ma().then(a=>{a!==u.codexAppServerMode&&v.updateSettings({codexAppServerMode:a})}).catch(()=>{})},[]),i.useEffect(()=>{fa().then(a=>{a!==u.opencodeServerMode&&v.updateSettings({opencodeServerMode:a})}).catch(()=>{})},[]),i.useEffect(()=>{ba().then(a=>{a!==u.piRpcMode&&v.updateSettings({piRpcMode:a})}).catch(()=>{})},[]),i.useEffect(()=>wt(a=>{R(a),y(!1)}),[]);const Ke=on.map(a=>({...a,label:o(`config:time.${a.value}`)})),He=ln.map(a=>({...a,label:o(`config:floor.${hn[a.value]||a.value}`)})),Oe=cn.map(a=>({...a,label:o(`config:animation.${mn[a.value]||a.value}`)})),Fe=rn.map(a=>({...a,label:o(`config:colorMode.${a.value}`)})),Re=dn.map(a=>({...a,label:o(`config:terrain.${pn[a.key]}`)})),Be=un.map(a=>({...a,label:o(`config:sky.${gn[a.value??""]}`)})),ke=t.trim()?Gt(t).map(a=>a.id):null,_=a=>ke?ke.includes(a):!0,ue=u.customAgentNames||[],x=ue.length>0?ue:St,H=()=>{const a=A.trim();a&&!ue.includes(a)&&(v.updateSettings({customAgentNames:[...ue,a]}),se(""))},re=a=>{v.updateSettings({customAgentNames:ue.filter(P=>P!==a)})},Ne=()=>{v.updateSettings({customAgentNames:[]})},Me=u.fileSearchExcludeDirs??[...rs],ss=()=>{const a=K.trim();if(ps(a)){if(Me.includes(a)){J("");return}v.updateSettings({fileSearchExcludeDirs:[...Me,a]}),J("")}},_s=a=>{v.updateSettings({fileSearchExcludeDirs:Me.filter(P=>P!==a)})},Is=()=>{v.updateSettings({fileSearchExcludeDirs:[...rs]})},ts=()=>{const a=O.trim();if(a){if(w.includes(a)){V("");return}R([...w,a]),y(!0),V("")}},Ds=a=>{R(w.filter((P,q)=>q!==a)),y(!0)},as=(a,P)=>{const q=a+P;if(q<0||q>=w.length)return;const oe=w.slice();[oe[a],oe[q]]=[oe[q],oe[a]],R(oe),y(!0)},$s=()=>{Ot(w),y(!1),Ye()},Ls=a=>{F(a),ae(!0)},ns=()=>{Ue(Pe.AUTH_TOKEN,S),ae(!1),Ye()},Os=a=>{$e(a),Le(!0)},os=()=>{ra(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=>{M(a),v.updateSettings({historyLimit:a})},Rs=a=>{const P=s.terrain[a];typeof P=="boolean"&&ye({[a]:!P})},G=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(W,{title:"Plugins",storageKey:"plugins",defaultOpen:!0,forceOpen:G&&_("plugins"),children:e.jsxs("div",{className:"config-row config-row--plugins",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(W,{title:o("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:G&&_("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:o("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:C,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(T,{text:o("config:general.hideCosts"),query:t})}),e.jsx(ee,{checked:u.hideCost,onChange:a=>v.updateSettings({hideCost:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.streamTextLiveTitle"),children:e.jsx(T,{text:o("config:general.streamTextLive"),query:t})}),e.jsx(ee,{checked:u.streamTextLive!==!1,onChange:a=>v.updateSettings({streamTextLive:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.toolHoverPreviewTitle"),children:e.jsx(T,{text:o("config:general.toolHoverPreview"),query:t})}),e.jsx(ee,{checked:u.toolHoverPreview===!0,onChange:a=>v.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(T,{text:"Agent activity dock",query:t})}),e.jsx("select",{className:"config-select",value:f,onChange:a=>At(a.target.value),children:kt.map(a=>e.jsx("option",{value:a,children:Ct[a]},a))})]}),f!=="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(T,{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=>Tt(parseInt(a.target.value,10)||0)})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(T,{text:o("config:general.showFPS"),query:t})}),e.jsx(ee,{checked:u.showFPS,onChange:a=>v.updateSettings({showFPS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(T,{text:o("config:general.powerSaving"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.powerSaving,onChange:a=>v.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(T,{text:o("config:general.lowPowerMode"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.lowPowerMode===!0,onChange:a=>v.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(T,{text:o("config:general.tmuxMode"),query:t})}),e.jsx(ee,{checked:u.tmuxMode,onChange:async a=>{v.updateSettings({tmuxMode:a});try{await ua(a)}catch(P){console.error("Failed to sync tmux mode setting to server:",P)}}})]}),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(T,{text:o("config:general.interactiveMode"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.interactiveMode,onChange:async a=>{v.updateSettings({interactiveMode:a});try{await ha(a)}catch(P){console.error("Failed to sync interactive mode setting to server:",P)}}})]}),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(T,{text:o("config:general.codexAppServerMode"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.codexAppServerMode,onChange:async a=>{v.updateSettings({codexAppServerMode:a});try{await ga(a)}catch(P){console.error("Failed to sync codex app-server mode setting to server:",P)}}})]}),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(T,{text:o("config:general.opencodeServerMode"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.opencodeServerMode,onChange:async a=>{v.updateSettings({opencodeServerMode:a});try{await xa(a)}catch(P){console.error("Failed to sync opencode server mode setting to server:",P)}}})]}),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(T,{text:o("config:general.piRpcMode"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.piRpcMode,onChange:async a=>{v.updateSettings({piRpcMode:a});try{await ja(a)}catch(P){console.error("Failed to sync pi RPC mode setting to server:",P)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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=>v.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(T,{text:"Notification sounds",query:t})}),e.jsx(ee,{checked:u.notificationSoundEnabled,onChange:a=>{v.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(T,{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 P=parseInt(a.target.value);v.updateSettings({notificationSoundVolume:P}),Ss(P,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(T,{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 P=!!j[a.kind],q=u[a.settingKey],oe=P&&q===_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=Pt(q))==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:q,onChange:de=>{const Ee=de.target.value;v.updateSettings({[a.settingKey]:Ee}),We(Ee,u.notificationSoundVolume,a.kind)},children:[P&&e.jsx("option",{value:_e,children:"Your uploaded file"}),_t.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(q,u.notificationSoundVolume,a.kind),disabled:us(q),title:us(q)?"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&&z(a.kind,Ee)}})]}),P&&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)}),$&&e.jsx("div",{className:"config-sound-error",children:$})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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=>v.updateSettings({externalEditorCommand:a.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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=>v.updateSettings({tabTitle:a.target.value})})]}),e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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:K,onChange:a=>J(a.target.value),onKeyDown:a=>{a.key==="Enter"&&ss()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ss,disabled:!ps(K),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(T,{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 P;if(a==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const q=navigator.language,oe=((P=Xe.find(ge=>ge.value!=="auto"&&q.startsWith(ge.value.split("-")[0])))==null?void 0:P.value)||"en";Ge.changeLanguage(oe)}else localStorage.setItem("tide-commander-language-mode","manual"),Ge.changeLanguage(a)}})]})]}),_("agentNames")&&e.jsx(W,{title:o("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:G&&_("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children: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:A,onChange:a=>se(a.target.value),onKeyDown:a=>{a.key==="Enter"&&H()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:H,disabled:!A.trim(),title:o("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:x.map((a,P)=>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}-${P}`))}),ue.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:Ne,children:o("common:buttons.resetToDefaults")})]})}),_("defaultClass")&&e.jsx(W,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:G&&_("defaultClass"),children:e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-hint",children:'Class pre-selected when the spawn modal opens. "Random" picks a different class each time.'}),e.jsxs("div",{className:"agent-names-list",style:{flexWrap:"wrap",gap:"6px",marginTop:"8px"},children:[e.jsx("div",{className:`agent-name-chip${g==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{E("random"),Ue(Pe.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(It).map(([a,P])=>e.jsx("div",{className:`agent-name-chip${g===a?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{E(a),Ue(Pe.DEFAULT_AGENT_CLASS,a)},children:e.jsxs("span",{className:"agent-name-text",children:[P.icon," ",a.charAt(0).toUpperCase()+a.slice(1)]})},a)),k.map(a=>e.jsx("div",{className:`agent-name-chip${g===a.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{E(a.id),Ue(Pe.DEFAULT_AGENT_CLASS,a.id)},children:e.jsxs("span",{className:"agent-name-text",children:[a.icon," ",a.name]})},a.id))]})]})}),_("defaultSkills")&&e.jsx(W,{title:"Default Agent Skills",storageKey:"defaultSkills",defaultOpen:!1,forceOpen:G&&_("defaultSkills"),children:e.jsx(Sa,{})}),_("appearance")&&e.jsx(W,{title:o("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:G&&_("appearance"),children:e.jsx(ka,{})}),_("connection")&&e.jsxs(W,{title:o("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:G&&_("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:o("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:w.map((a,P)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:o("config:connection.priorityLabel",{defaultValue:"Priority"}),children:P+1}),e.jsx("span",{className:"backend-url-text",title:a,children:a}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>as(P,-1),disabled:P===0,title:o("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>as(P,1),disabled:P===w.length-1,title:o("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ds(P),title:o("common:buttons.remove"),children:"x"})]},`${a}-${P}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:O,onChange:a=>V(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:!O.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(T,{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:S,onChange:a=>Ls(a.target.value),placeholder:o("config:connection.tokenPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&B&&ns()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>D(!te),title:o(te?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(L,{name:te?"eye-closed":"eye",size:14})}),B&&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(T,{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(T,{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(W,{title:o("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:G&&_("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(T,{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(T,{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(T,{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(T,{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(W,{title:o("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:G&&_("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(T,{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(T,{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(T,{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(T,{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(T,{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(W,{title:o("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:G&&_("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(T,{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(T,{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(T,{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(T,{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(T,{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(T,{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(W,{title:o("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:G&&_("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(T,{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(W,{title:o("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:G&&_("secrets"),children:e.jsx(ta,{})}),_("claudeAccounts")&&e.jsx(W,{title:o("config:sections.claudeAccounts",{defaultValue:"Claude Accounts"}),storageKey:"claudeAccounts",defaultOpen:!1,forceOpen:G&&_("claudeAccounts"),children:e.jsx(Dt,{})}),_("grokAccounts")&&e.jsx(W,{title:o("config:sections.grokAccounts",{defaultValue:"Grok Accounts"}),storageKey:"grokAccounts",defaultOpen:!1,forceOpen:G&&_("grokAccounts"),children:e.jsx(hs,{provider:"grok"})}),_("codexAccounts")&&e.jsx(W,{title:o("config:sections.codexAccounts",{defaultValue:"Codex Accounts"}),storageKey:"codexAccounts",defaultOpen:!1,forceOpen:G&&_("codexAccounts"),children:e.jsx(hs,{provider:"codex"})}),_("systemPrompt")&&e.jsx(W,{title:o("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:G&&_("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:o("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>ce(!0),children:o("config:systemPrompt.editPrompt")})]})}),_("data")&&e.jsx(W,{title:o("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:G&&_("data"),children:e.jsx(wa,{})}),_("integrations")&&e.jsx(W,{title:o("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:G&&_("integrations"),children:e.jsx(Da,{onOpenModal:a=>{a==="whatsapp"?me(!0):l==null||l(a)}})}),_("workflows")&&e.jsxs(W,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:G&&_("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(T,{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(W,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:G&&_("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(T,{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(W,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:G&&_("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(T,{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(W,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:G&&_("statistics"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(T,{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(W,{title:o("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:G&&_("experimental"),children:[e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Lightweight 2D top-down view for better performance",children:[e.jsx(T,{text:o("config:experimental.2dView"),query:t})," ",e.jsx(L,{name:"map",size:12})]}),e.jsx(ee,{checked:u.experimental2DView,onChange:a=>v.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(T,{text:o("config:experimental.voiceAssistant"),query:t})," ",e.jsx(L,{name:"microphone",size:12})]}),e.jsx(ee,{checked:u.experimentalVoiceAssistant,onChange:a=>v.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(T,{text:o("config:experimental.tts"),query:t})," ",e.jsx(L,{name:"speaker-on",size:12})]}),e.jsx(ee,{checked:u.experimentalTTS,onChange:a=>v.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(T,{text:o("config:experimental.echoPrompt"),query:t})}),e.jsx(ee,{checked:u.experimentalEchoPrompt,onChange:async a=>{v.updateSettings({experimentalEchoPrompt:a});try{await la(a)}catch(P){console.error("Failed to sync echo prompt setting to server:",P)}}})]}),e.jsx("span",{className:"config-hint",children:o("config:experimental.hint")})]}),_("about")&&e.jsx(W,{title:o("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:G&&_("about"),children:e.jsx(_a,{})})]}),e.jsx($a,{isOpen:ie,onClose:()=>ce(!1)}),e.jsx(Ra,{isOpen:le,onClose:()=>he(!1)}),e.jsx(Va,{isOpen:Ae,onClose:()=>Se(!1)}),e.jsx(an,{isOpen:pe,onClose:()=>Te(!1)}),e.jsx(nn,{isOpen:je,onClose:()=>me(!1),onOpenConfig:()=>he(!0),onOpenNotifications:()=>Se(!0),onOpenHistory:()=>Te(!0)})]})}function wn({onConfigChange:s,onToolChange:n,config:t,isOpen:l,onClose:d,initialSearchQuery:r,onOpenBuildingModal:c,onOpenAreaExplorer:m,onOpenIntegrationsModal:h,onOpenPluginsModal:o,onOpenMonitoringModal:u,onOpenStatisticsModal:k,onOpenWorkflowEditor:g,onOpenTriggerManager:E}){const{t:f}=Z(["config","common"]),I=Ft(),j=Rt(),p=Bt(),b=Mt(),N=Ut(),$=Array.from(I.values()),U=Array.from(j.values()),[K,J]=i.useState(""),z=i.useRef(null);if(i.useEffect(()=>{const w=R=>{R.key==="Escape"&&l&&d()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[l,d]),i.useEffect(()=>{l&&J(r??"")},[l,r]),i.useEffect(()=>{if(l&&z.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const R=setTimeout(()=>{var ne;(ne=z.current)==null||ne.focus()},50);return()=>clearTimeout(R)}},[l]),!l)return null;const X=w=>{n(N===w?null:w)},C=w=>{v.selectArea(b===w?null:w),n("select")},M=(w,R)=>{w.stopPropagation(),v.deleteArea(R)};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:f("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:f("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:z,type:"text",placeholder:f("config:searchPlaceholder"),value:K,onChange:w=>J(w.target.value),className:"toolbox-search-input"}),K&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>J(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(W,{title:f("config:areas.title",{count:$.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${N==="select"?"active":""}`,onClick:()=>X("select"),title:f("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 ${N==="rectangle"?"active":""}`,onClick:()=>X("rectangle"),title:f("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 ${N==="circle"?"active":""}`,onClick:()=>X("circle"),title:f("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:$.length===0?e.jsx("div",{className:"areas-empty",children:f("config:areas.drawToCreate")}):$.map(w=>e.jsx(Xt,{area:w,isSelected:b===w.id,onClick:()=>C(w.id),onDelete:R=>M(R,w.id)},w.id))})]})}),b&&e.jsx(sa,{area:I.get(b),onClose:()=>v.selectArea(null),onOpenFolder:m}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(W,{title:f("config:buildings.title",{count:U.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:w=>{w.stopPropagation(),c==null||c()},title:f("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:U.length===0?e.jsx("div",{className:"buildings-empty",children:f("config:buildings.clickToAdd")}):U.map(w=>e.jsx(Zt,{building:w,isSelected:p.has(w.id),onClick:()=>{v.selectBuilding(p.has(w.id)?null:w.id)},onEdit:()=>c==null?void 0:c(w.id)},w.id))})})}),p.size===1&&(()=>{const w=Array.from(p)[0],R=j.get(w);return R?e.jsx(Qt,{building:R,onClose:()=>v.selectBuilding(null),onOpenModal:()=>c==null?void 0:c(w)}):null})(),e.jsx(fn,{config:t,onChange:s,searchQuery:K,onOpenIntegrationsModal:h,onOpenPluginsModal:o,onOpenMonitoringModal:u,onOpenStatisticsModal:k,onOpenWorkflowEditor:g,onOpenTriggerManager:E})]})]})]})}export{wn as Toolbox};
1
+ import{r as i,j as e,I as L,u as Z,cg as js,ax as vs,ch as Bs,cj as Ms,s as v,dj as Us,F as zs,dk as Vs,a5 as be,Y as Q,ah as Y,c as fe,d as xe,i as Ks,dl as Hs,dm as qs,dn as Ws,dp as Gs,dq as Ys,dr as Js,ds as Xs,dt as Ns,du as Zs,dv as Qs,dw as et,b6 as st,dx as tt,dy as at,dz as nt,dA as ot,aK as it,ac as Ie,E as lt,dB as ys,dC as ct,dD as Ze,dE as rt,dF as dt,dG as ut,dH as pt,dI as ht,dJ as mt,dK as gt,bx as ft,k as xt,m as bt,S as Pe,dL as jt,dM as vt,dN as Nt,dO as qe,dP as yt,dQ as wt,B as St,cl as rs,dR as kt,dS as Ct,dT as At,dU as Tt,dV as ws,dW as ds,dX as Ss,dY as Et,dZ as Pt,d_ as _e,d$ as _t,e0 as We,e1 as us,e2 as ps,cc as Ge,R as Ue,Q as It,e3 as Ye,e4 as Dt,e5 as hs,e6 as $t,e7 as Lt,e8 as Ot,a8 as Ft,f as Rt,e9 as Bt,ea as Mt,eb as Ut}from"./main-sBSI_4k0.js";import{g as zt,d as Vt,u as Kt}from"./area-logos-BFSIooyB.js";import{u as Ht,a as qt,b as Wt}from"./default-agent-skills-hW2YTtT1.js";import{s as Gt}from"./settingsSearch-Cv7ya9n1.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-GtkNAxzd.js";const ks="tide-toolbox-collapse";function Yt(s,n){try{const t=localStorage.getItem(`${ks}-${s}`);if(t!==null)return t==="true"}catch{}return n}function Jt(s,n){try{localStorage.setItem(`${ks}-${s}`,String(n))}catch{}}function W({title:s,storageKey:n,defaultOpen:t=!1,forceOpen:l=!1,children:d,headerExtra:r}){const[c,m]=i.useState(()=>n?Yt(n,t):t),h=()=>{const u=!c;m(u),n&&Jt(n,u)},o=l||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(L,{name:o?"caret-down":"caret-right",size:10})})]})]}),o&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Xt({area:s,isSelected:n,onClick:t,onDelete:l}){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:l,title:d("config:areas.deleteArea"),children:"×"})]})}function Zt({building:s,isSelected:n,onClick:t,onEdit:l}){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(L,{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(),l()},title:d("config:buildings.editBuilding"),children:e.jsx(L,{name:"gear",size:14})})]})}function Qt({building:s,onClose:n,onOpenModal:t}){var o,u,k,g,E,f,I,j;const{t:l}=Z(["config","common"]),r=Bs().get(s.id)||[],c=Ms[s.style||"server-rack"],m=p=>{v.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(L,{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:l("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:l("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:l("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:l("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)||l("config:buildings.noStartCommand"),children:[e.jsx(L,{name:"play",size:12})," ",l("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>m("stop"),disabled:!((k=s.commands)!=null&&k.stop)||s.status==="stopped",title:((g=s.commands)==null?void 0:g.stop)||l("config:buildings.noStopCommand"),children:[e.jsx(L,{name:"stop",size:12,weight:"fill"})," ",l("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>m("restart"),disabled:!((E=s.commands)!=null&&E.restart),title:((f=s.commands)==null?void 0:f.restart)||l("config:buildings.noRestartCommand"),children:[e.jsx(L,{name:"refresh",size:12})," ",l("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>m("healthCheck"),disabled:!((I=s.commands)!=null&&I.healthCheck),title:((j=s.commands)==null?void 0:j.healthCheck)||l("config:buildings.noHealthCheck"),children:[e.jsx(L,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:l("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(L,{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:[l("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>v.clearBuildingLogs(s.id),title:l("common:buttons.clear"),children:l("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(L,{name:"gear",size:12})," ",l("config:buildings.fullSettings")]})})]})}const ea=[{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 sa({area:s,onClose:n,onOpenFolder:t}){var ne;const{t:l}=Z(["config","common"]),[d,r]=i.useState(s.name),[c,m]=i.useState(s.prompt||""),[h,o]=i.useState(!1),[u,k]=i.useState(""),[g,E]=i.useState(!1),f=i.useRef(null);i.useEffect(()=>{r(s.name)},[s.id,s.name]),i.useEffect(()=>{m(s.prompt||"")},[s.id,s.prompt]);const I=y=>{const O=y.target.value;r(O),v.updateArea(s.id,{name:O})},j=y=>{v.updateArea(s.id,{color:y})},p=y=>{const O=y.target.value;m(O),v.updateArea(s.id,{prompt:O})},b=()=>{u.trim()&&(v.addDirectoryToArea(s.id,u.trim()),k(""),o(!1))},N=(y,O)=>{O.stopPropagation(),v.removeDirectoryFromArea(s.id,y)},$=()=>{v.bringAreaToFront(s.id)},U=()=>{v.sendAreaToBack(s.id)},K=i.useCallback(()=>{let y=2,O=2;s.type==="rectangle"&&s.width&&s.height?(y=s.width,O=s.height):s.type==="circle"&&s.radius&&(y=s.radius*1.414,O=s.radius*1.414);const V=Math.min(y,O)*.4;return{width:Math.round(V*10)/10,height:Math.round(V*10)/10}},[s.type,s.width,s.height,s.radius]),J=async y=>{var V;const O=(V=y.target.files)==null?void 0:V[0];if(O){E(!0);try{const S=await Kt(s.id,O),F=K();v.updateArea(s.id,{logo:{filename:S.filename,position:"center",width:F.width,height:F.height,keepAspectRatio:!0,opacity:.8}})}catch(S){console.error("Failed to upload logo:",S)}finally{E(!1),f.current&&(f.current.value="")}}},z=async()=>{try{await Vt(s.id),v.updateArea(s.id,{logo:void 0})}catch(y){console.error("Failed to remove logo:",y)}},X=y=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,position:y}})},C=y=>{if(!s.logo)return;const O=parseFloat(y.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const V=s.logo.height/s.logo.width;v.updateArea(s.id,{logo:{...s.logo,width:O,height:Math.round(O*V*10)/10}})}else v.updateArea(s.id,{logo:{...s.logo,width:O}})},M=y=>{if(!s.logo)return;const O=parseFloat(y.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const V=s.logo.width/s.logo.height;v.updateArea(s.id,{logo:{...s.logo,height:O,width:Math.round(O*V*10)/10}})}else v.updateArea(s.id,{logo:{...s.logo,height:O}})},w=()=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},R=y=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(y.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:l("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:l("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange:I,placeholder:l("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:l("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:Us.map(y=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===y?"selected":""}`,style:{backgroundColor:y},onClick:()=>j(y),"aria-label":`Set area color ${y}`,"aria-pressed":s.color===y,title:y},y))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:l("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:$,title:l("config:areas.bringToFront"),children:[e.jsx(L,{name:"arrow-up",size:12})," ",l("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:U,title:l("config:areas.sendToBack"),children:[e.jsx(L,{name:"arrow-down",size:12})," ",l("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:l("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:zt(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:z,children:l("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var y;return(y=f.current)==null?void 0:y.click()},disabled:g,children:g?"...":e.jsx(L,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:l("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:ea.map(({key:y,labelKey:O})=>{var V;return e.jsx("button",{className:`area-logo-pos-btn ${((V=s.logo)==null?void 0:V.position)===y?"active":""}`,onClick:()=>X(y),children:l(`config:areas.${O}`)},y)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:l("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:l("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:C,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:l("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:M,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:l("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:w}),l("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:l("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:R,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 y;return(y=f.current)==null?void 0:y.click()},disabled:g,children:g?"...":l("config:areas.uploadLogo")}),e.jsx("input",{ref:f,type:"file",accept:"image/*",style:{display:"none"},onChange:J})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:l("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(y=>e.jsxs("div",{className:"area-folder-item",title:y,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:l("config:areas.openFolder"),children:e.jsx(L,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:y.split("/").pop()||y}),e.jsx("button",{className:"area-folder-remove",onClick:O=>N(y,O),title:l("config:areas.removeFolder"),children:"×"})]},y)),h?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(zs,{value:u,onChange:k,onSubmit:b,placeholder:l("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:l("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:l("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:c,onChange:p,placeholder:l("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:l("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:l("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:l("config:areas.rightClickUnassign")})]})]})}function ta(){const{t:s}=Z(["config","common"]),n=Vs(),[t,l]=i.useState(!1),[d,r]=i.useState(null),[c,m]=i.useState({name:"",key:"",value:"",description:""}),[h,o]=i.useState(null),u=()=>{l(!0),r(null),m({name:"",key:"",value:"",description:""})},k=p=>{r(p.id),l(!1),m({name:p.name,key:p.key,value:p.value,description:p.description||""})},g=()=>{l(!1),r(null),m({name:"",key:"",value:"",description:""})},E=()=>{!c.name.trim()||!c.key.trim()||(d?v.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}):v.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())},f=p=>{o(p)},I=()=>{h&&(v.deleteSecret(h),d===h&&g())},j=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:()=>j(p.key),title:s("config:secrets.copyPlaceholder"),children:`{{${p.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>k(p),title:s("common:buttons.edit"),children:e.jsx(L,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>f(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:E,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 aa(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch system prompt: ${n.statusText}`);return(await n.json()).prompt||""}async function na(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function oa(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to clear system prompt: ${n.statusText}`)}async function ia(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch echo prompt setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function la(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function ca(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex binary path: ${n.statusText}`);return(await n.json()).path||""}async function ra(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function da(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch tmux mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ua(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function pa(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch interactive mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ha(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function ma(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/codex-app-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex app-server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ga(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/codex-app-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update codex app-server mode setting: ${t.statusText}`)}async function fa(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/opencode-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch opencode server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function xa(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/opencode-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update opencode server mode setting: ${t.statusText}`)}async function ba(){const s=Q(),n=await fetch(`${Y()}/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 ja(s){const n=Q(),t=await fetch(`${Y()}/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 va(){const s=Q(),n=await fetch(`${Y()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch backup status: ${n.statusText}`);return n.json()}async function Na(s){const n=Q(),t=await fetch(`${Y()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok){const l=await t.json().catch(()=>({}));throw new Error(l.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function ya({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:l=>n(l.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function wa(){const{t:s}=Z(["config","common"]),[n,t]=i.useState([]),[l,d]=i.useState(new Set),[r,c]=i.useState(new Set),[m,h]=i.useState(!1),[o,u]=i.useState(!1),[k,g]=i.useState(null),[E,f]=i.useState(null),[I,j]=i.useState(null),[p,b]=i.useState(null),[N,$]=i.useState(!1),[U,K]=i.useState(null);i.useEffect(()=>{fe(xe("/api/config/categories")).then(S=>S.json()).then(S=>{const F=Array.isArray(S)?S:[];t(F),d(new Set(F.map(B=>B.id)))}).catch(S=>console.error("Failed to fetch config categories:",S))},[]),i.useEffect(()=>{va().then(b).catch(S=>{console.error("Failed to fetch backup status:",S),K(S.message||"Failed to fetch backup status")})},[]);const J=async S=>{if(!N){$(!0),K(null);try{const F=await Na(S);b(F)}catch(F){K(F.message||"Failed to update backup setting")}finally{$(!1)}}},z=S=>{d(F=>{const B=new Set(F);return B.has(S)?B.delete(S):B.add(S),B})},X=S=>{c(F=>{const B=new Set(F);return B.has(S)?B.delete(S):B.add(S),B})},C=()=>d(new Set(n.map(S=>S.id))),M=()=>d(new Set),w=()=>{E&&c(new Set(E.categories.map(S=>S.id)))},R=()=>c(new Set),ne=async()=>{var S;if(l.size!==0){h(!0),j(null);try{const F=Array.from(l).join(","),B=await fe(xe(`/api/config/export?categories=${F}`));if(!B.ok)throw new Error("Export failed");const ae=await B.blob(),te=window.URL.createObjectURL(ae),D=document.createElement("a");D.href=te;const A=B.headers.get("Content-Disposition"),se=((S=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:S[1])||"tide-commander-config.zip";D.download=se,document.body.appendChild(D),D.click(),document.body.removeChild(D),window.URL.revokeObjectURL(te),j({type:"success",text:s("config:data.exportSuccess")})}catch(F){j({type:"error",text:F.message||"Export failed"})}finally{h(!1)}}},y=async S=>{var B;const F=(B=S.target.files)==null?void 0:B[0];if(F){g(F),j(null),f(null),c(new Set);try{const ae=await fe(xe("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await F.arrayBuffer()});if(!ae.ok){const A=await ae.json();throw new Error(A.error||"Failed to preview config file")}const te=await ae.json(),D=Array.isArray(te.categories)?te.categories:[];f({...te,categories:D}),c(new Set(D.map(A=>A.id)))}catch(ae){j({type:"error",text:ae.message||"Failed to read config file"}),g(null)}}},O=async()=>{if(!(!k||r.size===0)){u(!0),j(null);try{const S=Array.from(r).join(","),F=await fe(xe(`/api/config/import?categories=${S}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await k.arrayBuffer()}),B=await F.json();if(!F.ok)throw new Error(B.error||"Import failed");j({type:"success",text:B.message||s("config:data.importSuccess")}),g(null),f(null),c(new Set)}catch(S){j({type:"error",text:S.message||"Import failed"})}finally{u(!1)}}},V=()=>{g(null),f(null),c(new Set),j(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(ya,{checked:!!(p!=null&&p.enabled),disabled:N||!p,onChange:J})]}),e.jsxs("div",{className:"data-backup-info",children:[p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:p.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!p.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:p.scriptPath})]}),p.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(p.lastRunAt).toLocaleString(),p.lastRunOk===!0&&" — ok",p.lastRunOk===!1&&p.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",p.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),U&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:U})]})]}),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:C,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:M,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:n.map(S=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:l.has(S.id),onChange:()=>z(S.id)}),e.jsx("span",{className:"data-category-name",children:S.name})]},S.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ne,disabled:m||l.size===0,children:m?s("config:data.exporting"):s("config:data.exportCount",{count:l.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),k?E?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:k.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(E.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:w,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:R,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:E.categories.map(S=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:r.has(S.id),onChange:()=>X(S.id)}),e.jsx("span",{className:"data-category-name",children:S.name}),S.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",S.fileCount," ",s("config:data.files"),")"]})]},S.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:V,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:O,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:y,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function Sa(){const s=Ks(),n=Ht(),[t,l]=i.useState(n.slugs),[d,r]=i.useState(!1),[c,m]=i.useState(null),[h,o]=i.useState("");i.useEffect(()=>{l(n.slugs)},[n.slugs]);const[u,k]=i.useState(null);i.useEffect(()=>{n.loaded&&k(N=>N??new Set(n.slugs))},[n.loaded,n.slugs]);const g=i.useMemo(()=>{const N=u??new Set(n.slugs);return s.filter($=>$.enabled).sort(($,U)=>{const K=Number(N.has(U.slug))-Number(N.has($.slug));return K!==0?K:$.name.localeCompare(U.name)})},[s,u,n.slugs]),E=i.useMemo(()=>{const N=h.trim().toLowerCase();return N?g.filter($=>$.name.toLowerCase().includes(N)||$.slug.toLowerCase().includes(N)||$.description.toLowerCase().includes(N)):g},[g,h]),f=i.useCallback(async N=>{const $=t;l(N),r(!0),m(null);try{await qt(N)}catch(U){l($),m((U==null?void 0:U.message)||"Failed to save default skills")}finally{r(!1)}},[t]),I=i.useCallback(N=>{f(t.includes(N)?t.filter($=>$!==N):[...t,N])},[f,t]),j=i.useCallback(async()=>{r(!0),m(null);try{await Wt()}catch(N){m((N==null?void 0:N.message)||"Failed to reset default skills")}finally{r(!1)}},[]),p=t.length,b=i.useMemo(()=>{const N=new Set(s.map($=>$.slug));return t.filter($=>!N.has($))},[s,t]);return e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-hint",children:"Skills pre-selected when you create an agent. You can still change them per agent, and agents that already exist are not affected. Each selected skill is added to every new agent's prompt, so fewer means more room for the actual work."}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"8px",flexWrap:"wrap"},children:[e.jsx("input",{type:"text",className:"config-input",placeholder:"Search skills...",value:h,onChange:N=>o(N.target.value),style:{flex:"1 1 160px",minWidth:0}}),e.jsxs("span",{className:"config-hint",style:{whiteSpace:"nowrap"},children:[p," selected"]}),e.jsx("button",{type:"button",className:"config-button",onClick:()=>void j(),disabled:d||!n.configured,title:n.configured?"Go back to the skills Tide Commander ships with":"Already using the shipped defaults",children:"Reset"})]}),c&&e.jsx("span",{className:"config-hint",style:{color:"var(--color-danger, #e5534b)",marginTop:"6px"},children:c}),b.length>0&&e.jsxs("span",{className:"config-hint",style:{marginTop:"6px"},children:["Not installed here, ignored when spawning: ",b.join(", ")]}),e.jsxs("div",{className:"agent-names-list",style:{flexWrap:"wrap",gap:"6px",marginTop:"8px"},children:[E.map(N=>e.jsx("div",{className:`agent-name-chip${t.includes(N.slug)?" agent-name-chip--selected":""}`,style:{cursor:d?"wait":"pointer",userSelect:"none"},title:N.description,onClick:()=>{d||I(N.slug)},children:e.jsx("span",{className:"agent-name-text",children:N.name})},N.id)),E.length===0&&e.jsxs("span",{className:"config-hint",children:['No skills match "',h,'".']})]})]})}function ka(){const[s,n]=i.useState(()=>Hs()),t=l=>{n(l);const d=Ys(l);Js(d)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:qs.map(l=>e.jsxs("button",{className:`theme-option ${s===l.id?"active":""}`,onClick:()=>t(l.id),title:l.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:l.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:l.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:l.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:l.name})]},l.id))})})}function Ca(){const{t:s}=Z(["config"]),{installInfo:n,phase:t,output:l,error:d,newVersion:r,autoRestart:c,refreshInstallInfo:m,runUpdate:h,reset:o}=Xs(),[u,k]=i.useState(!1),g=i.useRef(null);i.useEffect(()=>{m()},[m]),i.useEffect(()=>{g.current&&(g.current.scrollTop=g.current.scrollHeight)},[l]);const E=i.useCallback(()=>{k(!0)},[]),f=i.useCallback(()=>{k(!1)},[]),I=i.useCallback(()=>{k(!1),h()},[h]),j=i.useCallback(()=>{o(),k(!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:E,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:f,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:l||"..."}),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:j,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 Aa(){const{t:s}=Z(["config"]),[n,t]=i.useState(null),[l,d]=i.useState(!1),[r,c]=i.useState(null);i.useEffect(()=>{Zs().then(t).catch(u=>c(u.message))},[]);const m=i.useCallback(async u=>{if(!l){d(!0),c(null);try{t(await Qs(u))}catch(k){c(k.message)}finally{d(!1)}}},[l]),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:l||!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 Ta(){var N;const{t:s}=Z(["config"]),{isAndroid:n,supported:t,otaActive:l,bundleState:d,serverInfo:r,infoError:c,updateAvailable:m,phase:h,progress:o,error:u,autoSync:k,checkNow:g,syncNow:E,resetToBundled:f,setAutoSync:I}=et(),[j,p]=i.useState(null),b=i.useRef(g);return b.current=g,i.useEffect(()=>{n&&(b.current(!1),st.getInfo().then($=>p($.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:[l?s("config:webBundle.sourceOta",{hash:((N=d==null?void 0:d.hash)==null?void 0:N.slice(0,8))??"?"}):s("config:webBundle.sourceBundled"),j&&` · ${s("config:webBundle.apkVersion",{version:j})}`]}),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:k,onChange:$=>I($.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 E(),disabled:h!=="idle"||!r,children:h==="syncing"?s("config:webBundle.syncingPct",{percent:o??0}):s("config:webBundle.syncNow")}),l&&e.jsx("button",{className:"about-update-btn changelog",onClick:()=>void f(),children:s("config:webBundle.reset")})]})]})}function Ea(){const{t:s}=Z(["config"]),[n,t]=i.useState(null),[l,d]=i.useState(!1),[r,c]=i.useState(null);i.useEffect(()=>{nt().then(t).catch(()=>t(null))},[]);const m=i.useCallback(async h=>{if(!l){d(!0),c(null);try{await ot(h),t(h)}catch(o){c(o.message)}finally{d(!1)}}},[l]);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:l,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 Pa(){var p;const{t:s}=Z(["config"]),[n,t]=i.useState(null),[l,d]=i.useState(""),[r,c]=i.useState(!1),[m,h]=i.useState(!1),[o,u]=i.useState(null),[k,g]=i.useState(null),E=i.useCallback(()=>{tt().then(t)},[]);i.useEffect(E,[E]);const f=i.useCallback(async()=>{if(!(m||!l.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:l})}),N=await b.json();if(!b.ok)throw new Error(N.error||"Invalid service account");d(""),c(!1),g(s("config:about.pushSaved",{project:N.projectId})),E()}catch(b){u(b.message)}finally{h(!1)}}},[m,l,E,s]),I=i.useCallback(async()=>{h(!0),u(null),g(null);const b=await at();if(h(!1),!b){u(s("config:about.pushTestFailed"));return}g(s("config:about.pushTestSent",{count:b.sent})),E()},[E,s]);if(!n)return null;const j=((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:j}):s("config:about.pushNotConfigured")})}),r?e.jsxs(e.Fragment,{children:[e.jsx("textarea",{className:"about-push-credentials",value:l,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 f(),disabled:m||!l.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&&j>0&&e.jsx("button",{className:"about-update-btn download",onClick:()=>void I(),disabled:m,children:s("config:about.pushTest")})]}),k&&e.jsx("div",{className:"about-autoupdate-devnote",children:k}),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 _a(){const{t:s}=Z(["config"]),{updateAvailable:n,updateInfo:t,recentReleases:l,isChecking:d,error:r,currentVersion:c,isAndroid:m,downloadPhase:h,downloadProgress:o,checkForUpdate:u,downloadAndInstall:k,openReleasePage:g}=Ws(),[E,f]=i.useState(!1),I=p=>p?`${(p/(1024*1024)).toFixed(1)} MB`:"",j=p=>new Date(p).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:e.jsx(L,{name:"waves",size:24})}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:c}),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(Ca,{}),e.jsx(Aa,{}),e.jsx(Ta,{}),e.jsx(Pa,{}),e.jsx(Ea,{}),e.jsx("div",{className:"about-changelog-row",children:e.jsx("button",{className:"about-update-btn changelog",onClick:()=>f(!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 k(),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")})]}),l.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:l.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:j(p.publishedAt)})]},p.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:e.jsx(L,{name:"package",size:14})}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]}),E&&e.jsx(Gs,{onClose:()=>f(!1)})]})}const Ia={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function Da({onOpenModal:s}){const[n,t]=i.useState([]),[l,d]=i.useState(!0),r=i.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 i.useEffect(()=>{r()},[r]),l?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=Ia[c.id]||"🔌",h=!!c.status.error,o=c.status.connected,u=h?"#f38ba8":o?"#a6e3a1":"#fab387",k=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:k,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:E=>{E.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:E=>{E.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 $a({isOpen:s,onClose:n,initialAgentId:t}){const{t:l}=Z(["config"]),d=it(),[r,c]=i.useState(""),[m,h]=i.useState(""),[o,u]=i.useState(!1),[k,g]=i.useState(""),[E,f]=i.useState(""),[I,j]=i.useState(null),[p,b]=i.useState(null),[N,$]=i.useState(!1),[U,K]=i.useState(!1),[J,z]=i.useState(!1),[X,C]=i.useState(null),M=i.useMemo(()=>[...d].sort((D,A)=>D.name.localeCompare(A.name)),[d]),w=i.useMemo(()=>d.find(D=>D.id===r),[d,r]),R=r===ze;i.useEffect(()=>{if(!s)return;const D=t&&d.some(A=>A.id===t)?t:ze;c(D),u(!1),aa().then(A=>h(A)).catch(()=>h("")).finally(()=>u(!0))},[s]),i.useEffect(()=>{const D=r===ze?m:(w==null?void 0:w.customPrompt)??"";g(D),f(D),$(!1),j(null),b(null)},[r,o]);const ne=D=>{const A=D.target.value;g(A),$(A!==E),j(null),b(null)},y=async()=>{if(r)try{j(null),b(null),R?(await na(k),h(k),b(l("config:systemPrompt.savedGlobal"))):(v.updateAgentProperties(r,{customPrompt:k}),b(l("config:systemPrompt.saved"))),f(k),$(!1)}catch(D){j(D instanceof Error?D.message:"Failed to save system prompt")}},O=()=>{K(!0)},V=async()=>{if(r)try{j(null),b(null),R?(await oa(),h(""),b(l("config:systemPrompt.clearedGlobal"))):(v.updateAgentProperties(r,{customPrompt:""}),b(l("config:systemPrompt.cleared"))),g(""),f(""),$(!1)}catch(D){j(D instanceof Error?D.message:"Failed to clear system prompt")}},S=()=>{g(E),$(!1),j(null),b(null)},F=D=>{if(D!==r){if(N){C(D),z(!0);return}c(D)}},B=()=>{if(N){C(null),z(!0);return}n()},ae=()=>{if(z(!1),X){const D=X;C(null),c(D)}else n()},te=D=>{D.key==="Escape"&&(D.preventDefault(),B())};return s?e.jsxs(Ie,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:B,children:e.jsxs("div",{className:"system-prompt-modal",onClick:D=>D.stopPropagation(),onKeyDown:te,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:l("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:B,"aria-label":"Close",children:e.jsx(L,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"modal-description",children:l("config:systemPrompt.description")}),e.jsxs("div",{className:"agent-picker",children:[e.jsx("label",{htmlFor:"system-prompt-agent",className:"editor-label",children:l("config:systemPrompt.agentLabel")}),e.jsxs("div",{className:"agent-picker-row",children:[R?e.jsx(L,{name:"globe",size:20,className:"agent-picker-icon"}):w&&e.jsx(lt,{classId:w.class,size:20,className:"agent-picker-icon"}),e.jsxs("select",{id:"system-prompt-agent",className:"agent-picker-select",value:r,onChange:D=>F(D.target.value),children:[e.jsxs("option",{value:ze,children:[l("config:systemPrompt.globalOption"),m?" • ✦":""]}),M.map(D=>e.jsxs("option",{value:D.id,children:[D.name,D.customPrompt?" • ✦":""]},D.id))]})]})]}),I&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"warn",size:14})}),I]}),p&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{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:l("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[k.length," ",l("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:k,onChange:ne,placeholder:l("config:systemPrompt.placeholder"),rows:18,disabled:R&&!o,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:l(R?"config:systemPrompt.hintGlobal":"config:systemPrompt.hint")})]})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:O,disabled:!k||!r,children:l("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:B,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:S,disabled:!N,children:l("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:y,disabled:!N||!r,children:l("config:systemPrompt.save")})]})]})]})}),e.jsx(be,{isOpen:U,title:l("config:systemPrompt.clear"),message:l(R?"config:systemPrompt.confirmClearGlobal":"config:systemPrompt.confirmClear"),confirmLabel:l("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{V()},onClose:()=>K(!1)}),e.jsx(be,{isOpen:J,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:ae,onClose:()=>{z(!1),C(null)}})]}):null}const ms={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},La=2500,Oa=12e4;function gs(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function Fa(s,n){return s.enabled===n.enabled&&s.baseUrl===n.baseUrl&&s.defaultSessionId===n.defaultSessionId&&s.webhookVerifyToken===n.webhookVerifyToken&&s.showIncomingToasts===n.showIncomingToasts}function Ra({isOpen:s,onClose:n}){const{t}=Z(["config"]),[l,d]=i.useState(ms),[r,c]=i.useState(ms),[m,h]=i.useState(!1),[o,u]=i.useState([]),[k,g]=i.useState(!0),[E,f]=i.useState(null),[I,j]=i.useState(null),[p,b]=i.useState(""),[N,$]=i.useState(!1),[U,K]=i.useState(""),[J,z]=i.useState(null),[X,C]=i.useState(null),[M,w]=i.useState(null),R=i.useRef(null),ne=i.useRef(0),[y,O]=i.useState(""),[V,S]=i.useState(""),[F,B]=i.useState(null),[ae,te]=i.useState(!1),[D,A]=i.useState(!1),[se,ie]=i.useState(!1),[ce,le]=i.useState(!1),[he,Ae]=i.useState(null),Se=!Fa(l,r),pe=i.useCallback(()=>{R.current&&(clearTimeout(R.current),R.current=null)},[]),Te=i.useCallback(async()=>{try{g(!0),f(null),j(null);const[x,H]=await Promise.all([ys(),ct()]),re=gs(x);if(d(re),c(re),h(!!H.configured),H.configured)try{const Ne=await Ze();u(Array.isArray(Ne)?Ne:[])}catch{u([])}else u([])}catch(x){f(x instanceof Error?x.message:t("config:whatsapp.errors.loadFailed"))}finally{g(!1)}},[t]),je=i.useCallback(async()=>{try{const x=await Ze();u(Array.isArray(x)?x:[])}catch{}},[]);i.useEffect(()=>(s?Te():(pe(),z(null),C(null),w(null),b(""),$(!1),B(null)),()=>{pe()}),[s,Te,pe]);const me=(x,H)=>{d(re=>({...re,[x]:H})),f(null),j(null)},De=async()=>{try{f(null),j(null);const x=await ht({enabled:l.enabled,baseUrl:l.baseUrl.trim(),defaultSessionId:l.defaultSessionId.trim(),webhookVerifyToken:l.webhookVerifyToken,showIncomingToasts:l.showIncomingToasts});window.dispatchEvent(new CustomEvent("tide:whatsapp-config-updated"));const H=gs(x);d(H),c(H),j(t("config:whatsapp.saved"))}catch(x){f(x instanceof Error?x.message:t("config:whatsapp.errors.saveFailed"))}},$e=()=>{d(r),f(null),j(null)},ve=()=>{if(Se){A(!0);return}n()},Le=x=>{x.key==="Escape"&&(x.preventDefault(),ve())},Ke=async()=>{const x=p.trim();if(x)try{f(null),j(null),await dt(x),b(""),$(!1),h(!0),j(t("config:whatsapp.apiKeySaved"))}catch(H){f(H instanceof Error?H.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},He=()=>{ie(!0)},Oe=async()=>{try{f(null),j(null),await mt(),h(!1),j(t("config:whatsapp.apiKeyCleared"))}catch(x){f(x instanceof Error?x.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},Fe=i.useCallback(async x=>{if(Date.now()>ne.current){w(t("config:whatsapp.pairingTimeout")),z(null),C(null),pe(),je();return}try{const H=await rt(x);if(H.status&&["connected","paired","open","ready"].includes(H.status.toLowerCase())){w(t("config:whatsapp.pairingSuccess")),z(null),C(null),pe(),je();return}const Ne=H.qrUrl??H.qr??null;Ne&&C(Ne)}catch(H){w(H instanceof Error?H.message:t("config:whatsapp.errors.qrFetchFailed"))}R.current=setTimeout(()=>{Fe(x)},La)},[je,pe,t]),Re=async()=>{const x=U.trim();if(x)try{f(null),j(null),w(null),C(null),pe(),await ut(x),K(""),z(x),ne.current=Date.now()+Oa,Fe(x),je()}catch(H){f(H instanceof Error?H.message:t("config:whatsapp.errors.sessionCreateFailed"))}},Be=()=>{pe(),z(null),C(null),w(null)},ke=x=>{Ae(x),le(!0)},_=async()=>{if(he)try{f(null),j(null),await gt(he),J===he&&Be(),je(),j(t("config:whatsapp.sessionDeleted"))}catch(x){f(x instanceof Error?x.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{Ae(null)}},ue=async()=>{const x=y.trim(),H=V.trim();if(!(!x||!H))try{te(!0),B(null);const re=l.defaultSessionId.trim()||void 0;await pt(x,H,re),B({kind:"success",text:t("config:whatsapp.testSent")})}catch(re){B({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:x=>x.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(L,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:k?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsapp.description")}),E&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"warn",size:14})}),E]}),I&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{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:l.enabled,onChange:x=>me("enabled",x.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:l.showIncomingToasts,onChange:x=>me("showIncomingToasts",x.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:l.baseUrl,onChange:x=>me("baseUrl",x.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:l.defaultSessionId,onChange:x=>me("defaultSessionId",x.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:l.webhookVerifyToken,onChange:x=>me("webhookVerifyToken",x.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(L,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(L,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:N?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:p,onChange:x=>b(x.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>$(x=>!x),title:t(N?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(L,{name:N?"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(x=>e.jsxs("div",{className:"wa-session-row",children:[e.jsxs("div",{className:"wa-session-info",children:[e.jsx("span",{className:"wa-session-id",children:x.id}),e.jsx("span",{className:`wa-session-status status-${(x.status??"unknown").toLowerCase()}`,children:x.status||"—"}),x.pairedNumber&&e.jsx("span",{className:"wa-session-paired",children:x.pairedNumber})]}),e.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:()=>ke(x.id),children:t("config:whatsapp.deleteSession")})]},x.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:U,onChange:x=>K(x.target.value),onKeyDown:x=>{x.key==="Enter"&&Re()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Re,disabled:!U.trim()||J!==null,children:t("config:whatsapp.addSession")})]}),J&&e.jsxs("div",{className:"wa-qr-panel",children:[e.jsxs("div",{className:"wa-qr-header",children:[e.jsx("span",{children:t("config:whatsapp.qrPrompt",{id:J})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick: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")})]})]}),M&&!J&&e.jsx("div",{className:"wa-pairing-message",children:M})]}),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:y,onChange:x=>O(x.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:V,onChange:x=>S(x.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:!y.trim()||!V.trim()||ae,children:t(ae?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),F&&e.jsxs("div",{className:`alert ${F.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:F.kind==="success"?"check":"warn",size:14})}),F.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||k,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:De,disabled:!Se||k,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(be,{isOpen:D,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{A(!1),n()},onClose:()=>A(!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 Ba(){const s=await fetch(`${Y()}/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 Ma(s){const n=await fetch(`${Y()}/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 Ua(){const s=await fetch(`${Y()}/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 za(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 Va({isOpen:s,onClose:n}){const{t}=Z(["config"]),[l,d]=i.useState(fs),[r,c]=i.useState(fs),[m,h]=i.useState(!0),[o,u]=i.useState(null),[k,g]=i.useState(null),[E,f]=i.useState(!1),[I,j]=i.useState(!1),p=!za(l,r),b=i.useCallback(async()=>{try{h(!0),u(null),g(null);const C=await Ba(),M={filter:{...Ve,...C.filter},recipient:C.recipient??""};d(M),c(M)}catch(C){u(C instanceof Error?C.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{h(!1)}},[t]);i.useEffect(()=>{s&&b()},[s,b]);const N=(C,M)=>{d(w=>({...w,filter:{...w.filter,[C]:M}})),u(null),g(null)},$=C=>{d(M=>({...M,recipient:C})),u(null),g(null)},U=async()=>{try{u(null),g(null);const C=await Ma({filter:l.filter,recipient:l.recipient.trim()}),M={filter:{...Ve,...C.filter},recipient:C.recipient??""};d(M),c(M),g(t("config:whatsappNotifications.saved"))}catch(C){u(C instanceof Error?C.message:t("config:whatsappNotifications.errors.saveFailed"))}},K=()=>{d(r),u(null),g(null)},J=async()=>{try{u(null),g(null);const C=await Ua(),M={filter:{...Ve,...C.filter},recipient:C.recipient??""};d(M),c(M),g(t("config:whatsappNotifications.resetDone"))}catch(C){u(C instanceof Error?C.message:t("config:whatsappNotifications.errors.resetFailed"))}},z=()=>{if(p){f(!0);return}n()},X=C=>{C.key==="Escape"&&(C.preventDefault(),z())};return s?e.jsxs(Ie,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:z,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:C=>C.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:z,"aria-label":"Close",children:e.jsx(L,{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(L,{name:"warn",size:14})}),o]}),k&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"check",size:14})}),k]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.recipient")}),e.jsxs("div",{className:"wan-field",children:[e.jsx("label",{htmlFor:"wan-recipient",className:"wan-label",children:t("config:whatsappNotifications.recipientLabel")}),e.jsx("input",{id:"wan-recipient",type:"text",className:"wan-input",placeholder:t("config:whatsappNotifications.recipientPlaceholder"),value:l.recipient,onChange:C=>$(C.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(C=>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.${C}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${C}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:l.filter[C],onChange:M=>N(C,M.target.checked)}),e.jsx("span",{className:"wan-toggle-track",children:e.jsx("span",{className:"wan-toggle-thumb"})})]})]},C))]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:()=>j(!0),disabled:m,children:t("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:z,children:t("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:K,disabled:!p||m,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:U,disabled:!p||m,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(be,{isOpen:E,title:t("config:whatsappNotifications.unsavedTitle"),message:t("config:whatsappNotifications.unsavedMessage"),confirmLabel:t("config:whatsappNotifications.closeAnyway"),cancelLabel:t("config:whatsappNotifications.keepEditing"),variant:"danger",onConfirm:()=>{f(!1),n()},onClose:()=>f(!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:()=>{J(),j(!1)},onClose:()=>j(!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 Ka(s,n=Date.now()){const t=s*1e3,l=n-t;if(l<0)return xs(t);const d=Math.floor(l/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 Ha(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 qa(s,n){return s.length<=n?s:s.slice(0,Math.max(0,n-1)).trimEnd()+"…"}function Wa({chats:s,selectedChatId:n,loading:t,error:l,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:"⟳"})]}),l&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:l}),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&&!l&&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}]`,k=h.chatId===n,g=As(h.chatId),E=h.isGroup?h.groupName:h.fromName,f=E||g,I=!!E&&E!==g;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${k?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>d(h.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:h.chatId,children:f}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:Ka(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," "]}),qa(u,40)]}),h.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:h.unreadCount})]})]})},h.chatId)})})]})}function Ga({message:s}){const n=s.direction==="outbound"?"outbound":"inbound",t=Ts(s.messageType),l=(s.body??"").trim(),d=l.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:l}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:r}),s.audioTranscription&&e.jsxs("span",{className:"whatsapp-history-bubble__transcription",children:["“",s.audioTranscription,"”"]}),s.mediaPath&&e.jsx("a",{className:"whatsapp-history-bubble__media-link",href:s.mediaPath,target:"_blank",rel:"noopener noreferrer",children:s.mediaFilename||"open media"}),e.jsx("span",{className:"whatsapp-history-bubble__time",children:Ha(s.timestamp)})]})})}const Ya=["all","inbound","outbound"],Ja=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function Xa({direction:s,type:n,onDirectionChange:t,onTypeChange:l,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:Ya.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=>l(c.target.value),disabled:d,children:Ja.map(c=>e.jsx("option",{value:c,children:r(`config:whatsappHistory.typeValues.${c}`)},c))})]})]})}const Za=80;function Qa({chatId:s,messages:n,loading:t,loadingMore:l,error:d,hasMore:r,direction:c,type:m,onDirectionChange:h,onTypeChange:o,onLoadMore:u}){const{t:k}=Z(["config"]),g=i.useRef(null),E=i.useRef(null),f=i.useRef(!1),I=i.useRef(null);i.useEffect(()=>{E.current!==s&&(E.current=s,f.current=!1)},[s]),i.useLayoutEffect(()=>{g.current&&(f.current||n.length!==0&&(g.current.scrollTop=g.current.scrollHeight,f.current=!0))},[s,n.length]),i.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 j=i.useCallback(()=>{!r||l||t||(g.current&&(I.current=g.current.scrollHeight),u())},[r,l,t,u]),p=i.useCallback(b=>{if(!f.current)return;b.currentTarget.scrollTop<=Za&&j()},[j]);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(Xa,{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:j,disabled:l||t,children:k(l?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),d&&e.jsx("div",{className:"whatsapp-history-messages__error",children:d}),t&&n.length===0&&e.jsxs("div",{className:"whatsapp-history-messages__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:k("config:whatsappHistory.loadingMessages")})]}),!t&&!d&&n.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:k("config:whatsappHistory.emptyMessages")}),n.map(b=>e.jsx(Ga,{message:b},en(b)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:k("config:whatsappHistory.selectChat")})})}function en(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 sn(s){const n=`${Y()}/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 l=new URLSearchParams;t.cursor&&l.set("cursor",t.cursor),typeof t.limit=="number"&&l.set("limit",String(t.limit)),t.direction&&l.set("direction",t.direction),t.type&&l.set("type",t.type);const d=l.toString(),r=`${Y()}/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 tn=50;function an({isOpen:s,onClose:n}){const{t}=Z(["config"]),[l,d]=i.useState([]),[r,c]=i.useState(null),[m,h]=i.useState(null),[o,u]=i.useState([]),[k,g]=i.useState(!1),[E,f]=i.useState(null),[I,j]=i.useState(null),[p,b]=i.useState([]),[N,$]=i.useState(!1),[U,K]=i.useState(!1),[J,z]=i.useState(null),[X,C]=i.useState(null),[M,w]=i.useState("all"),[R,ne]=i.useState("all"),[y,O]=i.useState(()=>Date.now()),V=i.useRef(0);i.useEffect(()=>{if(!s)return;const A=window.setInterval(()=>O(Date.now()),6e4);return()=>window.clearInterval(A)},[s]),i.useEffect(()=>{if(!s)return;let A=!1;return(async()=>{var se;try{h(null);const[ie,ce]=await Promise.all([Ze().catch(()=>[]),ys().catch(()=>null)]);if(A)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(A)return;h(ie instanceof Error?ie.message:String(ie))}})(),()=>{A=!0}},[s]);const S=i.useCallback(async A=>{g(!0),f(null);try{const se=await sn(A);u(se.chats)}catch(se){f(se instanceof Error?se.message:String(se))}finally{g(!1)}},[]);i.useEffect(()=>{!s||!r||(j(null),b([]),C(null),S(r))},[s,r,S]);const F=i.useMemo(()=>{const A={limit:tn};return M!=="all"&&(A.direction=M),R!=="all"&&(A.type=R),A},[M,R]),B=i.useCallback(async(A,se,ie)=>{const ce=++V.current;$(!0),z(null),b([]),C(null);try{const le=await bs(A,se,ie);if(ce!==V.current)return;b([...le.messages].reverse()),C(le.nextCursor)}catch(le){if(ce!==V.current)return;z(le instanceof Error?le.message:String(le))}finally{ce===V.current&&$(!1)}},[]);i.useEffect(()=>{!s||!r||!I||B(r,I,F)},[s,r,I,F,B]);const ae=i.useCallback(async()=>{if(!(!r||!I||!X)){K(!0),z(null);try{const A=await bs(r,I,{...F,cursor:X});b(se=>[...[...A.messages].reverse(),...se]),C(A.nextCursor)}catch(A){z(A instanceof Error?A.message:String(A))}finally{K(!1)}}},[r,I,X,F]),te=i.useCallback(()=>{r&&S(r)},[r,S]),D=i.useCallback(A=>{A.key==="Escape"&&(A.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:A=>A.stopPropagation(),onKeyDown:D,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:A=>c(A.target.value||null),disabled:l.length===0,children:[l.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),l.map(A=>e.jsxs("option",{value:A.id,children:[A.id,A.pairedNumber?` (${A.pairedNumber})`:""]},A.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(L,{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(Wa,{chats:o,selectedChatId:I,loading:k,error:E,onSelect:j,onRefresh:te,now:y}),e.jsx(Qa,{chatId:I,messages:p,loading:N,loadingMore:U,error:J,hasMore:X!==null,direction:M,type:R,onDirectionChange:w,onTypeChange:ne,onLoadMore:ae})]})]})})}):null}function nn({isOpen:s,onClose:n,onOpenConfig:t,onOpenNotifications:l,onOpenHistory:d}){const{t:r}=Z(["config"]);if(i.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(L,{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(L,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children: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(l),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(L,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children: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(L,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children: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:Et}],on=[{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:"🌙"}],ln=[{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:"🔴"}],cn=[{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:"👎"}],rn=[{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:"💜"}],dn=[{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"}],un=[{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"}],pn={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},hn={none:"grass","pokemon-stadium":"pokemon"},mn={"emote-yes":"yes","emote-no":"no"},gn={"":"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:l=!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}),!l&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function T({text:s,query:n}){if(!n.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),l=n.toLowerCase(),d=t.indexOf(l);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 fn({config:s,onChange:n,searchQuery:t="",onOpenIntegrationsModal:l,onOpenPluginsModal:d,onOpenMonitoringModal:r,onOpenStatisticsModal:c,onOpenWorkflowEditor:m,onOpenTriggerManager:h}){var ls;const{t:o}=Z(["config","common"]),u=ft(),k=xt(),[g,E]=i.useState(()=>bt(Pe.DEFAULT_AGENT_CLASS)||"scout"),f=jt(),I=vt(),[j,p]=i.useState(()=>Nt()),[b,N]=i.useState(null),[$,U]=i.useState(null),[K,J]=i.useState("");i.useEffect(()=>{qe().then(p)},[]);const z=async(a,P)=>{U(null),N(a);try{const q=await fe(xe(`/api/custom-sounds/${a}`),{method:"POST",headers:{"Content-Type":P.type||"audio/mpeg"},body:P});if(!q.ok){const de=await q.json().catch(()=>({error:`Upload failed (${q.status})`}));throw new Error(de.error||`Upload failed (${q.status})`)}const oe=await qe();p({...oe});const ge=Je.find(de=>de.kind===a);ge&&v.updateSettings({[ge.settingKey]:_e}),We(_e,u.notificationSoundVolume,a)}catch(q){U(q instanceof Error?q.message:"Upload failed")}finally{N(null)}},X=async a=>{U(null);try{await fe(xe(`/api/custom-sounds/${a}`),{method:"DELETE"}),$t({[a]:null});const P=await qe();p({...P});const q=Je.find(oe=>oe.kind===a);q&&v.getSettings()[q.settingKey]===_e&&v.updateSettings({[q.settingKey]:Lt[a]})}catch(P){U(P instanceof Error?P.message:"Failed to reset sound")}},[C,M]=i.useState(u.historyLimit),[w,R]=i.useState(()=>yt()),[ne,y]=i.useState(!1),[O,V]=i.useState(""),[S,F]=i.useState(()=>Q()),[B,ae]=i.useState(!1),[te,D]=i.useState(!1),[A,se]=i.useState(""),[ie,ce]=i.useState(!1),[le,he]=i.useState(!1),[Ae,Se]=i.useState(!1),[pe,Te]=i.useState(!1),[je,me]=i.useState(!1),[De,$e]=i.useState(""),[ve,Le]=i.useState(!1);i.useEffect(()=>{ca().then($e).catch(()=>{})},[]),i.useEffect(()=>{ia().then(a=>{a!==u.experimentalEchoPrompt&&v.updateSettings({experimentalEchoPrompt:a})}).catch(()=>{})},[]),i.useEffect(()=>{da().then(a=>{a!==u.tmuxMode&&v.updateSettings({tmuxMode:a})}).catch(()=>{})},[]),i.useEffect(()=>{pa().then(a=>{a!==u.interactiveMode&&v.updateSettings({interactiveMode:a})}).catch(()=>{})},[]),i.useEffect(()=>{ma().then(a=>{a!==u.codexAppServerMode&&v.updateSettings({codexAppServerMode:a})}).catch(()=>{})},[]),i.useEffect(()=>{fa().then(a=>{a!==u.opencodeServerMode&&v.updateSettings({opencodeServerMode:a})}).catch(()=>{})},[]),i.useEffect(()=>{ba().then(a=>{a!==u.piRpcMode&&v.updateSettings({piRpcMode:a})}).catch(()=>{})},[]),i.useEffect(()=>wt(a=>{R(a),y(!1)}),[]);const Ke=on.map(a=>({...a,label:o(`config:time.${a.value}`)})),He=ln.map(a=>({...a,label:o(`config:floor.${hn[a.value]||a.value}`)})),Oe=cn.map(a=>({...a,label:o(`config:animation.${mn[a.value]||a.value}`)})),Fe=rn.map(a=>({...a,label:o(`config:colorMode.${a.value}`)})),Re=dn.map(a=>({...a,label:o(`config:terrain.${pn[a.key]}`)})),Be=un.map(a=>({...a,label:o(`config:sky.${gn[a.value??""]}`)})),ke=t.trim()?Gt(t).map(a=>a.id):null,_=a=>ke?ke.includes(a):!0,ue=u.customAgentNames||[],x=ue.length>0?ue:St,H=()=>{const a=A.trim();a&&!ue.includes(a)&&(v.updateSettings({customAgentNames:[...ue,a]}),se(""))},re=a=>{v.updateSettings({customAgentNames:ue.filter(P=>P!==a)})},Ne=()=>{v.updateSettings({customAgentNames:[]})},Me=u.fileSearchExcludeDirs??[...rs],ss=()=>{const a=K.trim();if(ps(a)){if(Me.includes(a)){J("");return}v.updateSettings({fileSearchExcludeDirs:[...Me,a]}),J("")}},_s=a=>{v.updateSettings({fileSearchExcludeDirs:Me.filter(P=>P!==a)})},Is=()=>{v.updateSettings({fileSearchExcludeDirs:[...rs]})},ts=()=>{const a=O.trim();if(a){if(w.includes(a)){V("");return}R([...w,a]),y(!0),V("")}},Ds=a=>{R(w.filter((P,q)=>q!==a)),y(!0)},as=(a,P)=>{const q=a+P;if(q<0||q>=w.length)return;const oe=w.slice();[oe[a],oe[q]]=[oe[q],oe[a]],R(oe),y(!0)},$s=()=>{Ot(w),y(!1),Ye()},Ls=a=>{F(a),ae(!0)},ns=()=>{Ue(Pe.AUTH_TOKEN,S),ae(!1),Ye()},Os=a=>{$e(a),Le(!0)},os=()=>{ra(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=>{M(a),v.updateSettings({historyLimit:a})},Rs=a=>{const P=s.terrain[a];typeof P=="boolean"&&ye({[a]:!P})},G=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(W,{title:"Plugins",storageKey:"plugins",defaultOpen:!0,forceOpen:G&&_("plugins"),children:e.jsxs("div",{className:"config-row config-row--plugins",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(W,{title:o("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:G&&_("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:o("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:C,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(T,{text:o("config:general.hideCosts"),query:t})}),e.jsx(ee,{checked:u.hideCost,onChange:a=>v.updateSettings({hideCost:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.streamTextLiveTitle"),children:e.jsx(T,{text:o("config:general.streamTextLive"),query:t})}),e.jsx(ee,{checked:u.streamTextLive!==!1,onChange:a=>v.updateSettings({streamTextLive:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.toolHoverPreviewTitle"),children:e.jsx(T,{text:o("config:general.toolHoverPreview"),query:t})}),e.jsx(ee,{checked:u.toolHoverPreview===!0,onChange:a=>v.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(T,{text:"Agent activity dock",query:t})}),e.jsx("select",{className:"config-select",value:f,onChange:a=>At(a.target.value),children:kt.map(a=>e.jsx("option",{value:a,children:Ct[a]},a))})]}),f!=="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(T,{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=>Tt(parseInt(a.target.value,10)||0)})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(T,{text:o("config:general.showFPS"),query:t})}),e.jsx(ee,{checked:u.showFPS,onChange:a=>v.updateSettings({showFPS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(T,{text:o("config:general.powerSaving"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.powerSaving,onChange:a=>v.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(T,{text:o("config:general.lowPowerMode"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.lowPowerMode===!0,onChange:a=>v.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(T,{text:o("config:general.tmuxMode"),query:t})}),e.jsx(ee,{checked:u.tmuxMode,onChange:async a=>{v.updateSettings({tmuxMode:a});try{await ua(a)}catch(P){console.error("Failed to sync tmux mode setting to server:",P)}}})]}),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(T,{text:o("config:general.interactiveMode"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.interactiveMode,onChange:async a=>{v.updateSettings({interactiveMode:a});try{await ha(a)}catch(P){console.error("Failed to sync interactive mode setting to server:",P)}}})]}),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(T,{text:o("config:general.codexAppServerMode"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.codexAppServerMode,onChange:async a=>{v.updateSettings({codexAppServerMode:a});try{await ga(a)}catch(P){console.error("Failed to sync codex app-server mode setting to server:",P)}}})]}),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(T,{text:o("config:general.opencodeServerMode"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.opencodeServerMode,onChange:async a=>{v.updateSettings({opencodeServerMode:a});try{await xa(a)}catch(P){console.error("Failed to sync opencode server mode setting to server:",P)}}})]}),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(T,{text:o("config:general.piRpcMode"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.piRpcMode,onChange:async a=>{v.updateSettings({piRpcMode:a});try{await ja(a)}catch(P){console.error("Failed to sync pi RPC mode setting to server:",P)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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=>v.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(T,{text:"Notification sounds",query:t})}),e.jsx(ee,{checked:u.notificationSoundEnabled,onChange:a=>{v.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(T,{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 P=parseInt(a.target.value);v.updateSettings({notificationSoundVolume:P}),Ss(P,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(T,{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 P=!!j[a.kind],q=u[a.settingKey],oe=P&&q===_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=Pt(q))==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:q,onChange:de=>{const Ee=de.target.value;v.updateSettings({[a.settingKey]:Ee}),We(Ee,u.notificationSoundVolume,a.kind)},children:[P&&e.jsx("option",{value:_e,children:"Your uploaded file"}),_t.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(q,u.notificationSoundVolume,a.kind),disabled:us(q),title:us(q)?"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&&z(a.kind,Ee)}})]}),P&&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)}),$&&e.jsx("div",{className:"config-sound-error",children:$})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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=>v.updateSettings({externalEditorCommand:a.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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=>v.updateSettings({tabTitle:a.target.value})})]}),e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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:K,onChange:a=>J(a.target.value),onKeyDown:a=>{a.key==="Enter"&&ss()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ss,disabled:!ps(K),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(T,{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 P;if(a==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const q=navigator.language,oe=((P=Xe.find(ge=>ge.value!=="auto"&&q.startsWith(ge.value.split("-")[0])))==null?void 0:P.value)||"en";Ge.changeLanguage(oe)}else localStorage.setItem("tide-commander-language-mode","manual"),Ge.changeLanguage(a)}})]})]}),_("agentNames")&&e.jsx(W,{title:o("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:G&&_("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children: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:A,onChange:a=>se(a.target.value),onKeyDown:a=>{a.key==="Enter"&&H()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:H,disabled:!A.trim(),title:o("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:x.map((a,P)=>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}-${P}`))}),ue.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:Ne,children:o("common:buttons.resetToDefaults")})]})}),_("defaultClass")&&e.jsx(W,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:G&&_("defaultClass"),children:e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-hint",children:'Class pre-selected when the spawn modal opens. "Random" picks a different class each time.'}),e.jsxs("div",{className:"agent-names-list",style:{flexWrap:"wrap",gap:"6px",marginTop:"8px"},children:[e.jsx("div",{className:`agent-name-chip${g==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{E("random"),Ue(Pe.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(It).map(([a,P])=>e.jsx("div",{className:`agent-name-chip${g===a?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{E(a),Ue(Pe.DEFAULT_AGENT_CLASS,a)},children:e.jsxs("span",{className:"agent-name-text",children:[P.icon," ",a.charAt(0).toUpperCase()+a.slice(1)]})},a)),k.map(a=>e.jsx("div",{className:`agent-name-chip${g===a.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{E(a.id),Ue(Pe.DEFAULT_AGENT_CLASS,a.id)},children:e.jsxs("span",{className:"agent-name-text",children:[a.icon," ",a.name]})},a.id))]})]})}),_("defaultSkills")&&e.jsx(W,{title:"Default Agent Skills",storageKey:"defaultSkills",defaultOpen:!1,forceOpen:G&&_("defaultSkills"),children:e.jsx(Sa,{})}),_("appearance")&&e.jsx(W,{title:o("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:G&&_("appearance"),children:e.jsx(ka,{})}),_("connection")&&e.jsxs(W,{title:o("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:G&&_("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:o("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:w.map((a,P)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:o("config:connection.priorityLabel",{defaultValue:"Priority"}),children:P+1}),e.jsx("span",{className:"backend-url-text",title:a,children:a}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>as(P,-1),disabled:P===0,title:o("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>as(P,1),disabled:P===w.length-1,title:o("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ds(P),title:o("common:buttons.remove"),children:"x"})]},`${a}-${P}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:O,onChange:a=>V(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:!O.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(T,{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:S,onChange:a=>Ls(a.target.value),placeholder:o("config:connection.tokenPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&B&&ns()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>D(!te),title:o(te?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(L,{name:te?"eye-closed":"eye",size:14})}),B&&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(T,{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(T,{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(W,{title:o("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:G&&_("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(T,{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(T,{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(T,{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(T,{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(W,{title:o("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:G&&_("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(T,{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(T,{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(T,{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(T,{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(T,{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(W,{title:o("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:G&&_("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(T,{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(T,{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(T,{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(T,{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(T,{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(T,{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(W,{title:o("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:G&&_("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{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(T,{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(W,{title:o("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:G&&_("secrets"),children:e.jsx(ta,{})}),_("claudeAccounts")&&e.jsx(W,{title:o("config:sections.claudeAccounts",{defaultValue:"Claude Accounts"}),storageKey:"claudeAccounts",defaultOpen:!1,forceOpen:G&&_("claudeAccounts"),children:e.jsx(Dt,{})}),_("grokAccounts")&&e.jsx(W,{title:o("config:sections.grokAccounts",{defaultValue:"Grok Accounts"}),storageKey:"grokAccounts",defaultOpen:!1,forceOpen:G&&_("grokAccounts"),children:e.jsx(hs,{provider:"grok"})}),_("codexAccounts")&&e.jsx(W,{title:o("config:sections.codexAccounts",{defaultValue:"Codex Accounts"}),storageKey:"codexAccounts",defaultOpen:!1,forceOpen:G&&_("codexAccounts"),children:e.jsx(hs,{provider:"codex"})}),_("systemPrompt")&&e.jsx(W,{title:o("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:G&&_("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:o("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>ce(!0),children:o("config:systemPrompt.editPrompt")})]})}),_("data")&&e.jsx(W,{title:o("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:G&&_("data"),children:e.jsx(wa,{})}),_("integrations")&&e.jsx(W,{title:o("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:G&&_("integrations"),children:e.jsx(Da,{onOpenModal:a=>{a==="whatsapp"?me(!0):l==null||l(a)}})}),_("workflows")&&e.jsxs(W,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:G&&_("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(T,{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(W,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:G&&_("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(T,{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(W,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:G&&_("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(T,{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(W,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:G&&_("statistics"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(T,{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(W,{title:o("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:G&&_("experimental"),children:[e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Lightweight 2D top-down view for better performance",children:[e.jsx(T,{text:o("config:experimental.2dView"),query:t})," ",e.jsx(L,{name:"map",size:12})]}),e.jsx(ee,{checked:u.experimental2DView,onChange:a=>v.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(T,{text:o("config:experimental.voiceAssistant"),query:t})," ",e.jsx(L,{name:"microphone",size:12})]}),e.jsx(ee,{checked:u.experimentalVoiceAssistant,onChange:a=>v.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(T,{text:o("config:experimental.tts"),query:t})," ",e.jsx(L,{name:"speaker-on",size:12})]}),e.jsx(ee,{checked:u.experimentalTTS,onChange:a=>v.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(T,{text:o("config:experimental.echoPrompt"),query:t})}),e.jsx(ee,{checked:u.experimentalEchoPrompt,onChange:async a=>{v.updateSettings({experimentalEchoPrompt:a});try{await la(a)}catch(P){console.error("Failed to sync echo prompt setting to server:",P)}}})]}),e.jsx("span",{className:"config-hint",children:o("config:experimental.hint")})]}),_("about")&&e.jsx(W,{title:o("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:G&&_("about"),children:e.jsx(_a,{})})]}),e.jsx($a,{isOpen:ie,onClose:()=>ce(!1)}),e.jsx(Ra,{isOpen:le,onClose:()=>he(!1)}),e.jsx(Va,{isOpen:Ae,onClose:()=>Se(!1)}),e.jsx(an,{isOpen:pe,onClose:()=>Te(!1)}),e.jsx(nn,{isOpen:je,onClose:()=>me(!1),onOpenConfig:()=>he(!0),onOpenNotifications:()=>Se(!0),onOpenHistory:()=>Te(!0)})]})}function wn({onConfigChange:s,onToolChange:n,config:t,isOpen:l,onClose:d,initialSearchQuery:r,onOpenBuildingModal:c,onOpenAreaExplorer:m,onOpenIntegrationsModal:h,onOpenPluginsModal:o,onOpenMonitoringModal:u,onOpenStatisticsModal:k,onOpenWorkflowEditor:g,onOpenTriggerManager:E}){const{t:f}=Z(["config","common"]),I=Ft(),j=Rt(),p=Bt(),b=Mt(),N=Ut(),$=Array.from(I.values()),U=Array.from(j.values()),[K,J]=i.useState(""),z=i.useRef(null);if(i.useEffect(()=>{const w=R=>{R.key==="Escape"&&l&&d()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[l,d]),i.useEffect(()=>{l&&J(r??"")},[l,r]),i.useEffect(()=>{if(l&&z.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const R=setTimeout(()=>{var ne;(ne=z.current)==null||ne.focus()},50);return()=>clearTimeout(R)}},[l]),!l)return null;const X=w=>{n(N===w?null:w)},C=w=>{v.selectArea(b===w?null:w),n("select")},M=(w,R)=>{w.stopPropagation(),v.deleteArea(R)};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:f("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:f("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:z,type:"text",placeholder:f("config:searchPlaceholder"),value:K,onChange:w=>J(w.target.value),className:"toolbox-search-input"}),K&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>J(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(W,{title:f("config:areas.title",{count:$.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${N==="select"?"active":""}`,onClick:()=>X("select"),title:f("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 ${N==="rectangle"?"active":""}`,onClick:()=>X("rectangle"),title:f("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 ${N==="circle"?"active":""}`,onClick:()=>X("circle"),title:f("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:$.length===0?e.jsx("div",{className:"areas-empty",children:f("config:areas.drawToCreate")}):$.map(w=>e.jsx(Xt,{area:w,isSelected:b===w.id,onClick:()=>C(w.id),onDelete:R=>M(R,w.id)},w.id))})]})}),b&&e.jsx(sa,{area:I.get(b),onClose:()=>v.selectArea(null),onOpenFolder:m}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(W,{title:f("config:buildings.title",{count:U.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:w=>{w.stopPropagation(),c==null||c()},title:f("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:U.length===0?e.jsx("div",{className:"buildings-empty",children:f("config:buildings.clickToAdd")}):U.map(w=>e.jsx(Zt,{building:w,isSelected:p.has(w.id),onClick:()=>{v.selectBuilding(p.has(w.id)?null:w.id)},onEdit:()=>c==null?void 0:c(w.id)},w.id))})})}),p.size===1&&(()=>{const w=Array.from(p)[0],R=j.get(w);return R?e.jsx(Qt,{building:R,onClose:()=>v.selectBuilding(null),onOpenModal:()=>c==null?void 0:c(w)}):null})(),e.jsx(fn,{config:t,onChange:s,searchQuery:K,onOpenIntegrationsModal:h,onOpenPluginsModal:o,onOpenMonitoringModal:u,onOpenStatisticsModal:k,onOpenWorkflowEditor:g,onOpenTriggerManager:E})]})]})]})}export{wn as Toolbox};