tmex-cli 0.16.1 → 0.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +10 -60
  2. package/dist/runtime/server.js +972 -330
  3. package/package.json +1 -1
  4. package/resources/fe-dist/assets/DevicePage-DtByPprm.js +24 -0
  5. package/resources/fe-dist/assets/{DevicesPage-sJHXbS_f.js → DevicesPage-WMW0FcaU.js} +1 -1
  6. package/resources/fe-dist/assets/{FilePage-7FFd1YcW.js → FilePage-C3yjgRDh.js} +1 -1
  7. package/resources/fe-dist/assets/SettingsPage-CKZEPwEq.js +39 -0
  8. package/resources/fe-dist/assets/agent-tab-B77EotmX.js +38 -0
  9. package/resources/fe-dist/assets/{api-DV7-9Pvt.js → api-DZDjPn8l.js} +1 -1
  10. package/resources/fe-dist/assets/{arc-PDHKfnGP.js → arc-DNrUdLWP.js} +1 -1
  11. package/resources/fe-dist/assets/{architectureDiagram-3BPJPVTR-BiPHTh1e.js → architectureDiagram-3BPJPVTR-B5DYf-5o.js} +1 -1
  12. package/resources/fe-dist/assets/{blockDiagram-GPEHLZMM-DP_BRHKg.js → blockDiagram-GPEHLZMM-DSgjcUbw.js} +1 -1
  13. package/resources/fe-dist/assets/{c4Diagram-AAUBKEIU-D16QYgyT.js → c4Diagram-AAUBKEIU-DKjqulHT.js} +1 -1
  14. package/resources/fe-dist/assets/{card-DmfNw0hd.js → card-DWQzPt-3.js} +1 -1
  15. package/resources/fe-dist/assets/channel-CpZANba-.js +1 -0
  16. package/resources/fe-dist/assets/{chunk-2J33WTMH-DOjtL7ww.js → chunk-2J33WTMH-DHQ_-AlN.js} +1 -1
  17. package/resources/fe-dist/assets/{chunk-4BX2VUAB-BbT67ZXa.js → chunk-4BX2VUAB-C7sszhBq.js} +1 -1
  18. package/resources/fe-dist/assets/{chunk-55IACEB6-CnnXwmY_.js → chunk-55IACEB6-BkPT2okv.js} +1 -1
  19. package/resources/fe-dist/assets/{chunk-727SXJPM-TyUdLEW5.js → chunk-727SXJPM-BsD5c54G.js} +1 -1
  20. package/resources/fe-dist/assets/{chunk-AQP2D5EJ-BMpK4dqa.js → chunk-AQP2D5EJ-Dx3mc4xO.js} +1 -1
  21. package/resources/fe-dist/assets/{chunk-FMBD7UC4-Dx0HVCZZ.js → chunk-FMBD7UC4-CyZO-UAp.js} +1 -1
  22. package/resources/fe-dist/assets/{chunk-ND2GUHAM-BQCoMEti.js → chunk-ND2GUHAM-DNxRBeA7.js} +1 -1
  23. package/resources/fe-dist/assets/{chunk-QZHKN3VN-ilmf5OgK.js → chunk-QZHKN3VN-DsPa138W.js} +1 -1
  24. package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-BW09ep_0.js +1 -0
  25. package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-BW09ep_0.js +1 -0
  26. package/resources/fe-dist/assets/{copy-Ct5TNzGp.js → copy-DwXKDgGT.js} +1 -1
  27. package/resources/fe-dist/assets/{cose-bilkent-S5V4N54A-CpWhM7Za.js → cose-bilkent-S5V4N54A-C1d180_v.js} +1 -1
  28. package/resources/fe-dist/assets/{dagre-BM42HDAG-CWJttTzC.js → dagre-BM42HDAG-Bv8hvnH7.js} +1 -1
  29. package/resources/fe-dist/assets/{diagram-2AECGRRQ-BD8ny_Yg.js → diagram-2AECGRRQ-DfbJBHI6.js} +1 -1
  30. package/resources/fe-dist/assets/{diagram-5GNKFQAL-CeHcPWRz.js → diagram-5GNKFQAL-COnOrAiu.js} +1 -1
  31. package/resources/fe-dist/assets/{diagram-KO2AKTUF-tVlrBE8C.js → diagram-KO2AKTUF-BOtU5EdV.js} +1 -1
  32. package/resources/fe-dist/assets/{diagram-LMA3HP47-DGUn-oQn.js → diagram-LMA3HP47-B-WcT-Mc.js} +1 -1
  33. package/resources/fe-dist/assets/{diagram-OG6HWLK6-xKCd1kwA.js → diagram-OG6HWLK6-BptGbu0F.js} +1 -1
  34. package/resources/fe-dist/assets/en_US-BihUhDmr.js +1 -0
  35. package/resources/fe-dist/assets/{erDiagram-TEJ5UH35-C6M5qkGl.js → erDiagram-TEJ5UH35-H06uoCHU.js} +1 -1
  36. package/resources/fe-dist/assets/{files-tab-BWkYfaye.js → files-tab-C841Mmn_.js} +1 -1
  37. package/resources/fe-dist/assets/{flowDiagram-I6XJVG4X-D0MZDHnB.js → flowDiagram-I6XJVG4X-QOk_IVWN.js} +1 -1
  38. package/resources/fe-dist/assets/{ganttDiagram-6RSMTGT7-YeduSSa_.js → ganttDiagram-6RSMTGT7-Q7s2jHyi.js} +1 -1
  39. package/resources/fe-dist/assets/{gitGraphDiagram-PVQCEYII-Nem1Mvvg.js → gitGraphDiagram-PVQCEYII-Q7tAtx1u.js} +1 -1
  40. package/resources/fe-dist/assets/{index-iee3U_rD.js → index-C2v9tHtI.js} +1 -1
  41. package/resources/fe-dist/assets/{index-B3ddLSja.js → index-Dc3Fwpho.js} +63 -63
  42. package/resources/fe-dist/assets/index-j9kTGUS5.css +1 -0
  43. package/resources/fe-dist/assets/{infoDiagram-5YYISTIA-Bh6bbh_V.js → infoDiagram-5YYISTIA-B9n7MrtF.js} +1 -1
  44. package/resources/fe-dist/assets/{ishikawaDiagram-YF4QCWOH-CsZHu48j.js → ishikawaDiagram-YF4QCWOH-oZeau8IS.js} +1 -1
  45. package/resources/fe-dist/assets/ja_JP-f5sXmz8W.js +1 -0
  46. package/resources/fe-dist/assets/{journeyDiagram-JHISSGLW-CPgnovXt.js → journeyDiagram-JHISSGLW-ClXjUmc1.js} +1 -1
  47. package/resources/fe-dist/assets/{kanban-definition-UN3LZRKU-D4OAuDsS.js → kanban-definition-UN3LZRKU-Cwn4VzH2.js} +1 -1
  48. package/resources/fe-dist/assets/{linear-CcA4wV7f.js → linear-BNOQBDiB.js} +1 -1
  49. package/resources/fe-dist/assets/{markdown-preview-CBGlxpTs.js → markdown-preview-BsYVAcJ1.js} +3 -3
  50. package/resources/fe-dist/assets/{mermaid.core-D-CshtYr.js → mermaid.core-C3nmuA6R.js} +5 -5
  51. package/resources/fe-dist/assets/{mindmap-definition-RKZ34NQL-DBpI1nMC.js → mindmap-definition-RKZ34NQL-BKstxajf.js} +1 -1
  52. package/resources/fe-dist/assets/{pieDiagram-4H26LBE5-D4kh0_Y0.js → pieDiagram-4H26LBE5-D_2bHoC9.js} +1 -1
  53. package/resources/fe-dist/assets/{quadrantDiagram-W4KKPZXB-DNw3oGHQ.js → quadrantDiagram-W4KKPZXB-D6K_QmUy.js} +1 -1
  54. package/resources/fe-dist/assets/{requirementDiagram-4Y6WPE33-DqtMaND0.js → requirementDiagram-4Y6WPE33-B1SWUDkA.js} +1 -1
  55. package/resources/fe-dist/assets/{sankeyDiagram-5OEKKPKP-D-m9Pyie.js → sankeyDiagram-5OEKKPKP-DPmalO0b.js} +1 -1
  56. package/resources/fe-dist/assets/{send-DaOB9hLq.js → send-J45szXFM.js} +1 -1
  57. package/resources/fe-dist/assets/{sequenceDiagram-3UESZ5HK-CjrimNJf.js → sequenceDiagram-3UESZ5HK-C08DcZug.js} +1 -1
  58. package/resources/fe-dist/assets/{stateDiagram-AJRCARHV-BT5d8Z8W.js → stateDiagram-AJRCARHV-K9bVAVhg.js} +1 -1
  59. package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-DTGkSC6X.js +1 -0
  60. package/resources/fe-dist/assets/{terminal-settings-panel-DDhlnbRH.js → terminal-settings-panel-tZuaqdqz.js} +2 -2
  61. package/resources/fe-dist/assets/{timeline-definition-PNZ67QCA-BeocAFDX.js → timeline-definition-PNZ67QCA-DG0FtOvK.js} +1 -1
  62. package/resources/fe-dist/assets/{transfer-toast-DXl4RHsV.js → transfer-toast-D72q4082.js} +1 -1
  63. package/resources/fe-dist/assets/{triangle-alert-FQRTtbTP.js → triangle-alert-CagsqsWp.js} +1 -1
  64. package/resources/fe-dist/assets/{vennDiagram-CIIHVFJN-CYlmUB5_.js → vennDiagram-CIIHVFJN-CKBEKUkA.js} +1 -1
  65. package/resources/fe-dist/assets/{wardley-L42UT6IY-CTyaodt9.js → wardley-L42UT6IY-DTlpnptg.js} +1 -1
  66. package/resources/fe-dist/assets/{wardleyDiagram-YWT4CUSO-DNlEcEwQ.js → wardleyDiagram-YWT4CUSO-CnwEikRb.js} +1 -1
  67. package/resources/fe-dist/assets/{xychartDiagram-2RQKCTM6-7Zi-6P-I.js → xychartDiagram-2RQKCTM6-uaYRX4Ue.js} +1 -1
  68. package/resources/fe-dist/assets/{zap-BFIAXPXd.js → zap-DcJ8Gp1I.js} +1 -1
  69. package/resources/fe-dist/assets/zh_CN-CPdvelFW.js +1 -0
  70. package/resources/fe-dist/index.html +2 -2
  71. package/resources/gateway-drizzle/0012_naive_lizard.sql +8 -0
  72. package/resources/gateway-drizzle/0013_bored_blindfold.sql +1 -0
  73. package/resources/gateway-drizzle/0014_lucky_killraven.sql +1 -0
  74. package/resources/gateway-drizzle/meta/_journal.json +21 -0
  75. package/resources/fe-dist/assets/DevicePage-Ccz8gNji.js +0 -24
  76. package/resources/fe-dist/assets/SettingsPage-FrEtqZyI.js +0 -39
  77. package/resources/fe-dist/assets/agent-tab-9THUj7Cf.js +0 -38
  78. package/resources/fe-dist/assets/channel-Dzz9b4fW.js +0 -1
  79. package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-BB9_4XLL.js +0 -1
  80. package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-BB9_4XLL.js +0 -1
  81. package/resources/fe-dist/assets/en_US-CjVU4anP.js +0 -1
  82. package/resources/fe-dist/assets/index-CuFTSN9i.css +0 -1
  83. package/resources/fe-dist/assets/ja_JP-Bq-BwOH_.js +0 -1
  84. package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-kSh9IuUW.js +0 -1
  85. package/resources/fe-dist/assets/zh_CN-BuxyXhCT.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmex-cli",
3
- "version": "0.16.1",
3
+ "version": "0.16.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "tmex": "./bin/tmex.js",
@@ -0,0 +1,24 @@
1
+ import{Y as qe,u as Ie,j as i,aD as jt,aE as Ct,aF as Nt,aG as Pt,aH as kt,at as It,r as n,d as H,af as ge,ai as ut,ah as dt,ag as Mt,aj as Lt,aI as At,aJ as _t,o as Le,aK as zt,D as Dt,p as $t,q as Bt,s as Ft,ay as ft,aL as Ze,aM as et,aw as ht,b as mt,aN as tt,aO as Ht,c as nt,aC as pt,aP as Pe,aQ as Wt,aq as Ue,y as Ot,a2 as qt,B as Ne,T as Xt,aR as Yt,aS as Ut,aT as Vt,aU as Kt,aV as Gt,$ as Qt,aW as Jt,A as Zt,f as en,g as tn,i as nn,k as rn,l as sn,m as on,n as cn}from"./index-Dc3Fwpho.js";import{T as an,C as ln,c as un,F as dn,a as wt,R as fn,A as hn,f as mn,t as pn,S as wn}from"./terminal-settings-panel-tZuaqdqz.js";import{e as gn}from"./selection-clipboard-D3gUQQ7L.js";import{C as xn}from"./copy-DwXKDgGT.js";import{S as ct,K as vn}from"./send-J45szXFM.js";const bn=/^[0-9a-fA-F]{4}$/;function Sn(t){if(typeof t!="string"||t.length<6)return null;const e=t.slice(0,4);if(!bn.test(e)||t[4]!==",")return null;const s={input:t,pos:5},c=gt(s);return!c||s.pos!==t.length?null:{checksum:e,root:c}}function Be(t){const e=t.pos;for(;t.pos<t.input.length;){const s=t.input.charCodeAt(t.pos);if(s<48||s>57)break;t.pos+=1}return t.pos===e?null:Number.parseInt(t.input.slice(e,t.pos),10)}function Fe(t,e){return t.input[t.pos]!==e?!1:(t.pos+=1,!0)}function gt(t){const e=Be(t);if(e===null||!Fe(t,"x"))return null;const s=Be(t);if(s===null||!Fe(t,","))return null;const c=Be(t);if(c===null||!Fe(t,","))return null;const u=Be(t);if(u===null)return null;const w=t.input[t.pos];if(w===","){t.pos+=1;const g=Be(t);return g===null?null:{type:"leaf",paneNumId:g,width:e,height:s,x:c,y:u}}if(w==="{"||w==="["){const g=w==="{"?"}":"]";t.pos+=1;const x=[];for(;;){const I=gt(t);if(!I)return null;if(x.push(I),!Fe(t,",")){if(Fe(t,g))break;return null}}return x.length<2?null:{type:w==="{"?"row":"column",width:e,height:s,x:c,y:u,children:x}}return null}function Ve(t){return`%${t.paneNumId}`}/**
2
+ * @license lucide-react v0.564.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const yn=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],En=qe("columns-2",yn);/**
7
+ * @license lucide-react v0.564.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const Rn=[["path",{d:"m13.5 8.5-5 5",key:"1cs55j"}],["path",{d:"m8.5 8.5 5 5",key:"a8mexj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]],Tn=qe("search-x",Rn);/**
12
+ * @license lucide-react v0.564.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const jn=[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]],Cn=qe("settings-2",jn);/**
17
+ * @license lucide-react v0.564.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const Nn=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],Pn=qe("smartphone",Nn);function kn({open:t,onOpenChange:e}){const{t:s}=Ie();return i.jsx(jt,{open:t,onOpenChange:e,children:i.jsxs(Ct,{side:"bottom",className:"max-h-[88dvh] overflow-y-auto pb-[var(--tmex-safe-area-bottom)] sm:mx-auto sm:max-w-md sm:rounded-t-2xl sm:border sm:border-b-0","data-testid":"keyboard-behavior-sheet",children:[i.jsxs(Nt,{children:[i.jsx(Pt,{children:s("settings.terminal.title")}),i.jsx(kt,{children:s("settings.terminal.savedInBrowser")})]}),i.jsx("div",{className:"px-4 pb-4",children:i.jsx(an,{})})]})})}function In({visible:t,canPaste:e,onCopy:s,onPaste:c,onDismiss:u}){const{t:w}=Ie();if(!t)return null;const g=x=>{x.preventDefault()};return i.jsxs("div",{className:"absolute top-2 left-1/2 z-20 flex -translate-x-1/2 items-center gap-1 rounded-lg border bg-background/95 p-1 shadow-md backdrop-blur","data-testid":"terminal-selection-toolbar",children:[i.jsxs("button",{type:"button",className:"flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground",onMouseDown:g,onClick:s,"data-testid":"terminal-selection-copy",children:[i.jsx(xn,{className:"h-4 w-4"}),w("terminal.copy")]}),e&&i.jsxs("button",{type:"button",className:"flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground",onMouseDown:g,onClick:c,"data-testid":"terminal-selection-paste",children:[i.jsx(ln,{className:"h-4 w-4"}),w("terminal.paste")]}),i.jsx("button",{type:"button",className:"flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground",onMouseDown:g,onClick:u,"aria-label":w("terminal.clearSelection"),"data-testid":"terminal-selection-dismiss",children:i.jsx(It,{className:"h-4 w-4"})})]})}function xt(t){if(!t)return t;const e=t.replace(/\r\n/g,`
22
+ `);return(e.endsWith(`
23
+ `)?e.slice(0,-1):e).replace(/\n/g,`\r
24
+ `)}const Mn="\x1B[?1049h\x1B[H\x1B[2J";function Ln(t){return Mn+xt(t)}function An(t,e){let s=e,c=0;for(const x of t)x===10&&!s&&(c+=1),s=x===13;const u=s;if(c===0)return{normalized:t,endedWithCR:u};const w=new Uint8Array(t.length+c);let g=0;s=e;for(const x of t)x===10&&!s&&(w[g]=13,g+=1),w[g]=x,g+=1,s=x===13;return{normalized:w,endedWithCR:u}}const _n=1.3,zn=36,Dn=500,$n=12;function Bn(t,e){const s=n.useRef(!1);return n.useEffect(()=>{const c=t.current;if(!c||!(window.innerWidth<768||navigator.maxTouchPoints>0||"ontouchstart"in window))return;s.current=!0;let w=0,g=null,x=!1,I=0,V=0,X=0,E=null,M=!1;const Z=()=>{E!==null&&(clearTimeout(E),E=null)},r=v=>v?!!(v.closest(".scrollbar")||v.closest(".slider")||v.closest(".xterm-scroll-area")):!1,oe=(v,b,T)=>{const C=T instanceof Element?T:null;if(r(C))return!0;const A=document.elementFromPoint(v,b);if(r(A))return!0;const W=c.querySelector(".xterm");if(!(W instanceof HTMLElement))return!1;const S=W.getBoundingClientRect(),Y=v>=S.left&&v<=S.right,R=b>=S.top&&b<=S.bottom;return!Y||!R?!1:v>=S.right-zn},P=()=>[c.querySelector(".xterm-viewport"),c.querySelector(".xterm-scrollable-element")].filter(b=>b instanceof HTMLElement),ce=v=>{if(g===null)return null;for(let b=0;b<v.length;b+=1){const T=v.item(b);if(T&&T.identifier===g)return T}return null},ee=v=>{if(Z(),v.touches.length!==1)return;const b=v.touches.item(0);b&&(g=b.identifier,w=b.clientY,I=0,x=oe(b.clientX,b.clientY,v.target),V=b.clientX,X=b.clientY,M=!1,x||(E=setTimeout(()=>{var C;E=null;const T=(e==null?void 0:e())??null;(C=T==null?void 0:T.startTouchSelection)!=null&&C.call(T,V,X,"word")&&(M=!0)},Dn)))},we=v=>{var Y,R,_,z,te,L,K,ne,ue;const b=ce(v.touches)??v.touches.item(0);if(!b)return;if(M){const q=(e==null?void 0:e())??null;(Y=q==null?void 0:q.updateTouchSelection)==null||Y.call(q,b.clientX,b.clientY),v.cancelable&&v.preventDefault();return}if(E!==null&&Math.hypot(b.clientX-V,b.clientY-X)>$n&&Z(),x||(x=oe(b.clientX,b.clientY,v.target),x&&(I=0)),x)return;const T=b.clientY,C=w-T;if(w=T,C===0)return;let A=!1,W=!1;const S=(e==null?void 0:e())??null;if(S){const q=S==null?void 0:S._core,ie=((te=(z=(_=(R=q==null?void 0:q._renderService)==null?void 0:R.dimensions)==null?void 0:_.css)==null?void 0:z.cell)==null?void 0:te.height)??18;I+=C*_n;const O=I>0?Math.floor(I/ie):Math.ceil(I/ie);if(typeof S.handleViewportGesture=="function")O!==0&&(A=S.handleViewportGesture({source:"touch",deltaY:O*ie,clientX:b.clientX,clientY:b.clientY}),I-=O*ie);else if(O!==0){const N=((K=(L=S.buffer)==null?void 0:L.active)==null?void 0:K.viewportY)??0;S.scrollLines(O);const pe=((ue=(ne=S.buffer)==null?void 0:ne.active)==null?void 0:ue.viewportY)??0;A=N!==pe,W=O<0&&N<=0&&pe<=0,I-=O*ie}}else{const q=P();if(q.length===0)return;for(const ie of q){const O=ie.scrollTop;ie.scrollTop+=C;const N=ie.scrollTop;Math.abs(N-O)>0&&(A=!0),C<0&&N<=0&&(W=!0)}if(!A){const ie=c.querySelector(".xterm");if(ie instanceof HTMLElement){const O=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaMode:WheelEvent.DOM_DELTA_PIXEL,deltaY:C}),N=ie.dispatchEvent(O);A=O.defaultPrevented||!N}}}v.cancelable&&(A||W)&&v.preventDefault()},ae=v=>{var T;if(Z(),!(g===null||!ce(v.changedTouches))&&(g=null,I=0,x=!1,M)){M=!1;const C=(e==null?void 0:e())??null;(T=C==null?void 0:C.endTouchSelection)==null||T.call(C)}},h=v=>{M&&v.preventDefault()};return c.addEventListener("touchstart",ee,{passive:!0}),c.addEventListener("touchmove",we,{passive:!1}),c.addEventListener("touchend",ae,{passive:!0}),c.addEventListener("touchcancel",ae,{passive:!0}),c.addEventListener("contextmenu",h),()=>{s.current=!1,Z(),c.removeEventListener("touchstart",ee),c.removeEventListener("touchmove",we),c.removeEventListener("touchend",ae),c.removeEventListener("touchcancel",ae),c.removeEventListener("contextmenu",h)}},[t,e]),s}function Fn({now:t,remoteSize:e,pendingLocalSize:s,ttlMs:c=2e3}){return!s||t-s.at>c?!0:s.cols===e.cols&&s.rows===e.rows}function Hn({currentSize:t,containerSize:e,force:s=!1}){return s?!0:t.cols!==e.cols||t.rows!==e.rows}function Wn({deviceId:t,paneId:e,deviceConnected:s,isSelectionInvalid:c,sizingMode:u="report",onResize:w,onSync:g,onResizeSettled:x,getContainerRect:I}){const V=n.useRef(null),X=n.useRef(null),E=n.useRef(null),M=n.useRef(null),Z=n.useRef(0),r=n.useRef([]),oe=n.useRef(null),P=n.useRef(null),ce=n.useRef(I),ee=n.useRef(!1),we=n.useRef(w),ae=n.useRef(g),h=n.useRef(x);n.useEffect(()=>{we.current=w},[w]),n.useEffect(()=>{ae.current=g},[g]),n.useEffect(()=>{h.current=x},[x]),n.useEffect(()=>{ce.current=I},[I]);const v=n.useCallback(()=>{var ue,q,ie,O,N,pe,fe,a,l,y;const R=P.current,_=oe.current;if(!R||!_||!R.element)return null;let z;try{const $=_.proposeDimensions();if(!$)throw new Error("fitAddon.proposeDimensions() returned null");z=Math.max(2,$.cols)}catch{const $=R._core,le=((O=(ie=(q=(ue=$==null?void 0:$._renderService)==null?void 0:ue.dimensions)==null?void 0:q.css)==null?void 0:ie.cell)==null?void 0:O.width)??9,he=(N=ce.current)==null?void 0:N.call(ce);if(!he||he.width===0)return null;z=Math.max(2,Math.floor(he.width/le))}const te=(pe=ce.current)==null?void 0:pe.call(ce);if(!te||te.height===0)return null;const L=R._core,K=((y=(l=(a=(fe=L==null?void 0:L._renderService)==null?void 0:fe.dimensions)==null?void 0:a.css)==null?void 0:l.cell)==null?void 0:y.height)??17,ne=Math.max(2,Math.floor(te.height/K));return{cols:z,rows:ne}},[]),b=n.useCallback((R,_)=>{const z=P.current;z&&(z.cols===R&&z.rows===_||z.resize(R,_))},[]),T=n.useCallback((R,_=!1)=>{var ue;if(u==="follow"||!t||!e||!s||c&&R!=="sync"||!_&&Date.now()<Z.current||!P.current)return!1;const te=v();if(!te)return!1;const{cols:L,rows:K}=te,ne=E.current;return!_&&ne&&ne.cols===L&&ne.rows===K?(b(L,K),!0):(b(L,K),R==="sync"?ae.current(L,K):we.current(L,K),E.current={cols:L,rows:K},M.current={cols:L,rows:K,at:Date.now()},(ue=h.current)==null||ue.call(h,L,K),!0)},[b,s,t,c,v,e,u]),C=n.useCallback((R="resize",_={})=>{const{immediate:z=!1,force:te=!1}=_;X.current!==null&&(window.clearTimeout(X.current),X.current=null),V.current!==null&&(cancelAnimationFrame(V.current),V.current=null);const L=()=>{V.current=requestAnimationFrame(()=>{V.current=null,T(R,te)})};if(z){L();return}X.current=window.setTimeout(()=>{X.current=null,L()},150)},[T]),A=n.useCallback(()=>{for(const R of r.current)window.clearTimeout(R);r.current=[]},[]),W=n.useCallback(()=>{var _;A(),C("sync",{immediate:!0,force:!0});const R=window.setTimeout(()=>{C("sync",{immediate:!0,force:!0})},60);r.current.push(R),typeof document<"u"&&"fonts"in document&&((_=document.fonts)!=null&&_.ready)&&document.fonts.ready.then(()=>{C("sync",{immediate:!0,force:!0})}).catch(()=>{})},[A,C]);n.useEffect(()=>{let R=null;const _=()=>{R!==null&&cancelAnimationFrame(R),R=requestAnimationFrame(()=>{R=null,C("resize")})};return window.addEventListener("resize",_),()=>{window.removeEventListener("resize",_),R!==null&&cancelAnimationFrame(R)}},[C]),n.useEffect(()=>{const R=()=>{var ue;const L=P.current,K=v();if(!L||!K)return;if(!Hn({currentSize:{cols:Math.max(2,L.cols),rows:Math.max(2,L.rows)},containerSize:K})){(ue=L.forceFullRepaint)==null||ue.call(L);return}C("sync",{force:!0})},_=()=>{if(document.visibilityState!=="visible"){ee.current=!0;return}ee.current&&(ee.current=!1,R())},z=()=>{ee.current=!0},te=()=>{ee.current&&(ee.current=!1,R())};return document.addEventListener("visibilitychange",_),window.addEventListener("blur",z),window.addEventListener("focus",te),()=>{document.removeEventListener("visibilitychange",_),window.removeEventListener("blur",z),window.removeEventListener("focus",te)}},[v,C]),n.useEffect(()=>()=>{A(),X.current!==null&&window.clearTimeout(X.current),V.current!==null&&cancelAnimationFrame(V.current)},[A]);const S=n.useCallback(R=>{oe.current=R},[]),Y=n.useCallback(R=>{P.current=R},[]);return{scheduleResize:C,runPostSelectResize:W,clearPostSelectResizeTimers:A,setFitAddon:S,setTerminal:Y,lastReportedSize:E,pendingLocalSize:M,suppressLocalResizeUntil:Z}}const On=1e4,Ge="tmex:terminal-mode-cache";function qn(t,e){try{const s=sessionStorage.getItem(Ge);return s?JSON.parse(s)[`${t}:${e}`]??null:null}catch{return null}}function Xn(t,e,s){try{const c=sessionStorage.getItem(Ge),u=c?JSON.parse(c):{},w=`${t}:${e}`;s?u[w]=s:delete u[w],sessionStorage.setItem(Ge,JSON.stringify(u))}catch{}}function Yn(){return{mouseX10:!1,mouseNormal:!0,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1}}function Un(t,e){if(!e)return t?{...t,mouseX10:!1,mouseNormal:!1,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgrPixels:!1,mouseUrxvt:!1,altScreen1047:!1,altScreen1049:!1}:null;const s=Yn();if(!t)return s;const c=t.mouseNormal||t.mouseButton||t.mouseAny;return{...t,mouseX10:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1,mouseNormal:c?t.mouseNormal:s.mouseNormal}}function Vn(t){var s;const e=globalThis;e.__tmexE2eXterm=t,e.__tmexE2eTerminal=t,e.__tmexE2eTerminalEngine=wt,e.__tmexE2eTerminalRenderer=((s=t.getRendererKind)==null?void 0:s.call(t))??null}function Kn(t){if(!t)return;const e=globalThis;e.__tmexE2eTerminal!==t&&e.__tmexE2eXterm!==t||(e.__tmexE2eXterm=null,e.__tmexE2eTerminal=null,e.__tmexE2eTerminalEngine=null,e.__tmexE2eTerminalRenderer=null,e.__tmexE2eTerminalSelectionText=null)}const rt=n.forwardRef(({deviceId:t,paneId:e,theme:s,inputMode:c,deviceConnected:u,isSelectionInvalid:w,sizingMode:g="report",autoFocus:x=!0,focused:I=!0,onResize:V,onSync:X,onResizeSettled:E,children:M},Z)=>{const[r,oe]=n.useState(null),[P,ce]=n.useState(!1),ee=H(d=>d.sendInput),we=ge(d=>d.terminalFontId),ae=ge(d=>d.terminalFontSize),h=ge(d=>d.terminalLineHeight),{t:v}=Ie(),b=n.useMemo(()=>{switch(s){case"light":return dt;default:return ut}},[s]),T=n.useRef(null),C=n.useRef(null),A=n.useRef(null),W=n.useRef(t),S=n.useRef(e),Y=n.useRef(t),R=n.useRef(e),_=n.useRef(u&&!w),z=n.useRef(c),te=n.useRef(b),L=n.useRef(!1),K=n.useRef(!1),ne=n.useRef(null),ue=n.useRef(!1),q=n.useCallback((d,f,j)=>{!(d!=null&&d.exportModeSnapshot)||!f||!j||Xn(f,j,d.exportModeSnapshot())},[]),ie=n.useCallback(()=>r,[r]);Bn(T,ie),n.useEffect(()=>{W.current=t,S.current=e,K.current=!1},[t,e]),n.useEffect(()=>{_.current=u&&!w},[u,w]),n.useEffect(()=>{z.current=c},[c]),n.useEffect(()=>{te.current=b},[b]);const O=n.useCallback(d=>{if(!d||c!=="direct"||!_.current)return;const f=W.current,j=S.current;!f||!j||ee(f,j,d,!1)},[c,ee]),{pendingLocalSize:N,scheduleResize:pe,runPostSelectResize:fe,setFitAddon:a,setTerminal:l}=Wn({deviceId:t,paneId:e,deviceConnected:u,isSelectionInvalid:w,sizingMode:g,onResize:V,onSync:X,onResizeSettled:E,getContainerRect:()=>{const d=T.current;if(!d)return null;const f=d.getBoundingClientRect();return{width:f.width,height:f.height}}});n.useEffect(()=>{let d=!1,f=null;return(async()=>{if(await Mt(we,ae),d)return;const j=await un({fontFamily:Lt(we),fontSize:ae,lineHeight:h,scrollback:On,theme:te.current,disableStdin:z.current==="editor"});if(d){j.dispose();return}f=j,C.current&&j.open(C.current),oe(j)})(),()=>{d=!0,oe(null),Kn(f),f==null||f.dispose()}},[we,ae,h]),n.useEffect(()=>{!r||!x||Vn(r)},[r,x]),n.useEffect(()=>{var d;(d=r==null?void 0:r.setFocused)==null||d.call(r,I)},[r,I]),n.useEffect(()=>{!r||!("setTheme"in r)||r.setTheme(b)},[r,b]),n.useEffect(()=>{!r||!("setDisableStdin"in r)||r.setDisableStdin(c==="editor")},[r,c]),n.useEffect(()=>{if(!(r!=null&&r.getCursorViewportRect))return;const d=()=>{var f;return((f=r.getCursorViewportRect)==null?void 0:f.call(r))??null};return zt(d),()=>At(d)},[r]),n.useEffect(()=>{!r||c!=="direct"||!x||window.innerWidth<768||"ontouchstart"in window||r.focus()},[r,c,x]);const y=n.useMemo(()=>r?{onReset:()=>{q(r,Y.current,R.current),ue.current=!0,r.reset(),L.current=!1,fe()},onApplyHistory:(d,f)=>{var U,J;const j=Un(qn(W.current,S.current),f);j&&((U=r.restoreModeSnapshot)==null||U.call(r,j));const B=f?Ln(d):xt(d);K.current=!0,r.write(B),(J=r.forceFullRepaint)==null||J.call(r),ue.current=!1,Y.current=W.current,R.current=S.current,q(r,W.current,S.current)},onOutput:d=>{const f=An(d,L.current);L.current=f.endedWithCR,r.write(f.normalized),K.current&&(r.buffer.active.baseY<=1&&r.scrollToTop(),K.current=!1),Y.current=W.current,R.current=S.current,q(r,W.current,S.current)}}:null,[r,q,fe]);n.useEffect(()=>{r?ne.current!==r&&(L.current=!1,Y.current=W.current,R.current=S.current,ne.current=r):ne.current=null},[r]),n.useEffect(()=>{if(!(!r||!t||!e))return()=>{if(ue.current){ue.current=!1;return}q(r,Y.current,R.current)}},[t,r,e,q]),n.useEffect(()=>{if(!(!y||!t||!e))return _t(t,e,y)},[y,t,e]),n.useEffect(()=>{if(!r){A.current=null,a(null),l(null);return}const d=new dn;return r.loadAddon(d),A.current=d,a(d),l(r),fe(),()=>{try{d.dispose()}finally{A.current=null,a(null),l(null)}}},[r,fe,a,l]),n.useEffect(()=>{const d=T.current;if(!d)return;let f=null;const j=new ResizeObserver(()=>{f!==null&&cancelAnimationFrame(f),f=requestAnimationFrame(()=>{f=null,pe("resize")})});return j.observe(d),()=>{j.disconnect(),f!==null&&cancelAnimationFrame(f)}},[pe]),n.useEffect(()=>{if(!r||!t||!e)return;const d=r.onData(f=>{!u||w||O(f)});return r.attachCustomKeyEventHandler(f=>!u||w||f.type!=="keydown"||c!=="direct"?!0:f.shiftKey&&f.key==="Enter"?(f.preventDefault(),O("\x1B[13;2u"),!1):!0),()=>{d.dispose(),r.attachCustomKeyEventHandler(()=>!0)}},[r,u,w,c,O,t,e]),n.useEffect(()=>{if(!(r!=null&&r.onLinkActivated))return;const d=r.onLinkActivated(f=>{window.open(f,"_blank","noopener,noreferrer")});return()=>d.dispose()},[r]),n.useEffect(()=>{if(!(r!=null&&r.onSelectionChange)){ce(!1);return}const d=r.onSelectionChange(f=>{ce(!!f)});return()=>{d.dispose(),ce(!1)}},[r]);const $=n.useCallback(()=>{var f;if(!r)return;const d=((f=r.getSelection)==null?void 0:f.call(r))??"";d&&gn(d).then(()=>{Le.success(v("terminal.copied"))}).catch(()=>{Le.error(v("terminal.copyFailed"))}).finally(()=>{var j;(j=r.clearSelection)==null||j.call(r),r.focus()})},[r,v]),le=n.useCallback(()=>{var f;if(!r)return;((f=navigator.clipboard)!=null&&f.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(j=>{var B;j&&r.paste(j),(B=r.clearSelection)==null||B.call(r),r.focus()}).catch(()=>{Le.error(v("terminal.pasteFailed"))})},[r,v]),he=n.useCallback(()=>{var d;(d=r==null?void 0:r.clearSelection)==null||d.call(r),r==null||r.focus()},[r]);return n.useImperativeHandle(Z,()=>({write:d=>r==null?void 0:r.write(d),reset:()=>{r==null||r.reset(),L.current=!1},scrollToBottom:()=>r==null?void 0:r.scrollToBottom(),resize:(d,f)=>r==null?void 0:r.resize(d,f),getTerminal:()=>r??null,getSize:()=>r?{cols:Math.max(2,r.cols),rows:Math.max(2,r.rows)}:null,runPostSelectResize:()=>fe(),scheduleResize:(d,f)=>pe(d,f),calculateSizeFromContainer:()=>{var Te,xe,F,re,D,G,Q,de,Ee,Re,ve,Me,Ae,ze,me,_e;const d=T.current,f=r,j=A.current;if(!d||!f)return null;const B=d.getBoundingClientRect();if(B.width===0||B.height===0)return null;const U=f._core;let J;if(j)try{const je=j.proposeDimensions();if(je)J=Math.max(2,je.cols);else{const De=((re=(F=(xe=(Te=U==null?void 0:U._renderService)==null?void 0:Te.dimensions)==null?void 0:xe.css)==null?void 0:F.cell)==null?void 0:re.width)??9;J=Math.max(2,Math.floor(B.width/De))}}catch{const je=((de=(Q=(G=(D=U==null?void 0:U._renderService)==null?void 0:D.dimensions)==null?void 0:G.css)==null?void 0:Q.cell)==null?void 0:de.width)??9;J=Math.max(2,Math.floor(B.width/je))}else{const je=((Me=(ve=(Re=(Ee=U==null?void 0:U._renderService)==null?void 0:Ee.dimensions)==null?void 0:Re.css)==null?void 0:ve.cell)==null?void 0:Me.width)??9;J=Math.max(2,Math.floor(B.width/je))}const Ce=((_e=(me=(ze=(Ae=U==null?void 0:U._renderService)==null?void 0:Ae.dimensions)==null?void 0:ze.css)==null?void 0:me.cell)==null?void 0:_e.height)??17,ye=Math.max(2,Math.floor(B.height/Ce));return{cols:J,rows:ye}},getPendingLocalSize:()=>N.current,getCellSize:()=>{var j,B,U;const d=r==null?void 0:r._core,f=(U=(B=(j=d==null?void 0:d._renderService)==null?void 0:j.dimensions)==null?void 0:B.css)==null?void 0:U.cell;return!(f!=null&&f.width)||!(f!=null&&f.height)?null:{width:f.width,height:f.height}}}),[r,N,fe,pe]),i.jsxs("div",{className:"flex h-full w-full flex-col",style:{backgroundColor:b.background},"data-terminal-engine":wt,children:[i.jsxs("div",{ref:T,className:"relative min-h-0 w-full flex-1",children:[i.jsx("div",{ref:C,className:"absolute inset-0"}),i.jsx(In,{visible:P,canPaste:c==="direct"&&u&&!w,onCopy:$,onPaste:le,onDismiss:he})]}),M]})});rt.displayName="Terminal";function Gn({window:t,currentPaneId:e,onSelectPane:s}){const{t:c}=Ie();return i.jsxs(Dt,{children:[i.jsxs($t,{"data-testid":"pane-switcher-button","aria-label":c("window.switchPane"),title:c("window.switchPane"),className:"relative inline-flex size-7 items-center justify-center rounded-[min(var(--radius-md),12px)] text-sm hover:bg-muted hover:text-foreground data-popup-open:bg-muted",children:[i.jsx(En,{className:"h-4 w-4"}),i.jsx("span",{className:"absolute -right-0.5 -top-0.5 flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-primary px-0.5 text-[9px] font-medium leading-none text-primary-foreground",children:t.panes.length})]}),i.jsx(Bt,{align:"end",backdrop:!0,className:"min-w-56 max-w-[80vw]","data-testid":"pane-switcher-menu",children:t.panes.map(u=>{const w=u.id===e;return i.jsxs(Ft,{"data-testid":"pane-switcher-item","data-pane-id":u.id,className:`py-2 [@media(any-pointer:coarse)]:py-2.5 ${w?"bg-primary/10 text-primary":u.active?"bg-accent text-accent-foreground":""}`,onClick:()=>{w||s(u.id)},children:[i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"font-mono text-[11px] leading-tight font-medium line-clamp-2 [overflow-wrap:break-word]",children:u.customName||u.title||c("window.pane")}),u.currentCommand&&i.jsx("span",{className:"font-mono text-[10.5px] leading-tight text-muted-foreground line-clamp-1 break-all",children:u.currentPath?`${u.currentCommand}@${u.currentPath}`:u.currentCommand})]}),w&&i.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-primary"})]},u.id)})})]})}function Qn(t,e){return ft(s=>{for(const c of Object.values(s.sessions))if(!(!c||c.deviceId!==t||c.paneId!==e)&&!(c.status==="stopped"||c.status==="error")){if(c.status==="running"){const u=s.inProgress[c.id];return u&&(u.texts.length>0||u.toolCalls.length>0||u.reasonings.length>0),"generating"}return"bound"}return"none"})}function Qe(t){return t.type==="leaf"?t:t.type==="row"?Qe(t.children[t.children.length-1]):Qe(t.children[0])}function Je(t){return t.type==="leaf"?t:t.type==="column"?Je(t.children[t.children.length-1]):Je(t.children[0])}function Jn(t,e){const s=[],c=[],u=w=>{if(w.type==="leaf"){s.push({paneId:Ve(w),cols:w.width,rows:w.height,rect:{left:w.x*e.width,top:w.y*e.height,width:w.width*e.width,height:w.height*e.height}});return}for(let g=0;g<w.children.length;g+=1){const x=w.children[g];if(u(x),g!==w.children.length-1)if(w.type==="row"){const I=Qe(x);c.push({axis:"x",rect:{left:(x.x+x.width)*e.width,top:w.y*e.height,width:e.width,height:w.height*e.height},edgeLeafPaneId:Ve(I)})}else{const I=Je(x);c.push({axis:"y",rect:{left:w.x*e.width,top:(x.y+x.height)*e.height,width:w.width*e.width,height:e.height},edgeLeafPaneId:Ve(I)})}}};return u(t),{panes:s,gutters:c}}function We(t){if(t.type==="leaf")return 1;if(t.type==="column"){let s=0;for(const c of t.children)s+=We(c);return s}let e=1;for(const s of t.children)e=Math.max(e,We(s));return e}function Oe(t){if(t.type==="leaf")return 1;if(t.type==="row"){let s=0;for(const c of t.children)s+=Oe(c);return s}let e=1;for(const s of t.children)e=Math.max(e,Oe(s));return e}function Zn(t,e){const s=We(t),c=Oe(t),u=Math.max(0,e.viewport.width-c*e.paneChrome.width),w=Math.max(0,e.viewport.height-s*e.paneChrome.height),g=Math.max(2,Math.floor(u/e.cell.width)),x=Math.max(2,Math.floor(w/e.cell.height));return{cols:g,rows:x}}function er(t){return t?t.panes.map(e=>`${e.paneId}:${e.cols}x${e.rows}`).join("|"):""}function tr(t,e){const s=Math.min(1,Math.max(0,t)),c=Math.min(1,Math.max(0,e)),u=[["left",s],["right",1-s],["top",c],["bottom",1-c]];return u.sort((w,g)=>w[1]-g[1]),u[0][0]}const at=150,nr=200,rr=15,sr=46,or=38,ir=12,cr=6;function lt(t){var e,s;return((e=t==null?void 0:t.customName)==null?void 0:e.trim())||((s=t==null?void 0:t.title)==null?void 0:s.trim())||"Pane"}function ar(t){var c,u;const e=(c=t==null?void 0:t.currentCommand)==null?void 0:c.trim();if(!e)return null;const s=(u=t==null?void 0:t.currentPath)==null?void 0:u.trim();return s?`${e}@${s}`:e}function lr({paneId:t}){return Ze(s=>!!s.ringingPanes[t])?i.jsx("span",{className:"bell-blink shrink-0",children:"🔔 "}):null}function ur({deviceId:t,paneId:e}){const{t:s}=Ie(),c=Qn(t,e);return c==="none"?null:c==="generating"?i.jsxs("span",{className:"shrink-0 select-none text-xs",title:s("agent.paneBadge.generating"),"aria-label":s("agent.paneBadge.generating"),children:["🤖",i.jsx("span",{className:"ml-0.5 text-[10px] animate-pulse",children:"✨"})]}):i.jsx("span",{className:"text-muted-foreground/60 shrink-0 select-none text-xs grayscale",title:s("agent.paneBadge.bound"),"aria-label":s("agent.paneBadge.bound"),children:"🤖"})}const dr={left:"left-0 top-0 bottom-0 w-1/2",right:"right-0 top-0 bottom-0 w-1/2",top:"left-0 right-0 top-0 h-1/2",bottom:"left-0 right-0 bottom-0 h-1/2"};function fr({deviceId:t,window:e,focusedPaneId:s,theme:c,inputMode:u,deviceConnected:w,focusedTerminalRef:g,onUserSelectPane:x,onWindowResize:I,onWindowResizeSettled:V}){var N,pe,fe;const X=n.useRef(null),E=n.useRef(new Map),[M,Z]=n.useState(null),[r,oe]=n.useState(null),{t:P}=Ie(),ce=H(a=>a.subscribePanes),ee=H(a=>a.fetchPaneHistory),we=H(a=>a.resizePaneInWindow),ae=H(a=>a.movePane),h=H(a=>a.breakPane),v=H(a=>a.closePane),b=n.useMemo(()=>{const a=new Map;for(const l of e.panes)a.set(l.id,l);return a},[e.panes]),T=n.useMemo(()=>e.layout?Sn(e.layout):null,[e.layout]),C=n.useMemo(()=>T?Jn(T.root,{width:1,height:1}):null,[T]),A=n.useRef(C);A.current=C;const W=(T==null?void 0:T.root.width)??1,S=(T==null?void 0:T.root.height)??1,Y=e.panes.map(a=>a.id).join(",");n.useEffect(()=>(ce(t,Y?Y.split(","):[]),()=>{ce(t,[])}),[t,Y,ce]);const R=n.useRef({key:"",fetched:new Set});n.useEffect(()=>{const a=`${t}:${e.id}`;R.current.key!==a&&(R.current={key:a,fetched:new Set});for(const l of Y?Y.split(","):[])R.current.fetched.has(l)||l!==s&&(R.current.fetched.add(l),ee(t,l))},[t,e.id,Y,s,ee]),n.useEffect(()=>{var l,y;u!=="direct"||window.innerWidth<768||"ontouchstart"in window||(y=(l=E.current.get(s))==null?void 0:l.getTerminal())==null||y.focus()},[s,u]);const _=n.useCallback(()=>{var a;for(const l of[s,...E.current.keys()]){const y=(a=E.current.get(l))==null?void 0:a.getCellSize();if(y)return y}return null},[s]),z=er(C);n.useEffect(()=>{var l;const a=A.current;if(a)for(const y of a.panes)(l=E.current.get(y.paneId))==null||l.resize(y.cols,y.rows)},[z]);const te=n.useMemo(()=>T?We(T.root):1,[T]),L=n.useMemo(()=>T?Oe(T.root):1,[T]),K=n.useCallback(()=>{const a=X.current;if(!a||!T)return!1;const l=a.getBoundingClientRect();if(l.width<1||l.height<1)return!1;const y=_();if(!y)return!1;const{cols:$,rows:le}=Zn(T.root,{viewport:{width:l.width,height:l.height},cell:y,paneChrome:{width:ir,height:sr}});return I($,le),V==null||V($,le),!0},[_,T,I,V]),ne=n.useRef(K);n.useEffect(()=>{ne.current=K},[K]),n.useEffect(()=>{const a=X.current;if(!a)return;let l=null,y=null,$=0;const le=()=>{if(ne.current()){$=0;return}$<rr&&($+=1,y=setTimeout(le,nr))},he=new ResizeObserver(()=>{l&&clearTimeout(l),l=setTimeout(le,at)});return he.observe(a),()=>{he.disconnect(),l&&clearTimeout(l),y&&clearTimeout(y)}},[]),n.useEffect(()=>{const a=setTimeout(()=>{ne.current()},at);return()=>clearTimeout(a)},[te,L]);const ue=n.useCallback((a,l,y)=>{y.preventDefault();const $=X.current;if(!$)return;const le=y.clientX,he=y.clientY,d=y.currentTarget;d.setPointerCapture(y.pointerId),Z({gutterIndex:a,deltaPx:0});const f=J=>{const Ce=l.axis==="x"?J.clientX-le:J.clientY-he;Z({gutterIndex:a,deltaPx:Ce})},j=(J,Ce)=>{if(d.removeEventListener("pointermove",f),d.removeEventListener("pointerup",B),d.removeEventListener("pointercancel",U),window.removeEventListener("pointerup",B),window.removeEventListener("pointercancel",U),Z(null),!Ce)return;const ye=_();if(!ye)return;const Te=l.axis==="x"?J.clientX-le:J.clientY-he,xe=l.axis==="x"?ye.width:ye.height;if(xe<=0)return;const F=Math.round(Te/xe);if(F===0)return;const re=$.querySelector(`[data-pane-id="${l.edgeLeafPaneId}"]`);if(!re)return;const D=re.getBoundingClientRect(),Q=(l.axis==="x"?Math.floor(D.width/xe):Math.floor(D.height/xe))+F;Q<2||(ne.current(),we(t,l.edgeLeafPaneId,l.axis==="x"?{cols:Q}:{rows:Q}))},B=J=>j(J,!0),U=J=>j(J,!1);d.addEventListener("pointermove",f),window.addEventListener("pointerup",B),window.addEventListener("pointercancel",U)},[t,_,we]),q=n.useCallback((a,l)=>{const y=X.current,$=C;if(!y||!$)return;l.preventDefault();const le=l.clientX,he=l.clientY,d=l.currentTarget;d.setPointerCapture(l.pointerId);let f=!1;const j=(F,re)=>{const D=y.getBoundingClientRect();if(D.width<1||D.height<1)return null;const G=(F-D.left)/D.width*Math.max(1,W),Q=(re-D.top)/D.height*Math.max(1,S);for(const de of $.panes)if(G>=de.rect.left&&G<=de.rect.left+de.rect.width&&Q>=de.rect.top&&Q<=de.rect.top+de.rect.height){const Ee=(G-de.rect.left)/Math.max(1e-6,de.rect.width),Re=(Q-de.rect.top)/Math.max(1e-6,de.rect.height);return{paneId:de.paneId,position:tr(Ee,Re)}}return null},B=(F,re,D)=>F>=D.left&&F<=D.right&&re>=D.top&&re<=D.bottom,U=(F,re)=>{for(const D of Array.from(document.querySelectorAll('[data-testid^="window-item-"]'))){const G=D.getBoundingClientRect();if(G.width<1||!B(F,re,G))continue;const Q=(D.getAttribute("data-testid")??"").replace("window-item-","");return!Q||Q===e.id?null:{type:"window",windowId:Q,rect:{left:G.left,top:G.top,width:G.width,height:G.height}}}for(const D of Array.from(document.querySelectorAll('[data-slot="sidebar"]'))){const G=D.getBoundingClientRect();if(!(G.width<1||!B(F,re,G)))return{type:"break",rect:{left:G.left,top:G.top,width:G.width,height:G.height}}}return null},J=(F,re)=>{const D=j(F,re);return D?D.paneId===a?null:{type:"pane",...D}:U(F,re)},Ce=F=>{const re=Math.hypot(F.clientX-le,F.clientY-he);!f&&re<cr||(f=!0,oe({srcPaneId:a,active:!0,pointerX:F.clientX,pointerY:F.clientY,target:J(F.clientX,F.clientY)}))},ye=(F,re)=>{var G,Q;if(d.removeEventListener("pointermove",Ce),d.removeEventListener("pointerup",Te),d.removeEventListener("pointercancel",xe),window.removeEventListener("pointerup",Te),window.removeEventListener("pointercancel",xe),oe(null),!re||!f)return;const D=J(F.clientX,F.clientY);if(D){if(D.type==="pane"){ae(t,a,D.paneId,D.position);return}if(D.type==="window"){const de=(Q=(G=H.getState().snapshots[t])==null?void 0:G.session)==null?void 0:Q.windows,Ee=de==null?void 0:de.find(ve=>ve.id===D.windowId),Re=(Ee==null?void 0:Ee.panes.find(ve=>ve.active))??(Ee==null?void 0:Ee.panes[0]);Re&&ae(t,a,Re.id,"right");return}h(t,a)}},Te=F=>ye(F,!0),xe=F=>ye(F,!1);d.addEventListener("pointermove",Ce),window.addEventListener("pointerup",Te),window.addEventListener("pointercancel",xe)},[t,C,ae,h,W,S,e.id]),ie=n.useCallback(a=>l=>{var y;if(l){E.current.set(a,l);const $=(y=A.current)==null?void 0:y.panes.find(le=>le.paneId===a);$&&l.resize($.cols,$.rows)}else E.current.delete(a);a===s&&g(l)},[s,g]);if(n.useEffect(()=>{g(E.current.get(s)??null)},[s,g]),!C)return null;const O=(a,l)=>`${a/Math.max(1,l)*100}%`;return i.jsxs("div",{ref:X,className:"relative h-full w-full min-h-0 min-w-0","data-testid":"split-terminal-area",children:[C.panes.map(a=>{var d;const l=a.paneId===s,y=b.get(a.paneId),$=ar(y),le=(r==null?void 0:r.active)&&r.srcPaneId===a.paneId,he=r!=null&&r.active&&((d=r.target)==null?void 0:d.type)==="pane"&&r.target.paneId===a.paneId?r.target.position:null;return i.jsxs("div",{className:`absolute flex flex-col overflow-hidden ${le?"opacity-60":""}`,"data-testid":"split-pane","data-pane-id":a.paneId,"data-focused":l||void 0,style:{left:O(a.rect.left,W),top:O(a.rect.top,S),width:O(a.rect.width,W),height:O(a.rect.height,S)},onPointerDownCapture:()=>{l||x(e.id,a.paneId)},children:[i.jsx("div",{className:"shrink-0 px-1.5 pt-1.5 pb-2",style:{height:or},children:i.jsxs("div",{"data-testid":"split-pane-titlebar","data-active":l||void 0,className:`flex h-6 cursor-grab touch-none select-none items-center gap-1.5 rounded-md px-2.5 transition-colors active:cursor-grabbing ${l?"bg-foreground/10":"bg-foreground/[0.04]"}`,onPointerDown:f=>q(a.paneId,f),children:[i.jsx(lr,{paneId:a.paneId}),i.jsx(ur,{deviceId:t,paneId:a.paneId}),i.jsx("span",{className:`shrink-0 truncate font-mono text-[10.5px] leading-none ${l?"text-foreground/90":"text-foreground/50"}`,children:lt(y)}),$&&i.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-[10px] leading-none ${l?"text-muted-foreground":"text-muted-foreground/60"}`,children:$}),i.jsx("button",{type:"button","data-testid":`split-pane-close-${a.paneId}`,"aria-label":P("window.closePane"),title:P("window.closePane"),className:"ml-auto flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground/50 hover:bg-foreground/10 hover:text-foreground",onPointerDown:f=>f.stopPropagation(),onClick:f=>{f.stopPropagation(),v(t,a.paneId)},children:i.jsx("span",{className:"text-xs leading-none",children:"×"})})]})}),i.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden px-1.5 pb-2","data-pane-content-id":a.paneId,children:i.jsx(rt,{ref:ie(a.paneId),deviceId:t,paneId:a.paneId,theme:c,inputMode:u,deviceConnected:w,isSelectionInvalid:!1,sizingMode:"follow",autoFocus:l,focused:l,onResize:()=>{},onSync:()=>{}},`${t}:${a.paneId}`)}),he&&i.jsx("div",{"data-testid":"split-pane-drop-preview","data-position":he,className:`pointer-events-none absolute z-30 rounded-sm bg-primary/20 ring-1 ring-inset ring-primary/60 ${dr[he]}`})]},a.paneId)}),(M!==null||(r==null?void 0:r.active))&&i.jsx("div",{"data-testid":"split-drag-shield",className:`absolute inset-0 z-30 ${M!==null?((N=C.gutters[M.gutterIndex])==null?void 0:N.axis)==="x"?"cursor-col-resize":"cursor-row-resize":"cursor-grabbing"}`}),(r==null?void 0:r.active)&&r.target&&r.target.type!=="pane"&&i.jsx("div",{"data-testid":"split-pane-sidebar-drop","data-drop-type":r.target.type,className:"pointer-events-none fixed z-40 rounded-lg bg-primary/15 ring-1 ring-inset ring-primary/50",style:{left:r.target.rect.left,top:r.target.rect.top,width:r.target.rect.width,height:r.target.rect.height}}),(r==null?void 0:r.active)&&i.jsxs("div",{className:"pointer-events-none fixed z-50 rounded border border-primary/40 bg-popover/95 px-2 py-1 font-mono text-[10.5px] text-popover-foreground shadow-md",style:{left:r.pointerX+12,top:r.pointerY+12},children:[i.jsx("div",{children:lt(b.get(r.srcPaneId))}),((pe=r.target)==null?void 0:pe.type)==="window"&&i.jsx("div",{className:"text-[9.5px] text-muted-foreground",children:P("window.moveToWindow")}),((fe=r.target)==null?void 0:fe.type)==="break"&&i.jsx("div",{className:"text-[9.5px] text-muted-foreground",children:P("window.breakToWindow")})]}),C.gutters.map((a,l)=>{const y=a.axis==="x",$=(M==null?void 0:M.gutterIndex)===l;return i.jsxs("div",{className:"absolute z-20",style:{left:O(a.rect.left,W),top:O(a.rect.top,S),width:O(y?1:a.rect.width,W),height:O(y?a.rect.height:1,S)},children:[i.jsx("div",{"data-testid":"split-gutter","data-axis":a.axis,className:`absolute touch-none select-none ${y?"-inset-x-1 inset-y-0 cursor-col-resize":"inset-x-0 -inset-y-1 cursor-row-resize"}`,onPointerDown:le=>ue(l,a,le),children:i.jsx("div",{className:`absolute bg-foreground/[0.08] transition-colors hover:bg-primary/50 ${y?"inset-y-0 left-1/2 w-px -translate-x-1/2":"inset-x-0 top-1/2 h-px -translate-y-1/2"} ${$?"bg-primary":""}`})}),$&&M&&i.jsx("div",{className:"pointer-events-none absolute bg-primary/70",style:y?{top:0,bottom:0,width:2,left:`calc(50% + ${M.deltaPx}px)`}:{left:0,right:0,height:2,top:`calc(50% + ${M.deltaPx}px)`}})]},`${e.layout??""}:${l}`)})]})}const hr=1200,mr=2e3;function ke(t,e){return!t||!e?!1:t.windowId===e.windowId&&t.paneId===e.paneId}function vt(t,e){const s=t.filter(c=>e-c.at<hr);return s.length===0?null:s.reduce((c,u)=>u.at>c.at?u:c)}function He(t,e=Date.now()){return!t||e-t.at>mr?null:t}function pr(t){const e=t.now??Date.now(),s=vt(t.recentSelectRequests,e),c=w=>!!(w&&w.paneId===t.activePaneFromEvent.paneId&&w.windowId!==t.activePaneFromEvent.windowId);if(s&&!ke(s,t.activePaneFromEvent)&&!c(s)||ke(t.currentRoute,t.activePaneFromEvent)||ke(t.lastHandledActive,t.activePaneFromEvent))return!0;const u=He(t.pendingUserSelection,e);return!!(u&&!ke(u,t.activePaneFromEvent)&&!c(u))}function wr(t){const e=t.now??Date.now(),s=vt(t.recentSelectRequests,e),c=He(t.pendingUserSelection,e);return!!(c&&!ke(c,t.snapshotActive)||s&&!ke(s,t.snapshotActive))}function gr(t){const e=t.now??Date.now(),s=He(t.pendingUserSelection,e);return!(s&&ke(s,t.routeTarget)||t.snapshotActive&&ke(t.snapshotActive,t.routeTarget))}const Ke=n.memo(function({onActivate:e,disabled:s}){const{data:c}=nt({queryKey:pn,queryFn:mn,staleTime:6e4}),u=(c==null?void 0:c.items)??[];return u.length===0?null:i.jsx("div",{className:"terminal-shortcuts-strip","data-testid":"terminal-shortcuts-strip",children:i.jsx(wn,{items:u,useIcons:(c==null?void 0:c.useIcons)??!1,onActivate:e,disabled:s,preventFocusSteal:!0,rowTestId:"terminal-shortcuts-row",idPrefix:"terminal-shortcut"})})});function Er(){var it;const{t}=Ie(),{deviceId:e,windowId:s,paneId:c}=et(),u=ht(),w=n.useRef(null),g=n.useRef(null),x=n.useRef(null),I=n.useRef(null),V=n.useRef(!1),X=n.useRef(!1),E=n.useRef(null),M=H(o=>o.selectPane),Z=H(o=>o.focusPane),r=H(o=>e?o.snapshots[e]:void 0),oe=H(o=>{var m;return e?(m=o.deviceErrors)==null?void 0:m[e]:void 0}),P=H(o=>{var m;return e?((m=o.deviceConnected)==null?void 0:m[e])??!1:!1}),ee=!!H(o=>{var m;return e?(m=o.deviceReconnecting)==null?void 0:m[e]:void 0}),we=H(o=>e?o.connectedDevices.has(e):!1),ae=mt(o=>{var m;return((m=o.settings)==null?void 0:m.siteName)??"tmex"}),h=n.useMemo(()=>tt(c),[c]),v=n.useMemo(()=>e&&h?`${e}:${h}`:null,[e,h]),[b,T]=n.useState(!1),C=n.useRef(!1);n.useEffect(()=>{C.current=b},[b]);const[A,W]=n.useState(""),S=n.useRef(!1),Y=!P||!h,[R,_]=n.useState(!1),z=ge(o=>o.inputMode),te=ge(o=>o.theme),L=ge(o=>o.editorSendWithEnter),K=ge(o=>o.setEditorSendWithEnter),ne=ge(o=>o.addEditorHistory),ue=ge(o=>o.setEditorDraft),q=ge(o=>o.removeEditorDraft),ie=ge(o=>v?o.editorDrafts[v]??"":""),O=n.useMemo(()=>Ht(),[]),N=(it=r==null?void 0:r.session)==null?void 0:it.windows,pe=te==="light"?dt:ut,{data:fe}=nt({queryKey:["devices"],queryFn:async()=>{const o=await fetch("/api/devices");if(!o.ok)throw new Error("Failed to fetch devices");return o.json()},throwOnError:!1}),a=n.useMemo(()=>{if(e)return fe==null?void 0:fe.devices.find(o=>o.id===e)},[e,fe==null?void 0:fe.devices]),l=n.useMemo(()=>{if(!(!s||!N))return N.find(o=>o.id===s)},[s,N]),y=n.useMemo(()=>{if(!(!h||!l))return l.panes.find(o=>o.id===h)},[h,l]),$=!!N,d=$&&!!s&&!l?t("terminal.windowClosed"):$&&!!s&&!!h&&!!l&&!y?t("terminal.paneClosed"):null,f=!!d,j=!!(P&&h&&!f),B=!!(!b&&l&&l.panes.length>1&&l.layout&&!f),U=n.useRef(B);n.useEffect(()=>{U.current=B},[B]);const J=Ze(o=>o.ringingPanes),Ce=n.useMemo(()=>{if(!l||!y)return null;const o=(a==null?void 0:a.name)??e,m=pt({paneCustomName:y.customName,paneTitle:y.title,windowName:l.name,windowCustomName:l.customName,deviceName:o});return J[y.id]?`🔔 ${m}`:m},[a==null?void 0:a.name,e,y,l,J]),ye=n.useMemo(()=>{if(!N||N.length===0)return null;const o=N.find(p=>p.active),m=o==null?void 0:o.panes.find(p=>p.active);return!o||!m?null:{windowId:o.id,paneId:m.id}},[N]),Te=b&&l&&l.panes.length>1?l.id:null,xe=n.useRef(Te);n.useEffect(()=>{xe.current=Te},[Te]);const F=n.useRef(!1);n.useEffect(()=>{F.current=!!N&&!!s},[N,s]);const re=n.useCallback((o,m)=>{if(!e||!h)return;const p=xe.current;if(p){H.getState().applyStackedLayout(e,p,o,m);return}C.current&&!F.current||H.getState().resizePane(e,h,o,m)},[e,h]),D=n.useCallback((o,m)=>{if(!e||!h)return;const p=xe.current;if(p){H.getState().applyStackedLayout(e,p,o,m);return}C.current&&!F.current||H.getState().syncPaneSize(e,h,o,m)},[e,h]),G=n.useCallback(()=>{e&&H.getState().syncThemeAfterResize(e)},[e]),Q=n.useCallback((o,m)=>{var $e;const p=I.current;if(U.current){const Se=($e=w.current)==null?void 0:$e.getBoundingClientRect(),Ye=p==null?void 0:p.getCellSize();return Se&&Ye&&Se.width>0&&Se.height>0?{cols:Math.max(2,Math.floor(Se.width/Ye.width)),rows:Math.max(2,Math.floor(Se.height/Ye.height))}:void 0}if(C.current)return;const k=(p==null?void 0:p.calculateSizeFromContainer())??(p==null?void 0:p.getSize())??void 0;if(k)return k;if(!o||!m||!N)return;const se=N.find(Se=>Se.id===o),be=se==null?void 0:se.panes.find(Se=>Se.id===m);if(!(!be||be.width<=1||be.height<=1))return{cols:be.width,rows:be.height}},[N]),de=n.useCallback((o,m)=>{e&&(E.current={windowId:o,paneId:m,at:Date.now()},u(`/devices/${e}/windows/${o}/panes/${Pe(m)}`,{replace:!0}))},[e,u]),Ee=n.useCallback(o=>{I.current=o},[]);n.useEffect(()=>{const o=()=>{T(window.innerWidth<768||"ontouchstart"in window)};return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),n.useEffect(()=>{if(!b||!O||X.current)return;X.current=!0;const o=()=>{window.scrollTo(0,1)},m=window.requestAnimationFrame(o),p=window.setTimeout(o,120),k=window.setTimeout(o,420);return()=>{window.cancelAnimationFrame(m),window.clearTimeout(p),window.clearTimeout(k)}},[O,b]),n.useEffect(()=>{e&&(V.current=!1,_e.current=null,je.current=null,E.current=null,Re.current=[])},[e]),n.useEffect(()=>{P||(V.current=!1)},[P]),n.useEffect(()=>{if(!e||!P||!s||!N)return;if(N.length===0){u("/devices",{replace:!0});return}const o=N.find(p=>p.id===s);if(!o)return;if(!h){const p=o.panes.find(k=>k.active)??o.panes[0];p&&u(`/devices/${e}/windows/${s}/panes/${Pe(p.id)}`,{replace:!0});return}if(!o.panes.find(p=>p.id===h)){const p=N.find(se=>se.panes.some(be=>be.id===h));if(p){u(`/devices/${e}/windows/${p.id}/panes/${Pe(h)}`,{replace:!0});return}const k=o.panes.find(se=>se.active)??o.panes[0];k&&u(`/devices/${e}/windows/${s}/panes/${Pe(k.id)}`,{replace:!0});return}},[e,P,N,s,h,u]),n.useEffect(()=>{if(!e||!P||!N||N.length===0||s&&h||V.current)return;const o=N.find(p=>p.active)??N[0],m=o.panes.find(p=>p.active)??o.panes[0];m&&(V.current=!0,u(`/devices/${e}/windows/${o.id}/panes/${Pe(m.id)}`,{replace:!0}))},[P,e,u,h,s,N]);const Re=n.useRef([]),ve=n.useCallback((o,m)=>{const p=Date.now(),k=[...Re.current.filter(se=>p-se.at<2e3),{windowId:o,paneId:m,at:p}];Re.current=k.slice(-8)},[]),Me=n.useRef(null);n.useEffect(()=>{Me.current=null},[e,h]);const Ae=n.useRef(null),ze=n.useRef(B);n.useEffect(()=>{ze.current!==B&&(ze.current=B,Me.current=null,Ae.current=null)},[B]),n.useEffect(()=>{if(!e||!s||!h||Y||!P)return;const o=`${e}:${s}:${h}`;if(Me.current===o)return;Me.current=o;const m=B&&Ae.current===`${e}:${s}`&&!!(l!=null&&l.panes.some(k=>k.id===h));if(ve(s,h),m){Z(e,s,h);return}const p=Q(s,h);M(e,s,h,p),Ae.current=`${e}:${s}`},[P,e,Z,Q,Y,B,ve,h,M,l,s]),n.useEffect(()=>{if(!e||!P||!s||!h)return;const o={windowId:s,paneId:h};gr({routeTarget:o,snapshotActive:ye,pendingUserSelection:E.current})&&(E.current={windowId:o.windowId,paneId:o.paneId,at:Date.now()})},[P,e,h,ye,s]);const me=H(o=>e?o.activePaneFromEvent[e]:void 0),_e=n.useRef(null);n.useEffect(()=>{if(!e||!P||!s||!h||!me)return;const o=Date.now(),m=He(E.current,o);if(E.current=m,pr({now:o,pendingUserSelection:m,activePaneFromEvent:me,currentRoute:{windowId:s,paneId:h},recentSelectRequests:Re.current,lastHandledActive:_e.current}))return;if(_e.current={...me},m&&m.windowId===me.windowId&&m.paneId===me.paneId&&(E.current=null),!(U.current&&me.windowId===s)){const k=Q(me.windowId,me.paneId);ve(me.windowId,me.paneId),M(e,me.windowId,me.paneId,k)}u(`/devices/${e}/windows/${me.windowId}/panes/${Pe(me.paneId)}`,{replace:!0})},[e,P,s,h,me,ve,Q,M,u]);const je=n.useRef(null);n.useEffect(()=>{if(!e||!P||!N||N.length===0)return;const o=Re.current,m=N.find(Se=>Se.active);if(!m)return;const p=m.panes.find(Se=>Se.active);if(!p)return;const k={windowId:m.id,paneId:p.id},se=Date.now(),be=He(E.current,se);if(E.current=be,wr({now:se,pendingUserSelection:be,snapshotActive:k,recentSelectRequests:o})||je.current&&je.current.windowId===k.windowId&&je.current.paneId===k.paneId||(je.current={...k},be&&be.windowId===k.windowId&&be.paneId===k.paneId&&(E.current=null),s===k.windowId&&h===k.paneId))return;if(!(U.current&&k.windowId===s)){const Se=Q(k.windowId,k.paneId);ve(k.windowId,k.paneId),M(e,k.windowId,k.paneId,Se)}u(`/devices/${e}/windows/${k.windowId}/panes/${Pe(k.paneId)}`,{replace:!0})},[e,P,N,s,h,ve,Q,M,u]);const De=H(o=>e?o.pendingCreateWindowAt[e]:void 0);n.useEffect(()=>{if(!e||!P||!De)return;const o=5e3,m=Date.now()-De;if(m>o){H.getState().clearPendingCreateWindow(e);return}if(!ye){const se=window.setTimeout(()=>{H.getState().clearPendingCreateWindow(e)},o-m);return()=>window.clearTimeout(se)}const p=ye;if(s===p.windowId&&h===p.paneId){const se=window.setTimeout(()=>{H.getState().clearPendingCreateWindow(e)},o-m);return()=>window.clearTimeout(se)}E.current={windowId:p.windowId,paneId:p.paneId,at:Date.now()};const k=Q(p.windowId,p.paneId);ve(p.windowId,p.paneId),M(e,p.windowId,p.paneId,k),u(`/devices/${e}/windows/${p.windowId}/panes/${Pe(p.paneId)}`,{replace:!0}),H.getState().clearPendingCreateWindow(e)},[e,P,De,ye,s,h,ve,Q,M,u]),n.useEffect(()=>{if(B||!j||!y||Y)return;const o=I.current,m=o==null?void 0:o.getTerminal();if(!m)return;const p=Math.max(2,Math.floor(y.width||0)),k=Math.max(2,Math.floor(y.height||0));if(!p||!k)return;const se=Date.now(),be={cols:p,rows:k},$e=(o==null?void 0:o.getPendingLocalSize())??null;Fn({now:se,remoteSize:be,pendingLocalSize:$e})&&(m.cols===p&&m.rows===k||m.resize(p,k))},[j,Y,B,y]),n.useEffect(()=>{const o=window.requestAnimationFrame(()=>{var p;(p=I.current)==null||p.scrollToBottom()}),m=window.setTimeout(()=>{var p;(p=I.current)==null||p.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(o),window.clearTimeout(m)}},[z]),n.useEffect(()=>{oe!=null&&oe.message&&Le.error(oe.message)},[oe==null?void 0:oe.message]),n.useEffect(()=>(document.title=Wt(Ce),()=>{document.title=ae}),[ae,Ce]),n.useEffect(()=>{const o=()=>{var m;(m=I.current)==null||m.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",o),()=>{window.removeEventListener("tmex:jump-to-latest",o)}},[]),n.useEffect(()=>{const o=m=>{const{deviceId:p,windowId:k,paneId:se}=m.detail;p===e&&(E.current={windowId:k,paneId:se,at:Date.now()})};return window.addEventListener("tmex:user-initiated-selection",o),()=>{window.removeEventListener("tmex:user-initiated-selection",o)}},[e]),n.useEffect(()=>{W(ie)},[ie]);const st=n.useCallback(o=>{if(!e||!h||!j)return;H.getState().sendInput(e,h,o,!1)},[j,e,h]),Xe=n.useCallback(o=>{var m,p;if(o.type==="action"){if(o.action==="toggleKeyboard"){ge.getState().setInputMode(z==="direct"?"editor":"direct");return}if(o.action==="scrollToBottom"){(m=I.current)==null||m.scrollToBottom();return}}if(o.type==="send"){o.payload&&st(o.payload);return}if(!(!e||!h||!j))switch(o.action){case"paste":{((p=navigator.clipboard)!=null&&p.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(se=>{se&&H.getState().paste(e,h,se)}).catch(()=>Le.error(t("terminal.pasteFailed")));break}case"newAgentSession":ft.getState().startDraft(e,h,null),ge.getState().setSidebarCollapsed(!1),ge.getState().setSidebarTab("agent");break}},[j,e,st,z,h,t]),bt=n.useCallback(()=>{if(!j){Le.error(t("wsError.checkGateway"));return}if(!e||!h||!A.trim())return;_(!0),window.setTimeout(()=>_(!1),150);const o=L?`${A}\r`:A;H.getState().sendInput(e,h,o,!1),ne(A),v&&q(v),W("")},[ne,j,e,v,L,A,q,h,t]),St=n.useCallback(()=>{if(!j){Le.error(t("wsError.checkGateway"));return}if(!e||!h||!A.trim())return;_(!0),window.setTimeout(()=>_(!1),150);const o=A.split(/\r?\n/),m=H.getState();for(const p of o)p.trim()&&m.sendInput(e,h,`${p}\r`,!1);ne(A),v&&q(v),W("")},[ne,j,e,v,A,q,h,t]),yt=n.useCallback(()=>{var o;(o=x.current)==null||o.focus({preventScroll:!0})},[]);if(!e)return i.jsx("div",{className:"flex h-full items-center justify-center p-4",children:i.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground",children:t("device.noDevices")})});const Et=!!h&&!f&&(P||ee),Rt=P&&!!h&&!f&&!y,Tt=we&&!P&&!oe&&!ee,ot=i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:i.jsx(Ue,{className:"h-6 w-6 text-muted-foreground animate-spin"})}),i.jsx("h3",{className:"text-lg font-medium",children:t("terminal.connecting")})]});return i.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[i.jsx("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${b&&z==="editor"?"pb-1":""}`,children:i.jsxs("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:pe.background},children:[f?i.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:i.jsxs("div",{className:"max-w-sm space-y-4",children:[i.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:i.jsx(Tn,{className:"h-6 w-6 text-muted-foreground"})}),i.jsx("p",{className:"text-sm text-muted-foreground","data-testid":"terminal-selection-invalid",children:d})]})}):Et&&h?B&&l?i.jsxs("div",{className:"flex h-full min-h-0 w-full flex-1 flex-col","data-virtual-keyboard-avoid":!0,children:[i.jsx("div",{ref:w,className:"relative min-h-0 flex-1",children:i.jsx(fr,{deviceId:e,window:l,focusedPaneId:h,theme:te,inputMode:z,deviceConnected:P,focusedTerminalRef:Ee,onUserSelectPane:de,onWindowResize:re,onWindowResizeSettled:G},`${e}:${l.id}`)}),z==="direct"&&i.jsx("div",{className:"kb-floating-shortcuts",style:{backgroundColor:pe.background},children:i.jsx(Ke,{onActivate:Xe,disabled:!j})})]}):i.jsx("div",{ref:w,className:"flex-1 h-full min-h-0 w-full","data-virtual-keyboard-avoid":!0,children:i.jsx(rt,{ref:I,deviceId:e,paneId:h,theme:te,inputMode:z,deviceConnected:P,isSelectionInvalid:f,onResize:re,onSync:D,onResizeSettled:G,children:z==="direct"&&i.jsx("div",{className:"kb-floating-shortcuts",style:{backgroundColor:pe.background},children:i.jsx(Ke,{onActivate:Xe,disabled:!j})})},`${e}:${h}`)}):i.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:i.jsx("div",{className:"max-w-sm space-y-4",children:Tt?ot:!P&&!ee?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:i.jsx("span",{className:"text-2xl text-muted-foreground",children:"🔌"})}),i.jsx("h3",{className:"text-lg font-medium",children:t("device.disconnected")}),i.jsx("p",{className:"text-sm text-muted-foreground",children:t("device.connectToStart")})]}):s?ot:i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:i.jsx("span",{className:"text-2xl text-muted-foreground",children:"📋"})}),i.jsx("h3",{className:"text-lg font-medium",children:t("window.noWindowSelected")}),i.jsx("p",{className:"text-sm text-muted-foreground",children:t("window.selectWindowToStart")})]})})}),ee&&i.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-2 z-10 flex justify-center","data-testid":"terminal-reconnecting-indicator",children:i.jsx(Ot,{deviceId:e,className:"shadow-sm"})}),Rt&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:i.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border bg-card/90 px-4 py-3 shadow-sm",children:[i.jsx("div",{className:"h-7 w-7 rounded-full border-2 border-primary border-t-transparent animate-spin"}),i.jsx("span",{className:"text-xs text-muted-foreground","data-testid":"terminal-status-text",children:t("terminal.connecting")})]})})]})}),z==="editor"&&i.jsxs("div",{ref:g,"data-virtual-keyboard-avoid":!0,className:"editor-mode-input bg-card/85 backdrop-blur-sm",children:[b&&i.jsx(Ke,{onActivate:o=>{Xe(o),o.type==="send"&&yt()},disabled:!j}),i.jsx("textarea",{ref:x,"data-testid":"editor-input",className:"min-h-[88px] max-h-[28vh] w-full resize-y rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground shadow-xs outline-none transition-colors focus:border-ring",value:A,onChange:o=>{const m=o.target.value;if(W(m),!!v){if(m){ue(v,m);return}q(v)}},placeholder:t("terminal.inputPlaceholder"),onCompositionStart:()=>{S.current=!0},onCompositionEnd:()=>{S.current=!1}}),i.jsx("div",{className:"actions mt-2",children:i.jsxs("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[i.jsxs("div",{className:"send-with-enter-toggle mr-auto flex items-center gap-2 text-xs text-muted-foreground","data-testid":"editor-send-with-enter-toggle",children:[i.jsx(qt,{size:"sm",checked:L,onCheckedChange:o=>K(!!o)}),i.jsx("span",{children:t("terminal.editorSendWithEnter")})]}),i.jsxs(Ne,{variant:"outline",size:"sm","data-testid":"editor-clear",onMouseDown:o=>o.preventDefault(),onClick:()=>{var o;W(""),v&&q(v),b&&z==="editor"&&((o=x.current)==null||o.focus({preventScroll:!0}))},title:t("terminal.clear"),children:[i.jsx(Xt,{className:"h-4 w-4"}),t("terminal.clear")]}),i.jsxs(Ne,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onMouseDown:o=>o.preventDefault(),onClick:()=>{var o;St(),b&&z==="editor"&&((o=x.current)==null||o.focus({preventScroll:!0}))},disabled:!j||R,children:[R?i.jsx(Ue,{className:"h-4 w-4 animate-spin"}):i.jsx(ct,{className:"h-4 w-4"}),t("terminal.editorSendLineByLine")]}),i.jsxs(Ne,{variant:"default",size:"sm","data-testid":"editor-send",onMouseDown:o=>o.preventDefault(),onClick:()=>{var o;bt(),b&&z==="editor"&&((o=x.current)==null||o.focus({preventScroll:!0}))},disabled:!j||R,children:[R?i.jsx(Ue,{className:"h-4 w-4 animate-spin"}):i.jsx(ct,{className:"h-4 w-4"}),t("common.send")]})]})})]})]})}function Rr(){const{deviceId:t,windowId:e,paneId:s}=et(),c=s?tt(s):void 0,u=H(E=>E.snapshots),w=mt(E=>{var M;return((M=E.settings)==null?void 0:M.siteName)??"tmex"}),g=t?u[t]:void 0,x=n.useMemo(()=>{var E;if(!(!e||!((E=g==null?void 0:g.session)!=null&&E.windows)))return g.session.windows.find(M=>M.id===e)},[e,g]),I=n.useMemo(()=>{if(!(!c||!x))return x.panes.find(E=>E.id===c)},[c,x]),V=n.useMemo(()=>x&&I?pt({paneCustomName:I.customName,paneTitle:I.title,windowName:x.name,windowCustomName:x.customName,deviceName:w}):t??"",[x,I,w,t]),X=Ze(E=>c?!!E.ringingPanes[c]:!1);return i.jsxs(i.Fragment,{children:[X&&i.jsx("span",{className:"bell-blink",children:"🔔 "}),V]})}function Tr(){const{t}=Ie(),{deviceId:e,windowId:s,paneId:c}=et(),u=ht(),w=Yt(),g=c?tt(c):void 0,x=ge(S=>S.inputMode),I=ge(S=>S.setInputMode),V=H(S=>{var Y;return e?((Y=S.deviceConnected)==null?void 0:Y[e])??!1:!1}),X=H(S=>e?S.snapshots[e]:void 0),E=n.useMemo(()=>{var S;if(!(!s||!((S=X==null?void 0:X.session)!=null&&S.windows)))return X.session.windows.find(Y=>Y.id===s)},[s,X]),M=n.useCallback(S=>{!e||!s||u(`/devices/${e}/windows/${s}/panes/${Pe(S)}`,{replace:!0})},[e,s,u]),Z=n.useMemo(()=>{if(!(!g||!E))return E.panes.find(S=>S.id===g)},[g,E]),r=n.useCallback(S=>{!e||!g||H.getState().splitPane(e,g,S,Z==null?void 0:Z.currentPath)},[e,g,Z==null?void 0:Z.currentPath]),[oe,P]=n.useState(!1),[ce,ee]=n.useState(!1),[we,ae]=n.useState(!1),h=!!(g&&V),b=(nt({queryKey:Vt(e??"",g??""),queryFn:()=>Ut(e??"",g??""),enabled:!!(e&&g),throwOnError:!1}).data??[]).some(S=>S.enabled),T=()=>{I(x==="direct"?"editor":"direct")},C=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},A=()=>{P(!0)},W=()=>{window.location.reload()};return i.jsxs(i.Fragment,{children:[w&&g&&E&&E.panes.length>1&&i.jsx(Gn,{window:E,currentPaneId:g,onSelectPane:M}),!w&&i.jsxs(i.Fragment,{children:[i.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:()=>r("right"),disabled:!h,"data-testid":"split-right-button","aria-label":t("window.splitRight"),title:t("window.splitRight"),children:i.jsx(Kt,{className:"h-4 w-4"})}),i.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:()=>r("down"),disabled:!h,"data-testid":"split-down-button","aria-label":t("window.splitDown"),title:t("window.splitDown"),children:i.jsx(Gt,{className:"h-4 w-4"})})]}),i.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:A,"aria-label":t("nav.refreshPage"),title:t("nav.refreshPage"),children:i.jsx(fn,{className:"h-4 w-4"})}),i.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:T,disabled:!h,"data-testid":"terminal-input-mode-toggle","aria-label":t(x==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:t(x==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:x==="direct"?i.jsx(vn,{className:"h-4 w-4"}):i.jsx(Pn,{className:"h-4 w-4"})}),i.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:C,disabled:!h,"aria-label":t("nav.jumpToLatest"),title:t("nav.jumpToLatest"),children:i.jsx(hn,{className:"h-4 w-4"})}),i.jsxs(Ne,{variant:"ghost",size:"icon-sm",className:"relative",onClick:()=>ee(!0),disabled:!g,"data-testid":"watch-open-button","aria-label":t("watch.title"),title:t("watch.title"),children:[i.jsx(Qt,{className:"h-4 w-4"}),b&&i.jsx("span",{className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-primary","data-testid":"watch-active-indicator"})]}),i.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:()=>ae(!0),"data-testid":"keyboard-behavior-open-button","aria-label":t("settings.terminal.title"),title:t("settings.terminal.title"),children:i.jsx(Cn,{className:"h-4 w-4"})}),i.jsx(kn,{open:we,onOpenChange:ae}),e&&g&&i.jsx(Jt,{open:ce,onOpenChange:ee,deviceId:e,paneId:g}),i.jsx(Zt,{open:oe,onOpenChange:P,children:i.jsxs(en,{children:[i.jsxs(tn,{children:[i.jsx(nn,{children:t("nav.refreshPage")}),i.jsx(rn,{children:t("nav.refreshPageConfirm")})]}),i.jsxs(sn,{children:[i.jsx(on,{onClick:()=>P(!1),children:t("common.cancel")}),i.jsx(cn,{onClick:W,children:t("common.confirm")})]})]})})]})}export{Tr as PageActions,Rr as PageTitle,Er as default};
@@ -1 +1 @@
1
- import{u as b,r as v,a as _,b as ie,c as re,d as ne,e as I,t as oe,j as s,M as X,B as C,P as Y,A as ce,f as de,g as le,h as ue,T as ee,i as me,k as he,l as pe,m as xe,n as ve,G as fe,o as f,D as ge,p as ye,E as je,q as we,s as $,v as Ne,w as De,x as Q,y as Ce,S as be,L as Se,z as ke,C as Ee,F as Me,H as Pe,I as Ie,J as Ke,K as x,N as z,O as V,Q as U,R as J,U as w,V as Re,W as $e}from"./index-B3ddLSja.js";import{C as M,a as P,b as Ae,c as Te,d as Fe}from"./card-DmfNw0hd.js";import{Z as We}from"./zap-BFIAXPXd.js";function g(e){const o=e.trim();return o||void 0}function qe(e){return e?{name:e.name,type:e.type,host:e.host??"",port:e.port??22,username:e.username??"",sshConfigRef:e.sshConfigRef??"",session:e.session??"tmex",defaultWorkingDir:e.defaultWorkingDir??"",authMode:e.type==="local"?"auto":e.authMode,password:"",privateKey:"",privateKeyPassphrase:""}:{name:"",type:"local",host:"",port:22,username:"root",sshConfigRef:"",session:"tmex",defaultWorkingDir:"",authMode:"auto",password:"",privateKey:"",privateKeyPassphrase:""}}function Le(e){if(e.type==="local")return{name:e.name.trim(),type:"local",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:"auto"};const o={name:e.name.trim(),type:"ssh",host:e.host.trim(),port:e.port,username:e.username.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:e.authMode};return e.authMode==="configRef"&&(o.sshConfigRef=e.sshConfigRef.trim()),e.authMode==="password"&&(o.password=e.password),e.authMode==="key"&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function He(e){if(e.type==="local")return{name:e.name.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:"auto"};const o={name:e.name.trim(),host:e.host.trim(),port:e.port,username:e.username.trim(),sshConfigRef:e.authMode==="configRef"?e.sshConfigRef.trim():"",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:e.authMode};return e.authMode==="password"&&e.password&&(o.password=e.password),e.authMode==="key"&&e.privateKey&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function se(e){return Number.isInteger(e)&&e>=1&&e<=65535}function Oe(e){return e.type!=="ssh"?null:e.host.trim()?se(e.port)?e.username.trim()?e.authMode==="configRef"&&!e.sshConfigRef.trim()?"validation.sshConfigRequired":null:"validation.usernameRequired":"validation.portRequired":"validation.hostRequired"}async function G(e,o){try{return(await e.json()).error??o}catch{return o}}function Ue(){const{t:e}=b(),[o,m]=v.useState(!1),[t,y]=v.useState(null),[r,d]=v.useState(null),l=_(),h=ie(n=>{var p;return((p=n.settings)==null?void 0:p.language)??"en_US"});v.useEffect(()=>{const n=()=>m(!0);return window.addEventListener("tmex:open-add-device",n),()=>window.removeEventListener("tmex:open-add-device",n)},[]);const{data:c,isLoading:K,isError:N}=re({queryKey:["devices"],queryFn:async()=>{const n=await fetch("/api/devices");if(!n.ok)throw new Error(e("device.loadFailed"));return n.json()},throwOnError:!1}),S=ne(n=>n.hydrateDeviceErrors);v.useEffect(()=>{c!=null&&c.devices&&S(c.devices.map(n=>({deviceId:n.id,lastError:n.lastError??null,lastErrorType:n.lastErrorType??null})))},[c,S]);const k=I({mutationFn:async n=>{if(!(await fetch(`/api/devices/${n}`,{method:"DELETE"})).ok)throw new Error(e("device.deleteFailed"))},onSuccess:()=>{l.invalidateQueries({queryKey:["devices"]}),f.success(e("common.success"))},onError:n=>{f.error(n instanceof Error?n.message:e("common.error"))}}),E=v.useMemo(()=>[...(c==null?void 0:c.devices)??[]].sort((p,D)=>p.sortOrder-D.sortOrder||p.name.localeCompare(D.name,oe(h),{numeric:!0,sensitivity:"base"})),[c==null?void 0:c.devices,h]);return s.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-3 p-3 pb-[calc(1rem+env(safe-area-inset-bottom))] sm:gap-4 sm:p-5","data-testid":"devices-page",children:[K?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-muted-foreground",children:e("common.loading")})}):N?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-destructive",children:e("device.loadFailed")})}):E.length===0?s.jsx(M,{children:s.jsxs(P,{className:"space-y-4 py-14 text-center",children:[s.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl border border-border bg-muted",children:s.jsx(X,{className:"h-6 w-6 text-muted-foreground"})}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-medium",children:e("device.noDevices")}),s.jsx("p",{className:"text-sm text-muted-foreground",children:e("device.addDevice")})]}),s.jsxs(C,{variant:"default","data-testid":"devices-add-empty",onClick:()=>m(!0),children:[s.jsx(Y,{className:"h-4 w-4"}),e("device.addDevice")]})]})}):s.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:E.map(n=>s.jsx(Be,{device:n,onEdit:()=>y(n),onDelete:()=>d(n)},n.id))}),o&&s.jsx(Z,{mode:"create",onClose:()=>m(!1)}),t&&s.jsx(Z,{mode:"edit",device:t,onClose:()=>y(null)}),s.jsx(ce,{open:r!==null,onOpenChange:n=>!n&&d(null),children:s.jsxs(de,{children:[s.jsxs(le,{children:[s.jsx(ue,{className:"bg-destructive/10",children:s.jsx(ee,{className:"h-5 w-5 text-destructive"})}),s.jsx(me,{children:e("device.deleteConfirm")}),s.jsx(he,{children:e("device.deleteDescription",{name:(r==null?void 0:r.name)??""})})]}),s.jsxs(pe,{children:[s.jsx(xe,{children:e("common.cancel")}),s.jsx(ve,{variant:"destructive",disabled:!r||k.isPending,onClick:()=>{r&&(k.mutate(r.id),d(null))},children:e("common.delete")})]})]})})]})}function Be({device:e,onEdit:o,onDelete:m}){const{t}=b(),y=e.type==="local"?s.jsx(X,{className:"h-4 w-4"}):s.jsx(fe,{className:"h-4 w-4"}),r=e.type==="local"?t("device.typeLocal"):`${e.username??"-"}@${e.host??"-"}:${e.port??22}`,d=I({mutationFn:async()=>{const l=await fetch(`/api/devices/${e.id}/test-connection`,{method:"POST"});let h=null;try{h=await l.json()}catch{h=null}if(!l.ok){const c=h;throw new Error((c==null?void 0:c.error)??t("common.error"))}return h},onSuccess:l=>{f.success(l.message??t("common.success"))},onError:l=>{f.error(l instanceof Error?l.message:t("common.error"))}});return s.jsxs(M,{"data-testid":"device-card","data-device-id":e.id,"data-device-name":e.name,className:"overflow-hidden border-border/50",children:[s.jsxs(Ae,{className:"space-y-2 pb-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[s.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border bg-muted text-muted-foreground",children:y}),s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsx(Te,{className:"line-clamp-1 text-sm",title:e.name,children:e.name}),s.jsx(Fe,{className:"line-clamp-1 text-xs",children:r})]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:s.jsxs(ge,{children:[s.jsx(ye,{render:s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":`device-card-actions-${e.id}`,"aria-label":t("common.edit"),title:t("common.edit")}),children:s.jsx(je,{className:"h-4 w-4"})}),s.jsxs(we,{align:"end",children:[s.jsxs($,{"data-testid":`device-card-edit-${e.id}`,onClick:o,children:[s.jsx(Ne,{className:"h-4 w-4"}),t("common.edit")]}),e.type==="ssh"&&s.jsxs($,{"data-testid":`device-card-test-${e.id}`,onClick:()=>d.mutate(),disabled:d.isPending,children:[s.jsx(We,{className:"h-4 w-4"}),t("common.test")]}),s.jsx(De,{}),s.jsxs($,{"data-testid":`device-card-delete-${e.id}`,variant:"destructive",onClick:m,children:[s.jsx(ee,{className:"h-4 w-4"}),t("common.delete")]})]})]})})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.type==="local"?t("device.typeLocal"):t("device.typeSSHBadge")}),e.session&&s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.session}),s.jsx(Ce,{deviceId:e.id})]})]}),s.jsxs(P,{className:"pt-0",children:[s.jsx(be,{className:"mb-2"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(Se,{to:`/devices/${e.id}`,"data-testid":`device-card-connect-${e.id}`,className:ke({variant:"outline",size:"sm"}),children:t("device.connect")})})]})]})}function Z({mode:e,device:o,onClose:m}){const{t}=b(),y=_(),[r,d]=v.useState(qe(o)),[l,h]=v.useState(!1),[c,K]=v.useState(!1),N=e==="edit",S=r.type==="ssh",k=I({mutationFn:async a=>{const i=await fetch("/api/devices",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.createFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),E=I({mutationFn:async a=>{if(!o)throw new Error(t("apiError.deviceNotFound"));const i=await fetch(`/api/devices/${o.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.updateFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),n=async a=>{a.preventDefault(),K(!0);const i=Oe(r);if(i){f.error(t(i));return}h(!0);try{e==="create"?await k.mutateAsync(Le(r)):await E.mutateAsync(He(r))}catch{}finally{h(!1)}},p=`${e}-device-name`,D=`${e}-device-type`,A=`${e}-device-host`,T=`${e}-device-port`,F=`${e}-device-username`,W=`${e}-device-session`,q=`${e}-device-default-working-dir`,L=`${e}-device-auth-mode`,H=`${e}-device-password`,O=`${e}-device-private-key`,B=`${e}-device-private-key-passphrase`,te={local:t("device.typeLocal"),ssh:t("device.typeSSH")},ae={password:t("device.authPassword"),key:t("device.authKey"),agent:t("device.authAgent"),configRef:t("device.authConfigRef")},R=a=>s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:a}),u=(a,i,j)=>s.jsxs("label",{className:"block text-xs font-medium text-foreground",htmlFor:a,children:[i,j&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]});return s.jsx(Ee,{open:!0,onOpenChange:a=>!a&&m(),children:s.jsxs(Me,{"data-testid":"device-dialog",className:"w-full max-w-2xl",children:[s.jsxs(Pe,{children:[s.jsx(Ie,{children:t(N?"device.editDevice":"device.addDevice")}),s.jsx(Ke,{children:t(N?"device.editDeviceDescription":"device.addDeviceDescription")})]}),s.jsxs("form",{onSubmit:n,className:"space-y-4",children:[s.jsxs("div",{className:"-mr-2 max-h-[min(70dvh,720px)] space-y-5 overflow-y-auto pr-2",children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionBasic")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(p,t("device.name"),!0),s.jsx(x,{id:p,"data-testid":"device-name-input",type:"text",value:r.name,onChange:a=>d(i=>({...i,name:a.target.value})),placeholder:t("device.namePlaceholder"),required:!0})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(D,t("device.type")),s.jsxs(z,{value:r.type,onValueChange:a=>{if(!a)return;const i=a;d(j=>({...j,type:i,authMode:i==="local"?"auto":j.authMode==="auto"?"agent":j.authMode}))},disabled:N,children:[s.jsx(V,{id:D,"data-testid":"device-type-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.type"),children:a=>te[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"local",children:t("device.typeLocal")}),s.jsx(w,{value:"ssh",children:t("device.typeSSH")})]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(W,t("device.session")),s.jsx(x,{id:W,"data-testid":"device-session-input",type:"text",value:r.session,onChange:a=>d(i=>({...i,session:a.target.value})),placeholder:t("device.sessionPlaceholder")})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(q,t("device.defaultWorkingDir")),s.jsx(x,{id:q,"data-testid":"device-default-working-dir-input",type:"text",value:r.defaultWorkingDir,onChange:a=>d(i=>({...i,defaultWorkingDir:a.target.value})),placeholder:t("device.defaultWorkingDirPlaceholder")})]})]})]}),S&&s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionConnection")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(A,t("device.host"),!0),s.jsx(x,{id:A,type:"text",value:r.host,onChange:a=>d(i=>({...i,host:a.target.value})),placeholder:t("device.hostPlaceholder"),"aria-invalid":c&&!r.host.trim()})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(T,t("device.port"),!0),s.jsx(x,{id:T,type:"number",value:Number.isNaN(r.port)?"":r.port,onChange:a=>{const i=a.target.value;d(j=>({...j,port:i===""?Number.NaN:Number.parseInt(i,10)}))},min:1,max:65535,"aria-invalid":c&&!se(r.port)})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(F,t("device.username"),!0),s.jsx(x,{id:F,type:"text",value:r.username,onChange:a=>d(i=>({...i,username:a.target.value})),placeholder:t("device.usernamePlaceholder"),"aria-invalid":c&&!r.username.trim()})]})]})]}),s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionAuth")),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[u(L,t("device.authMode")),s.jsxs(z,{value:r.authMode,onValueChange:a=>{a&&d(i=>({...i,authMode:a}))},children:[s.jsx(V,{id:L,"data-testid":"device-auth-mode-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.authMode"),children:a=>ae[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"password",children:t("device.authPassword")}),s.jsx(w,{value:"key",children:t("device.authKey")}),s.jsx(w,{value:"agent",children:t("device.authAgent")}),s.jsx(w,{value:"configRef",children:t("device.authConfigRef")})]})]})]}),r.authMode==="password"&&s.jsxs("div",{className:"space-y-1.5",children:[u(H,t("device.password")),s.jsx(x,{id:H,type:"password",value:r.password,onChange:a=>d(i=>({...i,password:a.target.value}))})]}),r.authMode==="key"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"space-y-1.5",children:[u(O,t("device.privateKey")),s.jsx(Re,{id:O,value:r.privateKey,onChange:a=>d(i=>({...i,privateKey:a.target.value})),className:"h-28 font-mono text-xs",placeholder:t("device.privateKeyPlaceholder")})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(B,t("device.passphrase")),s.jsx(x,{id:B,type:"password",value:r.privateKeyPassphrase,onChange:a=>d(i=>({...i,privateKeyPassphrase:a.target.value}))})]})]}),r.authMode==="configRef"&&s.jsxs("div",{className:"space-y-1.5",children:[u(`${e}-device-ssh-config-ref`,t("device.authConfigRef"),!0),s.jsx(x,{id:`${e}-device-ssh-config-ref`,"data-testid":"device-ssh-config-ref-input",type:"text",value:r.sshConfigRef,onChange:a=>d(i=>({...i,sshConfigRef:a.target.value})),placeholder:t("device.sshConfigRefPlaceholder"),"aria-invalid":c&&!r.sshConfigRef.trim()}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("device.sshConfigRefHint")})]})]})]})]})]}),s.jsxs($e,{children:[s.jsx(C,{type:"button",variant:"outline",onClick:m,children:t("common.cancel")}),s.jsx(C,{type:"submit",variant:"default","data-testid":"device-dialog-save",disabled:l,children:t(l?"common.saving":"common.save")})]})]})]})})}function Je(){const{t:e}=b();return s.jsx(s.Fragment,{children:e("sidebar.manageDevices")})}function Ge(){const{t:e}=b(),o=()=>{window.dispatchEvent(new CustomEvent("tmex:open-add-device"))};return s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":"devices-add",onClick:o,"aria-label":e("sidebar.addDevice"),title:e("sidebar.addDevice"),children:s.jsx(Y,{className:"h-4 w-4"})})}export{Ge as PageActions,Je as PageTitle,Ue as default};
1
+ import{u as b,r as v,a as _,b as ie,c as re,d as ne,e as I,t as oe,j as s,M as X,B as C,P as Y,A as ce,f as de,g as le,h as ue,T as ee,i as me,k as he,l as pe,m as xe,n as ve,G as fe,o as f,D as ge,p as ye,E as je,q as we,s as $,v as Ne,w as De,x as Q,y as Ce,S as be,L as Se,z as ke,C as Ee,F as Me,H as Pe,I as Ie,J as Ke,K as x,N as z,O as V,Q as U,R as J,U as w,V as Re,W as $e}from"./index-Dc3Fwpho.js";import{C as M,a as P,b as Ae,c as Te,d as Fe}from"./card-DWQzPt-3.js";import{Z as We}from"./zap-DcJ8Gp1I.js";function g(e){const o=e.trim();return o||void 0}function qe(e){return e?{name:e.name,type:e.type,host:e.host??"",port:e.port??22,username:e.username??"",sshConfigRef:e.sshConfigRef??"",session:e.session??"tmex",defaultWorkingDir:e.defaultWorkingDir??"",authMode:e.type==="local"?"auto":e.authMode,password:"",privateKey:"",privateKeyPassphrase:""}:{name:"",type:"local",host:"",port:22,username:"root",sshConfigRef:"",session:"tmex",defaultWorkingDir:"",authMode:"auto",password:"",privateKey:"",privateKeyPassphrase:""}}function Le(e){if(e.type==="local")return{name:e.name.trim(),type:"local",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:"auto"};const o={name:e.name.trim(),type:"ssh",host:e.host.trim(),port:e.port,username:e.username.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:e.authMode};return e.authMode==="configRef"&&(o.sshConfigRef=e.sshConfigRef.trim()),e.authMode==="password"&&(o.password=e.password),e.authMode==="key"&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function He(e){if(e.type==="local")return{name:e.name.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:"auto"};const o={name:e.name.trim(),host:e.host.trim(),port:e.port,username:e.username.trim(),sshConfigRef:e.authMode==="configRef"?e.sshConfigRef.trim():"",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:e.authMode};return e.authMode==="password"&&e.password&&(o.password=e.password),e.authMode==="key"&&e.privateKey&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function se(e){return Number.isInteger(e)&&e>=1&&e<=65535}function Oe(e){return e.type!=="ssh"?null:e.host.trim()?se(e.port)?e.username.trim()?e.authMode==="configRef"&&!e.sshConfigRef.trim()?"validation.sshConfigRequired":null:"validation.usernameRequired":"validation.portRequired":"validation.hostRequired"}async function G(e,o){try{return(await e.json()).error??o}catch{return o}}function Ue(){const{t:e}=b(),[o,m]=v.useState(!1),[t,y]=v.useState(null),[r,d]=v.useState(null),l=_(),h=ie(n=>{var p;return((p=n.settings)==null?void 0:p.language)??"en_US"});v.useEffect(()=>{const n=()=>m(!0);return window.addEventListener("tmex:open-add-device",n),()=>window.removeEventListener("tmex:open-add-device",n)},[]);const{data:c,isLoading:K,isError:N}=re({queryKey:["devices"],queryFn:async()=>{const n=await fetch("/api/devices");if(!n.ok)throw new Error(e("device.loadFailed"));return n.json()},throwOnError:!1}),S=ne(n=>n.hydrateDeviceErrors);v.useEffect(()=>{c!=null&&c.devices&&S(c.devices.map(n=>({deviceId:n.id,lastError:n.lastError??null,lastErrorType:n.lastErrorType??null})))},[c,S]);const k=I({mutationFn:async n=>{if(!(await fetch(`/api/devices/${n}`,{method:"DELETE"})).ok)throw new Error(e("device.deleteFailed"))},onSuccess:()=>{l.invalidateQueries({queryKey:["devices"]}),f.success(e("common.success"))},onError:n=>{f.error(n instanceof Error?n.message:e("common.error"))}}),E=v.useMemo(()=>[...(c==null?void 0:c.devices)??[]].sort((p,D)=>p.sortOrder-D.sortOrder||p.name.localeCompare(D.name,oe(h),{numeric:!0,sensitivity:"base"})),[c==null?void 0:c.devices,h]);return s.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-3 p-3 pb-[calc(1rem+env(safe-area-inset-bottom))] sm:gap-4 sm:p-5","data-testid":"devices-page",children:[K?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-muted-foreground",children:e("common.loading")})}):N?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-destructive",children:e("device.loadFailed")})}):E.length===0?s.jsx(M,{children:s.jsxs(P,{className:"space-y-4 py-14 text-center",children:[s.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl border border-border bg-muted",children:s.jsx(X,{className:"h-6 w-6 text-muted-foreground"})}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-medium",children:e("device.noDevices")}),s.jsx("p",{className:"text-sm text-muted-foreground",children:e("device.addDevice")})]}),s.jsxs(C,{variant:"default","data-testid":"devices-add-empty",onClick:()=>m(!0),children:[s.jsx(Y,{className:"h-4 w-4"}),e("device.addDevice")]})]})}):s.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:E.map(n=>s.jsx(Be,{device:n,onEdit:()=>y(n),onDelete:()=>d(n)},n.id))}),o&&s.jsx(Z,{mode:"create",onClose:()=>m(!1)}),t&&s.jsx(Z,{mode:"edit",device:t,onClose:()=>y(null)}),s.jsx(ce,{open:r!==null,onOpenChange:n=>!n&&d(null),children:s.jsxs(de,{children:[s.jsxs(le,{children:[s.jsx(ue,{className:"bg-destructive/10",children:s.jsx(ee,{className:"h-5 w-5 text-destructive"})}),s.jsx(me,{children:e("device.deleteConfirm")}),s.jsx(he,{children:e("device.deleteDescription",{name:(r==null?void 0:r.name)??""})})]}),s.jsxs(pe,{children:[s.jsx(xe,{children:e("common.cancel")}),s.jsx(ve,{variant:"destructive",disabled:!r||k.isPending,onClick:()=>{r&&(k.mutate(r.id),d(null))},children:e("common.delete")})]})]})})]})}function Be({device:e,onEdit:o,onDelete:m}){const{t}=b(),y=e.type==="local"?s.jsx(X,{className:"h-4 w-4"}):s.jsx(fe,{className:"h-4 w-4"}),r=e.type==="local"?t("device.typeLocal"):`${e.username??"-"}@${e.host??"-"}:${e.port??22}`,d=I({mutationFn:async()=>{const l=await fetch(`/api/devices/${e.id}/test-connection`,{method:"POST"});let h=null;try{h=await l.json()}catch{h=null}if(!l.ok){const c=h;throw new Error((c==null?void 0:c.error)??t("common.error"))}return h},onSuccess:l=>{f.success(l.message??t("common.success"))},onError:l=>{f.error(l instanceof Error?l.message:t("common.error"))}});return s.jsxs(M,{"data-testid":"device-card","data-device-id":e.id,"data-device-name":e.name,className:"overflow-hidden border-border/50",children:[s.jsxs(Ae,{className:"space-y-2 pb-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[s.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border bg-muted text-muted-foreground",children:y}),s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsx(Te,{className:"line-clamp-1 text-sm",title:e.name,children:e.name}),s.jsx(Fe,{className:"line-clamp-1 text-xs",children:r})]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:s.jsxs(ge,{children:[s.jsx(ye,{render:s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":`device-card-actions-${e.id}`,"aria-label":t("common.edit"),title:t("common.edit")}),children:s.jsx(je,{className:"h-4 w-4"})}),s.jsxs(we,{align:"end",children:[s.jsxs($,{"data-testid":`device-card-edit-${e.id}`,onClick:o,children:[s.jsx(Ne,{className:"h-4 w-4"}),t("common.edit")]}),e.type==="ssh"&&s.jsxs($,{"data-testid":`device-card-test-${e.id}`,onClick:()=>d.mutate(),disabled:d.isPending,children:[s.jsx(We,{className:"h-4 w-4"}),t("common.test")]}),s.jsx(De,{}),s.jsxs($,{"data-testid":`device-card-delete-${e.id}`,variant:"destructive",onClick:m,children:[s.jsx(ee,{className:"h-4 w-4"}),t("common.delete")]})]})]})})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.type==="local"?t("device.typeLocal"):t("device.typeSSHBadge")}),e.session&&s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.session}),s.jsx(Ce,{deviceId:e.id})]})]}),s.jsxs(P,{className:"pt-0",children:[s.jsx(be,{className:"mb-2"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(Se,{to:`/devices/${e.id}`,"data-testid":`device-card-connect-${e.id}`,className:ke({variant:"outline",size:"sm"}),children:t("device.connect")})})]})]})}function Z({mode:e,device:o,onClose:m}){const{t}=b(),y=_(),[r,d]=v.useState(qe(o)),[l,h]=v.useState(!1),[c,K]=v.useState(!1),N=e==="edit",S=r.type==="ssh",k=I({mutationFn:async a=>{const i=await fetch("/api/devices",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.createFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),E=I({mutationFn:async a=>{if(!o)throw new Error(t("apiError.deviceNotFound"));const i=await fetch(`/api/devices/${o.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.updateFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),n=async a=>{a.preventDefault(),K(!0);const i=Oe(r);if(i){f.error(t(i));return}h(!0);try{e==="create"?await k.mutateAsync(Le(r)):await E.mutateAsync(He(r))}catch{}finally{h(!1)}},p=`${e}-device-name`,D=`${e}-device-type`,A=`${e}-device-host`,T=`${e}-device-port`,F=`${e}-device-username`,W=`${e}-device-session`,q=`${e}-device-default-working-dir`,L=`${e}-device-auth-mode`,H=`${e}-device-password`,O=`${e}-device-private-key`,B=`${e}-device-private-key-passphrase`,te={local:t("device.typeLocal"),ssh:t("device.typeSSH")},ae={password:t("device.authPassword"),key:t("device.authKey"),agent:t("device.authAgent"),configRef:t("device.authConfigRef")},R=a=>s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:a}),u=(a,i,j)=>s.jsxs("label",{className:"block text-xs font-medium text-foreground",htmlFor:a,children:[i,j&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]});return s.jsx(Ee,{open:!0,onOpenChange:a=>!a&&m(),children:s.jsxs(Me,{"data-testid":"device-dialog",className:"w-full max-w-2xl",children:[s.jsxs(Pe,{children:[s.jsx(Ie,{children:t(N?"device.editDevice":"device.addDevice")}),s.jsx(Ke,{children:t(N?"device.editDeviceDescription":"device.addDeviceDescription")})]}),s.jsxs("form",{onSubmit:n,className:"space-y-4",children:[s.jsxs("div",{className:"-mr-2 max-h-[min(70dvh,720px)] space-y-5 overflow-y-auto pr-2",children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionBasic")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(p,t("device.name"),!0),s.jsx(x,{id:p,"data-testid":"device-name-input",type:"text",value:r.name,onChange:a=>d(i=>({...i,name:a.target.value})),placeholder:t("device.namePlaceholder"),required:!0})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(D,t("device.type")),s.jsxs(z,{value:r.type,onValueChange:a=>{if(!a)return;const i=a;d(j=>({...j,type:i,authMode:i==="local"?"auto":j.authMode==="auto"?"agent":j.authMode}))},disabled:N,children:[s.jsx(V,{id:D,"data-testid":"device-type-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.type"),children:a=>te[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"local",children:t("device.typeLocal")}),s.jsx(w,{value:"ssh",children:t("device.typeSSH")})]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(W,t("device.session")),s.jsx(x,{id:W,"data-testid":"device-session-input",type:"text",value:r.session,onChange:a=>d(i=>({...i,session:a.target.value})),placeholder:t("device.sessionPlaceholder")})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(q,t("device.defaultWorkingDir")),s.jsx(x,{id:q,"data-testid":"device-default-working-dir-input",type:"text",value:r.defaultWorkingDir,onChange:a=>d(i=>({...i,defaultWorkingDir:a.target.value})),placeholder:t("device.defaultWorkingDirPlaceholder")})]})]})]}),S&&s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionConnection")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(A,t("device.host"),!0),s.jsx(x,{id:A,type:"text",value:r.host,onChange:a=>d(i=>({...i,host:a.target.value})),placeholder:t("device.hostPlaceholder"),"aria-invalid":c&&!r.host.trim()})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(T,t("device.port"),!0),s.jsx(x,{id:T,type:"number",value:Number.isNaN(r.port)?"":r.port,onChange:a=>{const i=a.target.value;d(j=>({...j,port:i===""?Number.NaN:Number.parseInt(i,10)}))},min:1,max:65535,"aria-invalid":c&&!se(r.port)})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(F,t("device.username"),!0),s.jsx(x,{id:F,type:"text",value:r.username,onChange:a=>d(i=>({...i,username:a.target.value})),placeholder:t("device.usernamePlaceholder"),"aria-invalid":c&&!r.username.trim()})]})]})]}),s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionAuth")),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[u(L,t("device.authMode")),s.jsxs(z,{value:r.authMode,onValueChange:a=>{a&&d(i=>({...i,authMode:a}))},children:[s.jsx(V,{id:L,"data-testid":"device-auth-mode-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.authMode"),children:a=>ae[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"password",children:t("device.authPassword")}),s.jsx(w,{value:"key",children:t("device.authKey")}),s.jsx(w,{value:"agent",children:t("device.authAgent")}),s.jsx(w,{value:"configRef",children:t("device.authConfigRef")})]})]})]}),r.authMode==="password"&&s.jsxs("div",{className:"space-y-1.5",children:[u(H,t("device.password")),s.jsx(x,{id:H,type:"password",value:r.password,onChange:a=>d(i=>({...i,password:a.target.value}))})]}),r.authMode==="key"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"space-y-1.5",children:[u(O,t("device.privateKey")),s.jsx(Re,{id:O,value:r.privateKey,onChange:a=>d(i=>({...i,privateKey:a.target.value})),className:"h-28 font-mono text-xs",placeholder:t("device.privateKeyPlaceholder")})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(B,t("device.passphrase")),s.jsx(x,{id:B,type:"password",value:r.privateKeyPassphrase,onChange:a=>d(i=>({...i,privateKeyPassphrase:a.target.value}))})]})]}),r.authMode==="configRef"&&s.jsxs("div",{className:"space-y-1.5",children:[u(`${e}-device-ssh-config-ref`,t("device.authConfigRef"),!0),s.jsx(x,{id:`${e}-device-ssh-config-ref`,"data-testid":"device-ssh-config-ref-input",type:"text",value:r.sshConfigRef,onChange:a=>d(i=>({...i,sshConfigRef:a.target.value})),placeholder:t("device.sshConfigRefPlaceholder"),"aria-invalid":c&&!r.sshConfigRef.trim()}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("device.sshConfigRefHint")})]})]})]})]})]}),s.jsxs($e,{children:[s.jsx(C,{type:"button",variant:"outline",onClick:m,children:t("common.cancel")}),s.jsx(C,{type:"submit",variant:"default","data-testid":"device-dialog-save",disabled:l,children:t(l?"common.saving":"common.save")})]})]})]})})}function Je(){const{t:e}=b();return s.jsx(s.Fragment,{children:e("sidebar.manageDevices")})}function Ge(){const{t:e}=b(),o=()=>{window.dispatchEvent(new CustomEvent("tmex:open-add-device"))};return s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":"devices-add",onClick:o,"aria-label":e("sidebar.addDevice"),title:e("sidebar.addDevice"),children:s.jsx(Y,{className:"h-4 w-4"})})}export{Ge as PageActions,Je as PageTitle,Ue as default};
@@ -1,4 +1,4 @@
1
- import{Y as zn,_ as ut,r as oe,j as h,X as gt,aL as bt,u as ae,c as $n,aq as qn,a as mt,B as se,Z as nn}from"./index-B3ddLSja.js";import{r as pt,M as _t}from"./markdown-preview-CBGlxpTs.js";import{k as ft,d as Ve,l as te,D as Kn,m as Et,f as ht,c as Nt}from"./api-DV7-9Pvt.js";import{R as yt,s as vt}from"./transfer-toast-DXl4RHsV.js";import"./index-iee3U_rD.js";/**
1
+ import{Y as zn,_ as ut,r as oe,j as h,X as gt,aM as bt,u as ae,c as $n,aq as qn,a as mt,B as se,Z as nn}from"./index-Dc3Fwpho.js";import{r as pt,M as _t}from"./markdown-preview-BsYVAcJ1.js";import{k as ft,d as Ve,l as te,D as Kn,m as Et,f as ht,c as Nt}from"./api-DZDjPn8l.js";import{R as yt,s as vt}from"./transfer-toast-D72q4082.js";import"./index-C2v9tHtI.js";/**
2
2
  * @license lucide-react v0.564.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -0,0 +1,39 @@
1
+ import{Y as ce,u as F,j as e,L as Pt,M as Ye,z as Ft,r as y,c as K,B as k,P as xe,a as O,e as M,o as b,a2 as _,v as Oe,T as te,A as fe,f as pe,g as we,h as At,i as ye,k as je,l as ve,m as be,n as Ne,C as ae,F as ne,H as ie,I as re,J as Ce,N as Ee,O as ke,Q as Se,R as Me,U as le,K as D,W as de,aq as Q,G as Tt,x as dt,at as Rt,b as ge,t as Xe,bt as $,X as mt,af as It,bu as Lt,bv as $t,aB as Dt,bw as Ot,bx as Bt,by as _t,bz as zt,bA as et,Z as qt}from"./index-Dc3Fwpho.js";import{C as U,b as G,c as W,d as ut,a as H}from"./card-DWQzPt-3.js";import{e as Kt,h as ht,F as He,i as Qt,j as Ut,D as Ht}from"./api-DZDjPn8l.js";import{R as Ze,T as Vt,b as Gt,d as Wt}from"./terminal-settings-panel-tZuaqdqz.js";import{S as gt}from"./send-J45szXFM.js";import{M as Jt}from"./markdown-preview-BsYVAcJ1.js";import{T as xt}from"./triangle-alert-CagsqsWp.js";import"./selection-clipboard-D3gUQQ7L.js";import"./index-C2v9tHtI.js";/**
2
+ * @license lucide-react v0.564.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const Yt=[["path",{d:"M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z",key:"lc1i9w"}],["path",{d:"m7 16.5-4.74-2.85",key:"1o9zyk"}],["path",{d:"m7 16.5 5-3",key:"va8pkn"}],["path",{d:"M7 16.5v5.17",key:"jnp8gn"}],["path",{d:"M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z",key:"8zsnat"}],["path",{d:"m17 16.5-5-3",key:"8arw3v"}],["path",{d:"m17 16.5 4.74-2.85",key:"8rfmw"}],["path",{d:"M17 16.5v5.17",key:"k6z78m"}],["path",{d:"M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z",key:"1xygjf"}],["path",{d:"M12 8 7.26 5.15",key:"1vbdud"}],["path",{d:"m12 8 4.74-2.85",key:"3rx089"}],["path",{d:"M12 13.5V8",key:"1io7kd"}]],Xt=ce("boxes",Yt);/**
7
+ * @license lucide-react v0.564.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const Zt=[["rect",{width:"5",height:"5",x:"3",y:"3",rx:"1",key:"1tu5fj"}],["rect",{width:"5",height:"5",x:"16",y:"3",rx:"1",key:"1v8r4q"}],["rect",{width:"5",height:"5",x:"3",y:"16",rx:"1",key:"1x03jg"}],["path",{d:"M21 16h-3a2 2 0 0 0-2 2v3",key:"177gqh"}],["path",{d:"M21 21v.01",key:"ents32"}],["path",{d:"M12 7v3a2 2 0 0 1-2 2H7",key:"8crl2c"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M12 3h.01",key:"n36tog"}],["path",{d:"M12 16v.01",key:"133mhm"}],["path",{d:"M16 12h1",key:"1slzba"}],["path",{d:"M21 12v.01",key:"1lwtk9"}],["path",{d:"M12 21v-1",key:"1880an"}]],Ve=ce("qr-code",Zt);/**
12
+ * @license lucide-react v0.564.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const es=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],ee=ce("save",es);/**
17
+ * @license lucide-react v0.564.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const ts=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],ss=ce("server",ts);/**
22
+ * @license lucide-react v0.564.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */const as=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],tt=ce("shield",as);/**
27
+ * @license lucide-react v0.564.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const ns=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],is=ce("users",ns);function rs(){const{t}=F();return e.jsxs(U,{className:"border-0 ring-0",children:[e.jsxs(G,{children:[e.jsx(W,{children:t("settings.deviceManagement.title")}),e.jsx(ut,{children:t("settings.deviceManagement.description")})]}),e.jsx(H,{children:e.jsxs(Pt,{to:"/devices","data-testid":"settings-device-management-link",className:Ft({variant:"secondary"}),children:[e.jsx(Ye,{className:"h-4 w-4"}),t("settings.deviceManagement.openButton")]})})]})}function $e({type:t,className:o}){return t==="ssh"?e.jsx(Tt,{className:o}):e.jsx(Ye,{className:o})}function os(){var r,m;const{t}=F(),[o,s]=y.useState(!1),[l,c]=y.useState(void 0),h=K({queryKey:["files","roots"],queryFn:Kt}),p=K({queryKey:["devices"],queryFn:async()=>{const d=await fetch("/api/devices");if(!d.ok)throw new Error(`HTTP ${d.status}`);return await d.json()},throwOnError:!1}),f=((r=h.data)==null?void 0:r.roots)??[],a=((m=p.data)==null?void 0:m.devices)??[],n=()=>{c(void 0),s(!0)},i=d=>{c(d),s(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0","data-testid":"settings-files-section",children:[e.jsxs(G,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(W,{children:t("settings.files.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settings.files.description")})]}),e.jsxs(k,{variant:"secondary","data-testid":"settings-files-root-add",onClick:n,children:[e.jsx(xe,{className:"h-4 w-4"}),t("settings.files.addRoot")]})]}),e.jsxs(H,{className:"space-y-3",children:[h.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!h.isLoading&&f.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground","data-testid":"settings-files-empty",children:t("settings.files.empty")}),f.map(d=>e.jsx(ls,{root:d,onEdit:i},d.id))]})]}),e.jsx(cs,{open:o,onOpenChange:s,root:l,devices:a})]})}function ls({root:t,onEdit:o}){const{t:s}=F(),l=O(),[c,h]=y.useState(!1),p=M({mutationFn:({id:a,enabled:n})=>ht(a,{enabled:n}),onSuccess:async()=>{await l.invalidateQueries({queryKey:["files"]})},onError:()=>{b.error(s("settings.files.toggleFailed"))}}),f=M({mutationFn:a=>Qt(a),onSuccess:async()=>{await l.invalidateQueries({queryKey:["files"]}),b.success(s("common.success"))},onError:a=>{const n=a instanceof He?a.message:s("settings.files.deleteFailed");b.error(n)}});return e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-border p-3","data-testid":`settings-files-root-${t.id}`,children:[e.jsx(_,{checked:t.enabled,disabled:p.isPending,onCheckedChange:a=>p.mutate({id:t.id,enabled:!!a}),"data-testid":`settings-files-root-enabled-${t.id}`}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx($e,{type:t.deviceType,className:"h-3.5 w-3.5 shrink-0"}),t.deviceName===null?e.jsx("span",{className:"text-destructive",children:s("settings.files.missing")}):e.jsx("span",{className:"truncate",children:t.deviceName})]}),e.jsx("div",{className:"truncate font-mono text-xs",children:t.path}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:t.name})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("common.edit"),"data-testid":`settings-files-root-edit-${t.id}`,onClick:()=>o(t),children:e.jsx(Oe,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("common.delete"),"data-testid":`settings-files-root-delete-${t.id}`,onClick:()=>h(!0),disabled:f.isPending,children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(fe,{open:c,onOpenChange:h,children:e.jsxs(pe,{children:[e.jsxs(we,{children:[e.jsx(At,{className:"bg-destructive/10",children:e.jsx(te,{className:"h-5 w-5 text-destructive"})}),e.jsx(ye,{children:s("settings.files.deleteTitle")}),e.jsx(je,{children:s("settings.files.deleteDesc",{path:t.path})})]}),e.jsxs(ve,{children:[e.jsx(be,{children:s("common.cancel")}),e.jsx(Ne,{variant:"destructive","data-testid":`settings-files-root-delete-confirm-${t.id}`,onClick:()=>{f.mutate(t.id),h(!1)},children:s("common.delete")})]})]})})]})}const st="h-9 w-full";function cs({open:t,onOpenChange:o,root:s,devices:l}){const{t:c}=F(),h=O(),p=!!s,[f,a]=y.useState(""),[n,i]=y.useState(""),[r,m]=y.useState(!0);y.useEffect(()=>{t&&(a((s==null?void 0:s.deviceId)??""),i((s==null?void 0:s.path)??""),m((s==null?void 0:s.enabled)??!0))},[t,s]);const d=M({mutationFn:()=>{const E={deviceId:f,path:n.trim(),enabled:r};return Ut(E)},onSuccess:async()=>{await h.invalidateQueries({queryKey:["files"]}),b.success(c("common.success")),o(!1)},onError:E=>{const z=E instanceof He?E.message:c("settings.files.addFailed");b.error(z)}}),u=M({mutationFn:()=>{if(!s)throw new Error(c("settings.files.updateFailed"));const E={path:n.trim(),enabled:r};return ht(s.id,E)},onSuccess:async()=>{await h.invalidateQueries({queryKey:["files"]}),b.success(c("common.success")),o(!1)},onError:E=>{const z=E instanceof He?E.message:c("settings.files.updateFailed");b.error(z)}}),w=d.isPending||u.isPending,C=n.trim().startsWith("/")&&(p||f.length>0),x=()=>{!C||w||(p?u.mutate():d.mutate())},N=l.find(E=>E.id===f);return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":p?`settings-files-edit-modal-${s==null?void 0:s.id}`:"settings-files-add-modal",children:[e.jsxs(ie,{children:[e.jsx(re,{children:c(p?"settings.files.modalEditTitle":"settings.files.modalAddTitle")}),e.jsx(Ce,{children:c("settings.files.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"files-form-device",children:c("settings.files.device")}),p?e.jsxs("div",{className:"flex h-9 items-center gap-1.5 rounded-lg border border-input bg-muted/30 px-2.5 text-sm",children:[e.jsx($e,{type:(s==null?void 0:s.deviceType)??null,className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:(s==null?void 0:s.deviceName)??c("settings.files.missing")})]}):e.jsxs(Ee,{value:f,onValueChange:E=>{E&&a(E)},children:[e.jsx(ke,{id:"files-form-device","data-testid":"settings-files-device-select",className:st,disabled:l.length===0,children:e.jsx(Se,{children:N?e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($e,{type:N.type,className:"h-4 w-4 shrink-0"}),N.name]}):e.jsx("span",{className:"text-muted-foreground",children:c("settings.files.devicePlaceholder")})})}),e.jsx(Me,{children:l.map(E=>e.jsxs(le,{value:E.id,children:[e.jsx($e,{type:E.type,className:"h-4 w-4 shrink-0"}),E.name]},E.id))})]}),!p&&l.length===0&&e.jsx("p",{className:"text-xs text-destructive",children:c("settings.files.noDevices")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"files-form-path",children:c("settings.files.path")}),e.jsx(D,{id:"files-form-path","data-testid":"settings-files-path-input",value:n,onChange:E=>i(E.target.value),placeholder:c("settings.files.pathPlaceholder"),className:`${st} font-mono`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c("settings.files.pathHint")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{checked:r,onCheckedChange:E=>m(!!E),"data-testid":"settings-files-enabled-switch"}),e.jsx("label",{className:"text-sm font-medium",htmlFor:"settings-files-enabled-switch",children:c("settings.files.enabled")})]})]}),e.jsxs(de,{children:[e.jsx(k,{variant:"outline",onClick:()=>o(!1),disabled:w,children:c("common.cancel")}),e.jsxs(k,{variant:"secondary","data-testid":"settings-files-form-submit",onClick:x,disabled:!C||w,children:[w?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),c("common.save")]})]})]})})}async function Z(t,o){try{return(await t.json()).error??o}catch{return o}}const ds=["openai-chat","openai-responses"],Re="h-9 w-full";function ms({open:t,onOpenChange:o,provider:s}){const{t:l}=F(),c=O(),h=!!s,[p,f]=y.useState(""),[a,n]=y.useState(""),[i,r]=y.useState("openai-chat"),[m,d]=y.useState("");y.useEffect(()=>{t&&(f((s==null?void 0:s.name)??""),n((s==null?void 0:s.baseUrl)??""),r((s==null?void 0:s.protocol)??"openai-chat"),d(""))},[t,s]);const u=M({mutationFn:async()=>{const x={name:p.trim(),protocol:i,baseUrl:a.trim(),apiKey:m.trim(),enabled:!0},N=await fetch("/api/llm/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)});if(!N.ok)throw new Error(await Z(N,l("settings.llm.createFailed")));return await N.json()},onSuccess:async x=>{await c.invalidateQueries({queryKey:["llm-providers"]}),x.modelsError?b.warning(l("settings.llm.modelsFetchFailed",{error:x.modelsError})):b.success(l("common.success")),o(!1)},onError:x=>{b.error(x instanceof Error?x.message:l("common.error"))}}),w=M({mutationFn:async()=>{if(!s)throw new Error(l("settings.llm.updateFailed"));const x={name:p.trim(),baseUrl:a.trim(),protocol:i};m.trim()&&(x.apiKey=m.trim());const N=await fetch(`/api/llm/providers/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)});if(!N.ok)throw new Error(await Z(N,l("settings.llm.updateFailed")));return await N.json()},onSuccess:async x=>{await c.invalidateQueries({queryKey:["llm-providers"]}),x.modelsError?b.warning(l("settings.llm.modelsFetchFailed",{error:x.modelsError})):b.success(l("common.success")),o(!1)},onError:x=>{b.error(x instanceof Error?x.message:l("common.error"))}}),j=u.isPending||w.isPending,g=p.trim().length>0&&a.trim().length>0&&(h||m.trim().length>0),C=()=>{!g||j||(h?w.mutate():u.mutate())};return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":h?`llm-provider-edit-modal-${s==null?void 0:s.id}`:"llm-provider-add-modal",children:[e.jsxs(ie,{children:[e.jsx(re,{children:l(h?"settings.llm.editProvider":"settings.llm.addProvider")}),e.jsx(Ce,{children:l("settings.llm.formHint")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-name",children:l("settings.llm.name")}),e.jsx(D,{id:"llm-form-name","data-testid":"llm-provider-name-input",value:p,onChange:x=>f(x.target.value),placeholder:l("settings.llm.namePlaceholder"),className:Re})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-baseurl",children:l("settings.llm.baseUrl")}),e.jsx(D,{id:"llm-form-baseurl","data-testid":"llm-provider-baseurl-input",value:a,onChange:x=>n(x.target.value),placeholder:l("settings.llm.baseUrlPlaceholder"),className:Re}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.llm.baseUrlHint")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-protocol",children:l("settings.llm.protocol")}),e.jsxs(Ee,{value:i,onValueChange:x=>{x&&r(x)},children:[e.jsx(ke,{id:"llm-form-protocol","data-testid":"llm-provider-protocol-select",className:Re,children:e.jsx(Se,{})}),e.jsx(Me,{children:ds.map(x=>e.jsx(le,{value:x,children:x},x))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-apikey",children:l("settings.llm.apiKey")}),e.jsx(D,{id:"llm-form-apikey","data-testid":"llm-provider-apikey-input","data-key-set":s!=null&&s.hasApiKey?"true":"false",type:"password",value:m,onChange:x=>d(x.target.value),placeholder:s!=null&&s.hasApiKey?l("settings.llm.apiKeySetPlaceholder"):l("settings.llm.apiKeyPlaceholder"),className:Re})]})]}),e.jsxs(de,{children:[e.jsx(k,{variant:"outline",onClick:()=>o(!1),disabled:j,children:l("common.cancel")}),e.jsxs(k,{variant:"secondary","data-testid":"llm-provider-form-submit",onClick:C,disabled:!g||j,children:[j?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),l("common.save")]})]})]})})}function us({models:t,onChange:o}){const{t:s}=F(),[l,c]=y.useState(""),h=(a,n)=>{o(t.map(i=>i.id===a?{...i,enabled:n}:i))},p=a=>{o(t.filter(n=>n.id!==a))},f=()=>{const a=l.trim();if(a){if(t.some(n=>n.id===a)){c("");return}o([...t,{id:a,source:"manual",enabled:!0}]),c("")}};return e.jsxs("div",{className:"space-y-3","data-testid":"llm-provider-models",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{value:l,onChange:a=>c(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),f())},placeholder:s("settings.llm.addModelPlaceholder"),className:"h-9","data-testid":"llm-provider-add-model-input"}),e.jsxs(k,{type:"button",variant:"outline",size:"lg",onClick:f,disabled:!l.trim(),"data-testid":"llm-provider-add-model",children:[e.jsx(xe,{className:"h-4 w-4"}),s("common.add")]})]}),t.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settings.llm.modelsNotFetched")}):e.jsx("ul",{className:"max-h-56 space-y-1 overflow-y-auto rounded-lg border border-border bg-background p-2",children:t.map(a=>e.jsxs("li",{className:"flex items-center justify-between gap-2 rounded-md px-2 py-1.5","data-testid":`llm-provider-model-${a.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(_,{checked:a.enabled,onCheckedChange:n=>h(a.id,!!n),"data-testid":`llm-provider-model-toggle-${a.id}`}),e.jsx("span",{className:"truncate font-mono text-xs",children:a.id}),a.source==="manual"&&e.jsx(dt,{variant:"secondary",children:s("settings.llm.modelManual")})]}),a.source==="manual"&&e.jsx(k,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>p(a.id),"data-testid":`llm-provider-model-remove-${a.id}`,children:e.jsx(Rt,{className:"h-4 w-4"})})]},a.id))})]})}function hs(t){return t.modelDetails.map(o=>({id:o.id,source:o.source,enabled:o.enabled}))}function gs({open:t,onOpenChange:o,provider:s}){const{t:l}=F(),c=O(),[h,p]=y.useState([]);y.useEffect(()=>{t&&p(hs(s))},[t,s]);const f=M({mutationFn:async()=>{const a=h.filter(m=>m.source==="manual").map(m=>m.id),n=h.filter(m=>!m.enabled).map(m=>m.id),i={manualModels:a,disabledModels:n},r=await fetch(`/api/llm/providers/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await Z(r,l("settings.llm.updateFailed")));return await r.json()},onSuccess:async a=>{await c.invalidateQueries({queryKey:["llm-providers"]}),a.modelsError?b.warning(l("settings.llm.modelsFetchFailed",{error:a.modelsError})):b.success(l("common.success")),o(!1)},onError:a=>{b.error(a instanceof Error?a.message:l("common.error"))}});return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":`llm-provider-models-modal-${s.id}`,children:[e.jsxs(ie,{children:[e.jsx(re,{children:l("settings.llm.modelsTitle",{name:s.name})}),e.jsx(Ce,{children:l("settings.llm.modelsHint")})]}),e.jsx(us,{models:h,onChange:p}),e.jsxs(de,{children:[e.jsx(k,{variant:"outline",onClick:()=>o(!1),disabled:f.isPending,children:l("common.cancel")}),e.jsxs(k,{variant:"secondary","data-testid":`llm-provider-models-save-${s.id}`,onClick:()=>f.mutate(),disabled:f.isPending,children:[f.isPending?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),l("common.save")]})]})]})})}function xs(t){try{const o=new URL(t);return`${o.protocol}//${o.host}${o.pathname==="/"?"":o.pathname}`}catch{return t}}function fs({provider:t,onEdit:o}){const{t:s}=F(),l=O(),[c,h]=y.useState(!1),[p,f]=y.useState(!1),a=M({mutationFn:async r=>{const m=await fetch(`/api/llm/providers/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:r})});if(!m.ok)throw new Error(await Z(m,s("settings.llm.updateFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["llm-providers"]})},onError:r=>{b.error(r instanceof Error?r.message:s("common.error"))}}),n=M({mutationFn:async()=>{const r=await fetch(`/api/llm/providers/${t.id}/refresh-models`,{method:"POST"});if(!r.ok)throw new Error(await Z(r,s("settings.llm.refreshModelsFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["llm-providers"]}),b.success(s("common.success"))},onError:r=>{b.error(r instanceof Error?r.message:s("common.error"))}}),i=M({mutationFn:async()=>{const r=await fetch(`/api/llm/providers/${t.id}`,{method:"DELETE"});if(!r.ok)throw new Error(await Z(r,s("settings.llm.deleteFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["llm-providers"]}),await l.invalidateQueries({queryKey:["llm-settings"]}),b.success(s("common.success"))},onError:r=>{b.error(r instanceof Error?r.message:s("common.error"))}});return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-3 sm:flex-row sm:items-center sm:justify-between","data-testid":`llm-provider-row-${t.id}`,"data-provider-name":t.name,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(_,{checked:t.enabled,disabled:a.isPending,onCheckedChange:r=>a.mutate(!!r),"data-testid":`llm-provider-enabled-${t.id}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-medium",children:t.name}),e.jsx(dt,{variant:"outline",children:t.protocol})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"truncate font-mono",children:xs(t.baseUrl)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:"whitespace-nowrap",children:s("settings.llm.modelsCount",{total:t.models.length})})]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("settings.llm.refreshModels"),"data-testid":`llm-provider-refresh-models-${t.id}`,onClick:()=>n.mutate(),disabled:n.isPending,children:n.isPending?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(Ze,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("settings.llm.models"),"data-testid":`llm-provider-models-${t.id}`,onClick:()=>f(!0),children:e.jsx(Xt,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("common.edit"),"data-testid":`llm-provider-edit-${t.id}`,onClick:()=>o(t),children:e.jsx(Oe,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("common.delete"),"data-testid":`llm-provider-delete-${t.id}`,onClick:()=>h(!0),disabled:i.isPending,children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(gs,{open:p,onOpenChange:f,provider:t}),e.jsx(fe,{open:c,onOpenChange:h,children:e.jsxs(pe,{children:[e.jsxs(we,{children:[e.jsx(ye,{children:s("settings.llm.deleteProvider")}),e.jsx(je,{children:s("settings.llm.deleteConfirm",{name:t.name})})]}),e.jsxs(ve,{children:[e.jsx(be,{onClick:()=>h(!1),children:s("common.cancel")}),e.jsx(Ne,{variant:"destructive","data-testid":`llm-provider-delete-confirm-${t.id}`,onClick:()=>{i.mutate(),h(!1)},children:s("common.confirm")})]})]})})]})}function ps(){var n;const{t}=F(),[o,s]=y.useState(!1),[l,c]=y.useState(void 0),h=K({queryKey:["llm-providers"],queryFn:async()=>{const i=await fetch("/api/llm/providers");if(!i.ok)throw new Error(await Z(i,t("settings.llm.loadFailed")));return await i.json()}}),p=((n=h.data)==null?void 0:n.providers)??[],f=()=>{c(void 0),s(!0)},a=i=>{c(i),s(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0","data-testid":"llm-providers-section",children:[e.jsxs(G,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsx(W,{children:t("settings.llm.title")}),e.jsxs(k,{variant:"secondary","data-testid":"llm-provider-add",onClick:f,children:[e.jsx(xe,{className:"h-4 w-4"}),t("settings.llm.addProvider")]})]}),e.jsxs(H,{className:"space-y-3",children:[h.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!h.isLoading&&p.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground","data-testid":"llm-providers-empty",children:t("settings.llm.empty")}),p.map(i=>e.jsx(fs,{provider:i,onEdit:a},i.id))]})]}),e.jsx(ms,{open:o,onOpenChange:s,provider:l}),e.jsx(ws,{providers:p})]})}const Be="__none__";function ws({providers:t}){var w,j;const{t:o}=F(),s=O(),[l,c]=y.useState(null),[h,p]=y.useState(""),f=K({queryKey:["llm-settings"],queryFn:async()=>{const g=await fetch("/api/llm/settings");if(!g.ok)throw new Error(await Z(g,o("settings.llm.settingsLoadFailed")));return await g.json()}}),a=((w=f.data)==null?void 0:w.settings.defaultProviderId)??null,n=((j=f.data)==null?void 0:j.settings.defaultModelId)??"",i=!!f.data;y.useEffect(()=>{i&&(c(a),p(n))},[i,a,n]);const r=M({mutationFn:async()=>{const g={defaultProviderId:l,defaultModelId:h.trim()||null},C=await fetch("/api/llm/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!C.ok)throw new Error(await Z(C,o("settings.llm.settingsSaveFailed")))},onSuccess:async()=>{await s.invalidateQueries({queryKey:["llm-settings"]}),b.success(o("common.success"))},onError:g=>{b.error(g instanceof Error?g.message:o("common.error"))}}),m=t.filter(g=>g.enabled),d=t.find(g=>g.id===l),u=(d==null?void 0:d.models)??[];return e.jsxs(U,{className:"border-0 ring-0","data-testid":"llm-defaults-section",children:[e.jsx(G,{children:e.jsx(W,{children:o("settings.llm.defaults")})}),e.jsxs(H,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-default-provider-select",children:o("settings.llm.defaultProvider")}),e.jsxs(Ee,{value:l??Be,onValueChange:g=>{g&&c(g===Be?null:g)},children:[e.jsx(ke,{id:"llm-default-provider-select","data-testid":"llm-default-provider-select",className:"h-9 w-full",children:e.jsx(Se,{children:(d==null?void 0:d.name)??o("settings.llm.defaultProviderNone")})}),e.jsxs(Me,{children:[e.jsx(le,{value:Be,children:o("settings.llm.defaultProviderNone")}),m.map(g=>e.jsx(le,{value:g.id,children:g.name},g.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-default-model-input",children:o("settings.llm.defaultModel")}),e.jsx(D,{id:"llm-default-model-input","data-testid":"llm-default-model-input",list:"llm-default-model-options",value:h,onChange:g=>p(g.target.value),placeholder:o("settings.llm.defaultModelPlaceholder"),className:"h-9"}),e.jsx("datalist",{id:"llm-default-model-options",children:u.map(g=>e.jsx("option",{value:g},g))})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(k,{variant:"secondary","data-testid":"llm-defaults-save",onClick:()=>r.mutate(),disabled:r.isPending||f.isLoading,className:"w-full sm:w-auto",children:[r.isPending?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),o("settings.llm.saveDefaults")]})})]})]})}const ys=["none","tavily","brave"];async function _e(t,o){try{return(await t.json()).error??o}catch{return o}}function js(){var j;const{t}=F(),o=O(),[s,l]=y.useState("none"),[c,h]=y.useState(""),[p,f]=y.useState(""),[a,n]=y.useState(null),i=K({queryKey:["llm-settings"],queryFn:async()=>{const g=await fetch("/api/llm/settings");if(!g.ok)throw new Error(await _e(g,t("settings.search.loadFailed")));return await g.json()}}),r=(j=i.data)==null?void 0:j.settings,m=r==null?void 0:r.searchProvider;y.useEffect(()=>{m&&l(m)},[m]);const d=M({mutationFn:async()=>{const g={searchProvider:s};c.trim()&&(g.tavilyApiKey=c.trim()),p.trim()&&(g.braveApiKey=p.trim());const C=await fetch("/api/llm/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!C.ok)throw new Error(await _e(C,t("settings.search.saveFailed")))},onSuccess:async()=>{h(""),f(""),await o.invalidateQueries({queryKey:["llm-settings"]}),b.success(t("common.success"))},onError:g=>{b.error(g instanceof Error?g.message:t("common.error"))}}),u=M({mutationFn:async g=>{const C={[g]:""},x=await fetch("/api/llm/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(C)});if(!x.ok)throw new Error(await _e(x,t("settings.search.saveFailed")))},onSuccess:async()=>{await o.invalidateQueries({queryKey:["llm-settings"]}),b.success(t("common.success"))},onError:g=>{b.error(g instanceof Error?g.message:t("common.error"))}}),w=g=>g==="none"?t("settings.search.providerNone"):g==="tavily"?"Tavily":"Brave";return e.jsxs(U,{className:"border-0 ring-0","data-testid":"settings-search-section",children:[e.jsx(G,{children:e.jsx(W,{children:t("settings.search.title")})}),e.jsxs(H,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"search-provider-select",children:t("settings.search.provider")}),e.jsxs(Ee,{value:s,onValueChange:g=>{g&&l(g)},children:[e.jsx(ke,{id:"search-provider-select","data-testid":"settings-search-provider-select",className:"w-full min-h-10",children:e.jsx(Se,{children:w(s)})}),e.jsx(Me,{children:ys.map(g=>e.jsx(le,{value:g,children:w(g)},g))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.search.responsesApiHint")})]}),e.jsx(at,{id:"search-tavily-key-input",testId:"settings-search-tavily",label:t("settings.search.tavilyApiKey"),value:c,hasKey:(r==null?void 0:r.hasTavilyApiKey)??!1,onChange:h,onClear:()=>n("tavilyApiKey"),clearing:u.isPending&&u.variables==="tavilyApiKey"}),e.jsx(at,{id:"search-brave-key-input",testId:"settings-search-brave",label:t("settings.search.braveApiKey"),value:p,hasKey:(r==null?void 0:r.hasBraveApiKey)??!1,onChange:f,onClear:()=>n("braveApiKey"),clearing:u.isPending&&u.variables==="braveApiKey"}),e.jsx(fe,{open:a!==null,onOpenChange:g=>{g||n(null)},children:e.jsxs(pe,{children:[e.jsxs(we,{children:[e.jsx(ye,{children:t("settings.search.clearKey")}),e.jsx(je,{children:t("settings.search.clearKeyConfirm")})]}),e.jsxs(ve,{children:[e.jsx(be,{children:t("common.cancel")}),e.jsx(Ne,{"data-testid":"settings-search-clear-confirm",onClick:()=>{a&&u.mutate(a),n(null)},children:t("settings.search.clearKey")})]})]})}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(k,{variant:"secondary","data-testid":"settings-search-save",onClick:()=>d.mutate(),disabled:d.isPending||i.isLoading,className:"w-full sm:w-auto",children:[d.isPending?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),t("common.save")]})})]})]})}function at({id:t,testId:o,label:s,value:l,hasKey:c,onChange:h,onClear:p,clearing:f}){const{t:a}=F();return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:t,children:s}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{id:t,"data-testid":`${o}-input`,"data-key-set":c?"true":"false",type:"password",value:l,onChange:n=>h(n.target.value),placeholder:a(c?"settings.search.keySetPlaceholder":"settings.search.keyPlaceholder"),className:"min-h-10"}),c&&e.jsxs(k,{variant:"outline",size:"sm","data-testid":`${o}-clear`,onClick:p,disabled:f,className:"shrink-0",children:[e.jsx(te,{className:"h-4 w-4"}),a("settings.search.clearKey")]})]})]})}const nt="min-h-10";async function it(t,o){try{return(await t.json()).error??o}catch{return o}}function vs({open:t,onOpenChange:o,bot:s}){const{t:l}=F(),c=O(),h=!!s,[p,f]=y.useState(""),[a,n]=y.useState(""),[i,r]=y.useState(!0);y.useEffect(()=>{t&&(f((s==null?void 0:s.name)??""),n(""),r((s==null?void 0:s.allowAuthRequests)??!0))},[t,s]);const m=M({mutationFn:async()=>{const g=await fetch("/api/settings/telegram/bots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:p.trim(),token:a.trim(),enabled:!0,allowAuthRequests:i})});if(!g.ok)throw new Error(await it(g,l("telegram.createFailed")))},onSuccess:async()=>{await c.invalidateQueries({queryKey:["telegram-bots"]}),b.success(l("common.success")),o(!1)},onError:g=>{b.error(g instanceof Error?g.message:l("common.error"))}}),d=M({mutationFn:async()=>{if(!s)throw new Error(l("telegram.updateFailed"));const g={name:p.trim(),allowAuthRequests:i};a.trim()&&(g.token=a.trim());const C=await fetch(`/api/settings/telegram/bots/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!C.ok)throw new Error(await it(C,l("telegram.updateFailed")))},onSuccess:async()=>{await c.invalidateQueries({queryKey:["telegram-bots"]}),b.success(l("common.success")),o(!1)},onError:g=>{b.error(g instanceof Error?g.message:l("common.error"))}}),u=m.isPending||d.isPending,w=p.trim().length>0&&(h||a.trim().length>0),j=()=>{!w||u||(h?d.mutate():m.mutate())};return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":h?`telegram-bot-edit-modal-${s==null?void 0:s.id}`:"telegram-bot-add-modal",children:[e.jsx(ie,{children:e.jsx(re,{children:l(h?"telegram.editBot":"telegram.addBot")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"telegram-bot-name",children:l("telegram.botName")}),e.jsx(D,{id:"telegram-bot-name","data-testid":"telegram-bot-name-input",value:p,onChange:g=>f(g.target.value),placeholder:l("telegram.botNamePlaceholder"),className:nt})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"telegram-bot-token",children:l("telegram.botToken")}),e.jsx(D,{id:"telegram-bot-token","data-testid":"telegram-bot-token-input",type:"password",value:a,onChange:g=>n(g.target.value),placeholder:l(h?"telegram.tokenPlaceholder":"telegram.botTokenPlaceholder"),className:nt})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium",children:l("telegram.allowAuthRequests")}),e.jsx(_,{checked:i,"data-testid":"telegram-bot-allow-auth",onCheckedChange:g=>r(!!g)})]})]}),e.jsxs(de,{children:[e.jsx(k,{variant:"outline",onClick:()=>o(!1),disabled:u,children:l("common.cancel")}),e.jsxs(k,{variant:"secondary","data-testid":"telegram-bot-form-submit",onClick:j,disabled:!w||u,children:[u?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),l("common.save")]})]})]})})}async function Ie(t,o){try{return(await t.json()).error??o}catch{return o}}function bs({open:t,onOpenChange:o,botId:s,botName:l}){var m;const{t:c}=F(),h=O(),p=K({queryKey:["telegram-bot-chats",s],enabled:t,queryFn:async()=>{const d=await fetch(`/api/settings/telegram/bots/${s}/chats`);if(!d.ok)throw new Error(await Ie(d,c("telegram.loadChatsFailed")));return await d.json()}}),f=y.useMemo(()=>{var u;const d=((u=p.data)==null?void 0:u.chats)??[];return{pending:d.filter(w=>w.status==="pending"),authorized:d.filter(w=>w.status==="authorized")}},[(m=p.data)==null?void 0:m.chats]),a=async()=>{await Promise.all([h.invalidateQueries({queryKey:["telegram-bots"]}),h.invalidateQueries({queryKey:["telegram-bot-chats",s]})])},n=M({mutationFn:async d=>{const u=await fetch(`/api/settings/telegram/bots/${s}/chats/${encodeURIComponent(d)}/approve`,{method:"POST"});if(!u.ok)throw new Error(await Ie(u,c("telegram.approveFailed")))},onSuccess:async()=>{await a(),b.success(c("common.success"))},onError:d=>{b.error(d instanceof Error?d.message:c("common.error"))}}),i=M({mutationFn:async d=>{const u=await fetch(`/api/settings/telegram/bots/${s}/chats/${encodeURIComponent(d)}`,{method:"DELETE"});if(!u.ok)throw new Error(await Ie(u,c("telegram.removeFailed")))},onSuccess:async()=>{await a(),b.success(c("common.success"))},onError:d=>{b.error(d instanceof Error?d.message:c("common.error"))}}),r=M({mutationFn:async d=>{const u=await fetch(`/api/settings/telegram/bots/${s}/chats/${encodeURIComponent(d)}/test`,{method:"POST"});if(!u.ok)throw new Error(await Ie(u,c("telegram.testMessageFailed")))},onSuccess:()=>{b.success(c("common.success"))},onError:d=>{b.error(d instanceof Error?d.message:c("common.error"))}});return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-2xl","data-testid":`telegram-bot-chats-modal-${s}`,children:[e.jsxs(ie,{children:[e.jsx(re,{children:c("telegram.chats")}),e.jsx(Ce,{children:l})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"flex items-center gap-1 text-sm font-semibold",children:[e.jsx(tt,{className:"h-4 w-4"}),c("telegram.pendingChats")]}),f.pending.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:c("telegram.noPendingChats")}),f.pending.map(d=>e.jsx(rt,{chat:d,pending:!0,onApprove:()=>n.mutate(d.chatId),onDelete:()=>i.mutate(d.chatId)},`${d.botId}-${d.chatId}`))]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"flex items-center gap-1 text-sm font-semibold",children:[e.jsx(tt,{className:"h-4 w-4"}),c("telegram.chats")]}),f.authorized.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:c("telegram.noAuthorizedChats")}),f.authorized.map(d=>e.jsx(rt,{chat:d,pending:!1,onTest:()=>r.mutate(d.chatId),onDelete:()=>i.mutate(d.chatId)},`${d.botId}-${d.chatId}`))]}),p.isLoading&&e.jsx("div",{className:"text-xs text-muted-foreground lg:col-span-2",children:c("common.loading")})]})]})})}function rt({chat:t,pending:o,onApprove:s,onDelete:l,onTest:c}){const{t:h}=F(),p=ge(f=>{var a;return((a=f.settings)==null?void 0:a.language)??"en_US"});return e.jsxs("div",{className:"space-y-2 rounded border-0 bg-background p-3",children:[e.jsx("div",{className:"truncate text-sm font-medium",title:t.displayName,children:t.displayName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[h("telegram.chatId"),":",t.chatId]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(t.appliedAt).toLocaleString(Xe(p))}),e.jsx("div",{className:"flex items-center justify-end gap-2 pt-1",children:o?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",size:"sm",onClick:l,children:h("telegram.reject")}),e.jsx(k,{variant:"secondary",size:"sm",onClick:s,children:h("telegram.authorize")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(k,{variant:"secondary",size:"sm",onClick:c,children:[e.jsx(gt,{className:"h-3.5 w-3.5"}),h("telegram.sendTestMessage")]}),e.jsx(k,{variant:"destructive",size:"sm",onClick:l,children:h("common.delete")})]})})]})}async function ot(t,o){try{return(await t.json()).error??o}catch{return o}}function Ns({bot:t,onEdit:o}){const{t:s}=F(),l=O(),[c,h]=y.useState(!1),p=M({mutationFn:async a=>{const n=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:a})});if(!n.ok)throw new Error(await ot(n,s("telegram.updateFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["telegram-bots"]})},onError:a=>{b.error(a instanceof Error?a.message:s("common.error"))}}),f=M({mutationFn:async()=>{const a=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"DELETE"});if(!a.ok)throw new Error(await ot(a,s("telegram.deleteFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["telegram-bots"]}),b.success(s("common.success"))},onError:a=>{b.error(a instanceof Error?a.message:s("common.error"))}});return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-3 sm:flex-row sm:items-center sm:justify-between","data-testid":`telegram-bot-card-${t.id}`,"data-bot-name":t.name,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(_,{checked:t.enabled,disabled:p.isPending,onCheckedChange:a=>p.mutate(!!a),"data-testid":`telegram-bot-enabled-${t.id}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:t.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("telegram.authCount",{authorized:t.authorizedCount,pending:t.pendingCount})})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("telegram.chats"),"data-testid":`telegram-bot-chats-${t.id}`,onClick:()=>h(!0),children:e.jsx(is,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("common.edit"),"data-testid":`telegram-bot-edit-${t.id}`,onClick:()=>o(t),children:e.jsx(Oe,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("telegram.deleteBot"),"data-testid":`telegram-bot-delete-${t.id}`,onClick:()=>f.mutate(),disabled:f.isPending,children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(bs,{open:c,onOpenChange:h,botId:t.id,botName:t.name})]})}async function Cs(t,o){try{return(await t.json()).error??o}catch{return o}}function Es(){var n;const{t}=F(),[o,s]=y.useState(!1),[l,c]=y.useState(void 0),h=K({queryKey:["telegram-bots"],queryFn:async()=>{const i=await fetch("/api/settings/telegram/bots");if(!i.ok)throw new Error(await Cs(i,t("telegram.loadBotsFailed")));return await i.json()}}),p=((n=h.data)==null?void 0:n.bots)??[],f=()=>{c(void 0),s(!0)},a=i=>{c(i),s(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0",children:[e.jsxs(G,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsx(W,{children:t("telegram.title")}),e.jsxs(k,{variant:"secondary","data-testid":"telegram-add-bot",onClick:f,children:[e.jsx(xe,{className:"h-4 w-4"}),t("telegram.addBot")]})]}),e.jsxs(H,{className:"space-y-3",children:[h.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!h.isLoading&&p.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("telegram.noBots")}),p.map(i=>e.jsx(Ns,{bot:i,onEdit:a},i.id))]})]}),e.jsx(vs,{open:o,onOpenChange:s,bot:l})]})}function ks(){const{t}=F();return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(U,{className:"border-0 ring-0",children:[e.jsx(G,{children:e.jsx(W,{children:t("settings.terminal.title")})}),e.jsx(H,{children:e.jsx(Vt,{showShortcuts:!1})})]}),e.jsxs(U,{className:"border-0 ring-0",children:[e.jsxs(G,{children:[e.jsx(W,{children:t("settings.terminal.shortcuts.title")}),e.jsx(ut,{children:t("settings.terminal.shortcuts.savedOnServer")})]}),e.jsx(H,{children:e.jsx(Gt,{})})]})]})}async function ze(t,o){try{return(await t.json()).error??o}catch{return o}}function qe({label:t,value:o}){return e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2 text-sm font-medium",children:t}),e.jsx("div",{className:"min-w-0 truncate text-right text-sm text-muted-foreground",children:o})]})}function Ss(){const{t}=F(),o=O(),s=ge(x=>{var N;return((N=x.settings)==null?void 0:N.language)??"en_US"}),[l,c]=y.useState(!1),[h,p]=y.useState(!1),f=y.useRef(!1),n=K({queryKey:["system-info"],queryFn:async()=>{const x=await fetch("/api/system/info");if(!x.ok)throw new Error(await ze(x,t("settings.loadFailed")));return await x.json()}}).data,i=K({queryKey:["system-update-check"],enabled:!1,gcTime:0,queryFn:async()=>{const x=await fetch("/api/system/update-check");if(!x.ok)throw new Error(await ze(x,t("settings.version.checkFailed")));return await x.json()}}),r=i.data,d=K({queryKey:["system-upgrade-status"],enabled:h,refetchInterval:x=>{var E;const N=(E=x.state.data)==null?void 0:E.state;return h||N&&N!=="idle"?2e3:!1},retry:!0,queryFn:async()=>{const x=await fetch("/api/system/upgrade");if(!x.ok)throw new Error("status");return await x.json()}}).data;y.useEffect(()=>{if(!h)return;const x=d==null?void 0:d.state;x&&x!=="idle"?f.current=!0:x==="idle"&&(d!=null&&d.error)?(f.current=!1,p(!1),b.error(d.error)):x==="idle"&&f.current&&(f.current=!1,p(!1),o.invalidateQueries({queryKey:["system-info"]}),o.removeQueries({queryKey:["system-update-check"]}),b.success(t("common.success")))},[h,d,o,t]);const u=M({mutationFn:async x=>{const N=await fetch("/api/system/upgrade",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({version:x})});if(!N.ok)throw new Error(await ze(N,t("common.error")));return await N.json()},onSuccess:x=>{f.current=!1,p(!0),o.setQueryData(["system-upgrade-status"],x),b.success(t("settings.version.upgradeStarted"))},onError:x=>{b.error(x instanceof Error?x.message:t("common.error"))}}),w=x=>t(x==="launchd"?"settings.version.deploymentLaunchd":x==="systemd"?"settings.version.deploymentSystemd":"settings.version.deploymentNone"),j=h&&(d==null?void 0:d.state)!==void 0,g=(d==null?void 0:d.state)==="downloading"?t("settings.version.stateDownloading"):(d==null?void 0:d.state)==="executing"?t("settings.version.stateExecuting"):null,C=n!=null&&n.canSelfUpdate?null:n!=null&&n.isProd?n!=null&&n.installedViaCli?null:t("settings.version.upgradeDisabledNonCli"):t("settings.version.upgradeDisabledDev");return e.jsxs(U,{className:"border-0 ring-0",children:[e.jsx(G,{children:e.jsx(W,{children:t("settings.version.title")})}),e.jsxs(H,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(qe,{label:t("settings.version.currentVersion"),value:e.jsx("span",{"data-testid":"settings-version-current",className:"font-mono",children:n?n.version:t("common.loading")})}),e.jsx(qe,{label:t("settings.version.installMethod"),value:n?n.installedViaCli?t("settings.version.installMethodCli"):t("settings.version.installMethodNonCli"):"-"}),e.jsx(qe,{label:t("settings.version.deployment"),value:n?w(n.deployment):"-"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(k,{variant:"outline","data-testid":"settings-version-check",onClick:()=>i.refetch(),disabled:i.isFetching||j,children:[i.isFetching?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(Ze,{className:"h-4 w-4"}),i.isFetching?t("settings.version.checking"):t("settings.version.checkUpdate")]}),r&&e.jsxs("span",{className:"text-sm text-muted-foreground","data-testid":"settings-version-latest",children:[r.hasUpdate&&r.latestVersion?t("settings.version.updateAvailable",{version:r.latestVersion}):t("settings.version.upToDate"),r.publishedAt?` · ${t("settings.version.publishedAt",{date:new Date(r.publishedAt).toLocaleDateString(Xe(s))})}`:""]})]}),i.isError&&e.jsx("div",{className:"text-sm text-destructive",children:t("settings.version.checkFailed")}),(r==null?void 0:r.hasUpdate)&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-semibold",children:t("settings.version.changelog")}),e.jsx("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:r.changelog?e.jsx(Jt,{source:r.changelog,basePath:"/"}):e.jsx("div",{className:"text-sm text-muted-foreground",children:t("settings.version.changelogUnavailable")})}),n!=null&&n.canSelfUpdate?e.jsxs(k,{variant:"secondary","data-testid":"settings-version-upgrade",disabled:j||u.isPending,onClick:()=>c(!0),children:[j?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(Ht,{className:"h-4 w-4"}),t("settings.version.upgrade")]}):e.jsxs("div",{className:"space-y-1",children:[C&&e.jsx("div",{className:"text-sm text-muted-foreground",children:C}),e.jsx("div",{className:"text-xs text-muted-foreground font-mono",children:t("settings.version.terminalHint")})]})]}),j&&g&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-border bg-card px-4 py-3","data-testid":"settings-version-upgrade-status",children:[e.jsx(Q,{className:"mt-0.5 h-4 w-4 shrink-0 animate-spin text-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm font-medium",children:g}),e.jsx("div",{className:"text-xs text-muted-foreground",children:t("settings.version.interruptNotice")})]})]})]}),e.jsx(fe,{open:l,onOpenChange:c,children:e.jsxs(pe,{children:[e.jsxs(we,{children:[e.jsxs(ye,{className:"flex items-center gap-2",children:[e.jsx(xt,{className:"h-5 w-5 text-destructive"}),t("settings.version.upgradeWarningTitle")]}),e.jsx(je,{children:t("settings.version.upgradeWarningBody")})]}),e.jsxs(ve,{children:[e.jsx(be,{onClick:()=>c(!1),children:t("common.cancel")}),e.jsx(Ne,{variant:"destructive","data-testid":"settings-version-upgrade-confirm",onClick:()=>{c(!1),r!=null&&r.latestVersion&&u.mutate(r.latestVersion)},children:t("settings.version.upgrade")})]})]})})]})}const Ke=["terminal_bell","terminal_notification","tmux_window_close","tmux_pane_close","device_tmux_missing","device_disconnect","session_created","session_closed","agent_confirmation_pending","agent_turn_finished","agent_error","watch_triggered","watch_model_unavailable","watch_rule_error"];async function Qe(t,o){try{return(await t.json()).error??o}catch{return o}}function Ms(){var d;const{t}=F(),o=O(),s=ge(u=>{var w;return((w=u.settings)==null?void 0:w.language)??"en_US"}),[l,c]=y.useState(""),[h,p]=y.useState(""),[f,a]=y.useState(Ke),n=K({queryKey:["webhooks"],queryFn:async()=>{const u=await fetch("/api/webhooks");if(!u.ok)throw new Error(await Qe(u,t("webhook.loadFailed")));return await u.json()}}),i=M({mutationFn:async()=>{const u=await fetch("/api/webhooks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:l,secret:h,eventMask:f})});if(!u.ok)throw new Error(await Qe(u,t("webhook.createFailed")))},onSuccess:async()=>{c(""),p(""),a(Ke),await o.invalidateQueries({queryKey:["webhooks"]}),b.success(t("common.success"))},onError:u=>{b.error(u instanceof Error?u.message:t("common.error"))}}),r=M({mutationFn:async u=>{const w=await fetch(`/api/webhooks/${u}`,{method:"DELETE"});if(!w.ok)throw new Error(await Qe(w,t("webhook.deleteFailed")))},onSuccess:async()=>{await o.invalidateQueries({queryKey:["webhooks"]}),b.success(t("common.success"))},onError:u=>{b.error(u instanceof Error?u.message:t("common.error"))}}),m=((d=n.data)==null?void 0:d.webhooks)??[];return e.jsxs(U,{className:"border-0 ring-0",children:[e.jsx(G,{children:e.jsx(W,{children:t("webhook.title")})}),e.jsxs(H,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-12 md:items-end",children:[e.jsxs("div",{className:"md:col-span-6 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"webhook-url-input",children:t("webhook.url")}),e.jsx(D,{id:"webhook-url-input","data-testid":"webhook-url-input",value:l,onChange:u=>c(u.target.value),placeholder:"https://example.com/webhook",className:"min-h-10"})]}),e.jsxs("div",{className:"md:col-span-4 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"webhook-secret-input",children:t("webhook.secret")}),e.jsx(D,{id:"webhook-secret-input","data-testid":"webhook-secret-input",value:h,onChange:u=>p(u.target.value),placeholder:t("webhook.secretPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs(k,{variant:"secondary",className:"w-full md:w-auto","data-testid":"webhook-add",onClick:()=>i.mutate(),disabled:i.isPending||!l.trim()||!h.trim()||f.length===0,children:[i.isPending?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),t("webhook.add")]})})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("div",{className:"text-sm font-medium",children:t("webhook.eventMask")}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:Ke.map(u=>{const w=f.includes(u);return e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-background px-3 py-2",children:[e.jsx("div",{className:"min-w-0 pr-2 text-sm font-medium",children:t(`notification.eventType.${u}`)}),e.jsx(_,{checked:w,"data-testid":`webhook-event-${u}`,onCheckedChange:j=>{a(g=>j?g.includes(u)?g:[...g,u]:g.filter(C=>C!==u))}})]},u)})})]}),e.jsxs("div",{className:"space-y-2",children:[n.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!n.isLoading&&m.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("webhook.empty")}),m.map(u=>e.jsxs("div",{"data-testid":"webhook-item","data-webhook-url":u.url,className:"flex items-center justify-between gap-3 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:u.url}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(u.createdAt).toLocaleString(Xe(s))})]}),e.jsx(k,{variant:"ghost",size:"icon-sm","data-testid":"webhook-delete",onClick:()=>r.mutate(u.id),disabled:r.isPending,"aria-label":t("common.delete"),title:t("common.delete"),children:e.jsx(te,{className:"h-4 w-4"})})]},u.id))]})]})]})}var Ps=Object.defineProperty,De=Object.getOwnPropertySymbols,ft=Object.prototype.hasOwnProperty,pt=Object.prototype.propertyIsEnumerable,lt=(t,o,s)=>o in t?Ps(t,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[o]=s,Ge=(t,o)=>{for(var s in o||(o={}))ft.call(o,s)&&lt(t,s,o[s]);if(De)for(var s of De(o))pt.call(o,s)&&lt(t,s,o[s]);return t},We=(t,o)=>{var s={};for(var l in t)ft.call(t,l)&&o.indexOf(l)<0&&(s[l]=t[l]);if(t!=null&&De)for(var l of De(t))o.indexOf(l)<0&&pt.call(t,l)&&(s[l]=t[l]);return s};/**
32
+ * @license QR Code generator library (TypeScript)
33
+ * Copyright (c) Project Nayuki.
34
+ * SPDX-License-Identifier: MIT
35
+ */var se;(t=>{const o=class S{constructor(a,n,i,r){if(this.version=a,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],a<S.MIN_VERSION||a>S.MAX_VERSION)throw new RangeError("Version value out of range");if(r<-1||r>7)throw new RangeError("Mask value out of range");this.size=a*4+17;let m=[];for(let u=0;u<this.size;u++)m.push(!1);for(let u=0;u<this.size;u++)this.modules.push(m.slice()),this.isFunction.push(m.slice());this.drawFunctionPatterns();const d=this.addEccAndInterleave(i);if(this.drawCodewords(d),r==-1){let u=1e9;for(let w=0;w<8;w++){this.applyMask(w),this.drawFormatBits(w);const j=this.getPenaltyScore();j<u&&(r=w,u=j),this.applyMask(w)}}c(0<=r&&r<=7),this.mask=r,this.applyMask(r),this.drawFormatBits(r),this.isFunction=[]}static encodeText(a,n){const i=t.QrSegment.makeSegments(a);return S.encodeSegments(i,n)}static encodeBinary(a,n){const i=t.QrSegment.makeBytes(a);return S.encodeSegments([i],n)}static encodeSegments(a,n,i=1,r=40,m=-1,d=!0){if(!(S.MIN_VERSION<=i&&i<=r&&r<=S.MAX_VERSION)||m<-1||m>7)throw new RangeError("Invalid value");let u,w;for(u=i;;u++){const x=S.getNumDataCodewords(u,n)*8,N=p.getTotalBits(a,u);if(N<=x){w=N;break}if(u>=r)throw new RangeError("Data too long")}for(const x of[S.Ecc.MEDIUM,S.Ecc.QUARTILE,S.Ecc.HIGH])d&&w<=S.getNumDataCodewords(u,x)*8&&(n=x);let j=[];for(const x of a){s(x.mode.modeBits,4,j),s(x.numChars,x.mode.numCharCountBits(u),j);for(const N of x.getData())j.push(N)}c(j.length==w);const g=S.getNumDataCodewords(u,n)*8;c(j.length<=g),s(0,Math.min(4,g-j.length),j),s(0,(8-j.length%8)%8,j),c(j.length%8==0);for(let x=236;j.length<g;x^=253)s(x,8,j);let C=[];for(;C.length*8<j.length;)C.push(0);return j.forEach((x,N)=>C[N>>>3]|=x<<7-(N&7)),new S(u,n,C,m)}getModule(a,n){return 0<=a&&a<this.size&&0<=n&&n<this.size&&this.modules[n][a]}getModules(){return this.modules}drawFunctionPatterns(){for(let i=0;i<this.size;i++)this.setFunctionModule(6,i,i%2==0),this.setFunctionModule(i,6,i%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const a=this.getAlignmentPatternPositions(),n=a.length;for(let i=0;i<n;i++)for(let r=0;r<n;r++)i==0&&r==0||i==0&&r==n-1||i==n-1&&r==0||this.drawAlignmentPattern(a[i],a[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(a){const n=this.errorCorrectionLevel.formatBits<<3|a;let i=n;for(let m=0;m<10;m++)i=i<<1^(i>>>9)*1335;const r=(n<<10|i)^21522;c(r>>>15==0);for(let m=0;m<=5;m++)this.setFunctionModule(8,m,l(r,m));this.setFunctionModule(8,7,l(r,6)),this.setFunctionModule(8,8,l(r,7)),this.setFunctionModule(7,8,l(r,8));for(let m=9;m<15;m++)this.setFunctionModule(14-m,8,l(r,m));for(let m=0;m<8;m++)this.setFunctionModule(this.size-1-m,8,l(r,m));for(let m=8;m<15;m++)this.setFunctionModule(8,this.size-15+m,l(r,m));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let a=this.version;for(let i=0;i<12;i++)a=a<<1^(a>>>11)*7973;const n=this.version<<12|a;c(n>>>18==0);for(let i=0;i<18;i++){const r=l(n,i),m=this.size-11+i%3,d=Math.floor(i/3);this.setFunctionModule(m,d,r),this.setFunctionModule(d,m,r)}}drawFinderPattern(a,n){for(let i=-4;i<=4;i++)for(let r=-4;r<=4;r++){const m=Math.max(Math.abs(r),Math.abs(i)),d=a+r,u=n+i;0<=d&&d<this.size&&0<=u&&u<this.size&&this.setFunctionModule(d,u,m!=2&&m!=4)}}drawAlignmentPattern(a,n){for(let i=-2;i<=2;i++)for(let r=-2;r<=2;r++)this.setFunctionModule(a+r,n+i,Math.max(Math.abs(r),Math.abs(i))!=1)}setFunctionModule(a,n,i){this.modules[n][a]=i,this.isFunction[n][a]=!0}addEccAndInterleave(a){const n=this.version,i=this.errorCorrectionLevel;if(a.length!=S.getNumDataCodewords(n,i))throw new RangeError("Invalid argument");const r=S.NUM_ERROR_CORRECTION_BLOCKS[i.ordinal][n],m=S.ECC_CODEWORDS_PER_BLOCK[i.ordinal][n],d=Math.floor(S.getNumRawDataModules(n)/8),u=r-d%r,w=Math.floor(d/r);let j=[];const g=S.reedSolomonComputeDivisor(m);for(let x=0,N=0;x<r;x++){let E=a.slice(N,N+w-m+(x<u?0:1));N+=E.length;const z=S.reedSolomonComputeRemainder(E,g);x<u&&E.push(0),j.push(E.concat(z))}let C=[];for(let x=0;x<j[0].length;x++)j.forEach((N,E)=>{(x!=w-m||E>=u)&&C.push(N[x])});return c(C.length==d),C}drawCodewords(a){if(a.length!=Math.floor(S.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let n=0;for(let i=this.size-1;i>=1;i-=2){i==6&&(i=5);for(let r=0;r<this.size;r++)for(let m=0;m<2;m++){const d=i-m,w=(i+1&2)==0?this.size-1-r:r;!this.isFunction[w][d]&&n<a.length*8&&(this.modules[w][d]=l(a[n>>>3],7-(n&7)),n++)}}c(n==a.length*8)}applyMask(a){if(a<0||a>7)throw new RangeError("Mask value out of range");for(let n=0;n<this.size;n++)for(let i=0;i<this.size;i++){let r;switch(a){case 0:r=(i+n)%2==0;break;case 1:r=n%2==0;break;case 2:r=i%3==0;break;case 3:r=(i+n)%3==0;break;case 4:r=(Math.floor(i/3)+Math.floor(n/2))%2==0;break;case 5:r=i*n%2+i*n%3==0;break;case 6:r=(i*n%2+i*n%3)%2==0;break;case 7:r=((i+n)%2+i*n%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[n][i]&&r&&(this.modules[n][i]=!this.modules[n][i])}}getPenaltyScore(){let a=0;for(let m=0;m<this.size;m++){let d=!1,u=0,w=[0,0,0,0,0,0,0];for(let j=0;j<this.size;j++)this.modules[m][j]==d?(u++,u==5?a+=S.PENALTY_N1:u>5&&a++):(this.finderPenaltyAddHistory(u,w),d||(a+=this.finderPenaltyCountPatterns(w)*S.PENALTY_N3),d=this.modules[m][j],u=1);a+=this.finderPenaltyTerminateAndCount(d,u,w)*S.PENALTY_N3}for(let m=0;m<this.size;m++){let d=!1,u=0,w=[0,0,0,0,0,0,0];for(let j=0;j<this.size;j++)this.modules[j][m]==d?(u++,u==5?a+=S.PENALTY_N1:u>5&&a++):(this.finderPenaltyAddHistory(u,w),d||(a+=this.finderPenaltyCountPatterns(w)*S.PENALTY_N3),d=this.modules[j][m],u=1);a+=this.finderPenaltyTerminateAndCount(d,u,w)*S.PENALTY_N3}for(let m=0;m<this.size-1;m++)for(let d=0;d<this.size-1;d++){const u=this.modules[m][d];u==this.modules[m][d+1]&&u==this.modules[m+1][d]&&u==this.modules[m+1][d+1]&&(a+=S.PENALTY_N2)}let n=0;for(const m of this.modules)n=m.reduce((d,u)=>d+(u?1:0),n);const i=this.size*this.size,r=Math.ceil(Math.abs(n*20-i*10)/i)-1;return c(0<=r&&r<=9),a+=r*S.PENALTY_N4,c(0<=a&&a<=2568888),a}getAlignmentPatternPositions(){if(this.version==1)return[];{const a=Math.floor(this.version/7)+2,n=this.version==32?26:Math.ceil((this.version*4+4)/(a*2-2))*2;let i=[6];for(let r=this.size-7;i.length<a;r-=n)i.splice(1,0,r);return i}}static getNumRawDataModules(a){if(a<S.MIN_VERSION||a>S.MAX_VERSION)throw new RangeError("Version number out of range");let n=(16*a+128)*a+64;if(a>=2){const i=Math.floor(a/7)+2;n-=(25*i-10)*i-55,a>=7&&(n-=36)}return c(208<=n&&n<=29648),n}static getNumDataCodewords(a,n){return Math.floor(S.getNumRawDataModules(a)/8)-S.ECC_CODEWORDS_PER_BLOCK[n.ordinal][a]*S.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][a]}static reedSolomonComputeDivisor(a){if(a<1||a>255)throw new RangeError("Degree out of range");let n=[];for(let r=0;r<a-1;r++)n.push(0);n.push(1);let i=1;for(let r=0;r<a;r++){for(let m=0;m<n.length;m++)n[m]=S.reedSolomonMultiply(n[m],i),m+1<n.length&&(n[m]^=n[m+1]);i=S.reedSolomonMultiply(i,2)}return n}static reedSolomonComputeRemainder(a,n){let i=n.map(r=>0);for(const r of a){const m=r^i.shift();i.push(0),n.forEach((d,u)=>i[u]^=S.reedSolomonMultiply(d,m))}return i}static reedSolomonMultiply(a,n){if(a>>>8||n>>>8)throw new RangeError("Byte out of range");let i=0;for(let r=7;r>=0;r--)i=i<<1^(i>>>7)*285,i^=(n>>>r&1)*a;return c(i>>>8==0),i}finderPenaltyCountPatterns(a){const n=a[1];c(n<=this.size*3);const i=n>0&&a[2]==n&&a[3]==n*3&&a[4]==n&&a[5]==n;return(i&&a[0]>=n*4&&a[6]>=n?1:0)+(i&&a[6]>=n*4&&a[0]>=n?1:0)}finderPenaltyTerminateAndCount(a,n,i){return a&&(this.finderPenaltyAddHistory(n,i),n=0),n+=this.size,this.finderPenaltyAddHistory(n,i),this.finderPenaltyCountPatterns(i)}finderPenaltyAddHistory(a,n){n[0]==0&&(a+=this.size),n.pop(),n.unshift(a)}};o.MIN_VERSION=1,o.MAX_VERSION=40,o.PENALTY_N1=3,o.PENALTY_N2=3,o.PENALTY_N3=40,o.PENALTY_N4=10,o.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],o.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],t.QrCode=o;function s(f,a,n){if(a<0||a>31||f>>>a)throw new RangeError("Value out of range");for(let i=a-1;i>=0;i--)n.push(f>>>i&1)}function l(f,a){return(f>>>a&1)!=0}function c(f){if(!f)throw new Error("Assertion error")}const h=class R{constructor(a,n,i){if(this.mode=a,this.numChars=n,this.bitData=i,n<0)throw new RangeError("Invalid argument");this.bitData=i.slice()}static makeBytes(a){let n=[];for(const i of a)s(i,8,n);return new R(R.Mode.BYTE,a.length,n)}static makeNumeric(a){if(!R.isNumeric(a))throw new RangeError("String contains non-numeric characters");let n=[];for(let i=0;i<a.length;){const r=Math.min(a.length-i,3);s(parseInt(a.substring(i,i+r),10),r*3+1,n),i+=r}return new R(R.Mode.NUMERIC,a.length,n)}static makeAlphanumeric(a){if(!R.isAlphanumeric(a))throw new RangeError("String contains unencodable characters in alphanumeric mode");let n=[],i;for(i=0;i+2<=a.length;i+=2){let r=R.ALPHANUMERIC_CHARSET.indexOf(a.charAt(i))*45;r+=R.ALPHANUMERIC_CHARSET.indexOf(a.charAt(i+1)),s(r,11,n)}return i<a.length&&s(R.ALPHANUMERIC_CHARSET.indexOf(a.charAt(i)),6,n),new R(R.Mode.ALPHANUMERIC,a.length,n)}static makeSegments(a){return a==""?[]:R.isNumeric(a)?[R.makeNumeric(a)]:R.isAlphanumeric(a)?[R.makeAlphanumeric(a)]:[R.makeBytes(R.toUtf8ByteArray(a))]}static makeEci(a){let n=[];if(a<0)throw new RangeError("ECI assignment value out of range");if(a<128)s(a,8,n);else if(a<16384)s(2,2,n),s(a,14,n);else if(a<1e6)s(6,3,n),s(a,21,n);else throw new RangeError("ECI assignment value out of range");return new R(R.Mode.ECI,0,n)}static isNumeric(a){return R.NUMERIC_REGEX.test(a)}static isAlphanumeric(a){return R.ALPHANUMERIC_REGEX.test(a)}getData(){return this.bitData.slice()}static getTotalBits(a,n){let i=0;for(const r of a){const m=r.mode.numCharCountBits(n);if(r.numChars>=1<<m)return 1/0;i+=4+m+r.bitData.length}return i}static toUtf8ByteArray(a){a=encodeURI(a);let n=[];for(let i=0;i<a.length;i++)a.charAt(i)!="%"?n.push(a.charCodeAt(i)):(n.push(parseInt(a.substring(i+1,i+3),16)),i+=2);return n}};h.NUMERIC_REGEX=/^[0-9]*$/,h.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,h.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let p=h;t.QrSegment=h})(se||(se={}));(t=>{(o=>{const s=class{constructor(c,h){this.ordinal=c,this.formatBits=h}};s.LOW=new s(0,1),s.MEDIUM=new s(1,0),s.QUARTILE=new s(2,3),s.HIGH=new s(3,2),o.Ecc=s})(t.QrCode||(t.QrCode={}))})(se||(se={}));(t=>{(o=>{const s=class{constructor(c,h){this.modeBits=c,this.numBitsCharCount=h}numCharCountBits(c){return this.numBitsCharCount[Math.floor((c+7)/17)]}};s.NUMERIC=new s(1,[10,12,14]),s.ALPHANUMERIC=new s(2,[9,11,13]),s.BYTE=new s(4,[8,16,16]),s.KANJI=new s(8,[8,10,12]),s.ECI=new s(7,[0,0,0]),o.Mode=s})(t.QrSegment||(t.QrSegment={}))})(se||(se={}));var oe=se;/**
36
+ * @license qrcode.react
37
+ * Copyright (c) Paul O'Shannessy
38
+ * SPDX-License-Identifier: ISC
39
+ */var Fs={L:oe.QrCode.Ecc.LOW,M:oe.QrCode.Ecc.MEDIUM,Q:oe.QrCode.Ecc.QUARTILE,H:oe.QrCode.Ecc.HIGH},wt=128,yt="L",jt="#FFFFFF",vt="#000000",bt=!1,Nt=1,As=4,Ts=0,Rs=.1;function Ct(t,o=0){const s=[];return t.forEach(function(l,c){let h=null;l.forEach(function(p,f){if(!p&&h!==null){s.push(`M${h+o} ${c+o}h${f-h}v1H${h+o}z`),h=null;return}if(f===l.length-1){if(!p)return;h===null?s.push(`M${f+o},${c+o} h1v1H${f+o}z`):s.push(`M${h+o},${c+o} h${f+1-h}v1H${h+o}z`);return}p&&h===null&&(h=f)})}),s.join("")}function Et(t,o){return t.slice().map((s,l)=>l<o.y||l>=o.y+o.h?s:s.map((c,h)=>h<o.x||h>=o.x+o.w?c:!1))}function Is(t,o,s,l){if(l==null)return null;const c=t.length+s*2,h=Math.floor(o*Rs),p=c/o,f=(l.width||h)*p,a=(l.height||h)*p,n=l.x==null?t.length/2-f/2:l.x*p,i=l.y==null?t.length/2-a/2:l.y*p,r=l.opacity==null?1:l.opacity;let m=null;if(l.excavate){let u=Math.floor(n),w=Math.floor(i),j=Math.ceil(f+n-u),g=Math.ceil(a+i-w);m={x:u,y:w,w:j,h:g}}const d=l.crossOrigin;return{x:n,y:i,h:a,w:f,excavation:m,opacity:r,crossOrigin:d}}function Ls(t,o){return o!=null?Math.max(Math.floor(o),0):t?As:Ts}function kt({value:t,level:o,minVersion:s,includeMargin:l,marginSize:c,imageSettings:h,size:p,boostLevel:f}){let a=$.useMemo(()=>{const u=(Array.isArray(t)?t:[t]).reduce((w,j)=>(w.push(...oe.QrSegment.makeSegments(j)),w),[]);return oe.QrCode.encodeSegments(u,Fs[o],s,void 0,void 0,f)},[t,o,s,f]);const{cells:n,margin:i,numCells:r,calculatedImageSettings:m}=$.useMemo(()=>{let d=a.getModules();const u=Ls(l,c),w=d.length+u*2,j=Is(d,p,u,h);return{cells:d,margin:u,numCells:w,calculatedImageSettings:j}},[a,p,h,l,c]);return{qrcode:a,margin:i,cells:n,numCells:r,calculatedImageSettings:m}}var $s=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),Ds=$.forwardRef(function(o,s){const l=o,{value:c,size:h=wt,level:p=yt,bgColor:f=jt,fgColor:a=vt,includeMargin:n=bt,minVersion:i=Nt,boostLevel:r,marginSize:m,imageSettings:d}=l,w=We(l,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:j}=w,g=We(w,["style"]),C=d==null?void 0:d.src,x=$.useRef(null),N=$.useRef(null),E=$.useCallback(V=>{x.current=V,typeof s=="function"?s(V):s&&(s.current=V)},[s]),[z,P]=$.useState(!1),{margin:A,cells:T,numCells:I,calculatedImageSettings:L}=kt({value:c,level:p,minVersion:i,boostLevel:r,includeMargin:n,marginSize:m,imageSettings:d,size:h});$.useEffect(()=>{if(x.current!=null){const V=x.current,J=V.getContext("2d");if(!J)return;let Pe=T;const X=N.current,me=L!=null&&X!==null&&X.complete&&X.naturalHeight!==0&&X.naturalWidth!==0;me&&L.excavation!=null&&(Pe=Et(T,L.excavation));const Fe=window.devicePixelRatio||1;V.height=V.width=h*Fe;const ue=h/I*Fe;J.scale(ue,ue),J.fillStyle=f,J.fillRect(0,0,I,I),J.fillStyle=a,$s?J.fill(new Path2D(Ct(Pe,A))):T.forEach(function(Ae,Te){Ae.forEach(function(v,B){v&&J.fillRect(B+A,Te+A,1,1)})}),L&&(J.globalAlpha=L.opacity),me&&J.drawImage(X,L.x+A,L.y+A,L.w,L.h)}}),$.useEffect(()=>{P(!1)},[C]);const Y=Ge({height:h,width:h},j);let q=null;return C!=null&&(q=$.createElement("img",{src:C,key:C,style:{display:"none"},onLoad:()=>{P(!0)},ref:N,crossOrigin:L==null?void 0:L.crossOrigin})),$.createElement($.Fragment,null,$.createElement("canvas",Ge({style:Y,height:h,width:h,ref:E,role:"img"},g)),q)});Ds.displayName="QRCodeCanvas";var St=$.forwardRef(function(o,s){const l=o,{value:c,size:h=wt,level:p=yt,bgColor:f=jt,fgColor:a=vt,includeMargin:n=bt,minVersion:i=Nt,boostLevel:r,title:m,marginSize:d,imageSettings:u}=l,w=We(l,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:j,cells:g,numCells:C,calculatedImageSettings:x}=kt({value:c,level:p,minVersion:i,boostLevel:r,includeMargin:n,marginSize:d,imageSettings:u,size:h});let N=g,E=null;u!=null&&x!=null&&(x.excavation!=null&&(N=Et(g,x.excavation)),E=$.createElement("image",{href:u.src,height:x.h,width:x.w,x:x.x+j,y:x.y+j,preserveAspectRatio:"none",opacity:x.opacity,crossOrigin:x.crossOrigin}));const z=Ct(N,j);return $.createElement("svg",Ge({height:h,width:h,viewBox:`0 0 ${C} ${C}`,ref:s,role:"img"},w),!!m&&$.createElement("title",null,m),$.createElement("path",{fill:f,d:`M0,0 h${C}v${C}H0z`,shapeRendering:"crispEdges"}),$.createElement("path",{fill:a,d:z,shapeRendering:"crispEdges"}),E)});St.displayName="QRCodeSVG";const Le=1500;async function he(t,o){try{return(await t.json()).error??o}catch{return o}}function Mt({open:t,onOpenChange:o,accountId:s,accountName:l}){const{t:c}=F(),h=O(),[p,f]=y.useState(null),[a,n]=y.useState("starting"),[i,r]=y.useState(null),m=y.useRef(null),d=y.useRef(0),u=y.useRef(null),w=y.useCallback(()=>{m.current!==null&&(clearTimeout(m.current),m.current=null)},[]),j=y.useCallback(()=>{var P;w(),(P=u.current)==null||P.abort(),u.current=null,d.current+=1},[w]),g=y.useCallback(async()=>{j(),await h.invalidateQueries({queryKey:["weixin-accounts"]}),b.success(c("weixin.bindSuccess")),o(!1)},[j,o,h,c]),C=y.useCallback(async(P,A,T)=>{try{const I=await fetch(`/api/settings/weixin/accounts/${s}/users`,{signal:A});if(d.current!==P)return;if(!I.ok)throw new Error(await he(I,c("weixin.loginFailed")));const L=await I.json();if(d.current!==P)return;const Y=L.users.find(q=>!T.has(q.userId)||q.lastInboundAt!==T.get(q.userId));if(Y){if(n("binding"),r(c("weixin.bindingInProgress")),Y.status==="pending"){const q=await fetch(`/api/settings/weixin/accounts/${s}/users/${encodeURIComponent(Y.userId)}/approve`,{method:"POST",signal:A});if(d.current!==P)return;if(!q.ok)throw new Error(await he(q,c("weixin.approveFailed")))}await g();return}m.current=setTimeout(()=>void C(P,A,T),Le)}catch(I){if(A.aborted||d.current!==P)return;n("error"),r(I instanceof Error?I.message:c("weixin.loginFailed"))}},[s,g,c]),x=y.useCallback(async(P,A)=>{try{const T=await fetch(`/api/settings/weixin/accounts/${s}/login/status`,{signal:A});if(d.current!==P)return;if(!T.ok)throw new Error(await he(T,c("weixin.loginFailed")));const I=await T.json();if(d.current!==P)return;if(I.status==="expired"){n("expired"),r(c("weixin.loginExpired"));return}if(I.status==="error"){n("error"),r(c("weixin.loginError",{message:I.message??""}));return}if(I.loggedIn||I.status==="confirmed"){const L=await fetch(`/api/settings/weixin/accounts/${s}/users`,{signal:A});if(d.current!==P)return;if(!L.ok)throw new Error(await he(L,c("weixin.loginFailed")));const Y=await L.json();if(d.current!==P)return;const q=new Map(Y.users.map(V=>[V.userId,V.lastInboundAt]));n("awaitMessage"),r(c("weixin.scanConfirmedSendHint")),m.current=setTimeout(()=>void C(P,A,q),Le);return}n("scanning"),r(c("weixin.scanQrcodeHint")),m.current=setTimeout(()=>void x(P,A),Le)}catch(T){if(A.aborted||d.current!==P)return;n("error"),r(T instanceof Error?T.message:c("weixin.loginFailed"))}},[s,C,c]),N=y.useCallback(async()=>{j();const P=d.current,A=new AbortController;u.current=A,n("starting"),r(null),f(null);try{const T=await fetch(`/api/settings/weixin/accounts/${s}/login/start`,{method:"POST",signal:A.signal});if(d.current!==P)return;if(!T.ok)throw new Error(await he(T,c("weixin.loginFailed")));const I=await T.json();if(d.current!==P)return;f(I.qrcodeUrl),n("scanning"),r(c("weixin.scanQrcodeHint")),m.current=setTimeout(()=>void x(P,A.signal),Le)}catch(T){if(A.signal.aborted||d.current!==P)return;n("error"),r(T instanceof Error?T.message:c("weixin.loginFailed"))}},[s,j,x,c]);y.useEffect(()=>{if(!t){j();return}return N(),j},[t,s]);const E=a==="starting",z=a==="expired"||a==="error";return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-sm","data-testid":`weixin-account-login-modal-${s}`,children:[e.jsxs(ie,{children:[e.jsx(re,{children:c("weixin.scanToLogin")}),e.jsx(Ce,{children:l})]}),e.jsxs("div",{className:"flex flex-col items-center gap-3 py-2",children:[e.jsxs("div",{className:"flex h-56 w-56 items-center justify-center rounded-lg border border-border bg-white",children:[E&&e.jsx(Q,{className:"h-8 w-8 animate-spin text-muted-foreground"}),!E&&p&&e.jsx(St,{value:p,size:208,marginSize:3,"data-testid":`weixin-account-login-qrcode-${s}`}),!E&&!p&&e.jsx(Ve,{className:"h-10 w-10 text-muted-foreground"})]}),i&&e.jsx("p",{className:"text-center text-sm font-medium","data-testid":`weixin-account-login-status-${s}`,children:i})]}),e.jsxs(de,{children:[z&&e.jsxs(k,{variant:"secondary","data-testid":"weixin-account-login-refresh",onClick:()=>void N(),children:[e.jsx(Ze,{className:"h-4 w-4"}),c("weixin.refreshQrcode")]}),e.jsx(k,{variant:"outline",onClick:()=>o(!1),children:c("weixin.closeLogin")})]})]})})}const Os="min-h-10";async function ct(t,o){try{return(await t.json()).error??o}catch{return o}}function Bs({open:t,onOpenChange:o,account:s}){const{t:l}=F(),c=O(),h=!!s,[p,f]=y.useState(""),[a,n]=y.useState(!0),[i,r]=y.useState(null);y.useEffect(()=>{t&&(f((s==null?void 0:s.name)??""),n((s==null?void 0:s.enabled)??!0))},[t,s]);const m=M({mutationFn:async()=>{const g=await fetch("/api/settings/weixin/accounts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:p.trim(),enabled:a,allowAuthRequests:!0})});if(!g.ok)throw new Error(await ct(g,l("weixin.createFailed")));return await g.json()},onSuccess:async g=>{await c.invalidateQueries({queryKey:["weixin-accounts"]}),b.success(l("weixin.accountCreated")),o(!1),r({id:g.accountId,name:p.trim()})},onError:g=>{b.error(g instanceof Error?g.message:l("common.error"))}}),d=M({mutationFn:async()=>{if(!s)throw new Error(l("weixin.updateFailed"));const g=await fetch(`/api/settings/weixin/accounts/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:p.trim(),enabled:a})});if(!g.ok)throw new Error(await ct(g,l("weixin.updateFailed")))},onSuccess:async()=>{await c.invalidateQueries({queryKey:["weixin-accounts"]}),b.success(l("weixin.accountUpdated")),o(!1)},onError:g=>{b.error(g instanceof Error?g.message:l("common.error"))}}),u=m.isPending||d.isPending,w=p.trim().length>0,j=()=>{!w||u||(h?d.mutate():m.mutate())};return e.jsxs(e.Fragment,{children:[e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":h?`weixin-account-edit-modal-${s==null?void 0:s.id}`:"weixin-account-add-modal",children:[e.jsx(ie,{children:e.jsx(re,{children:l(h?"weixin.editAccount":"weixin.addAccount")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"weixin-account-name",children:l("weixin.accountName")}),e.jsx(D,{id:"weixin-account-name","data-testid":"weixin-account-name-input",value:p,onChange:g=>f(g.target.value),placeholder:l("weixin.accountNamePlaceholder"),className:Os})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium",children:l("weixin.enableAccount")}),e.jsx(_,{checked:a,"data-testid":"weixin-account-enabled",onCheckedChange:g=>n(!!g)})]})]}),e.jsxs(de,{children:[e.jsx(k,{variant:"outline",onClick:()=>o(!1),disabled:u,children:l("common.cancel")}),e.jsxs(k,{variant:"secondary","data-testid":"weixin-account-form-submit",onClick:j,disabled:!w||u,children:[u?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),l("common.save")]})]})]})}),i&&e.jsx(Mt,{open:!!i,onOpenChange:g=>{g||r(null)},accountId:i.id,accountName:i.name})]})}async function Ue(t,o){try{return(await t.json()).error??o}catch{return o}}function _s({account:t,onEdit:o}){const{t:s}=F(),l=O(),[c,h]=y.useState(!1),p=t.loggedIn&&t.authorizedCount>0,f=M({mutationFn:async r=>{const m=await fetch(`/api/settings/weixin/accounts/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:r})});if(!m.ok)throw new Error(await Ue(m,s("weixin.updateFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["weixin-accounts"]})},onError:r=>{b.error(r instanceof Error?r.message:s("common.error"))}}),a=M({mutationFn:async()=>{const r=await fetch(`/api/settings/weixin/accounts/${t.id}/test`,{method:"POST"});if(!r.ok)throw new Error(await Ue(r,s("weixin.testMessageFailed")))},onSuccess:()=>{b.success(s("weixin.testMessageSent"))},onError:r=>{b.error(r instanceof Error?r.message:s("weixin.testMessageFailed"))}}),n=M({mutationFn:async()=>{const r=await fetch(`/api/settings/weixin/accounts/${t.id}`,{method:"DELETE"});if(!r.ok)throw new Error(await Ue(r,s("weixin.deleteFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["weixin-accounts"]}),b.success(s("weixin.accountDeleted"))},onError:r=>{b.error(r instanceof Error?r.message:s("common.error"))}}),i=t.loggedIn?p?{label:s("weixin.bound"),tone:"success"}:{label:s("weixin.unbound"),tone:"muted"}:{label:s("weixin.notLoggedIn"),tone:"muted"};return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-3 sm:flex-row sm:items-center sm:justify-between","data-testid":`weixin-account-card-${t.id}`,"data-account-name":t.name,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(_,{checked:t.enabled,disabled:f.isPending,onCheckedChange:r=>f.mutate(!!r),"data-testid":`weixin-account-enabled-${t.id}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate font-medium",children:t.name}),e.jsx("span",{className:mt("shrink-0 rounded px-1.5 py-0.5 text-xs font-medium",i.tone==="success"?"bg-emerald-500/15 text-emerald-600 dark:text-emerald-400":"bg-muted text-muted-foreground"),"data-testid":`weixin-account-login-state-${t.id}`,children:i.label}),p&&t.needsReactivationCount>0&&e.jsxs("span",{className:"flex shrink-0 items-center gap-1 rounded bg-destructive/15 px-1.5 py-0.5 text-xs font-medium text-destructive",title:s("weixin.reactivationHint"),"data-testid":`weixin-account-needs-reactivation-${t.id}`,children:[e.jsx(xt,{className:"h-3.5 w-3.5"}),s("weixin.needsReactivation")]})]}),p&&t.needsReactivationCount>0&&e.jsx("div",{className:"mt-0.5 text-xs text-muted-foreground",children:s("weixin.reactivationHint")})]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-1",children:[p?e.jsxs(e.Fragment,{children:[e.jsxs(k,{variant:"ghost",size:"sm","data-testid":`weixin-account-relogin-${t.id}`,onClick:()=>h(!0),children:[e.jsx(Ve,{className:"h-4 w-4"}),s("weixin.relogin")]}),e.jsxs(k,{variant:"ghost",size:"sm","data-testid":`weixin-account-test-${t.id}`,onClick:()=>a.mutate(),disabled:a.isPending,children:[e.jsx(gt,{className:"h-4 w-4"}),s("weixin.testMessage")]})]}):e.jsxs(k,{variant:"secondary",size:"sm","data-testid":`weixin-account-login-${t.id}`,onClick:()=>h(!0),children:[e.jsx(Ve,{className:"h-4 w-4"}),s("weixin.bindAction")]}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("common.edit"),"data-testid":`weixin-account-edit-${t.id}`,onClick:()=>o(t),children:e.jsx(Oe,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("weixin.deleteAccount"),"data-testid":`weixin-account-delete-${t.id}`,onClick:()=>n.mutate(),disabled:n.isPending,children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(Mt,{open:c,onOpenChange:h,accountId:t.id,accountName:t.name})]})}async function zs(t,o){try{return(await t.json()).error??o}catch{return o}}function qs(){var n;const{t}=F(),[o,s]=y.useState(!1),[l,c]=y.useState(void 0),h=K({queryKey:["weixin-accounts"],queryFn:async()=>{const i=await fetch("/api/settings/weixin/accounts");if(!i.ok)throw new Error(await zs(i,t("weixin.loadAccountsFailed")));return await i.json()}}),p=((n=h.data)==null?void 0:n.accounts)??[],f=()=>{c(void 0),s(!0)},a=i=>{c(i),s(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0",children:[e.jsxs(G,{className:"flex flex-row items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx(W,{children:t("weixin.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("weixin.subtitle")})]}),e.jsxs(k,{variant:"secondary","data-testid":"weixin-add-account",onClick:f,children:[e.jsx(xe,{className:"h-4 w-4"}),t("weixin.addAccount")]})]}),e.jsxs(H,{className:"space-y-3",children:[e.jsx("p",{className:"rounded-lg border border-border bg-muted/40 p-3 text-xs text-muted-foreground",children:t("weixin.replyOnlyNotice")}),h.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!h.isLoading&&p.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("weixin.noAccounts")}),p.map(i=>e.jsx(_s,{account:i,onEdit:a},i.id))]})]}),e.jsx(Bs,{open:o,onOpenChange:s,account:l})]})}async function Je(t,o){try{return(await t.json()).error??o}catch{return o}}function ea(){var Ae,Te;const{t}=F(),o=O(),{refreshSettings:s}=ge(),[l,c]=y.useState("general"),h=It(v=>v.theme),p=ge(v=>v.updateTheme),f=h==="dark",[a,n]=y.useState("tmex"),[i,r]=y.useState(window.location.origin),[m,d]=y.useState("en_US"),[u,w]=y.useState(6),[j,g]=y.useState(3),[C,x]=y.useState(!0),[N,E]=y.useState(!0),[z,P]=y.useState(!0),[A,T]=y.useState(!0),[I,L]=y.useState(2),[Y,q]=y.useState(10),[V,J]=y.useState(!1),Pe=v=>{const B=v?"dark":"light";p(B),document.documentElement.classList.toggle("dark",B==="dark")},X=K({queryKey:["site-settings"],queryFn:async()=>{const v=await fetch("/api/settings/site");if(!v.ok)throw new Error(await Je(v,t("settings.loadFailed")));return await v.json()}});y.useEffect(()=>{var B;const v=(B=X.data)==null?void 0:B.settings;v&&(n(v.siteName),r(v.siteUrl),d(v.language??"en_US"),w(v.bellThrottleSeconds),g(v.notificationThrottleSeconds??3),x(v.enableBrowserNotificationToast??!0),E(v.enableNotificationPush??!0),P(v.enableBellPush??!0),T(v.enableBellSound??!0))},[(Ae=X.data)==null?void 0:Ae.settings]);const me=M({mutationFn:async()=>{const B=await fetch("/api/settings/site",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({siteName:a,siteUrl:i,language:m,bellThrottleSeconds:u,notificationThrottleSeconds:j,enableBrowserNotificationToast:C,enableNotificationPush:N,enableBellPush:z,enableBellSound:A,sshReconnectMaxRetries:I,sshReconnectDelaySeconds:Y})});if(!B.ok)throw new Error(await Je(B,t("settings.saveFailed")))},onSuccess:async()=>{var v,B;await Promise.all([o.invalidateQueries({queryKey:["site-settings"]}),s()]),b.success(t("settings.settingsSaved")),((B=(v=X.data)==null?void 0:v.settings)==null?void 0:B.language)!==m&&(qt.changeLanguage(m),J(!0))},onError:v=>{b.error(v instanceof Error?v.message:t("common.error"))}}),Fe=[{value:"general",label:t("settings.tabGroup.general"),icon:Lt,testId:"settings-tab-general"},{value:"terminal",label:t("settings.tabGroup.terminal"),icon:Ye,testId:"settings-tab-terminal"},{value:"devicesAndFiles",label:t("settings.tabGroup.devicesAndFiles"),icon:ss,testId:"settings-tab-devicesAndFiles"},{value:"notifications",label:t("settings.tabGroup.notifications"),icon:$t,testId:"settings-tab-notifications"},{value:"ai",label:t("settings.tabGroup.ai"),icon:Dt,testId:"settings-tab-ai"}],ue=e.jsx("div",{className:"flex justify-end pt-2",children:e.jsxs(k,{variant:"secondary","data-testid":"settings-save",onClick:()=>me.mutate(),disabled:me.isPending,className:"w-full sm:w-auto",children:[e.jsx(ee,{className:"h-4 w-4"}),t("common.save")]})});return e.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-4 p-3 pb-[calc(2rem+env(safe-area-inset-bottom))] sm:gap-6 sm:p-5","data-testid":"settings-page",children:[e.jsx(Ot,{value:l,onValueChange:v=>c(v),children:e.jsx(Bt,{className:"w-full gap-1 !justify-start overflow-x-auto rounded-xl border border-border/60 p-1.5 group-data-horizontal/tabs:h-12 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:Fe.map(v=>{const B=v.icon;return e.jsxs(_t,{value:v.value,"data-testid":v.testId,className:mt(zt,"min-w-max gap-2 px-3.5"),children:[e.jsx(B,{}),v.label]},v.value)})})}),l==="general"&&e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0",children:[e.jsx(G,{children:e.jsx(W,{children:t("settings.siteSettings")})}),e.jsxs(H,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"site-name-input",children:t("settings.siteName")}),e.jsx(D,{id:"site-name-input",value:a,onChange:v=>n(v.target.value),placeholder:t("settings.siteNamePlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"site-url-input",children:t("settings.siteUrl")}),e.jsx(D,{id:"site-url-input",value:i,onChange:v=>r(v.target.value),placeholder:t("settings.siteUrlPlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"language-select",children:t("settings.language")}),e.jsxs(Ee,{value:m,onValueChange:v=>{v&&d(v)},children:[e.jsx(ke,{id:"language-select","data-testid":"settings-language-select",className:"w-full min-h-10",children:e.jsx(Se,{placeholder:t("settings.language"),children:((Te=et.locales.find(v=>v.code===m))==null?void 0:Te.nativeName)??m})}),e.jsx(Me,{className:"max-h-[var(--tmex-viewport-height)]",children:et.locales.map(v=>e.jsx(le,{value:v.code,children:v.nativeName},v.code))})]}),V&&e.jsx("p",{className:"mt-1 text-xs text-primary","data-testid":"settings-refresh-notice",children:t("settings.refreshToApply")})]}),e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.theme")})}),e.jsx(_,{checked:f,onCheckedChange:v=>Pe(!!v),"data-testid":"settings-theme-toggle"})]})}),ue]})]}),e.jsx(Ss,{})]}),l==="devicesAndFiles"&&e.jsxs(e.Fragment,{children:[e.jsx(rs,{}),e.jsx(os,{})]}),l==="notifications"&&e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"border-0 ring-0",children:e.jsxs(H,{className:"space-y-6 pt-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableNotificationPush")})}),e.jsx(_,{checked:N,onCheckedChange:v=>E(!!v),"data-testid":"settings-enable-notification-push"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableBellPush")})}),e.jsx(_,{checked:z,onCheckedChange:v=>P(!!v),"data-testid":"settings-enable-bell-push"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableBellSound")})}),e.jsx(_,{checked:A,onCheckedChange:v=>T(!!v),"data-testid":"settings-enable-bell-sound"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableBrowserNotificationToast")})}),e.jsx(_,{checked:C,onCheckedChange:v=>x(!!v),"data-testid":"settings-enable-browser-notification-toast"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"bell-throttle-input",children:t("settings.bellThrottle")}),e.jsx(D,{id:"bell-throttle-input",type:"number",value:u,min:0,max:300,onChange:v=>w(Number(v.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"notification-throttle-input",children:t("settings.notificationThrottle")}),e.jsx(D,{id:"notification-throttle-input",type:"number",value:j,min:0,max:300,onChange:v=>g(Number(v.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"ssh-reconnect-retries-input",children:t("settings.sshReconnectMaxRetries")}),e.jsx(D,{id:"ssh-reconnect-retries-input",type:"number",value:I,min:0,max:20,onChange:v=>L(Number(v.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"ssh-reconnect-delay-input",children:t("settings.sshReconnectDelay")}),e.jsx(D,{id:"ssh-reconnect-delay-input",type:"number",value:Y,min:1,max:300,onChange:v=>q(Number(v.target.value)),className:"min-h-10"})]})]}),ue]})}),e.jsx(Es,{}),e.jsx(qs,{}),e.jsx(Ms,{})]}),l==="ai"&&e.jsxs(e.Fragment,{children:[e.jsx(ps,{}),e.jsx(js,{})]}),l==="terminal"&&e.jsx(ks,{})]})}function ta(){const{t}=F();return e.jsx(e.Fragment,{children:t("sidebar.settings")})}function sa(){const{t}=F(),[o,s]=y.useState(!1),l=M({mutationFn:async()=>{const c=await fetch("/api/settings/restart",{method:"POST"});if(!c.ok)throw new Error(await Je(c,t("settings.restartFailed")))},onSuccess:()=>{b.success(t("settings.restartScheduled"))},onError:c=>{b.error(c instanceof Error?c.message:t("common.error"))}});return e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"ghost",size:"icon-sm",onClick:()=>s(!0),disabled:l.isPending,"aria-label":t("settings.restartGateway"),title:t("settings.restartGateway"),className:"text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(Wt,{className:"h-4 w-4"})}),e.jsx(fe,{open:o,onOpenChange:s,children:e.jsxs(pe,{children:[e.jsxs(we,{children:[e.jsx(ye,{children:t("settings.restartGateway")}),e.jsx(je,{children:t("settings.restartConfirm")})]}),e.jsxs(ve,{children:[e.jsx(be,{onClick:()=>s(!1),children:t("common.cancel")}),e.jsx(Ne,{variant:"destructive",onClick:()=>{l.mutate(),s(!1)},children:t("common.confirm")})]})]})})]})}export{sa as PageActions,ta as PageTitle,ea as default};