@camstack/addon-admin-ui 0.1.16 → 0.1.17

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 (24) hide show
  1. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DlquBRmD.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CziSE-Do.js} +1 -1
  2. package/dist/assets/{devices-CVfa8e_5.js → devices-BfsgGvwu.js} +1 -1
  3. package/dist/assets/{hostInit-Bq0J4U4L.js → hostInit-7yPTCcmg.js} +1 -1
  4. package/dist/assets/{index-C5--Sp9A.js → index-BlKJSHE9.js} +2 -2
  5. package/dist/assets/index-C-M4yvxf.js +1 -0
  6. package/dist/assets/{index-BqEwAQt-.js → index-DculG9Gi.js} +2 -2
  7. package/dist/assets/index-DfH297U6.js +1 -0
  8. package/dist/assets/{index-CJH_U_aT.js → index-Dvmk3HcY.js} +1 -1
  9. package/dist/assets/index-K1-f6oQr.js +1 -0
  10. package/dist/assets/{index-Bftw8yZ0.js → index-X-IEwb-L.js} +2 -2
  11. package/dist/assets/index-cfq-Npln.js +1 -0
  12. package/dist/assets/{index-CLnkxPD7.js → index-iCcWZGKs.js} +1 -1
  13. package/dist/assets/index-ptcmLXsE.js +1 -0
  14. package/dist/assets/{remoteEntry-qFyESaJr.js → remoteEntry-Da_G1gka.js} +1 -1
  15. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-cGbq1Btt.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-kSAHDLPS.js} +2 -2
  16. package/dist/index.html +3 -3
  17. package/dist/mf-entry-bootstrap-0.js +2 -2
  18. package/dist/sw.js +1 -1
  19. package/package.json +1 -1
  20. package/dist/assets/index-B3BmQjhl.js +0 -1
  21. package/dist/assets/index-BYRl5bfb.js +0 -1
  22. package/dist/assets/index-gZlh9vZc.js +0 -1
  23. package/dist/assets/index-o6URf7uT.js +0 -1
  24. package/dist/assets/index-otlbS_ZJ.js +0 -1
@@ -1,4 +1,4 @@
1
- import{b as wj,g as Sj}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_1_jsx_mf_2_runtime__loadShare__.mjs-C_6K4VBY.js";import{r as Pl}from"./__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs_commonjs-proxy-CSyOECfO.js";import{r as Rl}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_1_jsx_mf_2_runtime__loadShare__.mjs_commonjs-proxy-DrLZNXOX.js";import{r as kj}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-xw6c6JeS.js";import{r as jj}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs_commonjs-proxy-BEKtiDI3.js";import{r as Nj}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs_commonjs-proxy-DXPQtD9p.js";import{r as Cj}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_client__loadShare__.mjs_commonjs-proxy-WD2WouMQ.js";import{r as Mj}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs_commonjs-proxy-GvBGLFI2.js";import{r as Ej}from"./index-CLnkxPD7.js";import{s as Aj}from"./index-CJH_U_aT.js";function Pj(c,Me){for(var gt=0;gt<Me.length;gt++){const Fe=Me[gt];if(typeof Fe!="string"&&!Array.isArray(Fe)){for(const ze in Fe)if(ze!=="default"&&!(ze in c)){const rt=Object.getOwnPropertyDescriptor(Fe,ze);rt&&Object.defineProperty(c,ze,rt.get?rt:{enumerable:!0,get:()=>Fe[ze]})}}}return Object.freeze(Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}))}var En={},An={},El;function Rj(){return El||(El=1,(function(c){Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}),Dl();let Me=Pl,gt=Rl;var Fe={frigate:"#3b82f6",scrypted:"#a855f7",reolink:"#06b6d4",homeAssistant:"#22d3ee",rtsp:"#78716c"},ze={primary:"#f59e42",primaryForeground:"#0c0a09",background:"#0c0a09",backgroundElevated:"#1c1917",surface:"#1c1917",surfaceHover:"#292524",border:"#292524",borderSubtle:"#1c1917",foreground:"#fafaf9",foregroundMuted:"#a8a29e",foregroundSubtle:"#78716c",foregroundDisabled:"#57534e",success:"#4ade80",warning:"#fbbf24",danger:"#f87171",info:"#60a5fa",provider:Fe},rt={primary:"#e67e22",primaryForeground:"#ffffff",background:"#fafaf9",backgroundElevated:"#ffffff",surface:"#f5f5f4",surfaceHover:"#e7e5e4",border:"#d6d3d1",borderSubtle:"#e7e5e4",foreground:"#1c1917",foregroundMuted:"#57534e",foregroundSubtle:"#78716c",foregroundDisabled:"#a8a29e",success:"#16a34a",warning:"#d97706",danger:"#dc2626",info:"#2563eb",provider:Fe},Et={colors:{dark:ze,light:rt},spacing:{xs:2,sm:4,md:8,lg:12,xl:16,"2xl":24,"3xl":32},radius:{sm:4,md:6,lg:8,xl:12},typography:{fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',sizes:{xs:{fontSize:10,lineHeight:14},sm:{fontSize:11,lineHeight:16},base:{fontSize:12,lineHeight:18},lg:{fontSize:13,lineHeight:18},xl:{fontSize:14,lineHeight:20},"2xl":{fontSize:16,lineHeight:22},"3xl":{fontSize:20,lineHeight:28}},weights:{regular:400,medium:500,semibold:600,bold:700}},table:{rowHeight:28,headerHeight:24,cellPaddingX:8,cellPaddingY:6},sidebar:{width:176,itemHeight:28,iconSize:14}};function hr(le,ge){const me={...le};for(const we in ge){const Ue=ge[we],Ye=le[we];Ue!==void 0&&typeof Ue=="object"&&Ue!==null&&!Array.isArray(Ue)&&typeof Ye=="object"&&Ye!==null?me[we]=hr(Ye,Ue):Ue!==void 0&&(me[we]=Ue)}return me}function gr(le){return le?hr(structuredClone(Et),le):structuredClone(Et)}function Qe(le){return le.replace(/[A-Z]/g,ge=>`-${ge.toLowerCase()}`)}function Ge(le){return`--color-${Qe(le)}`}function h(le){const ge=[];for(const[me,we]of Object.entries(le))me!=="provider"&&ge.push(` ${Ge(me)}: ${we};`);return ge.join(`
1
+ import{b as wj,g as Sj}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_1_jsx_mf_2_runtime__loadShare__.mjs-C_6K4VBY.js";import{r as Pl}from"./__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs_commonjs-proxy-CSyOECfO.js";import{r as Rl}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_1_jsx_mf_2_runtime__loadShare__.mjs_commonjs-proxy-DrLZNXOX.js";import{r as kj}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-xw6c6JeS.js";import{r as jj}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs_commonjs-proxy-BEKtiDI3.js";import{r as Nj}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs_commonjs-proxy-DXPQtD9p.js";import{r as Cj}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_client__loadShare__.mjs_commonjs-proxy-WD2WouMQ.js";import{r as Mj}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs_commonjs-proxy-GvBGLFI2.js";import{r as Ej}from"./index-iCcWZGKs.js";import{s as Aj}from"./index-Dvmk3HcY.js";function Pj(c,Me){for(var gt=0;gt<Me.length;gt++){const Fe=Me[gt];if(typeof Fe!="string"&&!Array.isArray(Fe)){for(const ze in Fe)if(ze!=="default"&&!(ze in c)){const rt=Object.getOwnPropertyDescriptor(Fe,ze);rt&&Object.defineProperty(c,ze,rt.get?rt:{enumerable:!0,get:()=>Fe[ze]})}}}return Object.freeze(Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}))}var En={},An={},El;function Rj(){return El||(El=1,(function(c){Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}),Dl();let Me=Pl,gt=Rl;var Fe={frigate:"#3b82f6",scrypted:"#a855f7",reolink:"#06b6d4",homeAssistant:"#22d3ee",rtsp:"#78716c"},ze={primary:"#f59e42",primaryForeground:"#0c0a09",background:"#0c0a09",backgroundElevated:"#1c1917",surface:"#1c1917",surfaceHover:"#292524",border:"#292524",borderSubtle:"#1c1917",foreground:"#fafaf9",foregroundMuted:"#a8a29e",foregroundSubtle:"#78716c",foregroundDisabled:"#57534e",success:"#4ade80",warning:"#fbbf24",danger:"#f87171",info:"#60a5fa",provider:Fe},rt={primary:"#e67e22",primaryForeground:"#ffffff",background:"#fafaf9",backgroundElevated:"#ffffff",surface:"#f5f5f4",surfaceHover:"#e7e5e4",border:"#d6d3d1",borderSubtle:"#e7e5e4",foreground:"#1c1917",foregroundMuted:"#57534e",foregroundSubtle:"#78716c",foregroundDisabled:"#a8a29e",success:"#16a34a",warning:"#d97706",danger:"#dc2626",info:"#2563eb",provider:Fe},Et={colors:{dark:ze,light:rt},spacing:{xs:2,sm:4,md:8,lg:12,xl:16,"2xl":24,"3xl":32},radius:{sm:4,md:6,lg:8,xl:12},typography:{fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',sizes:{xs:{fontSize:10,lineHeight:14},sm:{fontSize:11,lineHeight:16},base:{fontSize:12,lineHeight:18},lg:{fontSize:13,lineHeight:18},xl:{fontSize:14,lineHeight:20},"2xl":{fontSize:16,lineHeight:22},"3xl":{fontSize:20,lineHeight:28}},weights:{regular:400,medium:500,semibold:600,bold:700}},table:{rowHeight:28,headerHeight:24,cellPaddingX:8,cellPaddingY:6},sidebar:{width:176,itemHeight:28,iconSize:14}};function hr(le,ge){const me={...le};for(const we in ge){const Ue=ge[we],Ye=le[we];Ue!==void 0&&typeof Ue=="object"&&Ue!==null&&!Array.isArray(Ue)&&typeof Ye=="object"&&Ye!==null?me[we]=hr(Ye,Ue):Ue!==void 0&&(me[we]=Ue)}return me}function gr(le){return le?hr(structuredClone(Et),le):structuredClone(Et)}function Qe(le){return le.replace(/[A-Z]/g,ge=>`-${ge.toLowerCase()}`)}function Ge(le){return`--color-${Qe(le)}`}function h(le){const ge=[];for(const[me,we]of Object.entries(le))me!=="provider"&&ge.push(` ${Ge(me)}: ${we};`);return ge.join(`
2
2
  `)}function r(le){const ge=[];for(const[me,we]of Object.entries(le))ge.push(` --color-provider-${Qe(me)}: ${we};`);return ge.join(`
3
3
  `)}function Ze(le){const ge=[];for(const[me,we]of Object.entries(le))ge.push(` --spacing-${me}: ${we}px;`);return ge.join(`
4
4
  `)}function bt(le){const ge=[];for(const[me,we]of Object.entries(le))ge.push(` --radius-${me}: ${we}px;`);return ge.join(`
@@ -73,7 +73,7 @@ ${s.slice(0,5).join(`
73
73
  *
74
74
  * This source code is licensed under the ISC license.
75
75
  * See the LICENSE file in the root directory of this source tree.
76
- */var P=(e,t)=>{const s=(0,h.forwardRef)(({className:n,...o},a)=>(0,h.createElement)(Pd,{ref:a,iconNode:t,className:Qo(`lucide-${Cd(Uo(e))}`,`lucide-${e}`,n),...o}));return s.displayName=Uo(e),s},ft=P("activity",[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",key:"169zse"}]]),Rd=P("arrow-down",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]),Dd=P("arrow-left",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]),Td=P("arrow-right",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]),As=P("arrow-up-to-line",[["path",{d:"M5 3h14",key:"7usisc"}],["path",{d:"m18 13-6-6-6 6",key:"1kf1n9"}],["path",{d:"M12 7v14",key:"1akyts"}]]),Id=P("arrow-up",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]),Ld=P("battery-full",[["path",{d:"M10 10v4",key:"1mb2ec"}],["path",{d:"M14 10v4",key:"1nt88p"}],["path",{d:"M22 14v-4",key:"14q9d5"}],["path",{d:"M6 10v4",key:"1n77qd"}],["rect",{x:"2",y:"6",width:"16",height:"12",rx:"2",key:"13zb55"}]]),Od=P("battery-low",[["path",{d:"M22 14v-4",key:"14q9d5"}],["path",{d:"M6 14v-4",key:"14a6bd"}],["rect",{x:"2",y:"6",width:"16",height:"12",rx:"2",key:"13zb55"}]]),_d=P("battery-warning",[["path",{d:"M10 17h.01",key:"nbq80n"}],["path",{d:"M10 7v6",key:"nne03l"}],["path",{d:"M14 6h2a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2",key:"1m83kb"}],["path",{d:"M22 14v-4",key:"14q9d5"}],["path",{d:"M6 18H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2",key:"h8lgfh"}]]),Ho=P("battery",[["path",{d:"M 22 14 L 22 10",key:"nqc4tb"}],["rect",{x:"2",y:"6",width:"16",height:"12",rx:"2",key:"13zb55"}]]),$d=P("bell-ring",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M22 8c0-2.3-.8-4.3-2-6",key:"5bb3ad"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}],["path",{d:"M4 2C2.8 3.7 2 5.7 2 8",key:"tap9e0"}]]),Ir=P("bell",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]]),Gd=P("bug",[["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z",key:"uouzyp"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M21 21a4 4 0 0 0-3.81-4",key:"1b0z45"}],["path",{d:"M21 5a4 4 0 0 1-3.55 3.97",key:"5cxbf6"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M3 21a4 4 0 0 1 3.81-4",key:"1fjd4g"}],["path",{d:"M3 5a4 4 0 0 0 3.55 3.97",key:"1d7oge"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M9 7.13V6a3 3 0 1 1 6 0v1.13",key:"1vgav8"}]]),Ps=P("camera",[["path",{d:"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z",key:"18u6gg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]]),Bd=P("cast",[["path",{d:"M2 8V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-6",key:"3zrzxg"}],["path",{d:"M2 12a9 9 0 0 1 8 8",key:"g6cvee"}],["path",{d:"M2 16a5 5 0 0 1 4 4",key:"1y1dii"}],["line",{x1:"2",x2:"2.01",y1:"20",y2:"20",key:"xu2jvo"}]]),sr=P("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]),St=P("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]),Fd=P("chevron-left",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]),mt=P("chevron-right",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]),Lr=P("circle-alert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]),zd=P("circle-check-big",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]),Qd=P("circle-check",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]),Ud=P("circle-dot",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]]),Hd=P("circle-pause",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"10",x2:"10",y1:"15",y2:"9",key:"c1nkhi"}],["line",{x1:"14",x2:"14",y1:"15",y2:"9",key:"h65svq"}]]),Vd=P("circle-plus",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M12 8v8",key:"napkw2"}]]),Vo=P("circle-question-mark",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]),Wd=P("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]),qd=P("copy-plus",[["line",{x1:"15",x2:"15",y1:"12",y2:"18",key:"1p7wdc"}],["line",{x1:"12",x2:"18",y1:"15",y2:"15",key:"1nscbv"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]),pt=P("copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]),Kd=P("cpu",[["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M17 20v2",key:"1rnc9c"}],["path",{d:"M17 2v2",key:"11trls"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M2 17h2",key:"7oei6x"}],["path",{d:"M2 7h2",key:"asdhe0"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"M20 17h2",key:"1fpfkl"}],["path",{d:"M20 7h2",key:"1o8tra"}],["path",{d:"M7 20v2",key:"4gnj0m"}],["path",{d:"M7 2v2",key:"1i4yhu"}],["rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",key:"1vbyd7"}],["rect",{x:"8",y:"8",width:"8",height:"8",rx:"1",key:"z9xiuo"}]]),Wo=P("crosshair",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"22",x2:"18",y1:"12",y2:"12",key:"l9bcsi"}],["line",{x1:"6",x2:"2",y1:"12",y2:"12",key:"13hhkx"}],["line",{x1:"12",x2:"12",y1:"6",y2:"2",key:"10w3f3"}],["line",{x1:"12",x2:"12",y1:"22",y2:"18",key:"15g9kq"}]]),Zd=P("database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]),qo=P("door-open",[["path",{d:"M11 20H2",key:"nlcfvz"}],["path",{d:"M11 4.562v16.157a1 1 0 0 0 1.242.97L19 20V5.562a2 2 0 0 0-1.515-1.94l-4-1A2 2 0 0 0 11 4.561z",key:"au4z13"}],["path",{d:"M11 4H8a2 2 0 0 0-2 2v14",key:"74r1mk"}],["path",{d:"M14 12h.01",key:"1jfl7z"}],["path",{d:"M22 20h-3",key:"vhrsz"}]]),Rs=P("download",[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]]),Ko=P("ellipsis-vertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]),Zo=P("external-link",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]),Yo=P("eye-off",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),Or=P("eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]),Xo=P("funnel",[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]]),Yd=P("grip-horizontal",[["circle",{cx:"12",cy:"9",r:"1",key:"124mty"}],["circle",{cx:"19",cy:"9",r:"1",key:"1ruzo2"}],["circle",{cx:"5",cy:"9",r:"1",key:"1a8b28"}],["circle",{cx:"12",cy:"15",r:"1",key:"1e56xg"}],["circle",{cx:"19",cy:"15",r:"1",key:"1a92ep"}],["circle",{cx:"5",cy:"15",r:"1",key:"5r1jwy"}]]),Jo=P("house",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]]),Xd=P("image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]),Jd=P("inbox",[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]]),ef=P("info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]),tf=P("layout-grid",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]]),ea=P("lightbulb",[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]]),qe=P("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]),rf=P("locate-fixed",[["line",{x1:"2",x2:"5",y1:"12",y2:"12",key:"bvdh0s"}],["line",{x1:"19",x2:"22",y1:"12",y2:"12",key:"1tbv5k"}],["line",{x1:"12",x2:"12",y1:"2",y2:"5",key:"11lu5j"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}],["circle",{cx:"12",cy:"12",r:"7",key:"fim9np"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]),ta=P("maximize-2",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]]),sf=P("menu",[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]]),ra=P("mic",[["path",{d:"M12 19v3",key:"npa21l"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["rect",{x:"9",y:"2",width:"6",height:"13",rx:"3",key:"s6n7sd"}]]),sa=P("minimize-2",[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]]),na=P("minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]),Ds=P("moon",[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]]),nf=P("music",[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]]),Ts=P("network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]),Is=P("play",[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]]),_r=P("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]),of=P("plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]]),af=P("power-off",[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),oa=P("radar",[["path",{d:"M19.07 4.93A10 10 0 0 0 6.99 3.34",key:"z3du51"}],["path",{d:"M4 6h.01",key:"oypzma"}],["path",{d:"M2.29 9.62A10 10 0 1 0 21.31 8.35",key:"qzzz0"}],["path",{d:"M16.24 7.76A6 6 0 1 0 8.23 16.67",key:"1yjesh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M17.99 11.66A6 6 0 0 1 15.77 16.67",key:"1u2y91"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"m13.41 10.59 5.66-5.66",key:"mhq4k0"}]]),lf=P("radio",[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]),Ls=P("refresh-cw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]),aa=P("rotate-ccw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]),ia=P("rotate-cw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]),cf=P("save",[["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"}]]),uf=P("scan",[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}]]),df=P("scroll-text",[["path",{d:"M15 12h-5",key:"r7krc0"}],["path",{d:"M15 8h-5",key:"1khuty"}],["path",{d:"M19 17V5a2 2 0 0 0-2-2H4",key:"zz82l3"}],["path",{d:"M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3",key:"1ph1d7"}]]),nr=P("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),ff=P("server",[["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"}]]),mf=P("shield",[["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"}]]),pf=P("ship",[["path",{d:"M12 10.189V14",key:"1p8cqu"}],["path",{d:"M12 2v3",key:"qbqxhf"}],["path",{d:"M19 13V7a2 2 0 0 0-2-2H7a2 2 0 0 0-2 2v6",key:"qpkstq"}],["path",{d:"M19.38 20A11.6 11.6 0 0 0 21 14l-8.188-3.639a2 2 0 0 0-1.624 0L3 14a11.6 11.6 0 0 0 2.81 7.76",key:"7tigtc"}],["path",{d:"M2 21c.6.5 1.2 1 2.5 1 2.5 0 2.5-2 5-2 1.3 0 1.9.5 2.5 1s1.2 1 2.5 1c2.5 0 2.5-2 5-2 1.3 0 1.9.5 2.5 1",key:"1924j5"}]]),hf=P("sliders-horizontal",[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]]),la=P("square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]),gf=P("star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]),ca=P("sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]),bf=P("table-2",[["path",{d:"M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18",key:"gugj83"}]]),ua=P("target",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]),xf=P("thermometer",[["path",{d:"M14 4v10.54a4 4 0 1 1-4 0V4a2 2 0 0 1 4 0Z",key:"17jzev"}]]),vf=P("toggle-left",[["circle",{cx:"9",cy:"12",r:"3",key:"u3jwor"}],["rect",{width:"20",height:"14",x:"2",y:"5",rx:"7",key:"g7kal2"}]]),at=P("trash-2",[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]]),yf=P("trending-up",[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]]),wf=P("trending-down",[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]]),or=P("triangle-alert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]),da=P("upload",[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]),Sf=P("wifi-off",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),fa=P("wifi",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]]),Os=P("wrench",[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]]),Pe=P("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),ma=P("zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]),kf=P("zoom-in",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]),jf=P("zoom-out",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]),Nf={frigate:pf,scrypted:mf,reolink:lf,homeAssistant:Jo,rtsp:Bd},Cf={online:Qd,offline:Wd,degraded:Lr,unknown:Vo},pa=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,ha=Wt,kt=(e,t)=>s=>{var n;if(t?.variants==null)return ha(e,s?.class,s?.className);const{variants:o,defaultVariants:a}=t,i=Object.keys(o).map(u=>{const d=s?.[u],f=a?.[u];if(d===null)return null;const p=pa(d)||pa(f);return o[u][p]}),l=s&&Object.entries(s).reduce((u,d)=>{let[f,p]=d;return p===void 0||(u[f]=p),u},{});return ha(e,i,t==null||(n=t.compoundVariants)===null||n===void 0?void 0:n.reduce((u,d)=>{let{class:f,className:p,...g}=d;return Object.entries(g).every(b=>{let[x,v]=b;return Array.isArray(v)?v.includes({...a,...l}[x]):{...a,...l}[x]===v})?[...u,f,p]:u},[]),s?.class,s?.className)},Mf=kt("inline-flex items-center justify-center rounded-md font-medium transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none",{variants:{variant:{primary:"bg-primary text-primary-foreground hover:bg-primary/90",secondary:"bg-surface text-foreground hover:bg-surface-hover",ghost:"hover:bg-surface-hover text-foreground-muted",danger:"bg-danger text-white hover:bg-danger/90",outline:"border border-border bg-transparent hover:bg-surface-hover"},size:{sm:"h-7 px-2.5 text-xs gap-1.5",md:"h-8 px-3 text-sm gap-2",lg:"h-9 px-4 text-sm gap-2"}},defaultVariants:{variant:"primary",size:"sm"}}),ar=(0,h.forwardRef)(({className:e,variant:t,size:s,...n},o)=>(0,r.jsx)("button",{ref:o,className:j(Mf({variant:t,size:s}),e),...n}));ar.displayName="Button";var Ef=kt("inline-flex items-center justify-center rounded-md font-medium transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none",{variants:{variant:{primary:"bg-primary text-primary-foreground hover:bg-primary/90",secondary:"bg-surface text-foreground hover:bg-surface-hover",ghost:"hover:bg-surface-hover text-foreground-muted",danger:"bg-danger text-white hover:bg-danger/90",outline:"border border-border bg-transparent hover:bg-surface-hover"},size:{sm:"h-7 w-7",md:"h-8 w-8",lg:"h-9 w-9"}},defaultVariants:{variant:"primary",size:"sm"}}),_s=(0,h.forwardRef)(({className:e,variant:t,size:s,icon:n,...o},a)=>(0,r.jsx)("button",{ref:a,className:j(Ef({variant:t,size:s}),e),...o,children:(0,r.jsx)(n,{className:"h-4 w-4"})}));_s.displayName="IconButton";var Af=kt("inline-flex items-center rounded-full text-xs font-medium px-2 py-0.5",{variants:{variant:{default:"bg-surface-hover text-foreground",success:"bg-success/15 text-success",warning:"bg-warning/15 text-warning",danger:"bg-danger/15 text-danger",info:"bg-info/15 text-info"},styleVariant:{solid:"",outline:"border bg-transparent"}},defaultVariants:{variant:"default",styleVariant:"solid"}}),Gt=(0,h.forwardRef)(({className:e,variant:t,style:s,...n},o)=>(0,r.jsx)("span",{ref:o,className:j(Af({variant:t,styleVariant:s}),e),...n}));Gt.displayName="Badge";var Pf=kt("rounded-lg p-3",{variants:{variant:{flat:"bg-surface",bordered:"bg-surface border border-border"}},defaultVariants:{variant:"bordered"}}),$s=(0,h.forwardRef)(({className:e,variant:t,...s},n)=>(0,r.jsx)("div",{ref:n,className:j(Pf({variant:t}),e),...s}));$s.displayName="Card";function ga({expanded:e,onExpandedChange:t,header:s,children:n,dimmed:o=!1,hideChevron:a=!1,className:i}){return(0,r.jsxs)("div",{className:j("rounded-lg border border-border bg-surface overflow-hidden",o&&"opacity-[0.45]",i),children:[(0,r.jsxs)("div",{role:"button",tabIndex:0,className:"flex items-center gap-2.5 px-3 py-2.5 cursor-pointer select-none",onClick:()=>t(!e),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),t(!e))},children:[!a&&(0,r.jsx)("span",{className:"text-foreground-subtle shrink-0",children:e?(0,r.jsx)(St,{className:"h-4 w-4"}):(0,r.jsx)(mt,{className:"h-4 w-4"})}),s]}),e&&n&&(0,r.jsx)("div",{className:"border-t border-border px-3 py-3",children:n})]})}var Gs=(0,h.forwardRef)(({className:e,...t},s)=>(0,r.jsx)("label",{ref:s,className:j("text-[10px] uppercase tracking-wider text-foreground-muted font-medium",e),...t}));Gs.displayName="Label";var Rf=kt("",{variants:{orientation:{horizontal:"h-px w-full bg-border-subtle",vertical:"w-px h-full bg-border-subtle"}},defaultVariants:{orientation:"horizontal"}}),Bs=(0,h.forwardRef)(({className:e,orientation:t,...s},n)=>(0,r.jsx)("div",{ref:n,role:"separator",className:j(Rf({orientation:t}),e),...s}));Bs.displayName="Separator";var ba=(0,h.forwardRef)(({className:e,...t},s)=>(0,r.jsx)("div",{ref:s,className:j("animate-pulse bg-surface-hover rounded-md h-4 w-full",e),...t}));ba.displayName="Skeleton";var xa=kt("h-7 w-full px-2.5 text-xs bg-surface border rounded-md text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary transition-colors",{variants:{state:{default:"border-border",error:"border-danger"}},defaultVariants:{state:"default"}}),$r=(0,h.forwardRef)(({className:e,state:t,leftSlot:s,rightSlot:n,...o},a)=>s||n?(0,r.jsxs)("div",{className:"relative flex items-center w-full",children:[s&&(0,r.jsx)("div",{className:"absolute left-2.5 flex items-center pointer-events-none",children:s}),(0,r.jsx)("input",{ref:a,className:j(xa({state:t}),s?"pl-7":"",n?"pr-7":"",e),...o}),n&&(0,r.jsx)("div",{className:"absolute right-2.5 flex items-center pointer-events-none",children:n})]}):(0,r.jsx)("input",{ref:a,className:j(xa({state:t}),e),...o}));$r.displayName="Input";var Gr=(0,h.forwardRef)(({className:e,options:t,...s},n)=>(0,r.jsxs)("div",{className:"relative w-full",children:[(0,r.jsx)("select",{ref:n,className:j("h-7 w-full px-2.5 text-xs bg-surface border border-border rounded-md text-foreground appearance-none pr-7 focus:outline-none focus:ring-1 focus:ring-primary",e),...s,children:t.map(o=>(0,r.jsx)("option",{value:o.value,children:o.label},o.value))}),(0,r.jsx)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none text-foreground-muted",children:(0,r.jsx)(St,{className:"h-3.5 w-3.5"})})]}));Gr.displayName="Select";var va=(0,h.forwardRef)(({className:e,...t},s)=>(0,r.jsx)("input",{ref:s,type:"checkbox",className:j("w-3.5 h-3.5 rounded-sm border border-border accent-primary",e),...t}));va.displayName="Checkbox";var ya=(0,h.forwardRef)(({className:e,checked:t,onCheckedChange:s,label:n,...o},a)=>(0,r.jsxs)("button",{ref:a,role:"switch","aria-checked":t,type:"button",onClick:()=>s(!t),className:j("inline-flex items-center gap-2",e),...o,children:[(0,r.jsx)("span",{className:j("w-8 h-4 rounded-full transition-colors",t?"bg-primary":"bg-surface-hover"),children:(0,r.jsx)("span",{className:j("block w-3.5 h-3.5 rounded-full bg-white transition-transform",t?"translate-x-4":"translate-x-0.5")})}),n&&(0,r.jsx)("span",{className:"text-xs text-foreground",children:n})]}));ya.displayName="Switch";var wa=(0,h.createContext)(null);function Sa(){const e=(0,h.useContext)(wa);if(!e)throw new Error("Dialog compound components must be used within <Dialog>");return e}function ka({children:e,open:t,onOpenChange:s}){const[n,o]=(0,h.useState)(!1),a=t??n,i=(0,h.useId)(),l=(0,h.useCallback)(u=>{s?.(u),t===void 0&&o(u)},[t,s]);return(0,r.jsx)(wa.Provider,{value:{open:a,setOpen:l,contentId:i},children:e})}function Df({children:e,...t}){const{setOpen:s}=Sa();return(0,r.jsx)("button",{type:"button",onClick:()=>s(!0),...t,children:e})}var Tf=kt("bg-background-elevated border border-border rounded-lg p-4 backdrop:bg-black/50 backdrop:backdrop-blur-sm max-w-[calc(100vw-2rem)] max-h-[calc(100dvh-2rem)] overflow-y-auto",{variants:{width:{sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg"}},defaultVariants:{width:"md"}}),Fs=(0,h.forwardRef)(({className:e,width:t,children:s,...n},o)=>{const{open:a,setOpen:i,contentId:l}=Sa(),u=(0,h.useRef)(null),d=o??u;(0,h.useEffect)(()=>{const p=d.current;p&&(a&&!p.open&&p.showModal(),!a&&p.open&&p.close())},[a,d]);const f=p=>{p.target===p.currentTarget&&i(!1)};return(0,r.jsx)("dialog",{ref:d,id:l,className:j(Tf({width:t}),"w-full",e),onClick:f,onClose:()=>i(!1),...n,children:s})});Fs.displayName="DialogContent";function ja({className:e,...t}){return(0,r.jsx)("div",{className:j("flex flex-col gap-1 mb-3",e),...t})}function Na({className:e,...t}){return(0,r.jsx)("div",{className:j("flex justify-end gap-2 mt-4",e),...t})}function Ca({className:e,...t}){return(0,r.jsx)("h2",{className:j("text-sm font-semibold text-foreground",e),...t})}function Ma({className:e,...t}){return(0,r.jsx)("p",{className:j("text-xs text-foreground-muted",e),...t})}var Ea=(0,h.createContext)(null);function zs(){const e=(0,h.useContext)(Ea);if(!e)throw new Error("Dropdown compound components must be used within <Dropdown>");return e}function If({children:e}){const[t,s]=(0,h.useState)(!1),n=(0,h.useId)(),o=(0,h.useId)(),a=(0,h.useRef)(null);return(0,r.jsx)(Ea.Provider,{value:{open:t,setOpen:s,triggerId:n,contentId:o,triggerRef:a},children:(0,r.jsx)("div",{className:"relative inline-block",children:e})})}function Lf({children:e,...t}){const{open:s,setOpen:n,triggerId:o,contentId:a,triggerRef:i}=zs();return(0,r.jsx)("button",{type:"button",ref:i,id:o,"aria-haspopup":"menu","aria-expanded":s,"aria-controls":s?a:void 0,onClick:()=>n(!s),...t,children:e})}function Of({className:e,children:t,align:s="start",offset:n=4,...o}){const{open:a,setOpen:i,contentId:l,triggerId:u,triggerRef:d}=zs(),f=(0,h.useRef)(null),[p,g]=(0,h.useState)(null);return(0,h.useLayoutEffect)(()=>{if(!a){g(null);return}const b=()=>{const x=d.current;if(!x)return;const v=x.getBoundingClientRect(),w=s==="end"?v.right:v.left;g({top:v.bottom+n,left:w,minWidth:v.width})};return b(),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0),()=>{window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0)}},[a,s,n,d]),(0,h.useEffect)(()=>{if(!a)return;const b=v=>{const w=f.current,y=d.current;w&&!w.contains(v.target)&&!y?.contains(v.target)&&i(!1)},x=v=>{v.key==="Escape"&&i(!1)};return document.addEventListener("mousedown",b),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("keydown",x)}},[a,i,d]),!a||!p||typeof document>"u"?null:(0,Ze.createPortal)((0,r.jsx)("div",{ref:f,id:l,role:"menu","aria-labelledby":u,style:{position:"fixed",top:p.top,...s==="end"?{right:window.innerWidth-p.left}:{left:p.left},minWidth:p.minWidth},className:j("z-50 bg-background-elevated border border-border rounded-md shadow-lg py-1 min-w-[160px]",e),...o,children:t}),document.body)}function _f({className:e,icon:t,variant:s="default",children:n,onClick:o,...a}){const{setOpen:i}=zs(),l=(0,h.useCallback)(u=>{o?.(u),i(!1)},[o,i]);return(0,r.jsxs)("button",{type:"button",role:"menuitem",className:j("h-7 text-xs px-2 w-full text-left flex items-center gap-2",s==="danger"?"text-danger hover:bg-danger/10":"text-foreground hover:bg-surface-hover",e),onClick:l,...a,children:[t&&(0,r.jsx)(t,{size:14}),n]})}var Aa=(0,h.createContext)(null);function Pa(){const e=(0,h.useContext)(Aa);if(!e)throw new Error("Tooltip compound components must be used within <Tooltip>");return e}function $f({children:e}){const[t,s]=(0,h.useState)(!1),n=(0,h.useRef)(null),o=(0,h.useId)(),a=()=>{n.current=setTimeout(()=>s(!0),300)},i=()=>{n.current&&clearTimeout(n.current),s(!1)};return(0,r.jsx)(Aa.Provider,{value:{open:t,show:a,hide:i,tooltipId:o},children:(0,r.jsx)("div",{className:"relative inline-block",children:e})})}function Gf({children:e,...t}){const{show:s,hide:n,tooltipId:o,open:a}=Pa();return(0,r.jsx)("div",{onMouseEnter:s,onMouseLeave:n,onFocus:s,onBlur:n,"aria-describedby":a?o:void 0,...t,children:e})}function Bf({className:e,children:t,...s}){const{open:n,tooltipId:o}=Pa();return(0,r.jsx)("div",{id:o,role:"tooltip",className:j("absolute bottom-full left-1/2 -translate-x-1/2 mb-2 bg-foreground text-background text-xs px-2 py-1 rounded-md shadow-md whitespace-nowrap pointer-events-none transition-opacity duration-150",n?"opacity-100":"opacity-0",e),...s,children:t})}var Ra="(max-width: 767px)",Da="(min-width: 768px) and (max-width: 1023px)";function Ta(e){return t=>{const s=window.matchMedia(e);return s.addEventListener("change",t),()=>s.removeEventListener("change",t)}}function Ia(e){return()=>window.matchMedia(e).matches}function La(){return!1}function ir(){return(0,h.useSyncExternalStore)(Ta(Ra),Ia(Ra),La)}function Ff(){return(0,h.useSyncExternalStore)(Ta(Da),Ia(Da),La)}function Qs({open:e,onClose:t,title:s,children:n,className:o}){return(0,h.useEffect)(()=>{if(!e)return;const a=i=>{i.key==="Escape"&&t()};return document.addEventListener("keydown",a),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",a),document.body.style.overflow=""}},[e,t]),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:j("fixed inset-0 z-40 bg-black/50 transition-opacity duration-200",e?"opacity-100":"pointer-events-none opacity-0"),onClick:t,"aria-hidden":"true"}),(0,r.jsxs)("div",{role:"dialog","aria-modal":"true",className:j("fixed inset-x-0 bottom-0 z-50 flex flex-col bg-background-elevated border-t border-border rounded-t-xl shadow-2xl transition-transform duration-200 ease-out","max-h-[80dvh]",e?"translate-y-0":"translate-y-full",o),children:[(0,r.jsx)("div",{className:"flex justify-center pt-2 pb-1",children:(0,r.jsx)("div",{className:"h-1 w-8 rounded-full bg-foreground-subtle/30"})}),s&&(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 pb-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:s}),(0,r.jsx)("button",{onClick:t,className:"p-1 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors",children:(0,r.jsx)(Pe,{className:"h-4 w-4"})})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:n})]})]})}var Oa=(0,h.createContext)(null);function _a(){const e=(0,h.useContext)(Oa);if(!e)throw new Error("Popover compound components must be used within <Popover>");return e}function $a({children:e,open:t,onOpenChange:s}){const[n,o]=(0,h.useState)(!1),a=t??n,i=(0,h.useId)(),l=(0,h.useId)(),u=(0,h.useCallback)(d=>{s?.(d),t===void 0&&o(d)},[t,s]);return(0,r.jsx)(Oa.Provider,{value:{open:a,setOpen:u,triggerId:i,contentId:l},children:(0,r.jsx)("div",{className:"relative inline-block",children:e})})}function Ga({children:e,...t}){const{open:s,setOpen:n,triggerId:o,contentId:a}=_a();return(0,r.jsx)("button",{type:"button",id:o,"aria-haspopup":"dialog","aria-expanded":s,"aria-controls":s?a:void 0,onClick:()=>n(!s),...t,children:e})}function Ba({className:e,children:t,...s}){const{open:n,setOpen:o,contentId:a,triggerId:i}=_a(),l=ir(),u=(0,h.useRef)(null);return(0,h.useEffect)(()=>{if(!n||l)return;const d=p=>{const g=u.current,b=document.getElementById(i);g&&!g.contains(p.target)&&!b?.contains(p.target)&&o(!1)},f=p=>{p.key==="Escape"&&o(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",f)}},[n,o,i,l]),n?l?(0,r.jsx)(Qs,{open:n,onClose:()=>o(!1),children:t}):(0,r.jsx)("div",{ref:u,id:a,role:"dialog","aria-labelledby":i,className:j("absolute left-0 top-full z-50 mt-1 bg-background-elevated border border-border rounded-lg shadow-lg p-3",e),...s,children:t}):null}var Fa=(0,h.createContext)(null);function za(){const e=(0,h.useContext)(Fa);if(!e)throw new Error("Tabs compound components must be used within <Tabs>");return e}function zf({value:e,onValueChange:t,defaultValue:s="",className:n,...o}){const[a,i]=(0,h.useState)(s),l=e??a,u=(0,h.useCallback)(d=>{t?.(d),e===void 0&&i(d)},[e,t]);return(0,r.jsx)(Fa.Provider,{value:{value:l,setValue:u},children:(0,r.jsx)("div",{className:n,...o})})}function Qf({className:e,...t}){return(0,r.jsx)("div",{role:"tablist",className:j("flex flex-row border-b border-border-subtle",e),...t})}function Uf({value:e,className:t,...s}){const{value:n,setValue:o}=za(),a=e===n;return(0,r.jsx)("button",{type:"button",role:"tab","aria-selected":a,"aria-controls":`tabpanel-${e}`,tabIndex:a?0:-1,className:j("h-7 text-xs px-3 transition-colors",a?"border-b-2 border-primary text-foreground font-medium":"text-foreground-muted hover:text-foreground",t),onClick:()=>o(e),...s})}function Hf({value:e,className:t,...s}){const{value:n}=za();return e!==n?null:(0,r.jsx)("div",{role:"tabpanel",id:`tabpanel-${e}`,className:j("pt-3",t),...s})}var Us=(0,h.forwardRef)(({className:e,...t},s)=>(0,r.jsx)("div",{ref:s,className:j("overflow-auto [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-surface-hover [&::-webkit-scrollbar-thumb]:rounded-full",e),...t}));Us.displayName="ScrollArea";function Vf({title:e,onClose:t,children:s,defaultWidth:n=360,defaultHeight:o=280,minWidth:a=280,minHeight:i=160,offsetIndex:l=0,className:u}){const[d,f]=(0,h.useState)({x:80+l*30,y:80+l*30}),[p,g]=(0,h.useState)({w:n,h:o}),[b,x]=(0,h.useState)(!1),v=(0,h.useRef)(!1),w=(0,h.useRef)(!1),y=(0,h.useRef)({x:0,y:0}),S=ir(),k=(0,h.useCallback)(N=>{N.preventDefault(),v.current=!0,y.current={x:N.clientX-d.x,y:N.clientY-d.y}},[d]),C=(0,h.useCallback)(N=>{N.preventDefault(),N.stopPropagation(),w.current=!0,y.current={x:N.clientX,y:N.clientY}},[]);return(0,h.useEffect)(()=>{const N=R=>{if(v.current&&f({x:R.clientX-y.current.x,y:R.clientY-y.current.y}),w.current){const A=R.clientX-y.current.x,Q=R.clientY-y.current.y;y.current={x:R.clientX,y:R.clientY},g(ee=>({w:Math.max(a,ee.w+A),h:Math.max(i,ee.h+Q)}))}},E=()=>{v.current=!1,w.current=!1};return window.addEventListener("mousemove",N),window.addEventListener("mouseup",E),()=>{window.removeEventListener("mousemove",N),window.removeEventListener("mouseup",E)}},[a,i]),S?(0,r.jsxs)("div",{className:j("fixed inset-x-0 bottom-0 z-50 rounded-t-xl border-t border-border bg-background-elevated shadow-2xl flex flex-col overflow-hidden",u),style:{maxHeight:"60dvh"},children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b border-border shrink-0 bg-surface",children:[(0,r.jsx)("span",{className:"text-[11px] font-medium truncate",children:e}),(0,r.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,r.jsx)("button",{onClick:()=>x(!b),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",children:b?(0,r.jsx)(ta,{size:12}):(0,r.jsx)(sa,{size:12})}),(0,r.jsx)("button",{onClick:t,className:"p-0.5 rounded hover:bg-danger/20 text-foreground-muted hover:text-danger transition-colors",children:(0,r.jsx)(Pe,{size:12})})]})]}),!b&&(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:s})]}):(0,r.jsxs)("div",{className:j("fixed z-50 rounded-lg border border-border bg-background-elevated shadow-2xl flex flex-col overflow-hidden",u),style:{left:d.x,top:d.y,width:b?280:p.w,height:b?"auto":p.h},children:[(0,r.jsxs)("div",{onMouseDown:k,className:"flex items-center justify-between gap-2 px-3 py-2 border-b border-border cursor-move select-none shrink-0 bg-surface",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,r.jsx)(Yd,{size:12,className:"text-foreground-subtle shrink-0"}),(0,r.jsx)("span",{className:"text-[11px] font-medium truncate",children:e})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,r.jsx)("button",{onClick:()=>x(!b),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",title:b?"Restore":"Minimize",children:b?(0,r.jsx)(ta,{size:12}):(0,r.jsx)(sa,{size:12})}),(0,r.jsx)("button",{onClick:t,className:"p-0.5 rounded hover:bg-danger/20 text-foreground-muted hover:text-danger transition-colors",title:"Close",children:(0,r.jsx)(Pe,{size:12})})]})]}),!b&&(0,r.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto relative",children:[s,(0,r.jsx)("div",{onMouseDown:C,className:"absolute bottom-0 right-0 w-4 h-4 cursor-nwse-resize",style:{background:"linear-gradient(135deg, transparent 50%, var(--color-foreground-subtle) 50%)",opacity:.4}})]})]})}function Qa({open:e,onClose:t,children:s,className:n,width:o="w-64"}){const a=(0,h.useRef)(null);return(0,h.useEffect)(()=>{if(!e)return;const i=l=>{l.key==="Escape"&&t()};return document.addEventListener("keydown",i),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",i),document.body.style.overflow=""}},[e,t]),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:j("fixed inset-0 z-40 bg-black/50 backdrop-blur-sm transition-opacity duration-200",e?"opacity-100":"pointer-events-none opacity-0"),onClick:t,"aria-hidden":"true"}),(0,r.jsx)("div",{ref:a,role:"dialog","aria-modal":"true",className:j("fixed inset-y-0 left-0 z-50 flex flex-col bg-surface border-r border-border shadow-2xl transition-transform duration-200 ease-out",o,e?"translate-x-0":"-translate-x-full",n),children:s})]})}function Wf({items:e,className:t}){return(0,r.jsx)("nav",{className:`flex items-center gap-1 text-[11px] text-foreground-subtle ${t??""}`,children:e.map((s,n)=>{const o=n===e.length-1,a=!o&&(s.onClick||s.href);return(0,r.jsxs)(h.default.Fragment,{children:[n>0&&(0,r.jsx)(mt,{className:"h-3 w-3 flex-shrink-0"}),a?s.onClick?(0,r.jsx)("button",{type:"button",onClick:s.onClick,className:"hover:text-foreground transition-colors",children:s.label}):(0,r.jsx)("a",{href:s.href,className:"hover:text-foreground transition-colors",children:s.label}):(0,r.jsx)("span",{className:o?"text-foreground font-medium":"",children:s.label})]},n)})})}var Ua={left:"text-left",right:"text-right",center:"text-center"};function qf({columns:e,rows:t,rowKey:s,onRowClick:n,minWidthPx:o=480,emptyMessage:a,className:i,bordered:l=!0,rowClassName:u}){return t.length===0&&a?(0,r.jsx)("div",{className:`rounded-lg ${l?"border border-border":""} bg-surface px-3 py-4 text-xs text-foreground-subtle text-center ${i??""}`,children:a}):t.length===0?null:(0,r.jsx)("div",{className:`rounded-lg ${l?"border border-border":""} bg-surface overflow-x-auto ${i??""}`,children:(0,r.jsxs)("table",{className:"w-full text-xs",style:{minWidth:`${o}px`},children:[(0,r.jsx)("thead",{className:"bg-surface",children:(0,r.jsx)("tr",{children:e.map(d=>{const f=d.align??"left",p=d.nowrap??!0;return(0,r.jsx)("th",{className:["px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border",Ua[f],p?"whitespace-nowrap":"",d.width??""].filter(Boolean).join(" "),children:d.headerRender?d.headerRender():d.header},d.key)})})}),(0,r.jsx)("tbody",{children:t.map((d,f)=>{const p=s?s(d,f):f,g=u?.(d,f)??"",b=n!==void 0;return(0,r.jsx)("tr",{onClick:b?()=>n(d,f):void 0,className:[b?"cursor-pointer hover:bg-primary/5":"hover:bg-primary/5",g].filter(Boolean).join(" "),children:e.map(x=>{const v=x.align??"left",w=x.nowrap??!1;return(0,r.jsx)("td",{className:["px-3 py-2 text-foreground border-b border-border",Ua[v],w?"whitespace-nowrap":""].filter(Boolean).join(" "),children:x.render(d,f)},x.key)})},p)})})]})})}function Kf({open:e,onClose:t,title:s,subtitle:n,footer:o,children:a,widthClass:i="w-[360px]"}){return(0,h.useEffect)(()=>{if(!e)return;const l=u=>{u.key==="Escape"&&t()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e,t]),e?(0,r.jsxs)("aside",{className:j("absolute top-0 right-0 bottom-0 z-20 flex flex-col","bg-surface border-l border-border shadow-xl",i),role:"dialog","aria-modal":"false",children:[(0,r.jsxs)("header",{className:"flex items-start justify-between gap-2 px-4 py-3 border-b border-border",children:[(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("div",{className:"text-sm font-semibold text-foreground truncate",children:s}),n!==void 0&&(0,r.jsx)("div",{className:"text-[11px] text-foreground-subtle mt-0.5 truncate",children:n})]}),(0,r.jsx)("button",{type:"button",onClick:t,className:"p-1 rounded hover:bg-muted text-foreground-subtle hover:text-foreground","aria-label":"Close panel",children:(0,r.jsx)(Pe,{className:"w-4 h-4"})})]}),(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3",children:a}),o!==void 0&&(0,r.jsx)("footer",{className:"flex items-center gap-2 justify-end px-4 py-3 border-t border-border",children:o})]}):null}var Zf={inherit:"bg-muted",on:"bg-emerald-500",off:"bg-orange-500",na:"bg-gray-300 opacity-50"};function Ha({node:e,depth:t,selectedAddonId:s,onSelect:n,agentDots:o}){const a=e.addonId===s,i=o?.[e.addonId]??[];return(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{type:"button",onClick:()=>n(e.addonId),className:j("w-full flex items-center justify-between gap-2 text-left px-3 py-1.5 text-xs","border-l-2",a?"bg-accent border-primary text-foreground font-medium":"border-transparent hover:bg-muted/40 text-foreground"),style:{paddingLeft:`${12+t*14}px`},children:[(0,r.jsx)("span",{className:"truncate",children:e.addonName}),i.length>0&&(0,r.jsx)("span",{className:"flex items-center gap-1 shrink-0",children:i.map(l=>(0,r.jsx)("span",{title:`${l.agentNodeId}: ${l.state}`,className:j("w-2 h-2 rounded-full",Zf[l.state])},l.agentNodeId))})]}),e.children.map(l=>(0,r.jsx)(Ha,{node:l,depth:t+1,selectedAddonId:s,onSelect:n,agentDots:o},l.addonId))]})}function Yf({tree:e,selectedAddonId:t,onSelect:s,agentDots:n,className:o}){return(0,r.jsx)("div",{className:j("flex flex-col py-2",o),children:e.map(a=>(0,r.jsx)(Ha,{node:a,depth:0,selectedAddonId:t,onSelect:s,agentDots:n},a.addonId))})}function Xf(e){const t=[],s=[],n=new Map;for(const a of e.slots)for(const i of a.addons){const l={addonId:i.id,addonName:i.name,slot:i.slot,inputClasses:i.inputClasses,outputClasses:i.outputClasses,children:[]};i.slot==="audio-classifier"?t.push(l):(s.push(l),n.set(i.id,l))}const o=[];for(const a of s){if(a.inputClasses.length===0){o.push(a);continue}const i=s.find(l=>l.addonId!==a.addonId&&l.outputClasses.some(u=>a.inputClasses.includes(u)));i&&i.children.push(a)}return[...o,...t]}function Jf(e){return e?e.models.map(t=>({id:t.id,name:t.name})):[]}function Br({step:e,schema:t,allSchemas:s,depth:n=0,onChange:o,onDelete:a,readOnly:i=!1,toggleMode:l="simple",overrideState:u=null,onOverrideChange:d,inheritedEnabled:f,hideModelAndSettings:p=!1}){const[g,b]=(0,h.useState)(!1),x=Jf(t);if(x.length>0&&!x.some(w=>w.id===e.modelId)&&!i){const w=(t?.defaultModelId?x.find(y=>y.id===t.defaultModelId):null)??x[0];w&&w.id!==e.modelId&&queueMicrotask(()=>o({...e,modelId:w.id}))}const v=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("span",{className:"text-[10px] uppercase tracking-wider font-medium text-foreground-subtle/60 block leading-none",children:e.slot}),(0,r.jsx)("span",{className:"text-sm font-semibold text-foreground truncate block leading-tight",children:e.addonName}),(0,r.jsxs)("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(w=>(0,r.jsx)("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-blue-500/12 text-blue-400",children:w},w)),e.inputClasses.length>0&&e.outputClasses.length>0&&(0,r.jsx)("span",{className:"text-foreground-subtle/40 text-[10px]",children:"→"}),e.outputClasses.map(w=>(0,r.jsx)("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-green-500/12 text-green-400",children:w},w))]})]}),!i&&l==="simple"&&(0,r.jsx)("button",{onClick:w=>{w.stopPropagation(),o({...e,enabled:!e.enabled})},className:j("relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors",e.enabled?"bg-success":"bg-foreground-subtle/30"),children:(0,r.jsx)("span",{className:j("inline-block h-4 w-4 rounded-full bg-white shadow transition-transform",e.enabled?"translate-x-6":"translate-x-1")})}),!i&&l==="threeState"&&d&&(0,r.jsxs)("div",{className:"flex items-center gap-0.5 rounded-md border border-border p-0.5",onClick:w=>w.stopPropagation(),children:[(0,r.jsx)(Vs,{label:"Inherit",active:u===null,variant:"inherit",subtext:f===void 0?void 0:f?"on":"off",onClick:()=>d(null)}),(0,r.jsx)(Vs,{label:"On",active:u===!0,variant:"on",onClick:()=>d(!0)}),(0,r.jsx)(Vs,{label:"Off",active:u===!1,variant:"off",onClick:()=>d(!1)})]})]});return(0,r.jsx)(ga,{expanded:g,onExpandedChange:b,dimmed:!e.enabled,header:v,children:p?(0,r.jsx)("p",{className:"text-[11px] text-foreground-subtle",children:"Model and detection settings are managed per agent — open the Pipeline page for this camera's agent to edit them."}):(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)(Hs,{label:"Model",value:e.modelId,disabled:i,options:x.map(w=>({value:w.id,label:w.name})),onChange:w=>o({...e,modelId:w})}),e.slot==="audio-classifier"&&e.engine&&(0,r.jsx)(Hs,{label:"Runtime",value:`${e.engine.runtime}/${e.engine.backend}`,disabled:i,options:[{value:"node/cpu",label:"Node.js — ONNX CPU"},{value:"node/coreml",label:"Node.js — Apple SoundAnalysis (macOS)"},{value:"python/cpu",label:"Python — ONNX CPU"}],onChange:w=>{const[y,S]=w.split("/");o({...e,engine:{runtime:y,backend:S,format:S==="coreml"?"coreml":"onnx"}})}}),t?.configSchema?.map(w=>(0,r.jsx)(Fr,{field:w,allFields:t.configSchema??[],step:e,disabled:i,onChange:o},w.key))]})})}function Hs({label:e,value:t,options:s,disabled:n,onChange:o}){return(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e}),(0,r.jsxs)("select",{value:t,onChange:a=>o(a.target.value),disabled:n,className:"w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground focus:outline-none focus:border-primary/50",children:[s.length===0&&(0,r.jsx)("option",{value:t,children:t||"default"}),s.map(a=>(0,r.jsx)("option",{value:a.value,disabled:a.disabled,children:a.label},a.value))]})]})}function em({label:e,description:t,value:s,options:n,disabled:o,onChange:a}){function i(l){o||a(s.includes(l)?s.filter(u=>u!==l):[...s,l])}return(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1",children:e}),t&&(0,r.jsx)("p",{className:"text-[10px] text-foreground-subtle/60 mb-1.5",children:t}),(0,r.jsx)("div",{className:"flex flex-wrap gap-1.5",children:n.map(l=>(0,r.jsx)("button",{type:"button",disabled:o,onClick:()=>i(l.value),className:j("text-[10px] font-medium px-2 py-1 rounded-md border transition-colors",s.includes(l.value)?"bg-primary/20 text-primary border-primary/40":"bg-surface text-foreground-subtle border-border hover:border-primary/30",o&&"opacity-50 cursor-not-allowed"),children:l.label},l.value))})]})}function tm(e,t,s){const n=t.settings?.[e];if(n!==void 0)return n;const o=s.find(a=>"key"in a&&a.key===e);return o&&"default"in o?o.default:void 0}function Fr({field:e,allFields:t,step:s,disabled:n,onChange:o}){const a=e.type!=="separator"&&e.type!=="info"?e.showWhen:void 0;if(a){const{field:l,equals:u,notEquals:d,in:f,notIn:p}=a,g=tm(l,s,t);if(u!==void 0&&g!==u||d!==void 0&&g===d||f!==void 0&&!f.includes(g)||p!==void 0&&p.includes(g))return null}function i(l){o({...s,settings:{...s.settings,[e.key]:l}})}if(e.type==="select"){const l=s.settings?.[e.key],u=typeof l=="string"?l:e.default??"";return(0,r.jsx)(Hs,{label:e.label,value:u,disabled:n||e.disabled,options:e.options,onChange:i})}if(e.type==="multiselect"){const l=s.settings?.[e.key],u=Array.isArray(l)?l:Array.isArray(e.default)?e.default:[];return(0,r.jsx)(em,{label:e.label,description:e.description,value:u,options:e.options,disabled:n||e.disabled,onChange:i})}if(e.type==="slider"||e.type==="number"){const l=s.settings?.[e.key],u=typeof e.default=="number"?e.default:e.min??0,d=typeof l=="number"?l:u,f=e.min??0,p=e.max??1,g=e.step??.01,b=e.type==="slider"?e.showValue:!0,x="unit"in e?e.unit:void 0,v=e.type==="slider"?e.displayScale:void 0,w=v?d/v:d;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,r.jsx)("span",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide",children:e.label}),b&&(0,r.jsxs)("span",{className:"text-xs font-medium text-foreground tabular-nums",children:[typeof w=="number"?w.toFixed(2).replace(/\.?0+$/,""):w,x?` ${x}`:""]})]}),e.description&&(0,r.jsx)("p",{className:"text-[10px] text-foreground-subtle/60 mb-1.5",children:e.description}),(0,r.jsx)("input",{type:"range",min:f,max:p,step:g,value:d,disabled:n||e.disabled,onChange:y=>i(Number(y.target.value)),className:"w-full accent-primary h-1.5"})]})}if(e.type==="boolean"){const l=s.settings?.[e.key];return(0,r.jsxs)("label",{className:"flex items-center gap-2",children:[(0,r.jsx)("input",{type:"checkbox",checked:typeof l=="boolean"?l:e.default===!0,disabled:n||e.disabled,onChange:u=>i(u.target.checked),className:"h-3.5 w-3.5 accent-primary"}),(0,r.jsx)("span",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide",children:e.label})]})}if(e.type==="text"||e.type==="password"||e.type==="textarea"){const l=s.settings?.[e.key],u=typeof l=="string"?l:e.default??"",d=e.type==="password"?"password":"text";return(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e.label}),e.type==="textarea"?(0,r.jsx)("textarea",{value:u,disabled:n||e.disabled,placeholder:e.placeholder,onChange:f=>i(f.target.value),rows:3,className:"w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground focus:outline-none focus:border-primary/50 resize-y"}):(0,r.jsx)("input",{type:d,value:u,disabled:n||e.disabled,placeholder:e.placeholder,onChange:f=>i(f.target.value),className:"w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground focus:outline-none focus:border-primary/50"})]})}return e.type==="separator"?(0,r.jsx)("div",{className:"border-t border-border my-2"}):e.type==="info"?(0,r.jsx)("div",{className:"rounded-md border border-border bg-surface px-2 py-1.5 text-[10px] text-foreground-subtle",children:e.content}):null}function Vs({label:e,active:t,variant:s,subtext:n,onClick:o}){return(0,r.jsxs)("button",{type:"button",onClick:o,className:j("px-2 py-1 text-[10px] font-medium rounded transition-colors",t?s==="on"?"bg-green-500/20 text-green-400":s==="off"?"bg-red-500/20 text-red-400":"bg-primary/20 text-primary":"text-foreground-subtle hover:bg-surface-hover"),children:[e,n&&t&&(0,r.jsxs)("span",{className:"ml-1 opacity-60",children:["(",n,")"]})]})}function Va(e,t){return{addonId:e.id,addonName:e.name,slot:e.slot,inputClasses:[...e.inputClasses],outputClasses:[...e.outputClasses],enabled:t.enabled,modelId:t.modelId,children:[],settings:{...t.settings}}}function rm(e,t,s){return s?{enabled:s.enabled??t.enabled,modelId:s.modelId??t.modelId,settings:s.settings??t.settings}:t}function sm({addon:e,agentDefault:t,modelsForFormat:s,onChangeAgentConfig:n}){const o=a=>{n?.({...t,...a})};return(0,r.jsxs)("div",{className:"space-y-4 text-xs",children:[(0,r.jsxs)("label",{className:"flex items-center gap-2",children:[(0,r.jsx)("input",{type:"checkbox",checked:t.enabled,onChange:a=>o({enabled:a.target.checked})}),(0,r.jsxs)("span",{children:["Enabled on this agent (",e.name,")"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle mb-1",children:"Model"}),(0,r.jsx)("select",{className:"w-full bg-surface border border-border rounded px-2 py-1 text-xs",value:t.modelId,onChange:a=>o({modelId:a.target.value}),children:s.map(a=>(0,r.jsx)("option",{value:a.id,children:a.name},a.id))})]}),(e.configSchema?.length??0)>0&&(0,r.jsxs)("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[(0,r.jsx)("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),e.configSchema?.map(a=>(0,r.jsx)(Fr,{field:a,allFields:e.configSchema??[],step:Va(e,t),disabled:!1,onChange:i=>o({settings:{...i.settings}})},a.key))]})]})}function nm({addon:e,agentDefault:t,agentNodeId:s,currentPatch:n,modelsForFormat:o,onChangePatch:a}){const i=rm("device",t,n),l=b=>{const x=b.enabled!==void 0||b.modelId!==void 0||b.settings!==void 0;a?.(x?b:null)},u=b=>{const{enabled:x,...v}=n??{};l(b==="inherit"?v:{...v,enabled:b==="on"})},d=b=>{const{modelId:x,...v}=n??{};l(b===void 0?v:{...v,modelId:b})},f=b=>{const{settings:x,...v}=n??{};l(b===void 0?v:{...v,settings:b})},p=n?.enabled===void 0?"inherit":n.enabled?"on":"off",g=n?.modelId!==void 0;return(0,r.jsxs)("div",{className:"space-y-4 text-xs",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[["inherit","on","off"].map(b=>(0,r.jsx)("button",{type:"button",onClick:()=>u(b),className:j("px-3 py-1 border border-border rounded text-xs capitalize",p===b?"bg-primary text-primary-foreground border-primary":"bg-surface text-foreground hover:bg-muted"),children:b},b)),(0,r.jsxs)("span",{className:"ml-2 text-[10px] text-foreground-subtle",children:["agent default: ",(0,r.jsx)("span",{className:"font-semibold",children:t.enabled?"on":"off"})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,r.jsx)("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Model"}),g?(0,r.jsx)("button",{type:"button",className:"text-[10px] text-foreground-subtle hover:text-foreground",onClick:()=>d(void 0),children:"Clear"}):(0,r.jsx)("button",{type:"button",className:"text-[10px] text-primary hover:underline",onClick:()=>d(t.modelId),children:"Override"})]}),(0,r.jsx)("select",{disabled:!g,className:"w-full bg-surface border border-border rounded px-2 py-1 text-xs disabled:opacity-50",value:g?n?.modelId??t.modelId:t.modelId,onChange:b=>d(b.target.value),children:o.map(b=>(0,r.jsx)("option",{value:b.id,children:b.name},b.id))}),!g&&(0,r.jsxs)("div",{className:"text-[10px] text-foreground-subtle mt-1",children:["inherits from ",s]})]}),(e.configSchema?.length??0)>0&&(()=>{const b=n?.settings!==void 0;return(0,r.jsxs)("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),b?(0,r.jsx)("button",{type:"button",className:"text-[10px] text-foreground-subtle hover:text-foreground",onClick:()=>f(void 0),children:"Clear"}):(0,r.jsx)("button",{type:"button",className:"text-[10px] text-primary hover:underline",onClick:()=>f({...t.settings}),children:"Override"})]}),e.configSchema?.map(x=>(0,r.jsx)(Fr,{field:x,allFields:e.configSchema??[],step:Va(e,i),disabled:!b,onChange:v=>f({...v.settings})},x.key)),!b&&(0,r.jsxs)("div",{className:"text-[10px] text-foreground-subtle",children:["inherits from ",s]})]})})(),(0,r.jsxs)("div",{className:"rounded bg-muted/40 px-3 py-2 text-[11px] text-foreground-subtle",children:[(0,r.jsx)("div",{className:"font-semibold text-foreground mb-0.5",children:"Effective config preview"}),(0,r.jsxs)("div",{className:"font-mono truncate",children:[e.id," · model: ",i.modelId," · ",i.enabled?"on":"off"]})]})]})}function om(e){const{mode:t,addon:s,agentDefault:n,agentNodeId:o,currentPatch:a,onChangeAgentConfig:i,onChangePatch:l,engineFormat:u}=e,d=(0,h.useMemo)(()=>s.models.filter(f=>!!f.formats[u]),[s.models,u]);return t==="agent"?(0,r.jsx)(sm,{addon:s,agentDefault:n,modelsForFormat:d,onChangeAgentConfig:i}):(0,r.jsx)(nm,{addon:s,agentDefault:n,agentNodeId:o,currentPatch:a,modelsForFormat:d,onChangePatch:l})}function am(e){const t=[],s=(n,o)=>{for(const a of n)t.push({node:a,depth:o}),s(a.children,o+1)};return s(e,0),t}var Wa={detector:{label:"detector",className:"text-emerald-500"},cropper:{label:"cropper",className:"text-blue-500"},classifier:{label:"classifier",className:"text-violet-500"},refiner:{label:"refiner",className:"text-amber-500"},"audio-classifier":{label:"audio classifier",className:"text-pink-500"}};function im({slot:e}){const t=Wa[e]??Wa.classifier;return(0,r.jsx)("span",{className:j("text-[9px] font-semibold uppercase tracking-widest leading-none",t.className),children:t.label})}var qa="inline-flex items-center rounded bg-muted px-1.5 py-px text-[9px] font-medium text-foreground-subtle";function lm({inputs:e,outputs:t}){return e.length===0&&t.length===0?null:(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 flex-wrap",children:[e.map(s=>(0,r.jsx)("span",{className:j(qa,"bg-blue-500/10 text-blue-500"),children:s},`in-${s}`)),e.length>0&&t.length>0&&(0,r.jsx)("span",{className:"text-foreground-subtle/60 text-[9px]",children:"→"}),t.map(s=>(0,r.jsx)("span",{className:j(qa,"bg-emerald-500/10 text-emerald-500"),children:s},`out-${s}`))]})}function cm({enabled:e,onChange:t,disabled:s}){return(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":e,disabled:s,onClick:n=>{n.stopPropagation(),t(!e)},className:j("relative inline-flex h-3.5 w-7 shrink-0 items-center rounded-full transition-colors",e?"bg-emerald-500":"bg-foreground-subtle/30",s?"opacity-50 cursor-not-allowed":"cursor-pointer"),title:e?"Click to disable":"Click to enable",children:(0,r.jsx)("span",{className:j("inline-block h-3 w-3 rounded-full bg-white shadow transition-transform",e?"translate-x-3.5":"translate-x-0.5")})})}function um(e){return e.kind==="enabled"?(0,r.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,r.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500 shrink-0"}),(0,r.jsx)("span",{className:"font-mono text-foreground",children:e.modelId})]}):e.kind==="disabled"?(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 text-foreground-subtle",children:[(0,r.jsx)("span",{className:"h-1.5 w-1.5 rounded-full border border-foreground-subtle/60 shrink-0"}),"off"]}):(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 text-foreground-subtle/70",children:[(0,r.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-muted shrink-0"}),"n/a"]})}function dm({node:e,depth:t,agents:s,getCellState:n,onCellClick:o,selectedCell:a,toggleProps:i}){return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"sticky left-0 z-10 bg-surface px-3 py-2 border-b border-border text-xs flex items-start gap-2",style:{paddingLeft:`${12+t*14}px`},children:[(0,r.jsxs)("div",{className:"flex flex-col gap-1 min-w-0 flex-1",children:[(0,r.jsx)(im,{slot:e.slot}),(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,r.jsx)("span",{className:"font-semibold truncate",children:e.addonName}),(0,r.jsx)(lm,{inputs:e.inputClasses,outputs:e.outputClasses})]})]}),i&&(0,r.jsx)("span",{className:"pl-2 pt-0.5 shrink-0",children:(0,r.jsx)(cm,{enabled:i.enabled,onChange:i.onChange,disabled:i.disabled})})]}),s.map(l=>{const u=n(e.addonId,l.agentNodeId),d=a?.addonId===e.addonId&&a.agentNodeId===l.agentNodeId;return(0,r.jsx)("button",{type:"button",onClick:()=>o(e.addonId,l.agentNodeId),className:j("text-left px-3 py-1.5 border-b border-l border-border text-xs hover:bg-muted/40",u.kind==="enabled"&&"bg-emerald-500/5",u.kind==="na"&&"bg-muted/30",d&&"ring-2 ring-primary ring-inset"),children:um(u)},l.agentNodeId)})]})}function fm({tree:e,agents:t,getCellState:s,onCellClick:n,selectedCell:o,onToggleEnabled:a}){const i=(0,h.useMemo)(()=>am(e),[e]),l=`minmax(320px, 1fr) repeat(${t.length}, minmax(160px, 220px))`,u=a!==void 0&&t.length===1,d=t[0]?.agentNodeId;return(0,r.jsx)("div",{className:"overflow-auto border border-border rounded",children:(0,r.jsxs)("div",{className:"grid",style:{gridTemplateColumns:l},children:[(0,r.jsx)("div",{className:"sticky top-0 left-0 z-20 bg-muted/60 px-3 py-2 text-[10px] uppercase tracking-widest text-foreground-subtle border-b border-border",children:"Step"}),t.map(f=>(0,r.jsxs)("div",{className:"sticky top-0 z-10 bg-muted/60 px-3 py-2 border-b border-l border-border",children:[(0,r.jsx)("div",{className:"text-xs font-semibold text-foreground",children:f.agentNodeId}),(0,r.jsx)("div",{className:"text-[10px] text-foreground-subtle truncate",children:f.engineLabel})]},f.agentNodeId)),i.map(({node:f,depth:p})=>{const g=u&&d!==void 0?s(f.addonId,d):null;return(0,r.jsx)(dm,{node:f,depth:p,agents:t,getCellState:s,onCellClick:n,selectedCell:o,toggleProps:u&&g!==null?{enabled:g.kind==="enabled",onChange:b=>a?.(f.addonId,b),disabled:g.kind==="na"}:void 0},f.addonId)})]})})}var Ka=typeof globalThis<"u"?globalThis.__camstackTrpcReact:void 0,m=Ka??(0,st.createTRPCReact)();typeof globalThis<"u"&&!Ka&&(globalThis.__camstackTrpcReact=m);var Ws=ot("camstack:system",null);function Za({system:e,children:t}){return(0,r.jsx)(Ws.Provider,{value:e,children:t})}function jt(){const e=(0,h.useContext)(Ws);if(!e)throw new Error("useSystem(): no <SystemProvider> in tree");return e}function mm(){return(0,h.useContext)(Ws)}function lr(e,t){const s=jt(),n=(0,h.useRef)(t);n.current=t;const[o,a]=(0,h.useState)(s.connectionVersion);(0,h.useEffect)(()=>s.subscribeConnectionEvents((i,l)=>{i==="connected"&&a(l)}),[s]),(0,h.useEffect)(()=>s.subscribeEvent(e,i=>{n.current(i)}),[s,e,o])}function qs(e){const t=(0,h.useRef)(e);return t.current=e,t}function Ks(e,t){const[s,n]=(0,h.useState)(null),o=qs(t);return lr(e,a=>{const i=a.data,l=o.current;l&&!l(i)||n(i)}),s}function pm(e,t,s){const[n,o]=(0,h.useState)(()=>new Map),a=qs(t),i=qs(s);return lr(e,l=>{const u=l.data,d=i.current;if(d&&!d(u))return;const f=a.current(u);o(p=>{const g=new Map(p);return g.set(f,u),g})}),{map:n,values:(0,h.useMemo)(()=>Array.from(n.values()),[n])}}function zr(){const{data:e,isLoading:t}=m.nodes.topology.useQuery(void 0,{staleTime:6e4}),s=Ks("cluster.topology-snapshot")?.nodes??e;return{nodes:(0,h.useMemo)(()=>{const n=[];for(const o of s??[])n.push({id:String(o.id??""),name:String(o.name??o.id??""),shortName:o.isHub?"HUB":String(o.name??o.id??""),isHub:!!o.isHub,isOnline:!!o.isOnline,localIps:o.localIps??[],addons:(o.addons??[]).map(a=>({addonId:a.id,capabilities:a.capabilities}))});return n.sort((o,a)=>o.isHub!==a.isHub?o.isHub?-1:1:o.name.localeCompare(a.name)),n},[s]),isLoading:t}}function hm({selectedNodeId:e,onSelect:t,label:s="Node",hideIcon:n=!1,alwaysShow:o=!1}){const{nodes:a}=zr();return!o&&a.length<=1?null:(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[!n&&(0,r.jsx)(ff,{className:"h-3.5 w-3.5 text-foreground-subtle"}),s&&(0,r.jsx)("span",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:s}),(0,r.jsx)("div",{className:"flex rounded-md border border-border overflow-hidden text-[11px] font-medium",children:a.map((i,l)=>{const u=e===i.id;return(0,r.jsx)("button",{type:"button",onClick:()=>t(i.id),disabled:!i.isOnline,title:i.isOnline?i.name:`${i.name} (offline)`,className:j("px-2.5 py-1 transition-colors",u?"bg-primary/15 text-primary":"bg-transparent text-foreground-subtle hover:bg-surface-hover hover:text-foreground",l>0&&"border-l border-border",!i.isOnline&&"opacity-50 cursor-not-allowed"),children:i.shortName},i.id)})})]})}var gm={online:{colorClass:"bg-success",label:"Online"},offline:{colorClass:"bg-danger",label:"Offline"},degraded:{colorClass:"bg-warning",label:"Degraded"},unknown:{colorClass:"bg-foreground-subtle",label:"Unknown"}};function bm({status:e,showDot:t=!0,showLabel:s=!0,size:n="sm",className:o}){const a=gm[e];return(0,r.jsxs)("span",{className:j("inline-flex items-center gap-1.5",n==="sm"?"text-xs":"text-sm",o),children:[t&&(0,r.jsx)("span",{className:j("h-1.5 w-1.5 shrink-0 rounded-full",a.colorClass),"aria-hidden":"true"}),s&&(0,r.jsx)("span",{className:"text-foreground",children:a.label})]})}var xm={frigate:{colorClass:"bg-provider-frigate",label:"Frigate"},scrypted:{colorClass:"bg-provider-scrypted",label:"Scrypted"},reolink:{colorClass:"bg-provider-reolink",label:"Reolink"},homeAssistant:{colorClass:"bg-provider-homeAssistant",label:"Home Assistant"},rtsp:{colorClass:"bg-provider-rtsp",label:"RTSP"}};function vm({provider:e,showLabel:t=!0,className:s}){const n=xm[e];return(0,r.jsxs)("span",{className:j("inline-flex items-center gap-1.5 text-xs",s),children:[(0,r.jsx)("span",{className:j("h-1.5 w-1.5 shrink-0 rounded-sm",n.colorClass),"aria-hidden":"true"}),t&&(0,r.jsx)("span",{className:"text-foreground",children:n.label})]})}var ym={success:"bg-emerald-400 text-emerald-950",warning:"bg-amber-400 text-amber-950",danger:"bg-red-400 text-red-950",info:"bg-blue-400 text-blue-950",neutral:"bg-foreground-subtle/20 text-foreground"};function Ya({children:e,variant:t="neutral",mono:s,className:n}){return(0,r.jsx)("span",{className:j("inline-flex items-center rounded-md px-2 py-0.5 text-[11px] font-bold leading-tight",s&&"font-mono",ym[t],n),children:e})}function wm({version:e,preRelease:t,className:s}){return(0,r.jsx)(Ya,{variant:t??/-(alpha|beta|rc|dev|canary|next)/i.test(e)?"warning":"success",mono:!0,className:s,children:e})}function Sm({label:e,description:t,error:s,required:n,children:o,orientation:a="vertical",className:i}){const l=a==="horizontal";return(0,r.jsxs)("div",{className:j("flex gap-2",l?"flex-row items-center justify-between":"flex-col",i),children:[(0,r.jsxs)("div",{className:j(l?"flex-1":""),children:[(0,r.jsxs)(Gs,{children:[e,n&&(0,r.jsx)("span",{className:"text-danger ml-0.5",children:"*"})]}),t&&(0,r.jsx)("p",{className:"text-foreground-subtle text-xs mt-0.5",children:t})]}),(0,r.jsx)("div",{className:j(l?"shrink-0":""),children:o}),s&&(0,r.jsx)("p",{className:"text-danger text-xs",children:s})]})}function km({title:e,subtitle:t,actions:s,className:n}){return(0,r.jsxs)("div",{className:j("flex flex-col gap-2 mb-3 sm:flex-row sm:items-center sm:justify-between",n),children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h1",{className:"text-sm font-semibold text-foreground",children:e}),t&&(0,r.jsx)("p",{className:"text-foreground-subtle text-xs",children:t})]}),s&&(0,r.jsx)("div",{className:"flex items-center gap-2 flex-wrap",children:s})]})}function jm({icon:e,title:t,description:s,action:n,className:o}){return(0,r.jsxs)("div",{className:j("flex flex-col items-center justify-center gap-3 py-12",o),children:[e&&(0,r.jsx)(e,{className:"h-12 w-12 text-foreground-subtle","aria-hidden":"true"}),(0,r.jsxs)("div",{className:"flex flex-col items-center gap-1 text-center",children:[(0,r.jsx)("p",{className:"text-foreground-muted text-sm font-medium",children:t}),s&&(0,r.jsx)("p",{className:"text-foreground-subtle text-xs max-w-xs",children:s})]}),n&&(0,r.jsx)("div",{className:"mt-1",children:n})]})}var Xa=ot("camstack:confirm-dialog",null);function Qr(){const e=(0,h.useContext)(Xa);if(!e)throw new Error("useConfirm must be used within ConfirmDialogProvider");return e.confirm}function Nm({children:e}){const[t,s]=(0,h.useState)(null),n=(0,h.useCallback)(u=>new Promise(d=>{s({...u,resolve:d})}),[]),o=()=>{t?.resolve(!0),s(null)},a=()=>{t?.resolve(!1),s(null)},i={danger:{icon:"text-red-400",button:"bg-red-500 hover:bg-red-600 text-white"},warning:{icon:"text-orange-400",button:"bg-orange-500 hover:bg-orange-600 text-white"},default:{icon:"text-primary",button:"bg-primary hover:bg-primary/90 text-white"}},l=t?i[t.variant??"default"]:i.default;return(0,r.jsxs)(Xa.Provider,{value:{confirm:n},children:[e,t&&(0,r.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,r.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:a}),(0,r.jsxs)("div",{className:"relative z-10 w-full max-w-sm mx-4 rounded-xl border border-border bg-surface shadow-2xl overflow-hidden animate-in fade-in zoom-in-95 duration-150",onClick:u=>u.stopPropagation(),children:[(0,r.jsxs)("div",{className:"px-5 pt-5 pb-4",children:[(0,r.jsx)("h3",{className:"text-sm font-semibold text-foreground",children:t.title}),(0,r.jsx)("p",{className:"mt-2 text-xs text-foreground-subtle leading-relaxed",children:t.message})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border bg-surface-hover/30",children:[(0,r.jsx)("button",{type:"button",onClick:a,className:"px-3 py-1.5 text-xs font-medium rounded-md border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:t.cancelLabel??"Cancel"}),(0,r.jsx)("button",{type:"button",onClick:o,className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${l.button}`,children:t.confirmLabel??"Confirm"})]})]})]})]})}function Cm({value:e,label:t,trend:s,className:n}){return(0,r.jsxs)($s,{className:j("flex flex-col gap-1",n),children:[(0,r.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,r.jsx)("span",{className:"text-2xl font-semibold text-foreground",children:e}),s&&(0,r.jsxs)("span",{className:j("inline-flex items-center gap-0.5 text-xs font-medium",s.direction==="up"?"text-success":"text-danger"),children:[s.direction==="up"?(0,r.jsx)(yf,{className:"h-3 w-3"}):(0,r.jsx)(wf,{className:"h-3 w-3"}),s.value,"%"]})]}),(0,r.jsx)("span",{className:"text-xs text-foreground-muted",children:t})]})}function Mm({items:e,className:t}){return(0,r.jsx)("dl",{className:j("flex flex-col",t),children:e.map(s=>(0,r.jsxs)("div",{className:"flex items-center h-7",children:[(0,r.jsx)("dt",{className:"text-foreground-subtle text-xs w-1/3 shrink-0",children:s.key}),(0,r.jsx)("dd",{className:"text-foreground text-xs",children:s.value})]},s.key))})}function Em({children:e,maxHeight:t=300,className:s}){const[n,o]=(0,h.useState)(!1),a=(0,h.useCallback)(()=>{navigator.clipboard.writeText(e).then(()=>{o(!0),setTimeout(()=>o(!1),2e3)})},[e]);return(0,r.jsxs)("div",{className:j("relative group",s),children:[(0,r.jsx)(Us,{style:{maxHeight:t},children:(0,r.jsx)("pre",{className:"font-mono text-xs bg-surface p-3 rounded-md border border-border-subtle",children:(0,r.jsx)("code",{children:e})})}),(0,r.jsx)("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,r.jsx)(_s,{icon:n?sr:pt,"aria-label":"Copy code",variant:"ghost",size:"sm",onClick:a})})]})}function Am({filters:e,values:t,onChange:s,className:n}){const o=ir(),[a,i]=(0,h.useState)(!1),l=(d,f)=>{s({...t,[d]:f})},u=Object.values(t).filter(d=>d!==void 0&&d!=="").length;if(o){const d=e.find(p=>p.type==="search"),f=e.some(p=>p.type!=="search");return(0,r.jsxs)("div",{className:j("flex items-center gap-2",n),children:[d&&(0,r.jsx)($r,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:p=>l(d.key,p.target.value),leftSlot:(0,r.jsx)(nr,{className:"h-3 w-3 text-foreground-subtle"}),className:"flex-1"}),f&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-foreground-muted hover:bg-surface-hover transition-colors shrink-0",children:[(0,r.jsx)(hf,{className:"h-3.5 w-3.5"}),"Filters",u>0&&(0,r.jsx)(Gt,{variant:"info",className:"ml-1 text-[10px] px-1 py-0",children:u})]}),(0,r.jsx)(Qs,{open:a,onClose:()=>i(!1),title:"Filters",children:(0,r.jsx)("div",{className:"flex flex-col gap-3",children:e.filter(p=>p.type!=="search").map(p=>{switch(p.type){case"select":return(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"text-xs text-foreground-muted mb-1 block",children:p.label}),(0,r.jsx)(Gr,{options:p.options,value:t[p.key]??"",onChange:g=>l(p.key,g.target.value),className:"w-full"})]},p.key);case"badge-toggle":return(0,r.jsx)("div",{className:"flex items-center gap-1 flex-wrap",children:p.options.map(g=>{const b=t[p.key]===g.value;return(0,r.jsx)("button",{type:"button",onClick:()=>l(p.key,b?void 0:g.value),children:(0,r.jsx)(Gt,{variant:b?"info":"default",className:"cursor-pointer",children:g.label})},g.value)})},p.key);default:return null}})})})]})]})}return(0,r.jsx)("div",{className:j("flex items-center gap-2 flex-wrap",n),children:e.map(d=>{switch(d.type){case"search":return(0,r.jsx)($r,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:f=>l(d.key,f.target.value),leftSlot:(0,r.jsx)(nr,{className:"h-3 w-3 text-foreground-subtle"}),className:"w-48"},d.key);case"select":return(0,r.jsx)(Gr,{options:d.options,value:t[d.key]??"",onChange:f=>l(d.key,f.target.value),className:"w-36"},d.key);case"badge-toggle":return(0,r.jsx)("div",{className:"flex items-center gap-1",children:d.options.map(f=>{const p=t[d.key]===f.value;return(0,r.jsx)("button",{type:"button",onClick:()=>l(d.key,p?void 0:f.value),children:(0,r.jsx)(Gt,{variant:p?"info":"default",className:"cursor-pointer",children:f.label})},f.value)})},d.key);default:return null}})})}function Zs({label:e,icon:t,href:s,badge:n,active:o=!1,className:a}){return(0,r.jsxs)("a",{href:s,className:j("flex items-center gap-2 h-7 px-2 text-[11px] transition-colors",o?"border-l-2 border-primary bg-primary/[0.08] text-foreground rounded-r-md":"text-foreground-subtle hover:bg-surface-hover rounded-md",a),children:[(0,r.jsx)(t,{className:"h-3.5 w-3.5 shrink-0"}),(0,r.jsx)("span",{className:"truncate flex-1",children:e}),n!==void 0&&(0,r.jsx)(Gt,{className:"ml-auto text-[10px] px-1.5 py-0",children:n})]})}function Ys({logo:e,sections:t,footer:s,onNavigate:n,className:o}){return(0,r.jsxs)("nav",{className:j("bg-surface border-r border-border h-full flex flex-col",o),children:[e&&(0,r.jsx)("div",{className:"px-3 py-2 shrink-0",children:e}),(0,r.jsx)("div",{className:"flex-1 overflow-auto px-1 py-1",children:t.map((a,i)=>(0,r.jsxs)("div",{className:j(i>0?"mt-3":""),children:[a.label&&(0,r.jsx)("span",{className:"text-[10px] text-foreground-disabled uppercase tracking-wider px-2 mb-1 block",children:a.label}),(0,r.jsx)("div",{className:"flex flex-col gap-0.5",onClick:n,children:a.items.map(l=>(0,r.jsx)(Zs,{...l},l.href))})]},i))}),s&&s.length>0&&(0,r.jsxs)("div",{className:"shrink-0 px-1 pb-1",children:[(0,r.jsx)(Bs,{className:"mb-1"}),(0,r.jsx)("div",{className:"flex flex-col gap-0.5",onClick:n,children:s.map(a=>(0,r.jsx)(Zs,{...a},a.href))})]})]})}function Pm({sidebar:e,header:t,mobileLogo:s,mobileActions:n,children:o,className:a}){const i=ir(),[l,u]=(0,h.useState)(!1);return(0,r.jsxs)("div",{className:j("flex h-screen",a),children:[!i&&(0,r.jsx)(Ys,{...e,className:j("w-44",e.className)}),i&&(0,r.jsx)(Qa,{open:l,onClose:()=>u(!1),width:"w-64",children:(0,r.jsx)(Ys,{...e,onNavigate:()=>u(!1),className:"w-full border-r-0"})}),(0,r.jsxs)("div",{className:"flex flex-1 flex-col min-w-0",children:[i&&(0,r.jsxs)("header",{className:"flex items-center h-12 border-b border-border px-3 shrink-0 bg-surface/80 backdrop-blur-sm",children:[(0,r.jsx)("button",{onClick:()=>u(!0),className:"p-1.5 -ml-1.5 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors","aria-label":"Open menu",children:(0,r.jsx)(sf,{className:"h-5 w-5"})}),s&&(0,r.jsx)("div",{className:"flex-1 flex justify-center",children:s}),n&&(0,r.jsx)("div",{className:"shrink-0",children:n})]}),!i&&t&&(0,r.jsxs)("header",{className:"flex items-center h-10 border-b border-border px-4 shrink-0",children:[t.breadcrumbs&&t.breadcrumbs.length>0&&(0,r.jsx)("nav",{className:"flex items-center gap-1 text-xs flex-1 min-w-0",children:t.breadcrumbs.map((d,f)=>{const p=f===t.breadcrumbs.length-1;return(0,r.jsxs)("span",{className:"flex items-center gap-1",children:[f>0&&(0,r.jsx)(mt,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),d.href&&!p?(0,r.jsx)("a",{href:d.href,className:"text-foreground-subtle hover:text-foreground transition-colors truncate",children:d.label}):(0,r.jsx)("span",{className:"text-foreground truncate",children:d.label})]},f)})}),t.actions&&(0,r.jsx)("div",{className:"flex items-center gap-2 ml-auto shrink-0",children:t.actions})]}),(0,r.jsx)("main",{className:"flex-1 overflow-auto p-4",children:o})]})]})}var Rm={online:"bg-success",offline:"bg-danger",warning:"bg-warning",unknown:"bg-foreground-subtle"};function Dm({title:e,subtitle:t,status:s,selected:n,onClick:o,badges:a,actions:i,offlineAction:l,className:u}){const d=s==="offline";return(0,r.jsxs)("div",{onClick:o,className:j("w-full rounded-lg border p-3 text-left transition-colors",o&&"cursor-pointer",n?"border-primary bg-primary/10":"border-border bg-surface hover:bg-surface-hover",d&&!n&&"opacity-50",u),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium truncate",children:e}),s&&(0,r.jsx)("span",{className:j("h-2 w-2 rounded-full shrink-0",Rm[s])})]}),t&&(0,r.jsx)("div",{className:"text-[11px] text-foreground-muted",children:t}),a&&a.length>0&&(0,r.jsx)("div",{className:"flex flex-wrap gap-1 mt-2",children:a.map((f,p)=>{const g=j("rounded px-1.5 py-0.5 text-[10px] flex items-center gap-0.5",n?"bg-primary/20":"bg-surface-hover",f.onClick&&"hover:opacity-80 transition-opacity cursor-pointer");return f.onClick?(0,r.jsxs)("button",{onClick:b=>{b.stopPropagation(),f.onClick()},className:g,children:[f.icon,f.label]},p):(0,r.jsxs)("span",{className:g,children:[f.icon,f.label]},p)})}),!d&&i&&i.length>0&&(0,r.jsx)("div",{className:"flex items-center gap-0.5 mt-2 -mb-1",children:i.map((f,p)=>(0,r.jsx)("button",{onClick:g=>{g.stopPropagation(),f.onClick()},className:"p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors",title:f.label,"aria-label":f.label,children:f.icon},p))}),d&&l&&(0,r.jsx)("div",{className:"mt-2",onClick:f=>f.stopPropagation(),children:l})]})}function Tm({children:e,minCardWidth:t=220,gap:s=3,className:n}){return(0,r.jsx)("div",{className:j("p-4 overflow-y-auto flex-1 content-start",n),style:{display:"grid",gridTemplateColumns:`repeat(auto-fill, minmax(${t}px, 1fr))`,gap:`${s*4}px`},children:e})}var Im="capability.binding-changed";function cr(e,t){const[s,n]=(0,h.useState)(null);return(0,h.useEffect)(()=>{if(t===null){n(null);return}let o=!1;const a=async()=>{try{const l=await e.deviceManager.getBindings.query({deviceId:t});o||n(l)}catch{o||n(l=>l)}};a();const i=e.live?.onEvent.subscribe({category:Im},{onData:l=>{const u=l.data?.source;if(!u){a();return}u.type==="device"&&u.id===t&&a()}});return()=>{o=!0,i?.unsubscribe()}},[e,t]),(0,h.useMemo)(()=>s?(0,z.createDeviceProxy)(e,s):null,[e,s])}function Xs(e){const t=(0,h.useCallback)(n=>e?e.subscribe(()=>n()):()=>{},[e]),s=(0,h.useCallback)(()=>e?.value,[e]);return(0,h.useSyncExternalStore)(t,s,s)}function Ja(e,t,s){const n=cr(e,t);return Xs(n?s(n.state):void 0)}function Bt(e){const t=cr(e.trpc,e.deviceId),s=Xs(t!==null?e.slice(t):void 0),n=t!==null?e.cap(t):void 0;return{dev:t,cap:n,slice:s,available:(e.requireFeature===void 0||(e.deviceFeatures??[]).includes(e.requireFeature))&&n!==void 0&&s!==void 0}}function Lm(e){return e.parentDeviceId===null?"top-level":e.role?"accessory":"adopted"}var Om={minimal:{showIntegrationIcon:!1,showParentBadge:!1,showSnapshot:!1,showBattery:!1,showStableId:!1,showId:!1,showSwitchToggle:!0,showChildrenAccordion:!1},compact:{showIntegrationIcon:!0,showParentBadge:!0,showSnapshot:!0,showBattery:!0,showStableId:!1,showId:!1,showSwitchToggle:!0,showChildrenAccordion:!0},expanded:{showIntegrationIcon:!1,showParentBadge:!0,showSnapshot:!0,showBattery:!0,showStableId:!0,showId:!0,showSwitchToggle:!0,showChildrenAccordion:!0}};function _m(e){const t=Om[e.variant??"compact"];return{showIntegrationIcon:e.showIntegrationIcon??t.showIntegrationIcon,showParentBadge:e.showParentBadge??t.showParentBadge,showSnapshot:e.showSnapshot??t.showSnapshot,showBattery:e.showBattery??t.showBattery,showStableId:e.showStableId??t.showStableId,showId:e.showId??t.showId,showSwitchToggle:e.showSwitchToggle??t.showSwitchToggle,showChildrenAccordion:e.showChildrenAccordion??t.showChildrenAccordion}}var $m={siren:Ir,floodlight:ea,spotlight:ca,"pir-sensor":oa,chime:nf,autotrack:Wo,nightvision:Ds,"privacy-mask":Yo,doorbell:qo},Gm={camera:Ps,hub:Ts,nvr:Ts,light:ea,siren:Ir,switch:vf,sensor:oa,thermostat:xf,button:Ud,generic:Os};function ei(e){return e.role?$m[e.role]??Os:Gm[e.type.toLowerCase()]??Ps}var ti={"native-snapshot":Xd,"two-way-audio":ra,"pan-tilt-zoom":Wo,"ptz-autotrack":rf,"doorbell-button":qo,"motion-trigger":ft,"battery-operated":Ho,rebootable:ia},ri={"native-snapshot":"Native snapshot","two-way-audio":"Two-way audio","pan-tilt-zoom":"Pan-Tilt-Zoom","ptz-autotrack":"PTZ autotrack","doorbell-button":"Doorbell button","motion-trigger":"Motion trigger","battery-operated":"Battery operated",rebootable:"Rebootable"},Bm={"native-snapshot":"snapshot",rebootable:"reboot","pan-tilt-zoom":"ptz","ptz-autotrack":"ptz-autotrack","two-way-audio":"intercom","motion-trigger":"motion-trigger"},si=new Set(["camera","hub","nvr"]);function ni(e){return!si.has(e.type.toLowerCase())}function oi(e){return e.role?!0:!si.has(e.type.toLowerCase())}function ai(e){return(e.features??[]).includes("motion-trigger")}function Fm(e){if(e.length<=24)return e;const t=e.lastIndexOf(":");if(t>=0&&t<e.length-4)return e.slice(t+1);const s=e.split("-");if(s.length>2){const n=s.slice(-2).join("-");if(n.length>=6)return n}return`…${e.slice(-18)}`}function zm({trpc:e,accessoryChildren:t,adoptedChildren:s,onNavigate:n}){return(0,r.jsxs)("div",{className:"border-t border-border-subtle/50",children:[s.length>0&&(0,r.jsx)(ii,{trpc:e,label:"Adopted devices",rows:s,onNavigate:n}),t.length>0&&(0,r.jsx)(ii,{trpc:e,label:"Accessories",rows:t,onNavigate:n})]})}function ii({trpc:e,label:t,rows:s,onNavigate:n}){return(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"px-3 pt-1.5 pb-1 text-[9px] font-semibold uppercase tracking-wide text-foreground-subtle",children:t}),(0,r.jsx)("ul",{children:s.map(o=>(0,r.jsx)(Qm,{trpc:e,child:o,onNavigate:n},o.id))})]})}function Qm({trpc:e,child:t,onNavigate:s}){const n=!t.disabled,o=n&&ni(t),a=n&&ai(t);return(0,r.jsx)("li",{children:(0,r.jsxs)("div",{onClick:i=>{i.stopPropagation(),s(t.id)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-surface-hover transition-colors cursor-pointer",children:[(0,r.jsx)(ei(t),{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),(0,r.jsx)("span",{className:"text-[10.5px] text-foreground flex-1 truncate",children:t.name}),a&&(0,r.jsx)(Hm,{trpc:e,deviceId:t.id,features:t.features}),o&&(0,r.jsx)(Um,{trpc:e,deviceId:t.id}),(0,r.jsx)("span",{className:j("h-1.5 w-1.5 rounded-full flex-shrink-0",t.online?"bg-success":"bg-foreground-subtle/40"),title:t.online?"Online":"Offline"})]})})}function Um({trpc:e,deviceId:t}){const{dev:s,cap:n,slice:o,available:a}=Bt({trpc:e,deviceId:t,cap:p=>p.switch,slice:p=>p.state.switch}),[i,l]=(0,h.useState)(!1);if(s!==null&&!n)return null;const u=o?.on===!0,d={transform:u?"translateX(14px)":"translateX(2px)"},f=async p=>{if(p.stopPropagation(),!(i||!a||!n)){l(!0);try{await n.setState({on:!u})}finally{l(!1)}}};return(0,r.jsx)("button",{type:"button",onClick:p=>{f(p)},disabled:i||!a,className:j("relative inline-flex h-4 w-7 items-center rounded-full border transition-colors flex-shrink-0",u?"bg-success/30 border-success/50":"bg-surface-hover border-border",i&&"opacity-60",!a&&"opacity-40 cursor-not-allowed"),title:a?u?"Turn off":"Turn on":"Awaiting state…","aria-pressed":u,children:(0,r.jsx)("span",{className:j("absolute h-3 w-3 rounded-full transition-all",u?"bg-success":"bg-foreground-subtle"),style:d})})}function Hm({trpc:e,deviceId:t,features:s}){const{dev:n,cap:o,slice:a,available:i}=Bt({trpc:e,deviceId:t,cap:p=>p.motionTrigger,slice:p=>p.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:s}),[l,u]=(0,h.useState)(!1);if(n!==null&&!o)return null;const d=a?.enabled===!0,f=async p=>{if(p.stopPropagation(),!(l||!i||!o)){u(!0);try{await o.setMotionTrigger({enabled:!d})}finally{u(!1)}}};return(0,r.jsx)("button",{type:"button",onClick:p=>{f(p)},disabled:l||!i,className:j("inline-flex h-4 w-4 items-center justify-center rounded transition-colors flex-shrink-0",d?"text-primary bg-primary/10":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover",(l||!i)&&"opacity-50"),title:i?d?"Motion-trigger: on (click to disable)":"Motion-trigger: off (click to enable)":"Awaiting state…","aria-pressed":d,children:(0,r.jsx)(ft,{className:"h-2.5 w-2.5"})})}function li({trpc:e,device:t,flags:s}){if(t.disabled)return null;const n=t.type.toLowerCase(),o=s.showSwitchToggle&&ni(t),a=ai(t),i=n==="hub"||n==="nvr",l=(t.features??[]).includes("rebootable"),u=i&&l;return(0,r.jsxs)(r.Fragment,{children:[a&&(0,r.jsx)(Wm,{trpc:e,deviceId:t.id,features:t.features}),o&&(0,r.jsx)(Vm,{trpc:e,deviceId:t.id}),u&&(0,r.jsx)(Km,{trpc:e,deviceId:t.id})]})}function Vm({trpc:e,deviceId:t}){const{dev:s,cap:n,slice:o,available:a}=Bt({trpc:e,deviceId:t,cap:p=>p.switch,slice:p=>p.state.switch}),[i,l]=(0,h.useState)(!1);if(s!==null&&!n)return null;const u=o?.on===!0,d={transform:u?"translateX(14px)":"translateX(2px)"},f=async p=>{if(p.stopPropagation(),!(i||!a||!n)){l(!0);try{await n.setState({on:!u})}finally{l(!1)}}};return(0,r.jsx)("button",{type:"button",onClick:p=>{f(p)},disabled:i||!a,className:j("relative inline-flex h-4 w-7 items-center rounded-full border transition-colors flex-shrink-0",u?"bg-success/30 border-success/50":"bg-surface-hover border-border",i&&"opacity-60",!a&&"opacity-40 cursor-not-allowed"),title:a?u?"Turn off":"Turn on":"Awaiting state…","aria-pressed":u,children:(0,r.jsx)("span",{className:j("absolute h-3 w-3 rounded-full transition-all",u?"bg-success":"bg-foreground-subtle"),style:d})})}function Wm({trpc:e,deviceId:t,features:s}){const{dev:n,cap:o,slice:a,available:i}=Bt({trpc:e,deviceId:t,cap:p=>p.motionTrigger,slice:p=>p.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:s}),[l,u]=(0,h.useState)(!1);if(n!==null&&!o)return null;const d=a?.enabled===!0,f=async p=>{if(p.stopPropagation(),!(l||!i||!o)){u(!0);try{await o.setMotionTrigger({enabled:!d})}finally{u(!1)}}};return(0,r.jsx)("button",{type:"button",onClick:p=>{f(p)},disabled:l||!i,className:j("inline-flex h-4 w-4 items-center justify-center rounded transition-colors flex-shrink-0",d?"text-primary bg-primary/10":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover",(l||!i)&&"opacity-50"),title:i?d?"Motion-trigger: on (click to disable)":"Motion-trigger: off (click to enable)":"Awaiting state…","aria-pressed":d,children:(0,r.jsx)(ft,{className:"h-2.5 w-2.5"})})}var Js=168,qm=4;function Km({trpc:e,deviceId:t}){const{dev:s,cap:n}=Bt({trpc:e,deviceId:t,cap:w=>w.reboot,slice:()=>{}}),o=(0,h.useRef)(null),a=(0,h.useRef)(null),[i,l]=(0,h.useState)(null),[u,d]=(0,h.useState)(!1),f=s!==null&&n!==void 0&&n!==null,p=i!==null,g=()=>l(null),b=()=>{const w=o.current;if(!w)return;const y=w.getBoundingClientRect(),S=y.right-Js,k=Math.max(8,Math.min(S,window.innerWidth-Js-8));l({top:y.bottom+qm,left:k})};if((0,h.useEffect)(()=>{if(!p)return;const w=S=>{const k=o.current,C=a.current,N=S.target;N!==null&&(k&&k.contains(N)||C&&C.contains(N)||g())},y=S=>{S.key==="Escape"&&(S.stopPropagation(),g())};return document.addEventListener("mousedown",w),document.addEventListener("keydown",y),()=>{document.removeEventListener("mousedown",w),document.removeEventListener("keydown",y)}},[p]),s!==null&&!n)return null;const x=w=>{w.stopPropagation(),p?g():b()},v=async()=>{if(!(u||!f||!n)){d(!0),g();try{await n.reboot({})}finally{d(!1)}}};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{ref:o,type:"button",onClick:x,disabled:u||!f,className:j("inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0",(u||!f)&&"opacity-50",p&&"bg-surface-hover text-foreground"),title:"More actions","aria-label":"More actions","aria-haspopup":"menu","aria-expanded":p,children:(0,r.jsx)(Ko,{className:"h-3 w-3"})}),i&&(0,Ze.createPortal)((0,r.jsx)("div",{ref:a,role:"menu",style:{position:"fixed",top:i.top,left:i.left,width:Js},className:"z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-1",onClick:w=>w.stopPropagation(),children:(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>{v()},disabled:u||!f,className:j("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-[11px] text-foreground","hover:bg-surface-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed"),children:[(0,r.jsx)(ia,{className:"h-3 w-3 shrink-0 text-foreground-subtle"}),(0,r.jsx)("span",{children:"Reboot device"})]})}),document.body)]})}var Zm=Object.freeze([]);function Ym(e){return e==="native"?"native":"enhanced"}function Xm(e){return e.map(t=>({kind:"marker",feature:t}))}function Jm(e,t){const s=new Map,n=t.entries??[];for(const a of n)s.set(a.capName,a);const o=[];for(const a of e){const i=Bm[a];if(i===void 0){o.push({kind:"marker",feature:a});continue}const l=s.get(i);l&&o.push({kind:Ym(l.kind),feature:a,capName:i})}return o}function ep(e,t,s){const[n,o]=(0,h.useState)(null),[a,i]=(0,h.useState)(!1),[l,u]=(0,h.useState)(!0);return(0,h.useEffect)(()=>{if(t===null){o(null),i(!1),u(!1);return}let d=!1;u(!0),i(!1);const f=async()=>{try{const g=await e.deviceManager.getBindings.query({deviceId:t});if(d)return;o(g),u(!1)}catch{if(d)return;i(!0),u(!1)}};f();const p=e.live?.onEvent.subscribe({category:"capability.binding-changed"},{onData:g=>{const b=g.data?.source;if(!b){f();return}b.type==="device"&&b.id===t&&f()}});return()=>{d=!0,p?.unsubscribe()}},[e,t]),s.length===0?{loading:l,resolved:Zm}:l||a||!n?{loading:l,resolved:Xm(s)}:{loading:!1,resolved:Jm(s,n)}}var tp=[];function ci({trpc:e,device:t,flags:s,accessoryCount:n,adoptedCount:o,showFeatureRow:a=!1}){const i=n+o,l=s.showChildrenAccordion&&i>0,u=t.features??tp,d=a&&u.length>0,{resolved:f}=ep(e,d?t.id:null,u),p=d&&f.length>0;return!l&&!p?null:(0,r.jsxs)("div",{className:"flex items-center gap-1.5 flex-nowrap whitespace-nowrap min-w-0",children:[l&&(0,r.jsx)(rp,{accessoryCount:n,adoptedCount:o}),p&&(0,r.jsx)(sp,{resolved:f})]})}function rp({accessoryCount:e,adoptedCount:t}){const s=e+t;return s===0?null:(0,r.jsxs)("span",{className:"text-[9px] font-medium text-foreground-subtle bg-surface-elevated/60 rounded px-1.5 py-0.5 flex-shrink-0",title:t>0&&e>0?`${String(t)} adopted · ${String(e)} accessor${e===1?"y":"ies"}`:t>0?`${String(t)} adopted`:`${String(e)} accessor${e===1?"y":"ies"}`,children:["+",s]})}var ui=240,di=200;function sp({resolved:e}){const t=(0,h.useRef)(null),[s,n]=(0,h.useState)(null),o=()=>{const i=t.current;if(!i)return;const l=i.getBoundingClientRect();n({top:window.innerHeight-l.bottom>=di?l.bottom+4:l.top-di-4,left:Math.max(8,Math.min(l.left,window.innerWidth-ui-8))})},a=()=>n(null);return(0,r.jsxs)("span",{ref:t,className:"relative inline-flex items-center gap-1 cursor-help",onMouseEnter:o,onMouseLeave:a,children:[e.map(i=>{const l=ti[i.feature];return l?(0,r.jsx)("span",{className:"inline-flex items-center justify-center h-4 w-4 rounded bg-surface-elevated/60 text-foreground-subtle",title:ri[i.feature]??i.feature,children:(0,r.jsx)(l,{className:"h-2.5 w-2.5"})},i.feature):null}),s&&(0,Ze.createPortal)((0,r.jsx)(np,{resolved:e,position:s}),document.body)]})}function np({resolved:e,position:t}){return(0,r.jsxs)("div",{style:{position:"fixed",top:t.top,left:t.left,width:ui,pointerEvents:"none"},className:"z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-2",children:[(0,r.jsx)("h5",{className:"text-[9px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5",children:"Features"}),(0,r.jsx)("ul",{className:"space-y-0.5",children:e.map(s=>(0,r.jsx)(op,{entry:s},s.feature))})]})}function op({entry:e}){const t=ti[e.feature],s=ri[e.feature]??e.feature;return(0,r.jsxs)("li",{className:"flex items-center justify-between gap-2 text-[10px]",children:[(0,r.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[t&&(0,r.jsx)(t,{className:"h-3 w-3 text-foreground-subtle"}),(0,r.jsx)("span",{children:s})]}),(0,r.jsx)(ap,{kind:e.kind})]})}function ap({kind:e}){return e==="marker"?(0,r.jsx)("span",{className:"text-[8.5px] px-1 rounded text-foreground-subtle",title:"Informational marker (no cap registered)",children:"marker"}):(0,r.jsx)("span",{className:j("text-[8.5px] px-1 rounded",e==="native"?"bg-success/15 text-success":"bg-primary/15 text-primary"),children:e})}function fi({device:e,variant:t,flags:s,parent:n,integrationIcon:o,hasChildren:a,expanded:i,onToggleExpand:l,onNavigateToParent:u}){const d=ei(e);return(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[s.showChildrenAccordion&&a?(0,r.jsx)("button",{type:"button",onClick:f=>{f.stopPropagation(),l()},className:"flex h-3.5 w-3.5 items-center justify-center text-foreground-subtle hover:text-foreground transition-colors flex-shrink-0","aria-label":i?"Collapse children":"Expand children","aria-expanded":i,children:i?(0,r.jsx)(St,{className:"h-3 w-3"}):(0,r.jsx)(mt,{className:"h-3 w-3"})}):s.showChildrenAccordion?(0,r.jsx)("span",{className:"h-3.5 w-3.5 flex-shrink-0"}):null,(0,r.jsx)(d,{className:j("text-foreground-subtle flex-shrink-0",t==="minimal"?"h-3 w-3":"h-3.5 w-3.5")}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[s.showIntegrationIcon&&o&&(0,r.jsx)("span",{className:"flex-shrink-0",children:o}),(0,r.jsx)("span",{className:j("font-semibold text-foreground truncate",t==="minimal"?"text-[10.5px]":"text-[11px]"),title:e.name,children:e.name})]}),(s.showId||s.showStableId)&&(0,r.jsxs)("div",{className:"mt-0.5 flex items-center gap-1 text-[9px] text-foreground-subtle font-mono truncate",title:s.showStableId?`stableId: ${e.stableId}`:void 0,children:[s.showId&&(0,r.jsxs)("span",{className:"flex-shrink-0 tabular-nums",children:["#",String(e.id)]}),s.showId&&s.showStableId&&(0,r.jsx)("span",{className:"flex-shrink-0 opacity-50",children:"·"}),s.showStableId&&(0,r.jsx)("span",{className:"truncate",children:Fm(e.stableId)})]}),s.showParentBadge&&n&&(0,r.jsxs)("button",{type:"button",onClick:f=>{f.stopPropagation(),u(n.id)},className:"mt-0.5 inline-flex max-w-full items-center gap-1 text-[9px] text-foreground-subtle hover:text-primary transition-colors",title:`Open parent: ${n.name} (#${String(n.id)})`,children:[(0,r.jsx)(Ts,{className:"h-2.5 w-2.5 shrink-0"}),(0,r.jsxs)("span",{className:"truncate",children:["Under: ",n.name]})]})]})]})}function mi(e,t){return Ja(e,t,s=>s.battery)??null}function pi(e,t){const s=cr(e,t),n=(0,h.useRef)(!1),{data:o,isLoading:a,isFetching:i,refetch:l}=(0,Ee.useQuery)({queryKey:["device",t,"snapshot"],queryFn:()=>{if(!s)throw new Error("useDeviceSnapshotImage: device proxy not ready");const f=n.current;return n.current=!1,s.snapshot?.getSnapshot({force:f})??null},enabled:s!==null&&t!==null,staleTime:1e4,gcTime:1440*60*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,retry:!1}),u=o?`data:${o.contentType};base64,${o.base64}`:null;function d(){n.current=!0,l()}return{src:u,loading:a||i,refresh:d}}function ip(e){return e<=10?_d:e<=30?Od:e>=95?Ld:Ho}function lp(e,t){return t!=="none"?"text-emerald-400":e<=10?"text-rose-400":e<=30?"text-amber-400":"text-foreground-subtle"}function hi({status:e,variant:t="compact",className:s}){if(!e)return null;const n=ip(e.percentage),o=lp(e.percentage,e.charging),a=e.charging==="solar"?ca:e.charging==="dc"?of:null,i=e.sleeping;return(0,r.jsxs)("span",{className:j("inline-flex items-center gap-1 text-[10px] font-medium",o,s),title:`Battery: ${Math.round(e.percentage)}%`+(e.charging!=="none"?` · charging (${e.charging})`:"")+(e.sleeping?" · sleeping":""),children:[(0,r.jsx)(n,{className:"h-3.5 w-3.5"}),(0,r.jsxs)("span",{children:[Math.round(e.percentage),"%"]}),a&&(0,r.jsx)(a,{className:"h-3 w-3"}),i&&(0,r.jsx)(Ds,{className:"h-3 w-3 text-blue-300"}),t==="full"&&e.charging!=="none"&&(0,r.jsx)("span",{className:"text-foreground-subtle",children:e.charging})]})}function gi({trpc:e,device:t,status:s,enabled:n,showStatusPills:o=!1}){const a=pi(e,n&&t.online?t.id:null),i=(t.features??[]).includes("battery-operated"),l=o&&i&&!t.disabled,u=mi(e,l?t.id:null);return!n&&!l?null:(0,r.jsxs)("span",{className:"inline-flex items-center gap-1.5 flex-nowrap whitespace-nowrap",children:[l&&u&&(0,r.jsx)(hi,{status:u}),n&&(0,r.jsx)(cp,{deviceName:t.name,snapshotUrl:a.src,status:s})]})}var en=288,bi=196,tn=8;function cp({deviceName:e,snapshotUrl:t,status:s}){const n=(0,h.useRef)(null),[o,a]=(0,h.useState)(null),i=s==="offline"||s==="disabled",l=()=>{const d=n.current;if(!d)return;const f=d.getBoundingClientRect(),p=f.top,g=window.innerHeight-f.bottom,b=p<bi+tn&&g>p,x=b?f.bottom+tn:f.top-bi-tn,v=f.right-en;a({top:x,left:Math.max(8,Math.min(v,window.innerWidth-en-8)),placeBelow:b})},u=()=>a(null);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{ref:n,type:"button",onClick:d=>d.stopPropagation(),onMouseEnter:l,onMouseLeave:u,onFocus:l,onBlur:u,className:"flex h-6 w-6 items-center justify-center rounded text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors flex-shrink-0",title:"Preview","aria-label":"Preview snapshot",children:(0,r.jsx)(Or,{className:"h-3.5 w-3.5"})}),o&&(0,Ze.createPortal)((0,r.jsxs)("div",{style:{position:"fixed",top:o.top,left:o.left,width:en,pointerEvents:"none"},className:"rounded-lg border border-border bg-surface shadow-lg shadow-black/30 z-[9999] overflow-hidden",children:[(0,r.jsx)("div",{className:"h-40 bg-background flex items-center justify-center",children:t&&!i?(0,r.jsx)("img",{src:t,alt:e,className:"h-full w-full object-cover"}):(0,r.jsx)("span",{className:"text-xs text-foreground-subtle",children:s==="offline"?"Offline — no snapshot":s==="disabled"?"Disabled":"No snapshot yet"})}),(0,r.jsx)("div",{className:"px-3 py-2",children:(0,r.jsx)("p",{className:"text-xs font-semibold text-foreground truncate",children:e})})]}),document.body)]})}function xi({status:e}){const t=e==="disabled"?"bg-warning":e==="online"?"bg-success":"bg-danger",s=e==="disabled"?"Disabled":e==="online"?"Online":"Offline";return(0,r.jsx)("span",{className:j("h-1.5 w-1.5 rounded-full flex-shrink-0",t),title:s})}function Ur(e){const{trpc:t,device:s,parent:n,integrationIcon:o,onNavigate:a,className:i}=e,l=_m(e),u=e.variant??"compact",d=e.view??"card",f=!s.disabled,p=s.isCamera??s.type.toLowerCase()==="camera",g=e.children??[],b=g.filter(oi),x=g.filter(R=>!oi(R)),v=g.length>0,[w,y]=(0,h.useState)(!1),S=e.expanded??w,k=e.onToggleExpand??(()=>y(R=>!R)),C=R=>{a?.(R)},N=e.indentLevel??(e.isAccessoryRow?2:0),E=f?s.online?"online":"offline":"disabled";return d==="table"?(0,r.jsx)(dp,{trpc:t,device:s,variant:u,flags:l,parent:n??null,integrationIcon:o??null,accessoryCount:b.length,adoptedCount:x.length,hasChildren:v,expanded:S,onToggleExpand:k,onNavigate:C,displayStatus:E,isCamera:p,showSnapshot:l.showSnapshot&&p,isAccessoryRow:e.isAccessoryRow??!1,indentLevel:N,className:i}):(0,r.jsxs)("div",{className:j("rounded-lg border border-border bg-surface transition-colors",!f&&"opacity-60",i),children:[(0,r.jsxs)("div",{onClick:()=>C(s.id),className:j("flex items-center gap-2 cursor-pointer hover:border-foreground-subtle/30 w-full",u==="minimal"?"px-2.5 py-1.5":"px-3 py-2.5"),children:[(0,r.jsx)(fi,{device:s,variant:u,flags:l,parent:n??null,integrationIcon:o??null,hasChildren:v,expanded:S,onToggleExpand:k,onNavigateToParent:C}),(0,r.jsx)(ci,{trpc:t,device:s,flags:l,accessoryCount:b.length,adoptedCount:x.length,showFeatureRow:!1}),(0,r.jsx)(gi,{trpc:t,device:s,status:E,enabled:l.showSnapshot&&p,showStatusPills:!0}),(0,r.jsx)(li,{trpc:t,device:s,flags:l}),(0,r.jsx)(xi,{status:E})]}),S&&v&&(0,r.jsx)(zm,{trpc:t,accessoryChildren:b,adoptedChildren:x,onNavigate:C})]})}var up={0:"pl-2",1:"pl-6",2:"pl-8"};function dp(e){const{trpc:t,device:s,variant:n,flags:o,parent:a,integrationIcon:i,accessoryCount:l,adoptedCount:u,hasChildren:d,expanded:f,onToggleExpand:p,onNavigate:g,displayStatus:b,isCamera:x,showSnapshot:v,isAccessoryRow:w,indentLevel:y,className:S}=e;return(0,r.jsxs)("tr",{onClick:()=>g(s.id),className:j("cursor-pointer hover:bg-surface-hover transition-colors",!o.showChildrenAccordion&&"border-b border-border-subtle/40",w&&"bg-foreground-subtle/[0.03]",S),children:[(0,r.jsx)("td",{className:j("py-2 align-middle pr-2",up[y]),children:(0,r.jsx)(fi,{device:s,variant:n,flags:o,parent:a,integrationIcon:i,hasChildren:d,expanded:f,onToggleExpand:p,onNavigateToParent:g})}),(0,r.jsx)("td",{className:"px-2 py-2 align-middle text-[10px] text-foreground-subtle whitespace-nowrap",children:s.type}),(0,r.jsx)("td",{className:"px-2 py-2 align-middle",children:(0,r.jsx)(ci,{trpc:t,device:s,flags:o,accessoryCount:l,adoptedCount:u,showFeatureRow:!0})}),(0,r.jsx)("td",{className:"px-2 py-2 align-middle",children:(0,r.jsx)(gi,{trpc:t,device:s,status:b,enabled:v&&x,showStatusPills:!0})}),(0,r.jsx)("td",{className:"px-2 py-2 align-middle text-right whitespace-nowrap",children:(0,r.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,r.jsx)(li,{trpc:t,device:s,flags:o}),(0,r.jsx)(xi,{status:b})]})})]})}function vi(e,t){const[s,n]=(0,h.useState)(e);return(0,h.useEffect)(()=>{const o=setTimeout(()=>n(e),t);return()=>clearTimeout(o)},[e,t]),s}var fp=new Set(["hub","nvr"]);function mp(e){const t=new Map;for(const o of e)t.set(o.id,o);const s=[],n=new Map;for(const o of e){const a=o.parentDeviceId;if(a==null){s.push(o);continue}const i=t.get(a);if(!i){s.push(o);continue}const l=o.role!==null&&o.role!==void 0;if(fp.has(i.type)&&!l){s.push(o);continue}const u=n.get(a);u?u.push(o):n.set(a,[o])}return{topLevel:s,accessoriesByParent:n}}var yi=2;function pp(e,t){if(t<=1)return[{kind:"page",n:1}];if(t<=7){const a=[];for(let i=1;i<=t;i++)a.push({kind:"page",n:i});return a}const s=[],n=Math.max(2,e-yi),o=Math.min(t-1,e+yi);s.push({kind:"page",n:1}),n>2&&s.push({kind:"ellipsis",side:"left"});for(let a=n;a<=o;a++)s.push({kind:"page",n:a});return o<t-1&&s.push({kind:"ellipsis",side:"right"}),s.push({kind:"page",n:t}),s}function hp({currentPage:e,totalItems:t,pageSize:s,onPageChange:n,itemNoun:o="devices"}){if(t<=s)return null;const a=Math.ceil(t/s),i=(e-1)*s+1,l=Math.min(e*s,t),u=pp(e,a);return(0,r.jsxs)("div",{className:"flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle",children:[(0,r.jsxs)("span",{children:["Showing ",i,"–",l," of ",t," ",o]}),(0,r.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,r.jsx)("button",{type:"button","aria-label":"Previous page",disabled:e===1,onClick:()=>n(e-1),className:j("inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle","hover:text-foreground hover:bg-surface-hover transition-colors","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface"),children:(0,r.jsx)(Fd,{className:"h-3 w-3"})}),u.map((d,f)=>d.kind==="ellipsis"?(0,r.jsx)("span",{className:"px-1 text-foreground-subtle/60 select-none",children:"…"},`e-${f}`):(0,r.jsx)("button",{type:"button",onClick:()=>n(d.n),className:j("inline-flex items-center justify-center h-7 min-w-7 px-1.5 rounded border text-[10.5px] font-medium transition-colors",d.n===e?"border-primary/40 bg-primary/10 text-primary":"border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),children:d.n},`p-${d.n}`)),(0,r.jsx)("button",{type:"button","aria-label":"Next page",disabled:e===a,onClick:()=>n(e+1),className:j("inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle","hover:text-foreground hover:bg-surface-hover transition-colors","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface"),children:(0,r.jsx)(mt,{className:"h-3 w-3"})})]})]})}function gp({view:e,onViewChange:t,types:s,currentType:n,onTypeChange:o,addons:a,currentAddon:i,onAddonChange:l,hideAddons:u=!1}){return(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,r.jsxs)("span",{className:"inline-flex border border-border rounded-md overflow-hidden",children:[(0,r.jsx)("button",{type:"button",onClick:()=>t("cards"),className:j("inline-flex items-center justify-center h-7 w-8 transition-colors",e==="cards"?"bg-primary/10 text-primary":"bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),"aria-label":"Cards view",children:(0,r.jsx)(tf,{className:"h-3.5 w-3.5"})}),(0,r.jsx)("button",{type:"button",onClick:()=>t("table"),className:j("inline-flex items-center justify-center h-7 w-8 border-l border-border transition-colors",e==="table"?"bg-primary/10 text-primary":"bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),"aria-label":"Table view",children:(0,r.jsx)(bf,{className:"h-3.5 w-3.5"})})]}),s&&s.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(wi,{children:"Type"}),(0,r.jsx)(rn,{active:n===null,onClick:()=>o(null),children:"All"}),s.map(d=>(0,r.jsx)(rn,{active:n===d,onClick:()=>o(n===d?null:d),children:bp(d)},d))]}),!u&&a&&a.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(wi,{children:"Integration"}),a.map(d=>(0,r.jsx)(rn,{active:i===d.id,icon:d.icon,onClick:()=>l(i===d.id?null:d.id),showClearIcon:i===d.id,children:d.name},d.id))]})]})}function wi({children:e}){return(0,r.jsx)("span",{className:"text-[10px] font-medium uppercase tracking-wider text-foreground-subtle ml-1",children:e})}function rn({active:e,icon:t,onClick:s,showClearIcon:n,children:o}){return(0,r.jsxs)("button",{type:"button",onClick:s,className:j("inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border text-[10.5px] font-medium transition-colors",e?"border-primary/40 bg-primary/15 text-primary":"border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),children:[t&&(0,r.jsx)("span",{className:"inline-flex items-center",children:t}),(0,r.jsx)("span",{children:o}),e&&n&&(0,r.jsx)(Pe,{className:"h-2.5 w-2.5 opacity-70"})]})}function bp(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function xp({variant:e,onClearFilters:t}){return(0,r.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[(0,r.jsx)(Jd,{className:"h-8 w-8 text-foreground-subtle/40 mb-3"}),(0,r.jsx)("p",{className:"text-sm font-medium text-foreground-subtle",children:e==="filtered"?"No devices match the current filters":"No devices yet"}),e==="filtered"&&t&&(0,r.jsx)("button",{type:"button",onClick:t,className:"mt-2 text-[11px] text-primary hover:underline",children:"Clear filters"})]})}function et(e,t){if(e==="root")return t;switch(t){case"view":return"deviceView";case"page":return"devicePage";case"type":return"deviceType";case"q":return"deviceQ";case"addon":return"deviceAddon"}}function Si(e){try{const t=localStorage.getItem(`camstack:${e}:lastFilters`);if(!t)return{};const s=JSON.parse(t);return typeof s!="object"||s===null?{}:s}catch{return{}}}function vp(e,t){try{localStorage.setItem(`camstack:${e}:lastFilters`,JSON.stringify(t))}catch{}}function ki(e,t,s){const n=new URLSearchParams(window.location.search),o=n.get(et(e,"view")),a=o==="cards"||o==="table"?o:s.view??t,i=n.get(et(e,"page")),l=i?parseInt(i,10):1;return{view:a,page:Number.isFinite(l)&&l>=1?l:1,addon:n.get(et(e,"addon"))??s.addon??null,type:n.get(et(e,"type"))??s.type??null,q:n.get(et(e,"q"))??s.q??""}}function yp(e,t,s){const n=new URLSearchParams(window.location.search),o=(l,u)=>{u===null||u===""?n.delete(l):n.set(l,u)};o(et(e,"view"),t.view===s?null:t.view),o(et(e,"page"),t.page===1?null:String(t.page)),o(et(e,"addon"),t.addon),o(et(e,"type"),t.type),o(et(e,"q"),t.q||null);const a=n.toString(),i=a?`${window.location.pathname}?${a}`:window.location.pathname;window.history.replaceState(null,"",i)}function wp(e){const{scope:t,defaultView:s,lsKey:n}=e,[o,a]=(0,h.useState)(()=>ki(t,s,Si(n))),i=(0,h.useRef)(o);i.current=o,(0,h.useEffect)(()=>{const u=()=>{const d=ki(t,s,Si(n));i.current=d,a(d)};return window.addEventListener("popstate",u),()=>window.removeEventListener("popstate",u)},[t,s,n]);const l=(0,h.useCallback)(u=>{const d=u(i.current);i.current=d,a(d),yp(t,d,s),vp(n,{view:d.view,addon:d.addon,type:d.type,q:d.q})},[t,s,n]);return{state:o,setView:(0,h.useCallback)(u=>l(d=>({...d,view:u})),[l]),setPage:(0,h.useCallback)(u=>l(d=>({...d,page:u})),[l]),setAddon:(0,h.useCallback)(u=>l(d=>({...d,addon:u,page:1})),[l]),setType:(0,h.useCallback)(u=>l(d=>({...d,type:u,page:1})),[l]),setQ:(0,h.useCallback)(u=>l(d=>({...d,q:u,page:1})),[l]),clearFilters:(0,h.useCallback)(()=>l(u=>({...u,addon:null,type:null,q:"",page:1})),[l])}}var Sp={cards:24,table:50};function kp(e){const{devices:t,trpc:s,defaultView:n="table",filters:o,forceAddon:a,resolveIntegrationIcon:i,resolveParent:l,onNavigate:u,pageSize:d=Sp,urlScope:f="root",lsKey:p=f==="root"?"devices":"integrations:nested"}=e,g=wp({scope:f,defaultView:n,lsKey:p}),b=g.state.view,x=b==="cards"?d.cards:d.table,[v,w]=(0,h.useState)(g.state.q),y=vi(v,300);(0,h.useEffect)(()=>{y!==g.state.q&&g.setQ(y)},[y]);const S=a??g.state.addon,k=(0,h.useMemo)(()=>{const ae=g.state.q.toLowerCase().trim();return t.filter(ce=>!(S&&ce.addonId!==S||g.state.type&&ce.type!==g.state.type||ae&&!ce.name.toLowerCase().includes(ae)&&!ce.stableId.toLowerCase().includes(ae)))},[t,S,g.state.type,g.state.q]),C=(0,h.useMemo)(()=>mp(k),[k]),N=(0,h.useMemo)(()=>{if(g.state.q.trim()==="")return new Set;const ae=g.state.q.toLowerCase().trim(),ce=new Set;for(const[se,J]of C.accessoriesByParent.entries())J.some(H=>H.name.toLowerCase().includes(ae)||H.stableId.toLowerCase().includes(ae))&&ce.add(se);return ce},[C.accessoriesByParent,g.state.q]),E=C.topLevel.length,R=Math.max(1,Math.ceil(E/x)),A=Math.min(g.state.page,R),Q=(A-1)*x,ee=C.topLevel.slice(Q,Q+x);(0,h.useEffect)(()=>{A!==g.state.page&&g.setPage(A)},[A]),Ap();const ne=S!=null||g.state.type!==null||g.state.q!=="",pe=E===0;return(0,r.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[(0,r.jsx)(gp,{view:b,onViewChange:g.setView,types:o?.types,currentType:g.state.type,onTypeChange:g.setType,addons:o?.addons,currentAddon:g.state.addon,onAddonChange:g.setAddon,hideAddons:a!==void 0}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)(nr,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle pointer-events-none"}),(0,r.jsx)("input",{type:"text",value:v,onChange:ae=>w(ae.target.value),placeholder:"Search by name or stableId","aria-label":"Search devices by name or stableId",className:"h-7 pl-7 pr-2.5 rounded-md border border-border bg-surface text-[11px] text-foreground placeholder:text-foreground-subtle/60 focus:outline-none focus:ring-1 focus:ring-primary/40 w-56"})]})]}),pe?(0,r.jsx)(xp,{variant:ne?"filtered":"nofilter",onClearFilters:ne?g.clearFilters:void 0}):b==="cards"?(0,r.jsx)(jp,{rows:ee,accessoriesByParent:C.accessoriesByParent,trpc:s,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:u??null}):(0,r.jsx)(Mp,{rows:ee,accessoriesByParent:C.accessoriesByParent,autoExpandedParents:N,devices:k,trpc:s,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:u??null}),(0,r.jsx)(hp,{currentPage:A,totalItems:E,pageSize:x,onPageChange:g.setPage}),a===void 0&&ne&&E>0&&(0,r.jsxs)("p",{className:"text-[11px] text-foreground-subtle",children:["Showing ",E," of ",t.length," devices",S&&(0,r.jsxs)(r.Fragment,{children:[" ","· filtered by"," ",(0,r.jsx)("strong",{className:"text-primary",children:o?.addons?.find(ae=>ae.id===S)?.name??S})]})]})]})}function jp({rows:e,accessoriesByParent:t,trpc:s,resolveIntegrationIcon:n,resolveParent:o,onNavigate:a}){return(0,r.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:e.map(i=>{const l=t.get(i.id)??[];return(0,r.jsx)(Ur,{trpc:s,device:i,view:"card",integrationIcon:n?.(i.addonId)??null,parent:i.parentDeviceId!==null?o?.(i.parentDeviceId)??null:null,children:l,onNavigate:a??void 0},i.id)})})}var Np=new Set(["hub","nvr"]);function Cp(e,t){return e.parentDeviceId===null||t===null?0:Np.has(t.toLowerCase())?1:0}function Mp({rows:e,accessoriesByParent:t,autoExpandedParents:s,devices:n,trpc:o,resolveIntegrationIcon:a,resolveParent:i,onNavigate:l}){const u=(0,h.useMemo)(()=>{const d=new Map;for(const f of n)d.set(f.id,f.type);return d},[n]);return(0,r.jsx)("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:(0,r.jsxs)("table",{className:"w-full border-collapse",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border",children:[(0,r.jsx)("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle",children:"Name"}),(0,r.jsx)("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-24",children:"Type"}),(0,r.jsx)("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Features"}),(0,r.jsx)("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-20",children:"Preview"}),(0,r.jsx)("th",{className:"text-right px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Actions"})]})}),(0,r.jsx)("tbody",{children:e.map(d=>{const f=t.get(d.id)??[],p=f.length>0,g=s.has(d.id),b=d.parentDeviceId!==null?i?.(d.parentDeviceId)??null:null,x=d.parentDeviceId!==null?u.get(d.parentDeviceId)??null:null;return(0,r.jsx)(Ep,{parent:d,accessories:f,hasAccessories:p,forceExpanded:g,trpc:o,integrationIcon:a?.(d.addonId)??null,parentRowParent:b,indentLevel:Cp(d,x),onNavigate:l??null},d.id)})})]})})}function Ep({parent:e,accessories:t,hasAccessories:s,forceExpanded:n,trpc:o,integrationIcon:a,parentRowParent:i,indentLevel:l,onNavigate:u}){const[d,f]=(0,h.useState)(n),p=(0,h.useRef)(n);(0,h.useEffect)(()=>{p.current!==n&&(f(n),p.current=n)},[n]);const g=()=>f(b=>!b);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Ur,{trpc:o,device:e,view:"table",integrationIcon:a,parent:i,children:t,onNavigate:u??void 0,showChildrenAccordion:s,expanded:d,onToggleExpand:g,indentLevel:l}),s&&d&&t.map(b=>(0,r.jsx)(Ur,{trpc:o,device:b,view:"table",integrationIcon:null,parent:null,isAccessoryRow:!0,showChildrenAccordion:!1,onNavigate:u??void 0},b.id))]})}function Ap(){(0,Ee.useQueryClient)()}function Pp({options:e,value:t,onChange:s}){return(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:e.map(n=>{const o=n.id===t;return(0,r.jsxs)("button",{onClick:()=>n.available&&s(n.id),disabled:!n.available,className:`flex items-center gap-2 rounded-lg border px-3 py-2 text-xs font-medium transition-all ${o?"border-primary/40 bg-primary/10 text-primary":n.available?"border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground":"border-border/40 bg-surface/40 text-foreground-subtle/40 cursor-not-allowed"}`,children:[(0,r.jsx)(Kd,{className:"h-3.5 w-3.5 shrink-0"}),n.label,n.isBest&&(0,r.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded-full bg-amber-500/15 px-1.5 py-0.5 text-[10px] font-semibold text-amber-400",children:[(0,r.jsx)(gf,{className:"h-2.5 w-2.5"}),"Best"]}),n.platformScore!=null&&(0,r.jsxs)("span",{className:"text-[10px] text-foreground-subtle/60",children:["(",n.platformScore,")"]}),(0,r.jsx)("span",{className:`h-1.5 w-1.5 rounded-full ${n.available?"bg-success":"bg-danger"}`})]},n.id)})})}function Rp(e,t){const s=new Set(t.slots.flatMap(i=>i.addons.map(l=>l.id))),n=[];function o(i){if(!s.has(i.addonId))return n.push(`Addon "${i.addonId}" is no longer available — step removed`),null;const l=t.slots.flatMap(f=>f.addons).find(f=>f.id===i.addonId);let u=i.modelId;if(l&&!l.models.some(f=>f.id===u)){const f=l.defaultModelId;n.push(`Model "${u}" not available for ${i.addonId} — using "${f}"`),u=f}const d=i.children.map(f=>o(f)).filter(f=>f!==null);return{...i,modelId:u,children:d}}const a=e.map(i=>o(i)).filter(i=>i!==null);return{valid:n.length===0,steps:a,warnings:n}}function Dp(e){const t=new Map;for(const s of e.slots)for(const n of s.addons)t.set(n.id,n);return t}function sn(e){return{addonId:e.id,addonName:e.name,slot:e.slot,inputClasses:[...e.inputClasses],outputClasses:[...e.outputClasses],enabled:!0,modelId:e.defaultModelId,children:[]}}function nn({addon:e,onClick:t}){return(0,r.jsx)("button",{type:"button",onClick:t,className:"w-full rounded-lg border border-dashed border-border/60 px-3 py-2.5 text-left transition-all hover:border-primary/30 hover:bg-surface/60 group",children:(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)(Vd,{className:"h-[18px] w-[18px] text-foreground-subtle/30 group-hover:text-primary/60 shrink-0"}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("span",{className:"text-[13px] font-medium text-foreground-subtle/50 group-hover:text-foreground-subtle block truncate",children:e.name}),(0,r.jsxs)("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(s=>(0,r.jsx)("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-blue-500/8 text-blue-400/50",children:s},s)),e.inputClasses.length>0&&e.outputClasses.length>0&&(0,r.jsx)("span",{className:"text-foreground-subtle/25 text-[10px]",children:"→"}),e.outputClasses.map(s=>(0,r.jsx)("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-green-500/8 text-green-400/50",children:s},s))]})]})]})})}function Tp({schema:e,steps:t,onChange:s,templates:n,selectedTemplateId:o,onSelectTemplate:a,onSaveTemplate:i,onUpdateTemplate:l,onDeleteTemplate:u,readOnly:d=!1,excludeAddons:f=[],hideTemplates:p=!1,showOnlyEnabled:g=!1,showSlotLabels:b=!1,toggleMode:x="simple",overrides:v={},onOverrideChange:w,inheritedEnabledByAddon:y={},hideModelAndSettings:S=!1}){const k=$=>({toggleMode:x,hideModelAndSettings:S,...x==="threeState"?{overrideState:v[$]!==void 0?v[$]:null,onOverrideChange:w?_=>w($,_):void 0,inheritedEnabled:y[$]}:{}}),C=(0,h.useMemo)(()=>new Set(f),[f]),N=(0,h.useMemo)(()=>Dp(e),[e]),[E,R]=(0,h.useState)([]),A=o?JSON.stringify(t)!==JSON.stringify(n.find($=>$.id===o)?.steps):!1;function Q($){const _=$.target.value||null;if(_){const te=n.find(U=>U.id===_);te&&R([...Rp(te.steps,e).warnings])}else R([]);a(_)}function ee(){o&&l(o,t)}function ne(){const $=window.prompt("Template name:");$?.trim()&&i($.trim(),t)}function pe(){if(!o)return;const $=n.find(_=>_.id===o);$&&window.confirm(`Delete template "${$.name}"?`)&&u(o)}function ae($){s(t.map(_=>_.addonId!==$.addonId?_:ce($)))}function ce($){const _=$.children.some(te=>te.enabled||te.children.some(U=>U.enabled));return{...$,enabled:$.enabled||_,children:$.children.map(te=>{const U=te.children.some(V=>V.enabled);return{...te,enabled:te.enabled||U}})}}function se($,_){const te=sn(_);s(t.map(U=>U.addonId!==$?U:{...U,children:[...U.children,te]}))}function J($){const _=new Set;for(const te of $){_.add(te.addonId);for(const V of te.children)_.add(V.addonId);const U=J(te.children);for(const V of U)_.add(V)}return _}const H=J(t);function xe($){const _=N.get($.addonId);if(!_)return[];const te=e.slots.find(F=>F.id===_.slot)?.parentSlot==null,U=_.childSlots,V=new Set($.children.map(F=>F.addonId)),W=[];for(const F of e.slots)if(U.includes(F.id))for(const X of F.addons){if(V.has(X.id)||C.has(X.id))continue;const q=X.inputClasses.length===0;q&&!te||(q||X.inputClasses.some(Re=>$.outputClasses.includes(Re)))&&W.push(X)}return W}function de($){const _=g?{...$,children:$.children.filter(U=>U.enabled).map(U=>({...U,children:U.children.filter(V=>V.enabled)}))}:$,te=g?[]:xe(_);return(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)(Br,{step:_,schema:N.get(_.addonId)??null,allSchemas:N,onChange:ae,onDelete:d?void 0:U=>s(t.filter(V=>V.addonId!==U)),readOnly:d,...k(_.addonId)}),(_.children.length>0||te.length>0)&&(0,r.jsxs)("div",{className:"ml-4 pl-3 border-l border-border/60 space-y-1.5",children:[b&&(0,r.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/40",children:"Slot: Cropper / Classifier"}),_.children.map(U=>{const V=xe(U);return(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)(Br,{step:U,schema:N.get(U.addonId)??null,allSchemas:N,depth:1,onChange:W=>{ae({..._,children:_.children.map(F=>F.addonId===W.addonId?W:F)})},onDelete:d?void 0:W=>{ae({..._,children:_.children.filter(F=>F.addonId!==W)})},readOnly:d,...k(U.addonId)}),(U.children.length>0||V.length>0)&&(0,r.jsxs)("div",{className:"ml-4 pl-3 border-l border-border/40 space-y-1.5",children:[b&&(0,r.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/30",children:"Slot: Recognizer"}),U.children.map(W=>(0,r.jsx)(Br,{step:W,schema:N.get(W.addonId)??null,allSchemas:N,depth:2,onChange:F=>{ae({..._,children:_.children.map(X=>X.addonId===U.addonId?{...X,children:X.children.map(q=>q.addonId===F.addonId?F:q)}:X)})},onDelete:d?void 0:F=>{ae({..._,children:_.children.map(X=>X.addonId===U.addonId?{...X,children:X.children.filter(q=>q.addonId!==F)}:X)})},readOnly:d,...k(W.addonId)},W.addonId)),!d&&V.map(W=>(0,r.jsx)(nn,{addon:W,onClick:()=>{const F=sn(W);ae({..._,children:_.children.map(X=>X.addonId===U.addonId?{...X,children:[...X.children,F]}:X)})}},W.id))]})]},U.addonId)}),!d&&te.map(U=>(0,r.jsx)(nn,{addon:U,onClick:()=>se(_.addonId,U)},U.id))]})]},_.addonId)}const D=e.slots.filter($=>$.parentSlot===null).sort(($,_)=>$.priority-_.priority);return(0,r.jsxs)("div",{className:"space-y-4",children:[!p&&(0,r.jsx)("div",{className:"rounded-lg border border-border bg-surface p-3",children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{className:"relative flex-1 min-w-0",children:(0,r.jsxs)("select",{value:o??"",onChange:Q,className:"w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:border-primary/50",children:[(0,r.jsx)("option",{value:"",children:"No template"}),n.map($=>(0,r.jsx)("option",{value:$.id,children:$.name},$.id))]})}),A&&(0,r.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500 shrink-0"}),(0,r.jsx)("button",{onClick:ee,disabled:!o||d,title:"Save",className:j("p-2 rounded-lg border border-border transition-colors",o&&!d?"text-foreground-subtle hover:bg-surface-hover":"text-foreground-subtle/30 cursor-not-allowed"),children:(0,r.jsx)(cf,{className:"h-4 w-4"})}),(0,r.jsx)("button",{onClick:ne,disabled:d,title:"Save As",className:j("p-2 rounded-lg border border-border transition-colors",d?"text-foreground-subtle/30 cursor-not-allowed":"text-foreground-subtle hover:bg-surface-hover"),children:(0,r.jsx)(qd,{className:"h-4 w-4"})}),(0,r.jsx)("button",{onClick:pe,disabled:!o||d,title:"Delete",className:j("p-2 rounded-lg border border-border transition-colors",o&&!d?"text-foreground-subtle hover:text-danger":"text-foreground-subtle/30 cursor-not-allowed"),children:(0,r.jsx)(at,{className:"h-4 w-4"})})]})}),E.length>0&&(0,r.jsxs)("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 text-xs text-amber-400 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("span",{className:"font-medium",children:"Template loaded with warnings:"}),(0,r.jsx)("button",{onClick:()=>R([]),className:"text-amber-400/60 hover:text-amber-400",children:(0,r.jsx)(Pe,{className:"h-3.5 w-3.5"})})]}),E.map(($,_)=>(0,r.jsxs)("div",{children:["• ",$]},_))]}),D.map($=>{const _=t.filter(F=>F.slot===$.id&&!C.has(F.addonId)),te=g?_.filter(F=>F.enabled):_,U=g?[]:$.addons.filter(F=>!H.has(F.id)&&!C.has(F.id)),V=new Map,W=[];for(const F of te)F.group?(V.has(F.group)||V.set(F.group,[]),V.get(F.group).push(F)):W.push(F);return(0,r.jsxs)("div",{className:"space-y-2",children:[b&&(0,r.jsxs)("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50",children:["Slot: ",$.label]}),W.map(F=>de(F)),[...V.entries()].map(([F,X])=>(0,r.jsxs)("div",{className:"space-y-2 rounded-lg border border-border/40 p-2",children:[(0,r.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50 px-1",children:F}),X.map(q=>de(q))]},F)),!d&&U.map(F=>(0,r.jsx)(nn,{addon:F,onClick:()=>{s([...t,sn(F)])}},F.id))]},$.id)})]})}var ur={person:"#3b82f6",vehicle:"#f59e0b",animal:"#22c55e",face:"#a855f7",plate:"#ec4899",bird:"#14b8a6",dog:"#84cc16",cat:"#f97316",car:"#f59e0b",truck:"#d97706",bus:"#b45309",motorcycle:"#eab308",bicycle:"#ca8a04",motion:"#facc15"},ji=["#ef4444","#8b5cf6","#06b6d4","#f97316","#10b981","#6366f1","#e11d48","#0891b2","#7c3aed","#059669"],Ip="#f59e42";function _e(e,t){if(t?.[e])return t[e];if(t?.[e.toLowerCase()])return t[e.toLowerCase()];if(ur[e])return ur[e];if(ur[e.toLowerCase()])return ur[e.toLowerCase()];let s=0;for(let n=0;n<e.length;n++)s=s*31+(e.codePointAt(n)??0)>>>0;return ji[s%ji.length]??"#f59e42"}function Lp({src:e,imageWidth:t,imageHeight:s,detections:n=[],classColors:o,aspectRatio:a,className:i,placeholder:l,showConfidence:u=!0,minConfidence:d=0,borderWidth:f=2}){function p(y){return _e(y,o)}const g=a??(t&&s?`${t}/${s}`:"16/9"),b=n.filter(y=>y.score>=d),x=b.filter(y=>y.kind==="first-level"),v=b.filter(y=>y.kind==="detail"),w=$p(v,y=>y.parentId??"");return(0,r.jsx)("div",{className:j("rounded-lg border border-border bg-surface overflow-hidden relative",i),style:{aspectRatio:g},children:e?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("img",{src:e,className:"absolute inset-0 w-full h-full object-fill",alt:""}),b.map((y,S)=>y.debug?.mask&&y.debug.maskWidth&&y.debug.maskHeight?(0,r.jsx)(Op,{mask:y.debug.mask,maskWidth:y.debug.maskWidth,maskHeight:y.debug.maskHeight,bbox:y.bbox,imageWidth:t,imageHeight:s,color:p(y.macroClass)},`mask-${S}`):null),x.map(y=>{const S=w.get(y.id)??[];return(0,r.jsx)(Ni,{detection:y,imageWidth:t,imageHeight:s,color:p(y.macroClass),showConfidence:u,borderWidth:y.debug?.mask?1:f,children:S.map(k=>(0,r.jsx)(_p,{child:k,parentBbox:y.bbox,color:p(k.macroClass),showConfidence:u},`child-${k.id}`))},`det-${y.id}`)}),v.filter(y=>!y.parentId||!x.some(S=>S.id===y.parentId)).map(y=>(0,r.jsx)(Ni,{detection:y,imageWidth:t,imageHeight:s,color:p(y.macroClass),showConfidence:u,borderWidth:f},`orphan-${y.id}`))]}):(0,r.jsx)("div",{className:"w-full h-full flex items-center justify-center text-foreground-subtle text-sm",children:l??"No image loaded"})})}function Ni({detection:e,imageWidth:t,imageHeight:s,color:n,showConfidence:o,borderWidth:a,children:i}){const{x:l,y:u,width:d,height:f}=e.bbox,p=(0,r.jsxs)("div",{className:"absolute left-0 flex flex-col items-start gap-px",style:{bottom:"100%",marginBottom:"2px"},children:[(0,r.jsxs)("span",{className:"text-[10px] px-1 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:n},children:[e.macroClass,o&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((g,b)=>(0,r.jsxs)("span",{className:"text-[9px] font-semibold px-1 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:_e(g.label)},children:[g.label," ",(g.score*100).toFixed(0),"%"]},`${e.id}-lbl-${b}`))]});return(0,r.jsxs)("div",{className:"absolute rounded-sm",style:{left:`${l/t*100}%`,top:`${u/s*100}%`,width:`${d/t*100}%`,height:`${f/s*100}%`,borderWidth:`${a}px`,borderStyle:"solid",borderColor:n},children:[p,i]})}function Op({mask:e,maskWidth:t,maskHeight:s,bbox:n,imageWidth:o,imageHeight:a,color:i}){const l=(0,h.useRef)(null);return(0,h.useEffect)(()=>{const u=l.current;if(!u)return;const d=u.getContext("2d");if(!d)return;const f=atob(e),p=new Uint8Array(f.length);for(let y=0;y<f.length;y++)p[y]=f.charCodeAt(y);const g=parseInt(i.slice(1,3),16),b=parseInt(i.slice(3,5),16),x=parseInt(i.slice(5,7),16);u.width=t,u.height=s;const v=d.createImageData(t,s),w=t*s;for(let y=0;y<w;y++){const S=y<p.length?p[y]:0,k=y*4;S>0&&(v.data[k]=g,v.data[k+1]=b,v.data[k+2]=x,v.data[k+3]=120)}d.putImageData(v,0,0)},[e,t,s,i]),(0,r.jsx)("canvas",{ref:l,className:"absolute pointer-events-none",style:{left:`${n.x/o*100}%`,top:`${n.y/a*100}%`,width:`${n.width/o*100}%`,height:`${n.height/a*100}%`,imageRendering:"pixelated"}})}function _p({child:e,parentBbox:t,color:s,showConfidence:n}){if(t.width<=0||t.height<=0)return null;const o=(e.bbox.x-t.x)/t.width*100,a=(e.bbox.y-t.y)/t.height*100,i=e.bbox.width/t.width*100,l=e.bbox.height/t.height*100;return(0,r.jsx)("div",{className:"absolute rounded-sm",style:{left:`${Math.max(0,o)}%`,top:`${Math.max(0,a)}%`,width:`${Math.min(100,i)}%`,height:`${Math.min(100,l)}%`,borderWidth:"1px",borderStyle:"solid",borderColor:s},children:(0,r.jsxs)("div",{className:"absolute left-0 flex flex-col items-start gap-px",style:{bottom:"100%",marginBottom:"1px"},children:[(0,r.jsxs)("span",{className:"text-[9px] px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:s},children:[e.macroClass,n&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((u,d)=>(0,r.jsxs)("span",{className:"text-[8px] font-semibold px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:_e(u.label)},children:[u.label," ",(u.score*100).toFixed(0),"%"]},`${e.id}-lbl-${d}`))]})})}function $p(e,t){const s=new Map;for(const n of e){const o=t(n),a=s.get(o)??[];a.push(n),s.set(o,a)}return s}function Gp({detections:e,classColors:t,className:s,hiddenKeys:n,onToggleVisibility:o}){const a=t;if(e.length===0)return(0,r.jsx)("div",{className:"text-sm text-foreground-subtle italic text-center py-4",children:"No detections"});const i=e.filter(f=>f.kind==="first-level"),l=e.filter(f=>f.kind==="detail"),u=new Map;for(const f of l){if(!f.parentId)continue;const p=u.get(f.parentId)??[];p.push(f),u.set(f.parentId,p)}const d=l.filter(f=>!f.parentId||!i.some(p=>p.id===f.parentId));return(0,r.jsxs)("div",{className:s,children:[(0,r.jsxs)("div",{className:"text-xs font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:["Detections (",e.length,")"]}),(0,r.jsxs)("div",{className:"space-y-2",children:[i.map(f=>(0,r.jsx)(Ci,{detection:f,children_:u.get(f.id)??[],colors:a,hiddenKeys:n,onToggleVisibility:o},f.id)),d.map(f=>(0,r.jsx)(Ci,{detection:f,children_:[],colors:a,hiddenKeys:n,onToggleVisibility:o},f.id))]})]})}function Ci({detection:e,children_:t,colors:s,hiddenKeys:n,onToggleVisibility:o}){const a=_e(e.macroClass,s),i=!n?.has(e.id),l=e.debug?.mask,u=e.debug?.maskWidth,d=e.debug?.maskHeight,f=e.debug?.alternateLabels;return(0,r.jsxs)("div",{className:`rounded-md border border-border bg-surface p-3 space-y-1 ${i?"":"opacity-40"}`,children:[(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[o&&(0,r.jsx)("input",{type:"checkbox",checked:i,onChange:()=>o(e.id,!i),className:"h-3.5 w-3.5 rounded border-border accent-primary cursor-pointer shrink-0"}),(0,r.jsx)("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{backgroundColor:a}}),(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:e.macroClass}),e.kind==="detail"&&(0,r.jsx)("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:"detail"}),l&&u&&d&&(0,r.jsxs)("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",u,"x",d]})]}),(0,r.jsx)(zp,{confidence:e.score})]}),(0,r.jsxs)("div",{className:"text-[10px] text-foreground-subtle font-mono",children:["bbox: [",Math.round(e.bbox.x),", ",Math.round(e.bbox.y),","," ",Math.round(e.bbox.x+e.bbox.width),","," ",Math.round(e.bbox.y+e.bbox.height),"]"]}),e.labels.length>0&&(0,r.jsx)("div",{className:"flex flex-wrap gap-1 mt-1",children:e.labels.map((p,g)=>(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 text-[10px] font-medium px-1.5 py-0.5 rounded-full",style:{backgroundColor:_e(p.label,s)+"20",color:_e(p.label,s)},children:[p.label,(0,r.jsxs)("span",{className:"opacity-60",children:[(p.score*100).toFixed(0),"%"]}),p.detectionId&&(0,r.jsxs)("span",{className:"opacity-40 text-[8px]",children:["→ ",p.detectionId]})]},g))}),f&&Object.keys(f).length>0&&(0,r.jsx)(Fp,{alternateLabels:f,colors:s}),t.length>0&&(0,r.jsx)(Bp,{items:t,colors:s,hiddenKeys:n,onToggleVisibility:o})]})}function Bp({items:e,colors:t,hiddenKeys:s,onToggleVisibility:n}){return(0,r.jsx)("div",{className:"ml-4 mt-1.5 space-y-1.5 border-l-2 border-border pl-3",children:e.map(o=>{const a=_e(o.macroClass,t),i=!s?.has(o.id),l=o.debug?.mask,u=o.debug?.maskWidth,d=o.debug?.maskHeight;return(0,r.jsxs)("div",{className:`text-xs space-y-0.5 ${i?"":"opacity-40"}`,children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[n&&(0,r.jsx)("input",{type:"checkbox",checked:i,onChange:()=>n(o.id,!i),className:"h-3 w-3 rounded border-border accent-primary cursor-pointer shrink-0"}),(0,r.jsx)("span",{className:"h-1.5 w-1.5 rounded-full shrink-0",style:{backgroundColor:a}}),(0,r.jsx)("span",{className:"font-medium",style:{color:a},children:o.macroClass}),(0,r.jsxs)("span",{className:"text-foreground-subtle",children:[(o.score*100).toFixed(0),"%"]}),l&&u&&d&&(0,r.jsxs)("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",u,"x",d]})]}),o.labels.length>0&&(0,r.jsx)("div",{className:"flex flex-wrap gap-1 ml-5 mt-0.5",children:o.labels.map((f,p)=>(0,r.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-[9px] font-medium px-1 py-0.5 rounded-full",style:{backgroundColor:_e(f.label,t)+"20",color:_e(f.label,t)},children:[f.label," ",(0,r.jsxs)("span",{className:"opacity-60",children:[(f.score*100).toFixed(0),"%"]})]},p))})]},o.id)})})}function Fp({alternateLabels:e,colors:t}){const[s,n]=(0,h.useState)(!1),o=Object.keys(e);return(0,r.jsxs)("div",{className:"mt-1",children:[(0,r.jsxs)("button",{onClick:()=>n(a=>!a),className:"text-[9px] text-foreground-subtle hover:text-foreground transition-colors flex items-center gap-1",children:[(0,r.jsx)("span",{className:`transition-transform ${s?"rotate-90":""}`,children:"▶"}),"Alternates (",o.length," source",o.length!==1?"s":"",")"]}),s&&(0,r.jsx)("div",{className:"mt-1 ml-3 space-y-1.5",children:o.map(a=>{const i=e[a];return!i||i.length===0?null:(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-[9px] font-medium text-foreground-subtle mb-0.5",children:a}),(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:i.map((l,u)=>(0,r.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-[9px] px-1 py-0.5 rounded-full",style:{backgroundColor:_e(a,t)+"10",color:_e(a,t),opacity:Math.max(.4,l.score)},children:[l.label,(0,r.jsxs)("span",{className:"opacity-60",children:[(l.score*100).toFixed(1),"%"]})]},u))})]},a)})})]})}function zp({confidence:e}){return(0,r.jsxs)("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${e>=.8?"bg-success/10 text-success":e>=.5?"bg-warning/10 text-warning":"bg-danger/10 text-danger"}`,children:[(e*100).toFixed(1),"%"]})}function Qp({timings:e,totalMs:t,className:s}){const n=Object.entries(e);return n.length===0&&t===void 0?null:(0,r.jsxs)("div",{className:`rounded-lg border border-border bg-surface p-3 space-y-2 ${s??""}`,children:[(0,r.jsx)("div",{className:"text-xs font-medium text-foreground-subtle uppercase tracking-wide",children:"Timings"}),(0,r.jsxs)("div",{className:"space-y-1 text-xs",children:[n.map(([o,a])=>(0,r.jsxs)("div",{className:"flex justify-between",children:[(0,r.jsx)("span",{className:"text-foreground-subtle",children:o}),(0,r.jsxs)("span",{className:"font-mono text-foreground",children:[a.toFixed(1),"ms"]})]},o)),t!==void 0&&(0,r.jsxs)("div",{className:"flex justify-between pt-1 border-t border-border font-medium text-foreground",children:[(0,r.jsx)("span",{children:"Total"}),(0,r.jsxs)("span",{className:"font-mono",children:[t.toFixed(1),"ms"]})]})]})]})}function Up({images:e,selectedFilename:t,uploadedName:s,onSelect:n,onUpload:o,className:a,accept:i="image/*",uploadLabel:l="Upload..."}){const u=()=>{const d=document.createElement("input");d.type="file",d.accept=i,d.onchange=()=>{const f=d.files?.[0];if(!f)return;const p=new FileReader;p.onload=()=>{const g=p.result,b=g.split(",")[1];b&&o(b,f.name,g)},p.readAsDataURL(f)},d.click()};return(0,r.jsxs)("div",{className:`flex flex-wrap items-center gap-2 ${a??""}`,children:[e.map(d=>(0,r.jsx)("button",{onClick:()=>n(d.filename),className:`px-3 py-1.5 text-xs rounded-md border transition-colors ${t===d.filename?"bg-primary text-primary-foreground border-primary":"bg-surface border-border text-foreground hover:border-primary/50"}`,children:d.id??d.filename.replace(/\.[^.]+$/,"")},d.filename)),(0,r.jsx)("button",{onClick:u,className:"px-3 py-1.5 text-xs rounded-md border border-border bg-surface text-foreground hover:bg-surface-hover transition-colors",children:l}),s&&(0,r.jsx)("span",{className:"text-xs text-foreground-subtle",children:s})]})}var Hr="w-full px-3 py-2 text-sm rounded-md border border-border bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-primary/50";function Hp({runtime:e,backend:t,modelId:s,agentId:n="hub",runtimes:o,backends:a,models:i,agents:l=[],onRuntimeChange:u,onBackendChange:d,onModelChange:f,onAgentChange:p,layout:g="grid",className:b,showAgent:x=!1}){return(0,r.jsxs)("div",{className:`${g==="grid"?"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4":g==="horizontal"?"flex flex-wrap items-end gap-4":"space-y-3"} ${b??""}`,children:[x&&l.length>0&&(0,r.jsxs)("label",{className:"space-y-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-foreground-subtle",children:"Agent"}),(0,r.jsx)("select",{value:n,onChange:v=>p?.(v.target.value),className:Hr,children:l.map(v=>(0,r.jsxs)("option",{value:v.id,children:[v.name," (",v.status,")"]},v.id))})]}),(0,r.jsxs)("label",{className:"space-y-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-foreground-subtle",children:"Runtime"}),(0,r.jsx)("select",{value:e,onChange:v=>u(v.target.value),className:Hr,children:o.map(v=>(0,r.jsxs)("option",{value:v.value,disabled:!v.available,children:[v.label,v.available?"":" (unavailable)"]},v.value))})]}),(0,r.jsxs)("label",{className:"space-y-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-foreground-subtle",children:"Backend"}),(0,r.jsx)("select",{value:t,onChange:v=>d(v.target.value),className:Hr,children:a.map(v=>(0,r.jsxs)("option",{value:v.id,disabled:!v.available,children:[v.label,v.available?"":" (unavailable)"]},v.id))})]}),(0,r.jsxs)("label",{className:"space-y-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-foreground-subtle",children:"Model"}),(0,r.jsx)("select",{value:s,onChange:v=>f(v.target.value),className:Hr,children:i.length===0?(0,r.jsx)("option",{value:"",children:"No compatible models"}):i.map(v=>(0,r.jsxs)("option",{value:v.id,children:[v.name,v.downloaded?" ✓":""]},v.id))})]})]})}var Vp=class{constructor(){this.keyToValue=new Map,this.valueToKey=new Map}set(e,t){this.keyToValue.set(e,t),this.valueToKey.set(t,e)}getByKey(e){return this.keyToValue.get(e)}getByValue(e){return this.valueToKey.get(e)}clear(){this.keyToValue.clear(),this.valueToKey.clear()}},Mi=class{constructor(e){this.generateIdentifier=e,this.kv=new Vp}register(e,t){this.kv.getByValue(e)||(t||(t=this.generateIdentifier(e)),this.kv.set(t,e))}clear(){this.kv.clear()}getIdentifier(e){return this.kv.getByValue(e)}getValue(e){return this.kv.getByKey(e)}},Wp=class extends Mi{constructor(){super(e=>e.name),this.classToAllowedProps=new Map}register(e,t){typeof t=="object"?(t.allowProps&&this.classToAllowedProps.set(e,t.allowProps),super.register(e,t.identifier)):super.register(e,t)}getAllowedProps(e){return this.classToAllowedProps.get(e)}};function qp(e){if("values"in Object)return Object.values(e);const t=[];for(const s in e)e.hasOwnProperty(s)&&t.push(e[s]);return t}function Kp(e,t){const s=qp(e);if("find"in s)return s.find(t);const n=s;for(let o=0;o<n.length;o++){const a=n[o];if(t(a))return a}}function Ft(e,t){Object.entries(e).forEach(([s,n])=>t(n,s))}function Vr(e,t){return e.indexOf(t)!==-1}function Ei(e,t){for(let s=0;s<e.length;s++){const n=e[s];if(t(n))return n}}var Zp=class{constructor(){this.transfomers={}}register(e){this.transfomers[e.name]=e}findApplicable(e){return Kp(this.transfomers,t=>t.isApplicable(e))}findByName(e){return this.transfomers[e]}},Yp=e=>Object.prototype.toString.call(e).slice(8,-1),Ai=e=>typeof e>"u",Xp=e=>e===null,dr=e=>typeof e!="object"||e===null||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:Object.getPrototypeOf(e)===Object.prototype,on=e=>dr(e)&&Object.keys(e).length===0,ht=e=>Array.isArray(e),Jp=e=>typeof e=="string",eh=e=>typeof e=="number"&&!isNaN(e),th=e=>typeof e=="boolean",rh=e=>e instanceof RegExp,fr=e=>e instanceof Map,mr=e=>e instanceof Set,Pi=e=>Yp(e)==="Symbol",sh=e=>e instanceof Date&&!isNaN(e.valueOf()),Ri=e=>e instanceof Error,Di=e=>typeof e=="number"&&isNaN(e),nh=e=>th(e)||Xp(e)||Ai(e)||eh(e)||Jp(e)||Pi(e),oh=e=>typeof e=="bigint",ah=e=>e===1/0||e===-1/0,ih=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),lh=e=>e instanceof URL,an=e=>e.replace(/\\/g,"\\\\").replace(/\./g,"\\."),ln=e=>e.map(String).map(an).join("."),pr=(e,t)=>{const s=[];let n="";for(let a=0;a<e.length;a++){let i=e.charAt(a);if(!t&&i==="\\"){const l=e.charAt(a+1);if(l==="\\"){n+="\\",a++;continue}else if(l!==".")throw Error("invalid path")}if(i==="\\"&&e.charAt(a+1)==="."){n+=".",a++;continue}if(i==="."){s.push(n),n="";continue}n+=i}const o=n;return s.push(o),s};function tt(e,t,s,n){return{isApplicable:e,annotation:t,transform:s,untransform:n}}var Ti=[tt(Ai,"undefined",()=>null,()=>{}),tt(oh,"bigint",e=>e.toString(),e=>typeof BigInt<"u"?BigInt(e):(console.error("Please add a BigInt polyfill."),e)),tt(sh,"Date",e=>e.toISOString(),e=>new Date(e)),tt(Ri,"Error",(e,t)=>{const s={name:e.name,message:e.message};return"cause"in e&&(s.cause=e.cause),t.allowedErrorProps.forEach(n=>{s[n]=e[n]}),s},(e,t)=>{const s=new Error(e.message,{cause:e.cause});return s.name=e.name,s.stack=e.stack,t.allowedErrorProps.forEach(n=>{s[n]=e[n]}),s}),tt(rh,"regexp",e=>""+e,e=>{const t=e.slice(1,e.lastIndexOf("/")),s=e.slice(e.lastIndexOf("/")+1);return new RegExp(t,s)}),tt(mr,"set",e=>[...e.values()],e=>new Set(e)),tt(fr,"map",e=>[...e.entries()],e=>new Map(e)),tt(e=>Di(e)||ah(e),"number",e=>Di(e)?"NaN":e>0?"Infinity":"-Infinity",Number),tt(e=>e===0&&1/e===-1/0,"number",()=>"-0",Number),tt(lh,"URL",e=>e.toString(),e=>new URL(e))];function Wr(e,t,s,n){return{isApplicable:e,annotation:t,transform:s,untransform:n}}var Ii=Wr((e,t)=>Pi(e)?!!t.symbolRegistry.getIdentifier(e):!1,(e,t)=>["symbol",t.symbolRegistry.getIdentifier(e)],e=>e.description,(e,t,s)=>{const n=s.symbolRegistry.getValue(t[1]);if(!n)throw new Error("Trying to deserialize unknown symbol");return n}),ch=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce((e,t)=>(e[t.name]=t,e),{}),Li=Wr(ih,e=>["typed-array",e.constructor.name],e=>[...e],(e,t)=>{const s=ch[t[1]];if(!s)throw new Error("Trying to deserialize unknown typed array");return new s(e)});function Oi(e,t){return e?.constructor?!!t.classRegistry.getIdentifier(e.constructor):!1}var _i=Wr(Oi,(e,t)=>["class",t.classRegistry.getIdentifier(e.constructor)],(e,t)=>{const s=t.classRegistry.getAllowedProps(e.constructor);if(!s)return{...e};const n={};return s.forEach(o=>{n[o]=e[o]}),n},(e,t,s)=>{const n=s.classRegistry.getValue(t[1]);if(!n)throw new Error(`Trying to deserialize unknown class '${t[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);return Object.assign(Object.create(n.prototype),e)}),$i=Wr((e,t)=>!!t.customTransformerRegistry.findApplicable(e),(e,t)=>["custom",t.customTransformerRegistry.findApplicable(e).name],(e,t)=>t.customTransformerRegistry.findApplicable(e).serialize(e),(e,t,s)=>{const n=s.customTransformerRegistry.findByName(t[1]);if(!n)throw new Error("Trying to deserialize unknown custom value");return n.deserialize(e)}),uh=[_i,Ii,$i,Li],Gi=(e,t)=>{const s=Ei(uh,o=>o.isApplicable(e,t));if(s)return{value:s.transform(e,t),type:s.annotation(e,t)};const n=Ei(Ti,o=>o.isApplicable(e,t));if(n)return{value:n.transform(e,t),type:n.annotation}},Bi={};Ti.forEach(e=>{Bi[e.annotation]=e});var dh=(e,t,s)=>{if(ht(t))switch(t[0]){case"symbol":return Ii.untransform(e,t,s);case"class":return _i.untransform(e,t,s);case"custom":return $i.untransform(e,t,s);case"typed-array":return Li.untransform(e,t,s);default:throw new Error("Unknown transformation: "+t)}else{const n=Bi[t];if(!n)throw new Error("Unknown transformation: "+t);return n.untransform(e,s)}},zt=(e,t)=>{if(t>e.size)throw new Error("index out of bounds");const s=e.keys();for(;t>0;)s.next(),t--;return s.next().value};function Fi(e){if(Vr(e,"__proto__"))throw new Error("__proto__ is not allowed as a property");if(Vr(e,"prototype"))throw new Error("prototype is not allowed as a property");if(Vr(e,"constructor"))throw new Error("constructor is not allowed as a property")}var fh=(e,t)=>{Fi(t);for(let s=0;s<t.length;s++){const n=t[s];if(mr(e))e=zt(e,+n);else if(fr(e)){const o=+n,a=+t[++s]==0?"key":"value",i=zt(e,o);switch(a){case"key":e=i;break;case"value":e=e.get(i);break}}else e=e[n]}return e},cn=(e,t,s)=>{if(Fi(t),t.length===0)return s(e);let n=e;for(let a=0;a<t.length-1;a++){const i=t[a];if(ht(n)){const l=+i;n=n[l]}else if(dr(n))n=n[i];else if(mr(n)){const l=+i;n=zt(n,l)}else if(fr(n)){if(a===t.length-2)break;const l=+i,u=+t[++a]==0?"key":"value",d=zt(n,l);switch(u){case"key":n=d;break;case"value":n=n.get(d);break}}}const o=t[t.length-1];if(ht(n)?n[+o]=s(n[+o]):dr(n)&&(n[o]=s(n[o])),mr(n)){const a=zt(n,+o),i=s(a);a!==i&&(n.delete(a),n.add(i))}if(fr(n)){const a=+t[t.length-2],i=zt(n,a);switch(+o==0?"key":"value"){case"key":{const l=s(i);n.set(l,n.get(i)),l!==i&&n.delete(i);break}case"value":n.set(i,s(n.get(i)));break}}return e},zi=e=>e<1;function un(e,t,s,n=[]){if(!e)return;const o=zi(s);if(!ht(e)){Ft(e,(l,u)=>un(l,t,s,[...n,...pr(u,o)]));return}const[a,i]=e;i&&Ft(i,(l,u)=>{un(l,t,s,[...n,...pr(u,o)])}),t(a,n)}function mh(e,t,s,n){return un(t,(o,a)=>{e=cn(e,a,i=>dh(i,o,n))},s),e}function ph(e,t,s){const n=zi(s);function o(a,i){const l=fh(e,pr(i,n));a.map(u=>pr(u,n)).forEach(u=>{e=cn(e,u,()=>l)})}if(ht(t)){const[a,i]=t;a.forEach(l=>{e=cn(e,pr(l,n),()=>e)}),i&&Ft(i,o)}else Ft(t,o);return e}var hh=(e,t)=>dr(e)||ht(e)||fr(e)||mr(e)||Ri(e)||Oi(e,t);function gh(e,t,s){const n=s.get(e);n?n.push(t):s.set(e,[t])}function bh(e,t){const s={};let n;return e.forEach(o=>{if(o.length<=1)return;t||(o=o.map(l=>l.map(String)).sort((l,u)=>l.length-u.length));const[a,...i]=o;a.length===0?n=i.map(ln):s[ln(a)]=i.map(ln)}),n?on(s)?[n]:[n,s]:on(s)?void 0:s}var Qi=(e,t,s,n,o=[],a=[],i=new Map)=>{const l=nh(e);if(!l){gh(e,o,t);const b=i.get(e);if(b)return n?{transformedValue:null}:b}if(!hh(e,s)){const b=Gi(e,s),x=b?{transformedValue:b.value,annotations:[b.type]}:{transformedValue:e};return l||i.set(e,x),x}if(Vr(a,e))return{transformedValue:null};const u=Gi(e,s),d=u?.value??e,f=ht(d)?[]:{},p={};Ft(d,(b,x)=>{if(x==="__proto__"||x==="constructor"||x==="prototype")throw new Error(`Detected property ${x}. This is a prototype pollution risk, please remove it from your object.`);const v=Qi(b,t,s,n,[...o,x],[...a,e],i);f[x]=v.transformedValue,ht(v.annotations)?p[an(x)]=v.annotations:dr(v.annotations)&&Ft(v.annotations,(w,y)=>{p[an(x)+"."+y]=w})});const g=on(p)?{transformedValue:f,annotations:u?[u.type]:void 0}:{transformedValue:f,annotations:u?[u.type,p]:p};return l||i.set(e,g),g};function Ui(e){return Object.prototype.toString.call(e).slice(8,-1)}function Hi(e){return Ui(e)==="Array"}function xh(e){if(Ui(e)!=="Object")return!1;const t=Object.getPrototypeOf(e);return!!t&&t.constructor===Object&&t===Object.prototype}function vh(e,t,s,n,o){const a={}.propertyIsEnumerable.call(n,t)?"enumerable":"nonenumerable";a==="enumerable"&&(e[t]=s),o&&a==="nonenumerable"&&Object.defineProperty(e,t,{value:s,enumerable:!1,writable:!0,configurable:!0})}function dn(e,t={}){if(Hi(e))return e.map(o=>dn(o,t));if(!xh(e))return e;const s=Object.getOwnPropertyNames(e),n=Object.getOwnPropertySymbols(e);return[...s,...n].reduce((o,a)=>{if(a==="__proto__"||Hi(t.props)&&!t.props.includes(a))return o;const i=e[a];return vh(o,a,dn(i,t),e,t.nonenumerable),o},{})}var ie=class{constructor({dedupe:e=!1}={}){this.classRegistry=new Wp,this.symbolRegistry=new Mi(t=>t.description??""),this.customTransformerRegistry=new Zp,this.allowedErrorProps=[],this.dedupe=e}serialize(e){const t=new Map,s=Qi(e,t,this,this.dedupe),n={json:s.transformedValue};s.annotations&&(n.meta={...n.meta,values:s.annotations});const o=bh(t,this.dedupe);return o&&(n.meta={...n.meta,referentialEqualities:o}),n.meta&&(n.meta.v=1),n}deserialize(e,t){const{json:s,meta:n}=e;let o=t?.inPlace?s:dn(s);return n?.values&&(o=mh(o,n.values,n.v??0,this)),n?.referentialEqualities&&(o=ph(o,n.referentialEqualities,n.v??0)),o}stringify(e){return JSON.stringify(this.serialize(e))}parse(e){return this.deserialize(JSON.parse(e),{inPlace:!0})}registerClass(e,t){this.classRegistry.register(e,t)}registerSymbol(e,t){this.symbolRegistry.register(e,t)}registerCustom(e,t){this.customTransformerRegistry.register({name:t,...e})}allowErrorProps(...e){this.allowedErrorProps.push(...e)}};ie.defaultInstance=new ie,ie.serialize=ie.defaultInstance.serialize.bind(ie.defaultInstance),ie.deserialize=ie.defaultInstance.deserialize.bind(ie.defaultInstance),ie.stringify=ie.defaultInstance.stringify.bind(ie.defaultInstance),ie.parse=ie.defaultInstance.parse.bind(ie.defaultInstance),ie.registerClass=ie.defaultInstance.registerClass.bind(ie.defaultInstance),ie.registerSymbol=ie.defaultInstance.registerSymbol.bind(ie.defaultInstance),ie.registerCustom=ie.defaultInstance.registerCustom.bind(ie.defaultInstance),ie.allowErrorProps=ie.defaultInstance.allowErrorProps.bind(ie.defaultInstance),ie.serialize,ie.deserialize,ie.stringify,ie.parse,ie.registerClass,ie.registerCustom,ie.registerSymbol,ie.allowErrorProps;function yh({className:e}){return(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[(0,r.jsx)("path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function wh({className:e}){return(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[(0,r.jsx)("path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"}),(0,r.jsx)("path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}),(0,r.jsx)("path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"}),(0,r.jsx)("path",{d:"m2 2 20 20"})]})}function Sh({className:e}){return(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function Vi({onLogin:e,serverUrl:t,logoSrc:s,error:n,className:o}){const[a,i]=(0,h.useState)(""),[l,u]=(0,h.useState)(""),[d,f]=(0,h.useState)(!1),[p,g]=(0,h.useState)(!1),[b,x]=(0,h.useState)(null),v=n??b,w=async y=>{if(y.preventDefault(),!p){x(null),g(!0);try{await e(a,l)}catch(S){x(S instanceof Error?S.message:"Login failed. Please try again.")}finally{g(!1)}}};return(0,r.jsx)("div",{className:j("flex min-h-screen items-center justify-center bg-background p-4",o),children:(0,r.jsxs)("div",{className:"w-full max-w-sm",children:[s&&(0,r.jsx)("div",{className:"flex justify-center mb-8",children:(0,r.jsx)("img",{src:s,alt:"Logo",className:"h-12"})}),t&&(0,r.jsx)("p",{className:"mb-4 text-center text-xs text-foreground-subtle truncate",children:t}),(0,r.jsxs)("form",{onSubmit:w,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[v&&(0,r.jsx)("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:v}),(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("label",{className:"text-xs font-medium text-foreground-subtle",children:"Username"}),(0,r.jsx)("input",{type:"text",value:a,onChange:y=>i(y.target.value),autoComplete:"username",required:!0,className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary"})]}),(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("label",{className:"text-xs font-medium text-foreground-subtle",children:"Password"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("input",{type:d?"text":"password",value:l,onChange:y=>u(y.target.value),autoComplete:"current-password",required:!0,className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary"}),(0,r.jsx)("button",{type:"button",onClick:()=>f(y=>!y),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",tabIndex:-1,children:d?(0,r.jsx)(wh,{className:"h-4 w-4"}):(0,r.jsx)(yh,{className:"h-4 w-4"})})]})]}),(0,r.jsxs)("button",{type:"submit",disabled:p,className:"w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center justify-center gap-2",children:[p&&(0,r.jsx)(Sh,{className:"h-4 w-4 animate-spin"}),p?"Logging in...":"Log in"]})]})]})})}var fn="camstack_dev_token",Wi=(0,h.createContext)(null);function kh(){const e=(0,h.useContext)(Wi);if(!e)throw new Error("useDevShell must be used within a DevShell");return e}function jh(){return typeof window>"u"?null:localStorage.getItem(fn)}function Nh({className:e}){return(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,r.jsx)("path",{d:"M12 2v2"}),(0,r.jsx)("path",{d:"M12 20v2"}),(0,r.jsx)("path",{d:"m4.93 4.93 1.41 1.41"}),(0,r.jsx)("path",{d:"m17.66 17.66 1.41 1.41"}),(0,r.jsx)("path",{d:"M2 12h2"}),(0,r.jsx)("path",{d:"M20 12h2"}),(0,r.jsx)("path",{d:"m6.34 17.66-1.41 1.41"}),(0,r.jsx)("path",{d:"m19.07 4.93-1.41 1.41"})]})}function Ch({className:e}){return(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:(0,r.jsx)("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})})}function Mh({children:e,serverUrl:t,title:s,token:n,onLogout:o}){const a=Ge.useThemeMode$1(),i=(0,h.useMemo)(()=>[(0,Te.splitLink)({condition:g=>g.type==="subscription",true:(0,Te.wsLink)({client:(0,Te.createWSClient)({url:t.replace(/^http/,"ws")+"/trpc",connectionParams:()=>({token:n})}),transformer:ie}),false:(0,Te.httpLink)({url:`${t}/trpc`,transformer:ie,headers:()=>({authorization:`Bearer ${n}`})})})],[t,n]),l=(0,h.useMemo)(()=>(0,Te.createTRPCClient)({links:i}),[i]),u=(0,h.useMemo)(()=>m.createClient({links:i}),[i]),d=(0,h.useMemo)(()=>(0,ns.createSystem)({serverUrl:t,token:n}),[t,n]);(0,h.useEffect)(()=>(d.init().catch(()=>{}),()=>{d.close()}),[d]);const f=(0,h.useMemo)(()=>new Ee.QueryClient,[]),p=(0,h.useMemo)(()=>({trpc:l,token:n,logout:o}),[l,n,o]);return(0,r.jsx)(Za,{system:d,children:(0,r.jsx)(m.Provider,{client:u,queryClient:f,children:(0,r.jsx)(Ee.QueryClientProvider,{client:f,children:(0,r.jsx)(Wi.Provider,{value:p,children:(0,r.jsxs)("div",{className:"min-h-screen bg-background text-foreground",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between border-b border-border bg-surface px-4 py-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"rounded bg-warning/20 px-2 py-0.5 text-xs font-bold text-warning",children:"DEV MODE"}),s&&(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:s}),(0,r.jsx)("span",{className:"text-xs text-foreground-subtle",children:t})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("button",{type:"button",onClick:a.toggleMode,className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",title:`Theme: ${a.mode}`,children:[a.resolvedMode==="dark"?(0,r.jsx)(Nh,{className:"h-3.5 w-3.5"}):(0,r.jsx)(Ch,{className:"h-3.5 w-3.5"}),a.mode==="dark"?"Dark":a.mode==="light"?"Light":"System"]}),(0,r.jsx)("button",{type:"button",onClick:o,className:"rounded-md px-2.5 py-1 text-xs font-medium text-danger hover:bg-danger/10 transition-colors",children:"Logout"})]})]}),(0,r.jsx)("div",{className:"p-4",children:e({trpc:l,theme:a})})]})})})})})}function qi({children:e,serverUrl:t="https://localhost:4443",title:s}){const[n,o]=(0,h.useState)(jh),a=(0,h.useCallback)(async(l,u)=>{const d=await(0,Te.createTRPCClient)({links:[(0,Te.httpLink)({url:`${t}/trpc`,transformer:ie})]}).auth.login.mutate({username:l,password:u});if(!d.token)throw new Error("No token returned");localStorage.setItem(fn,d.token),o(d.token)},[t]),i=(0,h.useCallback)(()=>{localStorage.removeItem(fn),o(null)},[]);return n?(0,r.jsx)(Ge.ThemeProvider$1,{children:(0,r.jsx)(Mh,{serverUrl:t,title:s,token:n,onLogout:i,children:e})}):(0,r.jsx)(Ge.ThemeProvider$1,{children:(0,r.jsx)(Vi,{onLogin:a,serverUrl:t})})}function Eh(e,t={}){const{serverUrl:s="https://localhost:4443",title:n,rootId:o="root"}=t,a=document.getElementById(o);if(!a){console.error(`[mountAddonPage] Element #${o} not found`);return}(0,bt.createRoot)(a).render((0,h.createElement)(qi,{serverUrl:s,title:n,children:({trpc:i,theme:l})=>(0,h.createElement)(e,{trpc:i,theme:{isDark:l.resolvedMode==="dark"},navigate:u=>{console.log("[dev] navigate:",u)}})}))}var Ki=ot("camstack:custom-field-renderers",{});function Ah({renderers:e,children:t}){return(0,r.jsx)(Ki.Provider,{value:e,children:t})}function Zi(e){return(0,h.useContext)(Ki)[e]??null}var mn=ot("camstack:device-context",null);function Ph({deviceId:e,device:t,children:s}){const n={deviceId:e,device:t??null};return(0,r.jsx)(mn.Provider,{value:n,children:s})}function Yi(){return(0,h.useContext)(mn)?.deviceId??null}function Rh(){return(0,h.useContext)(mn)?.device??null}var Dh=m.accessories.getStatus.useQuery,Th=m.addonPages.listPages.useQuery,Ih=m.addons.list.useQuery,Lh=m.addons.getLogs.useQuery,Oh=m.addons.listPackages.useQuery,_h=m.addons.installPackage.useMutation,$h=m.addons.installFromWorkspace.useMutation,Gh=m.addons.isWorkspaceAvailable.useQuery,Bh=m.addons.listWorkspacePackages.useQuery,Fh=m.addons.uninstallPackage.useMutation,zh=m.addons.reloadPackages.useMutation,Qh=m.addons.searchAvailable.useQuery,Uh=m.addons.listUpdates.useQuery,Hh=m.addons.updatePackage.useMutation,Vh=m.addons.rollbackPackage.useMutation,Wh=m.addons.forceRefresh.useMutation,qh=m.addons.restartServer.useMutation,Kh=m.addons.getVersions.useQuery,Zh=m.addons.restartAddon.useMutation,Yh=m.addons.retryLoad.useMutation,Xh=m.addons.getAutoUpdateSettings.useQuery,Jh=m.addons.setAutoUpdateSettings.useMutation,eg=m.addons.getAddonAutoUpdate.useQuery,tg=m.addons.setAddonAutoUpdate.useMutation,rg=m.addons.applyAutoUpdateToAll.useMutation,sg=m.addons.custom.useMutation,ng=m.addons.onAddonLogs.useSubscription,og=m.addonSettings.getGlobalSettings.useQuery,ag=m.addonSettings.updateGlobalSettings.useMutation,ig=m.addonSettings.getDeviceSettings.useQuery,lg=m.addonSettings.updateDeviceSettings.useMutation,Xi=m.addonWidgets.listWidgets.useQuery,cg=m.alerts.emit.useMutation,ug=m.alerts.update.useMutation,dg=m.alerts.list.useQuery,fg=m.alerts.getUnreadCount.useQuery,mg=m.alerts.markRead.useMutation,pg=m.alerts.markAllRead.useMutation,hg=m.alerts.dismiss.useMutation,gg=m.audioAnalysis.resolveDeviceSettings.useQuery,bg=m.audioAnalysis.getDeviceSettingsContribution.useQuery,xg=m.audioAnalysis.getDeviceLiveContribution.useQuery,vg=m.audioAnalysis.applyDeviceSettingsPatch.useMutation,yg=m.audioAnalyzer.analyseChunk.useMutation,wg=m.audioAnalyzer.classify.useQuery,Sg=m.audioAnalyzer.isReady.useQuery,kg=m.audioAnalyzer.dispose.useMutation,jg=m.audioAnalyzer.reprobeAudioEngine.useMutation,Ng=m.audioCodec.listSupportedCodecs.useQuery,Cg=m.audioCodec.canHandle.useQuery,Mg=m.audioCodec.createDecodeSession.useMutation,Eg=m.audioCodec.createEncodeSession.useMutation,Ag=m.audioCodec.closeSession.useMutation,Pg=m.audioCodec.pushEncodedFrame.useMutation,Rg=m.audioCodec.pullPcm.useQuery,Dg=m.audioCodec.pushPcm.useMutation,Tg=m.audioCodec.pullEncoded.useQuery,Ig=m.audioCodec.flushEncode.useMutation,Lg=m.audioCodec.listActiveSessions.useQuery,Og=m.audioMetrics.getCurrentSnapshot.useQuery,_g=m.audioMetrics.getHistory.useQuery,$g=m.authentication.listProviders.useQuery,Gg=m.authentication.setProviderEnabled.useMutation,Bg=m.backup.listDestinations.useQuery,Fg=m.backup.trigger.useMutation,zg=m.backup.list.useQuery,Qg=m.backup.listLocations.useQuery,Ug=m.backup.getEntries.useQuery,Hg=m.backup.restore.useMutation,Vg=m.backup.delete.useMutation,Wg=m.backup.listArchives.useQuery,qg=m.backup.upsertDestinationPolicy.useMutation,Kg=m.backup.previewSchedule.useQuery,Zg=m.battery.getStatus.useQuery,Yg=m.brightness.setBrightness.useMutation,Xg=m.brightness.getStatus.useQuery,Jg=m.cameraStreams.getCameraStreams.useQuery,e0=m.cameraStreams.getBrokerStreams.useQuery,t0=m.cameraStreams.getRtspEntries.useQuery,r0=m.decoder.supportsCodec.useQuery,s0=m.decoder.getInfo.useQuery,n0=m.decoder.createSession.useQuery,o0=m.decoder.destroySession.useQuery,a0=m.decoder.pushPacket.useQuery,i0=m.decoder.openStream.useQuery,l0=m.decoder.pullFrames.useQuery,c0=m.decoder.updateConfig.useQuery,u0=m.decoder.getStats.useQuery,d0=m.decoder.listActiveSessions.useQuery,f0=m.decoder.reprobeHwaccel.useMutation,m0=m.detectionPipeline.getDeviceSettingsContribution.useQuery,p0=m.detectionPipeline.getDeviceLiveContribution.useQuery,h0=m.detectionPipeline.applyDeviceSettingsPatch.useMutation,g0=m.deviceDiscovery.listDiscovered.useQuery,b0=m.deviceDiscovery.refreshDiscovery.useMutation,x0=m.deviceDiscovery.adoptDevice.useMutation,v0=m.deviceDiscovery.releaseDevice.useMutation,y0=m.deviceDiscovery.getStatus.useQuery,w0=m.deviceManager.allocateDeviceId.useMutation,S0=m.deviceManager.registerDevice.useMutation,k0=m.deviceManager.removeDevice.useMutation,j0=m.deviceManager.persistConfig.useMutation,N0=m.deviceManager.loadConfig.useQuery,C0=m.deviceManager.loadRuntimeState.useQuery,M0=m.deviceManager.loadMeta.useQuery,E0=m.deviceManager.setName.useMutation,A0=m.deviceManager.setLocation.useMutation,P0=m.deviceManager.setMetadata.useMutation,R0=m.deviceManager.listLocations.useQuery,D0=m.deviceManager.addLocation.useMutation,T0=m.deviceManager.removeLocation.useMutation,I0=m.deviceManager.setDisabled.useMutation,L0=m.deviceManager.listPersistedByAddon.useQuery,O0=m.deviceManager.listAll.useQuery,_0=m.deviceManager.getDevice.useQuery,$0=m.deviceManager.getChildren.useQuery,G0=m.deviceManager.getStreamSources.useQuery,B0=m.deviceManager.getConfigSchema.useQuery,F0=m.deviceManager.getSettingsSchema.useQuery,z0=m.deviceManager.updateConfig.useMutation,Q0=m.deviceManager.enable.useMutation,U0=m.deviceManager.disable.useMutation,H0=m.deviceManager.remove.useMutation,V0=m.deviceManager.getStreamProfileMap.useQuery,W0=m.deviceManager.setStreamProfileMap.useMutation,q0=m.deviceManager.probeStreams.useMutation,K0=m.deviceManager.getBindings.useQuery,Z0=m.deviceManager.getAllBindings.useQuery,Y0=m.deviceManager.setWrapperActive.useMutation,X0=m.deviceManager.listWrappersForCap.useQuery,J0=m.deviceManager.listBindableCapsForDeviceType.useQuery,eb=m.deviceManager.getDeviceSettingsAggregate.useQuery,tb=m.deviceManager.getDeviceLiveInfoAggregate.useQuery,rb=m.deviceManager.getDeviceAggregate.useQuery,sb=m.deviceManager.updateDeviceField.useMutation,nb=m.deviceManager.updateDeviceFieldsBatch.useMutation,ob=m.deviceManager.discoverDevices.useMutation,ab=m.deviceManager.adoptDevice.useMutation,ib=m.deviceManager.getCreationSchema.useQuery,lb=m.deviceManager.createDevice.useMutation,cb=m.deviceManager.testCreationField.useMutation,ub=m.deviceManager.testField.useMutation,db=m.deviceManager.getDeviceStatusAggregate.useQuery,fb=m.deviceOps.getStreamSources.useQuery,mb=m.deviceOps.getConfigEntries.useQuery,pb=m.deviceOps.setConfig.useMutation,hb=m.deviceOps.removeDevice.useMutation,gb=m.deviceOps.getSettingsSchema.useQuery,bb=m.deviceProvider.start.useMutation,xb=m.deviceProvider.stop.useMutation,vb=m.deviceProvider.getStatus.useQuery,yb=m.deviceProvider.getDevices.useQuery,wb=m.deviceProvider.supportsDiscovery.useQuery,Sb=m.deviceProvider.discoverDevices.useMutation,kb=m.deviceProvider.adoptDiscoveredDevice.useMutation,jb=m.deviceProvider.supportsManualCreation.useQuery,Nb=m.deviceProvider.getChildCreationSchema.useQuery,Cb=m.deviceProvider.createDevice.useMutation,Mb=m.deviceProvider.testCreationField.useMutation,Eb=m.deviceState.getSnapshot.useQuery,Ab=m.deviceState.getCapSlice.useQuery,Pb=m.deviceState.getAllSnapshots.useQuery,Rb=m.deviceState.setCapSlice.useMutation,Db=m.doorbell.getStatus.useQuery,Tb=m.events.getEvents.useQuery,Ib=m.events.getEventThumbnail.useQuery,Lb=m.events.getEventClipUrl.useQuery,Ob=m.integrations.list.useQuery,_b=m.integrations.get.useQuery,$b=m.integrations.getByAddonId.useQuery,Gb=m.integrations.create.useMutation,Bb=m.integrations.update.useMutation,Fb=m.integrations.delete.useMutation,zb=m.integrations.getSettings.useQuery,Qb=m.integrations.setSettings.useMutation,Ub=m.integrations.getAvailableTypes.useQuery,Hb=m.integrations.testConnection.useMutation,Vb=m.intercom.startSession.useMutation,Wb=m.intercom.handleAnswer.useMutation,qb=m.intercom.stopSession.useMutation,Kb=m.intercom.getStatus.useQuery,Zb=m.localNetwork.list.useQuery,Yb=m.localNetwork.getPreferred.useQuery,Xb=m.localNetwork.getConnectionEndpoints.useQuery,Jb=m.localNetwork.getAllowedAddresses.useQuery,ex=m.localNetwork.setAllowedAddresses.useMutation,tx=m.localNetwork.resetAllowlistToBestMatch.useMutation,rx=m.meshOrchestrator.listProviders.useQuery,sx=m.meshOrchestrator.joinProvider.useMutation,nx=m.meshOrchestrator.leaveProvider.useMutation,ox=m.metricsProvider.collectSnapshot.useQuery,ax=m.metricsProvider.getCached.useQuery,ix=m.metricsProvider.getCurrent.useQuery,lx=m.metricsProvider.getDiskSpace.useQuery,cx=m.metricsProvider.getGpuInfo.useQuery,ux=m.metricsProvider.getCpuTemperature.useQuery,dx=m.metricsProvider.getProcessStats.useQuery,fx=m.metricsProvider.listAddonInstances.useQuery,mx=m.metricsProvider.getAddonStats.useQuery,px=m.metricsProvider.listNodeProcesses.useQuery,hx=m.metricsProvider.killProcess.useMutation,gx=m.motion.isDetected.useQuery,bx=m.motion.getStatus.useQuery,xx=m.motionDetection.analyze.useMutation,vx=m.motionDetection.removeCamera.useMutation,yx=m.motionDetection.reset.useMutation,wx=m.motionDetection.getDeviceSettingsContribution.useQuery,Sx=m.motionDetection.getDeviceLiveContribution.useQuery,kx=m.motionDetection.applyDeviceSettingsPatch.useMutation,jx=m.motionTrigger.setMotionTrigger.useMutation,Nx=m.motionTrigger.getStatus.useQuery,Cx=m.nativeObjectDetection.getStatus.useQuery,Mx=m.networkQuality.getDeviceStats.useQuery,Ex=m.networkQuality.getAllStats.useQuery,Ax=m.networkQuality.reportClientStats.useMutation,Px=m.nodes.topology.useQuery,Rx=m.nodes.deployAddon.useMutation,Dx=m.nodes.undeployAddon.useMutation,Tx=m.nodes.restartAddon.useMutation,Ix=m.nodes.restartProcess.useMutation,Lx=m.nodes.restartNode.useMutation,Ox=m.nodes.shutdownNode.useMutation,_x=m.nodes.renameNode.useMutation,$x=m.nodes.clusterAddonStatus.useQuery,Gx=m.nodes.setProcessLogLevel.useMutation,Bx=m.nodes.executeQuery.useMutation,Fx=m.notificationOutput.send.useMutation,zx=m.notificationOutput.sendTest.useMutation,Qx=m.osd.setOverlay.useMutation,Ux=m.osd.getStatus.useQuery,Hx=m.pipelineAnalytics.getActiveTracks.useQuery,Vx=m.pipelineAnalytics.getTrack.useQuery,Wx=m.pipelineAnalytics.listTracks.useQuery,qx=m.pipelineAnalytics.clearTracks.useMutation,Kx=m.pipelineAnalytics.getMotionEvents.useQuery,Zx=m.pipelineAnalytics.getObjectEvents.useQuery,Yx=m.pipelineAnalytics.getAudioEvents.useQuery,Xx=m.pipelineAnalytics.getEventMedia.useQuery,Jx=m.pipelineAnalytics.getTrackMedia.useQuery,ev=m.pipelineAnalytics.getDeviceSettingsContribution.useQuery,tv=m.pipelineAnalytics.getDeviceLiveContribution.useQuery,rv=m.pipelineAnalytics.applyDeviceSettingsPatch.useMutation,sv=m.pipelineExecutor.getAvailableEngines.useQuery,nv=m.pipelineExecutor.getSelectedEngine.useQuery,ov=m.pipelineExecutor.getDefaultSteps.useQuery,av=m.pipelineExecutor.reprobeEngine.useMutation,iv=m.pipelineExecutor.getVideoPipelineSteps.useQuery,lv=m.pipelineExecutor.setVideoPipelineSteps.useMutation,cv=m.pipelineExecutor.getSchema.useQuery,uv=m.pipelineExecutor.getGlobalSteps.useQuery,dv=m.pipelineExecutor.getGlobalPipelineConfig.useQuery,fv=m.pipelineExecutor.getOrchestratorConfigSchema.useQuery,mv=m.pipelineExecutor.listTemplates.useQuery,pv=m.pipelineExecutor.saveTemplate.useMutation,hv=m.pipelineExecutor.updateTemplate.useMutation,gv=m.pipelineExecutor.deleteTemplate.useMutation,bv=m.pipelineExecutor.getCapabilities.useQuery,xv=m.pipelineExecutor.getAddonModels.useQuery,vv=m.pipelineExecutor.downloadModel.useMutation,yv=m.pipelineExecutor.deleteModel.useMutation,wv=m.pipelineExecutor.detect.useQuery,Sv=m.pipelineExecutor.runPipeline.useMutation,kv=m.pipelineExecutor.runPipelineBatch.useMutation,jv=m.pipelineExecutor.cacheFrameInPool.useMutation,Nv=m.pipelineExecutor.inferCached.useMutation,Cv=m.pipelineExecutor.uncacheFrame.useMutation,Mv=m.pipelineExecutor.getEffectiveTuning.useQuery,Ev=m.pipelineExecutor.listLoadedEngines.useQuery,Av=m.pipelineExecutor.spinEngine.useMutation,Pv=m.pipelineExecutor.killEngine.useMutation,Rv=m.pipelineExecutor.listReferenceImages.useQuery,Dv=m.pipelineExecutor.getReferenceImage.useQuery,Tv=m.pipelineExecutor.getReferenceAudioFiles.useQuery,Iv=m.pipelineExecutor.getReferenceAudio.useQuery,Lv=m.pipelineExecutor.getAudioCapabilities.useQuery,Ov=m.pipelineExecutor.runAudioTest.useMutation,_v=m.pipelineExecutor.getDetectionConfigSchema.useQuery,$v=m.pipelineOrchestrator.assignPipeline.useMutation,Gv=m.pipelineOrchestrator.unassignPipeline.useMutation,Bv=m.pipelineOrchestrator.rebalance.useMutation,Fv=m.pipelineOrchestrator.getPipelineAssignments.useQuery,zv=m.pipelineOrchestrator.getPipelineAssignment.useQuery,Qv=m.pipelineOrchestrator.getAgentLoad.useQuery,Uv=m.pipelineOrchestrator.getGlobalMetrics.useQuery,Hv=m.pipelineOrchestrator.getCameraMetrics.useQuery,Vv=m.pipelineOrchestrator.getCapabilityBindings.useQuery,Wv=m.pipelineOrchestrator.setCapabilityBinding.useMutation,qv=m.pipelineOrchestrator.assignDecoder.useMutation,Kv=m.pipelineOrchestrator.unassignDecoder.useMutation,Zv=m.pipelineOrchestrator.getDecoderAssignments.useQuery,Yv=m.pipelineOrchestrator.assignAudio.useMutation,Xv=m.pipelineOrchestrator.unassignAudio.useMutation,Jv=m.pipelineOrchestrator.getAudioAssignment.useQuery,ey=m.pipelineOrchestrator.getAudioNodeLoad.useQuery,ty=m.pipelineOrchestrator.getAudioAssignments.useQuery,ry=m.pipelineOrchestrator.getDecoderAssignment.useQuery,sy=m.pipelineOrchestrator.getAgentSettings.useQuery,ny=m.pipelineOrchestrator.listAgentSettings.useQuery,oy=m.pipelineOrchestrator.setAgentAddonDefaults.useMutation,ay=m.pipelineOrchestrator.removeAgentSettings.useMutation,iy=m.pipelineOrchestrator.getCameraSettings.useQuery,ly=m.pipelineOrchestrator.setCameraStepToggle.useMutation,cy=m.pipelineOrchestrator.getCameraStepOverrides.useQuery,uy=m.pipelineOrchestrator.setCameraStepOverride.useMutation,dy=m.pipelineOrchestrator.setCameraPipelineForAgent.useMutation,fy=m.pipelineOrchestrator.resolvePipeline.useQuery,my=m.pipelineOrchestrator.listTemplates.useQuery,py=m.pipelineOrchestrator.saveTemplate.useMutation,hy=m.pipelineOrchestrator.updateTemplate.useMutation,gy=m.pipelineOrchestrator.deleteTemplate.useMutation,by=m.pipelineOrchestrator.getDeviceSettingsContribution.useQuery,xy=m.pipelineOrchestrator.getDeviceLiveContribution.useQuery,vy=m.pipelineOrchestrator.applyDeviceSettingsPatch.useMutation,yy=m.pipelineRunner.attachCamera.useMutation,wy=m.pipelineRunner.detachCamera.useMutation,Sy=m.pipelineRunner.reportMotion.useMutation,ky=m.pipelineRunner.getLocalLoad.useQuery,jy=m.pipelineRunner.getLocalMetrics.useQuery,Ny=m.pipelineRunner.getCameraMetrics.useQuery,Cy=m.pipelineRunner.getAllCameraMetrics.useQuery,My=m.pipelineRunner.getLocalCameras.useQuery,Ey=m.platformProbe.getCapabilities.useQuery,Ay=m.platformProbe.getHardware.useQuery,Py=m.platformProbe.resolveInferenceConfig.useQuery,Ry=m.platformProbe.resolveHwAccel.useQuery,Dy=m.ptz.move.useMutation,Ty=m.ptz.continuousMove.useMutation,Iy=m.ptz.stop.useMutation,Ly=m.ptz.getPresets.useQuery,Oy=m.ptz.goToPreset.useMutation,_y=m.ptz.goHome.useMutation,$y=m.ptz.getPosition.useQuery,Gy=m.ptz.getStatus.useQuery,By=m.ptzAutotrack.getStatus.useQuery,Fy=m.ptzAutotrack.setEnabled.useMutation,zy=m.ptzAutotrack.getSettings.useQuery,Qy=m.ptzAutotrack.setSettings.useMutation,Uy=m.reboot.reboot.useMutation,Hy=m.recording.getSegments.useQuery,Vy=m.recording.getPlaybackUrl.useQuery,Wy=m.recording.getThumbnailAt.useQuery,qy=m.recordingEngine.getStatus.useQuery,Ky=m.recordingEngine.enable.useMutation,Zy=m.recordingEngine.disable.useMutation,Yy=m.recordingEngine.getConfig.useQuery,Xy=m.recordingEngine.updateConfig.useMutation,Jy=m.recordingEngine.getPlaylist.useQuery,e1=m.recordingEngine.getThumbnail.useQuery,t1=m.recordingEngine.getSegments.useQuery,r1=m.recordingEngine.getAvailability.useQuery,s1=m.recordingEngine.estimateStorage.useQuery,n1=m.recordingEngine.estimateGlobalStorage.useQuery,o1=m.recordingEngine.getStorageUsage.useQuery,a1=m.recordingEngine.setPolicy.useMutation,i1=m.recordingEngine.getPolicy.useQuery,l1=m.recordingEngine.getPolicyStatus.useQuery,c1=m.recordingEngine.getRetentionConfig.useQuery,u1=m.recordingEngine.updateRetentionConfig.useMutation,d1=m.recordingEngine.getMotionStats.useQuery,f1=m.remoteAccess.listProviders.useQuery,m1=m.remoteAccess.startProvider.useMutation,p1=m.remoteAccess.stopProvider.useMutation,h1=m.settingsStore.get.useQuery,g1=m.settingsStore.set.useMutation,b1=m.settingsStore.query.useQuery,x1=m.settingsStore.insert.useMutation,v1=m.settingsStore.update.useMutation,y1=m.settingsStore.delete.useMutation,w1=m.settingsStore.count.useQuery,S1=m.settingsStore.isEmpty.useQuery,k1=m.settingsStore.declareCollection.useMutation,j1=m.snapshot.getSnapshot.useQuery,N1=m.snapshot.invalidateCache.useMutation,C1=m.snapshot.getStatus.useQuery,M1=m.snapshot.getDeviceSettingsContribution.useQuery,E1=m.snapshot.getDeviceLiveContribution.useQuery,A1=m.snapshot.applyDeviceSettingsPatch.useMutation,P1=m.snapshotProvider.supportsDevice.useQuery,R1=m.snapshotProvider.getSnapshot.useQuery,D1=m.storage.resolve.useQuery,T1=m.storage.write.useMutation,I1=m.storage.read.useQuery,L1=m.storage.exists.useQuery,O1=m.storage.list.useQuery,_1=m.storage.delete.useMutation,$1=m.storage.getAvailableSpace.useQuery,G1=m.storage.beginUpload.useMutation,B1=m.storage.writeChunk.useMutation,F1=m.storage.finalizeUpload.useMutation,z1=m.storage.abortUpload.useMutation,Q1=m.storage.beginDownload.useMutation,U1=m.storage.readChunk.useQuery,H1=m.storage.endDownload.useMutation,V1=m.storage.listLocations.useQuery,W1=m.storage.getDefaultLocation.useQuery,q1=m.storage.upsertLocation.useMutation,K1=m.storage.deleteLocation.useMutation,Z1=m.storage.testLocation.useQuery,Y1=m.storage.listProviders.useQuery,X1=m.storage.testConfig.useQuery,J1=m.streamBroker.publishCameraStream.useMutation,ew=m.streamBroker.retractCameraStream.useMutation,tw=m.streamBroker.assignProfile.useMutation,rw=m.streamBroker.unassignProfile.useMutation,sw=m.streamBroker.listAllCameraStreams.useQuery,nw=m.streamBroker.listAllProfileSlots.useQuery,ow=m.streamBroker.getBrokerStats.useQuery,aw=m.streamBroker.listClients.useQuery,iw=m.streamBroker.killClient.useMutation,lw=m.streamBroker.restartProfile.useMutation,cw=m.streamBroker.getStreamUrl.useQuery,uw=m.streamBroker.getBroker.useQuery,dw=m.streamBroker.setPreBufferDuration.useMutation,fw=m.streamBroker.getPreBufferInfo.useQuery,mw=m.streamBroker.getRtspPort.useQuery,pw=m.streamBroker.getAllRtspEntries.useQuery,hw=m.streamBroker.getRtspEntry.useQuery,gw=m.streamBroker.regenerateRtspToken.useMutation,bw=m.streamBroker.setRtspEnabled.useMutation,xw=m.streamBroker.isRtspEnabled.useQuery,vw=m.streamBroker.getDeviceSettingsContribution.useQuery,yw=m.streamBroker.getDeviceLiveContribution.useQuery,ww=m.streamBroker.applyDeviceSettingsPatch.useMutation,Sw=m.switch.setState.useMutation,kw=m.switch.getStatus.useQuery,jw=m.system.info.useQuery,Nw=m.system.health.useQuery,Cw=m.system.featureFlags.useQuery,Mw=m.system.networkAddresses.useQuery,Ew=m.system.getRetentionConfig.useQuery,Aw=m.system.setRetentionConfig.useMutation,Pw=m.system.forceRetentionCleanup.useMutation,Rw=m.toast.onToast.useSubscription,Dw=m.turnOrchestrator.listProviders.useQuery,Tw=m.turnOrchestrator.getAllServers.useQuery,Iw=m.turnOrchestrator.setProviderEnabled.useMutation,Lw=m.turnProvider.getTurnServers.useQuery,Ow=m.userManagement.listUsers.useQuery,_w=m.userManagement.createUser.useMutation,$w=m.userManagement.updateUser.useMutation,Gw=m.userManagement.deleteUser.useMutation,Bw=m.userManagement.resetPassword.useMutation,Fw=m.userManagement.validateCredentials.useMutation,zw=m.userManagement.listApiKeys.useQuery,Qw=m.userManagement.createApiKey.useMutation,Uw=m.userManagement.revokeApiKey.useMutation,Hw=m.userManagement.validateApiKey.useMutation,Vw=m.userManagement.createScopedToken.useMutation,Ww=m.userManagement.revokeScopedToken.useMutation,qw=m.userManagement.validateScopedToken.useQuery,Kw=m.userManagement.listScopedTokens.useQuery,Zw=m.webrtcSession.listStreams.useQuery,Yw=m.webrtcSession.createSession.useMutation,Xw=m.webrtcSession.handleAnswer.useMutation,Jw=m.webrtcSession.closeSession.useMutation,eS=m.webrtcSession.hasAdaptiveBitrate.useQuery,tS=m.zoneAnalytics.getCurrentSnapshot.useQuery,rS=m.zoneAnalytics.getZoneHistory.useQuery,sS=m.zoneAnalytics.getCameraHistory.useQuery,nS=m.zoneAnalytics.getUnzonedHistory.useQuery,oS=m.zoneRules.listRules.useQuery,aS=m.zoneRules.setRules.useMutation,iS=m.zones.listZones.useQuery,lS=m.zones.addZone.useMutation,cS=m.zones.removeZone.useMutation,uS=m.zones.updateZone.useMutation,Ji=ot("camstack:widget-registry",null),qr=new Map,Kr=new Map,el=new Set;function dS(e){if(!e||typeof e!="object")return!1;const t=e.default;return t!==null&&typeof t=="object"}function fS(e){if(!e||typeof e!="object")return typeof e;const t=e,s=Object.getPrototypeOf(t),n=s&&typeof s=="object"?s.constructor?.name:void 0;return{ownKeys:Object.keys(t),allKeys:Object.getOwnPropertyNames(t),proto:typeof n=="string"?n:void 0}}async function mS(e,t){const s=qr.get(e);if(s)return s;const n=Kr.get(e);if(n)return n;el.has(e)||(zo(),wd([{name:e,entry:t,type:"module"}],{force:!1}),el.add(e));const o=yd(`${e}/widgets`).then(a=>{if(!dS(a)){const l=fS(a);throw new Error(`Widget remote ${e} (${t}) does not expose a default record on './widgets'. Got: ${JSON.stringify(l)}`)}const i=a.default;return qr.set(e,i),Kr.delete(e),i}).catch(a=>{throw Kr.delete(e),a});return Kr.set(e,o),o}var pS=3e4,hS=2e3;function gS({children:e}){const t=(0,Ee.useQueryClient)(),s=(0,h.useRef)(Date.now()),{data:n}=Xi(void 0,{staleTime:0,refetchOnMount:"always",refetchInterval:l=>{const u=l.state.data;return u&&u.length>0||Date.now()-s.current>=pS?!1:hS}});lr("addon.widget-ready",()=>{t.invalidateQueries({queryKey:[["addonWidgets","listWidgets"]]})});const[o,a]=(0,h.useState)(0);(0,h.useEffect)(()=>{if(!n)return;let l=!1;const u=new Set;for(const d of n){if(u.has(d.remoteName)||(u.add(d.remoteName),qr.has(d.remoteName)))continue;const f=d.bundleUrl;mS(d.remoteName,f).then(()=>{l||a(p=>p+1)}).catch(p=>{const g=p instanceof Error?p.message:String(p);(typeof globalThis<"u"?globalThis.console:void 0)?.error?.("[WidgetRegistry] Failed to load widget remote",{remoteName:d.remoteName,entryUrl:f,reason:g})})}return()=>{l=!0}},[n]);const i=(0,h.useMemo)(()=>{const l=n??[],u=new Map;for(const f of l)u.set(`${f.addonId}/${f.stableId}`,f);const d=(f,p)=>({widgetId:f,addonId:p.addonId,stableId:p.stableId,label:p.label,description:p.description,icon:p.icon,remoteName:p.remoteName,bundleUrl:p.bundleUrl,hosts:p.hosts,requires:p.requires,defaultSize:p.defaultSize,allowedSizes:p.allowedSizes,defaultColumns:p.defaultColumns,defaultRows:p.defaultRows});return{resolve:f=>{const p=u.get(f);if(!p)return;const g=qr.get(p.remoteName);if(!g)return null;const b=g[p.stableId];if(b)return b},metadata:f=>{const p=u.get(f);if(p)return d(f,p)},listAll:()=>{const f=[];for(const[p,g]of u)f.push(d(p,g));return f}}},[n,o]);return(0,r.jsx)(Ji.Provider,{value:i,children:e})}function tl(e){return Zr().resolve(e)}function rl(e){return Zr().metadata(e)}function bS(){return Zr().listAll()}function Zr(){const e=sl();if(!e)throw new Error("useWidgetRegistry(): no <WidgetRegistryProvider> in tree");return e}function sl(){return xS(Ji)}function xS(e){return(0,h.useContext)(e)}function nl(e){const{widgetId:t,host:s="device-tab",config:n,deviceId:o,integrationId:a,instanceId:i,size:l,columns:u,rows:d}=e,f=tl(t),p=rl(t),g=(0,h.useMemo)(()=>i??t,[i,t]);if(f===void 0&&p===void 0)return(0,r.jsx)(Yr,{widgetId:t,reason:"unknown"});if(f===void 0)return(0,r.jsx)(Yr,{widgetId:t,reason:"missing-export"});if(f===null)return(0,r.jsx)(vS,{});if(p){if(p.requires.deviceContext&&o===void 0)return(0,r.jsx)(Yr,{widgetId:t,reason:"missing-device-context"});if(p.requires.integrationContext&&a===void 0)return(0,r.jsx)(Yr,{widgetId:t,reason:"missing-integration-context"})}return(0,r.jsx)(f,{instanceId:g,host:s,config:n,deviceId:o,integrationId:a,size:l,columns:u,rows:d})}function vS(){return(0,r.jsxs)("div",{className:"rounded-lg border border-border bg-surface/40 p-4 animate-pulse",children:[(0,r.jsx)("div",{className:"h-3 w-24 bg-foreground-subtle/20 rounded mb-2"}),(0,r.jsx)("div",{className:"h-2 w-full bg-foreground-subtle/10 rounded mb-1"}),(0,r.jsx)("div",{className:"h-2 w-3/4 bg-foreground-subtle/10 rounded"})]})}function Yr({widgetId:e,reason:t}){return(0,r.jsx)("div",{className:"rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning",children:t==="unknown"?`Widget "${e}" not registered`:t==="missing-export"?`Widget "${e}" bundle does not export this stableId`:t==="missing-device-context"?`Widget "${e}" requires a deviceId`:`Widget "${e}" requires an integrationId`})}var Nt="w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50 disabled:cursor-not-allowed",Xr="block text-[11px] font-medium text-foreground mb-1",yS="text-[10px] text-foreground-subtle mt-0.5";function je({label:e,description:t,required:s,span:n,children:o,translationFn:a}){const i=n===2?"col-span-2":n===3?"col-span-3":n===4?"col-span-4":"col-span-1",l=Ke(e,a),u=Ke(t,a);return(0,r.jsxs)("div",{className:i,children:[l!==void 0&&l!==""&&(0,r.jsxs)("label",{className:Xr,children:[l,s&&(0,r.jsx)("span",{className:"text-danger ml-0.5",children:"*"})]}),o,u&&(0,r.jsx)("p",{className:yS,children:u})]})}function wS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsx)("input",{type:e.inputType??"text",className:Nt,value:t==null?"":String(t),placeholder:e.placeholder,maxLength:e.maxLength,pattern:e.pattern,disabled:n||e.disabled,onChange:a=>s(a.target.value)})})}function SS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const[a,i]=(0,h.useState)(t==null?"":String(t)),l=(0,h.useRef)(!1);(0,h.useEffect)(()=>{l.current||i(t==null?"":String(t))},[t]);const u=d=>{if(i(d),d===""||d==="-"){s(void 0);return}const f=Number(d);Number.isNaN(f)||s(f)};return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)("input",{type:"number",className:Nt,value:a,placeholder:e.placeholder,min:e.min,max:e.max,step:e.step,disabled:n||e.disabled,onFocus:()=>{l.current=!0},onBlur:()=>{l.current=!1},onChange:d=>u(d.target.value)}),e.unit&&(0,r.jsx)("span",{className:"text-xs text-foreground-subtle whitespace-nowrap",children:e.unit})]})})}function kS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const a=!!t,i=n||e.disabled;return e.style==="checkbox"?(0,r.jsx)(je,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[(0,r.jsx)("input",{type:"checkbox",className:"h-3.5 w-3.5 rounded border-border accent-primary",checked:a,disabled:i,onChange:l=>s(l.target.checked)}),(0,r.jsx)("span",{className:"text-xs font-medium text-foreground",children:Ke(e.label,o)}),e.required&&(0,r.jsx)("span",{className:"text-danger",children:"*"})]})}):(0,r.jsx)(je,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("span",{className:Xr+" mb-0",children:[Ke(e.label,o),e.required&&(0,r.jsx)("span",{className:"text-danger ml-0.5",children:"*"})]}),(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":a,disabled:i,onClick:()=>!i&&s(!a),className:["relative inline-flex h-4 w-8 shrink-0 items-center rounded-full transition-colors duration-150",a?"bg-primary":"bg-foreground-subtle/30",i?"opacity-50 cursor-not-allowed":"cursor-pointer"].join(" "),children:(0,r.jsx)("span",{className:["inline-block h-3 w-3 rounded-full bg-white shadow transition-transform duration-150",a?"translate-x-4":"translate-x-0.5"].join(" ")})})]})})}function jS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const a=e.options.some(i=>i.value==="");return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("select",{className:Nt,value:t==null?"":String(t),disabled:n||e.disabled,onChange:i=>s(i.target.value),children:[!e.required&&!a&&(0,r.jsx)("option",{value:"",children:"— Select —"}),e.options.map(i=>(0,r.jsx)("option",{value:i.value,children:i.label},i.value))]})})}function NS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const a=Array.isArray(t)?t:[],i=l=>{if(a.includes(l))s(a.filter(u=>u!==l));else{if(e.maxItems!==void 0&&a.length>=e.maxItems)return;s([...a,l])}};return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:e.options.map(l=>{const u=a.includes(l.value);return(0,r.jsxs)("label",{className:["flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs cursor-pointer select-none transition-colors",u?"border-primary bg-primary/10 text-primary":"border-border bg-background text-foreground hover:bg-surface",n||e.disabled?"opacity-50 cursor-not-allowed":""].join(" "),children:[(0,r.jsx)("input",{type:"checkbox",className:"sr-only",checked:u,disabled:n||e.disabled,onChange:()=>i(l.value)}),l.label]},l.value)})})})}function CS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const[a,i]=(0,h.useState)(!1),l=e.showToggle!==!1;return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("input",{type:a?"text":"password",className:Nt+(l?" pr-9":""),value:t==null?"":String(t),placeholder:e.placeholder,disabled:n||e.disabled,onChange:u=>s(u.target.value)}),l&&(0,r.jsx)("button",{type:"button",className:"absolute right-2 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",tabIndex:-1,onClick:()=>i(u=>!u),children:a?(0,r.jsx)(Yo,{className:"h-3.5 w-3.5"}):(0,r.jsx)(Or,{className:"h-3.5 w-3.5"})})]})})}function MS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsx)("textarea",{className:Nt+" resize-y min-h-[60px]",value:t==null?"":String(t),placeholder:e.placeholder,rows:e.rows??3,maxLength:e.maxLength,disabled:n||e.disabled,onChange:a=>s(a.target.value)})})}function ES({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const a=t==null,i=e.nullable===!0,l=a?e.default??e.min:Number(t),u=e.showValue!==!1,d=e.nullLabel??"Auto",f=n||e.disabled,p=e.displayScale??1,g=e.min/p,b=e.max/p,x=l/p,v=(e.step??1)/p;if(i&&a)return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("button",{className:"w-full rounded-lg border border-dashed border-border px-3 py-2 text-xs text-foreground-subtle hover:border-primary/40 hover:text-primary transition-colors text-left",disabled:f,onClick:()=>s(e.default??e.min),children:[d," — click to set manually"]})});const w=e.showStepper===!0&&u,y=k=>{const C=l+k*(e.step??1),N=Math.min(e.max,Math.max(e.min,C));N!==l&&s(N)},S="flex h-6 w-6 shrink-0 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:cursor-not-allowed disabled:opacity-40";return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[(0,r.jsxs)("div",{className:"flex min-w-0 flex-1 basis-[160px] items-center gap-2",children:[(0,r.jsx)("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:g}),(0,r.jsx)("input",{type:"range",className:"min-w-0 flex-1 h-1 accent-primary cursor-pointer disabled:opacity-50",min:g,max:b,step:v,value:x,disabled:f,onChange:k=>s(Number(k.target.value)*p)}),(0,r.jsx)("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:b})]}),(u||i||e.unit)&&(0,r.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[w&&(0,r.jsx)("button",{type:"button",className:S,disabled:f||l<=e.min,onClick:()=>y(-1),title:`Decrease by ${e.step??1}`,"aria-label":"Decrement",children:(0,r.jsx)(na,{className:"h-3 w-3"})}),u&&(0,r.jsx)("input",{type:"number",className:"w-16 rounded border border-border bg-surface px-1.5 py-0.5 text-xs text-center text-foreground tabular-nums focus:outline-none focus:ring-1 focus:ring-primary",min:g,max:b,step:v,value:x,disabled:f,onChange:k=>{if(k.target.value===""){s(i?null:e.min);return}const C=Number(k.target.value)*p,N=e.step??1,E=C-e.min,R=e.min+Math.round(E/N)*N;s(Math.min(e.max,Math.max(e.min,R)))}}),w&&(0,r.jsx)("button",{type:"button",className:S,disabled:f||l>=e.max,onClick:()=>y(1),title:`Increase by ${e.step??1}`,"aria-label":"Increment",children:(0,r.jsx)(_r,{className:"h-3 w-3"})}),e.unit&&(0,r.jsx)("span",{className:"text-[10px] text-foreground-subtle",children:e.unit}),i&&(0,r.jsx)("button",{className:"text-[10px] text-foreground-subtle hover:text-primary transition-colors",title:`Reset to ${d}`,disabled:f,onClick:()=>s(null),children:d})]})]})})}function AS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const a=Array.isArray(t)?t:[],[i,l]=(0,h.useState)(""),u=(0,h.useRef)(null),d=(0,h.useCallback)(b=>{const x=b.trim();!x||a.includes(x)||e.maxTags!==void 0&&a.length>=e.maxTags||(s([...a,x]),l(""))},[a,e.maxTags,s]),f=b=>s(a.filter(x=>x!==b)),p=b=>{b.key==="Enter"||b.key===","?(b.preventDefault(),d(i)):b.key==="Backspace"&&i===""&&a.length>0&&f(a[a.length-1])},g=n||e.disabled;return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("div",{className:["flex flex-wrap gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 min-h-[38px] cursor-text","focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30",g?"opacity-50 cursor-not-allowed":""].join(" "),onClick:()=>!g&&u.current?.focus(),children:[a.map(b=>(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[b,!g&&(0,r.jsx)("button",{type:"button",onClick:()=>f(b),className:"hover:text-danger",children:(0,r.jsx)(Pe,{className:"h-2.5 w-2.5"})})]},b)),(0,r.jsx)("input",{ref:u,type:"text",className:"flex-1 min-w-[80px] bg-transparent text-sm text-foreground outline-none placeholder:text-foreground-disabled",value:i,placeholder:a.length===0?e.placeholder??"Add tags…":"",disabled:g,list:`tags-suggestions-${e.key}`,onChange:b=>l(b.target.value),onKeyDown:p,onBlur:()=>{i.trim()&&d(i)}}),e.suggestions&&(0,r.jsx)("datalist",{id:`tags-suggestions-${e.key}`,children:e.suggestions.map(b=>(0,r.jsx)("option",{value:b},b))})]})})}function ol({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const{nodes:a}=zr(),i=typeof t=="string"?t:"",l=e.showOffline?a:a.filter(u=>u.isOnline);return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("select",{className:"w-full px-3 py-2 text-sm bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-primary/50 disabled:opacity-50",value:i,onChange:u=>s(u.target.value),disabled:n,children:[(0,r.jsx)("option",{value:"",children:"Select node…"}),l.map(u=>(0,r.jsxs)("option",{value:u.id,disabled:!u.isOnline,children:[u.shortName,u.isOnline?"":" (offline)"]},u.id))]})})}function al({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const{nodes:a}=zr(),i=new Set(Array.isArray(t)?t.map(String):[]),l=e.showOffline?a:a.filter(d=>d.isOnline),u=d=>{const f=new Set(i);f.has(d)?f.delete(d):f.add(d),s([...f])};return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsx)("div",{className:"flex flex-wrap gap-1.5",children:l.map(d=>{const f=i.has(d.id);return(0,r.jsx)("button",{type:"button",onClick:()=>u(d.id),disabled:n||!d.isOnline,className:`px-2.5 py-1 text-xs font-medium rounded-md border transition-colors ${f?"border-primary bg-primary/10 text-primary":"border-border bg-surface text-foreground-subtle hover:bg-surface-hover"} ${d.isOnline?"":"opacity-50 cursor-not-allowed"}`,children:d.shortName},d.id)})})})}function PS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const a=t==null?"#000000":String(t);return(0,r.jsxs)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("input",{type:"color",className:"h-9 w-9 rounded-md border border-border bg-background cursor-pointer p-0.5 disabled:opacity-50",value:a,disabled:n||e.disabled,onChange:i=>s(i.target.value)}),(0,r.jsx)("input",{type:"text",className:Nt+" flex-1 font-mono",value:a,placeholder:"#000000",disabled:n||e.disabled,onChange:i=>s(i.target.value)})]}),e.presets&&e.presets.length>0&&(0,r.jsx)("div",{className:"flex gap-1.5 mt-1.5",children:e.presets.map(i=>(0,r.jsx)("button",{type:"button",className:"h-5 w-5 rounded-md border border-border hover:scale-110 transition-transform disabled:opacity-50",style:{backgroundColor:i},disabled:n||e.disabled,title:i,onClick:()=>s(i)},i))})]})}function RS({field:e,value:t,onChange:s,disabled:n,translationFn:o,onTestField:a,onAction:i,externalProbe:l}){const[u,d]=(0,h.useState)("idle"),[f,p]=(0,h.useState)(null),g=l?.status??u,b=l?.result??f,x=!!a||!!i,v=(0,h.useCallback)(async()=>{if(x){d("probing"),p(null);try{const S=a?await a(e.key,t):await i("test-probe",e.key,t),k=S&&typeof S=="object"?S:{status:"error",error:"Probe handler returned no result"};p(k),d(k.status==="ok"?"ok":"error")}catch(S){p({status:"error",error:S instanceof Error?S.message:String(S)}),d("error")}}},[a,i,e.key,t,x]),w=g==="probing"?"border-primary/40 bg-primary/10 text-primary":g==="ok"?"border-success/40 bg-success/10 text-success hover:bg-success/15":g==="error"?"border-danger/40 bg-danger/10 text-danger hover:bg-danger/15":"border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover",y=g==="probing"?(0,r.jsx)(qe,{className:"h-3 w-3 animate-spin"}):g==="ok"?(0,r.jsx)(zd,{className:"h-3 w-3"}):g==="error"?(0,r.jsx)(Lr,{className:"h-3 w-3"}):(0,r.jsx)(fa,{className:"h-3 w-3"});return(0,r.jsxs)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:[(0,r.jsxs)("div",{className:"@container flex items-center gap-2",style:{containerType:"inline-size"},children:[(0,r.jsxs)("button",{type:"button",onClick:v,title:"Test",disabled:e.disabled||g==="probing"||!x||!t,className:`flex-shrink-0 inline-flex items-center gap-1.5 rounded-md border px-2 py-2 text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed @[280px]:px-3 ${w}`,children:[y,(0,r.jsx)("span",{className:"hidden @[280px]:inline",children:"Test"})]}),(0,r.jsx)("input",{type:e.inputType??"url",className:Nt+" flex-1 min-w-0",value:t==null?"":String(t),placeholder:e.placeholder,disabled:n||e.disabled,onChange:S=>{s(S.target.value),u!=="idle"&&(d("idle"),p(null))}})]}),g==="ok"&&b?.labels&&b.labels.length>0&&(0,r.jsx)("div",{className:"flex flex-wrap gap-1 mt-1.5",children:b.labels.map((S,k)=>(0,r.jsx)("span",{className:"text-xs bg-success/10 text-success rounded px-2 py-0.5 font-mono",children:S},k))}),g==="error"&&b?.error&&(0,r.jsx)("p",{className:"text-xs text-danger mt-1 truncate",title:b.error,children:b.error})]})}function DS({field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a}){const[i,l]=(0,h.useState)(e.defaultCollapsed??!1),u=e.style==="accordion";return(0,r.jsx)("div",{className:e.span===2?"col-span-2":e.span===3?"col-span-3":e.span===4?"col-span-4":"col-span-1",children:(0,r.jsxs)("div",{className:"rounded-lg border border-border bg-surface/50 overflow-hidden",children:[(0,r.jsxs)("div",{className:["px-3 py-2 flex items-center justify-between",u?"cursor-pointer hover:bg-surface":""].join(" "),onClick:u?()=>l(d=>!d):void 0,children:[(0,r.jsx)("span",{className:"text-xs font-semibold text-foreground",children:Ke(e.label,o)}),u&&(0,r.jsx)("span",{className:"text-foreground-subtle text-xs",children:i?"▸":"▾"})]}),!i&&(0,r.jsx)("div",{className:"px-3 pb-3 grid grid-cols-2 gap-x-4 gap-y-3",children:e.fields.map(d=>(0,r.jsx)(Qt,{field:d,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a},d.key))})]})})}function TS({field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,onAction:i}){const[l,u]=(0,h.useState)(e.tabs[0]?.id??""),d=e.span===2?"col-span-2":e.span===3?"col-span-3":e.span===4?"col-span-4":"col-span-1";return e.tabs.length===0?null:(0,r.jsxs)("div",{className:d,children:[e.label&&(0,r.jsx)("div",{className:Xr,children:Ke(e.label,o)}),(0,r.jsxs)("div",{className:"rounded-lg border border-border-subtle bg-surface-hover/40 overflow-hidden",children:[(0,r.jsx)("div",{className:"flex flex-wrap gap-1 p-1.5 border-b border-border-subtle bg-surface/40",role:"tablist",children:e.tabs.map(f=>{const p=f.id===l;return(0,r.jsxs)("button",{type:"button",role:"tab","aria-selected":p,onClick:()=>u(f.id),className:`inline-flex items-center gap-1.5 whitespace-nowrap rounded-md px-2.5 py-1 text-[11px] transition-colors ${p?"bg-primary text-primary-foreground font-medium shadow-sm":"bg-transparent text-foreground-subtle hover:bg-surface hover:text-foreground"}`,children:[(0,r.jsx)("span",{children:Ke(f.label,o)}),f.badge&&(0,r.jsx)("span",{className:`text-[9px] px-1 py-0.5 rounded-full font-medium ${p?"bg-primary-foreground/20 text-primary-foreground":"bg-primary/10 text-primary"}`,children:f.badge})]},f.id)})}),e.tabs.map(f=>f.id!==l?null:(0,r.jsx)("div",{role:"tabpanel",className:"px-3 pb-3 pt-2 grid grid-cols-2 gap-x-4 gap-y-3",children:f.fields.map((p,g)=>{const b="key"in p&&typeof p.key=="string"?p.key:`__${f.id}__${g}`;return(0,r.jsx)(Qt,{field:p,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,onAction:i},b)})},f.id))]})]})}function IS({span:e}){return(0,r.jsx)("div",{className:e===2?"col-span-2":e===3?"col-span-3":e===4?"col-span-4":"col-span-full",children:(0,r.jsx)("hr",{className:"border-border"})})}var il={info:{border:"border-info",bg:"bg-info/5",text:"text-info"},warning:{border:"border-warning",bg:"bg-warning/5",text:"text-warning"},success:{border:"border-success",bg:"bg-success/5",text:"text-success"},danger:{border:"border-danger",bg:"bg-danger/5",text:"text-danger"}};function LS(e){if(typeof window>"u"||typeof DOMParser>"u")return"";const t=new Set(["A","UL","OL","LI","STRONG","EM","CODE","BR","P","SPAN"]),s=new DOMParser().parseFromString(`<div>${e}</div>`,"text/html"),n=s.body.firstElementChild;if(!n)return"";const o=a=>{const i=Array.from(a.children);for(const l of i){if(!t.has(l.tagName)){const d=s.createTextNode(l.textContent??"");l.replaceWith(d);continue}const u=l.tagName==="A"?new Set(["href"]):new Set;for(const d of Array.from(l.attributes))u.has(d.name)||l.removeAttribute(d.name);if(l.tagName==="A"){const d=l.getAttribute("href")??"";!/^https?:\/\//i.test(d)&&!d.startsWith("mailto:")?l.removeAttribute("href"):(l.setAttribute("target","_blank"),l.setAttribute("rel","noopener noreferrer"))}o(l)}};return o(n),n.innerHTML}function OS({field:e}){const t=il[e.variant??"info"]??il.info,s=e.format==="html";return(0,r.jsx)("div",{className:"col-span-full",children:(0,r.jsxs)("div",{className:`rounded-md border-l-4 px-3 py-2.5 ${t.border} ${t.bg}`,children:[e.label&&(0,r.jsx)("p",{className:`text-xs font-semibold mb-0.5 ${t.text}`,children:e.label}),s?(0,r.jsx)("div",{className:"text-xs text-foreground-subtle leading-relaxed info-html-content",dangerouslySetInnerHTML:{__html:LS(e.content)}}):(0,r.jsx)("p",{className:"text-xs text-foreground-subtle leading-relaxed whitespace-pre-line",children:e.content})]})})}var ll={ok:"bg-success",warn:"bg-amber-500",danger:"bg-danger",idle:"bg-foreground-subtle/40",unknown:"bg-foreground-subtle/40"};function _S(e){if(!Number.isFinite(e)||e<0)return"—";if(e<1e3)return`${e}ms`;const t=Math.round(e/1e3);if(t<60)return`${t}s`;const s=Math.floor(t/60),n=t%60;return n===0?`${s}m`:`${s}m ${n}s`}function $S(e){return!Number.isFinite(e)||e<=0?"—":new Date(e).toLocaleTimeString()}function GS({kind:e,value:t}){return t==null||t===""?(0,r.jsx)("span",{className:"text-foreground-subtle/60",children:"—"}):e==="monospace"?(0,r.jsx)("span",{className:"font-mono text-[11px]",children:String(t)}):e==="status"?(0,r.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,r.jsx)("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${ll[String(t).toLowerCase()]??ll.unknown}`}),(0,r.jsx)("span",{children:String(t)})]}):e==="duration"&&typeof t=="number"?(0,r.jsx)("span",{className:"font-mono text-[11px]",children:_S(t)}):e==="timestamp"&&typeof t=="number"?(0,r.jsx)("span",{className:"font-mono text-[11px]",children:$S(t)}):(0,r.jsx)("span",{children:String(t)})}function BS({field:e}){const t=e.value??[],s=e.description;return(0,r.jsxs)("div",{className:"col-span-full",children:[e.label&&(0,r.jsx)("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1",children:e.label}),s&&(0,r.jsx)("p",{className:"text-xs text-foreground-subtle mb-2",children:s}),t.length===0?(0,r.jsx)("div",{className:"rounded-md border border-border bg-surface-subtle px-3 py-2 text-xs text-foreground-subtle",children:e.emptyMessage??"No entries"}):(0,r.jsx)("div",{className:"rounded-md border border-border overflow-hidden",children:(0,r.jsxs)("table",{className:"w-full text-xs",children:[(0,r.jsx)("thead",{className:"bg-surface-subtle border-b border-border",children:(0,r.jsx)("tr",{children:e.columns.map(n=>(0,r.jsx)("th",{className:"px-3 py-1.5 text-left font-medium text-foreground-subtle",style:n.width?{width:n.width}:void 0,children:n.label},n.key))})}),(0,r.jsx)("tbody",{className:"divide-y divide-border",children:t.map((n,o)=>(0,r.jsx)("tr",{className:"hover:bg-surface-hover/40",children:e.columns.map(a=>(0,r.jsx)("td",{className:"px-3 py-1.5 align-top text-foreground",children:(0,r.jsx)(GS,{kind:a.kind,value:n[a.key]})},a.key))},o))})]})})]})}function FS({field:e,value:t,onChange:s,disabled:n,translationFn:o,onTestField:a,onAction:i}){const l=Array.isArray(t)?t:[],u=e.minRows??0,d=e.maxRows??Number.POSITIVE_INFINITY,f=(w,y,S)=>{const k=l.slice();k[w]={...k[w]??{},[y]:S},s(k)},p=w=>{l.length<=u||s(l.filter((y,S)=>S!==w))},g=()=>{if(l.length>=d)return;const w=e.defaultItem??{};s([...l,{...w}])},b=(w,y)=>e.rowTitleTemplate?e.rowTitleTemplate.replace(/\{(\w+)\}/g,(S,k)=>{const C=w[k];return C==null||C===""?"—":String(C)}):`Row ${y+1}`,x=l.length>u,v=l.length<d;return(0,r.jsxs)("div",{className:"col-span-full space-y-2",children:[(0,r.jsxs)("div",{className:"space-y-0.5",children:[e.label&&(0,r.jsx)("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle",children:Ke(e.label,o)}),e.description&&(0,r.jsx)("p",{className:"text-[11px] text-foreground-subtle",children:Ke(e.description,o)})]}),l.length===0?(0,r.jsx)("div",{className:"rounded-md border border-dashed border-border bg-background px-3 py-3 text-center text-[11px] text-foreground-subtle",children:e.emptyMessage??"No entries"}):(0,r.jsx)("div",{className:"space-y-2",children:l.map((w,y)=>(0,r.jsxs)("div",{className:"rounded-md border border-border bg-background",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-3 py-1.5",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-foreground",children:b(w,y)}),(0,r.jsxs)("button",{type:"button",onClick:()=>p(y),disabled:n||!x,className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-30 disabled:cursor-not-allowed",title:x?"Remove this row":`At least ${u} row(s) required`,children:[(0,r.jsx)(na,{className:"h-3 w-3"}),"Remove"]})]}),(0,r.jsx)("div",{className:"grid grid-cols-1 @[420px]:grid-cols-2 gap-x-3 gap-y-2 p-3",children:e.itemFields.map(S=>(0,r.jsx)(Qt,{field:S,values:w,onChange:(k,C)=>f(y,k,C),disabled:n,translationFn:o,onTestField:a,allFields:e.itemFields,onAction:i},S.key))})]},y))}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{type:"button",onClick:g,disabled:n||!v,className:"inline-flex items-center gap-1 rounded border border-border bg-surface px-3 py-1 text-[11px] font-medium text-foreground hover:border-primary/40 hover:bg-primary/5 disabled:opacity-30 disabled:cursor-not-allowed",children:[(0,r.jsx)(_r,{className:"h-3 w-3"}),e.addLabel??"Add"]}),!v&&Number.isFinite(d)&&(0,r.jsxs)("span",{className:"ml-2 text-[10px] text-foreground-subtle",children:["(limit: ",d,")"]})]})]})}function zS({field:e,disabled:t,onAction:s}){const[n,o]=(0,h.useState)(!1),a=Qr(),i=async()=>{if(!(e.confirmMessage&&!await a({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant==="danger"?"danger":"default"}))&&s){o(!0);try{await s(e.action,e.key)}finally{o(!1)}}},l={default:"border border-border text-foreground hover:bg-surface-hover",primary:"bg-primary text-primary-foreground hover:bg-primary/90",danger:"bg-danger text-white hover:bg-danger/90"};return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,children:(0,r.jsx)("button",{onClick:i,disabled:t||n,className:`inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${l[e.variant??"default"]??l.default}`,children:n?"Processing...":e.buttonLabel})})}function cl(e,t){const s={...e.paramsStatic??{}};if(e.paramsFromForm)for(const[n,o]of Object.entries(e.paramsFromForm)){const a=t[o];a!=null&&a!==""&&(s[n]=a)}return s}function QS({field:e,value:t,values:s,onChange:n,disabled:o,onAction:a}){const[i,l]=(0,h.useState)(!1),[u,d]=(0,h.useState)(null),[f,p]=(0,h.useState)(null),g=cl(e,s),b=Object.keys(e.paramsFromForm??{}).some(y=>g[y]===void 0);(0,h.useEffect)(()=>{if(!a||b){p(null),d(null);return}let y=!1;return l(!0),d(null),a(e.action,e.key,g).then(S=>{if(y)return;const k=S;let C=[];if(Array.isArray(k))C=k;else if(k&&typeof k=="object")for(const N of Object.keys(k)){const E=k[N];if(Array.isArray(E)){C=E;break}}p(C)}).catch(S=>{y||(d(S instanceof Error?S.message:String(S)),p([]))}).finally(()=>{y||l(!1)}),()=>{y=!0}},[(e.refreshOn??Object.values(e.paramsFromForm??{})).map(y=>`${y}=${JSON.stringify(s[y])}`).join("|"),a,e.action,e.key]);const x=e.mapOption.value,v=e.mapOption.label,w=e.mapOption.description;return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,children:b?(0,r.jsx)("div",{className:"text-[11px] text-foreground-subtle italic",children:e.emptyParamsMessage??"Fill the prerequisite fields above first."}):i?(0,r.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-foreground-subtle",children:[(0,r.jsx)(qe,{className:"h-3 w-3 animate-spin"})," Loading options…"]}):u?(0,r.jsx)("div",{className:"text-[11px] text-danger",children:u}):f&&f.length===0?(0,r.jsx)("div",{className:"text-[11px] text-foreground-subtle italic",children:e.emptyResultsMessage??"No options returned."}):(()=>{const y=(f??[]).some(S=>{const k=S[x];return k===""||k===void 0});return(0,r.jsxs)("select",{className:"w-full rounded-md border border-border bg-surface px-2 py-1.5 text-xs text-foreground",value:typeof t=="string"?t:"",disabled:o,onChange:S=>n(S.target.value),children:[!y&&(0,r.jsx)("option",{value:"",children:"— Select —"}),(f??[]).map((S,k)=>{const C=S[x],N=S[v],E=w?S[w]:void 0,R=typeof C=="string"&&C!==""?C:`row-${k}`;return(0,r.jsxs)("option",{value:typeof C=="string"?C:String(C??""),children:[typeof N=="string"?N:String(N??R),E!==void 0?` (${String(E)})`:""]},R)})]})})()})}function US({field:e,values:t,disabled:s,onAction:n}){const[o,a]=(0,h.useState)(!1),[i,l]=(0,h.useState)(null),u=Qr(),d=async()=>{if(e.confirmMessage&&!await u({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant==="danger"?"danger":"default"})||!n)return;const p=cl(e,t);a(!0),l(null);try{const g=await n(e.action,e.key,p);l({kind:"ok",text:e.successMessage?e.successMessage.replace(/\{(\w+)\}/g,(b,x)=>{const v=g?.[x];return v===void 0?"":String(v)}):"Done."})}catch(g){l({kind:"error",text:g instanceof Error?g.message:String(g)})}finally{a(!1)}},f={default:"border border-border text-foreground hover:bg-surface-hover",primary:"bg-primary text-primary-foreground hover:bg-primary/90",danger:"bg-danger text-white hover:bg-danger/90"};return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,children:(0,r.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,r.jsx)("button",{onClick:d,disabled:s||o,className:`inline-flex w-fit items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${f[e.variant??"default"]??f.default}`,children:o?"Working…":e.buttonLabel}),i&&(0,r.jsx)("div",{className:`text-[11px] ${i.kind==="ok"?"text-emerald-700 dark:text-emerald-300":"text-danger"}`,children:i.text})]})})}function HS({field:e}){const t=Yi();return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,children:(0,r.jsx)(nl,{widgetId:e.widgetId,host:"device-tab",config:e.widgetConfig,deviceId:t??void 0,instanceId:e.key})})}function VS(e,t){if(e==null)return"—";if(typeof e=="boolean")return e?"yes":"no";if(typeof e=="number"){const s=Number.isInteger(e)?String(e):e.toFixed(2);return t?`${s} ${t}`:s}return typeof e=="string"?e:JSON.stringify(e)}function WS({field:e,values:t,onAction:s,translationFn:n}){const o="key"in e?e.key:void 0;if(!o)return null;const a=t[o],i=a!==void 0?a:"default"in e?e.default:void 0,l=VS(i,"unit"in e?e.unit:void 0),u="label"in e?e.label:void 0,d="description"in e?e.description:void 0,f="span"in e?e.span:void 0,p="actions"in e?e.actions??[]:[];return(0,r.jsx)(je,{label:u,description:d,span:f,translationFn:n,children:(0,r.jsxs)("div",{className:"flex items-stretch gap-1",children:[(0,r.jsx)("div",{className:"flex-1 rounded-md border border-border bg-surface-alt px-2.5 py-1.5 text-xs text-foreground font-mono break-all",children:l}),p.length>0&&(0,r.jsx)("div",{className:"flex items-center gap-1",children:p.map(g=>(0,r.jsx)(KS,{action:g,fieldKey:o,value:i,onAction:s},g.action))})]})})}function qS({name:e}){const t="h-3.5 w-3.5";switch(e){case"copy":return(0,r.jsx)(pt,{className:t});case"refresh-cw":return(0,r.jsx)(Ls,{className:t});case"external-link":return(0,r.jsx)(Zo,{className:t});case"trash-2":return(0,r.jsx)(at,{className:t});case"download":return(0,r.jsx)(Rs,{className:t});case"upload":return(0,r.jsx)(da,{className:t});default:return(0,r.jsx)(Os,{className:t})}}function KS({action:e,fieldKey:t,value:s,onAction:n}){const o=Qr(),[a,i]=(0,h.useState)(!1),l=e.variant==="danger"?"text-danger hover:bg-danger/10 border-danger/30":e.variant==="primary"?"text-primary hover:bg-primary/10 border-primary/30":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover border-border",u=async()=>{if(!(e.confirmMessage&&!await o({title:e.tooltip,message:e.confirmMessage,variant:e.variant==="danger"?"danger":"default"}))){if(e.action==="copy-value"){try{await navigator.clipboard.writeText(typeof s=="string"?s:String(s))}catch{}return}if(n){i(!0);try{await n(e.action,t)}finally{i(!1)}}}};return(0,r.jsx)("button",{type:"button",onClick:u,disabled:a,title:e.tooltip,className:`inline-flex items-center justify-center rounded-md border px-2 py-1.5 transition-colors disabled:opacity-50 ${l}`,children:(0,r.jsx)(qS,{name:e.icon})})}function ZS(e){return"multiple"in e&&e.multiple!=null}function YS({field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,externalProbe:i,allFields:l,onAction:u}){const d=e.multiple,f=d.min,p=d.max,g=t[e.key],b=[...Array.isArray(g)?g:g!=null?[g]:[]],x=d.itemDefault!==void 0?d.itemDefault:"default"in e&&e.default!==void 0?e.default:"";for(;b.length<f;)b.push(x);const v=C=>s(e.key,[...C]),w=(C,N)=>{const E=[...b];E[C]=N,v(E)},y=()=>{b.length>=p||v([...b,x])},S=C=>{b.length<=f||v(b.filter((N,E)=>E!==C))},k=()=>{const{multiple:C,...N}=e;return{...N,...{label:void 0,description:void 0,required:!1}}};return(0,r.jsx)(je,{label:e.label,description:e.description,required:f>0?e.required:!1,span:e.span,translationFn:o,children:(0,r.jsxs)("div",{className:"space-y-2",children:[b.map((C,N)=>{const E=d.itemLabel?.replace("${n}",String(N+1));return(0,r.jsxs)("div",{className:"space-y-1",children:[E&&(0,r.jsx)("div",{className:Xr,children:E}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{className:"flex-1 min-w-0",children:(0,r.jsx)(Qt,{field:k(),values:{...t,[e.key]:C},onChange:(R,A)=>w(N,A),disabled:n,translationFn:o,onTestField:a,onAction:u,allFields:l})}),b.length>f&&(0,r.jsx)("button",{type:"button",onClick:()=>S(N),disabled:n,title:"Remove",className:"flex-shrink-0 inline-flex items-center justify-center rounded-md border border-border p-1.5 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors disabled:opacity-40",children:(0,r.jsx)(at,{className:"h-3.5 w-3.5"})})]})]},N)}),(0,r.jsxs)("div",{className:"flex items-center justify-between pt-1",children:[b.length<p?(0,r.jsxs)("button",{type:"button",onClick:y,disabled:n,className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40",children:[(0,r.jsx)(_r,{className:"h-3 w-3"}),d.addLabel??"Add"]}):(0,r.jsx)("span",{}),(0,r.jsxs)("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:[b.length,"/",p]})]})]})})}function ul(e,t,s){if(!("showWhen"in e)||!e.showWhen)return!0;const n=e.showWhen,o=t[n.field],a=s?.find(u=>"key"in u&&u.key===n.field),i=a&&"default"in a?a.default:void 0,l=o!==void 0?o:i;return n.equals!==void 0?l===n.equals:n.notEquals!==void 0?l!==n.notEquals:n.in!==void 0?n.in.includes(l):n.notIn!==void 0?!n.notIn.includes(l):n.includes!==void 0?Array.isArray(l)&&l.includes(n.includes):n.notIncludes!==void 0?!Array.isArray(l)||!l.includes(n.notIncludes):!0}function Qt({field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,externalProbe:i,allFields:l,onAction:u}){if(ZS(e))return(0,r.jsx)(YS,{field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,externalProbe:i,allFields:l,onAction:u});if("readonlyField"in e&&e.readonlyField===!0)return(0,r.jsx)(WS,{field:e,values:t,onAction:u,translationFn:o});if(!ul(e,t,l))return null;const d=t[e.key],f=d!==void 0?d:"default"in e?e.default:void 0,p=b=>s(e.key,b),g=Zi(e.type);switch(e.type){case"text":return(0,r.jsx)(wS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"number":return(0,r.jsx)(SS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"boolean":return(0,r.jsx)(kS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"select":return(0,r.jsx)(jS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"multiselect":return(0,r.jsx)(NS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"password":return(0,r.jsx)(CS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"textarea":return(0,r.jsx)(MS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"slider":return(0,r.jsx)(ES,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"tags":return(0,r.jsx)(AS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"color":return(0,r.jsx)(PS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"node-select":return(0,r.jsx)(ol,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"node-multiselect":return(0,r.jsx)(al,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"probe":return(0,r.jsx)(RS,{field:e,value:f,onChange:p,disabled:n,translationFn:o,onTestField:a,onAction:u,externalProbe:i});case"group":return(0,r.jsx)(DS,{field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a});case"sub-tabs":return(0,r.jsx)(TS,{field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,onAction:u});case"separator":return(0,r.jsx)(IS,{});case"info":return(0,r.jsx)(OS,{field:e});case"object-array":return(0,r.jsx)(BS,{field:e});case"editable-array":return(0,r.jsx)(FS,{field:e,value:f,onChange:p,disabled:n,translationFn:o,onTestField:a,onAction:u});case"button":return(0,r.jsx)(zS,{field:e,disabled:n,onAction:u});case"addon-action-select":return(0,r.jsx)(QS,{field:e,value:f,values:t,onChange:p,disabled:n,onAction:u});case"addon-action-button":return(0,r.jsx)(US,{field:e,values:t,disabled:n,onAction:u});case"widget":return(0,r.jsx)(HS,{field:e});default:return g?(0,r.jsx)(g,{field:e,value:f,onChange:p,disabled:n}):null}}function XS(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function Ke(e,t){if(e!==void 0)return t&&XS(e)?t(e):e}function JS({section:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,probeResults:i}){const[l,u]=(0,h.useState)(e.defaultCollapsed??!1),d=e.style==="accordion",f=e.columns??2,p=f===1?"grid-cols-1":f===3?"grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3":f===4?"grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4":"grid-cols-1 @[640px]:grid-cols-2";return(0,r.jsxs)("div",{className:"@container rounded-lg border border-border bg-surface p-3",style:{containerType:"inline-size"},children:[(0,r.jsxs)("div",{className:["flex items-center justify-between mb-2",d?"cursor-pointer":""].join(" "),onClick:d?()=>u(g=>!g):void 0,children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:Ke(e.title,o)}),e.description&&(0,r.jsx)("p",{className:"text-[10px] text-foreground-subtle mt-0.5",children:Ke(e.description,o)})]}),d&&(0,r.jsx)("span",{className:"text-foreground-subtle text-xs ml-2",children:l?"▸":"▾"})]}),!l&&(0,r.jsx)("div",{className:`grid ${p} gap-x-3 gap-y-2.5`,children:e.fields.map(g=>(0,r.jsx)(Qt,{field:g,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,externalProbe:i?.[g.key]},g.key))})]})}function dl({schema:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,probeResults:i,onClearProbe:l}){const u=(d,f)=>{s({...t,[d]:f}),l?.(d)};return(0,r.jsx)("div",{className:"space-y-4",children:e.sections.map(d=>(0,r.jsx)(JS,{section:d,values:t,onChange:u,disabled:n,translationFn:o,onTestField:a,probeResults:i},d.id))})}var ek=({open:e})=>(0,r.jsx)("svg",{className:`h-3 w-3 transition-transform ${e?"rotate-90":""}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:(0,r.jsx)("polyline",{points:"9 18 15 12 9 6"})});function fl(e){const t={};if(!e)return t;for(const s of e.sections)for(const n of s.fields){if(n.type==="separator"||n.type==="info"||n.type==="button"||n.type==="group")continue;const o=n.key;t[o]=n.value}return t}function tk(e){return{...e,sections:e.sections.map(t=>({...t,fields:t.fields.map(s=>{if(s.type==="separator"||s.type==="info"||s.type==="button"||s.type==="group")return s;const{value:n,...o}=s;return o})}))}}function rk({trpc:e,addonId:t,nodeId:s,title:n,disabled:o,onAfterChange:a,refreshToken:i,collapsible:l,defaultOpen:u,mode:d,onOverrideChange:f}){const p=d??"persist",[g,b]=(0,h.useState)(null),[x,v]=(0,h.useState)(!0),[w,y]=(0,h.useState)(null),[S,k]=(0,h.useState)(!1),[C,N]=(0,h.useState)(u??!1),[E,R]=(0,h.useState)({}),[A,Q]=(0,h.useState)(null);(0,h.useEffect)(()=>{Q(null),R({})},[e,t,s,i,p]),(0,h.useEffect)(()=>{let se=!1;v(!0),y(null);const J=p==="override"&&Object.keys(E).length>0?E:void 0;return e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:s,...J?{overlay:J}:{}}).then(H=>{se||(b(H),J||Q(fl(H)),v(!1))}).catch(H=>{se||(y(H instanceof Error?H.message:String(H)),v(!1))}),()=>{se=!0}},[e,t,s,i,p,JSON.stringify(E)]);const ee=(0,h.useMemo)(()=>fl(g),[g]),ne=(0,h.useMemo)(()=>g?tk(g):null,[g]),pe=async se=>{if(p==="override"){const H=A??ee,xe={};for(const D of Object.keys(se))se[D]!==H[D]&&(xe[D]=se[D]);const de={...H,...xe};R(xe),f?.(xe,de);return}const J={};for(const H of Object.keys(se))se[H]!==ee[H]&&(J[H]=se[H]);if(Object.keys(J).length!==0){k(!0);try{await e.addonSettings.updateGlobalSettings.mutate({addonId:t,nodeId:s,patch:J}),b(await e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:s})),a?.()}catch(H){y(H instanceof Error?H.message:String(H))}finally{k(!1)}}};if(x)return(0,r.jsxs)("div",{className:"text-xs text-foreground-subtle animate-pulse",children:["Loading ",n??t,"…"]});if(w)return(0,r.jsxs)("div",{className:"text-xs text-red-400",children:[n??t,": ",w]});if(!g||!ne)return(0,r.jsxs)("div",{className:"text-xs text-foreground-subtle",children:[n??t," not available on ",s,"."]});const ae=p==="override"?{...ee,...E}:ee,ce=(0,r.jsxs)(r.Fragment,{children:[p==="override"?(0,r.jsx)("div",{className:"mb-2 text-[11px] text-foreground-subtle",children:"Benchmark override — applies to this run only. The addon's saved settings are not changed."}):null,(0,r.jsx)(dl,{schema:ne,values:ae,onChange:pe,disabled:o===!0||S})]});return l===!0?(0,r.jsxs)("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>N(se=>!se),className:"w-full px-4 py-2 flex items-center gap-2 hover:bg-surface-hover text-left","aria-expanded":C,children:[(0,r.jsx)(ek,{open:C}),(0,r.jsx)("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide flex-1",children:n??t}),(0,r.jsx)("span",{className:"text-[10px] text-foreground-subtle",children:C?"hide":"edit"})]}),C?(0,r.jsx)("div",{className:"border-t border-border px-4 py-3",children:ce}):null]}):n?(0,r.jsxs)("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[(0,r.jsx)("div",{className:"border-b border-border px-4 py-2",children:(0,r.jsx)("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide",children:n})}),(0,r.jsx)("div",{className:"px-4 py-3",children:ce})]}):(0,r.jsx)("div",{children:ce})}function ml({detections:{motion:e,motionRaw:t,detection:s,phase:n},showMotionZones:o=!0,showMotionRaw:a=!0,showDetections:i=!0,showPhaseIndicator:l=!0}){const u=o&&e&&e.zones.length>0,d=a&&t&&t.boxes.length>0,f=i&&s&&s.detections.length>0;return!u&&!d&&!f&&!l?null:(0,r.jsxs)("div",{className:"absolute inset-0 pointer-events-none z-10",children:[l&&(0,r.jsx)(sk,{phase:n}),d&&(0,r.jsx)(nk,{raw:t}),u&&(0,r.jsx)(ok,{motion:e}),f&&(0,r.jsx)(ak,{detections:s.detections,frameWidth:s.frameWidth,frameHeight:s.frameHeight})]})}function sk({phase:e}){const t=us(e);return(0,r.jsxs)("div",{className:"absolute top-2 left-2 flex items-center gap-1.5 px-2 py-1 rounded-md bg-black/60 backdrop-blur-sm",children:[(0,r.jsx)("span",{className:`w-2 h-2 rounded-full ${t.dotClass}`}),(0,r.jsx)("span",{className:"text-[10px] font-semibold text-white uppercase tracking-wider",children:t.label})]})}function nk({raw:e}){return e.frameWidth===0||e.frameHeight===0?null:(0,r.jsx)(r.Fragment,{children:e.boxes.map((t,s)=>{const[n,o,a,i]=t.bbox,l=n/e.frameWidth*100,u=o/e.frameHeight*100,d=(a-n)/e.frameWidth*100,f=(i-o)/e.frameHeight*100,p=Math.max(.05,Math.min(.25,t.changeScore*.3));return(0,r.jsx)("div",{className:"absolute rounded-sm",style:{left:`${l}%`,top:`${u}%`,width:`${d}%`,height:`${f}%`,backgroundColor:`rgba(239, 68, 68, ${p})`}},`mr-${s}`)})})}function ok({motion:e}){return e.frameWidth===0||e.frameHeight===0?null:(0,r.jsx)(r.Fragment,{children:e.zones.filter(t=>t.w*t.h/(e.frameWidth*e.frameHeight)<.9).map((t,s)=>{const n=Math.max(.15,Math.min(.5,t.intensity/255));return(0,r.jsx)("div",{className:"absolute rounded-sm",style:{left:`${t.x/e.frameWidth*100}%`,top:`${t.y/e.frameHeight*100}%`,width:`${t.w/e.frameWidth*100}%`,height:`${t.h/e.frameHeight*100}%`,border:`1px solid rgba(250, 204, 21, ${n})`,backgroundColor:`rgba(250, 204, 21, ${n*.15})`}},`mz-${s}`)})})}function ak({detections:e,frameWidth:t,frameHeight:s}){return t===0||s===0?null:(0,r.jsx)(r.Fragment,{children:e.map(n=>{const{x:o,y:a,width:i,height:l}=n.bbox,u=o/t*100,d=a/s*100,f=i/t*100,p=l/s*100,g=_e(n.macroClass),b=[`${n.macroClass} ${(n.score*100).toFixed(0)}%`];for(const x of n.labels)b.push(x.label);return(0,r.jsx)("div",{className:"absolute border-2 rounded-sm",style:{left:`${u}%`,top:`${d}%`,width:`${f}%`,height:`${p}%`,borderColor:g},children:(0,r.jsx)("div",{className:"absolute -top-4 left-0 px-1 py-0.5 text-[9px] font-bold text-white rounded-sm whitespace-nowrap",style:{backgroundColor:g},children:b.join(" | ")})},`det-${n.id}`)})})}function ik(e){const t={};if(typeof window<"u"){if(e){const n=e.getBoundingClientRect();n.width>0&&n.height>0&&(t.viewportWidth=Math.round(n.width),t.viewportHeight=Math.round(n.height))}t.viewportWidth===void 0&&(t.viewportWidth=window.innerWidth,t.viewportHeight=window.innerHeight),t.devicePixelRatio=window.devicePixelRatio||1;const s=navigator.connection;s?.downlink&&s.downlink>0&&(t.downlinkMbps=s.downlink)}return t}var lk=3e3,ck=5;function pl({serverUrl:e,streamKey:t,label:s,autoPlay:n=!0,muted:o=!0,showControls:a=!0,className:i="",onStateChange:l,onError:u,overlay:d,createSession:f,sendAnswer:p,closeSession:g,hintsOverride:b}){const x=(0,h.useRef)(null),v=(0,h.useRef)(null),w=(0,h.useRef)(null),y=(0,h.useRef)(new Set),S=(0,h.useRef)(null),k=(0,h.useRef)(null),C=(0,h.useRef)(0),N=(0,h.useRef)(!0),[E,R]=(0,h.useState)("idle"),[A,Q]=(0,h.useState)(""),[ee,ne]=(0,h.useState)(o),[pe,ae]=(0,h.useState)(!1),[ce,se]=(0,h.useState)(!1),J=(0,h.useRef)(null),H=(0,h.useRef)(!1);(p||f)&&(H.current=!0);const xe=H.current,de=(0,h.useCallback)(K=>{R(K),l?.(K)},[l]),D=(0,h.useCallback)(()=>{if(S.current?.abort(),S.current=null,k.current&&(clearTimeout(k.current),k.current=null),w.current&&(w.current.close(),w.current=null),g&&y.current.size>0){for(const K of y.current)g(K).catch(()=>{});y.current.clear()}x.current&&(x.current.srcObject=null)},[g]),$=(0,h.useCallback)(async()=>{if(!N.current||!f||!p)return;D(),de("connecting");const K=new AbortController;S.current=K;try{const{sessionId:ue,sdpOffer:ve}=await f({...ik(v.current),...b});if(y.current.add(ue),!N.current||K.signal.aborted){g?.(ue).catch(()=>{}),y.current.delete(ue);return}const ye=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]});w.current=ye;const L=new MediaStream;ye.ontrack=I=>{console.debug("[WebRTC] ontrack",I.track.kind,I.track.readyState),L.addTrack(I.track),x.current&&(x.current.srcObject=L,x.current.play().catch(()=>{}))},ye.oniceconnectionstatechange=()=>{if(!N.current)return;const I=ye.iceConnectionState;console.debug("[WebRTC] ICE state:",I),I==="connected"||I==="completed"?(C.current=0,de("playing"),x.current?.paused&&(console.debug("[WebRTC] video was paused at ICE connected — calling play()"),x.current.play().catch(()=>{}))):(I==="failed"||I==="disconnected"||I==="closed")&&(de("disconnected"),V())},ye.onicecandidateerror=I=>{console.debug("[WebRTC] ICE candidate error:",I)},console.debug("[WebRTC] Setting remote description (server offer)..."),await ye.setRemoteDescription({type:"offer",sdp:ve});const M=await ye.createAnswer();if(await ye.setLocalDescription(M),console.debug("[WebRTC] Local description set, waiting for ICE gathering..."),await hl(ye),!N.current)return;const T=(ye.localDescription?.sdp??"").split(`
76
+ */var P=(e,t)=>{const s=(0,h.forwardRef)(({className:n,...o},a)=>(0,h.createElement)(Pd,{ref:a,iconNode:t,className:Qo(`lucide-${Cd(Uo(e))}`,`lucide-${e}`,n),...o}));return s.displayName=Uo(e),s},ft=P("activity",[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",key:"169zse"}]]),Rd=P("arrow-down",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]),Dd=P("arrow-left",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]),Td=P("arrow-right",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]),As=P("arrow-up-to-line",[["path",{d:"M5 3h14",key:"7usisc"}],["path",{d:"m18 13-6-6-6 6",key:"1kf1n9"}],["path",{d:"M12 7v14",key:"1akyts"}]]),Id=P("arrow-up",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]),Ld=P("battery-full",[["path",{d:"M10 10v4",key:"1mb2ec"}],["path",{d:"M14 10v4",key:"1nt88p"}],["path",{d:"M22 14v-4",key:"14q9d5"}],["path",{d:"M6 10v4",key:"1n77qd"}],["rect",{x:"2",y:"6",width:"16",height:"12",rx:"2",key:"13zb55"}]]),Od=P("battery-low",[["path",{d:"M22 14v-4",key:"14q9d5"}],["path",{d:"M6 14v-4",key:"14a6bd"}],["rect",{x:"2",y:"6",width:"16",height:"12",rx:"2",key:"13zb55"}]]),_d=P("battery-warning",[["path",{d:"M10 17h.01",key:"nbq80n"}],["path",{d:"M10 7v6",key:"nne03l"}],["path",{d:"M14 6h2a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2",key:"1m83kb"}],["path",{d:"M22 14v-4",key:"14q9d5"}],["path",{d:"M6 18H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2",key:"h8lgfh"}]]),Ho=P("battery",[["path",{d:"M 22 14 L 22 10",key:"nqc4tb"}],["rect",{x:"2",y:"6",width:"16",height:"12",rx:"2",key:"13zb55"}]]),$d=P("bell-ring",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M22 8c0-2.3-.8-4.3-2-6",key:"5bb3ad"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}],["path",{d:"M4 2C2.8 3.7 2 5.7 2 8",key:"tap9e0"}]]),Ir=P("bell",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]]),Gd=P("bug",[["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z",key:"uouzyp"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M21 21a4 4 0 0 0-3.81-4",key:"1b0z45"}],["path",{d:"M21 5a4 4 0 0 1-3.55 3.97",key:"5cxbf6"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M3 21a4 4 0 0 1 3.81-4",key:"1fjd4g"}],["path",{d:"M3 5a4 4 0 0 0 3.55 3.97",key:"1d7oge"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M9 7.13V6a3 3 0 1 1 6 0v1.13",key:"1vgav8"}]]),Ps=P("camera",[["path",{d:"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z",key:"18u6gg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]]),Bd=P("cast",[["path",{d:"M2 8V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-6",key:"3zrzxg"}],["path",{d:"M2 12a9 9 0 0 1 8 8",key:"g6cvee"}],["path",{d:"M2 16a5 5 0 0 1 4 4",key:"1y1dii"}],["line",{x1:"2",x2:"2.01",y1:"20",y2:"20",key:"xu2jvo"}]]),sr=P("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]),St=P("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]),Fd=P("chevron-left",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]),mt=P("chevron-right",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]),Lr=P("circle-alert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]),zd=P("circle-check-big",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]),Qd=P("circle-check",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]),Ud=P("circle-dot",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]]),Hd=P("circle-pause",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"10",x2:"10",y1:"15",y2:"9",key:"c1nkhi"}],["line",{x1:"14",x2:"14",y1:"15",y2:"9",key:"h65svq"}]]),Vd=P("circle-plus",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M12 8v8",key:"napkw2"}]]),Vo=P("circle-question-mark",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]),Wd=P("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]),qd=P("copy-plus",[["line",{x1:"15",x2:"15",y1:"12",y2:"18",key:"1p7wdc"}],["line",{x1:"12",x2:"18",y1:"15",y2:"15",key:"1nscbv"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]),pt=P("copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]),Kd=P("cpu",[["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M17 20v2",key:"1rnc9c"}],["path",{d:"M17 2v2",key:"11trls"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M2 17h2",key:"7oei6x"}],["path",{d:"M2 7h2",key:"asdhe0"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"M20 17h2",key:"1fpfkl"}],["path",{d:"M20 7h2",key:"1o8tra"}],["path",{d:"M7 20v2",key:"4gnj0m"}],["path",{d:"M7 2v2",key:"1i4yhu"}],["rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",key:"1vbyd7"}],["rect",{x:"8",y:"8",width:"8",height:"8",rx:"1",key:"z9xiuo"}]]),Wo=P("crosshair",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"22",x2:"18",y1:"12",y2:"12",key:"l9bcsi"}],["line",{x1:"6",x2:"2",y1:"12",y2:"12",key:"13hhkx"}],["line",{x1:"12",x2:"12",y1:"6",y2:"2",key:"10w3f3"}],["line",{x1:"12",x2:"12",y1:"22",y2:"18",key:"15g9kq"}]]),Zd=P("database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]),qo=P("door-open",[["path",{d:"M11 20H2",key:"nlcfvz"}],["path",{d:"M11 4.562v16.157a1 1 0 0 0 1.242.97L19 20V5.562a2 2 0 0 0-1.515-1.94l-4-1A2 2 0 0 0 11 4.561z",key:"au4z13"}],["path",{d:"M11 4H8a2 2 0 0 0-2 2v14",key:"74r1mk"}],["path",{d:"M14 12h.01",key:"1jfl7z"}],["path",{d:"M22 20h-3",key:"vhrsz"}]]),Rs=P("download",[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]]),Ko=P("ellipsis-vertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]),Zo=P("external-link",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]),Yo=P("eye-off",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),Or=P("eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]),Xo=P("funnel",[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]]),Yd=P("grip-horizontal",[["circle",{cx:"12",cy:"9",r:"1",key:"124mty"}],["circle",{cx:"19",cy:"9",r:"1",key:"1ruzo2"}],["circle",{cx:"5",cy:"9",r:"1",key:"1a8b28"}],["circle",{cx:"12",cy:"15",r:"1",key:"1e56xg"}],["circle",{cx:"19",cy:"15",r:"1",key:"1a92ep"}],["circle",{cx:"5",cy:"15",r:"1",key:"5r1jwy"}]]),Jo=P("house",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]]),Xd=P("image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]),Jd=P("inbox",[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]]),ef=P("info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]),tf=P("layout-grid",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]]),ea=P("lightbulb",[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]]),qe=P("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]),rf=P("locate-fixed",[["line",{x1:"2",x2:"5",y1:"12",y2:"12",key:"bvdh0s"}],["line",{x1:"19",x2:"22",y1:"12",y2:"12",key:"1tbv5k"}],["line",{x1:"12",x2:"12",y1:"2",y2:"5",key:"11lu5j"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}],["circle",{cx:"12",cy:"12",r:"7",key:"fim9np"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]),ta=P("maximize-2",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]]),sf=P("menu",[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]]),ra=P("mic",[["path",{d:"M12 19v3",key:"npa21l"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["rect",{x:"9",y:"2",width:"6",height:"13",rx:"3",key:"s6n7sd"}]]),sa=P("minimize-2",[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]]),na=P("minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]),Ds=P("moon",[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]]),nf=P("music",[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]]),Ts=P("network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]),Is=P("play",[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]]),_r=P("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]),of=P("plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]]),af=P("power-off",[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),oa=P("radar",[["path",{d:"M19.07 4.93A10 10 0 0 0 6.99 3.34",key:"z3du51"}],["path",{d:"M4 6h.01",key:"oypzma"}],["path",{d:"M2.29 9.62A10 10 0 1 0 21.31 8.35",key:"qzzz0"}],["path",{d:"M16.24 7.76A6 6 0 1 0 8.23 16.67",key:"1yjesh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M17.99 11.66A6 6 0 0 1 15.77 16.67",key:"1u2y91"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"m13.41 10.59 5.66-5.66",key:"mhq4k0"}]]),lf=P("radio",[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]),Ls=P("refresh-cw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]),aa=P("rotate-ccw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]),ia=P("rotate-cw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]),cf=P("save",[["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"}]]),uf=P("scan",[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}]]),df=P("scroll-text",[["path",{d:"M15 12h-5",key:"r7krc0"}],["path",{d:"M15 8h-5",key:"1khuty"}],["path",{d:"M19 17V5a2 2 0 0 0-2-2H4",key:"zz82l3"}],["path",{d:"M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3",key:"1ph1d7"}]]),nr=P("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),ff=P("server",[["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"}]]),mf=P("shield",[["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"}]]),pf=P("ship",[["path",{d:"M12 10.189V14",key:"1p8cqu"}],["path",{d:"M12 2v3",key:"qbqxhf"}],["path",{d:"M19 13V7a2 2 0 0 0-2-2H7a2 2 0 0 0-2 2v6",key:"qpkstq"}],["path",{d:"M19.38 20A11.6 11.6 0 0 0 21 14l-8.188-3.639a2 2 0 0 0-1.624 0L3 14a11.6 11.6 0 0 0 2.81 7.76",key:"7tigtc"}],["path",{d:"M2 21c.6.5 1.2 1 2.5 1 2.5 0 2.5-2 5-2 1.3 0 1.9.5 2.5 1s1.2 1 2.5 1c2.5 0 2.5-2 5-2 1.3 0 1.9.5 2.5 1",key:"1924j5"}]]),hf=P("sliders-horizontal",[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]]),la=P("square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]),gf=P("star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]),ca=P("sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]),bf=P("table-2",[["path",{d:"M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18",key:"gugj83"}]]),ua=P("target",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]),xf=P("thermometer",[["path",{d:"M14 4v10.54a4 4 0 1 1-4 0V4a2 2 0 0 1 4 0Z",key:"17jzev"}]]),vf=P("toggle-left",[["circle",{cx:"9",cy:"12",r:"3",key:"u3jwor"}],["rect",{width:"20",height:"14",x:"2",y:"5",rx:"7",key:"g7kal2"}]]),at=P("trash-2",[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]]),yf=P("trending-up",[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]]),wf=P("trending-down",[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]]),or=P("triangle-alert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]),da=P("upload",[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]),Sf=P("wifi-off",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),fa=P("wifi",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]]),Os=P("wrench",[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]]),Pe=P("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),ma=P("zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]),kf=P("zoom-in",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]),jf=P("zoom-out",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]),Nf={frigate:pf,scrypted:mf,reolink:lf,homeAssistant:Jo,rtsp:Bd},Cf={online:Qd,offline:Wd,degraded:Lr,unknown:Vo},pa=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,ha=Wt,kt=(e,t)=>s=>{var n;if(t?.variants==null)return ha(e,s?.class,s?.className);const{variants:o,defaultVariants:a}=t,i=Object.keys(o).map(u=>{const d=s?.[u],f=a?.[u];if(d===null)return null;const p=pa(d)||pa(f);return o[u][p]}),l=s&&Object.entries(s).reduce((u,d)=>{let[f,p]=d;return p===void 0||(u[f]=p),u},{});return ha(e,i,t==null||(n=t.compoundVariants)===null||n===void 0?void 0:n.reduce((u,d)=>{let{class:f,className:p,...g}=d;return Object.entries(g).every(b=>{let[x,v]=b;return Array.isArray(v)?v.includes({...a,...l}[x]):{...a,...l}[x]===v})?[...u,f,p]:u},[]),s?.class,s?.className)},Mf=kt("inline-flex items-center justify-center rounded-md font-medium transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none",{variants:{variant:{primary:"bg-primary text-primary-foreground hover:bg-primary/90",secondary:"bg-surface text-foreground hover:bg-surface-hover",ghost:"hover:bg-surface-hover text-foreground-muted",danger:"bg-danger text-white hover:bg-danger/90",outline:"border border-border bg-transparent hover:bg-surface-hover"},size:{sm:"h-7 px-2.5 text-xs gap-1.5",md:"h-8 px-3 text-sm gap-2",lg:"h-9 px-4 text-sm gap-2"}},defaultVariants:{variant:"primary",size:"sm"}}),ar=(0,h.forwardRef)(({className:e,variant:t,size:s,...n},o)=>(0,r.jsx)("button",{ref:o,className:j(Mf({variant:t,size:s}),e),...n}));ar.displayName="Button";var Ef=kt("inline-flex items-center justify-center rounded-md font-medium transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none",{variants:{variant:{primary:"bg-primary text-primary-foreground hover:bg-primary/90",secondary:"bg-surface text-foreground hover:bg-surface-hover",ghost:"hover:bg-surface-hover text-foreground-muted",danger:"bg-danger text-white hover:bg-danger/90",outline:"border border-border bg-transparent hover:bg-surface-hover"},size:{sm:"h-7 w-7",md:"h-8 w-8",lg:"h-9 w-9"}},defaultVariants:{variant:"primary",size:"sm"}}),_s=(0,h.forwardRef)(({className:e,variant:t,size:s,icon:n,...o},a)=>(0,r.jsx)("button",{ref:a,className:j(Ef({variant:t,size:s}),e),...o,children:(0,r.jsx)(n,{className:"h-4 w-4"})}));_s.displayName="IconButton";var Af=kt("inline-flex items-center rounded-full text-xs font-medium px-2 py-0.5",{variants:{variant:{default:"bg-surface-hover text-foreground",success:"bg-success/15 text-success",warning:"bg-warning/15 text-warning",danger:"bg-danger/15 text-danger",info:"bg-info/15 text-info"},styleVariant:{solid:"",outline:"border bg-transparent"}},defaultVariants:{variant:"default",styleVariant:"solid"}}),Gt=(0,h.forwardRef)(({className:e,variant:t,style:s,...n},o)=>(0,r.jsx)("span",{ref:o,className:j(Af({variant:t,styleVariant:s}),e),...n}));Gt.displayName="Badge";var Pf=kt("rounded-lg p-3",{variants:{variant:{flat:"bg-surface",bordered:"bg-surface border border-border"}},defaultVariants:{variant:"bordered"}}),$s=(0,h.forwardRef)(({className:e,variant:t,...s},n)=>(0,r.jsx)("div",{ref:n,className:j(Pf({variant:t}),e),...s}));$s.displayName="Card";function ga({expanded:e,onExpandedChange:t,header:s,children:n,dimmed:o=!1,hideChevron:a=!1,className:i}){return(0,r.jsxs)("div",{className:j("rounded-lg border border-border bg-surface overflow-hidden",o&&"opacity-[0.45]",i),children:[(0,r.jsxs)("div",{role:"button",tabIndex:0,className:"flex items-center gap-2.5 px-3 py-2.5 cursor-pointer select-none",onClick:()=>t(!e),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),t(!e))},children:[!a&&(0,r.jsx)("span",{className:"text-foreground-subtle shrink-0",children:e?(0,r.jsx)(St,{className:"h-4 w-4"}):(0,r.jsx)(mt,{className:"h-4 w-4"})}),s]}),e&&n&&(0,r.jsx)("div",{className:"border-t border-border px-3 py-3",children:n})]})}var Gs=(0,h.forwardRef)(({className:e,...t},s)=>(0,r.jsx)("label",{ref:s,className:j("text-[10px] uppercase tracking-wider text-foreground-muted font-medium",e),...t}));Gs.displayName="Label";var Rf=kt("",{variants:{orientation:{horizontal:"h-px w-full bg-border-subtle",vertical:"w-px h-full bg-border-subtle"}},defaultVariants:{orientation:"horizontal"}}),Bs=(0,h.forwardRef)(({className:e,orientation:t,...s},n)=>(0,r.jsx)("div",{ref:n,role:"separator",className:j(Rf({orientation:t}),e),...s}));Bs.displayName="Separator";var ba=(0,h.forwardRef)(({className:e,...t},s)=>(0,r.jsx)("div",{ref:s,className:j("animate-pulse bg-surface-hover rounded-md h-4 w-full",e),...t}));ba.displayName="Skeleton";var xa=kt("h-7 w-full px-2.5 text-xs bg-surface border rounded-md text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary transition-colors",{variants:{state:{default:"border-border",error:"border-danger"}},defaultVariants:{state:"default"}}),$r=(0,h.forwardRef)(({className:e,state:t,leftSlot:s,rightSlot:n,...o},a)=>s||n?(0,r.jsxs)("div",{className:"relative flex items-center w-full",children:[s&&(0,r.jsx)("div",{className:"absolute left-2.5 flex items-center pointer-events-none",children:s}),(0,r.jsx)("input",{ref:a,className:j(xa({state:t}),s?"pl-7":"",n?"pr-7":"",e),...o}),n&&(0,r.jsx)("div",{className:"absolute right-2.5 flex items-center pointer-events-none",children:n})]}):(0,r.jsx)("input",{ref:a,className:j(xa({state:t}),e),...o}));$r.displayName="Input";var Gr=(0,h.forwardRef)(({className:e,options:t,...s},n)=>(0,r.jsxs)("div",{className:"relative w-full",children:[(0,r.jsx)("select",{ref:n,className:j("h-7 w-full px-2.5 text-xs bg-surface border border-border rounded-md text-foreground appearance-none pr-7 focus:outline-none focus:ring-1 focus:ring-primary",e),...s,children:t.map(o=>(0,r.jsx)("option",{value:o.value,children:o.label},o.value))}),(0,r.jsx)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none text-foreground-muted",children:(0,r.jsx)(St,{className:"h-3.5 w-3.5"})})]}));Gr.displayName="Select";var va=(0,h.forwardRef)(({className:e,...t},s)=>(0,r.jsx)("input",{ref:s,type:"checkbox",className:j("w-3.5 h-3.5 rounded-sm border border-border accent-primary",e),...t}));va.displayName="Checkbox";var ya=(0,h.forwardRef)(({className:e,checked:t,onCheckedChange:s,label:n,...o},a)=>(0,r.jsxs)("button",{ref:a,role:"switch","aria-checked":t,type:"button",onClick:()=>s(!t),className:j("inline-flex items-center gap-2",e),...o,children:[(0,r.jsx)("span",{className:j("w-8 h-4 rounded-full transition-colors",t?"bg-primary":"bg-surface-hover"),children:(0,r.jsx)("span",{className:j("block w-3.5 h-3.5 rounded-full bg-white transition-transform",t?"translate-x-4":"translate-x-0.5")})}),n&&(0,r.jsx)("span",{className:"text-xs text-foreground",children:n})]}));ya.displayName="Switch";var wa=(0,h.createContext)(null);function Sa(){const e=(0,h.useContext)(wa);if(!e)throw new Error("Dialog compound components must be used within <Dialog>");return e}function ka({children:e,open:t,onOpenChange:s}){const[n,o]=(0,h.useState)(!1),a=t??n,i=(0,h.useId)(),l=(0,h.useCallback)(u=>{s?.(u),t===void 0&&o(u)},[t,s]);return(0,r.jsx)(wa.Provider,{value:{open:a,setOpen:l,contentId:i},children:e})}function Df({children:e,...t}){const{setOpen:s}=Sa();return(0,r.jsx)("button",{type:"button",onClick:()=>s(!0),...t,children:e})}var Tf=kt("bg-background-elevated border border-border rounded-lg p-4 backdrop:bg-black/50 backdrop:backdrop-blur-sm max-w-[calc(100vw-2rem)] max-h-[calc(100dvh-2rem)] overflow-y-auto",{variants:{width:{sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg"}},defaultVariants:{width:"md"}}),Fs=(0,h.forwardRef)(({className:e,width:t,children:s,...n},o)=>{const{open:a,setOpen:i,contentId:l}=Sa(),u=(0,h.useRef)(null),d=o??u;(0,h.useEffect)(()=>{const p=d.current;p&&(a&&!p.open&&p.showModal(),!a&&p.open&&p.close())},[a,d]);const f=p=>{p.target===p.currentTarget&&i(!1)};return(0,r.jsx)("dialog",{ref:d,id:l,className:j(Tf({width:t}),"w-full",e),onClick:f,onClose:()=>i(!1),...n,children:s})});Fs.displayName="DialogContent";function ja({className:e,...t}){return(0,r.jsx)("div",{className:j("flex flex-col gap-1 mb-3",e),...t})}function Na({className:e,...t}){return(0,r.jsx)("div",{className:j("flex justify-end gap-2 mt-4",e),...t})}function Ca({className:e,...t}){return(0,r.jsx)("h2",{className:j("text-sm font-semibold text-foreground",e),...t})}function Ma({className:e,...t}){return(0,r.jsx)("p",{className:j("text-xs text-foreground-muted",e),...t})}var Ea=(0,h.createContext)(null);function zs(){const e=(0,h.useContext)(Ea);if(!e)throw new Error("Dropdown compound components must be used within <Dropdown>");return e}function If({children:e}){const[t,s]=(0,h.useState)(!1),n=(0,h.useId)(),o=(0,h.useId)(),a=(0,h.useRef)(null);return(0,r.jsx)(Ea.Provider,{value:{open:t,setOpen:s,triggerId:n,contentId:o,triggerRef:a},children:(0,r.jsx)("div",{className:"relative inline-block",children:e})})}function Lf({children:e,...t}){const{open:s,setOpen:n,triggerId:o,contentId:a,triggerRef:i}=zs();return(0,r.jsx)("button",{type:"button",ref:i,id:o,"aria-haspopup":"menu","aria-expanded":s,"aria-controls":s?a:void 0,onClick:()=>n(!s),...t,children:e})}function Of({className:e,children:t,align:s="start",offset:n=4,...o}){const{open:a,setOpen:i,contentId:l,triggerId:u,triggerRef:d}=zs(),f=(0,h.useRef)(null),[p,g]=(0,h.useState)(null);return(0,h.useLayoutEffect)(()=>{if(!a){g(null);return}const b=()=>{const x=d.current;if(!x)return;const v=x.getBoundingClientRect(),w=s==="end"?v.right:v.left;g({top:v.bottom+n,left:w,minWidth:v.width})};return b(),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0),()=>{window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0)}},[a,s,n,d]),(0,h.useEffect)(()=>{if(!a)return;const b=v=>{const w=f.current,y=d.current;w&&!w.contains(v.target)&&!y?.contains(v.target)&&i(!1)},x=v=>{v.key==="Escape"&&i(!1)};return document.addEventListener("mousedown",b),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("keydown",x)}},[a,i,d]),!a||!p||typeof document>"u"?null:(0,Ze.createPortal)((0,r.jsx)("div",{ref:f,id:l,role:"menu","aria-labelledby":u,style:{position:"fixed",top:p.top,...s==="end"?{right:window.innerWidth-p.left}:{left:p.left},minWidth:p.minWidth},className:j("z-50 bg-background-elevated border border-border rounded-md shadow-lg py-1 min-w-[160px]",e),...o,children:t}),document.body)}function _f({className:e,icon:t,variant:s="default",children:n,onClick:o,...a}){const{setOpen:i}=zs(),l=(0,h.useCallback)(u=>{o?.(u),i(!1)},[o,i]);return(0,r.jsxs)("button",{type:"button",role:"menuitem",className:j("h-7 text-xs px-2 w-full text-left flex items-center gap-2",s==="danger"?"text-danger hover:bg-danger/10":"text-foreground hover:bg-surface-hover",e),onClick:l,...a,children:[t&&(0,r.jsx)(t,{size:14}),n]})}var Aa=(0,h.createContext)(null);function Pa(){const e=(0,h.useContext)(Aa);if(!e)throw new Error("Tooltip compound components must be used within <Tooltip>");return e}function $f({children:e}){const[t,s]=(0,h.useState)(!1),n=(0,h.useRef)(null),o=(0,h.useId)(),a=()=>{n.current=setTimeout(()=>s(!0),300)},i=()=>{n.current&&clearTimeout(n.current),s(!1)};return(0,r.jsx)(Aa.Provider,{value:{open:t,show:a,hide:i,tooltipId:o},children:(0,r.jsx)("div",{className:"relative inline-block",children:e})})}function Gf({children:e,...t}){const{show:s,hide:n,tooltipId:o,open:a}=Pa();return(0,r.jsx)("div",{onMouseEnter:s,onMouseLeave:n,onFocus:s,onBlur:n,"aria-describedby":a?o:void 0,...t,children:e})}function Bf({className:e,children:t,...s}){const{open:n,tooltipId:o}=Pa();return(0,r.jsx)("div",{id:o,role:"tooltip",className:j("absolute bottom-full left-1/2 -translate-x-1/2 mb-2 bg-foreground text-background text-xs px-2 py-1 rounded-md shadow-md whitespace-nowrap pointer-events-none transition-opacity duration-150",n?"opacity-100":"opacity-0",e),...s,children:t})}var Ra="(max-width: 767px)",Da="(min-width: 768px) and (max-width: 1023px)";function Ta(e){return t=>{const s=window.matchMedia(e);return s.addEventListener("change",t),()=>s.removeEventListener("change",t)}}function Ia(e){return()=>window.matchMedia(e).matches}function La(){return!1}function ir(){return(0,h.useSyncExternalStore)(Ta(Ra),Ia(Ra),La)}function Ff(){return(0,h.useSyncExternalStore)(Ta(Da),Ia(Da),La)}function Qs({open:e,onClose:t,title:s,children:n,className:o}){return(0,h.useEffect)(()=>{if(!e)return;const a=i=>{i.key==="Escape"&&t()};return document.addEventListener("keydown",a),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",a),document.body.style.overflow=""}},[e,t]),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:j("fixed inset-0 z-40 bg-black/50 transition-opacity duration-200",e?"opacity-100":"pointer-events-none opacity-0"),onClick:t,"aria-hidden":"true"}),(0,r.jsxs)("div",{role:"dialog","aria-modal":"true",className:j("fixed inset-x-0 bottom-0 z-50 flex flex-col bg-background-elevated border-t border-border rounded-t-xl shadow-2xl transition-transform duration-200 ease-out","max-h-[80dvh]",e?"translate-y-0":"translate-y-full",o),children:[(0,r.jsx)("div",{className:"flex justify-center pt-2 pb-1",children:(0,r.jsx)("div",{className:"h-1 w-8 rounded-full bg-foreground-subtle/30"})}),s&&(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 pb-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:s}),(0,r.jsx)("button",{onClick:t,className:"p-1 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors",children:(0,r.jsx)(Pe,{className:"h-4 w-4"})})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:n})]})]})}var Oa=(0,h.createContext)(null);function _a(){const e=(0,h.useContext)(Oa);if(!e)throw new Error("Popover compound components must be used within <Popover>");return e}function $a({children:e,open:t,onOpenChange:s}){const[n,o]=(0,h.useState)(!1),a=t??n,i=(0,h.useId)(),l=(0,h.useId)(),u=(0,h.useCallback)(d=>{s?.(d),t===void 0&&o(d)},[t,s]);return(0,r.jsx)(Oa.Provider,{value:{open:a,setOpen:u,triggerId:i,contentId:l},children:(0,r.jsx)("div",{className:"relative inline-block",children:e})})}function Ga({children:e,...t}){const{open:s,setOpen:n,triggerId:o,contentId:a}=_a();return(0,r.jsx)("button",{type:"button",id:o,"aria-haspopup":"dialog","aria-expanded":s,"aria-controls":s?a:void 0,onClick:()=>n(!s),...t,children:e})}function Ba({className:e,children:t,...s}){const{open:n,setOpen:o,contentId:a,triggerId:i}=_a(),l=ir(),u=(0,h.useRef)(null);return(0,h.useEffect)(()=>{if(!n||l)return;const d=p=>{const g=u.current,b=document.getElementById(i);g&&!g.contains(p.target)&&!b?.contains(p.target)&&o(!1)},f=p=>{p.key==="Escape"&&o(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",f)}},[n,o,i,l]),n?l?(0,r.jsx)(Qs,{open:n,onClose:()=>o(!1),children:t}):(0,r.jsx)("div",{ref:u,id:a,role:"dialog","aria-labelledby":i,className:j("absolute left-0 top-full z-50 mt-1 bg-background-elevated border border-border rounded-lg shadow-lg p-3",e),...s,children:t}):null}var Fa=(0,h.createContext)(null);function za(){const e=(0,h.useContext)(Fa);if(!e)throw new Error("Tabs compound components must be used within <Tabs>");return e}function zf({value:e,onValueChange:t,defaultValue:s="",className:n,...o}){const[a,i]=(0,h.useState)(s),l=e??a,u=(0,h.useCallback)(d=>{t?.(d),e===void 0&&i(d)},[e,t]);return(0,r.jsx)(Fa.Provider,{value:{value:l,setValue:u},children:(0,r.jsx)("div",{className:n,...o})})}function Qf({className:e,...t}){return(0,r.jsx)("div",{role:"tablist",className:j("flex flex-row border-b border-border-subtle",e),...t})}function Uf({value:e,className:t,...s}){const{value:n,setValue:o}=za(),a=e===n;return(0,r.jsx)("button",{type:"button",role:"tab","aria-selected":a,"aria-controls":`tabpanel-${e}`,tabIndex:a?0:-1,className:j("h-7 text-xs px-3 transition-colors",a?"border-b-2 border-primary text-foreground font-medium":"text-foreground-muted hover:text-foreground",t),onClick:()=>o(e),...s})}function Hf({value:e,className:t,...s}){const{value:n}=za();return e!==n?null:(0,r.jsx)("div",{role:"tabpanel",id:`tabpanel-${e}`,className:j("pt-3",t),...s})}var Us=(0,h.forwardRef)(({className:e,...t},s)=>(0,r.jsx)("div",{ref:s,className:j("overflow-auto [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-surface-hover [&::-webkit-scrollbar-thumb]:rounded-full",e),...t}));Us.displayName="ScrollArea";function Vf({title:e,onClose:t,children:s,defaultWidth:n=360,defaultHeight:o=280,minWidth:a=280,minHeight:i=160,offsetIndex:l=0,className:u}){const[d,f]=(0,h.useState)({x:80+l*30,y:80+l*30}),[p,g]=(0,h.useState)({w:n,h:o}),[b,x]=(0,h.useState)(!1),v=(0,h.useRef)(!1),w=(0,h.useRef)(!1),y=(0,h.useRef)({x:0,y:0}),S=ir(),k=(0,h.useCallback)(N=>{N.preventDefault(),v.current=!0,y.current={x:N.clientX-d.x,y:N.clientY-d.y}},[d]),C=(0,h.useCallback)(N=>{N.preventDefault(),N.stopPropagation(),w.current=!0,y.current={x:N.clientX,y:N.clientY}},[]);return(0,h.useEffect)(()=>{const N=R=>{if(v.current&&f({x:R.clientX-y.current.x,y:R.clientY-y.current.y}),w.current){const A=R.clientX-y.current.x,Q=R.clientY-y.current.y;y.current={x:R.clientX,y:R.clientY},g(ee=>({w:Math.max(a,ee.w+A),h:Math.max(i,ee.h+Q)}))}},E=()=>{v.current=!1,w.current=!1};return window.addEventListener("mousemove",N),window.addEventListener("mouseup",E),()=>{window.removeEventListener("mousemove",N),window.removeEventListener("mouseup",E)}},[a,i]),S?(0,r.jsxs)("div",{className:j("fixed inset-x-0 bottom-0 z-50 rounded-t-xl border-t border-border bg-background-elevated shadow-2xl flex flex-col overflow-hidden",u),style:{maxHeight:"60dvh"},children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b border-border shrink-0 bg-surface",children:[(0,r.jsx)("span",{className:"text-[11px] font-medium truncate",children:e}),(0,r.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,r.jsx)("button",{onClick:()=>x(!b),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",children:b?(0,r.jsx)(ta,{size:12}):(0,r.jsx)(sa,{size:12})}),(0,r.jsx)("button",{onClick:t,className:"p-0.5 rounded hover:bg-danger/20 text-foreground-muted hover:text-danger transition-colors",children:(0,r.jsx)(Pe,{size:12})})]})]}),!b&&(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:s})]}):(0,r.jsxs)("div",{className:j("fixed z-50 rounded-lg border border-border bg-background-elevated shadow-2xl flex flex-col overflow-hidden",u),style:{left:d.x,top:d.y,width:b?280:p.w,height:b?"auto":p.h},children:[(0,r.jsxs)("div",{onMouseDown:k,className:"flex items-center justify-between gap-2 px-3 py-2 border-b border-border cursor-move select-none shrink-0 bg-surface",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,r.jsx)(Yd,{size:12,className:"text-foreground-subtle shrink-0"}),(0,r.jsx)("span",{className:"text-[11px] font-medium truncate",children:e})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,r.jsx)("button",{onClick:()=>x(!b),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",title:b?"Restore":"Minimize",children:b?(0,r.jsx)(ta,{size:12}):(0,r.jsx)(sa,{size:12})}),(0,r.jsx)("button",{onClick:t,className:"p-0.5 rounded hover:bg-danger/20 text-foreground-muted hover:text-danger transition-colors",title:"Close",children:(0,r.jsx)(Pe,{size:12})})]})]}),!b&&(0,r.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto relative",children:[s,(0,r.jsx)("div",{onMouseDown:C,className:"absolute bottom-0 right-0 w-4 h-4 cursor-nwse-resize",style:{background:"linear-gradient(135deg, transparent 50%, var(--color-foreground-subtle) 50%)",opacity:.4}})]})]})}function Qa({open:e,onClose:t,children:s,className:n,width:o="w-64"}){const a=(0,h.useRef)(null);return(0,h.useEffect)(()=>{if(!e)return;const i=l=>{l.key==="Escape"&&t()};return document.addEventListener("keydown",i),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",i),document.body.style.overflow=""}},[e,t]),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:j("fixed inset-0 z-40 bg-black/50 backdrop-blur-sm transition-opacity duration-200",e?"opacity-100":"pointer-events-none opacity-0"),onClick:t,"aria-hidden":"true"}),(0,r.jsx)("div",{ref:a,role:"dialog","aria-modal":"true",className:j("fixed inset-y-0 left-0 z-50 flex flex-col bg-surface border-r border-border shadow-2xl transition-transform duration-200 ease-out",o,e?"translate-x-0":"-translate-x-full",n),children:s})]})}function Wf({items:e,className:t}){return(0,r.jsx)("nav",{className:`flex items-center gap-1 text-[11px] text-foreground-subtle ${t??""}`,children:e.map((s,n)=>{const o=n===e.length-1,a=!o&&(s.onClick||s.href);return(0,r.jsxs)(h.default.Fragment,{children:[n>0&&(0,r.jsx)(mt,{className:"h-3 w-3 flex-shrink-0"}),a?s.onClick?(0,r.jsx)("button",{type:"button",onClick:s.onClick,className:"hover:text-foreground transition-colors",children:s.label}):(0,r.jsx)("a",{href:s.href,className:"hover:text-foreground transition-colors",children:s.label}):(0,r.jsx)("span",{className:o?"text-foreground font-medium":"",children:s.label})]},n)})})}var Ua={left:"text-left",right:"text-right",center:"text-center"};function qf({columns:e,rows:t,rowKey:s,onRowClick:n,minWidthPx:o=480,emptyMessage:a,className:i,bordered:l=!0,rowClassName:u}){return t.length===0&&a?(0,r.jsx)("div",{className:`rounded-lg ${l?"border border-border":""} bg-surface px-3 py-4 text-xs text-foreground-subtle text-center ${i??""}`,children:a}):t.length===0?null:(0,r.jsx)("div",{className:`rounded-lg ${l?"border border-border":""} bg-surface overflow-x-auto ${i??""}`,children:(0,r.jsxs)("table",{className:"w-full text-xs",style:{minWidth:`${o}px`},children:[(0,r.jsx)("thead",{className:"bg-surface",children:(0,r.jsx)("tr",{children:e.map(d=>{const f=d.align??"left",p=d.nowrap??!0;return(0,r.jsx)("th",{className:["px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border",Ua[f],p?"whitespace-nowrap":"",d.width??""].filter(Boolean).join(" "),children:d.headerRender?d.headerRender():d.header},d.key)})})}),(0,r.jsx)("tbody",{children:t.map((d,f)=>{const p=s?s(d,f):f,g=u?.(d,f)??"",b=n!==void 0;return(0,r.jsx)("tr",{onClick:b?()=>n(d,f):void 0,className:[b?"cursor-pointer hover:bg-primary/5":"hover:bg-primary/5",g].filter(Boolean).join(" "),children:e.map(x=>{const v=x.align??"left",w=x.nowrap??!1;return(0,r.jsx)("td",{className:["px-3 py-2 text-foreground border-b border-border",Ua[v],w?"whitespace-nowrap":""].filter(Boolean).join(" "),children:x.render(d,f)},x.key)})},p)})})]})})}function Kf({open:e,onClose:t,title:s,subtitle:n,footer:o,children:a,widthClass:i="w-[360px]"}){return(0,h.useEffect)(()=>{if(!e)return;const l=u=>{u.key==="Escape"&&t()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e,t]),e?(0,r.jsxs)("aside",{className:j("absolute top-0 right-0 bottom-0 z-20 flex flex-col","bg-surface border-l border-border shadow-xl",i),role:"dialog","aria-modal":"false",children:[(0,r.jsxs)("header",{className:"flex items-start justify-between gap-2 px-4 py-3 border-b border-border",children:[(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("div",{className:"text-sm font-semibold text-foreground truncate",children:s}),n!==void 0&&(0,r.jsx)("div",{className:"text-[11px] text-foreground-subtle mt-0.5 truncate",children:n})]}),(0,r.jsx)("button",{type:"button",onClick:t,className:"p-1 rounded hover:bg-muted text-foreground-subtle hover:text-foreground","aria-label":"Close panel",children:(0,r.jsx)(Pe,{className:"w-4 h-4"})})]}),(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3",children:a}),o!==void 0&&(0,r.jsx)("footer",{className:"flex items-center gap-2 justify-end px-4 py-3 border-t border-border",children:o})]}):null}var Zf={inherit:"bg-muted",on:"bg-emerald-500",off:"bg-orange-500",na:"bg-gray-300 opacity-50"};function Ha({node:e,depth:t,selectedAddonId:s,onSelect:n,agentDots:o}){const a=e.addonId===s,i=o?.[e.addonId]??[];return(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{type:"button",onClick:()=>n(e.addonId),className:j("w-full flex items-center justify-between gap-2 text-left px-3 py-1.5 text-xs","border-l-2",a?"bg-accent border-primary text-foreground font-medium":"border-transparent hover:bg-muted/40 text-foreground"),style:{paddingLeft:`${12+t*14}px`},children:[(0,r.jsx)("span",{className:"truncate",children:e.addonName}),i.length>0&&(0,r.jsx)("span",{className:"flex items-center gap-1 shrink-0",children:i.map(l=>(0,r.jsx)("span",{title:`${l.agentNodeId}: ${l.state}`,className:j("w-2 h-2 rounded-full",Zf[l.state])},l.agentNodeId))})]}),e.children.map(l=>(0,r.jsx)(Ha,{node:l,depth:t+1,selectedAddonId:s,onSelect:n,agentDots:o},l.addonId))]})}function Yf({tree:e,selectedAddonId:t,onSelect:s,agentDots:n,className:o}){return(0,r.jsx)("div",{className:j("flex flex-col py-2",o),children:e.map(a=>(0,r.jsx)(Ha,{node:a,depth:0,selectedAddonId:t,onSelect:s,agentDots:n},a.addonId))})}function Xf(e){const t=[],s=[],n=new Map;for(const a of e.slots)for(const i of a.addons){const l={addonId:i.id,addonName:i.name,slot:i.slot,inputClasses:i.inputClasses,outputClasses:i.outputClasses,children:[]};i.slot==="audio-classifier"?t.push(l):(s.push(l),n.set(i.id,l))}const o=[];for(const a of s){if(a.inputClasses.length===0){o.push(a);continue}const i=s.find(l=>l.addonId!==a.addonId&&l.outputClasses.some(u=>a.inputClasses.includes(u)));i&&i.children.push(a)}return[...o,...t]}function Jf(e){return e?e.models.map(t=>({id:t.id,name:t.name})):[]}function Br({step:e,schema:t,allSchemas:s,depth:n=0,onChange:o,onDelete:a,readOnly:i=!1,toggleMode:l="simple",overrideState:u=null,onOverrideChange:d,inheritedEnabled:f,hideModelAndSettings:p=!1}){const[g,b]=(0,h.useState)(!1),x=Jf(t);if(x.length>0&&!x.some(w=>w.id===e.modelId)&&!i){const w=(t?.defaultModelId?x.find(y=>y.id===t.defaultModelId):null)??x[0];w&&w.id!==e.modelId&&queueMicrotask(()=>o({...e,modelId:w.id}))}const v=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("span",{className:"text-[10px] uppercase tracking-wider font-medium text-foreground-subtle/60 block leading-none",children:e.slot}),(0,r.jsx)("span",{className:"text-sm font-semibold text-foreground truncate block leading-tight",children:e.addonName}),(0,r.jsxs)("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(w=>(0,r.jsx)("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-blue-500/12 text-blue-400",children:w},w)),e.inputClasses.length>0&&e.outputClasses.length>0&&(0,r.jsx)("span",{className:"text-foreground-subtle/40 text-[10px]",children:"→"}),e.outputClasses.map(w=>(0,r.jsx)("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-green-500/12 text-green-400",children:w},w))]})]}),!i&&l==="simple"&&(0,r.jsx)("button",{onClick:w=>{w.stopPropagation(),o({...e,enabled:!e.enabled})},className:j("relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors",e.enabled?"bg-success":"bg-foreground-subtle/30"),children:(0,r.jsx)("span",{className:j("inline-block h-4 w-4 rounded-full bg-white shadow transition-transform",e.enabled?"translate-x-6":"translate-x-1")})}),!i&&l==="threeState"&&d&&(0,r.jsxs)("div",{className:"flex items-center gap-0.5 rounded-md border border-border p-0.5",onClick:w=>w.stopPropagation(),children:[(0,r.jsx)(Vs,{label:"Inherit",active:u===null,variant:"inherit",subtext:f===void 0?void 0:f?"on":"off",onClick:()=>d(null)}),(0,r.jsx)(Vs,{label:"On",active:u===!0,variant:"on",onClick:()=>d(!0)}),(0,r.jsx)(Vs,{label:"Off",active:u===!1,variant:"off",onClick:()=>d(!1)})]})]});return(0,r.jsx)(ga,{expanded:g,onExpandedChange:b,dimmed:!e.enabled,header:v,children:p?(0,r.jsx)("p",{className:"text-[11px] text-foreground-subtle",children:"Model and detection settings are managed per agent — open the Pipeline page for this camera's agent to edit them."}):(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)(Hs,{label:"Model",value:e.modelId,disabled:i,options:x.map(w=>({value:w.id,label:w.name})),onChange:w=>o({...e,modelId:w})}),e.slot==="audio-classifier"&&e.engine&&(0,r.jsx)(Hs,{label:"Runtime",value:`${e.engine.runtime}/${e.engine.backend}`,disabled:i,options:[{value:"node/cpu",label:"Node.js — ONNX CPU"},{value:"node/coreml",label:"Node.js — Apple SoundAnalysis (macOS)"},{value:"python/cpu",label:"Python — ONNX CPU"}],onChange:w=>{const[y,S]=w.split("/");o({...e,engine:{runtime:y,backend:S,format:S==="coreml"?"coreml":"onnx"}})}}),t?.configSchema?.map(w=>(0,r.jsx)(Fr,{field:w,allFields:t.configSchema??[],step:e,disabled:i,onChange:o},w.key))]})})}function Hs({label:e,value:t,options:s,disabled:n,onChange:o}){return(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e}),(0,r.jsxs)("select",{value:t,onChange:a=>o(a.target.value),disabled:n,className:"w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground focus:outline-none focus:border-primary/50",children:[s.length===0&&(0,r.jsx)("option",{value:t,children:t||"default"}),s.map(a=>(0,r.jsx)("option",{value:a.value,disabled:a.disabled,children:a.label},a.value))]})]})}function em({label:e,description:t,value:s,options:n,disabled:o,onChange:a}){function i(l){o||a(s.includes(l)?s.filter(u=>u!==l):[...s,l])}return(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1",children:e}),t&&(0,r.jsx)("p",{className:"text-[10px] text-foreground-subtle/60 mb-1.5",children:t}),(0,r.jsx)("div",{className:"flex flex-wrap gap-1.5",children:n.map(l=>(0,r.jsx)("button",{type:"button",disabled:o,onClick:()=>i(l.value),className:j("text-[10px] font-medium px-2 py-1 rounded-md border transition-colors",s.includes(l.value)?"bg-primary/20 text-primary border-primary/40":"bg-surface text-foreground-subtle border-border hover:border-primary/30",o&&"opacity-50 cursor-not-allowed"),children:l.label},l.value))})]})}function tm(e,t,s){const n=t.settings?.[e];if(n!==void 0)return n;const o=s.find(a=>"key"in a&&a.key===e);return o&&"default"in o?o.default:void 0}function Fr({field:e,allFields:t,step:s,disabled:n,onChange:o}){const a=e.type!=="separator"&&e.type!=="info"?e.showWhen:void 0;if(a){const{field:l,equals:u,notEquals:d,in:f,notIn:p}=a,g=tm(l,s,t);if(u!==void 0&&g!==u||d!==void 0&&g===d||f!==void 0&&!f.includes(g)||p!==void 0&&p.includes(g))return null}function i(l){o({...s,settings:{...s.settings,[e.key]:l}})}if(e.type==="select"){const l=s.settings?.[e.key],u=typeof l=="string"?l:e.default??"";return(0,r.jsx)(Hs,{label:e.label,value:u,disabled:n||e.disabled,options:e.options,onChange:i})}if(e.type==="multiselect"){const l=s.settings?.[e.key],u=Array.isArray(l)?l:Array.isArray(e.default)?e.default:[];return(0,r.jsx)(em,{label:e.label,description:e.description,value:u,options:e.options,disabled:n||e.disabled,onChange:i})}if(e.type==="slider"||e.type==="number"){const l=s.settings?.[e.key],u=typeof e.default=="number"?e.default:e.min??0,d=typeof l=="number"?l:u,f=e.min??0,p=e.max??1,g=e.step??.01,b=e.type==="slider"?e.showValue:!0,x="unit"in e?e.unit:void 0,v=e.type==="slider"?e.displayScale:void 0,w=v?d/v:d;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,r.jsx)("span",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide",children:e.label}),b&&(0,r.jsxs)("span",{className:"text-xs font-medium text-foreground tabular-nums",children:[typeof w=="number"?w.toFixed(2).replace(/\.?0+$/,""):w,x?` ${x}`:""]})]}),e.description&&(0,r.jsx)("p",{className:"text-[10px] text-foreground-subtle/60 mb-1.5",children:e.description}),(0,r.jsx)("input",{type:"range",min:f,max:p,step:g,value:d,disabled:n||e.disabled,onChange:y=>i(Number(y.target.value)),className:"w-full accent-primary h-1.5"})]})}if(e.type==="boolean"){const l=s.settings?.[e.key];return(0,r.jsxs)("label",{className:"flex items-center gap-2",children:[(0,r.jsx)("input",{type:"checkbox",checked:typeof l=="boolean"?l:e.default===!0,disabled:n||e.disabled,onChange:u=>i(u.target.checked),className:"h-3.5 w-3.5 accent-primary"}),(0,r.jsx)("span",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide",children:e.label})]})}if(e.type==="text"||e.type==="password"||e.type==="textarea"){const l=s.settings?.[e.key],u=typeof l=="string"?l:e.default??"",d=e.type==="password"?"password":"text";return(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e.label}),e.type==="textarea"?(0,r.jsx)("textarea",{value:u,disabled:n||e.disabled,placeholder:e.placeholder,onChange:f=>i(f.target.value),rows:3,className:"w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground focus:outline-none focus:border-primary/50 resize-y"}):(0,r.jsx)("input",{type:d,value:u,disabled:n||e.disabled,placeholder:e.placeholder,onChange:f=>i(f.target.value),className:"w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground focus:outline-none focus:border-primary/50"})]})}return e.type==="separator"?(0,r.jsx)("div",{className:"border-t border-border my-2"}):e.type==="info"?(0,r.jsx)("div",{className:"rounded-md border border-border bg-surface px-2 py-1.5 text-[10px] text-foreground-subtle",children:e.content}):null}function Vs({label:e,active:t,variant:s,subtext:n,onClick:o}){return(0,r.jsxs)("button",{type:"button",onClick:o,className:j("px-2 py-1 text-[10px] font-medium rounded transition-colors",t?s==="on"?"bg-green-500/20 text-green-400":s==="off"?"bg-red-500/20 text-red-400":"bg-primary/20 text-primary":"text-foreground-subtle hover:bg-surface-hover"),children:[e,n&&t&&(0,r.jsxs)("span",{className:"ml-1 opacity-60",children:["(",n,")"]})]})}function Va(e,t){return{addonId:e.id,addonName:e.name,slot:e.slot,inputClasses:[...e.inputClasses],outputClasses:[...e.outputClasses],enabled:t.enabled,modelId:t.modelId,children:[],settings:{...t.settings}}}function rm(e,t,s){return s?{enabled:s.enabled??t.enabled,modelId:s.modelId??t.modelId,settings:s.settings??t.settings}:t}function sm({addon:e,agentDefault:t,modelsForFormat:s,onChangeAgentConfig:n}){const o=a=>{n?.({...t,...a})};return(0,r.jsxs)("div",{className:"space-y-4 text-xs",children:[(0,r.jsxs)("label",{className:"flex items-center gap-2",children:[(0,r.jsx)("input",{type:"checkbox",checked:t.enabled,onChange:a=>o({enabled:a.target.checked})}),(0,r.jsxs)("span",{children:["Enabled on this agent (",e.name,")"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle mb-1",children:"Model"}),(0,r.jsx)("select",{className:"w-full bg-surface border border-border rounded px-2 py-1 text-xs",value:t.modelId,onChange:a=>o({modelId:a.target.value}),children:s.map(a=>(0,r.jsx)("option",{value:a.id,children:a.name},a.id))})]}),(e.configSchema?.length??0)>0&&(0,r.jsxs)("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[(0,r.jsx)("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),e.configSchema?.map(a=>(0,r.jsx)(Fr,{field:a,allFields:e.configSchema??[],step:Va(e,t),disabled:!1,onChange:i=>o({settings:{...i.settings}})},a.key))]})]})}function nm({addon:e,agentDefault:t,agentNodeId:s,currentPatch:n,modelsForFormat:o,onChangePatch:a}){const i=rm("device",t,n),l=b=>{const x=b.enabled!==void 0||b.modelId!==void 0||b.settings!==void 0;a?.(x?b:null)},u=b=>{const{enabled:x,...v}=n??{};l(b==="inherit"?v:{...v,enabled:b==="on"})},d=b=>{const{modelId:x,...v}=n??{};l(b===void 0?v:{...v,modelId:b})},f=b=>{const{settings:x,...v}=n??{};l(b===void 0?v:{...v,settings:b})},p=n?.enabled===void 0?"inherit":n.enabled?"on":"off",g=n?.modelId!==void 0;return(0,r.jsxs)("div",{className:"space-y-4 text-xs",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[["inherit","on","off"].map(b=>(0,r.jsx)("button",{type:"button",onClick:()=>u(b),className:j("px-3 py-1 border border-border rounded text-xs capitalize",p===b?"bg-primary text-primary-foreground border-primary":"bg-surface text-foreground hover:bg-muted"),children:b},b)),(0,r.jsxs)("span",{className:"ml-2 text-[10px] text-foreground-subtle",children:["agent default: ",(0,r.jsx)("span",{className:"font-semibold",children:t.enabled?"on":"off"})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,r.jsx)("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Model"}),g?(0,r.jsx)("button",{type:"button",className:"text-[10px] text-foreground-subtle hover:text-foreground",onClick:()=>d(void 0),children:"Clear"}):(0,r.jsx)("button",{type:"button",className:"text-[10px] text-primary hover:underline",onClick:()=>d(t.modelId),children:"Override"})]}),(0,r.jsx)("select",{disabled:!g,className:"w-full bg-surface border border-border rounded px-2 py-1 text-xs disabled:opacity-50",value:g?n?.modelId??t.modelId:t.modelId,onChange:b=>d(b.target.value),children:o.map(b=>(0,r.jsx)("option",{value:b.id,children:b.name},b.id))}),!g&&(0,r.jsxs)("div",{className:"text-[10px] text-foreground-subtle mt-1",children:["inherits from ",s]})]}),(e.configSchema?.length??0)>0&&(()=>{const b=n?.settings!==void 0;return(0,r.jsxs)("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),b?(0,r.jsx)("button",{type:"button",className:"text-[10px] text-foreground-subtle hover:text-foreground",onClick:()=>f(void 0),children:"Clear"}):(0,r.jsx)("button",{type:"button",className:"text-[10px] text-primary hover:underline",onClick:()=>f({...t.settings}),children:"Override"})]}),e.configSchema?.map(x=>(0,r.jsx)(Fr,{field:x,allFields:e.configSchema??[],step:Va(e,i),disabled:!b,onChange:v=>f({...v.settings})},x.key)),!b&&(0,r.jsxs)("div",{className:"text-[10px] text-foreground-subtle",children:["inherits from ",s]})]})})(),(0,r.jsxs)("div",{className:"rounded bg-muted/40 px-3 py-2 text-[11px] text-foreground-subtle",children:[(0,r.jsx)("div",{className:"font-semibold text-foreground mb-0.5",children:"Effective config preview"}),(0,r.jsxs)("div",{className:"font-mono truncate",children:[e.id," · model: ",i.modelId," · ",i.enabled?"on":"off"]})]})]})}function om(e){const{mode:t,addon:s,agentDefault:n,agentNodeId:o,currentPatch:a,onChangeAgentConfig:i,onChangePatch:l,engineFormat:u}=e,d=(0,h.useMemo)(()=>s.models.filter(f=>!!f.formats[u]),[s.models,u]);return t==="agent"?(0,r.jsx)(sm,{addon:s,agentDefault:n,modelsForFormat:d,onChangeAgentConfig:i}):(0,r.jsx)(nm,{addon:s,agentDefault:n,agentNodeId:o,currentPatch:a,modelsForFormat:d,onChangePatch:l})}function am(e){const t=[],s=(n,o)=>{for(const a of n)t.push({node:a,depth:o}),s(a.children,o+1)};return s(e,0),t}var Wa={detector:{label:"detector",className:"text-emerald-500"},cropper:{label:"cropper",className:"text-blue-500"},classifier:{label:"classifier",className:"text-violet-500"},refiner:{label:"refiner",className:"text-amber-500"},"audio-classifier":{label:"audio classifier",className:"text-pink-500"}};function im({slot:e}){const t=Wa[e]??Wa.classifier;return(0,r.jsx)("span",{className:j("text-[9px] font-semibold uppercase tracking-widest leading-none",t.className),children:t.label})}var qa="inline-flex items-center rounded bg-muted px-1.5 py-px text-[9px] font-medium text-foreground-subtle";function lm({inputs:e,outputs:t}){return e.length===0&&t.length===0?null:(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 flex-wrap",children:[e.map(s=>(0,r.jsx)("span",{className:j(qa,"bg-blue-500/10 text-blue-500"),children:s},`in-${s}`)),e.length>0&&t.length>0&&(0,r.jsx)("span",{className:"text-foreground-subtle/60 text-[9px]",children:"→"}),t.map(s=>(0,r.jsx)("span",{className:j(qa,"bg-emerald-500/10 text-emerald-500"),children:s},`out-${s}`))]})}function cm({enabled:e,onChange:t,disabled:s}){return(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":e,disabled:s,onClick:n=>{n.stopPropagation(),t(!e)},className:j("relative inline-flex h-3.5 w-7 shrink-0 items-center rounded-full transition-colors",e?"bg-emerald-500":"bg-foreground-subtle/30",s?"opacity-50 cursor-not-allowed":"cursor-pointer"),title:e?"Click to disable":"Click to enable",children:(0,r.jsx)("span",{className:j("inline-block h-3 w-3 rounded-full bg-white shadow transition-transform",e?"translate-x-3.5":"translate-x-0.5")})})}function um(e){return e.kind==="enabled"?(0,r.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,r.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500 shrink-0"}),(0,r.jsx)("span",{className:"font-mono text-foreground",children:e.modelId})]}):e.kind==="disabled"?(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 text-foreground-subtle",children:[(0,r.jsx)("span",{className:"h-1.5 w-1.5 rounded-full border border-foreground-subtle/60 shrink-0"}),"off"]}):(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 text-foreground-subtle/70",children:[(0,r.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-muted shrink-0"}),"n/a"]})}function dm({node:e,depth:t,agents:s,getCellState:n,onCellClick:o,selectedCell:a,toggleProps:i}){return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"sticky left-0 z-10 bg-surface px-3 py-2 border-b border-border text-xs flex items-start gap-2",style:{paddingLeft:`${12+t*14}px`},children:[(0,r.jsxs)("div",{className:"flex flex-col gap-1 min-w-0 flex-1",children:[(0,r.jsx)(im,{slot:e.slot}),(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,r.jsx)("span",{className:"font-semibold truncate",children:e.addonName}),(0,r.jsx)(lm,{inputs:e.inputClasses,outputs:e.outputClasses})]})]}),i&&(0,r.jsx)("span",{className:"pl-2 pt-0.5 shrink-0",children:(0,r.jsx)(cm,{enabled:i.enabled,onChange:i.onChange,disabled:i.disabled})})]}),s.map(l=>{const u=n(e.addonId,l.agentNodeId),d=a?.addonId===e.addonId&&a.agentNodeId===l.agentNodeId;return(0,r.jsx)("button",{type:"button",onClick:()=>o(e.addonId,l.agentNodeId),className:j("text-left px-3 py-1.5 border-b border-l border-border text-xs hover:bg-muted/40",u.kind==="enabled"&&"bg-emerald-500/5",u.kind==="na"&&"bg-muted/30",d&&"ring-2 ring-primary ring-inset"),children:um(u)},l.agentNodeId)})]})}function fm({tree:e,agents:t,getCellState:s,onCellClick:n,selectedCell:o,onToggleEnabled:a}){const i=(0,h.useMemo)(()=>am(e),[e]),l=`minmax(320px, 1fr) repeat(${t.length}, minmax(160px, 220px))`,u=a!==void 0&&t.length===1,d=t[0]?.agentNodeId;return(0,r.jsx)("div",{className:"overflow-auto border border-border rounded",children:(0,r.jsxs)("div",{className:"grid",style:{gridTemplateColumns:l},children:[(0,r.jsx)("div",{className:"sticky top-0 left-0 z-20 bg-muted/60 px-3 py-2 text-[10px] uppercase tracking-widest text-foreground-subtle border-b border-border",children:"Step"}),t.map(f=>(0,r.jsxs)("div",{className:"sticky top-0 z-10 bg-muted/60 px-3 py-2 border-b border-l border-border",children:[(0,r.jsx)("div",{className:"text-xs font-semibold text-foreground",children:f.agentNodeId}),(0,r.jsx)("div",{className:"text-[10px] text-foreground-subtle truncate",children:f.engineLabel})]},f.agentNodeId)),i.map(({node:f,depth:p})=>{const g=u&&d!==void 0?s(f.addonId,d):null;return(0,r.jsx)(dm,{node:f,depth:p,agents:t,getCellState:s,onCellClick:n,selectedCell:o,toggleProps:u&&g!==null?{enabled:g.kind==="enabled",onChange:b=>a?.(f.addonId,b),disabled:g.kind==="na"}:void 0},f.addonId)})]})})}var Ka=typeof globalThis<"u"?globalThis.__camstackTrpcReact:void 0,m=Ka??(0,st.createTRPCReact)();typeof globalThis<"u"&&!Ka&&(globalThis.__camstackTrpcReact=m);var Ws=ot("camstack:system",null);function Za({system:e,children:t}){return(0,r.jsx)(Ws.Provider,{value:e,children:t})}function jt(){const e=(0,h.useContext)(Ws);if(!e)throw new Error("useSystem(): no <SystemProvider> in tree");return e}function mm(){return(0,h.useContext)(Ws)}function lr(e,t){const s=jt(),n=(0,h.useRef)(t);n.current=t;const[o,a]=(0,h.useState)(s.connectionVersion);(0,h.useEffect)(()=>s.subscribeConnectionEvents((i,l)=>{i==="connected"&&a(l)}),[s]),(0,h.useEffect)(()=>s.subscribeEvent(e,i=>{n.current(i)}),[s,e,o])}function qs(e){const t=(0,h.useRef)(e);return t.current=e,t}function Ks(e,t){const[s,n]=(0,h.useState)(null),o=qs(t);return lr(e,a=>{const i=a.data,l=o.current;l&&!l(i)||n(i)}),s}function pm(e,t,s){const[n,o]=(0,h.useState)(()=>new Map),a=qs(t),i=qs(s);return lr(e,l=>{const u=l.data,d=i.current;if(d&&!d(u))return;const f=a.current(u);o(p=>{const g=new Map(p);return g.set(f,u),g})}),{map:n,values:(0,h.useMemo)(()=>Array.from(n.values()),[n])}}function zr(){const{data:e,isLoading:t}=m.nodes.topology.useQuery(void 0,{staleTime:6e4}),s=Ks("cluster.topology-snapshot")?.nodes??e;return{nodes:(0,h.useMemo)(()=>{const n=[];for(const o of s??[])n.push({id:String(o.id??""),name:String(o.name??o.id??""),shortName:o.isHub?"HUB":String(o.name??o.id??""),isHub:!!o.isHub,isOnline:!!o.isOnline,localIps:o.localIps??[],addons:(o.addons??[]).map(a=>({addonId:a.id,capabilities:a.capabilities}))});return n.sort((o,a)=>o.isHub!==a.isHub?o.isHub?-1:1:o.name.localeCompare(a.name)),n},[s]),isLoading:t}}function hm({selectedNodeId:e,onSelect:t,label:s="Node",hideIcon:n=!1,alwaysShow:o=!1}){const{nodes:a}=zr();return!o&&a.length<=1?null:(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[!n&&(0,r.jsx)(ff,{className:"h-3.5 w-3.5 text-foreground-subtle"}),s&&(0,r.jsx)("span",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:s}),(0,r.jsx)("div",{className:"flex rounded-md border border-border overflow-hidden text-[11px] font-medium",children:a.map((i,l)=>{const u=e===i.id;return(0,r.jsx)("button",{type:"button",onClick:()=>t(i.id),disabled:!i.isOnline,title:i.isOnline?i.name:`${i.name} (offline)`,className:j("px-2.5 py-1 transition-colors",u?"bg-primary/15 text-primary":"bg-transparent text-foreground-subtle hover:bg-surface-hover hover:text-foreground",l>0&&"border-l border-border",!i.isOnline&&"opacity-50 cursor-not-allowed"),children:i.shortName},i.id)})})]})}var gm={online:{colorClass:"bg-success",label:"Online"},offline:{colorClass:"bg-danger",label:"Offline"},degraded:{colorClass:"bg-warning",label:"Degraded"},unknown:{colorClass:"bg-foreground-subtle",label:"Unknown"}};function bm({status:e,showDot:t=!0,showLabel:s=!0,size:n="sm",className:o}){const a=gm[e];return(0,r.jsxs)("span",{className:j("inline-flex items-center gap-1.5",n==="sm"?"text-xs":"text-sm",o),children:[t&&(0,r.jsx)("span",{className:j("h-1.5 w-1.5 shrink-0 rounded-full",a.colorClass),"aria-hidden":"true"}),s&&(0,r.jsx)("span",{className:"text-foreground",children:a.label})]})}var xm={frigate:{colorClass:"bg-provider-frigate",label:"Frigate"},scrypted:{colorClass:"bg-provider-scrypted",label:"Scrypted"},reolink:{colorClass:"bg-provider-reolink",label:"Reolink"},homeAssistant:{colorClass:"bg-provider-homeAssistant",label:"Home Assistant"},rtsp:{colorClass:"bg-provider-rtsp",label:"RTSP"}};function vm({provider:e,showLabel:t=!0,className:s}){const n=xm[e];return(0,r.jsxs)("span",{className:j("inline-flex items-center gap-1.5 text-xs",s),children:[(0,r.jsx)("span",{className:j("h-1.5 w-1.5 shrink-0 rounded-sm",n.colorClass),"aria-hidden":"true"}),t&&(0,r.jsx)("span",{className:"text-foreground",children:n.label})]})}var ym={success:"bg-emerald-400 text-emerald-950",warning:"bg-amber-400 text-amber-950",danger:"bg-red-400 text-red-950",info:"bg-blue-400 text-blue-950",neutral:"bg-foreground-subtle/20 text-foreground"};function Ya({children:e,variant:t="neutral",mono:s,className:n}){return(0,r.jsx)("span",{className:j("inline-flex items-center rounded-md px-2 py-0.5 text-[11px] font-bold leading-tight",s&&"font-mono",ym[t],n),children:e})}function wm({version:e,preRelease:t,className:s}){return(0,r.jsx)(Ya,{variant:t??/-(alpha|beta|rc|dev|canary|next)/i.test(e)?"warning":"success",mono:!0,className:s,children:e})}function Sm({label:e,description:t,error:s,required:n,children:o,orientation:a="vertical",className:i}){const l=a==="horizontal";return(0,r.jsxs)("div",{className:j("flex gap-2",l?"flex-row items-center justify-between":"flex-col",i),children:[(0,r.jsxs)("div",{className:j(l?"flex-1":""),children:[(0,r.jsxs)(Gs,{children:[e,n&&(0,r.jsx)("span",{className:"text-danger ml-0.5",children:"*"})]}),t&&(0,r.jsx)("p",{className:"text-foreground-subtle text-xs mt-0.5",children:t})]}),(0,r.jsx)("div",{className:j(l?"shrink-0":""),children:o}),s&&(0,r.jsx)("p",{className:"text-danger text-xs",children:s})]})}function km({title:e,subtitle:t,actions:s,className:n}){return(0,r.jsxs)("div",{className:j("flex flex-col gap-2 mb-3 sm:flex-row sm:items-center sm:justify-between",n),children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h1",{className:"text-sm font-semibold text-foreground",children:e}),t&&(0,r.jsx)("p",{className:"text-foreground-subtle text-xs",children:t})]}),s&&(0,r.jsx)("div",{className:"flex items-center gap-2 flex-wrap",children:s})]})}function jm({icon:e,title:t,description:s,action:n,className:o}){return(0,r.jsxs)("div",{className:j("flex flex-col items-center justify-center gap-3 py-12",o),children:[e&&(0,r.jsx)(e,{className:"h-12 w-12 text-foreground-subtle","aria-hidden":"true"}),(0,r.jsxs)("div",{className:"flex flex-col items-center gap-1 text-center",children:[(0,r.jsx)("p",{className:"text-foreground-muted text-sm font-medium",children:t}),s&&(0,r.jsx)("p",{className:"text-foreground-subtle text-xs max-w-xs",children:s})]}),n&&(0,r.jsx)("div",{className:"mt-1",children:n})]})}var Xa=ot("camstack:confirm-dialog",null);function Qr(){const e=(0,h.useContext)(Xa);if(!e)throw new Error("useConfirm must be used within ConfirmDialogProvider");return e.confirm}function Nm({children:e}){const[t,s]=(0,h.useState)(null),n=(0,h.useCallback)(u=>new Promise(d=>{s({...u,resolve:d})}),[]),o=()=>{t?.resolve(!0),s(null)},a=()=>{t?.resolve(!1),s(null)},i={danger:{icon:"text-red-400",button:"bg-red-500 hover:bg-red-600 text-white"},warning:{icon:"text-orange-400",button:"bg-orange-500 hover:bg-orange-600 text-white"},default:{icon:"text-primary",button:"bg-primary hover:bg-primary/90 text-white"}},l=t?i[t.variant??"default"]:i.default;return(0,r.jsxs)(Xa.Provider,{value:{confirm:n},children:[e,t&&(0,r.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,r.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:a}),(0,r.jsxs)("div",{className:"relative z-10 w-full max-w-sm mx-4 rounded-xl border border-border bg-surface shadow-2xl overflow-hidden animate-in fade-in zoom-in-95 duration-150",onClick:u=>u.stopPropagation(),children:[(0,r.jsxs)("div",{className:"px-5 pt-5 pb-4",children:[(0,r.jsx)("h3",{className:"text-sm font-semibold text-foreground",children:t.title}),(0,r.jsx)("p",{className:"mt-2 text-xs text-foreground-subtle leading-relaxed",children:t.message})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border bg-surface-hover/30",children:[(0,r.jsx)("button",{type:"button",onClick:a,className:"px-3 py-1.5 text-xs font-medium rounded-md border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:t.cancelLabel??"Cancel"}),(0,r.jsx)("button",{type:"button",onClick:o,className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${l.button}`,children:t.confirmLabel??"Confirm"})]})]})]})]})}function Cm({value:e,label:t,trend:s,className:n}){return(0,r.jsxs)($s,{className:j("flex flex-col gap-1",n),children:[(0,r.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,r.jsx)("span",{className:"text-2xl font-semibold text-foreground",children:e}),s&&(0,r.jsxs)("span",{className:j("inline-flex items-center gap-0.5 text-xs font-medium",s.direction==="up"?"text-success":"text-danger"),children:[s.direction==="up"?(0,r.jsx)(yf,{className:"h-3 w-3"}):(0,r.jsx)(wf,{className:"h-3 w-3"}),s.value,"%"]})]}),(0,r.jsx)("span",{className:"text-xs text-foreground-muted",children:t})]})}function Mm({items:e,className:t}){return(0,r.jsx)("dl",{className:j("flex flex-col",t),children:e.map(s=>(0,r.jsxs)("div",{className:"flex items-center h-7",children:[(0,r.jsx)("dt",{className:"text-foreground-subtle text-xs w-1/3 shrink-0",children:s.key}),(0,r.jsx)("dd",{className:"text-foreground text-xs",children:s.value})]},s.key))})}function Em({children:e,maxHeight:t=300,className:s}){const[n,o]=(0,h.useState)(!1),a=(0,h.useCallback)(()=>{navigator.clipboard.writeText(e).then(()=>{o(!0),setTimeout(()=>o(!1),2e3)})},[e]);return(0,r.jsxs)("div",{className:j("relative group",s),children:[(0,r.jsx)(Us,{style:{maxHeight:t},children:(0,r.jsx)("pre",{className:"font-mono text-xs bg-surface p-3 rounded-md border border-border-subtle",children:(0,r.jsx)("code",{children:e})})}),(0,r.jsx)("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,r.jsx)(_s,{icon:n?sr:pt,"aria-label":"Copy code",variant:"ghost",size:"sm",onClick:a})})]})}function Am({filters:e,values:t,onChange:s,className:n}){const o=ir(),[a,i]=(0,h.useState)(!1),l=(d,f)=>{s({...t,[d]:f})},u=Object.values(t).filter(d=>d!==void 0&&d!=="").length;if(o){const d=e.find(p=>p.type==="search"),f=e.some(p=>p.type!=="search");return(0,r.jsxs)("div",{className:j("flex items-center gap-2",n),children:[d&&(0,r.jsx)($r,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:p=>l(d.key,p.target.value),leftSlot:(0,r.jsx)(nr,{className:"h-3 w-3 text-foreground-subtle"}),className:"flex-1"}),f&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-foreground-muted hover:bg-surface-hover transition-colors shrink-0",children:[(0,r.jsx)(hf,{className:"h-3.5 w-3.5"}),"Filters",u>0&&(0,r.jsx)(Gt,{variant:"info",className:"ml-1 text-[10px] px-1 py-0",children:u})]}),(0,r.jsx)(Qs,{open:a,onClose:()=>i(!1),title:"Filters",children:(0,r.jsx)("div",{className:"flex flex-col gap-3",children:e.filter(p=>p.type!=="search").map(p=>{switch(p.type){case"select":return(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"text-xs text-foreground-muted mb-1 block",children:p.label}),(0,r.jsx)(Gr,{options:p.options,value:t[p.key]??"",onChange:g=>l(p.key,g.target.value),className:"w-full"})]},p.key);case"badge-toggle":return(0,r.jsx)("div",{className:"flex items-center gap-1 flex-wrap",children:p.options.map(g=>{const b=t[p.key]===g.value;return(0,r.jsx)("button",{type:"button",onClick:()=>l(p.key,b?void 0:g.value),children:(0,r.jsx)(Gt,{variant:b?"info":"default",className:"cursor-pointer",children:g.label})},g.value)})},p.key);default:return null}})})})]})]})}return(0,r.jsx)("div",{className:j("flex items-center gap-2 flex-wrap",n),children:e.map(d=>{switch(d.type){case"search":return(0,r.jsx)($r,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:f=>l(d.key,f.target.value),leftSlot:(0,r.jsx)(nr,{className:"h-3 w-3 text-foreground-subtle"}),className:"w-48"},d.key);case"select":return(0,r.jsx)(Gr,{options:d.options,value:t[d.key]??"",onChange:f=>l(d.key,f.target.value),className:"w-36"},d.key);case"badge-toggle":return(0,r.jsx)("div",{className:"flex items-center gap-1",children:d.options.map(f=>{const p=t[d.key]===f.value;return(0,r.jsx)("button",{type:"button",onClick:()=>l(d.key,p?void 0:f.value),children:(0,r.jsx)(Gt,{variant:p?"info":"default",className:"cursor-pointer",children:f.label})},f.value)})},d.key);default:return null}})})}function Zs({label:e,icon:t,href:s,badge:n,active:o=!1,className:a}){return(0,r.jsxs)("a",{href:s,className:j("flex items-center gap-2 h-7 px-2 text-[11px] transition-colors",o?"border-l-2 border-primary bg-primary/[0.08] text-foreground rounded-r-md":"text-foreground-subtle hover:bg-surface-hover rounded-md",a),children:[(0,r.jsx)(t,{className:"h-3.5 w-3.5 shrink-0"}),(0,r.jsx)("span",{className:"truncate flex-1",children:e}),n!==void 0&&(0,r.jsx)(Gt,{className:"ml-auto text-[10px] px-1.5 py-0",children:n})]})}function Ys({logo:e,sections:t,footer:s,onNavigate:n,className:o}){return(0,r.jsxs)("nav",{className:j("bg-surface border-r border-border h-full flex flex-col",o),children:[e&&(0,r.jsx)("div",{className:"px-3 py-2 shrink-0",children:e}),(0,r.jsx)("div",{className:"flex-1 overflow-auto px-1 py-1",children:t.map((a,i)=>(0,r.jsxs)("div",{className:j(i>0?"mt-3":""),children:[a.label&&(0,r.jsx)("span",{className:"text-[10px] text-foreground-disabled uppercase tracking-wider px-2 mb-1 block",children:a.label}),(0,r.jsx)("div",{className:"flex flex-col gap-0.5",onClick:n,children:a.items.map(l=>(0,r.jsx)(Zs,{...l},l.href))})]},i))}),s&&s.length>0&&(0,r.jsxs)("div",{className:"shrink-0 px-1 pb-1",children:[(0,r.jsx)(Bs,{className:"mb-1"}),(0,r.jsx)("div",{className:"flex flex-col gap-0.5",onClick:n,children:s.map(a=>(0,r.jsx)(Zs,{...a},a.href))})]})]})}function Pm({sidebar:e,header:t,mobileLogo:s,mobileActions:n,children:o,className:a}){const i=ir(),[l,u]=(0,h.useState)(!1);return(0,r.jsxs)("div",{className:j("flex h-screen",a),children:[!i&&(0,r.jsx)(Ys,{...e,className:j("w-44",e.className)}),i&&(0,r.jsx)(Qa,{open:l,onClose:()=>u(!1),width:"w-64",children:(0,r.jsx)(Ys,{...e,onNavigate:()=>u(!1),className:"w-full border-r-0"})}),(0,r.jsxs)("div",{className:"flex flex-1 flex-col min-w-0",children:[i&&(0,r.jsxs)("header",{className:"flex items-center h-12 border-b border-border px-3 shrink-0 bg-surface/80 backdrop-blur-sm",children:[(0,r.jsx)("button",{onClick:()=>u(!0),className:"p-1.5 -ml-1.5 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors","aria-label":"Open menu",children:(0,r.jsx)(sf,{className:"h-5 w-5"})}),s&&(0,r.jsx)("div",{className:"flex-1 flex justify-center",children:s}),n&&(0,r.jsx)("div",{className:"shrink-0",children:n})]}),!i&&t&&(0,r.jsxs)("header",{className:"flex items-center h-10 border-b border-border px-4 shrink-0",children:[t.breadcrumbs&&t.breadcrumbs.length>0&&(0,r.jsx)("nav",{className:"flex items-center gap-1 text-xs flex-1 min-w-0",children:t.breadcrumbs.map((d,f)=>{const p=f===t.breadcrumbs.length-1;return(0,r.jsxs)("span",{className:"flex items-center gap-1",children:[f>0&&(0,r.jsx)(mt,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),d.href&&!p?(0,r.jsx)("a",{href:d.href,className:"text-foreground-subtle hover:text-foreground transition-colors truncate",children:d.label}):(0,r.jsx)("span",{className:"text-foreground truncate",children:d.label})]},f)})}),t.actions&&(0,r.jsx)("div",{className:"flex items-center gap-2 ml-auto shrink-0",children:t.actions})]}),(0,r.jsx)("main",{className:"flex-1 overflow-auto p-4",children:o})]})]})}var Rm={online:"bg-success",offline:"bg-danger",warning:"bg-warning",unknown:"bg-foreground-subtle"};function Dm({title:e,subtitle:t,status:s,selected:n,onClick:o,badges:a,actions:i,offlineAction:l,className:u}){const d=s==="offline";return(0,r.jsxs)("div",{onClick:o,className:j("w-full rounded-lg border p-3 text-left transition-colors",o&&"cursor-pointer",n?"border-primary bg-primary/10":"border-border bg-surface hover:bg-surface-hover",d&&!n&&"opacity-50",u),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium truncate",children:e}),s&&(0,r.jsx)("span",{className:j("h-2 w-2 rounded-full shrink-0",Rm[s])})]}),t&&(0,r.jsx)("div",{className:"text-[11px] text-foreground-muted",children:t}),a&&a.length>0&&(0,r.jsx)("div",{className:"flex flex-wrap gap-1 mt-2",children:a.map((f,p)=>{const g=j("rounded px-1.5 py-0.5 text-[10px] flex items-center gap-0.5",n?"bg-primary/20":"bg-surface-hover",f.onClick&&"hover:opacity-80 transition-opacity cursor-pointer");return f.onClick?(0,r.jsxs)("button",{onClick:b=>{b.stopPropagation(),f.onClick()},className:g,children:[f.icon,f.label]},p):(0,r.jsxs)("span",{className:g,children:[f.icon,f.label]},p)})}),!d&&i&&i.length>0&&(0,r.jsx)("div",{className:"flex items-center gap-0.5 mt-2 -mb-1",children:i.map((f,p)=>(0,r.jsx)("button",{onClick:g=>{g.stopPropagation(),f.onClick()},className:"p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors",title:f.label,"aria-label":f.label,children:f.icon},p))}),d&&l&&(0,r.jsx)("div",{className:"mt-2",onClick:f=>f.stopPropagation(),children:l})]})}function Tm({children:e,minCardWidth:t=220,gap:s=3,className:n}){return(0,r.jsx)("div",{className:j("p-4 overflow-y-auto flex-1 content-start",n),style:{display:"grid",gridTemplateColumns:`repeat(auto-fill, minmax(${t}px, 1fr))`,gap:`${s*4}px`},children:e})}var Im="capability.binding-changed";function cr(e,t){const[s,n]=(0,h.useState)(null);return(0,h.useEffect)(()=>{if(t===null){n(null);return}let o=!1;const a=async()=>{try{const l=await e.deviceManager.getBindings.query({deviceId:t});o||n(l)}catch{o||n(l=>l)}};a();const i=e.live?.onEvent.subscribe({category:Im},{onData:l=>{const u=l.data?.source;if(!u){a();return}u.type==="device"&&u.id===t&&a()}});return()=>{o=!0,i?.unsubscribe()}},[e,t]),(0,h.useMemo)(()=>s?(0,z.createDeviceProxy)(e,s):null,[e,s])}function Xs(e){const t=(0,h.useCallback)(n=>e?e.subscribe(()=>n()):()=>{},[e]),s=(0,h.useCallback)(()=>e?.value,[e]);return(0,h.useSyncExternalStore)(t,s,s)}function Ja(e,t,s){const n=cr(e,t);return Xs(n?s(n.state):void 0)}function Bt(e){const t=cr(e.trpc,e.deviceId),s=Xs(t!==null?e.slice(t):void 0),n=t!==null?e.cap(t):void 0;return{dev:t,cap:n,slice:s,available:(e.requireFeature===void 0||(e.deviceFeatures??[]).includes(e.requireFeature))&&n!==void 0&&s!==void 0}}function Lm(e){return e.parentDeviceId===null?"top-level":e.role?"accessory":"adopted"}var Om={minimal:{showIntegrationIcon:!1,showParentBadge:!1,showSnapshot:!1,showBattery:!1,showStableId:!1,showId:!1,showSwitchToggle:!0,showChildrenAccordion:!1},compact:{showIntegrationIcon:!0,showParentBadge:!0,showSnapshot:!0,showBattery:!0,showStableId:!1,showId:!1,showSwitchToggle:!0,showChildrenAccordion:!0},expanded:{showIntegrationIcon:!1,showParentBadge:!0,showSnapshot:!0,showBattery:!0,showStableId:!0,showId:!0,showSwitchToggle:!0,showChildrenAccordion:!0}};function _m(e){const t=Om[e.variant??"compact"];return{showIntegrationIcon:e.showIntegrationIcon??t.showIntegrationIcon,showParentBadge:e.showParentBadge??t.showParentBadge,showSnapshot:e.showSnapshot??t.showSnapshot,showBattery:e.showBattery??t.showBattery,showStableId:e.showStableId??t.showStableId,showId:e.showId??t.showId,showSwitchToggle:e.showSwitchToggle??t.showSwitchToggle,showChildrenAccordion:e.showChildrenAccordion??t.showChildrenAccordion}}var $m={siren:Ir,floodlight:ea,spotlight:ca,"pir-sensor":oa,chime:nf,autotrack:Wo,nightvision:Ds,"privacy-mask":Yo,doorbell:qo},Gm={camera:Ps,hub:Ts,nvr:Ts,light:ea,siren:Ir,switch:vf,sensor:oa,thermostat:xf,button:Ud,generic:Os};function ei(e){return e.role?$m[e.role]??Os:Gm[e.type.toLowerCase()]??Ps}var ti={"native-snapshot":Xd,"two-way-audio":ra,"pan-tilt-zoom":Wo,"ptz-autotrack":rf,"doorbell-button":qo,"motion-trigger":ft,"battery-operated":Ho,rebootable:ia},ri={"native-snapshot":"Native snapshot","two-way-audio":"Two-way audio","pan-tilt-zoom":"Pan-Tilt-Zoom","ptz-autotrack":"PTZ autotrack","doorbell-button":"Doorbell button","motion-trigger":"Motion trigger","battery-operated":"Battery operated",rebootable:"Rebootable"},Bm={"native-snapshot":"snapshot",rebootable:"reboot","pan-tilt-zoom":"ptz","ptz-autotrack":"ptz-autotrack","two-way-audio":"intercom","motion-trigger":"motion-trigger"},si=new Set(["camera","hub","nvr"]);function ni(e){return!si.has(e.type.toLowerCase())}function oi(e){return e.role?!0:!si.has(e.type.toLowerCase())}function ai(e){return(e.features??[]).includes("motion-trigger")}function Fm(e){if(e.length<=24)return e;const t=e.lastIndexOf(":");if(t>=0&&t<e.length-4)return e.slice(t+1);const s=e.split("-");if(s.length>2){const n=s.slice(-2).join("-");if(n.length>=6)return n}return`…${e.slice(-18)}`}function zm({trpc:e,accessoryChildren:t,adoptedChildren:s,onNavigate:n}){return(0,r.jsxs)("div",{className:"border-t border-border-subtle/50",children:[s.length>0&&(0,r.jsx)(ii,{trpc:e,label:"Adopted devices",rows:s,onNavigate:n}),t.length>0&&(0,r.jsx)(ii,{trpc:e,label:"Accessories",rows:t,onNavigate:n})]})}function ii({trpc:e,label:t,rows:s,onNavigate:n}){return(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"px-3 pt-1.5 pb-1 text-[9px] font-semibold uppercase tracking-wide text-foreground-subtle",children:t}),(0,r.jsx)("ul",{children:s.map(o=>(0,r.jsx)(Qm,{trpc:e,child:o,onNavigate:n},o.id))})]})}function Qm({trpc:e,child:t,onNavigate:s}){const n=!t.disabled,o=n&&ni(t),a=n&&ai(t);return(0,r.jsx)("li",{children:(0,r.jsxs)("div",{onClick:i=>{i.stopPropagation(),s(t.id)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-surface-hover transition-colors cursor-pointer",children:[(0,r.jsx)(ei(t),{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),(0,r.jsx)("span",{className:"text-[10.5px] text-foreground flex-1 truncate",children:t.name}),a&&(0,r.jsx)(Hm,{trpc:e,deviceId:t.id,features:t.features}),o&&(0,r.jsx)(Um,{trpc:e,deviceId:t.id}),(0,r.jsx)("span",{className:j("h-1.5 w-1.5 rounded-full flex-shrink-0",t.online?"bg-success":"bg-foreground-subtle/40"),title:t.online?"Online":"Offline"})]})})}function Um({trpc:e,deviceId:t}){const{dev:s,cap:n,slice:o,available:a}=Bt({trpc:e,deviceId:t,cap:p=>p.switch,slice:p=>p.state.switch}),[i,l]=(0,h.useState)(!1);if(s!==null&&!n)return null;const u=o?.on===!0,d={transform:u?"translateX(14px)":"translateX(2px)"},f=async p=>{if(p.stopPropagation(),!(i||!a||!n)){l(!0);try{await n.setState({on:!u})}finally{l(!1)}}};return(0,r.jsx)("button",{type:"button",onClick:p=>{f(p)},disabled:i||!a,className:j("relative inline-flex h-4 w-7 items-center rounded-full border transition-colors flex-shrink-0",u?"bg-success/30 border-success/50":"bg-surface-hover border-border",i&&"opacity-60",!a&&"opacity-40 cursor-not-allowed"),title:a?u?"Turn off":"Turn on":"Awaiting state…","aria-pressed":u,children:(0,r.jsx)("span",{className:j("absolute h-3 w-3 rounded-full transition-all",u?"bg-success":"bg-foreground-subtle"),style:d})})}function Hm({trpc:e,deviceId:t,features:s}){const{dev:n,cap:o,slice:a,available:i}=Bt({trpc:e,deviceId:t,cap:p=>p.motionTrigger,slice:p=>p.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:s}),[l,u]=(0,h.useState)(!1);if(n!==null&&!o)return null;const d=a?.enabled===!0,f=async p=>{if(p.stopPropagation(),!(l||!i||!o)){u(!0);try{await o.setMotionTrigger({enabled:!d})}finally{u(!1)}}};return(0,r.jsx)("button",{type:"button",onClick:p=>{f(p)},disabled:l||!i,className:j("inline-flex h-4 w-4 items-center justify-center rounded transition-colors flex-shrink-0",d?"text-primary bg-primary/10":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover",(l||!i)&&"opacity-50"),title:i?d?"Motion-trigger: on (click to disable)":"Motion-trigger: off (click to enable)":"Awaiting state…","aria-pressed":d,children:(0,r.jsx)(ft,{className:"h-2.5 w-2.5"})})}function li({trpc:e,device:t,flags:s}){if(t.disabled)return null;const n=t.type.toLowerCase(),o=s.showSwitchToggle&&ni(t),a=ai(t),i=n==="hub"||n==="nvr",l=(t.features??[]).includes("rebootable"),u=i&&l;return(0,r.jsxs)(r.Fragment,{children:[a&&(0,r.jsx)(Wm,{trpc:e,deviceId:t.id,features:t.features}),o&&(0,r.jsx)(Vm,{trpc:e,deviceId:t.id}),u&&(0,r.jsx)(Km,{trpc:e,deviceId:t.id})]})}function Vm({trpc:e,deviceId:t}){const{dev:s,cap:n,slice:o,available:a}=Bt({trpc:e,deviceId:t,cap:p=>p.switch,slice:p=>p.state.switch}),[i,l]=(0,h.useState)(!1);if(s!==null&&!n)return null;const u=o?.on===!0,d={transform:u?"translateX(14px)":"translateX(2px)"},f=async p=>{if(p.stopPropagation(),!(i||!a||!n)){l(!0);try{await n.setState({on:!u})}finally{l(!1)}}};return(0,r.jsx)("button",{type:"button",onClick:p=>{f(p)},disabled:i||!a,className:j("relative inline-flex h-4 w-7 items-center rounded-full border transition-colors flex-shrink-0",u?"bg-success/30 border-success/50":"bg-surface-hover border-border",i&&"opacity-60",!a&&"opacity-40 cursor-not-allowed"),title:a?u?"Turn off":"Turn on":"Awaiting state…","aria-pressed":u,children:(0,r.jsx)("span",{className:j("absolute h-3 w-3 rounded-full transition-all",u?"bg-success":"bg-foreground-subtle"),style:d})})}function Wm({trpc:e,deviceId:t,features:s}){const{dev:n,cap:o,slice:a,available:i}=Bt({trpc:e,deviceId:t,cap:p=>p.motionTrigger,slice:p=>p.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:s}),[l,u]=(0,h.useState)(!1);if(n!==null&&!o)return null;const d=a?.enabled===!0,f=async p=>{if(p.stopPropagation(),!(l||!i||!o)){u(!0);try{await o.setMotionTrigger({enabled:!d})}finally{u(!1)}}};return(0,r.jsx)("button",{type:"button",onClick:p=>{f(p)},disabled:l||!i,className:j("inline-flex h-4 w-4 items-center justify-center rounded transition-colors flex-shrink-0",d?"text-primary bg-primary/10":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover",(l||!i)&&"opacity-50"),title:i?d?"Motion-trigger: on (click to disable)":"Motion-trigger: off (click to enable)":"Awaiting state…","aria-pressed":d,children:(0,r.jsx)(ft,{className:"h-2.5 w-2.5"})})}var Js=168,qm=4;function Km({trpc:e,deviceId:t}){const{dev:s,cap:n}=Bt({trpc:e,deviceId:t,cap:w=>w.reboot,slice:()=>{}}),o=(0,h.useRef)(null),a=(0,h.useRef)(null),[i,l]=(0,h.useState)(null),[u,d]=(0,h.useState)(!1),f=s!==null&&n!==void 0&&n!==null,p=i!==null,g=()=>l(null),b=()=>{const w=o.current;if(!w)return;const y=w.getBoundingClientRect(),S=y.right-Js,k=Math.max(8,Math.min(S,window.innerWidth-Js-8));l({top:y.bottom+qm,left:k})};if((0,h.useEffect)(()=>{if(!p)return;const w=S=>{const k=o.current,C=a.current,N=S.target;N!==null&&(k&&k.contains(N)||C&&C.contains(N)||g())},y=S=>{S.key==="Escape"&&(S.stopPropagation(),g())};return document.addEventListener("mousedown",w),document.addEventListener("keydown",y),()=>{document.removeEventListener("mousedown",w),document.removeEventListener("keydown",y)}},[p]),s!==null&&!n)return null;const x=w=>{w.stopPropagation(),p?g():b()},v=async()=>{if(!(u||!f||!n)){d(!0),g();try{await n.reboot({})}finally{d(!1)}}};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{ref:o,type:"button",onClick:x,disabled:u||!f,className:j("inline-flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0",(u||!f)&&"opacity-50",p&&"bg-surface-hover text-foreground"),title:"More actions","aria-label":"More actions","aria-haspopup":"menu","aria-expanded":p,children:(0,r.jsx)(Ko,{className:"h-3 w-3"})}),i&&(0,Ze.createPortal)((0,r.jsx)("div",{ref:a,role:"menu",style:{position:"fixed",top:i.top,left:i.left,width:Js},className:"z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-1",onClick:w=>w.stopPropagation(),children:(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>{v()},disabled:u||!f,className:j("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-[11px] text-foreground","hover:bg-surface-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed"),children:[(0,r.jsx)(ia,{className:"h-3 w-3 shrink-0 text-foreground-subtle"}),(0,r.jsx)("span",{children:"Reboot device"})]})}),document.body)]})}var Zm=Object.freeze([]);function Ym(e){return e==="native"?"native":"enhanced"}function Xm(e){return e.map(t=>({kind:"marker",feature:t}))}function Jm(e,t){const s=new Map,n=t.entries??[];for(const a of n)s.set(a.capName,a);const o=[];for(const a of e){const i=Bm[a];if(i===void 0){o.push({kind:"marker",feature:a});continue}const l=s.get(i);l&&o.push({kind:Ym(l.kind),feature:a,capName:i})}return o}function ep(e,t,s){const[n,o]=(0,h.useState)(null),[a,i]=(0,h.useState)(!1),[l,u]=(0,h.useState)(!0);return(0,h.useEffect)(()=>{if(t===null){o(null),i(!1),u(!1);return}let d=!1;u(!0),i(!1);const f=async()=>{try{const g=await e.deviceManager.getBindings.query({deviceId:t});if(d)return;o(g),u(!1)}catch{if(d)return;i(!0),u(!1)}};f();const p=e.live?.onEvent.subscribe({category:"capability.binding-changed"},{onData:g=>{const b=g.data?.source;if(!b){f();return}b.type==="device"&&b.id===t&&f()}});return()=>{d=!0,p?.unsubscribe()}},[e,t]),s.length===0?{loading:l,resolved:Zm}:l||a||!n?{loading:l,resolved:Xm(s)}:{loading:!1,resolved:Jm(s,n)}}var tp=[];function ci({trpc:e,device:t,flags:s,accessoryCount:n,adoptedCount:o,showFeatureRow:a=!1}){const i=n+o,l=s.showChildrenAccordion&&i>0,u=t.features??tp,d=a&&u.length>0,{resolved:f}=ep(e,d?t.id:null,u),p=d&&f.length>0;return!l&&!p?null:(0,r.jsxs)("div",{className:"flex items-center gap-1.5 flex-nowrap whitespace-nowrap min-w-0",children:[l&&(0,r.jsx)(rp,{accessoryCount:n,adoptedCount:o}),p&&(0,r.jsx)(sp,{resolved:f})]})}function rp({accessoryCount:e,adoptedCount:t}){const s=e+t;return s===0?null:(0,r.jsxs)("span",{className:"text-[9px] font-medium text-foreground-subtle bg-surface-elevated/60 rounded px-1.5 py-0.5 flex-shrink-0",title:t>0&&e>0?`${String(t)} adopted · ${String(e)} accessor${e===1?"y":"ies"}`:t>0?`${String(t)} adopted`:`${String(e)} accessor${e===1?"y":"ies"}`,children:["+",s]})}var ui=240,di=200;function sp({resolved:e}){const t=(0,h.useRef)(null),[s,n]=(0,h.useState)(null),o=()=>{const i=t.current;if(!i)return;const l=i.getBoundingClientRect();n({top:window.innerHeight-l.bottom>=di?l.bottom+4:l.top-di-4,left:Math.max(8,Math.min(l.left,window.innerWidth-ui-8))})},a=()=>n(null);return(0,r.jsxs)("span",{ref:t,className:"relative inline-flex items-center gap-1 cursor-help",onMouseEnter:o,onMouseLeave:a,children:[e.map(i=>{const l=ti[i.feature];return l?(0,r.jsx)("span",{className:"inline-flex items-center justify-center h-4 w-4 rounded bg-surface-elevated/60 text-foreground-subtle",title:ri[i.feature]??i.feature,children:(0,r.jsx)(l,{className:"h-2.5 w-2.5"})},i.feature):null}),s&&(0,Ze.createPortal)((0,r.jsx)(np,{resolved:e,position:s}),document.body)]})}function np({resolved:e,position:t}){return(0,r.jsxs)("div",{style:{position:"fixed",top:t.top,left:t.left,width:ui,pointerEvents:"none"},className:"z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-2",children:[(0,r.jsx)("h5",{className:"text-[9px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5",children:"Features"}),(0,r.jsx)("ul",{className:"space-y-0.5",children:e.map(s=>(0,r.jsx)(op,{entry:s},s.feature))})]})}function op({entry:e}){const t=ti[e.feature],s=ri[e.feature]??e.feature;return(0,r.jsxs)("li",{className:"flex items-center justify-between gap-2 text-[10px]",children:[(0,r.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[t&&(0,r.jsx)(t,{className:"h-3 w-3 text-foreground-subtle"}),(0,r.jsx)("span",{children:s})]}),(0,r.jsx)(ap,{kind:e.kind})]})}function ap({kind:e}){return e==="marker"?(0,r.jsx)("span",{className:"text-[8.5px] px-1 rounded text-foreground-subtle",title:"Informational marker (no cap registered)",children:"marker"}):(0,r.jsx)("span",{className:j("text-[8.5px] px-1 rounded",e==="native"?"bg-success/15 text-success":"bg-primary/15 text-primary"),children:e})}function fi({device:e,variant:t,flags:s,parent:n,integrationIcon:o,hasChildren:a,expanded:i,onToggleExpand:l,onNavigateToParent:u}){const d=ei(e);return(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[s.showChildrenAccordion&&a?(0,r.jsx)("button",{type:"button",onClick:f=>{f.stopPropagation(),l()},className:"flex h-3.5 w-3.5 items-center justify-center text-foreground-subtle hover:text-foreground transition-colors flex-shrink-0","aria-label":i?"Collapse children":"Expand children","aria-expanded":i,children:i?(0,r.jsx)(St,{className:"h-3 w-3"}):(0,r.jsx)(mt,{className:"h-3 w-3"})}):s.showChildrenAccordion?(0,r.jsx)("span",{className:"h-3.5 w-3.5 flex-shrink-0"}):null,(0,r.jsx)(d,{className:j("text-foreground-subtle flex-shrink-0",t==="minimal"?"h-3 w-3":"h-3.5 w-3.5")}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[s.showIntegrationIcon&&o&&(0,r.jsx)("span",{className:"flex-shrink-0",children:o}),(0,r.jsx)("span",{className:j("font-semibold text-foreground truncate",t==="minimal"?"text-[10.5px]":"text-[11px]"),title:e.name,children:e.name})]}),(s.showId||s.showStableId)&&(0,r.jsxs)("div",{className:"mt-0.5 flex items-center gap-1 text-[9px] text-foreground-subtle font-mono truncate",title:s.showStableId?`stableId: ${e.stableId}`:void 0,children:[s.showId&&(0,r.jsxs)("span",{className:"flex-shrink-0 tabular-nums",children:["#",String(e.id)]}),s.showId&&s.showStableId&&(0,r.jsx)("span",{className:"flex-shrink-0 opacity-50",children:"·"}),s.showStableId&&(0,r.jsx)("span",{className:"truncate",children:Fm(e.stableId)})]}),s.showParentBadge&&n&&(0,r.jsxs)("button",{type:"button",onClick:f=>{f.stopPropagation(),u(n.id)},className:"mt-0.5 inline-flex max-w-full items-center gap-1 text-[9px] text-foreground-subtle hover:text-primary transition-colors",title:`Open parent: ${n.name} (#${String(n.id)})`,children:[(0,r.jsx)(Ts,{className:"h-2.5 w-2.5 shrink-0"}),(0,r.jsxs)("span",{className:"truncate",children:["Under: ",n.name]})]})]})]})}function mi(e,t){return Ja(e,t,s=>s.battery)??null}function pi(e,t){const s=cr(e,t),n=(0,h.useRef)(!1),{data:o,isLoading:a,isFetching:i,refetch:l}=(0,Ee.useQuery)({queryKey:["device",t,"snapshot"],queryFn:()=>{if(!s)throw new Error("useDeviceSnapshotImage: device proxy not ready");const f=n.current;return n.current=!1,s.snapshot?.getSnapshot({force:f})??null},enabled:s!==null&&t!==null,staleTime:1e4,gcTime:1440*60*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,retry:!1}),u=o?`data:${o.contentType};base64,${o.base64}`:null;function d(){n.current=!0,l()}return{src:u,loading:a||i,refresh:d}}function ip(e){return e<=10?_d:e<=30?Od:e>=95?Ld:Ho}function lp(e,t){return t!=="none"?"text-emerald-400":e<=10?"text-rose-400":e<=30?"text-amber-400":"text-foreground-subtle"}function hi({status:e,variant:t="compact",className:s}){if(!e)return null;const n=ip(e.percentage),o=lp(e.percentage,e.charging),a=e.charging==="solar"?ca:e.charging==="dc"?of:null,i=e.sleeping;return(0,r.jsxs)("span",{className:j("inline-flex items-center gap-1 text-[10px] font-medium",o,s),title:`Battery: ${Math.round(e.percentage)}%`+(e.charging!=="none"?` · charging (${e.charging})`:"")+(e.sleeping?" · sleeping":""),children:[(0,r.jsx)(n,{className:"h-3.5 w-3.5"}),(0,r.jsxs)("span",{children:[Math.round(e.percentage),"%"]}),a&&(0,r.jsx)(a,{className:"h-3 w-3"}),i&&(0,r.jsx)(Ds,{className:"h-3 w-3 text-blue-300"}),t==="full"&&e.charging!=="none"&&(0,r.jsx)("span",{className:"text-foreground-subtle",children:e.charging})]})}function gi({trpc:e,device:t,status:s,enabled:n,showStatusPills:o=!1}){const a=pi(e,n&&t.online?t.id:null),i=(t.features??[]).includes("battery-operated"),l=o&&i&&!t.disabled,u=mi(e,l?t.id:null);return!n&&!l?null:(0,r.jsxs)("span",{className:"inline-flex items-center gap-1.5 flex-nowrap whitespace-nowrap",children:[l&&u&&(0,r.jsx)(hi,{status:u}),n&&(0,r.jsx)(cp,{deviceName:t.name,snapshotUrl:a.src,status:s})]})}var en=288,bi=196,tn=8;function cp({deviceName:e,snapshotUrl:t,status:s}){const n=(0,h.useRef)(null),[o,a]=(0,h.useState)(null),i=s==="offline"||s==="disabled",l=()=>{const d=n.current;if(!d)return;const f=d.getBoundingClientRect(),p=f.top,g=window.innerHeight-f.bottom,b=p<bi+tn&&g>p,x=b?f.bottom+tn:f.top-bi-tn,v=f.right-en;a({top:x,left:Math.max(8,Math.min(v,window.innerWidth-en-8)),placeBelow:b})},u=()=>a(null);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{ref:n,type:"button",onClick:d=>d.stopPropagation(),onMouseEnter:l,onMouseLeave:u,onFocus:l,onBlur:u,className:"flex h-6 w-6 items-center justify-center rounded text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors flex-shrink-0",title:"Preview","aria-label":"Preview snapshot",children:(0,r.jsx)(Or,{className:"h-3.5 w-3.5"})}),o&&(0,Ze.createPortal)((0,r.jsxs)("div",{style:{position:"fixed",top:o.top,left:o.left,width:en,pointerEvents:"none"},className:"rounded-lg border border-border bg-surface shadow-lg shadow-black/30 z-[9999] overflow-hidden",children:[(0,r.jsx)("div",{className:"h-40 bg-background flex items-center justify-center",children:t&&!i?(0,r.jsx)("img",{src:t,alt:e,className:"h-full w-full object-cover"}):(0,r.jsx)("span",{className:"text-xs text-foreground-subtle",children:s==="offline"?"Offline — no snapshot":s==="disabled"?"Disabled":"No snapshot yet"})}),(0,r.jsx)("div",{className:"px-3 py-2",children:(0,r.jsx)("p",{className:"text-xs font-semibold text-foreground truncate",children:e})})]}),document.body)]})}function xi({status:e}){const t=e==="disabled"?"bg-warning":e==="online"?"bg-success":"bg-danger",s=e==="disabled"?"Disabled":e==="online"?"Online":"Offline";return(0,r.jsx)("span",{className:j("h-1.5 w-1.5 rounded-full flex-shrink-0",t),title:s})}function Ur(e){const{trpc:t,device:s,parent:n,integrationIcon:o,onNavigate:a,className:i}=e,l=_m(e),u=e.variant??"compact",d=e.view??"card",f=!s.disabled,p=s.isCamera??s.type.toLowerCase()==="camera",g=e.children??[],b=g.filter(oi),x=g.filter(R=>!oi(R)),v=g.length>0,[w,y]=(0,h.useState)(!1),S=e.expanded??w,k=e.onToggleExpand??(()=>y(R=>!R)),C=R=>{a?.(R)},N=e.indentLevel??(e.isAccessoryRow?2:0),E=f?s.online?"online":"offline":"disabled";return d==="table"?(0,r.jsx)(dp,{trpc:t,device:s,variant:u,flags:l,parent:n??null,integrationIcon:o??null,accessoryCount:b.length,adoptedCount:x.length,hasChildren:v,expanded:S,onToggleExpand:k,onNavigate:C,displayStatus:E,isCamera:p,showSnapshot:l.showSnapshot&&p,isAccessoryRow:e.isAccessoryRow??!1,indentLevel:N,className:i}):(0,r.jsxs)("div",{className:j("rounded-lg border border-border bg-surface transition-colors",!f&&"opacity-60",i),children:[(0,r.jsxs)("div",{onClick:()=>C(s.id),className:j("flex items-center gap-2 cursor-pointer hover:border-foreground-subtle/30 w-full",u==="minimal"?"px-2.5 py-1.5":"px-3 py-2.5"),children:[(0,r.jsx)(fi,{device:s,variant:u,flags:l,parent:n??null,integrationIcon:o??null,hasChildren:v,expanded:S,onToggleExpand:k,onNavigateToParent:C}),(0,r.jsx)(ci,{trpc:t,device:s,flags:l,accessoryCount:b.length,adoptedCount:x.length,showFeatureRow:!1}),(0,r.jsx)(gi,{trpc:t,device:s,status:E,enabled:l.showSnapshot&&p,showStatusPills:!0}),(0,r.jsx)(li,{trpc:t,device:s,flags:l}),(0,r.jsx)(xi,{status:E})]}),S&&v&&(0,r.jsx)(zm,{trpc:t,accessoryChildren:b,adoptedChildren:x,onNavigate:C})]})}var up={0:"pl-2",1:"pl-6",2:"pl-8"};function dp(e){const{trpc:t,device:s,variant:n,flags:o,parent:a,integrationIcon:i,accessoryCount:l,adoptedCount:u,hasChildren:d,expanded:f,onToggleExpand:p,onNavigate:g,displayStatus:b,isCamera:x,showSnapshot:v,isAccessoryRow:w,indentLevel:y,className:S}=e;return(0,r.jsxs)("tr",{onClick:()=>g(s.id),className:j("cursor-pointer hover:bg-surface-hover transition-colors",!o.showChildrenAccordion&&"border-b border-border-subtle/40",w&&"bg-foreground-subtle/[0.03]",S),children:[(0,r.jsx)("td",{className:j("py-2 align-middle pr-2",up[y]),children:(0,r.jsx)(fi,{device:s,variant:n,flags:o,parent:a,integrationIcon:i,hasChildren:d,expanded:f,onToggleExpand:p,onNavigateToParent:g})}),(0,r.jsx)("td",{className:"px-2 py-2 align-middle text-[10px] text-foreground-subtle whitespace-nowrap",children:s.type}),(0,r.jsx)("td",{className:"px-2 py-2 align-middle",children:(0,r.jsx)(ci,{trpc:t,device:s,flags:o,accessoryCount:l,adoptedCount:u,showFeatureRow:!0})}),(0,r.jsx)("td",{className:"px-2 py-2 align-middle",children:(0,r.jsx)(gi,{trpc:t,device:s,status:b,enabled:v&&x,showStatusPills:!0})}),(0,r.jsx)("td",{className:"px-2 py-2 align-middle text-right whitespace-nowrap",children:(0,r.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,r.jsx)(li,{trpc:t,device:s,flags:o}),(0,r.jsx)(xi,{status:b})]})})]})}function vi(e,t){const[s,n]=(0,h.useState)(e);return(0,h.useEffect)(()=>{const o=setTimeout(()=>n(e),t);return()=>clearTimeout(o)},[e,t]),s}var fp=new Set(["hub","nvr"]);function mp(e){const t=new Map;for(const o of e)t.set(o.id,o);const s=[],n=new Map;for(const o of e){const a=o.parentDeviceId;if(a==null){s.push(o);continue}const i=t.get(a);if(!i){s.push(o);continue}const l=o.role!==null&&o.role!==void 0;if(fp.has(i.type)&&!l){s.push(o);continue}const u=n.get(a);u?u.push(o):n.set(a,[o])}return{topLevel:s,accessoriesByParent:n}}var yi=2;function pp(e,t){if(t<=1)return[{kind:"page",n:1}];if(t<=7){const a=[];for(let i=1;i<=t;i++)a.push({kind:"page",n:i});return a}const s=[],n=Math.max(2,e-yi),o=Math.min(t-1,e+yi);s.push({kind:"page",n:1}),n>2&&s.push({kind:"ellipsis",side:"left"});for(let a=n;a<=o;a++)s.push({kind:"page",n:a});return o<t-1&&s.push({kind:"ellipsis",side:"right"}),s.push({kind:"page",n:t}),s}function hp({currentPage:e,totalItems:t,pageSize:s,onPageChange:n,itemNoun:o="devices"}){if(t<=s)return null;const a=Math.ceil(t/s),i=(e-1)*s+1,l=Math.min(e*s,t),u=pp(e,a);return(0,r.jsxs)("div",{className:"flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle",children:[(0,r.jsxs)("span",{children:["Showing ",i,"–",l," of ",t," ",o]}),(0,r.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,r.jsx)("button",{type:"button","aria-label":"Previous page",disabled:e===1,onClick:()=>n(e-1),className:j("inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle","hover:text-foreground hover:bg-surface-hover transition-colors","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface"),children:(0,r.jsx)(Fd,{className:"h-3 w-3"})}),u.map((d,f)=>d.kind==="ellipsis"?(0,r.jsx)("span",{className:"px-1 text-foreground-subtle/60 select-none",children:"…"},`e-${f}`):(0,r.jsx)("button",{type:"button",onClick:()=>n(d.n),className:j("inline-flex items-center justify-center h-7 min-w-7 px-1.5 rounded border text-[10.5px] font-medium transition-colors",d.n===e?"border-primary/40 bg-primary/10 text-primary":"border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),children:d.n},`p-${d.n}`)),(0,r.jsx)("button",{type:"button","aria-label":"Next page",disabled:e===a,onClick:()=>n(e+1),className:j("inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle","hover:text-foreground hover:bg-surface-hover transition-colors","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface"),children:(0,r.jsx)(mt,{className:"h-3 w-3"})})]})]})}function gp({view:e,onViewChange:t,types:s,currentType:n,onTypeChange:o,addons:a,currentAddon:i,onAddonChange:l,hideAddons:u=!1}){return(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,r.jsxs)("span",{className:"inline-flex border border-border rounded-md overflow-hidden",children:[(0,r.jsx)("button",{type:"button",onClick:()=>t("cards"),className:j("inline-flex items-center justify-center h-7 w-8 transition-colors",e==="cards"?"bg-primary/10 text-primary":"bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),"aria-label":"Cards view",children:(0,r.jsx)(tf,{className:"h-3.5 w-3.5"})}),(0,r.jsx)("button",{type:"button",onClick:()=>t("table"),className:j("inline-flex items-center justify-center h-7 w-8 border-l border-border transition-colors",e==="table"?"bg-primary/10 text-primary":"bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),"aria-label":"Table view",children:(0,r.jsx)(bf,{className:"h-3.5 w-3.5"})})]}),s&&s.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(wi,{children:"Type"}),(0,r.jsx)(rn,{active:n===null,onClick:()=>o(null),children:"All"}),s.map(d=>(0,r.jsx)(rn,{active:n===d,onClick:()=>o(n===d?null:d),children:bp(d)},d))]}),!u&&a&&a.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(wi,{children:"Integration"}),a.map(d=>(0,r.jsx)(rn,{active:i===d.id,icon:d.icon,onClick:()=>l(i===d.id?null:d.id),showClearIcon:i===d.id,children:d.name},d.id))]})]})}function wi({children:e}){return(0,r.jsx)("span",{className:"text-[10px] font-medium uppercase tracking-wider text-foreground-subtle ml-1",children:e})}function rn({active:e,icon:t,onClick:s,showClearIcon:n,children:o}){return(0,r.jsxs)("button",{type:"button",onClick:s,className:j("inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border text-[10.5px] font-medium transition-colors",e?"border-primary/40 bg-primary/15 text-primary":"border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),children:[t&&(0,r.jsx)("span",{className:"inline-flex items-center",children:t}),(0,r.jsx)("span",{children:o}),e&&n&&(0,r.jsx)(Pe,{className:"h-2.5 w-2.5 opacity-70"})]})}function bp(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function xp({variant:e,onClearFilters:t}){return(0,r.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[(0,r.jsx)(Jd,{className:"h-8 w-8 text-foreground-subtle/40 mb-3"}),(0,r.jsx)("p",{className:"text-sm font-medium text-foreground-subtle",children:e==="filtered"?"No devices match the current filters":"No devices yet"}),e==="filtered"&&t&&(0,r.jsx)("button",{type:"button",onClick:t,className:"mt-2 text-[11px] text-primary hover:underline",children:"Clear filters"})]})}function et(e,t){if(e==="root")return t;switch(t){case"view":return"deviceView";case"page":return"devicePage";case"type":return"deviceType";case"q":return"deviceQ";case"addon":return"deviceAddon"}}function Si(e){try{const t=localStorage.getItem(`camstack:${e}:lastFilters`);if(!t)return{};const s=JSON.parse(t);return typeof s!="object"||s===null?{}:s}catch{return{}}}function vp(e,t){try{localStorage.setItem(`camstack:${e}:lastFilters`,JSON.stringify(t))}catch{}}function ki(e,t,s){const n=new URLSearchParams(window.location.search),o=n.get(et(e,"view")),a=o==="cards"||o==="table"?o:s.view??t,i=n.get(et(e,"page")),l=i?parseInt(i,10):1;return{view:a,page:Number.isFinite(l)&&l>=1?l:1,addon:n.get(et(e,"addon"))??s.addon??null,type:n.get(et(e,"type"))??s.type??null,q:n.get(et(e,"q"))??s.q??""}}function yp(e,t,s){const n=new URLSearchParams(window.location.search),o=(l,u)=>{u===null||u===""?n.delete(l):n.set(l,u)};o(et(e,"view"),t.view===s?null:t.view),o(et(e,"page"),t.page===1?null:String(t.page)),o(et(e,"addon"),t.addon),o(et(e,"type"),t.type),o(et(e,"q"),t.q||null);const a=n.toString(),i=a?`${window.location.pathname}?${a}`:window.location.pathname;window.history.replaceState(null,"",i)}function wp(e){const{scope:t,defaultView:s,lsKey:n}=e,[o,a]=(0,h.useState)(()=>ki(t,s,Si(n))),i=(0,h.useRef)(o);i.current=o,(0,h.useEffect)(()=>{const u=()=>{const d=ki(t,s,Si(n));i.current=d,a(d)};return window.addEventListener("popstate",u),()=>window.removeEventListener("popstate",u)},[t,s,n]);const l=(0,h.useCallback)(u=>{const d=u(i.current);i.current=d,a(d),yp(t,d,s),vp(n,{view:d.view,addon:d.addon,type:d.type,q:d.q})},[t,s,n]);return{state:o,setView:(0,h.useCallback)(u=>l(d=>({...d,view:u})),[l]),setPage:(0,h.useCallback)(u=>l(d=>({...d,page:u})),[l]),setAddon:(0,h.useCallback)(u=>l(d=>({...d,addon:u,page:1})),[l]),setType:(0,h.useCallback)(u=>l(d=>({...d,type:u,page:1})),[l]),setQ:(0,h.useCallback)(u=>l(d=>({...d,q:u,page:1})),[l]),clearFilters:(0,h.useCallback)(()=>l(u=>({...u,addon:null,type:null,q:"",page:1})),[l])}}var Sp={cards:24,table:50};function kp(e){const{devices:t,trpc:s,defaultView:n="table",filters:o,forceAddon:a,resolveIntegrationIcon:i,resolveParent:l,onNavigate:u,pageSize:d=Sp,urlScope:f="root",lsKey:p=f==="root"?"devices":"integrations:nested"}=e,g=wp({scope:f,defaultView:n,lsKey:p}),b=g.state.view,x=b==="cards"?d.cards:d.table,[v,w]=(0,h.useState)(g.state.q),y=vi(v,300);(0,h.useEffect)(()=>{y!==g.state.q&&g.setQ(y)},[y]);const S=a??g.state.addon,k=(0,h.useMemo)(()=>{const ae=g.state.q.toLowerCase().trim();return t.filter(ce=>!(S&&ce.addonId!==S||g.state.type&&ce.type!==g.state.type||ae&&!ce.name.toLowerCase().includes(ae)&&!ce.stableId.toLowerCase().includes(ae)))},[t,S,g.state.type,g.state.q]),C=(0,h.useMemo)(()=>mp(k),[k]),N=(0,h.useMemo)(()=>{if(g.state.q.trim()==="")return new Set;const ae=g.state.q.toLowerCase().trim(),ce=new Set;for(const[se,J]of C.accessoriesByParent.entries())J.some(H=>H.name.toLowerCase().includes(ae)||H.stableId.toLowerCase().includes(ae))&&ce.add(se);return ce},[C.accessoriesByParent,g.state.q]),E=C.topLevel.length,R=Math.max(1,Math.ceil(E/x)),A=Math.min(g.state.page,R),Q=(A-1)*x,ee=C.topLevel.slice(Q,Q+x);(0,h.useEffect)(()=>{A!==g.state.page&&g.setPage(A)},[A]),Ap();const ne=S!=null||g.state.type!==null||g.state.q!=="",pe=E===0;return(0,r.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[(0,r.jsx)(gp,{view:b,onViewChange:g.setView,types:o?.types,currentType:g.state.type,onTypeChange:g.setType,addons:o?.addons,currentAddon:g.state.addon,onAddonChange:g.setAddon,hideAddons:a!==void 0}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)(nr,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle pointer-events-none"}),(0,r.jsx)("input",{type:"text",value:v,onChange:ae=>w(ae.target.value),placeholder:"Search by name or stableId","aria-label":"Search devices by name or stableId",className:"h-7 pl-7 pr-2.5 rounded-md border border-border bg-surface text-[11px] text-foreground placeholder:text-foreground-subtle/60 focus:outline-none focus:ring-1 focus:ring-primary/40 w-56"})]})]}),pe?(0,r.jsx)(xp,{variant:ne?"filtered":"nofilter",onClearFilters:ne?g.clearFilters:void 0}):b==="cards"?(0,r.jsx)(jp,{rows:ee,accessoriesByParent:C.accessoriesByParent,trpc:s,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:u??null}):(0,r.jsx)(Mp,{rows:ee,accessoriesByParent:C.accessoriesByParent,autoExpandedParents:N,devices:k,trpc:s,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:u??null}),(0,r.jsx)(hp,{currentPage:A,totalItems:E,pageSize:x,onPageChange:g.setPage}),a===void 0&&ne&&E>0&&(0,r.jsxs)("p",{className:"text-[11px] text-foreground-subtle",children:["Showing ",E," of ",t.length," devices",S&&(0,r.jsxs)(r.Fragment,{children:[" ","· filtered by"," ",(0,r.jsx)("strong",{className:"text-primary",children:o?.addons?.find(ae=>ae.id===S)?.name??S})]})]})]})}function jp({rows:e,accessoriesByParent:t,trpc:s,resolveIntegrationIcon:n,resolveParent:o,onNavigate:a}){return(0,r.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:e.map(i=>{const l=t.get(i.id)??[];return(0,r.jsx)(Ur,{trpc:s,device:i,view:"card",integrationIcon:n?.(i.addonId)??null,parent:i.parentDeviceId!==null?o?.(i.parentDeviceId)??null:null,children:l,onNavigate:a??void 0},i.id)})})}var Np=new Set(["hub","nvr"]);function Cp(e,t){return e.parentDeviceId===null||t===null?0:Np.has(t.toLowerCase())?1:0}function Mp({rows:e,accessoriesByParent:t,autoExpandedParents:s,devices:n,trpc:o,resolveIntegrationIcon:a,resolveParent:i,onNavigate:l}){const u=(0,h.useMemo)(()=>{const d=new Map;for(const f of n)d.set(f.id,f.type);return d},[n]);return(0,r.jsx)("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:(0,r.jsxs)("table",{className:"w-full border-collapse",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border",children:[(0,r.jsx)("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle",children:"Name"}),(0,r.jsx)("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-24",children:"Type"}),(0,r.jsx)("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Features"}),(0,r.jsx)("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-20",children:"Preview"}),(0,r.jsx)("th",{className:"text-right px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Actions"})]})}),(0,r.jsx)("tbody",{children:e.map(d=>{const f=t.get(d.id)??[],p=f.length>0,g=s.has(d.id),b=d.parentDeviceId!==null?i?.(d.parentDeviceId)??null:null,x=d.parentDeviceId!==null?u.get(d.parentDeviceId)??null:null;return(0,r.jsx)(Ep,{parent:d,accessories:f,hasAccessories:p,forceExpanded:g,trpc:o,integrationIcon:a?.(d.addonId)??null,parentRowParent:b,indentLevel:Cp(d,x),onNavigate:l??null},d.id)})})]})})}function Ep({parent:e,accessories:t,hasAccessories:s,forceExpanded:n,trpc:o,integrationIcon:a,parentRowParent:i,indentLevel:l,onNavigate:u}){const[d,f]=(0,h.useState)(n),p=(0,h.useRef)(n);(0,h.useEffect)(()=>{p.current!==n&&(f(n),p.current=n)},[n]);const g=()=>f(b=>!b);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Ur,{trpc:o,device:e,view:"table",integrationIcon:a,parent:i,children:t,onNavigate:u??void 0,showChildrenAccordion:s,expanded:d,onToggleExpand:g,indentLevel:l}),s&&d&&t.map(b=>(0,r.jsx)(Ur,{trpc:o,device:b,view:"table",integrationIcon:null,parent:null,isAccessoryRow:!0,showChildrenAccordion:!1,onNavigate:u??void 0},b.id))]})}function Ap(){(0,Ee.useQueryClient)()}function Pp({options:e,value:t,onChange:s}){return(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:e.map(n=>{const o=n.id===t;return(0,r.jsxs)("button",{onClick:()=>n.available&&s(n.id),disabled:!n.available,className:`flex items-center gap-2 rounded-lg border px-3 py-2 text-xs font-medium transition-all ${o?"border-primary/40 bg-primary/10 text-primary":n.available?"border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground":"border-border/40 bg-surface/40 text-foreground-subtle/40 cursor-not-allowed"}`,children:[(0,r.jsx)(Kd,{className:"h-3.5 w-3.5 shrink-0"}),n.label,n.isBest&&(0,r.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded-full bg-amber-500/15 px-1.5 py-0.5 text-[10px] font-semibold text-amber-400",children:[(0,r.jsx)(gf,{className:"h-2.5 w-2.5"}),"Best"]}),n.platformScore!=null&&(0,r.jsxs)("span",{className:"text-[10px] text-foreground-subtle/60",children:["(",n.platformScore,")"]}),(0,r.jsx)("span",{className:`h-1.5 w-1.5 rounded-full ${n.available?"bg-success":"bg-danger"}`})]},n.id)})})}function Rp(e,t){const s=new Set(t.slots.flatMap(i=>i.addons.map(l=>l.id))),n=[];function o(i){if(!s.has(i.addonId))return n.push(`Addon "${i.addonId}" is no longer available — step removed`),null;const l=t.slots.flatMap(f=>f.addons).find(f=>f.id===i.addonId);let u=i.modelId;if(l&&!l.models.some(f=>f.id===u)){const f=l.defaultModelId;n.push(`Model "${u}" not available for ${i.addonId} — using "${f}"`),u=f}const d=i.children.map(f=>o(f)).filter(f=>f!==null);return{...i,modelId:u,children:d}}const a=e.map(i=>o(i)).filter(i=>i!==null);return{valid:n.length===0,steps:a,warnings:n}}function Dp(e){const t=new Map;for(const s of e.slots)for(const n of s.addons)t.set(n.id,n);return t}function sn(e){return{addonId:e.id,addonName:e.name,slot:e.slot,inputClasses:[...e.inputClasses],outputClasses:[...e.outputClasses],enabled:!0,modelId:e.defaultModelId,children:[]}}function nn({addon:e,onClick:t}){return(0,r.jsx)("button",{type:"button",onClick:t,className:"w-full rounded-lg border border-dashed border-border/60 px-3 py-2.5 text-left transition-all hover:border-primary/30 hover:bg-surface/60 group",children:(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)(Vd,{className:"h-[18px] w-[18px] text-foreground-subtle/30 group-hover:text-primary/60 shrink-0"}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("span",{className:"text-[13px] font-medium text-foreground-subtle/50 group-hover:text-foreground-subtle block truncate",children:e.name}),(0,r.jsxs)("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(s=>(0,r.jsx)("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-blue-500/8 text-blue-400/50",children:s},s)),e.inputClasses.length>0&&e.outputClasses.length>0&&(0,r.jsx)("span",{className:"text-foreground-subtle/25 text-[10px]",children:"→"}),e.outputClasses.map(s=>(0,r.jsx)("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-green-500/8 text-green-400/50",children:s},s))]})]})]})})}function Tp({schema:e,steps:t,onChange:s,templates:n,selectedTemplateId:o,onSelectTemplate:a,onSaveTemplate:i,onUpdateTemplate:l,onDeleteTemplate:u,readOnly:d=!1,excludeAddons:f=[],hideTemplates:p=!1,showOnlyEnabled:g=!1,showSlotLabels:b=!1,toggleMode:x="simple",overrides:v={},onOverrideChange:w,inheritedEnabledByAddon:y={},hideModelAndSettings:S=!1}){const k=$=>({toggleMode:x,hideModelAndSettings:S,...x==="threeState"?{overrideState:v[$]!==void 0?v[$]:null,onOverrideChange:w?_=>w($,_):void 0,inheritedEnabled:y[$]}:{}}),C=(0,h.useMemo)(()=>new Set(f),[f]),N=(0,h.useMemo)(()=>Dp(e),[e]),[E,R]=(0,h.useState)([]),A=o?JSON.stringify(t)!==JSON.stringify(n.find($=>$.id===o)?.steps):!1;function Q($){const _=$.target.value||null;if(_){const te=n.find(U=>U.id===_);te&&R([...Rp(te.steps,e).warnings])}else R([]);a(_)}function ee(){o&&l(o,t)}function ne(){const $=window.prompt("Template name:");$?.trim()&&i($.trim(),t)}function pe(){if(!o)return;const $=n.find(_=>_.id===o);$&&window.confirm(`Delete template "${$.name}"?`)&&u(o)}function ae($){s(t.map(_=>_.addonId!==$.addonId?_:ce($)))}function ce($){const _=$.children.some(te=>te.enabled||te.children.some(U=>U.enabled));return{...$,enabled:$.enabled||_,children:$.children.map(te=>{const U=te.children.some(V=>V.enabled);return{...te,enabled:te.enabled||U}})}}function se($,_){const te=sn(_);s(t.map(U=>U.addonId!==$?U:{...U,children:[...U.children,te]}))}function J($){const _=new Set;for(const te of $){_.add(te.addonId);for(const V of te.children)_.add(V.addonId);const U=J(te.children);for(const V of U)_.add(V)}return _}const H=J(t);function xe($){const _=N.get($.addonId);if(!_)return[];const te=e.slots.find(F=>F.id===_.slot)?.parentSlot==null,U=_.childSlots,V=new Set($.children.map(F=>F.addonId)),W=[];for(const F of e.slots)if(U.includes(F.id))for(const X of F.addons){if(V.has(X.id)||C.has(X.id))continue;const q=X.inputClasses.length===0;q&&!te||(q||X.inputClasses.some(Re=>$.outputClasses.includes(Re)))&&W.push(X)}return W}function de($){const _=g?{...$,children:$.children.filter(U=>U.enabled).map(U=>({...U,children:U.children.filter(V=>V.enabled)}))}:$,te=g?[]:xe(_);return(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)(Br,{step:_,schema:N.get(_.addonId)??null,allSchemas:N,onChange:ae,onDelete:d?void 0:U=>s(t.filter(V=>V.addonId!==U)),readOnly:d,...k(_.addonId)}),(_.children.length>0||te.length>0)&&(0,r.jsxs)("div",{className:"ml-4 pl-3 border-l border-border/60 space-y-1.5",children:[b&&(0,r.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/40",children:"Slot: Cropper / Classifier"}),_.children.map(U=>{const V=xe(U);return(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)(Br,{step:U,schema:N.get(U.addonId)??null,allSchemas:N,depth:1,onChange:W=>{ae({..._,children:_.children.map(F=>F.addonId===W.addonId?W:F)})},onDelete:d?void 0:W=>{ae({..._,children:_.children.filter(F=>F.addonId!==W)})},readOnly:d,...k(U.addonId)}),(U.children.length>0||V.length>0)&&(0,r.jsxs)("div",{className:"ml-4 pl-3 border-l border-border/40 space-y-1.5",children:[b&&(0,r.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/30",children:"Slot: Recognizer"}),U.children.map(W=>(0,r.jsx)(Br,{step:W,schema:N.get(W.addonId)??null,allSchemas:N,depth:2,onChange:F=>{ae({..._,children:_.children.map(X=>X.addonId===U.addonId?{...X,children:X.children.map(q=>q.addonId===F.addonId?F:q)}:X)})},onDelete:d?void 0:F=>{ae({..._,children:_.children.map(X=>X.addonId===U.addonId?{...X,children:X.children.filter(q=>q.addonId!==F)}:X)})},readOnly:d,...k(W.addonId)},W.addonId)),!d&&V.map(W=>(0,r.jsx)(nn,{addon:W,onClick:()=>{const F=sn(W);ae({..._,children:_.children.map(X=>X.addonId===U.addonId?{...X,children:[...X.children,F]}:X)})}},W.id))]})]},U.addonId)}),!d&&te.map(U=>(0,r.jsx)(nn,{addon:U,onClick:()=>se(_.addonId,U)},U.id))]})]},_.addonId)}const D=e.slots.filter($=>$.parentSlot===null).sort(($,_)=>$.priority-_.priority);return(0,r.jsxs)("div",{className:"space-y-4",children:[!p&&(0,r.jsx)("div",{className:"rounded-lg border border-border bg-surface p-3",children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{className:"relative flex-1 min-w-0",children:(0,r.jsxs)("select",{value:o??"",onChange:Q,className:"w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:border-primary/50",children:[(0,r.jsx)("option",{value:"",children:"No template"}),n.map($=>(0,r.jsx)("option",{value:$.id,children:$.name},$.id))]})}),A&&(0,r.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500 shrink-0"}),(0,r.jsx)("button",{onClick:ee,disabled:!o||d,title:"Save",className:j("p-2 rounded-lg border border-border transition-colors",o&&!d?"text-foreground-subtle hover:bg-surface-hover":"text-foreground-subtle/30 cursor-not-allowed"),children:(0,r.jsx)(cf,{className:"h-4 w-4"})}),(0,r.jsx)("button",{onClick:ne,disabled:d,title:"Save As",className:j("p-2 rounded-lg border border-border transition-colors",d?"text-foreground-subtle/30 cursor-not-allowed":"text-foreground-subtle hover:bg-surface-hover"),children:(0,r.jsx)(qd,{className:"h-4 w-4"})}),(0,r.jsx)("button",{onClick:pe,disabled:!o||d,title:"Delete",className:j("p-2 rounded-lg border border-border transition-colors",o&&!d?"text-foreground-subtle hover:text-danger":"text-foreground-subtle/30 cursor-not-allowed"),children:(0,r.jsx)(at,{className:"h-4 w-4"})})]})}),E.length>0&&(0,r.jsxs)("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 text-xs text-amber-400 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("span",{className:"font-medium",children:"Template loaded with warnings:"}),(0,r.jsx)("button",{onClick:()=>R([]),className:"text-amber-400/60 hover:text-amber-400",children:(0,r.jsx)(Pe,{className:"h-3.5 w-3.5"})})]}),E.map(($,_)=>(0,r.jsxs)("div",{children:["• ",$]},_))]}),D.map($=>{const _=t.filter(F=>F.slot===$.id&&!C.has(F.addonId)),te=g?_.filter(F=>F.enabled):_,U=g?[]:$.addons.filter(F=>!H.has(F.id)&&!C.has(F.id)),V=new Map,W=[];for(const F of te)F.group?(V.has(F.group)||V.set(F.group,[]),V.get(F.group).push(F)):W.push(F);return(0,r.jsxs)("div",{className:"space-y-2",children:[b&&(0,r.jsxs)("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50",children:["Slot: ",$.label]}),W.map(F=>de(F)),[...V.entries()].map(([F,X])=>(0,r.jsxs)("div",{className:"space-y-2 rounded-lg border border-border/40 p-2",children:[(0,r.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50 px-1",children:F}),X.map(q=>de(q))]},F)),!d&&U.map(F=>(0,r.jsx)(nn,{addon:F,onClick:()=>{s([...t,sn(F)])}},F.id))]},$.id)})]})}var ur={person:"#3b82f6",vehicle:"#f59e0b",animal:"#22c55e",face:"#a855f7",plate:"#ec4899",bird:"#14b8a6",dog:"#84cc16",cat:"#f97316",car:"#f59e0b",truck:"#d97706",bus:"#b45309",motorcycle:"#eab308",bicycle:"#ca8a04",motion:"#facc15"},ji=["#ef4444","#8b5cf6","#06b6d4","#f97316","#10b981","#6366f1","#e11d48","#0891b2","#7c3aed","#059669"],Ip="#f59e42";function _e(e,t){if(t?.[e])return t[e];if(t?.[e.toLowerCase()])return t[e.toLowerCase()];if(ur[e])return ur[e];if(ur[e.toLowerCase()])return ur[e.toLowerCase()];let s=0;for(let n=0;n<e.length;n++)s=s*31+(e.codePointAt(n)??0)>>>0;return ji[s%ji.length]??"#f59e42"}function Lp({src:e,imageWidth:t,imageHeight:s,detections:n=[],classColors:o,aspectRatio:a,className:i,placeholder:l,showConfidence:u=!0,minConfidence:d=0,borderWidth:f=2}){function p(y){return _e(y,o)}const g=a??(t&&s?`${t}/${s}`:"16/9"),b=n.filter(y=>y.score>=d),x=b.filter(y=>y.kind==="first-level"),v=b.filter(y=>y.kind==="detail"),w=$p(v,y=>y.parentId??"");return(0,r.jsx)("div",{className:j("rounded-lg border border-border bg-surface overflow-hidden relative",i),style:{aspectRatio:g},children:e?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("img",{src:e,className:"absolute inset-0 w-full h-full object-fill",alt:""}),b.map((y,S)=>y.debug?.mask&&y.debug.maskWidth&&y.debug.maskHeight?(0,r.jsx)(Op,{mask:y.debug.mask,maskWidth:y.debug.maskWidth,maskHeight:y.debug.maskHeight,bbox:y.bbox,imageWidth:t,imageHeight:s,color:p(y.macroClass)},`mask-${S}`):null),x.map(y=>{const S=w.get(y.id)??[];return(0,r.jsx)(Ni,{detection:y,imageWidth:t,imageHeight:s,color:p(y.macroClass),showConfidence:u,borderWidth:y.debug?.mask?1:f,children:S.map(k=>(0,r.jsx)(_p,{child:k,parentBbox:y.bbox,color:p(k.macroClass),showConfidence:u},`child-${k.id}`))},`det-${y.id}`)}),v.filter(y=>!y.parentId||!x.some(S=>S.id===y.parentId)).map(y=>(0,r.jsx)(Ni,{detection:y,imageWidth:t,imageHeight:s,color:p(y.macroClass),showConfidence:u,borderWidth:f},`orphan-${y.id}`))]}):(0,r.jsx)("div",{className:"w-full h-full flex items-center justify-center text-foreground-subtle text-sm",children:l??"No image loaded"})})}function Ni({detection:e,imageWidth:t,imageHeight:s,color:n,showConfidence:o,borderWidth:a,children:i}){const{x:l,y:u,width:d,height:f}=e.bbox,p=(0,r.jsxs)("div",{className:"absolute left-0 flex flex-col items-start gap-px",style:{bottom:"100%",marginBottom:"2px"},children:[(0,r.jsxs)("span",{className:"text-[10px] px-1 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:n},children:[e.macroClass,o&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((g,b)=>(0,r.jsxs)("span",{className:"text-[9px] font-semibold px-1 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:_e(g.label)},children:[g.label," ",(g.score*100).toFixed(0),"%"]},`${e.id}-lbl-${b}`))]});return(0,r.jsxs)("div",{className:"absolute rounded-sm",style:{left:`${l/t*100}%`,top:`${u/s*100}%`,width:`${d/t*100}%`,height:`${f/s*100}%`,borderWidth:`${a}px`,borderStyle:"solid",borderColor:n},children:[p,i]})}function Op({mask:e,maskWidth:t,maskHeight:s,bbox:n,imageWidth:o,imageHeight:a,color:i}){const l=(0,h.useRef)(null);return(0,h.useEffect)(()=>{const u=l.current;if(!u)return;const d=u.getContext("2d");if(!d)return;const f=atob(e),p=new Uint8Array(f.length);for(let y=0;y<f.length;y++)p[y]=f.charCodeAt(y);const g=parseInt(i.slice(1,3),16),b=parseInt(i.slice(3,5),16),x=parseInt(i.slice(5,7),16);u.width=t,u.height=s;const v=d.createImageData(t,s),w=t*s;for(let y=0;y<w;y++){const S=y<p.length?p[y]:0,k=y*4;S>0&&(v.data[k]=g,v.data[k+1]=b,v.data[k+2]=x,v.data[k+3]=120)}d.putImageData(v,0,0)},[e,t,s,i]),(0,r.jsx)("canvas",{ref:l,className:"absolute pointer-events-none",style:{left:`${n.x/o*100}%`,top:`${n.y/a*100}%`,width:`${n.width/o*100}%`,height:`${n.height/a*100}%`,imageRendering:"pixelated"}})}function _p({child:e,parentBbox:t,color:s,showConfidence:n}){if(t.width<=0||t.height<=0)return null;const o=(e.bbox.x-t.x)/t.width*100,a=(e.bbox.y-t.y)/t.height*100,i=e.bbox.width/t.width*100,l=e.bbox.height/t.height*100;return(0,r.jsx)("div",{className:"absolute rounded-sm",style:{left:`${Math.max(0,o)}%`,top:`${Math.max(0,a)}%`,width:`${Math.min(100,i)}%`,height:`${Math.min(100,l)}%`,borderWidth:"1px",borderStyle:"solid",borderColor:s},children:(0,r.jsxs)("div",{className:"absolute left-0 flex flex-col items-start gap-px",style:{bottom:"100%",marginBottom:"1px"},children:[(0,r.jsxs)("span",{className:"text-[9px] px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:s},children:[e.macroClass,n&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((u,d)=>(0,r.jsxs)("span",{className:"text-[8px] font-semibold px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:_e(u.label)},children:[u.label," ",(u.score*100).toFixed(0),"%"]},`${e.id}-lbl-${d}`))]})})}function $p(e,t){const s=new Map;for(const n of e){const o=t(n),a=s.get(o)??[];a.push(n),s.set(o,a)}return s}function Gp({detections:e,classColors:t,className:s,hiddenKeys:n,onToggleVisibility:o}){const a=t;if(e.length===0)return(0,r.jsx)("div",{className:"text-sm text-foreground-subtle italic text-center py-4",children:"No detections"});const i=e.filter(f=>f.kind==="first-level"),l=e.filter(f=>f.kind==="detail"),u=new Map;for(const f of l){if(!f.parentId)continue;const p=u.get(f.parentId)??[];p.push(f),u.set(f.parentId,p)}const d=l.filter(f=>!f.parentId||!i.some(p=>p.id===f.parentId));return(0,r.jsxs)("div",{className:s,children:[(0,r.jsxs)("div",{className:"text-xs font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:["Detections (",e.length,")"]}),(0,r.jsxs)("div",{className:"space-y-2",children:[i.map(f=>(0,r.jsx)(Ci,{detection:f,children_:u.get(f.id)??[],colors:a,hiddenKeys:n,onToggleVisibility:o},f.id)),d.map(f=>(0,r.jsx)(Ci,{detection:f,children_:[],colors:a,hiddenKeys:n,onToggleVisibility:o},f.id))]})]})}function Ci({detection:e,children_:t,colors:s,hiddenKeys:n,onToggleVisibility:o}){const a=_e(e.macroClass,s),i=!n?.has(e.id),l=e.debug?.mask,u=e.debug?.maskWidth,d=e.debug?.maskHeight,f=e.debug?.alternateLabels;return(0,r.jsxs)("div",{className:`rounded-md border border-border bg-surface p-3 space-y-1 ${i?"":"opacity-40"}`,children:[(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[o&&(0,r.jsx)("input",{type:"checkbox",checked:i,onChange:()=>o(e.id,!i),className:"h-3.5 w-3.5 rounded border-border accent-primary cursor-pointer shrink-0"}),(0,r.jsx)("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{backgroundColor:a}}),(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:e.macroClass}),e.kind==="detail"&&(0,r.jsx)("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:"detail"}),l&&u&&d&&(0,r.jsxs)("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",u,"x",d]})]}),(0,r.jsx)(zp,{confidence:e.score})]}),(0,r.jsxs)("div",{className:"text-[10px] text-foreground-subtle font-mono",children:["bbox: [",Math.round(e.bbox.x),", ",Math.round(e.bbox.y),","," ",Math.round(e.bbox.x+e.bbox.width),","," ",Math.round(e.bbox.y+e.bbox.height),"]"]}),e.labels.length>0&&(0,r.jsx)("div",{className:"flex flex-wrap gap-1 mt-1",children:e.labels.map((p,g)=>(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 text-[10px] font-medium px-1.5 py-0.5 rounded-full",style:{backgroundColor:_e(p.label,s)+"20",color:_e(p.label,s)},children:[p.label,(0,r.jsxs)("span",{className:"opacity-60",children:[(p.score*100).toFixed(0),"%"]}),p.detectionId&&(0,r.jsxs)("span",{className:"opacity-40 text-[8px]",children:["→ ",p.detectionId]})]},g))}),f&&Object.keys(f).length>0&&(0,r.jsx)(Fp,{alternateLabels:f,colors:s}),t.length>0&&(0,r.jsx)(Bp,{items:t,colors:s,hiddenKeys:n,onToggleVisibility:o})]})}function Bp({items:e,colors:t,hiddenKeys:s,onToggleVisibility:n}){return(0,r.jsx)("div",{className:"ml-4 mt-1.5 space-y-1.5 border-l-2 border-border pl-3",children:e.map(o=>{const a=_e(o.macroClass,t),i=!s?.has(o.id),l=o.debug?.mask,u=o.debug?.maskWidth,d=o.debug?.maskHeight;return(0,r.jsxs)("div",{className:`text-xs space-y-0.5 ${i?"":"opacity-40"}`,children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[n&&(0,r.jsx)("input",{type:"checkbox",checked:i,onChange:()=>n(o.id,!i),className:"h-3 w-3 rounded border-border accent-primary cursor-pointer shrink-0"}),(0,r.jsx)("span",{className:"h-1.5 w-1.5 rounded-full shrink-0",style:{backgroundColor:a}}),(0,r.jsx)("span",{className:"font-medium",style:{color:a},children:o.macroClass}),(0,r.jsxs)("span",{className:"text-foreground-subtle",children:[(o.score*100).toFixed(0),"%"]}),l&&u&&d&&(0,r.jsxs)("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",u,"x",d]})]}),o.labels.length>0&&(0,r.jsx)("div",{className:"flex flex-wrap gap-1 ml-5 mt-0.5",children:o.labels.map((f,p)=>(0,r.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-[9px] font-medium px-1 py-0.5 rounded-full",style:{backgroundColor:_e(f.label,t)+"20",color:_e(f.label,t)},children:[f.label," ",(0,r.jsxs)("span",{className:"opacity-60",children:[(f.score*100).toFixed(0),"%"]})]},p))})]},o.id)})})}function Fp({alternateLabels:e,colors:t}){const[s,n]=(0,h.useState)(!1),o=Object.keys(e);return(0,r.jsxs)("div",{className:"mt-1",children:[(0,r.jsxs)("button",{onClick:()=>n(a=>!a),className:"text-[9px] text-foreground-subtle hover:text-foreground transition-colors flex items-center gap-1",children:[(0,r.jsx)("span",{className:`transition-transform ${s?"rotate-90":""}`,children:"▶"}),"Alternates (",o.length," source",o.length!==1?"s":"",")"]}),s&&(0,r.jsx)("div",{className:"mt-1 ml-3 space-y-1.5",children:o.map(a=>{const i=e[a];return!i||i.length===0?null:(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-[9px] font-medium text-foreground-subtle mb-0.5",children:a}),(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:i.map((l,u)=>(0,r.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-[9px] px-1 py-0.5 rounded-full",style:{backgroundColor:_e(a,t)+"10",color:_e(a,t),opacity:Math.max(.4,l.score)},children:[l.label,(0,r.jsxs)("span",{className:"opacity-60",children:[(l.score*100).toFixed(1),"%"]})]},u))})]},a)})})]})}function zp({confidence:e}){return(0,r.jsxs)("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${e>=.8?"bg-success/10 text-success":e>=.5?"bg-warning/10 text-warning":"bg-danger/10 text-danger"}`,children:[(e*100).toFixed(1),"%"]})}function Qp({timings:e,totalMs:t,className:s}){const n=Object.entries(e);return n.length===0&&t===void 0?null:(0,r.jsxs)("div",{className:`rounded-lg border border-border bg-surface p-3 space-y-2 ${s??""}`,children:[(0,r.jsx)("div",{className:"text-xs font-medium text-foreground-subtle uppercase tracking-wide",children:"Timings"}),(0,r.jsxs)("div",{className:"space-y-1 text-xs",children:[n.map(([o,a])=>(0,r.jsxs)("div",{className:"flex justify-between",children:[(0,r.jsx)("span",{className:"text-foreground-subtle",children:o}),(0,r.jsxs)("span",{className:"font-mono text-foreground",children:[a.toFixed(1),"ms"]})]},o)),t!==void 0&&(0,r.jsxs)("div",{className:"flex justify-between pt-1 border-t border-border font-medium text-foreground",children:[(0,r.jsx)("span",{children:"Total"}),(0,r.jsxs)("span",{className:"font-mono",children:[t.toFixed(1),"ms"]})]})]})]})}function Up({images:e,selectedFilename:t,uploadedName:s,onSelect:n,onUpload:o,className:a,accept:i="image/*",uploadLabel:l="Upload..."}){const u=()=>{const d=document.createElement("input");d.type="file",d.accept=i,d.onchange=()=>{const f=d.files?.[0];if(!f)return;const p=new FileReader;p.onload=()=>{const g=p.result,b=g.split(",")[1];b&&o(b,f.name,g)},p.readAsDataURL(f)},d.click()};return(0,r.jsxs)("div",{className:`flex flex-wrap items-center gap-2 ${a??""}`,children:[e.map(d=>(0,r.jsx)("button",{onClick:()=>n(d.filename),className:`px-3 py-1.5 text-xs rounded-md border transition-colors ${t===d.filename?"bg-primary text-primary-foreground border-primary":"bg-surface border-border text-foreground hover:border-primary/50"}`,children:d.id??d.filename.replace(/\.[^.]+$/,"")},d.filename)),(0,r.jsx)("button",{onClick:u,className:"px-3 py-1.5 text-xs rounded-md border border-border bg-surface text-foreground hover:bg-surface-hover transition-colors",children:l}),s&&(0,r.jsx)("span",{className:"text-xs text-foreground-subtle",children:s})]})}var Hr="w-full px-3 py-2 text-sm rounded-md border border-border bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-primary/50";function Hp({runtime:e,backend:t,modelId:s,agentId:n="hub",runtimes:o,backends:a,models:i,agents:l=[],onRuntimeChange:u,onBackendChange:d,onModelChange:f,onAgentChange:p,layout:g="grid",className:b,showAgent:x=!1}){return(0,r.jsxs)("div",{className:`${g==="grid"?"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4":g==="horizontal"?"flex flex-wrap items-end gap-4":"space-y-3"} ${b??""}`,children:[x&&l.length>0&&(0,r.jsxs)("label",{className:"space-y-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-foreground-subtle",children:"Agent"}),(0,r.jsx)("select",{value:n,onChange:v=>p?.(v.target.value),className:Hr,children:l.map(v=>(0,r.jsxs)("option",{value:v.id,children:[v.name," (",v.status,")"]},v.id))})]}),(0,r.jsxs)("label",{className:"space-y-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-foreground-subtle",children:"Runtime"}),(0,r.jsx)("select",{value:e,onChange:v=>u(v.target.value),className:Hr,children:o.map(v=>(0,r.jsxs)("option",{value:v.value,disabled:!v.available,children:[v.label,v.available?"":" (unavailable)"]},v.value))})]}),(0,r.jsxs)("label",{className:"space-y-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-foreground-subtle",children:"Backend"}),(0,r.jsx)("select",{value:t,onChange:v=>d(v.target.value),className:Hr,children:a.map(v=>(0,r.jsxs)("option",{value:v.id,disabled:!v.available,children:[v.label,v.available?"":" (unavailable)"]},v.id))})]}),(0,r.jsxs)("label",{className:"space-y-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-foreground-subtle",children:"Model"}),(0,r.jsx)("select",{value:s,onChange:v=>f(v.target.value),className:Hr,children:i.length===0?(0,r.jsx)("option",{value:"",children:"No compatible models"}):i.map(v=>(0,r.jsxs)("option",{value:v.id,children:[v.name,v.downloaded?" ✓":""]},v.id))})]})]})}var Vp=class{constructor(){this.keyToValue=new Map,this.valueToKey=new Map}set(e,t){this.keyToValue.set(e,t),this.valueToKey.set(t,e)}getByKey(e){return this.keyToValue.get(e)}getByValue(e){return this.valueToKey.get(e)}clear(){this.keyToValue.clear(),this.valueToKey.clear()}},Mi=class{constructor(e){this.generateIdentifier=e,this.kv=new Vp}register(e,t){this.kv.getByValue(e)||(t||(t=this.generateIdentifier(e)),this.kv.set(t,e))}clear(){this.kv.clear()}getIdentifier(e){return this.kv.getByValue(e)}getValue(e){return this.kv.getByKey(e)}},Wp=class extends Mi{constructor(){super(e=>e.name),this.classToAllowedProps=new Map}register(e,t){typeof t=="object"?(t.allowProps&&this.classToAllowedProps.set(e,t.allowProps),super.register(e,t.identifier)):super.register(e,t)}getAllowedProps(e){return this.classToAllowedProps.get(e)}};function qp(e){if("values"in Object)return Object.values(e);const t=[];for(const s in e)e.hasOwnProperty(s)&&t.push(e[s]);return t}function Kp(e,t){const s=qp(e);if("find"in s)return s.find(t);const n=s;for(let o=0;o<n.length;o++){const a=n[o];if(t(a))return a}}function Ft(e,t){Object.entries(e).forEach(([s,n])=>t(n,s))}function Vr(e,t){return e.indexOf(t)!==-1}function Ei(e,t){for(let s=0;s<e.length;s++){const n=e[s];if(t(n))return n}}var Zp=class{constructor(){this.transfomers={}}register(e){this.transfomers[e.name]=e}findApplicable(e){return Kp(this.transfomers,t=>t.isApplicable(e))}findByName(e){return this.transfomers[e]}},Yp=e=>Object.prototype.toString.call(e).slice(8,-1),Ai=e=>typeof e>"u",Xp=e=>e===null,dr=e=>typeof e!="object"||e===null||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:Object.getPrototypeOf(e)===Object.prototype,on=e=>dr(e)&&Object.keys(e).length===0,ht=e=>Array.isArray(e),Jp=e=>typeof e=="string",eh=e=>typeof e=="number"&&!isNaN(e),th=e=>typeof e=="boolean",rh=e=>e instanceof RegExp,fr=e=>e instanceof Map,mr=e=>e instanceof Set,Pi=e=>Yp(e)==="Symbol",sh=e=>e instanceof Date&&!isNaN(e.valueOf()),Ri=e=>e instanceof Error,Di=e=>typeof e=="number"&&isNaN(e),nh=e=>th(e)||Xp(e)||Ai(e)||eh(e)||Jp(e)||Pi(e),oh=e=>typeof e=="bigint",ah=e=>e===1/0||e===-1/0,ih=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),lh=e=>e instanceof URL,an=e=>e.replace(/\\/g,"\\\\").replace(/\./g,"\\."),ln=e=>e.map(String).map(an).join("."),pr=(e,t)=>{const s=[];let n="";for(let a=0;a<e.length;a++){let i=e.charAt(a);if(!t&&i==="\\"){const l=e.charAt(a+1);if(l==="\\"){n+="\\",a++;continue}else if(l!==".")throw Error("invalid path")}if(i==="\\"&&e.charAt(a+1)==="."){n+=".",a++;continue}if(i==="."){s.push(n),n="";continue}n+=i}const o=n;return s.push(o),s};function tt(e,t,s,n){return{isApplicable:e,annotation:t,transform:s,untransform:n}}var Ti=[tt(Ai,"undefined",()=>null,()=>{}),tt(oh,"bigint",e=>e.toString(),e=>typeof BigInt<"u"?BigInt(e):(console.error("Please add a BigInt polyfill."),e)),tt(sh,"Date",e=>e.toISOString(),e=>new Date(e)),tt(Ri,"Error",(e,t)=>{const s={name:e.name,message:e.message};return"cause"in e&&(s.cause=e.cause),t.allowedErrorProps.forEach(n=>{s[n]=e[n]}),s},(e,t)=>{const s=new Error(e.message,{cause:e.cause});return s.name=e.name,s.stack=e.stack,t.allowedErrorProps.forEach(n=>{s[n]=e[n]}),s}),tt(rh,"regexp",e=>""+e,e=>{const t=e.slice(1,e.lastIndexOf("/")),s=e.slice(e.lastIndexOf("/")+1);return new RegExp(t,s)}),tt(mr,"set",e=>[...e.values()],e=>new Set(e)),tt(fr,"map",e=>[...e.entries()],e=>new Map(e)),tt(e=>Di(e)||ah(e),"number",e=>Di(e)?"NaN":e>0?"Infinity":"-Infinity",Number),tt(e=>e===0&&1/e===-1/0,"number",()=>"-0",Number),tt(lh,"URL",e=>e.toString(),e=>new URL(e))];function Wr(e,t,s,n){return{isApplicable:e,annotation:t,transform:s,untransform:n}}var Ii=Wr((e,t)=>Pi(e)?!!t.symbolRegistry.getIdentifier(e):!1,(e,t)=>["symbol",t.symbolRegistry.getIdentifier(e)],e=>e.description,(e,t,s)=>{const n=s.symbolRegistry.getValue(t[1]);if(!n)throw new Error("Trying to deserialize unknown symbol");return n}),ch=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce((e,t)=>(e[t.name]=t,e),{}),Li=Wr(ih,e=>["typed-array",e.constructor.name],e=>[...e],(e,t)=>{const s=ch[t[1]];if(!s)throw new Error("Trying to deserialize unknown typed array");return new s(e)});function Oi(e,t){return e?.constructor?!!t.classRegistry.getIdentifier(e.constructor):!1}var _i=Wr(Oi,(e,t)=>["class",t.classRegistry.getIdentifier(e.constructor)],(e,t)=>{const s=t.classRegistry.getAllowedProps(e.constructor);if(!s)return{...e};const n={};return s.forEach(o=>{n[o]=e[o]}),n},(e,t,s)=>{const n=s.classRegistry.getValue(t[1]);if(!n)throw new Error(`Trying to deserialize unknown class '${t[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);return Object.assign(Object.create(n.prototype),e)}),$i=Wr((e,t)=>!!t.customTransformerRegistry.findApplicable(e),(e,t)=>["custom",t.customTransformerRegistry.findApplicable(e).name],(e,t)=>t.customTransformerRegistry.findApplicable(e).serialize(e),(e,t,s)=>{const n=s.customTransformerRegistry.findByName(t[1]);if(!n)throw new Error("Trying to deserialize unknown custom value");return n.deserialize(e)}),uh=[_i,Ii,$i,Li],Gi=(e,t)=>{const s=Ei(uh,o=>o.isApplicable(e,t));if(s)return{value:s.transform(e,t),type:s.annotation(e,t)};const n=Ei(Ti,o=>o.isApplicable(e,t));if(n)return{value:n.transform(e,t),type:n.annotation}},Bi={};Ti.forEach(e=>{Bi[e.annotation]=e});var dh=(e,t,s)=>{if(ht(t))switch(t[0]){case"symbol":return Ii.untransform(e,t,s);case"class":return _i.untransform(e,t,s);case"custom":return $i.untransform(e,t,s);case"typed-array":return Li.untransform(e,t,s);default:throw new Error("Unknown transformation: "+t)}else{const n=Bi[t];if(!n)throw new Error("Unknown transformation: "+t);return n.untransform(e,s)}},zt=(e,t)=>{if(t>e.size)throw new Error("index out of bounds");const s=e.keys();for(;t>0;)s.next(),t--;return s.next().value};function Fi(e){if(Vr(e,"__proto__"))throw new Error("__proto__ is not allowed as a property");if(Vr(e,"prototype"))throw new Error("prototype is not allowed as a property");if(Vr(e,"constructor"))throw new Error("constructor is not allowed as a property")}var fh=(e,t)=>{Fi(t);for(let s=0;s<t.length;s++){const n=t[s];if(mr(e))e=zt(e,+n);else if(fr(e)){const o=+n,a=+t[++s]==0?"key":"value",i=zt(e,o);switch(a){case"key":e=i;break;case"value":e=e.get(i);break}}else e=e[n]}return e},cn=(e,t,s)=>{if(Fi(t),t.length===0)return s(e);let n=e;for(let a=0;a<t.length-1;a++){const i=t[a];if(ht(n)){const l=+i;n=n[l]}else if(dr(n))n=n[i];else if(mr(n)){const l=+i;n=zt(n,l)}else if(fr(n)){if(a===t.length-2)break;const l=+i,u=+t[++a]==0?"key":"value",d=zt(n,l);switch(u){case"key":n=d;break;case"value":n=n.get(d);break}}}const o=t[t.length-1];if(ht(n)?n[+o]=s(n[+o]):dr(n)&&(n[o]=s(n[o])),mr(n)){const a=zt(n,+o),i=s(a);a!==i&&(n.delete(a),n.add(i))}if(fr(n)){const a=+t[t.length-2],i=zt(n,a);switch(+o==0?"key":"value"){case"key":{const l=s(i);n.set(l,n.get(i)),l!==i&&n.delete(i);break}case"value":n.set(i,s(n.get(i)));break}}return e},zi=e=>e<1;function un(e,t,s,n=[]){if(!e)return;const o=zi(s);if(!ht(e)){Ft(e,(l,u)=>un(l,t,s,[...n,...pr(u,o)]));return}const[a,i]=e;i&&Ft(i,(l,u)=>{un(l,t,s,[...n,...pr(u,o)])}),t(a,n)}function mh(e,t,s,n){return un(t,(o,a)=>{e=cn(e,a,i=>dh(i,o,n))},s),e}function ph(e,t,s){const n=zi(s);function o(a,i){const l=fh(e,pr(i,n));a.map(u=>pr(u,n)).forEach(u=>{e=cn(e,u,()=>l)})}if(ht(t)){const[a,i]=t;a.forEach(l=>{e=cn(e,pr(l,n),()=>e)}),i&&Ft(i,o)}else Ft(t,o);return e}var hh=(e,t)=>dr(e)||ht(e)||fr(e)||mr(e)||Ri(e)||Oi(e,t);function gh(e,t,s){const n=s.get(e);n?n.push(t):s.set(e,[t])}function bh(e,t){const s={};let n;return e.forEach(o=>{if(o.length<=1)return;t||(o=o.map(l=>l.map(String)).sort((l,u)=>l.length-u.length));const[a,...i]=o;a.length===0?n=i.map(ln):s[ln(a)]=i.map(ln)}),n?on(s)?[n]:[n,s]:on(s)?void 0:s}var Qi=(e,t,s,n,o=[],a=[],i=new Map)=>{const l=nh(e);if(!l){gh(e,o,t);const b=i.get(e);if(b)return n?{transformedValue:null}:b}if(!hh(e,s)){const b=Gi(e,s),x=b?{transformedValue:b.value,annotations:[b.type]}:{transformedValue:e};return l||i.set(e,x),x}if(Vr(a,e))return{transformedValue:null};const u=Gi(e,s),d=u?.value??e,f=ht(d)?[]:{},p={};Ft(d,(b,x)=>{if(x==="__proto__"||x==="constructor"||x==="prototype")throw new Error(`Detected property ${x}. This is a prototype pollution risk, please remove it from your object.`);const v=Qi(b,t,s,n,[...o,x],[...a,e],i);f[x]=v.transformedValue,ht(v.annotations)?p[an(x)]=v.annotations:dr(v.annotations)&&Ft(v.annotations,(w,y)=>{p[an(x)+"."+y]=w})});const g=on(p)?{transformedValue:f,annotations:u?[u.type]:void 0}:{transformedValue:f,annotations:u?[u.type,p]:p};return l||i.set(e,g),g};function Ui(e){return Object.prototype.toString.call(e).slice(8,-1)}function Hi(e){return Ui(e)==="Array"}function xh(e){if(Ui(e)!=="Object")return!1;const t=Object.getPrototypeOf(e);return!!t&&t.constructor===Object&&t===Object.prototype}function vh(e,t,s,n,o){const a={}.propertyIsEnumerable.call(n,t)?"enumerable":"nonenumerable";a==="enumerable"&&(e[t]=s),o&&a==="nonenumerable"&&Object.defineProperty(e,t,{value:s,enumerable:!1,writable:!0,configurable:!0})}function dn(e,t={}){if(Hi(e))return e.map(o=>dn(o,t));if(!xh(e))return e;const s=Object.getOwnPropertyNames(e),n=Object.getOwnPropertySymbols(e);return[...s,...n].reduce((o,a)=>{if(a==="__proto__"||Hi(t.props)&&!t.props.includes(a))return o;const i=e[a];return vh(o,a,dn(i,t),e,t.nonenumerable),o},{})}var ie=class{constructor({dedupe:e=!1}={}){this.classRegistry=new Wp,this.symbolRegistry=new Mi(t=>t.description??""),this.customTransformerRegistry=new Zp,this.allowedErrorProps=[],this.dedupe=e}serialize(e){const t=new Map,s=Qi(e,t,this,this.dedupe),n={json:s.transformedValue};s.annotations&&(n.meta={...n.meta,values:s.annotations});const o=bh(t,this.dedupe);return o&&(n.meta={...n.meta,referentialEqualities:o}),n.meta&&(n.meta.v=1),n}deserialize(e,t){const{json:s,meta:n}=e;let o=t?.inPlace?s:dn(s);return n?.values&&(o=mh(o,n.values,n.v??0,this)),n?.referentialEqualities&&(o=ph(o,n.referentialEqualities,n.v??0)),o}stringify(e){return JSON.stringify(this.serialize(e))}parse(e){return this.deserialize(JSON.parse(e),{inPlace:!0})}registerClass(e,t){this.classRegistry.register(e,t)}registerSymbol(e,t){this.symbolRegistry.register(e,t)}registerCustom(e,t){this.customTransformerRegistry.register({name:t,...e})}allowErrorProps(...e){this.allowedErrorProps.push(...e)}};ie.defaultInstance=new ie,ie.serialize=ie.defaultInstance.serialize.bind(ie.defaultInstance),ie.deserialize=ie.defaultInstance.deserialize.bind(ie.defaultInstance),ie.stringify=ie.defaultInstance.stringify.bind(ie.defaultInstance),ie.parse=ie.defaultInstance.parse.bind(ie.defaultInstance),ie.registerClass=ie.defaultInstance.registerClass.bind(ie.defaultInstance),ie.registerSymbol=ie.defaultInstance.registerSymbol.bind(ie.defaultInstance),ie.registerCustom=ie.defaultInstance.registerCustom.bind(ie.defaultInstance),ie.allowErrorProps=ie.defaultInstance.allowErrorProps.bind(ie.defaultInstance),ie.serialize,ie.deserialize,ie.stringify,ie.parse,ie.registerClass,ie.registerCustom,ie.registerSymbol,ie.allowErrorProps;function yh({className:e}){return(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[(0,r.jsx)("path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function wh({className:e}){return(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[(0,r.jsx)("path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"}),(0,r.jsx)("path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}),(0,r.jsx)("path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"}),(0,r.jsx)("path",{d:"m2 2 20 20"})]})}function Sh({className:e}){return(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function Vi({onLogin:e,serverUrl:t,logoSrc:s,error:n,className:o}){const[a,i]=(0,h.useState)(""),[l,u]=(0,h.useState)(""),[d,f]=(0,h.useState)(!1),[p,g]=(0,h.useState)(!1),[b,x]=(0,h.useState)(null),v=n??b,w=async y=>{if(y.preventDefault(),!p){x(null),g(!0);try{await e(a,l)}catch(S){x(S instanceof Error?S.message:"Login failed. Please try again.")}finally{g(!1)}}};return(0,r.jsx)("div",{className:j("flex min-h-screen items-center justify-center bg-background p-4",o),children:(0,r.jsxs)("div",{className:"w-full max-w-sm",children:[s&&(0,r.jsx)("div",{className:"flex justify-center mb-8",children:(0,r.jsx)("img",{src:s,alt:"Logo",className:"h-12"})}),t&&(0,r.jsx)("p",{className:"mb-4 text-center text-xs text-foreground-subtle truncate",children:t}),(0,r.jsxs)("form",{onSubmit:w,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[v&&(0,r.jsx)("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:v}),(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("label",{className:"text-xs font-medium text-foreground-subtle",children:"Username"}),(0,r.jsx)("input",{type:"text",value:a,onChange:y=>i(y.target.value),autoComplete:"username",required:!0,className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary"})]}),(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("label",{className:"text-xs font-medium text-foreground-subtle",children:"Password"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("input",{type:d?"text":"password",value:l,onChange:y=>u(y.target.value),autoComplete:"current-password",required:!0,className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary"}),(0,r.jsx)("button",{type:"button",onClick:()=>f(y=>!y),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",tabIndex:-1,children:d?(0,r.jsx)(wh,{className:"h-4 w-4"}):(0,r.jsx)(yh,{className:"h-4 w-4"})})]})]}),(0,r.jsxs)("button",{type:"submit",disabled:p,className:"w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center justify-center gap-2",children:[p&&(0,r.jsx)(Sh,{className:"h-4 w-4 animate-spin"}),p?"Logging in...":"Log in"]})]})]})})}var fn="camstack_dev_token",Wi=(0,h.createContext)(null);function kh(){const e=(0,h.useContext)(Wi);if(!e)throw new Error("useDevShell must be used within a DevShell");return e}function jh(){return typeof window>"u"?null:localStorage.getItem(fn)}function Nh({className:e}){return(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,r.jsx)("path",{d:"M12 2v2"}),(0,r.jsx)("path",{d:"M12 20v2"}),(0,r.jsx)("path",{d:"m4.93 4.93 1.41 1.41"}),(0,r.jsx)("path",{d:"m17.66 17.66 1.41 1.41"}),(0,r.jsx)("path",{d:"M2 12h2"}),(0,r.jsx)("path",{d:"M20 12h2"}),(0,r.jsx)("path",{d:"m6.34 17.66-1.41 1.41"}),(0,r.jsx)("path",{d:"m19.07 4.93-1.41 1.41"})]})}function Ch({className:e}){return(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:(0,r.jsx)("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})})}function Mh({children:e,serverUrl:t,title:s,token:n,onLogout:o}){const a=Ge.useThemeMode$1(),i=(0,h.useMemo)(()=>[(0,Te.splitLink)({condition:g=>g.type==="subscription",true:(0,Te.wsLink)({client:(0,Te.createWSClient)({url:t.replace(/^http/,"ws")+"/trpc",connectionParams:()=>({token:n})}),transformer:ie}),false:(0,Te.httpLink)({url:`${t}/trpc`,transformer:ie,headers:()=>({authorization:`Bearer ${n}`})})})],[t,n]),l=(0,h.useMemo)(()=>(0,Te.createTRPCClient)({links:i}),[i]),u=(0,h.useMemo)(()=>m.createClient({links:i}),[i]),d=(0,h.useMemo)(()=>(0,ns.createSystem)({serverUrl:t,token:n}),[t,n]);(0,h.useEffect)(()=>(d.init().catch(()=>{}),()=>{d.close()}),[d]);const f=(0,h.useMemo)(()=>new Ee.QueryClient,[]),p=(0,h.useMemo)(()=>({trpc:l,token:n,logout:o}),[l,n,o]);return(0,r.jsx)(Za,{system:d,children:(0,r.jsx)(m.Provider,{client:u,queryClient:f,children:(0,r.jsx)(Ee.QueryClientProvider,{client:f,children:(0,r.jsx)(Wi.Provider,{value:p,children:(0,r.jsxs)("div",{className:"min-h-screen bg-background text-foreground",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between border-b border-border bg-surface px-4 py-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"rounded bg-warning/20 px-2 py-0.5 text-xs font-bold text-warning",children:"DEV MODE"}),s&&(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:s}),(0,r.jsx)("span",{className:"text-xs text-foreground-subtle",children:t})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("button",{type:"button",onClick:a.toggleMode,className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",title:`Theme: ${a.mode}`,children:[a.resolvedMode==="dark"?(0,r.jsx)(Nh,{className:"h-3.5 w-3.5"}):(0,r.jsx)(Ch,{className:"h-3.5 w-3.5"}),a.mode==="dark"?"Dark":a.mode==="light"?"Light":"System"]}),(0,r.jsx)("button",{type:"button",onClick:o,className:"rounded-md px-2.5 py-1 text-xs font-medium text-danger hover:bg-danger/10 transition-colors",children:"Logout"})]})]}),(0,r.jsx)("div",{className:"p-4",children:e({trpc:l,theme:a})})]})})})})})}function qi({children:e,serverUrl:t="https://localhost:4443",title:s}){const[n,o]=(0,h.useState)(jh),a=(0,h.useCallback)(async(l,u)=>{const d=await(0,Te.createTRPCClient)({links:[(0,Te.httpLink)({url:`${t}/trpc`,transformer:ie})]}).auth.login.mutate({username:l,password:u});if(!d.token)throw new Error("No token returned");localStorage.setItem(fn,d.token),o(d.token)},[t]),i=(0,h.useCallback)(()=>{localStorage.removeItem(fn),o(null)},[]);return n?(0,r.jsx)(Ge.ThemeProvider$1,{children:(0,r.jsx)(Mh,{serverUrl:t,title:s,token:n,onLogout:i,children:e})}):(0,r.jsx)(Ge.ThemeProvider$1,{children:(0,r.jsx)(Vi,{onLogin:a,serverUrl:t})})}function Eh(e,t={}){const{serverUrl:s="https://localhost:4443",title:n,rootId:o="root"}=t,a=document.getElementById(o);if(!a){console.error(`[mountAddonPage] Element #${o} not found`);return}(0,bt.createRoot)(a).render((0,h.createElement)(qi,{serverUrl:s,title:n,children:({trpc:i,theme:l})=>(0,h.createElement)(e,{trpc:i,theme:{isDark:l.resolvedMode==="dark"},navigate:u=>{console.log("[dev] navigate:",u)}})}))}var Ki=ot("camstack:custom-field-renderers",{});function Ah({renderers:e,children:t}){return(0,r.jsx)(Ki.Provider,{value:e,children:t})}function Zi(e){return(0,h.useContext)(Ki)[e]??null}var mn=ot("camstack:device-context",null);function Ph({deviceId:e,device:t,children:s}){const n={deviceId:e,device:t??null};return(0,r.jsx)(mn.Provider,{value:n,children:s})}function Yi(){return(0,h.useContext)(mn)?.deviceId??null}function Rh(){return(0,h.useContext)(mn)?.device??null}var Dh=m.accessories.getStatus.useQuery,Th=m.addonPages.listPages.useQuery,Ih=m.addons.list.useQuery,Lh=m.addons.getLogs.useQuery,Oh=m.addons.listPackages.useQuery,_h=m.addons.installPackage.useMutation,$h=m.addons.installFromWorkspace.useMutation,Gh=m.addons.isWorkspaceAvailable.useQuery,Bh=m.addons.listWorkspacePackages.useQuery,Fh=m.addons.uninstallPackage.useMutation,zh=m.addons.reloadPackages.useMutation,Qh=m.addons.searchAvailable.useQuery,Uh=m.addons.listUpdates.useQuery,Hh=m.addons.updatePackage.useMutation,Vh=m.addons.rollbackPackage.useMutation,Wh=m.addons.forceRefresh.useMutation,qh=m.addons.restartServer.useMutation,Kh=m.addons.getVersions.useQuery,Zh=m.addons.restartAddon.useMutation,Yh=m.addons.retryLoad.useMutation,Xh=m.addons.getAutoUpdateSettings.useQuery,Jh=m.addons.setAutoUpdateSettings.useMutation,eg=m.addons.getAddonAutoUpdate.useQuery,tg=m.addons.setAddonAutoUpdate.useMutation,rg=m.addons.applyAutoUpdateToAll.useMutation,sg=m.addons.custom.useMutation,ng=m.addons.onAddonLogs.useSubscription,og=m.addonSettings.getGlobalSettings.useQuery,ag=m.addonSettings.updateGlobalSettings.useMutation,ig=m.addonSettings.getDeviceSettings.useQuery,lg=m.addonSettings.updateDeviceSettings.useMutation,Xi=m.addonWidgets.listWidgets.useQuery,cg=m.alerts.emit.useMutation,ug=m.alerts.update.useMutation,dg=m.alerts.list.useQuery,fg=m.alerts.getUnreadCount.useQuery,mg=m.alerts.markRead.useMutation,pg=m.alerts.markAllRead.useMutation,hg=m.alerts.dismiss.useMutation,gg=m.audioAnalysis.resolveDeviceSettings.useQuery,bg=m.audioAnalysis.getDeviceSettingsContribution.useQuery,xg=m.audioAnalysis.getDeviceLiveContribution.useQuery,vg=m.audioAnalysis.applyDeviceSettingsPatch.useMutation,yg=m.audioAnalyzer.analyseChunk.useMutation,wg=m.audioAnalyzer.classify.useQuery,Sg=m.audioAnalyzer.isReady.useQuery,kg=m.audioAnalyzer.dispose.useMutation,jg=m.audioAnalyzer.reprobeAudioEngine.useMutation,Ng=m.audioCodec.listSupportedCodecs.useQuery,Cg=m.audioCodec.canHandle.useQuery,Mg=m.audioCodec.createDecodeSession.useMutation,Eg=m.audioCodec.createEncodeSession.useMutation,Ag=m.audioCodec.closeSession.useMutation,Pg=m.audioCodec.pushEncodedFrame.useMutation,Rg=m.audioCodec.pullPcm.useQuery,Dg=m.audioCodec.pushPcm.useMutation,Tg=m.audioCodec.pullEncoded.useQuery,Ig=m.audioCodec.flushEncode.useMutation,Lg=m.audioCodec.listActiveSessions.useQuery,Og=m.audioMetrics.getCurrentSnapshot.useQuery,_g=m.audioMetrics.getHistory.useQuery,$g=m.authentication.listProviders.useQuery,Gg=m.authentication.setProviderEnabled.useMutation,Bg=m.backup.listDestinations.useQuery,Fg=m.backup.trigger.useMutation,zg=m.backup.list.useQuery,Qg=m.backup.listLocations.useQuery,Ug=m.backup.getEntries.useQuery,Hg=m.backup.restore.useMutation,Vg=m.backup.delete.useMutation,Wg=m.backup.listArchives.useQuery,qg=m.backup.upsertDestinationPolicy.useMutation,Kg=m.backup.previewSchedule.useQuery,Zg=m.battery.getStatus.useQuery,Yg=m.brightness.setBrightness.useMutation,Xg=m.brightness.getStatus.useQuery,Jg=m.cameraStreams.getCameraStreams.useQuery,e0=m.cameraStreams.getBrokerStreams.useQuery,t0=m.cameraStreams.getRtspEntries.useQuery,r0=m.decoder.supportsCodec.useQuery,s0=m.decoder.getInfo.useQuery,n0=m.decoder.createSession.useQuery,o0=m.decoder.destroySession.useQuery,a0=m.decoder.pushPacket.useQuery,i0=m.decoder.openStream.useQuery,l0=m.decoder.pullFrames.useQuery,c0=m.decoder.updateConfig.useQuery,u0=m.decoder.getStats.useQuery,d0=m.decoder.listActiveSessions.useQuery,f0=m.decoder.reprobeHwaccel.useMutation,m0=m.detectionPipeline.getDeviceSettingsContribution.useQuery,p0=m.detectionPipeline.getDeviceLiveContribution.useQuery,h0=m.detectionPipeline.applyDeviceSettingsPatch.useMutation,g0=m.deviceDiscovery.listDiscovered.useQuery,b0=m.deviceDiscovery.refreshDiscovery.useMutation,x0=m.deviceDiscovery.adoptDevice.useMutation,v0=m.deviceDiscovery.releaseDevice.useMutation,y0=m.deviceDiscovery.getStatus.useQuery,w0=m.deviceManager.allocateDeviceId.useMutation,S0=m.deviceManager.registerDevice.useMutation,k0=m.deviceManager.removeDevice.useMutation,j0=m.deviceManager.persistConfig.useMutation,N0=m.deviceManager.loadConfig.useQuery,C0=m.deviceManager.loadRuntimeState.useQuery,M0=m.deviceManager.loadMeta.useQuery,E0=m.deviceManager.setName.useMutation,A0=m.deviceManager.setLocation.useMutation,P0=m.deviceManager.setMetadata.useMutation,R0=m.deviceManager.listLocations.useQuery,D0=m.deviceManager.addLocation.useMutation,T0=m.deviceManager.removeLocation.useMutation,I0=m.deviceManager.setDisabled.useMutation,L0=m.deviceManager.listPersistedByAddon.useQuery,O0=m.deviceManager.listAll.useQuery,_0=m.deviceManager.getDevice.useQuery,$0=m.deviceManager.getChildren.useQuery,G0=m.deviceManager.getStreamSources.useQuery,B0=m.deviceManager.getConfigSchema.useQuery,F0=m.deviceManager.getSettingsSchema.useQuery,z0=m.deviceManager.updateConfig.useMutation,Q0=m.deviceManager.enable.useMutation,U0=m.deviceManager.disable.useMutation,H0=m.deviceManager.remove.useMutation,V0=m.deviceManager.getStreamProfileMap.useQuery,W0=m.deviceManager.setStreamProfileMap.useMutation,q0=m.deviceManager.probeStreams.useMutation,K0=m.deviceManager.getBindings.useQuery,Z0=m.deviceManager.getAllBindings.useQuery,Y0=m.deviceManager.setWrapperActive.useMutation,X0=m.deviceManager.listWrappersForCap.useQuery,J0=m.deviceManager.listBindableCapsForDeviceType.useQuery,eb=m.deviceManager.getDeviceSettingsAggregate.useQuery,tb=m.deviceManager.getDeviceLiveInfoAggregate.useQuery,rb=m.deviceManager.getDeviceAggregate.useQuery,sb=m.deviceManager.updateDeviceField.useMutation,nb=m.deviceManager.updateDeviceFieldsBatch.useMutation,ob=m.deviceManager.discoverDevices.useMutation,ab=m.deviceManager.adoptDevice.useMutation,ib=m.deviceManager.getCreationSchema.useQuery,lb=m.deviceManager.createDevice.useMutation,cb=m.deviceManager.testCreationField.useMutation,ub=m.deviceManager.testField.useMutation,db=m.deviceManager.getDeviceStatusAggregate.useQuery,fb=m.deviceOps.getStreamSources.useQuery,mb=m.deviceOps.getConfigEntries.useQuery,pb=m.deviceOps.setConfig.useMutation,hb=m.deviceOps.removeDevice.useMutation,gb=m.deviceOps.getSettingsSchema.useQuery,bb=m.deviceProvider.start.useMutation,xb=m.deviceProvider.stop.useMutation,vb=m.deviceProvider.getStatus.useQuery,yb=m.deviceProvider.getDevices.useQuery,wb=m.deviceProvider.supportsDiscovery.useQuery,Sb=m.deviceProvider.discoverDevices.useMutation,kb=m.deviceProvider.adoptDiscoveredDevice.useMutation,jb=m.deviceProvider.supportsManualCreation.useQuery,Nb=m.deviceProvider.getChildCreationSchema.useQuery,Cb=m.deviceProvider.createDevice.useMutation,Mb=m.deviceProvider.testCreationField.useMutation,Eb=m.deviceState.getSnapshot.useQuery,Ab=m.deviceState.getCapSlice.useQuery,Pb=m.deviceState.getAllSnapshots.useQuery,Rb=m.deviceState.setCapSlice.useMutation,Db=m.doorbell.getStatus.useQuery,Tb=m.events.getEvents.useQuery,Ib=m.events.getEventThumbnail.useQuery,Lb=m.events.getEventClipUrl.useQuery,Ob=m.integrations.list.useQuery,_b=m.integrations.get.useQuery,$b=m.integrations.getByAddonId.useQuery,Gb=m.integrations.create.useMutation,Bb=m.integrations.update.useMutation,Fb=m.integrations.delete.useMutation,zb=m.integrations.getSettings.useQuery,Qb=m.integrations.setSettings.useMutation,Ub=m.integrations.getAvailableTypes.useQuery,Hb=m.integrations.testConnection.useMutation,Vb=m.intercom.startSession.useMutation,Wb=m.intercom.handleAnswer.useMutation,qb=m.intercom.stopSession.useMutation,Kb=m.intercom.getStatus.useQuery,Zb=m.localNetwork.list.useQuery,Yb=m.localNetwork.getPreferred.useQuery,Xb=m.localNetwork.getConnectionEndpoints.useQuery,Jb=m.localNetwork.getAllowedAddresses.useQuery,ex=m.localNetwork.setAllowedAddresses.useMutation,tx=m.localNetwork.resetAllowlistToBestMatch.useMutation,rx=m.meshOrchestrator.listProviders.useQuery,sx=m.meshOrchestrator.joinProvider.useMutation,nx=m.meshOrchestrator.leaveProvider.useMutation,ox=m.metricsProvider.collectSnapshot.useQuery,ax=m.metricsProvider.getCached.useQuery,ix=m.metricsProvider.getCurrent.useQuery,lx=m.metricsProvider.getDiskSpace.useQuery,cx=m.metricsProvider.getGpuInfo.useQuery,ux=m.metricsProvider.getCpuTemperature.useQuery,dx=m.metricsProvider.getProcessStats.useQuery,fx=m.metricsProvider.listAddonInstances.useQuery,mx=m.metricsProvider.getAddonStats.useQuery,px=m.metricsProvider.listNodeProcesses.useQuery,hx=m.metricsProvider.killProcess.useMutation,gx=m.motion.isDetected.useQuery,bx=m.motion.getStatus.useQuery,xx=m.motionDetection.analyze.useMutation,vx=m.motionDetection.removeCamera.useMutation,yx=m.motionDetection.reset.useMutation,wx=m.motionDetection.getDeviceSettingsContribution.useQuery,Sx=m.motionDetection.getDeviceLiveContribution.useQuery,kx=m.motionDetection.applyDeviceSettingsPatch.useMutation,jx=m.motionTrigger.setMotionTrigger.useMutation,Nx=m.motionTrigger.getStatus.useQuery,Cx=m.nativeObjectDetection.getStatus.useQuery,Mx=m.networkQuality.getDeviceStats.useQuery,Ex=m.networkQuality.getAllStats.useQuery,Ax=m.networkQuality.reportClientStats.useMutation,Px=m.nodes.topology.useQuery,Rx=m.nodes.deployAddon.useMutation,Dx=m.nodes.undeployAddon.useMutation,Tx=m.nodes.restartAddon.useMutation,Ix=m.nodes.restartProcess.useMutation,Lx=m.nodes.restartNode.useMutation,Ox=m.nodes.shutdownNode.useMutation,_x=m.nodes.renameNode.useMutation,$x=m.nodes.clusterAddonStatus.useQuery,Gx=m.nodes.setProcessLogLevel.useMutation,Bx=m.nodes.executeQuery.useMutation,Fx=m.notificationOutput.send.useMutation,zx=m.notificationOutput.sendTest.useMutation,Qx=m.osd.setOverlay.useMutation,Ux=m.osd.getStatus.useQuery,Hx=m.pipelineAnalytics.getActiveTracks.useQuery,Vx=m.pipelineAnalytics.getTrack.useQuery,Wx=m.pipelineAnalytics.listTracks.useQuery,qx=m.pipelineAnalytics.clearTracks.useMutation,Kx=m.pipelineAnalytics.getMotionEvents.useQuery,Zx=m.pipelineAnalytics.getObjectEvents.useQuery,Yx=m.pipelineAnalytics.getAudioEvents.useQuery,Xx=m.pipelineAnalytics.getEventMedia.useQuery,Jx=m.pipelineAnalytics.getTrackMedia.useQuery,ev=m.pipelineAnalytics.getDeviceSettingsContribution.useQuery,tv=m.pipelineAnalytics.getDeviceLiveContribution.useQuery,rv=m.pipelineAnalytics.applyDeviceSettingsPatch.useMutation,sv=m.pipelineExecutor.getAvailableEngines.useQuery,nv=m.pipelineExecutor.getSelectedEngine.useQuery,ov=m.pipelineExecutor.getDefaultSteps.useQuery,av=m.pipelineExecutor.reprobeEngine.useMutation,iv=m.pipelineExecutor.getVideoPipelineSteps.useQuery,lv=m.pipelineExecutor.setVideoPipelineSteps.useMutation,cv=m.pipelineExecutor.getSchema.useQuery,uv=m.pipelineExecutor.getGlobalSteps.useQuery,dv=m.pipelineExecutor.getGlobalPipelineConfig.useQuery,fv=m.pipelineExecutor.getOrchestratorConfigSchema.useQuery,mv=m.pipelineExecutor.listTemplates.useQuery,pv=m.pipelineExecutor.saveTemplate.useMutation,hv=m.pipelineExecutor.updateTemplate.useMutation,gv=m.pipelineExecutor.deleteTemplate.useMutation,bv=m.pipelineExecutor.getCapabilities.useQuery,xv=m.pipelineExecutor.getAddonModels.useQuery,vv=m.pipelineExecutor.downloadModel.useMutation,yv=m.pipelineExecutor.deleteModel.useMutation,wv=m.pipelineExecutor.detect.useQuery,Sv=m.pipelineExecutor.runPipeline.useMutation,kv=m.pipelineExecutor.runPipelineBatch.useMutation,jv=m.pipelineExecutor.cacheFrameInPool.useMutation,Nv=m.pipelineExecutor.inferCached.useMutation,Cv=m.pipelineExecutor.uncacheFrame.useMutation,Mv=m.pipelineExecutor.getEffectiveTuning.useQuery,Ev=m.pipelineExecutor.listLoadedEngines.useQuery,Av=m.pipelineExecutor.spinEngine.useMutation,Pv=m.pipelineExecutor.killEngine.useMutation,Rv=m.pipelineExecutor.listReferenceImages.useQuery,Dv=m.pipelineExecutor.getReferenceImage.useQuery,Tv=m.pipelineExecutor.getReferenceAudioFiles.useQuery,Iv=m.pipelineExecutor.getReferenceAudio.useQuery,Lv=m.pipelineExecutor.getAudioCapabilities.useQuery,Ov=m.pipelineExecutor.runAudioTest.useMutation,_v=m.pipelineExecutor.getDetectionConfigSchema.useQuery,$v=m.pipelineOrchestrator.assignPipeline.useMutation,Gv=m.pipelineOrchestrator.unassignPipeline.useMutation,Bv=m.pipelineOrchestrator.rebalance.useMutation,Fv=m.pipelineOrchestrator.getPipelineAssignments.useQuery,zv=m.pipelineOrchestrator.getPipelineAssignment.useQuery,Qv=m.pipelineOrchestrator.getAgentLoad.useQuery,Uv=m.pipelineOrchestrator.getGlobalMetrics.useQuery,Hv=m.pipelineOrchestrator.getCameraMetrics.useQuery,Vv=m.pipelineOrchestrator.getCapabilityBindings.useQuery,Wv=m.pipelineOrchestrator.setCapabilityBinding.useMutation,qv=m.pipelineOrchestrator.assignDecoder.useMutation,Kv=m.pipelineOrchestrator.unassignDecoder.useMutation,Zv=m.pipelineOrchestrator.getDecoderAssignments.useQuery,Yv=m.pipelineOrchestrator.assignAudio.useMutation,Xv=m.pipelineOrchestrator.unassignAudio.useMutation,Jv=m.pipelineOrchestrator.getAudioAssignment.useQuery,ey=m.pipelineOrchestrator.getAudioNodeLoad.useQuery,ty=m.pipelineOrchestrator.getAudioAssignments.useQuery,ry=m.pipelineOrchestrator.getDecoderAssignment.useQuery,sy=m.pipelineOrchestrator.getAgentSettings.useQuery,ny=m.pipelineOrchestrator.listAgentSettings.useQuery,oy=m.pipelineOrchestrator.setAgentAddonDefaults.useMutation,ay=m.pipelineOrchestrator.removeAgentSettings.useMutation,iy=m.pipelineOrchestrator.getCameraSettings.useQuery,ly=m.pipelineOrchestrator.setCameraStepToggle.useMutation,cy=m.pipelineOrchestrator.getCameraStepOverrides.useQuery,uy=m.pipelineOrchestrator.setCameraStepOverride.useMutation,dy=m.pipelineOrchestrator.setCameraPipelineForAgent.useMutation,fy=m.pipelineOrchestrator.resolvePipeline.useQuery,my=m.pipelineOrchestrator.listTemplates.useQuery,py=m.pipelineOrchestrator.saveTemplate.useMutation,hy=m.pipelineOrchestrator.updateTemplate.useMutation,gy=m.pipelineOrchestrator.deleteTemplate.useMutation,by=m.pipelineOrchestrator.getDeviceSettingsContribution.useQuery,xy=m.pipelineOrchestrator.getDeviceLiveContribution.useQuery,vy=m.pipelineOrchestrator.applyDeviceSettingsPatch.useMutation,yy=m.pipelineRunner.attachCamera.useMutation,wy=m.pipelineRunner.detachCamera.useMutation,Sy=m.pipelineRunner.reportMotion.useMutation,ky=m.pipelineRunner.getLocalLoad.useQuery,jy=m.pipelineRunner.getLocalMetrics.useQuery,Ny=m.pipelineRunner.getCameraMetrics.useQuery,Cy=m.pipelineRunner.getAllCameraMetrics.useQuery,My=m.pipelineRunner.getLocalCameras.useQuery,Ey=m.platformProbe.getCapabilities.useQuery,Ay=m.platformProbe.getHardware.useQuery,Py=m.platformProbe.resolveInferenceConfig.useQuery,Ry=m.platformProbe.resolveHwAccel.useQuery,Dy=m.ptz.move.useMutation,Ty=m.ptz.continuousMove.useMutation,Iy=m.ptz.stop.useMutation,Ly=m.ptz.getPresets.useQuery,Oy=m.ptz.goToPreset.useMutation,_y=m.ptz.goHome.useMutation,$y=m.ptz.getPosition.useQuery,Gy=m.ptz.getStatus.useQuery,By=m.ptzAutotrack.getStatus.useQuery,Fy=m.ptzAutotrack.setEnabled.useMutation,zy=m.ptzAutotrack.getSettings.useQuery,Qy=m.ptzAutotrack.setSettings.useMutation,Uy=m.reboot.reboot.useMutation,Hy=m.recording.getSegments.useQuery,Vy=m.recording.getPlaybackUrl.useQuery,Wy=m.recording.getThumbnailAt.useQuery,qy=m.recordingEngine.getStatus.useQuery,Ky=m.recordingEngine.enable.useMutation,Zy=m.recordingEngine.disable.useMutation,Yy=m.recordingEngine.getConfig.useQuery,Xy=m.recordingEngine.updateConfig.useMutation,Jy=m.recordingEngine.getPlaylist.useQuery,e1=m.recordingEngine.getThumbnail.useQuery,t1=m.recordingEngine.getSegments.useQuery,r1=m.recordingEngine.getAvailability.useQuery,s1=m.recordingEngine.estimateStorage.useQuery,n1=m.recordingEngine.estimateGlobalStorage.useQuery,o1=m.recordingEngine.getStorageUsage.useQuery,a1=m.recordingEngine.setPolicy.useMutation,i1=m.recordingEngine.getPolicy.useQuery,l1=m.recordingEngine.getPolicyStatus.useQuery,c1=m.recordingEngine.getRetentionConfig.useQuery,u1=m.recordingEngine.updateRetentionConfig.useMutation,d1=m.recordingEngine.getMotionStats.useQuery,f1=m.remoteAccess.listProviders.useQuery,m1=m.remoteAccess.startProvider.useMutation,p1=m.remoteAccess.stopProvider.useMutation,h1=m.settingsStore.get.useQuery,g1=m.settingsStore.set.useMutation,b1=m.settingsStore.query.useQuery,x1=m.settingsStore.insert.useMutation,v1=m.settingsStore.update.useMutation,y1=m.settingsStore.delete.useMutation,w1=m.settingsStore.count.useQuery,S1=m.settingsStore.isEmpty.useQuery,k1=m.settingsStore.declareCollection.useMutation,j1=m.snapshot.getSnapshot.useQuery,N1=m.snapshot.invalidateCache.useMutation,C1=m.snapshot.getStatus.useQuery,M1=m.snapshot.getDeviceSettingsContribution.useQuery,E1=m.snapshot.getDeviceLiveContribution.useQuery,A1=m.snapshot.applyDeviceSettingsPatch.useMutation,P1=m.snapshotProvider.supportsDevice.useQuery,R1=m.snapshotProvider.getSnapshot.useQuery,D1=m.storage.resolve.useQuery,T1=m.storage.write.useMutation,I1=m.storage.read.useQuery,L1=m.storage.exists.useQuery,O1=m.storage.list.useQuery,_1=m.storage.delete.useMutation,$1=m.storage.getAvailableSpace.useQuery,G1=m.storage.beginUpload.useMutation,B1=m.storage.writeChunk.useMutation,F1=m.storage.finalizeUpload.useMutation,z1=m.storage.abortUpload.useMutation,Q1=m.storage.beginDownload.useMutation,U1=m.storage.readChunk.useQuery,H1=m.storage.endDownload.useMutation,V1=m.storage.listLocations.useQuery,W1=m.storage.getDefaultLocation.useQuery,q1=m.storage.upsertLocation.useMutation,K1=m.storage.deleteLocation.useMutation,Z1=m.storage.testLocation.useQuery,Y1=m.storage.listProviders.useQuery,X1=m.storage.testConfig.useQuery,J1=m.streamBroker.publishCameraStream.useMutation,ew=m.streamBroker.retractCameraStream.useMutation,tw=m.streamBroker.assignProfile.useMutation,rw=m.streamBroker.unassignProfile.useMutation,sw=m.streamBroker.listAllCameraStreams.useQuery,nw=m.streamBroker.listAllProfileSlots.useQuery,ow=m.streamBroker.getBrokerStats.useQuery,aw=m.streamBroker.listClients.useQuery,iw=m.streamBroker.killClient.useMutation,lw=m.streamBroker.restartProfile.useMutation,cw=m.streamBroker.getStreamUrl.useQuery,uw=m.streamBroker.getBroker.useQuery,dw=m.streamBroker.setPreBufferDuration.useMutation,fw=m.streamBroker.getPreBufferInfo.useQuery,mw=m.streamBroker.getRtspPort.useQuery,pw=m.streamBroker.getAllRtspEntries.useQuery,hw=m.streamBroker.getRtspEntry.useQuery,gw=m.streamBroker.regenerateRtspToken.useMutation,bw=m.streamBroker.setRtspEnabled.useMutation,xw=m.streamBroker.isRtspEnabled.useQuery,vw=m.streamBroker.getDeviceSettingsContribution.useQuery,yw=m.streamBroker.getDeviceLiveContribution.useQuery,ww=m.streamBroker.applyDeviceSettingsPatch.useMutation,Sw=m.switch.setState.useMutation,kw=m.switch.getStatus.useQuery,jw=m.system.info.useQuery,Nw=m.system.health.useQuery,Cw=m.system.featureFlags.useQuery,Mw=m.system.networkAddresses.useQuery,Ew=m.system.getRetentionConfig.useQuery,Aw=m.system.setRetentionConfig.useMutation,Pw=m.system.forceRetentionCleanup.useMutation,Rw=m.toast.onToast.useSubscription,Dw=m.turnOrchestrator.listProviders.useQuery,Tw=m.turnOrchestrator.getAllServers.useQuery,Iw=m.turnOrchestrator.setProviderEnabled.useMutation,Lw=m.turnProvider.getTurnServers.useQuery,Ow=m.userManagement.listUsers.useQuery,_w=m.userManagement.createUser.useMutation,$w=m.userManagement.updateUser.useMutation,Gw=m.userManagement.deleteUser.useMutation,Bw=m.userManagement.resetPassword.useMutation,Fw=m.userManagement.validateCredentials.useMutation,zw=m.userManagement.listApiKeys.useQuery,Qw=m.userManagement.createApiKey.useMutation,Uw=m.userManagement.revokeApiKey.useMutation,Hw=m.userManagement.validateApiKey.useMutation,Vw=m.userManagement.createScopedToken.useMutation,Ww=m.userManagement.revokeScopedToken.useMutation,qw=m.userManagement.validateScopedToken.useQuery,Kw=m.userManagement.listScopedTokens.useQuery,Zw=m.webrtcSession.listStreams.useQuery,Yw=m.webrtcSession.createSession.useMutation,Xw=m.webrtcSession.handleAnswer.useMutation,Jw=m.webrtcSession.closeSession.useMutation,eS=m.webrtcSession.hasAdaptiveBitrate.useQuery,tS=m.zoneAnalytics.getCurrentSnapshot.useQuery,rS=m.zoneAnalytics.getZoneHistory.useQuery,sS=m.zoneAnalytics.getCameraHistory.useQuery,nS=m.zoneAnalytics.getUnzonedHistory.useQuery,oS=m.zoneRules.listRules.useQuery,aS=m.zoneRules.setRules.useMutation,iS=m.zones.listZones.useQuery,lS=m.zones.addZone.useMutation,cS=m.zones.removeZone.useMutation,uS=m.zones.updateZone.useMutation,Ji=ot("camstack:widget-registry",null),qr=new Map,Kr=new Map,el=new Set;function dS(e){if(!e||typeof e!="object")return!1;const t=e.default;return t!==null&&typeof t=="object"}function fS(e){if(!e||typeof e!="object")return typeof e;const t=e,s=Object.getPrototypeOf(t),n=s&&typeof s=="object"?s.constructor?.name:void 0;return{ownKeys:Object.keys(t),allKeys:Object.getOwnPropertyNames(t),proto:typeof n=="string"?n:void 0}}async function mS(e,t){const s=qr.get(e);if(s)return s;const n=Kr.get(e);if(n)return n;el.has(e)||(zo(),wd([{name:e,entry:t,type:"module"}],{force:!1}),el.add(e));const o=yd(`${e}/widgets`).then(a=>{if(!dS(a)){const l=fS(a);throw new Error(`Widget remote ${e} (${t}) does not expose a default record on './widgets'. Got: ${JSON.stringify(l)}`)}const i=a.default;return qr.set(e,i),Kr.delete(e),i}).catch(a=>{throw Kr.delete(e),a});return Kr.set(e,o),o}var pS=3e4,hS=2e3;function gS({children:e}){const t=(0,Ee.useQueryClient)(),s=(0,h.useRef)(Date.now()),{data:n}=Xi(void 0,{staleTime:0,refetchOnMount:"always",refetchInterval:l=>{const u=l.state.data;return u&&u.length>0||Date.now()-s.current>=pS?!1:hS}});lr("addon.widget-ready",()=>{t.invalidateQueries({queryKey:[["addonWidgets","listWidgets"]]})});const[o,a]=(0,h.useState)(0);(0,h.useEffect)(()=>{if(!n)return;let l=!1;const u=new Set;for(const d of n){if(u.has(d.remoteName)||(u.add(d.remoteName),qr.has(d.remoteName)))continue;const f=d.bundleUrl;mS(d.remoteName,f).then(()=>{l||a(p=>p+1)}).catch(p=>{const g=p instanceof Error?p.message:String(p);(typeof globalThis<"u"?globalThis.console:void 0)?.error?.("[WidgetRegistry] Failed to load widget remote",{remoteName:d.remoteName,entryUrl:f,reason:g})})}return()=>{l=!0}},[n]);const i=(0,h.useMemo)(()=>{const l=n??[],u=new Map;for(const f of l)u.set(`${f.addonId}/${f.stableId}`,f);const d=(f,p)=>({widgetId:f,addonId:p.addonId,stableId:p.stableId,label:p.label,description:p.description,icon:p.icon,remoteName:p.remoteName,bundleUrl:p.bundleUrl,hosts:p.hosts,requires:p.requires,defaultSize:p.defaultSize,allowedSizes:p.allowedSizes,defaultColumns:p.defaultColumns,defaultRows:p.defaultRows});return{resolve:f=>{const p=u.get(f);if(!p)return;const g=qr.get(p.remoteName);if(!g)return null;const b=g[p.stableId];if(b)return b},metadata:f=>{const p=u.get(f);if(p)return d(f,p)},listAll:()=>{const f=[];for(const[p,g]of u)f.push(d(p,g));return f}}},[n,o]);return(0,r.jsx)(Ji.Provider,{value:i,children:e})}function tl(e){return Zr().resolve(e)}function rl(e){return Zr().metadata(e)}function bS(){return Zr().listAll()}function Zr(){const e=sl();if(!e)throw new Error("useWidgetRegistry(): no <WidgetRegistryProvider> in tree");return e}function sl(){return xS(Ji)}function xS(e){return(0,h.useContext)(e)}function nl(e){const{widgetId:t,host:s="device-tab",config:n,deviceId:o,integrationId:a,instanceId:i,size:l,columns:u,rows:d}=e,f=tl(t),p=rl(t),g=(0,h.useMemo)(()=>i??t,[i,t]);if(f===void 0&&p===void 0)return(0,r.jsx)(Yr,{widgetId:t,reason:"unknown"});if(f===void 0)return(0,r.jsx)(Yr,{widgetId:t,reason:"missing-export"});if(f===null)return(0,r.jsx)(vS,{});if(p){if(p.requires.deviceContext&&o===void 0)return(0,r.jsx)(Yr,{widgetId:t,reason:"missing-device-context"});if(p.requires.integrationContext&&a===void 0)return(0,r.jsx)(Yr,{widgetId:t,reason:"missing-integration-context"})}return(0,r.jsx)(f,{instanceId:g,host:s,config:n,deviceId:o,integrationId:a,size:l,columns:u,rows:d})}function vS(){return(0,r.jsxs)("div",{className:"rounded-lg border border-border bg-surface/40 p-4 animate-pulse",children:[(0,r.jsx)("div",{className:"h-3 w-24 bg-foreground-subtle/20 rounded mb-2"}),(0,r.jsx)("div",{className:"h-2 w-full bg-foreground-subtle/10 rounded mb-1"}),(0,r.jsx)("div",{className:"h-2 w-3/4 bg-foreground-subtle/10 rounded"})]})}function Yr({widgetId:e,reason:t}){return(0,r.jsx)("div",{className:"rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning",children:t==="unknown"?`Widget "${e}" not registered`:t==="missing-export"?`Widget "${e}" bundle does not export this stableId`:t==="missing-device-context"?`Widget "${e}" requires a deviceId`:`Widget "${e}" requires an integrationId`})}var Nt="w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50 disabled:cursor-not-allowed",Xr="block text-[11px] font-medium text-foreground mb-1",yS="text-[10px] text-foreground-subtle mt-0.5";function je({label:e,description:t,required:s,span:n,children:o,translationFn:a}){const i=n===2?"col-span-2":n===3?"col-span-3":n===4?"col-span-4":"col-span-1",l=Ke(e,a),u=Ke(t,a);return(0,r.jsxs)("div",{className:i,children:[l!==void 0&&l!==""&&(0,r.jsxs)("label",{className:Xr,children:[l,s&&(0,r.jsx)("span",{className:"text-danger ml-0.5",children:"*"})]}),o,u&&(0,r.jsx)("p",{className:yS,children:u})]})}function wS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsx)("input",{type:e.inputType??"text",className:Nt,value:t==null?"":String(t),placeholder:e.placeholder,maxLength:e.maxLength,pattern:e.pattern,disabled:n||e.disabled,onChange:a=>s(a.target.value)})})}function SS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const[a,i]=(0,h.useState)(t==null?"":String(t)),l=(0,h.useRef)(!1);(0,h.useEffect)(()=>{l.current||i(t==null?"":String(t))},[t]);const u=d=>{if(i(d),d===""||d==="-"){s(void 0);return}const f=Number(d);Number.isNaN(f)||s(f)};return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)("input",{type:"number",className:Nt,value:a,placeholder:e.placeholder,min:e.min,max:e.max,step:e.step,disabled:n||e.disabled,onFocus:()=>{l.current=!0},onBlur:()=>{l.current=!1},onChange:d=>u(d.target.value)}),e.unit&&(0,r.jsx)("span",{className:"text-xs text-foreground-subtle whitespace-nowrap",children:e.unit})]})})}function kS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const a=!!t,i=n||e.disabled;return e.style==="checkbox"?(0,r.jsx)(je,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[(0,r.jsx)("input",{type:"checkbox",className:"h-3.5 w-3.5 rounded border-border accent-primary",checked:a,disabled:i,onChange:l=>s(l.target.checked)}),(0,r.jsx)("span",{className:"text-xs font-medium text-foreground",children:Ke(e.label,o)}),e.required&&(0,r.jsx)("span",{className:"text-danger",children:"*"})]})}):(0,r.jsx)(je,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("span",{className:Xr+" mb-0",children:[Ke(e.label,o),e.required&&(0,r.jsx)("span",{className:"text-danger ml-0.5",children:"*"})]}),(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":a,disabled:i,onClick:()=>!i&&s(!a),className:["relative inline-flex h-4 w-8 shrink-0 items-center rounded-full transition-colors duration-150",a?"bg-primary":"bg-foreground-subtle/30",i?"opacity-50 cursor-not-allowed":"cursor-pointer"].join(" "),children:(0,r.jsx)("span",{className:["inline-block h-3 w-3 rounded-full bg-white shadow transition-transform duration-150",a?"translate-x-4":"translate-x-0.5"].join(" ")})})]})})}function jS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const a=e.options.some(i=>i.value==="");return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("select",{className:Nt,value:t==null?"":String(t),disabled:n||e.disabled,onChange:i=>s(i.target.value),children:[!e.required&&!a&&(0,r.jsx)("option",{value:"",children:"— Select —"}),e.options.map(i=>(0,r.jsx)("option",{value:i.value,children:i.label},i.value))]})})}function NS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const a=Array.isArray(t)?t:[],i=l=>{if(a.includes(l))s(a.filter(u=>u!==l));else{if(e.maxItems!==void 0&&a.length>=e.maxItems)return;s([...a,l])}};return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:e.options.map(l=>{const u=a.includes(l.value);return(0,r.jsxs)("label",{className:["flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs cursor-pointer select-none transition-colors",u?"border-primary bg-primary/10 text-primary":"border-border bg-background text-foreground hover:bg-surface",n||e.disabled?"opacity-50 cursor-not-allowed":""].join(" "),children:[(0,r.jsx)("input",{type:"checkbox",className:"sr-only",checked:u,disabled:n||e.disabled,onChange:()=>i(l.value)}),l.label]},l.value)})})})}function CS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const[a,i]=(0,h.useState)(!1),l=e.showToggle!==!1;return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("input",{type:a?"text":"password",className:Nt+(l?" pr-9":""),value:t==null?"":String(t),placeholder:e.placeholder,disabled:n||e.disabled,onChange:u=>s(u.target.value)}),l&&(0,r.jsx)("button",{type:"button",className:"absolute right-2 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",tabIndex:-1,onClick:()=>i(u=>!u),children:a?(0,r.jsx)(Yo,{className:"h-3.5 w-3.5"}):(0,r.jsx)(Or,{className:"h-3.5 w-3.5"})})]})})}function MS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsx)("textarea",{className:Nt+" resize-y min-h-[60px]",value:t==null?"":String(t),placeholder:e.placeholder,rows:e.rows??3,maxLength:e.maxLength,disabled:n||e.disabled,onChange:a=>s(a.target.value)})})}function ES({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const a=t==null,i=e.nullable===!0,l=a?e.default??e.min:Number(t),u=e.showValue!==!1,d=e.nullLabel??"Auto",f=n||e.disabled,p=e.displayScale??1,g=e.min/p,b=e.max/p,x=l/p,v=(e.step??1)/p;if(i&&a)return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("button",{className:"w-full rounded-lg border border-dashed border-border px-3 py-2 text-xs text-foreground-subtle hover:border-primary/40 hover:text-primary transition-colors text-left",disabled:f,onClick:()=>s(e.default??e.min),children:[d," — click to set manually"]})});const w=e.showStepper===!0&&u,y=k=>{const C=l+k*(e.step??1),N=Math.min(e.max,Math.max(e.min,C));N!==l&&s(N)},S="flex h-6 w-6 shrink-0 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:cursor-not-allowed disabled:opacity-40";return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[(0,r.jsxs)("div",{className:"flex min-w-0 flex-1 basis-[160px] items-center gap-2",children:[(0,r.jsx)("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:g}),(0,r.jsx)("input",{type:"range",className:"min-w-0 flex-1 h-1 accent-primary cursor-pointer disabled:opacity-50",min:g,max:b,step:v,value:x,disabled:f,onChange:k=>s(Number(k.target.value)*p)}),(0,r.jsx)("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:b})]}),(u||i||e.unit)&&(0,r.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[w&&(0,r.jsx)("button",{type:"button",className:S,disabled:f||l<=e.min,onClick:()=>y(-1),title:`Decrease by ${e.step??1}`,"aria-label":"Decrement",children:(0,r.jsx)(na,{className:"h-3 w-3"})}),u&&(0,r.jsx)("input",{type:"number",className:"w-16 rounded border border-border bg-surface px-1.5 py-0.5 text-xs text-center text-foreground tabular-nums focus:outline-none focus:ring-1 focus:ring-primary",min:g,max:b,step:v,value:x,disabled:f,onChange:k=>{if(k.target.value===""){s(i?null:e.min);return}const C=Number(k.target.value)*p,N=e.step??1,E=C-e.min,R=e.min+Math.round(E/N)*N;s(Math.min(e.max,Math.max(e.min,R)))}}),w&&(0,r.jsx)("button",{type:"button",className:S,disabled:f||l>=e.max,onClick:()=>y(1),title:`Increase by ${e.step??1}`,"aria-label":"Increment",children:(0,r.jsx)(_r,{className:"h-3 w-3"})}),e.unit&&(0,r.jsx)("span",{className:"text-[10px] text-foreground-subtle",children:e.unit}),i&&(0,r.jsx)("button",{className:"text-[10px] text-foreground-subtle hover:text-primary transition-colors",title:`Reset to ${d}`,disabled:f,onClick:()=>s(null),children:d})]})]})})}function AS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const a=Array.isArray(t)?t:[],[i,l]=(0,h.useState)(""),u=(0,h.useRef)(null),d=(0,h.useCallback)(b=>{const x=b.trim();!x||a.includes(x)||e.maxTags!==void 0&&a.length>=e.maxTags||(s([...a,x]),l(""))},[a,e.maxTags,s]),f=b=>s(a.filter(x=>x!==b)),p=b=>{b.key==="Enter"||b.key===","?(b.preventDefault(),d(i)):b.key==="Backspace"&&i===""&&a.length>0&&f(a[a.length-1])},g=n||e.disabled;return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("div",{className:["flex flex-wrap gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 min-h-[38px] cursor-text","focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30",g?"opacity-50 cursor-not-allowed":""].join(" "),onClick:()=>!g&&u.current?.focus(),children:[a.map(b=>(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[b,!g&&(0,r.jsx)("button",{type:"button",onClick:()=>f(b),className:"hover:text-danger",children:(0,r.jsx)(Pe,{className:"h-2.5 w-2.5"})})]},b)),(0,r.jsx)("input",{ref:u,type:"text",className:"flex-1 min-w-[80px] bg-transparent text-sm text-foreground outline-none placeholder:text-foreground-disabled",value:i,placeholder:a.length===0?e.placeholder??"Add tags…":"",disabled:g,list:`tags-suggestions-${e.key}`,onChange:b=>l(b.target.value),onKeyDown:p,onBlur:()=>{i.trim()&&d(i)}}),e.suggestions&&(0,r.jsx)("datalist",{id:`tags-suggestions-${e.key}`,children:e.suggestions.map(b=>(0,r.jsx)("option",{value:b},b))})]})})}function ol({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const{nodes:a}=zr(),i=typeof t=="string"?t:"",l=e.showOffline?a:a.filter(u=>u.isOnline);return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsxs)("select",{className:"w-full px-3 py-2 text-sm bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-primary/50 disabled:opacity-50",value:i,onChange:u=>s(u.target.value),disabled:n,children:[(0,r.jsx)("option",{value:"",children:"Select node…"}),l.map(u=>(0,r.jsxs)("option",{value:u.id,disabled:!u.isOnline,children:[u.shortName,u.isOnline?"":" (offline)"]},u.id))]})})}function al({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const{nodes:a}=zr(),i=new Set(Array.isArray(t)?t.map(String):[]),l=e.showOffline?a:a.filter(d=>d.isOnline),u=d=>{const f=new Set(i);f.has(d)?f.delete(d):f.add(d),s([...f])};return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:(0,r.jsx)("div",{className:"flex flex-wrap gap-1.5",children:l.map(d=>{const f=i.has(d.id);return(0,r.jsx)("button",{type:"button",onClick:()=>u(d.id),disabled:n||!d.isOnline,className:`px-2.5 py-1 text-xs font-medium rounded-md border transition-colors ${f?"border-primary bg-primary/10 text-primary":"border-border bg-surface text-foreground-subtle hover:bg-surface-hover"} ${d.isOnline?"":"opacity-50 cursor-not-allowed"}`,children:d.shortName},d.id)})})})}function PS({field:e,value:t,onChange:s,disabled:n,translationFn:o}){const a=t==null?"#000000":String(t);return(0,r.jsxs)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("input",{type:"color",className:"h-9 w-9 rounded-md border border-border bg-background cursor-pointer p-0.5 disabled:opacity-50",value:a,disabled:n||e.disabled,onChange:i=>s(i.target.value)}),(0,r.jsx)("input",{type:"text",className:Nt+" flex-1 font-mono",value:a,placeholder:"#000000",disabled:n||e.disabled,onChange:i=>s(i.target.value)})]}),e.presets&&e.presets.length>0&&(0,r.jsx)("div",{className:"flex gap-1.5 mt-1.5",children:e.presets.map(i=>(0,r.jsx)("button",{type:"button",className:"h-5 w-5 rounded-md border border-border hover:scale-110 transition-transform disabled:opacity-50",style:{backgroundColor:i},disabled:n||e.disabled,title:i,onClick:()=>s(i)},i))})]})}function RS({field:e,value:t,onChange:s,disabled:n,translationFn:o,onTestField:a,onAction:i,externalProbe:l}){const[u,d]=(0,h.useState)("idle"),[f,p]=(0,h.useState)(null),g=l?.status??u,b=l?.result??f,x=!!a||!!i,v=(0,h.useCallback)(async()=>{if(x){d("probing"),p(null);try{const S=a?await a(e.key,t):await i("test-probe",e.key,t),k=S&&typeof S=="object"?S:{status:"error",error:"Probe handler returned no result"};p(k),d(k.status==="ok"?"ok":"error")}catch(S){p({status:"error",error:S instanceof Error?S.message:String(S)}),d("error")}}},[a,i,e.key,t,x]),w=g==="probing"?"border-primary/40 bg-primary/10 text-primary":g==="ok"?"border-success/40 bg-success/10 text-success hover:bg-success/15":g==="error"?"border-danger/40 bg-danger/10 text-danger hover:bg-danger/15":"border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover",y=g==="probing"?(0,r.jsx)(qe,{className:"h-3 w-3 animate-spin"}):g==="ok"?(0,r.jsx)(zd,{className:"h-3 w-3"}):g==="error"?(0,r.jsx)(Lr,{className:"h-3 w-3"}):(0,r.jsx)(fa,{className:"h-3 w-3"});return(0,r.jsxs)(je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:o,children:[(0,r.jsxs)("div",{className:"@container flex items-center gap-2",style:{containerType:"inline-size"},children:[(0,r.jsxs)("button",{type:"button",onClick:v,title:"Test",disabled:e.disabled||g==="probing"||!x||!t,className:`flex-shrink-0 inline-flex items-center gap-1.5 rounded-md border px-2 py-2 text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed @[280px]:px-3 ${w}`,children:[y,(0,r.jsx)("span",{className:"hidden @[280px]:inline",children:"Test"})]}),(0,r.jsx)("input",{type:e.inputType??"url",className:Nt+" flex-1 min-w-0",value:t==null?"":String(t),placeholder:e.placeholder,disabled:n||e.disabled,onChange:S=>{s(S.target.value),u!=="idle"&&(d("idle"),p(null))}})]}),g==="ok"&&b?.labels&&b.labels.length>0&&(0,r.jsx)("div",{className:"flex flex-wrap gap-1 mt-1.5",children:b.labels.map((S,k)=>(0,r.jsx)("span",{className:"text-xs bg-success/10 text-success rounded px-2 py-0.5 font-mono",children:S},k))}),g==="error"&&b?.error&&(0,r.jsx)("p",{className:"text-xs text-danger mt-1 truncate",title:b.error,children:b.error})]})}function DS({field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a}){const[i,l]=(0,h.useState)(e.defaultCollapsed??!1),u=e.style==="accordion";return(0,r.jsx)("div",{className:e.span===2?"col-span-2":e.span===3?"col-span-3":e.span===4?"col-span-4":"col-span-1",children:(0,r.jsxs)("div",{className:"rounded-lg border border-border bg-surface/50 overflow-hidden",children:[(0,r.jsxs)("div",{className:["px-3 py-2 flex items-center justify-between",u?"cursor-pointer hover:bg-surface":""].join(" "),onClick:u?()=>l(d=>!d):void 0,children:[(0,r.jsx)("span",{className:"text-xs font-semibold text-foreground",children:Ke(e.label,o)}),u&&(0,r.jsx)("span",{className:"text-foreground-subtle text-xs",children:i?"▸":"▾"})]}),!i&&(0,r.jsx)("div",{className:"px-3 pb-3 grid grid-cols-2 gap-x-4 gap-y-3",children:e.fields.map(d=>(0,r.jsx)(Qt,{field:d,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a},d.key))})]})})}function TS({field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,onAction:i}){const[l,u]=(0,h.useState)(e.tabs[0]?.id??""),d=e.span===2?"col-span-2":e.span===3?"col-span-3":e.span===4?"col-span-4":"col-span-1";return e.tabs.length===0?null:(0,r.jsxs)("div",{className:d,children:[e.label&&(0,r.jsx)("div",{className:Xr,children:Ke(e.label,o)}),(0,r.jsxs)("div",{className:"rounded-lg border border-border-subtle bg-surface-hover/40 overflow-hidden",children:[(0,r.jsx)("div",{className:"flex flex-wrap gap-1 p-1.5 border-b border-border-subtle bg-surface/40",role:"tablist",children:e.tabs.map(f=>{const p=f.id===l;return(0,r.jsxs)("button",{type:"button",role:"tab","aria-selected":p,onClick:()=>u(f.id),className:`inline-flex items-center gap-1.5 whitespace-nowrap rounded-md px-2.5 py-1 text-[11px] transition-colors ${p?"bg-primary text-primary-foreground font-medium shadow-sm":"bg-transparent text-foreground-subtle hover:bg-surface hover:text-foreground"}`,children:[(0,r.jsx)("span",{children:Ke(f.label,o)}),f.badge&&(0,r.jsx)("span",{className:`text-[9px] px-1 py-0.5 rounded-full font-medium ${p?"bg-primary-foreground/20 text-primary-foreground":"bg-primary/10 text-primary"}`,children:f.badge})]},f.id)})}),e.tabs.map(f=>f.id!==l?null:(0,r.jsx)("div",{role:"tabpanel",className:"px-3 pb-3 pt-2 grid grid-cols-2 gap-x-4 gap-y-3",children:f.fields.map((p,g)=>{const b="key"in p&&typeof p.key=="string"?p.key:`__${f.id}__${g}`;return(0,r.jsx)(Qt,{field:p,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,onAction:i},b)})},f.id))]})]})}function IS({span:e}){return(0,r.jsx)("div",{className:e===2?"col-span-2":e===3?"col-span-3":e===4?"col-span-4":"col-span-full",children:(0,r.jsx)("hr",{className:"border-border"})})}var il={info:{border:"border-info",bg:"bg-info/5",text:"text-info"},warning:{border:"border-warning",bg:"bg-warning/5",text:"text-warning"},success:{border:"border-success",bg:"bg-success/5",text:"text-success"},danger:{border:"border-danger",bg:"bg-danger/5",text:"text-danger"}};function LS(e){if(typeof window>"u"||typeof DOMParser>"u")return"";const t=new Set(["A","UL","OL","LI","STRONG","EM","CODE","BR","P","SPAN"]),s=new DOMParser().parseFromString(`<div>${e}</div>`,"text/html"),n=s.body.firstElementChild;if(!n)return"";const o=a=>{const i=Array.from(a.children);for(const l of i){if(!t.has(l.tagName)){const d=s.createTextNode(l.textContent??"");l.replaceWith(d);continue}const u=l.tagName==="A"?new Set(["href"]):new Set;for(const d of Array.from(l.attributes))u.has(d.name)||l.removeAttribute(d.name);if(l.tagName==="A"){const d=l.getAttribute("href")??"";!/^https?:\/\//i.test(d)&&!d.startsWith("mailto:")?l.removeAttribute("href"):(l.setAttribute("target","_blank"),l.setAttribute("rel","noopener noreferrer"))}o(l)}};return o(n),n.innerHTML}function OS({field:e}){const t=il[e.variant??"info"]??il.info,s=e.format==="html";return(0,r.jsx)("div",{className:"col-span-full",children:(0,r.jsxs)("div",{className:`rounded-md border-l-4 px-3 py-2.5 ${t.border} ${t.bg}`,children:[e.label&&(0,r.jsx)("p",{className:`text-xs font-semibold mb-0.5 ${t.text}`,children:e.label}),s?(0,r.jsx)("div",{className:"text-xs text-foreground-subtle leading-relaxed info-html-content",dangerouslySetInnerHTML:{__html:LS(e.content)}}):(0,r.jsx)("p",{className:"text-xs text-foreground-subtle leading-relaxed whitespace-pre-line",children:e.content})]})})}var ll={ok:"bg-success",warn:"bg-amber-500",danger:"bg-danger",idle:"bg-foreground-subtle/40",unknown:"bg-foreground-subtle/40"};function _S(e){if(!Number.isFinite(e)||e<0)return"—";if(e<1e3)return`${e}ms`;const t=Math.round(e/1e3);if(t<60)return`${t}s`;const s=Math.floor(t/60),n=t%60;return n===0?`${s}m`:`${s}m ${n}s`}function $S(e){return!Number.isFinite(e)||e<=0?"—":new Date(e).toLocaleTimeString()}function GS({kind:e,value:t}){return t==null||t===""?(0,r.jsx)("span",{className:"text-foreground-subtle/60",children:"—"}):e==="monospace"?(0,r.jsx)("span",{className:"font-mono text-[11px]",children:String(t)}):e==="status"?(0,r.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,r.jsx)("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${ll[String(t).toLowerCase()]??ll.unknown}`}),(0,r.jsx)("span",{children:String(t)})]}):e==="duration"&&typeof t=="number"?(0,r.jsx)("span",{className:"font-mono text-[11px]",children:_S(t)}):e==="timestamp"&&typeof t=="number"?(0,r.jsx)("span",{className:"font-mono text-[11px]",children:$S(t)}):(0,r.jsx)("span",{children:String(t)})}function BS({field:e}){const t=e.value??[],s=e.description;return(0,r.jsxs)("div",{className:"col-span-full",children:[e.label&&(0,r.jsx)("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1",children:e.label}),s&&(0,r.jsx)("p",{className:"text-xs text-foreground-subtle mb-2",children:s}),t.length===0?(0,r.jsx)("div",{className:"rounded-md border border-border bg-surface-subtle px-3 py-2 text-xs text-foreground-subtle",children:e.emptyMessage??"No entries"}):(0,r.jsx)("div",{className:"rounded-md border border-border overflow-hidden",children:(0,r.jsxs)("table",{className:"w-full text-xs",children:[(0,r.jsx)("thead",{className:"bg-surface-subtle border-b border-border",children:(0,r.jsx)("tr",{children:e.columns.map(n=>(0,r.jsx)("th",{className:"px-3 py-1.5 text-left font-medium text-foreground-subtle",style:n.width?{width:n.width}:void 0,children:n.label},n.key))})}),(0,r.jsx)("tbody",{className:"divide-y divide-border",children:t.map((n,o)=>(0,r.jsx)("tr",{className:"hover:bg-surface-hover/40",children:e.columns.map(a=>(0,r.jsx)("td",{className:"px-3 py-1.5 align-top text-foreground",children:(0,r.jsx)(GS,{kind:a.kind,value:n[a.key]})},a.key))},o))})]})})]})}function FS({field:e,value:t,onChange:s,disabled:n,translationFn:o,onTestField:a,onAction:i}){const l=Array.isArray(t)?t:[],u=e.minRows??0,d=e.maxRows??Number.POSITIVE_INFINITY,f=(w,y,S)=>{const k=l.slice();k[w]={...k[w]??{},[y]:S},s(k)},p=w=>{l.length<=u||s(l.filter((y,S)=>S!==w))},g=()=>{if(l.length>=d)return;const w=e.defaultItem??{};s([...l,{...w}])},b=(w,y)=>e.rowTitleTemplate?e.rowTitleTemplate.replace(/\{(\w+)\}/g,(S,k)=>{const C=w[k];return C==null||C===""?"—":String(C)}):`Row ${y+1}`,x=l.length>u,v=l.length<d;return(0,r.jsxs)("div",{className:"col-span-full space-y-2",children:[(0,r.jsxs)("div",{className:"space-y-0.5",children:[e.label&&(0,r.jsx)("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle",children:Ke(e.label,o)}),e.description&&(0,r.jsx)("p",{className:"text-[11px] text-foreground-subtle",children:Ke(e.description,o)})]}),l.length===0?(0,r.jsx)("div",{className:"rounded-md border border-dashed border-border bg-background px-3 py-3 text-center text-[11px] text-foreground-subtle",children:e.emptyMessage??"No entries"}):(0,r.jsx)("div",{className:"space-y-2",children:l.map((w,y)=>(0,r.jsxs)("div",{className:"rounded-md border border-border bg-background",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-3 py-1.5",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-foreground",children:b(w,y)}),(0,r.jsxs)("button",{type:"button",onClick:()=>p(y),disabled:n||!x,className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-30 disabled:cursor-not-allowed",title:x?"Remove this row":`At least ${u} row(s) required`,children:[(0,r.jsx)(na,{className:"h-3 w-3"}),"Remove"]})]}),(0,r.jsx)("div",{className:"grid grid-cols-1 @[420px]:grid-cols-2 gap-x-3 gap-y-2 p-3",children:e.itemFields.map(S=>(0,r.jsx)(Qt,{field:S,values:w,onChange:(k,C)=>f(y,k,C),disabled:n,translationFn:o,onTestField:a,allFields:e.itemFields,onAction:i},S.key))})]},y))}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{type:"button",onClick:g,disabled:n||!v,className:"inline-flex items-center gap-1 rounded border border-border bg-surface px-3 py-1 text-[11px] font-medium text-foreground hover:border-primary/40 hover:bg-primary/5 disabled:opacity-30 disabled:cursor-not-allowed",children:[(0,r.jsx)(_r,{className:"h-3 w-3"}),e.addLabel??"Add"]}),!v&&Number.isFinite(d)&&(0,r.jsxs)("span",{className:"ml-2 text-[10px] text-foreground-subtle",children:["(limit: ",d,")"]})]})]})}function zS({field:e,disabled:t,onAction:s}){const[n,o]=(0,h.useState)(!1),a=Qr(),i=async()=>{if(!(e.confirmMessage&&!await a({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant==="danger"?"danger":"default"}))&&s){o(!0);try{await s(e.action,e.key)}finally{o(!1)}}},l={default:"border border-border text-foreground hover:bg-surface-hover",primary:"bg-primary text-primary-foreground hover:bg-primary/90",danger:"bg-danger text-white hover:bg-danger/90"};return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,children:(0,r.jsx)("button",{onClick:i,disabled:t||n,className:`inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${l[e.variant??"default"]??l.default}`,children:n?"Processing...":e.buttonLabel})})}function cl(e,t){const s={...e.paramsStatic??{}};if(e.paramsFromForm)for(const[n,o]of Object.entries(e.paramsFromForm)){const a=t[o];a!=null&&a!==""&&(s[n]=a)}return s}function QS({field:e,value:t,values:s,onChange:n,disabled:o,onAction:a}){const[i,l]=(0,h.useState)(!1),[u,d]=(0,h.useState)(null),[f,p]=(0,h.useState)(null),g=cl(e,s),b=Object.keys(e.paramsFromForm??{}).some(y=>g[y]===void 0);(0,h.useEffect)(()=>{if(!a||b){p(null),d(null);return}let y=!1;return l(!0),d(null),a(e.action,e.key,g).then(S=>{if(y)return;const k=S;let C=[];if(Array.isArray(k))C=k;else if(k&&typeof k=="object")for(const N of Object.keys(k)){const E=k[N];if(Array.isArray(E)){C=E;break}}p(C)}).catch(S=>{y||(d(S instanceof Error?S.message:String(S)),p([]))}).finally(()=>{y||l(!1)}),()=>{y=!0}},[(e.refreshOn??Object.values(e.paramsFromForm??{})).map(y=>`${y}=${JSON.stringify(s[y])}`).join("|"),a,e.action,e.key]);const x=e.mapOption.value,v=e.mapOption.label,w=e.mapOption.description;return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,children:b?(0,r.jsx)("div",{className:"text-[11px] text-foreground-subtle italic",children:e.emptyParamsMessage??"Fill the prerequisite fields above first."}):i?(0,r.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-foreground-subtle",children:[(0,r.jsx)(qe,{className:"h-3 w-3 animate-spin"})," Loading options…"]}):u?(0,r.jsx)("div",{className:"text-[11px] text-danger",children:u}):f&&f.length===0?(0,r.jsx)("div",{className:"text-[11px] text-foreground-subtle italic",children:e.emptyResultsMessage??"No options returned."}):(()=>{const y=(f??[]).some(S=>{const k=S[x];return k===""||k===void 0});return(0,r.jsxs)("select",{className:"w-full rounded-md border border-border bg-surface px-2 py-1.5 text-xs text-foreground",value:typeof t=="string"?t:"",disabled:o,onChange:S=>n(S.target.value),children:[!y&&(0,r.jsx)("option",{value:"",children:"— Select —"}),(f??[]).map((S,k)=>{const C=S[x],N=S[v],E=w?S[w]:void 0,R=typeof C=="string"&&C!==""?C:`row-${k}`;return(0,r.jsxs)("option",{value:typeof C=="string"?C:String(C??""),children:[typeof N=="string"?N:String(N??R),E!==void 0?` (${String(E)})`:""]},R)})]})})()})}function US({field:e,values:t,disabled:s,onAction:n}){const[o,a]=(0,h.useState)(!1),[i,l]=(0,h.useState)(null),u=Qr(),d=async()=>{if(e.confirmMessage&&!await u({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant==="danger"?"danger":"default"})||!n)return;const p=cl(e,t);a(!0),l(null);try{const g=await n(e.action,e.key,p),b=typeof g=="object"&&g!==null?g:null;l({kind:"ok",text:e.successMessage?e.successMessage.replace(/\{(\w+)\}/g,(x,v)=>{const w=b?.[v];return w===void 0?"":String(w)}):"Done."})}catch(g){l({kind:"error",text:g instanceof Error?g.message:String(g)})}finally{a(!1)}},f={default:"border border-border text-foreground hover:bg-surface-hover",primary:"bg-primary text-primary-foreground hover:bg-primary/90",danger:"bg-danger text-white hover:bg-danger/90"};return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,children:(0,r.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,r.jsx)("button",{onClick:d,disabled:s||o,className:`inline-flex w-fit items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${f[e.variant??"default"]??f.default}`,children:o?"Working…":e.buttonLabel}),i&&(0,r.jsx)("div",{className:`text-[11px] ${i.kind==="ok"?"text-emerald-700 dark:text-emerald-300":"text-danger"}`,children:i.text})]})})}function HS({field:e}){const t=Yi();return(0,r.jsx)(je,{label:e.label,description:e.description,required:e.required,span:e.span,children:(0,r.jsx)(nl,{widgetId:e.widgetId,host:"device-tab",config:e.widgetConfig,deviceId:t??void 0,instanceId:e.key})})}function VS(e,t){if(e==null)return"—";if(typeof e=="boolean")return e?"yes":"no";if(typeof e=="number"){const s=Number.isInteger(e)?String(e):e.toFixed(2);return t?`${s} ${t}`:s}return typeof e=="string"?e:JSON.stringify(e)}function WS({field:e,values:t,onAction:s,translationFn:n}){const o="key"in e?e.key:void 0;if(!o)return null;const a=t[o],i=a!==void 0?a:"default"in e?e.default:void 0,l=VS(i,"unit"in e?e.unit:void 0),u="label"in e?e.label:void 0,d="description"in e?e.description:void 0,f="span"in e?e.span:void 0,p="actions"in e?e.actions??[]:[];return(0,r.jsx)(je,{label:u,description:d,span:f,translationFn:n,children:(0,r.jsxs)("div",{className:"flex items-stretch gap-1",children:[(0,r.jsx)("div",{className:"flex-1 rounded-md border border-border bg-surface-alt px-2.5 py-1.5 text-xs text-foreground font-mono break-all",children:l}),p.length>0&&(0,r.jsx)("div",{className:"flex items-center gap-1",children:p.map(g=>(0,r.jsx)(KS,{action:g,fieldKey:o,value:i,onAction:s},g.action))})]})})}function qS({name:e}){const t="h-3.5 w-3.5";switch(e){case"copy":return(0,r.jsx)(pt,{className:t});case"refresh-cw":return(0,r.jsx)(Ls,{className:t});case"external-link":return(0,r.jsx)(Zo,{className:t});case"trash-2":return(0,r.jsx)(at,{className:t});case"download":return(0,r.jsx)(Rs,{className:t});case"upload":return(0,r.jsx)(da,{className:t});default:return(0,r.jsx)(Os,{className:t})}}function KS({action:e,fieldKey:t,value:s,onAction:n}){const o=Qr(),[a,i]=(0,h.useState)(!1),l=e.variant==="danger"?"text-danger hover:bg-danger/10 border-danger/30":e.variant==="primary"?"text-primary hover:bg-primary/10 border-primary/30":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover border-border",u=async()=>{if(!(e.confirmMessage&&!await o({title:e.tooltip,message:e.confirmMessage,variant:e.variant==="danger"?"danger":"default"}))){if(e.action==="copy-value"){try{await navigator.clipboard.writeText(typeof s=="string"?s:String(s))}catch{}return}if(n){i(!0);try{await n(e.action,t)}finally{i(!1)}}}};return(0,r.jsx)("button",{type:"button",onClick:u,disabled:a,title:e.tooltip,className:`inline-flex items-center justify-center rounded-md border px-2 py-1.5 transition-colors disabled:opacity-50 ${l}`,children:(0,r.jsx)(qS,{name:e.icon})})}function ZS(e){return"multiple"in e&&e.multiple!=null}function YS({field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,externalProbe:i,allFields:l,onAction:u}){const d=e.multiple,f=d.min,p=d.max,g=t[e.key],b=[...Array.isArray(g)?g:g!=null?[g]:[]],x=d.itemDefault!==void 0?d.itemDefault:"default"in e&&e.default!==void 0?e.default:"";for(;b.length<f;)b.push(x);const v=C=>s(e.key,[...C]),w=(C,N)=>{const E=[...b];E[C]=N,v(E)},y=()=>{b.length>=p||v([...b,x])},S=C=>{b.length<=f||v(b.filter((N,E)=>E!==C))},k=()=>{const{multiple:C,...N}=e;return{...N,...{label:void 0,description:void 0,required:!1}}};return(0,r.jsx)(je,{label:e.label,description:e.description,required:f>0?e.required:!1,span:e.span,translationFn:o,children:(0,r.jsxs)("div",{className:"space-y-2",children:[b.map((C,N)=>{const E=d.itemLabel?.replace("${n}",String(N+1));return(0,r.jsxs)("div",{className:"space-y-1",children:[E&&(0,r.jsx)("div",{className:Xr,children:E}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{className:"flex-1 min-w-0",children:(0,r.jsx)(Qt,{field:k(),values:{...t,[e.key]:C},onChange:(R,A)=>w(N,A),disabled:n,translationFn:o,onTestField:a,onAction:u,allFields:l})}),b.length>f&&(0,r.jsx)("button",{type:"button",onClick:()=>S(N),disabled:n,title:"Remove",className:"flex-shrink-0 inline-flex items-center justify-center rounded-md border border-border p-1.5 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors disabled:opacity-40",children:(0,r.jsx)(at,{className:"h-3.5 w-3.5"})})]})]},N)}),(0,r.jsxs)("div",{className:"flex items-center justify-between pt-1",children:[b.length<p?(0,r.jsxs)("button",{type:"button",onClick:y,disabled:n,className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40",children:[(0,r.jsx)(_r,{className:"h-3 w-3"}),d.addLabel??"Add"]}):(0,r.jsx)("span",{}),(0,r.jsxs)("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:[b.length,"/",p]})]})]})})}function ul(e,t,s){if(!("showWhen"in e)||!e.showWhen)return!0;const n=e.showWhen,o=t[n.field],a=s?.find(u=>"key"in u&&u.key===n.field),i=a&&"default"in a?a.default:void 0,l=o!==void 0?o:i;return n.equals!==void 0?l===n.equals:n.notEquals!==void 0?l!==n.notEquals:n.in!==void 0?n.in.includes(l):n.notIn!==void 0?!n.notIn.includes(l):n.includes!==void 0?Array.isArray(l)&&l.includes(n.includes):n.notIncludes!==void 0?!Array.isArray(l)||!l.includes(n.notIncludes):!0}function Qt({field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,externalProbe:i,allFields:l,onAction:u}){if(ZS(e))return(0,r.jsx)(YS,{field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,externalProbe:i,allFields:l,onAction:u});if("readonlyField"in e&&e.readonlyField===!0)return(0,r.jsx)(WS,{field:e,values:t,onAction:u,translationFn:o});if(!ul(e,t,l))return null;const d=t[e.key],f=d!==void 0?d:"default"in e?e.default:void 0,p=b=>s(e.key,b),g=Zi(e.type);switch(e.type){case"text":return(0,r.jsx)(wS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"number":return(0,r.jsx)(SS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"boolean":return(0,r.jsx)(kS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"select":return(0,r.jsx)(jS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"multiselect":return(0,r.jsx)(NS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"password":return(0,r.jsx)(CS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"textarea":return(0,r.jsx)(MS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"slider":return(0,r.jsx)(ES,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"tags":return(0,r.jsx)(AS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"color":return(0,r.jsx)(PS,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"node-select":return(0,r.jsx)(ol,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"node-multiselect":return(0,r.jsx)(al,{field:e,value:f,onChange:p,disabled:n,translationFn:o});case"probe":return(0,r.jsx)(RS,{field:e,value:f,onChange:p,disabled:n,translationFn:o,onTestField:a,onAction:u,externalProbe:i});case"group":return(0,r.jsx)(DS,{field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a});case"sub-tabs":return(0,r.jsx)(TS,{field:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,onAction:u});case"separator":return(0,r.jsx)(IS,{});case"info":return(0,r.jsx)(OS,{field:e});case"object-array":return(0,r.jsx)(BS,{field:e});case"editable-array":return(0,r.jsx)(FS,{field:e,value:f,onChange:p,disabled:n,translationFn:o,onTestField:a,onAction:u});case"button":return(0,r.jsx)(zS,{field:e,disabled:n,onAction:u});case"addon-action-select":return(0,r.jsx)(QS,{field:e,value:f,values:t,onChange:p,disabled:n,onAction:u});case"addon-action-button":return(0,r.jsx)(US,{field:e,values:t,disabled:n,onAction:u});case"widget":return(0,r.jsx)(HS,{field:e});default:return g?(0,r.jsx)(g,{field:e,value:f,onChange:p,disabled:n}):null}}function XS(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function Ke(e,t){if(e!==void 0)return t&&XS(e)?t(e):e}function JS({section:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,probeResults:i}){const[l,u]=(0,h.useState)(e.defaultCollapsed??!1),d=e.style==="accordion",f=e.columns??2,p=f===1?"grid-cols-1":f===3?"grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3":f===4?"grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4":"grid-cols-1 @[640px]:grid-cols-2";return(0,r.jsxs)("div",{className:"@container rounded-lg border border-border bg-surface p-3",style:{containerType:"inline-size"},children:[(0,r.jsxs)("div",{className:["flex items-center justify-between mb-2",d?"cursor-pointer":""].join(" "),onClick:d?()=>u(g=>!g):void 0,children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:Ke(e.title,o)}),e.description&&(0,r.jsx)("p",{className:"text-[10px] text-foreground-subtle mt-0.5",children:Ke(e.description,o)})]}),d&&(0,r.jsx)("span",{className:"text-foreground-subtle text-xs ml-2",children:l?"▸":"▾"})]}),!l&&(0,r.jsx)("div",{className:`grid ${p} gap-x-3 gap-y-2.5`,children:e.fields.map(g=>(0,r.jsx)(Qt,{field:g,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,externalProbe:i?.[g.key]},g.key))})]})}function dl({schema:e,values:t,onChange:s,disabled:n,translationFn:o,onTestField:a,probeResults:i,onClearProbe:l}){const u=(d,f)=>{s({...t,[d]:f}),l?.(d)};return(0,r.jsx)("div",{className:"space-y-4",children:e.sections.map(d=>(0,r.jsx)(JS,{section:d,values:t,onChange:u,disabled:n,translationFn:o,onTestField:a,probeResults:i},d.id))})}var ek=({open:e})=>(0,r.jsx)("svg",{className:`h-3 w-3 transition-transform ${e?"rotate-90":""}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:(0,r.jsx)("polyline",{points:"9 18 15 12 9 6"})});function fl(e){const t={};if(!e)return t;for(const s of e.sections)for(const n of s.fields){if(n.type==="separator"||n.type==="info"||n.type==="button"||n.type==="group")continue;const o=n.key;t[o]=n.value}return t}function tk(e){return{...e,sections:e.sections.map(t=>({...t,fields:t.fields.map(s=>{if(s.type==="separator"||s.type==="info"||s.type==="button"||s.type==="group")return s;const{value:n,...o}=s;return o})}))}}function rk({trpc:e,addonId:t,nodeId:s,title:n,disabled:o,onAfterChange:a,refreshToken:i,collapsible:l,defaultOpen:u,mode:d,onOverrideChange:f}){const p=d??"persist",[g,b]=(0,h.useState)(null),[x,v]=(0,h.useState)(!0),[w,y]=(0,h.useState)(null),[S,k]=(0,h.useState)(!1),[C,N]=(0,h.useState)(u??!1),[E,R]=(0,h.useState)({}),[A,Q]=(0,h.useState)(null);(0,h.useEffect)(()=>{Q(null),R({})},[e,t,s,i,p]),(0,h.useEffect)(()=>{let se=!1;v(!0),y(null);const J=p==="override"&&Object.keys(E).length>0?E:void 0;return e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:s,...J?{overlay:J}:{}}).then(H=>{se||(b(H),J||Q(fl(H)),v(!1))}).catch(H=>{se||(y(H instanceof Error?H.message:String(H)),v(!1))}),()=>{se=!0}},[e,t,s,i,p,JSON.stringify(E)]);const ee=(0,h.useMemo)(()=>fl(g),[g]),ne=(0,h.useMemo)(()=>g?tk(g):null,[g]),pe=async se=>{if(p==="override"){const H=A??ee,xe={};for(const D of Object.keys(se))se[D]!==H[D]&&(xe[D]=se[D]);const de={...H,...xe};R(xe),f?.(xe,de);return}const J={};for(const H of Object.keys(se))se[H]!==ee[H]&&(J[H]=se[H]);if(Object.keys(J).length!==0){k(!0);try{await e.addonSettings.updateGlobalSettings.mutate({addonId:t,nodeId:s,patch:J}),b(await e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:s})),a?.()}catch(H){y(H instanceof Error?H.message:String(H))}finally{k(!1)}}};if(x)return(0,r.jsxs)("div",{className:"text-xs text-foreground-subtle animate-pulse",children:["Loading ",n??t,"…"]});if(w)return(0,r.jsxs)("div",{className:"text-xs text-red-400",children:[n??t,": ",w]});if(!g||!ne)return(0,r.jsxs)("div",{className:"text-xs text-foreground-subtle",children:[n??t," not available on ",s,"."]});const ae=p==="override"?{...ee,...E}:ee,ce=(0,r.jsxs)(r.Fragment,{children:[p==="override"?(0,r.jsx)("div",{className:"mb-2 text-[11px] text-foreground-subtle",children:"Benchmark override — applies to this run only. The addon's saved settings are not changed."}):null,(0,r.jsx)(dl,{schema:ne,values:ae,onChange:pe,disabled:o===!0||S})]});return l===!0?(0,r.jsxs)("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>N(se=>!se),className:"w-full px-4 py-2 flex items-center gap-2 hover:bg-surface-hover text-left","aria-expanded":C,children:[(0,r.jsx)(ek,{open:C}),(0,r.jsx)("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide flex-1",children:n??t}),(0,r.jsx)("span",{className:"text-[10px] text-foreground-subtle",children:C?"hide":"edit"})]}),C?(0,r.jsx)("div",{className:"border-t border-border px-4 py-3",children:ce}):null]}):n?(0,r.jsxs)("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[(0,r.jsx)("div",{className:"border-b border-border px-4 py-2",children:(0,r.jsx)("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide",children:n})}),(0,r.jsx)("div",{className:"px-4 py-3",children:ce})]}):(0,r.jsx)("div",{children:ce})}function ml({detections:{motion:e,motionRaw:t,detection:s,phase:n},showMotionZones:o=!0,showMotionRaw:a=!0,showDetections:i=!0,showPhaseIndicator:l=!0}){const u=o&&e&&e.zones.length>0,d=a&&t&&t.boxes.length>0,f=i&&s&&s.detections.length>0;return!u&&!d&&!f&&!l?null:(0,r.jsxs)("div",{className:"absolute inset-0 pointer-events-none z-10",children:[l&&(0,r.jsx)(sk,{phase:n}),d&&(0,r.jsx)(nk,{raw:t}),u&&(0,r.jsx)(ok,{motion:e}),f&&(0,r.jsx)(ak,{detections:s.detections,frameWidth:s.frameWidth,frameHeight:s.frameHeight})]})}function sk({phase:e}){const t=us(e);return(0,r.jsxs)("div",{className:"absolute top-2 left-2 flex items-center gap-1.5 px-2 py-1 rounded-md bg-black/60 backdrop-blur-sm",children:[(0,r.jsx)("span",{className:`w-2 h-2 rounded-full ${t.dotClass}`}),(0,r.jsx)("span",{className:"text-[10px] font-semibold text-white uppercase tracking-wider",children:t.label})]})}function nk({raw:e}){return e.frameWidth===0||e.frameHeight===0?null:(0,r.jsx)(r.Fragment,{children:e.boxes.map((t,s)=>{const[n,o,a,i]=t.bbox,l=n/e.frameWidth*100,u=o/e.frameHeight*100,d=(a-n)/e.frameWidth*100,f=(i-o)/e.frameHeight*100,p=Math.max(.05,Math.min(.25,t.changeScore*.3));return(0,r.jsx)("div",{className:"absolute rounded-sm",style:{left:`${l}%`,top:`${u}%`,width:`${d}%`,height:`${f}%`,backgroundColor:`rgba(239, 68, 68, ${p})`}},`mr-${s}`)})})}function ok({motion:e}){return e.frameWidth===0||e.frameHeight===0?null:(0,r.jsx)(r.Fragment,{children:e.zones.filter(t=>t.w*t.h/(e.frameWidth*e.frameHeight)<.9).map((t,s)=>{const n=Math.max(.15,Math.min(.5,t.intensity/255));return(0,r.jsx)("div",{className:"absolute rounded-sm",style:{left:`${t.x/e.frameWidth*100}%`,top:`${t.y/e.frameHeight*100}%`,width:`${t.w/e.frameWidth*100}%`,height:`${t.h/e.frameHeight*100}%`,border:`1px solid rgba(250, 204, 21, ${n})`,backgroundColor:`rgba(250, 204, 21, ${n*.15})`}},`mz-${s}`)})})}function ak({detections:e,frameWidth:t,frameHeight:s}){return t===0||s===0?null:(0,r.jsx)(r.Fragment,{children:e.map(n=>{const{x:o,y:a,width:i,height:l}=n.bbox,u=o/t*100,d=a/s*100,f=i/t*100,p=l/s*100,g=_e(n.macroClass),b=[`${n.macroClass} ${(n.score*100).toFixed(0)}%`];for(const x of n.labels)b.push(x.label);return(0,r.jsx)("div",{className:"absolute border-2 rounded-sm",style:{left:`${u}%`,top:`${d}%`,width:`${f}%`,height:`${p}%`,borderColor:g},children:(0,r.jsx)("div",{className:"absolute -top-4 left-0 px-1 py-0.5 text-[9px] font-bold text-white rounded-sm whitespace-nowrap",style:{backgroundColor:g},children:b.join(" | ")})},`det-${n.id}`)})})}function ik(e){const t={};if(typeof window<"u"){if(e){const n=e.getBoundingClientRect();n.width>0&&n.height>0&&(t.viewportWidth=Math.round(n.width),t.viewportHeight=Math.round(n.height))}t.viewportWidth===void 0&&(t.viewportWidth=window.innerWidth,t.viewportHeight=window.innerHeight),t.devicePixelRatio=window.devicePixelRatio||1;const s=navigator.connection;s?.downlink&&s.downlink>0&&(t.downlinkMbps=s.downlink)}return t}var lk=3e3,ck=5;function pl({serverUrl:e,streamKey:t,label:s,autoPlay:n=!0,muted:o=!0,showControls:a=!0,className:i="",onStateChange:l,onError:u,overlay:d,createSession:f,sendAnswer:p,closeSession:g,hintsOverride:b}){const x=(0,h.useRef)(null),v=(0,h.useRef)(null),w=(0,h.useRef)(null),y=(0,h.useRef)(new Set),S=(0,h.useRef)(null),k=(0,h.useRef)(null),C=(0,h.useRef)(0),N=(0,h.useRef)(!0),[E,R]=(0,h.useState)("idle"),[A,Q]=(0,h.useState)(""),[ee,ne]=(0,h.useState)(o),[pe,ae]=(0,h.useState)(!1),[ce,se]=(0,h.useState)(!1),J=(0,h.useRef)(null),H=(0,h.useRef)(!1);(p||f)&&(H.current=!0);const xe=H.current,de=(0,h.useCallback)(K=>{R(K),l?.(K)},[l]),D=(0,h.useCallback)(()=>{if(S.current?.abort(),S.current=null,k.current&&(clearTimeout(k.current),k.current=null),w.current&&(w.current.close(),w.current=null),g&&y.current.size>0){for(const K of y.current)g(K).catch(()=>{});y.current.clear()}x.current&&(x.current.srcObject=null)},[g]),$=(0,h.useCallback)(async()=>{if(!N.current||!f||!p)return;D(),de("connecting");const K=new AbortController;S.current=K;try{const{sessionId:ue,sdpOffer:ve}=await f({...ik(v.current),...b});if(y.current.add(ue),!N.current||K.signal.aborted){g?.(ue).catch(()=>{}),y.current.delete(ue);return}const ye=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]});w.current=ye;const L=new MediaStream;ye.ontrack=I=>{console.debug("[WebRTC] ontrack",I.track.kind,I.track.readyState),L.addTrack(I.track),x.current&&(x.current.srcObject=L,x.current.play().catch(()=>{}))},ye.oniceconnectionstatechange=()=>{if(!N.current)return;const I=ye.iceConnectionState;console.debug("[WebRTC] ICE state:",I),I==="connected"||I==="completed"?(C.current=0,de("playing"),x.current?.paused&&(console.debug("[WebRTC] video was paused at ICE connected — calling play()"),x.current.play().catch(()=>{}))):(I==="failed"||I==="disconnected"||I==="closed")&&(de("disconnected"),V())},ye.onicecandidateerror=I=>{console.debug("[WebRTC] ICE candidate error:",I)},console.debug("[WebRTC] Setting remote description (server offer)..."),await ye.setRemoteDescription({type:"offer",sdp:ve});const M=await ye.createAnswer();if(await ye.setLocalDescription(M),console.debug("[WebRTC] Local description set, waiting for ICE gathering..."),await hl(ye),!N.current)return;const T=(ye.localDescription?.sdp??"").split(`
77
77
  `).filter(I=>I.startsWith("a=candidate:")).length;console.debug("[WebRTC] Sending answer to server",{localCandidates:T,sessionId:ue.slice(0,8)}),await p(ue,ye.localDescription?.sdp??""),console.debug("[WebRTC] Answer sent successfully");const Z=ye,re=()=>{const I=Z.connectionState;if(I==="closed"||I==="failed")return;const Y=x.current;Y&&Y.readyState===0&&console.log(`[WebRTC] no video data yet (ice=${Z.iceConnectionState})`)};setTimeout(re,3e3),setTimeout(re,8e3)}catch(ue){if(!N.current)return;const ve=ue instanceof Error?ue.message:String(ue);Q(ve),de("error"),u?.(ve),V()}},[e,t,f,p,D,de,u,b]),_=(0,h.useCallback)(async()=>{if(N.current){D(),de("connecting");try{const K=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]});w.current=K,K.addTransceiver("video",{direction:"recvonly"}),K.addTransceiver("audio",{direction:"recvonly"});const ue=new MediaStream;K.ontrack=T=>{ue.addTrack(T.track),x.current&&(x.current.srcObject=ue,x.current.play().catch(()=>{}))},K.oniceconnectionstatechange=()=>{if(!N.current)return;const T=K.iceConnectionState;T==="connected"||T==="completed"?(C.current=0,de("playing"),x.current?.paused&&x.current.play().catch(()=>{})):(T==="failed"||T==="disconnected"||T==="closed")&&(de("disconnected"),V())};const ve=await K.createOffer();if(await K.setLocalDescription(ve),await hl(K),!N.current)return;const ye=`${e}/api/webrtc?src=${encodeURIComponent(t)}`,L=await fetch(ye,{method:"POST",headers:{"Content-Type":"application/sdp"},body:K.localDescription?.sdp??""});if(!L.ok)throw new Error(`WHEP ${L.status}: ${L.statusText}`);const M=await L.text();await K.setRemoteDescription({type:"answer",sdp:M})}catch(K){if(!N.current)return;const ue=K instanceof Error?K.message:String(K);Q(ue),de("error"),u?.(ue),V()}}},[e,t,D,de,u]),te=xe?$:_,U=(0,h.useRef)(()=>{});U.current=te;const V=(0,h.useCallback)(()=>{N.current&&(C.current>=ck||(C.current+=1,k.current=setTimeout(()=>{N.current&&U.current()},lk)))},[]);(0,h.useEffect)(()=>(N.current=!0,C.current=0,n&&te(),()=>{N.current=!1,D()}),[e,t]);const W=(0,h.useRef)(!1);(0,h.useEffect)(()=>{!n||!xe||!f||!p||W.current||w.current||(W.current=!0,te())},[n,xe,f,p,te]);const F=()=>{C.current=0,te()},X=()=>{x.current&&(x.current.muted=!x.current.muted,ne(x.current.muted))},q=async()=>{if(v.current)try{document.fullscreenElement?await document.exitFullscreen():await v.current.requestFullscreen()}catch(K){console.warn(`Fullscreen toggle failed: ${K instanceof Error?K.message:K}`)}},Re=()=>{if(!x.current)return;const K=document.createElement("canvas");K.width=x.current.videoWidth||1280,K.height=x.current.videoHeight||720;const ue=K.getContext("2d");if(!ue)return;ue.drawImage(x.current,0,0);const ve=document.createElement("a");ve.download=`${t.replace(/[/:]/g,"-")}-${Date.now()}.jpg`,ve.href=K.toDataURL("image/jpeg",.92),ve.click()};(0,h.useEffect)(()=>{const K=()=>ae(!!document.fullscreenElement);return document.addEventListener("fullscreenchange",K),()=>document.removeEventListener("fullscreenchange",K)},[]);const De=()=>{se(!0),J.current&&clearTimeout(J.current),J.current=setTimeout(()=>se(!1),3e3)};return(0,r.jsxs)("div",{ref:v,className:`relative bg-black overflow-hidden group ${i}`,onMouseMove:De,onMouseEnter:De,children:[(0,r.jsx)("video",{ref:x,autoPlay:n,muted:ee,playsInline:!0,className:"w-full h-full object-contain"}),s&&E==="playing"&&(0,r.jsx)("div",{className:"absolute top-2 left-2 px-2 py-0.5 rounded bg-black/60 text-[10px] text-white font-medium",children:s}),d,E==="connecting"&&(0,r.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-black/70 gap-2",children:[(0,r.jsx)("svg",{className:"h-6 w-6 text-white/60 animate-spin",viewBox:"0 0 24 24",fill:"none",children:(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"32",strokeDashoffset:"32",className:"animate-[dash_1.5s_ease-in-out_infinite]"})}),(0,r.jsx)("span",{className:"text-xs text-white/60",children:"Connecting…"})]}),(E==="error"||E==="disconnected")&&(0,r.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-black/70 gap-2",children:[(0,r.jsx)("svg",{className:"h-6 w-6 text-red-400",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,r.jsx)("path",{d:"M1 1l5.5 5.5M23 23l-5.5-5.5M8.11 15.89a8 8 0 0110.78-10.78M3.64 3.64A12 12 0 0020.36 20.36",strokeLinecap:"round"})}),(0,r.jsx)("span",{className:"text-xs text-red-400 text-center px-4",children:E==="error"?A||"Connection failed":"Disconnected"}),(0,r.jsx)("button",{onClick:F,className:"mt-1 inline-flex items-center gap-1.5 rounded px-3 py-1 text-xs bg-white/10 text-white hover:bg-white/20 transition-colors",children:"Reconnect"})]}),a&&E==="playing"&&(0,r.jsxs)("div",{className:`absolute bottom-0 inset-x-0 flex items-center justify-between px-3 py-1.5 bg-gradient-to-t from-black/80 to-transparent transition-opacity duration-200 ${ce?"opacity-100":"opacity-0"}`,children:[(0,r.jsx)("div",{className:"flex items-center gap-1",children:(0,r.jsx)(pn,{onClick:X,title:ee?"Unmute":"Mute",children:ee?(0,r.jsxs)("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,r.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,r.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,r.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]}):(0,r.jsxs)("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,r.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,r.jsx)("path",{d:"M19.07 4.93a10 10 0 010 14.14M15.54 8.46a5 5 0 010 7.07"})]})})}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)(pn,{onClick:Re,title:"Take snapshot",children:(0,r.jsxs)("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,r.jsx)("path",{d:"M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z"}),(0,r.jsx)("circle",{cx:"12",cy:"13",r:"4"})]})}),(0,r.jsx)(pn,{onClick:q,title:pe?"Exit fullscreen":"Fullscreen",children:pe?(0,r.jsx)("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:(0,r.jsx)("path",{d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,r.jsx)("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:(0,r.jsx)("path",{d:"M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3"})})})]})]})]})}function pn({onClick:e,title:t,children:s}){return(0,r.jsx)("button",{onClick:e,title:t,className:"rounded-full p-1.5 text-white/80 hover:text-white hover:bg-white/20 transition-colors",children:s})}async function hl(e){if(e.iceGatheringState!=="complete")return new Promise(t=>{const s=()=>{e.iceGatheringState==="complete"&&(e.removeEventListener("icegatheringstatechange",s),t())};e.addEventListener("icegatheringstatechange",s),setTimeout(t,5e3)})}var hn=ot("camstack:player-overlays-state",null),gn=ot("camstack:player-overlays-actions",null);function uk({children:e}){const[t,s]=(0,h.useState)(()=>new Map),[n,o]=(0,h.useState)(()=>new Map),a=(0,h.useCallback)(p=>{s(g=>{const b=new Map(g);return b.set(p.id,p),b})},[]),i=(0,h.useCallback)(p=>{s(g=>{if(!g.has(p))return g;const b=new Map(g);return b.delete(p),b})},[]),l=(0,h.useCallback)(p=>{o(g=>{const b=new Map(g);return b.set(p.id,p),b})},[]),u=(0,h.useCallback)(p=>{o(g=>{if(!g.has(p))return g;const b=new Map(g);return b.delete(p),b})},[]),d=(0,h.useMemo)(()=>({layers:t,buttons:n}),[t,n]),f=(0,h.useMemo)(()=>({setLayer:a,removeLayer:i,setButton:l,removeButton:u}),[a,i,l,u]);return(0,r.jsx)(hn.Provider,{value:d,children:(0,r.jsx)(gn.Provider,{value:f,children:e})})}function dk(){const e=(0,h.useContext)(hn);return(0,h.useMemo)(()=>e?[...e.layers.values()].sort((t,s)=>t.order-s.order):[],[e])}function gl(){const e=(0,h.useContext)(hn);return(0,h.useMemo)(()=>e?[...e.buttons.values()].sort((t,s)=>t.order-s.order):[],[e])}function fk(e){const t=(0,h.useContext)(gn);(0,h.useEffect)(()=>{if(!(!t||!e))return t.setLayer(e),()=>t.removeLayer(e.id)},[t,e])}function mk(e){const t=(0,h.useContext)(gn);(0,h.useEffect)(()=>{if(!(!t||!e))return t.setButton(e),()=>t.removeButton(e.id)},[t,e])}function pk(e){return e==="streaming"?"bg-emerald-500":e==="connecting"?"bg-amber-500":e==="error"?"bg-rose-500":"bg-zinc-500"}function hk(e){const t=Math.floor(e/1e3);return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:`${Math.floor(t/3600)}h${Math.floor(t%3600/60)}m`}function bn({className:e}){return(0,r.jsx)("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polygon",{points:"5 3 19 12 5 21 5 3"})})}function gk({className:e}){return(0,r.jsx)("svg",{className:e,viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("rect",{x:"6",y:"6",width:"12",height:"12",rx:"1"})})}function bk({className:e}){return(0,r.jsxs)("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z"}),(0,r.jsx)("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),(0,r.jsx)("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),(0,r.jsx)("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}function xk({className:e}){return(0,r.jsxs)("svg",{className:e,viewBox:"0 0 24 24",fill:"currentColor",children:[(0,r.jsx)("circle",{cx:"5",cy:"12",r:"2"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,r.jsx)("circle",{cx:"19",cy:"12",r:"2"})]})}function xn({label:e,active:t,onClick:s}){return(0,r.jsxs)("button",{type:"button",onClick:s,className:"w-full flex items-center justify-between gap-3 px-3 py-1.5 text-[11px] text-foreground hover:bg-surface-hover transition-colors",children:[(0,r.jsx)("span",{children:e}),(0,r.jsx)("span",{className:`inline-block h-3 w-5 rounded-full transition-colors ${t?"bg-primary":"bg-foreground-subtle/30"} relative`,children:(0,r.jsx)("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-white transition-all ${t?"left-2.5":"left-0.5"}`})})]})}function bl({className:e}){return(0,r.jsxs)("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"23 4 23 10 17 10"}),(0,r.jsx)("polyline",{points:"1 20 1 14 7 14"}),(0,r.jsx)("path",{d:"M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15"})]})}function vk({className:e}){return(0,r.jsxs)("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"2",y1:"2",x2:"22",y2:"22"}),(0,r.jsx)("path",{d:"M10.41 10.41a2 2 0 11-2.83-2.83"}),(0,r.jsx)("line",{x1:"13.5",y1:"13.5",x2:"6",y2:"21"}),(0,r.jsx)("path",{d:"M18 12l-1.5-1.5"}),(0,r.jsx)("path",{d:"M21 15V5a2 2 0 00-2-2H5"}),(0,r.jsx)("path",{d:"M21 21H5a2 2 0 01-2-2V11"})]})}function yk({serverUrl:e,createSession:t,sendAnswer:s,closeSession:n,streams:o,activeStreamId:a,onStreamChange:i,deviceName:l,phase:u,pipelineMetrics:d,detections:f,defaultShowDetections:p=!0,defaultShowMotion:g=!1,streamStats:b,autoPlay:x=!1,showPlayStop:v=!1,snapshotSrc:w,snapshotLoading:y=!1,onRefreshSnapshot:S,showStreamStats:k=!1,children:C,extraOverlay:N,ptzAvailable:E=!1,ptzShown:R=!1,ptzOverlay:A,onPtzToggle:Q,intercomAvailable:ee=!1,intercomShown:ne=!1,onIntercomToggle:pe,chromeless:ae=!1,className:ce}){const se=gl(),[J,H]=(0,h.useState)(x),[xe,de]=(0,h.useState)(p),[D,$]=(0,h.useState)(g),[_,te]=(0,h.useState)(null),[U,V]=(0,h.useState)(!1),W=(0,h.useRef)(null);(0,h.useEffect)(()=>{if(!U)return;function I(Y){W.current&&!W.current.contains(Y.target)&&V(!1)}return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[U]);const F=a??_??o?.[0]?.id??"",X=o?.find(I=>I.id===F)??o?.[0],q=X?.inputFps!=null?{status:X.status??"unknown",inputFps:X.inputFps,bitrateKbps:X.bitrateKbps??0}:null,Re=I=>{te(I),i?.(I),J&&v&&(H(!1),setTimeout(()=>H(!0),50))},De=(0,h.useMemo)(()=>{const I=X?.target;if(I)return Y=>t(I,Y)},[t,X]),K=o,ue=()=>H(!0),ve=()=>H(!1),ye=d?.phase??u,L=ye==="active",M=!!f,T=M&&(xe||D),Z=E&&R&&!!A,re=v?J:!0;return(0,r.jsxs)("div",{className:`overflow-hidden ${ae?"":"rounded-xl border border-border bg-surface"} ${ce??""}`,children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(b??q)&&(0,r.jsx)("span",{className:`w-2 h-2 rounded-full ${pk((b??q).status)}`}),l&&(0,r.jsx)("span",{className:"text-xs font-medium text-foreground",children:l}),K&&K.length>1&&(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("select",{"data-testid":"stream-profile-select",value:F,onChange:I=>Re(I.target.value),className:"appearance-none cursor-pointer rounded-md border border-border bg-surface-hover hover:bg-surface text-foreground text-[11px] font-medium pl-2 pr-6 py-1 focus:outline-none focus:ring-1 focus:ring-primary transition-colors",children:K.map(I=>(0,r.jsx)("option",{value:I.id,children:I.label},I.id))}),(0,r.jsx)("span",{className:"pointer-events-none absolute right-1.5 top-1/2 -translate-y-1/2 text-foreground-subtle",children:(0,r.jsx)("svg",{className:"h-2.5 w-2.5",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"3 4.5 6 7.5 9 4.5"})})})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[ee&&(0,r.jsxs)("button",{"data-testid":"stream-intercom-toggle","data-intercom-shown":ne?"true":"false",onClick:pe,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors ${ne?"bg-primary/15 text-primary":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,title:ne?"Close intercom":"Open intercom",children:[(0,r.jsx)(bk,{className:"h-3 w-3"}),(0,r.jsx)("span",{className:"hidden xl:inline",children:"Intercom"})]}),se.map(I=>{const Y=I.tone==="primary"?"bg-primary text-primary-foreground":"bg-primary/15 text-primary";return(0,r.jsxs)("button",{type:"button","data-toolbar-button-id":I.id,"data-toolbar-button-active":I.active?"true":"false",onClick:I.onClick,disabled:I.disabled,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors disabled:opacity-50 ${I.active?Y:"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,title:I.title??I.label,children:[I.icon,(0,r.jsx)("span",{className:"hidden xl:inline",children:I.label})]},I.id)}),v&&(0,r.jsxs)("button",{"data-testid":"stream-play-toggle","data-stream-playing":re?"true":"false",onClick:re?ve:ue,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors ${re?"bg-danger/10 text-danger hover:bg-danger/20":"bg-primary/10 text-primary hover:bg-primary/20"}`,title:re?"Stop stream":"Start stream",children:[re?(0,r.jsx)(gk,{className:"h-3 w-3"}):(0,r.jsx)(bn,{className:"h-3 w-3"}),(0,r.jsx)("span",{className:"hidden xl:inline",children:re?"Stop":"Play"})]}),S&&(0,r.jsxs)("button",{"data-testid":"stream-snapshot-refresh",onClick:S,disabled:y,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50",title:"Force snapshot refresh",children:[(0,r.jsx)(bl,{className:`h-3 w-3 ${y?"animate-spin":""}`}),(0,r.jsx)("span",{className:"hidden xl:inline",children:"Snapshot"})]}),(M||E||d||ye||b||q&&q.inputFps>0)&&(0,r.jsxs)("div",{ref:W,className:"relative",children:[(0,r.jsx)("button",{onClick:()=>V(I=>!I),title:"More controls",className:"inline-flex items-center justify-center rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:(0,r.jsx)(xk,{className:"h-3.5 w-3.5"})}),U&&(0,r.jsxs)("div",{className:"absolute right-0 top-full mt-1 z-30 min-w-[200px] rounded-lg border border-border bg-surface shadow-xl py-1.5",children:[k&&b&&(0,r.jsxs)("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[(0,r.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,r.jsx)("span",{children:"Input"}),(0,r.jsxs)("span",{className:"tabular-nums text-foreground",children:[b.inputFps.toFixed(1)," fps"]})]}),(0,r.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,r.jsx)("span",{children:"Decode"}),(0,r.jsxs)("span",{className:"tabular-nums text-foreground",children:[b.decodeFps.toFixed(1)," fps"]})]}),(0,r.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,r.jsx)("span",{children:"Uptime"}),(0,r.jsx)("span",{className:"tabular-nums text-foreground",children:hk(b.uptimeMs)})]})]}),!k&&q&&q.inputFps>0&&(0,r.jsxs)("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[(0,r.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,r.jsx)("span",{children:"Input"}),(0,r.jsxs)("span",{className:"tabular-nums text-foreground",children:[q.inputFps.toFixed(1)," fps"]})]}),q.bitrateKbps>0&&(0,r.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,r.jsx)("span",{children:"Bitrate"}),(0,r.jsxs)("span",{className:"tabular-nums text-foreground",children:[q.bitrateKbps," kbps"]})]})]}),(d||M&&ye)&&(0,r.jsxs)("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[(0,r.jsxs)("div",{className:"flex justify-between gap-3 items-center",children:[(0,r.jsx)("span",{children:"Phase"}),(0,r.jsxs)("span",{className:`flex items-center gap-1 font-semibold uppercase tracking-wider ${L?"text-red-400":"text-emerald-400"}`,children:[(0,r.jsx)("span",{className:`w-1.5 h-1.5 rounded-full ${L?"bg-red-500 animate-pulse":"bg-emerald-500"}`}),L?"Active":"Watching"]})]}),d&&d.detectionFps>0&&(0,r.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,r.jsx)("span",{children:"Detection"}),(0,r.jsxs)("span",{className:"tabular-nums text-foreground",children:[d.detectionFps.toFixed(1)," det/s"]})]}),d&&d.avgInferenceMs>0&&(0,r.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,r.jsx)("span",{children:"Inference"}),(0,r.jsxs)("span",{className:"tabular-nums text-foreground",children:[d.avgInferenceMs.toFixed(0)," ms"]})]})]}),M&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(xn,{label:"Show detections",active:xe,onClick:()=>de(I=>!I)}),(0,r.jsx)(xn,{label:"Show motion",active:D,onClick:()=>$(I=>!I)})]}),E&&(0,r.jsx)(xn,{label:"PTZ controls",active:R,onClick:()=>{Q?.(),V(!1)}})]})]})]})]}),re?(0,r.jsx)("div",{className:"aspect-video relative",children:(0,r.jsx)(pl,{serverUrl:e,streamKey:F,autoPlay:!0,className:"w-full h-full",createSession:De,sendAnswer:s,closeSession:n,overlay:T||N||Z?(0,r.jsxs)(r.Fragment,{children:[T&&(0,r.jsx)(ml,{detections:f,showPhaseIndicator:!1,showMotionZones:D,showMotionRaw:D,showDetections:xe}),N,Z&&A]}):void 0},F)}):(0,r.jsx)(wk,{src:w??null,isLoading:y,onPlay:ue,onRetry:S,extraOverlay:N||Z?(0,r.jsxs)(r.Fragment,{children:[N,Z&&A]}):null,suppressPlayHover:!!N||Z}),C]})}function wk({src:e,isLoading:t,onPlay:s,onRetry:n,extraOverlay:o,suppressPlayHover:a=!1}){return e?(0,r.jsxs)("div",{className:"relative w-full aspect-video bg-black/90 flex items-center justify-center",children:[(0,r.jsx)("img",{src:e,alt:"Camera snapshot",className:"w-full h-full object-contain"}),!a&&(0,r.jsx)("button",{onClick:s,className:"absolute inset-0 flex items-center justify-center bg-black/30 opacity-0 hover:opacity-100 transition-opacity cursor-pointer",children:(0,r.jsx)("div",{className:"h-14 w-14 rounded-full bg-white/20 backdrop-blur-sm flex items-center justify-center",children:(0,r.jsx)(bn,{className:"h-7 w-7 text-white ml-0.5"})})}),o]}):t?(0,r.jsx)("div",{className:"relative w-full aspect-video bg-black/90 flex items-center justify-center",children:(0,r.jsx)("div",{className:"h-8 w-8 border-2 border-white/20 border-t-white/60 rounded-full animate-spin"})}):(0,r.jsx)("div",{className:"relative w-full aspect-video bg-black/90 flex items-center justify-center",children:(0,r.jsxs)("div",{className:"flex flex-col items-center gap-2 text-white/40",children:[(0,r.jsx)(vk,{className:"h-8 w-8"}),(0,r.jsx)("span",{className:"text-xs",children:"No snapshot available"}),(0,r.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[n&&(0,r.jsxs)("button",{onClick:n,className:"inline-flex items-center gap-1.5 rounded-md border border-white/20 px-3 py-1.5 text-xs font-medium text-white/60 hover:text-white hover:border-white/40 transition-colors",children:[(0,r.jsx)(bl,{className:"h-3 w-3"}),"Retry"]}),(0,r.jsxs)("button",{onClick:s,className:"inline-flex items-center gap-1.5 rounded-md bg-primary/80 px-3 py-1.5 text-xs font-medium text-white hover:bg-primary transition-colors",children:[(0,r.jsx)(bn,{className:"h-3 w-3"}),"Play Live"]})]})]})})}function Sk({samples:e,sampleRate:t=16e3,height:s=96,className:n="",color:o="#3b82f6",bgColor:a="transparent"}){const i=(0,h.useRef)(null),l=(0,h.useRef)(null),u=(0,h.useCallback)(()=>{const f=i.current,p=l.current;if(!f||!p||!e||e.length===0)return;const g=p.clientWidth;if(g===0)return;const b=window.devicePixelRatio||1;f.width=g*b,f.height=s*b,f.style.width=`${g}px`,f.style.height=`${s}px`;const x=f.getContext("2d");if(!x)return;x.scale(b,b),a!=="transparent"?(x.fillStyle=a,x.fillRect(0,0,g,s)):x.clearRect(0,0,g,s);const v=e.length/g,w=s/2;x.fillStyle=o,x.globalAlpha=.7;for(let y=0;y<g;y++){const S=Math.floor(y*v),k=Math.min(Math.floor((y+1)*v),e.length);let C=0,N=0;for(let Q=S;Q<k;Q++){const ee=e[Q];ee<C&&(C=ee),ee>N&&(N=ee)}const E=w-N*w,R=w-C*w,A=Math.max(1,R-E);x.fillRect(y,E,1,A)}x.globalAlpha=1,x.strokeStyle=o,x.globalAlpha=.2,x.lineWidth=1,x.beginPath(),x.moveTo(0,w),x.lineTo(g,w),x.stroke(),x.globalAlpha=1},[e,s,o,a]);(0,h.useEffect)(()=>{u()},[u]),(0,h.useEffect)(()=>{const f=new ResizeObserver(()=>u()),p=l.current;return p&&f.observe(p),()=>f.disconnect()},[u]);const d=((e&&t?Math.round(e.length/t*1e3):0)/1e3).toFixed(1);return(0,r.jsxs)("div",{ref:l,className:`relative ${n}`,children:[(0,r.jsx)("canvas",{ref:i,className:"w-full rounded-md"}),e&&e.length>0&&(0,r.jsxs)("div",{className:"absolute bottom-1 right-2 text-[10px] text-foreground-subtle/60 font-mono",children:[d,"s · ",t/1e3,"kHz · ",e.length.toLocaleString()," samples"]})]})}function kk({currentDbfs:e,durationSec:t=30,maxSamples:s=120,height:n=64,className:o="",color:a="#10b981",clipColor:i="#ef4444",clipThreshold:l=-6,minDbfs:u=-96}){const d=(0,h.useRef)(null),f=(0,h.useRef)(null),[p,g]=(0,h.useState)([]);(0,h.useEffect)(()=>{e!==null&&g(v=>{const w=[...v,{dbfs:e,timestamp:Date.now()}];return w.length>s?w.slice(-s):w})},[e,s]);const b=(0,h.useCallback)(()=>{const v=d.current,w=f.current;if(!v||!w)return;const y=w.clientWidth;if(y===0)return;const S=window.devicePixelRatio||1;v.width=y*S,v.height=n*S,v.style.width=`${y}px`,v.style.height=`${n}px`;const k=v.getContext("2d");if(!k||(k.scale(S,S),k.clearRect(0,0,y,n),p.length===0))return;const C=p[p.length-1].timestamp,N=t*1e3,E=C-N,R=p.filter(ne=>ne.timestamp>=E);if(R.length===0)return;const A=Math.max(1,Math.floor(y/(t*2))),Q=Math.abs(u);for(const ne of R){const pe=ne.timestamp-E,ae=Math.floor(pe/N*y),ce=(Math.max(u,Math.min(0,ne.dbfs))-u)/Q,se=Math.max(1,ce*n);k.fillStyle=ne.dbfs>=l?i:a,k.globalAlpha=.8,k.fillRect(ae,n-se,A,se)}k.globalAlpha=1;const ee=n-(l-u)/Q*n;k.strokeStyle=i,k.globalAlpha=.25,k.lineWidth=1,k.setLineDash([4,4]),k.beginPath(),k.moveTo(0,ee),k.lineTo(y,ee),k.stroke(),k.setLineDash([]),k.globalAlpha=1},[p,t,n,a,i,l,u]);(0,h.useEffect)(()=>{b()},[b]),(0,h.useEffect)(()=>{const v=new ResizeObserver(()=>b()),w=f.current;return w&&v.observe(w),()=>v.disconnect()},[b]);const x=p.length>0?p[p.length-1].dbfs:null;return(0,r.jsxs)("div",{ref:f,className:`relative ${o}`,children:[(0,r.jsx)("canvas",{ref:d,className:"w-full rounded-md"}),(0,r.jsxs)("div",{className:"absolute top-1 left-2 text-[9px] text-foreground-subtle/50 font-mono",children:[t,"s"]}),x!==null&&(0,r.jsxs)("div",{className:"absolute bottom-1 right-2 text-[9px] text-foreground-subtle/50 font-mono",children:[x.toFixed(1)," dBFS · ",p.length," samples"]})]})}function jk(e){return e>=.8?"bg-emerald-500":e>=.5?"bg-amber-500":e>=.3?"bg-orange-500":"bg-zinc-500"}function Nk(e){return e>=.8?"text-emerald-400":e>=.5?"text-amber-400":e>=.3?"text-orange-400":"text-zinc-400"}function Ck({classifications:e,processing:t=!1,inferenceMs:s,maxItems:n=10,className:o=""}){const a=e.slice(0,n),i=a.length>0?a[0].score:1;return t?(0,r.jsx)("div",{className:`rounded-xl border border-border bg-surface p-4 text-center ${o}`,children:(0,r.jsx)("div",{className:"text-sm text-foreground-subtle animate-pulse",children:"Classifying audio..."})}):a.length===0?(0,r.jsx)("div",{className:`rounded-xl border border-border bg-surface p-4 text-center ${o}`,children:(0,r.jsx)("div",{className:"text-xs text-foreground-subtle",children:"No classifications yet"})}):(0,r.jsxs)("div",{className:`rounded-xl border border-border bg-surface overflow-hidden ${o}`,children:[(0,r.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center justify-between",children:[(0,r.jsx)("h3",{className:"text-xs font-medium text-foreground",children:"Audio Classifications"}),(0,r.jsxs)("div",{className:"flex items-center gap-3 text-[10px] text-foreground-subtle",children:[a.length<e.length&&(0,r.jsxs)("span",{children:["showing ",a.length," of ",e.length]}),s!==void 0&&(0,r.jsxs)("span",{className:"font-mono",children:[s.toFixed(1),"ms"]})]})]}),(0,r.jsx)("div",{className:"divide-y divide-border/50",children:a.map((l,u)=>{const d=i>0?l.score/i*100:0;return(0,r.jsxs)("div",{className:"px-3 py-1.5 flex items-center gap-3 hover:bg-surface-hover/30",children:[(0,r.jsx)("span",{className:"text-[10px] text-foreground-subtle w-5 text-right font-mono",children:u+1}),(0,r.jsx)("span",{className:"text-xs font-medium text-foreground min-w-[120px]",children:l.className}),(0,r.jsx)("div",{className:"flex-1 h-2 rounded-full bg-zinc-800 overflow-hidden",children:(0,r.jsx)("div",{className:`h-full rounded-full transition-all duration-300 ${jk(l.score)}`,style:{width:`${d}%`}})}),(0,r.jsxs)("span",{className:`text-xs font-mono font-semibold w-14 text-right ${Nk(l.score)}`,children:[(l.score*100).toFixed(1),"%"]})]},`${l.className}-${u}`)})})]})}function Mk({data:e,label:t="Response",className:s=""}){const[n,o]=(0,h.useState)(!1);if(!e)return null;const a=JSON.stringify(e,null,2);return(0,r.jsxs)("div",{className:`rounded-xl border border-border bg-surface overflow-hidden ${s}`,children:[(0,r.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center justify-between cursor-pointer select-none hover:bg-surface-hover/30",onClick:()=>o(i=>!i),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-[10px] text-foreground-subtle",children:n?"▼":"▶"}),(0,r.jsx)("h3",{className:"text-xs font-medium text-foreground",children:t})]}),(0,r.jsx)("span",{className:"text-[10px] text-foreground-subtle font-mono",children:a.length>1e3?`${(a.length/1024).toFixed(1)} KB`:`${a.length} bytes`})]}),n&&(0,r.jsx)("div",{className:"max-h-80 overflow-y-auto overflow-x-auto",children:(0,r.jsx)("pre",{className:"p-3 text-[10px] leading-4 font-mono text-foreground-subtle whitespace-pre",children:a})})]})}var Ek={Activity:ft,Eye:Or,AlertTriangle:or,PauseCircle:Hd,PowerOff:af};function Ak({phase:e,...t}){const s=Ek[us(e).icon];return(0,r.jsx)(s,{...t})}function Ct(e){const[t,s]=(0,h.useState)([]),n=(0,h.useCallback)(a=>{s(i=>{const l=[...i,a];return l.length>e?l.slice(-e):l})},[e]),o=(0,h.useCallback)(()=>{s([])},[]);return(0,h.useMemo)(()=>({entries:t,append:n,reset:o}),[t,n,o])}function xl(e){if(e===null)return"null";if(e===void 0)return"undefined";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e)}catch{return String(e)}}var vl={error:{icon:Lr,color:"text-red-400"},warn:{icon:or,color:"text-amber-400"},info:{icon:ef,color:"text-blue-400"},debug:{icon:Gd,color:"text-gray-500"}},yl={debug:0,info:1,warn:2,error:3},Pk=["all","debug","info","warn","error"],Rk=500;function Dk(e,t){return t?(yl[e]??0)>=(yl[t]??0):!0}function vn({agentId:e,addonId:t,deviceId:s,integrationId:n,requestId:o,level:a,maxHeight:i="max-h-96",showScope:l=!1,showFilters:u=!0,limit:d=100,liveBuffer:f,onClose:p,className:g}){const[b,x]=(0,h.useState)(""),[v,w]=(0,h.useState)(""),[y,S]=(0,h.useState)(a),k=e,C=t??(b||void 0),N=s??(v?Number(v):void 0),E=n,R=o,A=(0,h.useMemo)(()=>{const M={};return k&&(M.agentId=k),C&&(M.addonId=C),N!==void 0&&Number.isFinite(N)&&(M.deviceId=N),E&&(M.integrationId=E),R&&(M.requestId=R),Object.keys(M).length>0?M:void 0},[k,C,N,E,R]),Q=Ct(Rk),ee=f??Q,ne=ee.entries,[pe,ae]=(0,h.useState)(0),[ce,se]=(0,h.useState)(!1),[J,H]=(0,h.useState)(!1),[xe,de]=(0,h.useState)(new Set),[D,$]=(0,h.useState)(""),_=(0,h.useRef)(null),te=`${k??""}:${C??""}:${String(N??"")}:${E??""}:${R??""}`,U=(0,h.useRef)(te);(0,h.useEffect)(()=>{U.current!==te&&(U.current=te,ee.reset(),ae(0),de(new Set))},[te,ee]);const{data:V,isLoading:W}=m.logs.query.useQuery({...A?{tags:A}:{},limit:d},{staleTime:3e4});m.logs.subscribe.useSubscription({...A?{tags:A}:{}},{onData:M=>{ee.append(M)}});const F=(0,h.useRef)(ne.length);(0,h.useEffect)(()=>{const M=_.current;if(!M){F.current=ne.length;return}const T=F.current;if(F.current=ne.length,!(ne.length<=T)){if(ce&&M.scrollTop<=8)M.scrollTo({top:0});else if(!ce&&M.scrollTop>0){const Z=M.querySelector("tbody tr"),re=Z instanceof HTMLElement?Z.offsetHeight:24;M.scrollTop+=re*(ne.length-T)}}},[ne.length,ce]);const X=(0,h.useMemo)(()=>{const M=(V??[]).map(Y=>({timestamp:Y.timestamp,level:Y.level,message:Y.message,scope:Y.scope,tags:Y.tags,meta:Y.meta})),T=new Set,Z=[];for(const Y of[...ne].reverse()){const Se=`${Y.timestamp}|${Y.level}|${Y.scope??""}|${Y.message}`;T.has(Se)||(T.add(Se),Z.push(Y))}for(const Y of M){const Se=`${Y.timestamp}|${Y.level}|${Y.scope??""}|${Y.message}`;T.has(Se)||(T.add(Se),Z.push(Y))}const re=(pe>0?Z.filter(Y=>new Date(Y.timestamp).getTime()>pe):Z).filter(Y=>Dk(Y.level,y)),I=D.trim().toLowerCase();return I?re.filter(Y=>{if(Y.message.toLowerCase().includes(I)||Y.scope&&Y.scope.toLowerCase().includes(I))return!0;if(Y.tags){for(const Se of Object.values(Y.tags))if(Se!==void 0&&String(Se).toLowerCase().includes(I))return!0}if(Y.meta){for(const Se of Object.values(Y.meta))if(Se!=null&&xl(Se).toLowerCase().includes(I))return!0}return!1}):re},[V,ne,y,pe,D]),q=(0,h.useCallback)(()=>{const M=X.map(T=>{const Z=new Date(T.timestamp).toLocaleTimeString(),re=T.tags?" "+Object.entries(T.tags).filter(([,I])=>I).map(([I,Y])=>`${I}=${Y}`).join(" "):"";return`${Z} [${T.level.toUpperCase()}]${T.scope?` [${T.scope}]`:""}${re} ${T.message}`});navigator.clipboard.writeText(M.join(`
78
78
  `)).then(()=>{H(!0),setTimeout(()=>H(!1),1500)})},[X]),Re=m.logs.clear.useMutation(),De=(0,h.useCallback)(()=>{ae(Date.now()),ee.reset(),Re.mutate({...A?{tags:A}:{}})},[ee,Re,A]),K=(0,h.useCallback)(M=>{de(T=>{const Z=new Set(T);return Z.has(M)?Z.delete(M):Z.add(M),Z})},[]),[ue,ve]=(0,h.useState)(null),ye=(0,h.useCallback)((M,T)=>{const Z=new Date(M.timestamp).toISOString(),re=M.tags?" "+Object.entries(M.tags).filter(([,Se])=>Se).map(([Se,it])=>`${Se}=${it}`).join(" "):"",I=M.meta&&Object.keys(M.meta).length>0?` meta=${JSON.stringify(M.meta)}`:"",Y=`${Z} [${M.level.toUpperCase()}]${M.scope?` [${M.scope}]`:""}${re} ${M.message}${I}`;navigator.clipboard.writeText(Y).then(()=>{ve(T),setTimeout(()=>ve(Se=>Se===T?null:Se),1200)})},[]),L=(0,h.useCallback)(M=>`${M.timestamp}|${M.level}|${M.scope??""}|${M.message}`,[]);return(0,r.jsxs)("div",{className:j("h-full min-h-0 flex flex-col",g),onClick:M=>M.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,r.jsx)("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle font-medium",children:"Logs"}),k&&(0,r.jsx)(yn,{label:"agent",value:k}),C&&(0,r.jsx)(yn,{label:"addon",value:C}),N!==void 0&&(0,r.jsx)(yn,{label:"device",value:`#${N}`}),(0,r.jsx)("div",{className:"flex rounded border border-border overflow-hidden text-[9px]",children:Pk.map(M=>(0,r.jsxs)("button",{type:"button",onClick:()=>S(M==="all"?void 0:M),className:j("px-1.5 py-0.5 capitalize transition-colors",M==="all"&&!y||y===M?"bg-primary/10 text-primary":"text-foreground-subtle hover:bg-surface-hover",M!=="all"&&"border-l border-border"),children:[M,M!=="all"?"+":""]},M))}),(0,r.jsx)(wn,{icon:As,label:ce?"Auto":"Paused",active:!ce,onClick:()=>{se(M=>!M),!ce&&_.current&&_.current.scrollTo({top:0,behavior:"smooth"})}}),(0,r.jsx)(wn,{icon:pt,label:J?"Copied!":"Copy",onClick:q,disabled:X.length===0}),(0,r.jsx)(wn,{icon:at,label:"Clear",onClick:De}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("input",{type:"text",value:D,onChange:M=>$(M.target.value),placeholder:"Search…",className:"w-32 pl-1.5 pr-5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50"}),D&&(0,r.jsx)("button",{type:"button",onClick:()=>$(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",title:"Clear search",children:(0,r.jsx)(Pe,{className:"h-2.5 w-2.5"})})]}),ne.length>0&&(0,r.jsxs)("span",{className:"text-[9px] text-emerald-400 font-medium",children:["+",ne.length," live"]})]}),p&&(0,r.jsx)("button",{type:"button",onClick:p,className:"text-foreground-subtle hover:text-foreground",children:(0,r.jsx)(Pe,{className:"h-3.5 w-3.5"})})]}),u&&(!t||!s)&&(0,r.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1 border-b border-border/50 bg-surface/50 text-[10px]",children:[!t&&(0,r.jsxs)("label",{className:"flex items-center gap-1",children:[(0,r.jsx)("span",{className:"text-foreground-subtle",children:"Addon:"}),(0,r.jsx)("input",{type:"text",value:b,onChange:M=>x(M.target.value),placeholder:"all",className:"w-28 px-1.5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50"})]}),!s&&(0,r.jsxs)("label",{className:"flex items-center gap-1",children:[(0,r.jsx)("span",{className:"text-foreground-subtle",children:"Device:"}),(0,r.jsx)("input",{type:"text",inputMode:"numeric",value:v,onChange:M=>w(M.target.value),placeholder:"all",className:"w-16 px-1.5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50"})]})]}),(0,r.jsxs)("div",{ref:_,className:j("flex-1 min-h-0 overflow-auto font-mono text-[10px]",i),children:[W&&(0,r.jsxs)("div",{className:"flex items-center justify-center gap-2 py-6 text-foreground-subtle",children:[(0,r.jsx)(qe,{className:"h-3.5 w-3.5 animate-spin"}),"Loading logs..."]}),!W&&X.length===0&&(0,r.jsx)("div",{className:"py-4 text-center text-foreground-subtle",children:"No logs found"}),X.length>0&&(0,r.jsx)("table",{className:"w-full",children:(0,r.jsx)("tbody",{children:X.map(M=>{const T=vl[M.level]??vl.info,Z=T.icon,re=L(M),I=xe.has(re),Y=M.tags&&Object.keys(M.tags).length>0,Se=M.meta&&Object.keys(M.meta).length>0,it=Y||Se;return(0,r.jsxs)("tr",{className:j("hover:bg-surface-hover/30 border-b border-border/30",it&&"cursor-pointer"),onClick:it?()=>K(re):void 0,children:[(0,r.jsx)("td",{className:"px-2 py-1 text-foreground-subtle whitespace-nowrap align-top w-[70px]",children:new Date(M.timestamp).toLocaleTimeString()}),(0,r.jsx)("td",{className:j("px-1 py-1 align-top w-5",T.color),children:(0,r.jsx)(Z,{className:"h-3 w-3"})}),l&&(0,r.jsx)("td",{className:"px-2 py-1 text-foreground-subtle align-top truncate max-w-[120px]",title:M.scope,children:M.scope?.replace(/^addon:/,"")??""}),(0,r.jsx)("td",{className:"px-2 py-1 text-foreground break-all",children:(0,r.jsxs)("div",{className:"flex items-start gap-1",children:[it&&(I?(0,r.jsx)(St,{className:"h-3 w-3 text-foreground-subtle shrink-0 mt-0.5"}):(0,r.jsx)(mt,{className:"h-3 w-3 text-foreground-subtle shrink-0 mt-0.5"})),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[M.message,I&&it&&(0,r.jsxs)("div",{className:"mt-1 text-[9px] text-foreground-subtle bg-surface rounded px-2 py-1 space-y-0.5",children:[Se&&Object.entries(M.meta).filter(([,$e])=>$e!==void 0&&$e!=="").map(([$e,Ht])=>(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{className:"text-amber-400/80 font-medium",children:$e}),(0,r.jsx)("span",{className:"text-foreground-subtle",children:": "}),(0,r.jsx)("span",{className:"text-foreground break-all",children:xl(Ht)})]},`m-${$e}`)),Y&&Object.entries(M.tags).filter(([,$e])=>$e!==void 0).map(([$e,Ht])=>(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{className:"text-primary/70 font-medium",children:$e}),(0,r.jsx)("span",{className:"text-foreground-subtle",children:": "}),(0,r.jsx)("span",{className:"text-foreground",children:Ht})]},`t-${$e}`))]})]})]})}),(0,r.jsx)("td",{className:"px-1 py-1 align-top w-5",children:(0,r.jsx)(Ik,{copied:ue===re,onCopy:()=>ye(M,re)})})]},re)})})})]})]})}function Tk({position:e="bottom",className:t,...s}){return(0,r.jsx)("div",{className:j(e==="bottom"?"absolute bottom-0 left-0 right-0 z-10 border-t border-border bg-surface/95 backdrop-blur-sm":"absolute inset-x-2 bottom-2 z-10 rounded-lg border border-border bg-surface/95 backdrop-blur-sm shadow-xl",t),children:(0,r.jsx)(vn,{maxHeight:"max-h-48",...s})})}function yn({label:e,value:t}){return(0,r.jsxs)("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium",children:[e,": ",t]})}function Ik({copied:e,onCopy:t}){return(0,r.jsx)("button",{type:"button",title:"Copy this row",onClick:s=>{s.stopPropagation(),t()},className:j("rounded p-0.5 transition-colors",e?"text-emerald-400":"text-foreground-subtle/60 hover:text-foreground hover:bg-surface-hover"),children:e?(0,r.jsx)(sr,{className:"h-3 w-3"}):(0,r.jsx)(pt,{className:"h-3 w-3"})})}function wn({icon:e,label:t,onClick:s,disabled:n,active:o}){return(0,r.jsxs)("button",{type:"button",onClick:s,disabled:n,className:j("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",o?"border-amber-500/30 bg-amber-500/10 text-amber-400":"border-border text-foreground-subtle hover:text-foreground",n&&"opacity-40 cursor-not-allowed"),children:[(0,r.jsx)(e,{className:"h-2.5 w-2.5"}),t]})}function Lk(e,t,s,n){if(n!==void 0&&(e.source.deviceId??(e.source.type==="device"&&typeof e.source.id=="number"?e.source.id:void 0))!==n||s!==void 0&&(e.source.addonId??(e.source.type==="addon"&&typeof e.source.id=="string"?e.source.id:void 0))!==s)return!1;if(t!==void 0){const o=e.source.nodeId;if(!o||o!==t&&!o.startsWith(`${t}/`))return!1}return!0}var Ok={[z.EventCategory.AddonStarted]:{icon:Is,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Started"},[z.EventCategory.AddonInstalled]:{icon:Rs,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Installed"},[z.EventCategory.AddonRestarted]:{icon:Ls,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Restarted"},[z.EventCategory.AddonUpdated]:{icon:da,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Updated"},[z.EventCategory.AddonStopped]:{icon:la,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"Stopped"},[z.EventCategory.AddonUninstalled]:{icon:at,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"Uninstalled"},[z.EventCategory.AddonCrashed]:{icon:Lr,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Crashed"},[z.EventCategory.AddonError]:{icon:or,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Error"},[z.EventCategory.DetectionPhaseTransition]:{icon:ft,color:"bg-violet-500/15 text-violet-400 border-violet-500/30",label:"Phase"},[z.EventCategory.DetectionResult]:{icon:uf,color:"bg-purple-500/15 text-purple-400 border-purple-500/30",label:"Detection"},[z.EventCategory.DetectionEvent]:{icon:Or,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Event"},[z.EventCategory.DetectionCameraNative]:{icon:ua,color:"bg-cyan-500/15 text-cyan-400 border-cyan-500/30",label:"Camera AI"},[z.EventCategory.ProviderMotion]:{icon:ma,color:"bg-orange-500/15 text-orange-400 border-orange-500/30",label:"Motion"},[z.EventCategory.MotionOnMotionChanged]:{icon:ma,color:"bg-orange-500/15 text-orange-400 border-orange-500/30",label:"Motion"},[z.EventCategory.MotionAnalysis]:{icon:ft,color:"bg-orange-500/10 text-orange-300 border-orange-500/20",label:"Motion analysis"},[z.EventCategory.MotionZonesRaw]:{icon:ft,color:"bg-orange-500/10 text-orange-300 border-orange-500/20",label:"Motion zones"},[z.EventCategory.ProviderDetection]:{icon:ua,color:"bg-cyan-500/15 text-cyan-400 border-cyan-500/30",label:"Provider Det"},[z.EventCategory.PipelineAudioInferenceResult]:{icon:ra,color:"bg-pink-500/15 text-pink-400 border-pink-500/30",label:"Audio"},[z.EventCategory.AgentOnline]:{icon:Is,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Agent Online"},[z.EventCategory.AgentOffline]:{icon:la,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Agent Offline"},[z.EventCategory.DeviceRegistered]:{icon:Rs,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Registered"},[z.EventCategory.DeviceUnregistered]:{icon:at,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Unregistered"},[z.EventCategory.DeviceStateChanged]:{icon:ft,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"State"}};function Sn(e,t){const s=Ok[e]??{icon:Is,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:e.split(".").pop()??e};if(e===z.EventCategory.DeviceStateChanged&&t&&typeof t.capName=="string"){const n=t.capName;return{...s,label:n}}return s}var Ut=Object.freeze([...new Set(Object.values(z.EventCategory))].sort()),_k=Object.freeze([z.EventCategory.PipelineCameraMetricsSnapshot,z.EventCategory.PipelineRunnerLoadSnapshot,z.EventCategory.PipelineEngineMetricsSnapshot,z.EventCategory.PipelineInferenceResult,z.EventCategory.PipelineTrace,z.EventCategory.PipelineProgress,z.EventCategory.StreamBrokerMetricsSnapshot,z.EventCategory.MetricsNodeResourcesSnapshot,z.EventCategory.MetricsNodeProcessesSnapshot,z.EventCategory.ClusterTopologySnapshot,z.EventCategory.MotionAnalysis,z.EventCategory.MotionZonesRaw,z.EventCategory.DetectionResult,z.EventCategory.PipelineAudioInferenceResult,z.EventCategory.PlatformProbePhase,z.EventCategory.BenchmarkProgress,z.EventCategory.ModelDownloadProgress]),$k=new Set(_k),Gk=Object.freeze(Ut.filter(e=>!$k.has(e)));function Jr(e,t){if(e===z.EventCategory.DetectionPhaseTransition){const o=t.to,a=t.from,i=typeof t.source=="string"?t.source:null,l=typeof t.cooldownMs=="number"?t.cooldownMs:null,u=i?` (${i}${l?`, ${Math.round(l/1e3)}s cooldown`:""})`:"";return o==="active"?`Motion detected — phase active${u}`:o==="watching"?`Cooldown expired — phase watching${u}`:`Phase: ${String(a)} → ${String(o)}${u}`}if(e===z.EventCategory.DetectionResult){const o=t.frame?.detections??[];if(o.length===0)return null;const a=new Map;for(const i of o){const l=i,u=l.class??l.macroClass,d=typeof u=="string"?u:"";d&&a.set(d,(a.get(d)??0)+1)}return[...a.entries()].map(([i,l])=>l>1?`${i} ×${l}`:i).join(", ")}if(e===z.EventCategory.PipelineAudioInferenceResult){const o=t.frame?.detections??[];return o.length===0?null:o.map(a=>{const i=a,l=i.macroClass??i.class??i.label,u=typeof l=="string"?l:"",d=i.score;return d?`${u} (${Math.round(d*100)}%)`:u}).filter(Boolean).join(", ")}if(e===z.EventCategory.DetectionEvent){const o=t.label??t.class,a=t.score??t.confidence,i=[];return typeof o=="string"&&i.push(o),typeof a=="number"&&i.push(`${Math.round(a*100)}%`),i.length>0?i.join(" — "):null}if(e===z.EventCategory.ProviderMotion)return t.active===!0?"motion start":"motion stop";if(e===z.EventCategory.DeviceStateChanged){const o=t.slice;if(o&&typeof o=="object"){const a=Object.keys(o).filter(i=>i!=="lastFetchedAt"&&i!=="ts");if(a.length>0)return a.slice(0,4).join(", ")+(a.length>4?"…":"")}return null}if(e===z.EventCategory.MotionOnMotionChanged){const o=t.detected,a=typeof t.source=="string"?t.source:null,i=o===!0?"motion start":o===!1?"motion stop":"motion";return a?`${i} (${a})`:i}if(e===z.EventCategory.ProviderDetection||e===z.EventCategory.DetectionCameraNative){const o=t.detections??[];if(!Array.isArray(o)||o.length===0)return(typeof t.class=="string"?t.class:null)??null;const a=new Map;for(const i of o){const l=i,u=l.class??l.macroClass,d=typeof u=="string"?u:"";d&&a.set(d,(a.get(d)??0)+1)}return[...a.entries()].map(([i,l])=>l>1?`${i} ×${l}`:i).join(", ")}const s=t.addonId,n=t.error;return n||(s?`addon: ${s}`:null)}function Bk(e){const t=e.category;return t===z.EventCategory.DetectionResult||t===z.EventCategory.PipelineAudioInferenceResult?Jr(t,e.data)!==null:!0}var Fk=300;function kn({agentId:e,addonId:t,deviceId:s,defaultCategories:n,categories:o,category:a,maxHeight:i="max-h-96",limit:l=50,showCategoryFilter:u=!0,showFilters:d=!1,liveBuffer:f,onClose:p,className:g}){const b=(0,h.useMemo)(()=>n??o??Gk,[n,o]),x=(0,h.useMemo)(()=>[...b].sort().join(","),[b]),[v,w]=(0,h.useState)(()=>new Set(b)),y=(0,h.useRef)(x);(0,h.useEffect)(()=>{y.current!==x&&(y.current=x,w(new Set(b)))},[x,b]);const S=Ct(Fk),k=f??S,C=k.entries,[N,E]=(0,h.useState)(!0),[R,A]=(0,h.useState)(new Set),[Q,ee]=(0,h.useState)(""),[ne,pe]=(0,h.useState)(!1),[ae,ce]=(0,h.useState)(""),[se,J]=(0,h.useState)(0),H=(0,h.useRef)(null),xe=(0,h.useRef)(null),de=`${e??""}:${t??""}:${String(s??"")}:${a??""}`,D=(0,h.useRef)(de);(0,h.useEffect)(()=>{D.current!==de&&(D.current=de,k.reset(),A(new Set),J(0))},[de,k]),(0,h.useEffect)(()=>{if(!ne)return;const O=fe=>{const he=xe.current;he&&fe.target instanceof Node&&!he.contains(fe.target)&&pe(!1)};return document.addEventListener("mousedown",O),()=>{document.removeEventListener("mousedown",O)}},[ne]);const $=(0,h.useMemo)(()=>{const O={};return e&&(O.agentId=e),t&&(O.addonId=t),s!==void 0&&(O.deviceId=s),a&&(O.category=a),O},[e,t,s,a]),_=(0,h.useMemo)(()=>[...v].sort(),[v]),te=(0,h.useMemo)(()=>{const O={...$,limit:l};return _.length>0&&_.length<Ut.length&&(O.category=_),O},[$,l,(0,h.useMemo)(()=>_.join(","),[_]),_]),{data:U,isLoading:V}=m.systemEvents.getRecent.useQuery(te,{staleTime:3e4}),W=(0,h.useRef)(v);(0,h.useEffect)(()=>{W.current=v},[v]);const F=$;m.systemEvents.subscribe.useSubscription(F,{onData:O=>{const fe=O;fe?.id&&Lk(fe,e,t,s)&&W.current.has(fe.category)&&k.append(fe)}});const X=(0,h.useRef)(C.length);(0,h.useEffect)(()=>{const O=H.current;if(!O){X.current=C.length;return}const fe=X.current;if(X.current=C.length,!(C.length<=fe)){if(N&&O.scrollTop<=8)O.scrollTo({top:0});else if(!N&&O.scrollTop>0){const he=O.firstElementChild?.firstElementChild,be=he instanceof HTMLElement?he.offsetHeight:28;O.scrollTop+=be*(C.length-fe)}}},[C.length,N]);const q=(0,h.useMemo)(()=>{const O=new Map;for(const be of U??[])O.set(be.id,be);for(const be of C)O.set(be.id,be);let fe=[...O.values()].filter(be=>v.has(be.category)).filter(Bk);se>0&&(fe=fe.filter(be=>new Date(be.timestamp).getTime()>se));const he=Q.trim().toLowerCase();return he&&(fe=fe.filter(be=>{if(be.category.toLowerCase().includes(he)||Sn(be.category,be.data).label.toLowerCase().includes(he))return!0;const Mt=Jr(be.category,be.data);if(Mt&&Mt.toLowerCase().includes(he))return!0;try{if(new Date(be.timestamp).toLocaleTimeString().toLowerCase().includes(he))return!0}catch{}try{if(JSON.stringify(be.data).toLowerCase().includes(he)||JSON.stringify(be.source).toLowerCase().includes(he))return!0}catch{}return!1})),fe.sort((be,Mt)=>new Date(Mt.timestamp).getTime()-new Date(be.timestamp).getTime())},[U,C,v,Q,se]),Re=(0,h.useCallback)(O=>{A(fe=>{const he=new Set(fe);return he.has(O)?he.delete(O):he.add(O),he})},[]),De=(0,h.useCallback)(O=>{w(fe=>{const he=new Set(fe);return he.has(O)?he.delete(O):he.add(O),he})},[]),K=(0,h.useCallback)(()=>{w(new Set(b)),ee(""),J(0)},[b]),ue=(0,h.useCallback)(()=>{J(Date.now()),k.reset()},[k]),[ve,ye]=(0,h.useState)(!1),[L,M]=(0,h.useState)(null),T=(0,h.useCallback)(O=>{const fe=new Date(O.timestamp).toISOString(),he=Jr(O.category,O.data)??"",be=he?` ${he}`:"";return`${fe} [${O.category}]${be} data=${JSON.stringify(O.data)}`},[]),Z=(0,h.useCallback)(()=>{const O=q.map(T);navigator.clipboard.writeText(O.join(`
79
79
  `)).then(()=>{ye(!0),setTimeout(()=>ye(!1),1500)})},[q,T]),re=(0,h.useCallback)(O=>{navigator.clipboard.writeText(T(O)).then(()=>{M(O.id),setTimeout(()=>M(fe=>fe===O.id?null:fe),1200)})},[T]),I=(0,h.useCallback)(()=>{w(new Set(Ut))},[]),Y=(0,h.useCallback)(()=>{w(new Set)},[]),Se=(0,h.useMemo)(()=>{const O=ae.trim().toLowerCase();return O?Ut.filter(fe=>fe.toLowerCase().includes(O)):Ut},[ae]),it=Ut.length,$e=v.size,Ht=$e===it,yj=Ht?"All":`${$e}/${it}`;return(0,r.jsxs)("div",{className:j("h-full min-h-0 flex flex-col",g),onClick:O=>O.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,r.jsx)("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle font-medium",children:"Events"}),e&&(0,r.jsx)(es,{label:"agent",value:e}),t&&(0,r.jsx)(es,{label:"addon",value:t}),s!==void 0&&(0,r.jsx)(es,{label:"device",value:`#${s}`}),a&&(0,r.jsx)(es,{label:"category",value:a}),(0,r.jsxs)("button",{type:"button",onClick:()=>{E(O=>!O),!N&&H.current&&H.current.scrollTo({top:0,behavior:"smooth"})},className:j("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",N?"border-border text-foreground-subtle hover:text-foreground":"border-amber-500/30 bg-amber-500/10 text-amber-400"),children:[(0,r.jsx)(As,{className:"h-2.5 w-2.5"}),N?"Auto":"Paused"]}),u&&(0,r.jsxs)("div",{className:"relative",ref:xe,children:[(0,r.jsxs)("button",{type:"button",onClick:()=>pe(O=>!O),className:j("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",Ht?"border-border text-foreground-subtle hover:text-foreground":"border-violet-500/30 bg-violet-500/10 text-violet-400"),title:"Pick events to track",children:[(0,r.jsx)(Xo,{className:"h-2.5 w-2.5"}),"Filter (",yj,")"]}),ne&&(0,r.jsx)(zk,{search:ae,onSearchChange:ce,categories:Se,active:v,onToggle:De,onSelectAll:I,onSelectNone:Y,onResetDefaults:K})]}),(0,r.jsxs)("button",{type:"button",onClick:K,className:"inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors",title:"Reset filters to defaults",children:[(0,r.jsx)(aa,{className:"h-2.5 w-2.5"}),"Reset"]}),(0,r.jsxs)("button",{type:"button",onClick:ue,className:"inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors",title:"Clear visible entries",children:[(0,r.jsx)(at,{className:"h-2.5 w-2.5"}),"Clear"]}),(0,r.jsxs)("button",{type:"button",onClick:Z,disabled:q.length===0,className:j("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",ve?"border-emerald-500/30 bg-emerald-500/10 text-emerald-400":"border-border text-foreground-subtle hover:text-foreground",q.length===0&&"opacity-40 cursor-not-allowed"),title:"Copy all visible events",children:[(0,r.jsx)(pt,{className:"h-2.5 w-2.5"}),ve?"Copied!":"Copy"]}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("input",{type:"text",value:Q,onChange:O=>ee(O.target.value),placeholder:"Search…",className:"w-32 pl-1.5 pr-5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50"}),Q&&(0,r.jsx)("button",{type:"button",onClick:()=>ee(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",title:"Clear search",children:(0,r.jsx)(Pe,{className:"h-2.5 w-2.5"})})]}),C.length>0&&(0,r.jsxs)("span",{className:"text-[9px] text-emerald-400 font-medium",children:["+",C.length," live"]})]}),p&&(0,r.jsx)("button",{type:"button",onClick:p,className:"text-foreground-subtle hover:text-foreground",children:(0,r.jsx)(Pe,{className:"h-3.5 w-3.5"})})]}),(0,r.jsxs)("div",{ref:H,className:j("flex-1 min-h-0 overflow-auto text-[10px]",i),children:[V&&(0,r.jsxs)("div",{className:"flex items-center justify-center gap-2 py-6 text-foreground-subtle",children:[(0,r.jsx)(qe,{className:"h-3.5 w-3.5 animate-spin"}),"Loading events..."]}),!V&&q.length===0&&(0,r.jsx)("div",{className:"py-4 text-center text-foreground-subtle",children:"No events found"}),q.length>0&&(0,r.jsx)("div",{className:"divide-y divide-border/30",children:q.map(O=>{const fe=Sn(O.category,O.data),he=fe.icon,be=Jr(O.category,O.data),Mt=R.has(O.id);return(0,r.jsxs)("div",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-surface-hover/30 cursor-pointer",onClick:()=>Re(O.id),children:[(0,r.jsx)("span",{className:"text-foreground-subtle whitespace-nowrap w-[70px] shrink-0 pt-0.5",children:new Date(O.timestamp).toLocaleTimeString()}),(0,r.jsx)(Uk,{copied:L===O.id,onCopy:()=>re(O)}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[Mt?(0,r.jsx)(St,{className:"h-3 w-3 text-foreground-subtle shrink-0"}):(0,r.jsx)(mt,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),(0,r.jsxs)("span",{className:j("inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[9px] font-medium",fe.color),children:[(0,r.jsx)(he,{className:"h-2.5 w-2.5"}),fe.label]}),O.source.nodeId&&O.source.nodeId!=="hub"&&(0,r.jsx)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-foreground-subtle/10 text-foreground-subtle font-mono",children:O.source.nodeId})]}),be&&(0,r.jsx)("p",{className:"text-foreground-subtle text-[10px] mt-0.5 ml-5",children:be}),Mt&&(0,r.jsxs)("div",{className:"mt-1 ml-5 text-[9px] bg-surface rounded px-2 py-1.5 space-y-0.5 font-mono overflow-x-auto",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{className:"text-primary/70",children:"source"}),(0,r.jsx)("span",{className:"text-foreground-subtle",children:": "}),(0,r.jsx)("span",{className:"text-foreground",children:JSON.stringify(O.source)})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{className:"text-primary/70",children:"category"}),(0,r.jsx)("span",{className:"text-foreground-subtle",children:": "}),(0,r.jsx)("span",{className:"text-foreground",children:O.category})]}),Object.entries(O.data).map(([Ml,Mn])=>(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{className:"text-primary/70",children:Ml}),(0,r.jsx)("span",{className:"text-foreground-subtle",children:": "}),(0,r.jsx)("span",{className:"text-foreground break-all",children:typeof Mn=="object"?JSON.stringify(Mn):String(Mn)})]},Ml))]})]})]},O.id)})})]})]})}function zk({search:e,onSearchChange:t,categories:s,active:n,onToggle:o,onSelectAll:a,onSelectNone:i,onResetDefaults:l}){return(0,r.jsxs)("div",{className:"absolute z-20 top-full mt-1 left-0 w-72 max-h-80 rounded-md border border-border bg-surface shadow-lg flex flex-col",onClick:u=>u.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border/50",children:[(0,r.jsx)(nr,{className:"h-3 w-3 text-foreground-subtle"}),(0,r.jsx)("input",{type:"text",value:e,onChange:u=>t(u.target.value),placeholder:"Filter categories…",className:"flex-1 bg-transparent text-[10px] focus:outline-none text-foreground placeholder:text-foreground-subtle",autoFocus:!0}),e&&(0,r.jsx)("button",{type:"button",onClick:()=>t(""),className:"text-foreground-subtle hover:text-foreground",children:(0,r.jsx)(Pe,{className:"h-2.5 w-2.5"})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1 border-b border-border/50 text-[9px]",children:[(0,r.jsx)("button",{type:"button",onClick:a,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"All"}),(0,r.jsx)("button",{type:"button",onClick:i,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"None"}),(0,r.jsx)("button",{type:"button",onClick:l,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"Defaults"})]}),(0,r.jsxs)("div",{className:"overflow-y-auto flex-1",children:[s.length===0&&(0,r.jsx)("div",{className:"text-[10px] text-foreground-subtle italic px-2 py-3 text-center",children:"No matches"}),s.map(u=>{const d=n.has(u),f=Sn(u),p=f.icon;return(0,r.jsxs)("button",{type:"button",onClick:()=>o(u),className:"w-full flex items-center gap-2 px-2 py-1 text-left hover:bg-surface-hover/40 text-[10px]",children:[(0,r.jsx)("input",{type:"checkbox",readOnly:!0,checked:d,className:"accent-violet-500"}),(0,r.jsxs)("span",{className:j("inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[9px] font-medium shrink-0",f.color),children:[(0,r.jsx)(p,{className:"h-2.5 w-2.5"}),f.label]}),(0,r.jsx)("span",{className:"text-foreground-subtle font-mono truncate",children:u})]},u)})]})]})}function Qk({position:e="bottom",className:t,...s}){return(0,r.jsx)("div",{className:j(e==="bottom"?"absolute bottom-0 left-0 right-0 z-10 border-t border-border bg-surface/95 backdrop-blur-sm":"absolute inset-x-2 bottom-2 z-10 rounded-lg border border-border bg-surface/95 backdrop-blur-sm shadow-xl",t),children:(0,r.jsx)(kn,{maxHeight:"max-h-48",...s})})}function es({label:e,value:t}){return(0,r.jsxs)("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium",children:[e,": ",t]})}function Uk({copied:e,onCopy:t}){return(0,r.jsx)("button",{type:"button",title:"Copy this event",onClick:s=>{s.stopPropagation(),t()},className:j("rounded p-0.5 transition-colors mt-0.5",e?"text-emerald-400":"text-foreground-subtle/60 hover:text-foreground hover:bg-surface-hover"),children:e?(0,r.jsx)(sr,{className:"h-3 w-3"}):(0,r.jsx)(pt,{className:"h-3 w-3"})})}function Hk({deviceId:e,className:t="",onOpenChild:s}){const n=m.useUtils(),o=m.deviceDiscovery.listDiscovered.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),a=m.deviceDiscovery.getStatus.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),i=m.deviceDiscovery.refreshDiscovery.useMutation({onSuccess:()=>{n.deviceDiscovery.listDiscovered.invalidate({deviceId:e}),n.deviceDiscovery.getStatus.invalidate({deviceId:e})}}),l=m.deviceDiscovery.adoptDevice.useMutation({onSuccess:()=>{n.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),u=m.deviceDiscovery.releaseDevice.useMutation({onSuccess:()=>{n.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),[d,f]=(0,h.useState)(null),{available:p,adopted:g}=(0,h.useMemo)(()=>{const k=o.data??[],C=E=>typeof E.metadata.rtspChannel=="number"?E.metadata.rtspChannel:Number.POSITIVE_INFINITY,N=(E,R)=>{const A=C(E),Q=C(R);return A!==Q?A-Q:E.name.localeCompare(R.name)};return{available:k.filter(E=>!E.alreadyAdopted).sort(N),adopted:k.filter(E=>E.alreadyAdopted).sort(N)}},[o.data]),b=a.data,x=b?.lastError??null,v=b?.lastDiscoveryAt??null;async function w(){await i.mutateAsync({deviceId:e}).catch(()=>{})}async function y(k){f(k.childNativeId);try{await l.mutateAsync({deviceId:e,childNativeId:k.childNativeId})}finally{f(null)}}async function S(k){if(k.adoptedDeviceId!=null){f(k.childNativeId);try{await u.mutateAsync({deviceId:e,childDeviceId:k.adoptedDeviceId})}finally{f(null)}}}return(0,r.jsxs)("div",{className:`rounded-xl border border-border bg-surface ${t}`,children:[(0,r.jsxs)("div",{className:"flex items-start justify-between gap-2 border-b border-border px-3 py-2 sm:px-5 sm:py-3",children:[(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("h3",{className:"text-sm font-semibold text-foreground",children:"Discovered devices"}),(0,r.jsxs)("p",{className:"text-[11px] text-foreground-subtle",children:["Channels behind this hub. Click ",(0,r.jsx)("span",{className:"font-medium",children:"Add"})," to promote a channel to a managed device, or ",(0,r.jsx)("span",{className:"font-medium",children:"Remove"})," to detach."]})]}),(0,r.jsxs)("button",{type:"button",onClick:w,disabled:i.isPending,className:"inline-flex items-center gap-1.5 rounded-lg border border-border px-2 py-1.5 sm:px-3 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 shrink-0",children:[i.isPending?(0,r.jsx)(qe,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(Ls,{className:"h-3.5 w-3.5"}),(0,r.jsx)("span",{className:"hidden sm:inline",children:"Refresh"})]})]}),x?(0,r.jsxs)("div",{className:"flex items-start gap-2 border-b border-border bg-destructive/10 px-5 py-2 text-[11px] text-destructive",children:[(0,r.jsx)(or,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),(0,r.jsxs)("span",{children:["Last refresh failed: ",x]})]}):null,o.isLoading?(0,r.jsx)("div",{className:"flex items-center justify-center py-8 text-foreground-subtle",children:(0,r.jsx)(qe,{className:"h-5 w-5 animate-spin"})}):p.length===0&&g.length===0?(0,r.jsx)("div",{className:"px-5 py-8 text-center text-xs text-foreground-subtle",children:"No channels reported by the hub yet. Click Refresh to enumerate."}):(0,r.jsxs)(r.Fragment,{children:[p.length>0?(0,r.jsx)(wl,{title:"Available to add",count:p.length,tone:"primary",children:p.map(k=>(0,r.jsx)(Sl,{child:k,busy:d===k.childNativeId,onAdopt:y,onRelease:S,onOpenChild:s},k.childNativeId))}):null,g.length>0?(0,r.jsx)(wl,{title:"Already adopted",count:g.length,tone:"muted",children:g.map(k=>(0,r.jsx)(Sl,{child:k,busy:d===k.childNativeId,onAdopt:y,onRelease:S,onOpenChild:s},k.childNativeId))}):null]}),v!=null?(0,r.jsxs)("div",{className:"border-t border-border px-5 py-2 text-[10px] text-foreground-subtle",children:["Last refreshed ",new Date(v).toLocaleString()]}):null]})}function wl({title:e,count:t,tone:s,children:n}){return(0,r.jsxs)("div",{className:"border-t border-border",children:[(0,r.jsxs)("div",{className:`flex items-center justify-between border-b px-3 sm:px-5 py-1.5 text-[10px] uppercase tracking-wider ${s==="primary"?"bg-primary/5 text-primary border-primary/30":"bg-surface text-foreground-subtle border-border"}`,children:[(0,r.jsx)("span",{className:"font-semibold",children:e}),(0,r.jsx)("span",{className:"font-mono",children:t})]}),(0,r.jsx)("div",{className:"divide-y divide-border",children:n})]})}function Sl({child:e,busy:t,onAdopt:s,onRelease:n,onOpenChild:o}){return(0,r.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 px-3 py-2 sm:px-5 sm:py-3 sm:flex-nowrap sm:gap-3",children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[(0,r.jsx)(Vk,{status:e.status}),(0,r.jsx)("span",{className:"truncate text-sm font-medium text-foreground",children:e.name}),e.metadata.isDoorbell?(0,r.jsx)("span",{className:"rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle",children:"Doorbell"}):null,e.metadata.isBattery?(0,r.jsx)("span",{className:"rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle",children:"Battery"}):null,e.metadata.isMultifocal?(0,r.jsx)("span",{className:"rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle",children:"Multifocal"}):null]}),(0,r.jsxs)("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle",children:[typeof e.metadata.rtspChannel=="number"?(0,r.jsxs)("span",{children:["ch ",(0,r.jsx)("span",{className:"font-mono",children:e.metadata.rtspChannel})]}):null,e.metadata.model?(0,r.jsx)("span",{className:"truncate max-w-[160px]",children:e.metadata.model}):null,e.metadata.uid?(0,r.jsxs)("span",{className:"font-mono truncate max-w-[140px]",children:[e.metadata.uid.slice(0,12),"…"]}):null]})]}),e.alreadyAdopted?(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[o&&e.adoptedDeviceId!==null?(0,r.jsxs)("button",{type:"button",onClick:()=>o(e.adoptedDeviceId),className:"inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",title:"Open device detail",children:[(0,r.jsx)(Zo,{className:"h-3.5 w-3.5"}),"Open"]}):null,(0,r.jsxs)("button",{type:"button",onClick:()=>{n(e)},disabled:t,className:"inline-flex items-center gap-1.5 rounded-lg border border-destructive/30 px-3 py-1.5 text-xs text-destructive hover:bg-destructive/10 transition-colors disabled:opacity-50",children:[t?(0,r.jsx)(qe,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(at,{className:"h-3.5 w-3.5"}),"Remove"]})]}):(0,r.jsxs)("button",{type:"button",onClick:()=>{s(e)},disabled:t,className:"inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50",children:[t?(0,r.jsx)(qe,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(_r,{className:"h-3.5 w-3.5"}),"Add"]})]})}function Vk({status:e}){switch(e){case"online":return(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/40 bg-emerald-500/10 px-2 py-0.5 text-[10px] font-medium text-emerald-500",children:[(0,r.jsx)(fa,{className:"h-2.5 w-2.5"})," online"]});case"sleeping":return(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] font-medium text-amber-500",children:[(0,r.jsx)(Ds,{className:"h-2.5 w-2.5"})," sleeping"]});case"offline":return(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-destructive/40 bg-destructive/10 px-2 py-0.5 text-[10px] font-medium text-destructive",children:[(0,r.jsx)(Sf,{className:"h-2.5 w-2.5"})," offline"]});default:return(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-border bg-surface px-2 py-0.5 text-[10px] font-medium text-foreground-subtle",children:[(0,r.jsx)(Vo,{className:"h-2.5 w-2.5"})," unknown"]})}}function Wk(e,t){if(!e||typeof e!="object")return!1;const s=e;if(s.category!==z.EventCategory.DeviceStateChanged)return!1;const n=s.data;return!(!n||typeof n!="object"||n.deviceId!==t||typeof n.capName!="string"||!n.slice||typeof n.slice!="object")}function jn(e){if(!e||typeof e!="object")return null;const t=e,s=typeof t.id=="string"?t.id:null,n=typeof t.timestamp=="string"?t.timestamp:null,o=t.data;return!s||!n||!o||typeof o!="object"||typeof o.capName!="string"||!o.slice||typeof o.slice!="object"?null:{id:s,timestamp:n,capName:o.capName,slice:o.slice}}var qk=300,Kk=Object.freeze([...new Set(z.ALL_CAPABILITY_DEFINITIONS.filter(e=>e.scope==="device").map(e=>e.name))].sort());function kl({deviceId:e,defaultCaps:t,maxHeight:s="max-h-96",limit:n=50,liveBuffer:o,onClose:a,className:i}){const[l,u]=(0,h.useState)((0,h.useMemo)(()=>new Set(t??[]),[t])),[d,f]=(0,h.useState)(""),[p,g]=(0,h.useState)(!0),[b,x]=(0,h.useState)(new Set),[v,w]=(0,h.useState)(0),[y,S]=(0,h.useState)(!1),[k,C]=(0,h.useState)(""),N=(0,h.useRef)(null),E=Ct(qk),R=o??E,A=R.entries,Q=(0,h.useRef)(null),ee=(0,h.useRef)(e);(0,h.useEffect)(()=>{ee.current!==e&&(ee.current=e,R.reset(),x(new Set),w(0))},[e,R]);const ne=(0,h.useMemo)(()=>({deviceId:e,category:z.EventCategory.DeviceStateChanged,limit:n}),[e,n]),{data:pe,isLoading:ae}=m.systemEvents.getRecent.useQuery(ne,{staleTime:3e4}),ce=(0,h.useRef)(l);(0,h.useEffect)(()=>{ce.current=l},[l]),m.systemEvents.subscribe.useSubscription({deviceId:e,category:z.EventCategory.DeviceStateChanged},{onData:L=>{if(!Wk(L,e))return;const M=jn(L);if(!M)return;const T=ce.current;T.size>0&&!T.has(M.capName)||R.append(M)}});const se=(0,h.useRef)(A.length);(0,h.useEffect)(()=>{const L=Q.current;if(!L){se.current=A.length;return}const M=se.current;if(se.current=A.length,!(A.length<=M)){if(p&&L.scrollTop<=8)L.scrollTo({top:0});else if(!p&&L.scrollTop>0){const T=L.firstElementChild?.firstElementChild,Z=T instanceof HTMLElement?T.offsetHeight:28,re=A.length-M;L.scrollTop+=Z*re}}},[A.length,p]);const J=(0,h.useMemo)(()=>{const L=new Map;for(const Z of pe??[]){const re=jn(Z);re&&L.set(re.id,re)}for(const Z of A)L.set(Z.id,Z);let M=[...L.values()];v>0&&(M=M.filter(Z=>new Date(Z.timestamp).getTime()>v)),l.size>0&&(M=M.filter(Z=>l.has(Z.capName)));const T=d.trim().toLowerCase();return T&&(M=M.filter(Z=>{if(Z.capName.toLowerCase().includes(T))return!0;try{if(new Date(Z.timestamp).toLocaleTimeString().toLowerCase().includes(T))return!0}catch{}try{if(Object.entries(Z.slice).map(([re,I])=>`${re}=${Nn(I)}`).join(" · ").toLowerCase().includes(T))return!0}catch{}try{if(JSON.stringify(Z.slice).toLowerCase().includes(T))return!0}catch{}return!1})),M.sort((Z,re)=>new Date(re.timestamp).getTime()-new Date(Z.timestamp).getTime())},[pe,A,l,d,v]),H=(0,h.useMemo)(()=>{const L=new Set(Kk);for(const M of pe??[]){const T=jn(M);T&&L.add(T.capName)}for(const M of A)L.add(M.capName);return[...L].sort()},[pe,A]),xe=(0,h.useCallback)(L=>{x(M=>{const T=new Set(M);return T.has(L)?T.delete(L):T.add(L),T})},[]),de=(0,h.useCallback)(L=>{u(M=>{const T=new Set(M);return T.has(L)?T.delete(L):T.add(L),T})},[]),D=(0,h.useCallback)(()=>{u(new Set(t??[])),f("")},[t]),$=(0,h.useCallback)(()=>{w(Date.now()),R.reset()},[R]),[_,te]=(0,h.useState)(!1),[U,V]=(0,h.useState)(null),W=(0,h.useCallback)(L=>`${new Date(L.timestamp).toISOString()} [${L.capName}] slice=${JSON.stringify(L.slice)}`,[]),F=(0,h.useCallback)(()=>{const L=J.map(W);navigator.clipboard.writeText(L.join(`