tide-commander 1.151.1 → 1.151.2
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.
- package/CHANGELOG.md +8 -0
- package/dist/assets/{BossLogsModal-BRXVs2zX.js → BossLogsModal-DGb6Dawk.js} +1 -1
- package/dist/assets/{BossSpawnModal-BqM8EeOS.js → BossSpawnModal-bAPCPdSd.js} +1 -1
- package/dist/assets/{ControlsModal-Do6sfsyz.js → ControlsModal-Coq__bu-.js} +1 -1
- package/dist/assets/{DockerLogsModal-Clb8M2rL.js → DockerLogsModal-BQZeOuV9.js} +1 -1
- package/dist/assets/{EmbeddedEditor-DMFNGABf.js → EmbeddedEditor-BtJp9gMt.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-D4-bi1Rt.js → GmailOAuthSetup-DCbuudZO.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-D2Wyhnw0.js → GoogleOAuthSetup-Cuw3G9nk.js} +1 -1
- package/dist/assets/{IframeModal-Zun7245W.js → IframeModal-C_PL3LoC.js} +1 -1
- package/dist/assets/{IntegrationsPanel-U8SIOpPt.js → IntegrationsPanel-UzwNp4gx.js} +2 -2
- package/dist/assets/{LogViewerModal-BnFRX2hq.js → LogViewerModal-CCJv9FIp.js} +1 -1
- package/dist/assets/{MonitoringModal-CObUxMPl.js → MonitoringModal-DxTy2EgU.js} +1 -1
- package/dist/assets/{PM2LogsModal-DLf14YCU.js → PM2LogsModal-4hthqpZH.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-Chg4LCCi.js → RestoreArchivedAreaModal-D5RJraJz.js} +1 -1
- package/dist/assets/{Scene2DCanvas-CI_QSx9i.js → Scene2DCanvas-BdttXSwh.js} +1 -1
- package/dist/assets/{SceneManager-SS5ahbEe.js → SceneManager-BIk_uwP8.js} +1 -1
- package/dist/assets/{SkillsPanel-DgPHgt3c.js → SkillsPanel-rUryywpx.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-iIjyM2kW.js → SlackMultiInstanceSetup-C2rz0yH8.js} +1 -1
- package/dist/assets/{SpawnModal-BDgxHGYh.js → SpawnModal-DLGHvjww.js} +1 -1
- package/dist/assets/{StatisticsModal-BuYkJsul.js → StatisticsModal-Dp3UcJM-.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-D71lnDXZ.js → SubordinateAssignmentModal-xAZzPmge.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-DKiXSpSu.js → TriggerManagerPanel-D1gEAv-W.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-Dz6fJy8X.js → WorkflowEditorPanel-CWbOnKmv.js} +1 -1
- package/dist/assets/{area-logos-UIiMtczR.js → area-logos-t-kcQpe2.js} +1 -1
- package/dist/assets/{index-DrUrcPns.js → index-AhX-UCt7.js} +1 -1
- package/dist/assets/{index-Ci67fScw.js → index-BIjoVXsQ.js} +1 -1
- package/dist/assets/index-BNzYPyBm.css +1 -0
- package/dist/assets/{index-BAvhLzXF.js → index-BPhmYxbC.js} +3 -3
- package/dist/assets/{index-DvSK7N4C.js → index-BZtRj8Ya.js} +1 -1
- package/dist/assets/{index-BZKCuVK4.js → index-BzjVLEUP.js} +2 -2
- package/dist/assets/{index-DgxY9KIr.js → index-Cht8feDm.js} +1 -1
- package/dist/assets/{index-4BenQ81a.js → index-D56tkDkl.js} +1 -1
- package/dist/assets/{index-BXnQVuar.js → index-D5lCtmXE.js} +1 -1
- package/dist/assets/{index-OQ-kWRyS.js → index-DDE2P-En.js} +1 -1
- package/dist/assets/main-4YL5DKtG.css +1 -0
- package/dist/assets/{main-CEq_Fs_S.js → main-B-26AddI.js} +7 -7
- package/dist/assets/{web-jsCXVjsN.js → web-1nZKBCf7.js} +1 -1
- package/dist/assets/{web-DSHhrW0P.js → web-C1FuDjQR.js} +1 -1
- package/dist/assets/{web-BSnmr2eo.js → web-CBnEMFyp.js} +1 -1
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/dist/assets/index-CLA5nZlA.css +0 -1
- package/dist/assets/main-CX7XkoZ4.css +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as l,j as e,I,u as Z,bl as Xe,ag as Qe,bm as rs,bn as ds,s as A,bo as us,bd as ps,bp as hs,C as he,K as se,L as X,i as we,k as ke,bq as ms,br as gs,bs as fs,bt as xs,bu as bs,bv as js,bw as vs,bx as es,by as Ns,bz as ys,X as ws,bA as Se,a9 as ks,bB as ss,bC as Ss,bD as Be,bE as Cs,bF as As,bG as Ts,bH as _s,bI as Es,bJ as Ps,bK as Is,as as Ls,b6 as $s,_ as Ds,S as ye,bL as Fs,bM as Os,b8 as Rs,bN as ze,$ as Pe,bi as zs,bO as Ue,bP as Us,a5 as Ms,m as Bs,bQ as Vs,bR as Ks,bS as Hs}from"./main-CEq_Fs_S.js";import{g as qs,d as Ws,u as Gs}from"./area-logos-UIiMtczR.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ts="tide-toolbox-collapse";function Ys(s,a){try{const t=localStorage.getItem(`${ts}-${s}`);if(t!==null)return t==="true"}catch{}return a}function Js(s,a){try{localStorage.setItem(`${ts}-${s}`,String(a))}catch{}}function W({title:s,storageKey:a,defaultOpen:t=!1,forceOpen:o=!1,children:d,headerExtra:r}){const[c,f]=l.useState(()=>a?Ys(a,t):t),n=()=>{const y=!c;f(y),a&&Js(a,y)},g=o||c;return e.jsxs("div",{className:`collapsible-section ${g?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:n,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(I,{name:g?"caret-down":"caret-right",size:10})})]})]}),g&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Zs({area:s,isSelected:a,onClick:t,onDelete:o}){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 ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[c," ",r>0&&`• ${r} ${r>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:d("config:areas.deleteArea"),children:"×"})]})}function Xs({building:s,isSelected:a,onClick:t,onEdit:o}){var f;const{t:d}=Z(["config"]),r=((f=s.pm2Status)==null?void 0:f.ports)||[],c=(n,g)=>{n.stopPropagation(),window.open(`http://${window.location.hostname}:${g}`,"_blank")};return e.jsxs("div",{className:`building-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:Xe[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(I,{name:Qe(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(n=>e.jsxs("a",{href:`http://${window.location.hostname}:${n}`,className:"building-port-link",onClick:g=>c(g,n),title:`Open :${n}`,children:[":",n]},n))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:n=>{n.stopPropagation(),o()},title:d("config:buildings.editBuilding"),children:e.jsx(I,{name:"gear",size:14})})]})}function Qs({building:s,onClose:a,onOpenModal:t}){var g,y,k,m,E,v,S,x;const{t:o}=Z(["config","common"]),r=rs().get(s.id)||[],c=ds[s.style||"server-rack"],f=u=>{A.sendBuildingCommand(s.id,u)},n=u=>{window.open(u,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx(I,{name:Qe(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:Xe[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:a,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children: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:o("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>f("start"),disabled:!((g=s.commands)!=null&&g.start)||s.status==="running",title:((y=s.commands)==null?void 0:y.start)||o("config:buildings.noStartCommand"),children:[e.jsx(I,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>f("stop"),disabled:!((k=s.commands)!=null&&k.stop)||s.status==="stopped",title:((m=s.commands)==null?void 0:m.stop)||o("config:buildings.noStopCommand"),children:[e.jsx(I,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>f("restart"),disabled:!((E=s.commands)!=null&&E.restart),title:((v=s.commands)==null?void 0:v.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx(I,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>f("healthCheck"),disabled:!((S=s.commands)!=null&&S.healthCheck),title:((x=s.commands)==null?void 0:x.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx(I,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((u,w)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>n(u.url),title:u.url,children:[e.jsx(I,{name:"link",size:12})," ",u.label||u.url]},w))})]}),r.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[o("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>A.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:r.slice(-5).map((u,w)=>e.jsx("div",{className:"building-editor-log-entry",children:u},w))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(I,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}const et=[{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 st({area:s,onClose:a,onOpenFolder:t}){var te;const{t:o}=Z(["config","common"]),[d,r]=l.useState(s.name),[c,f]=l.useState(s.prompt||""),[n,g]=l.useState(!1),[y,k]=l.useState(""),[m,E]=l.useState(!1),v=l.useRef(null);l.useEffect(()=>{r(s.name)},[s.id,s.name]),l.useEffect(()=>{f(s.prompt||"")},[s.id,s.prompt]);const S=j=>{const $=j.target.value;r($),A.updateArea(s.id,{name:$})},x=j=>{A.updateArea(s.id,{color:j})},u=j=>{const $=j.target.value;f($),A.updateArea(s.id,{prompt:$})},w=()=>{y.trim()&&(A.addDirectoryToArea(s.id,y.trim()),k(""),g(!1))},B=(j,$)=>{$.stopPropagation(),A.removeDirectoryFromArea(s.id,j)},z=()=>{A.bringAreaToFront(s.id)},G=()=>{A.sendAreaToBack(s.id)},K=l.useCallback(()=>{let j=2,$=2;s.type==="rectangle"&&s.width&&s.height?(j=s.width,$=s.height):s.type==="circle"&&s.radius&&(j=s.radius*1.414,$=s.radius*1.414);const M=Math.min(j,$)*.4;return{width:Math.round(M*10)/10,height:Math.round(M*10)/10}},[s.type,s.width,s.height,s.radius]),H=async j=>{var M;const $=(M=j.target.files)==null?void 0:M[0];if($){E(!0);try{const b=await Gs(s.id,$),L=K();A.updateArea(s.id,{logo:{filename:b.filename,position:"center",width:L.width,height:L.height,keepAspectRatio:!0,opacity:.8}})}catch(b){console.error("Failed to upload logo:",b)}finally{E(!1),v.current&&(v.current.value="")}}},R=async()=>{try{await Ws(s.id),A.updateArea(s.id,{logo:void 0})}catch(j){console.error("Failed to remove logo:",j)}},V=j=>{s.logo&&A.updateArea(s.id,{logo:{...s.logo,position:j}})},p=j=>{if(!s.logo)return;const $=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const M=s.logo.height/s.logo.width;A.updateArea(s.id,{logo:{...s.logo,width:$,height:Math.round($*M*10)/10}})}else A.updateArea(s.id,{logo:{...s.logo,width:$}})},_=j=>{if(!s.logo)return;const $=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const M=s.logo.width/s.logo.height;A.updateArea(s.id,{logo:{...s.logo,height:$,width:Math.round($*M*10)/10}})}else A.updateArea(s.id,{logo:{...s.logo,height:$}})},U=()=>{s.logo&&A.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},q=j=>{s.logo&&A.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(j.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:o("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:a,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange:S,placeholder:o("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:us.map(j=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===j?"selected":""}`,style:{backgroundColor:j},onClick:()=>x(j),"aria-label":`Set area color ${j}`,"aria-pressed":s.color===j,title:j},j))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:z,title:o("config:areas.bringToFront"),children:[e.jsx(I,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:G,title:o("config:areas.sendToBack"),children:[e.jsx(I,{name:"arrow-down",size:12})," ",o("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(te=s.logo)!=null&&te.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:qs(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:R,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var j;return(j=v.current)==null?void 0:j.click()},disabled:m,children:m?"...":e.jsx(I,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:et.map(({key:j,labelKey:$})=>{var M;return e.jsx("button",{className:`area-logo-pos-btn ${((M=s.logo)==null?void 0:M.position)===j?"active":""}`,onClick:()=>V(j),children:o(`config:areas.${$}`)},j)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:p,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:_,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:o("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:U}),o("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoOpacity")}),e.jsxs("div",{className:"area-logo-opacity-row",children:[e.jsx("input",{type:"range",min:0,max:1,step:.05,value:s.logo.opacity??.8,onChange:q,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var j;return(j=v.current)==null?void 0:j.click()},disabled:m,children:m?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:v,type:"file",accept:"image/*",style:{display:"none"},onChange:H})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(j=>e.jsxs("div",{className:"area-folder-item",title:j,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:o("config:areas.openFolder"),children:e.jsx(I,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:j.split("/").pop()||j}),e.jsx("button",{className:"area-folder-remove",onClick:$=>B(j,$),title:o("config:areas.removeFolder"),children:"×"})]},j)),n?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(ps,{value:y,onChange:k,onSubmit:w,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:w,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>g(!0),children:o("config:areas.addFolder")})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:c,onChange:u,placeholder:o("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:o("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:o("config:areas.rightClickUnassign")})]})]})}function tt(){const{t:s}=Z(["config","common"]),a=hs(),[t,o]=l.useState(!1),[d,r]=l.useState(null),[c,f]=l.useState({name:"",key:"",value:"",description:""}),[n,g]=l.useState(null),y=()=>{o(!0),r(null),f({name:"",key:"",value:"",description:""})},k=u=>{r(u.id),o(!1),f({name:u.name,key:u.key,value:u.value,description:u.description||""})},m=()=>{o(!1),r(null),f({name:"",key:"",value:"",description:""})},E=()=>{!c.name.trim()||!c.key.trim()||(d?A.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}):A.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),m())},v=u=>{g(u)},S=()=>{n&&(A.deleteSecret(n),d===n&&m())},x=u=>{navigator.clipboard.writeText(`{{${u}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children:a.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):a.map(u=>e.jsxs("div",{className:`secret-item ${d===u.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:u.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>x(u.key),title:s("config:secrets.copyPlaceholder"),children:`{{${u.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>k(u),title:s("common:buttons.edit"),children:e.jsx(I,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>v(u.id),title:s("common:buttons.delete"),children:"×"})]})]}),u.description&&e.jsx("div",{className:"secret-item-description",children:u.description})]},u.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:u=>f({...c,name:u.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:u=>f({...c,key:u.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:u=>f({...c,value:u.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:u=>f({...c,description:u.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:m,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick: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:y,children:s("config:secrets.addSecret")}),e.jsx(he,{isOpen:n!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:S,onClose:()=>g(null)})]})}async function at(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch system prompt: ${a.statusText}`);return(await a.json()).prompt||""}async function nt(s){const a=se(),t=await fetch(`${X()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function it(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to clear system prompt: ${a.statusText}`)}async function ot(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch echo prompt setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function lt(s){const a=se(),t=await fetch(`${X()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function ct(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch codex binary path: ${a.statusText}`);return(await a.json()).path||""}async function rt(s){const a=se(),t=await fetch(`${X()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function dt(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch tmux mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ut(s){const a=se(),t=await fetch(`${X()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function pt(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch interactive mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ht(s){const a=se(),t=await fetch(`${X()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function mt(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch backup status: ${a.statusText}`);return a.json()}async function gt(s){const a=se(),t=await fetch(`${X()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function ft({checked:s,onChange:a,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:o=>a(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function xt(){const{t:s}=Z(["config","common"]),[a,t]=l.useState([]),[o,d]=l.useState(new Set),[r,c]=l.useState(new Set),[f,n]=l.useState(!1),[g,y]=l.useState(!1),[k,m]=l.useState(null),[E,v]=l.useState(null),[S,x]=l.useState(null),[u,w]=l.useState(null),[B,z]=l.useState(!1),[G,K]=l.useState(null);l.useEffect(()=>{we(ke("/api/config/categories")).then(b=>b.json()).then(b=>{const L=Array.isArray(b)?b:[];t(L),d(new Set(L.map(D=>D.id)))}).catch(b=>console.error("Failed to fetch config categories:",b))},[]),l.useEffect(()=>{mt().then(w).catch(b=>{console.error("Failed to fetch backup status:",b),K(b.message||"Failed to fetch backup status")})},[]);const H=async b=>{if(!B){z(!0),K(null);try{const L=await gt(b);w(L)}catch(L){K(L.message||"Failed to update backup setting")}finally{z(!1)}}},R=b=>{d(L=>{const D=new Set(L);return D.has(b)?D.delete(b):D.add(b),D})},V=b=>{c(L=>{const D=new Set(L);return D.has(b)?D.delete(b):D.add(b),D})},p=()=>d(new Set(a.map(b=>b.id))),_=()=>d(new Set),U=()=>{E&&c(new Set(E.categories.map(b=>b.id)))},q=()=>c(new Set),te=async()=>{var b;if(o.size!==0){n(!0),x(null);try{const L=Array.from(o).join(","),D=await we(ke(`/api/config/export?categories=${L}`));if(!D.ok)throw new Error("Export failed");const Q=await D.blob(),ee=window.URL.createObjectURL(Q),C=document.createElement("a");C.href=ee;const N=D.headers.get("Content-Disposition"),Y=((b=N==null?void 0:N.match(/filename="(.+)"/))==null?void 0:b[1])||"tide-commander-config.zip";C.download=Y,document.body.appendChild(C),C.click(),document.body.removeChild(C),window.URL.revokeObjectURL(ee),x({type:"success",text:s("config:data.exportSuccess")})}catch(L){x({type:"error",text:L.message||"Export failed"})}finally{n(!1)}}},j=async b=>{var D;const L=(D=b.target.files)==null?void 0:D[0];if(L){m(L),x(null),v(null),c(new Set);try{const Q=await we(ke("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await L.arrayBuffer()});if(!Q.ok){const N=await Q.json();throw new Error(N.error||"Failed to preview config file")}const ee=await Q.json(),C=Array.isArray(ee.categories)?ee.categories:[];v({...ee,categories:C}),c(new Set(C.map(N=>N.id)))}catch(Q){x({type:"error",text:Q.message||"Failed to read config file"}),m(null)}}},$=async()=>{if(!(!k||r.size===0)){y(!0),x(null);try{const b=Array.from(r).join(","),L=await we(ke(`/api/config/import?categories=${b}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await k.arrayBuffer()}),D=await L.json();if(!L.ok)throw new Error(D.error||"Import failed");x({type:"success",text:D.message||s("config:data.importSuccess")}),m(null),v(null),c(new Set)}catch(b){x({type:"error",text:b.message||"Import failed"})}finally{y(!1)}}},M=()=>{m(null),v(null),c(new Set),x(null)};return e.jsxs("div",{className:"data-section",children:[S&&e.jsx("div",{className:`data-message data-message-${S.type}`,children:S.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(ft,{checked:!!(u!=null&&u.enabled),disabled:B||!u,onChange:H})]}),e.jsxs("div",{className:"data-backup-info",children:[u?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:u.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!u.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:u.scriptPath})]}),u.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(u.lastRunAt).toLocaleString(),u.lastRunOk===!0&&" — ok",u.lastRunOk===!1&&u.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",u.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),G&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:G})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:p,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:_,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:a.map(b=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(b.id),onChange:()=>R(b.id)}),e.jsx("span",{className:"data-category-name",children:b.name})]},b.id))}),e.jsx("button",{className:"data-action-btn export",onClick:te,disabled:f||o.size===0,children:f?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),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:U,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:q,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:E.categories.map(b=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:r.has(b.id),onChange:()=>V(b.id)}),e.jsx("span",{className:"data-category-name",children:b.name}),b.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",b.fileCount," ",s("config:data.files"),")"]})]},b.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:M,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:$,disabled:g||r.size===0,children:g?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:j,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function bt(){const[s,a]=l.useState(()=>ms()),t=o=>{a(o);const d=bs(o);js(d)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:gs.map(o=>e.jsxs("button",{className:`theme-option ${s===o.id?"active":""}`,onClick:()=>t(o.id),title:o.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:o.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:o.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:o.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:o.name})]},o.id))})})}function jt(){const{t:s}=Z(["config"]),{installInfo:a,phase:t,output:o,error:d,newVersion:r,autoRestart:c,refreshInstallInfo:f,runUpdate:n,reset:g}=vs(),[y,k]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{f()},[f]),l.useEffect(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)},[o]);const E=l.useCallback(()=>{k(!0)},[]),v=l.useCallback(()=>{k(!1)},[]),S=l.useCallback(()=>{k(!1),n()},[n]),x=l.useCallback(()=>{g(),k(!1),f()},[g,f]),u=es.isNativePlatform(),w=s(u?"config:about.autoUpdateServerTitle":"config:about.autoUpdateTitle");return a?a.isGlobalInstall?a.autoUpdateSupported?!a.updateAvailable&&t==="idle"?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:w}),t==="idle"&&!y&&a.updateAvailable&&e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsxs("span",{className:"about-autoupdate-versions",children:[e.jsx("span",{className:"about-autoupdate-current",children:a.currentVersion}),e.jsx("span",{className:"about-autoupdate-arrow",children:"→"}),e.jsx("span",{className:"about-autoupdate-latest",children:a.latestVersion})]}),e.jsx("button",{className:"about-update-btn download",onClick:E,children:s("config:about.autoUpdateButton")})]}),t==="idle"&&y&&e.jsxs("div",{className:"about-autoupdate-confirm",children:[e.jsx("div",{className:"about-autoupdate-confirm-title",children:s("config:about.autoUpdateConfirmTitle")}),e.jsx("div",{className:"about-autoupdate-confirm-body",children:s("config:about.autoUpdateConfirmBody")}),e.jsxs("div",{className:"about-autoupdate-confirm-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:v,children:s("config:about.autoUpdateCancel")}),e.jsx("button",{className:"about-update-btn download",onClick:S,children:s("config:about.autoUpdateConfirm")})]})]}),(t==="running"||t==="success"||t==="failed")&&e.jsxs("div",{className:"about-autoupdate-stream",children:[e.jsxs("div",{className:"about-autoupdate-stream-title",children:[t==="running"&&s("config:about.autoUpdateRunning"),t==="success"&&s("config:about.autoUpdateSuccess"),t==="failed"&&s("config:about.autoUpdateFailed")]}),e.jsx("pre",{ref:m,className:"about-autoupdate-output",children:o||"..."}),t==="success"&&e.jsxs("div",{className:"about-autoupdate-success-hint",children:[r&&e.jsxs("div",{className:"about-autoupdate-newversion",children:["v",r]}),e.jsx("div",{children:s(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:x,children:s("config:about.autoUpdateClose")})})]})]}):u?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:w}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdatePackageManagerNotice",{pm:a.packageManager})}),a.suggestedManualCommand&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"about-autoupdate-manualhint",children:s("config:about.autoUpdateManualCommand")}),e.jsx("pre",{className:"about-autoupdate-manualcmd",children:a.suggestedManualCommand})]})]}):u?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:w}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdateDevMode")})]}):null}function vt(){const{t:s}=Z(["config"]),[a,t]=l.useState(null),[o,d]=l.useState(!1),[r,c]=l.useState(null);l.useEffect(()=>{Ns().then(t).catch(y=>c(y.message))},[]);const f=l.useCallback(async y=>{if(!o){d(!0),c(null);try{t(await ys(y))}catch(k){c(k.message)}finally{d(!1)}}},[o]),n=es.isNativePlatform(),g=s(n?"config:about.unattendedServerTitle":"config:about.unattendedTitle");return!a&&!r?null:a?n&&!a.supported?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:g}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:about.unattendedDesc")}),e.jsxs("label",{className:"config-toggle",style:a.supported?void 0:{opacity:.5},children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:a.enabled,disabled:o||!a.supported,onChange:y=>void f(y.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),!a.supported&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedUnsupported")}),a.supported&&a.enabled&&a.pendingRestartVersion&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedPendingRestart",{version:a.pendingRestartVersion})}),a.supported&&a.enabled&&!a.pendingRestartVersion&&a.lastResult&&e.jsx("div",{className:"about-autoupdate-devnote",children:a.lastResult}),r&&e.jsx("div",{className:"about-update-error",children:r})]}):n?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:g}),e.jsx("div",{className:"about-update-error",children:r})]})}function Nt(){const{t:s}=Z(["config"]),{updateAvailable:a,updateInfo:t,recentReleases:o,isChecking:d,error:r,currentVersion:c,isAndroid:f,downloadPhase:n,downloadProgress:g,checkForUpdate:y,downloadAndInstall:k,openReleasePage:m}=fs(),[E,v]=l.useState(!1),S=u=>u?`${(u/(1024*1024)).toFixed(1)} MB`:"",x=u=>new Date(u).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:e.jsx(I,{name:"waves",size:24})}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:c}),a&&t?e.jsx("span",{className:"about-version-update-badge",onClick:m,title:`Update available: ${t.version}`,children:t.version}):e.jsxs("a",{href:"https://github.com/deivid11/tide-commander/releases",target:"_blank",rel:"noopener noreferrer",className:"about-version-status",children:["(",s("config:about.updated"),")"]})]})]}),e.jsx(jt,{}),e.jsx(vt,{}),e.jsx("div",{className:"about-changelog-row",children:e.jsx("button",{className:"about-update-btn changelog",onClick:()=>v(!0),children:s("config:about.changelog")})}),e.jsxs("div",{className:"about-update",children:[a&&t?e.jsxs("div",{className:"about-update-available",children:[e.jsxs("div",{className:"about-update-header",children:[e.jsx("span",{className:"about-update-badge",children:s("config:about.updateAvailable")}),e.jsx("span",{className:"about-update-version",children:t.version})]}),t.apkSize&&e.jsxs("div",{className:"about-update-size",children:[s("config:about.sizeLabel"),": ",S(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:m,children:s("config:about.changelog")}),f&&t.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:()=>void k(),disabled:n!=="idle",children:n==="downloading"?s("config:appUpdateBanner.downloadingPct",{percent:g??0}):s(n==="installing"?"config:appUpdateBanner.installHint":"config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:m,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(d?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>y(!0),disabled:d,children:d?"...":s("config:about.check")})]}),o.length>0&&e.jsxs("div",{className:"about-releases",children:[e.jsx("div",{className:"about-releases-title",children:s("config:about.recentReleases")}),e.jsx("div",{className:"about-releases-list",children:o.map(u=>e.jsxs("a",{href:u.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${u.version===`v${c}`||u.version===c?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:u.version}),e.jsx("span",{className:"about-release-date",children:x(u.publishedAt)})]},u.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:e.jsx(I,{name:"package",size:14})}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]}),E&&e.jsx(xs,{onClose:()=>v(!1)})]})}const yt={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function wt({onOpenModal:s}){const[a,t]=l.useState([]),[o,d]=l.useState(!0),r=l.useCallback(async()=>{try{const c=await we(ke("/api/integrations"));if(!c.ok)return;const f=await c.json();t(f)}catch{}finally{d(!1)}},[]);return l.useEffect(()=>{r()},[r]),o?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):a.length===0?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"No integrations available."}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[a.map(c=>{const f=yt[c.id]||"🔌",n=!!c.status.error,g=c.status.connected,y=n?"#f38ba8":g?"#a6e3a1":"#fab387",k=n?"Error":g?"Connected":"Setup Required",m=n?"✗":g?"✓":"⚠";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 8px",borderRadius:4,background:"var(--surface-1, #181825)",border:"1px solid var(--border, #313244)",fontSize:12,minHeight:26},children:[e.jsx("span",{style:{fontSize:13,flexShrink:0},children:f}),e.jsx("span",{style:{flex:1,minWidth:0,color:"var(--text-primary, #cdd6f4)",fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c.name}),e.jsx("span",{style:{color:y,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:k,children:m}),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 Ie="__global__";function kt({isOpen:s,onClose:a,initialAgentId:t}){const{t:o}=Z(["config"]),d=ws(),[r,c]=l.useState(""),[f,n]=l.useState(""),[g,y]=l.useState(!1),[k,m]=l.useState(""),[E,v]=l.useState(""),[S,x]=l.useState(null),[u,w]=l.useState(null),[B,z]=l.useState(!1),[G,K]=l.useState(!1),[H,R]=l.useState(!1),[V,p]=l.useState(null),_=l.useMemo(()=>[...d].sort((C,N)=>C.name.localeCompare(N.name)),[d]),U=l.useMemo(()=>d.find(C=>C.id===r),[d,r]),q=r===Ie;l.useEffect(()=>{if(!s)return;const C=t&&d.some(N=>N.id===t)?t:Ie;c(C),y(!1),at().then(N=>n(N)).catch(()=>n("")).finally(()=>y(!0))},[s]),l.useEffect(()=>{const C=r===Ie?f:(U==null?void 0:U.customPrompt)??"";m(C),v(C),z(!1),x(null),w(null)},[r,g]);const te=C=>{const N=C.target.value;m(N),z(N!==E),x(null),w(null)},j=async()=>{if(r)try{x(null),w(null),q?(await nt(k),n(k),w(o("config:systemPrompt.savedGlobal"))):(A.updateAgentProperties(r,{customPrompt:k}),w(o("config:systemPrompt.saved"))),v(k),z(!1)}catch(C){x(C instanceof Error?C.message:"Failed to save system prompt")}},$=()=>{K(!0)},M=async()=>{if(r)try{x(null),w(null),q?(await it(),n(""),w(o("config:systemPrompt.clearedGlobal"))):(A.updateAgentProperties(r,{customPrompt:""}),w(o("config:systemPrompt.cleared"))),m(""),v(""),z(!1)}catch(C){x(C instanceof Error?C.message:"Failed to clear system prompt")}},b=()=>{m(E),z(!1),x(null),w(null)},L=C=>{if(C!==r){if(B){p(C),R(!0);return}c(C)}},D=()=>{if(B){p(null),R(!0);return}a()},Q=()=>{if(R(!1),V){const C=V;p(null),c(C)}else a()},ee=C=>{C.key==="Escape"&&(C.preventDefault(),D())};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:D,children:e.jsxs("div",{className:"system-prompt-modal",onClick:C=>C.stopPropagation(),onKeyDown:ee,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:o("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:D,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"modal-description",children:o("config:systemPrompt.description")}),e.jsxs("div",{className:"agent-picker",children:[e.jsx("label",{htmlFor:"system-prompt-agent",className:"editor-label",children:o("config:systemPrompt.agentLabel")}),e.jsxs("div",{className:"agent-picker-row",children:[q?e.jsx(I,{name:"globe",size:20,className:"agent-picker-icon"}):U&&e.jsx(ks,{classId:U.class,size:20,className:"agent-picker-icon"}),e.jsxs("select",{id:"system-prompt-agent",className:"agent-picker-select",value:r,onChange:C=>L(C.target.value),children:[e.jsxs("option",{value:Ie,children:[o("config:systemPrompt.globalOption"),f?" • ✦":""]}),_.map(C=>e.jsxs("option",{value:C.id,children:[C.name,C.customPrompt?" • ✦":""]},C.id))]})]})]}),S&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),S]}),u&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),u]}),e.jsxs("div",{className:"editor-wrapper",children:[e.jsxs("div",{className:"editor-header",children:[e.jsx("label",{htmlFor:"prompt-input",className:"editor-label",children:o("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[k.length," ",o("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:k,onChange:te,placeholder:o("config:systemPrompt.placeholder"),rows:18,disabled:q&&!g,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:o(q?"config:systemPrompt.hintGlobal":"config:systemPrompt.hint")})]})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:$,disabled:!k||!r,children:o("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:D,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:b,disabled:!B,children:o("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:j,disabled:!B||!r,children:o("config:systemPrompt.save")})]})]})]})}),e.jsx(he,{isOpen:G,title:o("config:systemPrompt.clear"),message:o(q?"config:systemPrompt.confirmClearGlobal":"config:systemPrompt.confirmClear"),confirmLabel:o("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{M()},onClose:()=>K(!1)}),e.jsx(he,{isOpen:H,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:Q,onClose:()=>{R(!1),p(null)}})]}):null}const We={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},St=2500,Ct=12e4;function Ge(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function At(s,a){return s.enabled===a.enabled&&s.baseUrl===a.baseUrl&&s.defaultSessionId===a.defaultSessionId&&s.webhookVerifyToken===a.webhookVerifyToken&&s.showIncomingToasts===a.showIncomingToasts}function Tt({isOpen:s,onClose:a}){const{t}=Z(["config"]),[o,d]=l.useState(We),[r,c]=l.useState(We),[f,n]=l.useState(!1),[g,y]=l.useState([]),[k,m]=l.useState(!0),[E,v]=l.useState(null),[S,x]=l.useState(null),[u,w]=l.useState(""),[B,z]=l.useState(!1),[G,K]=l.useState(""),[H,R]=l.useState(null),[V,p]=l.useState(null),[_,U]=l.useState(null),q=l.useRef(null),te=l.useRef(0),[j,$]=l.useState(""),[M,b]=l.useState(""),[L,D]=l.useState(null),[Q,ee]=l.useState(!1),[C,N]=l.useState(!1),[Y,ae]=l.useState(!1),[le,ie]=l.useState(!1),[ue,je]=l.useState(null),ve=!At(o,r),re=l.useCallback(()=>{q.current&&(clearTimeout(q.current),q.current=null)},[]),me=l.useCallback(async()=>{try{m(!0),v(null),x(null);const[h,F]=await Promise.all([ss(),Ss()]),oe=Ge(h);if(d(oe),c(oe),n(!!F.configured),F.configured)try{const fe=await Be();y(Array.isArray(fe)?fe:[])}catch{y([])}else y([])}catch(h){v(h instanceof Error?h.message:t("config:whatsapp.errors.loadFailed"))}finally{m(!1)}},[t]),P=l.useCallback(async()=>{try{const h=await Be();y(Array.isArray(h)?h:[])}catch{}},[]);l.useEffect(()=>(s?me():(re(),R(null),p(null),U(null),w(""),z(!1),D(null)),()=>{re()}),[s,me,re]);const pe=(h,F)=>{d(oe=>({...oe,[h]:F})),v(null),x(null)},ce=async()=>{try{v(null),x(null);const h=await Es({enabled:o.enabled,baseUrl:o.baseUrl.trim(),defaultSessionId:o.defaultSessionId.trim(),webhookVerifyToken:o.webhookVerifyToken,showIncomingToasts:o.showIncomingToasts});window.dispatchEvent(new CustomEvent("tide:whatsapp-config-updated"));const F=Ge(h);d(F),c(F),x(t("config:whatsapp.saved"))}catch(h){v(h instanceof Error?h.message:t("config:whatsapp.errors.saveFailed"))}},$e=()=>{d(r),v(null),x(null)},ge=()=>{if(ve){N(!0);return}a()},De=h=>{h.key==="Escape"&&(h.preventDefault(),ge())},Fe=async()=>{const h=u.trim();if(h)try{v(null),x(null),await As(h),w(""),z(!1),n(!0),x(t("config:whatsapp.apiKeySaved"))}catch(F){v(F instanceof Error?F.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},Ce=()=>{ae(!0)},Oe=async()=>{try{v(null),x(null),await Ps(),n(!1),x(t("config:whatsapp.apiKeyCleared"))}catch(h){v(h instanceof Error?h.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},Ne=l.useCallback(async h=>{if(Date.now()>te.current){U(t("config:whatsapp.pairingTimeout")),R(null),p(null),re(),P();return}try{const F=await Cs(h);if(F.status&&["connected","paired","open","ready"].includes(F.status.toLowerCase())){U(t("config:whatsapp.pairingSuccess")),R(null),p(null),re(),P();return}const fe=F.qrUrl??F.qr??null;fe&&p(fe)}catch(F){U(F instanceof Error?F.message:t("config:whatsapp.errors.qrFetchFailed"))}q.current=setTimeout(()=>{Ne(h)},St)},[P,re,t]),Ae=async()=>{const h=G.trim();if(h)try{v(null),x(null),U(null),p(null),re(),await Ts(h),K(""),R(h),te.current=Date.now()+Ct,Ne(h),P()}catch(F){v(F instanceof Error?F.message:t("config:whatsapp.errors.sessionCreateFailed"))}},Te=()=>{re(),R(null),p(null),U(null)},_e=h=>{je(h),ie(!0)},Re=async()=>{if(ue)try{v(null),x(null),await Is(ue),H===ue&&Te(),P(),x(t("config:whatsapp.sessionDeleted"))}catch(h){v(h instanceof Error?h.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{je(null)}},Ee=async()=>{const h=j.trim(),F=M.trim();if(!(!h||!F))try{ee(!0),D(null);const oe=o.defaultSessionId.trim()||void 0;await _s(h,F,oe),D({kind:"success",text:t("config:whatsapp.testSent")})}catch(oe){D({kind:"error",text:oe instanceof Error?oe.message:t("config:whatsapp.errors.testSendFailed")})}finally{ee(!1)}};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:ge,children:e.jsxs("div",{className:"whatsapp-config-modal",onClick:h=>h.stopPropagation(),onKeyDown:De,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsapp.title")}),e.jsx("button",{className:"modal-close",onClick:ge,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:k?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsapp.description")}),E&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),E]}),S&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),S]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.general")}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-enabled",className:"wa-label",children:t("config:whatsapp.enabled")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-enabled",type:"checkbox",checked:o.enabled,onChange:h=>pe("enabled",h.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-show-toasts",className:"wa-label",children:t("config:whatsapp.showIncomingToasts")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-show-toasts",type:"checkbox",checked:o.showIncomingToasts,onChange:h=>pe("showIncomingToasts",h.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.showIncomingToastsHelp")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-base-url",className:"wa-label",children:t("config:whatsapp.baseUrl")}),e.jsx("input",{id:"wa-base-url",type:"text",className:"wa-input",placeholder:"http://localhost:3007",value:o.baseUrl,onChange:h=>pe("baseUrl",h.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-default-session",className:"wa-label",children:t("config:whatsapp.defaultSessionId")}),e.jsx("input",{id:"wa-default-session",type:"text",className:"wa-input",placeholder:t("config:whatsapp.defaultSessionIdPlaceholder"),value:o.defaultSessionId,onChange:h=>pe("defaultSessionId",h.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-webhook-token",className:"wa-label",children:t("config:whatsapp.webhookVerifyToken")}),e.jsx("input",{id:"wa-webhook-token",type:"text",className:"wa-input",placeholder:t("config:whatsapp.webhookVerifyTokenPlaceholder"),value:o.webhookVerifyToken,onChange:h=>pe("webhookVerifyToken",h.target.value)})]})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.apiKey")}),e.jsx("div",{className:"wa-key-status",children:f?e.jsxs("span",{className:"wa-status wa-status-ok",children:[e.jsx(I,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(I,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:B?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:u,onChange:h=>w(h.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>z(h=>!h),title:t(B?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(I,{name:B?"eye-closed":"eye",size:14})}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Fe,disabled:!u.trim(),children:t("config:whatsapp.saveKey")}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:Ce,disabled:!f,children:t("config:whatsapp.clearKey")})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.apiKeyHint")})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.sessions")}),e.jsx("div",{className:"wa-sessions-list",children:!Array.isArray(g)||g.length===0?e.jsx("div",{className:"wa-empty",children:t("config:whatsapp.noSessions")}):g.map(h=>e.jsxs("div",{className:"wa-session-row",children:[e.jsxs("div",{className:"wa-session-info",children:[e.jsx("span",{className:"wa-session-id",children:h.id}),e.jsx("span",{className:`wa-session-status status-${(h.status??"unknown").toLowerCase()}`,children:h.status||"—"}),h.pairedNumber&&e.jsx("span",{className:"wa-session-paired",children:h.pairedNumber})]}),e.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:()=>_e(h.id),children:t("config:whatsapp.deleteSession")})]},h.id))}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:"text",className:"wa-input",placeholder:t("config:whatsapp.addSessionPlaceholder"),value:G,onChange:h=>K(h.target.value),onKeyDown:h=>{h.key==="Enter"&&Ae()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ae,disabled:!G.trim()||H!==null,children:t("config:whatsapp.addSession")})]}),H&&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:H})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Te,children:t("config:whatsapp.cancelPairing")})]}),V?e.jsx("div",{className:"wa-qr-image",children:e.jsx("img",{src:V,alt:"WhatsApp pairing QR code"})}):e.jsxs("div",{className:"wa-qr-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.waitingForQr")})]})]}),_&&!H&&e.jsx("div",{className:"wa-pairing-message",children:_})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.testMessage")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-to",className:"wa-label",children:t("config:whatsapp.testTo")}),e.jsx("input",{id:"wa-test-to",type:"text",className:"wa-input",placeholder:t("config:whatsapp.testToPlaceholder"),value:j,onChange:h=>$(h.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:M,onChange:h=>b(h.target.value)})]}),e.jsx("div",{className:"wa-field-inline wa-field-end",children:e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ee,disabled:!j.trim()||!M.trim()||Q,children:t(Q?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),L&&e.jsxs("div",{className:`alert ${L.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:L.kind==="success"?"check":"warn",size:14})}),L.text]})]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left"}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:ge,children:t("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:$e,disabled:!ve||k,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:ce,disabled:!ve||k,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(he,{isOpen:C,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{N(!1),a()},onClose:()=>N(!1)}),e.jsx(he,{isOpen:Y,title:t("config:whatsapp.clearKey"),message:t("config:whatsapp.confirmClearKey"),confirmLabel:t("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Oe()},onClose:()=>ae(!1)}),e.jsx(he,{isOpen:le,title:t("config:whatsapp.deleteSession"),message:t("config:whatsapp.confirmDeleteSession",{id:ue??""}),confirmLabel:t("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Re()},onClose:()=>{ie(!1),je(null)}})]}):null}const as=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function Ve(s=!1){const a=se(),t={};return a&&(t.Authorization=`Bearer ${a}`),s&&(t["Content-Type"]="application/json"),t}async function Ke(s,a){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${a}: ${s.statusText}`}async function _t(){const s=await fetch(`${X()}/api/whatsapp/notification-config`,{headers:Ve()});if(!s.ok)throw new Error(await Ke(s,"Failed to fetch WhatsApp notification config"));return s.json()}async function Et(s){const a=await fetch(`${X()}/api/whatsapp/notification-config`,{method:"PATCH",headers:Ve(!0),body:JSON.stringify(s)});if(!a.ok)throw new Error(await Ke(a,"Failed to update WhatsApp notification config"));return a.json()}async function Pt(){const s=await fetch(`${X()}/api/whatsapp/notification-config`,{method:"DELETE",headers:Ve()});if(!s.ok)throw new Error(await Ke(s,"Failed to reset WhatsApp notification config"));return s.json()}const Le={messages:!0,statusChanges:!0,taskComplete:!0,errors:!0,planReady:!0,agentSpawned:!0,agentStopped:!0},Ye={filter:{...Le},recipient:""};function It(s,a){if(s.recipient!==a.recipient)return!1;for(const t of as)if(s.filter[t]!==a.filter[t])return!1;return!0}function Lt({isOpen:s,onClose:a}){const{t}=Z(["config"]),[o,d]=l.useState(Ye),[r,c]=l.useState(Ye),[f,n]=l.useState(!0),[g,y]=l.useState(null),[k,m]=l.useState(null),[E,v]=l.useState(!1),[S,x]=l.useState(!1),u=!It(o,r),w=l.useCallback(async()=>{try{n(!0),y(null),m(null);const p=await _t(),_={filter:{...Le,...p.filter},recipient:p.recipient??""};d(_),c(_)}catch(p){y(p instanceof Error?p.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{n(!1)}},[t]);l.useEffect(()=>{s&&w()},[s,w]);const B=(p,_)=>{d(U=>({...U,filter:{...U.filter,[p]:_}})),y(null),m(null)},z=p=>{d(_=>({..._,recipient:p})),y(null),m(null)},G=async()=>{try{y(null),m(null);const p=await Et({filter:o.filter,recipient:o.recipient.trim()}),_={filter:{...Le,...p.filter},recipient:p.recipient??""};d(_),c(_),m(t("config:whatsappNotifications.saved"))}catch(p){y(p instanceof Error?p.message:t("config:whatsappNotifications.errors.saveFailed"))}},K=()=>{d(r),y(null),m(null)},H=async()=>{try{y(null),m(null);const p=await Pt(),_={filter:{...Le,...p.filter},recipient:p.recipient??""};d(_),c(_),m(t("config:whatsappNotifications.resetDone"))}catch(p){y(p instanceof Error?p.message:t("config:whatsappNotifications.errors.resetFailed"))}},R=()=>{if(u){v(!0);return}a()},V=p=>{p.key==="Escape"&&(p.preventDefault(),R())};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:R,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:p=>p.stopPropagation(),onKeyDown:V,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappNotifications.title")}),e.jsx("button",{className:"modal-close",onClick:R,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:f?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsappNotifications.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsappNotifications.description")}),g&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),g]}),k&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),k]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.recipient")}),e.jsxs("div",{className:"wan-field",children:[e.jsx("label",{htmlFor:"wan-recipient",className:"wan-label",children:t("config:whatsappNotifications.recipientLabel")}),e.jsx("input",{id:"wan-recipient",type:"text",className:"wan-input",placeholder:t("config:whatsappNotifications.recipientPlaceholder"),value:o.recipient,onChange:p=>z(p.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")}),as.map(p=>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.${p}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${p}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:o.filter[p],onChange:_=>B(p,_.target.checked)}),e.jsx("span",{className:"wan-toggle-track",children:e.jsx("span",{className:"wan-toggle-thumb"})})]})]},p))]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:()=>x(!0),disabled:f,children:t("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:R,children:t("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:K,disabled:!u||f,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:G,disabled:!u||f,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(he,{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:()=>{v(!1),a()},onClose:()=>v(!1)}),e.jsx(he,{isOpen:S,title:t("config:whatsappNotifications.resetToDefaults"),message:t("config:whatsappNotifications.confirmReset"),confirmLabel:t("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{H(),x(!1)},onClose:()=>x(!1)})]}):null}function ns(s){const a=s.replace(/@.*$/,"");return/^\d{10,15}$/.test(a)?a.startsWith("521")&&a.length===13?`+52 1 ${a.slice(3,5)} ${a.slice(5,9)} ${a.slice(9)}`:a.startsWith("52")&&a.length===12?`+52 ${a.slice(2,4)} ${a.slice(4,8)} ${a.slice(8)}`:a.startsWith("1")&&a.length===11?`+1 ${a.slice(1,4)} ${a.slice(4,7)} ${a.slice(7)}`:`+${a}`:s}function $t(s,a=Date.now()){const t=s*1e3,o=a-t;if(o<0)return Je(t);const d=Math.floor(o/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`:Je(t)}function Je(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Dt(s){const a=s*1e3;return new Date(a).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function is(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 Ft(s,a){return s.length<=a?s:s.slice(0,Math.max(0,a-1)).trimEnd()+"…"}function Ot({chats:s,selectedChatId:a,loading:t,error:o,onSelect:d,onRefresh:r,now:c}){const{t:f}=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:f("config:whatsappHistory.chats")}),e.jsx("button",{type:"button",className:"whatsapp-history-chatlist__refresh",onClick:r,disabled:t,"aria-label":f("config:whatsappHistory.refresh"),title:f("config:whatsappHistory.refresh"),children:"⟳"})]}),o&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:o}),t&&s.length===0&&e.jsxs("div",{className:"whatsapp-history-chatlist__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:f("config:whatsappHistory.loadingChats")})]}),!t&&!o&&s.length===0&&e.jsx("div",{className:"whatsapp-history-chatlist__empty",children:f("config:whatsappHistory.emptyChats")}),e.jsx("ul",{className:"whatsapp-history-chatlist__items",children:s.map(n=>{const g=is(n.lastMessageType),y=n.lastMessagePreview||`[${n.lastMessageType}]`,k=n.chatId===a,m=ns(n.chatId),E=n.isGroup?n.groupName:n.fromName,v=E||m,S=!!E&&E!==m;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${k?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>d(n.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:n.chatId,children:v}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:$t(n.lastTimestamp,c)})]}),S&&e.jsx("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--jid",children:e.jsx("span",{className:"whatsapp-history-chatlist__jid",children:m})}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[n.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),g&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[g," "]}),Ft(y,40)]}),n.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:n.unreadCount})]})]})},n.chatId)})})]})}function Rt({message:s}){const a=s.direction==="outbound"?"outbound":"inbound",t=is(s.messageType),o=(s.body??"").trim(),d=o.length>0,r=d?null:`[${s.messageType}]`;return e.jsx("div",{className:`whatsapp-history-bubble whatsapp-history-bubble--${a}`,children:e.jsxs("div",{className:"whatsapp-history-bubble__inner",children:[t&&e.jsx("span",{className:"whatsapp-history-bubble__type-icon",title:s.messageType,children:t}),d?e.jsx("span",{className:"whatsapp-history-bubble__body",children:o}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:r}),s.audioTranscription&&e.jsxs("span",{className:"whatsapp-history-bubble__transcription",children:["“",s.audioTranscription,"”"]}),s.mediaPath&&e.jsx("a",{className:"whatsapp-history-bubble__media-link",href:s.mediaPath,target:"_blank",rel:"noopener noreferrer",children:s.mediaFilename||"open media"}),e.jsx("span",{className:"whatsapp-history-bubble__time",children:Dt(s.timestamp)})]})})}const zt=["all","inbound","outbound"],Ut=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function Mt({direction:s,type:a,onDirectionChange:t,onTypeChange:o,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:zt.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:a,onChange:c=>o(c.target.value),disabled:d,children:Ut.map(c=>e.jsx("option",{value:c,children:r(`config:whatsappHistory.typeValues.${c}`)},c))})]})]})}const Bt=80;function Vt({chatId:s,messages:a,loading:t,loadingMore:o,error:d,hasMore:r,direction:c,type:f,onDirectionChange:n,onTypeChange:g,onLoadMore:y}){const{t:k}=Z(["config"]),m=l.useRef(null),E=l.useRef(null),v=l.useRef(!1),S=l.useRef(null);l.useEffect(()=>{E.current!==s&&(E.current=s,v.current=!1)},[s]),l.useLayoutEffect(()=>{m.current&&(v.current||a.length!==0&&(m.current.scrollTop=m.current.scrollHeight,v.current=!0))},[s,a.length]),l.useLayoutEffect(()=>{if(!m.current||S.current===null)return;const w=m.current.scrollHeight-S.current;S.current=null,w>0&&(m.current.scrollTop+=w)},[a.length]);const x=l.useCallback(()=>{!r||o||t||(m.current&&(S.current=m.current.scrollHeight),y())},[r,o,t,y]),u=l.useCallback(w=>{if(!v.current)return;w.currentTarget.scrollTop<=Bt&&x()},[x]);return s?e.jsxs("div",{className:"whatsapp-history-messages",children:[e.jsxs("div",{className:"whatsapp-history-messages__header",children:[e.jsx("div",{className:"whatsapp-history-messages__title",children:ns(s)}),e.jsx(Mt,{direction:c,type:f,onDirectionChange:n,onTypeChange:g,disabled:t})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:m,onScroll:u,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:x,disabled:o||t,children:k(o?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),d&&e.jsx("div",{className:"whatsapp-history-messages__error",children:d}),t&&a.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&&a.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:k("config:whatsappHistory.emptyMessages")}),a.map(w=>e.jsx(Rt,{message:w},Kt(w)))]})]}):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 Kt(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 os(){const s=se(),a={};return s&&(a.Authorization=`Bearer ${s}`),a}async function ls(s,a){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${a}: ${s.statusText}`}async function Ht(s){const a=`${X()}/api/whatsapp/chats/${encodeURIComponent(s)}`,t=await fetch(a,{headers:os()});if(!t.ok)throw new Error(await ls(t,"Failed to fetch WhatsApp chats"));return t.json()}async function Ze(s,a,t={}){const o=new URLSearchParams;t.cursor&&o.set("cursor",t.cursor),typeof t.limit=="number"&&o.set("limit",String(t.limit)),t.direction&&o.set("direction",t.direction),t.type&&o.set("type",t.type);const d=o.toString(),r=`${X()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(a)}/messages${d?`?${d}`:""}`,c=await fetch(r,{headers:os()});if(!c.ok)throw new Error(await ls(c,"Failed to fetch WhatsApp messages"));return c.json()}const qt=50;function Wt({isOpen:s,onClose:a}){const{t}=Z(["config"]),[o,d]=l.useState([]),[r,c]=l.useState(null),[f,n]=l.useState(null),[g,y]=l.useState([]),[k,m]=l.useState(!1),[E,v]=l.useState(null),[S,x]=l.useState(null),[u,w]=l.useState([]),[B,z]=l.useState(!1),[G,K]=l.useState(!1),[H,R]=l.useState(null),[V,p]=l.useState(null),[_,U]=l.useState("all"),[q,te]=l.useState("all"),[j,$]=l.useState(()=>Date.now()),M=l.useRef(0);l.useEffect(()=>{if(!s)return;const N=window.setInterval(()=>$(Date.now()),6e4);return()=>window.clearInterval(N)},[s]),l.useEffect(()=>{if(!s)return;let N=!1;return(async()=>{var Y;try{n(null);const[ae,le]=await Promise.all([Be().catch(()=>[]),ss().catch(()=>null)]);if(N)return;d(ae);const ie=(le==null?void 0:le.defaultSessionId)||((Y=ae[0])==null?void 0:Y.id)||null;c(ue=>ue??ie)}catch(ae){if(N)return;n(ae instanceof Error?ae.message:String(ae))}})(),()=>{N=!0}},[s]);const b=l.useCallback(async N=>{m(!0),v(null);try{const Y=await Ht(N);y(Y.chats)}catch(Y){v(Y instanceof Error?Y.message:String(Y))}finally{m(!1)}},[]);l.useEffect(()=>{!s||!r||(x(null),w([]),p(null),b(r))},[s,r,b]);const L=l.useMemo(()=>{const N={limit:qt};return _!=="all"&&(N.direction=_),q!=="all"&&(N.type=q),N},[_,q]),D=l.useCallback(async(N,Y,ae)=>{const le=++M.current;z(!0),R(null),w([]),p(null);try{const ie=await Ze(N,Y,ae);if(le!==M.current)return;w([...ie.messages].reverse()),p(ie.nextCursor)}catch(ie){if(le!==M.current)return;R(ie instanceof Error?ie.message:String(ie))}finally{le===M.current&&z(!1)}},[]);l.useEffect(()=>{!s||!r||!S||D(r,S,L)},[s,r,S,L,D]);const Q=l.useCallback(async()=>{if(!(!r||!S||!V)){K(!0),R(null);try{const N=await Ze(r,S,{...L,cursor:V});w(Y=>[...[...N.messages].reverse(),...Y]),p(N.nextCursor)}catch(N){R(N instanceof Error?N.message:String(N))}finally{K(!1)}}},[r,S,V,L]),ee=l.useCallback(()=>{r&&b(r)},[r,b]),C=l.useCallback(N=>{N.key==="Escape"&&(N.preventDefault(),a())},[a]);return s?e.jsx(Se,{children:e.jsx("div",{className:"modal-overlay visible",onClick:a,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:N=>N.stopPropagation(),onKeyDown:C,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:N=>c(N.target.value||null),disabled:o.length===0,children:[o.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),o.map(N=>e.jsxs("option",{value:N.id,children:[N.id,N.pairedNumber?` (${N.pairedNumber})`:""]},N.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:a,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),f&&e.jsx("div",{className:"whatsapp-history-modal__alert",children:f}),e.jsxs("div",{className:"whatsapp-history-modal__body",children:[e.jsx(Ot,{chats:g,selectedChatId:S,loading:k,error:E,onSelect:x,onRefresh:ee,now:j}),e.jsx(Vt,{chatId:S,messages:u,loading:B,loadingMore:G,error:H,hasMore:V!==null,direction:_,type:q,onDirectionChange:U,onTypeChange:te,onLoadMore:Q})]})]})})}):null}function Gt({isOpen:s,onClose:a,onOpenConfig:t,onOpenNotifications:o,onOpenHistory:d}){const{t:r}=Z(["config"]);if(l.useEffect(()=>{if(!s)return;const f=n=>{n.key==="Escape"&&(n.preventDefault(),a())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[s,a]),!s)return null;const c=f=>{a(),f()};return e.jsx(Se,{children:e.jsx("div",{className:"modal-overlay visible",onClick:a,children:e.jsxs("div",{className:"whatsapp-hub-modal",onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"whatsapp-hub-modal__icon",children:"📱"}),r("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:a,"aria-label":"Close",children:e.jsx(I,{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(I,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children: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(o),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children: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(I,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children: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 Yt=[{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:"🌙"}],Jt=[{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:"🔴"}],Zt=[{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:"👎"}],Xt=[{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:"💜"}],Qt=[{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"}],ea=[{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"}],sa={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},ta={none:"grass","pokemon-stadium":"pokemon"},aa={"emote-yes":"yes","emote-no":"no"},na={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function ne({checked:s,onChange:a}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:t=>a(t.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function be({options:s,value:a,onChange:t,iconOnly:o=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(d=>e.jsxs("button",{className:`chip ${a===d.value?"active":""}`,onClick:()=>t(d.value),title:d.label,children:[e.jsx("span",{className:"chip-icon",children:d.icon}),!o&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function T({text:s,query:a}){if(!a.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),o=a.toLowerCase(),d=t.indexOf(o);if(d===-1)return e.jsx(e.Fragment,{children:s});const r=s.slice(0,d),c=s.slice(d,d+a.length),f=s.slice(d+a.length);return e.jsxs(e.Fragment,{children:[r,e.jsx("mark",{className:"search-highlight",children:c}),f]})}const ia=[{id:"general",title:"General",keywords:["history","hide costs","grid","fps","power saving","performance","limit","editor","external editor","language","idioma","语言","vibration","haptic","intensity","tab title","tmux","process persistence","interactive","tui","terminal","experimental","claude","stream","streaming","word by word","live text","grok"]},{id:"agentNames",title:"Agent Names",keywords:["agent","names","custom","characters","rename"]},{id:"defaultClass",title:"Default Spawn Class",keywords:["default","class","spawn","agent","scout","builder","random"]},{id:"appearance",title:"Appearance",keywords:["theme","appearance","color","dark","light","style","look"]},{id:"connection",title:"Connection",keywords:["backend","url","auth","token","reconnect","server","api","connect","codex","opencode","binary","path"]},{id:"scene",title:"Scene",keywords:["character","size","indicator","scale","time","dawn","day","dusk","night","auto"]},{id:"terrain",title:"Terrain",keywords:["trees","bushes","house","lamps","grass","clouds","fog","brightness","floor","sky","color","environment","battlefield","size","grid","simple","minimal","dark","clean"]},{id:"modelStyle",title:"Agent Model Style",keywords:["saturation","roughness","metalness","glow","emissive","reflections","wireframe","color mode","material","shader"]},{id:"animations",title:"Animations",keywords:["idle","working","animation","walk","run","sprint","jump","sit","crouch"]},{id:"secrets",title:"Secrets",keywords:["secrets","api","key","password","credentials","env","environment"]},{id:"systemPrompt",title:"System Prompt",keywords:["system","prompt","global","instructions","ai","agent","rules","guidelines"]},{id:"data",title:"Data",keywords:["export","import","backup","restore","save","load","json"]},{id:"integrations",title:"Integrations",keywords:["integrations","integraciones","plugins","gmail","slack","jira","calendar","docx","email","whatsapp","notifications","notification","baileys","history","historial","chat","messages","inbox","config","setup"]},{id:"workflows",title:"Workflows",keywords:["workflow","automation","state machine","editor","actions","transitions","pipeline"]},{id:"triggers",title:"Triggers",keywords:["trigger","event","webhook","cron","slack","email","jira","matching","fire"]},{id:"monitoring",title:"Monitoring",keywords:["monitoring","logs","triggers","events","history","workflow","traces","audit","timeline"]},{id:"statistics",title:"Statistics",keywords:["statistics","stats","usage","tokens","token","claude","chart","graph","pie","cost"]},{id:"experimental",title:"Experimental",keywords:["experimental","2d","view","voice","assistant","speech","tts","text to speech","echo","prompt","duplicate"]},{id:"about",title:"About",keywords:["about","version","update","credits","github","releases"]}],Me=[{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 oa({config:s,onChange:a,searchQuery:t="",onOpenIntegrationsModal:o,onOpenMonitoringModal:d,onOpenStatisticsModal:r,onOpenWorkflowEditor:c,onOpenTriggerManager:f}){var He;const{t:n}=Z(["config","common"]),g=Ls(),y=$s(),[k,m]=l.useState(()=>Ds(ye.DEFAULT_AGENT_CLASS)||"scout"),[E,v]=l.useState(g.historyLimit),[S,x]=l.useState(()=>Fs()),[u,w]=l.useState(!1),[B,z]=l.useState(""),[G,K]=l.useState(()=>se()),[H,R]=l.useState(!1),[V,p]=l.useState(!1),[_,U]=l.useState(""),[q,te]=l.useState(!1),[j,$]=l.useState(!1),[M,b]=l.useState(!1),[L,D]=l.useState(!1),[Q,ee]=l.useState(!1),[C,N]=l.useState(""),[Y,ae]=l.useState(!1);l.useEffect(()=>{ct().then(N).catch(()=>{})},[]),l.useEffect(()=>{ot().then(i=>{i!==g.experimentalEchoPrompt&&A.updateSettings({experimentalEchoPrompt:i})}).catch(()=>{})},[]),l.useEffect(()=>{dt().then(i=>{i!==g.tmuxMode&&A.updateSettings({tmuxMode:i})}).catch(()=>{})},[]),l.useEffect(()=>{pt().then(i=>{i!==g.interactiveMode&&A.updateSettings({interactiveMode:i})}).catch(()=>{})},[]),l.useEffect(()=>Os(i=>{x(i),w(!1)}),[]);const le=Yt.map(i=>({...i,label:n(`config:time.${i.value}`)})),ie=Jt.map(i=>({...i,label:n(`config:floor.${ta[i.value]||i.value}`)})),ue=Zt.map(i=>({...i,label:n(`config:animation.${aa[i.value]||i.value}`)})),je=Xt.map(i=>({...i,label:n(`config:colorMode.${i.value}`)})),ve=Qt.map(i=>({...i,label:n(`config:terrain.${sa[i.key]}`)})),re=ea.map(i=>({...i,label:n(`config:sky.${na[i.value??""]}`)})),me=t.trim()?ia.filter(i=>{const O=t.toLowerCase();return i.title.toLowerCase().includes(O)||i.keywords.some(de=>de.toLowerCase().includes(O))}).map(i=>i.id):null,P=i=>me?me.includes(i):!0,pe=P("integrations"),ce=g.customAgentNames||[],$e=ce.length>0?ce:Rs,ge=()=>{const i=_.trim();i&&!ce.includes(i)&&(A.updateSettings({customAgentNames:[...ce,i]}),U(""))},De=i=>{A.updateSettings({customAgentNames:ce.filter(O=>O!==i)})},Fe=()=>{A.updateSettings({customAgentNames:[]})},Ce=()=>{const i=B.trim();if(i){if(S.includes(i)){z("");return}x([...S,i]),w(!0),z("")}},Oe=i=>{x(S.filter((O,de)=>de!==i)),w(!0)},Ne=(i,O)=>{const de=i+O;if(de<0||de>=S.length)return;const xe=S.slice();[xe[i],xe[de]]=[xe[de],xe[i]],x(xe),w(!0)},Ae=()=>{Us(S),w(!1),Ue()},Te=i=>{K(i),R(!0)},_e=()=>{Pe(ye.AUTH_TOKEN,G),R(!1),Ue()},Re=i=>{N(i),ae(!0)},Ee=()=>{rt(C).catch(()=>{}),ae(!1)},h=i=>{a({...s,terrain:{...s.terrain,...i}})},F=i=>{a({...s,modelStyle:{...s.modelStyle,...i}})},oe=i=>{a({...s,animations:{...s.animations,...i}})},fe=i=>{v(i),A.updateSettings({historyLimit:i})},cs=i=>{const O=s.terrain[i];typeof O=="boolean"&&h({[i]:!O})},J=t.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[me&&me.length===0&&e.jsx("div",{className:"config-no-results",children:n("config:noResults",{query:t})}),P("general")&&e.jsxs(W,{title:n("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:J&&P("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:E,onChange:i=>fe(parseInt(i.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:n("config:general.hideCosts"),query:t})}),e.jsx(ne,{checked:g.hideCost,onChange:i=>A.updateSettings({hideCost:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:n("config:general.streamTextLiveTitle"),children:e.jsx(T,{text:n("config:general.streamTextLive"),query:t})}),e.jsx(ne,{checked:g.streamTextLive!==!1,onChange:i=>A.updateSettings({streamTextLive:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.grid"),query:t})}),e.jsx(ne,{checked:s.gridVisible,onChange:i=>a({...s,gridVisible:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.showFPS"),query:t})}),e.jsx(ne,{checked:g.showFPS,onChange:i=>A.updateSettings({showFPS:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.fpsLimit"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:i=>a({...s,fpsLimit:parseInt(i.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:n("config:general.powerSaving"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ne,{checked:g.powerSaving,onChange:i=>A.updateSettings({powerSaving:i})})]}),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:n("config:general.tmuxMode"),query:t})}),e.jsx(ne,{checked:g.tmuxMode,onChange:async i=>{A.updateSettings({tmuxMode:i});try{await ut(i)}catch(O){console.error("Failed to sync tmux mode setting to server:",O)}}})]}),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:n("config:general.interactiveMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ne,{checked:g.interactiveMode,onChange:async i=>{A.updateSettings({interactiveMode:i});try{await ht(i)}catch(O){console.error("Failed to sync interactive mode setting to server:",O)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.vibrationIntensity"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:g.vibrationIntensity,onChange:i=>A.updateSettings({vibrationIntensity:parseInt(i.target.value)})}),e.jsx("span",{className:"config-value",children:g.vibrationIntensity===0?n("config:vibrationValues.off"):g.vibrationIntensity===1?n("config:vibrationValues.ultraLight"):g.vibrationIntensity===2?n("config:vibrationValues.veryLight"):g.vibrationIntensity===3?n("config:vibrationValues.light"):g.vibrationIntensity===4?n("config:vibrationValues.medium"):n("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.externalEditor"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:n("config:general.externalEditorPlaceholder"),value:g.externalEditorCommand||"",onChange:i=>A.updateSettings({externalEditorCommand:i.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.tabTitle"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:n("config:general.tabTitlePlaceholder"),value:g.tabTitle||"",onChange:i=>A.updateSettings({tabTitle:i.target.value})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.language"),query:t})}),e.jsx(be,{options:Me,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((He=Me.find(i=>i.value!=="auto"&&ze.language.startsWith(i.value.split("-")[0])))==null?void 0:He.value)||"en":"auto",onChange:i=>{var O;if(i==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const de=navigator.language,xe=((O=Me.find(qe=>qe.value!=="auto"&&de.startsWith(qe.value.split("-")[0])))==null?void 0:O.value)||"en";ze.changeLanguage(xe)}else localStorage.setItem("tide-commander-language-mode","manual"),ze.changeLanguage(i)}})]})]}),P("agentNames")&&e.jsx(W,{title:n("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:J&&P("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:ce.length>0?n("config:agentNames.customConfigured",{count:ce.length}):n("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:n("config:agentNames.addPlaceholder"),value:_,onChange:i=>U(i.target.value),onKeyDown:i=>{i.key==="Enter"&&ge()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ge,disabled:!_.trim(),title:n("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:$e.map((i,O)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:i}),ce.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>De(i),title:n("common:buttons.remove"),children:"x"})]},`${i}-${O}`))}),ce.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:Fe,children:n("common:buttons.resetToDefaults")})]})}),P("defaultClass")&&e.jsx(W,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:J&&P("defaultClass"),children:e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-hint",children:'Class pre-selected when the spawn modal opens. "Random" picks a different class each time.'}),e.jsxs("div",{className:"agent-names-list",style:{flexWrap:"wrap",gap:"6px",marginTop:"8px"},children:[e.jsx("div",{className:`agent-name-chip${k==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m("random"),Pe(ye.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(zs).map(([i,O])=>e.jsx("div",{className:`agent-name-chip${k===i?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(i),Pe(ye.DEFAULT_AGENT_CLASS,i)},children:e.jsxs("span",{className:"agent-name-text",children:[O.icon," ",i.charAt(0).toUpperCase()+i.slice(1)]})},i)),y.map(i=>e.jsx("div",{className:`agent-name-chip${k===i.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(i.id),Pe(ye.DEFAULT_AGENT_CLASS,i.id)},children:e.jsxs("span",{className:"agent-name-text",children:[i.icon," ",i.name]})},i.id))]})]})}),P("appearance")&&e.jsx(W,{title:n("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:J&&P("appearance"),children:e.jsx(bt,{})}),P("connection")&&e.jsxs(W,{title:n("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:J&&P("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:S.map((i,O)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:n("config:connection.priorityLabel",{defaultValue:"Priority"}),children:O+1}),e.jsx("span",{className:"backend-url-text",title:i,children:i}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ne(O,-1),disabled:O===0,title:n("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ne(O,1),disabled:O===S.length-1,title:n("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Oe(O),title:n("common:buttons.remove"),children:"x"})]},`${i}-${O}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:B,onChange:i=>z(i.target.value),placeholder:n("config:connection.addUrlPlaceholder",{defaultValue:"http://host:port"}),onKeyDown:i=>{i.key==="Enter"&&Ce()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ce,disabled:!B.trim(),title:n("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),u&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ae,title:n("config:connection.saveAndReconnect"),children:n("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:n("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:n("config:connection.authToken"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:V?"text":"password",className:"config-input config-input-full",value:G,onChange:i=>Te(i.target.value),placeholder:n("config:connection.tokenPlaceholder"),onKeyDown:i=>{i.key==="Enter"&&H&&_e()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>p(!V),title:n(V?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(I,{name:V?"eye-closed":"eye",size:14})}),H&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:_e,title:n("config:connection.saveAndReconnect"),children:n("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:n("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:C,onChange:i=>Re(i.target.value),placeholder:n("config:connection.codexBinaryPathPlaceholder"),onKeyDown:i=>{i.key==="Enter"&&Y&&Ee()}}),Y&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ee,children:n("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:n("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("common:buttons.reconnect"),query:t})}),e.jsx("button",{className:"config-btn",onClick:()=>Ue(),title:"Force reconnect to server",children:n("common:buttons.reconnect")})]})]}),P("scene")&&e.jsxs(W,{title:n("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:J&&P("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>a({...s,characterScale:parseFloat(i.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:n("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:i=>a({...s,scale2d:parseFloat(i.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:n("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:i=>a({...s,scale3d:parseFloat(i.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:n("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:t})}),e.jsx(ne,{checked:s.show2DTaskLabels,onChange:i=>a({...s,show2DTaskLabels:i})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:scene.time"),query:t})}),e.jsx(be,{options:le,value:s.timeMode,onChange:i=>a({...s,timeMode:i}),iconOnly:!0})]})]}),P("terrain")&&e.jsxs(W,{title:n("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:J&&P("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:t})}),e.jsx(ne,{checked:s.terrain.simpleMode??!1,onChange:i=>h({simpleMode:i})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:ve.map(i=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[i.key]?"active":""}`,onClick:()=>cs(i.key),title:i.label,children:i.icon},i.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>h({fogDensity:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?n("config:fogValues.off"):s.terrain.fogDensity<=1?n("config:fogValues.low"):n("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>h({brightness:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?n("config:brightnessValues.dark"):s.terrain.brightness<=1.2?n("config:brightnessValues.normal"):n("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:terrainSettings.floor"),query:t})}),e.jsx(be,{options:ie,value:s.terrain.floorStyle,onChange:i=>h({floorStyle:i}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:terrainSettings.sky"),query:t})}),e.jsx("div",{className:"sky-color-selector",children:re.map(i=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===i.value?"active":""}`,onClick:()=>h({skyColor:i.value}),title:i.label,style:{background:i.color}},i.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:terrainSettings.battlefieldSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:i=>h({battlefieldSize:parseInt(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),P("modelStyle")&&e.jsxs(W,{title:n("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:J&&P("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>F({saturation:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?n("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?n("config:saturationValues.normal"):n("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>F({roughness:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?n("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?n("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?n("config:roughnessValues.normal"):n("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>F({metalness:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?n("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?n("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?n("config:metalnessValues.mixed"):n("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>F({emissiveBoost:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?n("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?n("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?n("config:glowValues.med"):n("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>F({envMapIntensity:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?n("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?n("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?n("config:reflectionValues.normal"):n("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:modelStyleSettings.wireframe"),query:t})}),e.jsx(ne,{checked:s.modelStyle.wireframe,onChange:i=>F({wireframe:i})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:modelStyleSettings.colorMode"),query:t})}),e.jsx(be,{options:je,value:s.modelStyle.colorMode,onChange:i=>F({colorMode:i}),iconOnly:!0})]})]}),P("animations")&&e.jsxs(W,{title:n("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:J&&P("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:animationSettings.idle"),query:t})}),e.jsx(be,{options:ue,value:s.animations.idleAnimation,onChange:i=>oe({idleAnimation:i}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:animationSettings.working"),query:t})}),e.jsx(be,{options:ue,value:s.animations.workingAnimation,onChange:i=>oe({workingAnimation:i}),iconOnly:!0})]})]}),P("secrets")&&e.jsx(W,{title:n("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:J&&P("secrets"),children:e.jsx(tt,{})}),P("systemPrompt")&&e.jsx(W,{title:n("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:J&&P("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>te(!0),children:n("config:systemPrompt.editPrompt")})]})}),P("data")&&e.jsx(W,{title:n("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:J&&P("data"),children:e.jsx(xt,{})}),pe&&e.jsx(W,{title:n("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:J&&pe,children:e.jsx(wt,{onOpenModal:i=>{i==="whatsapp"?ee(!0):o==null||o(i)}})}),P("workflows")&&e.jsxs(W,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:J&&P("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:()=>c==null?void 0:c(),children:"Open Workflow Editor"})})]}),P("triggers")&&e.jsxs(W,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:J&&P("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:()=>f==null?void 0:f(),children:"Open Trigger Manager"})})]}),P("monitoring")&&e.jsxs(W,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:J&&P("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:()=>d==null?void 0:d(),children:"Open Monitoring & Logs"})})]}),P("statistics")&&e.jsxs(W,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:J&&P("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:()=>r==null?void 0:r(),children:"Open Statistics"})})]}),P("experimental")&&e.jsxs(W,{title:n("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:J&&P("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:n("config:experimental.2dView"),query:t})," ",e.jsx(I,{name:"map",size:12})]}),e.jsx(ne,{checked:g.experimental2DView,onChange:i=>A.updateSettings({experimental2DView:i})})]}),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:n("config:experimental.voiceAssistant"),query:t})," ",e.jsx(I,{name:"microphone",size:12})]}),e.jsx(ne,{checked:g.experimentalVoiceAssistant,onChange:i=>A.updateSettings({experimentalVoiceAssistant:i})})]}),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:n("config:experimental.tts"),query:t})," ",e.jsx(I,{name:"speaker-on",size:12})]}),e.jsx(ne,{checked:g.experimentalTTS,onChange:i=>A.updateSettings({experimentalTTS:i})})]}),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:n("config:experimental.echoPrompt"),query:t})}),e.jsx(ne,{checked:g.experimentalEchoPrompt,onChange:async i=>{A.updateSettings({experimentalEchoPrompt:i});try{await lt(i)}catch(O){console.error("Failed to sync echo prompt setting to server:",O)}}})]}),e.jsx("span",{className:"config-hint",children:n("config:experimental.hint")})]}),P("about")&&e.jsx(W,{title:n("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:J&&P("about"),children:e.jsx(Nt,{})})]}),e.jsx(kt,{isOpen:q,onClose:()=>te(!1)}),e.jsx(Tt,{isOpen:j,onClose:()=>$(!1)}),e.jsx(Lt,{isOpen:M,onClose:()=>b(!1)}),e.jsx(Wt,{isOpen:L,onClose:()=>D(!1)}),e.jsx(Gt,{isOpen:Q,onClose:()=>ee(!1),onOpenConfig:()=>$(!0),onOpenNotifications:()=>b(!0),onOpenHistory:()=>D(!0)})]})}function ua({onConfigChange:s,onToolChange:a,config:t,isOpen:o,onClose:d,onOpenBuildingModal:r,onOpenAreaExplorer:c,onOpenIntegrationsModal:f,onOpenMonitoringModal:n,onOpenStatisticsModal:g,onOpenWorkflowEditor:y,onOpenTriggerManager:k}){const{t:m}=Z(["config","common"]),E=Ms(),v=Bs(),S=Vs(),x=Ks(),u=Hs(),w=Array.from(E.values()),B=Array.from(v.values()),[z,G]=l.useState(""),K=l.useRef(null);if(l.useEffect(()=>{const p=_=>{_.key==="Escape"&&o&&d()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[o,d]),l.useEffect(()=>{if(o&&K.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const _=setTimeout(()=>{var U;(U=K.current)==null||U.focus()},50);return()=>clearTimeout(_)}},[o]),!o)return null;const H=p=>{a(u===p?null:p)},R=p=>{A.selectArea(x===p?null:p),a("select")},V=(p,_)=>{p.stopPropagation(),A.deleteArea(_)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:d}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:m("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:m("common:buttons.close"),children:"×"})]}),e.jsxs("div",{className:"toolbox-search",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{ref:K,type:"text",placeholder:m("config:searchPlaceholder"),value:z,onChange:p=>G(p.target.value),className:"toolbox-search-input"}),z&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>G(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(W,{title:m("config:areas.title",{count:w.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${u==="select"?"active":""}`,onClick:()=>H("select"),title:m("config:tools.select"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"})})})}),e.jsx("button",{className:`tool-btn ${u==="rectangle"?"active":""}`,onClick:()=>H("rectangle"),title:m("config:tools.rectangle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"})})})}),e.jsx("button",{className:`tool-btn ${u==="circle"?"active":""}`,onClick:()=>H("circle"),title:m("config:tools.circle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("circle",{cx:"12",cy:"12",r:"9"})})})})]}),e.jsx("div",{className:"areas-list",children:w.length===0?e.jsx("div",{className:"areas-empty",children:m("config:areas.drawToCreate")}):w.map(p=>e.jsx(Zs,{area:p,isSelected:x===p.id,onClick:()=>R(p.id),onDelete:_=>V(_,p.id)},p.id))})]})}),x&&e.jsx(st,{area:E.get(x),onClose:()=>A.selectArea(null),onOpenFolder:c}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(W,{title:m("config:buildings.title",{count:B.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:p=>{p.stopPropagation(),r==null||r()},title:m("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:B.length===0?e.jsx("div",{className:"buildings-empty",children:m("config:buildings.clickToAdd")}):B.map(p=>e.jsx(Xs,{building:p,isSelected:S.has(p.id),onClick:()=>{A.selectBuilding(S.has(p.id)?null:p.id)},onEdit:()=>r==null?void 0:r(p.id)},p.id))})})}),S.size===1&&(()=>{const p=Array.from(S)[0],_=v.get(p);return _?e.jsx(Qs,{building:_,onClose:()=>A.selectBuilding(null),onOpenModal:()=>r==null?void 0:r(p)}):null})(),e.jsx(oa,{config:t,onChange:s,searchQuery:z,onOpenIntegrationsModal:f,onOpenMonitoringModal:n,onOpenStatisticsModal:g,onOpenWorkflowEditor:y,onOpenTriggerManager:k})]})]})]})}export{ua as Toolbox};
|
|
1
|
+
import{r as l,j as e,I,u as Z,bl as Xe,ag as Qe,bm as rs,bn as ds,s as A,bo as us,bd as ps,bp as hs,C as he,K as se,L as X,i as we,k as ke,bq as ms,br as gs,bs as fs,bt as xs,bu as bs,bv as js,bw as vs,bx as es,by as Ns,bz as ys,X as ws,bA as Se,a9 as ks,bB as ss,bC as Ss,bD as Be,bE as Cs,bF as As,bG as Ts,bH as _s,bI as Es,bJ as Ps,bK as Is,as as Ls,b6 as $s,_ as Ds,S as ye,bL as Fs,bM as Os,b8 as Rs,bN as ze,$ as Pe,bi as zs,bO as Ue,bP as Us,a5 as Ms,m as Bs,bQ as Vs,bR as Ks,bS as Hs}from"./main-B-26AddI.js";import{g as qs,d as Ws,u as Gs}from"./area-logos-t-kcQpe2.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ts="tide-toolbox-collapse";function Ys(s,a){try{const t=localStorage.getItem(`${ts}-${s}`);if(t!==null)return t==="true"}catch{}return a}function Js(s,a){try{localStorage.setItem(`${ts}-${s}`,String(a))}catch{}}function W({title:s,storageKey:a,defaultOpen:t=!1,forceOpen:o=!1,children:d,headerExtra:r}){const[c,f]=l.useState(()=>a?Ys(a,t):t),n=()=>{const y=!c;f(y),a&&Js(a,y)},g=o||c;return e.jsxs("div",{className:`collapsible-section ${g?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:n,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(I,{name:g?"caret-down":"caret-right",size:10})})]})]}),g&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Zs({area:s,isSelected:a,onClick:t,onDelete:o}){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 ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[c," ",r>0&&`• ${r} ${r>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:d("config:areas.deleteArea"),children:"×"})]})}function Xs({building:s,isSelected:a,onClick:t,onEdit:o}){var f;const{t:d}=Z(["config"]),r=((f=s.pm2Status)==null?void 0:f.ports)||[],c=(n,g)=>{n.stopPropagation(),window.open(`http://${window.location.hostname}:${g}`,"_blank")};return e.jsxs("div",{className:`building-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:Xe[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(I,{name:Qe(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(n=>e.jsxs("a",{href:`http://${window.location.hostname}:${n}`,className:"building-port-link",onClick:g=>c(g,n),title:`Open :${n}`,children:[":",n]},n))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:n=>{n.stopPropagation(),o()},title:d("config:buildings.editBuilding"),children:e.jsx(I,{name:"gear",size:14})})]})}function Qs({building:s,onClose:a,onOpenModal:t}){var g,y,k,m,E,v,S,x;const{t:o}=Z(["config","common"]),r=rs().get(s.id)||[],c=ds[s.style||"server-rack"],f=u=>{A.sendBuildingCommand(s.id,u)},n=u=>{window.open(u,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx(I,{name:Qe(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:Xe[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:a,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children: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:o("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>f("start"),disabled:!((g=s.commands)!=null&&g.start)||s.status==="running",title:((y=s.commands)==null?void 0:y.start)||o("config:buildings.noStartCommand"),children:[e.jsx(I,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>f("stop"),disabled:!((k=s.commands)!=null&&k.stop)||s.status==="stopped",title:((m=s.commands)==null?void 0:m.stop)||o("config:buildings.noStopCommand"),children:[e.jsx(I,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>f("restart"),disabled:!((E=s.commands)!=null&&E.restart),title:((v=s.commands)==null?void 0:v.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx(I,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>f("healthCheck"),disabled:!((S=s.commands)!=null&&S.healthCheck),title:((x=s.commands)==null?void 0:x.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx(I,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((u,w)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>n(u.url),title:u.url,children:[e.jsx(I,{name:"link",size:12})," ",u.label||u.url]},w))})]}),r.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[o("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>A.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:r.slice(-5).map((u,w)=>e.jsx("div",{className:"building-editor-log-entry",children:u},w))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(I,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}const et=[{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 st({area:s,onClose:a,onOpenFolder:t}){var te;const{t:o}=Z(["config","common"]),[d,r]=l.useState(s.name),[c,f]=l.useState(s.prompt||""),[n,g]=l.useState(!1),[y,k]=l.useState(""),[m,E]=l.useState(!1),v=l.useRef(null);l.useEffect(()=>{r(s.name)},[s.id,s.name]),l.useEffect(()=>{f(s.prompt||"")},[s.id,s.prompt]);const S=j=>{const $=j.target.value;r($),A.updateArea(s.id,{name:$})},x=j=>{A.updateArea(s.id,{color:j})},u=j=>{const $=j.target.value;f($),A.updateArea(s.id,{prompt:$})},w=()=>{y.trim()&&(A.addDirectoryToArea(s.id,y.trim()),k(""),g(!1))},B=(j,$)=>{$.stopPropagation(),A.removeDirectoryFromArea(s.id,j)},z=()=>{A.bringAreaToFront(s.id)},G=()=>{A.sendAreaToBack(s.id)},K=l.useCallback(()=>{let j=2,$=2;s.type==="rectangle"&&s.width&&s.height?(j=s.width,$=s.height):s.type==="circle"&&s.radius&&(j=s.radius*1.414,$=s.radius*1.414);const M=Math.min(j,$)*.4;return{width:Math.round(M*10)/10,height:Math.round(M*10)/10}},[s.type,s.width,s.height,s.radius]),H=async j=>{var M;const $=(M=j.target.files)==null?void 0:M[0];if($){E(!0);try{const b=await Gs(s.id,$),L=K();A.updateArea(s.id,{logo:{filename:b.filename,position:"center",width:L.width,height:L.height,keepAspectRatio:!0,opacity:.8}})}catch(b){console.error("Failed to upload logo:",b)}finally{E(!1),v.current&&(v.current.value="")}}},R=async()=>{try{await Ws(s.id),A.updateArea(s.id,{logo:void 0})}catch(j){console.error("Failed to remove logo:",j)}},V=j=>{s.logo&&A.updateArea(s.id,{logo:{...s.logo,position:j}})},p=j=>{if(!s.logo)return;const $=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const M=s.logo.height/s.logo.width;A.updateArea(s.id,{logo:{...s.logo,width:$,height:Math.round($*M*10)/10}})}else A.updateArea(s.id,{logo:{...s.logo,width:$}})},_=j=>{if(!s.logo)return;const $=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const M=s.logo.width/s.logo.height;A.updateArea(s.id,{logo:{...s.logo,height:$,width:Math.round($*M*10)/10}})}else A.updateArea(s.id,{logo:{...s.logo,height:$}})},U=()=>{s.logo&&A.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},q=j=>{s.logo&&A.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(j.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:o("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:a,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange:S,placeholder:o("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:us.map(j=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===j?"selected":""}`,style:{backgroundColor:j},onClick:()=>x(j),"aria-label":`Set area color ${j}`,"aria-pressed":s.color===j,title:j},j))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:z,title:o("config:areas.bringToFront"),children:[e.jsx(I,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:G,title:o("config:areas.sendToBack"),children:[e.jsx(I,{name:"arrow-down",size:12})," ",o("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(te=s.logo)!=null&&te.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:qs(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:R,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var j;return(j=v.current)==null?void 0:j.click()},disabled:m,children:m?"...":e.jsx(I,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:et.map(({key:j,labelKey:$})=>{var M;return e.jsx("button",{className:`area-logo-pos-btn ${((M=s.logo)==null?void 0:M.position)===j?"active":""}`,onClick:()=>V(j),children:o(`config:areas.${$}`)},j)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:p,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:_,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:o("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:U}),o("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoOpacity")}),e.jsxs("div",{className:"area-logo-opacity-row",children:[e.jsx("input",{type:"range",min:0,max:1,step:.05,value:s.logo.opacity??.8,onChange:q,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var j;return(j=v.current)==null?void 0:j.click()},disabled:m,children:m?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:v,type:"file",accept:"image/*",style:{display:"none"},onChange:H})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(j=>e.jsxs("div",{className:"area-folder-item",title:j,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:o("config:areas.openFolder"),children:e.jsx(I,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:j.split("/").pop()||j}),e.jsx("button",{className:"area-folder-remove",onClick:$=>B(j,$),title:o("config:areas.removeFolder"),children:"×"})]},j)),n?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(ps,{value:y,onChange:k,onSubmit:w,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:w,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>g(!0),children:o("config:areas.addFolder")})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:c,onChange:u,placeholder:o("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:o("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:o("config:areas.rightClickUnassign")})]})]})}function tt(){const{t:s}=Z(["config","common"]),a=hs(),[t,o]=l.useState(!1),[d,r]=l.useState(null),[c,f]=l.useState({name:"",key:"",value:"",description:""}),[n,g]=l.useState(null),y=()=>{o(!0),r(null),f({name:"",key:"",value:"",description:""})},k=u=>{r(u.id),o(!1),f({name:u.name,key:u.key,value:u.value,description:u.description||""})},m=()=>{o(!1),r(null),f({name:"",key:"",value:"",description:""})},E=()=>{!c.name.trim()||!c.key.trim()||(d?A.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}):A.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),m())},v=u=>{g(u)},S=()=>{n&&(A.deleteSecret(n),d===n&&m())},x=u=>{navigator.clipboard.writeText(`{{${u}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children:a.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):a.map(u=>e.jsxs("div",{className:`secret-item ${d===u.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:u.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>x(u.key),title:s("config:secrets.copyPlaceholder"),children:`{{${u.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>k(u),title:s("common:buttons.edit"),children:e.jsx(I,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>v(u.id),title:s("common:buttons.delete"),children:"×"})]})]}),u.description&&e.jsx("div",{className:"secret-item-description",children:u.description})]},u.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:u=>f({...c,name:u.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:u=>f({...c,key:u.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:u=>f({...c,value:u.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:u=>f({...c,description:u.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:m,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick: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:y,children:s("config:secrets.addSecret")}),e.jsx(he,{isOpen:n!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:S,onClose:()=>g(null)})]})}async function at(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch system prompt: ${a.statusText}`);return(await a.json()).prompt||""}async function nt(s){const a=se(),t=await fetch(`${X()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function it(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to clear system prompt: ${a.statusText}`)}async function ot(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch echo prompt setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function lt(s){const a=se(),t=await fetch(`${X()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function ct(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch codex binary path: ${a.statusText}`);return(await a.json()).path||""}async function rt(s){const a=se(),t=await fetch(`${X()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function dt(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch tmux mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ut(s){const a=se(),t=await fetch(`${X()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function pt(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch interactive mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ht(s){const a=se(),t=await fetch(`${X()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function mt(){const s=se(),a=await fetch(`${X()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch backup status: ${a.statusText}`);return a.json()}async function gt(s){const a=se(),t=await fetch(`${X()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function ft({checked:s,onChange:a,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:o=>a(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function xt(){const{t:s}=Z(["config","common"]),[a,t]=l.useState([]),[o,d]=l.useState(new Set),[r,c]=l.useState(new Set),[f,n]=l.useState(!1),[g,y]=l.useState(!1),[k,m]=l.useState(null),[E,v]=l.useState(null),[S,x]=l.useState(null),[u,w]=l.useState(null),[B,z]=l.useState(!1),[G,K]=l.useState(null);l.useEffect(()=>{we(ke("/api/config/categories")).then(b=>b.json()).then(b=>{const L=Array.isArray(b)?b:[];t(L),d(new Set(L.map(D=>D.id)))}).catch(b=>console.error("Failed to fetch config categories:",b))},[]),l.useEffect(()=>{mt().then(w).catch(b=>{console.error("Failed to fetch backup status:",b),K(b.message||"Failed to fetch backup status")})},[]);const H=async b=>{if(!B){z(!0),K(null);try{const L=await gt(b);w(L)}catch(L){K(L.message||"Failed to update backup setting")}finally{z(!1)}}},R=b=>{d(L=>{const D=new Set(L);return D.has(b)?D.delete(b):D.add(b),D})},V=b=>{c(L=>{const D=new Set(L);return D.has(b)?D.delete(b):D.add(b),D})},p=()=>d(new Set(a.map(b=>b.id))),_=()=>d(new Set),U=()=>{E&&c(new Set(E.categories.map(b=>b.id)))},q=()=>c(new Set),te=async()=>{var b;if(o.size!==0){n(!0),x(null);try{const L=Array.from(o).join(","),D=await we(ke(`/api/config/export?categories=${L}`));if(!D.ok)throw new Error("Export failed");const Q=await D.blob(),ee=window.URL.createObjectURL(Q),C=document.createElement("a");C.href=ee;const N=D.headers.get("Content-Disposition"),Y=((b=N==null?void 0:N.match(/filename="(.+)"/))==null?void 0:b[1])||"tide-commander-config.zip";C.download=Y,document.body.appendChild(C),C.click(),document.body.removeChild(C),window.URL.revokeObjectURL(ee),x({type:"success",text:s("config:data.exportSuccess")})}catch(L){x({type:"error",text:L.message||"Export failed"})}finally{n(!1)}}},j=async b=>{var D;const L=(D=b.target.files)==null?void 0:D[0];if(L){m(L),x(null),v(null),c(new Set);try{const Q=await we(ke("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await L.arrayBuffer()});if(!Q.ok){const N=await Q.json();throw new Error(N.error||"Failed to preview config file")}const ee=await Q.json(),C=Array.isArray(ee.categories)?ee.categories:[];v({...ee,categories:C}),c(new Set(C.map(N=>N.id)))}catch(Q){x({type:"error",text:Q.message||"Failed to read config file"}),m(null)}}},$=async()=>{if(!(!k||r.size===0)){y(!0),x(null);try{const b=Array.from(r).join(","),L=await we(ke(`/api/config/import?categories=${b}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await k.arrayBuffer()}),D=await L.json();if(!L.ok)throw new Error(D.error||"Import failed");x({type:"success",text:D.message||s("config:data.importSuccess")}),m(null),v(null),c(new Set)}catch(b){x({type:"error",text:b.message||"Import failed"})}finally{y(!1)}}},M=()=>{m(null),v(null),c(new Set),x(null)};return e.jsxs("div",{className:"data-section",children:[S&&e.jsx("div",{className:`data-message data-message-${S.type}`,children:S.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(ft,{checked:!!(u!=null&&u.enabled),disabled:B||!u,onChange:H})]}),e.jsxs("div",{className:"data-backup-info",children:[u?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:u.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!u.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:u.scriptPath})]}),u.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(u.lastRunAt).toLocaleString(),u.lastRunOk===!0&&" — ok",u.lastRunOk===!1&&u.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",u.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),G&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:G})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:p,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:_,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:a.map(b=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(b.id),onChange:()=>R(b.id)}),e.jsx("span",{className:"data-category-name",children:b.name})]},b.id))}),e.jsx("button",{className:"data-action-btn export",onClick:te,disabled:f||o.size===0,children:f?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),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:U,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:q,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:E.categories.map(b=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:r.has(b.id),onChange:()=>V(b.id)}),e.jsx("span",{className:"data-category-name",children:b.name}),b.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",b.fileCount," ",s("config:data.files"),")"]})]},b.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:M,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:$,disabled:g||r.size===0,children:g?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:j,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function bt(){const[s,a]=l.useState(()=>ms()),t=o=>{a(o);const d=bs(o);js(d)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:gs.map(o=>e.jsxs("button",{className:`theme-option ${s===o.id?"active":""}`,onClick:()=>t(o.id),title:o.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:o.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:o.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:o.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:o.name})]},o.id))})})}function jt(){const{t:s}=Z(["config"]),{installInfo:a,phase:t,output:o,error:d,newVersion:r,autoRestart:c,refreshInstallInfo:f,runUpdate:n,reset:g}=vs(),[y,k]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{f()},[f]),l.useEffect(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)},[o]);const E=l.useCallback(()=>{k(!0)},[]),v=l.useCallback(()=>{k(!1)},[]),S=l.useCallback(()=>{k(!1),n()},[n]),x=l.useCallback(()=>{g(),k(!1),f()},[g,f]),u=es.isNativePlatform(),w=s(u?"config:about.autoUpdateServerTitle":"config:about.autoUpdateTitle");return a?a.isGlobalInstall?a.autoUpdateSupported?!a.updateAvailable&&t==="idle"?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:w}),t==="idle"&&!y&&a.updateAvailable&&e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsxs("span",{className:"about-autoupdate-versions",children:[e.jsx("span",{className:"about-autoupdate-current",children:a.currentVersion}),e.jsx("span",{className:"about-autoupdate-arrow",children:"→"}),e.jsx("span",{className:"about-autoupdate-latest",children:a.latestVersion})]}),e.jsx("button",{className:"about-update-btn download",onClick:E,children:s("config:about.autoUpdateButton")})]}),t==="idle"&&y&&e.jsxs("div",{className:"about-autoupdate-confirm",children:[e.jsx("div",{className:"about-autoupdate-confirm-title",children:s("config:about.autoUpdateConfirmTitle")}),e.jsx("div",{className:"about-autoupdate-confirm-body",children:s("config:about.autoUpdateConfirmBody")}),e.jsxs("div",{className:"about-autoupdate-confirm-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:v,children:s("config:about.autoUpdateCancel")}),e.jsx("button",{className:"about-update-btn download",onClick:S,children:s("config:about.autoUpdateConfirm")})]})]}),(t==="running"||t==="success"||t==="failed")&&e.jsxs("div",{className:"about-autoupdate-stream",children:[e.jsxs("div",{className:"about-autoupdate-stream-title",children:[t==="running"&&s("config:about.autoUpdateRunning"),t==="success"&&s("config:about.autoUpdateSuccess"),t==="failed"&&s("config:about.autoUpdateFailed")]}),e.jsx("pre",{ref:m,className:"about-autoupdate-output",children:o||"..."}),t==="success"&&e.jsxs("div",{className:"about-autoupdate-success-hint",children:[r&&e.jsxs("div",{className:"about-autoupdate-newversion",children:["v",r]}),e.jsx("div",{children:s(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:x,children:s("config:about.autoUpdateClose")})})]})]}):u?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:w}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdatePackageManagerNotice",{pm:a.packageManager})}),a.suggestedManualCommand&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"about-autoupdate-manualhint",children:s("config:about.autoUpdateManualCommand")}),e.jsx("pre",{className:"about-autoupdate-manualcmd",children:a.suggestedManualCommand})]})]}):u?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:w}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdateDevMode")})]}):null}function vt(){const{t:s}=Z(["config"]),[a,t]=l.useState(null),[o,d]=l.useState(!1),[r,c]=l.useState(null);l.useEffect(()=>{Ns().then(t).catch(y=>c(y.message))},[]);const f=l.useCallback(async y=>{if(!o){d(!0),c(null);try{t(await ys(y))}catch(k){c(k.message)}finally{d(!1)}}},[o]),n=es.isNativePlatform(),g=s(n?"config:about.unattendedServerTitle":"config:about.unattendedTitle");return!a&&!r?null:a?n&&!a.supported?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:g}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:about.unattendedDesc")}),e.jsxs("label",{className:"config-toggle",style:a.supported?void 0:{opacity:.5},children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:a.enabled,disabled:o||!a.supported,onChange:y=>void f(y.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),!a.supported&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedUnsupported")}),a.supported&&a.enabled&&a.pendingRestartVersion&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedPendingRestart",{version:a.pendingRestartVersion})}),a.supported&&a.enabled&&!a.pendingRestartVersion&&a.lastResult&&e.jsx("div",{className:"about-autoupdate-devnote",children:a.lastResult}),r&&e.jsx("div",{className:"about-update-error",children:r})]}):n?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:g}),e.jsx("div",{className:"about-update-error",children:r})]})}function Nt(){const{t:s}=Z(["config"]),{updateAvailable:a,updateInfo:t,recentReleases:o,isChecking:d,error:r,currentVersion:c,isAndroid:f,downloadPhase:n,downloadProgress:g,checkForUpdate:y,downloadAndInstall:k,openReleasePage:m}=fs(),[E,v]=l.useState(!1),S=u=>u?`${(u/(1024*1024)).toFixed(1)} MB`:"",x=u=>new Date(u).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:e.jsx(I,{name:"waves",size:24})}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:c}),a&&t?e.jsx("span",{className:"about-version-update-badge",onClick:m,title:`Update available: ${t.version}`,children:t.version}):e.jsxs("a",{href:"https://github.com/deivid11/tide-commander/releases",target:"_blank",rel:"noopener noreferrer",className:"about-version-status",children:["(",s("config:about.updated"),")"]})]})]}),e.jsx(jt,{}),e.jsx(vt,{}),e.jsx("div",{className:"about-changelog-row",children:e.jsx("button",{className:"about-update-btn changelog",onClick:()=>v(!0),children:s("config:about.changelog")})}),e.jsxs("div",{className:"about-update",children:[a&&t?e.jsxs("div",{className:"about-update-available",children:[e.jsxs("div",{className:"about-update-header",children:[e.jsx("span",{className:"about-update-badge",children:s("config:about.updateAvailable")}),e.jsx("span",{className:"about-update-version",children:t.version})]}),t.apkSize&&e.jsxs("div",{className:"about-update-size",children:[s("config:about.sizeLabel"),": ",S(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:m,children:s("config:about.changelog")}),f&&t.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:()=>void k(),disabled:n!=="idle",children:n==="downloading"?s("config:appUpdateBanner.downloadingPct",{percent:g??0}):s(n==="installing"?"config:appUpdateBanner.installHint":"config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:m,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(d?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>y(!0),disabled:d,children:d?"...":s("config:about.check")})]}),o.length>0&&e.jsxs("div",{className:"about-releases",children:[e.jsx("div",{className:"about-releases-title",children:s("config:about.recentReleases")}),e.jsx("div",{className:"about-releases-list",children:o.map(u=>e.jsxs("a",{href:u.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${u.version===`v${c}`||u.version===c?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:u.version}),e.jsx("span",{className:"about-release-date",children:x(u.publishedAt)})]},u.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:e.jsx(I,{name:"package",size:14})}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]}),E&&e.jsx(xs,{onClose:()=>v(!1)})]})}const yt={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function wt({onOpenModal:s}){const[a,t]=l.useState([]),[o,d]=l.useState(!0),r=l.useCallback(async()=>{try{const c=await we(ke("/api/integrations"));if(!c.ok)return;const f=await c.json();t(f)}catch{}finally{d(!1)}},[]);return l.useEffect(()=>{r()},[r]),o?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):a.length===0?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"No integrations available."}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[a.map(c=>{const f=yt[c.id]||"🔌",n=!!c.status.error,g=c.status.connected,y=n?"#f38ba8":g?"#a6e3a1":"#fab387",k=n?"Error":g?"Connected":"Setup Required",m=n?"✗":g?"✓":"⚠";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 8px",borderRadius:4,background:"var(--surface-1, #181825)",border:"1px solid var(--border, #313244)",fontSize:12,minHeight:26},children:[e.jsx("span",{style:{fontSize:13,flexShrink:0},children:f}),e.jsx("span",{style:{flex:1,minWidth:0,color:"var(--text-primary, #cdd6f4)",fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c.name}),e.jsx("span",{style:{color:y,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:k,children:m}),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 Ie="__global__";function kt({isOpen:s,onClose:a,initialAgentId:t}){const{t:o}=Z(["config"]),d=ws(),[r,c]=l.useState(""),[f,n]=l.useState(""),[g,y]=l.useState(!1),[k,m]=l.useState(""),[E,v]=l.useState(""),[S,x]=l.useState(null),[u,w]=l.useState(null),[B,z]=l.useState(!1),[G,K]=l.useState(!1),[H,R]=l.useState(!1),[V,p]=l.useState(null),_=l.useMemo(()=>[...d].sort((C,N)=>C.name.localeCompare(N.name)),[d]),U=l.useMemo(()=>d.find(C=>C.id===r),[d,r]),q=r===Ie;l.useEffect(()=>{if(!s)return;const C=t&&d.some(N=>N.id===t)?t:Ie;c(C),y(!1),at().then(N=>n(N)).catch(()=>n("")).finally(()=>y(!0))},[s]),l.useEffect(()=>{const C=r===Ie?f:(U==null?void 0:U.customPrompt)??"";m(C),v(C),z(!1),x(null),w(null)},[r,g]);const te=C=>{const N=C.target.value;m(N),z(N!==E),x(null),w(null)},j=async()=>{if(r)try{x(null),w(null),q?(await nt(k),n(k),w(o("config:systemPrompt.savedGlobal"))):(A.updateAgentProperties(r,{customPrompt:k}),w(o("config:systemPrompt.saved"))),v(k),z(!1)}catch(C){x(C instanceof Error?C.message:"Failed to save system prompt")}},$=()=>{K(!0)},M=async()=>{if(r)try{x(null),w(null),q?(await it(),n(""),w(o("config:systemPrompt.clearedGlobal"))):(A.updateAgentProperties(r,{customPrompt:""}),w(o("config:systemPrompt.cleared"))),m(""),v(""),z(!1)}catch(C){x(C instanceof Error?C.message:"Failed to clear system prompt")}},b=()=>{m(E),z(!1),x(null),w(null)},L=C=>{if(C!==r){if(B){p(C),R(!0);return}c(C)}},D=()=>{if(B){p(null),R(!0);return}a()},Q=()=>{if(R(!1),V){const C=V;p(null),c(C)}else a()},ee=C=>{C.key==="Escape"&&(C.preventDefault(),D())};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:D,children:e.jsxs("div",{className:"system-prompt-modal",onClick:C=>C.stopPropagation(),onKeyDown:ee,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:o("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:D,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"modal-description",children:o("config:systemPrompt.description")}),e.jsxs("div",{className:"agent-picker",children:[e.jsx("label",{htmlFor:"system-prompt-agent",className:"editor-label",children:o("config:systemPrompt.agentLabel")}),e.jsxs("div",{className:"agent-picker-row",children:[q?e.jsx(I,{name:"globe",size:20,className:"agent-picker-icon"}):U&&e.jsx(ks,{classId:U.class,size:20,className:"agent-picker-icon"}),e.jsxs("select",{id:"system-prompt-agent",className:"agent-picker-select",value:r,onChange:C=>L(C.target.value),children:[e.jsxs("option",{value:Ie,children:[o("config:systemPrompt.globalOption"),f?" • ✦":""]}),_.map(C=>e.jsxs("option",{value:C.id,children:[C.name,C.customPrompt?" • ✦":""]},C.id))]})]})]}),S&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),S]}),u&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),u]}),e.jsxs("div",{className:"editor-wrapper",children:[e.jsxs("div",{className:"editor-header",children:[e.jsx("label",{htmlFor:"prompt-input",className:"editor-label",children:o("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[k.length," ",o("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:k,onChange:te,placeholder:o("config:systemPrompt.placeholder"),rows:18,disabled:q&&!g,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:o(q?"config:systemPrompt.hintGlobal":"config:systemPrompt.hint")})]})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:$,disabled:!k||!r,children:o("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:D,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:b,disabled:!B,children:o("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:j,disabled:!B||!r,children:o("config:systemPrompt.save")})]})]})]})}),e.jsx(he,{isOpen:G,title:o("config:systemPrompt.clear"),message:o(q?"config:systemPrompt.confirmClearGlobal":"config:systemPrompt.confirmClear"),confirmLabel:o("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{M()},onClose:()=>K(!1)}),e.jsx(he,{isOpen:H,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:Q,onClose:()=>{R(!1),p(null)}})]}):null}const We={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},St=2500,Ct=12e4;function Ge(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function At(s,a){return s.enabled===a.enabled&&s.baseUrl===a.baseUrl&&s.defaultSessionId===a.defaultSessionId&&s.webhookVerifyToken===a.webhookVerifyToken&&s.showIncomingToasts===a.showIncomingToasts}function Tt({isOpen:s,onClose:a}){const{t}=Z(["config"]),[o,d]=l.useState(We),[r,c]=l.useState(We),[f,n]=l.useState(!1),[g,y]=l.useState([]),[k,m]=l.useState(!0),[E,v]=l.useState(null),[S,x]=l.useState(null),[u,w]=l.useState(""),[B,z]=l.useState(!1),[G,K]=l.useState(""),[H,R]=l.useState(null),[V,p]=l.useState(null),[_,U]=l.useState(null),q=l.useRef(null),te=l.useRef(0),[j,$]=l.useState(""),[M,b]=l.useState(""),[L,D]=l.useState(null),[Q,ee]=l.useState(!1),[C,N]=l.useState(!1),[Y,ae]=l.useState(!1),[le,ie]=l.useState(!1),[ue,je]=l.useState(null),ve=!At(o,r),re=l.useCallback(()=>{q.current&&(clearTimeout(q.current),q.current=null)},[]),me=l.useCallback(async()=>{try{m(!0),v(null),x(null);const[h,F]=await Promise.all([ss(),Ss()]),oe=Ge(h);if(d(oe),c(oe),n(!!F.configured),F.configured)try{const fe=await Be();y(Array.isArray(fe)?fe:[])}catch{y([])}else y([])}catch(h){v(h instanceof Error?h.message:t("config:whatsapp.errors.loadFailed"))}finally{m(!1)}},[t]),P=l.useCallback(async()=>{try{const h=await Be();y(Array.isArray(h)?h:[])}catch{}},[]);l.useEffect(()=>(s?me():(re(),R(null),p(null),U(null),w(""),z(!1),D(null)),()=>{re()}),[s,me,re]);const pe=(h,F)=>{d(oe=>({...oe,[h]:F})),v(null),x(null)},ce=async()=>{try{v(null),x(null);const h=await Es({enabled:o.enabled,baseUrl:o.baseUrl.trim(),defaultSessionId:o.defaultSessionId.trim(),webhookVerifyToken:o.webhookVerifyToken,showIncomingToasts:o.showIncomingToasts});window.dispatchEvent(new CustomEvent("tide:whatsapp-config-updated"));const F=Ge(h);d(F),c(F),x(t("config:whatsapp.saved"))}catch(h){v(h instanceof Error?h.message:t("config:whatsapp.errors.saveFailed"))}},$e=()=>{d(r),v(null),x(null)},ge=()=>{if(ve){N(!0);return}a()},De=h=>{h.key==="Escape"&&(h.preventDefault(),ge())},Fe=async()=>{const h=u.trim();if(h)try{v(null),x(null),await As(h),w(""),z(!1),n(!0),x(t("config:whatsapp.apiKeySaved"))}catch(F){v(F instanceof Error?F.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},Ce=()=>{ae(!0)},Oe=async()=>{try{v(null),x(null),await Ps(),n(!1),x(t("config:whatsapp.apiKeyCleared"))}catch(h){v(h instanceof Error?h.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},Ne=l.useCallback(async h=>{if(Date.now()>te.current){U(t("config:whatsapp.pairingTimeout")),R(null),p(null),re(),P();return}try{const F=await Cs(h);if(F.status&&["connected","paired","open","ready"].includes(F.status.toLowerCase())){U(t("config:whatsapp.pairingSuccess")),R(null),p(null),re(),P();return}const fe=F.qrUrl??F.qr??null;fe&&p(fe)}catch(F){U(F instanceof Error?F.message:t("config:whatsapp.errors.qrFetchFailed"))}q.current=setTimeout(()=>{Ne(h)},St)},[P,re,t]),Ae=async()=>{const h=G.trim();if(h)try{v(null),x(null),U(null),p(null),re(),await Ts(h),K(""),R(h),te.current=Date.now()+Ct,Ne(h),P()}catch(F){v(F instanceof Error?F.message:t("config:whatsapp.errors.sessionCreateFailed"))}},Te=()=>{re(),R(null),p(null),U(null)},_e=h=>{je(h),ie(!0)},Re=async()=>{if(ue)try{v(null),x(null),await Is(ue),H===ue&&Te(),P(),x(t("config:whatsapp.sessionDeleted"))}catch(h){v(h instanceof Error?h.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{je(null)}},Ee=async()=>{const h=j.trim(),F=M.trim();if(!(!h||!F))try{ee(!0),D(null);const oe=o.defaultSessionId.trim()||void 0;await _s(h,F,oe),D({kind:"success",text:t("config:whatsapp.testSent")})}catch(oe){D({kind:"error",text:oe instanceof Error?oe.message:t("config:whatsapp.errors.testSendFailed")})}finally{ee(!1)}};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:ge,children:e.jsxs("div",{className:"whatsapp-config-modal",onClick:h=>h.stopPropagation(),onKeyDown:De,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsapp.title")}),e.jsx("button",{className:"modal-close",onClick:ge,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:k?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsapp.description")}),E&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),E]}),S&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),S]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.general")}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-enabled",className:"wa-label",children:t("config:whatsapp.enabled")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-enabled",type:"checkbox",checked:o.enabled,onChange:h=>pe("enabled",h.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-show-toasts",className:"wa-label",children:t("config:whatsapp.showIncomingToasts")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-show-toasts",type:"checkbox",checked:o.showIncomingToasts,onChange:h=>pe("showIncomingToasts",h.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.showIncomingToastsHelp")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-base-url",className:"wa-label",children:t("config:whatsapp.baseUrl")}),e.jsx("input",{id:"wa-base-url",type:"text",className:"wa-input",placeholder:"http://localhost:3007",value:o.baseUrl,onChange:h=>pe("baseUrl",h.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-default-session",className:"wa-label",children:t("config:whatsapp.defaultSessionId")}),e.jsx("input",{id:"wa-default-session",type:"text",className:"wa-input",placeholder:t("config:whatsapp.defaultSessionIdPlaceholder"),value:o.defaultSessionId,onChange:h=>pe("defaultSessionId",h.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-webhook-token",className:"wa-label",children:t("config:whatsapp.webhookVerifyToken")}),e.jsx("input",{id:"wa-webhook-token",type:"text",className:"wa-input",placeholder:t("config:whatsapp.webhookVerifyTokenPlaceholder"),value:o.webhookVerifyToken,onChange:h=>pe("webhookVerifyToken",h.target.value)})]})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.apiKey")}),e.jsx("div",{className:"wa-key-status",children:f?e.jsxs("span",{className:"wa-status wa-status-ok",children:[e.jsx(I,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(I,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:B?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:u,onChange:h=>w(h.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>z(h=>!h),title:t(B?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(I,{name:B?"eye-closed":"eye",size:14})}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Fe,disabled:!u.trim(),children:t("config:whatsapp.saveKey")}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:Ce,disabled:!f,children:t("config:whatsapp.clearKey")})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.apiKeyHint")})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.sessions")}),e.jsx("div",{className:"wa-sessions-list",children:!Array.isArray(g)||g.length===0?e.jsx("div",{className:"wa-empty",children:t("config:whatsapp.noSessions")}):g.map(h=>e.jsxs("div",{className:"wa-session-row",children:[e.jsxs("div",{className:"wa-session-info",children:[e.jsx("span",{className:"wa-session-id",children:h.id}),e.jsx("span",{className:`wa-session-status status-${(h.status??"unknown").toLowerCase()}`,children:h.status||"—"}),h.pairedNumber&&e.jsx("span",{className:"wa-session-paired",children:h.pairedNumber})]}),e.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:()=>_e(h.id),children:t("config:whatsapp.deleteSession")})]},h.id))}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:"text",className:"wa-input",placeholder:t("config:whatsapp.addSessionPlaceholder"),value:G,onChange:h=>K(h.target.value),onKeyDown:h=>{h.key==="Enter"&&Ae()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ae,disabled:!G.trim()||H!==null,children:t("config:whatsapp.addSession")})]}),H&&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:H})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Te,children:t("config:whatsapp.cancelPairing")})]}),V?e.jsx("div",{className:"wa-qr-image",children:e.jsx("img",{src:V,alt:"WhatsApp pairing QR code"})}):e.jsxs("div",{className:"wa-qr-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.waitingForQr")})]})]}),_&&!H&&e.jsx("div",{className:"wa-pairing-message",children:_})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.testMessage")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-to",className:"wa-label",children:t("config:whatsapp.testTo")}),e.jsx("input",{id:"wa-test-to",type:"text",className:"wa-input",placeholder:t("config:whatsapp.testToPlaceholder"),value:j,onChange:h=>$(h.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:M,onChange:h=>b(h.target.value)})]}),e.jsx("div",{className:"wa-field-inline wa-field-end",children:e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ee,disabled:!j.trim()||!M.trim()||Q,children:t(Q?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),L&&e.jsxs("div",{className:`alert ${L.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:L.kind==="success"?"check":"warn",size:14})}),L.text]})]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left"}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:ge,children:t("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:$e,disabled:!ve||k,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:ce,disabled:!ve||k,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(he,{isOpen:C,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{N(!1),a()},onClose:()=>N(!1)}),e.jsx(he,{isOpen:Y,title:t("config:whatsapp.clearKey"),message:t("config:whatsapp.confirmClearKey"),confirmLabel:t("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Oe()},onClose:()=>ae(!1)}),e.jsx(he,{isOpen:le,title:t("config:whatsapp.deleteSession"),message:t("config:whatsapp.confirmDeleteSession",{id:ue??""}),confirmLabel:t("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Re()},onClose:()=>{ie(!1),je(null)}})]}):null}const as=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function Ve(s=!1){const a=se(),t={};return a&&(t.Authorization=`Bearer ${a}`),s&&(t["Content-Type"]="application/json"),t}async function Ke(s,a){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${a}: ${s.statusText}`}async function _t(){const s=await fetch(`${X()}/api/whatsapp/notification-config`,{headers:Ve()});if(!s.ok)throw new Error(await Ke(s,"Failed to fetch WhatsApp notification config"));return s.json()}async function Et(s){const a=await fetch(`${X()}/api/whatsapp/notification-config`,{method:"PATCH",headers:Ve(!0),body:JSON.stringify(s)});if(!a.ok)throw new Error(await Ke(a,"Failed to update WhatsApp notification config"));return a.json()}async function Pt(){const s=await fetch(`${X()}/api/whatsapp/notification-config`,{method:"DELETE",headers:Ve()});if(!s.ok)throw new Error(await Ke(s,"Failed to reset WhatsApp notification config"));return s.json()}const Le={messages:!0,statusChanges:!0,taskComplete:!0,errors:!0,planReady:!0,agentSpawned:!0,agentStopped:!0},Ye={filter:{...Le},recipient:""};function It(s,a){if(s.recipient!==a.recipient)return!1;for(const t of as)if(s.filter[t]!==a.filter[t])return!1;return!0}function Lt({isOpen:s,onClose:a}){const{t}=Z(["config"]),[o,d]=l.useState(Ye),[r,c]=l.useState(Ye),[f,n]=l.useState(!0),[g,y]=l.useState(null),[k,m]=l.useState(null),[E,v]=l.useState(!1),[S,x]=l.useState(!1),u=!It(o,r),w=l.useCallback(async()=>{try{n(!0),y(null),m(null);const p=await _t(),_={filter:{...Le,...p.filter},recipient:p.recipient??""};d(_),c(_)}catch(p){y(p instanceof Error?p.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{n(!1)}},[t]);l.useEffect(()=>{s&&w()},[s,w]);const B=(p,_)=>{d(U=>({...U,filter:{...U.filter,[p]:_}})),y(null),m(null)},z=p=>{d(_=>({..._,recipient:p})),y(null),m(null)},G=async()=>{try{y(null),m(null);const p=await Et({filter:o.filter,recipient:o.recipient.trim()}),_={filter:{...Le,...p.filter},recipient:p.recipient??""};d(_),c(_),m(t("config:whatsappNotifications.saved"))}catch(p){y(p instanceof Error?p.message:t("config:whatsappNotifications.errors.saveFailed"))}},K=()=>{d(r),y(null),m(null)},H=async()=>{try{y(null),m(null);const p=await Pt(),_={filter:{...Le,...p.filter},recipient:p.recipient??""};d(_),c(_),m(t("config:whatsappNotifications.resetDone"))}catch(p){y(p instanceof Error?p.message:t("config:whatsappNotifications.errors.resetFailed"))}},R=()=>{if(u){v(!0);return}a()},V=p=>{p.key==="Escape"&&(p.preventDefault(),R())};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:R,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:p=>p.stopPropagation(),onKeyDown:V,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappNotifications.title")}),e.jsx("button",{className:"modal-close",onClick:R,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:f?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsappNotifications.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsappNotifications.description")}),g&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),g]}),k&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),k]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.recipient")}),e.jsxs("div",{className:"wan-field",children:[e.jsx("label",{htmlFor:"wan-recipient",className:"wan-label",children:t("config:whatsappNotifications.recipientLabel")}),e.jsx("input",{id:"wan-recipient",type:"text",className:"wan-input",placeholder:t("config:whatsappNotifications.recipientPlaceholder"),value:o.recipient,onChange:p=>z(p.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")}),as.map(p=>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.${p}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${p}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:o.filter[p],onChange:_=>B(p,_.target.checked)}),e.jsx("span",{className:"wan-toggle-track",children:e.jsx("span",{className:"wan-toggle-thumb"})})]})]},p))]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:()=>x(!0),disabled:f,children:t("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:R,children:t("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:K,disabled:!u||f,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:G,disabled:!u||f,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(he,{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:()=>{v(!1),a()},onClose:()=>v(!1)}),e.jsx(he,{isOpen:S,title:t("config:whatsappNotifications.resetToDefaults"),message:t("config:whatsappNotifications.confirmReset"),confirmLabel:t("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{H(),x(!1)},onClose:()=>x(!1)})]}):null}function ns(s){const a=s.replace(/@.*$/,"");return/^\d{10,15}$/.test(a)?a.startsWith("521")&&a.length===13?`+52 1 ${a.slice(3,5)} ${a.slice(5,9)} ${a.slice(9)}`:a.startsWith("52")&&a.length===12?`+52 ${a.slice(2,4)} ${a.slice(4,8)} ${a.slice(8)}`:a.startsWith("1")&&a.length===11?`+1 ${a.slice(1,4)} ${a.slice(4,7)} ${a.slice(7)}`:`+${a}`:s}function $t(s,a=Date.now()){const t=s*1e3,o=a-t;if(o<0)return Je(t);const d=Math.floor(o/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`:Je(t)}function Je(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Dt(s){const a=s*1e3;return new Date(a).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function is(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 Ft(s,a){return s.length<=a?s:s.slice(0,Math.max(0,a-1)).trimEnd()+"…"}function Ot({chats:s,selectedChatId:a,loading:t,error:o,onSelect:d,onRefresh:r,now:c}){const{t:f}=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:f("config:whatsappHistory.chats")}),e.jsx("button",{type:"button",className:"whatsapp-history-chatlist__refresh",onClick:r,disabled:t,"aria-label":f("config:whatsappHistory.refresh"),title:f("config:whatsappHistory.refresh"),children:"⟳"})]}),o&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:o}),t&&s.length===0&&e.jsxs("div",{className:"whatsapp-history-chatlist__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:f("config:whatsappHistory.loadingChats")})]}),!t&&!o&&s.length===0&&e.jsx("div",{className:"whatsapp-history-chatlist__empty",children:f("config:whatsappHistory.emptyChats")}),e.jsx("ul",{className:"whatsapp-history-chatlist__items",children:s.map(n=>{const g=is(n.lastMessageType),y=n.lastMessagePreview||`[${n.lastMessageType}]`,k=n.chatId===a,m=ns(n.chatId),E=n.isGroup?n.groupName:n.fromName,v=E||m,S=!!E&&E!==m;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${k?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>d(n.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:n.chatId,children:v}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:$t(n.lastTimestamp,c)})]}),S&&e.jsx("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--jid",children:e.jsx("span",{className:"whatsapp-history-chatlist__jid",children:m})}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[n.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),g&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[g," "]}),Ft(y,40)]}),n.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:n.unreadCount})]})]})},n.chatId)})})]})}function Rt({message:s}){const a=s.direction==="outbound"?"outbound":"inbound",t=is(s.messageType),o=(s.body??"").trim(),d=o.length>0,r=d?null:`[${s.messageType}]`;return e.jsx("div",{className:`whatsapp-history-bubble whatsapp-history-bubble--${a}`,children:e.jsxs("div",{className:"whatsapp-history-bubble__inner",children:[t&&e.jsx("span",{className:"whatsapp-history-bubble__type-icon",title:s.messageType,children:t}),d?e.jsx("span",{className:"whatsapp-history-bubble__body",children:o}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:r}),s.audioTranscription&&e.jsxs("span",{className:"whatsapp-history-bubble__transcription",children:["“",s.audioTranscription,"”"]}),s.mediaPath&&e.jsx("a",{className:"whatsapp-history-bubble__media-link",href:s.mediaPath,target:"_blank",rel:"noopener noreferrer",children:s.mediaFilename||"open media"}),e.jsx("span",{className:"whatsapp-history-bubble__time",children:Dt(s.timestamp)})]})})}const zt=["all","inbound","outbound"],Ut=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function Mt({direction:s,type:a,onDirectionChange:t,onTypeChange:o,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:zt.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:a,onChange:c=>o(c.target.value),disabled:d,children:Ut.map(c=>e.jsx("option",{value:c,children:r(`config:whatsappHistory.typeValues.${c}`)},c))})]})]})}const Bt=80;function Vt({chatId:s,messages:a,loading:t,loadingMore:o,error:d,hasMore:r,direction:c,type:f,onDirectionChange:n,onTypeChange:g,onLoadMore:y}){const{t:k}=Z(["config"]),m=l.useRef(null),E=l.useRef(null),v=l.useRef(!1),S=l.useRef(null);l.useEffect(()=>{E.current!==s&&(E.current=s,v.current=!1)},[s]),l.useLayoutEffect(()=>{m.current&&(v.current||a.length!==0&&(m.current.scrollTop=m.current.scrollHeight,v.current=!0))},[s,a.length]),l.useLayoutEffect(()=>{if(!m.current||S.current===null)return;const w=m.current.scrollHeight-S.current;S.current=null,w>0&&(m.current.scrollTop+=w)},[a.length]);const x=l.useCallback(()=>{!r||o||t||(m.current&&(S.current=m.current.scrollHeight),y())},[r,o,t,y]),u=l.useCallback(w=>{if(!v.current)return;w.currentTarget.scrollTop<=Bt&&x()},[x]);return s?e.jsxs("div",{className:"whatsapp-history-messages",children:[e.jsxs("div",{className:"whatsapp-history-messages__header",children:[e.jsx("div",{className:"whatsapp-history-messages__title",children:ns(s)}),e.jsx(Mt,{direction:c,type:f,onDirectionChange:n,onTypeChange:g,disabled:t})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:m,onScroll:u,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:x,disabled:o||t,children:k(o?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),d&&e.jsx("div",{className:"whatsapp-history-messages__error",children:d}),t&&a.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&&a.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:k("config:whatsappHistory.emptyMessages")}),a.map(w=>e.jsx(Rt,{message:w},Kt(w)))]})]}):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 Kt(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 os(){const s=se(),a={};return s&&(a.Authorization=`Bearer ${s}`),a}async function ls(s,a){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${a}: ${s.statusText}`}async function Ht(s){const a=`${X()}/api/whatsapp/chats/${encodeURIComponent(s)}`,t=await fetch(a,{headers:os()});if(!t.ok)throw new Error(await ls(t,"Failed to fetch WhatsApp chats"));return t.json()}async function Ze(s,a,t={}){const o=new URLSearchParams;t.cursor&&o.set("cursor",t.cursor),typeof t.limit=="number"&&o.set("limit",String(t.limit)),t.direction&&o.set("direction",t.direction),t.type&&o.set("type",t.type);const d=o.toString(),r=`${X()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(a)}/messages${d?`?${d}`:""}`,c=await fetch(r,{headers:os()});if(!c.ok)throw new Error(await ls(c,"Failed to fetch WhatsApp messages"));return c.json()}const qt=50;function Wt({isOpen:s,onClose:a}){const{t}=Z(["config"]),[o,d]=l.useState([]),[r,c]=l.useState(null),[f,n]=l.useState(null),[g,y]=l.useState([]),[k,m]=l.useState(!1),[E,v]=l.useState(null),[S,x]=l.useState(null),[u,w]=l.useState([]),[B,z]=l.useState(!1),[G,K]=l.useState(!1),[H,R]=l.useState(null),[V,p]=l.useState(null),[_,U]=l.useState("all"),[q,te]=l.useState("all"),[j,$]=l.useState(()=>Date.now()),M=l.useRef(0);l.useEffect(()=>{if(!s)return;const N=window.setInterval(()=>$(Date.now()),6e4);return()=>window.clearInterval(N)},[s]),l.useEffect(()=>{if(!s)return;let N=!1;return(async()=>{var Y;try{n(null);const[ae,le]=await Promise.all([Be().catch(()=>[]),ss().catch(()=>null)]);if(N)return;d(ae);const ie=(le==null?void 0:le.defaultSessionId)||((Y=ae[0])==null?void 0:Y.id)||null;c(ue=>ue??ie)}catch(ae){if(N)return;n(ae instanceof Error?ae.message:String(ae))}})(),()=>{N=!0}},[s]);const b=l.useCallback(async N=>{m(!0),v(null);try{const Y=await Ht(N);y(Y.chats)}catch(Y){v(Y instanceof Error?Y.message:String(Y))}finally{m(!1)}},[]);l.useEffect(()=>{!s||!r||(x(null),w([]),p(null),b(r))},[s,r,b]);const L=l.useMemo(()=>{const N={limit:qt};return _!=="all"&&(N.direction=_),q!=="all"&&(N.type=q),N},[_,q]),D=l.useCallback(async(N,Y,ae)=>{const le=++M.current;z(!0),R(null),w([]),p(null);try{const ie=await Ze(N,Y,ae);if(le!==M.current)return;w([...ie.messages].reverse()),p(ie.nextCursor)}catch(ie){if(le!==M.current)return;R(ie instanceof Error?ie.message:String(ie))}finally{le===M.current&&z(!1)}},[]);l.useEffect(()=>{!s||!r||!S||D(r,S,L)},[s,r,S,L,D]);const Q=l.useCallback(async()=>{if(!(!r||!S||!V)){K(!0),R(null);try{const N=await Ze(r,S,{...L,cursor:V});w(Y=>[...[...N.messages].reverse(),...Y]),p(N.nextCursor)}catch(N){R(N instanceof Error?N.message:String(N))}finally{K(!1)}}},[r,S,V,L]),ee=l.useCallback(()=>{r&&b(r)},[r,b]),C=l.useCallback(N=>{N.key==="Escape"&&(N.preventDefault(),a())},[a]);return s?e.jsx(Se,{children:e.jsx("div",{className:"modal-overlay visible",onClick:a,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:N=>N.stopPropagation(),onKeyDown:C,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:N=>c(N.target.value||null),disabled:o.length===0,children:[o.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),o.map(N=>e.jsxs("option",{value:N.id,children:[N.id,N.pairedNumber?` (${N.pairedNumber})`:""]},N.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:a,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),f&&e.jsx("div",{className:"whatsapp-history-modal__alert",children:f}),e.jsxs("div",{className:"whatsapp-history-modal__body",children:[e.jsx(Ot,{chats:g,selectedChatId:S,loading:k,error:E,onSelect:x,onRefresh:ee,now:j}),e.jsx(Vt,{chatId:S,messages:u,loading:B,loadingMore:G,error:H,hasMore:V!==null,direction:_,type:q,onDirectionChange:U,onTypeChange:te,onLoadMore:Q})]})]})})}):null}function Gt({isOpen:s,onClose:a,onOpenConfig:t,onOpenNotifications:o,onOpenHistory:d}){const{t:r}=Z(["config"]);if(l.useEffect(()=>{if(!s)return;const f=n=>{n.key==="Escape"&&(n.preventDefault(),a())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[s,a]),!s)return null;const c=f=>{a(),f()};return e.jsx(Se,{children:e.jsx("div",{className:"modal-overlay visible",onClick:a,children:e.jsxs("div",{className:"whatsapp-hub-modal",onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"whatsapp-hub-modal__icon",children:"📱"}),r("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:a,"aria-label":"Close",children:e.jsx(I,{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(I,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children: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(o),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children: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(I,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children: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 Yt=[{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:"🌙"}],Jt=[{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:"🔴"}],Zt=[{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:"👎"}],Xt=[{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:"💜"}],Qt=[{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"}],ea=[{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"}],sa={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},ta={none:"grass","pokemon-stadium":"pokemon"},aa={"emote-yes":"yes","emote-no":"no"},na={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function ne({checked:s,onChange:a}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:t=>a(t.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function be({options:s,value:a,onChange:t,iconOnly:o=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(d=>e.jsxs("button",{className:`chip ${a===d.value?"active":""}`,onClick:()=>t(d.value),title:d.label,children:[e.jsx("span",{className:"chip-icon",children:d.icon}),!o&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function T({text:s,query:a}){if(!a.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),o=a.toLowerCase(),d=t.indexOf(o);if(d===-1)return e.jsx(e.Fragment,{children:s});const r=s.slice(0,d),c=s.slice(d,d+a.length),f=s.slice(d+a.length);return e.jsxs(e.Fragment,{children:[r,e.jsx("mark",{className:"search-highlight",children:c}),f]})}const ia=[{id:"general",title:"General",keywords:["history","hide costs","grid","fps","power saving","performance","limit","editor","external editor","language","idioma","语言","vibration","haptic","intensity","tab title","tmux","process persistence","interactive","tui","terminal","experimental","claude","stream","streaming","word by word","live text","grok"]},{id:"agentNames",title:"Agent Names",keywords:["agent","names","custom","characters","rename"]},{id:"defaultClass",title:"Default Spawn Class",keywords:["default","class","spawn","agent","scout","builder","random"]},{id:"appearance",title:"Appearance",keywords:["theme","appearance","color","dark","light","style","look"]},{id:"connection",title:"Connection",keywords:["backend","url","auth","token","reconnect","server","api","connect","codex","opencode","binary","path"]},{id:"scene",title:"Scene",keywords:["character","size","indicator","scale","time","dawn","day","dusk","night","auto"]},{id:"terrain",title:"Terrain",keywords:["trees","bushes","house","lamps","grass","clouds","fog","brightness","floor","sky","color","environment","battlefield","size","grid","simple","minimal","dark","clean"]},{id:"modelStyle",title:"Agent Model Style",keywords:["saturation","roughness","metalness","glow","emissive","reflections","wireframe","color mode","material","shader"]},{id:"animations",title:"Animations",keywords:["idle","working","animation","walk","run","sprint","jump","sit","crouch"]},{id:"secrets",title:"Secrets",keywords:["secrets","api","key","password","credentials","env","environment"]},{id:"systemPrompt",title:"System Prompt",keywords:["system","prompt","global","instructions","ai","agent","rules","guidelines"]},{id:"data",title:"Data",keywords:["export","import","backup","restore","save","load","json"]},{id:"integrations",title:"Integrations",keywords:["integrations","integraciones","plugins","gmail","slack","jira","calendar","docx","email","whatsapp","notifications","notification","baileys","history","historial","chat","messages","inbox","config","setup"]},{id:"workflows",title:"Workflows",keywords:["workflow","automation","state machine","editor","actions","transitions","pipeline"]},{id:"triggers",title:"Triggers",keywords:["trigger","event","webhook","cron","slack","email","jira","matching","fire"]},{id:"monitoring",title:"Monitoring",keywords:["monitoring","logs","triggers","events","history","workflow","traces","audit","timeline"]},{id:"statistics",title:"Statistics",keywords:["statistics","stats","usage","tokens","token","claude","chart","graph","pie","cost"]},{id:"experimental",title:"Experimental",keywords:["experimental","2d","view","voice","assistant","speech","tts","text to speech","echo","prompt","duplicate"]},{id:"about",title:"About",keywords:["about","version","update","credits","github","releases"]}],Me=[{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 oa({config:s,onChange:a,searchQuery:t="",onOpenIntegrationsModal:o,onOpenMonitoringModal:d,onOpenStatisticsModal:r,onOpenWorkflowEditor:c,onOpenTriggerManager:f}){var He;const{t:n}=Z(["config","common"]),g=Ls(),y=$s(),[k,m]=l.useState(()=>Ds(ye.DEFAULT_AGENT_CLASS)||"scout"),[E,v]=l.useState(g.historyLimit),[S,x]=l.useState(()=>Fs()),[u,w]=l.useState(!1),[B,z]=l.useState(""),[G,K]=l.useState(()=>se()),[H,R]=l.useState(!1),[V,p]=l.useState(!1),[_,U]=l.useState(""),[q,te]=l.useState(!1),[j,$]=l.useState(!1),[M,b]=l.useState(!1),[L,D]=l.useState(!1),[Q,ee]=l.useState(!1),[C,N]=l.useState(""),[Y,ae]=l.useState(!1);l.useEffect(()=>{ct().then(N).catch(()=>{})},[]),l.useEffect(()=>{ot().then(i=>{i!==g.experimentalEchoPrompt&&A.updateSettings({experimentalEchoPrompt:i})}).catch(()=>{})},[]),l.useEffect(()=>{dt().then(i=>{i!==g.tmuxMode&&A.updateSettings({tmuxMode:i})}).catch(()=>{})},[]),l.useEffect(()=>{pt().then(i=>{i!==g.interactiveMode&&A.updateSettings({interactiveMode:i})}).catch(()=>{})},[]),l.useEffect(()=>Os(i=>{x(i),w(!1)}),[]);const le=Yt.map(i=>({...i,label:n(`config:time.${i.value}`)})),ie=Jt.map(i=>({...i,label:n(`config:floor.${ta[i.value]||i.value}`)})),ue=Zt.map(i=>({...i,label:n(`config:animation.${aa[i.value]||i.value}`)})),je=Xt.map(i=>({...i,label:n(`config:colorMode.${i.value}`)})),ve=Qt.map(i=>({...i,label:n(`config:terrain.${sa[i.key]}`)})),re=ea.map(i=>({...i,label:n(`config:sky.${na[i.value??""]}`)})),me=t.trim()?ia.filter(i=>{const O=t.toLowerCase();return i.title.toLowerCase().includes(O)||i.keywords.some(de=>de.toLowerCase().includes(O))}).map(i=>i.id):null,P=i=>me?me.includes(i):!0,pe=P("integrations"),ce=g.customAgentNames||[],$e=ce.length>0?ce:Rs,ge=()=>{const i=_.trim();i&&!ce.includes(i)&&(A.updateSettings({customAgentNames:[...ce,i]}),U(""))},De=i=>{A.updateSettings({customAgentNames:ce.filter(O=>O!==i)})},Fe=()=>{A.updateSettings({customAgentNames:[]})},Ce=()=>{const i=B.trim();if(i){if(S.includes(i)){z("");return}x([...S,i]),w(!0),z("")}},Oe=i=>{x(S.filter((O,de)=>de!==i)),w(!0)},Ne=(i,O)=>{const de=i+O;if(de<0||de>=S.length)return;const xe=S.slice();[xe[i],xe[de]]=[xe[de],xe[i]],x(xe),w(!0)},Ae=()=>{Us(S),w(!1),Ue()},Te=i=>{K(i),R(!0)},_e=()=>{Pe(ye.AUTH_TOKEN,G),R(!1),Ue()},Re=i=>{N(i),ae(!0)},Ee=()=>{rt(C).catch(()=>{}),ae(!1)},h=i=>{a({...s,terrain:{...s.terrain,...i}})},F=i=>{a({...s,modelStyle:{...s.modelStyle,...i}})},oe=i=>{a({...s,animations:{...s.animations,...i}})},fe=i=>{v(i),A.updateSettings({historyLimit:i})},cs=i=>{const O=s.terrain[i];typeof O=="boolean"&&h({[i]:!O})},J=t.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[me&&me.length===0&&e.jsx("div",{className:"config-no-results",children:n("config:noResults",{query:t})}),P("general")&&e.jsxs(W,{title:n("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:J&&P("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:E,onChange:i=>fe(parseInt(i.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:n("config:general.hideCosts"),query:t})}),e.jsx(ne,{checked:g.hideCost,onChange:i=>A.updateSettings({hideCost:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:n("config:general.streamTextLiveTitle"),children:e.jsx(T,{text:n("config:general.streamTextLive"),query:t})}),e.jsx(ne,{checked:g.streamTextLive!==!1,onChange:i=>A.updateSettings({streamTextLive:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.grid"),query:t})}),e.jsx(ne,{checked:s.gridVisible,onChange:i=>a({...s,gridVisible:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.showFPS"),query:t})}),e.jsx(ne,{checked:g.showFPS,onChange:i=>A.updateSettings({showFPS:i})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.fpsLimit"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:i=>a({...s,fpsLimit:parseInt(i.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:n("config:general.powerSaving"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ne,{checked:g.powerSaving,onChange:i=>A.updateSettings({powerSaving:i})})]}),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:n("config:general.tmuxMode"),query:t})}),e.jsx(ne,{checked:g.tmuxMode,onChange:async i=>{A.updateSettings({tmuxMode:i});try{await ut(i)}catch(O){console.error("Failed to sync tmux mode setting to server:",O)}}})]}),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:n("config:general.interactiveMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ne,{checked:g.interactiveMode,onChange:async i=>{A.updateSettings({interactiveMode:i});try{await ht(i)}catch(O){console.error("Failed to sync interactive mode setting to server:",O)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.vibrationIntensity"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:g.vibrationIntensity,onChange:i=>A.updateSettings({vibrationIntensity:parseInt(i.target.value)})}),e.jsx("span",{className:"config-value",children:g.vibrationIntensity===0?n("config:vibrationValues.off"):g.vibrationIntensity===1?n("config:vibrationValues.ultraLight"):g.vibrationIntensity===2?n("config:vibrationValues.veryLight"):g.vibrationIntensity===3?n("config:vibrationValues.light"):g.vibrationIntensity===4?n("config:vibrationValues.medium"):n("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.externalEditor"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:n("config:general.externalEditorPlaceholder"),value:g.externalEditorCommand||"",onChange:i=>A.updateSettings({externalEditorCommand:i.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.tabTitle"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:n("config:general.tabTitlePlaceholder"),value:g.tabTitle||"",onChange:i=>A.updateSettings({tabTitle:i.target.value})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:general.language"),query:t})}),e.jsx(be,{options:Me,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((He=Me.find(i=>i.value!=="auto"&&ze.language.startsWith(i.value.split("-")[0])))==null?void 0:He.value)||"en":"auto",onChange:i=>{var O;if(i==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const de=navigator.language,xe=((O=Me.find(qe=>qe.value!=="auto"&&de.startsWith(qe.value.split("-")[0])))==null?void 0:O.value)||"en";ze.changeLanguage(xe)}else localStorage.setItem("tide-commander-language-mode","manual"),ze.changeLanguage(i)}})]})]}),P("agentNames")&&e.jsx(W,{title:n("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:J&&P("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:ce.length>0?n("config:agentNames.customConfigured",{count:ce.length}):n("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:n("config:agentNames.addPlaceholder"),value:_,onChange:i=>U(i.target.value),onKeyDown:i=>{i.key==="Enter"&&ge()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ge,disabled:!_.trim(),title:n("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:$e.map((i,O)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:i}),ce.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>De(i),title:n("common:buttons.remove"),children:"x"})]},`${i}-${O}`))}),ce.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:Fe,children:n("common:buttons.resetToDefaults")})]})}),P("defaultClass")&&e.jsx(W,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:J&&P("defaultClass"),children:e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-hint",children:'Class pre-selected when the spawn modal opens. "Random" picks a different class each time.'}),e.jsxs("div",{className:"agent-names-list",style:{flexWrap:"wrap",gap:"6px",marginTop:"8px"},children:[e.jsx("div",{className:`agent-name-chip${k==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m("random"),Pe(ye.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(zs).map(([i,O])=>e.jsx("div",{className:`agent-name-chip${k===i?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(i),Pe(ye.DEFAULT_AGENT_CLASS,i)},children:e.jsxs("span",{className:"agent-name-text",children:[O.icon," ",i.charAt(0).toUpperCase()+i.slice(1)]})},i)),y.map(i=>e.jsx("div",{className:`agent-name-chip${k===i.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(i.id),Pe(ye.DEFAULT_AGENT_CLASS,i.id)},children:e.jsxs("span",{className:"agent-name-text",children:[i.icon," ",i.name]})},i.id))]})]})}),P("appearance")&&e.jsx(W,{title:n("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:J&&P("appearance"),children:e.jsx(bt,{})}),P("connection")&&e.jsxs(W,{title:n("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:J&&P("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:S.map((i,O)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:n("config:connection.priorityLabel",{defaultValue:"Priority"}),children:O+1}),e.jsx("span",{className:"backend-url-text",title:i,children:i}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ne(O,-1),disabled:O===0,title:n("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ne(O,1),disabled:O===S.length-1,title:n("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Oe(O),title:n("common:buttons.remove"),children:"x"})]},`${i}-${O}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:B,onChange:i=>z(i.target.value),placeholder:n("config:connection.addUrlPlaceholder",{defaultValue:"http://host:port"}),onKeyDown:i=>{i.key==="Enter"&&Ce()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ce,disabled:!B.trim(),title:n("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),u&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ae,title:n("config:connection.saveAndReconnect"),children:n("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:n("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:n("config:connection.authToken"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:V?"text":"password",className:"config-input config-input-full",value:G,onChange:i=>Te(i.target.value),placeholder:n("config:connection.tokenPlaceholder"),onKeyDown:i=>{i.key==="Enter"&&H&&_e()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>p(!V),title:n(V?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(I,{name:V?"eye-closed":"eye",size:14})}),H&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:_e,title:n("config:connection.saveAndReconnect"),children:n("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:n("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:C,onChange:i=>Re(i.target.value),placeholder:n("config:connection.codexBinaryPathPlaceholder"),onKeyDown:i=>{i.key==="Enter"&&Y&&Ee()}}),Y&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ee,children:n("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:n("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("common:buttons.reconnect"),query:t})}),e.jsx("button",{className:"config-btn",onClick:()=>Ue(),title:"Force reconnect to server",children:n("common:buttons.reconnect")})]})]}),P("scene")&&e.jsxs(W,{title:n("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:J&&P("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>a({...s,characterScale:parseFloat(i.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:n("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:i=>a({...s,scale2d:parseFloat(i.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:n("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:i=>a({...s,scale3d:parseFloat(i.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:n("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:t})}),e.jsx(ne,{checked:s.show2DTaskLabels,onChange:i=>a({...s,show2DTaskLabels:i})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:scene.time"),query:t})}),e.jsx(be,{options:le,value:s.timeMode,onChange:i=>a({...s,timeMode:i}),iconOnly:!0})]})]}),P("terrain")&&e.jsxs(W,{title:n("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:J&&P("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:t})}),e.jsx(ne,{checked:s.terrain.simpleMode??!1,onChange:i=>h({simpleMode:i})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:ve.map(i=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[i.key]?"active":""}`,onClick:()=>cs(i.key),title:i.label,children:i.icon},i.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>h({fogDensity:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?n("config:fogValues.off"):s.terrain.fogDensity<=1?n("config:fogValues.low"):n("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>h({brightness:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?n("config:brightnessValues.dark"):s.terrain.brightness<=1.2?n("config:brightnessValues.normal"):n("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:terrainSettings.floor"),query:t})}),e.jsx(be,{options:ie,value:s.terrain.floorStyle,onChange:i=>h({floorStyle:i}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:terrainSettings.sky"),query:t})}),e.jsx("div",{className:"sky-color-selector",children:re.map(i=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===i.value?"active":""}`,onClick:()=>h({skyColor:i.value}),title:i.label,style:{background:i.color}},i.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:terrainSettings.battlefieldSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:i=>h({battlefieldSize:parseInt(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),P("modelStyle")&&e.jsxs(W,{title:n("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:J&&P("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>F({saturation:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?n("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?n("config:saturationValues.normal"):n("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>F({roughness:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?n("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?n("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?n("config:roughnessValues.normal"):n("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>F({metalness:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?n("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?n("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?n("config:metalnessValues.mixed"):n("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>F({emissiveBoost:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?n("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?n("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?n("config:glowValues.med"):n("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("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:i=>F({envMapIntensity:parseFloat(i.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?n("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?n("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?n("config:reflectionValues.normal"):n("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:modelStyleSettings.wireframe"),query:t})}),e.jsx(ne,{checked:s.modelStyle.wireframe,onChange:i=>F({wireframe:i})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:modelStyleSettings.colorMode"),query:t})}),e.jsx(be,{options:je,value:s.modelStyle.colorMode,onChange:i=>F({colorMode:i}),iconOnly:!0})]})]}),P("animations")&&e.jsxs(W,{title:n("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:J&&P("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:animationSettings.idle"),query:t})}),e.jsx(be,{options:ue,value:s.animations.idleAnimation,onChange:i=>oe({idleAnimation:i}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:animationSettings.working"),query:t})}),e.jsx(be,{options:ue,value:s.animations.workingAnimation,onChange:i=>oe({workingAnimation:i}),iconOnly:!0})]})]}),P("secrets")&&e.jsx(W,{title:n("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:J&&P("secrets"),children:e.jsx(tt,{})}),P("systemPrompt")&&e.jsx(W,{title:n("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:J&&P("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(T,{text:n("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>te(!0),children:n("config:systemPrompt.editPrompt")})]})}),P("data")&&e.jsx(W,{title:n("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:J&&P("data"),children:e.jsx(xt,{})}),pe&&e.jsx(W,{title:n("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:J&&pe,children:e.jsx(wt,{onOpenModal:i=>{i==="whatsapp"?ee(!0):o==null||o(i)}})}),P("workflows")&&e.jsxs(W,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:J&&P("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:()=>c==null?void 0:c(),children:"Open Workflow Editor"})})]}),P("triggers")&&e.jsxs(W,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:J&&P("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:()=>f==null?void 0:f(),children:"Open Trigger Manager"})})]}),P("monitoring")&&e.jsxs(W,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:J&&P("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:()=>d==null?void 0:d(),children:"Open Monitoring & Logs"})})]}),P("statistics")&&e.jsxs(W,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:J&&P("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:()=>r==null?void 0:r(),children:"Open Statistics"})})]}),P("experimental")&&e.jsxs(W,{title:n("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:J&&P("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:n("config:experimental.2dView"),query:t})," ",e.jsx(I,{name:"map",size:12})]}),e.jsx(ne,{checked:g.experimental2DView,onChange:i=>A.updateSettings({experimental2DView:i})})]}),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:n("config:experimental.voiceAssistant"),query:t})," ",e.jsx(I,{name:"microphone",size:12})]}),e.jsx(ne,{checked:g.experimentalVoiceAssistant,onChange:i=>A.updateSettings({experimentalVoiceAssistant:i})})]}),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:n("config:experimental.tts"),query:t})," ",e.jsx(I,{name:"speaker-on",size:12})]}),e.jsx(ne,{checked:g.experimentalTTS,onChange:i=>A.updateSettings({experimentalTTS:i})})]}),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:n("config:experimental.echoPrompt"),query:t})}),e.jsx(ne,{checked:g.experimentalEchoPrompt,onChange:async i=>{A.updateSettings({experimentalEchoPrompt:i});try{await lt(i)}catch(O){console.error("Failed to sync echo prompt setting to server:",O)}}})]}),e.jsx("span",{className:"config-hint",children:n("config:experimental.hint")})]}),P("about")&&e.jsx(W,{title:n("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:J&&P("about"),children:e.jsx(Nt,{})})]}),e.jsx(kt,{isOpen:q,onClose:()=>te(!1)}),e.jsx(Tt,{isOpen:j,onClose:()=>$(!1)}),e.jsx(Lt,{isOpen:M,onClose:()=>b(!1)}),e.jsx(Wt,{isOpen:L,onClose:()=>D(!1)}),e.jsx(Gt,{isOpen:Q,onClose:()=>ee(!1),onOpenConfig:()=>$(!0),onOpenNotifications:()=>b(!0),onOpenHistory:()=>D(!0)})]})}function ua({onConfigChange:s,onToolChange:a,config:t,isOpen:o,onClose:d,onOpenBuildingModal:r,onOpenAreaExplorer:c,onOpenIntegrationsModal:f,onOpenMonitoringModal:n,onOpenStatisticsModal:g,onOpenWorkflowEditor:y,onOpenTriggerManager:k}){const{t:m}=Z(["config","common"]),E=Ms(),v=Bs(),S=Vs(),x=Ks(),u=Hs(),w=Array.from(E.values()),B=Array.from(v.values()),[z,G]=l.useState(""),K=l.useRef(null);if(l.useEffect(()=>{const p=_=>{_.key==="Escape"&&o&&d()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[o,d]),l.useEffect(()=>{if(o&&K.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const _=setTimeout(()=>{var U;(U=K.current)==null||U.focus()},50);return()=>clearTimeout(_)}},[o]),!o)return null;const H=p=>{a(u===p?null:p)},R=p=>{A.selectArea(x===p?null:p),a("select")},V=(p,_)=>{p.stopPropagation(),A.deleteArea(_)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:d}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:m("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:m("common:buttons.close"),children:"×"})]}),e.jsxs("div",{className:"toolbox-search",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{ref:K,type:"text",placeholder:m("config:searchPlaceholder"),value:z,onChange:p=>G(p.target.value),className:"toolbox-search-input"}),z&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>G(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(W,{title:m("config:areas.title",{count:w.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${u==="select"?"active":""}`,onClick:()=>H("select"),title:m("config:tools.select"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"})})})}),e.jsx("button",{className:`tool-btn ${u==="rectangle"?"active":""}`,onClick:()=>H("rectangle"),title:m("config:tools.rectangle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"})})})}),e.jsx("button",{className:`tool-btn ${u==="circle"?"active":""}`,onClick:()=>H("circle"),title:m("config:tools.circle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("circle",{cx:"12",cy:"12",r:"9"})})})})]}),e.jsx("div",{className:"areas-list",children:w.length===0?e.jsx("div",{className:"areas-empty",children:m("config:areas.drawToCreate")}):w.map(p=>e.jsx(Zs,{area:p,isSelected:x===p.id,onClick:()=>R(p.id),onDelete:_=>V(_,p.id)},p.id))})]})}),x&&e.jsx(st,{area:E.get(x),onClose:()=>A.selectArea(null),onOpenFolder:c}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(W,{title:m("config:buildings.title",{count:B.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:p=>{p.stopPropagation(),r==null||r()},title:m("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:B.length===0?e.jsx("div",{className:"buildings-empty",children:m("config:buildings.clickToAdd")}):B.map(p=>e.jsx(Xs,{building:p,isSelected:S.has(p.id),onClick:()=>{A.selectBuilding(S.has(p.id)?null:p.id)},onEdit:()=>r==null?void 0:r(p.id)},p.id))})})}),S.size===1&&(()=>{const p=Array.from(S)[0],_=v.get(p);return _?e.jsx(Qs,{building:_,onClose:()=>A.selectBuilding(null),onOpenModal:()=>r==null?void 0:r(p)}):null})(),e.jsx(oa,{config:t,onChange:s,searchQuery:z,onOpenIntegrationsModal:f,onOpenMonitoringModal:n,onOpenStatisticsModal:g,onOpenWorkflowEditor:y,onOpenTriggerManager:k})]})]})]})}export{ua as Toolbox};
|