tide-commander 1.129.2 → 1.131.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.
- package/dist/assets/{BossLogsModal-BMJsPBdB.js → BossLogsModal-CWI0TeXV.js} +1 -1
- package/dist/assets/{BossSpawnModal-DuDDNuE-.js → BossSpawnModal-CxiQJasU.js} +1 -1
- package/dist/assets/{ControlsModal-Cn3pkMIT.js → ControlsModal-BrPnWWpS.js} +1 -1
- package/dist/assets/{DockerLogsModal-D5XQ6zSr.js → DockerLogsModal-D1oIAzfZ.js} +1 -1
- package/dist/assets/{EmbeddedEditor-Ct4fmYRC.js → EmbeddedEditor-CHP_HStx.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-Cfxh0FZm.js → GmailOAuthSetup-DCn-EXjO.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-Z-Yv0mbQ.js → GoogleOAuthSetup-D26zofAR.js} +1 -1
- package/dist/assets/{IframeModal-eyoeBSzE.js → IframeModal-CSN8ck7s.js} +1 -1
- package/dist/assets/{IntegrationsPanel-DzdEuC2w.js → IntegrationsPanel-BU_xwMMT.js} +2 -2
- package/dist/assets/{LogViewerModal-fhtTos_b.js → LogViewerModal-Amod9PlS.js} +1 -1
- package/dist/assets/{MonitoringModal-D_QNY_Zh.js → MonitoringModal-D-2zR9Oi.js} +1 -1
- package/dist/assets/{PM2LogsModal-DulkKfnA.js → PM2LogsModal-B48puyEY.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-BkpEL2dc.js → RestoreArchivedAreaModal-C4IVaTMA.js} +1 -1
- package/dist/assets/{Scene2DCanvas-C5E1mERA.js → Scene2DCanvas-BYdgkm1n.js} +1 -1
- package/dist/assets/{SceneManager-BA7KiD3q.js → SceneManager-DVL0xQVk.js} +1 -1
- package/dist/assets/{SkillsPanel-uotqhq5s.js → SkillsPanel-BwCe6nFB.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-B1QA0scY.js → SlackMultiInstanceSetup-nSiRoxLD.js} +1 -1
- package/dist/assets/{SpawnModal-B1d-vt6c.js → SpawnModal-DXvcL-cq.js} +1 -1
- package/dist/assets/{StatisticsModal-CpMdoPSG.js → StatisticsModal-Dgq-n8L6.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-ALjpv2DP.js → SubordinateAssignmentModal-DflOgTr1.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-rrDTH1Oq.js → TriggerManagerPanel-wzVna9Th.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-BcuM9e70.js → WorkflowEditorPanel-Cv1Bb_0g.js} +1 -1
- package/dist/assets/{area-logos-BkmhbXfG.js → area-logos-6NdoVnoc.js} +1 -1
- package/dist/assets/{index-CfEgfolW.js → index-1_kNHqvQ.js} +1 -1
- package/dist/assets/index-Bsf5hZbp.js +11 -0
- package/dist/assets/{index-DI7bDj0E.js → index-CoGlYrB7.js} +5 -5
- package/dist/assets/{index-BiXjxgpq.js → index-CqwyKXtm.js} +1 -1
- package/dist/assets/index-D8cfBFRC.js +2 -0
- package/dist/assets/{index-DMCGsQg5.js → index-DZcn4bXn.js} +1 -1
- package/dist/assets/{index-BNoB11BS.js → index-SaaO8V1I.js} +2 -2
- package/dist/assets/{index-BoN1bGyV.js → index-Tn-mXnAH.js} +3 -3
- package/dist/assets/{index-C9NJLW6A.js → index-sLCEQwTe.js} +3 -3
- package/dist/assets/main-BPim_cvM.css +1 -0
- package/dist/assets/{main-CEKV7I4r.js → main-DffU4pm2.js} +110 -110
- package/dist/assets/{web-DTb2MfHS.js → web-BzTFbp-p.js} +1 -1
- package/dist/assets/{web-CvCmCymz.js → web-CNVP9dOO.js} +1 -1
- package/dist/assets/{web-jSBoGXkW.js → web-SdWeOa6A.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/locales/de/config.json +20 -13
- package/dist/locales/en/config.json +11 -6
- package/dist/locales/es/config.json +20 -13
- package/dist/locales/fr/config.json +20 -13
- package/dist/locales/hi/config.json +20 -13
- package/dist/locales/it/config.json +20 -13
- package/dist/locales/ja/config.json +20 -13
- package/dist/locales/pt/config.json +20 -13
- package/dist/locales/ru/config.json +20 -13
- package/dist/locales/zh-CN/config.json +20 -13
- package/dist/src/packages/server/claude/backend.js +10 -3
- package/dist/src/packages/server/claude/session-loader.js +56 -13
- package/dist/src/packages/server/codex/backend.js +6 -1
- package/package.json +1 -1
- package/dist/assets/index-ZQNyoovC.js +0 -2
- package/dist/assets/index-dfuoBomr.js +0 -11
- package/dist/assets/main-D086vUF0.css +0 -1
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{r as l,b3 as Re,b4 as Ye,j as e,I as L,u as Y,b5 as as,ab as ns,f as Ve,s as T,b6 as hs,b7 as ms,aY as gs,b8 as fs,C as he,G as oe,H as Z,h as je,i as ke,m as xs,b9 as bs,ba as js,bb as vs,bc as ws,P as Ns,bd as Se,a6 as ys,be as is,bf as ks,bg as Be,bh as Ss,bi as Cs,bj as As,bk as Ts,bl as _s,bm as Is,bn as Es,aS as Ps,W as Ls,S as ye,bo as $s,bp as Ds,aU as Fs,bq as Ue,X as Ee,b0 as Os,br as ze,bs as Rs}from"./main-CEKV7I4r.js";import{g as Us,d as zs,u as Ms}from"./area-logos-BkmhbXfG.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ke="deivid11/tide-commander",Bs=`https://api.github.com/repos/${Ke}/releases/latest`,Vs=`https://api.github.com/repos/${Ke}/releases?per_page=3`,Ks=3600*1e3,Je="app_update_dismissed_version",Ze="1.129.2";function Hs(){var y,C;const[s,i]=l.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:Ze}),t=((C=(y=Re)==null?void 0:y.getPlatform)==null?void 0:C.call(y))==="android"||!1,o=u=>u.replace(/^v/,"").split(".").map(g=>parseInt(g,10)||0),d=(u,p)=>{const g=o(u),v=o(p),j=Math.max(g.length,v.length);for(let m=0;m<j;m++){const k=g[m]||0,$=v[m]||0;if(k>$)return 1;if(k<$)return-1}return 0},r=async u=>{var g,v;if(Re&&Ye&&((v=(g=Re).isNativePlatform)==null?void 0:v.call(g))===!0){const j=await Ye.get({url:u,headers:{Accept:"application/vnd.github.v3+json"}});return{data:j.data,status:j.status}}else{const j=await fetch(u,{headers:{Accept:"application/vnd.github.v3+json"}});return j.ok?{data:await j.json(),status:j.status}:{data:null,status:j.status}}},c=l.useCallback(async(u=!1)=>{i(p=>({...p,isChecking:!0,error:null}));try{const[p,g]=await Promise.all([r(Bs),r(Vs)]);if(p.status!==200)throw new Error(`GitHub API error: ${p.status}`);const v=p.data,j=v.tag_name;let m=[];g.status===200&&g.data&&(m=g.data.map(w=>({version:w.tag_name,name:w.name,publishedAt:w.published_at,releaseUrl:w.html_url})));const k=localStorage.getItem(Je);if(!u&&k===j)return i(w=>({...w,isChecking:!1,updateAvailable:!1,recentReleases:m})),null;if(!(d(j,Ze)>0))return i(w=>({...w,isChecking:!1,updateAvailable:!1,recentReleases:m})),null;const I=v.assets.find(w=>w.name.endsWith(".apk")&&w.content_type==="application/vnd.android.package-archive"),V={version:j,name:v.name,changelog:v.body,releaseUrl:v.html_url,apkUrl:(I==null?void 0:I.browser_download_url)||null,apkSize:(I==null?void 0:I.size)||null,publishedAt:v.published_at};return i(w=>({...w,isChecking:!1,updateAvailable:!0,updateInfo:V,recentReleases:m})),V}catch(p){const g=p instanceof Error?p.message:"Failed to check for updates";return i(v=>({...v,isChecking:!1,error:g})),null}},[]),f=l.useCallback(async()=>{var u,p,g;if(!((u=s.updateInfo)!=null&&u.apkUrl)){(p=s.updateInfo)!=null&&p.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!t){(g=s.updateInfo)!=null&&g.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),i(v=>({...v,error:null}))}catch(v){const j=v instanceof Error?v.message:"Failed to open download";i(m=>({...m,error:j}))}},[s.updateInfo,t]),a=l.useCallback(()=>{s.updateInfo&&localStorage.setItem(Je,s.updateInfo.version),i(u=>({...u,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),x=l.useCallback(()=>{var u;(u=s.updateInfo)!=null&&u.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${Ke}/releases`,"_blank")},[s.updateInfo]);return l.useEffect(()=>{if(!t)return;const u=setTimeout(()=>{c()},5e3),p=setInterval(()=>{c()},Ks);return()=>{clearTimeout(u),clearInterval(p)}},[t,c]),{...s,isAndroid:t,checkForUpdate:c,downloadAndInstall:f,dismissUpdate:a,openReleasePage:x}}const os="tide-toolbox-collapse";function Ws(s,i){try{const t=localStorage.getItem(`${os}-${s}`);if(t!==null)return t==="true"}catch{}return i}function qs(s,i){try{localStorage.setItem(`${os}-${s}`,String(i))}catch{}}function K({title:s,storageKey:i,defaultOpen:t=!1,forceOpen:o=!1,children:d,headerExtra:r}){const[c,f]=l.useState(()=>i?Ws(i,t):t),a=()=>{const y=!c;f(y),i&&qs(i,y)},x=o||c;return e.jsxs("div",{className:`collapsible-section ${x?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:a,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[r,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(L,{name:x?"caret-down":"caret-right",size:10})})]})]}),x&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Gs({area:s,isSelected:i,onClick:t,onDelete:o}){const{t:d}=Y(["config","common"]),r=s.assignedAgentIds.length,c=s.type==="rectangle"?d("config:areas.rect"):d("config:areas.circle");return e.jsxs("div",{className:`area-item ${i?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[c," ",r>0&&`• ${r} ${r>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:d("config:areas.deleteArea"),children:"×"})]})}function Ys({building:s,isSelected:i,onClick:t,onEdit:o}){var f;const{t:d}=Y(["config"]),r=((f=s.pm2Status)==null?void 0:f.ports)||[],c=(a,x)=>{a.stopPropagation(),window.open(`http://${window.location.hostname}:${x}`,"_blank")};return e.jsxs("div",{className:`building-item ${i?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:as[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(L,{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,r.length>0&&e.jsx("span",{className:"building-ports",children:r.map(a=>e.jsxs("a",{href:`http://${window.location.hostname}:${a}`,className:"building-port-link",onClick:x=>c(x,a),title:`Open :${a}`,children:[":",a]},a))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:a=>{a.stopPropagation(),o()},title:d("config:buildings.editBuilding"),children:e.jsx(L,{name:"gear",size:14})})]})}function Js({building:s,onClose:i,onOpenModal:t}){var x,y,C,u,p,g,v,j;const{t:o}=Y(["config","common"]),{buildingLogs:d}=Ve(),r=T.getBuildingLogs(s.id),c=hs[s.style||"server-rack"],f=m=>{T.sendBuildingCommand(s.id,m)},a=m=>{window.open(m,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx(L,{name:ns(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:as[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:i,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:c.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>f("start"),disabled:!((x=s.commands)!=null&&x.start)||s.status==="running",title:((y=s.commands)==null?void 0:y.start)||o("config:buildings.noStartCommand"),children:[e.jsx(L,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>f("stop"),disabled:!((C=s.commands)!=null&&C.stop)||s.status==="stopped",title:((u=s.commands)==null?void 0:u.stop)||o("config:buildings.noStopCommand"),children:[e.jsx(L,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>f("restart"),disabled:!((p=s.commands)!=null&&p.restart),title:((g=s.commands)==null?void 0:g.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx(L,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>f("healthCheck"),disabled:!((v=s.commands)!=null&&v.healthCheck),title:((j=s.commands)==null?void 0:j.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx(L,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((m,k)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>a(m.url),title:m.url,children:[e.jsx(L,{name:"link",size:12})," ",m.label||m.url]},k))})]}),r.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[o("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>T.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:r.slice(-5).map((m,k)=>e.jsx("div",{className:"building-editor-log-entry",children:m},k))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(L,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}const Zs=[{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 Xs({area:s,onClose:i,onOpenFolder:t}){var Q;const{t:o}=Y(["config","common"]),[d,r]=l.useState(s.name),[c,f]=l.useState(s.prompt||""),[a,x]=l.useState(!1),[y,C]=l.useState(""),[u,p]=l.useState(!1),g=l.useRef(null);l.useEffect(()=>{r(s.name)},[s.id,s.name]),l.useEffect(()=>{f(s.prompt||"")},[s.id,s.prompt]);const v=N=>{const D=N.target.value;r(D),T.updateArea(s.id,{name:D})},j=N=>{T.updateArea(s.id,{color:N})},m=N=>{const D=N.target.value;f(D),T.updateArea(s.id,{prompt:D})},k=()=>{y.trim()&&(T.addDirectoryToArea(s.id,y.trim()),C(""),x(!1))},$=(N,D)=>{D.stopPropagation(),T.removeDirectoryFromArea(s.id,N)},I=()=>{T.bringAreaToFront(s.id)},V=()=>{T.sendAreaToBack(s.id)},w=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]),O=async N=>{var B;const D=(B=N.target.files)==null?void 0:B[0];if(D){p(!0);try{const h=await Ms(s.id,D),E=w();T.updateArea(s.id,{logo:{filename:h.filename,position:"center",width:E.width,height:E.height,keepAspectRatio:!0,opacity:.8}})}catch(h){console.error("Failed to upload logo:",h)}finally{p(!1),g.current&&(g.current.value="")}}},z=async()=>{try{await zs(s.id),T.updateArea(s.id,{logo:void 0})}catch(N){console.error("Failed to remove logo:",N)}},H=N=>{s.logo&&T.updateArea(s.id,{logo:{...s.logo,position:N}})},S=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;T.updateArea(s.id,{logo:{...s.logo,width:D,height:Math.round(D*B*10)/10}})}else T.updateArea(s.id,{logo:{...s.logo,width:D}})},R=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;T.updateArea(s.id,{logo:{...s.logo,height:D,width:Math.round(D*B*10)/10}})}else T.updateArea(s.id,{logo:{...s.logo,height:D}})},W=()=>{s.logo&&T.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},J=N=>{s.logo&&T.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:i,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange: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("button",{type:"button",className:`color-swatch ${s.color===N?"selected":""}`,style:{backgroundColor:N},onClick:()=>j(N),"aria-label":`Set area color ${N}`,"aria-pressed":s.color===N,title:N},N))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:I,title:o("config:areas.bringToFront"),children:[e.jsx(L,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:V,title:o("config:areas.sendToBack"),children:[e.jsx(L,{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:[(Q=s.logo)!=null&&Q.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Us(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:z,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:u,children:u?"...":e.jsx(L,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:Zs.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:()=>H(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:S,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:R,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:W}),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:u,children:u?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:g,type:"file",accept:"image/*",style:{display:"none"},onChange:O})]})]}),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:()=>t==null?void 0:t(s.id),title:o("config:areas.openFolder"),children:e.jsx(L,{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=>$(N,D),title:o("config:areas.removeFolder"),children:"×"})]},N)),a?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(gs,{value:y,onChange:C,onSubmit:k,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:k,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>x(!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:m,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 Qs(){const{t:s}=Y(["config","common"]),i=fs(),[t,o]=l.useState(!1),[d,r]=l.useState(null),[c,f]=l.useState({name:"",key:"",value:"",description:""}),[a,x]=l.useState(null),y=()=>{o(!0),r(null),f({name:"",key:"",value:"",description:""})},C=m=>{r(m.id),o(!1),f({name:m.name,key:m.key,value:m.value,description:m.description||""})},u=()=>{o(!1),r(null),f({name:"",key:"",value:"",description:""})},p=()=>{!c.name.trim()||!c.key.trim()||(d?T.updateSecret(d,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):T.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),u())},g=m=>{x(m)},v=()=>{a&&(T.deleteSecret(a),d===a&&u())},j=m=>{navigator.clipboard.writeText(`{{${m}}}`)};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:i.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):i.map(m=>e.jsxs("div",{className:`secret-item ${d===m.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:m.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>j(m.key),title:s("config:secrets.copyPlaceholder"),children:`{{${m.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>C(m),title:s("common:buttons.edit"),children:e.jsx(L,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>g(m.id),title:s("common:buttons.delete"),children:"×"})]})]}),m.description&&e.jsx("div",{className:"secret-item-description",children:m.description})]},m.id))}),(t||d)&&e.jsxs("div",{className:"secret-form",children:[e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.name")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.namePlaceholder"),value:c.name,onChange:m=>f({...c,name:m.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:m=>f({...c,key:m.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:m=>f({...c,value:m.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:m=>f({...c,description:m.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:u,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:p,disabled:!c.name.trim()||!c.key.trim(),children:s(d?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:y,children:s("config:secrets.addSecret")}),e.jsx(he,{isOpen:a!==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:()=>x(null)})]})}async function et(){const s=oe(),i=await fetch(`${Z()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch echo prompt setting: ${i.statusText}`);return(await i.json()).enabled||!1}async function st(s){const i=oe(),t=await fetch(`${Z()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function tt(){const s=oe(),i=await fetch(`${Z()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch codex binary path: ${i.statusText}`);return(await i.json()).path||""}async function at(s){const i=oe(),t=await fetch(`${Z()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function nt(){const s=oe(),i=await fetch(`${Z()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch tmux mode setting: ${i.statusText}`);return(await i.json()).enabled||!1}async function it(s){const i=oe(),t=await fetch(`${Z()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function ot(){const s=oe(),i=await fetch(`${Z()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch interactive mode setting: ${i.statusText}`);return(await i.json()).enabled||!1}async function lt(s){const i=oe(),t=await fetch(`${Z()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function ct(){const s=oe(),i=await fetch(`${Z()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch backup status: ${i.statusText}`);return i.json()}async function rt(s){const i=oe(),t=await fetch(`${Z()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({enabled:s})});if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function dt({checked:s,onChange:i,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:o=>i(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function ut(){const{t:s}=Y(["config","common"]),[i,t]=l.useState([]),[o,d]=l.useState(new Set),[r,c]=l.useState(new Set),[f,a]=l.useState(!1),[x,y]=l.useState(!1),[C,u]=l.useState(null),[p,g]=l.useState(null),[v,j]=l.useState(null),[m,k]=l.useState(null),[$,I]=l.useState(!1),[V,w]=l.useState(null);l.useEffect(()=>{je(ke("/api/config/categories")).then(h=>h.json()).then(h=>{const E=Array.isArray(h)?h:[];t(E),d(new Set(E.map(F=>F.id)))}).catch(h=>console.error("Failed to fetch config categories:",h))},[]),l.useEffect(()=>{ct().then(k).catch(h=>{console.error("Failed to fetch backup status:",h),w(h.message||"Failed to fetch backup status")})},[]);const O=async h=>{if(!$){I(!0),w(null);try{const E=await rt(h);k(E)}catch(E){w(E.message||"Failed to update backup setting")}finally{I(!1)}}},z=h=>{d(E=>{const F=new Set(E);return F.has(h)?F.delete(h):F.add(h),F})},H=h=>{c(E=>{const F=new Set(E);return F.has(h)?F.delete(h):F.add(h),F})},S=()=>d(new Set(i.map(h=>h.id))),R=()=>d(new Set),W=()=>{p&&c(new Set(p.categories.map(h=>h.id)))},J=()=>c(new Set),Q=async()=>{var h;if(o.size!==0){a(!0),j(null);try{const E=Array.from(o).join(","),F=await je(ke(`/api/config/export?categories=${E}`));if(!F.ok)throw new Error("Export failed");const ee=await F.blob(),se=window.URL.createObjectURL(ee),X=document.createElement("a");X.href=se;const A=F.headers.get("Content-Disposition"),q=((h=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:h[1])||"tide-commander-config.zip";X.download=q,document.body.appendChild(X),X.click(),document.body.removeChild(X),window.URL.revokeObjectURL(se),j({type:"success",text:s("config:data.exportSuccess")})}catch(E){j({type:"error",text:E.message||"Export failed"})}finally{a(!1)}}},N=async h=>{var F;const E=(F=h.target.files)==null?void 0:F[0];if(E){u(E),j(null),g(null),c(new Set);try{const ee=await je(ke("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await E.arrayBuffer()});if(!ee.ok){const A=await ee.json();throw new Error(A.error||"Failed to preview config file")}const se=await ee.json(),X=Array.isArray(se.categories)?se.categories:[];g({...se,categories:X}),c(new Set(X.map(A=>A.id)))}catch(ee){j({type:"error",text:ee.message||"Failed to read config file"}),u(null)}}},D=async()=>{if(!(!C||r.size===0)){y(!0),j(null);try{const h=Array.from(r).join(","),E=await je(ke(`/api/config/import?categories=${h}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await C.arrayBuffer()}),F=await E.json();if(!E.ok)throw new Error(F.error||"Import failed");j({type:"success",text:F.message||s("config:data.importSuccess")}),u(null),g(null),c(new Set)}catch(h){j({type:"error",text:h.message||"Import failed"})}finally{y(!1)}}},B=()=>{u(null),g(null),c(new Set),j(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(dt,{checked:!!(m!=null&&m.enabled),disabled:$||!m,onChange:O})]}),e.jsxs("div",{className:"data-backup-info",children:[m?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:m.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!m.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:m.scriptPath})]}),m.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(m.lastRunAt).toLocaleString(),m.lastRunOk===!0&&" — ok",m.lastRunOk===!1&&m.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",m.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),V&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:V})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:S,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:R,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:i.map(h=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(h.id),onChange:()=>z(h.id)}),e.jsx("span",{className:"data-category-name",children:h.name})]},h.id))}),e.jsx("button",{className:"data-action-btn export",onClick:Q,disabled:f||o.size===0,children:f?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),C?p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:C.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(p.exportedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-subtitle",children:s("config:data.selectToImport")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:W,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:J,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:p.categories.map(h=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:r.has(h.id),onChange:()=>H(h.id)}),e.jsx("span",{className:"data-category-name",children:h.name}),h.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",h.fileCount," ",s("config:data.files"),")"]})]},h.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:x||r.size===0,children:x?s("config:data.importing"):s("config:data.importCount",{count:r.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:N,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}async function pt(){const s=await je(`${Z()}/api/system/install-info`);if(!s.ok)throw new Error(`Failed to fetch install info: ${s.statusText}`);return s.json()}function ht(s,i){const t=new AbortController;return(async()=>{try{const o=await fetch(xs(`${Z()}/api/system/self-update`),{method:"POST",signal:t.signal,headers:{Accept:"text/event-stream"}});if(!o.ok||!o.body){const f=await o.text().catch(()=>"");let a=null;try{a=JSON.parse(f)}catch{}const x=a&&typeof a=="object"&&"error"in a&&typeof a.error=="string"?a.error:`Self-update failed: ${o.status} ${o.statusText}`;s({type:"error",message:x}),i(new Error(x));return}const d=o.body.getReader(),r=new TextDecoder("utf-8");let c="";for(;;){const{value:f,done:a}=await d.read();if(a)break;c+=r.decode(f,{stream:!0});let x=c.indexOf(`
|
|
2
|
-
|
|
3
|
-
`);for(;x!==-1;){const y=c.slice(0,x);c=c.slice(x+2);const C=y.split(`
|
|
4
|
-
`);let u="message",p="";for(const g of C)g.startsWith(":")||(g.startsWith("event:")?u=g.slice(6).trim():g.startsWith("data:")&&(p+=(p?`
|
|
5
|
-
`:"")+g.slice(5).trim()));if(p)try{const g=JSON.parse(p);s({type:u,...g})}catch{}x=c.indexOf(`
|
|
6
|
-
|
|
7
|
-
`)}}i()}catch(o){if(o.name==="AbortError"){i();return}i(o)}})(),()=>t.abort()}function mt(){const[s,i]=l.useState(()=>bs()),t=o=>{i(o);const d=vs(o);ws(d)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:js.map(o=>e.jsxs("button",{className:`theme-option ${s===o.id?"active":""}`,onClick:()=>t(o.id),title:o.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:o.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:o.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:o.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:o.name})]},o.id))})})}function gt(){const{t:s}=Y(["config"]),[i,t]=l.useState(null),[o,d]=l.useState("idle"),[r,c]=l.useState(""),[f,a]=l.useState(null),[x,y]=l.useState(null),C=l.useRef(null),u=l.useRef(null),p=l.useCallback(async()=>{try{const k=await pt();t(k)}catch{t(null)}},[]);l.useEffect(()=>{p()},[p]),l.useEffect(()=>{u.current&&(u.current.scrollTop=u.current.scrollHeight)},[r]);const g=l.useCallback(()=>{d("confirm")},[]),v=l.useCallback(()=>{d("idle")},[]),j=l.useCallback(()=>{d("running"),c(""),a(null),y(null);const k=ht($=>{switch($.type){case"start":c(I=>I+`${$.message}
|
|
8
|
-
`);break;case"stdout":c(I=>I+$.chunk);break;case"stderr":c(I=>I+$.chunk);break;case"error":a($.message),$.suggestedManualCommand&&c(I=>I+`
|
|
9
|
-
|
|
10
|
-
Suggested manual command: ${$.suggestedManualCommand}
|
|
11
|
-
`);break;case"done":$.success?(y($.newVersion),d("success")):d("failed");break}},$=>{$&&a(I=>I??$.message),d(I=>I==="running"?f?"failed":"success":I)});C.current=k},[f]),m=l.useCallback(()=>{var k;(k=C.current)==null||k.call(C),C.current=null,d("idle"),p()},[p]);return i?i.isGlobalInstall?i.autoUpdateSupported?!i.updateAvailable&&o==="idle"?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:about.autoUpdateTitle")}),o==="idle"&&i.updateAvailable&&e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsxs("span",{className:"about-autoupdate-versions",children:[e.jsx("span",{className:"about-autoupdate-current",children:i.currentVersion}),e.jsx("span",{className:"about-autoupdate-arrow",children:"→"}),e.jsx("span",{className:"about-autoupdate-latest",children:i.latestVersion})]}),e.jsx("button",{className:"about-update-btn download",onClick:g,children:s("config:about.autoUpdateButton")})]}),o==="confirm"&&e.jsxs("div",{className:"about-autoupdate-confirm",children:[e.jsx("div",{className:"about-autoupdate-confirm-title",children:s("config:about.autoUpdateConfirmTitle")}),e.jsx("div",{className:"about-autoupdate-confirm-body",children:s("config:about.autoUpdateConfirmBody")}),e.jsxs("div",{className:"about-autoupdate-confirm-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:v,children:s("config:about.autoUpdateCancel")}),e.jsx("button",{className:"about-update-btn download",onClick:j,children:s("config:about.autoUpdateConfirm")})]})]}),(o==="running"||o==="success"||o==="failed")&&e.jsxs("div",{className:"about-autoupdate-stream",children:[e.jsxs("div",{className:"about-autoupdate-stream-title",children:[o==="running"&&s("config:about.autoUpdateRunning"),o==="success"&&s("config:about.autoUpdateSuccess"),o==="failed"&&s("config:about.autoUpdateFailed")]}),e.jsx("pre",{ref:u,className:"about-autoupdate-output",children:r||"..."}),o==="success"&&e.jsxs("div",{className:"about-autoupdate-success-hint",children:[x&&e.jsxs("div",{className:"about-autoupdate-newversion",children:["v",x]}),e.jsx("div",{children:s("config:about.autoUpdateRestartHint")})]}),o==="failed"&&f&&e.jsx("div",{className:"about-update-error",children:f}),(o==="success"||o==="failed")&&e.jsx("div",{className:"about-autoupdate-stream-actions",children:e.jsx("button",{className:"about-update-btn changelog",onClick:m,children:s("config:about.autoUpdateClose")})})]})]}):e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:about.autoUpdateTitle")}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdatePackageManagerNotice",{pm:i.packageManager})}),i.suggestedManualCommand&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"about-autoupdate-manualhint",children:s("config:about.autoUpdateManualCommand")}),e.jsx("pre",{className:"about-autoupdate-manualcmd",children:i.suggestedManualCommand})]})]}):e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:about.autoUpdateTitle")}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdateDevMode")})]}):null}function ft(){const{t:s}=Y(["config"]),{updateAvailable:i,updateInfo:t,recentReleases:o,isChecking:d,error:r,currentVersion:c,isAndroid:f,checkForUpdate:a,downloadAndInstall:x,openReleasePage:y}=Hs(),C=p=>p?`${(p/(1024*1024)).toFixed(1)} MB`:"",u=p=>new Date(p).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:e.jsx(L,{name:"waves",size:24})}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:c}),i&&t?e.jsx("span",{className:"about-version-update-badge",onClick:y,title:`Update available: ${t.version}`,children:t.version}):e.jsxs("a",{href:"https://github.com/deivid11/tide-commander/releases",target:"_blank",rel:"noopener noreferrer",className:"about-version-status",children:["(",s("config:about.updated"),")"]})]})]}),e.jsx(gt,{}),e.jsxs("div",{className:"about-update",children:[i&&t?e.jsxs("div",{className:"about-update-available",children:[e.jsxs("div",{className:"about-update-header",children:[e.jsx("span",{className:"about-update-badge",children:s("config:about.updateAvailable")}),e.jsx("span",{className:"about-update-version",children:t.version})]}),t.apkSize&&e.jsxs("div",{className:"about-update-size",children:[s("config:about.sizeLabel"),": ",C(t.apkSize)]}),r&&e.jsx("div",{className:"about-update-error",children:r}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:y,children:s("config:about.changelog")}),f&&t.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:x,children:s("config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:y,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(d?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>a(!0),disabled:d,children:d?"...":s("config:about.check")})]}),o.length>0&&e.jsxs("div",{className:"about-releases",children:[e.jsx("div",{className:"about-releases-title",children:s("config:about.recentReleases")}),e.jsx("div",{className:"about-releases-list",children:o.map(p=>e.jsxs("a",{href:p.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${p.version===`v${c}`||p.version===c?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:p.version}),e.jsx("span",{className:"about-release-date",children:u(p.publishedAt)})]},p.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:e.jsx(L,{name:"package",size:14})}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]})]})}const xt={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function bt({onOpenModal:s}){const[i,t]=l.useState([]),[o,d]=l.useState(!0),r=l.useCallback(async()=>{try{const c=await je(ke("/api/integrations"));if(!c.ok)return;const f=await c.json();t(f)}catch{}finally{d(!1)}},[]);return l.useEffect(()=>{r()},[r]),o?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):i.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:[i.map(c=>{const f=xt[c.id]||"🔌",a=!!c.status.error,x=c.status.connected,y=a?"#f38ba8":x?"#a6e3a1":"#fab387",C=a?"Error":x?"Connected":"Setup Required",u=a?"✗":x?"✓":"⚠";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 8px",borderRadius:4,background:"var(--surface-1, #181825)",border:"1px solid var(--border, #313244)",fontSize:12,minHeight:26},children:[e.jsx("span",{style:{fontSize:13,flexShrink:0},children:f}),e.jsx("span",{style:{flex:1,minWidth:0,color:"var(--text-primary, #cdd6f4)",fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c.name}),e.jsx("span",{style:{color:y,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:C,children:u}),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:p=>{p.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:p=>{p.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 jt({isOpen:s,onClose:i,initialAgentId:t}){const{t:o}=Y(["config"]),d=Ns(),[r,c]=l.useState(""),[f,a]=l.useState(""),[x,y]=l.useState(""),[C,u]=l.useState(null),[p,g]=l.useState(null),[v,j]=l.useState(!1),[m,k]=l.useState(!1),[$,I]=l.useState(!1),[V,w]=l.useState(null),O=l.useMemo(()=>[...d].sort((h,E)=>h.name.localeCompare(E.name)),[d]),z=l.useMemo(()=>d.find(h=>h.id===r),[d,r]);l.useEffect(()=>{var E;if(!s)return;const h=t&&d.some(F=>F.id===t)?t:((E=O[0])==null?void 0:E.id)??"";c(h)},[s]),l.useEffect(()=>{const h=(z==null?void 0:z.customPrompt)??"";a(h),y(h),j(!1),u(null),g(null)},[r]);const H=h=>{const E=h.target.value;a(E),j(E!==x),u(null),g(null)},S=()=>{if(r)try{u(null),g(null),T.updateAgentProperties(r,{customPrompt:f}),y(f),j(!1),g(o("config:systemPrompt.saved"))}catch(h){u(h instanceof Error?h.message:"Failed to save system prompt")}},R=()=>{k(!0)},W=()=>{if(r)try{u(null),g(null),T.updateAgentProperties(r,{customPrompt:""}),a(""),y(""),j(!1),g(o("config:systemPrompt.cleared"))}catch(h){u(h instanceof Error?h.message:"Failed to clear system prompt")}},J=()=>{a(x),j(!1),u(null),g(null)},Q=h=>{if(h!==r){if(v){w(h),I(!0);return}c(h)}},N=()=>{if(v){w(null),I(!0);return}i()},D=()=>{if(I(!1),V){const h=V;w(null),c(h)}else i()},B=h=>{h.key==="Escape"&&(h.preventDefault(),N())};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:N,children:e.jsxs("div",{className:"system-prompt-modal",onClick:h=>h.stopPropagation(),onKeyDown:B,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:o("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:N,"aria-label":"Close",children:e.jsx(L,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:O.length===0?e.jsx("div",{className:"loading-state",children:e.jsx("p",{children:o("config:systemPrompt.noAgents")})}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:o("config:systemPrompt.description")}),e.jsxs("div",{className:"agent-picker",children:[e.jsx("label",{htmlFor:"system-prompt-agent",className:"editor-label",children:o("config:systemPrompt.agentLabel")}),e.jsxs("div",{className:"agent-picker-row",children:[z&&e.jsx(ys,{classId:z.class,size:20,className:"agent-picker-icon"}),e.jsx("select",{id:"system-prompt-agent",className:"agent-picker-select",value:r,onChange:h=>Q(h.target.value),children:O.map(h=>e.jsxs("option",{value:h.id,children:[h.name,h.customPrompt?" • ✦":""]},h.id))})]})]}),C&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"warn",size:14})}),C]}),p&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"check",size:14})}),p]}),e.jsxs("div",{className:"editor-wrapper",children:[e.jsxs("div",{className:"editor-header",children:[e.jsx("label",{htmlFor:"prompt-input",className:"editor-label",children:o("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[f.length," ",o("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:f,onChange:H,placeholder:o("config:systemPrompt.placeholder"),rows:18,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:o("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:R,disabled:!f||!r,children:o("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:N,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:J,disabled:!v,children:o("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:S,disabled:!v||!r,children:o("config:systemPrompt.save")})]})]})]})}),e.jsx(he,{isOpen:m,title:o("config:systemPrompt.clear"),message:o("config:systemPrompt.confirmClear"),confirmLabel:o("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{W()},onClose:()=>k(!1)}),e.jsx(he,{isOpen:$,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:D,onClose:()=>{I(!1),w(null)}})]}):null}const Xe={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},vt=2500,wt=12e4;function Qe(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function Nt(s,i){return s.enabled===i.enabled&&s.baseUrl===i.baseUrl&&s.defaultSessionId===i.defaultSessionId&&s.webhookVerifyToken===i.webhookVerifyToken&&s.showIncomingToasts===i.showIncomingToasts}function yt({isOpen:s,onClose:i}){const{t}=Y(["config"]),[o,d]=l.useState(Xe),[r,c]=l.useState(Xe),[f,a]=l.useState(!1),[x,y]=l.useState([]),[C,u]=l.useState(!0),[p,g]=l.useState(null),[v,j]=l.useState(null),[m,k]=l.useState(""),[$,I]=l.useState(!1),[V,w]=l.useState(""),[O,z]=l.useState(null),[H,S]=l.useState(null),[R,W]=l.useState(null),J=l.useRef(null),Q=l.useRef(0),[N,D]=l.useState(""),[B,h]=l.useState(""),[E,F]=l.useState(null),[ee,se]=l.useState(!1),[X,A]=l.useState(!1),[q,te]=l.useState(!1),[le,ae]=l.useState(!1),[ue,ve]=l.useState(null),we=!Nt(o,r),re=l.useCallback(()=>{J.current&&(clearTimeout(J.current),J.current=null)},[]),me=l.useCallback(async()=>{try{u(!0),g(null),j(null);const[b,U]=await Promise.all([is(),ks()]),ne=Qe(b);if(d(ne),c(ne),a(!!U.configured),U.configured)try{const fe=await Be();y(Array.isArray(fe)?fe:[])}catch{y([])}else y([])}catch(b){g(b instanceof Error?b.message:t("config:whatsapp.errors.loadFailed"))}finally{u(!1)}},[t]),P=l.useCallback(async()=>{try{const b=await Be();y(Array.isArray(b)?b:[])}catch{}},[]);l.useEffect(()=>(s?me():(re(),z(null),S(null),W(null),k(""),I(!1),F(null)),()=>{re()}),[s,me,re]);const pe=(b,U)=>{d(ne=>({...ne,[b]:U})),g(null),j(null)},ce=async()=>{try{g(null),j(null);const b=await _s({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 U=Qe(b);d(U),c(U),j(t("config:whatsapp.saved"))}catch(b){g(b instanceof Error?b.message:t("config:whatsapp.errors.saveFailed"))}},Le=()=>{d(r),g(null),j(null)},ge=()=>{if(we){A(!0);return}i()},$e=b=>{b.key==="Escape"&&(b.preventDefault(),ge())},De=async()=>{const b=m.trim();if(b)try{g(null),j(null),await Cs(b),k(""),I(!1),a(!0),j(t("config:whatsapp.apiKeySaved"))}catch(U){g(U instanceof Error?U.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},Ce=()=>{te(!0)},Fe=async()=>{try{g(null),j(null),await Is(),a(!1),j(t("config:whatsapp.apiKeyCleared"))}catch(b){g(b instanceof Error?b.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},Ne=l.useCallback(async b=>{if(Date.now()>Q.current){W(t("config:whatsapp.pairingTimeout")),z(null),S(null),re(),P();return}try{const U=await Ss(b);if(U.status&&["connected","paired","open","ready"].includes(U.status.toLowerCase())){W(t("config:whatsapp.pairingSuccess")),z(null),S(null),re(),P();return}const fe=U.qrUrl??U.qr??null;fe&&S(fe)}catch(U){W(U instanceof Error?U.message:t("config:whatsapp.errors.qrFetchFailed"))}J.current=setTimeout(()=>{Ne(b)},vt)},[P,re,t]),Ae=async()=>{const b=V.trim();if(b)try{g(null),j(null),W(null),S(null),re(),await As(b),w(""),z(b),Q.current=Date.now()+wt,Ne(b),P()}catch(U){g(U instanceof Error?U.message:t("config:whatsapp.errors.sessionCreateFailed"))}},Te=()=>{re(),z(null),S(null),W(null)},_e=b=>{ve(b),ae(!0)},Oe=async()=>{if(ue)try{g(null),j(null),await Es(ue),O===ue&&Te(),P(),j(t("config:whatsapp.sessionDeleted"))}catch(b){g(b instanceof Error?b.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{ve(null)}},Ie=async()=>{const b=N.trim(),U=B.trim();if(!(!b||!U))try{se(!0),F(null);const ne=o.defaultSessionId.trim()||void 0;await Ts(b,U,ne),F({kind:"success",text:t("config:whatsapp.testSent")})}catch(ne){F({kind:"error",text:ne instanceof Error?ne.message:t("config:whatsapp.errors.testSendFailed")})}finally{se(!1)}};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:ge,children:e.jsxs("div",{className:"whatsapp-config-modal",onClick:b=>b.stopPropagation(),onKeyDown:$e,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsapp.title")}),e.jsx("button",{className:"modal-close",onClick:ge,"aria-label":"Close",children:e.jsx(L,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:C?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsapp.description")}),p&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"warn",size:14})}),p]}),v&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"check",size:14})}),v]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.general")}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-enabled",className:"wa-label",children:t("config:whatsapp.enabled")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-enabled",type:"checkbox",checked:o.enabled,onChange:b=>pe("enabled",b.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-show-toasts",className:"wa-label",children:t("config:whatsapp.showIncomingToasts")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-show-toasts",type:"checkbox",checked:o.showIncomingToasts,onChange:b=>pe("showIncomingToasts",b.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.showIncomingToastsHelp")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-base-url",className:"wa-label",children:t("config:whatsapp.baseUrl")}),e.jsx("input",{id:"wa-base-url",type:"text",className:"wa-input",placeholder:"http://localhost:3007",value:o.baseUrl,onChange:b=>pe("baseUrl",b.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-default-session",className:"wa-label",children:t("config:whatsapp.defaultSessionId")}),e.jsx("input",{id:"wa-default-session",type:"text",className:"wa-input",placeholder:t("config:whatsapp.defaultSessionIdPlaceholder"),value:o.defaultSessionId,onChange:b=>pe("defaultSessionId",b.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-webhook-token",className:"wa-label",children:t("config:whatsapp.webhookVerifyToken")}),e.jsx("input",{id:"wa-webhook-token",type:"text",className:"wa-input",placeholder:t("config:whatsapp.webhookVerifyTokenPlaceholder"),value:o.webhookVerifyToken,onChange:b=>pe("webhookVerifyToken",b.target.value)})]})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.apiKey")}),e.jsx("div",{className:"wa-key-status",children:f?e.jsxs("span",{className:"wa-status wa-status-ok",children:[e.jsx(L,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(L,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:$?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:m,onChange:b=>k(b.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>I(b=>!b),title:t($?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(L,{name:$?"eye-closed":"eye",size:14})}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:De,disabled:!m.trim(),children:t("config:whatsapp.saveKey")}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:Ce,disabled:!f,children:t("config:whatsapp.clearKey")})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.apiKeyHint")})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.sessions")}),e.jsx("div",{className:"wa-sessions-list",children:!Array.isArray(x)||x.length===0?e.jsx("div",{className:"wa-empty",children:t("config:whatsapp.noSessions")}):x.map(b=>e.jsxs("div",{className:"wa-session-row",children:[e.jsxs("div",{className:"wa-session-info",children:[e.jsx("span",{className:"wa-session-id",children:b.id}),e.jsx("span",{className:`wa-session-status status-${(b.status??"unknown").toLowerCase()}`,children:b.status||"—"}),b.pairedNumber&&e.jsx("span",{className:"wa-session-paired",children:b.pairedNumber})]}),e.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:()=>_e(b.id),children:t("config:whatsapp.deleteSession")})]},b.id))}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:"text",className:"wa-input",placeholder:t("config:whatsapp.addSessionPlaceholder"),value:V,onChange:b=>w(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Ae()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ae,disabled:!V.trim()||O!==null,children:t("config:whatsapp.addSession")})]}),O&&e.jsxs("div",{className:"wa-qr-panel",children:[e.jsxs("div",{className:"wa-qr-header",children:[e.jsx("span",{children:t("config:whatsapp.qrPrompt",{id:O})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Te,children:t("config:whatsapp.cancelPairing")})]}),H?e.jsx("div",{className:"wa-qr-image",children:e.jsx("img",{src:H,alt:"WhatsApp pairing QR code"})}):e.jsxs("div",{className:"wa-qr-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.waitingForQr")})]})]}),R&&!O&&e.jsx("div",{className:"wa-pairing-message",children:R})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.testMessage")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-to",className:"wa-label",children:t("config:whatsapp.testTo")}),e.jsx("input",{id:"wa-test-to",type:"text",className:"wa-input",placeholder:t("config:whatsapp.testToPlaceholder"),value:N,onChange:b=>D(b.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-message",className:"wa-label",children:t("config:whatsapp.testMessageBody")}),e.jsx("textarea",{id:"wa-test-message",className:"wa-textarea",rows:4,placeholder:t("config:whatsapp.testMessageBodyPlaceholder"),value:B,onChange:b=>h(b.target.value)})]}),e.jsx("div",{className:"wa-field-inline wa-field-end",children:e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ie,disabled:!N.trim()||!B.trim()||ee,children:t(ee?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),E&&e.jsxs("div",{className:`alert ${E.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:E.kind==="success"?"check":"warn",size:14})}),E.text]})]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left"}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:ge,children:t("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:Le,disabled:!we||C,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:ce,disabled:!we||C,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(he,{isOpen:X,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{A(!1),i()},onClose:()=>A(!1)}),e.jsx(he,{isOpen:q,title:t("config:whatsapp.clearKey"),message:t("config:whatsapp.confirmClearKey"),confirmLabel:t("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Fe()},onClose:()=>te(!1)}),e.jsx(he,{isOpen:le,title:t("config:whatsapp.deleteSession"),message:t("config:whatsapp.confirmDeleteSession",{id:ue??""}),confirmLabel:t("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Oe()},onClose:()=>{ae(!1),ve(null)}})]}):null}const ls=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function He(s=!1){const i=oe(),t={};return i&&(t.Authorization=`Bearer ${i}`),s&&(t["Content-Type"]="application/json"),t}async function We(s,i){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${i}: ${s.statusText}`}async function kt(){const s=await fetch(`${Z()}/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 St(s){const i=await fetch(`${Z()}/api/whatsapp/notification-config`,{method:"PATCH",headers:He(!0),body:JSON.stringify(s)});if(!i.ok)throw new Error(await We(i,"Failed to update WhatsApp notification config"));return i.json()}async function Ct(){const s=await fetch(`${Z()}/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 Pe={messages:!0,statusChanges:!0,taskComplete:!0,errors:!0,planReady:!0,agentSpawned:!0,agentStopped:!0},es={filter:{...Pe},recipient:""};function At(s,i){if(s.recipient!==i.recipient)return!1;for(const t of ls)if(s.filter[t]!==i.filter[t])return!1;return!0}function Tt({isOpen:s,onClose:i}){const{t}=Y(["config"]),[o,d]=l.useState(es),[r,c]=l.useState(es),[f,a]=l.useState(!0),[x,y]=l.useState(null),[C,u]=l.useState(null),[p,g]=l.useState(!1),[v,j]=l.useState(!1),m=!At(o,r),k=l.useCallback(async()=>{try{a(!0),y(null),u(null);const S=await kt(),R={filter:{...Pe,...S.filter},recipient:S.recipient??""};d(R),c(R)}catch(S){y(S instanceof Error?S.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{a(!1)}},[t]);l.useEffect(()=>{s&&k()},[s,k]);const $=(S,R)=>{d(W=>({...W,filter:{...W.filter,[S]:R}})),y(null),u(null)},I=S=>{d(R=>({...R,recipient:S})),y(null),u(null)},V=async()=>{try{y(null),u(null);const S=await St({filter:o.filter,recipient:o.recipient.trim()}),R={filter:{...Pe,...S.filter},recipient:S.recipient??""};d(R),c(R),u(t("config:whatsappNotifications.saved"))}catch(S){y(S instanceof Error?S.message:t("config:whatsappNotifications.errors.saveFailed"))}},w=()=>{d(r),y(null),u(null)},O=async()=>{try{y(null),u(null);const S=await Ct(),R={filter:{...Pe,...S.filter},recipient:S.recipient??""};d(R),c(R),u(t("config:whatsappNotifications.resetDone"))}catch(S){y(S instanceof Error?S.message:t("config:whatsappNotifications.errors.resetFailed"))}},z=()=>{if(m){g(!0);return}i()},H=S=>{S.key==="Escape"&&(S.preventDefault(),z())};return s?e.jsxs(Se,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:z,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:S=>S.stopPropagation(),onKeyDown:H,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappNotifications.title")}),e.jsx("button",{className:"modal-close",onClick:z,"aria-label":"Close",children:e.jsx(L,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:f?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsappNotifications.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsappNotifications.description")}),x&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"warn",size:14})}),x]}),C&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(L,{name:"check",size:14})}),C]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.recipient")}),e.jsxs("div",{className:"wan-field",children:[e.jsx("label",{htmlFor:"wan-recipient",className:"wan-label",children:t("config:whatsappNotifications.recipientLabel")}),e.jsx("input",{id:"wan-recipient",type:"text",className:"wan-input",placeholder:t("config:whatsappNotifications.recipientPlaceholder"),value:o.recipient,onChange:S=>I(S.target.value)}),e.jsx("span",{className:"wan-hint",children:t("config:whatsappNotifications.recipientHint")})]})]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.events")}),e.jsx("p",{className:"wan-section-hint",children:t("config:whatsappNotifications.eventsHint")}),ls.map(S=>e.jsxs("div",{className:"wan-toggle-row",children:[e.jsxs("div",{className:"wan-toggle-info",children:[e.jsx("span",{className:"wan-toggle-title",children:t(`config:whatsappNotifications.events.${S}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${S}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:o.filter[S],onChange:R=>$(S,R.target.checked)}),e.jsx("span",{className:"wan-toggle-track",children:e.jsx("span",{className:"wan-toggle-thumb"})})]})]},S))]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:()=>j(!0),disabled:f,children:t("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:z,children:t("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:w,disabled:!m||f,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:V,disabled:!m||f,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(he,{isOpen:p,title:t("config:whatsappNotifications.unsavedTitle"),message:t("config:whatsappNotifications.unsavedMessage"),confirmLabel:t("config:whatsappNotifications.closeAnyway"),cancelLabel:t("config:whatsappNotifications.keepEditing"),variant:"danger",onConfirm:()=>{g(!1),i()},onClose:()=>g(!1)}),e.jsx(he,{isOpen:v,title:t("config:whatsappNotifications.resetToDefaults"),message:t("config:whatsappNotifications.confirmReset"),confirmLabel:t("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{O(),j(!1)},onClose:()=>j(!1)})]}):null}function cs(s){const i=s.replace(/@.*$/,"");return/^\d{10,15}$/.test(i)?i.startsWith("521")&&i.length===13?`+52 1 ${i.slice(3,5)} ${i.slice(5,9)} ${i.slice(9)}`:i.startsWith("52")&&i.length===12?`+52 ${i.slice(2,4)} ${i.slice(4,8)} ${i.slice(8)}`:i.startsWith("1")&&i.length===11?`+1 ${i.slice(1,4)} ${i.slice(4,7)} ${i.slice(7)}`:`+${i}`:s}function _t(s,i=Date.now()){const t=s*1e3,o=i-t;if(o<0)return ss(t);const d=Math.floor(o/6e4);if(d<1)return"now";if(d<60)return`${d}m`;const r=Math.floor(d/60);if(r<24)return`${r}h`;const c=Math.floor(r/24);return c===1?"yesterday":c<7?`${c}d`:ss(t)}function ss(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function It(s){const i=s*1e3;return new Date(i).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 Et(s,i){return s.length<=i?s:s.slice(0,Math.max(0,i-1)).trimEnd()+"…"}function Pt({chats:s,selectedChatId:i,loading:t,error:o,onSelect:d,onRefresh:r,now:c}){const{t:f}=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:f("config:whatsappHistory.chats")}),e.jsx("button",{type:"button",className:"whatsapp-history-chatlist__refresh",onClick:r,disabled:t,"aria-label":f("config:whatsappHistory.refresh"),title:f("config:whatsappHistory.refresh"),children:"⟳"})]}),o&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:o}),t&&s.length===0&&e.jsxs("div",{className:"whatsapp-history-chatlist__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:f("config:whatsappHistory.loadingChats")})]}),!t&&!o&&s.length===0&&e.jsx("div",{className:"whatsapp-history-chatlist__empty",children:f("config:whatsappHistory.emptyChats")}),e.jsx("ul",{className:"whatsapp-history-chatlist__items",children:s.map(a=>{const x=rs(a.lastMessageType),y=a.lastMessagePreview||`[${a.lastMessageType}]`,C=a.chatId===i,u=cs(a.chatId),p=a.isGroup?a.groupName:a.fromName,g=p||u,v=!!p&&p!==u;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${C?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>d(a.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:a.chatId,children:g}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:_t(a.lastTimestamp,c)})]}),v&&e.jsx("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--jid",children:e.jsx("span",{className:"whatsapp-history-chatlist__jid",children:u})}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[a.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),x&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[x," "]}),Et(y,40)]}),a.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:a.unreadCount})]})]})},a.chatId)})})]})}function Lt({message:s}){const i=s.direction==="outbound"?"outbound":"inbound",t=rs(s.messageType),o=(s.body??"").trim(),d=o.length>0,r=d?null:`[${s.messageType}]`;return e.jsx("div",{className:`whatsapp-history-bubble whatsapp-history-bubble--${i}`,children:e.jsxs("div",{className:"whatsapp-history-bubble__inner",children:[t&&e.jsx("span",{className:"whatsapp-history-bubble__type-icon",title:s.messageType,children:t}),d?e.jsx("span",{className:"whatsapp-history-bubble__body",children:o}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:r}),s.audioTranscription&&e.jsxs("span",{className:"whatsapp-history-bubble__transcription",children:["“",s.audioTranscription,"”"]}),s.mediaPath&&e.jsx("a",{className:"whatsapp-history-bubble__media-link",href:s.mediaPath,target:"_blank",rel:"noopener noreferrer",children:s.mediaFilename||"open media"}),e.jsx("span",{className:"whatsapp-history-bubble__time",children:It(s.timestamp)})]})})}const $t=["all","inbound","outbound"],Dt=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function Ft({direction:s,type:i,onDirectionChange:t,onTypeChange:o,disabled:d}){const{t:r}=Y(["config"]);return e.jsxs("div",{className:"whatsapp-history-filters",children:[e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:r("config:whatsappHistory.direction")}),e.jsx("select",{value:s,onChange:c=>t(c.target.value),disabled:d,children:$t.map(c=>e.jsx("option",{value:c,children:r(`config:whatsappHistory.directionValues.${c}`)},c))})]}),e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:r("config:whatsappHistory.type")}),e.jsx("select",{value:i,onChange:c=>o(c.target.value),disabled:d,children:Dt.map(c=>e.jsx("option",{value:c,children:r(`config:whatsappHistory.typeValues.${c}`)},c))})]})]})}const Ot=80;function Rt({chatId:s,messages:i,loading:t,loadingMore:o,error:d,hasMore:r,direction:c,type:f,onDirectionChange:a,onTypeChange:x,onLoadMore:y}){const{t:C}=Y(["config"]),u=l.useRef(null),p=l.useRef(null),g=l.useRef(!1),v=l.useRef(null);l.useEffect(()=>{p.current!==s&&(p.current=s,g.current=!1)},[s]),l.useLayoutEffect(()=>{u.current&&(g.current||i.length!==0&&(u.current.scrollTop=u.current.scrollHeight,g.current=!0))},[s,i.length]),l.useLayoutEffect(()=>{if(!u.current||v.current===null)return;const k=u.current.scrollHeight-v.current;v.current=null,k>0&&(u.current.scrollTop+=k)},[i.length]);const j=l.useCallback(()=>{!r||o||t||(u.current&&(v.current=u.current.scrollHeight),y())},[r,o,t,y]),m=l.useCallback(k=>{if(!g.current)return;k.currentTarget.scrollTop<=Ot&&j()},[j]);return s?e.jsxs("div",{className:"whatsapp-history-messages",children:[e.jsxs("div",{className:"whatsapp-history-messages__header",children:[e.jsx("div",{className:"whatsapp-history-messages__title",children:cs(s)}),e.jsx(Ft,{direction:c,type:f,onDirectionChange:a,onTypeChange:x,disabled:t})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:u,onScroll:m,children:[r&&e.jsx("div",{className:"whatsapp-history-messages__load-more-row",children:e.jsx("button",{type:"button",className:"whatsapp-history-messages__load-more",onClick:j,disabled:o||t,children:C(o?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),d&&e.jsx("div",{className:"whatsapp-history-messages__error",children:d}),t&&i.length===0&&e.jsxs("div",{className:"whatsapp-history-messages__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:C("config:whatsappHistory.loadingMessages")})]}),!t&&!d&&i.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:C("config:whatsappHistory.emptyMessages")}),i.map(k=>e.jsx(Lt,{message:k},Ut(k)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:C("config:whatsappHistory.selectChat")})})}function Ut(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=oe(),i={};return s&&(i.Authorization=`Bearer ${s}`),i}async function us(s,i){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${i}: ${s.statusText}`}async function zt(s){const i=`${Z()}/api/whatsapp/chats/${encodeURIComponent(s)}`,t=await fetch(i,{headers:ds()});if(!t.ok)throw new Error(await us(t,"Failed to fetch WhatsApp chats"));return t.json()}async function ts(s,i,t={}){const o=new URLSearchParams;t.cursor&&o.set("cursor",t.cursor),typeof t.limit=="number"&&o.set("limit",String(t.limit)),t.direction&&o.set("direction",t.direction),t.type&&o.set("type",t.type);const d=o.toString(),r=`${Z()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(i)}/messages${d?`?${d}`:""}`,c=await fetch(r,{headers:ds()});if(!c.ok)throw new Error(await us(c,"Failed to fetch WhatsApp messages"));return c.json()}const Mt=50;function Bt({isOpen:s,onClose:i}){const{t}=Y(["config"]),[o,d]=l.useState([]),[r,c]=l.useState(null),[f,a]=l.useState(null),[x,y]=l.useState([]),[C,u]=l.useState(!1),[p,g]=l.useState(null),[v,j]=l.useState(null),[m,k]=l.useState([]),[$,I]=l.useState(!1),[V,w]=l.useState(!1),[O,z]=l.useState(null),[H,S]=l.useState(null),[R,W]=l.useState("all"),[J,Q]=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{a(null);const[te,le]=await Promise.all([Be().catch(()=>[]),is().catch(()=>null)]);if(A)return;d(te);const ae=(le==null?void 0:le.defaultSessionId)||((q=te[0])==null?void 0:q.id)||null;c(ue=>ue??ae)}catch(te){if(A)return;a(te instanceof Error?te.message:String(te))}})(),()=>{A=!0}},[s]);const h=l.useCallback(async A=>{u(!0),g(null);try{const q=await zt(A);y(q.chats)}catch(q){g(q instanceof Error?q.message:String(q))}finally{u(!1)}},[]);l.useEffect(()=>{!s||!r||(j(null),k([]),S(null),h(r))},[s,r,h]);const E=l.useMemo(()=>{const A={limit:Mt};return R!=="all"&&(A.direction=R),J!=="all"&&(A.type=J),A},[R,J]),F=l.useCallback(async(A,q,te)=>{const le=++B.current;I(!0),z(null),k([]),S(null);try{const ae=await ts(A,q,te);if(le!==B.current)return;k([...ae.messages].reverse()),S(ae.nextCursor)}catch(ae){if(le!==B.current)return;z(ae instanceof Error?ae.message:String(ae))}finally{le===B.current&&I(!1)}},[]);l.useEffect(()=>{!s||!r||!v||F(r,v,E)},[s,r,v,E,F]);const ee=l.useCallback(async()=>{if(!(!r||!v||!H)){w(!0),z(null);try{const A=await ts(r,v,{...E,cursor:H});k(q=>[...[...A.messages].reverse(),...q]),S(A.nextCursor)}catch(A){z(A instanceof Error?A.message:String(A))}finally{w(!1)}}},[r,v,H,E]),se=l.useCallback(()=>{r&&h(r)},[r,h]),X=l.useCallback(A=>{A.key==="Escape"&&(A.preventDefault(),i())},[i]);return s?e.jsx(Se,{children:e.jsx("div",{className:"modal-overlay visible",onClick:i,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:A=>A.stopPropagation(),onKeyDown:X,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappHistory.title")}),e.jsx("div",{className:"whatsapp-history-modal__session",children:e.jsxs("label",{children:[e.jsx("span",{children:t("config:whatsappHistory.session")}),e.jsxs("select",{value:r??"",onChange:A=>c(A.target.value||null),disabled:o.length===0,children:[o.length===0&&e.jsx("option",{value:"",children:t("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:i,"aria-label":"Close",children:e.jsx(L,{name:"close",size:16})})]}),f&&e.jsx("div",{className:"whatsapp-history-modal__alert",children:f}),e.jsxs("div",{className:"whatsapp-history-modal__body",children:[e.jsx(Pt,{chats:x,selectedChatId:v,loading:C,error:p,onSelect:j,onRefresh:se,now:N}),e.jsx(Rt,{chatId:v,messages:m,loading:$,loadingMore:V,error:O,hasMore:H!==null,direction:R,type:J,onDirectionChange:W,onTypeChange:Q,onLoadMore:ee})]})]})})}):null}function Vt({isOpen:s,onClose:i,onOpenConfig:t,onOpenNotifications:o,onOpenHistory:d}){const{t:r}=Y(["config"]);if(l.useEffect(()=>{if(!s)return;const f=a=>{a.key==="Escape"&&(a.preventDefault(),i())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[s,i]),!s)return null;const c=f=>{i(),f()};return e.jsx(Se,{children:e.jsx("div",{className:"modal-overlay visible",onClick:i,children:e.jsxs("div",{className:"whatsapp-hub-modal",onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"whatsapp-hub-modal__icon",children:"📱"}),r("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:i,"aria-label":"Close",children:e.jsx(L,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"whatsapp-hub-modal__intro",children:r("config:whatsappHub.intro",{defaultValue:"Pick what you want to manage for the WhatsApp integration."})}),e.jsxs("div",{className:"whatsapp-hub-modal__options",children:[e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(t),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(L,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:r("config:whatsappHub.config",{defaultValue:"Integration config"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:r("config:whatsappHub.configDesc",{defaultValue:"Server URL, API key, sessions and pairing."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(o),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(L,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:r("config:whatsappHub.notifications",{defaultValue:"Notifications"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:r("config:whatsappHub.notificationsDesc",{defaultValue:"Which agent events get forwarded and to whom."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>c(d),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(L,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:r("config:whatsappHub.history",{defaultValue:"History"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:r("config:whatsappHub.historyDesc",{defaultValue:"Browse persisted chats and messages."})})]})]})]})]})]})})})}const Kt=[{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:"🌙"}],Ht=[{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:"🔴"}],Wt=[{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:"👎"}],qt=[{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:"💜"}],Gt=[{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"}],Yt=[{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"}],Jt={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},Zt={none:"grass","pokemon-stadium":"pokemon"},Xt={"emote-yes":"yes","emote-no":"no"},Qt={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function ie({checked:s,onChange:i}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:t=>i(t.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function be({options:s,value:i,onChange:t,iconOnly:o=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(d=>e.jsxs("button",{className:`chip ${i===d.value?"active":""}`,onClick:()=>t(d.value),title:d.label,children:[e.jsx("span",{className:"chip-icon",children:d.icon}),!o&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function _({text:s,query:i}){if(!i.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),o=i.toLowerCase(),d=t.indexOf(o);if(d===-1)return e.jsx(e.Fragment,{children:s});const r=s.slice(0,d),c=s.slice(d,d+i.length),f=s.slice(d+i.length);return e.jsxs(e.Fragment,{children:[r,e.jsx("mark",{className:"search-highlight",children:c}),f]})}const ea=[{id:"general",title:"General",keywords:["history","hide costs","grid","fps","power saving","performance","limit","editor","external editor","language","idioma","语言","vibration","haptic","intensity","tab title","tmux","process persistence","interactive","tui","terminal","experimental","claude"]},{id:"agentNames",title:"Agent Names",keywords:["agent","names","custom","characters","rename"]},{id:"defaultClass",title:"Default Spawn Class",keywords:["default","class","spawn","agent","scout","builder","random"]},{id:"appearance",title:"Appearance",keywords:["theme","appearance","color","dark","light","style","look"]},{id:"connection",title:"Connection",keywords:["backend","url","auth","token","reconnect","server","api","connect","codex","opencode","binary","path"]},{id:"scene",title:"Scene",keywords:["character","size","indicator","scale","time","dawn","day","dusk","night","auto"]},{id:"terrain",title:"Terrain",keywords:["trees","bushes","house","lamps","grass","clouds","fog","brightness","floor","sky","color","environment","battlefield","size","grid","simple","minimal","dark","clean"]},{id:"modelStyle",title:"Agent Model Style",keywords:["saturation","roughness","metalness","glow","emissive","reflections","wireframe","color mode","material","shader"]},{id:"animations",title:"Animations",keywords:["idle","working","animation","walk","run","sprint","jump","sit","crouch"]},{id:"secrets",title:"Secrets",keywords:["secrets","api","key","password","credentials","env","environment"]},{id:"systemPrompt",title:"System Prompt",keywords:["system","prompt","global","instructions","ai","agent","rules","guidelines"]},{id:"data",title:"Data",keywords:["export","import","backup","restore","save","load","json"]},{id:"integrations",title:"Integrations",keywords:["integrations","integraciones","plugins","gmail","slack","jira","calendar","docx","email","whatsapp","notifications","notification","baileys","history","historial","chat","messages","inbox","config","setup"]},{id:"workflows",title:"Workflows",keywords:["workflow","automation","state machine","editor","actions","transitions","pipeline"]},{id:"triggers",title:"Triggers",keywords:["trigger","event","webhook","cron","slack","email","jira","matching","fire"]},{id:"monitoring",title:"Monitoring",keywords:["monitoring","logs","triggers","events","history","workflow","traces","audit","timeline"]},{id:"statistics",title:"Statistics",keywords:["statistics","stats","usage","tokens","token","claude","chart","graph","pie","cost"]},{id:"experimental",title:"Experimental",keywords:["experimental","2d","view","voice","assistant","speech","tts","text to speech","echo","prompt","duplicate"]},{id:"about",title:"About",keywords:["about","version","update","credits","github","releases"]}],Me=[{value:"auto",label:"Auto",icon:"🌐"},{value:"en",label:"English",icon:"🇺🇸"},{value:"zh-CN",label:"中文",icon:"🇨🇳"},{value:"es",label:"Español",icon:"🇪🇸"},{value:"hi",label:"हिन्दी",icon:"🇮🇳"},{value:"pt",label:"Português",icon:"🇧🇷"},{value:"ru",label:"Русский",icon:"🇷🇺"},{value:"ja",label:"日本語",icon:"🇯🇵"},{value:"de",label:"Deutsch",icon:"🇩🇪"},{value:"fr",label:"Français",icon:"🇫🇷"},{value:"it",label:"Italiano",icon:"🇮🇹"}];function sa({config:s,onChange:i,searchQuery:t="",onOpenIntegrationsModal:o,onOpenMonitoringModal:d,onOpenStatisticsModal:r,onOpenWorkflowEditor:c,onOpenTriggerManager:f}){var qe;const{t:a}=Y(["config","common"]),x=Ve(),y=Ps(),[C,u]=l.useState(()=>Ls(ye.DEFAULT_AGENT_CLASS)||"scout"),[p,g]=l.useState(x.settings.historyLimit),[v,j]=l.useState(()=>$s()),[m,k]=l.useState(!1),[$,I]=l.useState(""),[V,w]=l.useState(()=>oe()),[O,z]=l.useState(!1),[H,S]=l.useState(!1),[R,W]=l.useState(""),[J,Q]=l.useState(!1),[N,D]=l.useState(!1),[B,h]=l.useState(!1),[E,F]=l.useState(!1),[ee,se]=l.useState(!1),[X,A]=l.useState(""),[q,te]=l.useState(!1);l.useEffect(()=>{tt().then(A).catch(()=>{})},[]),l.useEffect(()=>{et().then(n=>{n!==x.settings.experimentalEchoPrompt&&T.updateSettings({experimentalEchoPrompt:n})}).catch(()=>{})},[]),l.useEffect(()=>{nt().then(n=>{n!==x.settings.tmuxMode&&T.updateSettings({tmuxMode:n})}).catch(()=>{})},[]),l.useEffect(()=>{ot().then(n=>{n!==x.settings.interactiveMode&&T.updateSettings({interactiveMode:n})}).catch(()=>{})},[]),l.useEffect(()=>Ds(n=>{j(n),k(!1)}),[]);const le=Kt.map(n=>({...n,label:a(`config:time.${n.value}`)})),ae=Ht.map(n=>({...n,label:a(`config:floor.${Zt[n.value]||n.value}`)})),ue=Wt.map(n=>({...n,label:a(`config:animation.${Xt[n.value]||n.value}`)})),ve=qt.map(n=>({...n,label:a(`config:colorMode.${n.value}`)})),we=Gt.map(n=>({...n,label:a(`config:terrain.${Jt[n.key]}`)})),re=Yt.map(n=>({...n,label:a(`config:sky.${Qt[n.value??""]}`)})),me=t.trim()?ea.filter(n=>{const M=t.toLowerCase();return n.title.toLowerCase().includes(M)||n.keywords.some(de=>de.toLowerCase().includes(M))}).map(n=>n.id):null,P=n=>me?me.includes(n):!0,pe=P("integrations"),ce=x.settings.customAgentNames||[],Le=ce.length>0?ce:Fs,ge=()=>{const n=R.trim();n&&!ce.includes(n)&&(T.updateSettings({customAgentNames:[...ce,n]}),W(""))},$e=n=>{T.updateSettings({customAgentNames:ce.filter(M=>M!==n)})},De=()=>{T.updateSettings({customAgentNames:[]})},Ce=()=>{const n=$.trim();if(n){if(v.includes(n)){I("");return}j([...v,n]),k(!0),I("")}},Fe=n=>{j(v.filter((M,de)=>de!==n)),k(!0)},Ne=(n,M)=>{const de=n+M;if(de<0||de>=v.length)return;const xe=v.slice();[xe[n],xe[de]]=[xe[de],xe[n]],j(xe),k(!0)},Ae=()=>{Rs(v),k(!1),ze()},Te=n=>{w(n),z(!0)},_e=()=>{Ee(ye.AUTH_TOKEN,V),z(!1),ze()},Oe=n=>{A(n),te(!0)},Ie=()=>{at(X).catch(()=>{}),te(!1)},b=n=>{i({...s,terrain:{...s.terrain,...n}})},U=n=>{i({...s,modelStyle:{...s.modelStyle,...n}})},ne=n=>{i({...s,animations:{...s.animations,...n}})},fe=n=>{g(n),T.updateSettings({historyLimit:n})},ps=n=>{const M=s.terrain[n];typeof M=="boolean"&&b({[n]:!M})},G=t.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[me&&me.length===0&&e.jsx("div",{className:"config-no-results",children:a("config:noResults",{query:t})}),P("general")&&e.jsxs(K,{title:a("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(_,{text:a("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:p,onChange:n=>fe(parseInt(n.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(_,{text:a("config:general.hideCosts"),query:t})}),e.jsx(ie,{checked:x.settings.hideCost,onChange:n=>T.updateSettings({hideCost:n})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:general.grid"),query:t})}),e.jsx(ie,{checked:s.gridVisible,onChange:n=>i({...s,gridVisible:n})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:general.showFPS"),query:t})}),e.jsx(ie,{checked:x.settings.showFPS,onChange:n=>T.updateSettings({showFPS:n})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:general.fpsLimit"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:n=>i({...s,fpsLimit:parseInt(n.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(_,{text:a("config:general.powerSaving"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ie,{checked:x.settings.powerSaving,onChange:n=>T.updateSettings({powerSaving:n})})]}),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(_,{text:a("config:general.tmuxMode"),query:t})}),e.jsx(ie,{checked:x.settings.tmuxMode,onChange:async n=>{T.updateSettings({tmuxMode:n});try{await it(n)}catch(M){console.error("Failed to sync tmux mode setting to server:",M)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Claude agents as the real interactive `claude` TUI inside tmux, reconstructing the conversation from the session transcript (requires tmux). Takes effect on server restart.",children:[e.jsx(_,{text:a("config:general.interactiveMode"),query:t})," ",e.jsx(L,{name:"bolt",size:12})]}),e.jsx(ie,{checked:x.settings.interactiveMode,onChange:async n=>{T.updateSettings({interactiveMode:n});try{await lt(n)}catch(M){console.error("Failed to sync interactive mode setting to server:",M)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:general.vibrationIntensity"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:x.settings.vibrationIntensity,onChange:n=>T.updateSettings({vibrationIntensity:parseInt(n.target.value)})}),e.jsx("span",{className:"config-value",children:x.settings.vibrationIntensity===0?a("config:vibrationValues.off"):x.settings.vibrationIntensity===1?a("config:vibrationValues.ultraLight"):x.settings.vibrationIntensity===2?a("config:vibrationValues.veryLight"):x.settings.vibrationIntensity===3?a("config:vibrationValues.light"):x.settings.vibrationIntensity===4?a("config:vibrationValues.medium"):a("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:general.externalEditor"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:a("config:general.externalEditorPlaceholder"),value:x.settings.externalEditorCommand||"",onChange:n=>T.updateSettings({externalEditorCommand:n.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:general.tabTitle"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:a("config:general.tabTitlePlaceholder"),value:x.settings.tabTitle||"",onChange:n=>T.updateSettings({tabTitle:n.target.value})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:general.language"),query:t})}),e.jsx(be,{options:Me,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((qe=Me.find(n=>n.value!=="auto"&&Ue.language.startsWith(n.value.split("-")[0])))==null?void 0:qe.value)||"en":"auto",onChange:n=>{var M;if(n==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const de=navigator.language,xe=((M=Me.find(Ge=>Ge.value!=="auto"&&de.startsWith(Ge.value.split("-")[0])))==null?void 0:M.value)||"en";Ue.changeLanguage(xe)}else localStorage.setItem("tide-commander-language-mode","manual"),Ue.changeLanguage(n)}})]})]}),P("agentNames")&&e.jsx(K,{title:a("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:ce.length>0?a("config:agentNames.customConfigured",{count:ce.length}):a("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:a("config:agentNames.addPlaceholder"),value:R,onChange:n=>W(n.target.value),onKeyDown:n=>{n.key==="Enter"&&ge()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ge,disabled:!R.trim(),title:a("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:Le.map((n,M)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:n}),ce.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>$e(n),title:a("common:buttons.remove"),children:"x"})]},`${n}-${M}`))}),ce.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:De,children:a("common:buttons.resetToDefaults")})]})}),P("defaultClass")&&e.jsx(K,{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${C==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{u("random"),Ee(ye.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(Os).map(([n,M])=>e.jsx("div",{className:`agent-name-chip${C===n?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{u(n),Ee(ye.DEFAULT_AGENT_CLASS,n)},children:e.jsxs("span",{className:"agent-name-text",children:[M.icon," ",n.charAt(0).toUpperCase()+n.slice(1)]})},n)),y.map(n=>e.jsx("div",{className:`agent-name-chip${C===n.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{u(n.id),Ee(ye.DEFAULT_AGENT_CLASS,n.id)},children:e.jsxs("span",{className:"agent-name-text",children:[n.icon," ",n.name]})},n.id))]})]})}),P("appearance")&&e.jsx(K,{title:a("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:G&&P("appearance"),children:e.jsx(mt,{})}),P("connection")&&e.jsxs(K,{title:a("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(_,{text:a("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:v.map((n,M)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:a("config:connection.priorityLabel",{defaultValue:"Priority"}),children:M+1}),e.jsx("span",{className:"backend-url-text",title:n,children:n}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ne(M,-1),disabled:M===0,title:a("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Ne(M,1),disabled:M===v.length-1,title:a("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Fe(M),title:a("common:buttons.remove"),children:"x"})]},`${n}-${M}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:$,onChange:n=>I(n.target.value),placeholder:a("config:connection.addUrlPlaceholder",{defaultValue:"http://host:port"}),onKeyDown:n=>{n.key==="Enter"&&Ce()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ce,disabled:!$.trim(),title:a("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),m&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ae,title:a("config:connection.saveAndReconnect"),children:a("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:a("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(_,{text:a("config:connection.authToken"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:H?"text":"password",className:"config-input config-input-full",value:V,onChange:n=>Te(n.target.value),placeholder:a("config:connection.tokenPlaceholder"),onKeyDown:n=>{n.key==="Enter"&&O&&_e()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>S(!H),title:a(H?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(L,{name:H?"eye-closed":"eye",size:14})}),O&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:_e,title:a("config:connection.saveAndReconnect"),children:a("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:a("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:connection.codexBinaryPath"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:X,onChange:n=>Oe(n.target.value),placeholder:a("config:connection.codexBinaryPathPlaceholder"),onKeyDown:n=>{n.key==="Enter"&&q&&Ie()}}),q&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Ie,children:a("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:a("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("common:buttons.reconnect"),query:t})}),e.jsx("button",{className:"config-btn",onClick:()=>ze(),title:"Force reconnect to server",children:a("common:buttons.reconnect")})]})]}),P("scene")&&e.jsxs(K,{title:a("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(_,{text:a("config:scene.characterSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"3.0",step:"0.1",value:s.characterScale,onChange:n=>i({...s,characterScale:parseFloat(n.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(_,{text:a("config:scene.scale2d",{defaultValue:"2D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale2d,onChange:n=>i({...s,scale2d:parseFloat(n.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(_,{text:a("config:scene.scale3d",{defaultValue:"3D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale3d,onChange:n=>i({...s,scale3d:parseFloat(n.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(_,{text:a("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:t})}),e.jsx(ie,{checked:s.show2DTaskLabels,onChange:n=>i({...s,show2DTaskLabels:n})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:scene.time"),query:t})}),e.jsx(be,{options:le,value:s.timeMode,onChange:n=>i({...s,timeMode:n}),iconOnly:!0})]})]}),P("terrain")&&e.jsxs(K,{title:a("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(_,{text:a("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:t})}),e.jsx(ie,{checked:s.terrain.simpleMode??!1,onChange:n=>b({simpleMode:n})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:we.map(n=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[n.key]?"active":""}`,onClick:()=>ps(n.key),title:n.label,children:n.icon},n.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:terrainSettings.fog"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.terrain.fogDensity,onChange:n=>b({fogDensity:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?a("config:fogValues.off"):s.terrain.fogDensity<=1?a("config:fogValues.low"):a("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:terrainSettings.brightness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.2",max:"2",step:"0.1",value:s.terrain.brightness,onChange:n=>b({brightness:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?a("config:brightnessValues.dark"):s.terrain.brightness<=1.2?a("config:brightnessValues.normal"):a("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:terrainSettings.floor"),query:t})}),e.jsx(be,{options:ae,value:s.terrain.floorStyle,onChange:n=>b({floorStyle:n}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:terrainSettings.sky"),query:t})}),e.jsx("div",{className:"sky-color-selector",children:re.map(n=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===n.value?"active":""}`,onClick:()=>b({skyColor:n.value}),title:n.label,style:{background:n.color}},n.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:terrainSettings.battlefieldSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:n=>b({battlefieldSize:parseInt(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),P("modelStyle")&&e.jsxs(K,{title:a("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(_,{text:a("config:modelStyleSettings.saturation"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.modelStyle.saturation,onChange:n=>U({saturation:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?a("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?a("config:saturationValues.normal"):a("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:modelStyleSettings.roughness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.roughness,onChange:n=>U({roughness:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?a("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?a("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?a("config:roughnessValues.normal"):a("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:modelStyleSettings.metalness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.metalness,onChange:n=>U({metalness:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?a("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?a("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?a("config:metalnessValues.mixed"):a("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:modelStyleSettings.glow"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"1",step:"0.05",value:s.modelStyle.emissiveBoost,onChange:n=>U({emissiveBoost:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?a("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?a("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?a("config:glowValues.med"):a("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:modelStyleSettings.reflections"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"2",step:"0.1",value:s.modelStyle.envMapIntensity,onChange:n=>U({envMapIntensity:parseFloat(n.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?a("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?a("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?a("config:reflectionValues.normal"):a("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:modelStyleSettings.wireframe"),query:t})}),e.jsx(ie,{checked:s.modelStyle.wireframe,onChange:n=>U({wireframe:n})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:modelStyleSettings.colorMode"),query:t})}),e.jsx(be,{options:ve,value:s.modelStyle.colorMode,onChange:n=>U({colorMode:n}),iconOnly:!0})]})]}),P("animations")&&e.jsxs(K,{title:a("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(_,{text:a("config:animationSettings.idle"),query:t})}),e.jsx(be,{options:ue,value:s.animations.idleAnimation,onChange:n=>ne({idleAnimation:n}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(_,{text:a("config:animationSettings.working"),query:t})}),e.jsx(be,{options:ue,value:s.animations.workingAnimation,onChange:n=>ne({workingAnimation:n}),iconOnly:!0})]})]}),P("secrets")&&e.jsx(K,{title:a("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:G&&P("secrets"),children:e.jsx(Qs,{})}),P("systemPrompt")&&e.jsx(K,{title:a("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(_,{text:a("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>Q(!0),children:a("config:systemPrompt.editPrompt")})]})}),P("data")&&e.jsx(K,{title:a("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:G&&P("data"),children:e.jsx(ut,{})}),pe&&e.jsx(K,{title:a("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:G&&pe,children:e.jsx(bt,{onOpenModal:n=>{n==="whatsapp"?se(!0):o==null||o(n)}})}),P("workflows")&&e.jsxs(K,{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(_,{text:"Create and manage automated workflow pipelines with visual state machine editor",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>c==null?void 0:c(),children:"Open Workflow Editor"})})]}),P("triggers")&&e.jsxs(K,{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(_,{text:"Create and manage event-driven triggers that fire agents with templates",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>f==null?void 0:f(),children:"Open Trigger Manager"})})]}),P("monitoring")&&e.jsxs(K,{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(_,{text:"View event logs, trigger history, workflow traces, and system stats",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>d==null?void 0:d(),children:"Open Monitoring & Logs"})})]}),P("statistics")&&e.jsxs(K,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:G&&P("statistics"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(_,{text:"View token usage charts and system-wide agent statistics",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>r==null?void 0:r(),children:"Open Statistics"})})]}),P("experimental")&&e.jsxs(K,{title:a("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(_,{text:a("config:experimental.2dView"),query:t})," ",e.jsx(L,{name:"map",size:12})]}),e.jsx(ie,{checked:x.settings.experimental2DView,onChange:n=>T.updateSettings({experimental2DView:n})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(_,{text:a("config:experimental.voiceAssistant"),query:t})," ",e.jsx(L,{name:"microphone",size:12})]}),e.jsx(ie,{checked:x.settings.experimentalVoiceAssistant,onChange:n=>T.updateSettings({experimentalVoiceAssistant:n})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(_,{text:a("config:experimental.tts"),query:t})," ",e.jsx(L,{name:"speaker-on",size:12})]}),e.jsx(ie,{checked:x.settings.experimentalTTS,onChange:n=>T.updateSettings({experimentalTTS:n})})]}),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(_,{text:a("config:experimental.echoPrompt"),query:t})}),e.jsx(ie,{checked:x.settings.experimentalEchoPrompt,onChange:async n=>{T.updateSettings({experimentalEchoPrompt:n});try{await st(n)}catch(M){console.error("Failed to sync echo prompt setting to server:",M)}}})]}),e.jsx("span",{className:"config-hint",children:a("config:experimental.hint")})]}),P("about")&&e.jsx(K,{title:a("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:G&&P("about"),children:e.jsx(ft,{})})]}),e.jsx(jt,{isOpen:J,onClose:()=>Q(!1)}),e.jsx(yt,{isOpen:N,onClose:()=>D(!1)}),e.jsx(Tt,{isOpen:B,onClose:()=>h(!1)}),e.jsx(Bt,{isOpen:E,onClose:()=>F(!1)}),e.jsx(Vt,{isOpen:ee,onClose:()=>se(!1),onOpenConfig:()=>D(!0),onOpenNotifications:()=>h(!0),onOpenHistory:()=>F(!0)})]})}function oa({onConfigChange:s,onToolChange:i,config:t,isOpen:o,onClose:d,onOpenBuildingModal:r,onOpenAreaExplorer:c,onOpenIntegrationsModal:f,onOpenMonitoringModal:a,onOpenStatisticsModal:x,onOpenWorkflowEditor:y,onOpenTriggerManager:C}){const{t:u}=Y(["config","common"]),p=Ve(),g=Array.from(p.areas.values()),v=Array.from(p.buildings.values()),[j,m]=l.useState(""),k=l.useRef(null);if(l.useEffect(()=>{const w=O=>{O.key==="Escape"&&o&&d()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[o,d]),l.useEffect(()=>{if(o&&k.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const O=setTimeout(()=>{var z;(z=k.current)==null||z.focus()},50);return()=>clearTimeout(O)}},[o]),!o)return null;const $=w=>{const O=p.activeTool===w?null:w;i(O)},I=w=>{T.selectArea(p.selectedAreaId===w?null:w),i("select")},V=(w,O)=>{w.stopPropagation(),T.deleteArea(O)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:d}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:u("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:u("common:buttons.close"),children:"×"})]}),e.jsxs("div",{className:"toolbox-search",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{ref:k,type:"text",placeholder:u("config:searchPlaceholder"),value:j,onChange:w=>m(w.target.value),className:"toolbox-search-input"}),j&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>m(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(K,{title:u("config:areas.title",{count:g.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${p.activeTool==="select"?"active":""}`,onClick:()=>$("select"),title:u("config:tools.select"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"})})})}),e.jsx("button",{className:`tool-btn ${p.activeTool==="rectangle"?"active":""}`,onClick:()=>$("rectangle"),title:u("config:tools.rectangle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"})})})}),e.jsx("button",{className:`tool-btn ${p.activeTool==="circle"?"active":""}`,onClick:()=>$("circle"),title:u("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:g.length===0?e.jsx("div",{className:"areas-empty",children:u("config:areas.drawToCreate")}):g.map(w=>e.jsx(Gs,{area:w,isSelected:p.selectedAreaId===w.id,onClick:()=>I(w.id),onDelete:O=>V(O,w.id)},w.id))})]})}),p.selectedAreaId&&e.jsx(Xs,{area:p.areas.get(p.selectedAreaId),onClose:()=>T.selectArea(null),onOpenFolder:c}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(K,{title:u("config:buildings.title",{count:v.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:w=>{w.stopPropagation(),r==null||r()},title:u("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:v.length===0?e.jsx("div",{className:"buildings-empty",children:u("config:buildings.clickToAdd")}):v.map(w=>e.jsx(Ys,{building:w,isSelected:p.selectedBuildingIds.has(w.id),onClick:()=>{T.selectBuilding(p.selectedBuildingIds.has(w.id)?null:w.id)},onEdit:()=>r==null?void 0:r(w.id)},w.id))})})}),p.selectedBuildingIds.size===1&&(()=>{const w=Array.from(p.selectedBuildingIds)[0],O=p.buildings.get(w);return O?e.jsx(Js,{building:O,onClose:()=>T.selectBuilding(null),onOpenModal:()=>r==null?void 0:r(w)}):null})(),e.jsx(sa,{config:t,onChange:s,searchQuery:j,onOpenIntegrationsModal:f,onOpenMonitoringModal:a,onOpenStatisticsModal:x,onOpenWorkflowEditor:y,onOpenTriggerManager:C})]})]})]})}export{oa as Toolbox};
|