tide-commander 1.98.0 → 1.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/assets/{BossLogsModal-P6MiZVuY.js → BossLogsModal-CDel834o.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-DZJ1Ngsz.js → BossSpawnModal-BB9wL5VV.js} +1 -1
  3. package/dist/assets/{ControlsModal-BjV0a1kc.js → ControlsModal-D5RE5MvT.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-DtddubKa.js → DockerLogsModal-B27P1JpZ.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-ByRepTwR.js → EmbeddedEditor-DP1jqsT_.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-DS6NmxUi.js → GmailOAuthSetup-DvuL5G8Q.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-kQyKInRW.js → GoogleOAuthSetup-CG6bSCjv.js} +1 -1
  8. package/dist/assets/{IframeModal-BuTPDTx1.js → IframeModal-ClnUGmJV.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-Bm19ZAd6.js → IntegrationsPanel-0vdfxZRq.js} +2 -2
  10. package/dist/assets/{LogViewerModal-DFlUtkDD.js → LogViewerModal-DLQlrZ4O.js} +1 -1
  11. package/dist/assets/{MonitoringModal-BEEPwGu5.js → MonitoringModal-DiC9TNCy.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-Di5MjyxZ.js → PM2LogsModal-BgPrnaP5.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-CNjmR7BX.js → RestoreArchivedAreaModal-CIN1OrOW.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-CA29sh9R.js → Scene2DCanvas-Bap6brvv.js} +1 -1
  15. package/dist/assets/{SceneManager-duyCA_TD.js → SceneManager-CidCW0PR.js} +1 -1
  16. package/dist/assets/{SkillsPanel-CkV4ci4Q.js → SkillsPanel-DHQTPaP2.js} +1 -1
  17. package/dist/assets/{SlackMultiInstanceSetup-iHZNQX3B.js → SlackMultiInstanceSetup-CQK4D89W.js} +1 -1
  18. package/dist/assets/{SpawnModal-bzQlnSQy.js → SpawnModal-Cx_k3HHC.js} +1 -1
  19. package/dist/assets/{SubordinateAssignmentModal-D6Ak_XQ1.js → SubordinateAssignmentModal-C1DOv51H.js} +1 -1
  20. package/dist/assets/{TriggerManagerPanel-CT8aMQ5P.js → TriggerManagerPanel-jP5RBK2L.js} +1 -1
  21. package/dist/assets/{WorkflowEditorPanel-DcV9ErU4.js → WorkflowEditorPanel-Dh6mZ8M4.js} +1 -1
  22. package/dist/assets/{index-Cirz97EK.js → index-B-ttQFx4.js} +2 -2
  23. package/dist/assets/index-BXnThzaG.js +11 -0
  24. package/dist/assets/{index-C0fIrrTS.js → index-CYwFXTQZ.js} +1 -1
  25. package/dist/assets/{index-Cnj2pM08.js → index-Cwlm-Pqi.js} +3 -3
  26. package/dist/assets/{index-Ba8umpS_.js → index-D96LXKm4.js} +1 -1
  27. package/dist/assets/{index-BQQV5Xax.js → index-DP5sMNS9.js} +1 -1
  28. package/dist/assets/{index-Dww2MWLN.js → index-DfEbuBH8.js} +1 -1
  29. package/dist/assets/{index-D2L5oc5D.js → index-DsKaX6TJ.js} +1 -1
  30. package/dist/assets/{index-DR7uaDtK.js → index-enJvXAbe.js} +1 -1
  31. package/dist/assets/{main-XbhAPjbi.js → main-B7wf_xU_.js} +91 -91
  32. package/dist/assets/main-DLzFxLC1.css +1 -0
  33. package/dist/assets/{web-C4LpSGoH.js → web-BHmmnvF7.js} +1 -1
  34. package/dist/assets/{web-CaPUSaID.js → web-IGuhG0xr.js} +1 -1
  35. package/dist/assets/{web-C-JnApw7.js → web-SOehUGgT.js} +1 -1
  36. package/dist/index.html +2 -2
  37. package/dist/locales/en/config.json +16 -1
  38. package/dist/src/packages/server/routes/index.js +2 -0
  39. package/dist/src/packages/server/routes/system.js +156 -0
  40. package/dist/src/packages/server/services/self-update-service.js +191 -0
  41. package/package.json +1 -1
  42. package/dist/assets/index-CDHzSAgq.js +0 -1
  43. package/dist/assets/main-CD03IZnY.css +0 -1
@@ -1 +0,0 @@
1
- import{r as l,aT as Re,aU as Ye,j as e,I,u as Y,aV as ts,a2 as ns,f as Ve,s as _,aW as hs,k as us,l as me,aX as Z,aY as ms,aM as gs,aZ as fs,C as ge,a_ as X,aJ as ke,a$ as xs,b0 as bs,b1 as js,b2 as ws,b3 as Se,b4 as is,b5 as ys,b6 as Me,b7 as vs,b8 as Ns,b9 as ks,ba as Ss,bb as Cs,bc as As,bd as Ts,aF as _s,J as Es,S as Ne,be as Is,bf as Ps,aH as Ls,bg as ze,K as Pe,aQ as $s,bh as Ue,bi as Ds}from"./main-XbhAPjbi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ke="deivid11/tide-commander",Fs=`https://api.github.com/repos/${Ke}/releases/latest`,Os=`https://api.github.com/repos/${Ke}/releases?per_page=3`,Rs=3600*1e3,Je="app_update_dismissed_version",Ze="1.98.0";function zs(){var x,y;const[s,n]=l.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:Ze}),a=((y=(x=Re)==null?void 0:x.getPlatform)==null?void 0:y.call(x))==="android"||!1,o=h=>h.replace(/^v/,"").split(".").map(g=>parseInt(g,10)||0),r=(h,f)=>{const g=o(h),v=o(f),b=Math.max(g.length,v.length);for(let p=0;p<b;p++){const L=g[p]||0,M=v[p]||0;if(L>M)return 1;if(L<M)return-1}return 0},d=async h=>{var g,v;if(Re&&Ye&&((v=(g=Re).isNativePlatform)==null?void 0:v.call(g))===!0){const b=await Ye.get({url:h,headers:{Accept:"application/vnd.github.v3+json"}});return{data:b.data,status:b.status}}else{const b=await fetch(h,{headers:{Accept:"application/vnd.github.v3+json"}});return b.ok?{data:await b.json(),status:b.status}:{data:null,status:b.status}}},c=l.useCallback(async(h=!1)=>{n(f=>({...f,isChecking:!0,error:null}));try{const[f,g]=await Promise.all([d(Fs),d(Os)]);if(f.status!==200)throw new Error(`GitHub API error: ${f.status}`);const v=f.data,b=v.tag_name;let p=[];g.status===200&&g.data&&(p=g.data.map(T=>({version:T.tag_name,name:T.name,publishedAt:T.published_at,releaseUrl:T.html_url})));const L=localStorage.getItem(Je);if(!h&&L===b)return n(T=>({...T,isChecking:!1,updateAvailable:!1,recentReleases:p})),null;if(!(r(b,Ze)>0))return n(T=>({...T,isChecking:!1,updateAvailable:!1,recentReleases:p})),null;const R=v.assets.find(T=>T.name.endsWith(".apk")&&T.content_type==="application/vnd.android.package-archive"),k={version:b,name:v.name,changelog:v.body,releaseUrl:v.html_url,apkUrl:(R==null?void 0:R.browser_download_url)||null,apkSize:(R==null?void 0:R.size)||null,publishedAt:v.published_at};return n(T=>({...T,isChecking:!1,updateAvailable:!0,updateInfo:k,recentReleases:p})),k}catch(f){const g=f instanceof Error?f.message:"Failed to check for updates";return n(v=>({...v,isChecking:!1,error:g})),null}},[]),i=l.useCallback(async()=>{var h,f,g;if(!((h=s.updateInfo)!=null&&h.apkUrl)){(f=s.updateInfo)!=null&&f.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!a){(g=s.updateInfo)!=null&&g.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),n(v=>({...v,error:null}))}catch(v){const b=v instanceof Error?v.message:"Failed to open download";n(p=>({...p,error:b}))}},[s.updateInfo,a]),u=l.useCallback(()=>{s.updateInfo&&localStorage.setItem(Je,s.updateInfo.version),n(h=>({...h,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),S=l.useCallback(()=>{var h;(h=s.updateInfo)!=null&&h.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${Ke}/releases`,"_blank")},[s.updateInfo]);return l.useEffect(()=>{if(!a)return;const h=setTimeout(()=>{c()},5e3),f=setInterval(()=>{c()},Rs);return()=>{clearTimeout(h),clearInterval(f)}},[a,c]),{...s,isAndroid:a,checkForUpdate:c,downloadAndInstall:i,dismissUpdate:u,openReleasePage:S}}const os="tide-toolbox-collapse";function Us(s,n){try{const a=localStorage.getItem(`${os}-${s}`);if(a!==null)return a==="true"}catch{}return n}function Bs(s,n){try{localStorage.setItem(`${os}-${s}`,String(n))}catch{}}function W({title:s,storageKey:n,defaultOpen:a=!1,forceOpen:o=!1,children:r,headerExtra:d}){const[c,i]=l.useState(()=>n?Us(n,a):a),u=()=>{const x=!c;i(x),n&&Bs(n,x)},S=o||c;return e.jsxs("div",{className:`collapsible-section ${S?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:u,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[d,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(I,{name:S?"caret-down":"caret-right",size:10})})]})]}),S&&e.jsx("div",{className:"collapsible-content",children:r})]})}function Ms({area:s,isSelected:n,onClick:a,onDelete:o}){const{t:r}=Y(["config","common"]),d=s.assignedAgentIds.length,c=s.type==="rectangle"?r("config:areas.rect"):r("config:areas.circle");return e.jsxs("div",{className:`area-item ${n?"selected":""}`,onClick:a,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," ",d>0&&`• ${d} ${d>1?r("common:labels.agents").toLowerCase():r("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:r("config:areas.deleteArea"),children:"×"})]})}function Vs({building:s,isSelected:n,onClick:a,onEdit:o}){var i;const{t:r}=Y(["config"]),d=((i=s.pm2Status)==null?void 0:i.ports)||[],c=(u,S)=>{u.stopPropagation(),window.open(`http://${window.location.hostname}:${S}`,"_blank")};return e.jsxs("div",{className:`building-item ${n?"selected":""}`,onClick:a,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:ts[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(I,{name:ns(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,d.length>0&&e.jsx("span",{className:"building-ports",children:d.map(u=>e.jsxs("a",{href:`http://${window.location.hostname}:${u}`,className:"building-port-link",onClick:S=>c(S,u),title:`Open :${u}`,children:[":",u]},u))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:u=>{u.stopPropagation(),o()},title:r("config:buildings.editBuilding"),children:e.jsx(I,{name:"gear",size:14})})]})}function Ks({building:s,onClose:n,onOpenModal:a}){var S,x,y,h,f,g,v,b;const{t:o}=Y(["config","common"]),{buildingLogs:r}=Ve(),d=_.getBuildingLogs(s.id),c=hs[s.style||"server-rack"],i=p=>{_.sendBuildingCommand(s.id,p)},u=p=>{window.open(p,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx(I,{name:ns(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:ts[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:n,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children: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:()=>i("start"),disabled:!((S=s.commands)!=null&&S.start)||s.status==="running",title:((x=s.commands)==null?void 0:x.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:()=>i("stop"),disabled:!((y=s.commands)!=null&&y.stop)||s.status==="stopped",title:((h=s.commands)==null?void 0:h.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:()=>i("restart"),disabled:!((f=s.commands)!=null&&f.restart),title:((g=s.commands)==null?void 0:g.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:()=>i("healthCheck"),disabled:!((v=s.commands)!=null&&v.healthCheck),title:((b=s.commands)==null?void 0:b.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((p,L)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>u(p.url),title:p.url,children:[e.jsx(I,{name:"link",size:12})," ",p.label||p.url]},L))})]}),d.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:()=>_.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:d.slice(-5).map((p,L)=>e.jsx("div",{className:"building-editor-log-entry",children:p},L))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:a,children:[e.jsx(I,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}async function Hs(s,n){const a=Z(),o=await fetch(me(`/api/areas/${s}/logo`),{method:"POST",headers:{"Content-Type":n.type||"image/png","X-Filename":encodeURIComponent(n.name),...a?{Authorization:`Bearer ${a}`}:{}},body:n});if(!o.ok){const r=await o.json().catch(()=>({error:o.statusText}));throw new Error(r.error||`Upload failed: ${o.statusText}`)}return o.json()}async function Ws(s){const n=Z(),a=await fetch(me(`/api/areas/${s}/logo`),{method:"DELETE",headers:{...n?{Authorization:`Bearer ${n}`}:{}}});if(!a.ok)throw new Error(`Failed to delete logo: ${a.statusText}`)}function qs(s){return us(me(`/api/areas/logos/${s}`))}const Gs=[{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 Ys({area:s,onClose:n,onOpenFolder:a}){var ce;const{t:o}=Y(["config","common"]),[r,d]=l.useState(s.name),[c,i]=l.useState(s.prompt||""),[u,S]=l.useState(!1),[x,y]=l.useState(""),[h,f]=l.useState(!1),g=l.useRef(null);l.useEffect(()=>{d(s.name)},[s.id,s.name]),l.useEffect(()=>{i(s.prompt||"")},[s.id,s.prompt]);const v=N=>{const D=N.target.value;d(D),_.updateArea(s.id,{name:D})},b=N=>{_.updateArea(s.id,{color:N})},p=N=>{const D=N.target.value;i(D),_.updateArea(s.id,{prompt:D})},L=()=>{x.trim()&&(_.addDirectoryToArea(s.id,x.trim()),y(""),S(!1))},M=(N,D)=>{D.stopPropagation(),_.removeDirectoryFromArea(s.id,N)},R=()=>{_.bringAreaToFront(s.id)},k=()=>{_.sendAreaToBack(s.id)},T=l.useCallback(()=>{let N=2,D=2;s.type==="rectangle"&&s.width&&s.height?(N=s.width,D=s.height):s.type==="circle"&&s.radius&&(N=s.radius*1.414,D=s.radius*1.414);const B=Math.min(N,D)*.4;return{width:Math.round(B*10)/10,height:Math.round(B*10)/10}},[s.type,s.width,s.height,s.radius]),V=async N=>{var B;const D=(B=N.target.files)==null?void 0:B[0];if(D){f(!0);try{const j=await Hs(s.id,D),$=T();_.updateArea(s.id,{logo:{filename:j.filename,position:"center",width:$.width,height:$.height,keepAspectRatio:!0,opacity:.8}})}catch(j){console.error("Failed to upload logo:",j)}finally{f(!1),g.current&&(g.current.value="")}}},U=async()=>{try{await Ws(s.id),_.updateArea(s.id,{logo:void 0})}catch(N){console.error("Failed to remove logo:",N)}},K=N=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,position:N}})},w=N=>{if(!s.logo)return;const D=parseFloat(N.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const B=s.logo.height/s.logo.width;_.updateArea(s.id,{logo:{...s.logo,width:D,height:Math.round(D*B*10)/10}})}else _.updateArea(s.id,{logo:{...s.logo,width:D}})},C=N=>{if(!s.logo)return;const D=parseFloat(N.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const B=s.logo.width/s.logo.height;_.updateArea(s.id,{logo:{...s.logo,height:D,width:Math.round(D*B*10)/10}})}else _.updateArea(s.id,{logo:{...s.logo,height:D}})},H=()=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},J=N=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(N.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:o("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:n,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:r,onChange:v,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:ms.map(N=>e.jsx("div",{className:`color-swatch ${s.color===N?"selected":""}`,style:{backgroundColor:N},onClick:()=>b(N)},N))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:R,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:k,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:[(ce=s.logo)!=null&&ce.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:U,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var N;return(N=g.current)==null?void 0:N.click()},disabled:h,children:h?"...":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:Gs.map(({key:N,labelKey:D})=>{var B;return e.jsx("button",{className:`area-logo-pos-btn ${((B=s.logo)==null?void 0:B.position)===N?"active":""}`,onClick:()=>K(N),children:o(`config:areas.${D}`)},N)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:w,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:C,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:H}),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:J,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var N;return(N=g.current)==null?void 0:N.click()},disabled:h,children:h?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:g,type:"file",accept:"image/*",style:{display:"none"},onChange:V})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(N=>e.jsxs("div",{className:"area-folder-item",title:N,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>a==null?void 0:a(s.id),title:o("config:areas.openFolder"),children:e.jsx(I,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:N.split("/").pop()||N}),e.jsx("button",{className:"area-folder-remove",onClick:D=>M(N,D),title:o("config:areas.removeFolder"),children:"×"})]},N)),u?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(gs,{value:x,onChange:y,onSubmit:L,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:L,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>S(!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:p,placeholder:o("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:o("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:o("config:areas.rightClickUnassign")})]})]})}function Js(){const{t:s}=Y(["config","common"]),n=fs(),[a,o]=l.useState(!1),[r,d]=l.useState(null),[c,i]=l.useState({name:"",key:"",value:"",description:""}),[u,S]=l.useState(null),x=()=>{o(!0),d(null),i({name:"",key:"",value:"",description:""})},y=p=>{d(p.id),o(!1),i({name:p.name,key:p.key,value:p.value,description:p.description||""})},h=()=>{o(!1),d(null),i({name:"",key:"",value:"",description:""})},f=()=>{!c.name.trim()||!c.key.trim()||(r?_.updateSecret(r,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):_.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),h())},g=p=>{S(p)},v=()=>{u&&(_.deleteSecret(u),r===u&&h())},b=p=>{navigator.clipboard.writeText(`{{${p}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children:n.length===0&&!a?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):n.map(p=>e.jsxs("div",{className:`secret-item ${r===p.id?"editing":""}`,children:[e.jsxs("div",{className:"secret-item-header",children:[e.jsxs("div",{className:"secret-item-info",children:[e.jsx("span",{className:"secret-item-name",children:p.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>b(p.key),title:s("config:secrets.copyPlaceholder"),children:`{{${p.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>y(p),title:s("common:buttons.edit"),children:e.jsx(I,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>g(p.id),title:s("common:buttons.delete"),children:"×"})]})]}),p.description&&e.jsx("div",{className:"secret-item-description",children:p.description})]},p.id))}),(a||r)&&e.jsxs("div",{className:"secret-form",children:[e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.name")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.namePlaceholder"),value:c.name,onChange:p=>i({...c,name:p.target.value}),autoFocus:!0})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:"Key"}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.keyPlaceholder"),value:c.key,onChange:p=>i({...c,key:p.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${c.key||"KEY"}}}`})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("config:secrets.secretValue")}),e.jsx("input",{type:"password",className:"secret-form-input",placeholder:s("config:secrets.valuePlaceholder"),value:c.value,onChange:p=>i({...c,value:p.target.value})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.description")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.descriptionPlaceholder"),value:c.description,onChange:p=>i({...c,description:p.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:h,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:f,disabled:!c.name.trim()||!c.key.trim(),children:s(r?"config:secrets.update":"common:buttons.add")})]})]}),!a&&!r&&e.jsx("button",{className:"secrets-add-btn",onClick:x,children:s("config:secrets.addSecret")}),e.jsx(ge,{isOpen:u!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:v,onClose:()=>S(null)})]})}async function Zs(){const s=Z(),n=await fetch(`${X()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch system prompt: ${n.statusText}`);return(await n.json()).prompt||""}async function Xs(s){const n=Z(),a=await fetch(`${X()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({prompt:s})});if(!a.ok)throw new Error(`Failed to update system prompt: ${a.statusText}`)}async function Qs(){const s=Z(),n=await fetch(`${X()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to clear system prompt: ${n.statusText}`)}async function ea(){const s=Z(),n=await fetch(`${X()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch echo prompt setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function sa(s){const n=Z(),a=await fetch(`${X()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!a.ok)throw new Error(`Failed to update echo prompt setting: ${a.statusText}`)}async function aa(){const s=Z(),n=await fetch(`${X()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex binary path: ${n.statusText}`);return(await n.json()).path||""}async function ta(s){const n=Z(),a=await fetch(`${X()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({path:s})});if(!a.ok)throw new Error(`Failed to update codex binary path: ${a.statusText}`)}async function na(){const s=Z(),n=await fetch(`${X()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch tmux mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ia(s){const n=Z(),a=await fetch(`${X()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!a.ok)throw new Error(`Failed to update tmux mode setting: ${a.statusText}`)}async function oa(){const s=Z(),n=await fetch(`${X()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch backup status: ${n.statusText}`);return n.json()}async function la(s){const n=Z(),a=await fetch(`${X()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!a.ok){const o=await a.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${a.statusText}`)}return a.json()}function ca({checked:s,onChange:n,disabled:a}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:a,onChange:o=>n(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function ra(){const{t:s}=Y(["config","common"]),[n,a]=l.useState([]),[o,r]=l.useState(new Set),[d,c]=l.useState(new Set),[i,u]=l.useState(!1),[S,x]=l.useState(!1),[y,h]=l.useState(null),[f,g]=l.useState(null),[v,b]=l.useState(null),[p,L]=l.useState(null),[M,R]=l.useState(!1),[k,T]=l.useState(null);l.useEffect(()=>{ke(me("/api/config/categories")).then(j=>j.json()).then(j=>{const $=Array.isArray(j)?j:[];a($),r(new Set($.map(F=>F.id)))}).catch(j=>console.error("Failed to fetch config categories:",j))},[]),l.useEffect(()=>{oa().then(L).catch(j=>{console.error("Failed to fetch backup status:",j),T(j.message||"Failed to fetch backup status")})},[]);const V=async j=>{if(!M){R(!0),T(null);try{const $=await la(j);L($)}catch($){T($.message||"Failed to update backup setting")}finally{R(!1)}}},U=j=>{r($=>{const F=new Set($);return F.has(j)?F.delete(j):F.add(j),F})},K=j=>{c($=>{const F=new Set($);return F.has(j)?F.delete(j):F.add(j),F})},w=()=>r(new Set(n.map(j=>j.id))),C=()=>r(new Set),H=()=>{f&&c(new Set(f.categories.map(j=>j.id)))},J=()=>c(new Set),ce=async()=>{var j;if(o.size!==0){u(!0),b(null);try{const $=Array.from(o).join(","),F=await ke(me(`/api/config/export?categories=${$}`));if(!F.ok)throw new Error("Export failed");const Q=await F.blob(),ae=window.URL.createObjectURL(Q),ee=document.createElement("a");ee.href=ae;const A=F.headers.get("Content-Disposition"),q=((j=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:j[1])||"tide-commander-config.zip";ee.download=q,document.body.appendChild(ee),ee.click(),document.body.removeChild(ee),window.URL.revokeObjectURL(ae),b({type:"success",text:s("config:data.exportSuccess")})}catch($){b({type:"error",text:$.message||"Export failed"})}finally{u(!1)}}},N=async j=>{var F;const $=(F=j.target.files)==null?void 0:F[0];if($){h($),b(null),g(null),c(new Set);try{const Q=await ke(me("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await $.arrayBuffer()});if(!Q.ok){const A=await Q.json();throw new Error(A.error||"Failed to preview config file")}const ae=await Q.json(),ee=Array.isArray(ae.categories)?ae.categories:[];g({...ae,categories:ee}),c(new Set(ee.map(A=>A.id)))}catch(Q){b({type:"error",text:Q.message||"Failed to read config file"}),h(null)}}},D=async()=>{if(!(!y||d.size===0)){x(!0),b(null);try{const j=Array.from(d).join(","),$=await ke(me(`/api/config/import?categories=${j}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await y.arrayBuffer()}),F=await $.json();if(!$.ok)throw new Error(F.error||"Import failed");b({type:"success",text:F.message||s("config:data.importSuccess")}),h(null),g(null),c(new Set)}catch(j){b({type:"error",text:j.message||"Import failed"})}finally{x(!1)}}},B=()=>{h(null),g(null),c(new Set),b(null)};return e.jsxs("div",{className:"data-section",children:[v&&e.jsx("div",{className:`data-message data-message-${v.type}`,children:v.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(ca,{checked:!!(p!=null&&p.enabled),disabled:M||!p,onChange:V})]}),e.jsxs("div",{className:"data-backup-info",children:[p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:p.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!p.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:p.scriptPath})]}),p.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(p.lastRunAt).toLocaleString(),p.lastRunOk===!0&&" — ok",p.lastRunOk===!1&&p.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",p.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),k&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:k})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:w,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:C,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:n.map(j=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(j.id),onChange:()=>U(j.id)}),e.jsx("span",{className:"data-category-name",children:j.name})]},j.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ce,disabled:i||o.size===0,children:i?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")})}),y?f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:y.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(f.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:H,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:J,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:f.categories.map(j=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:d.has(j.id),onChange:()=>K(j.id)}),e.jsx("span",{className:"data-category-name",children:j.name}),j.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",j.fileCount," ",s("config:data.files"),")"]})]},j.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:B,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:D,disabled:S||d.size===0,children:S?s("config:data.importing"):s("config:data.importCount",{count:d.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:N,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function da(){const[s,n]=l.useState(()=>xs()),a=o=>{n(o);const r=js(o);ws(r)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:bs.map(o=>e.jsxs("button",{className:`theme-option ${s===o.id?"active":""}`,onClick:()=>a(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 pa(){const{t:s}=Y(["config"]),{updateAvailable:n,updateInfo:a,recentReleases:o,isChecking:r,error:d,currentVersion:c,isAndroid:i,checkForUpdate:u,downloadAndInstall:S,openReleasePage:x}=zs(),y=f=>f?`${(f/(1024*1024)).toFixed(1)} MB`:"",h=f=>new Date(f).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}),n&&a?e.jsx("span",{className:"about-version-update-badge",onClick:x,title:`Update available: ${a.version}`,children:a.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.jsxs("div",{className:"about-update",children:[n&&a?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:a.version})]}),a.apkSize&&e.jsxs("div",{className:"about-update-size",children:[s("config:about.sizeLabel"),": ",y(a.apkSize)]}),d&&e.jsx("div",{className:"about-update-error",children:d}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:x,children:s("config:about.changelog")}),i&&a.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:S,children:s("config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:x,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(r?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>u(!0),disabled:r,children:r?"...":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(f=>e.jsxs("a",{href:f.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${f.version===`v${c}`||f.version===c?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:f.version}),e.jsx("span",{className:"about-release-date",children:h(f.publishedAt)})]},f.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")})]})]})]})}const ha={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function ua({onOpenModal:s}){const[n,a]=l.useState([]),[o,r]=l.useState(!0),d=l.useCallback(async()=>{try{const c=await ke(me("/api/integrations"));if(!c.ok)return;const i=await c.json();a(i)}catch{}finally{r(!1)}},[]);return l.useEffect(()=>{d()},[d]),o?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):n.length===0?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"No integrations available."}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[n.map(c=>{const i=ha[c.id]||"🔌",u=!!c.status.error,S=c.status.connected,x=u?"#f38ba8":S?"#a6e3a1":"#fab387",y=u?"Error":S?"Connected":"Setup Required",h=u?"✗":S?"✓":"⚠";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:i}),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:x,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:y,children:h}),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:f=>{f.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:f=>{f.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"})]})}function ma({isOpen:s,onClose:n}){const{t:a}=Y(["config"]),[o,r]=l.useState(""),[d,c]=l.useState(""),[i,u]=l.useState(!0),[S,x]=l.useState(null),[y,h]=l.useState(null),[f,g]=l.useState(!1),[v,b]=l.useState(!1),[p,L]=l.useState(!1);l.useEffect(()=>{s&&M()},[s]);const M=async()=>{try{u(!0),x(null),h(null);const C=await Zs();r(C),c(C),g(!1)}catch(C){x(C instanceof Error?C.message:"Failed to load system prompt")}finally{u(!1)}},R=C=>{const H=C.target.value;r(H),g(H!==d),x(null),h(null)},k=async()=>{try{x(null),h(null),await Xs(o),c(o),g(!1),h(a("config:systemPrompt.saved"))}catch(C){x(C instanceof Error?C.message:"Failed to save system prompt")}},T=()=>{b(!0)},V=async()=>{try{x(null),h(null),await Qs(),r(""),c(""),g(!1),h(a("config:systemPrompt.cleared"))}catch(C){x(C instanceof Error?C.message:"Failed to clear system prompt")}},U=()=>{r(d),g(!1),x(null),h(null)},K=()=>{if(f){L(!0);return}n()},w=C=>{C.key==="Escape"&&(C.preventDefault(),K())};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:K,children:e.jsxs("div",{className:"system-prompt-modal",onClick:C=>C.stopPropagation(),onKeyDown:w,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:a("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:K,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:i?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:"Loading system prompt..."})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:a("config:systemPrompt.description")}),S&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),S]}),y&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),y]}),e.jsxs("div",{className:"editor-wrapper",children:[e.jsxs("div",{className:"editor-header",children:[e.jsx("label",{htmlFor:"prompt-input",className:"editor-label",children:a("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[o.length," ",a("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:o,onChange:R,placeholder:a("config:systemPrompt.placeholder"),rows:18,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:a("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:T,disabled:!o||i,children:a("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:K,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:U,disabled:!f||i,children:a("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:k,disabled:!f||i,children:a("config:systemPrompt.save")})]})]})]})}),e.jsx(ge,{isOpen:v,title:a("config:systemPrompt.clear"),message:a("config:systemPrompt.confirmClear"),confirmLabel:a("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{V()},onClose:()=>b(!1)}),e.jsx(ge,{isOpen:p,title:"Unsaved Changes",message:"You have unsaved changes. Close anyway?",confirmLabel:"Close anyway",cancelLabel:"Keep editing",variant:"danger",onConfirm:n,onClose:()=>L(!1)})]}):null}const Xe={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},ga=2500,fa=12e4;function Qe(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function xa(s,n){return s.enabled===n.enabled&&s.baseUrl===n.baseUrl&&s.defaultSessionId===n.defaultSessionId&&s.webhookVerifyToken===n.webhookVerifyToken&&s.showIncomingToasts===n.showIncomingToasts}function ba({isOpen:s,onClose:n}){const{t:a}=Y(["config"]),[o,r]=l.useState(Xe),[d,c]=l.useState(Xe),[i,u]=l.useState(!1),[S,x]=l.useState([]),[y,h]=l.useState(!0),[f,g]=l.useState(null),[v,b]=l.useState(null),[p,L]=l.useState(""),[M,R]=l.useState(!1),[k,T]=l.useState(""),[V,U]=l.useState(null),[K,w]=l.useState(null),[C,H]=l.useState(null),J=l.useRef(null),ce=l.useRef(0),[N,D]=l.useState(""),[B,j]=l.useState(""),[$,F]=l.useState(null),[Q,ae]=l.useState(!1),[ee,A]=l.useState(!1),[q,ne]=l.useState(!1),[re,te]=l.useState(!1),[he,we]=l.useState(null),ye=!xa(o,d),ie=l.useCallback(()=>{J.current&&(clearTimeout(J.current),J.current=null)},[]),P=l.useCallback(async()=>{try{h(!0),g(null),b(null);const[m,z]=await Promise.all([is(),ys()]),oe=Qe(m);if(r(oe),c(oe),u(!!z.configured),z.configured)try{const fe=await Me();x(Array.isArray(fe)?fe:[])}catch{x([])}else x([])}catch(m){g(m instanceof Error?m.message:a("config:whatsapp.errors.loadFailed"))}finally{h(!1)}},[a]),ue=l.useCallback(async()=>{try{const m=await Me();x(Array.isArray(m)?m:[])}catch{}},[]);l.useEffect(()=>(s?P():(ie(),U(null),w(null),H(null),L(""),R(!1),F(null)),()=>{ie()}),[s,P,ie]);const se=(m,z)=>{r(oe=>({...oe,[m]:z})),g(null),b(null)},$e=async()=>{try{g(null),b(null);const m=await Cs({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 z=Qe(m);r(z),c(z),b(a("config:whatsapp.saved"))}catch(m){g(m instanceof Error?m.message:a("config:whatsapp.errors.saveFailed"))}},Ce=()=>{r(d),g(null),b(null)},be=()=>{if(ye){A(!0);return}n()},De=m=>{m.key==="Escape"&&(m.preventDefault(),be())},Ae=async()=>{const m=p.trim();if(m)try{g(null),b(null),await Ns(m),L(""),R(!1),u(!0),b(a("config:whatsapp.apiKeySaved"))}catch(z){g(z instanceof Error?z.message:a("config:whatsapp.errors.apiKeySaveFailed"))}},Fe=()=>{ne(!0)},Te=async()=>{try{g(null),b(null),await As(),u(!1),b(a("config:whatsapp.apiKeyCleared"))}catch(m){g(m instanceof Error?m.message:a("config:whatsapp.errors.apiKeyClearFailed"))}},_e=l.useCallback(async m=>{if(Date.now()>ce.current){H(a("config:whatsapp.pairingTimeout")),U(null),w(null),ie(),ue();return}try{const z=await vs(m);if(z.status&&["connected","paired","open","ready"].includes(z.status.toLowerCase())){H(a("config:whatsapp.pairingSuccess")),U(null),w(null),ie(),ue();return}const fe=z.qrUrl??z.qr??null;fe&&w(fe)}catch(z){H(z instanceof Error?z.message:a("config:whatsapp.errors.qrFetchFailed"))}J.current=setTimeout(()=>{_e(m)},ga)},[ue,ie,a]),Ee=async()=>{const m=k.trim();if(m)try{g(null),b(null),H(null),w(null),ie(),await ks(m),T(""),U(m),ce.current=Date.now()+fa,_e(m),ue()}catch(z){g(z instanceof Error?z.message:a("config:whatsapp.errors.sessionCreateFailed"))}},ve=()=>{ie(),U(null),w(null),H(null)},Oe=m=>{we(m),te(!0)},Ie=async()=>{if(he)try{g(null),b(null),await Ts(he),V===he&&ve(),ue(),b(a("config:whatsapp.sessionDeleted"))}catch(m){g(m instanceof Error?m.message:a("config:whatsapp.errors.sessionDeleteFailed"))}finally{we(null)}},pe=async()=>{const m=N.trim(),z=B.trim();if(!(!m||!z))try{ae(!0),F(null);const oe=o.defaultSessionId.trim()||void 0;await Ss(m,z,oe),F({kind:"success",text:a("config:whatsapp.testSent")})}catch(oe){F({kind:"error",text:oe instanceof Error?oe.message:a("config:whatsapp.errors.testSendFailed")})}finally{ae(!1)}};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:be,children:e.jsxs("div",{className:"whatsapp-config-modal",onClick:m=>m.stopPropagation(),onKeyDown:De,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:a("config:whatsapp.title")}),e.jsx("button",{className:"modal-close",onClick:be,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:y?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:a("config:whatsapp.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:a("config:whatsapp.description")}),f&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),f]}),v&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),v]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:a("config:whatsapp.sections.general")}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-enabled",className:"wa-label",children:a("config:whatsapp.enabled")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-enabled",type:"checkbox",checked:o.enabled,onChange:m=>se("enabled",m.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:a("config:whatsapp.showIncomingToasts")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-show-toasts",type:"checkbox",checked:o.showIncomingToasts,onChange:m=>se("showIncomingToasts",m.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsx("span",{className:"wa-hint",children:a("config:whatsapp.showIncomingToastsHelp")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-base-url",className:"wa-label",children:a("config:whatsapp.baseUrl")}),e.jsx("input",{id:"wa-base-url",type:"text",className:"wa-input",placeholder:"http://localhost:3007",value:o.baseUrl,onChange:m=>se("baseUrl",m.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-default-session",className:"wa-label",children:a("config:whatsapp.defaultSessionId")}),e.jsx("input",{id:"wa-default-session",type:"text",className:"wa-input",placeholder:a("config:whatsapp.defaultSessionIdPlaceholder"),value:o.defaultSessionId,onChange:m=>se("defaultSessionId",m.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-webhook-token",className:"wa-label",children:a("config:whatsapp.webhookVerifyToken")}),e.jsx("input",{id:"wa-webhook-token",type:"text",className:"wa-input",placeholder:a("config:whatsapp.webhookVerifyTokenPlaceholder"),value:o.webhookVerifyToken,onChange:m=>se("webhookVerifyToken",m.target.value)})]})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:a("config:whatsapp.sections.apiKey")}),e.jsx("div",{className:"wa-key-status",children:i?e.jsxs("span",{className:"wa-status wa-status-ok",children:[e.jsx(I,{name:"check",size:12})," ",a("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(I,{name:"warn",size:12})," ",a("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:M?"text":"password",className:"wa-input",placeholder:a("config:whatsapp.apiKeyPlaceholder"),value:p,onChange:m=>L(m.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>R(m=>!m),title:a(M?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(I,{name:M?"eye-closed":"eye",size:14})}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ae,disabled:!p.trim(),children:a("config:whatsapp.saveKey")}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:Fe,disabled:!i,children:a("config:whatsapp.clearKey")})]}),e.jsx("span",{className:"wa-hint",children:a("config:whatsapp.apiKeyHint")})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:a("config:whatsapp.sections.sessions")}),e.jsx("div",{className:"wa-sessions-list",children:!Array.isArray(S)||S.length===0?e.jsx("div",{className:"wa-empty",children:a("config:whatsapp.noSessions")}):S.map(m=>e.jsxs("div",{className:"wa-session-row",children:[e.jsxs("div",{className:"wa-session-info",children:[e.jsx("span",{className:"wa-session-id",children:m.id}),e.jsx("span",{className:`wa-session-status status-${(m.status??"unknown").toLowerCase()}`,children:m.status||"—"}),m.pairedNumber&&e.jsx("span",{className:"wa-session-paired",children:m.pairedNumber})]}),e.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:()=>Oe(m.id),children:a("config:whatsapp.deleteSession")})]},m.id))}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:"text",className:"wa-input",placeholder:a("config:whatsapp.addSessionPlaceholder"),value:k,onChange:m=>T(m.target.value),onKeyDown:m=>{m.key==="Enter"&&Ee()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ee,disabled:!k.trim()||V!==null,children:a("config:whatsapp.addSession")})]}),V&&e.jsxs("div",{className:"wa-qr-panel",children:[e.jsxs("div",{className:"wa-qr-header",children:[e.jsx("span",{children:a("config:whatsapp.qrPrompt",{id:V})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:ve,children:a("config:whatsapp.cancelPairing")})]}),K?e.jsx("div",{className:"wa-qr-image",children:e.jsx("img",{src:K,alt:"WhatsApp pairing QR code"})}):e.jsxs("div",{className:"wa-qr-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:a("config:whatsapp.waitingForQr")})]})]}),C&&!V&&e.jsx("div",{className:"wa-pairing-message",children:C})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:a("config:whatsapp.sections.testMessage")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-to",className:"wa-label",children:a("config:whatsapp.testTo")}),e.jsx("input",{id:"wa-test-to",type:"text",className:"wa-input",placeholder:a("config:whatsapp.testToPlaceholder"),value:N,onChange:m=>D(m.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-message",className:"wa-label",children:a("config:whatsapp.testMessageBody")}),e.jsx("textarea",{id:"wa-test-message",className:"wa-textarea",rows:4,placeholder:a("config:whatsapp.testMessageBodyPlaceholder"),value:B,onChange:m=>j(m.target.value)})]}),e.jsx("div",{className:"wa-field-inline wa-field-end",children:e.jsx("button",{type:"button",className:"btn btn-primary",onClick:pe,disabled:!N.trim()||!B.trim()||Q,children:a(Q?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),$&&e.jsxs("div",{className:`alert ${$.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:$.kind==="success"?"check":"warn",size:14})}),$.text]})]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left"}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:be,children:a("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:Ce,disabled:!ye||y,children:a("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:$e,disabled:!ye||y,children:a("config:whatsapp.save")})]})]})]})}),e.jsx(ge,{isOpen:ee,title:a("config:whatsapp.unsavedTitle"),message:a("config:whatsapp.unsavedMessage"),confirmLabel:a("config:whatsapp.closeAnyway"),cancelLabel:a("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{A(!1),n()},onClose:()=>A(!1)}),e.jsx(ge,{isOpen:q,title:a("config:whatsapp.clearKey"),message:a("config:whatsapp.confirmClearKey"),confirmLabel:a("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Te()},onClose:()=>ne(!1)}),e.jsx(ge,{isOpen:re,title:a("config:whatsapp.deleteSession"),message:a("config:whatsapp.confirmDeleteSession",{id:he??""}),confirmLabel:a("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Ie()},onClose:()=>{te(!1),we(null)}})]}):null}const ls=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function He(s=!1){const n=Z(),a={};return n&&(a.Authorization=`Bearer ${n}`),s&&(a["Content-Type"]="application/json"),a}async function We(s,n){try{const a=await s.json();if(a&&typeof a.error=="string")return a.error;if(a&&typeof a.message=="string")return a.message}catch{}return`${n}: ${s.statusText}`}async function ja(){const s=await fetch(`${X()}/api/whatsapp/notification-config`,{headers:He()});if(!s.ok)throw new Error(await We(s,"Failed to fetch WhatsApp notification config"));return s.json()}async function wa(s){const n=await fetch(`${X()}/api/whatsapp/notification-config`,{method:"PATCH",headers:He(!0),body:JSON.stringify(s)});if(!n.ok)throw new Error(await We(n,"Failed to update WhatsApp notification config"));return n.json()}async function ya(){const s=await fetch(`${X()}/api/whatsapp/notification-config`,{method:"DELETE",headers:He()});if(!s.ok)throw new Error(await We(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},es={filter:{...Le},recipient:""};function va(s,n){if(s.recipient!==n.recipient)return!1;for(const a of ls)if(s.filter[a]!==n.filter[a])return!1;return!0}function Na({isOpen:s,onClose:n}){const{t:a}=Y(["config"]),[o,r]=l.useState(es),[d,c]=l.useState(es),[i,u]=l.useState(!0),[S,x]=l.useState(null),[y,h]=l.useState(null),[f,g]=l.useState(!1),[v,b]=l.useState(!1),p=!va(o,d),L=l.useCallback(async()=>{try{u(!0),x(null),h(null);const w=await ja(),C={filter:{...Le,...w.filter},recipient:w.recipient??""};r(C),c(C)}catch(w){x(w instanceof Error?w.message:a("config:whatsappNotifications.errors.loadFailed"))}finally{u(!1)}},[a]);l.useEffect(()=>{s&&L()},[s,L]);const M=(w,C)=>{r(H=>({...H,filter:{...H.filter,[w]:C}})),x(null),h(null)},R=w=>{r(C=>({...C,recipient:w})),x(null),h(null)},k=async()=>{try{x(null),h(null);const w=await wa({filter:o.filter,recipient:o.recipient.trim()}),C={filter:{...Le,...w.filter},recipient:w.recipient??""};r(C),c(C),h(a("config:whatsappNotifications.saved"))}catch(w){x(w instanceof Error?w.message:a("config:whatsappNotifications.errors.saveFailed"))}},T=()=>{r(d),x(null),h(null)},V=async()=>{try{x(null),h(null);const w=await ya(),C={filter:{...Le,...w.filter},recipient:w.recipient??""};r(C),c(C),h(a("config:whatsappNotifications.resetDone"))}catch(w){x(w instanceof Error?w.message:a("config:whatsappNotifications.errors.resetFailed"))}},U=()=>{if(p){g(!0);return}n()},K=w=>{w.key==="Escape"&&(w.preventDefault(),U())};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:U,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:w=>w.stopPropagation(),onKeyDown:K,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:a("config:whatsappNotifications.title")}),e.jsx("button",{className:"modal-close",onClick:U,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:i?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:a("config:whatsappNotifications.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:a("config:whatsappNotifications.description")}),S&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),S]}),y&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),y]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:a("config:whatsappNotifications.sections.recipient")}),e.jsxs("div",{className:"wan-field",children:[e.jsx("label",{htmlFor:"wan-recipient",className:"wan-label",children:a("config:whatsappNotifications.recipientLabel")}),e.jsx("input",{id:"wan-recipient",type:"text",className:"wan-input",placeholder:a("config:whatsappNotifications.recipientPlaceholder"),value:o.recipient,onChange:w=>R(w.target.value)}),e.jsx("span",{className:"wan-hint",children:a("config:whatsappNotifications.recipientHint")})]})]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:a("config:whatsappNotifications.sections.events")}),e.jsx("p",{className:"wan-section-hint",children:a("config:whatsappNotifications.eventsHint")}),ls.map(w=>e.jsxs("div",{className:"wan-toggle-row",children:[e.jsxs("div",{className:"wan-toggle-info",children:[e.jsx("span",{className:"wan-toggle-title",children:a(`config:whatsappNotifications.events.${w}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:a(`config:whatsappNotifications.events.${w}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:o.filter[w],onChange:C=>M(w,C.target.checked)}),e.jsx("span",{className:"wan-toggle-track",children:e.jsx("span",{className:"wan-toggle-thumb"})})]})]},w))]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:()=>b(!0),disabled:i,children:a("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:U,children:a("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:T,disabled:!p||i,children:a("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:k,disabled:!p||i,children:a("config:whatsappNotifications.save")})]})]})]})}),e.jsx(ge,{isOpen:f,title:a("config:whatsappNotifications.unsavedTitle"),message:a("config:whatsappNotifications.unsavedMessage"),confirmLabel:a("config:whatsappNotifications.closeAnyway"),cancelLabel:a("config:whatsappNotifications.keepEditing"),variant:"danger",onConfirm:()=>{g(!1),n()},onClose:()=>g(!1)}),e.jsx(ge,{isOpen:v,title:a("config:whatsappNotifications.resetToDefaults"),message:a("config:whatsappNotifications.confirmReset"),confirmLabel:a("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{V(),b(!1)},onClose:()=>b(!1)})]}):null}function cs(s){const n=s.replace(/@.*$/,"");return/^\d{10,15}$/.test(n)?n.startsWith("521")&&n.length===13?`+52 1 ${n.slice(3,5)} ${n.slice(5,9)} ${n.slice(9)}`:n.startsWith("52")&&n.length===12?`+52 ${n.slice(2,4)} ${n.slice(4,8)} ${n.slice(8)}`:n.startsWith("1")&&n.length===11?`+1 ${n.slice(1,4)} ${n.slice(4,7)} ${n.slice(7)}`:`+${n}`:s}function ka(s,n=Date.now()){const a=s*1e3,o=n-a;if(o<0)return ss(a);const r=Math.floor(o/6e4);if(r<1)return"now";if(r<60)return`${r}m`;const d=Math.floor(r/60);if(d<24)return`${d}h`;const c=Math.floor(d/24);return c===1?"yesterday":c<7?`${c}d`:ss(a)}function ss(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Sa(s){const n=s*1e3;return new Date(n).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function rs(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 Ca(s,n){return s.length<=n?s:s.slice(0,Math.max(0,n-1)).trimEnd()+"…"}function Aa({chats:s,selectedChatId:n,loading:a,error:o,onSelect:r,onRefresh:d,now:c}){const{t:i}=Y(["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:i("config:whatsappHistory.chats")}),e.jsx("button",{type:"button",className:"whatsapp-history-chatlist__refresh",onClick:d,disabled:a,"aria-label":i("config:whatsappHistory.refresh"),title:i("config:whatsappHistory.refresh"),children:"⟳"})]}),o&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:o}),a&&s.length===0&&e.jsxs("div",{className:"whatsapp-history-chatlist__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:i("config:whatsappHistory.loadingChats")})]}),!a&&!o&&s.length===0&&e.jsx("div",{className:"whatsapp-history-chatlist__empty",children:i("config:whatsappHistory.emptyChats")}),e.jsx("ul",{className:"whatsapp-history-chatlist__items",children:s.map(u=>{const S=rs(u.lastMessageType),x=u.lastMessagePreview||`[${u.lastMessageType}]`,y=u.chatId===n;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${y?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>r(u.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",children:cs(u.chatId)}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:ka(u.lastTimestamp,c)})]}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[u.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),S&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[S," "]}),Ca(x,40)]}),u.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:u.unreadCount})]})]})},u.chatId)})})]})}function Ta({message:s}){const n=s.direction==="outbound"?"outbound":"inbound",a=rs(s.messageType),o=(s.body??"").trim(),r=o.length>0,d=r?null:`[${s.messageType}]`;return e.jsx("div",{className:`whatsapp-history-bubble whatsapp-history-bubble--${n}`,children:e.jsxs("div",{className:"whatsapp-history-bubble__inner",children:[a&&e.jsx("span",{className:"whatsapp-history-bubble__type-icon",title:s.messageType,children:a}),r?e.jsx("span",{className:"whatsapp-history-bubble__body",children:o}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:d}),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:Sa(s.timestamp)})]})})}const _a=["all","inbound","outbound"],Ea=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function Ia({direction:s,type:n,onDirectionChange:a,onTypeChange:o,disabled:r}){const{t:d}=Y(["config"]);return e.jsxs("div",{className:"whatsapp-history-filters",children:[e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:d("config:whatsappHistory.direction")}),e.jsx("select",{value:s,onChange:c=>a(c.target.value),disabled:r,children:_a.map(c=>e.jsx("option",{value:c,children:d(`config:whatsappHistory.directionValues.${c}`)},c))})]}),e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:d("config:whatsappHistory.type")}),e.jsx("select",{value:n,onChange:c=>o(c.target.value),disabled:r,children:Ea.map(c=>e.jsx("option",{value:c,children:d(`config:whatsappHistory.typeValues.${c}`)},c))})]})]})}function Pa({chatId:s,messages:n,loading:a,loadingMore:o,error:r,hasMore:d,direction:c,type:i,onDirectionChange:u,onTypeChange:S,onLoadMore:x}){const{t:y}=Y(["config"]),h=l.useRef(null),f=l.useRef(null);return l.useEffect(()=>{h.current&&f.current!==s&&(f.current=s,h.current.scrollTop=h.current.scrollHeight)},[s,n.length]),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:cs(s)}),e.jsx(Ia,{direction:c,type:i,onDirectionChange:u,onTypeChange:S,disabled:a})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:h,children:[d&&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||a,children:y(o?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),r&&e.jsx("div",{className:"whatsapp-history-messages__error",children:r}),a&&n.length===0&&e.jsxs("div",{className:"whatsapp-history-messages__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:y("config:whatsappHistory.loadingMessages")})]}),!a&&!r&&n.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:y("config:whatsappHistory.emptyMessages")}),n.map(g=>e.jsx(Ta,{message:g},La(g)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:y("config:whatsappHistory.selectChat")})})}function La(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 ds(){const s=Z(),n={};return s&&(n.Authorization=`Bearer ${s}`),n}async function ps(s,n){try{const a=await s.json();if(a&&typeof a.error=="string")return a.error;if(a&&typeof a.message=="string")return a.message}catch{}return`${n}: ${s.statusText}`}async function $a(s){const n=`${X()}/api/whatsapp/chats/${encodeURIComponent(s)}`,a=await fetch(n,{headers:ds()});if(!a.ok)throw new Error(await ps(a,"Failed to fetch WhatsApp chats"));return a.json()}async function as(s,n,a={}){const o=new URLSearchParams;a.cursor&&o.set("cursor",a.cursor),typeof a.limit=="number"&&o.set("limit",String(a.limit)),a.direction&&o.set("direction",a.direction),a.type&&o.set("type",a.type);const r=o.toString(),d=`${X()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(n)}/messages${r?`?${r}`:""}`,c=await fetch(d,{headers:ds()});if(!c.ok)throw new Error(await ps(c,"Failed to fetch WhatsApp messages"));return c.json()}const Da=50;function Fa({isOpen:s,onClose:n}){const{t:a}=Y(["config"]),[o,r]=l.useState([]),[d,c]=l.useState(null),[i,u]=l.useState(null),[S,x]=l.useState([]),[y,h]=l.useState(!1),[f,g]=l.useState(null),[v,b]=l.useState(null),[p,L]=l.useState([]),[M,R]=l.useState(!1),[k,T]=l.useState(!1),[V,U]=l.useState(null),[K,w]=l.useState(null),[C,H]=l.useState("all"),[J,ce]=l.useState("all"),[N,D]=l.useState(()=>Date.now()),B=l.useRef(0);l.useEffect(()=>{if(!s)return;const A=window.setInterval(()=>D(Date.now()),6e4);return()=>window.clearInterval(A)},[s]),l.useEffect(()=>{if(!s)return;let A=!1;return(async()=>{var q;try{u(null);const[ne,re]=await Promise.all([Me().catch(()=>[]),is().catch(()=>null)]);if(A)return;r(ne);const te=(re==null?void 0:re.defaultSessionId)||((q=ne[0])==null?void 0:q.id)||null;c(he=>he??te)}catch(ne){if(A)return;u(ne instanceof Error?ne.message:String(ne))}})(),()=>{A=!0}},[s]);const j=l.useCallback(async A=>{h(!0),g(null);try{const q=await $a(A);x(q.chats)}catch(q){g(q instanceof Error?q.message:String(q))}finally{h(!1)}},[]);l.useEffect(()=>{!s||!d||(b(null),L([]),w(null),j(d))},[s,d,j]);const $=l.useMemo(()=>{const A={limit:Da};return C!=="all"&&(A.direction=C),J!=="all"&&(A.type=J),A},[C,J]),F=l.useCallback(async(A,q,ne)=>{const re=++B.current;R(!0),U(null),L([]),w(null);try{const te=await as(A,q,ne);if(re!==B.current)return;L([...te.messages].reverse()),w(te.nextCursor)}catch(te){if(re!==B.current)return;U(te instanceof Error?te.message:String(te))}finally{re===B.current&&R(!1)}},[]);l.useEffect(()=>{!s||!d||!v||F(d,v,$)},[s,d,v,$,F]);const Q=l.useCallback(async()=>{if(!(!d||!v||!K)){T(!0),U(null);try{const A=await as(d,v,{...$,cursor:K});L(q=>[...[...A.messages].reverse(),...q]),w(A.nextCursor)}catch(A){U(A instanceof Error?A.message:String(A))}finally{T(!1)}}},[d,v,K,$]),ae=l.useCallback(()=>{d&&j(d)},[d,j]),ee=l.useCallback(A=>{A.key==="Escape"&&(A.preventDefault(),n())},[n]);return s?e.jsx(Se,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:A=>A.stopPropagation(),onKeyDown:ee,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:a("config:whatsappHistory.title")}),e.jsx("div",{className:"whatsapp-history-modal__session",children:e.jsxs("label",{children:[e.jsx("span",{children:a("config:whatsappHistory.session")}),e.jsxs("select",{value:d??"",onChange:A=>c(A.target.value||null),disabled:o.length===0,children:[o.length===0&&e.jsx("option",{value:"",children:a("config:whatsappHistory.noSessions")}),o.map(A=>e.jsxs("option",{value:A.id,children:[A.id,A.pairedNumber?` (${A.pairedNumber})`:""]},A.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),i&&e.jsx("div",{className:"whatsapp-history-modal__alert",children:i}),e.jsxs("div",{className:"whatsapp-history-modal__body",children:[e.jsx(Aa,{chats:S,selectedChatId:v,loading:y,error:f,onSelect:b,onRefresh:ae,now:N}),e.jsx(Pa,{chatId:v,messages:p,loading:M,loadingMore:k,error:V,hasMore:K!==null,direction:C,type:J,onDirectionChange:H,onTypeChange:ce,onLoadMore:Q})]})]})})}):null}function Oa({isOpen:s,onClose:n,onOpenConfig:a,onOpenNotifications:o,onOpenHistory:r}){const{t:d}=Y(["config"]);if(l.useEffect(()=>{if(!s)return;const i=u=>{u.key==="Escape"&&(u.preventDefault(),n())};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[s,n]),!s)return null;const c=i=>{n(),i()};return e.jsx(Se,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-hub-modal",onClick:i=>i.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"whatsapp-hub-modal__icon",children:"📱"}),d("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"whatsapp-hub-modal__intro",children:d("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(a),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:d("config:whatsappHub.config",{defaultValue:"Integration config"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:d("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:d("config:whatsappHub.notifications",{defaultValue:"Notifications"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:d("config:whatsappHub.notificationsDesc",{defaultValue:"Which agent events get forwarded and to whom."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(r),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:d("config:whatsappHub.history",{defaultValue:"History"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:d("config:whatsappHub.historyDesc",{defaultValue:"Browse persisted chats and messages."})})]})]})]})]})]})})})}const Ra=[{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:"🌙"}],za=[{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:"🔴"}],Ua=[{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:"👎"}],Ba=[{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:"💜"}],Ma=[{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"}],Va=[{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"}],Ka={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},Ha={none:"grass","pokemon-stadium":"pokemon"},Wa={"emote-yes":"yes","emote-no":"no"},qa={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function le({checked:s,onChange:n}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:a=>n(a.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function je({options:s,value:n,onChange:a,iconOnly:o=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(r=>e.jsxs("button",{className:`chip ${n===r.value?"active":""}`,onClick:()=>a(r.value),title:r.label,children:[e.jsx("span",{className:"chip-icon",children:r.icon}),!o&&e.jsx("span",{className:"chip-label",children:r.label})]},r.value))})}function E({text:s,query:n}){if(!n.trim())return e.jsx(e.Fragment,{children:s});const a=s.toLowerCase(),o=n.toLowerCase(),r=a.indexOf(o);if(r===-1)return e.jsx(e.Fragment,{children:s});const d=s.slice(0,r),c=s.slice(r,r+n.length),i=s.slice(r+n.length);return e.jsxs(e.Fragment,{children:[d,e.jsx("mark",{className:"search-highlight",children:c}),i]})}const Ga=[{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"]},{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:"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"]}],Be=[{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 Ya({config:s,onChange:n,searchQuery:a="",onOpenIntegrationsModal:o,onOpenMonitoringModal:r,onOpenWorkflowEditor:d,onOpenTriggerManager:c}){var qe;const{t:i}=Y(["config","common"]),u=Ve(),S=_s(),[x,y]=l.useState(()=>Es(Ne.DEFAULT_AGENT_CLASS)||"scout"),[h,f]=l.useState(u.settings.historyLimit),[g,v]=l.useState(()=>Is()),[b,p]=l.useState(!1),[L,M]=l.useState(""),[R,k]=l.useState(()=>Z()),[T,V]=l.useState(!1),[U,K]=l.useState(!1),[w,C]=l.useState(""),[H,J]=l.useState(!1),[ce,N]=l.useState(!1),[D,B]=l.useState(!1),[j,$]=l.useState(!1),[F,Q]=l.useState(!1),[ae,ee]=l.useState(""),[A,q]=l.useState(!1);l.useEffect(()=>{aa().then(ee).catch(()=>{})},[]),l.useEffect(()=>{ea().then(t=>{t!==u.settings.experimentalEchoPrompt&&_.updateSettings({experimentalEchoPrompt:t})}).catch(()=>{})},[]),l.useEffect(()=>{na().then(t=>{t!==u.settings.tmuxMode&&_.updateSettings({tmuxMode:t})}).catch(()=>{})},[]),l.useEffect(()=>Ps(t=>{v(t),p(!1)}),[]);const ne=Ra.map(t=>({...t,label:i(`config:time.${t.value}`)})),re=za.map(t=>({...t,label:i(`config:floor.${Ha[t.value]||t.value}`)})),te=Ua.map(t=>({...t,label:i(`config:animation.${Wa[t.value]||t.value}`)})),he=Ba.map(t=>({...t,label:i(`config:colorMode.${t.value}`)})),we=Ma.map(t=>({...t,label:i(`config:terrain.${Ka[t.key]}`)})),ye=Va.map(t=>({...t,label:i(`config:sky.${qa[t.value??""]}`)})),ie=a.trim()?Ga.filter(t=>{const O=a.toLowerCase();return t.title.toLowerCase().includes(O)||t.keywords.some(de=>de.toLowerCase().includes(O))}).map(t=>t.id):null,P=t=>ie?ie.includes(t):!0,ue=P("integrations"),se=u.settings.customAgentNames||[],$e=se.length>0?se:Ls,Ce=()=>{const t=w.trim();t&&!se.includes(t)&&(_.updateSettings({customAgentNames:[...se,t]}),C(""))},be=t=>{_.updateSettings({customAgentNames:se.filter(O=>O!==t)})},De=()=>{_.updateSettings({customAgentNames:[]})},Ae=()=>{const t=L.trim();if(t){if(g.includes(t)){M("");return}v([...g,t]),p(!0),M("")}},Fe=t=>{v(g.filter((O,de)=>de!==t)),p(!0)},Te=(t,O)=>{const de=t+O;if(de<0||de>=g.length)return;const xe=g.slice();[xe[t],xe[de]]=[xe[de],xe[t]],v(xe),p(!0)},_e=()=>{Ds(g),p(!1),Ue()},Ee=t=>{k(t),V(!0)},ve=()=>{Pe(Ne.AUTH_TOKEN,R),V(!1),Ue()},Oe=t=>{ee(t),q(!0)},Ie=()=>{ta(ae).catch(()=>{}),q(!1)},pe=t=>{n({...s,terrain:{...s.terrain,...t}})},m=t=>{n({...s,modelStyle:{...s.modelStyle,...t}})},z=t=>{n({...s,animations:{...s.animations,...t}})},oe=t=>{f(t),_.updateSettings({historyLimit:t})},fe=t=>{const O=s.terrain[t];typeof O=="boolean"&&pe({[t]:!O})},G=a.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[ie&&ie.length===0&&e.jsx("div",{className:"config-no-results",children:i("config:noResults",{query:a})}),P("general")&&e.jsxs(W,{title:i("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:G&&P("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:general.history"),query:a})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:h,onChange:t=>oe(parseInt(t.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(E,{text:i("config:general.hideCosts"),query:a})}),e.jsx(le,{checked:u.settings.hideCost,onChange:t=>_.updateSettings({hideCost:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:general.grid"),query:a})}),e.jsx(le,{checked:s.gridVisible,onChange:t=>n({...s,gridVisible:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:general.showFPS"),query:a})}),e.jsx(le,{checked:u.settings.showFPS,onChange:t=>_.updateSettings({showFPS:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:general.fpsLimit"),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:t=>n({...s,fpsLimit:parseInt(t.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(E,{text:i("config:general.powerSaving"),query:a})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(le,{checked:u.settings.powerSaving,onChange:t=>_.updateSettings({powerSaving:t})})]}),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(E,{text:i("config:general.tmuxMode"),query:a})}),e.jsx(le,{checked:u.settings.tmuxMode,onChange:async t=>{_.updateSettings({tmuxMode:t});try{await ia(t)}catch(O){console.error("Failed to sync tmux mode setting to server:",O)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:general.vibrationIntensity"),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:u.settings.vibrationIntensity,onChange:t=>_.updateSettings({vibrationIntensity:parseInt(t.target.value)})}),e.jsx("span",{className:"config-value",children:u.settings.vibrationIntensity===0?i("config:vibrationValues.off"):u.settings.vibrationIntensity===1?i("config:vibrationValues.ultraLight"):u.settings.vibrationIntensity===2?i("config:vibrationValues.veryLight"):u.settings.vibrationIntensity===3?i("config:vibrationValues.light"):u.settings.vibrationIntensity===4?i("config:vibrationValues.medium"):i("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:general.externalEditor"),query:a})}),e.jsx("input",{type:"text",className:"config-input",placeholder:i("config:general.externalEditorPlaceholder"),value:u.settings.externalEditorCommand||"",onChange:t=>_.updateSettings({externalEditorCommand:t.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:general.tabTitle"),query:a})}),e.jsx("input",{type:"text",className:"config-input",placeholder:i("config:general.tabTitlePlaceholder"),value:u.settings.tabTitle||"",onChange:t=>_.updateSettings({tabTitle:t.target.value})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:general.language"),query:a})}),e.jsx(je,{options:Be,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((qe=Be.find(t=>t.value!=="auto"&&ze.language.startsWith(t.value.split("-")[0])))==null?void 0:qe.value)||"en":"auto",onChange:t=>{var O;if(t==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const de=navigator.language,xe=((O=Be.find(Ge=>Ge.value!=="auto"&&de.startsWith(Ge.value.split("-")[0])))==null?void 0:O.value)||"en";ze.changeLanguage(xe)}else localStorage.setItem("tide-commander-language-mode","manual"),ze.changeLanguage(t)}})]})]}),P("agentNames")&&e.jsx(W,{title:i("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:G&&P("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:se.length>0?i("config:agentNames.customConfigured",{count:se.length}):i("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:i("config:agentNames.addPlaceholder"),value:w,onChange:t=>C(t.target.value),onKeyDown:t=>{t.key==="Enter"&&Ce()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ce,disabled:!w.trim(),title:i("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:$e.map((t,O)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:t}),se.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>be(t),title:i("common:buttons.remove"),children:"x"})]},`${t}-${O}`))}),se.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:De,children:i("common:buttons.resetToDefaults")})]})}),P("defaultClass")&&e.jsx(W,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:G&&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${x==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{y("random"),Pe(Ne.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries($s).map(([t,O])=>e.jsx("div",{className:`agent-name-chip${x===t?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{y(t),Pe(Ne.DEFAULT_AGENT_CLASS,t)},children:e.jsxs("span",{className:"agent-name-text",children:[O.icon," ",t.charAt(0).toUpperCase()+t.slice(1)]})},t)),S.map(t=>e.jsx("div",{className:`agent-name-chip${x===t.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{y(t.id),Pe(Ne.DEFAULT_AGENT_CLASS,t.id)},children:e.jsxs("span",{className:"agent-name-text",children:[t.icon," ",t.name]})},t.id))]})]})}),P("appearance")&&e.jsx(W,{title:i("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:G&&P("appearance"),children:e.jsx(da,{})}),P("connection")&&e.jsxs(W,{title:i("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:G&&P("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:connection.backendUrl"),query:a})}),e.jsx("div",{className:"backend-urls-list",children:g.map((t,O)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:i("config:connection.priorityLabel",{defaultValue:"Priority"}),children:O+1}),e.jsx("span",{className:"backend-url-text",title:t,children:t}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Te(O,-1),disabled:O===0,title:i("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Te(O,1),disabled:O===g.length-1,title:i("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Fe(O),title:i("common:buttons.remove"),children:"x"})]},`${t}-${O}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:L,onChange:t=>M(t.target.value),placeholder:i("config:connection.addUrlPlaceholder",{defaultValue:"http://host:port"}),onKeyDown:t=>{t.key==="Enter"&&Ae()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ae,disabled:!L.trim(),title:i("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),b&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:_e,title:i("config:connection.saveAndReconnect"),children:i("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:i("config:connection.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(E,{text:i("config:connection.authToken"),query:a})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:U?"text":"password",className:"config-input config-input-full",value:R,onChange:t=>Ee(t.target.value),placeholder:i("config:connection.tokenPlaceholder"),onKeyDown:t=>{t.key==="Enter"&&T&&ve()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>K(!U),title:i(U?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(I,{name:U?"eye-closed":"eye",size:14})}),T&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:ve,title:i("config:connection.saveAndReconnect"),children:i("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:i("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:connection.codexBinaryPath"),query:a})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:ae,onChange:t=>Oe(t.target.value),placeholder:i("config:connection.codexBinaryPathPlaceholder"),onKeyDown:t=>{t.key==="Enter"&&A&&Ie()}}),A&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ie,children:i("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:i("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("common:buttons.reconnect"),query:a})}),e.jsx("button",{className:"config-btn",onClick:()=>Ue(),title:"Force reconnect to server",children:i("common:buttons.reconnect")})]})]}),P("scene")&&e.jsxs(W,{title:i("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:G&&P("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:scene.characterSize"),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"3.0",step:"0.1",value:s.characterScale,onChange:t=>n({...s,characterScale:parseFloat(t.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(E,{text:i("config:scene.scale2d",{defaultValue:"2D Scale"}),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale2d,onChange:t=>n({...s,scale2d:parseFloat(t.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(E,{text:i("config:scene.scale3d",{defaultValue:"3D Scale"}),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale3d,onChange:t=>n({...s,scale3d:parseFloat(t.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(E,{text:i("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:a})}),e.jsx(le,{checked:s.show2DTaskLabels,onChange:t=>n({...s,show2DTaskLabels:t})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:scene.time"),query:a})}),e.jsx(je,{options:ne,value:s.timeMode,onChange:t=>n({...s,timeMode:t}),iconOnly:!0})]})]}),P("terrain")&&e.jsxs(W,{title:i("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:G&&P("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:a})}),e.jsx(le,{checked:s.terrain.simpleMode??!1,onChange:t=>pe({simpleMode:t})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:we.map(t=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[t.key]?"active":""}`,onClick:()=>fe(t.key),title:t.label,children:t.icon},t.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:terrainSettings.fog"),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.terrain.fogDensity,onChange:t=>pe({fogDensity:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?i("config:fogValues.off"):s.terrain.fogDensity<=1?i("config:fogValues.low"):i("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:terrainSettings.brightness"),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.2",max:"2",step:"0.1",value:s.terrain.brightness,onChange:t=>pe({brightness:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?i("config:brightnessValues.dark"):s.terrain.brightness<=1.2?i("config:brightnessValues.normal"):i("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:terrainSettings.floor"),query:a})}),e.jsx(je,{options:re,value:s.terrain.floorStyle,onChange:t=>pe({floorStyle:t}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:terrainSettings.sky"),query:a})}),e.jsx("div",{className:"sky-color-selector",children:ye.map(t=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===t.value?"active":""}`,onClick:()=>pe({skyColor:t.value}),title:t.label,style:{background:t.color}},t.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:terrainSettings.battlefieldSize"),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:t=>pe({battlefieldSize:parseInt(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),P("modelStyle")&&e.jsxs(W,{title:i("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:G&&P("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:modelStyleSettings.saturation"),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.modelStyle.saturation,onChange:t=>m({saturation:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?i("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?i("config:saturationValues.normal"):i("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:modelStyleSettings.roughness"),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.roughness,onChange:t=>m({roughness:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?i("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?i("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?i("config:roughnessValues.normal"):i("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:modelStyleSettings.metalness"),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.metalness,onChange:t=>m({metalness:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?i("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?i("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?i("config:metalnessValues.mixed"):i("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:modelStyleSettings.glow"),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"1",step:"0.05",value:s.modelStyle.emissiveBoost,onChange:t=>m({emissiveBoost:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?i("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?i("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?i("config:glowValues.med"):i("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:modelStyleSettings.reflections"),query:a})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"2",step:"0.1",value:s.modelStyle.envMapIntensity,onChange:t=>m({envMapIntensity:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?i("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?i("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?i("config:reflectionValues.normal"):i("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:modelStyleSettings.wireframe"),query:a})}),e.jsx(le,{checked:s.modelStyle.wireframe,onChange:t=>m({wireframe:t})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:modelStyleSettings.colorMode"),query:a})}),e.jsx(je,{options:he,value:s.modelStyle.colorMode,onChange:t=>m({colorMode:t}),iconOnly:!0})]})]}),P("animations")&&e.jsxs(W,{title:i("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:G&&P("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:animationSettings.idle"),query:a})}),e.jsx(je,{options:te,value:s.animations.idleAnimation,onChange:t=>z({idleAnimation:t}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:animationSettings.working"),query:a})}),e.jsx(je,{options:te,value:s.animations.workingAnimation,onChange:t=>z({workingAnimation:t}),iconOnly:!0})]})]}),P("secrets")&&e.jsx(W,{title:i("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:G&&P("secrets"),children:e.jsx(Js,{})}),P("systemPrompt")&&e.jsx(W,{title:i("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:G&&P("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(E,{text:i("config:systemPrompt.title"),query:a})}),e.jsx("button",{className:"config-button",onClick:()=>J(!0),children:i("config:systemPrompt.editPrompt")})]})}),P("data")&&e.jsx(W,{title:i("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:G&&P("data"),children:e.jsx(ra,{})}),ue&&e.jsx(W,{title:i("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:G&&ue,children:e.jsx(ua,{onOpenModal:t=>{t==="whatsapp"?Q(!0):o==null||o(t)}})}),P("workflows")&&e.jsxs(W,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:G&&P("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(E,{text:"Create and manage automated workflow pipelines with visual state machine editor",query:a})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>d==null?void 0:d(),children:"Open Workflow Editor"})})]}),P("triggers")&&e.jsxs(W,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:G&&P("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(E,{text:"Create and manage event-driven triggers that fire agents with templates",query:a})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>c==null?void 0:c(),children:"Open Trigger Manager"})})]}),P("monitoring")&&e.jsxs(W,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:G&&P("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(E,{text:"View event logs, trigger history, workflow traces, and system stats",query:a})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>r==null?void 0:r(),children:"Open Monitoring & Logs"})})]}),P("experimental")&&e.jsxs(W,{title:i("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:G&&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(E,{text:i("config:experimental.2dView"),query:a})," ",e.jsx(I,{name:"map",size:12})]}),e.jsx(le,{checked:u.settings.experimental2DView,onChange:t=>_.updateSettings({experimental2DView:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(E,{text:i("config:experimental.voiceAssistant"),query:a})," ",e.jsx(I,{name:"microphone",size:12})]}),e.jsx(le,{checked:u.settings.experimentalVoiceAssistant,onChange:t=>_.updateSettings({experimentalVoiceAssistant:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(E,{text:i("config:experimental.tts"),query:a})," ",e.jsx(I,{name:"speaker-on",size:12})]}),e.jsx(le,{checked:u.settings.experimentalTTS,onChange:t=>_.updateSettings({experimentalTTS:t})})]}),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(E,{text:i("config:experimental.echoPrompt"),query:a})}),e.jsx(le,{checked:u.settings.experimentalEchoPrompt,onChange:async t=>{_.updateSettings({experimentalEchoPrompt:t});try{await sa(t)}catch(O){console.error("Failed to sync echo prompt setting to server:",O)}}})]}),e.jsx("span",{className:"config-hint",children:i("config:experimental.hint")})]}),P("about")&&e.jsx(W,{title:i("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:G&&P("about"),children:e.jsx(pa,{})})]}),e.jsx(ma,{isOpen:H,onClose:()=>J(!1)}),e.jsx(ba,{isOpen:ce,onClose:()=>N(!1)}),e.jsx(Na,{isOpen:D,onClose:()=>B(!1)}),e.jsx(Fa,{isOpen:j,onClose:()=>$(!1)}),e.jsx(Oa,{isOpen:F,onClose:()=>Q(!1),onOpenConfig:()=>N(!0),onOpenNotifications:()=>B(!0),onOpenHistory:()=>$(!0)})]})}function Qa({onConfigChange:s,onToolChange:n,config:a,isOpen:o,onClose:r,onOpenBuildingModal:d,onOpenAreaExplorer:c,onOpenIntegrationsModal:i,onOpenMonitoringModal:u,onOpenWorkflowEditor:S,onOpenTriggerManager:x}){const{t:y}=Y(["config","common"]),h=Ve(),f=Array.from(h.areas.values()),g=Array.from(h.buildings.values()),[v,b]=l.useState(""),p=l.useRef(null);if(l.useEffect(()=>{const k=T=>{T.key==="Escape"&&o&&r()};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[o,r]),l.useEffect(()=>{if(o&&p.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const T=setTimeout(()=>{var V;(V=p.current)==null||V.focus()},50);return()=>clearTimeout(T)}},[o]),!o)return null;const L=k=>{const T=h.activeTool===k?null:k;n(T)},M=k=>{_.selectArea(h.selectedAreaId===k?null:k),n("select")},R=(k,T)=>{k.stopPropagation(),_.deleteArea(T)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:r}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:y("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:r,title:y("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:p,type:"text",placeholder:y("config:searchPlaceholder"),value:v,onChange:k=>b(k.target.value),className:"toolbox-search-input"}),v&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>b(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(W,{title:y("config:areas.title",{count:f.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${h.activeTool==="select"?"active":""}`,onClick:()=>L("select"),title:y("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 ${h.activeTool==="rectangle"?"active":""}`,onClick:()=>L("rectangle"),title:y("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 ${h.activeTool==="circle"?"active":""}`,onClick:()=>L("circle"),title:y("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:f.length===0?e.jsx("div",{className:"areas-empty",children:y("config:areas.drawToCreate")}):f.map(k=>e.jsx(Ms,{area:k,isSelected:h.selectedAreaId===k.id,onClick:()=>M(k.id),onDelete:T=>R(T,k.id)},k.id))})]})}),h.selectedAreaId&&e.jsx(Ys,{area:h.areas.get(h.selectedAreaId),onClose:()=>_.selectArea(null),onOpenFolder:c}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(W,{title:y("config:buildings.title",{count:g.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:k=>{k.stopPropagation(),d==null||d()},title:y("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:g.length===0?e.jsx("div",{className:"buildings-empty",children:y("config:buildings.clickToAdd")}):g.map(k=>e.jsx(Vs,{building:k,isSelected:h.selectedBuildingIds.has(k.id),onClick:()=>{_.selectBuilding(h.selectedBuildingIds.has(k.id)?null:k.id)},onEdit:()=>d==null?void 0:d(k.id)},k.id))})})}),h.selectedBuildingIds.size===1&&(()=>{const k=Array.from(h.selectedBuildingIds)[0],T=h.buildings.get(k);return T?e.jsx(Ks,{building:T,onClose:()=>_.selectBuilding(null),onOpenModal:()=>d==null?void 0:d(k)}):null})(),e.jsx(Ya,{config:a,onChange:s,searchQuery:v,onOpenIntegrationsModal:i,onOpenMonitoringModal:u,onOpenWorkflowEditor:S,onOpenTriggerManager:x})]})]})]})}export{Qa as Toolbox};