@camstack/addon-admin-ui 0.1.39 → 0.1.46

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 (47) hide show
  1. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs-Cv6qLu_-.js → __mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs-CRKSbdgN.js} +1 -1
  2. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs_commonjs-proxy-CChEG9e0.js → __mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs_commonjs-proxy-BGPfTw3V.js} +1 -1
  3. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs-C1BmHlGM.js → __mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs-jPpiOa0I.js} +1 -1
  4. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs_commonjs-proxy-Bxv_3KWz.js → __mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs_commonjs-proxy-DYNYuSL7.js} +1 -1
  5. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs-DC63qZbr.js → __mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs-ij0ODm-n.js} +1 -1
  6. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs_commonjs-proxy-D2C49VyZ.js → __mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs_commonjs-proxy-C4Ko8zXp.js} +1 -1
  7. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs-D3WbXy3O.js → __mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs-Cf5gSqc_.js} +1 -1
  8. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-Csg6EbPB.js → __mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-CYaX3FDr.js} +1 -1
  9. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs-CUc0oFNo.js → __mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs-rHwdrynu.js} +1 -1
  10. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs_commonjs-proxy-vh0hhA5d.js → __mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs_commonjs-proxy-DRDS6j-Y.js} +1 -1
  11. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.mjs-CpGtTxci.js → __mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.mjs-cUuqcEcL.js} +2 -2
  12. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.mjs_commonjs-proxy-RUDPE9aM.js → __mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.mjs_commonjs-proxy-CzMP41OH.js} +1 -1
  13. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-TUicghXo.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DNAkeUTZ.js} +1 -1
  14. package/dist/assets/{devices-GLp7me2a.js → devices-DaqavVOg.js} +1 -1
  15. package/dist/assets/{hostInit-94fVe_XD.js → hostInit-ByQycOVJ.js} +1 -1
  16. package/dist/assets/index-B6kubsZI.js +151 -0
  17. package/dist/assets/index-BI1a6Whs.js +1 -0
  18. package/dist/assets/index-BVNg3Krt.js +1185 -0
  19. package/dist/assets/{index-TiJwCuZx.js → index-BbwPCEeT.js} +1 -1
  20. package/dist/assets/{index-D6khiudP.js → index-BpC2rqYA.js} +1 -1
  21. package/dist/assets/index-CukoHCyD.js +1 -0
  22. package/dist/assets/{index-JJ5NLHxC.js → index-Cyva9RmE.js} +1 -1
  23. package/dist/assets/index-DLnW8nGB.css +1 -0
  24. package/dist/assets/index-DNydUTOB.js +1 -0
  25. package/dist/assets/{index-CwF7Dxf8.js → index-DVLRgczW.js} +1 -1
  26. package/dist/assets/index-PXbclFuZ.js +87 -0
  27. package/dist/assets/index-QqQmcu5i.js +1 -0
  28. package/dist/assets/method-access-map-DjDdPRYC.js +1 -0
  29. package/dist/assets/{remoteEntry-JLETvOnh.js → remoteEntry-iRKuVHUX.js} +1 -1
  30. package/dist/assets/{schemas-BEt-CulV.js → schemas-BdJePqbR.js} +5 -5
  31. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DM77_4pA.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-QVZxTxLo.js} +2 -2
  32. package/dist/index.html +152 -9
  33. package/dist/mf-entry-bootstrap-0.js +2 -2
  34. package/dist/server/addon.js +435 -52
  35. package/dist/server/addon.js.map +1 -1
  36. package/dist/sw.js +1 -1
  37. package/package.json +1 -1
  38. package/dist/assets/index-BM6aK9lG.js +0 -1150
  39. package/dist/assets/index-ByRJWRUP.js +0 -1
  40. package/dist/assets/index-COoei6lw.css +0 -1
  41. package/dist/assets/index-CtHpLu0L.js +0 -1
  42. package/dist/assets/index-DNY_otk4.js +0 -151
  43. package/dist/assets/index-DQFO9ZU6.js +0 -1
  44. package/dist/assets/index-WrAHDGEr.js +0 -87
  45. package/dist/assets/index-b0D9qthW.js +0 -1
  46. package/dist/assets/method-access-map-DLEhlu0x.js +0 -1
  47. package/dist/registerSW.js +0 -1
@@ -0,0 +1,1185 @@
1
+ import"./virtualExposes-_ivNhQLP.js";import{d as Pr}from"./virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-QVZxTxLo.js";import{c as r,a as Gm,d as u,e as me,g as YN}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_1_jsx_mf_2_runtime__loadShare__.mjs-C_6K4VBY.js";import{b as qe,e as I,h as U,c as J,f as q,d as Ne,a as Wm,n as Ke,k as _e,i as ne,m as er,o as Ra,g as Oa,R as Ze,p as je,q as Lc,r as ZN,s as XN,t as _r,j as JN,u as e2,v as t2,w as n2}from"./__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs-ij0ODm-n.js";import{a as Km,b as Qr}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs-Cf5gSqc_.js";import{a as Ym,b as Zm}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs-rHwdrynu.js";import{_ as Xm,m as cr,n as Me,o as Jm,p as eh,h as Rt,j as r2}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs-CRKSbdgN.js";import{_ as th,c as nh,s as rh,n as o2,B as s2,F as a2}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_client__loadShare__.mjs-DIkg6-MH.js";import{_ as oh,a as i2}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs-jPpiOa0I.js";import{_ as sh,a as Gn,b as l2,c as Mi,d as $r,e as sa,f as ah,g as ih,h as c2}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.mjs-cUuqcEcL.js";import{_ as lh}from"./__mfe_internal__admin_ui_host__loadShare__konva__loadShare__.mjs-g85Oidc0.js";import{c as d2,D as ch,E as u2,a as gt,M as p2,W as Al,b as Qs,N as f2,d as dh,S as m2,e as Gs}from"./index-BI1a6Whs.js";import{S as El,c as uh}from"./devices-DaqavVOg.js";import{o as h2,b as Ai,a as Tc,s as Wn,n as zu}from"./schemas-BdJePqbR.js";import{E as Ce,A as g2,K as b2}from"./method-access-map-DjDdPRYC.js";import{s as x2}from"./index-Cyva9RmE.js";import{a as Fu,C as ph,S as ju,s as y2}from"./index-DNydUTOB.js";import{r as fh}from"./__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs_commonjs-proxy-C4Ko8zXp.js";import{_ as v2}from"./preload-helper-BlTxHScW.js";import"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-CYaX3FDr.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))o(s);new MutationObserver(s=>{for(const a of s)if(a.type==="childList")for(const i of a.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&o(i)}).observe(document,{childList:!0,subtree:!0});function n(s){const a={};return s.integrity&&(a.integrity=s.integrity),s.referrerPolicy&&(a.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?a.credentials="include":s.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function o(s){if(s.ep)return;s.ep=!0;const a=n(s);fetch(s.href,a)}})();const mh={frigate:"#3b82f6",scrypted:"#a855f7",reolink:"#06b6d4",homeAssistant:"#22d3ee",rtsp:"#78716c"},hh={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:mh},gh={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:mh},Il={colors:{dark:hh,light:gh},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 bh(e,t){const n={...e};for(const o in t){const s=t[o],a=e[o];s!==void 0&&typeof s=="object"&&s!==null&&!Array.isArray(s)&&typeof a=="object"&&a!==null?n[o]=bh(a,s):s!==void 0&&(n[o]=s)}return n}function w2(e){return e?bh(structuredClone(Il),e):structuredClone(Il)}function xh(e){return e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function N2(e){return`--color-${xh(e)}`}function Hu(e){const t=[];for(const[n,o]of Object.entries(e))n!=="provider"&&t.push(` ${N2(n)}: ${o};`);return t.join(`
2
+ `)}function k2(e){const t=[];for(const[n,o]of Object.entries(e))t.push(` --color-provider-${xh(n)}: ${o};`);return t.join(`
3
+ `)}function S2(e){const t=[];for(const[n,o]of Object.entries(e))t.push(` --spacing-${n}: ${o}px;`);return t.join(`
4
+ `)}function C2(e){const t=[];for(const[n,o]of Object.entries(e))t.push(` --radius-${n}: ${o}px;`);return t.join(`
5
+ `)}function M2(e){const t=Hu(e.colors.dark),n=Hu(e.colors.light),o=k2(e.colors.dark.provider),s=S2(e.spacing),a=C2(e.radius);return`@theme {
6
+ ${o}
7
+ ${s}
8
+ ${a}
9
+ }
10
+
11
+ .dark {
12
+ ${t}
13
+ }
14
+
15
+ .light {
16
+ ${n}
17
+ }
18
+
19
+ @media (prefers-color-scheme: dark) {
20
+ :root {
21
+ ${t.replace(/^ {2}/gm," ")}
22
+ }
23
+ }
24
+
25
+ @media (prefers-color-scheme: light) {
26
+ :root {
27
+ ${n.replace(/^ {2}/gm," ")}
28
+ }
29
+ }
30
+ `}const yh=qe(null),Ei=["dark","light","system"];function vh(){return typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function A2(e,t){if(typeof window>"u")return t;const n=localStorage.getItem(e);return n==="dark"||n==="light"||n==="system"?n:t}function Vu(e){return e==="system"?vh():e}function aa({children:e,defaultMode:t="system",storageKey:n="camstack-theme-mode"}){const[o,s]=I(()=>A2(n,t)),[a,i]=I(()=>Vu(o)),l=U(p=>{s(p),i(Vu(p)),typeof window<"u"&&localStorage.setItem(n,p)},[n]),c=U(()=>{const f=(Ei.indexOf(o)+1)%Ei.length;l(Ei[f]??"dark")},[o,l]);J(()=>{if(typeof document>"u")return;const p=document.documentElement;p.classList.remove("dark","light"),p.classList.add(a)},[o,a]),J(()=>{if(typeof window>"u"||o!=="system")return;const p=window.matchMedia("(prefers-color-scheme: dark)"),f=()=>{i(vh())};return p.addEventListener("change",f),()=>p.removeEventListener("change",f)},[o]);const d=q(()=>({mode:o,resolvedMode:a,setMode:l,toggleMode:c}),[o,a,l,c]);return r(yh.Provider,{value:d,children:e})}function Yo(){const e=Ne(yh);if(!e)throw new Error("useThemeMode must be used within a ThemeProvider");return e}function wh(e){var t,n,o="";if(typeof e=="string"||typeof e=="number")o+=e;else if(typeof e=="object")if(Array.isArray(e)){var s=e.length;for(t=0;t<s;t++)e[t]&&(n=wh(e[t]))&&(o&&(o+=" "),o+=n)}else for(n in e)e[n]&&(o&&(o+=" "),o+=n);return o}function Nh(){for(var e,t,n=0,o="",s=arguments.length;n<s;n++)(e=arguments[n])&&(t=wh(e))&&(o&&(o+=" "),o+=t);return o}const E2=(e,t)=>{const n=new Array(e.length+t.length);for(let o=0;o<e.length;o++)n[o]=e[o];for(let o=0;o<t.length;o++)n[e.length+o]=t[o];return n},I2=(e,t)=>({classGroupId:e,validator:t}),kh=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),ia="-",Uu=[],P2="arbitrary..",_2=e=>{const t=D2(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:o}=e;return{getClassGroupId:i=>{if(i.startsWith("[")&&i.endsWith("]"))return $2(i);const l=i.split(ia),c=l[0]===""&&l.length>1?1:0;return Sh(l,c,t)},getConflictingClassGroupIds:(i,l)=>{if(l){const c=o[i],d=n[i];return c?d?E2(d,c):c:d||Uu}return n[i]||Uu}}},Sh=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;const s=e[t],a=n.nextPart.get(s);if(a){const d=Sh(e,t+1,a);if(d)return d}const i=n.validators;if(i===null)return;const l=t===0?e.join(ia):e.slice(t).join(ia),c=i.length;for(let d=0;d<c;d++){const p=i[d];if(p.validator(l))return p.classGroupId}},$2=e=>e.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const t=e.slice(1,-1),n=t.indexOf(":"),o=t.slice(0,n);return o?P2+o:void 0})(),D2=e=>{const{theme:t,classGroups:n}=e;return L2(n,t)},L2=(e,t)=>{const n=kh();for(const o in e){const s=e[o];Rc(s,n,o,t)}return n},Rc=(e,t,n,o)=>{const s=e.length;for(let a=0;a<s;a++){const i=e[a];T2(i,t,n,o)}},T2=(e,t,n,o)=>{if(typeof e=="string"){R2(e,t,n);return}if(typeof e=="function"){O2(e,t,n,o);return}B2(e,t,n,o)},R2=(e,t,n)=>{const o=e===""?t:Ch(t,e);o.classGroupId=n},O2=(e,t,n,o)=>{if(z2(e)){Rc(e(o),t,n,o);return}t.validators===null&&(t.validators=[]),t.validators.push(I2(n,e))},B2=(e,t,n,o)=>{const s=Object.entries(e),a=s.length;for(let i=0;i<a;i++){const[l,c]=s[i];Rc(c,Ch(t,l),n,o)}},Ch=(e,t)=>{let n=e;const o=t.split(ia),s=o.length;for(let a=0;a<s;a++){const i=o[a];let l=n.nextPart.get(i);l||(l=kh(),n.nextPart.set(i,l)),n=l}return n},z2=e=>"isThemeGetter"in e&&e.isThemeGetter===!0,F2=e=>{if(e<1)return{get:()=>{},set:()=>{}};let t=0,n=Object.create(null),o=Object.create(null);const s=(a,i)=>{n[a]=i,t++,t>e&&(t=0,o=n,n=Object.create(null))};return{get(a){let i=n[a];if(i!==void 0)return i;if((i=o[a])!==void 0)return s(a,i),i},set(a,i){a in n?n[a]=i:s(a,i)}}},Pl="!",qu=":",j2=[],Qu=(e,t,n,o,s)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:o,isExternal:s}),H2=e=>{const{prefix:t,experimentalParseClassName:n}=e;let o=s=>{const a=[];let i=0,l=0,c=0,d;const p=s.length;for(let x=0;x<p;x++){const b=s[x];if(i===0&&l===0){if(b===qu){a.push(s.slice(c,x)),c=x+1;continue}if(b==="/"){d=x;continue}}b==="["?i++:b==="]"?i--:b==="("?l++:b===")"&&l--}const f=a.length===0?s:s.slice(c);let m=f,h=!1;f.endsWith(Pl)?(m=f.slice(0,-1),h=!0):f.startsWith(Pl)&&(m=f.slice(1),h=!0);const g=d&&d>c?d-c:void 0;return Qu(a,h,m,g)};if(t){const s=t+qu,a=o;o=i=>i.startsWith(s)?a(i.slice(s.length)):Qu(j2,!1,i,void 0,!0)}if(n){const s=o;o=a=>n({className:a,parseClassName:s})}return o},V2=e=>{const t=new Map;return e.orderSensitiveModifiers.forEach((n,o)=>{t.set(n,1e6+o)}),n=>{const o=[];let s=[];for(let a=0;a<n.length;a++){const i=n[a],l=i[0]==="[",c=t.has(i);l||c?(s.length>0&&(s.sort(),o.push(...s),s=[]),o.push(i)):s.push(i)}return s.length>0&&(s.sort(),o.push(...s)),o}},U2=e=>({cache:F2(e.cacheSize),parseClassName:H2(e),sortModifiers:V2(e),..._2(e)}),q2=/\s+/,Q2=(e,t)=>{const{parseClassName:n,getClassGroupId:o,getConflictingClassGroupIds:s,sortModifiers:a}=t,i=[],l=e.trim().split(q2);let c="";for(let d=l.length-1;d>=0;d-=1){const p=l[d],{isExternal:f,modifiers:m,hasImportantModifier:h,baseClassName:g,maybePostfixModifierPosition:x}=n(p);if(f){c=p+(c.length>0?" "+c:c);continue}let b=!!x,y=o(b?g.substring(0,x):g);if(!y){if(!b){c=p+(c.length>0?" "+c:c);continue}if(y=o(g),!y){c=p+(c.length>0?" "+c:c);continue}b=!1}const w=m.length===0?"":m.length===1?m[0]:a(m).join(":"),v=h?w+Pl:w,N=v+y;if(i.indexOf(N)>-1)continue;i.push(N);const k=s(y,b);for(let C=0;C<k.length;++C){const D=k[C];i.push(v+D)}c=p+(c.length>0?" "+c:c)}return c},G2=(...e)=>{let t=0,n,o,s="";for(;t<e.length;)(n=e[t++])&&(o=Mh(n))&&(s&&(s+=" "),s+=o);return s},Mh=e=>{if(typeof e=="string")return e;let t,n="";for(let o=0;o<e.length;o++)e[o]&&(t=Mh(e[o]))&&(n&&(n+=" "),n+=t);return n},W2=(e,...t)=>{let n,o,s,a;const i=c=>{const d=t.reduce((p,f)=>f(p),e());return n=U2(d),o=n.cache.get,s=n.cache.set,a=l,l(c)},l=c=>{const d=o(c);if(d)return d;const p=Q2(c,n);return s(c,p),p};return a=i,(...c)=>a(G2(...c))},K2=[],nt=e=>{const t=n=>n[e]||K2;return t.isThemeGetter=!0,t},Ah=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,Eh=/^\((?:(\w[\w-]*):)?(.+)\)$/i,Y2=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,Z2=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,X2=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,J2=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,ek=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,tk=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Cn=e=>Y2.test(e),$e=e=>!!e&&!Number.isNaN(Number(e)),Mn=e=>!!e&&Number.isInteger(Number(e)),Ii=e=>e.endsWith("%")&&$e(e.slice(0,-1)),ln=e=>Z2.test(e),Ih=()=>!0,nk=e=>X2.test(e)&&!J2.test(e),Oc=()=>!1,rk=e=>ek.test(e),ok=e=>tk.test(e),sk=e=>!ve(e)&&!we(e),ak=e=>Bn(e,$h,Oc),ve=e=>Ah.test(e),Vn=e=>Bn(e,Dh,nk),Gu=e=>Bn(e,mk,$e),ik=e=>Bn(e,Th,Ih),lk=e=>Bn(e,Lh,Oc),Wu=e=>Bn(e,Ph,Oc),ck=e=>Bn(e,_h,ok),ms=e=>Bn(e,Rh,rk),we=e=>Eh.test(e),co=e=>dr(e,Dh),dk=e=>dr(e,Lh),Ku=e=>dr(e,Ph),uk=e=>dr(e,$h),pk=e=>dr(e,_h),hs=e=>dr(e,Rh,!0),fk=e=>dr(e,Th,!0),Bn=(e,t,n)=>{const o=Ah.exec(e);return o?o[1]?t(o[1]):n(o[2]):!1},dr=(e,t,n=!1)=>{const o=Eh.exec(e);return o?o[1]?t(o[1]):n:!1},Ph=e=>e==="position"||e==="percentage",_h=e=>e==="image"||e==="url",$h=e=>e==="length"||e==="size"||e==="bg-size",Dh=e=>e==="length",mk=e=>e==="number",Lh=e=>e==="family-name",Th=e=>e==="number"||e==="weight",Rh=e=>e==="shadow",hk=()=>{const e=nt("color"),t=nt("font"),n=nt("text"),o=nt("font-weight"),s=nt("tracking"),a=nt("leading"),i=nt("breakpoint"),l=nt("container"),c=nt("spacing"),d=nt("radius"),p=nt("shadow"),f=nt("inset-shadow"),m=nt("text-shadow"),h=nt("drop-shadow"),g=nt("blur"),x=nt("perspective"),b=nt("aspect"),y=nt("ease"),w=nt("animate"),v=()=>["auto","avoid","all","avoid-page","page","left","right","column"],N=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],k=()=>[...N(),we,ve],C=()=>["auto","hidden","clip","visible","scroll"],D=()=>["auto","contain","none"],M=()=>[we,ve,c],_=()=>[Cn,"full","auto",...M()],$=()=>[Mn,"none","subgrid",we,ve],E=()=>["auto",{span:["full",Mn,we,ve]},Mn,we,ve],R=()=>[Mn,"auto",we,ve],O=()=>["auto","min","max","fr",we,ve],A=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],P=()=>["start","end","center","stretch","center-safe","end-safe"],L=()=>["auto",...M()],B=()=>[Cn,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...M()],z=()=>[Cn,"screen","full","dvw","lvw","svw","min","max","fit",...M()],T=()=>[Cn,"screen","full","lh","dvh","lvh","svh","min","max","fit",...M()],F=()=>[e,we,ve],H=()=>[...N(),Ku,Wu,{position:[we,ve]}],j=()=>["no-repeat",{repeat:["","x","y","space","round"]}],Q=()=>["auto","cover","contain",uk,ak,{size:[we,ve]}],G=()=>[Ii,co,Vn],Z=()=>["","none","full",d,we,ve],V=()=>["",$e,co,Vn],K=()=>["solid","dashed","dotted","double"],X=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],te=()=>[$e,Ii,Ku,Wu],he=()=>["","none",g,we,ve],xe=()=>["none",$e,we,ve],ee=()=>["none",$e,we,ve],re=()=>[$e,we,ve],de=()=>[Cn,"full",...M()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[ln],breakpoint:[ln],color:[Ih],container:[ln],"drop-shadow":[ln],ease:["in","out","in-out"],font:[sk],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[ln],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[ln],shadow:[ln],spacing:["px",$e],text:[ln],"text-shadow":[ln],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",Cn,ve,we,b]}],container:["container"],columns:[{columns:[$e,ve,we,l]}],"break-after":[{"break-after":v()}],"break-before":[{"break-before":v()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],sr:["sr-only","not-sr-only"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:k()}],overflow:[{overflow:C()}],"overflow-x":[{"overflow-x":C()}],"overflow-y":[{"overflow-y":C()}],overscroll:[{overscroll:D()}],"overscroll-x":[{"overscroll-x":D()}],"overscroll-y":[{"overscroll-y":D()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:_()}],"inset-x":[{"inset-x":_()}],"inset-y":[{"inset-y":_()}],start:[{"inset-s":_(),start:_()}],end:[{"inset-e":_(),end:_()}],"inset-bs":[{"inset-bs":_()}],"inset-be":[{"inset-be":_()}],top:[{top:_()}],right:[{right:_()}],bottom:[{bottom:_()}],left:[{left:_()}],visibility:["visible","invisible","collapse"],z:[{z:[Mn,"auto",we,ve]}],basis:[{basis:[Cn,"full","auto",l,...M()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[$e,Cn,"auto","initial","none",ve]}],grow:[{grow:["",$e,we,ve]}],shrink:[{shrink:["",$e,we,ve]}],order:[{order:[Mn,"first","last","none",we,ve]}],"grid-cols":[{"grid-cols":$()}],"col-start-end":[{col:E()}],"col-start":[{"col-start":R()}],"col-end":[{"col-end":R()}],"grid-rows":[{"grid-rows":$()}],"row-start-end":[{row:E()}],"row-start":[{"row-start":R()}],"row-end":[{"row-end":R()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":O()}],"auto-rows":[{"auto-rows":O()}],gap:[{gap:M()}],"gap-x":[{"gap-x":M()}],"gap-y":[{"gap-y":M()}],"justify-content":[{justify:[...A(),"normal"]}],"justify-items":[{"justify-items":[...P(),"normal"]}],"justify-self":[{"justify-self":["auto",...P()]}],"align-content":[{content:["normal",...A()]}],"align-items":[{items:[...P(),{baseline:["","last"]}]}],"align-self":[{self:["auto",...P(),{baseline:["","last"]}]}],"place-content":[{"place-content":A()}],"place-items":[{"place-items":[...P(),"baseline"]}],"place-self":[{"place-self":["auto",...P()]}],p:[{p:M()}],px:[{px:M()}],py:[{py:M()}],ps:[{ps:M()}],pe:[{pe:M()}],pbs:[{pbs:M()}],pbe:[{pbe:M()}],pt:[{pt:M()}],pr:[{pr:M()}],pb:[{pb:M()}],pl:[{pl:M()}],m:[{m:L()}],mx:[{mx:L()}],my:[{my:L()}],ms:[{ms:L()}],me:[{me:L()}],mbs:[{mbs:L()}],mbe:[{mbe:L()}],mt:[{mt:L()}],mr:[{mr:L()}],mb:[{mb:L()}],ml:[{ml:L()}],"space-x":[{"space-x":M()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":M()}],"space-y-reverse":["space-y-reverse"],size:[{size:B()}],"inline-size":[{inline:["auto",...z()]}],"min-inline-size":[{"min-inline":["auto",...z()]}],"max-inline-size":[{"max-inline":["none",...z()]}],"block-size":[{block:["auto",...T()]}],"min-block-size":[{"min-block":["auto",...T()]}],"max-block-size":[{"max-block":["none",...T()]}],w:[{w:[l,"screen",...B()]}],"min-w":[{"min-w":[l,"screen","none",...B()]}],"max-w":[{"max-w":[l,"screen","none","prose",{screen:[i]},...B()]}],h:[{h:["screen","lh",...B()]}],"min-h":[{"min-h":["screen","lh","none",...B()]}],"max-h":[{"max-h":["screen","lh",...B()]}],"font-size":[{text:["base",n,co,Vn]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[o,fk,ik]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",Ii,ve]}],"font-family":[{font:[dk,lk,t]}],"font-features":[{"font-features":[ve]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:[s,we,ve]}],"line-clamp":[{"line-clamp":[$e,"none",we,Gu]}],leading:[{leading:[a,...M()]}],"list-image":[{"list-image":["none",we,ve]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",we,ve]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:F()}],"text-color":[{text:F()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...K(),"wavy"]}],"text-decoration-thickness":[{decoration:[$e,"from-font","auto",we,Vn]}],"text-decoration-color":[{decoration:F()}],"underline-offset":[{"underline-offset":[$e,"auto",we,ve]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:M()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",we,ve]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],wrap:[{wrap:["break-word","anywhere","normal"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",we,ve]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:H()}],"bg-repeat":[{bg:j()}],"bg-size":[{bg:Q()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},Mn,we,ve],radial:["",we,ve],conic:[Mn,we,ve]},pk,ck]}],"bg-color":[{bg:F()}],"gradient-from-pos":[{from:G()}],"gradient-via-pos":[{via:G()}],"gradient-to-pos":[{to:G()}],"gradient-from":[{from:F()}],"gradient-via":[{via:F()}],"gradient-to":[{to:F()}],rounded:[{rounded:Z()}],"rounded-s":[{"rounded-s":Z()}],"rounded-e":[{"rounded-e":Z()}],"rounded-t":[{"rounded-t":Z()}],"rounded-r":[{"rounded-r":Z()}],"rounded-b":[{"rounded-b":Z()}],"rounded-l":[{"rounded-l":Z()}],"rounded-ss":[{"rounded-ss":Z()}],"rounded-se":[{"rounded-se":Z()}],"rounded-ee":[{"rounded-ee":Z()}],"rounded-es":[{"rounded-es":Z()}],"rounded-tl":[{"rounded-tl":Z()}],"rounded-tr":[{"rounded-tr":Z()}],"rounded-br":[{"rounded-br":Z()}],"rounded-bl":[{"rounded-bl":Z()}],"border-w":[{border:V()}],"border-w-x":[{"border-x":V()}],"border-w-y":[{"border-y":V()}],"border-w-s":[{"border-s":V()}],"border-w-e":[{"border-e":V()}],"border-w-bs":[{"border-bs":V()}],"border-w-be":[{"border-be":V()}],"border-w-t":[{"border-t":V()}],"border-w-r":[{"border-r":V()}],"border-w-b":[{"border-b":V()}],"border-w-l":[{"border-l":V()}],"divide-x":[{"divide-x":V()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":V()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...K(),"hidden","none"]}],"divide-style":[{divide:[...K(),"hidden","none"]}],"border-color":[{border:F()}],"border-color-x":[{"border-x":F()}],"border-color-y":[{"border-y":F()}],"border-color-s":[{"border-s":F()}],"border-color-e":[{"border-e":F()}],"border-color-bs":[{"border-bs":F()}],"border-color-be":[{"border-be":F()}],"border-color-t":[{"border-t":F()}],"border-color-r":[{"border-r":F()}],"border-color-b":[{"border-b":F()}],"border-color-l":[{"border-l":F()}],"divide-color":[{divide:F()}],"outline-style":[{outline:[...K(),"none","hidden"]}],"outline-offset":[{"outline-offset":[$e,we,ve]}],"outline-w":[{outline:["",$e,co,Vn]}],"outline-color":[{outline:F()}],shadow:[{shadow:["","none",p,hs,ms]}],"shadow-color":[{shadow:F()}],"inset-shadow":[{"inset-shadow":["none",f,hs,ms]}],"inset-shadow-color":[{"inset-shadow":F()}],"ring-w":[{ring:V()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:F()}],"ring-offset-w":[{"ring-offset":[$e,Vn]}],"ring-offset-color":[{"ring-offset":F()}],"inset-ring-w":[{"inset-ring":V()}],"inset-ring-color":[{"inset-ring":F()}],"text-shadow":[{"text-shadow":["none",m,hs,ms]}],"text-shadow-color":[{"text-shadow":F()}],opacity:[{opacity:[$e,we,ve]}],"mix-blend":[{"mix-blend":[...X(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":X()}],"mask-clip":[{"mask-clip":["border","padding","content","fill","stroke","view"]},"mask-no-clip"],"mask-composite":[{mask:["add","subtract","intersect","exclude"]}],"mask-image-linear-pos":[{"mask-linear":[$e]}],"mask-image-linear-from-pos":[{"mask-linear-from":te()}],"mask-image-linear-to-pos":[{"mask-linear-to":te()}],"mask-image-linear-from-color":[{"mask-linear-from":F()}],"mask-image-linear-to-color":[{"mask-linear-to":F()}],"mask-image-t-from-pos":[{"mask-t-from":te()}],"mask-image-t-to-pos":[{"mask-t-to":te()}],"mask-image-t-from-color":[{"mask-t-from":F()}],"mask-image-t-to-color":[{"mask-t-to":F()}],"mask-image-r-from-pos":[{"mask-r-from":te()}],"mask-image-r-to-pos":[{"mask-r-to":te()}],"mask-image-r-from-color":[{"mask-r-from":F()}],"mask-image-r-to-color":[{"mask-r-to":F()}],"mask-image-b-from-pos":[{"mask-b-from":te()}],"mask-image-b-to-pos":[{"mask-b-to":te()}],"mask-image-b-from-color":[{"mask-b-from":F()}],"mask-image-b-to-color":[{"mask-b-to":F()}],"mask-image-l-from-pos":[{"mask-l-from":te()}],"mask-image-l-to-pos":[{"mask-l-to":te()}],"mask-image-l-from-color":[{"mask-l-from":F()}],"mask-image-l-to-color":[{"mask-l-to":F()}],"mask-image-x-from-pos":[{"mask-x-from":te()}],"mask-image-x-to-pos":[{"mask-x-to":te()}],"mask-image-x-from-color":[{"mask-x-from":F()}],"mask-image-x-to-color":[{"mask-x-to":F()}],"mask-image-y-from-pos":[{"mask-y-from":te()}],"mask-image-y-to-pos":[{"mask-y-to":te()}],"mask-image-y-from-color":[{"mask-y-from":F()}],"mask-image-y-to-color":[{"mask-y-to":F()}],"mask-image-radial":[{"mask-radial":[we,ve]}],"mask-image-radial-from-pos":[{"mask-radial-from":te()}],"mask-image-radial-to-pos":[{"mask-radial-to":te()}],"mask-image-radial-from-color":[{"mask-radial-from":F()}],"mask-image-radial-to-color":[{"mask-radial-to":F()}],"mask-image-radial-shape":[{"mask-radial":["circle","ellipse"]}],"mask-image-radial-size":[{"mask-radial":[{closest:["side","corner"],farthest:["side","corner"]}]}],"mask-image-radial-pos":[{"mask-radial-at":N()}],"mask-image-conic-pos":[{"mask-conic":[$e]}],"mask-image-conic-from-pos":[{"mask-conic-from":te()}],"mask-image-conic-to-pos":[{"mask-conic-to":te()}],"mask-image-conic-from-color":[{"mask-conic-from":F()}],"mask-image-conic-to-color":[{"mask-conic-to":F()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:H()}],"mask-repeat":[{mask:j()}],"mask-size":[{mask:Q()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",we,ve]}],filter:[{filter:["","none",we,ve]}],blur:[{blur:he()}],brightness:[{brightness:[$e,we,ve]}],contrast:[{contrast:[$e,we,ve]}],"drop-shadow":[{"drop-shadow":["","none",h,hs,ms]}],"drop-shadow-color":[{"drop-shadow":F()}],grayscale:[{grayscale:["",$e,we,ve]}],"hue-rotate":[{"hue-rotate":[$e,we,ve]}],invert:[{invert:["",$e,we,ve]}],saturate:[{saturate:[$e,we,ve]}],sepia:[{sepia:["",$e,we,ve]}],"backdrop-filter":[{"backdrop-filter":["","none",we,ve]}],"backdrop-blur":[{"backdrop-blur":he()}],"backdrop-brightness":[{"backdrop-brightness":[$e,we,ve]}],"backdrop-contrast":[{"backdrop-contrast":[$e,we,ve]}],"backdrop-grayscale":[{"backdrop-grayscale":["",$e,we,ve]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[$e,we,ve]}],"backdrop-invert":[{"backdrop-invert":["",$e,we,ve]}],"backdrop-opacity":[{"backdrop-opacity":[$e,we,ve]}],"backdrop-saturate":[{"backdrop-saturate":[$e,we,ve]}],"backdrop-sepia":[{"backdrop-sepia":["",$e,we,ve]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":M()}],"border-spacing-x":[{"border-spacing-x":M()}],"border-spacing-y":[{"border-spacing-y":M()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",we,ve]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[$e,"initial",we,ve]}],ease:[{ease:["linear","initial",y,we,ve]}],delay:[{delay:[$e,we,ve]}],animate:[{animate:["none",w,we,ve]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[x,we,ve]}],"perspective-origin":[{"perspective-origin":k()}],rotate:[{rotate:xe()}],"rotate-x":[{"rotate-x":xe()}],"rotate-y":[{"rotate-y":xe()}],"rotate-z":[{"rotate-z":xe()}],scale:[{scale:ee()}],"scale-x":[{"scale-x":ee()}],"scale-y":[{"scale-y":ee()}],"scale-z":[{"scale-z":ee()}],"scale-3d":["scale-3d"],skew:[{skew:re()}],"skew-x":[{"skew-x":re()}],"skew-y":[{"skew-y":re()}],transform:[{transform:[we,ve,"","none","gpu","cpu"]}],"transform-origin":[{origin:k()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:de()}],"translate-x":[{"translate-x":de()}],"translate-y":[{"translate-y":de()}],"translate-z":[{"translate-z":de()}],"translate-none":["translate-none"],accent:[{accent:F()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:F()}],"color-scheme":[{scheme:["normal","dark","light","light-dark","only-dark","only-light"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",we,ve]}],"field-sizing":[{"field-sizing":["fixed","content"]}],"pointer-events":[{"pointer-events":["auto","none"]}],resize:[{resize:["none","","y","x"]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":M()}],"scroll-mx":[{"scroll-mx":M()}],"scroll-my":[{"scroll-my":M()}],"scroll-ms":[{"scroll-ms":M()}],"scroll-me":[{"scroll-me":M()}],"scroll-mbs":[{"scroll-mbs":M()}],"scroll-mbe":[{"scroll-mbe":M()}],"scroll-mt":[{"scroll-mt":M()}],"scroll-mr":[{"scroll-mr":M()}],"scroll-mb":[{"scroll-mb":M()}],"scroll-ml":[{"scroll-ml":M()}],"scroll-p":[{"scroll-p":M()}],"scroll-px":[{"scroll-px":M()}],"scroll-py":[{"scroll-py":M()}],"scroll-ps":[{"scroll-ps":M()}],"scroll-pe":[{"scroll-pe":M()}],"scroll-pbs":[{"scroll-pbs":M()}],"scroll-pbe":[{"scroll-pbe":M()}],"scroll-pt":[{"scroll-pt":M()}],"scroll-pr":[{"scroll-pr":M()}],"scroll-pb":[{"scroll-pb":M()}],"scroll-pl":[{"scroll-pl":M()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",we,ve]}],fill:[{fill:["none",...F()]}],"stroke-w":[{stroke:[$e,co,Vn,Gu]}],stroke:[{stroke:["none",...F()]}],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","inset-bs","inset-be","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-x","border-w-y","border-w-s","border-w-e","border-w-bs","border-w-be","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-x","border-color-y","border-color-s","border-color-e","border-color-bs","border-color-be","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],translate:["translate-x","translate-y","translate-none"],"translate-none":["translate","translate-x","translate-y","translate-z"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mbs","scroll-mbe","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pbs","scroll-pbe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]},orderSensitiveModifiers:["*","**","after","backdrop","before","details-content","file","first-letter","first-line","marker","placeholder","selection"]}},gk=W2(hk);function Y(...e){return gk(Nh(e))}function bk(e){if(e==null||typeof e!="object")return null;const t=Reflect.get(e,"data");if(t!=null&&typeof t=="object"){const n=Reflect.get(t,"capRouteReason");if(typeof n=="string")return n}return null}function Do(e){const t=bk(e);return t!==null?t==="no-provider"||t==="node-offline":(e instanceof Error?e.message:String(e)).includes("provider not available")}const xk="rounded-lg border border-border bg-surface overflow-hidden",yk="border-b border-border px-3 sm:px-4 py-1.5 sm:py-2",vk="p-2 sm:p-3 lg:p-4",wk="space-y-3 sm:space-y-4",Nk="gap-2 sm:gap-3",Oh="px-3 sm:px-4 py-1.5 sm:py-2",kk="grid grid-cols-2 sm:grid-cols-2 lg:grid-cols-4",Sk="grid grid-cols-1 lg:grid-cols-2",Ck="flex flex-col-reverse md:flex-row",Mk="w-full md:w-44 lg:w-52 md:flex-shrink-0 border-b md:border-b-0 md:border-l border-border",Ak="text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider",Ek="text-[11px] sm:text-xs text-foreground",Qt="text-[10px] text-foreground-subtle",Ik="text-[11px] sm:text-xs font-medium text-foreground",Pk="text-base sm:text-lg font-semibold leading-tight text-foreground",_k="inline-flex items-center justify-center gap-1 rounded border border-border bg-surface px-1.5 py-0.5 sm:px-2 sm:py-1 text-[10px] sm:text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40",$k="inline-flex items-center justify-center gap-1 rounded border border-primary/40 bg-primary/15 px-1.5 py-0.5 sm:px-2 sm:py-1 text-[10px] sm:text-[11px] font-medium text-primary hover:bg-primary/25 transition-colors disabled:opacity-40",Dk="inline-flex items-center justify-center gap-1 rounded border border-danger/40 bg-danger/10 px-1.5 py-0.5 sm:px-2 sm:py-1 text-[10px] sm:text-[11px] font-medium text-danger hover:bg-danger/20 transition-colors disabled:opacity-40",Lk="inline-flex items-center justify-center gap-1 rounded border border-warning/40 bg-warning/10 px-1.5 py-0.5 sm:px-2 sm:py-1 text-[10px] sm:text-[11px] font-medium text-warning hover:bg-warning/20 transition-colors disabled:opacity-40",Tk="w-full rounded border border-border bg-background px-1.5 py-0.5 sm:px-2 sm:py-1 text-[11px] sm:text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none",Rk="inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors",Ok="border-primary/50 bg-primary/15 text-primary",Bk="border-border bg-surface text-foreground-subtle hover:bg-surface-hover";function zk(e,t){for(const n of e.slots)for(const o of n.addons)if(o.id===t)return o;return null}function Fk(e,t){return e.models.find(n=>n.id===t)??null}function jk(e,t){return e.models.find(n=>!!n.formats[t])??null}function Hk(e,t){const n=new Set((t.configSchema??[]).map(s=>s.key)),o={};for(const[s,a]of Object.entries(e))n.has(s)&&(o[s]=a);return o}function Bh(e){const{source:t,target:n,catalog:o,addonIds:s}=e,a=[];for(const i of s){const l=t.defaults[i];if(!l){a.push({addonId:i,outcome:"skip",modelId:null,reason:"no source entry",patch:null});continue}const c=zk(o,i);if(!c){a.push({addonId:i,outcome:"skip",modelId:null,reason:"addon not in target catalog",patch:null});continue}const d=Fk(c,l.modelId),p=d!==null&&!!d.formats[n.engine.format];let f,m;if(p)f=l.modelId,m="exact";else{const g=jk(c,n.engine.format);if(!g){a.push({addonId:i,outcome:"skip",modelId:null,reason:"no compatible model for target format",patch:null});continue}f=g.id,m="mapped"}const h={enabled:l.enabled,modelId:f,settings:Hk(l.settings,c)};a.push({addonId:i,outcome:m,modelId:f,patch:h})}return a}const _l={idle:{label:"Idle",textColor:"text-foreground-subtle",badgeClass:"border-border bg-surface-hover text-foreground-subtle",dotClass:"bg-gray-400",icon:"PowerOff"},active:{label:"Active",textColor:"text-success",badgeClass:"border-success/40 bg-success/10 text-success",dotClass:"bg-red-500 animate-pulse",icon:"Activity"},watching:{label:"Watching",textColor:"text-foreground-subtle",badgeClass:"border-border bg-surface-hover text-foreground-subtle",dotClass:"bg-emerald-500",icon:"Eye"},"load-shed":{label:"Load-Shed",textColor:"text-amber-500",badgeClass:"border-amber-500/40 bg-amber-500/10 text-amber-500",dotClass:"bg-amber-500",icon:"AlertTriangle"},paused:{label:"Paused",textColor:"text-gray-400",badgeClass:"border-gray-500/40 bg-gray-500/10 text-gray-400",dotClass:"bg-gray-400",icon:"PauseCircle"}};function Gr(e){return _l[e]??_l.watching}function wn(e,t){if(typeof globalThis>"u")return qe(t);const n=globalThis.__camstackSharedContexts,o=n??new Map;n||(globalThis.__camstackSharedContexts=o);const s=o.get(e);if(s)return s;const a=qe(t);return o.set(e,a),a}function Cr(e){const n=(typeof globalThis<"u"?globalThis:void 0)?.[e];return n&&typeof n=="object"?n:{}}const Vk={singleton:!0,requiredVersion:!1,eager:!0},Ct=e=>({version:"0.0.0",scope:"default",lib:e,shareConfig:Vk}),Yu="__mf_module_cache__";function Uk(){const e=globalThis,t=e[Yu];if(t&&typeof t=="object"){const o=t;return o.share??={},o.remote??={},o}const n={share:{},remote:{}};return e[Yu]=n,n}function qk(){const e=Uk();e.share.react??=Wm,e.share["react-dom"]??=Km,e.share["react-dom/client"]??=Ym,e.share["react/jsx-runtime"]??=Gm,e.share["@tanstack/react-query"]??=Xm,e.share["@trpc/client"]??=th,e.share["@trpc/react-query"]??=oh,e.share["react-konva"]??=sh,e.share.konva??=lh,e.share["@camstack/ui-library"]??=Cr("__camstackUiLibrary"),e.share["@camstack/sdk"]??=Cr("__camstackSdk"),e.share["@camstack/types"]??=Cr("__camstackTypes")}function Bc(){qk(),Pr.getInstance()===null&&Pr.init({name:"admin_ui_host",remotes:[],shared:{react:Ct(()=>Wm),"react-dom":Ct(()=>Km),"react-dom/client":Ct(()=>Ym),"react/jsx-runtime":Ct(()=>Gm),"@tanstack/react-query":Ct(()=>Xm),"@trpc/client":Ct(()=>th),"@trpc/react-query":Ct(()=>oh),"react-konva":Ct(()=>sh),konva:Ct(()=>lh),"@camstack/ui-library":Ct(()=>Cr("__camstackUiLibrary")),"@camstack/sdk":Ct(()=>Cr("__camstackSdk")),"@camstack/types":Ct(()=>Cr("__camstackTypes"))}})}/**
31
+ * @license lucide-react v0.576.0 - ISC
32
+ *
33
+ * This source code is licensed under the ISC license.
34
+ * See the LICENSE file in the root directory of this source tree.
35
+ */const zh=(...e)=>e.filter((t,n,o)=>!!t&&t.trim()!==""&&o.indexOf(t)===n).join(" ").trim();/**
36
+ * @license lucide-react v0.576.0 - ISC
37
+ *
38
+ * This source code is licensed under the ISC license.
39
+ * See the LICENSE file in the root directory of this source tree.
40
+ */const Qk=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();/**
41
+ * @license lucide-react v0.576.0 - ISC
42
+ *
43
+ * This source code is licensed under the ISC license.
44
+ * See the LICENSE file in the root directory of this source tree.
45
+ */const Gk=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,o)=>o?o.toUpperCase():n.toLowerCase());/**
46
+ * @license lucide-react v0.576.0 - ISC
47
+ *
48
+ * This source code is licensed under the ISC license.
49
+ * See the LICENSE file in the root directory of this source tree.
50
+ */const Zu=e=>{const t=Gk(e);return t.charAt(0).toUpperCase()+t.slice(1)};/**
51
+ * @license lucide-react v0.576.0 - ISC
52
+ *
53
+ * This source code is licensed under the ISC license.
54
+ * See the LICENSE file in the root directory of this source tree.
55
+ */var Wk={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
56
+ * @license lucide-react v0.576.0 - ISC
57
+ *
58
+ * This source code is licensed under the ISC license.
59
+ * See the LICENSE file in the root directory of this source tree.
60
+ */const Kk=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1};/**
61
+ * @license lucide-react v0.576.0 - ISC
62
+ *
63
+ * This source code is licensed under the ISC license.
64
+ * See the LICENSE file in the root directory of this source tree.
65
+ */const Yk=Ke(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:o,className:s="",children:a,iconNode:i,...l},c)=>_e("svg",{ref:c,...Wk,width:t,height:t,stroke:e,strokeWidth:o?Number(n)*24/Number(t):n,className:zh("lucide",s),...!a&&!Kk(l)&&{"aria-hidden":"true"},...l},[...i.map(([d,p])=>_e(d,p)),...Array.isArray(a)?a:[a]]));/**
66
+ * @license lucide-react v0.576.0 - ISC
67
+ *
68
+ * This source code is licensed under the ISC license.
69
+ * See the LICENSE file in the root directory of this source tree.
70
+ */const ce=(e,t)=>{const n=Ke(({className:o,...s},a)=>_e(Yk,{ref:a,iconNode:t,className:zh(`lucide-${Qk(Zu(e))}`,`lucide-${e}`,o),...s}));return n.displayName=Zu(e),n};/**
71
+ * @license lucide-react v0.576.0 - ISC
72
+ *
73
+ * This source code is licensed under the ISC license.
74
+ * See the LICENSE file in the root directory of this source tree.
75
+ */const Zk=[["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"}]],Pn=ce("activity",Zk);/**
76
+ * @license lucide-react v0.576.0 - ISC
77
+ *
78
+ * This source code is licensed under the ISC license.
79
+ * See the LICENSE file in the root directory of this source tree.
80
+ */const Xk=[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]],Jk=ce("arrow-down-to-line",Xk);/**
81
+ * @license lucide-react v0.576.0 - ISC
82
+ *
83
+ * This source code is licensed under the ISC license.
84
+ * See the LICENSE file in the root directory of this source tree.
85
+ */const e5=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],t5=ce("arrow-down",e5);/**
86
+ * @license lucide-react v0.576.0 - ISC
87
+ *
88
+ * This source code is licensed under the ISC license.
89
+ * See the LICENSE file in the root directory of this source tree.
90
+ */const n5=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],r5=ce("arrow-left",n5);/**
91
+ * @license lucide-react v0.576.0 - ISC
92
+ *
93
+ * This source code is licensed under the ISC license.
94
+ * See the LICENSE file in the root directory of this source tree.
95
+ */const o5=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],s5=ce("arrow-right",o5);/**
96
+ * @license lucide-react v0.576.0 - ISC
97
+ *
98
+ * This source code is licensed under the ISC license.
99
+ * See the LICENSE file in the root directory of this source tree.
100
+ */const a5=[["path",{d:"M5 3h14",key:"7usisc"}],["path",{d:"m18 13-6-6-6 6",key:"1kf1n9"}],["path",{d:"M12 7v14",key:"1akyts"}]],i5=ce("arrow-up-to-line",a5);/**
101
+ * @license lucide-react v0.576.0 - ISC
102
+ *
103
+ * This source code is licensed under the ISC license.
104
+ * See the LICENSE file in the root directory of this source tree.
105
+ */const l5=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],c5=ce("arrow-up",l5);/**
106
+ * @license lucide-react v0.576.0 - ISC
107
+ *
108
+ * This source code is licensed under the ISC license.
109
+ * See the LICENSE file in the root directory of this source tree.
110
+ */const d5=[["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"}]],u5=ce("battery-full",d5);/**
111
+ * @license lucide-react v0.576.0 - ISC
112
+ *
113
+ * This source code is licensed under the ISC license.
114
+ * See the LICENSE file in the root directory of this source tree.
115
+ */const p5=[["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"}]],f5=ce("battery-low",p5);/**
116
+ * @license lucide-react v0.576.0 - ISC
117
+ *
118
+ * This source code is licensed under the ISC license.
119
+ * See the LICENSE file in the root directory of this source tree.
120
+ */const m5=[["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"}]],h5=ce("battery-warning",m5);/**
121
+ * @license lucide-react v0.576.0 - ISC
122
+ *
123
+ * This source code is licensed under the ISC license.
124
+ * See the LICENSE file in the root directory of this source tree.
125
+ */const g5=[["path",{d:"M 22 14 L 22 10",key:"nqc4tb"}],["rect",{x:"2",y:"6",width:"16",height:"12",rx:"2",key:"13zb55"}]],Fh=ce("battery",g5);/**
126
+ * @license lucide-react v0.576.0 - ISC
127
+ *
128
+ * This source code is licensed under the ISC license.
129
+ * See the LICENSE file in the root directory of this source tree.
130
+ */const b5=[["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"}]],x5=ce("bell-ring",b5);/**
131
+ * @license lucide-react v0.576.0 - ISC
132
+ *
133
+ * This source code is licensed under the ISC license.
134
+ * See the LICENSE file in the root directory of this source tree.
135
+ */const y5=[["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"}]],Ba=ce("bell",y5);/**
136
+ * @license lucide-react v0.576.0 - ISC
137
+ *
138
+ * This source code is licensed under the ISC license.
139
+ * See the LICENSE file in the root directory of this source tree.
140
+ */const v5=[["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"}]],w5=ce("bug",v5);/**
141
+ * @license lucide-react v0.576.0 - ISC
142
+ *
143
+ * This source code is licensed under the ISC license.
144
+ * See the LICENSE file in the root directory of this source tree.
145
+ */const N5=[["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"}]],zc=ce("camera",N5);/**
146
+ * @license lucide-react v0.576.0 - ISC
147
+ *
148
+ * This source code is licensed under the ISC license.
149
+ * See the LICENSE file in the root directory of this source tree.
150
+ */const k5=[["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"}]],S5=ce("cast",k5);/**
151
+ * @license lucide-react v0.576.0 - ISC
152
+ *
153
+ * This source code is licensed under the ISC license.
154
+ * See the LICENSE file in the root directory of this source tree.
155
+ */const C5=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Wr=ce("check",C5);/**
156
+ * @license lucide-react v0.576.0 - ISC
157
+ *
158
+ * This source code is licensed under the ISC license.
159
+ * See the LICENSE file in the root directory of this source tree.
160
+ */const M5=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],zn=ce("chevron-down",M5);/**
161
+ * @license lucide-react v0.576.0 - ISC
162
+ *
163
+ * This source code is licensed under the ISC license.
164
+ * See the LICENSE file in the root directory of this source tree.
165
+ */const A5=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],E5=ce("chevron-left",A5);/**
166
+ * @license lucide-react v0.576.0 - ISC
167
+ *
168
+ * This source code is licensed under the ISC license.
169
+ * See the LICENSE file in the root directory of this source tree.
170
+ */const I5=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Fn=ce("chevron-right",I5);/**
171
+ * @license lucide-react v0.576.0 - ISC
172
+ *
173
+ * This source code is licensed under the ISC license.
174
+ * See the LICENSE file in the root directory of this source tree.
175
+ */const P5=[["path",{d:"m7 20 5-5 5 5",key:"13a0gw"}],["path",{d:"m7 4 5 5 5-5",key:"1kwcof"}]],_5=ce("chevrons-down-up",P5);/**
176
+ * @license lucide-react v0.576.0 - ISC
177
+ *
178
+ * This source code is licensed under the ISC license.
179
+ * See the LICENSE file in the root directory of this source tree.
180
+ */const $5=[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]],D5=ce("chevrons-up-down",$5);/**
181
+ * @license lucide-react v0.576.0 - ISC
182
+ *
183
+ * This source code is licensed under the ISC license.
184
+ * See the LICENSE file in the root directory of this source tree.
185
+ */const L5=[["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"}]],Kr=ce("circle-alert",L5);/**
186
+ * @license lucide-react v0.576.0 - ISC
187
+ *
188
+ * This source code is licensed under the ISC license.
189
+ * See the LICENSE file in the root directory of this source tree.
190
+ */const T5=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],R5=ce("circle-check-big",T5);/**
191
+ * @license lucide-react v0.576.0 - ISC
192
+ *
193
+ * This source code is licensed under the ISC license.
194
+ * See the LICENSE file in the root directory of this source tree.
195
+ */const O5=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],B5=ce("circle-check",O5);/**
196
+ * @license lucide-react v0.576.0 - ISC
197
+ *
198
+ * This source code is licensed under the ISC license.
199
+ * See the LICENSE file in the root directory of this source tree.
200
+ */const z5=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]],F5=ce("circle-dot",z5);/**
201
+ * @license lucide-react v0.576.0 - ISC
202
+ *
203
+ * This source code is licensed under the ISC license.
204
+ * See the LICENSE file in the root directory of this source tree.
205
+ */const j5=[["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"}]],H5=ce("circle-pause",j5);/**
206
+ * @license lucide-react v0.576.0 - ISC
207
+ *
208
+ * This source code is licensed under the ISC license.
209
+ * See the LICENSE file in the root directory of this source tree.
210
+ */const V5=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M12 8v8",key:"napkw2"}]],U5=ce("circle-plus",V5);/**
211
+ * @license lucide-react v0.576.0 - ISC
212
+ *
213
+ * This source code is licensed under the ISC license.
214
+ * See the LICENSE file in the root directory of this source tree.
215
+ */const q5=[["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"}]],jh=ce("circle-question-mark",q5);/**
216
+ * @license lucide-react v0.576.0 - ISC
217
+ *
218
+ * This source code is licensed under the ISC license.
219
+ * See the LICENSE file in the root directory of this source tree.
220
+ */const Q5=[["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"}]],G5=ce("circle-x",Q5);/**
221
+ * @license lucide-react v0.576.0 - ISC
222
+ *
223
+ * This source code is licensed under the ISC license.
224
+ * See the LICENSE file in the root directory of this source tree.
225
+ */const W5=[["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"}]],K5=ce("copy-plus",W5);/**
226
+ * @license lucide-react v0.576.0 - ISC
227
+ *
228
+ * This source code is licensed under the ISC license.
229
+ * See the LICENSE file in the root directory of this source tree.
230
+ */const Y5=[["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"}]],jn=ce("copy",Y5);/**
231
+ * @license lucide-react v0.576.0 - ISC
232
+ *
233
+ * This source code is licensed under the ISC license.
234
+ * See the LICENSE file in the root directory of this source tree.
235
+ */const Z5=[["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"}]],X5=ce("cpu",Z5);/**
236
+ * @license lucide-react v0.576.0 - ISC
237
+ *
238
+ * This source code is licensed under the ISC license.
239
+ * See the LICENSE file in the root directory of this source tree.
240
+ */const J5=[["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"}]],Fc=ce("crosshair",J5);/**
241
+ * @license lucide-react v0.576.0 - ISC
242
+ *
243
+ * This source code is licensed under the ISC license.
244
+ * See the LICENSE file in the root directory of this source tree.
245
+ */const eS=[["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"}]],tS=ce("database",eS);/**
246
+ * @license lucide-react v0.576.0 - ISC
247
+ *
248
+ * This source code is licensed under the ISC license.
249
+ * See the LICENSE file in the root directory of this source tree.
250
+ */const nS=[["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"}]],Hh=ce("door-open",nS);/**
251
+ * @license lucide-react v0.576.0 - ISC
252
+ *
253
+ * This source code is licensed under the ISC license.
254
+ * See the LICENSE file in the root directory of this source tree.
255
+ */const rS=[["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"}]],$l=ce("download",rS);/**
256
+ * @license lucide-react v0.576.0 - ISC
257
+ *
258
+ * This source code is licensed under the ISC license.
259
+ * See the LICENSE file in the root directory of this source tree.
260
+ */const oS=[["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"}]],Vh=ce("ellipsis-vertical",oS);/**
261
+ * @license lucide-react v0.576.0 - ISC
262
+ *
263
+ * This source code is licensed under the ISC license.
264
+ * See the LICENSE file in the root directory of this source tree.
265
+ */const sS=[["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"}]],Uh=ce("external-link",sS);/**
266
+ * @license lucide-react v0.576.0 - ISC
267
+ *
268
+ * This source code is licensed under the ISC license.
269
+ * See the LICENSE file in the root directory of this source tree.
270
+ */const aS=[["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"}]],jc=ce("eye-off",aS);/**
271
+ * @license lucide-react v0.576.0 - ISC
272
+ *
273
+ * This source code is licensed under the ISC license.
274
+ * See the LICENSE file in the root directory of this source tree.
275
+ */const iS=[["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"}]],Yr=ce("eye",iS);/**
276
+ * @license lucide-react v0.576.0 - ISC
277
+ *
278
+ * This source code is licensed under the ISC license.
279
+ * See the LICENSE file in the root directory of this source tree.
280
+ */const lS=[["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"}]],qh=ce("funnel",lS);/**
281
+ * @license lucide-react v0.576.0 - ISC
282
+ *
283
+ * This source code is licensed under the ISC license.
284
+ * See the LICENSE file in the root directory of this source tree.
285
+ */const cS=[["line",{x1:"6",x2:"10",y1:"11",y2:"11",key:"1gktln"}],["line",{x1:"8",x2:"8",y1:"9",y2:"13",key:"qnk9ow"}],["line",{x1:"15",x2:"15.01",y1:"12",y2:"12",key:"krot7o"}],["line",{x1:"18",x2:"18.01",y1:"10",y2:"10",key:"1lcuu1"}],["path",{d:"M17.32 5H6.68a4 4 0 0 0-3.978 3.59c-.006.052-.01.101-.017.152C2.604 9.416 2 14.456 2 16a3 3 0 0 0 3 3c1 0 1.5-.5 2-1l1.414-1.414A2 2 0 0 1 9.828 16h4.344a2 2 0 0 1 1.414.586L17 18c.5.5 1 1 2 1a3 3 0 0 0 3-3c0-1.545-.604-6.584-.685-7.258-.007-.05-.011-.1-.017-.151A4 4 0 0 0 17.32 5z",key:"mfqc10"}]],dS=ce("gamepad-2",cS);/**
286
+ * @license lucide-react v0.576.0 - ISC
287
+ *
288
+ * This source code is licensed under the ISC license.
289
+ * See the LICENSE file in the root directory of this source tree.
290
+ */const uS=[["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"}]],pS=ce("grip-horizontal",uS);/**
291
+ * @license lucide-react v0.576.0 - ISC
292
+ *
293
+ * This source code is licensed under the ISC license.
294
+ * See the LICENSE file in the root directory of this source tree.
295
+ */const fS=[["path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z",key:"yt0hxn"}]],mS=ce("hexagon",fS);/**
296
+ * @license lucide-react v0.576.0 - ISC
297
+ *
298
+ * This source code is licensed under the ISC license.
299
+ * See the LICENSE file in the root directory of this source tree.
300
+ */const hS=[["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"}]],Qh=ce("house",hS);/**
301
+ * @license lucide-react v0.576.0 - ISC
302
+ *
303
+ * This source code is licensed under the ISC license.
304
+ * See the LICENSE file in the root directory of this source tree.
305
+ */const gS=[["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"}]],bS=ce("image",gS);/**
306
+ * @license lucide-react v0.576.0 - ISC
307
+ *
308
+ * This source code is licensed under the ISC license.
309
+ * See the LICENSE file in the root directory of this source tree.
310
+ */const xS=[["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"}]],yS=ce("inbox",xS);/**
311
+ * @license lucide-react v0.576.0 - ISC
312
+ *
313
+ * This source code is licensed under the ISC license.
314
+ * See the LICENSE file in the root directory of this source tree.
315
+ */const vS=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],wS=ce("info",vS);/**
316
+ * @license lucide-react v0.576.0 - ISC
317
+ *
318
+ * This source code is licensed under the ISC license.
319
+ * See the LICENSE file in the root directory of this source tree.
320
+ */const NS=[["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"}]],kS=ce("layout-grid",NS);/**
321
+ * @license lucide-react v0.576.0 - ISC
322
+ *
323
+ * This source code is licensed under the ISC license.
324
+ * See the LICENSE file in the root directory of this source tree.
325
+ */const SS=[["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"}]],Gh=ce("lightbulb",SS);/**
326
+ * @license lucide-react v0.576.0 - ISC
327
+ *
328
+ * This source code is licensed under the ISC license.
329
+ * See the LICENSE file in the root directory of this source tree.
330
+ */const CS=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],yt=ce("loader-circle",CS);/**
331
+ * @license lucide-react v0.576.0 - ISC
332
+ *
333
+ * This source code is licensed under the ISC license.
334
+ * See the LICENSE file in the root directory of this source tree.
335
+ */const MS=[["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"}]],AS=ce("locate-fixed",MS);/**
336
+ * @license lucide-react v0.576.0 - ISC
337
+ *
338
+ * This source code is licensed under the ISC license.
339
+ * See the LICENSE file in the root directory of this source tree.
340
+ */const ES=[["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"}]],Xu=ce("maximize-2",ES);/**
341
+ * @license lucide-react v0.576.0 - ISC
342
+ *
343
+ * This source code is licensed under the ISC license.
344
+ * See the LICENSE file in the root directory of this source tree.
345
+ */const IS=[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]],PS=ce("menu",IS);/**
346
+ * @license lucide-react v0.576.0 - ISC
347
+ *
348
+ * This source code is licensed under the ISC license.
349
+ * See the LICENSE file in the root directory of this source tree.
350
+ */const _S=[["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"}]],Wh=ce("mic",_S);/**
351
+ * @license lucide-react v0.576.0 - ISC
352
+ *
353
+ * This source code is licensed under the ISC license.
354
+ * See the LICENSE file in the root directory of this source tree.
355
+ */const $S=[["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"}]],Ju=ce("minimize-2",$S);/**
356
+ * @license lucide-react v0.576.0 - ISC
357
+ *
358
+ * This source code is licensed under the ISC license.
359
+ * See the LICENSE file in the root directory of this source tree.
360
+ */const DS=[["path",{d:"M5 12h14",key:"1ays0h"}]],Kh=ce("minus",DS);/**
361
+ * @license lucide-react v0.576.0 - ISC
362
+ *
363
+ * This source code is licensed under the ISC license.
364
+ * See the LICENSE file in the root directory of this source tree.
365
+ */const LS=[["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"}]],Hc=ce("moon",LS);/**
366
+ * @license lucide-react v0.576.0 - ISC
367
+ *
368
+ * This source code is licensed under the ISC license.
369
+ * See the LICENSE file in the root directory of this source tree.
370
+ */const TS=[["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"}]],RS=ce("music",TS);/**
371
+ * @license lucide-react v0.576.0 - ISC
372
+ *
373
+ * This source code is licensed under the ISC license.
374
+ * See the LICENSE file in the root directory of this source tree.
375
+ */const OS=[["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"}]],Dl=ce("network",OS);/**
376
+ * @license lucide-react v0.576.0 - ISC
377
+ *
378
+ * This source code is licensed under the ISC license.
379
+ * See the LICENSE file in the root directory of this source tree.
380
+ */const BS=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],zS=ce("pencil",BS);/**
381
+ * @license lucide-react v0.576.0 - ISC
382
+ *
383
+ * This source code is licensed under the ISC license.
384
+ * See the LICENSE file in the root directory of this source tree.
385
+ */const FS=[["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"}]],Ll=ce("play",FS);/**
386
+ * @license lucide-react v0.576.0 - ISC
387
+ *
388
+ * This source code is licensed under the ISC license.
389
+ * See the LICENSE file in the root directory of this source tree.
390
+ */const jS=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],Zr=ce("plus",jS);/**
391
+ * @license lucide-react v0.576.0 - ISC
392
+ *
393
+ * This source code is licensed under the ISC license.
394
+ * See the LICENSE file in the root directory of this source tree.
395
+ */const HS=[["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"}]],VS=ce("plug",HS);/**
396
+ * @license lucide-react v0.576.0 - ISC
397
+ *
398
+ * This source code is licensed under the ISC license.
399
+ * See the LICENSE file in the root directory of this source tree.
400
+ */const US=[["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"}]],qS=ce("power-off",US);/**
401
+ * @license lucide-react v0.576.0 - ISC
402
+ *
403
+ * This source code is licensed under the ISC license.
404
+ * See the LICENSE file in the root directory of this source tree.
405
+ */const QS=[["rect",{width:"5",height:"5",x:"3",y:"3",rx:"1",key:"1tu5fj"}],["rect",{width:"5",height:"5",x:"16",y:"3",rx:"1",key:"1v8r4q"}],["rect",{width:"5",height:"5",x:"3",y:"16",rx:"1",key:"1x03jg"}],["path",{d:"M21 16h-3a2 2 0 0 0-2 2v3",key:"177gqh"}],["path",{d:"M21 21v.01",key:"ents32"}],["path",{d:"M12 7v3a2 2 0 0 1-2 2H7",key:"8crl2c"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M12 3h.01",key:"n36tog"}],["path",{d:"M12 16v.01",key:"133mhm"}],["path",{d:"M16 12h1",key:"1slzba"}],["path",{d:"M21 12v.01",key:"1lwtk9"}],["path",{d:"M12 21v-1",key:"1880an"}]],GS=ce("qr-code",QS);/**
406
+ * @license lucide-react v0.576.0 - ISC
407
+ *
408
+ * This source code is licensed under the ISC license.
409
+ * See the LICENSE file in the root directory of this source tree.
410
+ */const WS=[["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"}]],Yh=ce("radar",WS);/**
411
+ * @license lucide-react v0.576.0 - ISC
412
+ *
413
+ * This source code is licensed under the ISC license.
414
+ * See the LICENSE file in the root directory of this source tree.
415
+ */const KS=[["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"}]],YS=ce("radio",KS);/**
416
+ * @license lucide-react v0.576.0 - ISC
417
+ *
418
+ * This source code is licensed under the ISC license.
419
+ * See the LICENSE file in the root directory of this source tree.
420
+ */const ZS=[["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"}]],za=ce("refresh-cw",ZS);/**
421
+ * @license lucide-react v0.576.0 - ISC
422
+ *
423
+ * This source code is licensed under the ISC license.
424
+ * See the LICENSE file in the root directory of this source tree.
425
+ */const XS=[["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"}]],Zh=ce("rotate-ccw",XS);/**
426
+ * @license lucide-react v0.576.0 - ISC
427
+ *
428
+ * This source code is licensed under the ISC license.
429
+ * See the LICENSE file in the root directory of this source tree.
430
+ */const JS=[["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"}]],Xh=ce("rotate-cw",JS);/**
431
+ * @license lucide-react v0.576.0 - ISC
432
+ *
433
+ * This source code is licensed under the ISC license.
434
+ * See the LICENSE file in the root directory of this source tree.
435
+ */const eC=[["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"}]],tC=ce("save",eC);/**
436
+ * @license lucide-react v0.576.0 - ISC
437
+ *
438
+ * This source code is licensed under the ISC license.
439
+ * See the LICENSE file in the root directory of this source tree.
440
+ */const nC=[["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"}]],rC=ce("scan",nC);/**
441
+ * @license lucide-react v0.576.0 - ISC
442
+ *
443
+ * This source code is licensed under the ISC license.
444
+ * See the LICENSE file in the root directory of this source tree.
445
+ */const oC=[["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"}]],sC=ce("scroll-text",oC);/**
446
+ * @license lucide-react v0.576.0 - ISC
447
+ *
448
+ * This source code is licensed under the ISC license.
449
+ * See the LICENSE file in the root directory of this source tree.
450
+ */const aC=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],Lo=ce("search",aC);/**
451
+ * @license lucide-react v0.576.0 - ISC
452
+ *
453
+ * This source code is licensed under the ISC license.
454
+ * See the LICENSE file in the root directory of this source tree.
455
+ */const iC=[["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"}]],lC=ce("server",iC);/**
456
+ * @license lucide-react v0.576.0 - ISC
457
+ *
458
+ * This source code is licensed under the ISC license.
459
+ * See the LICENSE file in the root directory of this source tree.
460
+ */const cC=[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]],Tl=ce("share-2",cC);/**
461
+ * @license lucide-react v0.576.0 - ISC
462
+ *
463
+ * This source code is licensed under the ISC license.
464
+ * See the LICENSE file in the root directory of this source tree.
465
+ */const dC=[["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"}]],uC=ce("shield",dC);/**
466
+ * @license lucide-react v0.576.0 - ISC
467
+ *
468
+ * This source code is licensed under the ISC license.
469
+ * See the LICENSE file in the root directory of this source tree.
470
+ */const pC=[["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"}]],fC=ce("ship",pC);/**
471
+ * @license lucide-react v0.576.0 - ISC
472
+ *
473
+ * This source code is licensed under the ISC license.
474
+ * See the LICENSE file in the root directory of this source tree.
475
+ */const mC=[["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"}]],hC=ce("sliders-horizontal",mC);/**
476
+ * @license lucide-react v0.576.0 - ISC
477
+ *
478
+ * This source code is licensed under the ISC license.
479
+ * See the LICENSE file in the root directory of this source tree.
480
+ */const gC=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Rl=ce("square",gC);/**
481
+ * @license lucide-react v0.576.0 - ISC
482
+ *
483
+ * This source code is licensed under the ISC license.
484
+ * See the LICENSE file in the root directory of this source tree.
485
+ */const bC=[["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"}]],xC=ce("star",bC);/**
486
+ * @license lucide-react v0.576.0 - ISC
487
+ *
488
+ * This source code is licensed under the ISC license.
489
+ * See the LICENSE file in the root directory of this source tree.
490
+ */const yC=[["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"}]],Jh=ce("sun",yC);/**
491
+ * @license lucide-react v0.576.0 - ISC
492
+ *
493
+ * This source code is licensed under the ISC license.
494
+ * See the LICENSE file in the root directory of this source tree.
495
+ */const vC=[["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"}]],wC=ce("table-2",vC);/**
496
+ * @license lucide-react v0.576.0 - ISC
497
+ *
498
+ * This source code is licensed under the ISC license.
499
+ * See the LICENSE file in the root directory of this source tree.
500
+ */const NC=[["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"}]],ep=ce("target",NC);/**
501
+ * @license lucide-react v0.576.0 - ISC
502
+ *
503
+ * This source code is licensed under the ISC license.
504
+ * See the LICENSE file in the root directory of this source tree.
505
+ */const kC=[["path",{d:"M14 4v10.54a4 4 0 1 1-4 0V4a2 2 0 0 1 4 0Z",key:"17jzev"}]],SC=ce("thermometer",kC);/**
506
+ * @license lucide-react v0.576.0 - ISC
507
+ *
508
+ * This source code is licensed under the ISC license.
509
+ * See the LICENSE file in the root directory of this source tree.
510
+ */const CC=[["circle",{cx:"9",cy:"12",r:"3",key:"u3jwor"}],["rect",{width:"20",height:"14",x:"2",y:"5",rx:"7",key:"g7kal2"}]],MC=ce("toggle-left",CC);/**
511
+ * @license lucide-react v0.576.0 - ISC
512
+ *
513
+ * This source code is licensed under the ISC license.
514
+ * See the LICENSE file in the root directory of this source tree.
515
+ */const AC=[["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"}]],Jt=ce("trash-2",AC);/**
516
+ * @license lucide-react v0.576.0 - ISC
517
+ *
518
+ * This source code is licensed under the ISC license.
519
+ * See the LICENSE file in the root directory of this source tree.
520
+ */const EC=[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]],IC=ce("trending-up",EC);/**
521
+ * @license lucide-react v0.576.0 - ISC
522
+ *
523
+ * This source code is licensed under the ISC license.
524
+ * See the LICENSE file in the root directory of this source tree.
525
+ */const PC=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],_C=ce("trending-down",PC);/**
526
+ * @license lucide-react v0.576.0 - ISC
527
+ *
528
+ * This source code is licensed under the ISC license.
529
+ * See the LICENSE file in the root directory of this source tree.
530
+ */const $C=[["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"}]],Xr=ce("triangle-alert",$C);/**
531
+ * @license lucide-react v0.576.0 - ISC
532
+ *
533
+ * This source code is licensed under the ISC license.
534
+ * See the LICENSE file in the root directory of this source tree.
535
+ */const DC=[["path",{d:"M15 7h2a5 5 0 0 1 0 10h-2m-6 0H7A5 5 0 0 1 7 7h2",key:"1re2ne"}]],LC=ce("unlink-2",DC);/**
536
+ * @license lucide-react v0.576.0 - ISC
537
+ *
538
+ * This source code is licensed under the ISC license.
539
+ * See the LICENSE file in the root directory of this source tree.
540
+ */const TC=[["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"}]],eg=ce("upload",TC);/**
541
+ * @license lucide-react v0.576.0 - ISC
542
+ *
543
+ * This source code is licensed under the ISC license.
544
+ * See the LICENSE file in the root directory of this source tree.
545
+ */const RC=[["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"}]],OC=ce("wifi-off",RC);/**
546
+ * @license lucide-react v0.576.0 - ISC
547
+ *
548
+ * This source code is licensed under the ISC license.
549
+ * See the LICENSE file in the root directory of this source tree.
550
+ */const BC=[["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"}]],tg=ce("wifi",BC);/**
551
+ * @license lucide-react v0.576.0 - ISC
552
+ *
553
+ * This source code is licensed under the ISC license.
554
+ * See the LICENSE file in the root directory of this source tree.
555
+ */const zC=[["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"}]],Vc=ce("wrench",zC);/**
556
+ * @license lucide-react v0.576.0 - ISC
557
+ *
558
+ * This source code is licensed under the ISC license.
559
+ * See the LICENSE file in the root directory of this source tree.
560
+ */const FC=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],rt=ce("x",FC);/**
561
+ * @license lucide-react v0.576.0 - ISC
562
+ *
563
+ * This source code is licensed under the ISC license.
564
+ * See the LICENSE file in the root directory of this source tree.
565
+ */const jC=[["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"}]],tp=ce("zap",jC);/**
566
+ * @license lucide-react v0.576.0 - ISC
567
+ *
568
+ * This source code is licensed under the ISC license.
569
+ * See the LICENSE file in the root directory of this source tree.
570
+ */const HC=[["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"}]],VC=ce("zoom-in",HC);/**
571
+ * @license lucide-react v0.576.0 - ISC
572
+ *
573
+ * This source code is licensed under the ISC license.
574
+ * See the LICENSE file in the root directory of this source tree.
575
+ */const UC=[["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"}]],qC=ce("zoom-out",UC),QC={frigate:fC,scrypted:uC,reolink:YS,homeAssistant:Qh,rtsp:S5},GC={online:B5,offline:G5,degraded:Kr,unknown:jh},np=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,rp=Nh,ur=(e,t)=>n=>{var o;if(t?.variants==null)return rp(e,n?.class,n?.className);const{variants:s,defaultVariants:a}=t,i=Object.keys(s).map(d=>{const p=n?.[d],f=a?.[d];if(p===null)return null;const m=np(p)||np(f);return s[d][m]}),l=n&&Object.entries(n).reduce((d,p)=>{let[f,m]=p;return m===void 0||(d[f]=m),d},{}),c=t==null||(o=t.compoundVariants)===null||o===void 0?void 0:o.reduce((d,p)=>{let{class:f,className:m,...h}=p;return Object.entries(h).every(g=>{let[x,b]=g;return Array.isArray(b)?b.includes({...a,...l}[x]):{...a,...l}[x]===b})?[...d,f,m]:d},[]);return rp(e,i,c,n?.class,n?.className)},WC=ur("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"}}),Ue=Ke(({className:e,variant:t,size:n,...o},s)=>r("button",{ref:s,className:Y(WC({variant:t,size:n}),e),...o}));Ue.displayName="Button";const KC=ur("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"}}),Uc=Ke(({className:e,variant:t,size:n,icon:o,...s},a)=>r("button",{ref:a,className:Y(KC({variant:t,size:n}),e),...s,children:r(o,{className:"h-4 w-4"})}));Uc.displayName="IconButton";const YC=ur("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"}}),Kt=Ke(({className:e,variant:t,style:n,...o},s)=>r("span",{ref:s,className:Y(YC({variant:t,styleVariant:n}),e),...o}));Kt.displayName="Badge";const ZC=ur("rounded-lg p-3",{variants:{variant:{flat:"bg-surface",bordered:"bg-surface border border-border"}},defaultVariants:{variant:"bordered"}}),mn=Ke(({className:e,variant:t,...n},o)=>r("div",{ref:o,className:Y(ZC({variant:t}),e),...n}));mn.displayName="Card";function ng({expanded:e,onExpandedChange:t,header:n,children:o,dimmed:s=!1,hideChevron:a=!1,className:i}){return u("div",{className:Y("rounded-lg border border-border bg-surface overflow-hidden",s&&"opacity-[0.45]",i),children:[u("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&&r("span",{className:"text-foreground-subtle shrink-0",children:e?r(zn,{className:"h-4 w-4"}):r(Fn,{className:"h-4 w-4"})}),n]}),e&&o&&r("div",{className:"border-t border-border px-3 py-3",children:o})]})}const qc=Ke(({className:e,...t},n)=>r("label",{ref:n,className:Y("text-[10px] uppercase tracking-wider text-foreground-muted font-medium",e),...t}));qc.displayName="Label";const XC=ur("",{variants:{orientation:{horizontal:"h-px w-full bg-border-subtle",vertical:"w-px h-full bg-border-subtle"}},defaultVariants:{orientation:"horizontal"}}),Qc=Ke(({className:e,orientation:t,...n},o)=>r("div",{ref:o,role:"separator",className:Y(XC({orientation:t}),e),...n}));Qc.displayName="Separator";const rg=Ke(({className:e,...t},n)=>r("div",{ref:n,className:Y("animate-pulse bg-surface-hover rounded-md h-4 w-full",e),...t}));rg.displayName="Skeleton";const op=ur("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"}}),la=Ke(({className:e,state:t,leftSlot:n,rightSlot:o,...s},a)=>n||o?u("div",{className:"relative flex items-center w-full",children:[n&&r("div",{className:"absolute left-2.5 flex items-center pointer-events-none",children:n}),r("input",{ref:a,className:Y(op({state:t}),n?"pl-7":"",o?"pr-7":"",e),...s}),o&&r("div",{className:"absolute right-2.5 flex items-center pointer-events-none",children:o})]}):r("input",{ref:a,className:Y(op({state:t}),e),...s}));la.displayName="Input";const To=Ke(({className:e,options:t,...n},o)=>u("div",{className:"relative w-full",children:[r("select",{ref:o,className:Y("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),...n,children:t.map(s=>r("option",{value:s.value,children:s.label},s.value))}),r("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none text-foreground-muted",children:r(zn,{className:"h-3.5 w-3.5"})})]}));To.displayName="Select";const og=Ke(({className:e,...t},n)=>r("input",{ref:n,type:"checkbox",className:Y("w-3.5 h-3.5 rounded-sm border border-border accent-primary",e),...t}));og.displayName="Checkbox";const Gc=Ke(({className:e,checked:t,onCheckedChange:n,label:o,...s},a)=>u("button",{ref:a,role:"switch","aria-checked":t,type:"button",onClick:()=>n(!t),className:Y("inline-flex items-center gap-2",e),...s,children:[r("span",{className:Y("w-8 h-4 rounded-full transition-colors",t?"bg-primary":"bg-surface-hover"),children:r("span",{className:Y("block w-3.5 h-3.5 rounded-full bg-white transition-transform",t?"translate-x-4":"translate-x-0.5")})}),o&&r("span",{className:"text-xs text-foreground",children:o})]}));Gc.displayName="Switch";const sg=qe(null);function ag(){const e=Ne(sg);if(!e)throw new Error("Dialog compound components must be used within <Dialog>");return e}function ig({children:e,open:t,onOpenChange:n}){const[o,s]=I(!1),a=t??o,i=er(),l=U(c=>{n?.(c),t===void 0&&s(c)},[t,n]);return r(sg.Provider,{value:{open:a,setOpen:l,contentId:i},children:e})}function JC({children:e,...t}){const{setOpen:n}=ag();return r("button",{type:"button",onClick:()=>n(!0),...t,children:e})}const e3=ur("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"}}),Wc=Ke(({className:e,width:t,children:n,...o},s)=>{const{open:a,setOpen:i,contentId:l}=ag(),c=ne(null),d=s??c;J(()=>{const f=d.current;f&&(a&&!f.open&&f.showModal(),!a&&f.open&&f.close())},[a,d]);const p=f=>{f.target===f.currentTarget&&i(!1)};return r("dialog",{ref:d,id:l,className:Y(e3({width:t}),"w-full",e),onClick:p,onClose:()=>i(!1),...o,children:n})});Wc.displayName="DialogContent";function lg({className:e,...t}){return r("div",{className:Y("flex flex-col gap-1 mb-3",e),...t})}function cg({className:e,...t}){return r("div",{className:Y("flex justify-end gap-2 mt-4",e),...t})}function dg({className:e,...t}){return r("h2",{className:Y("text-sm font-semibold text-foreground",e),...t})}function ug({className:e,...t}){return r("p",{className:Y("text-xs text-foreground-muted",e),...t})}const pg=qe(null);function Kc(){const e=Ne(pg);if(!e)throw new Error("Dropdown compound components must be used within <Dropdown>");return e}function fg({children:e}){const[t,n]=I(!1),o=er(),s=er(),a=ne(null);return r(pg.Provider,{value:{open:t,setOpen:n,triggerId:o,contentId:s,triggerRef:a},children:r("div",{className:"relative inline-block",children:e})})}function mg({children:e,...t}){const{open:n,setOpen:o,triggerId:s,contentId:a,triggerRef:i}=Kc();return r("button",{type:"button",ref:i,id:s,"aria-haspopup":"menu","aria-expanded":n,"aria-controls":n?a:void 0,onClick:()=>o(!n),...t,children:e})}function hg({className:e,children:t,align:n="start",offset:o=4,...s}){const{open:a,setOpen:i,contentId:l,triggerId:c,triggerRef:d}=Kc(),p=ne(null),[f,m]=I(null);if(Ra(()=>{if(!a){m(null);return}const g=()=>{const x=d.current;if(!x)return;const b=x.getBoundingClientRect(),y=n==="end"?b.right:b.left;m({top:b.bottom+o,left:y,minWidth:b.width})};return g(),window.addEventListener("resize",g),window.addEventListener("scroll",g,!0),()=>{window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0)}},[a,n,o,d]),J(()=>{if(!a)return;const g=b=>{const y=p.current,w=d.current;y&&!y.contains(b.target)&&!w?.contains(b.target)&&i(!1)},x=b=>{b.key==="Escape"&&i(!1)};return document.addEventListener("mousedown",g),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",x)}},[a,i,d]),!a||!f||typeof document>"u")return null;const h={position:"fixed",top:f.top,...n==="end"?{right:window.innerWidth-f.left}:{left:f.left},minWidth:f.minWidth};return Qr(r("div",{ref:p,id:l,role:"menu","aria-labelledby":c,style:h,className:Y("z-50 bg-background-elevated border border-border rounded-md shadow-lg py-1 min-w-[160px]",e),...s,children:t}),document.body)}function gg({className:e,icon:t,variant:n="default",children:o,onClick:s,...a}){const{setOpen:i}=Kc(),l=U(c=>{s?.(c),i(!1)},[s,i]);return u("button",{type:"button",role:"menuitem",className:Y("h-7 text-xs px-2 w-full text-left flex items-center gap-2",n==="danger"?"text-danger hover:bg-danger/10":"text-foreground hover:bg-surface-hover",e),onClick:l,...a,children:[t&&r(t,{size:14}),o]})}const bg=qe(null);function xg(){const e=Ne(bg);if(!e)throw new Error("Tooltip compound components must be used within <Tooltip>");return e}function t3({children:e}){const[t,n]=I(!1),o=ne(null),s=er(),a=()=>{o.current=setTimeout(()=>n(!0),300)},i=()=>{o.current&&clearTimeout(o.current),n(!1)};return r(bg.Provider,{value:{open:t,show:a,hide:i,tooltipId:s},children:r("div",{className:"relative inline-block",children:e})})}function n3({children:e,...t}){const{show:n,hide:o,tooltipId:s,open:a}=xg();return r("div",{onMouseEnter:n,onMouseLeave:o,onFocus:n,onBlur:o,"aria-describedby":a?s:void 0,...t,children:e})}function r3({className:e,children:t,...n}){const{open:o,tooltipId:s}=xg();return r("div",{id:s,role:"tooltip",className:Y("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",o?"opacity-100":"opacity-0",e),...n,children:t})}const sp="(max-width: 767px)",ap="(min-width: 768px) and (max-width: 1023px)";function yg(e){return t=>{const n=window.matchMedia(e);return n.addEventListener("change",t),()=>n.removeEventListener("change",t)}}function vg(e){return()=>window.matchMedia(e).matches}function wg(){return!1}function pr(){return Oa(yg(sp),vg(sp),wg)}function Ng(){return Oa(yg(ap),vg(ap),wg)}function Yc({open:e,onClose:t,title:n,children:o,className:s}){return J(()=>{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]),u(me,{children:[r("div",{className:Y("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"}),u("div",{role:"dialog","aria-modal":"true",className:Y("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",s),children:[r("div",{className:"flex justify-center pt-2 pb-1",children:r("div",{className:"h-1 w-8 rounded-full bg-foreground-subtle/30"})}),n&&u("div",{className:"flex items-center justify-between px-4 pb-2",children:[r("span",{className:"text-sm font-medium text-foreground",children:n}),r("button",{onClick:t,className:"p-1 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors",children:r(rt,{className:"h-4 w-4"})})]}),r("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:o})]})]})}const kg=qe(null);function Sg(){const e=Ne(kg);if(!e)throw new Error("Popover compound components must be used within <Popover>");return e}function Cg({children:e,open:t,onOpenChange:n}){const[o,s]=I(!1),a=t??o,i=er(),l=er(),c=U(d=>{n?.(d),t===void 0&&s(d)},[t,n]);return r(kg.Provider,{value:{open:a,setOpen:c,triggerId:i,contentId:l},children:r("div",{className:"relative inline-block",children:e})})}function Mg({children:e,...t}){const{open:n,setOpen:o,triggerId:s,contentId:a}=Sg();return r("button",{type:"button",id:s,"aria-haspopup":"dialog","aria-expanded":n,"aria-controls":n?a:void 0,onClick:()=>o(!n),...t,children:e})}function Ag({className:e,children:t,...n}){const{open:o,setOpen:s,contentId:a,triggerId:i}=Sg(),l=pr(),c=ne(null);return J(()=>{if(!o||l)return;const d=f=>{const m=c.current,h=document.getElementById(i);m&&!m.contains(f.target)&&!h?.contains(f.target)&&s(!1)},p=f=>{f.key==="Escape"&&s(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",p),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",p)}},[o,s,i,l]),o?l?r(Yc,{open:o,onClose:()=>s(!1),children:t}):r("div",{ref:c,id:a,role:"dialog","aria-labelledby":i,className:Y("absolute left-0 top-full z-50 mt-1 bg-background-elevated border border-border rounded-lg shadow-lg p-3",e),...n,children:t}):null}const Eg=qe(null);function Ig(){const e=Ne(Eg);if(!e)throw new Error("Tabs compound components must be used within <Tabs>");return e}function o3({value:e,onValueChange:t,defaultValue:n="",className:o,...s}){const[a,i]=I(n),l=e??a,c=U(d=>{t?.(d),e===void 0&&i(d)},[e,t]);return r(Eg.Provider,{value:{value:l,setValue:c},children:r("div",{className:o,...s})})}function s3({className:e,...t}){return r("div",{role:"tablist",className:Y("flex flex-row border-b border-border-subtle",e),...t})}function a3({value:e,className:t,...n}){const{value:o,setValue:s}=Ig(),a=e===o,i=`tabpanel-${e}`;return r("button",{type:"button",role:"tab","aria-selected":a,"aria-controls":i,tabIndex:a?0:-1,className:Y("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:()=>s(e),...n})}function i3({value:e,className:t,...n}){const{value:o}=Ig();return e!==o?null:r("div",{role:"tabpanel",id:`tabpanel-${e}`,className:Y("pt-3",t),...n})}const Zc=Ke(({className:e,...t},n)=>r("div",{ref:n,className:Y("overflow-auto [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-surface-hover [&::-webkit-scrollbar-thumb]:rounded-full",e),...t}));Zc.displayName="ScrollArea";function l3({title:e,onClose:t,children:n,defaultWidth:o=360,defaultHeight:s=280,minWidth:a=280,minHeight:i=160,offsetIndex:l=0,className:c}){const[d,p]=I({x:80+l*30,y:80+l*30}),[f,m]=I({w:o,h:s}),[h,g]=I(!1),x=ne(!1),b=ne(!1),y=ne({x:0,y:0}),w=pr(),v=U(k=>{k.preventDefault(),x.current=!0,y.current={x:k.clientX-d.x,y:k.clientY-d.y}},[d]),N=U(k=>{k.preventDefault(),k.stopPropagation(),b.current=!0,y.current={x:k.clientX,y:k.clientY}},[]);return J(()=>{const k=D=>{if(x.current&&p({x:D.clientX-y.current.x,y:D.clientY-y.current.y}),b.current){const M=D.clientX-y.current.x,_=D.clientY-y.current.y;y.current={x:D.clientX,y:D.clientY},m($=>({w:Math.max(a,$.w+M),h:Math.max(i,$.h+_)}))}},C=()=>{x.current=!1,b.current=!1};return window.addEventListener("mousemove",k),window.addEventListener("mouseup",C),()=>{window.removeEventListener("mousemove",k),window.removeEventListener("mouseup",C)}},[a,i]),w?u("div",{className:Y("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",c),style:{maxHeight:"60dvh"},children:[u("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b border-border shrink-0 bg-surface",children:[r("span",{className:"text-[11px] font-medium truncate",children:e}),u("div",{className:"flex items-center gap-1 shrink-0",children:[r("button",{onClick:()=>g(!h),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",children:h?r(Xu,{size:12}):r(Ju,{size:12})}),r("button",{onClick:t,className:"p-0.5 rounded hover:bg-danger/20 text-foreground-muted hover:text-danger transition-colors",children:r(rt,{size:12})})]})]}),!h&&r("div",{className:"flex-1 min-h-0 overflow-y-auto",children:n})]}):u("div",{className:Y("fixed z-50 rounded-lg border border-border bg-background-elevated shadow-2xl flex flex-col overflow-hidden",c),style:{left:d.x,top:d.y,width:h?280:f.w,height:h?"auto":f.h},children:[u("div",{onMouseDown:v,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:[u("div",{className:"flex items-center gap-2 min-w-0",children:[r(pS,{size:12,className:"text-foreground-subtle shrink-0"}),r("span",{className:"text-[11px] font-medium truncate",children:e})]}),u("div",{className:"flex items-center gap-1 shrink-0",children:[r("button",{onClick:()=>g(!h),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",title:h?"Restore":"Minimize",children:h?r(Xu,{size:12}):r(Ju,{size:12})}),r("button",{onClick:t,className:"p-0.5 rounded hover:bg-danger/20 text-foreground-muted hover:text-danger transition-colors",title:"Close",children:r(rt,{size:12})})]})]}),!h&&u("div",{className:"flex-1 min-h-0 overflow-y-auto relative",children:[n,r("div",{onMouseDown:N,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 Xc({open:e,onClose:t,children:n,className:o,width:s="w-64"}){const a=ne(null);return J(()=>{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]),u(me,{children:[r("div",{className:Y("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"}),r("div",{ref:a,role:"dialog","aria-modal":"true",className:Y("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",s,e?"translate-x-0":"-translate-x-full",o),children:n})]})}function Jc({items:e,className:t}){return r("nav",{className:`flex items-center gap-1 text-[11px] text-foreground-subtle ${t??""}`,children:e.map((n,o)=>{const s=o===e.length-1,a=!s&&(n.onClick||n.href);return u(Ze.Fragment,{children:[o>0&&r(Fn,{className:"h-3 w-3 flex-shrink-0"}),a?n.onClick?r("button",{type:"button",onClick:n.onClick,className:"hover:text-foreground transition-colors",children:n.label}):r("a",{href:n.href,className:"hover:text-foreground transition-colors",children:n.label}):r("span",{className:s?"text-foreground font-medium":"",children:n.label})]},o)})})}const ip={left:"text-left",right:"text-right",center:"text-center"};function Fa({columns:e,rows:t,rowKey:n,onRowClick:o,minWidthPx:s=480,emptyMessage:a,className:i,bordered:l=!0,rowClassName:c}){if(t.length===0&&a)return r("div",{className:`rounded-lg ${l?"border border-border":""} bg-surface px-3 py-4 text-xs text-foreground-subtle text-center ${i??""}`,children:a});if(t.length===0)return null;const d=`rounded-lg ${l?"border border-border":""} bg-surface overflow-x-auto ${i??""}`;return r("div",{className:d,children:u("table",{className:"w-full text-xs",style:{minWidth:`${s}px`},children:[r("thead",{className:"bg-surface",children:r("tr",{children:e.map(p=>{const f=p.align??"left",m=p.nowrap??!0;return r("th",{className:["px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border",ip[f],m?"whitespace-nowrap":"",p.width??""].filter(Boolean).join(" "),children:p.headerRender?p.headerRender():p.header},p.key)})})}),r("tbody",{children:t.map((p,f)=>{const m=n?n(p,f):f,h=c?.(p,f)??"",g=o!==void 0;return r("tr",{onClick:g?()=>o(p,f):void 0,className:[g?"cursor-pointer hover:bg-primary/5":"hover:bg-primary/5",h].filter(Boolean).join(" "),children:e.map(x=>{const b=x.align??"left",y=x.nowrap??!1;return r("td",{className:["px-3 py-2 text-foreground border-b border-border",ip[b],y?"whitespace-nowrap":""].filter(Boolean).join(" "),children:x.render(p,f)},x.key)})},m)})})]})})}function ed({open:e,onClose:t,title:n,subtitle:o,footer:s,children:a,widthClass:i="w-[360px]"}){return J(()=>{if(!e)return;const l=c=>{c.key==="Escape"&&t()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e,t]),e?u("aside",{className:Y("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:[u("header",{className:"flex items-start justify-between gap-2 px-4 py-3 border-b border-border",children:[u("div",{className:"min-w-0",children:[r("div",{className:"text-sm font-semibold text-foreground truncate",children:n}),o!==void 0&&r("div",{className:"text-[11px] text-foreground-subtle mt-0.5 truncate",children:o})]}),r("button",{type:"button",onClick:t,className:"p-1 rounded hover:bg-muted text-foreground-subtle hover:text-foreground","aria-label":"Close panel",children:r(rt,{className:"w-4 h-4"})})]}),r("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3",children:a}),s!==void 0&&r("footer",{className:"flex items-center gap-2 justify-end px-4 py-3 border-t border-border",children:s})]}):null}const c3={inherit:"bg-muted",on:"bg-emerald-500",off:"bg-orange-500",na:"bg-gray-300 opacity-50"};function Pg({node:e,depth:t,selectedAddonId:n,onSelect:o,agentDots:s}){const a=e.addonId===n,i=s?.[e.addonId]??[];return u("div",{children:[u("button",{type:"button",onClick:()=>o(e.addonId),className:Y("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:[r("span",{className:"truncate",children:e.addonName}),i.length>0&&r("span",{className:"flex items-center gap-1 shrink-0",children:i.map(l=>r("span",{title:`${l.agentNodeId}: ${l.state}`,className:Y("w-2 h-2 rounded-full",c3[l.state])},l.agentNodeId))})]}),e.children.map(l=>r(Pg,{node:l,depth:t+1,selectedAddonId:n,onSelect:o,agentDots:s},l.addonId))]})}function _g({tree:e,selectedAddonId:t,onSelect:n,agentDots:o,className:s}){return r("div",{className:Y("flex flex-col py-2",s),children:e.map(a=>r(Pg,{node:a,depth:0,selectedAddonId:t,onSelect:n,agentDots:o},a.addonId))})}function ja(e){const t=[],n=[],o=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):(n.push(l),o.set(i.id,l))}const s=[];for(const a of n){if(a.inputClasses.length===0){s.push(a);continue}const i=n.find(l=>l.addonId!==a.addonId&&l.outputClasses.some(c=>a.inputClasses.includes(c)));i&&i.children.push(a)}return[...s,...t]}function d3(e){return e?e.models.map(t=>({id:t.id,name:t.name})):[]}function Ws({step:e,schema:t,allSchemas:n,depth:o=0,onChange:s,onDelete:a,readOnly:i=!1,toggleMode:l="simple",overrideState:c=null,onOverrideChange:d,inheritedEnabled:p,hideModelAndSettings:f=!1}){const[m,h]=I(!1),g=d3(t);if(g.length>0&&!g.some(b=>b.id===e.modelId)&&!i){const y=(t?.defaultModelId?g.find(w=>w.id===t.defaultModelId):null)??g[0];y&&y.id!==e.modelId&&queueMicrotask(()=>s({...e,modelId:y.id}))}const x=u(me,{children:[u("div",{className:"flex-1 min-w-0",children:[r("span",{className:"text-[10px] uppercase tracking-wider font-medium text-foreground-subtle/60 block leading-none",children:e.slot}),r("span",{className:"text-sm font-semibold text-foreground truncate block leading-tight",children:e.addonName}),u("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(b=>r("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-blue-500/12 text-blue-400",children:b},b)),e.inputClasses.length>0&&e.outputClasses.length>0&&r("span",{className:"text-foreground-subtle/40 text-[10px]",children:"→"}),e.outputClasses.map(b=>r("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-green-500/12 text-green-400",children:b},b))]})]}),!i&&l==="simple"&&r("button",{onClick:b=>{b.stopPropagation(),s({...e,enabled:!e.enabled})},className:Y("relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors",e.enabled?"bg-success":"bg-foreground-subtle/30"),children:r("span",{className:Y("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&&u("div",{className:"flex items-center gap-0.5 rounded-md border border-border p-0.5",onClick:b=>b.stopPropagation(),children:[r(Pi,{label:"Inherit",active:c===null,variant:"inherit",subtext:p===void 0?void 0:p?"on":"off",onClick:()=>d(null)}),r(Pi,{label:"On",active:c===!0,variant:"on",onClick:()=>d(!0)}),r(Pi,{label:"Off",active:c===!1,variant:"off",onClick:()=>d(!1)})]})]});return r(ng,{expanded:m,onExpandedChange:h,dimmed:!e.enabled,header:x,children:f?r("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."}):u("div",{className:"space-y-3",children:[r(Ol,{label:"Model",value:e.modelId,disabled:i,options:g.map(b=>({value:b.id,label:b.name})),onChange:b=>s({...e,modelId:b})}),e.slot==="audio-classifier"&&e.engine&&r(Ol,{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:b=>{const[y,w]=b.split("/");s({...e,engine:{runtime:y,backend:w,format:w==="coreml"?"coreml":"onnx"}})}}),t?.configSchema?.map(b=>r(Ha,{field:b,allFields:t.configSchema??[],step:e,disabled:i,onChange:s},b.key))]})})}function Ol({label:e,value:t,options:n,disabled:o,onChange:s}){return u("div",{children:[r("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e}),u("select",{value:t,onChange:a=>s(a.target.value),disabled:o,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:[n.length===0&&r("option",{value:t,children:t||"default"}),n.map(a=>r("option",{value:a.value,disabled:a.disabled,children:a.label},a.value))]})]})}function u3({label:e,description:t,value:n,options:o,disabled:s,onChange:a}){function i(l){if(s)return;const c=n.includes(l)?n.filter(d=>d!==l):[...n,l];a(c)}return u("div",{children:[r("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1",children:e}),t&&r("p",{className:"text-[10px] text-foreground-subtle/60 mb-1.5",children:t}),r("div",{className:"flex flex-wrap gap-1.5",children:o.map(l=>{const c=n.includes(l.value);return r("button",{type:"button",disabled:s,onClick:()=>i(l.value),className:Y("text-[10px] font-medium px-2 py-1 rounded-md border transition-colors",c?"bg-primary/20 text-primary border-primary/40":"bg-surface text-foreground-subtle border-border hover:border-primary/30",s&&"opacity-50 cursor-not-allowed"),children:l.label},l.value)})})]})}function p3(e,t,n){const o=t.settings?.[e];if(o!==void 0)return o;const s=n.find(a=>"key"in a&&a.key===e);return s&&"default"in s?s.default:void 0}function Ha({field:e,allFields:t,step:n,disabled:o,onChange:s}){const a=e.type!=="separator"&&e.type!=="info"?e.showWhen:void 0;if(a){const{field:l,equals:c,notEquals:d,in:p,notIn:f}=a,m=p3(l,n,t);if(c!==void 0&&m!==c||d!==void 0&&m===d||p!==void 0&&!p.includes(m)||f!==void 0&&f.includes(m))return null}function i(l){s({...n,settings:{...n.settings,[e.key]:l}})}if(e.type==="select"){const l=n.settings?.[e.key],c=typeof l=="string"?l:e.default??"";return r(Ol,{label:e.label,value:c,disabled:o||e.disabled,options:e.options,onChange:i})}if(e.type==="multiselect"){const l=n.settings?.[e.key],c=Array.isArray(l)?l:Array.isArray(e.default)?e.default:[];return r(u3,{label:e.label,description:e.description,value:c,options:e.options,disabled:o||e.disabled,onChange:i})}if(e.type==="slider"||e.type==="number"){const l=n.settings?.[e.key],c=typeof e.default=="number"?e.default:e.min??0,d=typeof l=="number"?l:c,p=e.min??0,f=e.max??1,m=e.step??.01,h=e.type==="slider"?e.showValue:!0,g="unit"in e?e.unit:void 0,x=e.type==="slider"?e.displayScale:void 0,b=x?d/x:d;return u("div",{children:[u("div",{className:"flex items-center justify-between mb-1",children:[r("span",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide",children:e.label}),h&&u("span",{className:"text-xs font-medium text-foreground tabular-nums",children:[typeof b=="number"?b.toFixed(2).replace(/\.?0+$/,""):b,g?` ${g}`:""]})]}),e.description&&r("p",{className:"text-[10px] text-foreground-subtle/60 mb-1.5",children:e.description}),r("input",{type:"range",min:p,max:f,step:m,value:d,disabled:o||e.disabled,onChange:y=>i(Number(y.target.value)),className:"w-full accent-primary h-1.5"})]})}if(e.type==="boolean"){const l=n.settings?.[e.key],c=typeof l=="boolean"?l:e.default===!0;return u("label",{className:"flex items-center gap-2",children:[r("input",{type:"checkbox",checked:c,disabled:o||e.disabled,onChange:d=>i(d.target.checked),className:"h-3.5 w-3.5 accent-primary"}),r("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=n.settings?.[e.key],c=typeof l=="string"?l:e.default??"",d=e.type==="password"?"password":"text";return u("div",{children:[r("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e.label}),e.type==="textarea"?r("textarea",{value:c,disabled:o||e.disabled,placeholder:e.placeholder,onChange:p=>i(p.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"}):r("input",{type:d,value:c,disabled:o||e.disabled,placeholder:e.placeholder,onChange:p=>i(p.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"?r("div",{className:"border-t border-border my-2"}):e.type==="info"?r("div",{className:"rounded-md border border-border bg-surface px-2 py-1.5 text-[10px] text-foreground-subtle",children:e.content}):null}function Pi({label:e,active:t,variant:n,subtext:o,onClick:s}){return u("button",{type:"button",onClick:s,className:Y("px-2 py-1 text-[10px] font-medium rounded transition-colors",t?n==="on"?"bg-green-500/20 text-green-400":n==="off"?"bg-red-500/20 text-red-400":"bg-primary/20 text-primary":"text-foreground-subtle hover:bg-surface-hover"),children:[e,o&&t&&u("span",{className:"ml-1 opacity-60",children:["(",o,")"]})]})}function $g(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 f3(e,t,n){return n?{enabled:n.enabled??t.enabled,modelId:n.modelId??t.modelId,settings:n.settings??t.settings}:t}function m3({addon:e,agentDefault:t,modelsForFormat:n,onChangeAgentConfig:o}){const s=a=>{o?.({...t,...a})};return u("div",{className:"space-y-4 text-xs",children:[u("label",{className:"flex items-center gap-2",children:[r("input",{type:"checkbox",checked:t.enabled,onChange:a=>s({enabled:a.target.checked})}),u("span",{children:["Enabled on this agent (",e.name,")"]})]}),u("div",{children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle mb-1",children:"Model"}),r("select",{className:"w-full bg-surface border border-border rounded px-2 py-1 text-xs",value:t.modelId,onChange:a=>s({modelId:a.target.value}),children:n.map(a=>r("option",{value:a.id,children:a.name},a.id))})]}),(e.configSchema?.length??0)>0&&u("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),e.configSchema?.map(a=>r(Ha,{field:a,allFields:e.configSchema??[],step:$g(e,t),disabled:!1,onChange:i=>s({settings:{...i.settings}})},a.key))]})]})}function h3({addon:e,agentDefault:t,agentNodeId:n,currentPatch:o,modelsForFormat:s,onChangePatch:a}){const i=f3("device",t,o),l=h=>{const g=h.enabled!==void 0||h.modelId!==void 0||h.settings!==void 0;a?.(g?h:null)},c=h=>{const{enabled:g,...x}=o??{},b=h==="inherit"?x:{...x,enabled:h==="on"};l(b)},d=h=>{const{modelId:g,...x}=o??{},b=h===void 0?x:{...x,modelId:h};l(b)},p=h=>{const{settings:g,...x}=o??{},b=h===void 0?x:{...x,settings:h};l(b)},f=o?.enabled===void 0?"inherit":o.enabled?"on":"off",m=o?.modelId!==void 0;return u("div",{className:"space-y-4 text-xs",children:[u("div",{className:"flex items-center gap-1",children:[["inherit","on","off"].map(h=>r("button",{type:"button",onClick:()=>c(h),className:Y("px-3 py-1 border border-border rounded text-xs capitalize",f===h?"bg-primary text-primary-foreground border-primary":"bg-surface text-foreground hover:bg-muted"),children:h},h)),u("span",{className:"ml-2 text-[10px] text-foreground-subtle",children:["agent default: ",r("span",{className:"font-semibold",children:t.enabled?"on":"off"})]})]}),u("div",{children:[u("div",{className:"flex items-center justify-between mb-1",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Model"}),m?r("button",{type:"button",className:"text-[10px] text-foreground-subtle hover:text-foreground",onClick:()=>d(void 0),children:"Clear"}):r("button",{type:"button",className:"text-[10px] text-primary hover:underline",onClick:()=>d(t.modelId),children:"Override"})]}),r("select",{disabled:!m,className:"w-full bg-surface border border-border rounded px-2 py-1 text-xs disabled:opacity-50",value:m?o?.modelId??t.modelId:t.modelId,onChange:h=>d(h.target.value),children:s.map(h=>r("option",{value:h.id,children:h.name},h.id))}),!m&&u("div",{className:"text-[10px] text-foreground-subtle mt-1",children:["inherits from ",n]})]}),(e.configSchema?.length??0)>0&&(()=>{const h=o?.settings!==void 0;return u("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[u("div",{className:"flex items-center justify-between",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),h?r("button",{type:"button",className:"text-[10px] text-foreground-subtle hover:text-foreground",onClick:()=>p(void 0),children:"Clear"}):r("button",{type:"button",className:"text-[10px] text-primary hover:underline",onClick:()=>p({...t.settings}),children:"Override"})]}),e.configSchema?.map(g=>r(Ha,{field:g,allFields:e.configSchema??[],step:$g(e,i),disabled:!h,onChange:x=>p({...x.settings})},g.key)),!h&&u("div",{className:"text-[10px] text-foreground-subtle",children:["inherits from ",n]})]})})(),u("div",{className:"rounded bg-muted/40 px-3 py-2 text-[11px] text-foreground-subtle",children:[r("div",{className:"font-semibold text-foreground mb-0.5",children:"Effective config preview"}),u("div",{className:"font-mono truncate",children:[e.id," · model: ",i.modelId," · ",i.enabled?"on":"off"]})]})]})}function Va(e){const{mode:t,addon:n,agentDefault:o,agentNodeId:s,currentPatch:a,onChangeAgentConfig:i,onChangePatch:l,engineFormat:c}=e,d=q(()=>n.models.filter(p=>!!p.formats[c]),[n.models,c]);return t==="agent"?r(m3,{addon:n,agentDefault:o,modelsForFormat:d,onChangeAgentConfig:i}):r(h3,{addon:n,agentDefault:o,agentNodeId:s,currentPatch:a,modelsForFormat:d,onChangePatch:l})}function g3(e){const t=[],n=(o,s)=>{for(const a of o)t.push({node:a,depth:s}),n(a.children,s+1)};return n(e,0),t}const lp={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 b3({slot:e}){const t=lp[e]??lp.classifier;return r("span",{className:Y("text-[9px] font-semibold uppercase tracking-widest leading-none",t.className),children:t.label})}const cp="inline-flex items-center rounded bg-muted px-1.5 py-px text-[9px] font-medium text-foreground-subtle";function x3({inputs:e,outputs:t}){return e.length===0&&t.length===0?null:u("span",{className:"inline-flex items-center gap-1 flex-wrap",children:[e.map(n=>r("span",{className:Y(cp,"bg-blue-500/10 text-blue-500"),children:n},`in-${n}`)),e.length>0&&t.length>0&&r("span",{className:"text-foreground-subtle/60 text-[9px]",children:"→"}),t.map(n=>r("span",{className:Y(cp,"bg-emerald-500/10 text-emerald-500"),children:n},`out-${n}`))]})}function y3({enabled:e,onChange:t,disabled:n}){return r("button",{type:"button",role:"switch","aria-checked":e,disabled:n,onClick:o=>{o.stopPropagation(),t(!e)},className:Y("relative inline-flex h-3.5 w-7 shrink-0 items-center rounded-full transition-colors",e?"bg-emerald-500":"bg-foreground-subtle/30",n?"opacity-50 cursor-not-allowed":"cursor-pointer"),title:e?"Click to disable":"Click to enable",children:r("span",{className:Y("inline-block h-3 w-3 rounded-full bg-white shadow transition-transform",e?"translate-x-3.5":"translate-x-0.5")})})}function v3(e){return e.kind==="enabled"?u("span",{className:"inline-flex items-center gap-1",children:[r("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500 shrink-0"}),r("span",{className:"font-mono text-foreground",children:e.modelId})]}):e.kind==="disabled"?u("span",{className:"inline-flex items-center gap-1 text-foreground-subtle",children:[r("span",{className:"h-1.5 w-1.5 rounded-full border border-foreground-subtle/60 shrink-0"}),"off"]}):u("span",{className:"inline-flex items-center gap-1 text-foreground-subtle/70",children:[r("span",{className:"h-1.5 w-1.5 rounded-full bg-muted shrink-0"}),"n/a"]})}function w3({node:e,depth:t,agents:n,getCellState:o,onCellClick:s,selectedCell:a,toggleProps:i}){return u(me,{children:[u("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:[u("div",{className:"flex flex-col gap-1 min-w-0 flex-1",children:[r(b3,{slot:e.slot}),u("div",{className:"flex items-center gap-2 flex-wrap",children:[r("span",{className:"font-semibold truncate",children:e.addonName}),r(x3,{inputs:e.inputClasses,outputs:e.outputClasses})]})]}),i&&r("span",{className:"pl-2 pt-0.5 shrink-0",children:r(y3,{enabled:i.enabled,onChange:i.onChange,disabled:i.disabled})})]}),n.map(l=>{const c=o(e.addonId,l.agentNodeId),d=a?.addonId===e.addonId&&a.agentNodeId===l.agentNodeId;return r("button",{type:"button",onClick:()=>s(e.addonId,l.agentNodeId),className:Y("text-left px-3 py-1.5 border-b border-l border-border text-xs hover:bg-muted/40",c.kind==="enabled"&&"bg-emerald-500/5",c.kind==="na"&&"bg-muted/30",d&&"ring-2 ring-primary ring-inset"),children:v3(c)},l.agentNodeId)})]})}function td({tree:e,agents:t,getCellState:n,onCellClick:o,selectedCell:s,onToggleEnabled:a}){const i=q(()=>g3(e),[e]),l=`minmax(320px, 1fr) repeat(${t.length}, minmax(160px, 220px))`,c=a!==void 0&&t.length===1,d=t[0]?.agentNodeId;return r("div",{className:"overflow-auto border border-border rounded",children:u("div",{className:"grid",style:{gridTemplateColumns:l},children:[r("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(p=>u("div",{className:"sticky top-0 z-10 bg-muted/60 px-3 py-2 border-b border-l border-border",children:[r("div",{className:"text-xs font-semibold text-foreground",children:p.agentNodeId}),r("div",{className:"text-[10px] text-foreground-subtle truncate",children:p.engineLabel})]},p.agentNodeId)),i.map(({node:p,depth:f})=>{const m=c&&d!==void 0?n(p.addonId,d):null,h=c&&m!==null?{enabled:m.kind==="enabled",onChange:g=>a?.(p.addonId,g),disabled:m.kind==="na"}:void 0;return r(w3,{node:p,depth:f,agents:t,getCellState:n,onCellClick:o,selectedCell:s,toggleProps:h},p.addonId)})]})})}const Dg=typeof globalThis<"u"?globalThis.__camstackTrpcReact:void 0,S=Dg??i2();typeof globalThis<"u"&&!Dg&&(globalThis.__camstackTrpcReact=S);const nd=wn("camstack:system",null);function rd({system:e,children:t}){return r(nd.Provider,{value:e,children:t})}function De(){const e=Ne(nd);if(!e)throw new Error("useSystem(): no <SystemProvider> in tree");return e}function N3(){return Ne(nd)}function ft(e,t){const n=De(),o=ne(t);o.current=t;const[s,a]=I(n.connectionVersion);J(()=>n.subscribeConnectionEvents((i,l)=>{i==="connected"&&a(l)}),[n]),J(()=>n.subscribeEvent(e,l=>{o.current(l)}),[n,e,s])}function Bl(e){const t=ne(e);return t.current=e,t}function Jr(e,t){const[n,o]=I(null),s=Bl(t);return ft(e,a=>{const i=a.data,l=s.current;l&&!l(i)||o(i)}),n}function od(e,t,n){const[o,s]=I(()=>new Map),a=Bl(t),i=Bl(n);ft(e,c=>{const d=c.data,p=i.current;if(p&&!p(d))return;const f=a.current(d);s(m=>{const h=new Map(m);return h.set(f,d),h})});const l=q(()=>Array.from(o.values()),[o]);return{map:o,values:l}}function eo(){const{data:e,isLoading:t}=S.nodes.topology.useQuery(void 0,{staleTime:6e4}),o=Jr("cluster.topology-snapshot")?.nodes??e;return{nodes:q(()=>{const a=[];for(const i of o??[])a.push({id:String(i.id??""),name:String(i.name??i.id??""),shortName:i.isHub?"HUB":String(i.name??i.id??""),isHub:!!i.isHub,isOnline:!!i.isOnline,localIps:i.localIps??[],addons:(i.addons??[]).map(l=>({addonId:l.id,capabilities:l.capabilities}))});return a.sort((i,l)=>i.isHub!==l.isHub?i.isHub?-1:1:i.name.localeCompare(l.name)),a},[o]),isLoading:t}}function Lg({selectedNodeId:e,onSelect:t,label:n="Node",hideIcon:o=!1,alwaysShow:s=!1}){const{nodes:a}=eo();return!s&&a.length<=1?null:u("div",{className:"flex items-center gap-1.5",children:[!o&&r(lC,{className:"h-3.5 w-3.5 text-foreground-subtle"}),n&&r("span",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:n}),r("div",{className:"flex rounded-md border border-border overflow-hidden text-[11px] font-medium",children:a.map((i,l)=>{const c=e===i.id;return r("button",{type:"button",onClick:()=>t(i.id),disabled:!i.isOnline,title:i.isOnline?i.name:`${i.name} (offline)`,className:Y("px-2.5 py-1 transition-colors",c?"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)})})]})}const k3={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 S3({status:e,showDot:t=!0,showLabel:n=!0,size:o="sm",className:s}){const a=k3[e];return u("span",{className:Y("inline-flex items-center gap-1.5",o==="sm"?"text-xs":"text-sm",s),children:[t&&r("span",{className:Y("h-1.5 w-1.5 shrink-0 rounded-full",a.colorClass),"aria-hidden":"true"}),n&&r("span",{className:"text-foreground",children:a.label})]})}const C3={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 M3({provider:e,showLabel:t=!0,className:n}){const o=C3[e];return u("span",{className:Y("inline-flex items-center gap-1.5 text-xs",n),children:[r("span",{className:Y("h-1.5 w-1.5 shrink-0 rounded-sm",o.colorClass),"aria-hidden":"true"}),t&&r("span",{className:"text-foreground",children:o.label})]})}const A3={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 Tg({children:e,variant:t="neutral",mono:n,className:o}){return r("span",{className:Y("inline-flex items-center rounded-md px-2 py-0.5 text-[11px] font-bold leading-tight",n&&"font-mono",A3[t],o),children:e})}function E3({version:e,preRelease:t,className:n}){const o=t??/-(alpha|beta|rc|dev|canary|next)/i.test(e);return r(Tg,{variant:o?"warning":"success",mono:!0,className:n,children:e})}function I3({label:e,description:t,error:n,required:o,children:s,orientation:a="vertical",className:i}){const l=a==="horizontal";return u("div",{className:Y("flex gap-2",l?"flex-row items-center justify-between":"flex-col",i),children:[u("div",{className:Y(l?"flex-1":""),children:[u(qc,{children:[e,o&&r("span",{className:"text-danger ml-0.5",children:"*"})]}),t&&r("p",{className:"text-foreground-subtle text-xs mt-0.5",children:t})]}),r("div",{className:Y(l?"shrink-0":""),children:s}),n&&r("p",{className:"text-danger text-xs",children:n})]})}function P3({title:e,subtitle:t,actions:n,className:o}){return u("div",{className:Y("flex flex-col gap-2 mb-3 sm:flex-row sm:items-center sm:justify-between",o),children:[u("div",{children:[r("h1",{className:"text-sm font-semibold text-foreground",children:e}),t&&r("p",{className:"text-foreground-subtle text-xs",children:t})]}),n&&r("div",{className:"flex items-center gap-2 flex-wrap",children:n})]})}function sd({icon:e,title:t,description:n,action:o,className:s}){return u("div",{className:Y("flex flex-col items-center justify-center gap-3 py-12",s),children:[e&&r(e,{className:"h-12 w-12 text-foreground-subtle","aria-hidden":"true"}),u("div",{className:"flex flex-col items-center gap-1 text-center",children:[r("p",{className:"text-foreground-muted text-sm font-medium",children:t}),n&&r("p",{className:"text-foreground-subtle text-xs max-w-xs",children:n})]}),o&&r("div",{className:"mt-1",children:o})]})}const _3={danger:{box:"border-danger/40 bg-danger/10",icon:"text-danger",title:"text-danger",message:"text-danger"},warning:{box:"border-amber-500/40 bg-amber-500/10",icon:"text-amber-600 dark:text-amber-400",title:"text-amber-700 dark:text-amber-300",message:"text-amber-700 dark:text-amber-300"}};function Zo({message:e,title:t,onRetry:n,action:o,variant:s="danger",className:a}){const i=_3[s],l=s==="warning"?Xr:Kr;return u("div",{role:"alert",className:Y("flex items-start gap-2.5 rounded border px-3 py-2.5",i.box,a),children:[r(l,{className:Y("h-4 w-4 mt-0.5 shrink-0",i.icon),"aria-hidden":"true"}),u("div",{className:"flex-1 min-w-0",children:[t&&r("p",{className:Y("text-xs font-semibold",i.title),children:t}),r("div",{className:Y("text-xs break-words",i.message,t?"mt-0.5":""),children:e})]}),o??(n&&u("button",{type:"button",onClick:n,className:Y("shrink-0 inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium","border border-current/30 hover:bg-current/10 transition-colors",i.message),children:[r(za,{className:"h-3 w-3","aria-hidden":"true"}),"Retry"]}))]})}const Rg=wn("camstack:confirm-dialog",null);function st(){const e=Ne(Rg);if(!e)throw new Error("useConfirm must be used within ConfirmDialogProvider");return e.confirm}function Og({children:e}){const[t,n]=I(null),o=U(c=>new Promise(d=>{n({...c,resolve:d})}),[]),s=()=>{t?.resolve(!0),n(null)},a=()=>{t?.resolve(!1),n(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 u(Rg.Provider,{value:{confirm:o},children:[e,t&&u("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[r("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:a}),u("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:c=>c.stopPropagation(),children:[u("div",{className:"px-5 pt-5 pb-4",children:[r("h3",{className:"text-sm font-semibold text-foreground",children:t.title}),r("p",{className:"mt-2 text-xs text-foreground-subtle leading-relaxed",children:t.message})]}),u("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border bg-surface-hover/30",children:[r("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"}),r("button",{type:"button",onClick:s,className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${l.button}`,children:t.confirmLabel??"Confirm"})]})]})]})]})}function $3({value:e,label:t,trend:n,className:o}){return u(mn,{className:Y("flex flex-col gap-1",o),children:[u("div",{className:"flex items-baseline gap-2",children:[r("span",{className:"text-2xl font-semibold text-foreground",children:e}),n&&u("span",{className:Y("inline-flex items-center gap-0.5 text-xs font-medium",n.direction==="up"?"text-success":"text-danger"),children:[n.direction==="up"?r(IC,{className:"h-3 w-3"}):r(_C,{className:"h-3 w-3"}),n.value,"%"]})]}),r("span",{className:"text-xs text-foreground-muted",children:t})]})}function D3({items:e,className:t}){return r("dl",{className:Y("flex flex-col",t),children:e.map(n=>u("div",{className:"flex items-center h-7",children:[r("dt",{className:"text-foreground-subtle text-xs w-1/3 shrink-0",children:n.key}),r("dd",{className:"text-foreground text-xs",children:n.value})]},n.key))})}function L3({children:e,maxHeight:t=300,className:n}){const[o,s]=I(!1),a=U(()=>{navigator.clipboard.writeText(e).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)})},[e]);return u("div",{className:Y("relative group",n),children:[r(Zc,{style:{maxHeight:t},children:r("pre",{className:"font-mono text-xs bg-surface p-3 rounded-md border border-border-subtle",children:r("code",{children:e})})}),r("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity",children:r(Uc,{icon:o?Wr:jn,"aria-label":"Copy code",variant:"ghost",size:"sm",onClick:a})})]})}function T3({filters:e,values:t,onChange:n,className:o}){const s=pr(),[a,i]=I(!1),l=(d,p)=>{n({...t,[d]:p})},c=Object.values(t).filter(d=>d!==void 0&&d!=="").length;if(s){const d=e.find(f=>f.type==="search"),p=e.some(f=>f.type!=="search");return u("div",{className:Y("flex items-center gap-2",o),children:[d&&r(la,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:f=>l(d.key,f.target.value),leftSlot:r(Lo,{className:"h-3 w-3 text-foreground-subtle"}),className:"flex-1"}),p&&u(me,{children:[u("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:[r(hC,{className:"h-3.5 w-3.5"}),"Filters",c>0&&r(Kt,{variant:"info",className:"ml-1 text-[10px] px-1 py-0",children:c})]}),r(Yc,{open:a,onClose:()=>i(!1),title:"Filters",children:r("div",{className:"flex flex-col gap-3",children:e.filter(f=>f.type!=="search").map(f=>{switch(f.type){case"select":return u("div",{children:[r("label",{className:"text-xs text-foreground-muted mb-1 block",children:f.label}),r(To,{options:f.options,value:t[f.key]??"",onChange:m=>l(f.key,m.target.value),className:"w-full"})]},f.key);case"badge-toggle":return r("div",{className:"flex items-center gap-1 flex-wrap",children:f.options.map(m=>{const g=t[f.key]===m.value;return r("button",{type:"button",onClick:()=>l(f.key,g?void 0:m.value),children:r(Kt,{variant:g?"info":"default",className:"cursor-pointer",children:m.label})},m.value)})},f.key);default:return null}})})})]})]})}return r("div",{className:Y("flex items-center gap-2 flex-wrap",o),children:e.map(d=>{switch(d.type){case"search":return r(la,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:p=>l(d.key,p.target.value),leftSlot:r(Lo,{className:"h-3 w-3 text-foreground-subtle"}),className:"w-48"},d.key);case"select":return r(To,{options:d.options,value:t[d.key]??"",onChange:p=>l(d.key,p.target.value),className:"w-36"},d.key);case"badge-toggle":return r("div",{className:"flex items-center gap-1",children:d.options.map(p=>{const m=t[d.key]===p.value;return r("button",{type:"button",onClick:()=>l(d.key,m?void 0:p.value),children:r(Kt,{variant:m?"info":"default",className:"cursor-pointer",children:p.label})},p.value)})},d.key);default:return null}})})}function zl({label:e,icon:t,href:n,badge:o,active:s=!1,className:a}){return u("a",{href:n,className:Y("flex items-center gap-2 h-7 px-2 text-[11px] transition-colors",s?"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:[r(t,{className:"h-3.5 w-3.5 shrink-0"}),r("span",{className:"truncate flex-1",children:e}),o!==void 0&&r(Kt,{className:"ml-auto text-[10px] px-1.5 py-0",children:o})]})}function Fl({logo:e,sections:t,footer:n,onNavigate:o,className:s}){return u("nav",{className:Y("bg-surface border-r border-border h-full flex flex-col",s),children:[e&&r("div",{className:"px-3 py-2 shrink-0",children:e}),r("div",{className:"flex-1 overflow-auto px-1 py-1",children:t.map((a,i)=>u("div",{className:Y(i>0?"mt-3":""),children:[a.label&&r("span",{className:"text-[10px] text-foreground-disabled uppercase tracking-wider px-2 mb-1 block",children:a.label}),r("div",{className:"flex flex-col gap-0.5",onClick:o,children:a.items.map(l=>r(zl,{...l},l.href))})]},i))}),n&&n.length>0&&u("div",{className:"shrink-0 px-1 pb-1",children:[r(Qc,{className:"mb-1"}),r("div",{className:"flex flex-col gap-0.5",onClick:o,children:n.map(a=>r(zl,{...a},a.href))})]})]})}function R3({sidebar:e,header:t,mobileLogo:n,mobileActions:o,children:s,className:a}){const i=pr(),[l,c]=I(!1);return u("div",{className:Y("flex h-screen",a),children:[!i&&r(Fl,{...e,className:Y("w-44",e.className)}),i&&r(Xc,{open:l,onClose:()=>c(!1),width:"w-64",children:r(Fl,{...e,onNavigate:()=>c(!1),className:"w-full border-r-0"})}),u("div",{className:"flex flex-1 flex-col min-w-0",children:[i&&u("header",{className:"flex items-center h-12 border-b border-border px-3 shrink-0 bg-surface/80 backdrop-blur-sm",children:[r("button",{onClick:()=>c(!0),className:"p-1.5 -ml-1.5 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors","aria-label":"Open menu",children:r(PS,{className:"h-5 w-5"})}),n&&r("div",{className:"flex-1 flex justify-center",children:n}),o&&r("div",{className:"shrink-0",children:o})]}),!i&&t&&u("header",{className:"flex items-center h-10 border-b border-border px-4 shrink-0",children:[t.breadcrumbs&&t.breadcrumbs.length>0&&r("nav",{className:"flex items-center gap-1 text-xs flex-1 min-w-0",children:t.breadcrumbs.map((d,p)=>{const f=p===t.breadcrumbs.length-1;return u("span",{className:"flex items-center gap-1",children:[p>0&&r(Fn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),d.href&&!f?r("a",{href:d.href,className:"text-foreground-subtle hover:text-foreground transition-colors truncate",children:d.label}):r("span",{className:"text-foreground truncate",children:d.label})]},p)})}),t.actions&&r("div",{className:"flex items-center gap-2 ml-auto shrink-0",children:t.actions})]}),r("main",{className:"flex-1 overflow-auto p-4",children:s})]})]})}const O3={online:"bg-success",offline:"bg-danger",warning:"bg-warning",unknown:"bg-foreground-subtle"};function B3({title:e,subtitle:t,status:n,selected:o,onClick:s,badges:a,actions:i,offlineAction:l,className:c}){const d=n==="offline";return u("div",{onClick:s,className:Y("w-full rounded-lg border p-3 text-left transition-colors",s&&"cursor-pointer",o?"border-primary bg-primary/10":"border-border bg-surface hover:bg-surface-hover",d&&!o&&"opacity-50",c),children:[u("div",{className:"flex items-center justify-between mb-2",children:[r("span",{className:"text-sm font-medium truncate",children:e}),n&&r("span",{className:Y("h-2 w-2 rounded-full shrink-0",O3[n])})]}),t&&r("div",{className:"text-[11px] text-foreground-muted",children:t}),a&&a.length>0&&r("div",{className:"flex flex-wrap gap-1 mt-2",children:a.map((p,f)=>{const m=Y("rounded px-1.5 py-0.5 text-[10px] flex items-center gap-0.5",o?"bg-primary/20":"bg-surface-hover",p.onClick&&"hover:opacity-80 transition-opacity cursor-pointer");return p.onClick?u("button",{onClick:h=>{h.stopPropagation(),p.onClick()},className:m,children:[p.icon,p.label]},f):u("span",{className:m,children:[p.icon,p.label]},f)})}),!d&&i&&i.length>0&&r("div",{className:"flex items-center gap-0.5 mt-2 -mb-1",children:i.map((p,f)=>r("button",{onClick:m=>{m.stopPropagation(),p.onClick()},className:"p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors",title:p.label,"aria-label":p.label,children:p.icon},f))}),d&&l&&r("div",{className:"mt-2",onClick:p=>p.stopPropagation(),children:l})]})}function z3({children:e,minCardWidth:t=220,gap:n=3,className:o}){return r("div",{className:Y("p-4 overflow-y-auto flex-1 content-start",o),style:{display:"grid",gridTemplateColumns:`repeat(auto-fill, minmax(${t}px, 1fr))`,gap:`${n*4}px`},children:e})}const F3="capability.binding-changed";function wt(e,t){const[n,o]=I(null);return J(()=>{if(t===null){o(null);return}let s=!1;const a=async()=>{try{const l=await e.deviceManager.getBindings.query({deviceId:t});s||o(l)}catch{s||o(l=>l)}};a();const i=e.live?.onEvent.subscribe({category:F3},{onData:l=>{const c=l.data?.source;if(!c){a();return}c.type==="device"&&c.id===t&&a()}});return()=>{s=!0,i?.unsubscribe()}},[e,t]),q(()=>n?d2(e,n):null,[e,n])}function hn(e){const t=U(o=>e?e.subscribe(()=>o()):()=>{},[e]),n=U(()=>e?.value,[e]);return Oa(t,n,n)}function Bg(e,t,n){const o=wt(e,t),s=o?n(o.state):void 0;return hn(s)}function to(e){const t=wt(e.trpc,e.deviceId),n=t!==null?e.slice(t):void 0,o=hn(n),s=t!==null?e.cap(t):void 0,c=(e.requireFeature===void 0||(e.deviceFeatures??[]).includes(e.requireFeature))&&s!==void 0&&o!==void 0;return{dev:t,cap:s,slice:o,available:c}}function j3(e){return e.parentDeviceId===null?"top-level":e.role?"accessory":"adopted"}const H3={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 V3(e){const t=H3[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}}const U3={siren:Ba,floodlight:Gh,spotlight:Jh,"pir-sensor":Yh,chime:RS,autotrack:Fc,nightvision:Hc,"privacy-mask":jc,doorbell:Hh},q3={camera:zc,hub:Dl,nvr:Dl,light:Gh,siren:Ba,switch:MC,sensor:Yh,thermostat:SC,button:F5,generic:Vc};function zg(e){return e.role?U3[e.role]??Vc:q3[e.type.toLowerCase()]??zc}const Fg={"native-snapshot":bS,"two-way-audio":Wh,"pan-tilt-zoom":Fc,"ptz-autotrack":AS,"doorbell-button":Hh,"motion-trigger":Pn,"battery-operated":Fh,rebootable:Xh},jg={"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"},Q3={"native-snapshot":"snapshot",rebootable:"reboot","pan-tilt-zoom":"ptz","ptz-autotrack":"ptz-autotrack","two-way-audio":"intercom","motion-trigger":"motion-trigger"},Hg=new Set(["camera","hub","nvr"]);function Vg(e){return!Hg.has(e.type.toLowerCase())}function dp(e){return e.role?!0:!Hg.has(e.type.toLowerCase())}function Ug(e){return(e.features??[]).includes("motion-trigger")}function G3(e){if(e.length<=24)return e;const t=e.lastIndexOf(":");if(t>=0&&t<e.length-4)return e.slice(t+1);const n=e.split("-");if(n.length>2){const o=n.slice(-2).join("-");if(o.length>=6)return o}return`…${e.slice(-18)}`}function W3({trpc:e,accessoryChildren:t,adoptedChildren:n,onNavigate:o}){return u("div",{className:"border-t border-border-subtle/50",children:[n.length>0&&r(up,{trpc:e,label:"Adopted devices",rows:n,onNavigate:o}),t.length>0&&r(up,{trpc:e,label:"Accessories",rows:t,onNavigate:o})]})}function up({trpc:e,label:t,rows:n,onNavigate:o}){return u("div",{children:[r("div",{className:"px-3 pt-1.5 pb-1 text-[9px] font-semibold uppercase tracking-wide text-foreground-subtle",children:t}),r("ul",{children:n.map(s=>r(K3,{trpc:e,child:s,onNavigate:o},s.id))})]})}function K3({trpc:e,child:t,onNavigate:n}){const o=!t.disabled,s=o&&Vg(t),a=o&&Ug(t),i=zg(t);return r("li",{children:u("div",{onClick:l=>{l.stopPropagation(),n(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:[r(i,{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),r("span",{className:"text-[10.5px] text-foreground flex-1 truncate",children:t.name}),a&&r(Z3,{trpc:e,deviceId:t.id,features:t.features}),s&&r(Y3,{trpc:e,deviceId:t.id}),r("span",{className:Y("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 Y3({trpc:e,deviceId:t}){const{dev:n,cap:o,slice:s,available:a}=to({trpc:e,deviceId:t,cap:f=>f.switch,slice:f=>f.state.switch}),[i,l]=I(!1);if(n!==null&&!o)return null;const c=s?.on===!0,d={transform:c?"translateX(14px)":"translateX(2px)"},p=async f=>{if(f.stopPropagation(),!(i||!a||!o)){l(!0);try{await o.setState({on:!c})}finally{l(!1)}}};return r("button",{type:"button",onClick:f=>{p(f)},disabled:i||!a,className:Y("relative inline-flex h-4 w-7 items-center rounded-full border transition-colors flex-shrink-0",c?"bg-success/30 border-success/50":"bg-surface-hover border-border",i&&"opacity-60",!a&&"opacity-40 cursor-not-allowed"),title:a?c?"Turn off":"Turn on":"Awaiting state…","aria-pressed":c,children:r("span",{className:Y("absolute h-3 w-3 rounded-full transition-all",c?"bg-success":"bg-foreground-subtle"),style:d})})}function Z3({trpc:e,deviceId:t,features:n}){const{dev:o,cap:s,slice:a,available:i}=to({trpc:e,deviceId:t,cap:f=>f.motionTrigger,slice:f=>f.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:n}),[l,c]=I(!1);if(o!==null&&!s)return null;const d=a?.enabled===!0,p=async f=>{if(f.stopPropagation(),!(l||!i||!s)){c(!0);try{await s.setMotionTrigger({enabled:!d})}finally{c(!1)}}};return r("button",{type:"button",onClick:f=>{p(f)},disabled:l||!i,className:Y("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:r(Pn,{className:"h-2.5 w-2.5"})})}const pp={up:{pan:0,tilt:1},down:{pan:0,tilt:-1},left:{pan:-1,tilt:0},right:{pan:1,tilt:0},"up-left":{pan:-1,tilt:1},"up-right":{pan:1,tilt:1},"down-left":{pan:-1,tilt:-1},"down-right":{pan:1,tilt:-1}};function ad(e,t,n){const o=n?.defaultSpeed??.5,s=n?.pulseMs??250,a=n?.enabled??!0,l=wt(e,a?t:null)?.ptz,[c,d]=I([]),[p,f]=I(null),[m,h]=I(!1),[g,x]=I(null),b=U(async()=>{if(!(!a||!l))try{const E=await l.getPresets({});d(E)}catch(E){if(Do(E))return;x(E instanceof Error?E.message:String(E))}},[l,a]),y=U(async()=>{if(!(!a||!l))try{const E=await l.getOptions({});f(E)}catch(E){if(Do(E))return;x(E instanceof Error?E.message:String(E))}},[l,a]);J(()=>{b(),y()},[b,y]);const w=U(async E=>{if(!(!a||!l)){x(null),h(!0);try{return await E()}catch(R){x(R instanceof Error?R.message:String(R));return}finally{h(!1)}}},[a,l]),v=U(async(E,R)=>{if(!l)return;const O=pp[E],A=R??o;await w(async()=>{await l.move({pan:O.pan,tilt:O.tilt,speed:A}),await new Promise(P=>setTimeout(P,s)),await l.stop({})})},[l,o,s,w]),N=U(async(E,R)=>{if(!l)return;const O=pp[E],A=R??o;await w(()=>l.continuousMove({pan:O.pan,tilt:O.tilt,speed:A}))},[l,o,w]),k=U(async()=>{l&&await w(()=>l.stop({}))},[l,w]),C=U(async(E,R)=>{if(!l)return;const O=E==="in"?1:-1,A=R??o;await w(async()=>{await l.move({zoom:O,speed:A}),await new Promise(P=>setTimeout(P,s)),await l.stop({})})},[l,o,s,w]),D=U(async()=>{l&&await w(()=>l.goHome({}))},[l,w]),M=U(async E=>{l&&await w(()=>l.goToPreset({presetId:E}))},[l,w]),_=U(async E=>{if(l)return w(async()=>{const R=new Set(c.map(P=>Number(P.id)).filter(P=>Number.isInteger(P)&&P>=0));let O=0;for(;R.has(O);)O+=1;const A=String(O);return await l.savePreset({presetId:A,name:E}),await b(),A})},[l,c,b,w]),$=U(async E=>{l&&await w(async()=>{await l.deletePreset({presetId:E}),await b()})},[l,b,w]);return{move:v,startContinuous:N,stopContinuous:k,zoom:C,goHome:D,goToPreset:M,savePreset:_,deletePreset:$,presets:c,refreshPresets:b,options:p,busy:m,error:g}}function gs({direction:e,icon:t,disabled:n,className:o,variant:s,onMove:a,onStart:i,onStop:l}){const[c,d]=I(null),[p,f]=I(!1),m=U(w=>{if(n)return;w.currentTarget.setPointerCapture(w.pointerId),d(Date.now()),f(!1);const v=setTimeout(()=>{f(!0),i(e)},250);w.currentTarget.dataset.timer=String(v)},[e,n,i]),h=U(w=>{const v=Number(w.currentTarget.dataset.timer);v&&clearTimeout(v),w.currentTarget.dataset.timer="",p?l():c!==null&&a(e),d(null),f(!1)},[p,e,a,l,c]),g=U(w=>{const v=Number(w.currentTarget.dataset.timer);v&&clearTimeout(v),w.currentTarget.dataset.timer="",p&&l(),d(null),f(!1)},[p,l]),x=s==="panel"?"h-9 w-9":"h-7 w-7",b=s==="panel"?"h-4 w-4":"h-3.5 w-3.5";return r("button",{type:"button",disabled:n,onPointerDown:m,onPointerUp:h,onPointerCancel:g,className:Y("flex items-center justify-center rounded transition-colors disabled:opacity-40",s==="panel"?"text-foreground hover:bg-surface-hover active:bg-surface-hover/80":"text-white hover:bg-white/15 active:bg-white/25",x,o),title:e,children:r(t,{className:b})})}function id({controls:e,mode:t="overlay",showPresets:n,showZoom:o=!0,showHome:s=!0,className:a}){const{move:i,startContinuous:l,stopContinuous:c,zoom:d,goHome:p,goToPreset:f,savePreset:m,deletePreset:h,presets:g,options:x,busy:b,error:y}=e,w=st(),[v,N]=I(!1),[k,C]=I(""),D=(n??g.length>0)&&g.length>0,M=t==="panel",_=M&&(x?.supportsPresets??!1),$=x?.maxPresets!==void 0&&g.length>=x.maxPresets,E=U(async()=>{const T=k.trim();if(!T||b||$)return;await m(T)!==void 0&&C("")},[k,b,$,m]),R=U(async(T,F)=>{await w({title:"Delete preset",message:`Delete PTZ preset "${F}"? This removes it from the camera.`,confirmLabel:"Delete",variant:"danger"})&&await h(T)},[w,h]),O=M?"flex flex-col items-stretch gap-2 w-full h-full p-3":"pointer-events-auto absolute top-3 right-3 z-10 flex flex-col items-end gap-2",A=Y(M?"flex items-center gap-3 rounded-lg p-2":"flex items-center gap-2 rounded-lg border border-white/30 bg-zinc-900/90 backdrop-blur-md p-2 shadow-lg shadow-black/40",b&&"ring-1 ring-primary/40"),P=M?"h-9 w-9":"h-7 w-7",L=M?"h-4 w-4":"h-3.5 w-3.5",B=M?"text-foreground hover:bg-surface-hover":"text-white hover:bg-white/15",z=M?"h-12 w-px bg-border mx-1":"h-12 w-px bg-white/15 mx-1";return u("div",{className:Y(O,a),children:[y&&u("div",{className:"rounded bg-danger/90 px-2 py-1 text-[10px] font-medium text-white shadow-lg max-w-[200px] self-center",children:["PTZ: ",y]}),u("div",{className:Y(A,M&&"justify-center"),children:[u("div",{className:"grid grid-cols-3 gap-0.5",children:[r("span",{"aria-hidden":!0,className:M?"h-9 w-9":"h-7 w-7"}),r(gs,{direction:"up",icon:c5,variant:t,onMove:i,onStart:l,onStop:c}),r("span",{"aria-hidden":!0,className:M?"h-9 w-9":"h-7 w-7"}),r(gs,{direction:"left",icon:r5,variant:t,onMove:i,onStart:l,onStop:c}),r("span",{"aria-hidden":!0,className:M?"h-9 w-9":"h-7 w-7"}),r(gs,{direction:"right",icon:s5,variant:t,onMove:i,onStart:l,onStop:c}),r("span",{"aria-hidden":!0,className:M?"h-9 w-9":"h-7 w-7"}),r(gs,{direction:"down",icon:t5,variant:t,onMove:i,onStart:l,onStop:c}),r("span",{"aria-hidden":!0,className:M?"h-9 w-9":"h-7 w-7"})]}),(o||s)&&r("div",{className:z}),u("div",{className:"flex flex-col gap-0.5",children:[o&&u(me,{children:[r("button",{type:"button",onClick:()=>d("in"),disabled:b,title:"Zoom in",className:Y("flex items-center justify-center rounded disabled:opacity-40",P,B),children:r(VC,{className:L})}),r("button",{type:"button",onClick:()=>d("out"),disabled:b,title:"Zoom out",className:Y("flex items-center justify-center rounded disabled:opacity-40",P,B),children:r(qC,{className:L})})]}),s&&r("button",{type:"button",onClick:()=>p(),disabled:b,title:"Go home",className:Y("flex items-center justify-center rounded disabled:opacity-40",P,B),children:r(Qh,{className:L})})]}),D&&u("div",{className:"relative",children:[u("button",{type:"button",onClick:()=>N(T=>!T),disabled:b,className:Y("flex items-center gap-1 rounded px-2 text-[10px] disabled:opacity-40",M?"h-9 text-foreground hover:bg-surface-hover":"h-7 text-white hover:bg-white/15"),title:"Presets",children:["Presets",r(zn,{className:Y("h-3 w-3 transition-transform",v&&"rotate-180")})]}),v&&r("div",{className:Y("absolute right-0 top-full mt-1 min-w-[140px] rounded-lg shadow-xl py-1 z-20",M?"bg-surface border border-border":"border border-white/30 bg-zinc-900/95 backdrop-blur-md"),children:g.map(T=>u("div",{className:Y("group flex items-center",M?"hover:bg-surface-hover":"hover:bg-white/15"),children:[r("button",{type:"button",onClick:()=>{f(T.id),N(!1)},disabled:b,className:Y("flex-1 px-3 py-1.5 text-left text-[10px] disabled:opacity-40",M?"text-foreground":"text-white"),children:T.name||T.id}),_&&r("button",{type:"button",onClick:()=>void R(T.id,T.name||T.id),disabled:b,title:`Delete preset ${T.name||T.id}`,className:Y("mr-1 flex h-5 w-5 shrink-0 items-center justify-center rounded","text-foreground-subtle hover:bg-danger/15 hover:text-danger disabled:opacity-40"),children:r(rt,{className:"h-3 w-3"})})]},T.id))})]})]}),_&&u("div",{className:"flex flex-col gap-1 rounded-lg border border-border p-2",children:[u("div",{className:"flex items-center gap-2",children:[r("input",{type:"text",value:k,onChange:T=>C(T.target.value),onKeyDown:T=>{T.key==="Enter"&&E()},disabled:b||$,placeholder:"New preset name",maxLength:64,className:Y("min-w-0 flex-1 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground","placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary/50","disabled:opacity-40")}),u("button",{type:"button",onClick:()=>void E(),disabled:b||$||k.trim().length===0,title:$?`Camera preset limit reached (${x?.maxPresets})`:"Save current position as a new preset",className:Y("flex h-7 shrink-0 items-center gap-1 rounded px-2 text-[10px] font-medium","bg-primary/15 text-primary hover:bg-primary/25 disabled:opacity-40"),children:[r(Zr,{className:"h-3 w-3"}),"Save current position"]})]}),$&&u("span",{className:"text-[10px] text-foreground-subtle",children:["Camera preset limit reached (",x?.maxPresets,"). Delete a preset to add a new one."]})]})]})}function qg({trpc:e,device:t,flags:n}){if(!!t.disabled)return null;const s=n.showSwitchToggle&&Vg(t),a=Ug(t),i=(t.features??[]).includes("rebootable"),l=(t.features??[]).includes("pan-tilt-zoom");return u(me,{children:[a&&r(J3,{trpc:e,deviceId:t.id,features:t.features}),s&&r(X3,{trpc:e,deviceId:t.id}),l&&r(nM,{trpc:e,deviceId:t.id}),i&&r(eM,{trpc:e,deviceId:t.id})]})}function X3({trpc:e,deviceId:t}){const{dev:n,cap:o,slice:s,available:a}=to({trpc:e,deviceId:t,cap:f=>f.switch,slice:f=>f.state.switch}),[i,l]=I(!1);if(n!==null&&!o)return null;const c=s?.on===!0,d={transform:c?"translateX(14px)":"translateX(2px)"},p=async f=>{if(f.stopPropagation(),!(i||!a||!o)){l(!0);try{await o.setState({on:!c})}finally{l(!1)}}};return r("button",{type:"button",onClick:f=>{p(f)},disabled:i||!a,className:Y("relative inline-flex h-4 w-7 items-center rounded-full border transition-colors flex-shrink-0",c?"bg-success/30 border-success/50":"bg-surface-hover border-border",i&&"opacity-60",!a&&"opacity-40 cursor-not-allowed"),title:a?c?"Turn off":"Turn on":"Awaiting state…","aria-pressed":c,children:r("span",{className:Y("absolute h-3 w-3 rounded-full transition-all",c?"bg-success":"bg-foreground-subtle"),style:d})})}function J3({trpc:e,deviceId:t,features:n}){const{dev:o,cap:s,slice:a,available:i}=to({trpc:e,deviceId:t,cap:f=>f.motionTrigger,slice:f=>f.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:n}),[l,c]=I(!1);if(o!==null&&!s)return null;const d=a?.enabled===!0,p=async f=>{if(f.stopPropagation(),!(l||!i||!s)){c(!0);try{await s.setMotionTrigger({enabled:!d})}finally{c(!1)}}};return r("button",{type:"button",onClick:f=>{p(f)},disabled:l||!i,className:Y("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:r(Pn,{className:"h-2.5 w-2.5"})})}const _i=168,Qg=4;function eM({trpc:e,deviceId:t}){const{dev:n,cap:o}=to({trpc:e,deviceId:t,cap:b=>b.reboot,slice:()=>{}}),s=ne(null),a=ne(null),[i,l]=I(null),[c,d]=I(!1),p=n!==null&&o!==void 0&&o!==null,f=i!==null,m=()=>l(null),h=()=>{const b=s.current;if(!b)return;const y=b.getBoundingClientRect(),w=y.right-_i,v=Math.max(8,Math.min(w,window.innerWidth-_i-8)),N=y.bottom+Qg;l({top:N,left:v})};if(J(()=>{if(!f)return;const b=w=>{const v=s.current,N=a.current,k=w.target;k!==null&&(v&&v.contains(k)||N&&N.contains(k)||m())},y=w=>{w.key==="Escape"&&(w.stopPropagation(),m())};return document.addEventListener("mousedown",b),document.addEventListener("keydown",y),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("keydown",y)}},[f]),n!==null&&!o)return null;const g=b=>{b.stopPropagation(),f?m():h()},x=async()=>{if(!(c||!p||!o)){d(!0),m();try{await o.reboot({})}finally{d(!1)}}};return u(me,{children:[r("button",{ref:s,type:"button",onClick:g,disabled:c||!p,className:Y("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",(c||!p)&&"opacity-50",f&&"bg-surface-hover text-foreground"),title:"More actions","aria-label":"More actions","aria-haspopup":"menu","aria-expanded":f,children:r(Vh,{className:"h-3 w-3"})}),i&&Qr(r("div",{ref:a,role:"menu",style:{position:"fixed",top:i.top,left:i.left,width:_i},className:"z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-1",onClick:b=>b.stopPropagation(),children:u("button",{type:"button",role:"menuitem",onClick:()=>{x()},disabled:c||!p,className:Y("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:[r(Xh,{className:"h-3 w-3 shrink-0 text-foreground-subtle"}),r("span",{children:"Reboot device"})]})}),document.body)]})}const tM=300;function nM({trpc:e,deviceId:t}){const n=ne(null),o=ne(null),[s,a]=I(null),i=s!==null,l=ad(e,t,{enabled:i}),c=()=>a(null),d=()=>{const f=n.current;if(!f)return;const m=f.getBoundingClientRect(),h=8,g=Math.min(tM,window.innerWidth-h*2),x=Math.max(h,Math.min(m.right-g,window.innerWidth-g-h)),b=m.bottom+Qg,y=Math.max(160,window.innerHeight-b-h);a({top:b,left:x,width:g,maxHeight:y})};return J(()=>{if(!i)return;const f=h=>{const g=n.current,x=o.current,b=h.target;b!==null&&(g&&g.contains(b)||x&&x.contains(b)||c())},m=h=>{h.key==="Escape"&&(h.stopPropagation(),c())};return document.addEventListener("mousedown",f),document.addEventListener("touchstart",f),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("touchstart",f),document.removeEventListener("keydown",m)}},[i]),u(me,{children:[r("button",{ref:n,type:"button",onClick:f=>{f.stopPropagation(),i?c():d()},className:Y("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",i&&"bg-surface-hover text-foreground"),title:"PTZ controls","aria-label":"PTZ controls","aria-haspopup":"dialog","aria-expanded":i,children:r(dS,{className:"h-3 w-3"})}),s&&Qr(r("div",{ref:o,style:{position:"fixed",top:s.top,left:s.left,width:s.width,maxHeight:s.maxHeight},className:"z-[9999] overflow-y-auto rounded-lg border border-border bg-surface shadow-lg shadow-black/30",onClick:f=>f.stopPropagation(),children:r(id,{mode:"panel",controls:l})}),document.body)]})}const rM=Object.freeze([]);function oM(e){return e==="native"?"native":"enhanced"}function sM(e){return e.map(t=>({kind:"marker",feature:t}))}function aM(e,t){const n=new Map,o=t.entries??[];for(const a of o)n.set(a.capName,a);const s=[];for(const a of e){const i=Q3[a];if(i===void 0){s.push({kind:"marker",feature:a});continue}const l=n.get(i);l&&s.push({kind:oM(l.kind),feature:a,capName:i})}return s}function iM(e,t,n){const[o,s]=I(null),[a,i]=I(!1),[l,c]=I(!0);return J(()=>{if(t===null){s(null),i(!1),c(!1);return}let d=!1;c(!0),i(!1);const p=async()=>{try{const m=await e.deviceManager.getBindings.query({deviceId:t});if(d)return;s(m),c(!1)}catch{if(d)return;i(!0),c(!1)}};p();const f=e.live?.onEvent.subscribe({category:"capability.binding-changed"},{onData:m=>{const h=m.data?.source;if(!h){p();return}h.type==="device"&&h.id===t&&p()}});return()=>{d=!0,f?.unsubscribe()}},[e,t]),n.length===0?{loading:l,resolved:rM}:l||a||!o?{loading:l,resolved:sM(n)}:{loading:!1,resolved:aM(n,o)}}const lM=[];function Gg({trpc:e,device:t,flags:n,accessoryCount:o,adoptedCount:s,showFeatureRow:a=!1}){const i=o+s,l=n.showChildrenAccordion&&i>0,c=t.features??lM,d=a&&c.length>0,{resolved:p}=iM(e,d?t.id:null,c),f=d&&p.length>0;return!l&&!f?null:u("div",{className:"flex items-center gap-1.5 flex-nowrap whitespace-nowrap min-w-0",children:[l&&r(cM,{accessoryCount:o,adoptedCount:s}),f&&r(dM,{resolved:p})]})}function cM({accessoryCount:e,adoptedCount:t}){const n=e+t;if(n===0)return null;const o=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"}`;return u("span",{className:"text-[9px] font-medium text-foreground-subtle bg-surface-elevated/60 rounded px-1.5 py-0.5 flex-shrink-0",title:o,children:["+",n]})}const Wg=240,fp=200;function dM({resolved:e}){const t=ne(null),[n,o]=I(null);return u("span",{ref:t,className:"relative inline-flex items-center gap-1 cursor-help",onMouseEnter:()=>{const i=t.current;if(!i)return;const l=i.getBoundingClientRect(),p=window.innerHeight-l.bottom>=fp?l.bottom+4:l.top-fp-4,f=Math.max(8,Math.min(l.left,window.innerWidth-Wg-8));o({top:p,left:f})},onMouseLeave:()=>o(null),children:[e.map(i=>{const l=Fg[i.feature];return l?r("span",{className:"inline-flex items-center justify-center h-4 w-4 rounded bg-surface-elevated/60 text-foreground-subtle",title:jg[i.feature]??i.feature,children:r(l,{className:"h-2.5 w-2.5"})},i.feature):null}),n&&Qr(r(uM,{resolved:e,position:n}),document.body)]})}function uM({resolved:e,position:t}){return u("div",{style:{position:"fixed",top:t.top,left:t.left,width:Wg,pointerEvents:"none"},className:"z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-2",children:[r("h5",{className:"text-[9px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5",children:"Features"}),r("ul",{className:"space-y-0.5",children:e.map(n=>r(pM,{entry:n},n.feature))})]})}function pM({entry:e}){const t=Fg[e.feature],n=jg[e.feature]??e.feature;return u("li",{className:"flex items-center justify-between gap-2 text-[10px]",children:[u("span",{className:"flex items-center gap-1.5 text-foreground",children:[t&&r(t,{className:"h-3 w-3 text-foreground-subtle"}),r("span",{children:n})]}),r(fM,{kind:e.kind})]})}function fM({kind:e}){return e==="marker"?r("span",{className:"text-[8.5px] px-1 rounded text-foreground-subtle",title:"Informational marker (no cap registered)",children:"marker"}):r("span",{className:Y("text-[8.5px] px-1 rounded",e==="native"?"bg-success/15 text-success":"bg-primary/15 text-primary"),children:e})}function Kg({device:e,variant:t,flags:n,parent:o,integrationIcon:s,hasChildren:a,expanded:i,onToggleExpand:l,onNavigateToParent:c}){const d=zg(e);return u("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[n.showChildrenAccordion&&a?r("button",{type:"button",onClick:p=>{p.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?r(zn,{className:"h-3 w-3"}):r(Fn,{className:"h-3 w-3"})}):n.showChildrenAccordion?r("span",{className:"h-3.5 w-3.5 flex-shrink-0"}):null,r(d,{className:Y("text-foreground-subtle flex-shrink-0",t==="minimal"?"h-3 w-3":"h-3.5 w-3.5")}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-1.5 min-w-0",children:[n.showIntegrationIcon&&s&&r("span",{className:"flex-shrink-0",children:s}),r("span",{className:Y("font-semibold text-foreground truncate",t==="minimal"?"text-[10.5px]":"text-[11px]"),title:e.name,children:e.name})]}),(n.showId||n.showStableId)&&u("div",{className:"mt-0.5 flex items-center gap-1 text-[9px] text-foreground-subtle font-mono truncate",title:n.showStableId?`stableId: ${e.stableId}`:void 0,children:[n.showId&&u("span",{className:"flex-shrink-0 tabular-nums",children:["#",String(e.id)]}),n.showId&&n.showStableId&&r("span",{className:"flex-shrink-0 opacity-50",children:"·"}),n.showStableId&&r("span",{className:"truncate",children:G3(e.stableId)})]}),n.showParentBadge&&o&&u("button",{type:"button",onClick:p=>{p.stopPropagation(),c(o.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: ${o.name} (#${String(o.id)})`,children:[r(Dl,{className:"h-2.5 w-2.5 shrink-0"}),u("span",{className:"truncate",children:["Under: ",o.name]})]})]})]})}function ld(e,t){return Bg(e,t,o=>o.battery)??null}function cd(e,t){const n=wt(e,t),o=ne(!1),{data:s,isLoading:a,isFetching:i,refetch:l}=cr({queryKey:["device",t,"snapshot"],queryFn:()=>{if(!n)throw new Error("useDeviceSnapshotImage: device proxy not ready");const p=o.current;return o.current=!1,n.snapshot?.getSnapshot({force:p})??null},enabled:n!==null&&t!==null,staleTime:1e4,gcTime:1440*60*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,retry:!1}),c=s?`data:${s.contentType};base64,${s.base64}`:null;function d(){o.current=!0,l()}return{src:c,loading:a||i,refresh:d}}function mM(e){return e<=10?h5:e<=30?f5:e>=95?u5:Fh}function hM(e,t){return t!=="none"?"text-emerald-400":e<=10?"text-rose-400":e<=30?"text-amber-400":"text-foreground-subtle"}function dd({status:e,variant:t="compact",className:n}){if(!e)return null;const o=mM(e.percentage),s=hM(e.percentage,e.charging),a=e.charging==="solar"?Jh:e.charging==="dc"?VS:null,i=e.sleeping;return u("span",{className:Y("inline-flex items-center gap-1 text-[10px] font-medium",s,n),title:`Battery: ${Math.round(e.percentage)}%`+(e.charging!=="none"?` · charging (${e.charging})`:"")+(e.sleeping?" · sleeping":""),children:[r(o,{className:"h-3.5 w-3.5"}),u("span",{children:[Math.round(e.percentage),"%"]}),a&&r(a,{className:"h-3 w-3"}),i&&r(Hc,{className:"h-3 w-3 text-blue-300"}),t==="full"&&e.charging!=="none"&&r("span",{className:"text-foreground-subtle",children:e.charging})]})}function Yg({trpc:e,device:t,status:n,enabled:o,showStatusPills:s=!1}){const a=o&&t.online,i=cd(e,a?t.id:null),l=(t.features??[]).includes("battery-operated"),c=s&&l&&!t.disabled,d=ld(e,c?t.id:null);return!o&&!c?null:u("span",{className:"inline-flex items-center gap-1.5 flex-nowrap whitespace-nowrap",children:[c&&d&&r(dd,{status:d}),o&&r(gM,{deviceName:t.name,snapshotUrl:i.src,status:n})]})}const $i=288,mp=196,Di=8;function gM({deviceName:e,snapshotUrl:t,status:n}){const o=ne(null),[s,a]=I(null),i=n==="offline"||n==="disabled",l=()=>{const d=o.current;if(!d)return;const p=d.getBoundingClientRect(),f=p.top,m=window.innerHeight-p.bottom,h=f<mp+Di&&m>f,g=h?p.bottom+Di:p.top-mp-Di,x=p.right-$i,b=Math.max(8,Math.min(x,window.innerWidth-$i-8));a({top:g,left:b,placeBelow:h})},c=()=>a(null);return u(me,{children:[r("button",{ref:o,type:"button",onClick:d=>d.stopPropagation(),onMouseEnter:l,onMouseLeave:c,onFocus:l,onBlur:c,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:r(Yr,{className:"h-3.5 w-3.5"})}),s&&Qr(u("div",{style:{position:"fixed",top:s.top,left:s.left,width:$i,pointerEvents:"none"},className:"rounded-lg border border-border bg-surface shadow-lg shadow-black/30 z-[9999] overflow-hidden",children:[r("div",{className:"h-40 bg-background flex items-center justify-center",children:t&&!i?r("img",{src:t,alt:e,className:"h-full w-full object-cover"}):r("span",{className:"text-xs text-foreground-subtle",children:n==="offline"?"Offline — no snapshot":n==="disabled"?"Disabled":"No snapshot yet"})}),r("div",{className:"px-3 py-2",children:r("p",{className:"text-xs font-semibold text-foreground truncate",children:e})})]}),document.body)]})}function Zg({status:e}){const t=e==="disabled"?"bg-warning":e==="online"?"bg-success":"bg-danger",n=e==="disabled"?"Disabled":e==="online"?"Online":"Offline";return r("span",{className:Y("h-1.5 w-1.5 rounded-full flex-shrink-0",t),title:n})}function Ro(e){const{trpc:t,device:n,parent:o,integrationIcon:s,onNavigate:a,className:i,renderRowAction:l}=e,c=V3(e),d=e.variant??"compact",p=e.view??"card",f=!n.disabled,m=n.isCamera??n.type.toLowerCase()==="camera",h=e.children??[],g=h.filter(dp),x=h.filter(M=>!dp(M)),b=h.length>0,[y,w]=I(!1),v=e.expanded??y,N=e.onToggleExpand??(()=>w(M=>!M)),k=M=>{a?.(M)},C=e.indentLevel??(e.isAccessoryRow?2:0),D=f?n.online?"online":"offline":"disabled";return p==="table"?r(xM,{trpc:t,device:n,variant:d,flags:c,parent:o??null,integrationIcon:s??null,accessoryCount:g.length,adoptedCount:x.length,hasChildren:b,expanded:v,onToggleExpand:N,onNavigate:k,displayStatus:D,isCamera:m,showSnapshot:c.showSnapshot&&m,isAccessoryRow:e.isAccessoryRow??!1,indentLevel:C,className:i,renderRowAction:l??null}):u("div",{className:Y("rounded-lg border border-border bg-surface transition-colors",!f&&"opacity-60",i),children:[u("div",{onClick:()=>k(n.id),className:Y("flex items-center gap-2 cursor-pointer hover:border-foreground-subtle/30 w-full",d==="minimal"?"px-2.5 py-1.5":"px-3 py-2.5"),children:[r(Kg,{device:n,variant:d,flags:c,parent:o??null,integrationIcon:s??null,hasChildren:b,expanded:v,onToggleExpand:N,onNavigateToParent:k}),r(Gg,{trpc:t,device:n,flags:c,accessoryCount:g.length,adoptedCount:x.length,showFeatureRow:!1}),r(Yg,{trpc:t,device:n,status:D,enabled:c.showSnapshot&&m,showStatusPills:!0}),r(qg,{trpc:t,device:n,flags:c}),l&&r("span",{onClick:M=>M.stopPropagation(),children:l(n)}),r(Zg,{status:D})]}),v&&b&&r(W3,{trpc:t,accessoryChildren:g,adoptedChildren:x,onNavigate:k})]})}const bM={0:"pl-2",1:"pl-6",2:"pl-8"};function xM(e){const{trpc:t,device:n,variant:o,flags:s,parent:a,integrationIcon:i,accessoryCount:l,adoptedCount:c,hasChildren:d,expanded:p,onToggleExpand:f,onNavigate:m,displayStatus:h,isCamera:g,showSnapshot:x,isAccessoryRow:b,indentLevel:y,className:w,renderRowAction:v}=e;return u("tr",{onClick:()=>m(n.id),className:Y("cursor-pointer hover:bg-surface-hover transition-colors",!s.showChildrenAccordion&&"border-b border-border-subtle/40",b&&"bg-foreground-subtle/[0.03]",w),children:[r("td",{className:Y("py-2 align-middle pr-2",bM[y]),children:r(Kg,{device:n,variant:o,flags:s,parent:a,integrationIcon:i,hasChildren:d,expanded:p,onToggleExpand:f,onNavigateToParent:m})}),r("td",{className:"hidden md:table-cell px-2 py-2 align-middle text-[10px] text-foreground-subtle whitespace-nowrap",children:n.type}),r("td",{className:"hidden lg:table-cell px-2 py-2 align-middle",children:r(Gg,{trpc:t,device:n,flags:s,accessoryCount:l,adoptedCount:c,showFeatureRow:!0})}),r("td",{className:"hidden sm:table-cell px-2 py-2 align-middle",children:r(Yg,{trpc:t,device:n,status:h,enabled:x&&g,showStatusPills:!0})}),r("td",{className:"px-2 py-2 align-middle text-right whitespace-nowrap",children:u("span",{className:"inline-flex items-center gap-1.5",children:[r(qg,{trpc:t,device:n,flags:s}),v&&r("span",{onClick:N=>N.stopPropagation(),children:v(n)}),r(Zg,{status:h})]})})]})}function Xg(e,t){const[n,o]=I(e);return J(()=>{const s=setTimeout(()=>o(e),t);return()=>clearTimeout(s)},[e,t]),n}const yM=new Set(["hub","nvr"]);function vM(e){const t=new Map;for(const s of e)t.set(s.id,s);const n=[],o=new Map;for(const s of e){const a=s.parentDeviceId;if(a==null){n.push(s);continue}const i=t.get(a);if(!i){n.push(s);continue}const l=s.role!==null&&s.role!==void 0;if(yM.has(i.type)&&!l){n.push(s);continue}const d=o.get(a);d?d.push(s):o.set(a,[s])}return{topLevel:n,accessoriesByParent:o}}const hp=2;function wM(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 n=[],o=Math.max(2,e-hp),s=Math.min(t-1,e+hp);n.push({kind:"page",n:1}),o>2&&n.push({kind:"ellipsis",side:"left"});for(let a=o;a<=s;a++)n.push({kind:"page",n:a});return s<t-1&&n.push({kind:"ellipsis",side:"right"}),n.push({kind:"page",n:t}),n}function NM({currentPage:e,totalItems:t,pageSize:n,onPageChange:o,itemNoun:s="devices"}){if(t<=n)return null;const a=Math.ceil(t/n),i=(e-1)*n+1,l=Math.min(e*n,t),c=wM(e,a);return u("div",{className:"flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle",children:[u("span",{children:["Showing ",i,"–",l," of ",t," ",s]}),u("span",{className:"inline-flex items-center gap-1",children:[r("button",{type:"button","aria-label":"Previous page",disabled:e===1,onClick:()=>o(e-1),className:Y("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:r(E5,{className:"h-3 w-3"})}),c.map((d,p)=>{if(d.kind==="ellipsis")return r("span",{className:"px-1 text-foreground-subtle/60 select-none",children:"…"},`e-${p}`);const f=d.n===e;return r("button",{type:"button",onClick:()=>o(d.n),className:Y("inline-flex items-center justify-center h-7 min-w-7 px-1.5 rounded border text-[10.5px] font-medium transition-colors",f?"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}`)}),r("button",{type:"button","aria-label":"Next page",disabled:e===a,onClick:()=>o(e+1),className:Y("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:r(Fn,{className:"h-3 w-3"})})]})]})}function kM({view:e,onViewChange:t,types:n,currentType:o,onTypeChange:s,addons:a,selectedAddons:i,onAddonsChange:l,hideAddons:c=!1}){return u("div",{className:"flex items-center gap-2 flex-wrap",children:[u("span",{className:"inline-flex border border-border rounded-md overflow-hidden",children:[r("button",{type:"button",onClick:()=>t("cards"),className:Y("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:r(kS,{className:"h-3.5 w-3.5"})}),r("button",{type:"button",onClick:()=>t("table"),className:Y("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:r(wC,{className:"h-3.5 w-3.5"})})]}),n&&n.length>0&&u(me,{children:[r(CM,{children:"Type"}),r(gp,{active:o===null,onClick:()=>s(null),children:"All"}),n.map(d=>r(gp,{active:o===d,onClick:()=>s(o===d?null:d),children:MM(d)},d))]}),!c&&a&&a.length>0&&r(SM,{addons:a,selected:i,onChange:l})]})}function SM({addons:e,selected:t,onChange:n}){const[o,s]=I(!1),a=ne(null);J(()=>{if(!o)return;const d=f=>{const m=f.target;m&&a.current&&!a.current.contains(m)&&s(!1)},p=f=>{f.key==="Escape"&&s(!1)};return document.addEventListener("mousedown",d),document.addEventListener("touchstart",d),document.addEventListener("keydown",p),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("touchstart",d),document.removeEventListener("keydown",p)}},[o]);const i=new Set(t),l=t.length,c=d=>{const p=new Set(i);p.has(d)?p.delete(d):p.add(d),n(e.filter(f=>p.has(f.id)).map(f=>f.id))};return u("div",{ref:a,className:"relative",children:[u("button",{type:"button",onClick:()=>s(d=>!d),className:Y("inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border text-[10.5px] font-medium transition-colors",l>0?"border-primary/40 bg-primary/15 text-primary":"border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),"aria-haspopup":"listbox","aria-expanded":o,children:[u("span",{children:["Integration",l>0?` · ${String(l)}`:""]}),r(zn,{className:Y("h-3 w-3 transition-transform",o&&"rotate-180")})]}),o&&u("div",{role:"listbox",className:"absolute left-0 top-full mt-1 z-30 min-w-[180px] max-h-72 overflow-y-auto rounded-lg border border-border bg-surface shadow-xl py-1",children:[l>0&&r("button",{type:"button",onClick:()=>n([]),className:"flex w-full items-center px-3 py-1.5 text-left text-[10.5px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground",children:"Clear selection"}),e.map(d=>{const p=i.has(d.id);return u("button",{type:"button",role:"option","aria-selected":p,onClick:()=>c(d.id),className:Y("flex w-full items-center gap-2 px-3 py-1.5 text-left text-[10.5px] transition-colors",p?"text-primary":"text-foreground hover:bg-surface-hover"),children:[r("span",{className:Y("flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border",p?"border-primary bg-primary/20":"border-border"),children:p&&r(Wr,{className:"h-2.5 w-2.5"})}),d.icon&&r("span",{className:"inline-flex items-center",children:d.icon}),r("span",{className:"truncate",children:d.name})]},d.id)})]})]})}function CM({children:e}){return r("span",{className:"text-[10px] font-medium uppercase tracking-wider text-foreground-subtle ml-1",children:e})}function gp({active:e,icon:t,onClick:n,children:o}){return u("button",{type:"button",onClick:n,className:Y("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&&r("span",{className:"inline-flex items-center",children:t}),r("span",{children:o})]})}function MM(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function AM({variant:e,onClearFilters:t}){return u("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[r(yS,{className:"h-8 w-8 text-foreground-subtle/40 mb-3"}),r("p",{className:"text-sm font-medium text-foreground-subtle",children:e==="filtered"?"No devices match the current filters":"No devices yet"}),e==="filtered"&&t&&r("button",{type:"button",onClick:t,className:"mt-2 text-[11px] text-primary hover:underline",children:"Clear filters"})]})}function EM(e){return e?e.split(",").map(t=>t.trim()).filter(t=>t.length>0):[]}function Gt(e,t){if(e==="root")return t==="addons"?"addon":t;switch(t){case"view":return"deviceView";case"page":return"devicePage";case"type":return"deviceType";case"q":return"deviceQ";case"addons":return"deviceAddon"}}function bp(e){try{const t=localStorage.getItem(`camstack:${e}:lastFilters`);if(!t)return{};const n=JSON.parse(t);return typeof n!="object"||n===null?{}:n}catch{return{}}}function IM(e,t){try{localStorage.setItem(`camstack:${e}:lastFilters`,JSON.stringify(t))}catch{}}function xp(e,t,n){const o=new URLSearchParams(window.location.search),s=o.get(Gt(e,"view")),a=s==="cards"||s==="table"?s:n.view??t,i=o.get(Gt(e,"page")),l=i?parseInt(i,10):1,c=Number.isFinite(l)&&l>=1?l:1,d=EM(o.get(Gt(e,"addons"))??n.addon??null),p=o.get(Gt(e,"type"))??n.type??null,f=o.get(Gt(e,"q"))??n.q??"";return{view:a,page:c,addons:d,type:p,q:f}}function PM(e,t,n){const o=new URLSearchParams(window.location.search),s=(l,c)=>{c===null||c===""?o.delete(l):o.set(l,c)};s(Gt(e,"view"),t.view===n?null:t.view),s(Gt(e,"page"),t.page===1?null:String(t.page)),s(Gt(e,"addons"),t.addons.length>0?t.addons.join(","):null),s(Gt(e,"type"),t.type),s(Gt(e,"q"),t.q||null);const a=o.toString(),i=a?`${window.location.pathname}?${a}`:window.location.pathname;window.history.replaceState(null,"",i)}function _M(e){const{scope:t,defaultView:n,lsKey:o}=e,[s,a]=I(()=>{const g=bp(o);return xp(t,n,g)}),i=ne(s);i.current=s,J(()=>{const g=()=>{const x=bp(o),b=xp(t,n,x);i.current=b,a(b)};return window.addEventListener("popstate",g),()=>window.removeEventListener("popstate",g)},[t,n,o]);const l=U(g=>{const x=g(i.current);i.current=x,a(x),PM(t,x,n),IM(o,{view:x.view,addon:x.addons.length>0?x.addons.join(","):null,type:x.type,q:x.q})},[t,n,o]),c=U(g=>l(x=>({...x,view:g})),[l]),d=U(g=>l(x=>({...x,page:g})),[l]),p=U(g=>l(x=>({...x,addons:g,page:1})),[l]),f=U(g=>l(x=>({...x,type:g,page:1})),[l]),m=U(g=>l(x=>({...x,q:g,page:1})),[l]),h=U(()=>l(g=>({...g,addons:[],type:null,q:"",page:1})),[l]);return{state:s,setView:c,setPage:d,setAddons:p,setType:f,setQ:m,clearFilters:h}}const $M={cards:24,table:50};function Dr(e){const{devices:t,trpc:n,defaultView:o="table",filters:s,forceAddon:a,resolveIntegrationIcon:i,resolveParent:l,onNavigate:c,pageSize:d=$M,urlScope:p="root",lsKey:f=p==="root"?"devices":"integrations:nested",renderRowAction:m}=e,h=_M({scope:p,defaultView:o,lsKey:f}),g=h.state.view,x=g==="cards"?d.cards:d.table,[b,y]=I(h.state.q),w=Xg(b,300);J(()=>{w!==h.state.q&&h.setQ(w)},[w]);const v=q(()=>a!==void 0?[a]:h.state.addons,[a,h.state.addons]),N=q(()=>{const A=h.state.q.toLowerCase().trim(),P=v.length>0?new Set(v):null;return t.filter(L=>!(P&&!P.has(L.addonId)||h.state.type&&L.type!==h.state.type||A&&!L.name.toLowerCase().includes(A)&&!L.stableId.toLowerCase().includes(A)))},[t,v,h.state.type,h.state.q]),k=q(()=>vM(N),[N]),C=q(()=>{if(h.state.q.trim()==="")return new Set;const A=h.state.q.toLowerCase().trim(),P=new Set;for(const[L,B]of k.accessoriesByParent.entries())B.some(z=>z.name.toLowerCase().includes(A)||z.stableId.toLowerCase().includes(A))&&P.add(L);return P},[k.accessoriesByParent,h.state.q]),D=k.topLevel.length,M=Math.max(1,Math.ceil(D/x)),_=Math.min(h.state.page,M),$=(_-1)*x,E=k.topLevel.slice($,$+x);J(()=>{_!==h.state.page&&h.setPage(_)},[_]),BM();const R=v.length>0||h.state.type!==null||h.state.q!=="",O=D===0;return u("div",{className:"flex flex-col gap-3",children:[u("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[r(kM,{view:g,onViewChange:h.setView,types:s?.types,currentType:h.state.type,onTypeChange:h.setType,addons:s?.addons,selectedAddons:h.state.addons,onAddonsChange:h.setAddons,hideAddons:a!==void 0}),u("div",{className:"relative",children:[r(Lo,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle pointer-events-none"}),r("input",{type:"text",value:b,onChange:A=>y(A.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"})]})]}),O?r(AM,{variant:R?"filtered":"nofilter",onClearFilters:R?h.clearFilters:void 0}):g==="cards"?r(DM,{rows:E,accessoriesByParent:k.accessoriesByParent,trpc:n,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:c??null,renderRowAction:m??null}):r(RM,{rows:E,accessoriesByParent:k.accessoriesByParent,autoExpandedParents:C,devices:N,trpc:n,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:c??null,renderRowAction:m??null}),r(NM,{currentPage:_,totalItems:D,pageSize:x,onPageChange:h.setPage}),a===void 0&&R&&D>0&&u("p",{className:"text-[11px] text-foreground-subtle",children:["Showing ",D," of ",t.length," devices",v.length>0&&u(me,{children:[" ","· filtered by"," ",r("strong",{className:"text-primary",children:v.map(A=>s?.addons?.find(P=>P.id===A)?.name??A).join(", ")})]})]})]})}function DM({rows:e,accessoriesByParent:t,trpc:n,resolveIntegrationIcon:o,resolveParent:s,onNavigate:a,renderRowAction:i}){return r("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:e.map(l=>{const c=t.get(l.id)??[];return r(Ro,{trpc:n,device:l,view:"card",integrationIcon:o?.(l.addonId)??null,parent:l.parentDeviceId!==null?s?.(l.parentDeviceId)??null:null,children:c,onNavigate:a??void 0,renderRowAction:i??void 0},l.id)})})}const LM=new Set(["hub","nvr"]);function TM(e,t){return e.parentDeviceId===null||t===null?0:LM.has(t.toLowerCase())?1:0}function RM({rows:e,accessoriesByParent:t,autoExpandedParents:n,devices:o,trpc:s,resolveIntegrationIcon:a,resolveParent:i,onNavigate:l,renderRowAction:c}){const d=q(()=>{const p=new Map;for(const f of o)p.set(f.id,f.type);return p},[o]);return r("div",{className:"rounded-lg border border-border bg-surface overflow-x-auto",children:u("table",{className:"w-full border-collapse",children:[r("thead",{children:u("tr",{className:"border-b border-border",children:[r("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle",children:"Name"}),r("th",{className:"hidden md:table-cell text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-24",children:"Type"}),r("th",{className:"hidden lg:table-cell text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Features"}),r("th",{className:"hidden sm:table-cell text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-20",children:"Preview"}),r("th",{className:"text-right px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Actions"})]})}),r("tbody",{children:e.map(p=>{const f=t.get(p.id)??[],m=f.length>0,h=n.has(p.id),g=p.parentDeviceId!==null?i?.(p.parentDeviceId)??null:null,x=p.parentDeviceId!==null?d.get(p.parentDeviceId)??null:null;return r(OM,{parent:p,accessories:f,hasAccessories:m,forceExpanded:h,trpc:s,integrationIcon:a?.(p.addonId)??null,parentRowParent:g,indentLevel:TM(p,x),onNavigate:l??null,renderRowAction:c??null},p.id)})})]})})}function OM({parent:e,accessories:t,hasAccessories:n,forceExpanded:o,trpc:s,integrationIcon:a,parentRowParent:i,indentLevel:l,onNavigate:c,renderRowAction:d}){const[p,f]=I(o),m=ne(o);return J(()=>{m.current!==o&&(f(o),m.current=o)},[o]),u(me,{children:[r(Ro,{trpc:s,device:e,view:"table",integrationIcon:a,parent:i,children:t,onNavigate:c??void 0,showChildrenAccordion:n,expanded:p,onToggleExpand:()=>f(x=>!x),indentLevel:l,renderRowAction:d??void 0}),n&&p&&t.map(x=>r(Ro,{trpc:s,device:x,view:"table",integrationIcon:null,parent:null,isAccessoryRow:!0,showChildrenAccordion:!1,onNavigate:c??void 0},x.id))]})}function BM(){Me()}function zM({options:e,value:t,onChange:n}){return r("div",{className:"flex flex-wrap gap-2",children:e.map(o=>{const s=o.id===t;return u("button",{onClick:()=>o.available&&n(o.id),disabled:!o.available,className:`flex items-center gap-2 rounded-lg border px-3 py-2 text-xs font-medium transition-all ${s?"border-primary/40 bg-primary/10 text-primary":o.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:[r(X5,{className:"h-3.5 w-3.5 shrink-0"}),o.label,o.isBest&&u("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:[r(xC,{className:"h-2.5 w-2.5"}),"Best"]}),o.platformScore!=null&&u("span",{className:"text-[10px] text-foreground-subtle/60",children:["(",o.platformScore,")"]}),r("span",{className:`h-1.5 w-1.5 rounded-full ${o.available?"bg-success":"bg-danger"}`})]},o.id)})})}function FM(e,t){const n=new Set(t.slots.flatMap(i=>i.addons.map(l=>l.id))),o=[];function s(i){if(!n.has(i.addonId))return o.push(`Addon "${i.addonId}" is no longer available — step removed`),null;const l=t.slots.flatMap(p=>p.addons).find(p=>p.id===i.addonId);let c=i.modelId;if(l&&!l.models.some(p=>p.id===c)){const p=l.defaultModelId;o.push(`Model "${c}" not available for ${i.addonId} — using "${p}"`),c=p}const d=i.children.map(p=>s(p)).filter(p=>p!==null);return{...i,modelId:c,children:d}}const a=e.map(i=>s(i)).filter(i=>i!==null);return{valid:o.length===0,steps:a,warnings:o}}function jM(e){const t=new Map;for(const n of e.slots)for(const o of n.addons)t.set(o.id,o);return t}function Li(e){return{addonId:e.id,addonName:e.name,slot:e.slot,inputClasses:[...e.inputClasses],outputClasses:[...e.outputClasses],enabled:!0,modelId:e.defaultModelId,children:[]}}function Ti({addon:e,onClick:t}){return r("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:u("div",{className:"flex items-center gap-3",children:[r(U5,{className:"h-[18px] w-[18px] text-foreground-subtle/30 group-hover:text-primary/60 shrink-0"}),u("div",{className:"flex-1 min-w-0",children:[r("span",{className:"text-[13px] font-medium text-foreground-subtle/50 group-hover:text-foreground-subtle block truncate",children:e.name}),u("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(n=>r("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:n},n)),e.inputClasses.length>0&&e.outputClasses.length>0&&r("span",{className:"text-foreground-subtle/25 text-[10px]",children:"→"}),e.outputClasses.map(n=>r("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:n},n))]})]})]})})}function ud({schema:e,steps:t,onChange:n,templates:o,selectedTemplateId:s,onSelectTemplate:a,onSaveTemplate:i,onUpdateTemplate:l,onDeleteTemplate:c,readOnly:d=!1,excludeAddons:p=[],hideTemplates:f=!1,showOnlyEnabled:m=!1,showSlotLabels:h=!1,toggleMode:g="simple",overrides:x={},onOverrideChange:b,inheritedEnabledByAddon:y={},hideModelAndSettings:w=!1}){const v=H=>({toggleMode:g,hideModelAndSettings:w,...g==="threeState"?{overrideState:x[H]!==void 0?x[H]:null,onOverrideChange:b?j=>b(H,j):void 0,inheritedEnabled:y[H]}:{}}),N=q(()=>new Set(p),[p]),k=q(()=>jM(e),[e]),[C,D]=I([]),M=s?JSON.stringify(t)!==JSON.stringify(o.find(H=>H.id===s)?.steps):!1;function _(H){const j=H.target.value||null;if(j){const Q=o.find(G=>G.id===j);if(Q){const G=FM(Q.steps,e);D([...G.warnings])}}else D([]);a(j)}function $(){s&&l(s,t)}function E(){const H=window.prompt("Template name:");H?.trim()&&i(H.trim(),t)}function R(){if(!s)return;const H=o.find(j=>j.id===s);H&&window.confirm(`Delete template "${H.name}"?`)&&c(s)}function O(H){n(t.map(j=>j.addonId!==H.addonId?j:A(H)))}function A(H){const j=H.children.some(Q=>Q.enabled||Q.children.some(G=>G.enabled));return{...H,enabled:H.enabled||j,children:H.children.map(Q=>{const G=Q.children.some(Z=>Z.enabled);return{...Q,enabled:Q.enabled||G}})}}function P(H,j){const Q=Li(j);n(t.map(G=>G.addonId!==H?G:{...G,children:[...G.children,Q]}))}function L(H){const j=new Set;for(const Q of H){j.add(Q.addonId);for(const Z of Q.children)j.add(Z.addonId);const G=L(Q.children);for(const Z of G)j.add(Z)}return j}const B=L(t);function z(H){const j=k.get(H.addonId);if(!j)return[];const G=e.slots.find(X=>X.id===j.slot)?.parentSlot==null,Z=j.childSlots,V=new Set(H.children.map(X=>X.addonId)),K=[];for(const X of e.slots)if(Z.includes(X.id))for(const te of X.addons){if(V.has(te.id)||N.has(te.id))continue;const he=te.inputClasses.length===0;if(he&&!G)continue;(he||te.inputClasses.some(ee=>H.outputClasses.includes(ee)))&&K.push(te)}return K}function T(H){const j=m?{...H,children:H.children.filter(G=>G.enabled).map(G=>({...G,children:G.children.filter(Z=>Z.enabled)}))}:H,Q=m?[]:z(j);return u("div",{className:"space-y-1.5",children:[r(Ws,{step:j,schema:k.get(j.addonId)??null,allSchemas:k,onChange:O,onDelete:d?void 0:G=>n(t.filter(Z=>Z.addonId!==G)),readOnly:d,...v(j.addonId)}),(j.children.length>0||Q.length>0)&&u("div",{className:"ml-4 pl-3 border-l border-border/60 space-y-1.5",children:[h&&r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/40",children:"Slot: Cropper / Classifier"}),j.children.map(G=>{const Z=z(G);return u("div",{className:"space-y-1.5",children:[r(Ws,{step:G,schema:k.get(G.addonId)??null,allSchemas:k,depth:1,onChange:V=>{O({...j,children:j.children.map(K=>K.addonId===V.addonId?V:K)})},onDelete:d?void 0:V=>{O({...j,children:j.children.filter(K=>K.addonId!==V)})},readOnly:d,...v(G.addonId)}),(G.children.length>0||Z.length>0)&&u("div",{className:"ml-4 pl-3 border-l border-border/40 space-y-1.5",children:[h&&r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/30",children:"Slot: Recognizer"}),G.children.map(V=>r(Ws,{step:V,schema:k.get(V.addonId)??null,allSchemas:k,depth:2,onChange:K=>{O({...j,children:j.children.map(X=>X.addonId===G.addonId?{...X,children:X.children.map(te=>te.addonId===K.addonId?K:te)}:X)})},onDelete:d?void 0:K=>{O({...j,children:j.children.map(X=>X.addonId===G.addonId?{...X,children:X.children.filter(te=>te.addonId!==K)}:X)})},readOnly:d,...v(V.addonId)},V.addonId)),!d&&Z.map(V=>r(Ti,{addon:V,onClick:()=>{const K=Li(V);O({...j,children:j.children.map(X=>X.addonId===G.addonId?{...X,children:[...X.children,K]}:X)})}},V.id))]})]},G.addonId)}),!d&&Q.map(G=>r(Ti,{addon:G,onClick:()=>P(j.addonId,G)},G.id))]})]},j.addonId)}const F=e.slots.filter(H=>H.parentSlot===null).sort((H,j)=>H.priority-j.priority);return u("div",{className:"space-y-4",children:[!f&&r("div",{className:"rounded-lg border border-border bg-surface p-3",children:u("div",{className:"flex items-center gap-2",children:[r("div",{className:"relative flex-1 min-w-0",children:u("select",{value:s??"",onChange:_,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:[r("option",{value:"",children:"No template"}),o.map(H=>r("option",{value:H.id,children:H.name},H.id))]})}),M&&r("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500 shrink-0"}),r("button",{onClick:$,disabled:!s||d,title:"Save",className:Y("p-2 rounded-lg border border-border transition-colors",s&&!d?"text-foreground-subtle hover:bg-surface-hover":"text-foreground-subtle/30 cursor-not-allowed"),children:r(tC,{className:"h-4 w-4"})}),r("button",{onClick:E,disabled:d,title:"Save As",className:Y("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:r(K5,{className:"h-4 w-4"})}),r("button",{onClick:R,disabled:!s||d,title:"Delete",className:Y("p-2 rounded-lg border border-border transition-colors",s&&!d?"text-foreground-subtle hover:text-danger":"text-foreground-subtle/30 cursor-not-allowed"),children:r(Jt,{className:"h-4 w-4"})})]})}),C.length>0&&u("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 text-xs text-amber-400 space-y-1",children:[u("div",{className:"flex items-center justify-between",children:[r("span",{className:"font-medium",children:"Template loaded with warnings:"}),r("button",{onClick:()=>D([]),className:"text-amber-400/60 hover:text-amber-400",children:r(rt,{className:"h-3.5 w-3.5"})})]}),C.map((H,j)=>u("div",{children:["• ",H]},j))]}),F.map(H=>{const j=t.filter(K=>K.slot===H.id&&!N.has(K.addonId)),Q=m?j.filter(K=>K.enabled):j,G=m?[]:H.addons.filter(K=>!B.has(K.id)&&!N.has(K.id)),Z=new Map,V=[];for(const K of Q)K.group?(Z.has(K.group)||Z.set(K.group,[]),Z.get(K.group).push(K)):V.push(K);return u("div",{className:"space-y-2",children:[h&&u("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50",children:["Slot: ",H.label]}),V.map(K=>T(K)),[...Z.entries()].map(([K,X])=>u("div",{className:"space-y-2 rounded-lg border border-border/40 p-2",children:[r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50 px-1",children:K}),X.map(te=>T(te))]},K)),!d&&G.map(K=>r(Ti,{addon:K,onClick:()=>{n([...t,Li(K)])}},K.id))]},H.id)})]})}const yo={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"},yp=["#ef4444","#8b5cf6","#06b6d4","#f97316","#10b981","#6366f1","#e11d48","#0891b2","#7c3aed","#059669"],Jg="#f59e42";function xt(e,t){if(t?.[e])return t[e];if(t?.[e.toLowerCase()])return t[e.toLowerCase()];if(yo[e])return yo[e];if(yo[e.toLowerCase()])return yo[e.toLowerCase()];let n=0;for(let o=0;o<e.length;o++)n=n*31+(e.codePointAt(o)??0)>>>0;return yp[n%yp.length]??Jg}function HM({src:e,imageWidth:t,imageHeight:n,detections:o=[],classColors:s,aspectRatio:a,className:i,placeholder:l,showConfidence:c=!0,minConfidence:d=0,borderWidth:p=2}){function f(y){return xt(y,s)}const m=a??(t&&n?`${t}/${n}`:"16/9"),h=o.filter(y=>y.score>=d),g=h.filter(y=>y.kind==="first-level"),x=h.filter(y=>y.kind==="detail"),b=qM(x,y=>y.parentId??"");return r("div",{className:Y("rounded-lg border border-border bg-surface overflow-hidden relative",i),style:{aspectRatio:m},children:e?u(me,{children:[r("img",{src:e,className:"absolute inset-0 w-full h-full object-fill",alt:""}),h.map((y,w)=>y.debug?.mask&&y.debug.maskWidth&&y.debug.maskHeight?r(VM,{mask:y.debug.mask,maskWidth:y.debug.maskWidth,maskHeight:y.debug.maskHeight,bbox:y.bbox,imageWidth:t,imageHeight:n,color:f(y.macroClass)},`mask-${w}`):null),g.map(y=>{const w=b.get(y.id)??[];return r(vp,{detection:y,imageWidth:t,imageHeight:n,color:f(y.macroClass),showConfidence:c,borderWidth:y.debug?.mask?1:p,children:w.map(v=>r(UM,{child:v,parentBbox:y.bbox,color:f(v.macroClass),showConfidence:c},`child-${v.id}`))},`det-${y.id}`)}),x.filter(y=>!y.parentId||!g.some(w=>w.id===y.parentId)).map(y=>r(vp,{detection:y,imageWidth:t,imageHeight:n,color:f(y.macroClass),showConfidence:c,borderWidth:p},`orphan-${y.id}`))]}):r("div",{className:"w-full h-full flex items-center justify-center text-foreground-subtle text-sm",children:l??"No image loaded"})})}function vp({detection:e,imageWidth:t,imageHeight:n,color:o,showConfidence:s,borderWidth:a,children:i}){const{x:l,y:c,width:d,height:p}=e.bbox,f=u("div",{className:"absolute left-0 flex flex-col items-start gap-px",style:{bottom:"100%",marginBottom:"2px"},children:[u("span",{className:"text-[10px] px-1 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:o},children:[e.macroClass,s&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((m,h)=>u("span",{className:"text-[9px] font-semibold px-1 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:xt(m.label)},children:[m.label," ",(m.score*100).toFixed(0),"%"]},`${e.id}-lbl-${h}`))]});return u("div",{className:"absolute rounded-sm",style:{left:`${l/t*100}%`,top:`${c/n*100}%`,width:`${d/t*100}%`,height:`${p/n*100}%`,borderWidth:`${a}px`,borderStyle:"solid",borderColor:o},children:[f,i]})}function VM({mask:e,maskWidth:t,maskHeight:n,bbox:o,imageWidth:s,imageHeight:a,color:i}){const l=ne(null);return J(()=>{const c=l.current;if(!c)return;const d=c.getContext("2d");if(!d)return;const p=atob(e),f=new Uint8Array(p.length);for(let y=0;y<p.length;y++)f[y]=p.charCodeAt(y);const m=parseInt(i.slice(1,3),16),h=parseInt(i.slice(3,5),16),g=parseInt(i.slice(5,7),16);c.width=t,c.height=n;const x=d.createImageData(t,n),b=t*n;for(let y=0;y<b;y++){const w=y<f.length?f[y]:0,v=y*4;w>0&&(x.data[v]=m,x.data[v+1]=h,x.data[v+2]=g,x.data[v+3]=120)}d.putImageData(x,0,0)},[e,t,n,i]),r("canvas",{ref:l,className:"absolute pointer-events-none",style:{left:`${o.x/s*100}%`,top:`${o.y/a*100}%`,width:`${o.width/s*100}%`,height:`${o.height/a*100}%`,imageRendering:"pixelated"}})}function UM({child:e,parentBbox:t,color:n,showConfidence:o}){if(t.width<=0||t.height<=0)return null;const s=(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 r("div",{className:"absolute rounded-sm",style:{left:`${Math.max(0,s)}%`,top:`${Math.max(0,a)}%`,width:`${Math.min(100,i)}%`,height:`${Math.min(100,l)}%`,borderWidth:"1px",borderStyle:"solid",borderColor:n},children:u("div",{className:"absolute left-0 flex flex-col items-start gap-px",style:{bottom:"100%",marginBottom:"1px"},children:[u("span",{className:"text-[9px] px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:n},children:[e.macroClass,o&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((c,d)=>u("span",{className:"text-[8px] font-semibold px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:xt(c.label)},children:[c.label," ",(c.score*100).toFixed(0),"%"]},`${e.id}-lbl-${d}`))]})})}function qM(e,t){const n=new Map;for(const o of e){const s=t(o),a=n.get(s)??[];a.push(o),n.set(s,a)}return n}function QM({detections:e,classColors:t,className:n,hiddenKeys:o,onToggleVisibility:s}){const a=t;if(e.length===0)return r("div",{className:"text-sm text-foreground-subtle italic text-center py-4",children:"No detections"});const i=e.filter(p=>p.kind==="first-level"),l=e.filter(p=>p.kind==="detail"),c=new Map;for(const p of l){if(!p.parentId)continue;const f=c.get(p.parentId)??[];f.push(p),c.set(p.parentId,f)}const d=l.filter(p=>!p.parentId||!i.some(f=>f.id===p.parentId));return u("div",{className:n,children:[u("div",{className:"text-xs font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:["Detections (",e.length,")"]}),u("div",{className:"space-y-2",children:[i.map(p=>r(wp,{detection:p,children_:c.get(p.id)??[],colors:a,hiddenKeys:o,onToggleVisibility:s},p.id)),d.map(p=>r(wp,{detection:p,children_:[],colors:a,hiddenKeys:o,onToggleVisibility:s},p.id))]})]})}function wp({detection:e,children_:t,colors:n,hiddenKeys:o,onToggleVisibility:s}){const a=xt(e.macroClass,n),i=!o?.has(e.id),l=e.debug?.mask,c=e.debug?.maskWidth,d=e.debug?.maskHeight,p=e.debug?.alternateLabels;return u("div",{className:`rounded-md border border-border bg-surface p-3 space-y-1 ${i?"":"opacity-40"}`,children:[u("div",{className:"flex justify-between items-center",children:[u("div",{className:"flex items-center gap-2",children:[s&&r("input",{type:"checkbox",checked:i,onChange:()=>s(e.id,!i),className:"h-3.5 w-3.5 rounded border-border accent-primary cursor-pointer shrink-0"}),r("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{backgroundColor:a}}),r("span",{className:"text-sm font-medium text-foreground",children:e.macroClass}),e.kind==="detail"&&r("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:"detail"}),l&&c&&d&&u("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",c,"x",d]})]}),r(KM,{confidence:e.score})]}),u("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&&r("div",{className:"flex flex-wrap gap-1 mt-1",children:e.labels.map((f,m)=>u("span",{className:"inline-flex items-center gap-1 text-[10px] font-medium px-1.5 py-0.5 rounded-full",style:{backgroundColor:xt(f.label,n)+"20",color:xt(f.label,n)},children:[f.label,u("span",{className:"opacity-60",children:[(f.score*100).toFixed(0),"%"]}),f.detectionId&&u("span",{className:"opacity-40 text-[8px]",children:["→ ",f.detectionId]})]},m))}),p&&Object.keys(p).length>0&&r(WM,{alternateLabels:p,colors:n}),t.length>0&&r(GM,{items:t,colors:n,hiddenKeys:o,onToggleVisibility:s})]})}function GM({items:e,colors:t,hiddenKeys:n,onToggleVisibility:o}){return r("div",{className:"ml-4 mt-1.5 space-y-1.5 border-l-2 border-border pl-3",children:e.map(s=>{const a=xt(s.macroClass,t),i=!n?.has(s.id),l=s.debug?.mask,c=s.debug?.maskWidth,d=s.debug?.maskHeight;return u("div",{className:`text-xs space-y-0.5 ${i?"":"opacity-40"}`,children:[u("div",{className:"flex items-center gap-1.5",children:[o&&r("input",{type:"checkbox",checked:i,onChange:()=>o(s.id,!i),className:"h-3 w-3 rounded border-border accent-primary cursor-pointer shrink-0"}),r("span",{className:"h-1.5 w-1.5 rounded-full shrink-0",style:{backgroundColor:a}}),r("span",{className:"font-medium",style:{color:a},children:s.macroClass}),u("span",{className:"text-foreground-subtle",children:[(s.score*100).toFixed(0),"%"]}),l&&c&&d&&u("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",c,"x",d]})]}),s.labels.length>0&&r("div",{className:"flex flex-wrap gap-1 ml-5 mt-0.5",children:s.labels.map((p,f)=>u("span",{className:"inline-flex items-center gap-0.5 text-[9px] font-medium px-1 py-0.5 rounded-full",style:{backgroundColor:xt(p.label,t)+"20",color:xt(p.label,t)},children:[p.label," ",u("span",{className:"opacity-60",children:[(p.score*100).toFixed(0),"%"]})]},f))})]},s.id)})})}function WM({alternateLabels:e,colors:t}){const[n,o]=I(!1),s=Object.keys(e);return u("div",{className:"mt-1",children:[u("button",{onClick:()=>o(a=>!a),className:"text-[9px] text-foreground-subtle hover:text-foreground transition-colors flex items-center gap-1",children:[r("span",{className:`transition-transform ${n?"rotate-90":""}`,children:"▶"}),"Alternates (",s.length," source",s.length!==1?"s":"",")"]}),n&&r("div",{className:"mt-1 ml-3 space-y-1.5",children:s.map(a=>{const i=e[a];return!i||i.length===0?null:u("div",{children:[r("div",{className:"text-[9px] font-medium text-foreground-subtle mb-0.5",children:a}),r("div",{className:"flex flex-wrap gap-1",children:i.map((l,c)=>u("span",{className:"inline-flex items-center gap-0.5 text-[9px] px-1 py-0.5 rounded-full",style:{backgroundColor:xt(a,t)+"10",color:xt(a,t),opacity:Math.max(.4,l.score)},children:[l.label,u("span",{className:"opacity-60",children:[(l.score*100).toFixed(1),"%"]})]},c))})]},a)})})]})}function KM({confidence:e}){const t=e>=.8?"bg-success/10 text-success":e>=.5?"bg-warning/10 text-warning":"bg-danger/10 text-danger";return u("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${t}`,children:[(e*100).toFixed(1),"%"]})}function YM({timings:e,totalMs:t,className:n}){const o=Object.entries(e);return o.length===0&&t===void 0?null:u("div",{className:`rounded-lg border border-border bg-surface p-3 space-y-2 ${n??""}`,children:[r("div",{className:"text-xs font-medium text-foreground-subtle uppercase tracking-wide",children:"Timings"}),u("div",{className:"space-y-1 text-xs",children:[o.map(([s,a])=>u("div",{className:"flex justify-between",children:[r("span",{className:"text-foreground-subtle",children:s}),u("span",{className:"font-mono text-foreground",children:[a.toFixed(1),"ms"]})]},s)),t!==void 0&&u("div",{className:"flex justify-between pt-1 border-t border-border font-medium text-foreground",children:[r("span",{children:"Total"}),u("span",{className:"font-mono",children:[t.toFixed(1),"ms"]})]})]})]})}function ZM({images:e,selectedFilename:t,uploadedName:n,onSelect:o,onUpload:s,className:a,accept:i="image/*",uploadLabel:l="Upload..."}){const c=()=>{const d=document.createElement("input");d.type="file",d.accept=i,d.onchange=()=>{const p=d.files?.[0];if(!p)return;const f=new FileReader;f.onload=()=>{const m=f.result,h=m.split(",")[1];h&&s(h,p.name,m)},f.readAsDataURL(p)},d.click()};return u("div",{className:`flex flex-wrap items-center gap-2 ${a??""}`,children:[e.map(d=>r("button",{onClick:()=>o(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)),r("button",{onClick:c,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}),n&&r("span",{className:"text-xs text-foreground-subtle",children:n})]})}const bs="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 XM({runtime:e,backend:t,modelId:n,agentId:o="hub",runtimes:s,backends:a,models:i,agents:l=[],onRuntimeChange:c,onBackendChange:d,onModelChange:p,onAgentChange:f,layout:m="grid",className:h,showAgent:g=!1}){return u("div",{className:`${m==="grid"?"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4":m==="horizontal"?"flex flex-wrap items-end gap-4":"space-y-3"} ${h??""}`,children:[g&&l.length>0&&u("label",{className:"space-y-1",children:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Agent"}),r("select",{value:o,onChange:b=>f?.(b.target.value),className:bs,children:l.map(b=>u("option",{value:b.id,children:[b.name," (",b.status,")"]},b.id))})]}),u("label",{className:"space-y-1",children:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Runtime"}),r("select",{value:e,onChange:b=>c(b.target.value),className:bs,children:s.map(b=>u("option",{value:b.value,disabled:!b.available,children:[b.label,b.available?"":" (unavailable)"]},b.value))})]}),u("label",{className:"space-y-1",children:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Backend"}),r("select",{value:t,onChange:b=>d(b.target.value),className:bs,children:a.map(b=>u("option",{value:b.id,disabled:!b.available,children:[b.label,b.available?"":" (unavailable)"]},b.id))})]}),u("label",{className:"space-y-1",children:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Model"}),r("select",{value:n,onChange:b=>p(b.target.value),className:bs,children:i.length===0?r("option",{value:"",children:"No compatible models"}):i.map(b=>u("option",{value:b.id,children:[b.name,b.downloaded?" ✓":""]},b.id))})]})]})}function JM({className:e}){return u("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:[r("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"}),r("circle",{cx:"12",cy:"12",r:"3"})]})}function e4({className:e}){return u("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:[r("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"}),r("path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}),r("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"}),r("path",{d:"m2 2 20 20"})]})}function t4({className:e}){return r("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:r("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function eb({onLogin:e,serverUrl:t,logoSrc:n,error:o,className:s}){const[a,i]=I(""),[l,c]=I(""),[d,p]=I(!1),[f,m]=I(!1),[h,g]=I(null),x=o??h,b=async y=>{if(y.preventDefault(),!f){g(null),m(!0);try{await e(a,l)}catch(w){const v=w instanceof Error?w.message:"Login failed. Please try again.";g(v)}finally{m(!1)}}};return r("div",{className:Y("flex min-h-screen items-center justify-center bg-background p-4",s),children:u("div",{className:"w-full max-w-sm",children:[n&&r("div",{className:"flex justify-center mb-8",children:r("img",{src:n,alt:"Logo",className:"h-12"})}),t&&r("p",{className:"mb-4 text-center text-xs text-foreground-subtle truncate",children:t}),u("form",{onSubmit:b,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[x&&r("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:x}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"Username"}),r("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"})]}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"Password"}),u("div",{className:"relative",children:[r("input",{type:d?"text":"password",value:l,onChange:y=>c(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"}),r("button",{type:"button",onClick:()=>p(y=>!y),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",tabIndex:-1,children:d?r(e4,{className:"h-4 w-4"}):r(JM,{className:"h-4 w-4"})})]})]}),u("button",{type:"submit",disabled:f,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:[f&&r(t4,{className:"h-4 w-4 animate-spin"}),f?"Logging in...":"Log in"]})]})]})})}const jl="camstack_dev_token",tb=qe(null);function n4(){const e=Ne(tb);if(!e)throw new Error("useDevShell must be used within a DevShell");return e}function r4(){return typeof window>"u"?null:localStorage.getItem(jl)}function o4({className:e}){return u("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:[r("circle",{cx:"12",cy:"12",r:"4"}),r("path",{d:"M12 2v2"}),r("path",{d:"M12 20v2"}),r("path",{d:"m4.93 4.93 1.41 1.41"}),r("path",{d:"m17.66 17.66 1.41 1.41"}),r("path",{d:"M2 12h2"}),r("path",{d:"M20 12h2"}),r("path",{d:"m6.34 17.66-1.41 1.41"}),r("path",{d:"m19.07 4.93-1.41 1.41"})]})}function s4({className:e}){return r("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:r("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})})}function a4({children:e,serverUrl:t,title:n,token:o,onLogout:s}){const a=Yo(),i=q(()=>{const m=t.replace(/^http/,"ws")+"/trpc",h=o2({url:m,connectionParams:()=>({token:o})});return[s2({condition:g=>g.type==="subscription",true:a2({client:h,transformer:El}),false:rh({url:`${t}/trpc`,transformer:El,headers:()=>({authorization:`Bearer ${o}`})})})]},[t,o]),l=q(()=>nh({links:i}),[i]),c=q(()=>S.createClient({links:i}),[i]),d=q(()=>uh({serverUrl:t,token:o}),[t,o]);J(()=>(d.init().catch(()=>{}),()=>{d.close()}),[d]);const p=q(()=>new Jm,[]),f=q(()=>({trpc:l,token:o,logout:s}),[l,o,s]);return r(rd,{system:d,children:r(S.Provider,{client:c,queryClient:p,children:r(eh,{client:p,children:r(tb.Provider,{value:f,children:u("div",{className:"min-h-screen bg-background text-foreground",children:[u("div",{className:"flex items-center justify-between border-b border-border bg-surface px-4 py-2",children:[u("div",{className:"flex items-center gap-2",children:[r("span",{className:"rounded bg-warning/20 px-2 py-0.5 text-xs font-bold text-warning",children:"DEV MODE"}),n&&r("span",{className:"text-sm font-medium text-foreground",children:n}),r("span",{className:"text-xs text-foreground-subtle",children:t})]}),u("div",{className:"flex items-center gap-2",children:[u("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"?r(o4,{className:"h-3.5 w-3.5"}):r(s4,{className:"h-3.5 w-3.5"}),a.mode==="dark"?"Dark":a.mode==="light"?"Light":"System"]}),r("button",{type:"button",onClick:s,className:"rounded-md px-2.5 py-1 text-xs font-medium text-danger hover:bg-danger/10 transition-colors",children:"Logout"})]})]}),r("div",{className:"p-4",children:e({trpc:l,theme:a})})]})})})})})}function nb({children:e,serverUrl:t="https://localhost:4443",title:n}){const[o,s]=I(r4),a=U(async(l,c)=>{const f=await nh({links:[rh({url:`${t}/trpc`,transformer:El})]}).auth.login.mutate({username:l,password:c});if(!f.token)throw new Error("No token returned");localStorage.setItem(jl,f.token),s(f.token)},[t]),i=U(()=>{localStorage.removeItem(jl),s(null)},[]);return o?r(aa,{children:r(a4,{serverUrl:t,title:n,token:o,onLogout:i,children:e})}):r(aa,{children:r(eb,{onLogin:a,serverUrl:t})})}function i4(e,t={}){const{serverUrl:n="https://localhost:4443",title:o,rootId:s="root"}=t,a=document.getElementById(s);if(!a){console.error(`[mountAddonPage] Element #${s} not found`);return}Zm(a).render(_e(nb,{serverUrl:n,title:o,children:({trpc:i,theme:l})=>_e(e,{trpc:i,theme:{isDark:l.resolvedMode==="dark"},navigate:c=>{console.log("[dev] navigate:",c)}})}))}const rb=wn("camstack:custom-field-renderers",{});function ob({renderers:e,children:t}){return r(rb.Provider,{value:e,children:t})}function sb(e){return Ne(rb)[e]??null}const pd=wn("camstack:device-context",null);function ab({deviceId:e,device:t,children:n}){const o={deviceId:e,device:t??null};return r(pd.Provider,{value:o,children:n})}function fd(){return Ne(pd)?.deviceId??null}function ib(){return Ne(pd)?.device??null}const l4=S.accessories.getStatus.useQuery,md=S.addonPages.listPages.useQuery,Nn=S.addons.list.useQuery,c4=S.addons.getLogs.useQuery,d4=S.addons.listPackages.useQuery,hd=S.addons.installPackage.useMutation,u4=S.addons.installFromWorkspace.useMutation,p4=S.addons.isWorkspaceAvailable.useQuery,f4=S.addons.listWorkspacePackages.useQuery,lb=S.addons.uninstallPackage.useMutation,cb=S.addons.reloadPackages.useMutation,db=S.addons.searchAvailable.useQuery,gd=S.addons.listUpdates.useQuery,Hl=S.addons.updatePackage.useMutation,m4=S.addons.rollbackPackage.useMutation,ub=S.addons.forceRefresh.useMutation,pb=S.addons.restartServer.useMutation,bd=S.addons.getLastRestart.useQuery,fb=S.addons.listFrameworkPackages.useQuery,Xo=S.addons.listCapabilityProviders.useQuery,mb=S.addons.setCapabilityProviderEnabled.useMutation,h4=S.addons.updateFrameworkPackage.useMutation,hb=S.addons.startBulkUpdate.useMutation,g4=S.addons.getBulkUpdateState.useQuery,gb=S.addons.cancelBulkUpdate.useMutation,bb=S.addons.listActiveBulkUpdates.useQuery,xb=S.addons.getVersions.useQuery,Jo=S.addons.restartAddon.useMutation,yb=S.addons.retryLoad.useMutation,vb=S.addons.getAutoUpdateSettings.useQuery,b4=S.addons.setAutoUpdateSettings.useMutation,wb=S.addons.getAddonAutoUpdate.useQuery,Nb=S.addons.setAddonAutoUpdate.useMutation,kb=S.addons.applyAutoUpdateToAll.useMutation,x4=S.addons.custom.useMutation,y4=S.addons.onAddonLogs.useSubscription,xd=S.addonSettings.getGlobalSettings.useQuery,Sb=S.addonSettings.updateGlobalSettings.useMutation,v4=S.addonSettings.getDeviceSettings.useQuery,Cb=S.addonSettings.updateDeviceSettings.useMutation,Mb=S.addonWidgets.listWidgets.useQuery,w4=S.alerts.emit.useMutation,N4=S.alerts.update.useMutation,Ab=S.alerts.list.useQuery,Eb=S.alerts.getUnreadCount.useQuery,Ib=S.alerts.markRead.useMutation,Pb=S.alerts.markAllRead.useMutation,_b=S.alerts.dismiss.useMutation,k4=S.audioAnalysis.resolveDeviceSettings.useQuery,S4=S.audioAnalysis.getDeviceSettingsContribution.useQuery,C4=S.audioAnalysis.getDeviceLiveContribution.useQuery,M4=S.audioAnalysis.applyDeviceSettingsPatch.useMutation,A4=S.audioAnalyzer.analyseChunk.useMutation,E4=S.audioAnalyzer.classify.useQuery,I4=S.audioAnalyzer.isReady.useQuery,P4=S.audioAnalyzer.dispose.useMutation,$b=S.audioAnalyzer.reprobeAudioEngine.useMutation,_4=S.audioCodec.listSupportedCodecs.useQuery,$4=S.audioCodec.canHandle.useQuery,D4=S.audioCodec.createDecodeSession.useMutation,L4=S.audioCodec.createEncodeSession.useMutation,T4=S.audioCodec.closeSession.useMutation,R4=S.audioCodec.pushEncodedFrame.useMutation,O4=S.audioCodec.pullPcm.useQuery,B4=S.audioCodec.pushPcm.useMutation,z4=S.audioCodec.pullEncoded.useQuery,F4=S.audioCodec.flushEncode.useMutation,j4=S.audioCodec.listActiveSessions.useQuery,Db=S.audioMetrics.getCurrentSnapshot.useQuery,H4=S.audioMetrics.getHistory.useQuery,yd=S.backup.listDestinations.useQuery,Lb=S.backup.trigger.useMutation,V4=S.backup.list.useQuery,Tb=S.backup.listLocations.useQuery,Rb=S.backup.getEntries.useQuery,Ob=S.backup.restore.useMutation,Bb=S.backup.delete.useMutation,vd=S.backup.listArchives.useQuery,zb=S.backup.upsertDestinationPolicy.useMutation,Fb=S.backup.previewSchedule.useQuery,U4=S.battery.getStatus.useQuery,q4=S.brightness.setBrightness.useMutation,Q4=S.brightness.getStatus.useQuery,G4=S.cameraCredentials.getCredentials.useQuery,W4=S.cameraCredentials.getStatus.useQuery,K4=S.cameraPipelineConfig.getDeviceSettingsContribution.useQuery,Y4=S.cameraPipelineConfig.getDeviceLiveContribution.useQuery,Z4=S.cameraPipelineConfig.applyDeviceSettingsPatch.useMutation,X4=S.cameraStreams.getCameraStreams.useQuery,J4=S.cameraStreams.getBrokerStreams.useQuery,jb=S.cameraStreams.getRtspEntries.useQuery,eA=S.decoder.supportsCodec.useQuery,tA=S.decoder.getInfo.useQuery,nA=S.decoder.createSession.useQuery,rA=S.decoder.destroySession.useQuery,oA=S.decoder.pushPacket.useQuery,sA=S.decoder.openStream.useQuery,aA=S.decoder.pullFrames.useQuery,iA=S.decoder.pullHandles.useQuery,lA=S.decoder.getFrame.useQuery,cA=S.decoder.getShmStats.useQuery,dA=S.decoder.updateConfig.useQuery,uA=S.decoder.getStats.useQuery,pA=S.decoder.listActiveSessions.useQuery,Hb=S.decoder.reprobeHwaccel.useMutation,fA=S.detectionPipeline.getDeviceSettingsContribution.useQuery,mA=S.detectionPipeline.getDeviceLiveContribution.useQuery,hA=S.detectionPipeline.applyDeviceSettingsPatch.useMutation,Vb=S.deviceDiscovery.listDiscovered.useQuery,Ub=S.deviceDiscovery.refreshDiscovery.useMutation,gA=S.deviceDiscovery.adoptDevice.useMutation,bA=S.deviceDiscovery.releaseDevice.useMutation,xA=S.deviceDiscovery.getStatus.useQuery,wd=S.deviceExport.getStatus.useQuery,qb=S.deviceExport.listSupportedDeviceKinds.useQuery,Qb=S.deviceExport.listExposedDevices.useQuery,Gb=S.deviceExport.exposeDevice.useMutation,Wb=S.deviceExport.unexposeDevice.useMutation,yA=S.deviceExport.getDeviceSettingsContribution.useQuery,vA=S.deviceExport.getDeviceLiveContribution.useQuery,wA=S.deviceExport.applyDeviceSettingsPatch.useMutation,NA=S.deviceManager.allocateDeviceId.useMutation,kA=S.deviceManager.registerDevice.useMutation,SA=S.deviceManager.removeDevice.useMutation,CA=S.deviceManager.persistConfig.useMutation,MA=S.deviceManager.loadConfig.useQuery,AA=S.deviceManager.loadRuntimeState.useQuery,EA=S.deviceManager.loadMeta.useQuery,Kb=S.deviceManager.setName.useMutation,Yb=S.deviceManager.setLocation.useMutation,IA=S.deviceManager.setMetadata.useMutation,Zb=S.deviceManager.listLocations.useQuery,PA=S.deviceManager.addLocation.useMutation,_A=S.deviceManager.removeLocation.useMutation,$A=S.deviceManager.setDisabled.useMutation,DA=S.deviceManager.listPersistedByAddon.useQuery,kn=S.deviceManager.listAll.useQuery,Lr=S.deviceManager.getDevice.useQuery,Xb=S.deviceManager.getChildren.useQuery,LA=S.deviceManager.getStreamSources.useQuery,TA=S.deviceManager.getConfigSchema.useQuery,RA=S.deviceManager.getSettingsSchema.useQuery,OA=S.deviceManager.updateConfig.useMutation,Jb=S.deviceManager.enable.useMutation,ex=S.deviceManager.disable.useMutation,tx=S.deviceManager.remove.useMutation,BA=S.deviceManager.getStreamProfileMap.useQuery,zA=S.deviceManager.setStreamProfileMap.useMutation,FA=S.deviceManager.probeStreams.useMutation,nx=S.deviceManager.getBindings.useQuery,jA=S.deviceManager.getAllBindings.useQuery,rx=S.deviceManager.setWrapperActive.useMutation,HA=S.deviceManager.listWrappersForCap.useQuery,ox=S.deviceManager.listBindableCapsForDeviceType.useQuery,VA=S.deviceManager.getDeviceSettingsAggregate.useQuery,UA=S.deviceManager.getDeviceLiveInfoAggregate.useQuery,Nd=S.deviceManager.getDeviceAggregate.useQuery,qA=S.deviceManager.updateDeviceField.useMutation,sx=S.deviceManager.updateDeviceFieldsBatch.useMutation,kd=S.deviceManager.discoverDevices.useMutation,ax=S.deviceManager.adoptDevice.useMutation,ix=S.deviceManager.getCreationSchema.useQuery,lx=S.deviceManager.createDevice.useMutation,Sd=S.deviceManager.testCreationField.useMutation,QA=S.deviceManager.testField.useMutation,GA=S.deviceManager.getDeviceStatusAggregate.useQuery,WA=S.deviceOps.getStreamSources.useQuery,KA=S.deviceOps.getConfigEntries.useQuery,YA=S.deviceOps.setConfig.useMutation,ZA=S.deviceOps.removeDevice.useMutation,XA=S.deviceOps.getSettingsSchema.useQuery,JA=S.deviceProvider.start.useMutation,eE=S.deviceProvider.stop.useMutation,tE=S.deviceProvider.getStatus.useQuery,nE=S.deviceProvider.getDevices.useQuery,rE=S.deviceProvider.supportsDiscovery.useQuery,oE=S.deviceProvider.discoverDevices.useMutation,sE=S.deviceProvider.adoptDiscoveredDevice.useMutation,aE=S.deviceProvider.supportsManualCreation.useQuery,iE=S.deviceProvider.getChildCreationSchema.useQuery,lE=S.deviceProvider.createDevice.useMutation,cE=S.deviceProvider.testCreationField.useMutation,dE=S.deviceState.getSnapshot.useQuery,uE=S.deviceState.getCapSlice.useQuery,pE=S.deviceState.getAllSnapshots.useQuery,fE=S.deviceState.setCapSlice.useMutation,mE=S.deviceStatus.getStatus.useQuery,hE=S.doorbell.getStatus.useQuery,gE=S.events.getEvents.useQuery,bE=S.events.getEventThumbnail.useQuery,xE=S.events.getEventClipUrl.useQuery,yE=S.featureProbe.getStatus.useQuery,Cd=S.integrations.list.useQuery,cx=S.integrations.get.useQuery,dx=S.integrations.getByAddonId.useQuery,ux=S.integrations.create.useMutation,px=S.integrations.update.useMutation,fx=S.integrations.delete.useMutation,vE=S.integrations.getSettings.useQuery,wE=S.integrations.setSettings.useMutation,mx=S.integrations.getAvailableTypes.useQuery,hx=S.integrations.testConnection.useMutation,gx=S.intercom.startSession.useMutation,bx=S.intercom.handleAnswer.useMutation,xx=S.intercom.stopSession.useMutation,NE=S.intercom.startTalkSession.useMutation,kE=S.intercom.pushTalkPcm.useMutation,SE=S.intercom.endTalkSession.useMutation,CE=S.intercom.getStatus.useQuery,yx=S.localNetwork.list.useQuery,ME=S.localNetwork.getPreferred.useQuery,vx=S.localNetwork.getConnectionEndpoints.useQuery,wx=S.localNetwork.getAllowedAddresses.useQuery,Nx=S.localNetwork.setAllowedAddresses.useMutation,kx=S.localNetwork.resetAllowlistToBestMatch.useMutation,Sx=S.meshNetwork.getStatus.useQuery,AE=S.meshNetwork.join.useMutation,Cx=S.meshNetwork.startLogin.useMutation,Mx=S.meshNetwork.leave.useMutation,Ax=S.meshNetwork.logout.useMutation,Ex=S.meshNetwork.listPeers.useQuery,EE=S.meshNetwork.testConnection.useMutation,IE=S.metricsProvider.collectSnapshot.useQuery,PE=S.metricsProvider.getCached.useQuery,_E=S.metricsProvider.getCurrent.useQuery,$E=S.metricsProvider.getDiskSpace.useQuery,DE=S.metricsProvider.getGpuInfo.useQuery,LE=S.metricsProvider.getCpuTemperature.useQuery,TE=S.metricsProvider.getProcessStats.useQuery,RE=S.metricsProvider.listAddonInstances.useQuery,OE=S.metricsProvider.getAddonStats.useQuery,Ix=S.metricsProvider.listNodeProcesses.useQuery,Px=S.metricsProvider.killProcess.useMutation,BE=S.motion.isDetected.useQuery,zE=S.motion.getStatus.useQuery,FE=S.motionDetection.analyze.useMutation,jE=S.motionDetection.removeCamera.useMutation,HE=S.motionDetection.reset.useMutation,VE=S.motionDetection.getDeviceSettingsContribution.useQuery,UE=S.motionDetection.getDeviceLiveContribution.useQuery,qE=S.motionDetection.applyDeviceSettingsPatch.useMutation,QE=S.motionTrigger.setMotionTrigger.useMutation,GE=S.motionTrigger.getStatus.useQuery,WE=S.motionZones.getOptions.useQuery,KE=S.motionZones.setZone.useMutation,YE=S.motionZones.getStatus.useQuery,ZE=S.mqttBroker.listBrokers.useQuery,XE=S.mqttBroker.getBrokerConfig.useQuery,JE=S.mqttBroker.addBroker.useMutation,eI=S.mqttBroker.removeBroker.useMutation,tI=S.mqttBroker.testConnection.useMutation,nI=S.mqttBroker.startEmbeddedBroker.useMutation,rI=S.mqttBroker.stopEmbeddedBroker.useMutation,_x=S.mqttBroker.getStatus.useQuery,oI=S.nativeObjectDetection.setEnabled.useMutation,sI=S.nativeObjectDetection.getStatus.useQuery,$x=S.networkAccess.start.useMutation,Dx=S.networkAccess.stop.useMutation,aI=S.networkAccess.getEndpoint.useQuery,Lx=S.networkAccess.getStatus.useQuery,iI=S.networkAccess.listEndpoints.useQuery,Tx=S.networkQuality.getDeviceStats.useQuery,lI=S.networkQuality.getAllStats.useQuery,cI=S.networkQuality.reportClientStats.useMutation,Hn=S.nodes.topology.useQuery,dI=S.nodes.deployAddon.useMutation,Rx=S.nodes.undeployAddon.useMutation,Ua=S.nodes.restartAddon.useMutation,Ox=S.nodes.restartProcess.useMutation,uI=S.nodes.restartNode.useMutation,pI=S.nodes.shutdownNode.useMutation,Bx=S.nodes.renameNode.useMutation,zx=S.nodes.clusterAddonStatus.useQuery,Fx=S.nodes.getCapUsageGraph.useQuery,jx=S.nodes.getNodeAddons.useQuery,Hx=S.nodes.setProcessLogLevel.useMutation,fI=S.nodes.executeQuery.useMutation,mI=S.notificationOutput.send.useMutation,hI=S.notificationOutput.sendTest.useMutation,gI=S.osd.setOverlay.useMutation,bI=S.osd.getStatus.useQuery,xI=S.pipelineAnalytics.getActiveTracks.useQuery,yI=S.pipelineAnalytics.getTrack.useQuery,vI=S.pipelineAnalytics.listTracks.useQuery,wI=S.pipelineAnalytics.clearTracks.useMutation,NI=S.pipelineAnalytics.getMotionEvents.useQuery,kI=S.pipelineAnalytics.getObjectEvents.useQuery,SI=S.pipelineAnalytics.getAudioEvents.useQuery,CI=S.pipelineAnalytics.getEventMedia.useQuery,MI=S.pipelineAnalytics.getTrackMedia.useQuery,AI=S.pipelineAnalytics.getDeviceSettingsContribution.useQuery,EI=S.pipelineAnalytics.getDeviceLiveContribution.useQuery,II=S.pipelineAnalytics.applyDeviceSettingsPatch.useMutation,Vx=S.pipelineExecutor.getAvailableEngines.useQuery,Ux=S.pipelineExecutor.getSelectedEngine.useQuery,PI=S.pipelineExecutor.getDefaultSteps.useQuery,qx=S.pipelineExecutor.reprobeEngine.useMutation,_I=S.pipelineExecutor.getVideoPipelineSteps.useQuery,$I=S.pipelineExecutor.setVideoPipelineSteps.useMutation,es=S.pipelineExecutor.getSchema.useQuery,DI=S.pipelineExecutor.getGlobalSteps.useQuery,LI=S.pipelineExecutor.getGlobalPipelineConfig.useQuery,TI=S.pipelineExecutor.getOrchestratorConfigSchema.useQuery,RI=S.pipelineExecutor.listTemplates.useQuery,OI=S.pipelineExecutor.saveTemplate.useMutation,BI=S.pipelineExecutor.updateTemplate.useMutation,zI=S.pipelineExecutor.deleteTemplate.useMutation,FI=S.pipelineExecutor.getCapabilities.useQuery,jI=S.pipelineExecutor.getAddonModels.useQuery,Qx=S.pipelineExecutor.downloadModel.useMutation,Gx=S.pipelineExecutor.deleteModel.useMutation,HI=S.pipelineExecutor.detect.useQuery,VI=S.pipelineExecutor.runPipeline.useMutation,UI=S.pipelineExecutor.runPipelineBatch.useMutation,qI=S.pipelineExecutor.cacheFrameInPool.useMutation,QI=S.pipelineExecutor.inferCached.useMutation,GI=S.pipelineExecutor.uncacheFrame.useMutation,WI=S.pipelineExecutor.getEffectiveTuning.useQuery,Wx=S.pipelineExecutor.listLoadedEngines.useQuery,KI=S.pipelineExecutor.spinEngine.useMutation,Kx=S.pipelineExecutor.killEngine.useMutation,YI=S.pipelineExecutor.listReferenceImages.useQuery,ZI=S.pipelineExecutor.getReferenceImage.useQuery,XI=S.pipelineExecutor.getReferenceAudioFiles.useQuery,JI=S.pipelineExecutor.getReferenceAudio.useQuery,eP=S.pipelineExecutor.getAudioCapabilities.useQuery,tP=S.pipelineExecutor.runAudioTest.useMutation,nP=S.pipelineExecutor.getDetectionConfigSchema.useQuery,Yx=S.pipelineOrchestrator.assignPipeline.useMutation,Zx=S.pipelineOrchestrator.unassignPipeline.useMutation,Xx=S.pipelineOrchestrator.rebalance.useMutation,qa=S.pipelineOrchestrator.getPipelineAssignments.useQuery,Md=S.pipelineOrchestrator.getPipelineAssignment.useQuery,Jx=S.pipelineOrchestrator.getAgentLoad.useQuery,rP=S.pipelineOrchestrator.getGlobalMetrics.useQuery,oP=S.pipelineOrchestrator.getCameraMetrics.useQuery,ey=S.pipelineOrchestrator.getCapabilityBindings.useQuery,ty=S.pipelineOrchestrator.setCapabilityBinding.useMutation,ny=S.pipelineOrchestrator.assignDecoder.useMutation,ry=S.pipelineOrchestrator.unassignDecoder.useMutation,oy=S.pipelineOrchestrator.getDecoderAssignments.useQuery,sy=S.pipelineOrchestrator.assignAudio.useMutation,ay=S.pipelineOrchestrator.unassignAudio.useMutation,sP=S.pipelineOrchestrator.getAudioAssignment.useQuery,iy=S.pipelineOrchestrator.getAudioNodeLoad.useQuery,ly=S.pipelineOrchestrator.getAudioAssignments.useQuery,aP=S.pipelineOrchestrator.getDecoderAssignment.useQuery,Ad=S.pipelineOrchestrator.getAgentSettings.useQuery,no=S.pipelineOrchestrator.listAgentSettings.useQuery,Ed=S.pipelineOrchestrator.setAgentAddonDefaults.useMutation,cy=S.pipelineOrchestrator.removeAgentSettings.useMutation,Id=S.pipelineOrchestrator.getCameraSettings.useQuery,dy=S.pipelineOrchestrator.setCameraStepToggle.useMutation,iP=S.pipelineOrchestrator.getCameraStepOverrides.useQuery,uy=S.pipelineOrchestrator.setCameraStepOverride.useMutation,py=S.pipelineOrchestrator.setCameraPipelineForAgent.useMutation,fy=S.pipelineOrchestrator.resolvePipeline.useQuery,my=S.pipelineOrchestrator.listTemplates.useQuery,lP=S.pipelineOrchestrator.saveTemplate.useMutation,hy=S.pipelineOrchestrator.updateTemplate.useMutation,gy=S.pipelineOrchestrator.deleteTemplate.useMutation,cP=S.pipelineOrchestrator.getDeviceSettingsContribution.useQuery,dP=S.pipelineOrchestrator.getDeviceLiveContribution.useQuery,uP=S.pipelineOrchestrator.applyDeviceSettingsPatch.useMutation,pP=S.pipelineRunner.attachCamera.useMutation,fP=S.pipelineRunner.detachCamera.useMutation,mP=S.pipelineRunner.reportMotion.useMutation,hP=S.pipelineRunner.getLocalLoad.useQuery,gP=S.pipelineRunner.getLocalMetrics.useQuery,by=S.pipelineRunner.getCameraMetrics.useQuery,bP=S.pipelineRunner.getAllCameraMetrics.useQuery,xy=S.pipelineRunner.getLocalCameras.useQuery,xP=S.platformProbe.getCapabilities.useQuery,yP=S.platformProbe.getHardware.useQuery,vP=S.platformProbe.resolveInferenceConfig.useQuery,wP=S.platformProbe.resolveHwAccel.useQuery,NP=S.platformProbe.getHardwareEncoders.useQuery,kP=S.platformProbe.refreshHardwareEncoders.useMutation,SP=S.privacyMask.getOptions.useQuery,CP=S.privacyMask.setMask.useMutation,MP=S.privacyMask.getStatus.useQuery,AP=S.ptz.move.useMutation,EP=S.ptz.continuousMove.useMutation,IP=S.ptz.stop.useMutation,PP=S.ptz.getPresets.useQuery,_P=S.ptz.goToPreset.useMutation,$P=S.ptz.savePreset.useMutation,DP=S.ptz.deletePreset.useMutation,LP=S.ptz.getOptions.useQuery,TP=S.ptz.goHome.useMutation,RP=S.ptz.getPosition.useQuery,OP=S.ptz.setAutofocus.useMutation,BP=S.ptz.getStatus.useQuery,yy=S.ptzAutotrack.getStatus.useQuery,vy=S.ptzAutotrack.setEnabled.useMutation,zP=S.ptzAutotrack.getSettings.useQuery,wy=S.ptzAutotrack.setSettings.useMutation,Ny=S.reboot.reboot.useMutation,FP=S.recording.getSegments.useQuery,jP=S.recording.getPlaybackUrl.useQuery,HP=S.recording.getThumbnailAt.useQuery,VP=S.recordingEngine.getStatus.useQuery,ky=S.recordingEngine.enable.useMutation,Sy=S.recordingEngine.disable.useMutation,Cy=S.recordingEngine.getConfig.useQuery,UP=S.recordingEngine.updateConfig.useMutation,qP=S.recordingEngine.getPlaylist.useQuery,QP=S.recordingEngine.getThumbnail.useQuery,My=S.recordingEngine.getSegments.useQuery,GP=S.recordingEngine.getAvailability.useQuery,WP=S.recordingEngine.estimateStorage.useQuery,KP=S.recordingEngine.estimateGlobalStorage.useQuery,Ay=S.recordingEngine.getStorageUsage.useQuery,YP=S.recordingEngine.setPolicy.useMutation,ZP=S.recordingEngine.getPolicy.useQuery,Ey=S.recordingEngine.getPolicyStatus.useQuery,Iy=S.recordingEngine.getRetentionConfig.useQuery,XP=S.recordingEngine.updateRetentionConfig.useMutation,JP=S.recordingEngine.getMotionStats.useQuery,e_=S.settingsStore.get.useQuery,t_=S.settingsStore.set.useMutation,n_=S.settingsStore.query.useQuery,r_=S.settingsStore.insert.useMutation,o_=S.settingsStore.update.useMutation,s_=S.settingsStore.delete.useMutation,a_=S.settingsStore.count.useQuery,i_=S.settingsStore.isEmpty.useQuery,l_=S.settingsStore.declareCollection.useMutation,c_=S.snapshot.getSnapshot.useQuery,d_=S.snapshot.invalidateCache.useMutation,u_=S.snapshot.getStatus.useQuery,p_=S.snapshot.getDeviceSettingsContribution.useQuery,f_=S.snapshot.getDeviceLiveContribution.useQuery,m_=S.snapshot.applyDeviceSettingsPatch.useMutation,h_=S.snapshotProvider.supportsDevice.useQuery,g_=S.snapshotProvider.getSnapshot.useQuery,b_=S.storage.resolve.useQuery,x_=S.storage.write.useMutation,y_=S.storage.read.useQuery,v_=S.storage.exists.useQuery,w_=S.storage.list.useQuery,N_=S.storage.delete.useMutation,k_=S.storage.getAvailableSpace.useQuery,S_=S.storage.beginUpload.useMutation,C_=S.storage.writeChunk.useMutation,M_=S.storage.finalizeUpload.useMutation,A_=S.storage.abortUpload.useMutation,E_=S.storage.beginDownload.useMutation,I_=S.storage.readChunk.useQuery,P_=S.storage.endDownload.useMutation,Py=S.storage.listLocations.useQuery,__=S.storage.getDefaultLocation.useQuery,Qa=S.storage.upsertLocation.useMutation,_y=S.storage.deleteLocation.useMutation,$_=S.storage.testLocation.useQuery,Pd=S.storage.listProviders.useQuery,D_=S.storage.testConfig.useQuery,L_=S.streamBroker.publishCameraStream.useMutation,T_=S.streamBroker.retractCameraStream.useMutation,R_=S.streamBroker.assignProfile.useMutation,O_=S.streamBroker.unassignProfile.useMutation,B_=S.streamBroker.listAllCameraStreams.useQuery,z_=S.streamBroker.listAllProfileSlots.useQuery,F_=S.streamBroker.getBrokerStats.useQuery,j_=S.streamBroker.listClients.useQuery,H_=S.streamBroker.killClient.useMutation,V_=S.streamBroker.restartProfile.useMutation,U_=S.streamBroker.getStreamUrl.useQuery,q_=S.streamBroker.getStreamWithCodec.useMutation,Q_=S.streamBroker.releaseStreamWithCodec.useMutation,G_=S.streamBroker.subscribeAudioChunks.useMutation,W_=S.streamBroker.pullAudioChunks.useQuery,K_=S.streamBroker.unsubscribeAudioChunks.useMutation,Y_=S.streamBroker.subscribeFrames.useMutation,Z_=S.streamBroker.pullFrameHandles.useQuery,X_=S.streamBroker.unsubscribeFrames.useMutation,J_=S.streamBroker.setPreBufferDuration.useMutation,e$=S.streamBroker.getPreBufferInfo.useQuery,t$=S.streamBroker.getRtspPort.useQuery,n$=S.streamBroker.getAllRtspEntries.useQuery,r$=S.streamBroker.getRtspEntry.useQuery,$y=S.streamBroker.regenerateRtspToken.useMutation,o$=S.streamBroker.setRtspEnabled.useMutation,s$=S.streamBroker.isRtspEnabled.useQuery,a$=S.streamBroker.getDeviceSettingsContribution.useQuery,i$=S.streamBroker.getDeviceLiveContribution.useQuery,l$=S.streamBroker.applyDeviceSettingsPatch.useMutation,c$=S.streamCatalog.getCatalog.useQuery,d$=S.streamParams.getOptions.useQuery,u$=S.streamParams.setProfile.useMutation,p$=S.streamParams.getConfigSchema.useQuery,f$=S.streamParams.getStatus.useQuery,m$=S.switch.setState.useMutation,h$=S.switch.getStatus.useQuery,g$=S.system.info.useQuery,b$=S.system.health.useQuery,x$=S.system.featureFlags.useQuery,y$=S.system.networkAddresses.useQuery,v$=S.system.getRetentionConfig.useQuery,w$=S.system.setRetentionConfig.useMutation,N$=S.system.forceRetentionCleanup.useMutation,Dy=S.toast.onToast.useSubscription,_d=S.turnProvider.getTurnServers.useQuery,$d=S.userManagement.listUsers.useQuery,Ly=S.userManagement.createUser.useMutation,Ty=S.userManagement.updateUser.useMutation,Ry=S.userManagement.deleteUser.useMutation,Dd=S.userManagement.resetPassword.useMutation,Oy=S.userManagement.setUserScopes.useMutation,k$=S.userManagement.validateCredentials.useMutation,By=S.userManagement.listApiKeys.useQuery,S$=S.userManagement.createApiKey.useMutation,zy=S.userManagement.revokeApiKey.useMutation,C$=S.userManagement.validateApiKey.useMutation,Fy=S.userManagement.createScopedToken.useMutation,jy=S.userManagement.revokeScopedToken.useMutation,M$=S.userManagement.validateScopedToken.useQuery,Hy=S.userManagement.listScopedTokens.useQuery,A$=S.userManagement.setupTotp.useMutation,E$=S.userManagement.confirmTotp.useMutation,Vy=S.userManagement.disableTotp.useMutation,Uy=S.userManagement.getTotpStatus.useQuery,I$=S.userManagement.verifyTotp.useMutation,P$=S.userManagement.oauthIssueCode.useMutation,_$=S.userManagement.oauthExchangeCode.useMutation,$$=S.userManagement.oauthRefresh.useMutation,D$=S.userManagement.oauthVerifyAccessToken.useQuery,qy=S.userManagement.listOauthSessions.useQuery,Qy=S.userManagement.revokeOauthSession.useMutation,L$=S.webrtcSession.listStreams.useQuery,T$=S.webrtcSession.createSession.useMutation,R$=S.webrtcSession.handleOffer.useMutation,O$=S.webrtcSession.handleAnswer.useMutation,B$=S.webrtcSession.addIceCandidate.useMutation,z$=S.webrtcSession.getIceCandidates.useQuery,F$=S.webrtcSession.closeSession.useMutation,j$=S.webrtcSession.hasAdaptiveBitrate.useQuery,H$=S.zoneAnalytics.getCurrentSnapshot.useQuery,V$=S.zoneAnalytics.getZoneHistory.useQuery,U$=S.zoneAnalytics.getCameraHistory.useQuery,q$=S.zoneAnalytics.getUnzonedHistory.useQuery,Q$=S.zoneRules.listRules.useQuery,G$=S.zoneRules.setRules.useMutation,W$=S.zones.listZones.useQuery,K$=S.zones.addZone.useMutation,Y$=S.zones.removeZone.useMutation,Z$=S.zones.updateZone.useMutation,Gy=wn("camstack:widget-registry",null),ca=new Map,xs=new Map,Np=new Set;function Ld(e,t){return`${e}::${t}`}function X$(e){if(!e||typeof e!="object")return!1;const t=e.default;return t!==null&&typeof t=="object"}function J$(e){if(!e||typeof e!="object")return typeof e;const t=e,n=Object.getPrototypeOf(t),o=n&&typeof n=="object"?n.constructor?.name:void 0;return{ownKeys:Object.keys(t),allKeys:Object.getOwnPropertyNames(t),proto:typeof o=="string"?o:void 0}}async function Td(e,t,n){const o=Ld(e,t),s=ca.get(o);if(s)return s;const a=xs.get(o);if(a)return a;Np.has(e)||(Bc(),Pr.registerRemotes([{name:e,entry:n,type:"module"}],{force:!1}),Np.add(e));const i=t.startsWith("./")?t.slice(2):t,l=Pr.loadRemote(`${e}/${i}`).then(c=>{if(!X$(c)){const p=J$(c);throw new Error(`Remote ${e} (${n}) does not expose a default record on '${t}'. Got: ${JSON.stringify(p)}`)}const d=c.default;return ca.set(o,d),xs.delete(o),d}).catch(c=>{throw xs.delete(o),c});return xs.set(o,l),l}function Vl(e,t){return ca.get(Ld(e,t))}const eD=3e4,tD=2e3;function Wy({children:e}){const t=Me(),n=ne(Date.now()),{data:o}=Mb(void 0,{staleTime:0,refetchOnMount:"always",refetchInterval:c=>{const d=c.state.data;return d&&d.length>0||Date.now()-n.current>=eD?!1:tD}});ft("addon.widget-ready",()=>{t.invalidateQueries({queryKey:[["addonWidgets","listWidgets"]]})});const[s,a]=I(0),i=q(()=>o??[],[o]);J(()=>{if(i.length===0)return;let c=!1;const d=new Set;for(const p of i){const f=Ld(p.remote.remoteName,p.remote.exposedModule);if(d.has(f)||(d.add(f),ca.has(f)))continue;const m=p.bundleUrl;Td(p.remote.remoteName,p.remote.exposedModule,m).then(()=>{c||a(h=>h+1)}).catch(h=>{const g=h instanceof Error?h.message:String(h);(typeof globalThis<"u"?globalThis.console:void 0)?.error?.("[WidgetRegistry] Failed to load widget remote",{remoteName:p.remote.remoteName,exposedModule:p.remote.exposedModule,entryUrl:m,reason:g})})}return()=>{c=!0}},[i]);const l=q(()=>{const c=new Map,d=new Map;for(const f of i)c.set(`${f.addonId}/${f.stableId}`,f),d.set(f.remote.remoteName,f.bundleUrl);const p=(f,m)=>({widgetId:f,addonId:m.addonId,stableId:m.stableId,tab:m.tab,subTab:m.subTab,label:m.label,order:m.order,kind:m.kind,remote:m.remote,description:m.description,icon:m.icon,bundleUrl:m.bundleUrl,hosts:m.hosts,requires:m.requires,defaultSize:m.defaultSize,allowedSizes:m.allowedSizes,defaultColumns:m.defaultColumns,defaultRows:m.defaultRows});return{resolve:f=>{const m=c.get(f);if(!m)return;const h=Vl(m.remote.remoteName,m.remote.exposedModule);if(!h)return null;const g=m.remote.componentKey??m.stableId,x=h[g];if(x)return x},metadata:f=>{const m=c.get(f);if(m)return p(f,m)},listAll:()=>{const f=[];for(const[m,h]of c)f.push(p(m,h));return f},entryUrlFor:f=>d.get(f)}},[i,s]);return r(Gy.Provider,{value:l,children:e})}function nD(e){return Ga().resolve(e)}function Ky(e){return Ga().metadata(e)}function Yy(){return Ga().listAll()}function Zy(e,t){const n=Rd(),o=t??n?.entryUrlFor(e.remoteName),[s,a]=I(0),[i,l]=I(!1);return J(()=>{if(!o||(l(!1),Vl(e.remoteName,e.exposedModule)))return;let c=!1;return Td(e.remoteName,e.exposedModule,o).then(()=>{c||a(d=>d+1)}).catch(d=>{const p=d instanceof Error?d.message:String(d);(typeof globalThis<"u"?globalThis.console:void 0)?.error?.("[WidgetRegistry] Failed to load remote component",{remoteName:e.remoteName,exposedModule:e.exposedModule,entryUrl:o,reason:p}),c||l(!0)}),()=>{c=!0}},[e.remoteName,e.exposedModule,o]),q(()=>{if(!o||i)return;const c=Vl(e.remoteName,e.exposedModule);if(!c)return null;const d=e.componentKey;return d===void 0?Object.values(c)[0]??void 0:c[d]??void 0},[e.remoteName,e.exposedModule,e.componentKey,o,s,i])}function Ga(){const e=Rd();if(!e)throw new Error("useWidgetRegistry(): no <WidgetRegistryProvider> in tree");return e}function Rd(){return rD(Gy)}function rD(e){return Ne(e)}function oD({deviceId:e}){const t=De(),n=wt(t.trpcClient,e),[o,s]=I(null),[a,i]=I(!1);J(()=>{if(!n)return;let c=!1;return(async()=>{try{const d=await n.ptz?.getStatus({});if(c||!d)return;s(d.autofocus)}catch{}})(),()=>{c=!0}},[n]);const l=U(async()=>{if(!(!n?.ptz||o===null)){i(!0);try{const c=!o;await n.ptz.setAutofocus({enabled:c}),s(c)}catch(c){console.error("ptz.setAutofocus failed",c)}finally{i(!1)}}},[n,o]);return o===null?null:u("div",{className:"flex items-center justify-between border-t border-border/40 mt-2 pt-2",children:[r("span",{className:"text-[10.5px] font-semibold text-foreground",children:"Autofocus"}),u("button",{type:"button",onClick:()=>void l(),disabled:a,"aria-pressed":o,className:`flex items-center gap-1.5 rounded-md px-2 py-1 text-[10px] font-medium transition-colors ${o?"bg-success/15 text-success hover:bg-success/25":"bg-surface-elevated/40 text-foreground-subtle hover:bg-surface-hover hover:text-foreground"} disabled:opacity-50`,children:[r("span",{className:`h-1.5 w-1.5 rounded-full ${o?"bg-success":"bg-foreground-subtle/40"}`}),o?"On":"Off"]})]})}function Xy({deviceId:e}){const t=De(),n=Number.isFinite(e),o=ad(t.trpcClient,n?e:0,{enabled:n});if(!n)return u("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]});const s=o.options?.hasAutofocus===!0;return u("div",{className:"flex flex-col h-full overflow-y-auto",children:[r("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider mb-2",children:"PTZ"}),r(id,{controls:o,mode:"panel"}),s&&r(oD,{deviceId:e})]})}function Jy(e){const t=Me(),n=e!==null&&Number.isFinite(e),o=yy({deviceId:e??0},{enabled:n,refetchInterval:5e3,retry:1}),s=vy({onSuccess:()=>{t.invalidateQueries({queryKey:[["ptzAutotrack"]]})}}),a=wy({onSuccess:()=>{t.invalidateQueries({queryKey:[["ptzAutotrack"]]})}}),i=U(async d=>{e!==null&&await s.mutateAsync({deviceId:e,enabled:d})},[e,s]),l=U(async d=>{e!==null&&await a.mutateAsync({deviceId:e,settings:d})},[e,a]),c=o.error?o.error.message:s.error?s.error.message:a.error?a.error.message:null;return{status:o.data??null,isLoading:o.isLoading,isPending:s.isPending||a.isPending,error:c,setEnabled:i,setSettings:l}}function e0({deviceId:e}){const{status:t,isLoading:n,isPending:o,error:s,setEnabled:a,setSettings:i}=Jy(Number.isFinite(e)?e:null),[l,c]=I({targetType:"",stopDelaySeconds:30,disappearDelaySeconds:15}),[d,p]=I(!1);return J(()=>{if(d)return;const f=t?.currentSettings;f&&c({targetType:f.targetType,stopDelaySeconds:f.stopDelaySeconds,disappearDelaySeconds:f.disappearDelaySeconds})},[t,d]),n&&!t?u("div",{className:"flex items-center gap-2 px-3 py-2 text-[10.5px] text-foreground-subtle",children:[r(yt,{className:"h-3 w-3 animate-spin"}),"Loading autotrack…"]}):u("div",{className:"border-t border-border/40 mt-2 pt-2 px-1 space-y-2",children:[u("div",{className:"flex items-center justify-between px-2",children:[u("h3",{className:"flex items-center gap-1.5 text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:[r(Fc,{className:"h-3 w-3 text-primary"}),"Autotrack"]}),u("button",{type:"button",onClick:()=>{a(!(t?.enabled??!1))},disabled:o,className:`flex items-center gap-1.5 rounded-md px-2 py-1 text-[10px] font-medium transition-colors ${t?.enabled?"bg-success/15 text-success hover:bg-success/25":"bg-surface-elevated/40 text-foreground-subtle hover:bg-surface-hover hover:text-foreground"} disabled:opacity-50`,"aria-pressed":t?.enabled??!1,children:[r("span",{className:`h-1.5 w-1.5 rounded-full ${t?.enabled?"bg-success":"bg-foreground-subtle/40"}`}),t?.enabled?"Enabled":"Disabled"]})]}),s&&u("div",{className:"flex items-start gap-1.5 rounded-md border border-danger/30 bg-danger/5 px-2 py-1.5 text-[10px] text-danger",children:[r(Kr,{className:"h-3 w-3 flex-shrink-0 mt-0.5"}),r("span",{className:"leading-snug break-words",children:s})]}),u("div",{className:"grid grid-cols-2 gap-2 px-2",children:[(t?.supportedTargetTypes?.length??0)>0&&u("label",{className:"col-span-2 flex flex-col gap-1",children:[r("span",{className:"text-[10px] font-medium text-foreground-subtle",children:"Target type"}),r("select",{value:l.targetType,onFocus:()=>p(!0),onChange:f=>c(m=>({...m,targetType:f.target.value})),onBlur:()=>{p(!1);const f=t?.currentSettings?.targetType??"";l.targetType!==f&&i({targetType:l.targetType})},disabled:o,className:"rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50",children:(t?.supportedTargetTypes??[]).map(f=>r("option",{value:f.value,children:f.label},f.value))})]}),u("label",{className:"flex flex-col gap-1",children:[r("span",{className:"text-[10px] font-medium text-foreground-subtle",children:"Stop delay (s)"}),r("input",{type:"number",min:0,max:300,value:l.stopDelaySeconds,onFocus:()=>p(!0),onChange:f=>c(m=>({...m,stopDelaySeconds:Number(f.target.value)||0})),onBlur:()=>{p(!1);const f=t?.currentSettings?.stopDelaySeconds??30;l.stopDelaySeconds!==f&&i({stopDelaySeconds:l.stopDelaySeconds})},disabled:o,className:"rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50"})]}),u("label",{className:"flex flex-col gap-1",children:[r("span",{className:"text-[10px] font-medium text-foreground-subtle",children:"Disappear delay (s)"}),r("input",{type:"number",min:0,max:300,value:l.disappearDelaySeconds,onFocus:()=>p(!0),onChange:f=>c(m=>({...m,disappearDelaySeconds:Number(f.target.value)||0})),onBlur:()=>{p(!1);const f=t?.currentSettings?.disappearDelaySeconds??15;l.disappearDelaySeconds!==f&&i({disappearDelaySeconds:l.disappearDelaySeconds})},disabled:o,className:"rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50"})]})]}),r("p",{className:"px-2 text-[9.5px] text-foreground-subtle leading-snug italic",children:"Settings save on blur. Vendor support varies — Reolink honours all three; Hikvision honours target type + stop delay only (disappear delay is accepted but ignored at firmware push)."})]})}const Od=wn("camstack:player-overlays-state",null),Bd=wn("camstack:player-overlays-actions",null);function t0({children:e}){const[t,n]=I(()=>new Map),[o,s]=I(()=>new Map),a=U(f=>{n(m=>{const h=new Map(m);return h.set(f.id,f),h})},[]),i=U(f=>{n(m=>{if(!m.has(f))return m;const h=new Map(m);return h.delete(f),h})},[]),l=U(f=>{s(m=>{const h=new Map(m);return h.set(f.id,f),h})},[]),c=U(f=>{s(m=>{if(!m.has(f))return m;const h=new Map(m);return h.delete(f),h})},[]),d=q(()=>({layers:t,buttons:o}),[t,o]),p=q(()=>({setLayer:a,removeLayer:i,setButton:l,removeButton:c}),[a,i,l,c]);return r(Od.Provider,{value:d,children:r(Bd.Provider,{value:p,children:e})})}function n0(){const e=Ne(Od);return q(()=>e?[...e.layers.values()].sort((t,n)=>t.order-n.order):[],[e])}function r0(){const e=Ne(Od);return q(()=>e?[...e.buttons.values()].sort((t,n)=>t.order-n.order):[],[e])}function zd(e){const t=Ne(Bd);J(()=>{if(!(!t||!e))return t.setLayer(e),()=>t.removeLayer(e.id)},[t,e])}function sD(e){const t=Ne(Bd);J(()=>{if(!(!t||!e))return t.setButton(e),()=>t.removeButton(e.id)},[t,e])}const o0={rect:"#ef4444",polygon:"#3b82f6",grid:"#6366f1",line:"#f59e0b"},s0="33",Fd="66",ys="#6366f1",br=3,kp=2,aD=12,Ri=16,Oi=9;function ko(e,t,n){return{x:e.x*t,y:e.y*n}}function Ul(e,t,n){return{x:e.x/t,y:e.y/n}}function a0(e,t,n){return e.flatMap(o=>[o.x*t,o.y*n])}function vr(e){return!Number.isFinite(e)||e<0?0:e>1?1:e}function iD(e){return e.color??o0[e.shape.kind]}function lD(e,t){const n=e[t],o=e[(t+1)%e.length];if(!n||!o)return[...e];const s={x:(n.x+o.x)/2,y:(n.y+o.y)/2};return[...e.slice(0,t+1),s,...e.slice(t+1)]}function cD(e,t){return e.length!==t.length?!1:e.every((n,o)=>{const s=t[o];return Math.abs(n.x-s.x)<1e-6&&Math.abs(n.y-s.y)<1e-6})}function dD(e){return e.kind==="polygon"||e.kind==="line"}function uD({items:e,selectedId:t,onSelect:n,onShapeChange:o,onDrawComplete:s,drawingKind:a,supportedShapes:i,transparent:l=!1,backdrop:c,polygonVertices:d,grid:p}){const f=ne(null),[m,h]=I({w:800,h:450}),[g,x]=I([]),[b,y]=I(null),[w,v]=I(null),[N,k]=I(null),C=a!==null&&i.includes(a);J(()=>{if(!N)return;const T=e.find(F=>F.id===N.itemId);if(!T||!dD(T.shape)){k(null);return}cD(T.shape.points,N.points)&&k(null)},[e,N]),J(()=>{const T=f.current;if(!T)return;const F=new ResizeObserver(H=>{const j=H[0];if(!j)return;const{width:Q,height:G}=j.contentRect;h(l?{w:Q,h:G}:{w:Q,h:Q*9/16})});return F.observe(T),()=>F.disconnect()},[l]),J(()=>{!C&&b!==null&&y(null)},[C,b]);const D=U(T=>{s(T),x([])},[s]),M=U(T=>{if(!C||a===null){n(null);return}const F=T.target.getStage();if(!F)return;const H=F.getPointerPosition();if(!H)return;const j=Ul(H,m.w,m.h);if(a==="rect"){const Q=vr(j.x),G=vr(j.y);D({kind:"rect",x:Q,y:G,width:Math.min(.2,1-Q),height:Math.min(.2,1-G)});return}if(a==="grid"){const Q=p?.width??Ri,G=p?.height??Oi;D({kind:"grid",gridWidth:Q,gridHeight:G,cells:Array.from({length:Q*G},()=>!1)});return}if(a==="line"){if(g.length===0){x([j]);return}D({kind:"line",points:[...g,j]});return}if(a==="polygon"){if(g.length===0){x([j]);return}if(g.length>=br){const Q=ko(g[0],m.w,m.h);if(Math.hypot(H.x-Q.x,H.y-Q.y)<aD){D({kind:"polygon",points:g});return}}x(Q=>[...Q,j])}},[C,a,g,m,p,D,n]),_=U(T=>{!C||a!=="polygon"||g.length<br||(T.cancelBubble=!0,D({kind:"polygon",points:g}))},[C,a,g,D]),$=ne(null),E=ne(null);J(()=>()=>{$.current!==null&&cancelAnimationFrame($.current)},[]);const R=U(T=>{if(!C)return;const F=T.target.getStage();F&&(E.current=F.getPointerPosition()??null,$.current===null&&($.current=requestAnimationFrame(()=>{$.current=null,y(E.current)})))},[C]),O=ne(!1),A=ne(!0),P=ne(new Set),L=U((T,F,H,j)=>{const Q=F.gridWidth*F.gridHeight;if(H<0||H>=Q||F.cells[H]===j)return;const G=[...F.cells];for(;G.length<Q;)G.push(!1);G.length=Q,G[H]=j,o(T,{...F,cells:G})},[o]),B=[];if(!l){for(let T=1;T<Ri;T++){const F=m.w/Ri*T;B.push(r(Gn,{points:[F,0,F,m.h],stroke:"#ffffff",strokeWidth:.5,opacity:.08},`gv-${T}`))}for(let T=1;T<Oi;T++){const F=m.h/Oi*T;B.push(r(Gn,{points:[0,F,m.w,F],stroke:"#ffffff",strokeWidth:.5,opacity:.08},`gh-${T}`))}}return u("div",{ref:f,className:l?"absolute inset-0":"relative w-full bg-zinc-900 rounded-lg overflow-hidden",style:{cursor:C?"crosshair":"default"},children:[c&&!l?r("div",{className:"absolute inset-0 pointer-events-none [&>*]:w-full [&>*]:h-full [&>img]:object-cover [&>video]:object-cover",style:{width:m.w,height:m.h},children:c}):null,u(l2,{width:m.w,height:m.h,onClick:M,onDblClick:_,onMouseMove:R,children:[u(Mi,{listening:!1,children:[r(Gn,{points:[0,0,m.w,0,m.w,m.h,0,m.h,0,0],stroke:"transparent",strokeWidth:0}),B]}),r(Mi,{children:e.map(T=>{const F=T.id===t,H=T.enabled===!1,j=iD(T),Q=F&&!C&&!H;if(T.shape.kind==="rect")return r(fD,{item:T,shape:T.shape,color:j,selected:F,dimmed:H,editable:Q,isDrawing:C,size:m,onSelect:n,onShapeChange:o},T.id);if(T.shape.kind==="grid")return r(mD,{item:T,shape:T.shape,color:j,dimmed:H,editable:Q,size:m,onSelect:n,paintingRef:O,paintValueRef:A,paintedRef:P,paintCell:L},T.id);const G=T.shape.kind==="line",Z=G?kp:Math.max(br,d?.min??br),V=G?kp:d?.max,K=N&&N.itemId===T.id?N.points:T.shape.points;return r(hD,{item:T,shape:T.shape,color:j,selected:F,dimmed:H,editable:Q,isLine:G,isDrawing:C,size:m,effectivePoints:K,minVertices:Z,maxVertices:V,isDragging:w===T.id,onSelect:n,onShapeChange:o,setDragOverride:k,setDraggingItemId:v},T.id)})}),r(Mi,{listening:!1,children:C&&g.length>0&&u($r,{children:[a==="polygon"&&g.length>=2&&r(Gn,{points:a0(g,m.w,m.h),stroke:ys,strokeWidth:1.5,dash:[6,3],opacity:.8}),a==="line"&&g.length===1&&b&&r(Gn,{points:[g[0].x*m.w,g[0].y*m.h,b.x,b.y],stroke:o0.line,strokeWidth:1.5,dash:[6,3],opacity:.7}),a==="polygon"&&b&&g.length>=1&&r(Gn,{points:[g[g.length-1].x*m.w,g[g.length-1].y*m.h,b.x,b.y],stroke:ys,strokeWidth:1,dash:[4,4],opacity:.5}),g.map((T,F)=>{const H=ko(T,m.w,m.h),j=F===0&&a==="polygon"&&g.length>=br;return r(sa,{x:H.x,y:H.y,radius:j?7:4,fill:j?ys:"#ffffff",stroke:ys,strokeWidth:1.5,opacity:.9},F)})]})})]}),C?r("div",{className:"px-3 py-1.5 bg-zinc-800/80 text-[11px] text-zinc-400 border-t border-zinc-700",children:a==="line"?"Click to set the start point, click again to complete the line":a==="rect"?"Click to drop a rectangle, then drag the corner to resize":a==="grid"?"Click to add the grid, then paint cells":g.length<br?"Click to add points (min 3). Double-click or click the first point to close.":"Continue adding points. Double-click or click the first point to close."}):null]})}const vs=.02;function pD(e,t){return Math.abs(e.x-t.x)<1e-6&&Math.abs(e.y-t.y)<1e-6&&Math.abs(e.width-t.width)<1e-6&&Math.abs(e.height-t.height)<1e-6}function fD({item:e,shape:t,color:n,selected:o,dimmed:s,editable:a,isDrawing:i,size:l,onSelect:c,onShapeChange:d}){const[p,f]=I(null),m={x:t.x,y:t.y,width:t.width,height:t.height};J(()=>{p&&pD(m,p)&&f(null)},[t.x,t.y,t.width,t.height,p]);const h=p??m,g=h.x*l.w,x=h.y*l.h,b=h.width*l.w,y=h.height*l.h,w=s?.35:o?1:.85,v=M=>{f(M),d(e.id,{kind:"rect",x:M.x,y:M.y,width:M.width,height:M.height})},N=M=>({x:Math.max(-g,Math.min(l.w-(g+b),M.x)),y:Math.max(-x,Math.min(l.h-(x+y),M.y))}),k=M=>{const _=M.target,$=_.x()/l.w,E=_.y()/l.h;if(_.position({x:0,y:0}),$===0&&E===0)return;const R=Math.min(Math.max(0,h.x+$),Math.max(0,1-h.width)),O=Math.min(Math.max(0,h.y+E),Math.max(0,1-h.height));v({...h,x:R,y:O})},C=M=>{const _=M.target,$=vr(_.x()/l.w-h.x),E=vr(_.y()/l.h-h.y);f({...h,width:Math.max(vs,Math.min($,1-h.x)),height:Math.max(vs,Math.min(E,1-h.y))})},D=M=>{const _=M.target,$=vr(_.x()/l.w-h.x),E=vr(_.y()/l.h-h.y);v({...h,width:Math.max(vs,Math.min($,1-h.x)),height:Math.max(vs,Math.min(E,1-h.y))})};return r($r,{onClick:M=>{M.cancelBubble=!0,i||c(e.id)},children:u($r,{draggable:a,dragBoundFunc:a?N:void 0,onDragEnd:a?k:void 0,onMouseEnter:M=>{if(!a)return;const _=M.target.getStage();_&&(_.container().style.cursor="move")},onMouseLeave:M=>{if(!a)return;const _=M.target.getStage();_&&(_.container().style.cursor=i?"crosshair":"default")},children:[r(ah,{x:g,y:x,width:b,height:y,fill:n+(o?Fd:s0),stroke:n,strokeWidth:o?2.5:1.5,opacity:w}),e.label?r(ih,{x:g,y:x-16,text:e.label,fontSize:12,fill:n,stroke:"#000000",strokeWidth:3,fillAfterStrokeEnabled:!0,fontStyle:"bold",listening:!1}):null,a?r(sa,{x:g+b,y:x+y,radius:6,fill:n,stroke:"#ffffff",strokeWidth:1.5,draggable:!0,dragBoundFunc:M=>({x:Math.min(l.w,Math.max(g,M.x)),y:Math.min(l.h,Math.max(x,M.y))}),onDragStart:M=>{M.cancelBubble=!0},onDragMove:C,onDragEnd:D,onMouseEnter:M=>{const _=M.target.getStage();_&&(_.container().style.cursor="nwse-resize")},onMouseLeave:M=>{const _=M.target.getStage();_&&(_.container().style.cursor="default")}}):null]})})}function mD({item:e,shape:t,color:n,dimmed:o,editable:s,size:a,onSelect:i,paintingRef:l,paintValueRef:c,paintedRef:d,paintCell:p}){const{gridWidth:f,gridHeight:m,cells:h}=t,g=a.w/f,x=a.h/m,b=f*m,y=o?.3:1,w=k=>{if(!s){i(e.id);return}const C=h[k]!==!0;l.current=!0,c.current=C,d.current=new Set([k]),p(e.id,t,k,C)},v=k=>{!l.current||!s||d.current.has(k)||(d.current.add(k),p(e.id,t,k,c.current))},N=()=>{l.current&&(l.current=!1,d.current=new Set)};return r($r,{opacity:y,onMouseUp:N,onMouseLeave:N,children:Array.from({length:b},(k,C)=>{const D=C%f,M=Math.floor(C/f),_=h[C]===!0;return r(ah,{x:D*g,y:M*x,width:g,height:x,fill:_?n+Fd:"#ffffff10",stroke:_?n:"#ffffff40",strokeWidth:.5,onMouseDown:$=>{$.cancelBubble=!0,w(C)},onMouseEnter:()=>v(C)},C)})})}function hD({item:e,shape:t,color:n,selected:o,dimmed:s,editable:a,isLine:i,isDrawing:l,size:c,effectivePoints:d,minVertices:p,maxVertices:f,isDragging:m,onSelect:h,onShapeChange:g,setDragOverride:x,setDraggingItemId:b}){const y=a0(d,c.w,c.h),w=s?.35:o?1:i?.8:.85,v=A=>i?{kind:"line",points:[...A]}:{kind:"polygon",points:[...A]},N=d.map(A=>A.x*c.w),k=d.map(A=>A.y*c.h),C=N.length>0?Math.min(...N):0,D=N.length>0?Math.max(...N):0,M=k.length>0?Math.min(...k):0,_=k.length>0?Math.max(...k):0,$=A=>({x:Math.max(-C,Math.min(c.w-D,A.x)),y:Math.max(-M,Math.min(c.h-_,A.y))}),E=A=>{const P=A.target,L=P.x()/c.w,B=P.y()/c.h;if(P.position({x:0,y:0}),b(null),L===0&&B===0)return;const z=t.points.map(T=>({x:T.x+L,y:T.y+B}));x({itemId:e.id,points:z}),g(e.id,v(z))},R=!i&&d.length>p,O=!i&&(f===void 0||d.length<f);return u($r,{onClick:A=>{A.cancelBubble=!0,l||h(e.id)},children:[u($r,{draggable:a,dragBoundFunc:a?$:void 0,onDragStart:a?()=>b(e.id):void 0,onDragEnd:a?E:void 0,onMouseEnter:A=>{if(!a)return;const P=A.target.getStage();P&&(P.container().style.cursor="move")},onMouseLeave:A=>{if(!a)return;const P=A.target.getStage();P&&(P.container().style.cursor=l?"crosshair":"default")},children:[i?r(c2,{points:y,stroke:n,strokeWidth:o?3:2,fill:n,pointerLength:10,pointerWidth:8,opacity:w}):r(Gn,{points:y,closed:!0,fill:n+(o?Fd:s0),stroke:n,strokeWidth:o?2.5:1.5,opacity:w}),e.label&&d.length>0?(()=>{const A=d.reduce((z,T)=>z+T.x,0)/d.length,P=d.reduce((z,T)=>z+T.y,0)/d.length,L=ko({x:A,y:P},c.w,c.h),B=Math.max(40,e.label.length*11*.62);return r(ih,{x:L.x-B/2,y:L.y-7,width:B,align:"center",text:e.label,fontSize:12,fill:n,stroke:"#000000",strokeWidth:3,fillAfterStrokeEnabled:!0,fontStyle:"bold",listening:!1})})():null]}),a&&!m&&d.map((A,P)=>{const L=ko(A,c.w,c.h);return r(sa,{x:L.x,y:L.y,radius:5,fill:n,stroke:"#ffffff",strokeWidth:1.5,draggable:!0,onDragMove:B=>{const z=Ul({x:B.target.x(),y:B.target.y()},c.w,c.h);x(T=>{const F=T&&T.itemId===e.id?T.points:t.points;return{itemId:e.id,points:F.map((H,j)=>j===P?z:H)}})},onDragEnd:B=>{const z=Ul({x:B.target.x(),y:B.target.y()},c.w,c.h),T=t.points.map((F,H)=>H===P?z:F);x({itemId:e.id,points:T}),g(e.id,v(T))},onContextMenu:B=>{B.evt.preventDefault(),B.cancelBubble=!0,R&&g(e.id,v(t.points.filter((z,T)=>T!==P)))}},`pt-${P}`)}),a&&!m&&O&&d.length>=2&&d.map((A,P)=>{const L=d[(P+1)%d.length],B=ko({x:(A.x+L.x)/2,y:(A.y+L.y)/2},c.w,c.h);return r(sa,{x:B.x,y:B.y,radius:4,fill:"#ffffff",stroke:n,strokeWidth:1.5,opacity:.6,onMouseEnter:z=>{const T=z.target;T.to({radius:6,opacity:1,duration:.1});const F=T.getStage();F&&(F.container().style.cursor="copy")},onMouseLeave:z=>{const T=z.target;T.to({radius:4,opacity:.6,duration:.1});const F=T.getStage();F&&(F.container().style.cursor=l?"crosshair":"default")},onClick:z=>{z.cancelBubble=!0,g(e.id,v(lD(t.points,P)))}},`mid-${P}`)})]})}const jd=je(uD),gD=110,bD="motion-zones",Bi=0,xD=[1,2,3],zi=1,uo="rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors",Fi="rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors";function Sp(e,t,n){const o=t*n,s=new Array(o);for(let a=0;a<o;a+=1)s[a]=e[a]===!0;return s}function yD(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function _n(e,t){return Math.ceil(e/t)}function da(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function ws(e,t,n,o){const s=_n(t,o),a=_n(n,o),i=new Array(s*a).fill(!1);for(let l=0;l<n;l+=1){const c=da(l,n,a);for(let d=0;d<t;d+=1)e[l*t+d]===!0&&(i[c*s+da(d,t,s)]=!0)}return i}function ji(e,t,n,o){const s=_n(t,o),a=_n(n,o),i=new Array(t*n).fill(!1);for(let l=0;l<n;l+=1){const c=da(l,n,a);for(let d=0;d<t;d+=1)i[l*t+d]=e[c*s+da(d,t,s)]===!0}return i}function i0({deviceId:e}){const t=De(),n=wt(t.trpcClient,e),[o,s]=I(null),[a,i]=I(!1),[l,c]=I(null),[d,p]=I(null),[f,m]=I(zi),[h,g]=I(!1),[x,b]=I(!1),y=ne(!1);J(()=>{if(!n)return;let F=!1;return y.current=!1,s(null),i(!1),c(null),p(null),m(zi),b(!1),(async()=>{try{const H=await n.motionZones?.getOptions({});if(F)return;if(!H)throw new Error("device proxy not ready");if(s(H),y.current)return;const j=await n.motionZones?.getStatus({});if(F)return;if(!j)throw new Error("device proxy not ready");y.current=!0;const Q=j.regions.find(V=>V.shape.kind==="grid"),G=Q?Q.shape.cells:[],Z=Sp(G,H.grid.width,H.grid.height);p(Z),c(ws(Z,H.grid.width,H.grid.height,zi))}catch(H){if(F)return;Do(H)?i(!0):console.error("Motion Zones load failed",H)}})(),()=>{F=!0}},[n]);const w=o?o.grid.width:0,v=o?o.grid.height:0,N=_n(w,f),k=_n(v,f),C=q(()=>l&&o?ji(l,w,v,f):null,[l,o,w,v,f]),D=q(()=>C!==null&&d!==null&&!yD(C,d),[C,d]),M=q(()=>C?C.reduce((F,H)=>H?F+1:F,0):0,[C]),_=w*v,$=N*k,E=U(F=>{$>0&&c(new Array($).fill(F))},[$]),R=U(()=>{c(F=>F&&F.map(H=>!H))},[]),O=U(()=>{d&&o&&c(ws(d,w,v,f))},[d,o,w,v,f]),A=U(F=>{F===f||!o||c(H=>{if(!H)return m(F),H;const j=ji(H,w,v,f),Q=ws(j,w,v,F);return m(F),Q})},[f,o,w,v]),P=q(()=>o&&l?[{id:Bi,shape:{kind:"grid",gridWidth:N,gridHeight:k,cells:[...l]}}]:[],[o,l,N,k]),L=U((F,H)=>{H.kind==="grid"&&c(H.cells)},[]),B=U(async()=>{if(!(!n||!l||!o)){g(!0);try{const F=ji(l,o.grid.width,o.grid.height,f),H={kind:"grid",gridWidth:o.grid.width,gridHeight:o.grid.height,cells:F};await n.motionZones?.setZone({patch:{regions:[{id:Bi,enabled:!0,shape:H}]}});const j=await n.motionZones?.getStatus({});if(j){const Q=j.regions.find(V=>V.shape.kind==="grid"),G=Q?Q.shape.cells:[],Z=Sp(G,o.grid.width,o.grid.height);p(Z),c(ws(Z,o.grid.width,o.grid.height,f))}}catch(F){console.error("Motion Zones save failed",F)}finally{g(!1)}}},[n,l,o,f]),z=q(()=>x&&!a&&o&&l?{id:bD,order:gD,node:r(jd,{transparent:!0,items:P,supportedShapes:["grid"],grid:{width:N,height:k},selectedId:Bi,onSelect:()=>{},onShapeChange:L,onDrawComplete:()=>{},drawingKind:null})}:null,[x,a,o,l,P,L,N,k]);zd(z);const T=!a&&o!==null&&l!==null;return n?u("div",{className:"flex flex-col gap-3",children:[r("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:"Motion Zones"}),a?r("p",{className:`${Qt} leading-relaxed`,children:"This camera doesn't expose an on-board motion zones grid."}):T?u(me,{children:[u("p",{className:`${Qt} leading-relaxed`,children:["Toggle ",r("strong",{className:"text-foreground",children:"Edit grid"})," to paint the region directly on the live frame, then ",r("strong",{className:"text-foreground",children:"Save"})," to push the mask to the camera. Pick a bigger ",r("strong",{className:"text-foreground",children:"Cell size"})," ","for quicker, broad-stroke painting — it's resampled to the camera's native"," ",o.grid.width,"×",o.grid.height," grid on save (×1 is the finest)."]}),u("div",{className:"flex items-center gap-2 flex-wrap",children:[r("button",{type:"button",onClick:()=>b(F=>!F),disabled:h,"aria-pressed":x,className:x?Fi:uo,children:x?"Done editing":"Edit grid"}),r("button",{type:"button",onClick:()=>E(!0),disabled:h,className:uo,children:"All on"}),r("button",{type:"button",onClick:()=>E(!1),disabled:h,className:uo,children:"All off"}),r("button",{type:"button",onClick:R,disabled:h,className:uo,children:"Invert"}),u("div",{className:"flex items-center gap-1 ml-1",role:"group","aria-label":"Cell size",children:[r("span",{className:`${Qt} mr-0.5`,children:"Cell size"}),xD.map(F=>u("button",{type:"button",onClick:()=>A(F),disabled:h,"aria-pressed":f===F,title:F===1?`Camera grid ${w}×${v} (finest)`:`${_n(w,F)}×${_n(v,F)} painting grid · cells ×${F} bigger`,className:f===F?Fi:uo,children:["×",F]},F))]}),u("span",{className:`${Qt} ml-1 tabular-nums`,children:[M," / ",_," cells · ",o.grid.width,"×",o.grid.height,f!==1?` · paint ${N}×${k}`:""]}),r("span",{className:"flex-1"}),r("button",{type:"button",onClick:O,disabled:h||!D,className:"rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors",children:"Revert"}),r("button",{type:"button",onClick:()=>void B(),disabled:h||!D,className:Fi,children:h?"Saving…":"Save"})]})]}):r("p",{className:`${Qt} leading-relaxed`,children:"Loading the camera's grid…"})]}):null}const vD=120,wD="privacy-mask",Ns="rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors",po="rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors";function Cp(e){return e.kind==="rect"||e.kind==="polygon"?e:null}function ND(e){const t=new Set(e.map(o=>o.id));let n=0;for(;t.has(n);)n+=1;return n}function kD(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(JSON.stringify(e[n])!==JSON.stringify(t[n]))return!1;return!0}function SD({deviceId:e}){const t=De(),n=wt(t.trpcClient,e),[o,s]=I(null),[a,i]=I(!1),[l,c]=I(null),[d,p]=I(null),[f,m]=I(!1),[h,g]=I(!1),[x,b]=I(null),[y,w]=I(null),v=ne(!1);J(()=>{if(!n)return;let V=!1;return v.current=!1,s(null),i(!1),c(null),p(null),g(!1),b(null),w(null),(async()=>{try{const K=await n.privacyMask?.getOptions({});if(V)return;if(!K)throw new Error("device proxy not ready");if(s(K),v.current)return;const X=await n.privacyMask?.getStatus({});if(V)return;if(!X)throw new Error("device proxy not ready");v.current=!0;const te={enabled:X.enabled,regions:X.regions};p(te),c(te)}catch(K){if(V)return;Do(K)?i(!0):console.error("Privacy Mask load failed",K)}})(),()=>{V=!0}},[n]);const N=q(()=>l!==null&&d!==null&&(l.enabled!==d.enabled||!kD(l.regions,d.regions)),[l,d]),k=l?l.regions.length:0,C=o?o.maxRegions:0,D=ne(0);J(()=>{D.current=C},[C]);const M=C>0&&k>=C,_=U(()=>{c(V=>V&&{...V,enabled:!V.enabled})},[]),$=U(V=>{b(typeof V=="number"?V:null)},[]),E=q(()=>l?l.regions.map(V=>({id:V.id,shape:V.shape,enabled:V.enabled,label:`Zone ${String(V.id)}`})):[],[l]),R=U((V,K)=>{const X=Cp(K);X&&c(te=>te&&{...te,regions:te.regions.map(he=>he.id===V?{...he,shape:X}:he)})},[]),O=U(V=>{const K=Cp(V);K&&(w(null),c(X=>{if(!X)return X;const te=D.current;if(te>0&&X.regions.length>=te)return X;const he=ND(X.regions),xe={id:he,enabled:!0,shape:K};return b(he),{...X,regions:[...X.regions,xe]}}))},[]),A=U(V=>{g(!0),b(null),w(V)},[]),P=U(V=>{g(!0),w(null),b(V)},[]),L=U(V=>{b(K=>K===V?null:K),c(K=>K&&{...K,regions:K.regions.filter(X=>X.id!==V)})},[]),B=U(()=>{w(null),b(null),d&&c({enabled:d.enabled,regions:d.regions})},[d]),z=U(async()=>{if(!(!n||!l)){m(!0);try{await n.privacyMask?.setMask({patch:{enabled:l.enabled,regions:[...l.regions]}});const V=await n.privacyMask?.getStatus({});if(V){const K={enabled:V.enabled,regions:V.regions};p(K),c(K)}}catch(V){console.error("Privacy Mask save failed",V)}finally{m(!1)}}},[n,l]),T=U(()=>{g(V=>(V&&(w(null),b(null)),!V))},[]),F=o?.supportedShapes??[],H=q(()=>h&&!a&&o&&l?{id:wD,order:vD,node:r(jd,{transparent:!0,items:E,supportedShapes:F,polygonVertices:o.polygonVertices,selectedId:x,onSelect:$,onShapeChange:R,onDrawComplete:O,drawingKind:y})}:null,[h,a,o,l,E,F,x,$,R,O,y]);zd(H);const j=o?.supportedShapes.includes("rect")??!1,Q=o?.supportedShapes.includes("polygon")??!1,G=o!==null&&(o.maxRegions<=0||o.supportedShapes.length===0),Z=!a&&!G&&o!==null&&l!==null;return n?u("div",{className:"flex flex-col gap-3",children:[r("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:"Privacy Mask"}),a||G?r("p",{className:`${Qt} leading-relaxed`,children:"This camera doesn't support an on-board privacy mask."}):Z?u(me,{children:[u("p",{className:`${Qt} leading-relaxed`,children:["Toggle ",r("strong",{className:"text-foreground",children:"Edit mask"})," to draw blanked-out zones on the live frame, then ",r("strong",{className:"text-foreground",children:"Save"})," to push them to the camera. Drag a rectangle to move, its corner to resize; drag polygon vertices, click an edge midpoint to add one, or right-click a vertex to remove it."]}),u("div",{className:"flex items-center gap-2 flex-wrap",children:[r("button",{type:"button",onClick:T,disabled:f,"aria-pressed":h,className:h?po:Ns,children:h?"Done editing":"Edit mask"}),r("button",{type:"button",onClick:_,disabled:f,"aria-pressed":l.enabled,className:l.enabled?po:Ns,children:l.enabled?"Mask on":"Mask off"}),j&&r("button",{type:"button",onClick:()=>A("rect"),disabled:f||M,"aria-pressed":y==="rect",className:y==="rect"?po:Ns,title:M?"Maximum zones reached":"Add a rectangle zone",children:"+ Rect"}),Q&&r("button",{type:"button",onClick:()=>A("polygon"),disabled:f||M,"aria-pressed":y==="polygon",className:y==="polygon"?po:Ns,title:M?"Maximum zones reached":"Add a polygon zone",children:"+ Polygon"}),u("span",{className:`${Qt} ml-1 tabular-nums`,children:[k," / ",C," zones"]}),r("span",{className:"flex-1"}),r("button",{type:"button",onClick:B,disabled:f||!N,className:"rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors",children:"Revert"}),r("button",{type:"button",onClick:()=>void z(),disabled:f||!N,className:po,children:f?"Saving…":"Save"})]}),k>0?r("div",{className:"flex flex-col gap-1",children:l.regions.map(V=>{const K=x===V.id,X=V.shape.kind==="polygon"?mS:Rl;return u("div",{className:`flex items-center gap-2 rounded-md border px-2 py-1 transition-colors ${K?"border-primary/50 bg-primary/10":"border-border bg-surface"}`,children:[u("button",{type:"button",onClick:()=>P(V.id),disabled:f,className:"flex flex-1 items-center gap-2 text-left text-[11px] font-medium text-foreground-subtle hover:text-foreground disabled:opacity-40 transition-colors",children:[r(X,{className:"h-3.5 w-3.5 shrink-0"}),u("span",{children:["Zone ",V.id]}),r("span",{className:"text-foreground-faint capitalize",children:V.shape.kind})]}),r("button",{type:"button",onClick:()=>L(V.id),disabled:f,"aria-label":`Delete zone ${String(V.id)}`,title:"Delete zone",className:"inline-flex h-6 w-6 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:border-red-400/40 hover:bg-red-500/10 hover:text-red-400 disabled:opacity-40 transition-colors",children:r(Jt,{className:"h-3.5 w-3.5"})})]},V.id)})}):null]}):r("p",{className:`${Qt} leading-relaxed`,children:"Loading the camera's privacy mask…"})]}):null}const l0={"host/motion-zones-grid":i0,"host/privacy-mask-grid":SD,"host/ptz-panel":Xy,"host/ptz-autotrack":e0};function Tr(e){const{widgetId:t,deviceId:n}=e,o=l0[t];return o!==void 0?n===void 0?r(So,{widgetId:t,reason:"missing-device-context"}):r(o,{deviceId:n}):r(CD,{...e})}function CD(e){const{widgetId:t}=e,n=Ky(t);return n===void 0?r(So,{widgetId:t,reason:"unknown"}):r(MD,{...e,metadata:n})}function MD(e){const{widgetId:t,host:n="device-tab",config:o,deviceId:s,integrationId:a,instanceId:i,size:l,columns:c,rows:d,metadata:p}=e,f=Zy(p.remote,p.bundleUrl),m=q(()=>i??t,[i,t]);return f===null?r(AD,{}):f===void 0?r(So,{widgetId:t,reason:"missing-export"}):p.requires.deviceContext&&s===void 0?r(So,{widgetId:t,reason:"missing-device-context"}):p.requires.integrationContext&&a===void 0?r(So,{widgetId:t,reason:"missing-integration-context"}):r(f,{instanceId:m,host:n,config:o,deviceId:s,integrationId:a,size:l,columns:c,rows:d})}function AD(){return u("div",{className:"rounded-lg border border-border bg-surface/40 p-4 animate-pulse",children:[r("div",{className:"h-3 w-24 bg-foreground-subtle/20 rounded mb-2"}),r("div",{className:"h-2 w-full bg-foreground-subtle/10 rounded mb-1"}),r("div",{className:"h-2 w-3/4 bg-foreground-subtle/10 rounded"})]})}function So({widgetId:e,reason:t}){const n=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`;return r("div",{className:"rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning",children:n})}const fr="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",Wa="block text-[11px] font-medium text-foreground mb-1 break-words",ED="text-[10px] text-foreground-subtle mt-0.5 break-words";function Je({label:e,description:t,required:n,span:o,children:s,translationFn:a}){const i=o===2?"col-span-1 @[480px]:col-span-2":o===3?"col-span-1 @[480px]:col-span-2 @[880px]:col-span-3":o===4?"col-span-1 @[480px]:col-span-2 @[1140px]:col-span-4":"col-span-1",l=Ft(e,a),c=Ft(t,a),d=l!==void 0&&l!=="";return u("div",{className:`${i} min-w-0`,children:[d&&u("label",{className:Wa,children:[l,n&&r("span",{className:"text-danger ml-0.5",children:"*"})]}),s,c&&r("p",{className:ED,children:c})]})}function ID({field:e,value:t,onChange:n,disabled:o,translationFn:s}){return r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("input",{type:e.inputType??"text",className:fr,value:t==null?"":String(t),placeholder:e.placeholder,maxLength:e.maxLength,pattern:e.pattern,disabled:o||e.disabled,onChange:a=>n(a.target.value)})})}function PD({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const[a,i]=I(t==null?"":String(t)),l=ne(!1);J(()=>{if(l.current)return;const d=t==null?"":String(t);i(d)},[t]);const c=d=>{if(i(d),d===""||d==="-"){n(void 0);return}const p=Number(d);Number.isNaN(p)||n(p)};return r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"flex items-center gap-1",children:[r("input",{type:"number",className:fr,value:a,placeholder:e.placeholder,min:e.min,max:e.max,step:e.step,disabled:o||e.disabled,onFocus:()=>{l.current=!0},onBlur:()=>{l.current=!1},onChange:d=>c(d.target.value)}),e.unit&&r("span",{className:"text-xs text-foreground-subtle whitespace-nowrap",children:e.unit})]})})}function _D({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=!!t,i=o||e.disabled;return e.style==="checkbox"?r(Je,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[r("input",{type:"checkbox",className:"h-3.5 w-3.5 rounded border-border accent-primary",checked:a,disabled:i,onChange:l=>n(l.target.checked)}),r("span",{className:"text-xs font-medium text-foreground",children:Ft(e.label,s)}),e.required&&r("span",{className:"text-danger",children:"*"})]})}):r(Je,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"flex items-center justify-between",children:[u("span",{className:Wa+" mb-0",children:[Ft(e.label,s),e.required&&r("span",{className:"text-danger ml-0.5",children:"*"})]}),r("button",{type:"button",role:"switch","aria-checked":a,disabled:i,onClick:()=>!i&&n(!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:r("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 $D({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=e.options.some(i=>i.value==="");return r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("select",{className:fr,value:t==null?"":String(t),disabled:o||e.disabled,onChange:i=>n(i.target.value),children:[!e.required&&!a&&r("option",{value:"",children:"— Select —"}),e.options.map(i=>r("option",{value:i.value,children:i.label},i.value))]})})}function DD({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=Array.isArray(t)?t:[],i=l=>{if(a.includes(l))n(a.filter(c=>c!==l));else{if(e.maxItems!==void 0&&a.length>=e.maxItems)return;n([...a,l])}};return r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("div",{className:"flex flex-wrap gap-2",children:e.options.map(l=>{const c=a.includes(l.value);return u("label",{className:["flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs cursor-pointer select-none transition-colors",c?"border-primary bg-primary/10 text-primary":"border-border bg-background text-foreground hover:bg-surface",o||e.disabled?"opacity-50 cursor-not-allowed":""].join(" "),children:[r("input",{type:"checkbox",className:"sr-only",checked:c,disabled:o||e.disabled,onChange:()=>i(l.value)}),l.label]},l.value)})})})}function LD({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const[a,i]=I(!1),l=e.showToggle!==!1;return r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"relative",children:[r("input",{type:a?"text":"password",className:fr+(l?" pr-9":""),value:t==null?"":String(t),placeholder:e.placeholder,disabled:o||e.disabled,onChange:c=>n(c.target.value)}),l&&r("button",{type:"button",className:"absolute right-2 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",tabIndex:-1,onClick:()=>i(c=>!c),children:a?r(jc,{className:"h-3.5 w-3.5"}):r(Yr,{className:"h-3.5 w-3.5"})})]})})}function TD({field:e,value:t,onChange:n,disabled:o,translationFn:s}){return r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("textarea",{className:fr+" resize-y min-h-[60px]",value:t==null?"":String(t),placeholder:e.placeholder,rows:e.rows??3,maxLength:e.maxLength,disabled:o||e.disabled,onChange:a=>n(a.target.value)})})}function RD({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=t==null,i=e.nullable===!0,l=a?e.default??e.min:Number(t),c=e.showValue!==!1,d=e.nullLabel??"Auto",p=o||e.disabled,f=e.displayScale??1,m=e.min/f,h=e.max/f,g=l/f,x=(e.step??1)/f;if(i&&a)return r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("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:p,onClick:()=>n(e.default??e.min),children:[d," — click to set manually"]})});const b=e.showStepper===!0&&c,y=v=>{const N=l+v*(e.step??1),k=Math.min(e.max,Math.max(e.min,N));k!==l&&n(k)},w="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 r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[u("div",{className:"flex min-w-0 flex-1 basis-[160px] items-center gap-2",children:[r("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:m}),r("input",{type:"range",className:"min-w-0 flex-1 h-1 accent-primary cursor-pointer disabled:opacity-50",min:m,max:h,step:x,value:g,disabled:p,onChange:v=>n(Number(v.target.value)*f)}),r("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:h})]}),(c||i||e.unit)&&u("div",{className:"flex shrink-0 items-center gap-2",children:[b&&r("button",{type:"button",className:w,disabled:p||l<=e.min,onClick:()=>y(-1),title:`Decrease by ${e.step??1}`,"aria-label":"Decrement",children:r(Kh,{className:"h-3 w-3"})}),c&&r("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:m,max:h,step:x,value:g,disabled:p,onChange:v=>{if(v.target.value===""){n(i?null:e.min);return}const N=Number(v.target.value)*f,k=e.step??1,C=N-e.min,D=e.min+Math.round(C/k)*k;n(Math.min(e.max,Math.max(e.min,D)))}}),b&&r("button",{type:"button",className:w,disabled:p||l>=e.max,onClick:()=>y(1),title:`Increase by ${e.step??1}`,"aria-label":"Increment",children:r(Zr,{className:"h-3 w-3"})}),e.unit&&r("span",{className:"text-[10px] text-foreground-subtle",children:e.unit}),i&&r("button",{className:"text-[10px] text-foreground-subtle hover:text-primary transition-colors",title:`Reset to ${d}`,disabled:p,onClick:()=>n(null),children:d})]})]})})}function OD({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=Array.isArray(t)?t:[],[i,l]=I(""),c=ne(null),d=U(h=>{const g=h.trim();!g||a.includes(g)||e.maxTags!==void 0&&a.length>=e.maxTags||(n([...a,g]),l(""))},[a,e.maxTags,n]),p=h=>n(a.filter(g=>g!==h)),f=h=>{h.key==="Enter"||h.key===","?(h.preventDefault(),d(i)):h.key==="Backspace"&&i===""&&a.length>0&&p(a[a.length-1])},m=o||e.disabled;return r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("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",m?"opacity-50 cursor-not-allowed":""].join(" "),onClick:()=>!m&&c.current?.focus(),children:[a.map(h=>u("span",{className:"inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[h,!m&&r("button",{type:"button",onClick:()=>p(h),className:"hover:text-danger",children:r(rt,{className:"h-2.5 w-2.5"})})]},h)),r("input",{ref:c,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:m,list:`tags-suggestions-${e.key}`,onChange:h=>l(h.target.value),onKeyDown:f,onBlur:()=>{i.trim()&&d(i)}}),e.suggestions&&r("datalist",{id:`tags-suggestions-${e.key}`,children:e.suggestions.map(h=>r("option",{value:h},h))})]})})}function c0({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const{nodes:a}=eo(),i=typeof t=="string"?t:"",l=e.showOffline?a:a.filter(c=>c.isOnline);return r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("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:c=>n(c.target.value),disabled:o,children:[r("option",{value:"",children:"Select node…"}),l.map(c=>u("option",{value:c.id,disabled:!c.isOnline,children:[c.shortName,c.isOnline?"":" (offline)"]},c.id))]})})}function d0({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const{nodes:a}=eo(),i=new Set(Array.isArray(t)?t.map(String):[]),l=e.showOffline?a:a.filter(d=>d.isOnline),c=d=>{const p=new Set(i);p.has(d)?p.delete(d):p.add(d),n([...p])};return r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("div",{className:"flex flex-wrap gap-1.5",children:l.map(d=>{const p=i.has(d.id);return r("button",{type:"button",onClick:()=>c(d.id),disabled:o||!d.isOnline,className:`px-2.5 py-1 text-xs font-medium rounded-md border transition-colors ${p?"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 BD({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=t==null?"#000000":String(t);return u(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:[u("div",{className:"flex items-center gap-2",children:[r("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:o||e.disabled,onChange:i=>n(i.target.value)}),r("input",{type:"text",className:fr+" flex-1 font-mono",value:a,placeholder:"#000000",disabled:o||e.disabled,onChange:i=>n(i.target.value)})]}),e.presets&&e.presets.length>0&&r("div",{className:"flex gap-1.5 mt-1.5",children:e.presets.map(i=>r("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:o||e.disabled,title:i,onClick:()=>n(i)},i))})]})}function zD({field:e,value:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i,externalProbe:l}){const[c,d]=I("idle"),[p,f]=I(null),m=l?.status??c,h=l?.result??p,g=!!a||!!i,x=U(async()=>{if(g){d("probing"),f(null);try{const w=a?await a(e.key,t):await i("test-probe",e.key,t),v=w&&typeof w=="object"?w:{status:"error",error:"Probe handler returned no result"};f(v),d(v.status==="ok"?"ok":"error")}catch(w){f({status:"error",error:w instanceof Error?w.message:String(w)}),d("error")}}},[a,i,e.key,t,g]),b=m==="probing"?"border-primary/40 bg-primary/10 text-primary":m==="ok"?"border-success/40 bg-success/10 text-success hover:bg-success/15":m==="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=m==="probing"?r(yt,{className:"h-3 w-3 animate-spin"}):m==="ok"?r(R5,{className:"h-3 w-3"}):m==="error"?r(Kr,{className:"h-3 w-3"}):r(tg,{className:"h-3 w-3"});return u(Je,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:[u("div",{className:"@container flex items-center gap-2",style:{containerType:"inline-size"},children:[u("button",{type:"button",onClick:x,title:"Test",disabled:e.disabled||m==="probing"||!g||!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 ${b}`,children:[y,r("span",{className:"hidden @[280px]:inline",children:"Test"})]}),r("input",{type:e.inputType??"url",className:fr+" flex-1 min-w-0",value:t==null?"":String(t),placeholder:e.placeholder,disabled:o||e.disabled,onChange:w=>{n(w.target.value),c!=="idle"&&(d("idle"),f(null))}})]}),m==="ok"&&h?.labels&&h.labels.length>0&&r("div",{className:"flex flex-wrap gap-1 mt-1.5",children:h.labels.map((w,v)=>r("span",{className:"text-xs bg-success/10 text-success rounded px-2 py-0.5 font-mono",children:w},v))}),m==="error"&&h?.error&&r("p",{className:"text-xs text-danger mt-1 truncate",title:h.error,children:h.error})]})}function FD({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a}){const[i,l]=I(e.defaultCollapsed??!1),c=e.style==="accordion",d=e.span===2?"col-span-2":e.span===3?"col-span-3":e.span===4?"col-span-4":"col-span-1";return r("div",{className:`${d} min-w-0`,children:u("div",{className:"@container rounded-lg border border-border bg-surface/50 overflow-hidden",style:{containerType:"inline-size"},children:[u("div",{className:["px-3 py-2 flex items-center justify-between min-w-0",c?"cursor-pointer hover:bg-surface":""].join(" "),onClick:c?()=>l(p=>!p):void 0,children:[r("span",{className:"text-xs font-semibold text-foreground min-w-0 break-words",children:Ft(e.label,s)}),c&&r("span",{className:"text-foreground-subtle text-xs shrink-0 ml-2",children:i?"▸":"▾"})]}),!i&&r("div",{className:"px-3 pb-3 grid grid-cols-1 @[480px]:grid-cols-2 gap-x-4 gap-y-3",children:e.fields.map(p=>r(mr,{field:p,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a},p.key))})]})})}function jD({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i}){const l=e.tabs[0]?.id??"",[c,d]=I(l),p=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:u("div",{className:`${p} min-w-0`,children:[e.label&&r("div",{className:Wa,children:Ft(e.label,s)}),u("div",{className:"@container rounded-lg border border-border-subtle bg-surface-hover/40 overflow-hidden",style:{containerType:"inline-size"},children:[r("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 m=f.id===c;return u("button",{type:"button",role:"tab","aria-selected":m,onClick:()=>d(f.id),className:`inline-flex items-center gap-1.5 whitespace-nowrap rounded-md px-2.5 py-1 text-[11px] transition-colors ${m?"bg-primary text-primary-foreground font-medium shadow-sm":"bg-transparent text-foreground-subtle hover:bg-surface hover:text-foreground"}`,children:[r("span",{children:Ft(f.label,s)}),f.badge&&r("span",{className:`text-[9px] px-1 py-0.5 rounded-full font-medium ${m?"bg-primary-foreground/20 text-primary-foreground":"bg-primary/10 text-primary"}`,children:f.badge})]},f.id)})}),e.tabs.map(f=>f.id!==c?null:r("div",{role:"tabpanel",className:"px-3 pb-3 pt-2 grid grid-cols-1 @[480px]:grid-cols-2 gap-x-4 gap-y-3",children:f.fields.map((m,h)=>{const g="key"in m&&typeof m.key=="string"?m.key:`__${f.id}__${h}`;return r(mr,{field:m,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i},g)})},f.id))]})]})}function HD({span:e}){return r("div",{className:e===2?"col-span-2":e===3?"col-span-3":e===4?"col-span-4":"col-span-full",children:r("hr",{className:"border-border"})})}const Mp={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 VD(e){if(typeof window>"u"||typeof DOMParser>"u")return"";const t=new Set(["A","UL","OL","LI","STRONG","EM","CODE","BR","P","SPAN"]),n=new DOMParser().parseFromString(`<div>${e}</div>`,"text/html"),o=n.body.firstElementChild;if(!o)return"";const s=a=>{const i=Array.from(a.children);for(const l of i){if(!t.has(l.tagName)){const d=n.createTextNode(l.textContent??"");l.replaceWith(d);continue}const c=l.tagName==="A"?new Set(["href"]):new Set;for(const d of Array.from(l.attributes))c.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"))}s(l)}};return s(o),o.innerHTML}function UD({field:e}){const t=e.variant??"info",n=Mp[t]??Mp.info,o=e.format==="html";return r("div",{className:"col-span-full",children:u("div",{className:`rounded-md border-l-4 px-3 py-2.5 ${n.border} ${n.bg}`,children:[e.label&&r("p",{className:`text-xs font-semibold mb-0.5 ${n.text}`,children:e.label}),o?r("div",{className:"text-xs text-foreground-subtle leading-relaxed info-html-content",dangerouslySetInnerHTML:{__html:VD(e.content)}}):r("p",{className:"text-xs text-foreground-subtle leading-relaxed whitespace-pre-line",children:e.content})]})})}const Ap={ok:"bg-success",warn:"bg-amber-500",danger:"bg-danger",idle:"bg-foreground-subtle/40",unknown:"bg-foreground-subtle/40"};function qD(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 n=Math.floor(t/60),o=t%60;return o===0?`${n}m`:`${n}m ${o}s`}function QD(e){return!Number.isFinite(e)||e<=0?"—":new Date(e).toLocaleTimeString()}function GD({kind:e,value:t}){if(t==null||t==="")return r("span",{className:"text-foreground-subtle/60",children:"—"});if(e==="monospace")return r("span",{className:"font-mono text-[11px]",children:String(t)});if(e==="status"){const n=String(t).toLowerCase(),o=Ap[n]??Ap.unknown;return u("span",{className:"inline-flex items-center gap-1.5",children:[r("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${o}`}),r("span",{children:String(t)})]})}return e==="duration"&&typeof t=="number"?r("span",{className:"font-mono text-[11px]",children:qD(t)}):e==="timestamp"&&typeof t=="number"?r("span",{className:"font-mono text-[11px]",children:QD(t)}):r("span",{children:String(t)})}function WD({field:e}){const t=e.value??[],n=e.description;return u("div",{className:"col-span-full",children:[e.label&&r("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1",children:e.label}),n&&r("p",{className:"text-xs text-foreground-subtle mb-2",children:n}),t.length===0?r("div",{className:"rounded-md border border-border bg-surface-subtle px-3 py-2 text-xs text-foreground-subtle",children:e.emptyMessage??"No entries"}):r("div",{className:"rounded-md border border-border overflow-hidden",children:u("table",{className:"w-full text-xs",children:[r("thead",{className:"bg-surface-subtle border-b border-border",children:r("tr",{children:e.columns.map(o=>r("th",{className:"px-3 py-1.5 text-left font-medium text-foreground-subtle",style:o.width?{width:o.width}:void 0,children:o.label},o.key))})}),r("tbody",{className:"divide-y divide-border",children:t.map((o,s)=>r("tr",{className:"hover:bg-surface-hover/40",children:e.columns.map(a=>r("td",{className:"px-3 py-1.5 align-top text-foreground",children:r(GD,{kind:a.kind,value:o[a.key]})},a.key))},s))})]})})]})}function KD({field:e,value:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i}){const l=Array.isArray(t)?t:[],c=e.minRows??0,d=e.maxRows??Number.POSITIVE_INFINITY,p=(b,y,w)=>{const v=l.slice(),N=v[b]??{};v[b]={...N,[y]:w},n(v)},f=b=>{l.length<=c||n(l.filter((y,w)=>w!==b))},m=()=>{if(l.length>=d)return;const b=e.defaultItem??{};n([...l,{...b}])},h=(b,y)=>e.rowTitleTemplate?e.rowTitleTemplate.replace(/\{(\w+)\}/g,(w,v)=>{const N=b[v];return N==null||N===""?"—":String(N)}):`Row ${y+1}`,g=l.length>c,x=l.length<d;return u("div",{className:"col-span-full space-y-2",children:[u("div",{className:"space-y-0.5",children:[e.label&&r("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle",children:Ft(e.label,s)}),e.description&&r("p",{className:"text-[11px] text-foreground-subtle",children:Ft(e.description,s)})]}),l.length===0?r("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"}):r("div",{className:"space-y-2",children:l.map((b,y)=>u("div",{className:"rounded-md border border-border bg-background",children:[u("div",{className:"flex items-center justify-between border-b border-border px-3 py-1.5",children:[r("span",{className:"text-xs font-medium text-foreground",children:h(b,y)}),u("button",{type:"button",onClick:()=>f(y),disabled:o||!g,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:g?"Remove this row":`At least ${c} row(s) required`,children:[r(Kh,{className:"h-3 w-3"}),"Remove"]})]}),r("div",{className:"grid grid-cols-1 @[480px]:grid-cols-2 gap-x-3 gap-y-2 p-3",children:e.itemFields.map(w=>r(mr,{field:w,values:b,onChange:(v,N)=>p(y,v,N),disabled:o,translationFn:s,onTestField:a,allFields:e.itemFields,onAction:i},w.key))})]},y))}),u("div",{children:[u("button",{type:"button",onClick:m,disabled:o||!x,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:[r(Zr,{className:"h-3 w-3"}),e.addLabel??"Add"]}),!x&&Number.isFinite(d)&&u("span",{className:"ml-2 text-[10px] text-foreground-subtle",children:["(limit: ",d,")"]})]})]})}function YD({field:e,disabled:t,onAction:n}){const[o,s]=I(!1),a=st(),i=async()=>{if(!(e.confirmMessage&&!await a({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant==="danger"?"danger":"default"}))&&n){s(!0);try{await n(e.action,e.key)}finally{s(!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 r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,children:r("button",{onClick:i,disabled:t||o,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:o?"Processing...":e.buttonLabel})})}function u0(e,t){const n={...e.paramsStatic??{}};if(e.paramsFromForm)for(const[o,s]of Object.entries(e.paramsFromForm)){const a=t[s];a!=null&&a!==""&&(n[o]=a)}return n}function ZD({field:e,value:t,values:n,onChange:o,disabled:s,onAction:a}){const[i,l]=I(!1),[c,d]=I(null),[p,f]=I(null),m=u0(e,n),h=Object.keys(e.paramsFromForm??{}).some(w=>m[w]===void 0),g=(e.refreshOn??Object.values(e.paramsFromForm??{})).map(w=>`${w}=${JSON.stringify(n[w])}`).join("|");J(()=>{if(!a||h){f(null),d(null);return}let w=!1;return l(!0),d(null),a(e.action,e.key,m).then(v=>{if(w)return;const N=v;let k=[];if(Array.isArray(N))k=N;else if(N&&typeof N=="object")for(const C of Object.keys(N)){const D=N[C];if(Array.isArray(D)){k=D;break}}f(k)}).catch(v=>{w||(d(v instanceof Error?v.message:String(v)),f([]))}).finally(()=>{w||l(!1)}),()=>{w=!0}},[g,a,e.action,e.key]);const x=e.mapOption.value,b=e.mapOption.label,y=e.mapOption.description;return r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,children:h?r("div",{className:"text-[11px] text-foreground-subtle italic",children:e.emptyParamsMessage??"Fill the prerequisite fields above first."}):i?u("div",{className:"flex items-center gap-2 text-[11px] text-foreground-subtle",children:[r(yt,{className:"h-3 w-3 animate-spin"})," Loading options…"]}):c?r("div",{className:"text-[11px] text-danger",children:c}):p&&p.length===0?r("div",{className:"text-[11px] text-foreground-subtle italic",children:e.emptyResultsMessage??"No options returned."}):(()=>{const w=(p??[]).some(v=>{const N=v[x];return N===""||N===void 0});return u("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:s,onChange:v=>o(v.target.value),children:[!w&&r("option",{value:"",children:"— Select —"}),(p??[]).map((v,N)=>{const k=v[x],C=v[b],D=y?v[y]:void 0,M=typeof k=="string"&&k!==""?k:`row-${N}`;return u("option",{value:typeof k=="string"?k:String(k??""),children:[typeof C=="string"?C:String(C??M),D!==void 0?` (${String(D)})`:""]},M)})]})})()})}function XD({field:e,values:t,disabled:n,onAction:o}){const[s,a]=I(!1),[i,l]=I(null),c=st(),d=async()=>{if(e.confirmMessage&&!await c({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant==="danger"?"danger":"default"})||!o)return;const f=u0(e,t);a(!0),l(null);try{const m=await o(e.action,e.key,f),h=typeof m=="object"&&m!==null?m:null,g=e.successMessage?e.successMessage.replace(/\{(\w+)\}/g,(x,b)=>{const y=h?.[b];return y===void 0?"":String(y)}):"Done.";l({kind:"ok",text:g})}catch(m){l({kind:"error",text:m instanceof Error?m.message:String(m)})}finally{a(!1)}},p={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 r(Je,{label:e.label,description:e.description,required:e.required,span:e.span,children:u("div",{className:"flex flex-col gap-1.5",children:[r("button",{onClick:d,disabled:n||s,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 ${p[e.variant??"default"]??p.default}`,children:s?"Working…":e.buttonLabel}),i&&r("div",{className:`text-[11px] ${i.kind==="ok"?"text-emerald-700 dark:text-emerald-300":"text-danger"}`,children:i.text})]})})}function JD({field:e}){const t=fd();return r(Tr,{widgetId:e.widgetId,host:"device-tab",config:e.widgetConfig,deviceId:t??void 0,instanceId:e.key})}function eL(e,t){if(e==null)return"—";if(typeof e=="boolean")return e?"yes":"no";if(typeof e=="number"){const n=Number.isInteger(e)?String(e):e.toFixed(2);return t?`${n} ${t}`:n}return typeof e=="string"?e:JSON.stringify(e)}function tL({field:e,values:t,onAction:n,translationFn:o}){const s="key"in e?e.key:void 0;if(!s)return null;const a=t[s],i=a!==void 0?a:"default"in e?e.default:void 0,l="unit"in e?e.unit:void 0,c=eL(i,l),d="label"in e?e.label:void 0,p="description"in e?e.description:void 0,f="span"in e?e.span:void 0,m="actions"in e?e.actions??[]:[];return r(Je,{label:d,description:p,span:f,translationFn:o,children:u("div",{className:"flex items-stretch gap-1",children:[r("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:c}),m.length>0&&r("div",{className:"flex items-center gap-1",children:m.map(h=>r(rL,{action:h,fieldKey:s,value:i,onAction:n},h.action))})]})})}function nL({name:e}){const t="h-3.5 w-3.5";switch(e){case"copy":return r(jn,{className:t});case"refresh-cw":return r(za,{className:t});case"external-link":return r(Uh,{className:t});case"trash-2":return r(Jt,{className:t});case"download":return r($l,{className:t});case"upload":return r(eg,{className:t});default:return r(Vc,{className:t})}}function rL({action:e,fieldKey:t,value:n,onAction:o}){const s=st(),[a,i]=I(!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";return r("button",{type:"button",onClick:async()=>{if(!(e.confirmMessage&&!await s({title:e.tooltip,message:e.confirmMessage,variant:e.variant==="danger"?"danger":"default"}))){if(e.action==="copy-value"){try{await navigator.clipboard.writeText(typeof n=="string"?n:String(n))}catch{}return}if(o){i(!0);try{await o(e.action,t)}finally{i(!1)}}}},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:r(nL,{name:e.icon})})}function oL(e){return"multiple"in e&&e.multiple!=null}function sL({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c}){const d=e.multiple,p=d.min,f=d.max,m=t[e.key],g=[...Array.isArray(m)?m:m!=null?[m]:[]],x=d.itemDefault!==void 0?d.itemDefault:"default"in e&&e.default!==void 0?e.default:"";for(;g.length<p;)g.push(x);const b=k=>n(e.key,[...k]),y=(k,C)=>{const D=[...g];D[k]=C,b(D)},w=()=>{g.length>=f||b([...g,x])},v=k=>{g.length<=p||b(g.filter((C,D)=>D!==k))},N=()=>{const{multiple:k,...C}=e;return{...C,...{label:void 0,description:void 0,required:!1}}};return r(Je,{label:e.label,description:e.description,required:p>0?e.required:!1,span:e.span,translationFn:s,children:u("div",{className:"space-y-2",children:[g.map((k,C)=>{const D=d.itemLabel?.replace("${n}",String(C+1));return u("div",{className:"space-y-1",children:[D&&r("div",{className:Wa,children:D}),u("div",{className:"flex items-center gap-2",children:[r("div",{className:"flex-1 min-w-0",children:r(mr,{field:N(),values:{...t,[e.key]:k},onChange:(M,_)=>y(C,_),disabled:o,translationFn:s,onTestField:a,onAction:c,allFields:l})}),g.length>p&&r("button",{type:"button",onClick:()=>v(C),disabled:o,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:r(Jt,{className:"h-3.5 w-3.5"})})]})]},C)}),u("div",{className:"flex items-center justify-between pt-1",children:[g.length<f?u("button",{type:"button",onClick:w,disabled:o,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:[r(Zr,{className:"h-3 w-3"}),d.addLabel??"Add"]}):r("span",{}),u("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:[g.length,"/",f]})]})]})})}function Hd(e,t,n){if(!("showWhen"in e)||!e.showWhen)return!0;const o=e.showWhen,s=t[o.field],a=n?.find(c=>"key"in c&&c.key===o.field),i=a&&"default"in a?a.default:void 0,l=s!==void 0?s:i;return o.equals!==void 0?l===o.equals:o.notEquals!==void 0?l!==o.notEquals:o.in!==void 0?o.in.includes(l):o.notIn!==void 0?!o.notIn.includes(l):o.includes!==void 0?Array.isArray(l)&&l.includes(o.includes):o.notIncludes!==void 0?!Array.isArray(l)||!l.includes(o.notIncludes):!0}function mr({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c}){if(oL(e))return r(sL,{field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c});if("readonlyField"in e&&e.readonlyField===!0)return r(tL,{field:e,values:t,onAction:c,translationFn:s});if(!Hd(e,t,l))return null;const d=t[e.key],p=d!==void 0?d:"default"in e?e.default:void 0,f=h=>n(e.key,h),m=sb(e.type);switch(e.type){case"text":return r(ID,{field:e,value:p,onChange:f,disabled:o,translationFn:s});case"number":return r(PD,{field:e,value:p,onChange:f,disabled:o,translationFn:s});case"boolean":return r(_D,{field:e,value:p,onChange:f,disabled:o,translationFn:s});case"select":return r($D,{field:e,value:p,onChange:f,disabled:o,translationFn:s});case"multiselect":return r(DD,{field:e,value:p,onChange:f,disabled:o,translationFn:s});case"password":return r(LD,{field:e,value:p,onChange:f,disabled:o,translationFn:s});case"textarea":return r(TD,{field:e,value:p,onChange:f,disabled:o,translationFn:s});case"slider":return r(RD,{field:e,value:p,onChange:f,disabled:o,translationFn:s});case"tags":return r(OD,{field:e,value:p,onChange:f,disabled:o,translationFn:s});case"color":return r(BD,{field:e,value:p,onChange:f,disabled:o,translationFn:s});case"node-select":return r(c0,{field:e,value:p,onChange:f,disabled:o,translationFn:s});case"node-multiselect":return r(d0,{field:e,value:p,onChange:f,disabled:o,translationFn:s});case"probe":return r(zD,{field:e,value:p,onChange:f,disabled:o,translationFn:s,onTestField:a,onAction:c,externalProbe:i});case"group":return r(FD,{field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a});case"sub-tabs":return r(jD,{field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:c});case"separator":return r(HD,{});case"info":return r(UD,{field:e});case"object-array":return r(WD,{field:e});case"editable-array":return r(KD,{field:e,value:p,onChange:f,disabled:o,translationFn:s,onTestField:a,onAction:c});case"button":return r(YD,{field:e,disabled:o,onAction:c});case"addon-action-select":return r(ZD,{field:e,value:p,values:t,onChange:f,disabled:o,onAction:c});case"addon-action-button":return r(XD,{field:e,values:t,disabled:o,onAction:c});case"widget":return r(JD,{field:e});default:return m?r(m,{field:e,value:p,onChange:f,disabled:o}):null}}function aL(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function Ft(e,t){if(e!==void 0)return t&&aL(e)?t(e):e}function iL({section:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,probeResults:i}){const[l,c]=I(e.defaultCollapsed??!1),d=e.style==="accordion",p=e.columns??2,f=p===1?"grid-cols-1":p===3?"grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3":p===4?"grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4":"grid-cols-1 @[480px]:grid-cols-2";return u("div",{className:"@container rounded-lg border border-border bg-surface p-3",style:{containerType:"inline-size"},children:[u("div",{className:["flex items-center justify-between mb-2",d?"cursor-pointer":""].join(" "),onClick:d?()=>c(m=>!m):void 0,children:[u("div",{children:[r("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:Ft(e.title,s)}),e.description&&r("p",{className:"text-[10px] text-foreground-subtle mt-0.5",children:Ft(e.description,s)})]}),d&&r("span",{className:"text-foreground-subtle text-xs ml-2",children:l?"▸":"▾"})]}),!l&&r("div",{className:`grid ${f} gap-x-3 gap-y-2.5`,children:e.fields.map(m=>r(mr,{field:m,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i?.[m.key]},m.key))})]})}function p0({schema:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,probeResults:i,onClearProbe:l}){const c=(d,p)=>{n({...t,[d]:p}),l?.(d)};return r("div",{className:"space-y-4",children:e.sections.map(d=>r(iL,{section:d,values:t,onChange:c,disabled:o,translationFn:s,onTestField:a,probeResults:i},d.id))})}const lL=({open:e})=>r("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:r("polyline",{points:"9 18 15 12 9 6"})});function Ep(e){const t={};if(!e)return t;for(const n of e.sections)for(const o of n.fields){if(o.type==="separator"||o.type==="info"||o.type==="button"||o.type==="group")continue;const s=o.key;t[s]=o.value}return t}function cL(e){return{...e,sections:e.sections.map(t=>({...t,fields:t.fields.map(n=>{if(n.type==="separator"||n.type==="info"||n.type==="button"||n.type==="group")return n;const{value:o,...s}=n;return s})}))}}function dL({trpc:e,addonId:t,nodeId:n,title:o,disabled:s,onAfterChange:a,refreshToken:i,collapsible:l,defaultOpen:c,mode:d,onOverrideChange:p}){const f=d??"persist",[m,h]=I(null),[g,x]=I(!0),[b,y]=I(null),[w,v]=I(!1),[N,k]=I(c??!1),[C,D]=I({}),[M,_]=I(null);J(()=>{_(null),D({})},[e,t,n,i,f]);const $=JSON.stringify(C);J(()=>{let L=!1;x(!0),y(null);const B=f==="override"&&Object.keys(C).length>0?C:void 0;return e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n,...B?{overlay:B}:{}}).then(z=>{L||(h(z),B||_(Ep(z)),x(!1))}).catch(z=>{L||(y(z instanceof Error?z.message:String(z)),x(!1))}),()=>{L=!0}},[e,t,n,i,f,$]);const E=q(()=>Ep(m),[m]),R=q(()=>m?cL(m):null,[m]),O=async L=>{if(f==="override"){const z=M??E,T={};for(const H of Object.keys(L))L[H]!==z[H]&&(T[H]=L[H]);const F={...z,...T};D(T),p?.(T,F);return}const B={};for(const z of Object.keys(L))L[z]!==E[z]&&(B[z]=L[z]);if(Object.keys(B).length!==0){v(!0);try{await e.addonSettings.updateGlobalSettings.mutate({addonId:t,nodeId:n,patch:B});const z=await e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n});h(z),a?.()}catch(z){y(z instanceof Error?z.message:String(z))}finally{v(!1)}}};if(g)return u("div",{className:"text-xs text-foreground-subtle animate-pulse",children:["Loading ",o??t,"…"]});if(b)return u("div",{className:"text-xs text-red-400",children:[o??t,": ",b]});if(!m||!R)return u("div",{className:"text-xs text-foreground-subtle",children:[o??t," not available on ",n,"."]});const A=f==="override"?{...E,...C}:E,P=u(me,{children:[f==="override"?r("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,r(p0,{schema:R,values:A,onChange:O,disabled:s===!0||w})]});return l===!0?u("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("button",{type:"button",onClick:()=>k(L=>!L),className:"w-full px-4 py-2 flex items-center gap-2 hover:bg-surface-hover text-left","aria-expanded":N,children:[r(lL,{open:N}),r("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide flex-1",children:o??t}),r("span",{className:"text-[10px] text-foreground-subtle",children:N?"hide":"edit"})]}),N?r("div",{className:"border-t border-border px-4 py-3",children:P}):null]}):o?u("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r("div",{className:"border-b border-border px-4 py-2",children:r("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide",children:o})}),r("div",{className:"px-4 py-3",children:P})]}):r("div",{children:P})}function f0({detections:{motion:e,motionRaw:t,detection:n,phase:o},showMotionZones:s=!0,showMotionRaw:a=!0,showDetections:i=!0,showPhaseIndicator:l=!0}){const c=s&&e&&e.zones.length>0,d=a&&t&&t.boxes.length>0,p=i&&n&&n.detections.length>0;return!c&&!d&&!p&&!l?null:u("div",{className:"absolute inset-0 pointer-events-none z-10",children:[l&&r(uL,{phase:o}),d&&r(pL,{raw:t}),c&&r(fL,{motion:e}),p&&r(mL,{detections:n.detections,frameWidth:n.frameWidth,frameHeight:n.frameHeight})]})}function uL({phase:e}){const t=Gr(e);return u("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:[r("span",{className:`w-2 h-2 rounded-full ${t.dotClass}`}),r("span",{className:"text-[10px] font-semibold text-white uppercase tracking-wider",children:t.label})]})}function pL({raw:e}){return e.frameWidth===0||e.frameHeight===0?null:r(me,{children:e.boxes.map((t,n)=>{const[o,s,a,i]=t.bbox,l=o/e.frameWidth*100,c=s/e.frameHeight*100,d=(a-o)/e.frameWidth*100,p=(i-s)/e.frameHeight*100,f=Math.max(.05,Math.min(.25,t.changeScore*.3));return r("div",{className:"absolute rounded-sm",style:{left:`${l}%`,top:`${c}%`,width:`${d}%`,height:`${p}%`,backgroundColor:`rgba(239, 68, 68, ${f})`}},`mr-${n}`)})})}function fL({motion:e}){if(e.frameWidth===0||e.frameHeight===0)return null;const t=e.zones.filter(n=>n.w*n.h/(e.frameWidth*e.frameHeight)<.9);return r(me,{children:t.map((n,o)=>{const s=Math.max(.15,Math.min(.5,n.intensity/255));return r("div",{className:"absolute rounded-sm",style:{left:`${n.x/e.frameWidth*100}%`,top:`${n.y/e.frameHeight*100}%`,width:`${n.w/e.frameWidth*100}%`,height:`${n.h/e.frameHeight*100}%`,border:`1px solid rgba(250, 204, 21, ${s})`,backgroundColor:`rgba(250, 204, 21, ${s*.15})`}},`mz-${o}`)})})}function mL({detections:e,frameWidth:t,frameHeight:n}){return t===0||n===0?null:r(me,{children:e.map(o=>{const{x:s,y:a,width:i,height:l}=o.bbox,c=s/t*100,d=a/n*100,p=i/t*100,f=l/n*100,m=xt(o.macroClass),h=[`${o.macroClass} ${(o.score*100).toFixed(0)}%`];for(const g of o.labels)h.push(g.label);return r("div",{className:"absolute border-2 rounded-sm",style:{left:`${c}%`,top:`${d}%`,width:`${p}%`,height:`${f}%`,borderColor:m},children:r("div",{className:"absolute -top-4 left-0 px-1 py-0.5 text-[9px] font-bold text-white rounded-sm whitespace-nowrap",style:{backgroundColor:m},children:h.join(" | ")})},`det-${o.id}`)})})}function hL(){return typeof window>"u"?!1:window.matchMedia("(hover: none) and (pointer: coarse)").matches||typeof navigator<"u"&&navigator.maxTouchPoints>0||"ontouchstart"in window}function gL(e){const t={};if(typeof window<"u"){if(e){const o=e.getBoundingClientRect();o.width>0&&o.height>0&&(t.viewportWidth=Math.round(o.width),t.viewportHeight=Math.round(o.height))}t.viewportWidth===void 0&&(t.viewportWidth=window.innerWidth,t.viewportHeight=window.innerHeight),t.devicePixelRatio=window.devicePixelRatio||1;const n=navigator.connection;n?.downlink&&n.downlink>0&&(t.downlinkMbps=n.downlink)}return t}const bL=1500,xL=15e3,yL=40;function m0({serverUrl:e,streamKey:t,label:n,autoPlay:o=!0,muted:s=!0,showControls:a=!0,className:i="",onStateChange:l,onError:c,overlay:d,createSession:p,sendAnswer:f,handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:x,closeSession:b,hintsOverride:y}){const w=ne(null),v=ne(null),N=ne(null),k=ne(new Set),C=ne(null),D=ne(null),M=ne(0),_=ne(!0),[$,E]=I("idle"),[R,O]=I(""),[A,P]=I(s),[L,B]=I(!1),[z,T]=I(!1),F=hL(),[H,j]=I(!0),Q=ne(null),G=ne(!1);(f||p)&&(G.current=!0);const Z=G.current,V=ne(!1);m&&(V.current=!0);const K=V.current,X=U(oe=>{E(oe),l?.(oe)},[l]),te=U(()=>{if(C.current?.abort(),C.current=null,D.current&&(clearTimeout(D.current),D.current=null),N.current&&(N.current.close(),N.current=null),b&&k.current.size>0){for(const oe of k.current)b(oe).catch(()=>{});k.current.clear()}w.current&&(w.current.srcObject=null)},[b]),he=U(async()=>{if(!_.current||!p||!f)return;te(),X("connecting");const oe=new AbortController;C.current=oe;try{const le={...gL(v.current),...y},{sessionId:ke,sdpOffer:ye,iceServers:ie}=await p(le);if(k.current.add(ke),!_.current||oe.signal.aborted){b?.(ke).catch(()=>{}),k.current.delete(ke);return}const ge=new RTCPeerConnection({iceServers:[...ie??[],{urls:"stun:stun.l.google.com:19302"}]});N.current=ge;const Pe=new MediaStream;ge.ontrack=Xe=>{console.debug("[WebRTC] ontrack",Xe.track.kind,Xe.track.readyState),Pe.addTrack(Xe.track),w.current&&(w.current.srcObject=Pe,w.current.play().catch(()=>{}))},ge.oniceconnectionstatechange=()=>{if(!_.current)return;const Xe=ge.iceConnectionState;console.debug("[WebRTC] ICE state:",Xe),Xe==="connected"||Xe==="completed"?(M.current=0,X("playing"),w.current?.paused&&(console.debug("[WebRTC] video was paused at ICE connected — calling play()"),w.current.play().catch(()=>{}))):(Xe==="failed"||Xe==="disconnected"||Xe==="closed")&&(X("disconnected"),ue())},ge.onicecandidateerror=Xe=>{console.debug("[WebRTC] ICE candidate error:",Xe)},console.debug("[WebRTC] Setting remote description (server offer)..."),await ge.setRemoteDescription({type:"offer",sdp:ye});const ze=await ge.createAnswer();if(await ge.setLocalDescription(ze),console.debug("[WebRTC] Local description set, waiting for ICE gathering..."),await Ip(ge),!_.current)return;const Fe=(ge.localDescription?.sdp??"").split(`
576
+ `).filter(Xe=>Xe.startsWith("a=candidate:")).length;console.debug("[WebRTC] Sending answer to server",{localCandidates:Fe,sessionId:ke.slice(0,8)}),await f(ke,ge.localDescription?.sdp??""),console.debug("[WebRTC] Answer sent successfully");const lt=ge,$t=()=>{const Xe=lt.connectionState;if(Xe==="closed"||Xe==="failed")return;const gr=w.current;gr&&gr.readyState===0&&console.log(`[WebRTC] no video data yet (ice=${lt.iceConnectionState})`)};setTimeout($t,3e3),setTimeout($t,8e3)}catch(fe){if(!_.current)return;const le=fe instanceof Error?fe.message:String(fe);O(le),X("error"),c?.(le),ue()}},[e,t,p,f,te,X,c,y]),xe=U(async()=>{if(_.current){te(),X("connecting");try{const oe=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]});N.current=oe,oe.addTransceiver("video",{direction:"recvonly"}),oe.addTransceiver("audio",{direction:"recvonly"});const fe=new MediaStream;oe.ontrack=ge=>{fe.addTrack(ge.track),w.current&&(w.current.srcObject=fe,w.current.play().catch(()=>{}))},oe.oniceconnectionstatechange=()=>{if(!_.current)return;const ge=oe.iceConnectionState;ge==="connected"||ge==="completed"?(M.current=0,X("playing"),w.current?.paused&&w.current.play().catch(()=>{})):(ge==="failed"||ge==="disconnected"||ge==="closed")&&(X("disconnected"),ue())};const le=await oe.createOffer();if(await oe.setLocalDescription(le),await Ip(oe),!_.current)return;const ke=`${e}/api/webrtc?src=${encodeURIComponent(t)}`,ye=await fetch(ke,{method:"POST",headers:{"Content-Type":"application/sdp"},body:oe.localDescription?.sdp??""});if(!ye.ok)throw new Error(`WHEP ${ye.status}: ${ye.statusText}`);const ie=await ye.text();await oe.setRemoteDescription({type:"answer",sdp:ie})}catch(oe){if(!_.current)return;const fe=oe instanceof Error?oe.message:String(oe);O(fe),X("error"),c?.(fe),ue()}}},[e,t,te,X,c]),ee=U(async()=>{if(!_.current||!m)return;te(),X("connecting");const oe=new AbortController;C.current=oe;try{const fe=await h?.();if(!_.current||oe.signal.aborted)return;const le=new RTCPeerConnection({iceServers:[...fe??[],{urls:"stun:stun.l.google.com:19302"}]});N.current=le;const ke=new MediaStream;le.ontrack=Fe=>{console.debug("[WebRTC] ontrack (client-offer)",Fe.track.kind,Fe.track.readyState),ke.addTrack(Fe.track),w.current&&(w.current.srcObject=ke,w.current.play().catch(()=>{}))},le.oniceconnectionstatechange=()=>{if(!_.current)return;const Fe=le.iceConnectionState;console.debug("[WebRTC] ICE state (client-offer):",Fe),Fe==="connected"||Fe==="completed"?(M.current=0,X("playing"),w.current?.paused&&w.current.play().catch(()=>{})):(Fe==="failed"||Fe==="disconnected"||Fe==="closed")&&(X("disconnected"),ue())};let ye=null;const ie=[];le.onicecandidate=Fe=>{if(!Fe.candidate)return;const lt=Fe.candidate.toJSON();ye&&g?g(ye,lt).catch(()=>{}):ie.push(lt)},le.addTransceiver("video",{direction:"recvonly"}),le.addTransceiver("audio",{direction:"recvonly"});const ge=await le.createOffer();if(await le.setLocalDescription(ge),!_.current||oe.signal.aborted)return;const{sessionId:Pe,sdpAnswer:ze}=await m(le.localDescription?.sdp??ge.sdp??"");if(ye=Pe,k.current.add(Pe),!_.current||oe.signal.aborted){b?.(Pe).catch(()=>{}),k.current.delete(Pe);return}if(g)for(const Fe of ie)g(Pe,Fe).catch(()=>{});if(ie.length=0,await le.setRemoteDescription({type:"answer",sdp:ze}),console.debug("[WebRTC] Client-offer answer set (trickle)",{sessionId:Pe.slice(0,8)}),x){const Fe=new Set,lt=Date.now(),$t=async()=>{if(!(!_.current||oe.signal.aborted||N.current!==le)){try{const{candidates:Xe,done:gr}=await x(Pe);for(const fs of Xe){const lo=fs.candidate??"";lo&&!Fe.has(lo)&&(Fe.add(lo),le.addIceCandidate(new RTCIceCandidate(fs)).catch(()=>{}))}const ps=le.iceConnectionState;if(gr||Date.now()-lt>1e4||ps==="connected"||ps==="completed")return}catch{}setTimeout(()=>{$t()},200)}};$t()}}catch(fe){if(!_.current)return;const le=fe instanceof Error?fe.message:String(fe);O(le),X("error"),c?.(le),ue()}},[m,h,g,x,b,te,X,c]),re=K?ee:Z?he:xe,de=ne(()=>{});de.current=re;const ue=U(()=>{if(!_.current||M.current>=yL)return;const oe=M.current;M.current+=1;const fe=Math.min(xL,bL*2**oe),le=Math.round(fe*(.8+Math.random()*.4));D.current=setTimeout(()=>{_.current&&de.current()},le)},[]);J(()=>(_.current=!0,M.current=0,o&&re(),()=>{_.current=!1,te()}),[e,t]);const be=ne(!1);J(()=>{if(o){if(K){if(!m)return}else if(Z){if(!p||!f)return}else return;be.current||N.current||(be.current=!0,re())}},[o,K,Z,m,p,f,re]);const Se=()=>{M.current=0,re()},Oe=()=>{w.current&&(w.current.muted=!w.current.muted,P(w.current.muted))},Be=async()=>{if(v.current)try{if(document.fullscreenElement){await document.exitFullscreen();return}if(v.current.requestFullscreen){await v.current.requestFullscreen();return}const oe=w.current;oe?.webkitEnterFullscreen&&oe.webkitEnterFullscreen()}catch(oe){console.warn(`Fullscreen toggle failed: ${oe instanceof Error?oe.message:oe}`)}},He=async()=>{const oe=w.current;if(oe)try{const fe=Reflect.get(oe,"webkitSetPresentationMode");if(typeof fe=="function"){const le=Reflect.get(oe,"webkitPresentationMode");fe.call(oe,le==="picture-in-picture"?"inline":"picture-in-picture");return}document.pictureInPictureElement?await document.exitPictureInPicture():await oe.requestPictureInPicture()}catch(fe){console.warn(`PiP toggle failed: ${fe instanceof Error?fe.message:String(fe)}`)}},se=()=>{if(!w.current)return;const oe=document.createElement("canvas");oe.width=w.current.videoWidth||1280,oe.height=w.current.videoHeight||720;const fe=oe.getContext("2d");if(!fe)return;fe.drawImage(w.current,0,0);const le=document.createElement("a");le.download=`${t.replace(/[/:]/g,"-")}-${Date.now()}.jpg`,le.href=oe.toDataURL("image/jpeg",.92),le.click()};J(()=>{const oe=()=>B(!!document.fullscreenElement);document.addEventListener("fullscreenchange",oe);const fe=w.current;return fe?.addEventListener("webkitbeginfullscreen",oe),fe?.addEventListener("webkitendfullscreen",oe),()=>{document.removeEventListener("fullscreenchange",oe),fe?.removeEventListener("webkitbeginfullscreen",oe),fe?.removeEventListener("webkitendfullscreen",oe)}},[]),J(()=>{const oe=w.current,fe=typeof document<"u"&&document.pictureInPictureEnabled===!0,le=oe!==null&&typeof Reflect.get(oe,"webkitSetPresentationMode")=="function";T(fe||le)},[]);const W=()=>{F||(j(!0),Q.current&&clearTimeout(Q.current),Q.current=setTimeout(()=>j(!1),3e3))},pe=()=>{j(oe=>!oe),Q.current&&clearTimeout(Q.current)};return u("div",{ref:v,className:`relative isolate bg-black overflow-hidden group ${i}`,onMouseMove:W,onMouseEnter:W,onTouchStart:pe,children:[r("video",{ref:w,autoPlay:o,muted:A,playsInline:!0,className:"w-full h-full object-contain relative z-0"}),n&&$==="playing"&&r("div",{className:"absolute top-2 left-2 z-10 transform-gpu px-2 py-0.5 rounded bg-black/60 text-[10px] text-white font-medium",children:n}),d,$==="connecting"&&u("div",{className:"absolute inset-0 z-10 transform-gpu flex flex-col items-center justify-center bg-black/70 gap-2",children:[r("svg",{className:"h-6 w-6 text-white/60 animate-spin",viewBox:"0 0 24 24",fill:"none",children:r("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]"})}),r("span",{className:"text-xs text-white/60",children:"Connecting…"})]}),($==="error"||$==="disconnected")&&u("div",{className:"absolute inset-0 z-10 transform-gpu flex flex-col items-center justify-center bg-black/70 gap-2",children:[r("svg",{className:"h-6 w-6 text-red-400",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:r("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"})}),r("span",{className:"text-xs text-red-400 text-center px-4",children:$==="error"?R||"Connection failed":"Disconnected"}),r("button",{onClick:Se,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&&$!=="idle"&&$!=="error"&&u("div",{className:`absolute bottom-0 inset-x-0 z-20 transform-gpu flex items-center justify-between px-3 py-1.5 bg-gradient-to-t from-black/80 to-transparent transition-opacity duration-200 ${F||H?"opacity-100 pointer-events-auto":"opacity-0 pointer-events-none"}`,children:[r("div",{className:"flex items-center gap-1",children:r(ks,{onClick:Oe,title:A?"Unmute":"Mute",children:A?u("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[r("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),r("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),r("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]}):u("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[r("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),r("path",{d:"M19.07 4.93a10 10 0 010 14.14M15.54 8.46a5 5 0 010 7.07"})]})})}),u("div",{className:"flex items-center gap-1",children:[r(ks,{onClick:se,title:"Take snapshot",children:u("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[r("path",{d:"M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z"}),r("circle",{cx:"12",cy:"13",r:"4"})]})}),z&&r(ks,{onClick:He,title:"Picture-in-Picture",children:u("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M21 9V6a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2h4"}),r("rect",{width:"10",height:"7",x:"12",y:"13",rx:"2"})]})}),r(ks,{onClick:Be,title:L?"Exit fullscreen":"Fullscreen",children:L?r("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:r("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"})}):r("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:r("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 ks({onClick:e,title:t,children:n}){return r("button",{onClick:e,title:t,className:"rounded-full p-1.5 min-w-[44px] min-h-[44px] flex items-center justify-center text-white/80 hover:text-white hover:bg-white/20 active:bg-white/30 transition-colors",children:n})}async function Ip(e){if(e.iceGatheringState!=="complete")return new Promise(t=>{let n=!1,o;const s=()=>{n||(n=!0,o&&clearInterval(o),e.removeEventListener("icegatheringstatechange",a),t())},a=()=>{e.iceGatheringState==="complete"&&s()};e.addEventListener("icegatheringstatechange",a);const i=Date.now();o=setInterval(()=>{const l=e.localDescription?.sdp??"";/ typ host/.test(l)&&Date.now()-i>=600&&s()},100),setTimeout(s,2500)})}function vL(e){return e==="streaming"?"bg-emerald-500":e==="connecting"?"bg-amber-500":e==="error"?"bg-rose-500":"bg-zinc-500"}function wL(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 ql({className:e}){return r("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r("polygon",{points:"5 3 19 12 5 21 5 3"})})}function NL({className:e}){return r("svg",{className:e,viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r("rect",{x:"6",y:"6",width:"12",height:"12",rx:"1"})})}function kL({className:e}){return u("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z"}),r("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),r("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),r("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}function SL({className:e}){return u("svg",{className:e,viewBox:"0 0 24 24",fill:"currentColor",children:[r("circle",{cx:"5",cy:"12",r:"2"}),r("circle",{cx:"12",cy:"12",r:"2"}),r("circle",{cx:"19",cy:"12",r:"2"})]})}function Hi({label:e,active:t,onClick:n}){return u("button",{type:"button",onClick:n,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:[r("span",{children:e}),r("span",{className:`inline-block h-3 w-5 rounded-full transition-colors ${t?"bg-primary":"bg-foreground-subtle/30"} relative`,children:r("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-white transition-all ${t?"left-2.5":"left-0.5"}`})})]})}function h0({className:e}){return u("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("polyline",{points:"23 4 23 10 17 10"}),r("polyline",{points:"1 20 1 14 7 14"}),r("path",{d:"M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15"})]})}function CL({className:e}){return u("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("line",{x1:"2",y1:"2",x2:"22",y2:"22"}),r("path",{d:"M10.41 10.41a2 2 0 11-2.83-2.83"}),r("line",{x1:"13.5",y1:"13.5",x2:"6",y2:"21"}),r("path",{d:"M18 12l-1.5-1.5"}),r("path",{d:"M21 15V5a2 2 0 00-2-2H5"}),r("path",{d:"M21 21H5a2 2 0 01-2-2V11"})]})}function g0({serverUrl:e,createSession:t,sendAnswer:n,handleOffer:o,getIceServers:s,addIceCandidate:a,getIceCandidates:i,closeSession:l,streams:c,activeStreamId:d,onStreamChange:p,deviceName:f,phase:m,pipelineMetrics:h,detections:g,defaultShowDetections:x=!0,defaultShowMotion:b=!1,streamStats:y,autoPlay:w=!1,showPlayStop:v=!1,snapshotSrc:N,snapshotLoading:k=!1,onRefreshSnapshot:C,showStreamStats:D=!1,children:M,extraOverlay:_,ptzAvailable:$=!1,ptzShown:E=!1,ptzOverlay:R,onPtzToggle:O,intercomAvailable:A=!1,intercomShown:P=!1,onIntercomToggle:L,chromeless:B=!1,className:z}){const T=r0(),[F,H]=I(w),[j,Q]=I(x),[G,Z]=I(b),[V,K]=I(null),[X,te]=I(!1),he=ne(null);J(()=>{if(!X)return;function le(ke){he.current&&!he.current.contains(ke.target)&&te(!1)}return document.addEventListener("mousedown",le),()=>document.removeEventListener("mousedown",le)},[X]);const xe=d??V??c?.[0]?.id??"",ee=c?.find(le=>le.id===xe)??c?.[0],re=ee?.inputFps!=null?{status:ee.status??"unknown",inputFps:ee.inputFps,bitrateKbps:ee.bitrateKbps??0}:null,de=le=>{K(le),p?.(le),F&&v&&(H(!1),setTimeout(()=>H(!0),50))},ue=q(()=>{const le=ee?.target;if(le)return ke=>t(le,ke)},[t,ee]),be=q(()=>{const le=ee?.target;if(!(!le||!o))return ke=>o(le,ke)},[o,ee]),Se=c,Oe=()=>H(!0),Be=()=>H(!1),He=h?.phase??m,se=He==="active",W=!!g,pe=W&&(j||G),oe=$&&E&&!!R,fe=v?F:!0;return u("div",{className:`overflow-hidden ${B?"":"rounded-xl border border-border bg-surface"} ${z??""}`,children:[u("div",{className:"flex flex-wrap items-center justify-between gap-2 px-3 py-2 border-b border-border",children:[u("div",{className:"flex items-center gap-2 min-w-0",children:[(y??re)&&r("span",{className:`shrink-0 w-2 h-2 rounded-full ${vL((y??re).status)}`}),f&&r("span",{className:"text-xs font-medium text-foreground truncate",children:f}),Se&&Se.length>1&&u("div",{className:"relative",children:[r("select",{"data-testid":"stream-profile-select",value:xe,onChange:le=>de(le.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:Se.map(le=>r("option",{value:le.id,children:le.label},le.id))}),r("span",{className:"pointer-events-none absolute right-1.5 top-1/2 -translate-y-1/2 text-foreground-subtle",children:r("svg",{className:"h-2.5 w-2.5",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r("polyline",{points:"3 4.5 6 7.5 9 4.5"})})})]})]}),u("div",{className:"flex items-center gap-1.5 shrink-0 ml-auto",children:[A&&u("button",{"data-testid":"stream-intercom-toggle","data-intercom-shown":P?"true":"false",onClick:L,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors ${P?"bg-primary/15 text-primary":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,title:P?"Close intercom":"Open intercom",children:[r(kL,{className:"h-3 w-3"}),r("span",{className:"hidden xl:inline",children:"Intercom"})]}),T.map(le=>{const ye=le.tone==="primary"?"bg-primary text-primary-foreground":"bg-primary/15 text-primary";return u("button",{type:"button","data-toolbar-button-id":le.id,"data-toolbar-button-active":le.active?"true":"false",onClick:le.onClick,disabled:le.disabled,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors disabled:opacity-50 ${le.active?ye:"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,title:le.title??le.label,children:[le.icon,r("span",{className:"hidden xl:inline",children:le.label})]},le.id)}),v&&u("button",{"data-testid":"stream-play-toggle","data-stream-playing":fe?"true":"false",onClick:fe?Be:Oe,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors ${fe?"bg-danger/10 text-danger hover:bg-danger/20":"bg-primary/10 text-primary hover:bg-primary/20"}`,title:fe?"Stop stream":"Start stream",children:[fe?r(NL,{className:"h-3 w-3"}):r(ql,{className:"h-3 w-3"}),r("span",{className:"hidden xl:inline",children:fe?"Stop":"Play"})]}),C&&u("button",{"data-testid":"stream-snapshot-refresh",onClick:C,disabled:k,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:[r(h0,{className:`h-3 w-3 ${k?"animate-spin":""}`}),r("span",{className:"hidden xl:inline",children:"Snapshot"})]}),(W||$||h||He||y||re&&re.inputFps>0)&&u("div",{ref:he,className:"relative",children:[r("button",{onClick:()=>te(le=>!le),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:r(SL,{className:"h-3.5 w-3.5"})}),X&&u("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:[D&&y&&u("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[u("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Input"}),u("span",{className:"tabular-nums text-foreground",children:[y.inputFps.toFixed(1)," fps"]})]}),u("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Decode"}),u("span",{className:"tabular-nums text-foreground",children:[y.decodeFps.toFixed(1)," fps"]})]}),u("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Uptime"}),r("span",{className:"tabular-nums text-foreground",children:wL(y.uptimeMs)})]})]}),!D&&re&&re.inputFps>0&&u("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[u("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Input"}),u("span",{className:"tabular-nums text-foreground",children:[re.inputFps.toFixed(1)," fps"]})]}),re.bitrateKbps>0&&u("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Bitrate"}),u("span",{className:"tabular-nums text-foreground",children:[re.bitrateKbps," kbps"]})]})]}),(h||W&&He)&&u("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[u("div",{className:"flex justify-between gap-3 items-center",children:[r("span",{children:"Phase"}),u("span",{className:`flex items-center gap-1 font-semibold uppercase tracking-wider ${se?"text-red-400":"text-emerald-400"}`,children:[r("span",{className:`w-1.5 h-1.5 rounded-full ${se?"bg-red-500 animate-pulse":"bg-emerald-500"}`}),se?"Active":"Watching"]})]}),h&&h.detectionFps>0&&u("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Detection"}),u("span",{className:"tabular-nums text-foreground",children:[h.detectionFps.toFixed(1)," det/s"]})]}),h&&h.avgInferenceMs>0&&u("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Inference"}),u("span",{className:"tabular-nums text-foreground",children:[h.avgInferenceMs.toFixed(0)," ms"]})]})]}),W&&u(me,{children:[r(Hi,{label:"Show detections",active:j,onClick:()=>Q(le=>!le)}),r(Hi,{label:"Show motion",active:G,onClick:()=>Z(le=>!le)})]}),$&&r(Hi,{label:"PTZ controls",active:E,onClick:()=>{O?.(),te(!1)}})]})]})]})]}),fe?r("div",{className:"aspect-video relative",children:r(m0,{serverUrl:e,streamKey:xe,autoPlay:!0,className:"w-full h-full",createSession:ue,sendAnswer:n,handleOffer:be,getIceServers:s,addIceCandidate:a,getIceCandidates:i,closeSession:l,overlay:pe||_||oe?u(me,{children:[pe&&r(f0,{detections:g,showPhaseIndicator:!1,showMotionZones:G,showMotionRaw:G,showDetections:j}),_,oe&&R]}):void 0},xe)}):r(ML,{src:N??null,isLoading:k,onPlay:Oe,onRetry:C,extraOverlay:_||oe?u(me,{children:[_,oe&&R]}):null,suppressPlayHover:!!_||oe}),M]})}function ML({src:e,isLoading:t,onPlay:n,onRetry:o,extraOverlay:s,suppressPlayHover:a=!1}){return e?u("div",{className:"relative w-full aspect-video bg-black/90 flex items-center justify-center",children:[r("img",{src:e,alt:"Camera snapshot",className:"w-full h-full object-contain"}),!a&&r("button",{onClick:n,className:"absolute inset-0 flex items-center justify-center bg-black/30 opacity-0 hover:opacity-100 transition-opacity cursor-pointer",children:r("div",{className:"h-14 w-14 rounded-full bg-white/20 backdrop-blur-sm flex items-center justify-center",children:r(ql,{className:"h-7 w-7 text-white ml-0.5"})})}),s]}):t?r("div",{className:"relative w-full aspect-video bg-black/90 flex items-center justify-center",children:r("div",{className:"h-8 w-8 border-2 border-white/20 border-t-white/60 rounded-full animate-spin"})}):r("div",{className:"relative w-full aspect-video bg-black/90 flex items-center justify-center",children:u("div",{className:"flex flex-col items-center gap-2 text-white/40",children:[r(CL,{className:"h-8 w-8"}),r("span",{className:"text-xs",children:"No snapshot available"}),u("div",{className:"flex items-center gap-2 mt-1",children:[o&&u("button",{onClick:o,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:[r(h0,{className:"h-3 w-3"}),"Retry"]}),u("button",{onClick:n,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:[r(ql,{className:"h-3 w-3"}),"Play Live"]})]})]})})}const Pp={value:"auto",label:"Auto (best available)"};function AL(e){return e.charAt(0).toUpperCase()+e.slice(1)}function EL({deviceId:e,value:t,onChange:n,disabled:o,label:s,className:a}){const i=er(),l=jb({deviceId:e},{refetchOnWindowFocus:!1}),[c,d]=I([Pp]);J(()=>{if(!l.data)return;const m=`${e}/`,h=[Pp];for(const g of l.data){if(!g.enabled)continue;const x=g.brokerId.startsWith(m)?g.brokerId.slice(m.length):g.brokerId;h.push({value:x,label:AL(x)})}d(h)},[l.data,e]);const p=s??"Preferred stream",f=l.isLoading?"Loading available streams…":l.isError?"Could not load streams — only Auto available.":c.length===1?"No enabled streams found — only Auto available.":null;return u("div",{className:a,children:[r("label",{id:i,className:"text-xs font-medium text-foreground-muted block mb-1",children:p}),r(To,{"aria-labelledby":i,options:c,value:t,disabled:o,onChange:m=>n(m.target.value)}),f!==null&&r("p",{className:"text-foreground-subtle text-[10px] mt-1",children:f})]})}var IL=Object.defineProperty,ua=Object.getOwnPropertySymbols,b0=Object.prototype.hasOwnProperty,x0=Object.prototype.propertyIsEnumerable,_p=(e,t,n)=>t in e?IL(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ql=(e,t)=>{for(var n in t||(t={}))b0.call(t,n)&&_p(e,n,t[n]);if(ua)for(var n of ua(t))x0.call(t,n)&&_p(e,n,t[n]);return e},Gl=(e,t)=>{var n={};for(var o in e)b0.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(e!=null&&ua)for(var o of ua(e))t.indexOf(o)<0&&x0.call(e,o)&&(n[o]=e[o]);return n};/**
577
+ * @license QR Code generator library (TypeScript)
578
+ * Copyright (c) Project Nayuki.
579
+ * SPDX-License-Identifier: MIT
580
+ */var tr;(e=>{const t=class Le{constructor(c,d,p,f){if(this.version=c,this.errorCorrectionLevel=d,this.modules=[],this.isFunction=[],c<Le.MIN_VERSION||c>Le.MAX_VERSION)throw new RangeError("Version value out of range");if(f<-1||f>7)throw new RangeError("Mask value out of range");this.size=c*4+17;let m=[];for(let g=0;g<this.size;g++)m.push(!1);for(let g=0;g<this.size;g++)this.modules.push(m.slice()),this.isFunction.push(m.slice());this.drawFunctionPatterns();const h=this.addEccAndInterleave(p);if(this.drawCodewords(h),f==-1){let g=1e9;for(let x=0;x<8;x++){this.applyMask(x),this.drawFormatBits(x);const b=this.getPenaltyScore();b<g&&(f=x,g=b),this.applyMask(x)}}s(0<=f&&f<=7),this.mask=f,this.applyMask(f),this.drawFormatBits(f),this.isFunction=[]}static encodeText(c,d){const p=e.QrSegment.makeSegments(c);return Le.encodeSegments(p,d)}static encodeBinary(c,d){const p=e.QrSegment.makeBytes(c);return Le.encodeSegments([p],d)}static encodeSegments(c,d,p=1,f=40,m=-1,h=!0){if(!(Le.MIN_VERSION<=p&&p<=f&&f<=Le.MAX_VERSION)||m<-1||m>7)throw new RangeError("Invalid value");let g,x;for(g=p;;g++){const v=Le.getNumDataCodewords(g,d)*8,N=i.getTotalBits(c,g);if(N<=v){x=N;break}if(g>=f)throw new RangeError("Data too long")}for(const v of[Le.Ecc.MEDIUM,Le.Ecc.QUARTILE,Le.Ecc.HIGH])h&&x<=Le.getNumDataCodewords(g,v)*8&&(d=v);let b=[];for(const v of c){n(v.mode.modeBits,4,b),n(v.numChars,v.mode.numCharCountBits(g),b);for(const N of v.getData())b.push(N)}s(b.length==x);const y=Le.getNumDataCodewords(g,d)*8;s(b.length<=y),n(0,Math.min(4,y-b.length),b),n(0,(8-b.length%8)%8,b),s(b.length%8==0);for(let v=236;b.length<y;v^=253)n(v,8,b);let w=[];for(;w.length*8<b.length;)w.push(0);return b.forEach((v,N)=>w[N>>>3]|=v<<7-(N&7)),new Le(g,d,w,m)}getModule(c,d){return 0<=c&&c<this.size&&0<=d&&d<this.size&&this.modules[d][c]}getModules(){return this.modules}drawFunctionPatterns(){for(let p=0;p<this.size;p++)this.setFunctionModule(6,p,p%2==0),this.setFunctionModule(p,6,p%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const c=this.getAlignmentPatternPositions(),d=c.length;for(let p=0;p<d;p++)for(let f=0;f<d;f++)p==0&&f==0||p==0&&f==d-1||p==d-1&&f==0||this.drawAlignmentPattern(c[p],c[f]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(c){const d=this.errorCorrectionLevel.formatBits<<3|c;let p=d;for(let m=0;m<10;m++)p=p<<1^(p>>>9)*1335;const f=(d<<10|p)^21522;s(f>>>15==0);for(let m=0;m<=5;m++)this.setFunctionModule(8,m,o(f,m));this.setFunctionModule(8,7,o(f,6)),this.setFunctionModule(8,8,o(f,7)),this.setFunctionModule(7,8,o(f,8));for(let m=9;m<15;m++)this.setFunctionModule(14-m,8,o(f,m));for(let m=0;m<8;m++)this.setFunctionModule(this.size-1-m,8,o(f,m));for(let m=8;m<15;m++)this.setFunctionModule(8,this.size-15+m,o(f,m));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let c=this.version;for(let p=0;p<12;p++)c=c<<1^(c>>>11)*7973;const d=this.version<<12|c;s(d>>>18==0);for(let p=0;p<18;p++){const f=o(d,p),m=this.size-11+p%3,h=Math.floor(p/3);this.setFunctionModule(m,h,f),this.setFunctionModule(h,m,f)}}drawFinderPattern(c,d){for(let p=-4;p<=4;p++)for(let f=-4;f<=4;f++){const m=Math.max(Math.abs(f),Math.abs(p)),h=c+f,g=d+p;0<=h&&h<this.size&&0<=g&&g<this.size&&this.setFunctionModule(h,g,m!=2&&m!=4)}}drawAlignmentPattern(c,d){for(let p=-2;p<=2;p++)for(let f=-2;f<=2;f++)this.setFunctionModule(c+f,d+p,Math.max(Math.abs(f),Math.abs(p))!=1)}setFunctionModule(c,d,p){this.modules[d][c]=p,this.isFunction[d][c]=!0}addEccAndInterleave(c){const d=this.version,p=this.errorCorrectionLevel;if(c.length!=Le.getNumDataCodewords(d,p))throw new RangeError("Invalid argument");const f=Le.NUM_ERROR_CORRECTION_BLOCKS[p.ordinal][d],m=Le.ECC_CODEWORDS_PER_BLOCK[p.ordinal][d],h=Math.floor(Le.getNumRawDataModules(d)/8),g=f-h%f,x=Math.floor(h/f);let b=[];const y=Le.reedSolomonComputeDivisor(m);for(let v=0,N=0;v<f;v++){let k=c.slice(N,N+x-m+(v<g?0:1));N+=k.length;const C=Le.reedSolomonComputeRemainder(k,y);v<g&&k.push(0),b.push(k.concat(C))}let w=[];for(let v=0;v<b[0].length;v++)b.forEach((N,k)=>{(v!=x-m||k>=g)&&w.push(N[v])});return s(w.length==h),w}drawCodewords(c){if(c.length!=Math.floor(Le.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let d=0;for(let p=this.size-1;p>=1;p-=2){p==6&&(p=5);for(let f=0;f<this.size;f++)for(let m=0;m<2;m++){const h=p-m,x=(p+1&2)==0?this.size-1-f:f;!this.isFunction[x][h]&&d<c.length*8&&(this.modules[x][h]=o(c[d>>>3],7-(d&7)),d++)}}s(d==c.length*8)}applyMask(c){if(c<0||c>7)throw new RangeError("Mask value out of range");for(let d=0;d<this.size;d++)for(let p=0;p<this.size;p++){let f;switch(c){case 0:f=(p+d)%2==0;break;case 1:f=d%2==0;break;case 2:f=p%3==0;break;case 3:f=(p+d)%3==0;break;case 4:f=(Math.floor(p/3)+Math.floor(d/2))%2==0;break;case 5:f=p*d%2+p*d%3==0;break;case 6:f=(p*d%2+p*d%3)%2==0;break;case 7:f=((p+d)%2+p*d%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[d][p]&&f&&(this.modules[d][p]=!this.modules[d][p])}}getPenaltyScore(){let c=0;for(let m=0;m<this.size;m++){let h=!1,g=0,x=[0,0,0,0,0,0,0];for(let b=0;b<this.size;b++)this.modules[m][b]==h?(g++,g==5?c+=Le.PENALTY_N1:g>5&&c++):(this.finderPenaltyAddHistory(g,x),h||(c+=this.finderPenaltyCountPatterns(x)*Le.PENALTY_N3),h=this.modules[m][b],g=1);c+=this.finderPenaltyTerminateAndCount(h,g,x)*Le.PENALTY_N3}for(let m=0;m<this.size;m++){let h=!1,g=0,x=[0,0,0,0,0,0,0];for(let b=0;b<this.size;b++)this.modules[b][m]==h?(g++,g==5?c+=Le.PENALTY_N1:g>5&&c++):(this.finderPenaltyAddHistory(g,x),h||(c+=this.finderPenaltyCountPatterns(x)*Le.PENALTY_N3),h=this.modules[b][m],g=1);c+=this.finderPenaltyTerminateAndCount(h,g,x)*Le.PENALTY_N3}for(let m=0;m<this.size-1;m++)for(let h=0;h<this.size-1;h++){const g=this.modules[m][h];g==this.modules[m][h+1]&&g==this.modules[m+1][h]&&g==this.modules[m+1][h+1]&&(c+=Le.PENALTY_N2)}let d=0;for(const m of this.modules)d=m.reduce((h,g)=>h+(g?1:0),d);const p=this.size*this.size,f=Math.ceil(Math.abs(d*20-p*10)/p)-1;return s(0<=f&&f<=9),c+=f*Le.PENALTY_N4,s(0<=c&&c<=2568888),c}getAlignmentPatternPositions(){if(this.version==1)return[];{const c=Math.floor(this.version/7)+2,d=this.version==32?26:Math.ceil((this.version*4+4)/(c*2-2))*2;let p=[6];for(let f=this.size-7;p.length<c;f-=d)p.splice(1,0,f);return p}}static getNumRawDataModules(c){if(c<Le.MIN_VERSION||c>Le.MAX_VERSION)throw new RangeError("Version number out of range");let d=(16*c+128)*c+64;if(c>=2){const p=Math.floor(c/7)+2;d-=(25*p-10)*p-55,c>=7&&(d-=36)}return s(208<=d&&d<=29648),d}static getNumDataCodewords(c,d){return Math.floor(Le.getNumRawDataModules(c)/8)-Le.ECC_CODEWORDS_PER_BLOCK[d.ordinal][c]*Le.NUM_ERROR_CORRECTION_BLOCKS[d.ordinal][c]}static reedSolomonComputeDivisor(c){if(c<1||c>255)throw new RangeError("Degree out of range");let d=[];for(let f=0;f<c-1;f++)d.push(0);d.push(1);let p=1;for(let f=0;f<c;f++){for(let m=0;m<d.length;m++)d[m]=Le.reedSolomonMultiply(d[m],p),m+1<d.length&&(d[m]^=d[m+1]);p=Le.reedSolomonMultiply(p,2)}return d}static reedSolomonComputeRemainder(c,d){let p=d.map(f=>0);for(const f of c){const m=f^p.shift();p.push(0),d.forEach((h,g)=>p[g]^=Le.reedSolomonMultiply(h,m))}return p}static reedSolomonMultiply(c,d){if(c>>>8||d>>>8)throw new RangeError("Byte out of range");let p=0;for(let f=7;f>=0;f--)p=p<<1^(p>>>7)*285,p^=(d>>>f&1)*c;return s(p>>>8==0),p}finderPenaltyCountPatterns(c){const d=c[1];s(d<=this.size*3);const p=d>0&&c[2]==d&&c[3]==d*3&&c[4]==d&&c[5]==d;return(p&&c[0]>=d*4&&c[6]>=d?1:0)+(p&&c[6]>=d*4&&c[0]>=d?1:0)}finderPenaltyTerminateAndCount(c,d,p){return c&&(this.finderPenaltyAddHistory(d,p),d=0),d+=this.size,this.finderPenaltyAddHistory(d,p),this.finderPenaltyCountPatterns(p)}finderPenaltyAddHistory(c,d){d[0]==0&&(c+=this.size),d.pop(),d.unshift(c)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(l,c,d){if(c<0||c>31||l>>>c)throw new RangeError("Value out of range");for(let p=c-1;p>=0;p--)d.push(l>>>p&1)}function o(l,c){return(l>>>c&1)!=0}function s(l){if(!l)throw new Error("Assertion error")}const a=class Ye{constructor(c,d,p){if(this.mode=c,this.numChars=d,this.bitData=p,d<0)throw new RangeError("Invalid argument");this.bitData=p.slice()}static makeBytes(c){let d=[];for(const p of c)n(p,8,d);return new Ye(Ye.Mode.BYTE,c.length,d)}static makeNumeric(c){if(!Ye.isNumeric(c))throw new RangeError("String contains non-numeric characters");let d=[];for(let p=0;p<c.length;){const f=Math.min(c.length-p,3);n(parseInt(c.substring(p,p+f),10),f*3+1,d),p+=f}return new Ye(Ye.Mode.NUMERIC,c.length,d)}static makeAlphanumeric(c){if(!Ye.isAlphanumeric(c))throw new RangeError("String contains unencodable characters in alphanumeric mode");let d=[],p;for(p=0;p+2<=c.length;p+=2){let f=Ye.ALPHANUMERIC_CHARSET.indexOf(c.charAt(p))*45;f+=Ye.ALPHANUMERIC_CHARSET.indexOf(c.charAt(p+1)),n(f,11,d)}return p<c.length&&n(Ye.ALPHANUMERIC_CHARSET.indexOf(c.charAt(p)),6,d),new Ye(Ye.Mode.ALPHANUMERIC,c.length,d)}static makeSegments(c){return c==""?[]:Ye.isNumeric(c)?[Ye.makeNumeric(c)]:Ye.isAlphanumeric(c)?[Ye.makeAlphanumeric(c)]:[Ye.makeBytes(Ye.toUtf8ByteArray(c))]}static makeEci(c){let d=[];if(c<0)throw new RangeError("ECI assignment value out of range");if(c<128)n(c,8,d);else if(c<16384)n(2,2,d),n(c,14,d);else if(c<1e6)n(6,3,d),n(c,21,d);else throw new RangeError("ECI assignment value out of range");return new Ye(Ye.Mode.ECI,0,d)}static isNumeric(c){return Ye.NUMERIC_REGEX.test(c)}static isAlphanumeric(c){return Ye.ALPHANUMERIC_REGEX.test(c)}getData(){return this.bitData.slice()}static getTotalBits(c,d){let p=0;for(const f of c){const m=f.mode.numCharCountBits(d);if(f.numChars>=1<<m)return 1/0;p+=4+m+f.bitData.length}return p}static toUtf8ByteArray(c){c=encodeURI(c);let d=[];for(let p=0;p<c.length;p++)c.charAt(p)!="%"?d.push(c.charCodeAt(p)):(d.push(parseInt(c.substring(p+1,p+3),16)),p+=2);return d}};a.NUMERIC_REGEX=/^[0-9]*$/,a.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,a.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let i=a;e.QrSegment=a})(tr||(tr={}));(e=>{(t=>{const n=class{constructor(s,a){this.ordinal=s,this.formatBits=a}};n.LOW=new n(0,1),n.MEDIUM=new n(1,0),n.QUARTILE=new n(2,3),n.HIGH=new n(3,2),t.Ecc=n})(e.QrCode||(e.QrCode={}))})(tr||(tr={}));(e=>{(t=>{const n=class{constructor(s,a){this.modeBits=s,this.numBitsCharCount=a}numCharCountBits(s){return this.numBitsCharCount[Math.floor((s+7)/17)]}};n.NUMERIC=new n(1,[10,12,14]),n.ALPHANUMERIC=new n(2,[9,11,13]),n.BYTE=new n(4,[8,16,16]),n.KANJI=new n(8,[8,10,12]),n.ECI=new n(7,[0,0,0]),t.Mode=n})(e.QrSegment||(e.QrSegment={}))})(tr||(tr={}));var wr=tr;/**
581
+ * @license qrcode.react
582
+ * Copyright (c) Paul O'Shannessy
583
+ * SPDX-License-Identifier: ISC
584
+ */var PL={L:wr.QrCode.Ecc.LOW,M:wr.QrCode.Ecc.MEDIUM,Q:wr.QrCode.Ecc.QUARTILE,H:wr.QrCode.Ecc.HIGH},y0=128,v0="L",w0="#FFFFFF",N0="#000000",k0=!1,S0=1,_L=4,$L=0,DL=.1;function C0(e,t=0){const n=[];return e.forEach(function(o,s){let a=null;o.forEach(function(i,l){if(!i&&a!==null){n.push(`M${a+t} ${s+t}h${l-a}v1H${a+t}z`),a=null;return}if(l===o.length-1){if(!i)return;a===null?n.push(`M${l+t},${s+t} h1v1H${l+t}z`):n.push(`M${a+t},${s+t} h${l+1-a}v1H${a+t}z`);return}i&&a===null&&(a=l)})}),n.join("")}function M0(e,t){return e.slice().map((n,o)=>o<t.y||o>=t.y+t.h?n:n.map((s,a)=>a<t.x||a>=t.x+t.w?s:!1))}function LL(e,t,n,o){if(o==null)return null;const s=e.length+n*2,a=Math.floor(t*DL),i=s/t,l=(o.width||a)*i,c=(o.height||a)*i,d=o.x==null?e.length/2-l/2:o.x*i,p=o.y==null?e.length/2-c/2:o.y*i,f=o.opacity==null?1:o.opacity;let m=null;if(o.excavate){let g=Math.floor(d),x=Math.floor(p),b=Math.ceil(l+d-g),y=Math.ceil(c+p-x);m={x:g,y:x,w:b,h:y}}const h=o.crossOrigin;return{x:d,y:p,h:c,w:l,excavation:m,opacity:f,crossOrigin:h}}function TL(e,t){return t!=null?Math.max(Math.floor(t),0):e?_L:$L}function A0({value:e,level:t,minVersion:n,includeMargin:o,marginSize:s,imageSettings:a,size:i,boostLevel:l}){let c=Ze.useMemo(()=>{const g=(Array.isArray(e)?e:[e]).reduce((x,b)=>(x.push(...wr.QrSegment.makeSegments(b)),x),[]);return wr.QrCode.encodeSegments(g,PL[t],n,void 0,void 0,l)},[e,t,n,l]);const{cells:d,margin:p,numCells:f,calculatedImageSettings:m}=Ze.useMemo(()=>{let h=c.getModules();const g=TL(o,s),x=h.length+g*2,b=LL(h,i,g,a);return{cells:h,margin:g,numCells:x,calculatedImageSettings:b}},[c,i,a,o,s]);return{qrcode:c,margin:p,cells:d,numCells:f,calculatedImageSettings:m}}var RL=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),OL=Ze.forwardRef(function(t,n){const o=t,{value:s,size:a=y0,level:i=v0,bgColor:l=w0,fgColor:c=N0,includeMargin:d=k0,minVersion:p=S0,boostLevel:f,marginSize:m,imageSettings:h}=o,x=Gl(o,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:b}=x,y=Gl(x,["style"]),w=h?.src,v=Ze.useRef(null),N=Ze.useRef(null),k=Ze.useCallback(A=>{v.current=A,typeof n=="function"?n(A):n&&(n.current=A)},[n]),[C,D]=Ze.useState(!1),{margin:M,cells:_,numCells:$,calculatedImageSettings:E}=A0({value:s,level:i,minVersion:p,boostLevel:f,includeMargin:d,marginSize:m,imageSettings:h,size:a});Ze.useEffect(()=>{if(v.current!=null){const A=v.current,P=A.getContext("2d");if(!P)return;let L=_;const B=N.current,z=E!=null&&B!==null&&B.complete&&B.naturalHeight!==0&&B.naturalWidth!==0;z&&E.excavation!=null&&(L=M0(_,E.excavation));const T=window.devicePixelRatio||1;A.height=A.width=a*T;const F=a/$*T;P.scale(F,F),P.fillStyle=l,P.fillRect(0,0,$,$),P.fillStyle=c,RL?P.fill(new Path2D(C0(L,M))):_.forEach(function(H,j){H.forEach(function(Q,G){Q&&P.fillRect(G+M,j+M,1,1)})}),E&&(P.globalAlpha=E.opacity),z&&P.drawImage(B,E.x+M,E.y+M,E.w,E.h)}}),Ze.useEffect(()=>{D(!1)},[w]);const R=Ql({height:a,width:a},b);let O=null;return w!=null&&(O=Ze.createElement("img",{src:w,key:w,style:{display:"none"},onLoad:()=>{D(!0)},ref:N,crossOrigin:E?.crossOrigin})),Ze.createElement(Ze.Fragment,null,Ze.createElement("canvas",Ql({style:R,height:a,width:a,ref:k,role:"img"},y)),O)});OL.displayName="QRCodeCanvas";var E0=Ze.forwardRef(function(t,n){const o=t,{value:s,size:a=y0,level:i=v0,bgColor:l=w0,fgColor:c=N0,includeMargin:d=k0,minVersion:p=S0,boostLevel:f,title:m,marginSize:h,imageSettings:g}=o,x=Gl(o,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:b,cells:y,numCells:w,calculatedImageSettings:v}=A0({value:s,level:i,minVersion:p,boostLevel:f,includeMargin:d,marginSize:h,imageSettings:g,size:a});let N=y,k=null;g!=null&&v!=null&&(v.excavation!=null&&(N=M0(y,v.excavation)),k=Ze.createElement("image",{href:g.src,height:v.h,width:v.w,x:v.x+b,y:v.y+b,preserveAspectRatio:"none",opacity:v.opacity,crossOrigin:v.crossOrigin}));const C=C0(N,b);return Ze.createElement("svg",Ql({height:a,width:a,viewBox:`0 0 ${w} ${w}`,ref:n,role:"img"},x),!!m&&Ze.createElement("title",null,m),Ze.createElement("path",{fill:l,d:`M0,0 h${w}v${w}H0z`,shapeRendering:"crispEdges"}),Ze.createElement("path",{fill:c,d:C,shapeRendering:"crispEdges"}),k)});E0.displayName="QRCodeSVG";const BL=192;function I0({value:e,size:t=BL,className:n,alt:o}){const s=e.trim();return s.length===0?null:r("div",{className:Y("inline-flex rounded-md bg-white p-2",n),children:r(E0,{value:s,size:t,marginSize:1,title:o??"QR code"})})}const zL=2e3;function P0({value:e,label:t,className:n,disabled:o}){const[s,a]=I(!1),i=U(()=>{e&&navigator.clipboard.writeText(e).then(()=>{a(!0),setTimeout(()=>a(!1),zL)})},[e]);return u(Ue,{size:"sm",variant:"ghost",type:"button",disabled:o||e.length===0,onClick:i,className:Y(n),"aria-label":s?"Copied":`Copy ${t??"value"}`,children:[s?r(Wr,{className:"h-3.5 w-3.5 text-success"}):r(jn,{className:"h-3.5 w-3.5"}),t?r("span",{className:"ml-1",children:s?"Copied":t}):null]})}const FL=Tc(u2),jL=h2({id:zu(),stableId:Wn(),addonId:Wn(),type:Wn(),name:Wn(),online:Ai(),disabled:Ai(),parentDeviceId:zu().nullable(),role:Wn().nullable().optional(),features:Tc(Wn()).optional(),isCamera:Ai().optional()}),HL=Tc(Wn()),$p=1e4;function VL(e){return e==="linked"?"success":e==="error"?"danger":"warning"}function UL(e){return e==="linked"?"Linked":e==="unlinked"?"Unlinked":e==="error"?"Error":e}function qL({field:e}){const[t,n]=I(!1),o=e.secret===!0,a=o&&!t?"•".repeat(Math.min(e.value.length,24)):e.value;return u("div",{className:"flex items-center gap-2 py-1.5",children:[r("span",{className:"text-[11px] text-foreground-subtle w-32 shrink-0",children:e.label}),r("span",{className:"flex-1 min-w-0 truncate font-mono text-xs text-foreground",children:a||"—"}),o&&r(Ue,{size:"sm",variant:"ghost",type:"button","aria-label":t?"Hide value":"Reveal value",onClick:()=>n(i=>!i),children:t?r(jc,{className:"h-3.5 w-3.5"}):r(Yr,{className:"h-3.5 w-3.5"})}),r(P0,{value:e.value,label:e.label})]})}function QL({setup:e}){const t=e.fields??[];return u("div",{className:"border-b border-border bg-surface-hover/10",children:[u("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-border",children:[r(GS,{className:"h-3.5 w-3.5 text-foreground-subtle shrink-0"}),r("span",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide",children:"Setup"})]}),u("div",{className:"flex flex-col gap-3 p-4 sm:flex-row sm:items-start",children:[e.qr&&r("div",{className:"shrink-0",children:r(I0,{value:e.qr,alt:"Pairing QR code"})}),u("div",{className:"flex-1 min-w-0",children:[e.note&&r("p",{className:"text-xs text-foreground-muted whitespace-pre-line mb-2",children:e.note}),t.length>0&&r("div",{className:"divide-y divide-border-subtle",children:t.map(n=>r(qL,{field:n},n.label))})]})]})]})}function GL({addonId:e,deviceId:t,exposed:n,busy:o,onExpose:s,onUnexpose:a}){return r(Ue,{size:"sm",variant:n?"ghost":"primary",disabled:o,onClick:l=>{l.stopPropagation(),!o&&(n?a(t):s(t))},title:n?`Stop exposing to "${e}"`:`Expose to "${e}"`,children:n?u(me,{children:[r(LC,{className:"mr-1 h-3.5 w-3.5"}),"Exposed"]}):u(me,{children:[r(Tl,{className:"mr-1 h-3.5 w-3.5"}),"Expose"]})})}function Vd({addonId:e,trpc:t,onOpenDevice:n}){const o=Me(),s=wd({nodeId:"hub",addonId:e},{refetchInterval:$p,retry:!1}),a=Qb({nodeId:"hub",addonId:e},{refetchInterval:$p,retry:!1}),i=qb({nodeId:"hub",addonId:e},{retry:!1}),l=kn({},{refetchInterval:5e3}),c=U(()=>{o.invalidateQueries({queryKey:[["deviceExport"]]})},[o]),d=Gb({onSuccess:c}),p=Wb({onSuccess:c}),f=q(()=>{const $=ch.safeParse(s.data);return $.success?$.data:null},[s.data]),m=q(()=>{const $=FL.safeParse(a.data);return $.success?$.data:[]},[a.data]),h=q(()=>new Set(m.map($=>$.deviceId)),[m]),g=q(()=>{const $=HL.safeParse(i.data);return new Set($.success?$.data:[])},[i.data]),x=q(()=>[...g].sort(),[g]),b=q(()=>{const $=l.data;if(!Array.isArray($))return[];const E=[];for(const R of $){const O=jL.safeParse(R);O.success&&g.has(O.data.type)&&E.push(O.data)}return E},[l.data,g]),y=f?.linkState??"unlinked",w=s.isLoading||a.isLoading||i.isLoading||l.isLoading,v=f?.exposedDeviceCount??h.size,N=d.isPending||p.isPending,k=U($=>{d.mutate({deviceId:$,nodeId:"hub",addonId:e})},[d,e]),C=U($=>{p.mutate({deviceId:$,nodeId:"hub",addonId:e})},[p,e]),D=U($=>{const E=String($.id);return r(GL,{addonId:e,deviceId:E,exposed:h.has(E),busy:N,onExpose:k,onUnexpose:C})},[e,h,N,k,C]),M=U($=>n?.(String($)),[n]),_=x.length>0;return u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5 border-b border-border bg-surface-hover/20",children:[u("div",{className:"flex items-center gap-2 min-w-0",children:[r(Tl,{className:"h-3.5 w-3.5 text-foreground-subtle shrink-0"}),r("span",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide",children:"Exported devices"}),r(Kt,{variant:VL(y),children:UL(y)}),u("span",{className:"text-[11px] text-foreground-subtle",children:[v," exposed"]})]}),w&&r(yt,{className:"h-3.5 w-3.5 animate-spin text-foreground-subtle"})]}),f?.error&&r("div",{className:"px-4 py-3 border-b border-border",children:r(Zo,{message:f.error})}),f?.setup&&r(QL,{setup:f.setup}),r("div",{className:"p-3",children:_&&b.length>0?r(Dr,{devices:b,trpc:t,defaultView:"table",filters:{types:x},urlScope:"nested",lsKey:`device-export:${e}`,onNavigate:n?M:void 0,renderRowAction:D}):r(sd,{icon:Tl,title:"No exportable devices",description:_?`No devices of the supported kinds (${x.join(", ")}) are available to expose to "${e}".`:`"${e}" reports no exportable device kinds yet.`})})]})}function WL({samples:e,sampleRate:t=16e3,height:n=96,className:o="",color:s="#3b82f6",bgColor:a="transparent"}){const i=ne(null),l=ne(null),c=U(()=>{const f=i.current,m=l.current;if(!f||!m||!e||e.length===0)return;const h=m.clientWidth;if(h===0)return;const g=window.devicePixelRatio||1;f.width=h*g,f.height=n*g,f.style.width=`${h}px`,f.style.height=`${n}px`;const x=f.getContext("2d");if(!x)return;x.scale(g,g),a!=="transparent"?(x.fillStyle=a,x.fillRect(0,0,h,n)):x.clearRect(0,0,h,n);const b=e.length/h,y=n/2;x.fillStyle=s,x.globalAlpha=.7;for(let w=0;w<h;w++){const v=Math.floor(w*b),N=Math.min(Math.floor((w+1)*b),e.length);let k=0,C=0;for(let $=v;$<N;$++){const E=e[$];E<k&&(k=E),E>C&&(C=E)}const D=y-C*y,M=y-k*y,_=Math.max(1,M-D);x.fillRect(w,D,1,_)}x.globalAlpha=1,x.strokeStyle=s,x.globalAlpha=.2,x.lineWidth=1,x.beginPath(),x.moveTo(0,y),x.lineTo(h,y),x.stroke(),x.globalAlpha=1},[e,n,s,a]);J(()=>{c()},[c]),J(()=>{const f=new ResizeObserver(()=>c()),m=l.current;return m&&f.observe(m),()=>f.disconnect()},[c]);const p=((e&&t?Math.round(e.length/t*1e3):0)/1e3).toFixed(1);return u("div",{ref:l,className:`relative ${o}`,children:[r("canvas",{ref:i,className:"w-full rounded-md"}),e&&e.length>0&&u("div",{className:"absolute bottom-1 right-2 text-[10px] text-foreground-subtle/60 font-mono",children:[p,"s · ",t/1e3,"kHz · ",e.length.toLocaleString()," samples"]})]})}function KL({currentDbfs:e,durationSec:t=30,maxSamples:n=120,height:o=64,className:s="",color:a="#10b981",clipColor:i="#ef4444",clipThreshold:l=-6,minDbfs:c=-96}){const d=ne(null),p=ne(null),[f,m]=I([]);J(()=>{e!==null&&m(x=>{const b=[...x,{dbfs:e,timestamp:Date.now()}];return b.length>n?b.slice(-n):b})},[e,n]);const h=U(()=>{const x=d.current,b=p.current;if(!x||!b)return;const y=b.clientWidth;if(y===0)return;const w=window.devicePixelRatio||1;x.width=y*w,x.height=o*w,x.style.width=`${y}px`,x.style.height=`${o}px`;const v=x.getContext("2d");if(!v||(v.scale(w,w),v.clearRect(0,0,y,o),f.length===0))return;const N=f[f.length-1].timestamp,k=t*1e3,C=N-k,D=f.filter(E=>E.timestamp>=C);if(D.length===0)return;const M=Math.max(1,Math.floor(y/(t*2))),_=Math.abs(c);for(const E of D){const R=E.timestamp-C,O=Math.floor(R/k*y),P=(Math.max(c,Math.min(0,E.dbfs))-c)/_,L=Math.max(1,P*o),B=E.dbfs>=l;v.fillStyle=B?i:a,v.globalAlpha=.8,v.fillRect(O,o-L,M,L)}v.globalAlpha=1;const $=o-(l-c)/_*o;v.strokeStyle=i,v.globalAlpha=.25,v.lineWidth=1,v.setLineDash([4,4]),v.beginPath(),v.moveTo(0,$),v.lineTo(y,$),v.stroke(),v.setLineDash([]),v.globalAlpha=1},[f,t,o,a,i,l,c]);J(()=>{h()},[h]),J(()=>{const x=new ResizeObserver(()=>h()),b=p.current;return b&&x.observe(b),()=>x.disconnect()},[h]);const g=f.length>0?f[f.length-1].dbfs:null;return u("div",{ref:p,className:`relative ${s}`,children:[r("canvas",{ref:d,className:"w-full rounded-md"}),u("div",{className:"absolute top-1 left-2 text-[9px] text-foreground-subtle/50 font-mono",children:[t,"s"]}),g!==null&&u("div",{className:"absolute bottom-1 right-2 text-[9px] text-foreground-subtle/50 font-mono",children:[g.toFixed(1)," dBFS · ",f.length," samples"]})]})}function YL(e){return e>=.8?"bg-emerald-500":e>=.5?"bg-amber-500":e>=.3?"bg-orange-500":"bg-zinc-500"}function ZL(e){return e>=.8?"text-emerald-400":e>=.5?"text-amber-400":e>=.3?"text-orange-400":"text-zinc-400"}function XL({classifications:e,processing:t=!1,inferenceMs:n,maxItems:o=10,className:s=""}){const a=e.slice(0,o),i=a.length>0?a[0].score:1;return t?r("div",{className:`rounded-xl border border-border bg-surface p-4 text-center ${s}`,children:r("div",{className:"text-sm text-foreground-subtle animate-pulse",children:"Classifying audio..."})}):a.length===0?r("div",{className:`rounded-xl border border-border bg-surface p-4 text-center ${s}`,children:r("div",{className:"text-xs text-foreground-subtle",children:"No classifications yet"})}):u("div",{className:`rounded-xl border border-border bg-surface overflow-hidden ${s}`,children:[u("div",{className:"px-3 py-2 border-b border-border flex items-center justify-between",children:[r("h3",{className:"text-xs font-medium text-foreground",children:"Audio Classifications"}),u("div",{className:"flex items-center gap-3 text-[10px] text-foreground-subtle",children:[a.length<e.length&&u("span",{children:["showing ",a.length," of ",e.length]}),n!==void 0&&u("span",{className:"font-mono",children:[n.toFixed(1),"ms"]})]})]}),r("div",{className:"divide-y divide-border/50",children:a.map((l,c)=>{const d=i>0?l.score/i*100:0;return u("div",{className:"px-3 py-1.5 flex items-center gap-3 hover:bg-surface-hover/30",children:[r("span",{className:"text-[10px] text-foreground-subtle w-5 text-right font-mono",children:c+1}),r("span",{className:"text-xs font-medium text-foreground min-w-[120px]",children:l.className}),r("div",{className:"flex-1 h-2 rounded-full bg-zinc-800 overflow-hidden",children:r("div",{className:`h-full rounded-full transition-all duration-300 ${YL(l.score)}`,style:{width:`${d}%`}})}),u("span",{className:`text-xs font-mono font-semibold w-14 text-right ${ZL(l.score)}`,children:[(l.score*100).toFixed(1),"%"]})]},`${l.className}-${c}`)})})]})}function JL({data:e,label:t="Response",className:n=""}){const[o,s]=I(!1);if(!e)return null;const a=JSON.stringify(e,null,2);return u("div",{className:`rounded-xl border border-border bg-surface overflow-hidden ${n}`,children:[u("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:()=>s(i=>!i),children:[u("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-[10px] text-foreground-subtle",children:o?"▼":"▶"}),r("h3",{className:"text-xs font-medium text-foreground",children:t})]}),r("span",{className:"text-[10px] text-foreground-subtle font-mono",children:a.length>1e3?`${(a.length/1024).toFixed(1)} KB`:`${a.length} bytes`})]}),o&&r("div",{className:"max-h-80 overflow-y-auto overflow-x-auto",children:r("pre",{className:"p-3 text-[10px] leading-4 font-mono text-foreground-subtle whitespace-pre",children:a})})]})}const eT={Activity:Pn,Eye:Yr,AlertTriangle:Xr,PauseCircle:H5,PowerOff:qS};function Ud({phase:e,...t}){const n=Gr(e),o=eT[n.icon];return r(o,{...t})}function Mr(e){const[t,n]=I([]),o=U(a=>{n(i=>{const l=[...i,a];return l.length>e?l.slice(-e):l})},[e]),s=U(()=>{n([])},[]);return q(()=>({entries:t,append:o,reset:s}),[t,o,s])}function Dp(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)}}const Lp={error:{icon:Kr,color:"text-red-400"},warn:{icon:Xr,color:"text-amber-400"},info:{icon:wS,color:"text-blue-400"},debug:{icon:w5,color:"text-gray-500"}},Tp={debug:0,info:1,warn:2,error:3},tT=["all","debug","info","warn","error"],nT=500;function rT(e,t){return t?(Tp[e]??0)>=(Tp[t]??0):!0}function rn({agentId:e,addonId:t,deviceId:n,integrationId:o,requestId:s,level:a,maxHeight:i="max-h-96",showScope:l=!1,showFilters:c=!0,limit:d=100,liveBuffer:p,onClose:f,className:m}){const[h,g]=I(""),[x,b]=I(""),[y,w]=I(a),v=e,N=t??(h||void 0),k=n??(x?Number(x):void 0),C=o,D=s,M=q(()=>{const W={};return v&&(W.agentId=v),N&&(W.addonId=N),k!==void 0&&Number.isFinite(k)&&(W.deviceId=k),C&&(W.integrationId=C),D&&(W.requestId=D),Object.keys(W).length>0?W:void 0},[v,N,k,C,D]),_=Mr(nT),$=p??_,E=$.entries,[R,O]=I(0),[A,P]=I(!0),[L,B]=I(!1),[z,T]=I(!1),[F,H]=I(new Set),[j,Q]=I(""),G=ne(null),Z=`${v??""}:${N??""}:${String(k??"")}:${C??""}:${D??""}`,V=ne(Z);J(()=>{V.current!==Z&&(V.current=Z,$.reset(),O(0),H(new Set),B(!1))},[Z,$]);const{data:K,isLoading:X}=S.logs.query.useQuery({...M?{tags:M}:{},limit:d},{staleTime:3e4});S.logs.subscribe.useSubscription({...M?{tags:M}:{}},{onData:W=>{$.append(W)}});const te=q(()=>{const W=(K??[]).map(ye=>({timestamp:ye.timestamp,level:ye.level,message:ye.message,scope:ye.scope,tags:ye.tags,meta:ye.meta})),pe=new Map;for(const ye of W)pe.set(`${ye.timestamp}|${ye.level}|${ye.scope??""}|${ye.message}`,ye);for(const ye of E)pe.set(`${ye.timestamp}|${ye.level}|${ye.scope??""}|${ye.message}`,ye);const oe=[...pe.values()].sort((ye,ie)=>new Date(ye.timestamp).getTime()-new Date(ie.timestamp).getTime()),le=(R>0?oe.filter(ye=>new Date(ye.timestamp).getTime()>R):oe).filter(ye=>rT(ye.level,y)),ke=j.trim().toLowerCase();return ke?le.filter(ye=>{if(ye.message.toLowerCase().includes(ke)||ye.scope&&ye.scope.toLowerCase().includes(ke))return!0;if(ye.tags){for(const ie of Object.values(ye.tags))if(ie!==void 0&&String(ie).toLowerCase().includes(ke))return!0}if(ye.meta){for(const ie of Object.values(ye.meta))if(ie!=null&&Dp(ie).toLowerCase().includes(ke))return!0}return!1}):le},[K,E,y,R,j]),he=ne(te.length);J(()=>{const W=G.current,pe=te.length>he.current;he.current=te.length,!(!W||!pe||!A)&&W.scrollTo({top:W.scrollHeight})},[te.length,A]);const xe=U(()=>{const W=G.current;if(!W)return;const pe=W.scrollHeight-W.scrollTop-W.clientHeight<32;P(oe=>oe===pe?oe:pe)},[]),ee=q(()=>te.filter(W=>W.tags&&Object.keys(W.tags).length>0||W.meta&&Object.keys(W.meta).length>0).map(W=>`${W.timestamp}|${W.level}|${W.scope??""}|${W.message}`),[te]),re=U(()=>{B(W=>(W&&H(new Set),!W))},[]),de=U(()=>{const W=te.map(pe=>{const oe=new Date(pe.timestamp).toLocaleTimeString(),fe=pe.tags?" "+Object.entries(pe.tags).filter(([,le])=>le).map(([le,ke])=>`${le}=${ke}`).join(" "):"";return`${oe} [${pe.level.toUpperCase()}]${pe.scope?` [${pe.scope}]`:""}${fe} ${pe.message}`});navigator.clipboard.writeText(W.join(`
585
+ `)).then(()=>{T(!0),setTimeout(()=>T(!1),1500)})},[te]),ue=S.logs.clear.useMutation(),be=U(()=>{O(Date.now()),$.reset(),ue.mutate({...M?{tags:M}:{}})},[$,ue,M]),Se=U(W=>{H(pe=>{const oe=new Set(pe);return oe.has(W)?oe.delete(W):oe.add(W),oe})},[]),[Oe,Be]=I(null),He=U((W,pe)=>{const oe=new Date(W.timestamp).toISOString(),fe=W.tags?" "+Object.entries(W.tags).filter(([,ye])=>ye).map(([ye,ie])=>`${ye}=${ie}`).join(" "):"",le=W.meta&&Object.keys(W.meta).length>0?` meta=${JSON.stringify(W.meta)}`:"",ke=`${oe} [${W.level.toUpperCase()}]${W.scope?` [${W.scope}]`:""}${fe} ${W.message}${le}`;navigator.clipboard.writeText(ke).then(()=>{Be(pe),setTimeout(()=>Be(ye=>ye===pe?null:ye),1200)})},[]),se=U(W=>`${W.timestamp}|${W.level}|${W.scope??""}|${W.message}`,[]);return u("div",{className:Y("h-full min-h-0 flex flex-col",m),onClick:W=>W.stopPropagation(),children:[u("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[r("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle font-medium",children:"Logs"}),v&&r(Vi,{label:"agent",value:v}),N&&r(Vi,{label:"addon",value:N}),k!==void 0&&r(Vi,{label:"device",value:`#${k}`}),r("div",{className:"flex rounded border border-border overflow-hidden text-[9px]",children:tT.map(W=>u("button",{type:"button",onClick:()=>w(W==="all"?void 0:W),className:Y("px-1.5 py-0.5 capitalize transition-colors",W==="all"&&!y||y===W?"bg-primary/10 text-primary":"text-foreground-subtle hover:bg-surface-hover",W!=="all"&&"border-l border-border"),children:[W,W!=="all"?"+":""]},W))}),r(Ss,{icon:Jk,label:A?"Following":"Paused",active:A,onClick:()=>{P(W=>{const pe=!W;return pe&&G.current&&G.current.scrollTo({top:G.current.scrollHeight,behavior:"smooth"}),pe})}}),r(Ss,{icon:L?_5:D5,label:L?"Collapse":"Expand",active:L,onClick:re,disabled:ee.length===0}),r(Ss,{icon:jn,label:z?"Copied!":"Copy",onClick:de,disabled:te.length===0}),r(Ss,{icon:Jt,label:"Clear",onClick:be}),u("div",{className:"relative",children:[r("input",{type:"text",value:j,onChange:W=>Q(W.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"}),j&&r("button",{type:"button",onClick:()=>Q(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",title:"Clear search",children:r(rt,{className:"h-2.5 w-2.5"})})]}),E.length>0&&u("span",{className:"text-[9px] text-emerald-400 font-medium",children:["+",E.length," live"]})]}),f&&r("button",{type:"button",onClick:f,className:"text-foreground-subtle hover:text-foreground",children:r(rt,{className:"h-3.5 w-3.5"})})]}),c&&(!t||!n)&&u("div",{className:"flex items-center gap-2 px-3 py-1 border-b border-border/50 bg-surface/50 text-[10px]",children:[!t&&u("label",{className:"flex items-center gap-1",children:[r("span",{className:"text-foreground-subtle",children:"Addon:"}),r("input",{type:"text",value:h,onChange:W=>g(W.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"})]}),!n&&u("label",{className:"flex items-center gap-1",children:[r("span",{className:"text-foreground-subtle",children:"Device:"}),r("input",{type:"text",inputMode:"numeric",value:x,onChange:W=>b(W.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"})]})]}),u("div",{ref:G,onScroll:xe,className:Y("flex-1 min-h-0 overflow-auto font-mono text-[10px]",i),children:[X&&u("div",{className:"flex items-center justify-center gap-2 py-6 text-foreground-subtle",children:[r(yt,{className:"h-3.5 w-3.5 animate-spin"}),"Loading logs..."]}),!X&&te.length===0&&r("div",{className:"py-4 text-center text-foreground-subtle",children:"No logs found"}),te.length>0&&r("table",{className:"w-full",children:r("tbody",{children:te.map(W=>{const pe=Lp[W.level]??Lp.info,oe=pe.icon,fe=se(W),le=L||F.has(fe),ke=W.tags&&Object.keys(W.tags).length>0,ye=W.meta&&Object.keys(W.meta).length>0,ie=ke||ye;return u("tr",{className:Y("hover:bg-surface-hover/30 border-b border-border/30",ie&&"cursor-pointer"),onClick:ie?()=>Se(fe):void 0,children:[r("td",{className:"px-2 py-1 text-foreground-subtle whitespace-nowrap align-top w-[70px]",children:new Date(W.timestamp).toLocaleTimeString()}),r("td",{className:Y("px-1 py-1 align-top w-5",pe.color),children:r(oe,{className:"h-3 w-3"})}),l&&r("td",{className:"px-2 py-1 text-foreground-subtle align-top truncate max-w-[120px]",title:W.scope,children:W.scope?.replace(/^addon:/,"")??""}),r("td",{className:"px-2 py-1 text-foreground break-all",children:u("div",{className:"flex items-start gap-1",children:[ie&&(le?r(zn,{className:"h-3 w-3 text-foreground-subtle shrink-0 mt-0.5"}):r(Fn,{className:"h-3 w-3 text-foreground-subtle shrink-0 mt-0.5"})),u("div",{className:"flex-1 min-w-0",children:[W.message,le&&ie&&u("div",{className:"mt-0.5 pl-3 text-[9px] leading-snug",children:[ye&&Object.entries(W.meta).filter(([,ge])=>ge!==void 0&&ge!=="").map(([ge,Pe])=>u("div",{className:"break-all",children:[r("span",{className:"text-amber-400/80",children:ge}),r("span",{className:"text-foreground-subtle",children:"="}),r("span",{className:"text-foreground",children:Dp(Pe)})]},`m-${ge}`)),ke&&Object.entries(W.tags).filter(([,ge])=>ge!==void 0).map(([ge,Pe])=>u("div",{className:"break-all",children:[r("span",{className:"text-primary/70",children:ge}),r("span",{className:"text-foreground-subtle",children:"="}),r("span",{className:"text-foreground",children:Pe})]},`t-${ge}`))]})]})]})}),r("td",{className:"px-1 py-1 align-top w-5",children:r(oT,{copied:Oe===fe,onCopy:()=>He(W,fe)})})]},fe)})})})]})]})}function _0({position:e="bottom",className:t,...n}){return r("div",{className:Y(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:r(rn,{maxHeight:"max-h-48",...n})})}function Vi({label:e,value:t}){return u("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium",children:[e,": ",t]})}function oT({copied:e,onCopy:t}){return r("button",{type:"button",title:"Copy this row",onClick:n=>{n.stopPropagation(),t()},className:Y("rounded p-0.5 transition-colors",e?"text-emerald-400":"text-foreground-subtle/60 hover:text-foreground hover:bg-surface-hover"),children:e?r(Wr,{className:"h-3 w-3"}):r(jn,{className:"h-3 w-3"})})}function Ss({icon:e,label:t,onClick:n,disabled:o,active:s}){return u("button",{type:"button",onClick:n,disabled:o,className:Y("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",s?"border-amber-500/30 bg-amber-500/10 text-amber-400":"border-border text-foreground-subtle hover:text-foreground",o&&"opacity-40 cursor-not-allowed"),children:[r(e,{className:"h-2.5 w-2.5"}),t]})}function sT(e,t,n,o){if(o!==void 0&&(e.source.deviceId??(e.source.type==="device"&&typeof e.source.id=="number"?e.source.id:void 0))!==o||n!==void 0&&(e.source.addonId??(e.source.type==="addon"&&typeof e.source.id=="string"?e.source.id:void 0))!==n)return!1;if(t!==void 0){const s=e.source.nodeId;if(!s||s!==t&&!s.startsWith(`${t}/`))return!1}return!0}const aT={[Ce.AddonStarted]:{icon:Ll,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Started"},[Ce.AddonInstalled]:{icon:$l,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Installed"},[Ce.AddonRestarted]:{icon:za,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Restarted"},[Ce.AddonUpdated]:{icon:eg,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Updated"},[Ce.AddonStopped]:{icon:Rl,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"Stopped"},[Ce.AddonUninstalled]:{icon:Jt,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"Uninstalled"},[Ce.AddonCrashed]:{icon:Kr,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Crashed"},[Ce.AddonError]:{icon:Xr,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Error"},[Ce.DetectionPhaseTransition]:{icon:Pn,color:"bg-violet-500/15 text-violet-400 border-violet-500/30",label:"Phase"},[Ce.DetectionResult]:{icon:rC,color:"bg-purple-500/15 text-purple-400 border-purple-500/30",label:"Detection"},[Ce.DetectionEvent]:{icon:Yr,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Event"},[Ce.DetectionCameraNative]:{icon:ep,color:"bg-cyan-500/15 text-cyan-400 border-cyan-500/30",label:"Camera AI"},[Ce.ProviderMotion]:{icon:tp,color:"bg-orange-500/15 text-orange-400 border-orange-500/30",label:"Motion"},[Ce.MotionOnMotionChanged]:{icon:tp,color:"bg-orange-500/15 text-orange-400 border-orange-500/30",label:"Motion"},[Ce.MotionAnalysis]:{icon:Pn,color:"bg-orange-500/10 text-orange-300 border-orange-500/20",label:"Motion analysis"},[Ce.MotionZonesRaw]:{icon:Pn,color:"bg-orange-500/10 text-orange-300 border-orange-500/20",label:"Motion zones"},[Ce.ProviderDetection]:{icon:ep,color:"bg-cyan-500/15 text-cyan-400 border-cyan-500/30",label:"Provider Det"},[Ce.PipelineAudioInferenceResult]:{icon:Wh,color:"bg-pink-500/15 text-pink-400 border-pink-500/30",label:"Audio"},[Ce.AgentOnline]:{icon:Ll,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Agent Online"},[Ce.AgentOffline]:{icon:Rl,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Agent Offline"},[Ce.DeviceRegistered]:{icon:$l,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Registered"},[Ce.DeviceUnregistered]:{icon:Jt,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Unregistered"},[Ce.DeviceStateChanged]:{icon:Pn,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"State"}};function Wl(e,t){const n=aT[e]??{icon:Ll,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:e.split(".").pop()??e};if(e===Ce.DeviceStateChanged&&t&&typeof t.capName=="string"){const o=t.capName;return{...n,label:o}}return n}const yr=Object.freeze([...new Set(Object.values(Ce))].sort()),iT=Object.freeze([Ce.PipelineCameraMetricsSnapshot,Ce.PipelineRunnerLoadSnapshot,Ce.PipelineEngineMetricsSnapshot,Ce.PipelineInferenceResult,Ce.PipelineTrace,Ce.PipelineProgress,Ce.StreamBrokerMetricsSnapshot,Ce.MetricsNodeResourcesSnapshot,Ce.MetricsNodeProcessesSnapshot,Ce.ClusterTopologySnapshot,Ce.MotionAnalysis,Ce.MotionZonesRaw,Ce.DetectionResult,Ce.PipelineAudioInferenceResult,Ce.PlatformProbePhase,Ce.BenchmarkProgress,Ce.ModelDownloadProgress]),lT=new Set(iT),cT=Object.freeze(yr.filter(e=>!lT.has(e)));function Ks(e,t){if(e===Ce.DetectionPhaseTransition){const s=t.to,a=t.from,i=typeof t.source=="string"?t.source:null,l=typeof t.cooldownMs=="number"?t.cooldownMs:null,c=i?` (${i}${l?`, ${Math.round(l/1e3)}s cooldown`:""})`:"";return s==="active"?`Motion detected — phase active${c}`:s==="watching"?`Cooldown expired — phase watching${c}`:`Phase: ${String(a)} → ${String(s)}${c}`}if(e===Ce.DetectionResult){const a=t.frame?.detections??[];if(a.length===0)return null;const i=new Map;for(const l of a){const c=l,d=c.class??c.macroClass,p=typeof d=="string"?d:"";p&&i.set(p,(i.get(p)??0)+1)}return[...i.entries()].map(([l,c])=>c>1?`${l} ×${c}`:l).join(", ")}if(e===Ce.PipelineAudioInferenceResult){const a=t.frame?.detections??[];return a.length===0?null:a.map(i=>{const l=i,c=l.macroClass??l.class??l.label,d=typeof c=="string"?c:"",p=l.score;return p?`${d} (${Math.round(p*100)}%)`:d}).filter(Boolean).join(", ")}if(e===Ce.DetectionEvent){const s=t.label??t.class,a=t.score??t.confidence,i=[];return typeof s=="string"&&i.push(s),typeof a=="number"&&i.push(`${Math.round(a*100)}%`),i.length>0?i.join(" — "):null}if(e===Ce.ProviderMotion)return t.active===!0?"motion start":"motion stop";if(e===Ce.DeviceStateChanged){const s=t.slice;if(s&&typeof s=="object"){const a=Object.keys(s).filter(i=>i!=="lastFetchedAt"&&i!=="ts");if(a.length>0)return a.slice(0,4).join(", ")+(a.length>4?"…":"")}return null}if(e===Ce.MotionOnMotionChanged){const s=t.detected,a=typeof t.source=="string"?t.source:null,i=s===!0?"motion start":s===!1?"motion stop":"motion";return a?`${i} (${a})`:i}if(e===Ce.ProviderDetection||e===Ce.DetectionCameraNative){const s=t.detections??[];if(!Array.isArray(s)||s.length===0)return(typeof t.class=="string"?t.class:null)??null;const a=new Map;for(const i of s){const l=i,c=l.class??l.macroClass,d=typeof c=="string"?c:"";d&&a.set(d,(a.get(d)??0)+1)}return[...a.entries()].map(([i,l])=>l>1?`${i} ×${l}`:i).join(", ")}const n=t.addonId,o=t.error;return o||(n?`addon: ${n}`:null)}function dT(e){const t=e.category;return t===Ce.DetectionResult||t===Ce.PipelineAudioInferenceResult?Ks(t,e.data)!==null:!0}const uT=300;function hr({agentId:e,addonId:t,deviceId:n,defaultCategories:o,categories:s,category:a,maxHeight:i="max-h-96",limit:l=50,showCategoryFilter:c=!0,showFilters:d=!1,liveBuffer:p,onClose:f,className:m}){const h=q(()=>o??s??cT,[o,s]),g=q(()=>[...h].sort().join(","),[h]),[x,b]=I(()=>new Set(h)),y=ne(g);J(()=>{y.current!==g&&(y.current=g,b(new Set(h)))},[g,h]);const w=Mr(uT),v=p??w,N=v.entries,[k,C]=I(!0),[D,M]=I(new Set),[_,$]=I(""),[E,R]=I(!1),[O,A]=I(""),[P,L]=I(0),B=ne(null),z=ne(null),T=`${e??""}:${t??""}:${String(n??"")}:${a??""}`,F=ne(T);J(()=>{F.current!==T&&(F.current=T,v.reset(),M(new Set),L(0))},[T,v]),J(()=>{if(!E)return;const ie=ge=>{const Pe=z.current;Pe&&ge.target instanceof Node&&!Pe.contains(ge.target)&&R(!1)};return document.addEventListener("mousedown",ie),()=>{document.removeEventListener("mousedown",ie)}},[E]);const H=q(()=>{const ie={};return e&&(ie.agentId=e),t&&(ie.addonId=t),n!==void 0&&(ie.deviceId=n),a&&(ie.category=a),ie},[e,t,n,a]),j=q(()=>[...x].sort(),[x]),Q=q(()=>j.join(","),[j]),G=q(()=>{const ie={...H,limit:l};return j.length>0&&j.length<yr.length&&(ie.category=j),ie},[H,l,Q,j]),{data:Z,isLoading:V}=S.systemEvents.getRecent.useQuery(G,{staleTime:3e4}),K=ne(x);J(()=>{K.current=x},[x]);const X=H;S.systemEvents.subscribe.useSubscription(X,{onData:ie=>{const ge=ie;ge?.id&&sT(ge,e,t,n)&&K.current.has(ge.category)&&v.append(ge)}});const te=ne(N.length);J(()=>{const ie=B.current;if(!ie){te.current=N.length;return}const ge=te.current;if(te.current=N.length,!(N.length<=ge)){if(k&&ie.scrollTop<=8)ie.scrollTo({top:0});else if(!k&&ie.scrollTop>0){const Pe=ie.firstElementChild?.firstElementChild,ze=Pe instanceof HTMLElement?Pe.offsetHeight:28;ie.scrollTop+=ze*(N.length-ge)}}},[N.length,k]);const he=q(()=>{const ie=new Map;for(const ze of Z??[])ie.set(ze.id,ze);for(const ze of N)ie.set(ze.id,ze);let ge=[...ie.values()].filter(ze=>x.has(ze.category)).filter(dT);P>0&&(ge=ge.filter(ze=>new Date(ze.timestamp).getTime()>P));const Pe=_.trim().toLowerCase();return Pe&&(ge=ge.filter(ze=>{if(ze.category.toLowerCase().includes(Pe)||Wl(ze.category,ze.data).label.toLowerCase().includes(Pe))return!0;const lt=Ks(ze.category,ze.data);if(lt&&lt.toLowerCase().includes(Pe))return!0;try{if(new Date(ze.timestamp).toLocaleTimeString().toLowerCase().includes(Pe))return!0}catch{}try{if(JSON.stringify(ze.data).toLowerCase().includes(Pe)||JSON.stringify(ze.source).toLowerCase().includes(Pe))return!0}catch{}return!1})),ge.sort((ze,Fe)=>new Date(Fe.timestamp).getTime()-new Date(ze.timestamp).getTime())},[Z,N,x,_,P]),xe=U(ie=>{M(ge=>{const Pe=new Set(ge);return Pe.has(ie)?Pe.delete(ie):Pe.add(ie),Pe})},[]),ee=U(ie=>{b(ge=>{const Pe=new Set(ge);return Pe.has(ie)?Pe.delete(ie):Pe.add(ie),Pe})},[]),re=U(()=>{b(new Set(h)),$(""),L(0)},[h]),de=U(()=>{L(Date.now()),v.reset()},[v]),[ue,be]=I(!1),[Se,Oe]=I(null),Be=U(ie=>{const ge=new Date(ie.timestamp).toISOString(),Pe=Ks(ie.category,ie.data)??"",ze=Pe?` ${Pe}`:"";return`${ge} [${ie.category}]${ze} data=${JSON.stringify(ie.data)}`},[]),He=U(()=>{const ie=he.map(Be);navigator.clipboard.writeText(ie.join(`
586
+ `)).then(()=>{be(!0),setTimeout(()=>be(!1),1500)})},[he,Be]),se=U(ie=>{navigator.clipboard.writeText(Be(ie)).then(()=>{Oe(ie.id),setTimeout(()=>Oe(ge=>ge===ie.id?null:ge),1200)})},[Be]),W=U(()=>{b(new Set(yr))},[]),pe=U(()=>{b(new Set)},[]),oe=q(()=>{const ie=O.trim().toLowerCase();return ie?yr.filter(ge=>ge.toLowerCase().includes(ie)):yr},[O]),fe=yr.length,le=x.size,ke=le===fe,ye=ke?"All":`${le}/${fe}`;return u("div",{className:Y("h-full min-h-0 flex flex-col",m),onClick:ie=>ie.stopPropagation(),children:[u("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[r("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle font-medium",children:"Events"}),e&&r(Cs,{label:"agent",value:e}),t&&r(Cs,{label:"addon",value:t}),n!==void 0&&r(Cs,{label:"device",value:`#${n}`}),a&&r(Cs,{label:"category",value:a}),u("button",{type:"button",onClick:()=>{C(ie=>!ie),!k&&B.current&&B.current.scrollTo({top:0,behavior:"smooth"})},className:Y("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",k?"border-border text-foreground-subtle hover:text-foreground":"border-amber-500/30 bg-amber-500/10 text-amber-400"),children:[r(i5,{className:"h-2.5 w-2.5"}),k?"Auto":"Paused"]}),c&&u("div",{className:"relative",ref:z,children:[u("button",{type:"button",onClick:()=>R(ie=>!ie),className:Y("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",ke?"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:[r(qh,{className:"h-2.5 w-2.5"}),"Filter (",ye,")"]}),E&&r(pT,{search:O,onSearchChange:A,categories:oe,active:x,onToggle:ee,onSelectAll:W,onSelectNone:pe,onResetDefaults:re})]}),u("button",{type:"button",onClick:re,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:[r(Zh,{className:"h-2.5 w-2.5"}),"Reset"]}),u("button",{type:"button",onClick:de,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:[r(Jt,{className:"h-2.5 w-2.5"}),"Clear"]}),u("button",{type:"button",onClick:He,disabled:he.length===0,className:Y("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",ue?"border-emerald-500/30 bg-emerald-500/10 text-emerald-400":"border-border text-foreground-subtle hover:text-foreground",he.length===0&&"opacity-40 cursor-not-allowed"),title:"Copy all visible events",children:[r(jn,{className:"h-2.5 w-2.5"}),ue?"Copied!":"Copy"]}),u("div",{className:"relative",children:[r("input",{type:"text",value:_,onChange:ie=>$(ie.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"}),_&&r("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:r(rt,{className:"h-2.5 w-2.5"})})]}),N.length>0&&u("span",{className:"text-[9px] text-emerald-400 font-medium",children:["+",N.length," live"]})]}),f&&r("button",{type:"button",onClick:f,className:"text-foreground-subtle hover:text-foreground",children:r(rt,{className:"h-3.5 w-3.5"})})]}),u("div",{ref:B,className:Y("flex-1 min-h-0 overflow-auto text-[10px]",i),children:[V&&u("div",{className:"flex items-center justify-center gap-2 py-6 text-foreground-subtle",children:[r(yt,{className:"h-3.5 w-3.5 animate-spin"}),"Loading events..."]}),!V&&he.length===0&&r("div",{className:"py-4 text-center text-foreground-subtle",children:"No events found"}),he.length>0&&r("div",{className:"divide-y divide-border/30",children:he.map(ie=>{const ge=Wl(ie.category,ie.data),Pe=ge.icon,ze=Ks(ie.category,ie.data),Fe=D.has(ie.id);return u("div",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-surface-hover/30 cursor-pointer",onClick:()=>xe(ie.id),children:[r("span",{className:"text-foreground-subtle whitespace-nowrap w-[70px] shrink-0 pt-0.5",children:new Date(ie.timestamp).toLocaleTimeString()}),r(mT,{copied:Se===ie.id,onCopy:()=>se(ie)}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-1.5",children:[Fe?r(zn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}):r(Fn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),u("span",{className:Y("inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[9px] font-medium",ge.color),children:[r(Pe,{className:"h-2.5 w-2.5"}),ge.label]}),ie.source.nodeId&&ie.source.nodeId!=="hub"&&r("span",{className:"text-[9px] px-1 py-0.5 rounded bg-foreground-subtle/10 text-foreground-subtle font-mono",children:ie.source.nodeId})]}),ze&&r("p",{className:"text-foreground-subtle text-[10px] mt-0.5 ml-5",children:ze}),Fe&&u("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:[u("div",{children:[r("span",{className:"text-primary/70",children:"source"}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground",children:JSON.stringify(ie.source)})]}),u("div",{children:[r("span",{className:"text-primary/70",children:"category"}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground",children:ie.category})]}),Object.entries(ie.data).map(([lt,$t])=>u("div",{children:[r("span",{className:"text-primary/70",children:lt}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground break-all",children:typeof $t=="object"?JSON.stringify($t):String($t)})]},lt))]})]})]},ie.id)})})]})]})}function pT({search:e,onSearchChange:t,categories:n,active:o,onToggle:s,onSelectAll:a,onSelectNone:i,onResetDefaults:l}){return u("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:c=>c.stopPropagation(),children:[u("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border/50",children:[r(Lo,{className:"h-3 w-3 text-foreground-subtle"}),r("input",{type:"text",value:e,onChange:c=>t(c.target.value),placeholder:"Filter categories…",className:"flex-1 bg-transparent text-[10px] focus:outline-none text-foreground placeholder:text-foreground-subtle",autoFocus:!0}),e&&r("button",{type:"button",onClick:()=>t(""),className:"text-foreground-subtle hover:text-foreground",children:r(rt,{className:"h-2.5 w-2.5"})})]}),u("div",{className:"flex items-center gap-1 px-2 py-1 border-b border-border/50 text-[9px]",children:[r("button",{type:"button",onClick:a,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"All"}),r("button",{type:"button",onClick:i,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"None"}),r("button",{type:"button",onClick:l,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"Defaults"})]}),u("div",{className:"overflow-y-auto flex-1",children:[n.length===0&&r("div",{className:"text-[10px] text-foreground-subtle italic px-2 py-3 text-center",children:"No matches"}),n.map(c=>{const d=o.has(c),p=Wl(c),f=p.icon;return u("button",{type:"button",onClick:()=>s(c),className:"w-full flex items-center gap-2 px-2 py-1 text-left hover:bg-surface-hover/40 text-[10px]",children:[r("input",{type:"checkbox",readOnly:!0,checked:d,className:"accent-violet-500"}),u("span",{className:Y("inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[9px] font-medium shrink-0",p.color),children:[r(f,{className:"h-2.5 w-2.5"}),p.label]}),r("span",{className:"text-foreground-subtle font-mono truncate",children:c})]},c)})]})]})}function fT({position:e="bottom",className:t,...n}){return r("div",{className:Y(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:r(hr,{maxHeight:"max-h-48",...n})})}function Cs({label:e,value:t}){return u("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium",children:[e,": ",t]})}function mT({copied:e,onCopy:t}){return r("button",{type:"button",title:"Copy this event",onClick:n=>{n.stopPropagation(),t()},className:Y("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?r(Wr,{className:"h-3 w-3"}):r(jn,{className:"h-3 w-3"})})}function $0({deviceId:e,className:t="",onOpenChild:n}){const o=S.useUtils(),s=S.deviceDiscovery.listDiscovered.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),a=S.deviceDiscovery.getStatus.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),i=S.deviceDiscovery.refreshDiscovery.useMutation({onSuccess:()=>{o.deviceDiscovery.listDiscovered.invalidate({deviceId:e}),o.deviceDiscovery.getStatus.invalidate({deviceId:e})}}),l=S.deviceDiscovery.adoptDevice.useMutation({onSuccess:()=>{o.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),c=S.deviceDiscovery.releaseDevice.useMutation({onSuccess:()=>{o.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),[d,p]=I(null),{available:f,adopted:m}=q(()=>{const v=s.data??[],N=C=>typeof C.metadata.rtspChannel=="number"?C.metadata.rtspChannel:Number.POSITIVE_INFINITY,k=(C,D)=>{const M=N(C),_=N(D);return M!==_?M-_:C.name.localeCompare(D.name)};return{available:v.filter(C=>!C.alreadyAdopted).sort(k),adopted:v.filter(C=>C.alreadyAdopted).sort(k)}},[s.data]),h=a.data,g=h?.lastError??null,x=h?.lastDiscoveryAt??null;async function b(){await i.mutateAsync({deviceId:e}).catch(()=>{})}async function y(v){p(v.childNativeId);try{await l.mutateAsync({deviceId:e,childNativeId:v.childNativeId})}finally{p(null)}}async function w(v){if(v.adoptedDeviceId!=null){p(v.childNativeId);try{await c.mutateAsync({deviceId:e,childDeviceId:v.adoptedDeviceId})}finally{p(null)}}}return u("div",{className:`rounded-xl border border-border bg-surface ${t}`,children:[u("div",{className:"flex items-start justify-between gap-2 border-b border-border px-3 py-2 sm:px-5 sm:py-3",children:[u("div",{className:"min-w-0",children:[r("h3",{className:"text-sm font-semibold text-foreground",children:"Discovered devices"}),u("p",{className:"text-[11px] text-foreground-subtle",children:["Channels behind this hub. Click ",r("span",{className:"font-medium",children:"Add"})," to promote a channel to a managed device, or ",r("span",{className:"font-medium",children:"Remove"})," to detach."]})]}),u("button",{type:"button",onClick:b,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?r(yt,{className:"h-3.5 w-3.5 animate-spin"}):r(za,{className:"h-3.5 w-3.5"}),r("span",{className:"hidden sm:inline",children:"Refresh"})]})]}),g?u("div",{className:"flex items-start gap-2 border-b border-border bg-destructive/10 px-5 py-2 text-[11px] text-destructive",children:[r(Xr,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),u("span",{children:["Last refresh failed: ",g]})]}):null,s.isLoading?r("div",{className:"flex items-center justify-center py-8 text-foreground-subtle",children:r(yt,{className:"h-5 w-5 animate-spin"})}):f.length===0&&m.length===0?r("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."}):u(me,{children:[f.length>0?r(Rp,{title:"Available to add",count:f.length,tone:"primary",children:f.map(v=>r(Op,{child:v,busy:d===v.childNativeId,onAdopt:y,onRelease:w,onOpenChild:n},v.childNativeId))}):null,m.length>0?r(Rp,{title:"Already adopted",count:m.length,tone:"muted",children:m.map(v=>r(Op,{child:v,busy:d===v.childNativeId,onAdopt:y,onRelease:w,onOpenChild:n},v.childNativeId))}):null]}),x!=null?u("div",{className:"border-t border-border px-5 py-2 text-[10px] text-foreground-subtle",children:["Last refreshed ",new Date(x).toLocaleString()]}):null]})}function Rp({title:e,count:t,tone:n,children:o}){return u("div",{className:"border-t border-border",children:[u("div",{className:`flex items-center justify-between border-b px-3 sm:px-5 py-1.5 text-[10px] uppercase tracking-wider ${n==="primary"?"bg-primary/5 text-primary border-primary/30":"bg-surface text-foreground-subtle border-border"}`,children:[r("span",{className:"font-semibold",children:e}),r("span",{className:"font-mono",children:t})]}),r("div",{className:"divide-y divide-border",children:o})]})}function Op({child:e,busy:t,onAdopt:n,onRelease:o,onOpenChild:s}){return u("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:[u("div",{className:"min-w-0 flex-1",children:[u("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[r(hT,{status:e.status}),r("span",{className:"truncate text-sm font-medium text-foreground",children:e.name}),e.metadata.isDoorbell?r("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?r("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?r("span",{className:"rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle",children:"Multifocal"}):null]}),u("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"?u("span",{children:["ch ",r("span",{className:"font-mono",children:e.metadata.rtspChannel})]}):null,e.metadata.model?r("span",{className:"truncate max-w-[160px]",children:e.metadata.model}):null,e.metadata.uid?u("span",{className:"font-mono truncate max-w-[140px]",children:[e.metadata.uid.slice(0,12),"…"]}):null]})]}),e.alreadyAdopted?u("div",{className:"flex items-center gap-2",children:[s&&e.adoptedDeviceId!==null?u("button",{type:"button",onClick:()=>s(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:[r(Uh,{className:"h-3.5 w-3.5"}),"Open"]}):null,u("button",{type:"button",onClick:()=>{o(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?r(yt,{className:"h-3.5 w-3.5 animate-spin"}):r(Jt,{className:"h-3.5 w-3.5"}),"Remove"]})]}):u("button",{type:"button",onClick:()=>{n(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?r(yt,{className:"h-3.5 w-3.5 animate-spin"}):r(Zr,{className:"h-3.5 w-3.5"}),"Add"]})]})}function hT({status:e}){switch(e){case"online":return u("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:[r(tg,{className:"h-2.5 w-2.5"})," online"]});case"sleeping":return u("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:[r(Hc,{className:"h-2.5 w-2.5"})," sleeping"]});case"offline":return u("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:[r(OC,{className:"h-2.5 w-2.5"})," offline"]});case"unknown":default:return u("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:[r(jh,{className:"h-2.5 w-2.5"})," unknown"]})}}function gT(e,t){if(!e||typeof e!="object")return null;const n=e;if(n.category!==Ce.DeviceStateChanged)return null;const o=n.data;return!o||typeof o!="object"||o.deviceId!==t||typeof o.capName!="string"||!o.slice||typeof o.slice!="object"?null:{capName:o.capName,slice:o.slice}}function bT(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}const xT=Object.freeze([...new Set(g2.filter(e=>e.scope==="device").map(e=>e.name))].sort()),yT=1;function qd({deviceId:e,defaultCaps:t,maxHeight:n="max-h-96",onClose:o,className:s}){const a=q(()=>new Set(t??[]),[t]),[i,l]=I(a),[c,d]=I(""),[p,f]=I(!1),[m,h]=I(""),g=ne(null),[x,b]=I(new Map),[y,w]=I(new Map),[,v]=I(0),N=ne(e);J(()=>{N.current!==e&&(N.current=e,b(new Map),w(new Map))},[e]);const{data:k,isLoading:C}=S.deviceState.getAllSnapshots.useQuery({},{staleTime:3e4}),D=ne(!1);J(()=>{if(D.current||!bT(k))return;const Z=k[String(e)];if(D.current=!0,!Z)return;const V=Date.now();b(K=>{const X=new Map(K);for(const[te,he]of Object.entries(Z))X.has(te)||X.set(te,{slice:he,updatedAt:V});return X})},[k,e]),J(()=>{D.current=!1},[e]),S.systemEvents.subscribe.useSubscription({deviceId:e,category:Ce.DeviceStateChanged},{onData:Z=>{const V=gT(Z,e);V&&b(K=>{const X=new Map(K);return X.set(V.capName,{slice:V.slice,updatedAt:Date.now()}),X})}}),J(()=>{const Z=setInterval(()=>v(V=>V+1),5e3);return()=>clearInterval(Z)},[]);const M=q(()=>{const Z=new Set(xT);for(const V of x.keys())Z.add(V);return[...Z].sort()},[x]),_=q(()=>{const Z=c.trim().toLowerCase();return[...x.keys()].sort().filter(K=>i.size>0&&!i.has(K)?!1:!Z||K.toLowerCase().includes(Z)?!0:Yl(x.get(K)?.slice??{},Z))},[x,i,c]),$=U(Z=>{l(V=>{const K=new Set(V);return K.has(Z)?K.delete(Z):K.add(Z),K})},[]),E=U(()=>{l(new Set(t??[])),d("")},[t]),R=U(()=>{l(new Set(M))},[M]),O=U(()=>{l(new Set)},[]),A=U((Z,V)=>{w(K=>{const X=new Map(K);return X.set(Z,!V),X})},[]),P=U((Z,V)=>{const K=y.get(Z);return K!==void 0?K:V<yT},[y]),[L,B]=I(!1),z=U(()=>{const Z={};for(const V of _){const K=x.get(V);K&&(Z[V]=K.slice)}navigator.clipboard.writeText(JSON.stringify(Z,null,2)).then(()=>{B(!0),setTimeout(()=>B(!1),1500)})},[_,x]),T=q(()=>{const Z=m.trim().toLowerCase();return Z?M.filter(V=>V.toLowerCase().includes(Z)):M},[m,M]),F=M.length,H=i.size,j=H===0||H===F,Q=j?"All":`${H}/${F}`;J(()=>{if(!p)return;const Z=V=>{const K=g.current;K&&!K.contains(V.target)&&f(!1)};return document.addEventListener("mousedown",Z),()=>document.removeEventListener("mousedown",Z)},[p]);const G=c.trim().toLowerCase();return u("div",{className:Y("h-full min-h-0 flex flex-col",s),onClick:Z=>Z.stopPropagation(),children:[u("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[r("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle font-medium",children:"State"}),r(ST,{label:"device",value:`#${e}`}),u("div",{className:"relative",ref:g,children:[u("button",{type:"button",onClick:()=>f(Z=>!Z),className:Y("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",j?"border-border text-foreground-subtle hover:text-foreground":"border-violet-500/30 bg-violet-500/10 text-violet-400"),title:"Pick caps to show",children:[r(qh,{className:"h-2.5 w-2.5"}),"Filter (",Q,")"]}),p&&r(CT,{search:m,onSearchChange:h,caps:T,active:i,onToggle:$,onSelectAll:R,onSelectNone:O,onResetDefaults:E})]}),u("button",{type:"button",onClick:E,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",children:[r(Zh,{className:"h-2.5 w-2.5"}),"Reset"]}),u("button",{type:"button",onClick:z,disabled:_.length===0,className:Y("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",L?"border-emerald-500/30 bg-emerald-500/10 text-emerald-400":"border-border text-foreground-subtle hover:text-foreground",_.length===0&&"opacity-40 cursor-not-allowed"),title:"Copy visible state as JSON",children:[r(jn,{className:"h-2.5 w-2.5"}),L?"Copied!":"Copy"]}),u("div",{className:"relative",children:[r("input",{type:"text",value:c,onChange:Z=>d(Z.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"}),c&&r("button",{type:"button",onClick:()=>d(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",title:"Clear search",children:r(rt,{className:"h-2.5 w-2.5"})})]}),u("span",{className:"text-[9px] text-emerald-400 font-medium inline-flex items-center gap-1",children:[r("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-400 animate-pulse"}),"live"]})]}),o&&r("button",{type:"button",onClick:o,className:"text-foreground-subtle hover:text-foreground",children:r(rt,{className:"h-3.5 w-3.5"})})]}),u("div",{className:Y("flex-1 min-h-0 overflow-auto text-[10px] font-mono",n),children:[C&&x.size===0&&u("div",{className:"flex items-center justify-center gap-2 py-6 text-foreground-subtle font-sans",children:[r(yt,{className:"h-3.5 w-3.5 animate-spin"}),"Loading device state..."]}),!C&&x.size===0&&r("div",{className:"py-4 text-center text-foreground-subtle font-sans",children:"No runtime state"}),!C&&x.size>0&&_.length===0&&r("div",{className:"py-4 text-center text-foreground-subtle font-sans",children:"No caps match the filter"}),_.length>0&&r("div",{className:"py-1",children:_.map(Z=>{const V=x.get(Z);return V?r(vT,{capName:Z,slice:V.slice,updatedAt:V.updatedAt,searchNeedle:G,isPathOpen:P,onToggle:A},Z):null})})]})]})}function vT({capName:e,slice:t,updatedAt:n,searchNeedle:o,isPathOpen:s,onToggle:a}){const i=e,l=s(i,0),c=Object.entries(t);return u("div",{children:[u("div",{className:"flex items-center gap-1.5 px-3 py-1 hover:bg-surface-hover/30 cursor-pointer select-none",onClick:()=>a(i,l),children:[r(T0,{open:l,hasChildren:c.length>0}),r("span",{className:"inline-flex items-center gap-1 rounded-full border border-violet-500/30 bg-violet-500/15 text-violet-400 px-2 py-0.5 text-[9px] font-medium font-sans",children:e}),u("span",{className:"text-[9px] text-foreground-subtle font-sans",children:[c.length," ",c.length===1?"key":"keys"]}),u("span",{className:"ml-auto text-[9px] text-foreground-subtle/70 font-sans tabular-nums",children:["updated ",kT(n)]})]}),l&&r("div",{children:c.length===0?r(L0,{depth:1,label:"empty slice"}):c.map(([d,p])=>r(D0,{path:`${i}.${d}`,nodeKey:d,value:p,depth:1,searchNeedle:o,isPathOpen:s,onToggle:a},d))})]})}function D0({path:e,nodeKey:t,value:n,depth:o,searchNeedle:s,isPathOpen:a,onToggle:i}){const l=wT(n),c={paddingLeft:`${12+o*14}px`};if(!l)return u("div",{className:"flex items-start gap-1 px-3 py-0.5",style:c,children:[r("span",{className:Y("shrink-0",Ui(t,s,"text-primary/70")),children:t}),r("span",{className:"text-foreground-subtle",children:":"}),r("span",{className:Y("break-all",Ui(Kl(n),s,NT(n))),children:Kl(n)})]});const d=a(e,o);return u("div",{children:[u("div",{className:"flex items-center gap-1 px-3 py-0.5 hover:bg-surface-hover/30 cursor-pointer select-none",style:c,onClick:()=>i(e,d),children:[r(T0,{open:d,hasChildren:l.entries.length>0}),r("span",{className:Ui(t,s,"text-primary/70"),children:t}),r("span",{className:"text-foreground-subtle/70 text-[9px]",children:l.summary})]}),d&&(l.entries.length===0?r(L0,{depth:o+1,label:l.kind==="array"?"empty array":"empty object"}):l.entries.map(([p,f])=>r(D0,{path:`${e}.${p}`,nodeKey:p,value:f,depth:o+1,searchNeedle:s,isPathOpen:a,onToggle:i},p)))]})}function L0({depth:e,label:t}){return r("div",{className:"px-3 py-0.5 text-foreground-subtle/60 italic",style:{paddingLeft:`${12+e*14}px`},children:t})}function T0({open:e,hasChildren:t}){return t?e?r(zn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}):r(Fn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}):r("span",{className:"inline-block w-3 shrink-0"})}function wT(e){if(Array.isArray(e))return{kind:"array",entries:e.map((t,n)=>[String(n),t]),summary:`[${e.length}]`};if(e&&typeof e=="object"){const t=Object.entries(e);return{kind:"object",entries:t,summary:`{${t.length}}`}}return null}function Kl(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)}}function NT(e){return e==null?"text-foreground-subtle/60":typeof e=="number"?"text-amber-400":typeof e=="boolean"?e?"text-emerald-400":"text-rose-400":"text-foreground"}function Ui(e,t,n){return t&&e.toLowerCase().includes(t)?Y(n,"bg-violet-500/20 rounded px-0.5"):n}function Yl(e,t){if(Array.isArray(e))return e.some(n=>Yl(n,t));if(e&&typeof e=="object"){for(const[n,o]of Object.entries(e))if(n.toLowerCase().includes(t)||Yl(o,t))return!0;return!1}return Kl(e).toLowerCase().includes(t)}function kT(e){const t=Date.now()-e;if(t<5e3)return"just now";const n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const o=Math.floor(n/60);return o<60?`${o}m ago`:`${Math.floor(o/60)}h ago`}function ST({label:e,value:t}){return u("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium font-sans",children:[e,": ",t]})}function CT({search:e,onSearchChange:t,caps:n,active:o,onToggle:s,onSelectAll:a,onSelectNone:i,onResetDefaults:l}){return u("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 font-sans",onClick:c=>c.stopPropagation(),children:[u("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border/50",children:[r(Lo,{className:"h-3 w-3 text-foreground-subtle"}),r("input",{type:"text",value:e,onChange:c=>t(c.target.value),placeholder:"Filter caps…",className:"flex-1 bg-transparent text-[10px] focus:outline-none text-foreground placeholder:text-foreground-subtle",autoFocus:!0}),e&&r("button",{type:"button",onClick:()=>t(""),className:"text-foreground-subtle hover:text-foreground",children:r(rt,{className:"h-2.5 w-2.5"})})]}),u("div",{className:"flex items-center gap-1 px-2 py-1 border-b border-border/50 text-[9px]",children:[r("button",{type:"button",onClick:a,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"All"}),r("button",{type:"button",onClick:i,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"None"}),r("button",{type:"button",onClick:l,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"Defaults"})]}),u("div",{className:"overflow-y-auto flex-1",children:[n.length===0&&r("div",{className:"text-[10px] text-foreground-subtle italic px-2 py-3 text-center",children:"No matches"}),n.map(c=>{const d=o.has(c);return u("button",{type:"button",onClick:()=>s(c),className:"w-full flex items-center gap-2 px-2 py-1 text-left hover:bg-surface-hover/40 text-[10px]",children:[r("input",{type:"checkbox",readOnly:!0,checked:d,className:"accent-violet-500"}),r("span",{className:"inline-flex items-center gap-1 rounded-full border border-violet-500/30 bg-violet-500/15 text-violet-400 px-1.5 py-0.5 text-[9px] font-medium shrink-0",children:c})]},c)})]})]})}const qi=500,MT=[{id:"logs",label:"Logs",icon:sC},{id:"events",label:"Events",icon:Ba},{id:"state",label:"State",icon:tS}];function AT({deviceId:e,defaultEventCategories:t,defaultStateCaps:n,initialTab:o="events",className:s,maxHeight:a="max-h-96"}){const[i,l]=I(o),c=Mr(qi),d=Mr(qi),p=Mr(qi),f=c.reset,m=d.reset,h=p.reset;return J(()=>{f(),m(),h()},[e,f,m,h]),u("div",{className:Y("flex flex-col h-full min-h-0",s),children:[r("div",{className:"flex items-center gap-1 mb-2 shrink-0",children:MT.map(({id:g,label:x,icon:b})=>u("button",{type:"button",onClick:()=>l(g),className:Y("inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[11px] font-medium transition-colors",i===g?"bg-primary/15 text-primary border border-primary/30":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover border border-transparent"),children:[r(b,{className:"h-3.5 w-3.5"}),x]},g))}),u("div",{className:"flex-1 min-h-0 overflow-hidden",children:[i==="logs"&&r(rn,{deviceId:e,maxHeight:a,showFilters:!1,liveBuffer:c}),i==="events"&&r(hr,{deviceId:e,defaultCategories:t,maxHeight:a,showCategoryFilter:!0,liveBuffer:d}),i==="state"&&r(qd,{deviceId:e,defaultCaps:n,maxHeight:a,liveBuffer:p})]})]})}function Qd({label:e,icon:t,title:n="Confirm action",description:o,confirmLabel:s,triggerVariant:a="outline",confirmVariant:i="danger",size:l="sm",disabled:c,className:d,action:p,onSuccess:f}){const[m,h]=I(!1),[g,x]=I(!1),[b,y]=I(null),w=async()=>{y(null),x(!0);try{const v=await p();f?.(v),h(!1)}catch(v){y(v instanceof Error?v.message:String(v))}finally{x(!1)}};return u(me,{children:[u(Ue,{type:"button",variant:a,size:l,disabled:c,onClick:()=>{y(null),h(!0)},className:d,children:[t&&r(t,{className:"h-3.5 w-3.5"}),e]}),r(ig,{open:m,onOpenChange:v=>!g&&h(v),children:u(Wc,{children:[u(lg,{children:[u(dg,{className:"flex items-center gap-2",children:[r(Xr,{className:"h-4 w-4 text-amber-400"}),n]}),typeof o=="string"?r(ug,{children:o}):o]}),b&&r("div",{className:Y("mt-2 px-3 py-2 rounded border border-danger/40 bg-danger/10","text-xs text-danger"),children:b}),u(cg,{children:[r(Ue,{type:"button",variant:"ghost",size:l,disabled:g,onClick:()=>h(!1),children:"Cancel"}),u(Ue,{type:"button",variant:i,size:l,disabled:g,onClick:()=>{w()},children:[g&&r(yt,{className:"h-3.5 w-3.5 animate-spin"}),s??e]})]})]})})]})}function ET(e,t){const n=document.createElement("a");n.href=t,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n)}function IT({trpc:e,deviceId:t,deviceName:n,size:o="sm",className:s}){const[a,i]=I(!1),[l,c]=I(!1),[d,p]=I(null),f=n.replace(/[^a-zA-Z0-9_.-]+/g,"_"),m=U(async k=>{i(!0),p(null),c(!1);try{const C=await e.snapshot.getSnapshot.query({deviceId:t,force:!0});if(!C)throw new Error("No snapshot available");const D=`data:${C.contentType};base64,${C.base64}`;if(k==="copy")try{await navigator.clipboard.writeText(D)}catch{throw new Error("Clipboard unavailable")}else{const M=C.contentType.includes("png")?"png":"jpg",_=new Date().toISOString().replace(/[:.]/g,"-");ET(`${f}-${_}.${M}`,D)}c(!0),setTimeout(()=>c(!1),1500)}catch(C){p(C instanceof Error?C.message:String(C))}finally{i(!1)}},[e,t,f]),h=o==="md"?"h-9 px-3 text-sm gap-2":"h-7 px-2.5 text-[11px] gap-1.5",[g,x]=I(null),[b,y]=I(!1),w=()=>{y(!1);const k=setTimeout(()=>{y(!0),m("copy")},600);x(k)},v=()=>{g&&(clearTimeout(g),x(null)),b||m("download")},N=()=>{g&&(clearTimeout(g),x(null))};return u("button",{type:"button",title:"Click to download · long-press to copy",disabled:a,onPointerDown:w,onPointerUp:v,onPointerLeave:N,onPointerCancel:N,className:Y("inline-flex items-center justify-center rounded-lg font-medium border border-border","text-foreground-subtle hover:text-foreground hover:bg-surface-hover","disabled:opacity-50 transition-colors",h,d&&"border-danger/40 text-danger",s),children:[a?r(yt,{className:"h-3.5 w-3.5 animate-spin"}):l?r(Wr,{className:"h-3.5 w-3.5 text-success"}):r(zc,{className:"h-3.5 w-3.5"}),"Snapshot"]})}function PT(e){const t=Date.now()-e;return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:`${Math.floor(t/864e5)}d ago`}function R0({history:e,limit:t=5,latestIsFresh:n,className:o}){if(e.length===0)return null;const s=n?x5:Ba,a=e.slice(0,t);return u("div",{className:Y("rounded-lg border border-border bg-surface px-3 py-2",o),children:[u("div",{className:"flex items-center gap-2 mb-2",children:[r(s,{className:Y("h-4 w-4 text-amber-400",n&&"animate-pulse")}),r("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle",children:"Recent presses"}),r("span",{className:"ml-auto rounded-full bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle border border-border",children:e.length})]}),r("ul",{className:"space-y-1",children:a.map(i=>u("li",{className:"flex items-center justify-between text-[11px]",title:new Date(i.timestamp).toLocaleString(),children:[r("span",{className:"text-foreground",children:PT(i.timestamp)}),r("span",{className:"text-foreground-subtle font-mono text-[10px]",children:new Date(i.timestamp).toLocaleTimeString()})]},`${i.deviceId}-${i.timestamp}`))})]})}function O0({items:e,header:t,triggerClassName:n,title:o="More actions"}){const[s,a]=I(!1),i=e.filter(l=>!l.hidden);return i.length===0?null:u(Cg,{open:s,onOpenChange:a,children:[r(Mg,{title:o,className:Y("inline-flex items-center justify-center rounded-lg p-2","text-foreground-subtle hover:text-foreground hover:bg-surface-hover","border border-transparent transition-colors",n),children:r(Vh,{className:"h-4 w-4"})}),u(Ag,{className:"left-auto right-0 mt-1 min-w-[200px] p-1",children:[t&&r("div",{className:"px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle",children:t}),r("ul",{className:"space-y-0.5",children:i.map((l,c)=>u("li",{children:[l.separatorBefore&&c>0&&r("div",{className:"my-1 h-px bg-border"}),u("button",{type:"button",disabled:l.disabled,onClick:()=>{l.disabled||(l.onClick(),a(!1))},className:Y("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-[12px]","transition-colors disabled:opacity-40 disabled:cursor-not-allowed",l.danger?"text-foreground hover:bg-danger/10 hover:text-danger":"text-foreground hover:bg-surface-hover"),children:[l.icon&&r(l.icon,{className:Y("h-3.5 w-3.5 shrink-0 mt-0.5",l.danger&&"text-danger/80")}),u("span",{className:"flex-1 min-w-0",children:[r("span",{className:"block leading-tight",children:l.label}),l.description&&r("span",{className:"block mt-0.5 text-[10px] text-foreground-subtle leading-tight",children:l.description})]})]})]},l.id))})]})]})}const _T=[{value:"view",label:"View",icon:Yr,hint:"Read-only — queries + subscriptions"},{value:"create",label:"Create",icon:zS,hint:"Mutations that create or update"},{value:"delete",label:"Delete",icon:Jt,hint:"Destructive ops (delete/revoke/reset/…)"}],$T=["device","system"];function DT(){return{type:"capability",target:"",access:["view"]}}function LT(e){if(e==null)return[];const t=new Set;for(const n of e)if(n.type==="device")for(const o of n.targets)t.add(o);return[...t]}function TT(e,t,n,o){let s;switch(e){case"addon":s=n;break;case"capability":s=o;break;case"category":s=$T.map(i=>({value:i,label:i}));break}if(t==null)return s;const a=new Set(t.filter(i=>i.type!=="device"&&i.type===e).map(i=>i.target));return s.filter(i=>a.has(i.value))}function RT(e,t){if(t==null)return["view","create","delete"];const n=t.filter(s=>s.type!==e.type?!1:s.type==="device"&&e.type==="device"?s.targets.some(a=>e.targets.includes(a)):s.type!=="device"&&e.type!=="device"?s.target===e.target:!1);if(n.length===0)return[];const o=new Set;for(const s of n)for(const a of s.access)o.add(a);return[...o]}function Gd({value:e,onChange:t,clampToParent:n,emptyHint:o}){const{data:s}=Nn(),{data:a}=kn({}),i=q(()=>(s??[]).map(g=>({value:g.manifest.id,label:g.manifest.id})).sort((g,x)=>g.label.localeCompare(x.label)),[s]),l=q(()=>[...b2].sort().map(g=>({value:g,label:g})),[]),c=q(()=>(a??[]).map(g=>({value:String(g.id),label:`${g.name} (#${g.id} · ${g.addonId})`})).sort((g,x)=>g.label.localeCompare(x.label)),[a]),d=q(()=>n==null?null:LT(n),[n]),p=(g,x)=>{const b=[...x];switch(g){case"category":return{type:"category",target:"device",access:b};case"capability":return{type:"capability",target:"",access:b};case"addon":return{type:"addon",target:"",access:b};case"device":return{type:"device",targets:[],access:b}}},f=(g,x)=>{t(e.map((b,y)=>{if(y!==g)return b;if(x.type!==void 0&&x.type!==b.type)return p(x.type,x.access??b.access);const w=[...x.access??b.access];return b.type==="device"?{type:"device",targets:[...x.targets??b.targets],access:w}:b.type==="category"?{type:"category",target:x.target??b.target,access:w}:b.type==="capability"?{type:"capability",target:x.target??b.target,access:w}:{type:"addon",target:x.target??b.target,access:w}}))},m=g=>{t(e.filter((x,b)=>b!==g))},h=()=>{t([...e,DT()])};return u("div",{className:"space-y-2",children:[e.length===0&&o&&r("div",{className:"text-[10px] text-foreground-subtle italic px-2 py-2",children:o}),e.map((g,x)=>{const b=RT(g,n);return u("div",{className:"flex flex-wrap items-start gap-1.5 rounded border border-border bg-surface px-2 py-1.5",children:[u("select",{value:g.type,onChange:y=>f(x,{type:y.target.value}),className:"rounded border border-border bg-background px-2 py-1 text-[11px] focus:outline-none focus:ring-1 focus:ring-primary",children:[r("option",{value:"category",children:"category"}),r("option",{value:"capability",children:"capability"}),r("option",{value:"addon",children:"addon"}),r("option",{value:"device",children:"device"})]}),g.type==="device"?r(OT,{value:g.targets,choices:c,clampToParent:d,onChange:y=>f(x,{targets:y})}):u("select",{value:g.target,onChange:y=>f(x,{target:y.target.value}),className:"flex-1 min-w-[160px] rounded border border-border bg-background px-2 py-1 text-[11px] font-mono focus:outline-none focus:ring-1 focus:ring-primary",children:[u("option",{value:"",children:["— pick ",g.type," —"]}),TT(g.type,n,i,l).map(y=>r("option",{value:y.value,children:y.label},y.value))]}),r("div",{className:"flex items-center gap-1",children:_T.map(({value:y,label:w,icon:v,hint:N})=>{const k=g.access.includes(y),C=n!=null&&!b.includes(y)&&!k;return u("label",{title:C?`${N} — not granted by your scope`:N,className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] cursor-pointer transition-colors ${k?"bg-primary/15 text-primary font-medium":"text-foreground-subtle hover:bg-foreground-subtle/10"} ${C?"opacity-40 cursor-not-allowed":""}`,children:[r("input",{type:"checkbox",checked:k,disabled:C,onChange:D=>{const M=new Set(g.access);D.target.checked?M.add(y):M.delete(y),f(x,{access:[...M]})},className:"sr-only"}),r(v,{className:"h-3 w-3"}),w]},y)})}),r("button",{type:"button",onClick:()=>m(x),className:"rounded p-1 text-foreground-subtle hover:bg-danger/10 hover:text-danger transition-colors",title:"Remove scope",children:r(rt,{className:"h-3 w-3"})})]},x)}),u("button",{type:"button",onClick:h,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-foreground-subtle/10 transition-colors",children:[r(Zr,{className:"h-3 w-3"}),"Add scope"]})]})}function OT({value:e,choices:t,clampToParent:n,onChange:o}){const[s,a]=I(""),i=q(()=>{const p=n==null?t:t.filter(m=>n.includes(m.value)),f=new Set(e);return p.filter(m=>!f.has(m.value))},[t,n,e]),l=p=>t.find(f=>f.value===p)?.label??`#${p}`,c=p=>{p&&(o([...e,p]),a(""))},d=p=>{o(e.filter(f=>f!==p))};return u("div",{className:"flex-1 min-w-[160px] flex flex-wrap items-center gap-1",children:[e.length===0&&r("span",{className:"text-[10px] text-foreground-subtle italic px-1",children:"no devices selected"}),e.map(p=>u("span",{className:"inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-mono text-primary",children:[l(p),r("button",{type:"button",onClick:()=>d(p),className:"hover:text-danger transition-colors",title:"Remove device",children:r(rt,{className:"h-2.5 w-2.5"})})]},p)),i.length>0&&u("select",{value:s,onChange:p=>c(p.target.value),className:"rounded border border-border bg-background px-1.5 py-0.5 text-[10px] focus:outline-none focus:ring-1 focus:ring-primary",children:[r("option",{value:"",children:"+ add device…"}),i.map(p=>r("option",{value:p.value,children:p.label},p.value))]})]})}function Wd(e){for(const t of e){if(t.type==="device"){if(t.targets.length===0)return"Scope device: pick at least one device"}else if(t.target.trim().length===0)return`Scope ${t.type}: pick a target`;if(t.access.length===0){const n=t.type==="device"?`[${t.targets.join(",")}]`:t.target;return`Scope ${t.type}:${n}: pick at least one access`}}return null}const B0=wn("camstack:zone-editing",null);function z0({children:e}){const[t,n]=I(!1),[o,s]=I(null),[a,i]=I(null),[l,c]=I(null),d=U(w=>{n(w),w||(s(null),i(null),c(null))},[]),p=U(w=>{s(w)},[]),f=U(w=>{i(w)},[]),m=U(w=>{n(!0),i(null),s(w),c(null)},[]),h=U(()=>{n(!1),s(null),i(null),c(null)},[]),g=U(w=>{i(w.id),c(w)},[]),x=U(w=>{c(v=>v===null?v:{...v,...w})},[]),b=U(()=>{c(null)},[]),y=q(()=>({editing:t,drawingKind:o,selectedZoneId:a,editingDraft:l,setEditing:d,setDrawingKind:p,setSelectedZoneId:f,startDrawing:m,exitEditing:h,enterDraft:g,updateDraft:x,discardDraft:b}),[t,o,a,l,d,p,f,m,h,g,x,b]);return r(B0.Provider,{value:y,children:e})}function BT(){return Ne(B0)}const Bp=500,zT=800;function Ms(e,t,n){try{const o=e.live;if(!o)return null;const s=o.onEvent;return!s||typeof s.subscribe!="function"?null:s.subscribe({category:t},{onData:n})}catch{return null}}function As(e,t){return e?.id===t}function F0(e,t){const[n,o]=I(null),[s,a]=I(null),[i,l]=I(null),[c,d]=I("watching"),p=ne(void 0),f=ne(void 0),m=ne(void 0);return J(()=>{if(t===null)return;const h=Ms(e,"detection.motion-analysis",g=>{const x=g;if(!As(x?.source,t))return;const b=x.data;!b?.regions||b.regions.length===0||(o({zones:b.regions.map(y=>({...y.bbox,intensity:y.intensity})),frameWidth:b.frameWidth,frameHeight:b.frameHeight}),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>o(null),Bp))});return()=>{h?.unsubscribe(),p.current&&clearTimeout(p.current)}},[e,t]),J(()=>{if(t===null)return;const h=Ms(e,"detection.motion-zones-raw",g=>{const x=g;if(!As(x?.source,t))return;const b=x.data;b?.zones&&(a({boxes:b.zones.map(y=>({bbox:y.bbox,changeScore:y.changeScore})),frameWidth:b.frameSize?.width??0,frameHeight:b.frameSize?.height??0,motionScore:b.zones.length>0?b.zones.reduce((y,w)=>y+w.changeScore,0)/b.zones.length:0}),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>a(null),Bp))});return()=>{h?.unsubscribe(),f.current&&clearTimeout(f.current)}},[e,t]),J(()=>{if(t===null)return;const h=Ms(e,"detection.result",g=>{const x=g;if(!As(x?.source,t))return;const b=x.data?.frame;b?.detections?.length&&(l({detections:b.detections,frameWidth:b.width,frameHeight:b.height}),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>l(null),zT))});return()=>{h?.unsubscribe(),m.current&&clearTimeout(m.current)}},[e,t]),J(()=>{if(t===null)return;const h=Ms(e,"detection.phase-transition",g=>{const x=g;As(x?.source,t)&&x.data?.to&&d(x.data.to)});return()=>{h?.unsubscribe()}},[e,t]),{motion:n,motionRaw:s,detection:i,phase:c}}function j0(e,t,n=5e3){const[o,s]=I([]);J(()=>{if(t===null)return;let b=!1;const y=()=>{e.webrtcSession.listStreams.query({deviceId:t}).then(v=>{b||s(v)}).catch(()=>{})};y();const w=setInterval(y,n);return()=>{b=!0,clearInterval(w)}},[e,t,n]);const[a,i]=I(null);J(()=>{if(t===null)return;let b=!1;return e.pipelineOrchestrator&&e.pipelineOrchestrator.getCameraMetrics.query({deviceId:t}).then(y=>{b||!y||i({phase:y.phase,detectionFps:y.actualFps,avgInferenceMs:y.avgInferenceTimeMs,droppedFrames:y.droppedFrames})}).catch(()=>{}),()=>{b=!0}},[e,t]),ft("pipeline.camera-metrics-snapshot",b=>{if(t===null)return;const y=b.data;y.deviceId!==t||!y.metrics||i({phase:y.metrics.phase,detectionFps:y.metrics.actualFps,avgInferenceMs:y.metrics.avgInferenceTimeMs,droppedFrames:y.metrics.droppedFrames})});const{streams:l,hasWebrtc:c}=q(()=>t===null||o.length===0?{streams:[],hasWebrtc:!1}:{streams:o.map(y=>({id:y.id,label:y.label,target:y.target,status:y.status,inputFps:y.inputFps,decodeFps:y.decodeFps,bitrateKbps:y.bitrateKbps})),hasWebrtc:!0},[t,o]),d=U(async()=>{if(e.turnProvider)try{return(await e.turnProvider.getTurnServers.query()).map(y=>({urls:typeof y.urls=="string"?y.urls:[...y.urls],...y.username!==void 0?{username:y.username}:{},...y.credential!==void 0?{credential:y.credential}:{}}))}catch{return}},[e]),p=U(async(b,y)=>{if(t===null)throw new Error("No device selected");const w=await e.webrtcSession.createSession.mutate({deviceId:t,target:b,hints:y}),v=await d();return{sessionId:w.sessionId,sdpOffer:w.sdpOffer,...v?{iceServers:v}:{}}},[e,t,d]),f=U(async(b,y)=>{if(t===null)throw new Error("No device selected");return e.webrtcSession.handleOffer.mutate({deviceId:t,target:b,sdpOffer:y})},[e,t]),m=U(async(b,y)=>{if(t===null)throw new Error("No device selected");await e.webrtcSession.handleAnswer.mutate({deviceId:t,sessionId:b,sdpAnswer:y})},[e,t]),h=U(async(b,y)=>{t!==null&&await e.webrtcSession.addIceCandidate.mutate({deviceId:t,sessionId:b,candidate:y.candidate??"",sdpMid:y.sdpMid??null,sdpMLineIndex:y.sdpMLineIndex??null}).catch(()=>{})},[e,t]),g=U(async b=>t===null?{candidates:[],done:!0}:e.webrtcSession.getIceCandidates.query({deviceId:t,sessionId:b}),[e,t]),x=U(async b=>{t!==null&&await e.webrtcSession.closeSession.mutate({deviceId:t,sessionId:b}).catch(()=>{})},[e,t]);return{streams:l,hasWebrtc:c,pipelineMetrics:a,createSession:p,handleOffer:f,getIceServers:d,addIceCandidate:h,getIceCandidates:g,sendAnswer:m,closeSession:x}}function H0(e){const t=e?.deviceId??null,n=e?.historyLimit??20,o=Jr("doorbell.onPressed",t!==null?i=>i.deviceId===t:void 0),[s,a]=I([]);return J(()=>{o&&a(i=>{if(i.length>0&&i[0].deviceId===o.deviceId&&i[0].timestamp===o.timestamp)return i;const l=[o,...i];return l.length>n?l.slice(0,n):l})},[o,n]),{latest:o??null,history:s}}function FT(e){const t=De(),n=q(()=>e?JSON.stringify(e):"",[e]),[o,s]=I(()=>t.listDevices(e));return J(()=>{const a=()=>{s(t.listDevices(e))};a();let i=null,l=null;try{i=t.onDeviceAdded(a),l=t.onDeviceRemoved(a)}catch{}const c=t.subscribeConnectionEvents(d=>{d==="connected"&&a()});return()=>{i?.(),l?.(),c()}},[t,e,n]),o}function jT(e){const t=De(),[n,o]=I(()=>e===null?null:t.getDevice(e));return J(()=>{if(e===null){o(null);return}const s=()=>{o(t.getDevice(e))};s();let a=null,i=null;try{a=t.onDeviceAdded(s),i=t.onDeviceRemoved(s)}catch{}const l=t.subscribeConnectionEvents(c=>{c==="connected"&&s()});return()=>{a?.(),i?.(),l()}},[t,e]),n}function HT(e,t,n){const o=De();return cr({queryKey:e,queryFn:()=>t(o)(),...n})}function VT(e,t){const n=De();return Rt({mutationFn:o=>e(n)(o),...t})}function UT(e,t){const n=De(),o=Me(),[s,a]=I(n.connectionVersion);J(()=>n.subscribeConnectionEvents((c,d)=>{c==="connected"&&a(d)}),[n]);const i=t.join("|"),l=JSON.stringify(e);J(()=>{const c=[],d=()=>{const p=JSON.parse(l),m=p.length===1&&Array.isArray(p[0])?p:[p];o.invalidateQueries({queryKey:m})};d();for(const p of i.split("|"))if(p)try{c.push(n.subscribeEvent(p,d))}catch{}return()=>{for(const p of c)p()}},[n,o,i,l,s])}const qT=Object.freeze(Object.defineProperty({__proto__:null,AddonGlobalSettingsForm:dL,AgentStepEditor:Va,AppShell:R3,AudioClassificationList:XL,AudioLevelWaveform:KL,AudioWaveform:WL,AutotrackSection:e0,BTN_COMPACT:_k,BTN_COMPACT_DANGER:Dk,BTN_COMPACT_PRIMARY:$k,BTN_COMPACT_WARNING:Lk,Badge:Kt,BatteryBadge:dd,BottomSheet:Yc,Breadcrumb:Jc,Button:Ue,CHIP_ACTIVE:Ok,CHIP_BASE:Rk,CHIP_INACTIVE:Bk,CLASS_COLORS:yo,CameraStreamPlayer:m0,Card:mn,Checkbox:og,CodeBlock:L3,CollapsibleCard:ng,ConfigFormBuilder:p0,ConfigFormField:mr,ConfigSchemaField:Ha,ConfirmActionButton:Qd,ConfirmDialogProvider:Og,CopyButton:P0,CustomFieldRenderersProvider:ob,DEFAULT_COLOR:Jg,DataTable:Fa,DetectionCanvas:HM,DetectionOverlay:f0,DetectionResultTree:QM,DevShell:nb,DeviceActivityPanel:AT,DeviceCard:B3,DeviceContextProvider:ab,DeviceExportPanel:Vd,DeviceGrid:z3,DeviceItem:Ro,DeviceList:Dr,Dialog:ig,DialogContent:Wc,DialogDescription:ug,DialogFooter:cg,DialogHeader:lg,DialogTitle:dg,DialogTrigger:JC,DiscoveryPanel:$0,DoorbellRecentPanel:R0,Dropdown:fg,DropdownContent:hg,DropdownItem:gg,DropdownTrigger:mg,EmptyState:sd,ErrorBox:Zo,EventStream:hr,FilterBar:T3,FloatingEventStream:fT,FloatingLogStream:_0,FloatingPanel:l3,FormField:I3,GRID_GAP:Nk,GRID_PAIRED:Sk,GRID_QUICK_STATS:kk,HOST_WIDGETS:l0,INPUT_COMPACT:Tk,IconButton:Uc,ImageSelector:ZM,InferenceConfigSelector:XM,Input:la,KebabMenu:O0,KeyValueList:D3,LIST_ROW:Oh,Label:qc,LogStream:rn,LoginForm:eb,MaskShapeCanvas:jd,MobileDrawer:Xc,MotionZonesSettings:i0,NodeMultiSelectField:d0,NodePicker:Lg,NodeSelectField:c0,PHASE_CONFIG:_l,PTZOverlay:id,PageHeader:P3,PhaseIcon:Ud,PipelineBuilder:ud,PipelineRuntimeSelector:zM,PipelineStep:Ws,PipelineTreeMatrix:td,PlayerOverlaysProvider:t0,Popover:Cg,PopoverContent:Ag,PopoverTrigger:Mg,ProviderBadge:M3,PtzPanel:Xy,QrCode:I0,ResponseLog:JL,SECTION_BODY:vk,SECTION_CARD:xk,SECTION_HEADER:yk,SPLIT_PANEL_OUTER:Ck,SPLIT_PANEL_SIDE:Mk,STACK_GAP:wk,ScopePicker:Gd,ScrollArea:Zc,Select:To,SemanticBadge:Tg,Separator:Qc,Sidebar:Fl,SidebarItem:zl,Skeleton:rg,SlideOverPanel:ed,SnapshotButton:IT,StatCard:$3,StateValuesStream:qd,StatusBadge:S3,StepTimings:YM,StepTreeMaster:_g,StreamBrokerSelector:EL,StreamPanel:g0,Switch:Gc,SystemProvider:rd,TEXT_FIELD_LABEL:Ek,TEXT_HINT:Qt,TEXT_METRIC:Pk,TEXT_SECTION_LABEL:Ak,TEXT_VALUE:Ik,Tabs:o3,TabsContent:i3,TabsList:s3,TabsTrigger:a3,ThemeProvider:aa,Tooltip:t3,TooltipContent:r3,TooltipTrigger:n3,VersionBadge:E3,WidgetRegistryProvider:Wy,WidgetSlot:Tr,ZoneEditingProvider:z0,buildStepTreeFromSchema:ja,cn:Y,createSharedContext:wn,createTheme:w2,darkColors:hh,defaultTheme:Il,deriveDeviceKind:j3,ensureMfHostInit:Bc,getClassColor:xt,getPhaseVisual:Gr,isAbsentProvider:Do,isFieldVisible:Hd,lightColors:gh,loadRemoteBundle:Td,mirror:Bh,mountAddonPage:i4,providerIcons:QC,statusIcons:GC,themeToCss:M2,trpc:S,useAccessoriesGetStatus:l4,useAddonPagesListPages:md,useAddonSettingsGetDeviceSettings:v4,useAddonSettingsGetGlobalSettings:xd,useAddonSettingsUpdateDeviceSettings:Cb,useAddonSettingsUpdateGlobalSettings:Sb,useAddonWidgetsListWidgets:Mb,useAddonsApplyAutoUpdateToAll:kb,useAddonsCancelBulkUpdate:gb,useAddonsCustom:x4,useAddonsForceRefresh:ub,useAddonsGetAddonAutoUpdate:wb,useAddonsGetAutoUpdateSettings:vb,useAddonsGetBulkUpdateState:g4,useAddonsGetLastRestart:bd,useAddonsGetLogs:c4,useAddonsGetVersions:xb,useAddonsInstallFromWorkspace:u4,useAddonsInstallPackage:hd,useAddonsIsWorkspaceAvailable:p4,useAddonsList:Nn,useAddonsListActiveBulkUpdates:bb,useAddonsListCapabilityProviders:Xo,useAddonsListFrameworkPackages:fb,useAddonsListPackages:d4,useAddonsListUpdates:gd,useAddonsListWorkspacePackages:f4,useAddonsOnAddonLogs:y4,useAddonsReloadPackages:cb,useAddonsRestartAddon:Jo,useAddonsRestartServer:pb,useAddonsRetryLoad:yb,useAddonsRollbackPackage:m4,useAddonsSearchAvailable:db,useAddonsSetAddonAutoUpdate:Nb,useAddonsSetAutoUpdateSettings:b4,useAddonsSetCapabilityProviderEnabled:mb,useAddonsStartBulkUpdate:hb,useAddonsUninstallPackage:lb,useAddonsUpdateFrameworkPackage:h4,useAddonsUpdatePackage:Hl,useAlertsDismiss:_b,useAlertsEmit:w4,useAlertsGetUnreadCount:Eb,useAlertsList:Ab,useAlertsMarkAllRead:Pb,useAlertsMarkRead:Ib,useAlertsUpdate:N4,useAllWidgets:Yy,useAudioAnalysisApplyDeviceSettingsPatch:M4,useAudioAnalysisGetDeviceLiveContribution:C4,useAudioAnalysisGetDeviceSettingsContribution:S4,useAudioAnalysisResolveDeviceSettings:k4,useAudioAnalyzerAnalyseChunk:A4,useAudioAnalyzerClassify:E4,useAudioAnalyzerDispose:P4,useAudioAnalyzerIsReady:I4,useAudioAnalyzerReprobeAudioEngine:$b,useAudioCodecCanHandle:$4,useAudioCodecCloseSession:T4,useAudioCodecCreateDecodeSession:D4,useAudioCodecCreateEncodeSession:L4,useAudioCodecFlushEncode:F4,useAudioCodecListActiveSessions:j4,useAudioCodecListSupportedCodecs:_4,useAudioCodecPullEncoded:z4,useAudioCodecPullPcm:O4,useAudioCodecPushEncodedFrame:R4,useAudioCodecPushPcm:B4,useAudioMetricsGetCurrentSnapshot:Db,useAudioMetricsGetHistory:H4,useBackupDelete:Bb,useBackupGetEntries:Rb,useBackupList:V4,useBackupListArchives:vd,useBackupListDestinations:yd,useBackupListLocations:Tb,useBackupPreviewSchedule:Fb,useBackupRestore:Ob,useBackupTrigger:Lb,useBackupUpsertDestinationPolicy:zb,useBatteryGetStatus:U4,useBrightnessGetStatus:Q4,useBrightnessSetBrightness:q4,useCameraCredentialsGetCredentials:G4,useCameraCredentialsGetStatus:W4,useCameraPipelineConfigApplyDeviceSettingsPatch:Z4,useCameraPipelineConfigGetDeviceLiveContribution:Y4,useCameraPipelineConfigGetDeviceSettingsContribution:K4,useCameraStreamsGetBrokerStreams:J4,useCameraStreamsGetCameraStreams:X4,useCameraStreamsGetRtspEntries:jb,useClusterNodes:eo,useConfirm:st,useCustomFieldRenderer:sb,useDebouncedString:Xg,useDecoderCreateSession:nA,useDecoderDestroySession:rA,useDecoderGetFrame:lA,useDecoderGetInfo:tA,useDecoderGetShmStats:cA,useDecoderGetStats:uA,useDecoderListActiveSessions:pA,useDecoderOpenStream:sA,useDecoderPullFrames:aA,useDecoderPullHandles:iA,useDecoderPushPacket:oA,useDecoderReprobeHwaccel:Hb,useDecoderSupportsCodec:eA,useDecoderUpdateConfig:dA,useDetectionPipelineApplyDeviceSettingsPatch:hA,useDetectionPipelineGetDeviceLiveContribution:mA,useDetectionPipelineGetDeviceSettingsContribution:fA,useDevShell:n4,useDevice:jT,useDeviceAutotrack:Jy,useDeviceBattery:ld,useDeviceCapability:to,useDeviceDetections:F0,useDeviceDiscoveryAdoptDevice:gA,useDeviceDiscoveryGetStatus:xA,useDeviceDiscoveryListDiscovered:Vb,useDeviceDiscoveryRefreshDiscovery:Ub,useDeviceDiscoveryReleaseDevice:bA,useDeviceExportApplyDeviceSettingsPatch:wA,useDeviceExportExposeDevice:Gb,useDeviceExportGetDeviceLiveContribution:vA,useDeviceExportGetDeviceSettingsContribution:yA,useDeviceExportGetStatus:wd,useDeviceExportListExposedDevices:Qb,useDeviceExportListSupportedDeviceKinds:qb,useDeviceExportUnexposeDevice:Wb,useDeviceId:fd,useDeviceManagerAddLocation:PA,useDeviceManagerAdoptDevice:ax,useDeviceManagerAllocateDeviceId:NA,useDeviceManagerCreateDevice:lx,useDeviceManagerDisable:ex,useDeviceManagerDiscoverDevices:kd,useDeviceManagerEnable:Jb,useDeviceManagerGetAllBindings:jA,useDeviceManagerGetBindings:nx,useDeviceManagerGetChildren:Xb,useDeviceManagerGetConfigSchema:TA,useDeviceManagerGetCreationSchema:ix,useDeviceManagerGetDevice:Lr,useDeviceManagerGetDeviceAggregate:Nd,useDeviceManagerGetDeviceLiveInfoAggregate:UA,useDeviceManagerGetDeviceSettingsAggregate:VA,useDeviceManagerGetDeviceStatusAggregate:GA,useDeviceManagerGetSettingsSchema:RA,useDeviceManagerGetStreamProfileMap:BA,useDeviceManagerGetStreamSources:LA,useDeviceManagerListAll:kn,useDeviceManagerListBindableCapsForDeviceType:ox,useDeviceManagerListLocations:Zb,useDeviceManagerListPersistedByAddon:DA,useDeviceManagerListWrappersForCap:HA,useDeviceManagerLoadConfig:MA,useDeviceManagerLoadMeta:EA,useDeviceManagerLoadRuntimeState:AA,useDeviceManagerPersistConfig:CA,useDeviceManagerProbeStreams:FA,useDeviceManagerRegisterDevice:kA,useDeviceManagerRemove:tx,useDeviceManagerRemoveDevice:SA,useDeviceManagerRemoveLocation:_A,useDeviceManagerSetDisabled:$A,useDeviceManagerSetLocation:Yb,useDeviceManagerSetMetadata:IA,useDeviceManagerSetName:Kb,useDeviceManagerSetStreamProfileMap:zA,useDeviceManagerSetWrapperActive:rx,useDeviceManagerTestCreationField:Sd,useDeviceManagerTestField:QA,useDeviceManagerUpdateConfig:OA,useDeviceManagerUpdateDeviceField:qA,useDeviceManagerUpdateDeviceFieldsBatch:sx,useDeviceOpsGetConfigEntries:KA,useDeviceOpsGetSettingsSchema:XA,useDeviceOpsGetStreamSources:WA,useDeviceOpsRemoveDevice:ZA,useDeviceOpsSetConfig:YA,useDeviceProviderAdoptDiscoveredDevice:sE,useDeviceProviderCreateDevice:lE,useDeviceProviderDiscoverDevices:oE,useDeviceProviderGetChildCreationSchema:iE,useDeviceProviderGetDevices:nE,useDeviceProviderGetStatus:tE,useDeviceProviderStart:JA,useDeviceProviderStop:eE,useDeviceProviderSupportsDiscovery:rE,useDeviceProviderSupportsManualCreation:aE,useDeviceProviderTestCreationField:cE,useDeviceProxy:wt,useDeviceSnapshot:ib,useDeviceSnapshotImage:cd,useDeviceState:Bg,useDeviceStateGetAllSnapshots:pE,useDeviceStateGetCapSlice:uE,useDeviceStateGetSnapshot:dE,useDeviceStateSetCapSlice:fE,useDeviceStateSlice:hn,useDeviceStatusGetStatus:mE,useDeviceWebrtc:j0,useDevices:FT,useDoorbellEvents:H0,useDoorbellGetStatus:hE,useEventInvalidation:UT,useEventStreamLatest:Jr,useEventStreamMap:od,useEventsGetEventClipUrl:xE,useEventsGetEventThumbnail:bE,useEventsGetEvents:gE,useFeatureProbeGetStatus:yE,useIntegrationsCreate:ux,useIntegrationsDelete:fx,useIntegrationsGet:cx,useIntegrationsGetAvailableTypes:mx,useIntegrationsGetByAddonId:dx,useIntegrationsGetSettings:vE,useIntegrationsList:Cd,useIntegrationsSetSettings:wE,useIntegrationsTestConnection:hx,useIntegrationsUpdate:px,useIntercomEndTalkSession:SE,useIntercomGetStatus:CE,useIntercomHandleAnswer:bx,useIntercomPushTalkPcm:kE,useIntercomStartSession:gx,useIntercomStartTalkSession:NE,useIntercomStopSession:xx,useIsMidWidth:Ng,useIsMobile:pr,useLiveBuffer:Mr,useLiveEvent:ft,useLocalNetworkGetAllowedAddresses:wx,useLocalNetworkGetConnectionEndpoints:vx,useLocalNetworkGetPreferred:ME,useLocalNetworkList:yx,useLocalNetworkResetAllowlistToBestMatch:kx,useLocalNetworkSetAllowedAddresses:Nx,useMeshNetworkGetStatus:Sx,useMeshNetworkJoin:AE,useMeshNetworkLeave:Mx,useMeshNetworkListPeers:Ex,useMeshNetworkLogout:Ax,useMeshNetworkStartLogin:Cx,useMeshNetworkTestConnection:EE,useMetricsProviderCollectSnapshot:IE,useMetricsProviderGetAddonStats:OE,useMetricsProviderGetCached:PE,useMetricsProviderGetCpuTemperature:LE,useMetricsProviderGetCurrent:_E,useMetricsProviderGetDiskSpace:$E,useMetricsProviderGetGpuInfo:DE,useMetricsProviderGetProcessStats:TE,useMetricsProviderKillProcess:Px,useMetricsProviderListAddonInstances:RE,useMetricsProviderListNodeProcesses:Ix,useMotionDetectionAnalyze:FE,useMotionDetectionApplyDeviceSettingsPatch:qE,useMotionDetectionGetDeviceLiveContribution:UE,useMotionDetectionGetDeviceSettingsContribution:VE,useMotionDetectionRemoveCamera:jE,useMotionDetectionReset:HE,useMotionGetStatus:zE,useMotionIsDetected:BE,useMotionTriggerGetStatus:GE,useMotionTriggerSetMotionTrigger:QE,useMotionZonesGetOptions:WE,useMotionZonesGetStatus:YE,useMotionZonesSetZone:KE,useMqttBrokerAddBroker:JE,useMqttBrokerGetBrokerConfig:XE,useMqttBrokerGetStatus:_x,useMqttBrokerListBrokers:ZE,useMqttBrokerRemoveBroker:eI,useMqttBrokerStartEmbeddedBroker:nI,useMqttBrokerStopEmbeddedBroker:rI,useMqttBrokerTestConnection:tI,useNativeObjectDetectionGetStatus:sI,useNativeObjectDetectionSetEnabled:oI,useNetworkAccessGetEndpoint:aI,useNetworkAccessGetStatus:Lx,useNetworkAccessListEndpoints:iI,useNetworkAccessStart:$x,useNetworkAccessStop:Dx,useNetworkQualityGetAllStats:lI,useNetworkQualityGetDeviceStats:Tx,useNetworkQualityReportClientStats:cI,useNodesClusterAddonStatus:zx,useNodesDeployAddon:dI,useNodesExecuteQuery:fI,useNodesGetCapUsageGraph:Fx,useNodesGetNodeAddons:jx,useNodesRenameNode:Bx,useNodesRestartAddon:Ua,useNodesRestartNode:uI,useNodesRestartProcess:Ox,useNodesSetProcessLogLevel:Hx,useNodesShutdownNode:pI,useNodesTopology:Hn,useNodesUndeployAddon:Rx,useNotificationOutputSend:mI,useNotificationOutputSendTest:hI,useOptionalSystem:N3,useOptionalWidgetRegistry:Rd,useOsdGetStatus:bI,useOsdSetOverlay:gI,usePTZ:ad,usePipelineAnalyticsApplyDeviceSettingsPatch:II,usePipelineAnalyticsClearTracks:wI,usePipelineAnalyticsGetActiveTracks:xI,usePipelineAnalyticsGetAudioEvents:SI,usePipelineAnalyticsGetDeviceLiveContribution:EI,usePipelineAnalyticsGetDeviceSettingsContribution:AI,usePipelineAnalyticsGetEventMedia:CI,usePipelineAnalyticsGetMotionEvents:NI,usePipelineAnalyticsGetObjectEvents:kI,usePipelineAnalyticsGetTrack:yI,usePipelineAnalyticsGetTrackMedia:MI,usePipelineAnalyticsListTracks:vI,usePipelineExecutorCacheFrameInPool:qI,usePipelineExecutorDeleteModel:Gx,usePipelineExecutorDeleteTemplate:zI,usePipelineExecutorDetect:HI,usePipelineExecutorDownloadModel:Qx,usePipelineExecutorGetAddonModels:jI,usePipelineExecutorGetAudioCapabilities:eP,usePipelineExecutorGetAvailableEngines:Vx,usePipelineExecutorGetCapabilities:FI,usePipelineExecutorGetDefaultSteps:PI,usePipelineExecutorGetDetectionConfigSchema:nP,usePipelineExecutorGetEffectiveTuning:WI,usePipelineExecutorGetGlobalPipelineConfig:LI,usePipelineExecutorGetGlobalSteps:DI,usePipelineExecutorGetOrchestratorConfigSchema:TI,usePipelineExecutorGetReferenceAudio:JI,usePipelineExecutorGetReferenceAudioFiles:XI,usePipelineExecutorGetReferenceImage:ZI,usePipelineExecutorGetSchema:es,usePipelineExecutorGetSelectedEngine:Ux,usePipelineExecutorGetVideoPipelineSteps:_I,usePipelineExecutorInferCached:QI,usePipelineExecutorKillEngine:Kx,usePipelineExecutorListLoadedEngines:Wx,usePipelineExecutorListReferenceImages:YI,usePipelineExecutorListTemplates:RI,usePipelineExecutorReprobeEngine:qx,usePipelineExecutorRunAudioTest:tP,usePipelineExecutorRunPipeline:VI,usePipelineExecutorRunPipelineBatch:UI,usePipelineExecutorSaveTemplate:OI,usePipelineExecutorSetVideoPipelineSteps:$I,usePipelineExecutorSpinEngine:KI,usePipelineExecutorUncacheFrame:GI,usePipelineExecutorUpdateTemplate:BI,usePipelineOrchestratorApplyDeviceSettingsPatch:uP,usePipelineOrchestratorAssignAudio:sy,usePipelineOrchestratorAssignDecoder:ny,usePipelineOrchestratorAssignPipeline:Yx,usePipelineOrchestratorDeleteTemplate:gy,usePipelineOrchestratorGetAgentLoad:Jx,usePipelineOrchestratorGetAgentSettings:Ad,usePipelineOrchestratorGetAudioAssignment:sP,usePipelineOrchestratorGetAudioAssignments:ly,usePipelineOrchestratorGetAudioNodeLoad:iy,usePipelineOrchestratorGetCameraMetrics:oP,usePipelineOrchestratorGetCameraSettings:Id,usePipelineOrchestratorGetCameraStepOverrides:iP,usePipelineOrchestratorGetCapabilityBindings:ey,usePipelineOrchestratorGetDecoderAssignment:aP,usePipelineOrchestratorGetDecoderAssignments:oy,usePipelineOrchestratorGetDeviceLiveContribution:dP,usePipelineOrchestratorGetDeviceSettingsContribution:cP,usePipelineOrchestratorGetGlobalMetrics:rP,usePipelineOrchestratorGetPipelineAssignment:Md,usePipelineOrchestratorGetPipelineAssignments:qa,usePipelineOrchestratorListAgentSettings:no,usePipelineOrchestratorListTemplates:my,usePipelineOrchestratorRebalance:Xx,usePipelineOrchestratorRemoveAgentSettings:cy,usePipelineOrchestratorResolvePipeline:fy,usePipelineOrchestratorSaveTemplate:lP,usePipelineOrchestratorSetAgentAddonDefaults:Ed,usePipelineOrchestratorSetCameraPipelineForAgent:py,usePipelineOrchestratorSetCameraStepOverride:uy,usePipelineOrchestratorSetCameraStepToggle:dy,usePipelineOrchestratorSetCapabilityBinding:ty,usePipelineOrchestratorUnassignAudio:ay,usePipelineOrchestratorUnassignDecoder:ry,usePipelineOrchestratorUnassignPipeline:Zx,usePipelineOrchestratorUpdateTemplate:hy,usePipelineRunnerAttachCamera:pP,usePipelineRunnerDetachCamera:fP,usePipelineRunnerGetAllCameraMetrics:bP,usePipelineRunnerGetCameraMetrics:by,usePipelineRunnerGetLocalCameras:xy,usePipelineRunnerGetLocalLoad:hP,usePipelineRunnerGetLocalMetrics:gP,usePipelineRunnerReportMotion:mP,usePlatformProbeGetCapabilities:xP,usePlatformProbeGetHardware:yP,usePlatformProbeGetHardwareEncoders:NP,usePlatformProbeRefreshHardwareEncoders:kP,usePlatformProbeResolveHwAccel:wP,usePlatformProbeResolveInferenceConfig:vP,usePlayerOverlayLayer:zd,usePlayerOverlayLayers:n0,usePlayerToolbarButton:sD,usePlayerToolbarButtons:r0,usePrivacyMaskGetOptions:SP,usePrivacyMaskGetStatus:MP,usePrivacyMaskSetMask:CP,usePtzAutotrackGetSettings:zP,usePtzAutotrackGetStatus:yy,usePtzAutotrackSetEnabled:vy,usePtzAutotrackSetSettings:wy,usePtzContinuousMove:EP,usePtzDeletePreset:DP,usePtzGetOptions:LP,usePtzGetPosition:RP,usePtzGetPresets:PP,usePtzGetStatus:BP,usePtzGoHome:TP,usePtzGoToPreset:_P,usePtzMove:AP,usePtzSavePreset:$P,usePtzSetAutofocus:OP,usePtzStop:IP,useRebootReboot:Ny,useRecordingEngineDisable:Sy,useRecordingEngineEnable:ky,useRecordingEngineEstimateGlobalStorage:KP,useRecordingEngineEstimateStorage:WP,useRecordingEngineGetAvailability:GP,useRecordingEngineGetConfig:Cy,useRecordingEngineGetMotionStats:JP,useRecordingEngineGetPlaylist:qP,useRecordingEngineGetPolicy:ZP,useRecordingEngineGetPolicyStatus:Ey,useRecordingEngineGetRetentionConfig:Iy,useRecordingEngineGetSegments:My,useRecordingEngineGetStatus:VP,useRecordingEngineGetStorageUsage:Ay,useRecordingEngineGetThumbnail:QP,useRecordingEngineSetPolicy:YP,useRecordingEngineUpdateConfig:UP,useRecordingEngineUpdateRetentionConfig:XP,useRecordingGetPlaybackUrl:jP,useRecordingGetSegments:FP,useRecordingGetThumbnailAt:HP,useRemoteComponent:Zy,useSettingsStoreCount:a_,useSettingsStoreDeclareCollection:l_,useSettingsStoreDelete:s_,useSettingsStoreGet:e_,useSettingsStoreInsert:r_,useSettingsStoreIsEmpty:i_,useSettingsStoreQuery:n_,useSettingsStoreSet:t_,useSettingsStoreUpdate:o_,useSnapshotApplyDeviceSettingsPatch:m_,useSnapshotGetDeviceLiveContribution:f_,useSnapshotGetDeviceSettingsContribution:p_,useSnapshotGetSnapshot:c_,useSnapshotGetStatus:u_,useSnapshotInvalidateCache:d_,useSnapshotProviderGetSnapshot:g_,useSnapshotProviderSupportsDevice:h_,useStorageAbortUpload:A_,useStorageBeginDownload:E_,useStorageBeginUpload:S_,useStorageDelete:N_,useStorageDeleteLocation:_y,useStorageEndDownload:P_,useStorageExists:v_,useStorageFinalizeUpload:M_,useStorageGetAvailableSpace:k_,useStorageGetDefaultLocation:__,useStorageList:w_,useStorageListLocations:Py,useStorageListProviders:Pd,useStorageRead:y_,useStorageReadChunk:I_,useStorageResolve:b_,useStorageTestConfig:D_,useStorageTestLocation:$_,useStorageUpsertLocation:Qa,useStorageWrite:x_,useStorageWriteChunk:C_,useStreamBrokerApplyDeviceSettingsPatch:l$,useStreamBrokerAssignProfile:R_,useStreamBrokerGetAllRtspEntries:n$,useStreamBrokerGetBrokerStats:F_,useStreamBrokerGetDeviceLiveContribution:i$,useStreamBrokerGetDeviceSettingsContribution:a$,useStreamBrokerGetPreBufferInfo:e$,useStreamBrokerGetRtspEntry:r$,useStreamBrokerGetRtspPort:t$,useStreamBrokerGetStreamUrl:U_,useStreamBrokerGetStreamWithCodec:q_,useStreamBrokerIsRtspEnabled:s$,useStreamBrokerKillClient:H_,useStreamBrokerListAllCameraStreams:B_,useStreamBrokerListAllProfileSlots:z_,useStreamBrokerListClients:j_,useStreamBrokerPublishCameraStream:L_,useStreamBrokerPullAudioChunks:W_,useStreamBrokerPullFrameHandles:Z_,useStreamBrokerRegenerateRtspToken:$y,useStreamBrokerReleaseStreamWithCodec:Q_,useStreamBrokerRestartProfile:V_,useStreamBrokerRetractCameraStream:T_,useStreamBrokerSetPreBufferDuration:J_,useStreamBrokerSetRtspEnabled:o$,useStreamBrokerSubscribeAudioChunks:G_,useStreamBrokerSubscribeFrames:Y_,useStreamBrokerUnassignProfile:O_,useStreamBrokerUnsubscribeAudioChunks:K_,useStreamBrokerUnsubscribeFrames:X_,useStreamCatalogGetCatalog:c$,useStreamParamsGetConfigSchema:p$,useStreamParamsGetOptions:d$,useStreamParamsGetStatus:f$,useStreamParamsSetProfile:u$,useSwitchGetStatus:h$,useSwitchSetState:m$,useSystem:De,useSystemFeatureFlags:x$,useSystemForceRetentionCleanup:N$,useSystemGetRetentionConfig:v$,useSystemHealth:b$,useSystemInfo:g$,useSystemMutation:VT,useSystemNetworkAddresses:y$,useSystemQuery:HT,useSystemSetRetentionConfig:w$,useThemeMode:Yo,useToastOnToast:Dy,useTurnProviderGetTurnServers:_d,useUserManagementConfirmTotp:E$,useUserManagementCreateApiKey:S$,useUserManagementCreateScopedToken:Fy,useUserManagementCreateUser:Ly,useUserManagementDeleteUser:Ry,useUserManagementDisableTotp:Vy,useUserManagementGetTotpStatus:Uy,useUserManagementListApiKeys:By,useUserManagementListOauthSessions:qy,useUserManagementListScopedTokens:Hy,useUserManagementListUsers:$d,useUserManagementOauthExchangeCode:_$,useUserManagementOauthIssueCode:P$,useUserManagementOauthRefresh:$$,useUserManagementOauthVerifyAccessToken:D$,useUserManagementResetPassword:Dd,useUserManagementRevokeApiKey:zy,useUserManagementRevokeOauthSession:Qy,useUserManagementRevokeScopedToken:jy,useUserManagementSetUserScopes:Oy,useUserManagementSetupTotp:A$,useUserManagementUpdateUser:Ty,useUserManagementValidateApiKey:C$,useUserManagementValidateCredentials:k$,useUserManagementValidateScopedToken:M$,useUserManagementVerifyTotp:I$,useWebrtcSessionAddIceCandidate:B$,useWebrtcSessionCloseSession:F$,useWebrtcSessionCreateSession:T$,useWebrtcSessionGetIceCandidates:z$,useWebrtcSessionHandleAnswer:O$,useWebrtcSessionHandleOffer:R$,useWebrtcSessionHasAdaptiveBitrate:j$,useWebrtcSessionListStreams:L$,useWidget:nD,useWidgetMetadata:Ky,useWidgetRegistry:Ga,useZoneAnalyticsGetCameraHistory:U$,useZoneAnalyticsGetCurrentSnapshot:H$,useZoneAnalyticsGetUnzonedHistory:q$,useZoneAnalyticsGetZoneHistory:V$,useZoneEditing:BT,useZoneRulesListRules:Q$,useZoneRulesSetRules:G$,useZonesAddZone:K$,useZonesListZones:W$,useZonesRemoveZone:Y$,useZonesUpdateZone:Z$,validateScopes:Wd},Symbol.toStringTag,{value:"Module"}));/**
587
+ * react-router v7.15.0
588
+ *
589
+ * Copyright (c) Remix Software Inc.
590
+ *
591
+ * This source code is licensed under the MIT license found in the
592
+ * LICENSE.md file in the root directory of this source tree.
593
+ *
594
+ * @license MIT
595
+ */var zp="popstate";function Fp(e){return typeof e=="object"&&e!=null&&"pathname"in e&&"search"in e&&"hash"in e&&"state"in e&&"key"in e}function QT(e={}){function t(o,s){let a=s.state?.masked,{pathname:i,search:l,hash:c}=a||o.location;return Zl("",{pathname:i,search:l,hash:c},s.state&&s.state.usr||null,s.state&&s.state.key||"default",a?{pathname:o.location.pathname,search:o.location.search,hash:o.location.hash}:void 0)}function n(o,s){return typeof s=="string"?s:Oo(s)}return WT(t,n,null,e)}function Qe(e,t){if(e===!1||e===null||typeof e>"u")throw new Error(t)}function Et(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}function GT(){return Math.random().toString(36).substring(2,10)}function jp(e,t){return{usr:e.state,key:e.key,idx:t,masked:e.mask?{pathname:e.pathname,search:e.search,hash:e.hash}:void 0}}function Zl(e,t,n=null,o,s){return{pathname:typeof e=="string"?e:e.pathname,search:"",hash:"",...typeof t=="string"?ro(t):t,state:n,key:t&&t.key||o||GT(),mask:s}}function Oo({pathname:e="/",search:t="",hash:n=""}){return t&&t!=="?"&&(e+=t.charAt(0)==="?"?t:"?"+t),n&&n!=="#"&&(e+=n.charAt(0)==="#"?n:"#"+n),e}function ro(e){let t={};if(e){let n=e.indexOf("#");n>=0&&(t.hash=e.substring(n),e=e.substring(0,n));let o=e.indexOf("?");o>=0&&(t.search=e.substring(o),e=e.substring(0,o)),e&&(t.pathname=e)}return t}function WT(e,t,n,o={}){let{window:s=document.defaultView,v5Compat:a=!1}=o,i=s.history,l="POP",c=null,d=p();d==null&&(d=0,i.replaceState({...i.state,idx:d},""));function p(){return(i.state||{idx:null}).idx}function f(){l="POP";let b=p(),y=b==null?null:b-d;d=b,c&&c({action:l,location:x.location,delta:y})}function m(b,y){l="PUSH";let w=Fp(b)?b:Zl(x.location,b,y);d=p()+1;let v=jp(w,d),N=x.createHref(w.mask||w);try{i.pushState(v,"",N)}catch(k){if(k instanceof DOMException&&k.name==="DataCloneError")throw k;s.location.assign(N)}a&&c&&c({action:l,location:x.location,delta:1})}function h(b,y){l="REPLACE";let w=Fp(b)?b:Zl(x.location,b,y);d=p();let v=jp(w,d),N=x.createHref(w.mask||w);i.replaceState(v,"",N),a&&c&&c({action:l,location:x.location,delta:0})}function g(b){return KT(b)}let x={get action(){return l},get location(){return e(s,i)},listen(b){if(c)throw new Error("A history only accepts one active listener");return s.addEventListener(zp,f),c=b,()=>{s.removeEventListener(zp,f),c=null}},createHref(b){return t(s,b)},createURL:g,encodeLocation(b){let y=g(b);return{pathname:y.pathname,search:y.search,hash:y.hash}},push:m,replace:h,go(b){return i.go(b)}};return x}function KT(e,t=!1){let n="http://localhost";typeof window<"u"&&(n=window.location.origin!=="null"?window.location.origin:window.location.href),Qe(n,"No window.location.(origin|href) available to create URL");let o=typeof e=="string"?e:Oo(e);return o=o.replace(/ $/,"%20"),!t&&o.startsWith("//")&&(o=n+o),new URL(o,n)}function V0(e,t,n="/"){return YT(e,t,n,!1)}function YT(e,t,n,o,s){let a=typeof t=="string"?ro(t):t,i=gn(a.pathname||"/",n);if(i==null)return null;let l=ZT(e),c=null,d=cR(i);for(let p=0;c==null&&p<l.length;++p)c=iR(l[p],d,o);return c}function ZT(e){let t=U0(e);return XT(t),t}function U0(e,t=[],n=[],o="",s=!1){let a=(i,l,c=s,d)=>{let p={relativePath:d===void 0?i.path||"":d,caseSensitive:i.caseSensitive===!0,childrenIndex:l,route:i};if(p.relativePath.startsWith("/")){if(!p.relativePath.startsWith(o)&&c)return;Qe(p.relativePath.startsWith(o),`Absolute route path "${p.relativePath}" nested under path "${o}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),p.relativePath=p.relativePath.slice(o.length)}let f=zt([o,p.relativePath]),m=n.concat(p);i.children&&i.children.length>0&&(Qe(i.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${f}".`),U0(i.children,t,m,f,c)),!(i.path==null&&!i.index)&&t.push({path:f,score:sR(f,i.index),routesMeta:m})};return e.forEach((i,l)=>{if(i.path===""||!i.path?.includes("?"))a(i,l);else for(let c of q0(i.path))a(i,l,!0,c)}),t}function q0(e){let t=e.split("/");if(t.length===0)return[];let[n,...o]=t,s=n.endsWith("?"),a=n.replace(/\?$/,"");if(o.length===0)return s?[a,""]:[a];let i=q0(o.join("/")),l=[];return l.push(...i.map(c=>c===""?a:[a,c].join("/"))),s&&l.push(...i),l.map(c=>e.startsWith("/")&&c===""?"/":c)}function XT(e){e.sort((t,n)=>t.score!==n.score?n.score-t.score:aR(t.routesMeta.map(o=>o.childrenIndex),n.routesMeta.map(o=>o.childrenIndex)))}var JT=/^:[\w-]+$/,eR=3,tR=2,nR=1,rR=10,oR=-2,Hp=e=>e==="*";function sR(e,t){let n=e.split("/"),o=n.length;return n.some(Hp)&&(o+=oR),t&&(o+=tR),n.filter(s=>!Hp(s)).reduce((s,a)=>s+(JT.test(a)?eR:a===""?nR:rR),o)}function aR(e,t){return e.length===t.length&&e.slice(0,-1).every((o,s)=>o===t[s])?e[e.length-1]-t[t.length-1]:0}function iR(e,t,n=!1){let{routesMeta:o}=e,s={},a="/",i=[];for(let l=0;l<o.length;++l){let c=o[l],d=l===o.length-1,p=a==="/"?t:t.slice(a.length)||"/",f=pa({path:c.relativePath,caseSensitive:c.caseSensitive,end:d},p),m=c.route;if(!f&&d&&n&&!o[o.length-1].route.index&&(f=pa({path:c.relativePath,caseSensitive:c.caseSensitive,end:!1},p)),!f)return null;Object.assign(s,f.params),i.push({params:s,pathname:zt([a,f.pathname]),pathnameBase:fR(zt([a,f.pathnameBase])),route:m}),f.pathnameBase!=="/"&&(a=zt([a,f.pathnameBase]))}return i}function pa(e,t){typeof e=="string"&&(e={path:e,caseSensitive:!1,end:!0});let[n,o]=lR(e.path,e.caseSensitive,e.end),s=t.match(n);if(!s)return null;let a=s[0],i=a.replace(/(.)\/+$/,"$1"),l=s.slice(1);return{params:o.reduce((d,{paramName:p,isOptional:f},m)=>{if(p==="*"){let g=l[m]||"";i=a.slice(0,a.length-g.length).replace(/(.)\/+$/,"$1")}const h=l[m];return f&&!h?d[p]=void 0:d[p]=(h||"").replace(/%2F/g,"/"),d},{}),pathname:a,pathnameBase:i,pattern:e}}function lR(e,t=!1,n=!0){Et(e==="*"||!e.endsWith("*")||e.endsWith("/*"),`Route path "${e}" will be treated as if it were "${e.replace(/\*$/,"/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/,"/*")}".`);let o=[],s="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(i,l,c,d,p)=>{if(o.push({paramName:l,isOptional:c!=null}),c){let f=p.charAt(d+i.length);return f&&f!=="/"?"/([^\\/]*)":"(?:/([^\\/]*))?"}return"/([^\\/]+)"}).replace(/\/([\w-]+)\?(\/|$)/g,"(/$1)?$2");return e.endsWith("*")?(o.push({paramName:"*"}),s+=e==="*"||e==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):n?s+="\\/*$":e!==""&&e!=="/"&&(s+="(?:(?=\\/|$))"),[new RegExp(s,t?void 0:"i"),o]}function cR(e){try{return e.split("/").map(t=>decodeURIComponent(t).replace(/\//g,"%2F")).join("/")}catch(t){return Et(!1,`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${t}).`),e}}function gn(e,t){if(t==="/")return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith("/")?t.length-1:t.length,o=e.charAt(n);return o&&o!=="/"?null:e.slice(n)||"/"}var dR=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;function uR(e,t="/"){let{pathname:n,search:o="",hash:s=""}=typeof e=="string"?ro(e):e,a;return n?(n=Q0(n),n.startsWith("/")?a=Vp(n.substring(1),"/"):a=Vp(n,t)):a=t,{pathname:a,search:mR(o),hash:hR(s)}}function Vp(e,t){let n=fa(t).split("/");return e.split("/").forEach(s=>{s===".."?n.length>1&&n.pop():s!=="."&&n.push(s)}),n.length>1?n.join("/"):"/"}function Qi(e,t,n,o){return`Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(o)}]. Please separate it out to the \`to.${n}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`}function pR(e){return e.filter((t,n)=>n===0||t.route.path&&t.route.path.length>0)}function Kd(e){let t=pR(e);return t.map((n,o)=>o===t.length-1?n.pathname:n.pathnameBase)}function Ka(e,t,n,o=!1){let s;typeof e=="string"?s=ro(e):(s={...e},Qe(!s.pathname||!s.pathname.includes("?"),Qi("?","pathname","search",s)),Qe(!s.pathname||!s.pathname.includes("#"),Qi("#","pathname","hash",s)),Qe(!s.search||!s.search.includes("#"),Qi("#","search","hash",s)));let a=e===""||s.pathname==="",i=a?"/":s.pathname,l;if(i==null)l=n;else{let f=t.length-1;if(!o&&i.startsWith("..")){let m=i.split("/");for(;m[0]==="..";)m.shift(),f-=1;s.pathname=m.join("/")}l=f>=0?t[f]:"/"}let c=uR(s,l),d=i&&i!=="/"&&i.endsWith("/"),p=(a||i===".")&&n.endsWith("/");return!c.pathname.endsWith("/")&&(d||p)&&(c.pathname+="/"),c}var Q0=e=>e.replace(/\/\/+/g,"/"),zt=e=>Q0(e.join("/")),fa=e=>e.replace(/\/+$/,""),fR=e=>fa(e).replace(/^\/*/,"/"),mR=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,hR=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e,gR=class{constructor(e,t,n,o=!1){this.status=e,this.statusText=t||"",this.internal=o,n instanceof Error?(this.data=n.toString(),this.error=n):this.data=n}};function bR(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}function xR(e){let t=e.map(n=>n.route.path).filter(Boolean);return zt(t)||"/"}var G0=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function W0(e,t){let n=e;if(typeof n!="string"||!dR.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let o=n,s=!1;if(G0)try{let a=new URL(window.location.href),i=n.startsWith("//")?new URL(a.protocol+n):new URL(n),l=gn(i.pathname,t);i.origin===a.origin&&l!=null?n=l+i.search+i.hash:s=!0}catch{Et(!1,`<Link to="${n}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:o,isExternal:s,to:n}}Object.getOwnPropertyNames(Object.prototype).sort().join("\0");var K0=["POST","PUT","PATCH","DELETE"];new Set(K0);var yR=["GET",...K0];new Set(yR);var oo=qe(null);oo.displayName="DataRouter";var Ya=qe(null);Ya.displayName="DataRouterState";var Y0=qe(!1);function vR(){return Ne(Y0)}var Z0=qe({isTransitioning:!1});Z0.displayName="ViewTransition";var wR=qe(new Map);wR.displayName="Fetchers";var NR=qe(null);NR.displayName="Await";var Nt=qe(null);Nt.displayName="Navigation";var ts=qe(null);ts.displayName="Location";var _t=qe({outlet:null,matches:[],isDataRoute:!1});_t.displayName="Route";var Yd=qe(null);Yd.displayName="RouteError";var X0="REACT_ROUTER_ERROR",kR="REDIRECT",SR="ROUTE_ERROR_RESPONSE";function CR(e){if(e.startsWith(`${X0}:${kR}:{`))try{let t=JSON.parse(e.slice(28));if(typeof t=="object"&&t&&typeof t.status=="number"&&typeof t.statusText=="string"&&typeof t.location=="string"&&typeof t.reloadDocument=="boolean"&&typeof t.replace=="boolean")return t}catch{}}function MR(e){if(e.startsWith(`${X0}:${SR}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t=="object"&&t&&typeof t.status=="number"&&typeof t.statusText=="string")return new gR(t.status,t.statusText,t.data)}catch{}}function AR(e,{relative:t}={}){Qe(so(),"useHref() may be used only in the context of a <Router> component.");let{basename:n,navigator:o}=Ne(Nt),{hash:s,pathname:a,search:i}=ns(e,{relative:t}),l=a;return n!=="/"&&(l=a==="/"?n:zt([n,a])),o.createHref({pathname:l,search:i,hash:s})}function so(){return Ne(ts)!=null}function kt(){return Qe(so(),"useLocation() may be used only in the context of a <Router> component."),Ne(ts).location}var J0="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function ev(e){Ne(Nt).static||Ra(e)}function at(){let{isDataRoute:e}=Ne(_t);return e?HR():ER()}function ER(){Qe(so(),"useNavigate() may be used only in the context of a <Router> component.");let e=Ne(oo),{basename:t,navigator:n}=Ne(Nt),{matches:o}=Ne(_t),{pathname:s}=kt(),a=JSON.stringify(Kd(o)),i=ne(!1);return ev(()=>{i.current=!0}),U((c,d={})=>{if(Et(i.current,J0),!i.current)return;if(typeof c=="number"){n.go(c);return}let p=Ka(c,JSON.parse(a),s,d.relative==="path");e==null&&t!=="/"&&(p.pathname=p.pathname==="/"?t:zt([t,p.pathname])),(d.replace?n.replace:n.push)(p,d.state,d)},[t,n,a,s,e])}var IR=qe(null);function PR(e){let t=Ne(_t).outlet;return q(()=>t&&_e(IR.Provider,{value:e},t),[t,e])}function Zd(){let{matches:e}=Ne(_t);return e[e.length-1]?.params??{}}function ns(e,{relative:t}={}){let{matches:n}=Ne(_t),{pathname:o}=kt(),s=JSON.stringify(Kd(n));return q(()=>Ka(e,JSON.parse(s),o,t==="path"),[e,s,o,t])}function _R(e,t){return tv(e,t)}function tv(e,t,n){Qe(so(),"useRoutes() may be used only in the context of a <Router> component.");let{navigator:o}=Ne(Nt),{matches:s}=Ne(_t),a=s[s.length-1],i=a?a.params:{},l=a?a.pathname:"/",c=a?a.pathnameBase:"/",d=a&&a.route;{let b=d&&d.path||"";rv(l,!d||b.endsWith("*")||b.endsWith("*?"),`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${l}" (under <Route path="${b}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
596
+
597
+ Please change the parent <Route path="${b}"> to <Route path="${b==="/"?"*":`${b}/*`}">.`)}let p=kt(),f;if(t){let b=typeof t=="string"?ro(t):t;Qe(c==="/"||b.pathname?.startsWith(c),`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${c}" but pathname "${b.pathname}" was given in the \`location\` prop.`),f=b}else f=p;let m=f.pathname||"/",h=m;if(c!=="/"){let b=c.replace(/^\//,"").split("/");h="/"+m.replace(/^\//,"").split("/").slice(b.length).join("/")}let g=n&&n.state.matches.length?n.state.matches.map(b=>Object.assign(b,{route:n.manifest[b.route.id]||b.route})):V0(e,{pathname:h});Et(d||g!=null,`No routes matched location "${f.pathname}${f.search}${f.hash}" `),Et(g==null||g[g.length-1].route.element!==void 0||g[g.length-1].route.Component!==void 0||g[g.length-1].route.lazy!==void 0,`Matched leaf route at location "${f.pathname}${f.search}${f.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`);let x=RR(g&&g.map(b=>Object.assign({},b,{params:Object.assign({},i,b.params),pathname:zt([c,o.encodeLocation?o.encodeLocation(b.pathname.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:b.pathname]),pathnameBase:b.pathnameBase==="/"?c:zt([c,o.encodeLocation?o.encodeLocation(b.pathnameBase.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:b.pathnameBase])})),s,n);return t&&x?_e(ts.Provider,{value:{location:{pathname:"/",search:"",hash:"",state:null,key:"default",mask:void 0,...f},navigationType:"POP"}},x):x}function $R(){let e=jR(),t=bR(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,o="rgba(200,200,200, 0.5)",s={padding:"0.5rem",backgroundColor:o},a={padding:"2px 4px",backgroundColor:o},i=null;return console.error("Error handled by React Router default ErrorBoundary:",e),i=_e(_r,null,_e("p",null,"💿 Hey developer 👋"),_e("p",null,"You can provide a way better UX than this when your app throws errors by providing your own ",_e("code",{style:a},"ErrorBoundary")," or"," ",_e("code",{style:a},"errorElement")," prop on your route.")),_e(_r,null,_e("h2",null,"Unexpected Application Error!"),_e("h3",{style:{fontStyle:"italic"}},t),n?_e("pre",{style:s},n):null,i)}var DR=_e($R,null),nv=class extends JN{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!=="idle"&&e.revalidation==="idle"?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error!==void 0?e.error:t.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.onError?this.props.onError(e,t):console.error("React Router caught the following error during render",e)}render(){let e=this.state.error;if(this.context&&typeof e=="object"&&e&&"digest"in e&&typeof e.digest=="string"){const n=MR(e.digest);n&&(e=n)}let t=e!==void 0?_e(_t.Provider,{value:this.props.routeContext},_e(Yd.Provider,{value:e,children:this.props.component})):this.props.children;return this.context?_e(LR,{error:e},t):t}};nv.contextType=Y0;var Gi=new WeakMap;function LR({children:e,error:t}){let{basename:n}=Ne(Nt);if(typeof t=="object"&&t&&"digest"in t&&typeof t.digest=="string"){let o=CR(t.digest);if(o){let s=Gi.get(t);if(s)throw s;let a=W0(o.location,n);if(G0&&!Gi.get(t))if(a.isExternal||o.reloadDocument)window.location.href=a.absoluteURL||a.to;else{const i=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(a.to,{replace:o.replace}));throw Gi.set(t,i),i}return _e("meta",{httpEquiv:"refresh",content:`0;url=${a.absoluteURL||a.to}`})}}return e}function TR({routeContext:e,match:t,children:n}){let o=Ne(oo);return o&&o.static&&o.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(o.staticContext._deepestRenderedBoundaryId=t.route.id),_e(_t.Provider,{value:e},n)}function RR(e,t=[],n){let o=n?.state;if(e==null){if(!o)return null;if(o.errors)e=o.matches;else if(t.length===0&&!o.initialized&&o.matches.length>0)e=o.matches;else return null}let s=e,a=o?.errors;if(a!=null){let p=s.findIndex(f=>f.route.id&&a?.[f.route.id]!==void 0);Qe(p>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(",")}`),s=s.slice(0,Math.min(s.length,p+1))}let i=!1,l=-1;if(n&&o){i=o.renderFallback;for(let p=0;p<s.length;p++){let f=s[p];if((f.route.HydrateFallback||f.route.hydrateFallbackElement)&&(l=p),f.route.id){let{loaderData:m,errors:h}=o,g=f.route.loader&&!m.hasOwnProperty(f.route.id)&&(!h||h[f.route.id]===void 0);if(f.route.lazy||g){n.isStatic&&(i=!0),l>=0?s=s.slice(0,l+1):s=[s[0]];break}}}}let c=n?.onError,d=o&&c?(p,f)=>{c(p,{location:o.location,params:o.matches?.[0]?.params??{},pattern:xR(o.matches),errorInfo:f})}:void 0;return s.reduceRight((p,f,m)=>{let h,g=!1,x=null,b=null;o&&(h=a&&f.route.id?a[f.route.id]:void 0,x=f.route.errorElement||DR,i&&(l<0&&m===0?(rv("route-fallback",!1,"No `HydrateFallback` element provided to render during initial hydration"),g=!0,b=null):l===m&&(g=!0,b=f.route.hydrateFallbackElement||null)));let y=t.concat(s.slice(0,m+1)),w=()=>{let v;return h?v=x:g?v=b:f.route.Component?v=_e(f.route.Component,null):f.route.element?v=f.route.element:v=p,_e(TR,{match:f,routeContext:{outlet:p,matches:y,isDataRoute:o!=null},children:v})};return o&&(f.route.ErrorBoundary||f.route.errorElement||m===0)?_e(nv,{location:o.location,revalidation:o.revalidation,component:x,error:h,children:w(),routeContext:{outlet:null,matches:y,isDataRoute:!0},onError:d}):w()},null)}function Xd(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function OR(e){let t=Ne(oo);return Qe(t,Xd(e)),t}function BR(e){let t=Ne(Ya);return Qe(t,Xd(e)),t}function zR(e){let t=Ne(_t);return Qe(t,Xd(e)),t}function Jd(e){let t=zR(e),n=t.matches[t.matches.length-1];return Qe(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function FR(){return Jd("useRouteId")}function jR(){let e=Ne(Yd),t=BR("useRouteError"),n=Jd("useRouteError");return e!==void 0?e:t.errors?.[n]}function HR(){let{router:e}=OR("useNavigate"),t=Jd("useNavigate"),n=ne(!1);return ev(()=>{n.current=!0}),U(async(s,a={})=>{Et(n.current,J0),n.current&&(typeof s=="number"?await e.navigate(s):await e.navigate(s,{fromRouteId:t,...a}))},[e,t])}var Up={};function rv(e,t,n){!t&&!Up[e]&&(Up[e]=!0,Et(!1,n))}je(VR);function VR({routes:e,manifest:t,future:n,state:o,isStatic:s,onError:a}){return tv(e,void 0,{manifest:t,state:o,isStatic:s,onError:a})}function ht({to:e,replace:t,state:n,relative:o}){Qe(so(),"<Navigate> may be used only in the context of a <Router> component.");let{static:s}=Ne(Nt);Et(!s,"<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.");let{matches:a}=Ne(_t),{pathname:i}=kt(),l=at(),c=Ka(e,Kd(a),i,o==="path"),d=JSON.stringify(c);return J(()=>{l(JSON.parse(d),{replace:t,state:n,relative:o})},[l,d,o,t,n]),null}function UR(e){return PR(e.context)}function Te(e){Qe(!1,"A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.")}function qR({basename:e="/",children:t=null,location:n,navigationType:o="POP",navigator:s,static:a=!1,useTransitions:i}){Qe(!so(),"You cannot render a <Router> inside another <Router>. You should never have more than one in your app.");let l=e.replace(/^\/*/,"/"),c=q(()=>({basename:l,navigator:s,static:a,useTransitions:i,future:{}}),[l,s,a,i]);typeof n=="string"&&(n=ro(n));let{pathname:d="/",search:p="",hash:f="",state:m=null,key:h="default",mask:g}=n,x=q(()=>{let b=gn(d,l);return b==null?null:{location:{pathname:b,search:p,hash:f,state:m,key:h,mask:g},navigationType:o}},[l,d,p,f,m,h,o,g]);return Et(x!=null,`<Router basename="${l}"> is not able to match the URL "${d}${p}${f}" because it does not start with the basename, so the <Router> won't render anything.`),x==null?null:_e(Nt.Provider,{value:c},_e(ts.Provider,{children:t,value:x}))}function QR({children:e,location:t}){return _R(Xl(e),t)}function Xl(e,t=[]){let n=[];return ZN.forEach(e,(o,s)=>{if(!XN(o))return;let a=[...t,s];if(o.type===_r){n.push.apply(n,Xl(o.props.children,a));return}Qe(o.type===Te,`[${typeof o.type=="string"?o.type:o.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`),Qe(!o.props.index||!o.props.children,"An index route cannot have child routes.");let i={id:o.props.id||a.join("-"),caseSensitive:o.props.caseSensitive,element:o.props.element,Component:o.props.Component,index:o.props.index,path:o.props.path,middleware:o.props.middleware,loader:o.props.loader,action:o.props.action,hydrateFallbackElement:o.props.hydrateFallbackElement,HydrateFallback:o.props.HydrateFallback,errorElement:o.props.errorElement,ErrorBoundary:o.props.ErrorBoundary,hasErrorBoundary:o.props.hasErrorBoundary===!0||o.props.ErrorBoundary!=null||o.props.errorElement!=null,shouldRevalidate:o.props.shouldRevalidate,handle:o.props.handle,lazy:o.props.lazy};o.props.children&&(i.children=Xl(o.props.children,a)),n.push(i)}),n}var Ys="get",Zs="application/x-www-form-urlencoded";function Za(e){return typeof HTMLElement<"u"&&e instanceof HTMLElement}function GR(e){return Za(e)&&e.tagName.toLowerCase()==="button"}function WR(e){return Za(e)&&e.tagName.toLowerCase()==="form"}function KR(e){return Za(e)&&e.tagName.toLowerCase()==="input"}function YR(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function ZR(e,t){return e.button===0&&(!t||t==="_self")&&!YR(e)}function Jl(e=""){return new URLSearchParams(typeof e=="string"||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let o=e[n];return t.concat(Array.isArray(o)?o.map(s=>[n,s]):[[n,o]])},[]))}function XR(e,t){let n=Jl(e);return t&&t.forEach((o,s)=>{n.has(s)||t.getAll(s).forEach(a=>{n.append(s,a)})}),n}var Es=null;function JR(){if(Es===null)try{new FormData(document.createElement("form"),0),Es=!1}catch{Es=!0}return Es}var e6=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function Wi(e){return e!=null&&!e6.has(e)?(Et(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Zs}"`),null):e}function t6(e,t){let n,o,s,a,i;if(WR(e)){let l=e.getAttribute("action");o=l?gn(l,t):null,n=e.getAttribute("method")||Ys,s=Wi(e.getAttribute("enctype"))||Zs,a=new FormData(e)}else if(GR(e)||KR(e)&&(e.type==="submit"||e.type==="image")){let l=e.form;if(l==null)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');let c=e.getAttribute("formaction")||l.getAttribute("action");if(o=c?gn(c,t):null,n=e.getAttribute("formmethod")||l.getAttribute("method")||Ys,s=Wi(e.getAttribute("formenctype"))||Wi(l.getAttribute("enctype"))||Zs,a=new FormData(l,e),!JR()){let{name:d,type:p,value:f}=e;if(p==="image"){let m=d?`${d}.`:"";a.append(`${m}x`,"0"),a.append(`${m}y`,"0")}else d&&a.append(d,f)}}else{if(Za(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');n=Ys,o=null,s=Zs,i=e}return a&&s==="text/plain"&&(i=a,a=void 0),{action:o,method:n.toLowerCase(),encType:s,formData:a,body:i}}Object.getOwnPropertyNames(Object.prototype).sort().join("\0");function eu(e,t){if(e===!1||e===null||typeof e>"u")throw new Error(t)}function ov(e,t,n,o){let s=typeof e=="string"?new URL(e,typeof window>"u"?"server://singlefetch/":window.location.origin):e;return n?s.pathname.endsWith("/")?s.pathname=`${s.pathname}_.${o}`:s.pathname=`${s.pathname}.${o}`:s.pathname==="/"?s.pathname=`_root.${o}`:t&&gn(s.pathname,t)==="/"?s.pathname=`${fa(t)}/_root.${o}`:s.pathname=`${fa(s.pathname)}.${o}`,s}async function n6(e,t){if(e.id in t)return t[e.id];try{let n=await import(e.module);return t[e.id]=n,n}catch(n){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(n),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function r6(e){return e==null?!1:e.href==null?e.rel==="preload"&&typeof e.imageSrcSet=="string"&&typeof e.imageSizes=="string":typeof e.rel=="string"&&typeof e.href=="string"}async function o6(e,t,n){let o=await Promise.all(e.map(async s=>{let a=t.routes[s.route.id];if(a){let i=await n6(a,n);return i.links?i.links():[]}return[]}));return l6(o.flat(1).filter(r6).filter(s=>s.rel==="stylesheet"||s.rel==="preload").map(s=>s.rel==="stylesheet"?{...s,rel:"prefetch",as:"style"}:{...s,rel:"prefetch"}))}function qp(e,t,n,o,s,a){let i=(c,d)=>n[d]?c.route.id!==n[d].route.id:!0,l=(c,d)=>n[d].pathname!==c.pathname||n[d].route.path?.endsWith("*")&&n[d].params["*"]!==c.params["*"];return a==="assets"?t.filter((c,d)=>i(c,d)||l(c,d)):a==="data"?t.filter((c,d)=>{let p=o.routes[c.route.id];if(!p||!p.hasLoader)return!1;if(i(c,d)||l(c,d))return!0;if(c.route.shouldRevalidate){let f=c.route.shouldRevalidate({currentUrl:new URL(s.pathname+s.search+s.hash,window.origin),currentParams:n[0]?.params||{},nextUrl:new URL(e,window.origin),nextParams:c.params,defaultShouldRevalidate:!0});if(typeof f=="boolean")return f}return!0}):[]}function s6(e,t,{includeHydrateFallback:n}={}){return a6(e.map(o=>{let s=t.routes[o.route.id];if(!s)return[];let a=[s.module];return s.clientActionModule&&(a=a.concat(s.clientActionModule)),s.clientLoaderModule&&(a=a.concat(s.clientLoaderModule)),n&&s.hydrateFallbackModule&&(a=a.concat(s.hydrateFallbackModule)),s.imports&&(a=a.concat(s.imports)),a}).flat(1))}function a6(e){return[...new Set(e)]}function i6(e){let t={},n=Object.keys(e).sort();for(let o of n)t[o]=e[o];return t}function l6(e,t){let n=new Set;return new Set(t),e.reduce((o,s)=>{let a=JSON.stringify(i6(s));return n.has(a)||(n.add(a),o.push({key:a,link:s})),o},[])}function tu(){let e=Ne(oo);return eu(e,"You must render this element inside a <DataRouterContext.Provider> element"),e}function c6(){let e=Ne(Ya);return eu(e,"You must render this element inside a <DataRouterStateContext.Provider> element"),e}var nu=qe(void 0);nu.displayName="FrameworkContext";function ru(){let e=Ne(nu);return eu(e,"You must render this element inside a <HydratedRouter> element"),e}function d6(e,t){let n=Ne(nu),[o,s]=I(!1),[a,i]=I(!1),{onFocus:l,onBlur:c,onMouseEnter:d,onMouseLeave:p,onTouchStart:f}=t,m=ne(null);J(()=>{if(e==="render"&&i(!0),e==="viewport"){let x=y=>{y.forEach(w=>{i(w.isIntersecting)})},b=new IntersectionObserver(x,{threshold:.5});return m.current&&b.observe(m.current),()=>{b.disconnect()}}},[e]),J(()=>{if(o){let x=setTimeout(()=>{i(!0)},100);return()=>{clearTimeout(x)}}},[o]);let h=()=>{s(!0)},g=()=>{s(!1),i(!1)};return n?e!=="intent"?[a,m,{}]:[a,m,{onFocus:fo(l,h),onBlur:fo(c,g),onMouseEnter:fo(d,h),onMouseLeave:fo(p,g),onTouchStart:fo(f,h)}]:[!1,m,{}]}function fo(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function u6({page:e,...t}){let n=vR(),{router:o}=tu(),s=q(()=>V0(o.routes,e,o.basename),[o.routes,e,o.basename]);return s?n?_e(f6,{page:e,matches:s,...t}):_e(m6,{page:e,matches:s,...t}):null}function p6(e){let{manifest:t,routeModules:n}=ru(),[o,s]=I([]);return J(()=>{let a=!1;return o6(e,t,n).then(i=>{a||s(i)}),()=>{a=!0}},[e,t,n]),o}function f6({page:e,matches:t,...n}){let o=kt(),{future:s}=ru(),{basename:a}=tu(),i=q(()=>{if(e===o.pathname+o.search+o.hash)return[];let l=ov(e,a,s.unstable_trailingSlashAwareDataRequests,"rsc"),c=!1,d=[];for(let p of t)typeof p.route.shouldRevalidate=="function"?c=!0:d.push(p.route.id);return c&&d.length>0&&l.searchParams.set("_routes",d.join(",")),[l.pathname+l.search]},[a,s.unstable_trailingSlashAwareDataRequests,e,o,t]);return _e(_r,null,i.map(l=>_e("link",{key:l,rel:"prefetch",as:"fetch",href:l,...n})))}function m6({page:e,matches:t,...n}){let o=kt(),{future:s,manifest:a,routeModules:i}=ru(),{basename:l}=tu(),{loaderData:c,matches:d}=c6(),p=q(()=>qp(e,t,d,a,o,"data"),[e,t,d,a,o]),f=q(()=>qp(e,t,d,a,o,"assets"),[e,t,d,a,o]),m=q(()=>{if(e===o.pathname+o.search+o.hash)return[];let x=new Set,b=!1;if(t.forEach(w=>{let v=a.routes[w.route.id];!v||!v.hasLoader||(!p.some(N=>N.route.id===w.route.id)&&w.route.id in c&&i[w.route.id]?.shouldRevalidate||v.hasClientLoader?b=!0:x.add(w.route.id))}),x.size===0)return[];let y=ov(e,l,s.unstable_trailingSlashAwareDataRequests,"data");return b&&x.size>0&&y.searchParams.set("_routes",t.filter(w=>x.has(w.route.id)).map(w=>w.route.id).join(",")),[y.pathname+y.search]},[l,s.unstable_trailingSlashAwareDataRequests,c,o,a,p,t,e,i]),h=q(()=>s6(f,a),[f,a]),g=p6(f);return _e(_r,null,m.map(x=>_e("link",{key:x,rel:"prefetch",as:"fetch",href:x,...n})),h.map(x=>_e("link",{key:x,rel:"modulepreload",href:x,...n})),g.map(({key:x,link:b})=>_e("link",{key:x,nonce:n.nonce,...b,crossOrigin:b.crossOrigin??n.crossOrigin})))}function h6(...e){return t=>{e.forEach(n=>{typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var g6=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";try{g6&&(window.__reactRouterVersion="7.15.0")}catch{}function b6({basename:e,children:t,useTransitions:n,window:o}){let s=ne();s.current==null&&(s.current=QT({window:o,v5Compat:!0}));let a=s.current,[i,l]=I({action:a.action,location:a.location}),c=U(d=>{n===!1?l(d):Lc(()=>l(d))},[n]);return Ra(()=>a.listen(c),[a,c]),_e(qR,{basename:e,children:t,location:i.location,navigationType:i.action,navigator:a,useTransitions:n})}var sv=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,ma=Ke(function({onClick:t,discover:n="render",prefetch:o="none",relative:s,reloadDocument:a,replace:i,mask:l,state:c,target:d,to:p,preventScrollReset:f,viewTransition:m,defaultShouldRevalidate:h,...g},x){let{basename:b,navigator:y,useTransitions:w}=Ne(Nt),v=typeof p=="string"&&sv.test(p),N=W0(p,b);p=N.to;let k=AR(p,{relative:s}),C=kt(),D=null;if(l){let P=Ka(l,[],C.mask?C.mask.pathname:"/",!0);b!=="/"&&(P.pathname=P.pathname==="/"?b:zt([b,P.pathname])),D=y.createHref(P)}let[M,_,$]=d6(o,g),E=w6(p,{replace:i,mask:l,state:c,target:d,preventScrollReset:f,relative:s,viewTransition:m,defaultShouldRevalidate:h,useTransitions:w});function R(P){t&&t(P),P.defaultPrevented||E(P)}let O=!(N.isExternal||a),A=_e("a",{...g,...$,href:(O?D:void 0)||N.absoluteURL||k,onClick:O?R:t,ref:h6(x,_),target:d,"data-discover":!v&&n==="render"?"true":void 0});return M&&!v?_e(_r,null,A,_e(u6,{page:k})):A});ma.displayName="Link";var x6=Ke(function({"aria-current":t="page",caseSensitive:n=!1,className:o="",end:s=!1,style:a,to:i,viewTransition:l,children:c,...d},p){let f=ns(i,{relative:d.relative}),m=kt(),h=Ne(Ya),{navigator:g,basename:x}=Ne(Nt),b=h!=null&&M6(f)&&l===!0,y=g.encodeLocation?g.encodeLocation(f).pathname:f.pathname,w=m.pathname,v=h&&h.navigation&&h.navigation.location?h.navigation.location.pathname:null;n||(w=w.toLowerCase(),v=v?v.toLowerCase():null,y=y.toLowerCase()),v&&x&&(v=gn(v,x)||v);const N=y!=="/"&&y.endsWith("/")?y.length-1:y.length;let k=w===y||!s&&w.startsWith(y)&&w.charAt(N)==="/",C=v!=null&&(v===y||!s&&v.startsWith(y)&&v.charAt(y.length)==="/"),D={isActive:k,isPending:C,isTransitioning:b},M=k?t:void 0,_;typeof o=="function"?_=o(D):_=[o,k?"active":null,C?"pending":null,b?"transitioning":null].filter(Boolean).join(" ");let $=typeof a=="function"?a(D):a;return _e(ma,{...d,"aria-current":M,className:_,ref:p,style:$,to:i,viewTransition:l},typeof c=="function"?c(D):c)});x6.displayName="NavLink";var y6=Ke(({discover:e="render",fetcherKey:t,navigate:n,reloadDocument:o,replace:s,state:a,method:i=Ys,action:l,onSubmit:c,relative:d,preventScrollReset:p,viewTransition:f,defaultShouldRevalidate:m,...h},g)=>{let{useTransitions:x}=Ne(Nt),b=S6(),y=C6(l,{relative:d}),w=i.toLowerCase()==="get"?"get":"post",v=typeof l=="string"&&sv.test(l);return _e("form",{ref:g,method:w,action:y,onSubmit:o?c:k=>{if(c&&c(k),k.defaultPrevented)return;k.preventDefault();let C=k.nativeEvent.submitter,D=C?.getAttribute("formmethod")||i,M=()=>b(C||k.currentTarget,{fetcherKey:t,method:D,navigate:n,replace:s,state:a,relative:d,preventScrollReset:p,viewTransition:f,defaultShouldRevalidate:m});x&&n!==!1?Lc(()=>M()):M()},...h,"data-discover":!v&&e==="render"?"true":void 0})});y6.displayName="Form";function v6(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function av(e){let t=Ne(oo);return Qe(t,v6(e)),t}function w6(e,{target:t,replace:n,mask:o,state:s,preventScrollReset:a,relative:i,viewTransition:l,defaultShouldRevalidate:c,useTransitions:d}={}){let p=at(),f=kt(),m=ns(e,{relative:i});return U(h=>{if(ZR(h,t)){h.preventDefault();let g=n!==void 0?n:Oo(f)===Oo(m),x=()=>p(e,{replace:g,mask:o,state:s,preventScrollReset:a,relative:i,viewTransition:l,defaultShouldRevalidate:c});d?Lc(()=>x()):x()}},[f,p,m,n,o,s,t,e,a,i,l,c,d])}function Xa(e){Et(typeof URLSearchParams<"u","You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let t=ne(Jl(e)),n=ne(!1),o=kt(),s=q(()=>XR(o.search,n.current?null:t.current),[o.search]),a=at(),i=U((l,c)=>{const d=Jl(typeof l=="function"?l(new URLSearchParams(s)):l);n.current=!0,a("?"+d,c)},[a,s]);return[s,i]}var N6=0,k6=()=>`__${String(++N6)}__`;function S6(){let{router:e}=av("useSubmit"),{basename:t}=Ne(Nt),n=FR(),o=e.fetch,s=e.navigate;return U(async(a,i={})=>{let{action:l,method:c,encType:d,formData:p,body:f}=t6(a,t);if(i.navigate===!1){let m=i.fetcherKey||k6();await o(m,n,i.action||l,{defaultShouldRevalidate:i.defaultShouldRevalidate,preventScrollReset:i.preventScrollReset,formData:p,body:f,formMethod:i.method||c,formEncType:i.encType||d,flushSync:i.flushSync})}else await s(i.action||l,{defaultShouldRevalidate:i.defaultShouldRevalidate,preventScrollReset:i.preventScrollReset,formData:p,body:f,formMethod:i.method||c,formEncType:i.encType||d,replace:i.replace,state:i.state,fromRouteId:n,flushSync:i.flushSync,viewTransition:i.viewTransition})},[o,s,t,n])}function C6(e,{relative:t}={}){let{basename:n}=Ne(Nt),o=Ne(_t);Qe(o,"useFormAction must be used inside a RouteContext");let[s]=o.matches.slice(-1),a={...ns(e||".",{relative:t})},i=kt();if(e==null){a.search=i.search;let l=new URLSearchParams(a.search),c=l.getAll("index");if(c.some(p=>p==="")){l.delete("index"),c.filter(f=>f).forEach(f=>l.append("index",f));let p=l.toString();a.search=p?`?${p}`:""}}return(!e||e===".")&&s.route.index&&(a.search=a.search?a.search.replace(/^\?/,"?index&"):"?index"),n!=="/"&&(a.pathname=a.pathname==="/"?n:zt([n,a.pathname])),Oo(a)}function M6(e,{relative:t}={}){let n=Ne(Z0);Qe(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:o}=av("useViewTransitionState"),s=ns(e,{relative:t});if(!n.isTransitioning)return!1;let a=gn(n.currentLocation.pathname,o)||n.currentLocation.pathname,i=gn(n.nextLocation.pathname,o)||n.nextLocation.pathname;return pa(s.pathname,i)!=null||pa(s.pathname,a)!=null}const A6=3e4;function E6(e){const t=ne(e);t.current=e,J(()=>{let n=null;const o=()=>{if(document.visibilityState==="hidden"){n=Date.now();return}if(document.visibilityState==="visible"&&n!==null){const i=Date.now()-n;n=null,i>=A6&&t.current()}},s=()=>{t.current()},a=i=>{i.persisted&&t.current()};return document.addEventListener("visibilitychange",o),window.addEventListener("online",s),window.addEventListener("pageshow",a),()=>{document.removeEventListener("visibilitychange",o),window.removeEventListener("online",s),window.removeEventListener("pageshow",a)}},[])}let ec="disconnected";const tc=new Set;function I6(){for(const e of tc)e()}function P6(e){ec!==e&&(ec=e,I6())}function _6(e){return tc.add(e),()=>{tc.delete(e)}}function Qp(){return ec}function $6(){return Oa(_6,Qp,Qp)}let Co=null;function Xs(){if(!Co){const e=window.location.origin,t=localStorage.getItem("camstack_admin_token")??void 0;Co=uh({serverUrl:e,token:t,onConnectionChange:n=>P6(n)})}return Co}function Nr(){Co?.close(),Co=null}/**
598
+ * @license lucide-react v0.511.0 - ISC
599
+ *
600
+ * This source code is licensed under the ISC license.
601
+ * See the LICENSE file in the root directory of this source tree.
602
+ */const D6=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),L6=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,o)=>o?o.toUpperCase():n.toLowerCase()),Gp=e=>{const t=L6(e);return t.charAt(0).toUpperCase()+t.slice(1)},iv=(...e)=>e.filter((t,n,o)=>!!t&&t.trim()!==""&&o.indexOf(t)===n).join(" ").trim(),T6=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};/**
603
+ * @license lucide-react v0.511.0 - ISC
604
+ *
605
+ * This source code is licensed under the ISC license.
606
+ * See the LICENSE file in the root directory of this source tree.
607
+ */var R6={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
608
+ * @license lucide-react v0.511.0 - ISC
609
+ *
610
+ * This source code is licensed under the ISC license.
611
+ * See the LICENSE file in the root directory of this source tree.
612
+ */const O6=Ke(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:o,className:s="",children:a,iconNode:i,...l},c)=>_e("svg",{ref:c,...R6,width:t,height:t,stroke:e,strokeWidth:o?Number(n)*24/Number(t):n,className:iv("lucide",s),...!a&&!T6(l)&&{"aria-hidden":"true"},...l},[...i.map(([d,p])=>_e(d,p)),...Array.isArray(a)?a:[a]]));/**
613
+ * @license lucide-react v0.511.0 - ISC
614
+ *
615
+ * This source code is licensed under the ISC license.
616
+ * See the LICENSE file in the root directory of this source tree.
617
+ */const ae=(e,t)=>{const n=Ke(({className:o,...s},a)=>_e(O6,{ref:a,iconNode:t,className:iv(`lucide-${D6(Gp(e))}`,`lucide-${e}`,o),...s}));return n.displayName=Gp(e),n};/**
618
+ * @license lucide-react v0.511.0 - ISC
619
+ *
620
+ * This source code is licensed under the ISC license.
621
+ * See the LICENSE file in the root directory of this source tree.
622
+ */const B6=[["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"}]],Ja=ae("activity",B6);/**
623
+ * @license lucide-react v0.511.0 - ISC
624
+ *
625
+ * This source code is licensed under the ISC license.
626
+ * See the LICENSE file in the root directory of this source tree.
627
+ */const z6=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],lv=ae("archive",z6);/**
628
+ * @license lucide-react v0.511.0 - ISC
629
+ *
630
+ * This source code is licensed under the ISC license.
631
+ * See the LICENSE file in the root directory of this source tree.
632
+ */const F6=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],ou=ae("arrow-left",F6);/**
633
+ * @license lucide-react v0.511.0 - ISC
634
+ *
635
+ * This source code is licensed under the ISC license.
636
+ * See the LICENSE file in the root directory of this source tree.
637
+ */const j6=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],H6=ae("arrow-right",j6);/**
638
+ * @license lucide-react v0.511.0 - ISC
639
+ *
640
+ * This source code is licensed under the ISC license.
641
+ * See the LICENSE file in the root directory of this source tree.
642
+ */const V6=[["rect",{width:"16",height:"10",x:"2",y:"7",rx:"2",ry:"2",key:"1w10f2"}],["line",{x1:"22",x2:"22",y1:"11",y2:"13",key:"4dh1rd"}],["line",{x1:"6",x2:"6",y1:"11",y2:"13",key:"1wd6dw"}],["line",{x1:"10",x2:"10",y1:"11",y2:"13",key:"haxvl5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"13",key:"c6fn6x"}]],U6=ae("battery-full",V6);/**
643
+ * @license lucide-react v0.511.0 - ISC
644
+ *
645
+ * This source code is licensed under the ISC license.
646
+ * See the LICENSE file in the root directory of this source tree.
647
+ */const q6=[["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"}]],rs=ae("bell",q6);/**
648
+ * @license lucide-react v0.511.0 - ISC
649
+ *
650
+ * This source code is licensed under the ISC license.
651
+ * See the LICENSE file in the root directory of this source tree.
652
+ */const Q6=[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}]],G6=ae("book-open",Q6);/**
653
+ * @license lucide-react v0.511.0 - ISC
654
+ *
655
+ * This source code is licensed under the ISC license.
656
+ * See the LICENSE file in the root directory of this source tree.
657
+ */const W6=[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]],K6=ae("bot",W6);/**
658
+ * @license lucide-react v0.511.0 - ISC
659
+ *
660
+ * This source code is licensed under the ISC license.
661
+ * See the LICENSE file in the root directory of this source tree.
662
+ */const Y6=[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]],su=ae("box",Y6);/**
663
+ * @license lucide-react v0.511.0 - ISC
664
+ *
665
+ * This source code is licensed under the ISC license.
666
+ * See the LICENSE file in the root directory of this source tree.
667
+ */const Z6=[["path",{d:"M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z",key:"lc1i9w"}],["path",{d:"m7 16.5-4.74-2.85",key:"1o9zyk"}],["path",{d:"m7 16.5 5-3",key:"va8pkn"}],["path",{d:"M7 16.5v5.17",key:"jnp8gn"}],["path",{d:"M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z",key:"8zsnat"}],["path",{d:"m17 16.5-5-3",key:"8arw3v"}],["path",{d:"m17 16.5 4.74-2.85",key:"8rfmw"}],["path",{d:"M17 16.5v5.17",key:"k6z78m"}],["path",{d:"M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z",key:"1xygjf"}],["path",{d:"M12 8 7.26 5.15",key:"1vbdud"}],["path",{d:"m12 8 4.74-2.85",key:"3rx089"}],["path",{d:"M12 13.5V8",key:"1io7kd"}]],ei=ae("boxes",Z6);/**
668
+ * @license lucide-react v0.511.0 - ISC
669
+ *
670
+ * This source code is licensed under the ISC license.
671
+ * See the LICENSE file in the root directory of this source tree.
672
+ */const X6=[["path",{d:"M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5",key:"1osxxc"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M3 10h5",key:"r794hk"}],["path",{d:"M17.5 17.5 16 16.3V14",key:"akvzfd"}],["circle",{cx:"16",cy:"16",r:"6",key:"qoo3c4"}]],J6=ae("calendar-clock",X6);/**
673
+ * @license lucide-react v0.511.0 - ISC
674
+ *
675
+ * This source code is licensed under the ISC license.
676
+ * See the LICENSE file in the root directory of this source tree.
677
+ */const eO=[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}]],cv=ae("calendar",eO);/**
678
+ * @license lucide-react v0.511.0 - ISC
679
+ *
680
+ * This source code is licensed under the ISC license.
681
+ * See the LICENSE file in the root directory of this source tree.
682
+ */const tO=[["path",{d:"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z",key:"1tc9qg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]],Rr=ae("camera",tO);/**
683
+ * @license lucide-react v0.511.0 - ISC
684
+ *
685
+ * This source code is licensed under the ISC license.
686
+ * See the LICENSE file in the root directory of this source tree.
687
+ */const nO=[["path",{d:"M16.75 12h3.632a1 1 0 0 1 .894 1.447l-2.034 4.069a1 1 0 0 1-1.708.134l-2.124-2.97",key:"ir91b5"}],["path",{d:"M17.106 9.053a1 1 0 0 1 .447 1.341l-3.106 6.211a1 1 0 0 1-1.342.447L3.61 12.3a2.92 2.92 0 0 1-1.3-3.91L3.69 5.6a2.92 2.92 0 0 1 3.92-1.3z",key:"jlp8i1"}],["path",{d:"M2 19h3.76a2 2 0 0 0 1.8-1.1L9 15",key:"19bib8"}],["path",{d:"M2 21v-4",key:"l40lih"}],["path",{d:"M7 9h.01",key:"19b3jx"}]],dv=ae("cctv",nO);/**
688
+ * @license lucide-react v0.511.0 - ISC
689
+ *
690
+ * This source code is licensed under the ISC license.
691
+ * See the LICENSE file in the root directory of this source tree.
692
+ */const rO=[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]],oO=ae("check-check",rO);/**
693
+ * @license lucide-react v0.511.0 - ISC
694
+ *
695
+ * This source code is licensed under the ISC license.
696
+ * See the LICENSE file in the root directory of this source tree.
697
+ */const sO=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],St=ae("check",sO);/**
698
+ * @license lucide-react v0.511.0 - ISC
699
+ *
700
+ * This source code is licensed under the ISC license.
701
+ * See the LICENSE file in the root directory of this source tree.
702
+ */const aO=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],en=ae("chevron-down",aO);/**
703
+ * @license lucide-react v0.511.0 - ISC
704
+ *
705
+ * This source code is licensed under the ISC license.
706
+ * See the LICENSE file in the root directory of this source tree.
707
+ */const iO=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],au=ae("chevron-left",iO);/**
708
+ * @license lucide-react v0.511.0 - ISC
709
+ *
710
+ * This source code is licensed under the ISC license.
711
+ * See the LICENSE file in the root directory of this source tree.
712
+ */const lO=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],on=ae("chevron-right",lO);/**
713
+ * @license lucide-react v0.511.0 - ISC
714
+ *
715
+ * This source code is licensed under the ISC license.
716
+ * See the LICENSE file in the root directory of this source tree.
717
+ */const cO=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],dO=ae("chevron-up",cO);/**
718
+ * @license lucide-react v0.511.0 - ISC
719
+ *
720
+ * This source code is licensed under the ISC license.
721
+ * See the LICENSE file in the root directory of this source tree.
722
+ */const uO=[["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"}]],nr=ae("circle-alert",uO);/**
723
+ * @license lucide-react v0.511.0 - ISC
724
+ *
725
+ * This source code is licensed under the ISC license.
726
+ * See the LICENSE file in the root directory of this source tree.
727
+ */const pO=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],Zn=ae("circle-check-big",pO);/**
728
+ * @license lucide-react v0.511.0 - ISC
729
+ *
730
+ * This source code is licensed under the ISC license.
731
+ * See the LICENSE file in the root directory of this source tree.
732
+ */const fO=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],ti=ae("circle-check",fO);/**
733
+ * @license lucide-react v0.511.0 - ISC
734
+ *
735
+ * This source code is licensed under the ISC license.
736
+ * See the LICENSE file in the root directory of this source tree.
737
+ */const mO=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]],uv=ae("circle-dot",mO);/**
738
+ * @license lucide-react v0.511.0 - ISC
739
+ *
740
+ * This source code is licensed under the ISC license.
741
+ * See the LICENSE file in the root directory of this source tree.
742
+ */const hO=[["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"}]],gO=ae("circle-help",hO);/**
743
+ * @license lucide-react v0.511.0 - ISC
744
+ *
745
+ * This source code is licensed under the ISC license.
746
+ * See the LICENSE file in the root directory of this source tree.
747
+ */const bO=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]],pv=ae("clock",bO);/**
748
+ * @license lucide-react v0.511.0 - ISC
749
+ *
750
+ * This source code is licensed under the ISC license.
751
+ * See the LICENSE file in the root directory of this source tree.
752
+ */const xO=[["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"}]],ha=ae("copy",xO);/**
753
+ * @license lucide-react v0.511.0 - ISC
754
+ *
755
+ * This source code is licensed under the ISC license.
756
+ * See the LICENSE file in the root directory of this source tree.
757
+ */const yO=[["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"}]],jt=ae("cpu",yO);/**
758
+ * @license lucide-react v0.511.0 - ISC
759
+ *
760
+ * This source code is licensed under the ISC license.
761
+ * See the LICENSE file in the root directory of this source tree.
762
+ */const vO=[["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"}]],fv=ae("database",vO);/**
763
+ * @license lucide-react v0.511.0 - ISC
764
+ *
765
+ * This source code is licensed under the ISC license.
766
+ * See the LICENSE file in the root directory of this source tree.
767
+ */const wO=[["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"}]],bn=ae("download",wO);/**
768
+ * @license lucide-react v0.511.0 - ISC
769
+ *
770
+ * This source code is licensed under the ISC license.
771
+ * See the LICENSE file in the root directory of this source tree.
772
+ */const NO=[["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"}]],kO=ae("ellipsis-vertical",NO);/**
773
+ * @license lucide-react v0.511.0 - ISC
774
+ *
775
+ * This source code is licensed under the ISC license.
776
+ * See the LICENSE file in the root directory of this source tree.
777
+ */const SO=[["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"}]],iu=ae("external-link",SO);/**
778
+ * @license lucide-react v0.511.0 - ISC
779
+ *
780
+ * This source code is licensed under the ISC license.
781
+ * See the LICENSE file in the root directory of this source tree.
782
+ */const CO=[["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"}]],mv=ae("eye-off",CO);/**
783
+ * @license lucide-react v0.511.0 - ISC
784
+ *
785
+ * This source code is licensed under the ISC license.
786
+ * See the LICENSE file in the root directory of this source tree.
787
+ */const MO=[["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"}]],ni=ae("eye",MO);/**
788
+ * @license lucide-react v0.511.0 - ISC
789
+ *
790
+ * This source code is licensed under the ISC license.
791
+ * See the LICENSE file in the root directory of this source tree.
792
+ */const AO=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M7 3v18",key:"bbkbws"}],["path",{d:"M3 7.5h4",key:"zfgn84"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 16.5h4",key:"1230mu"}],["path",{d:"M17 3v18",key:"in4fa5"}],["path",{d:"M17 7.5h4",key:"myr1c1"}],["path",{d:"M17 16.5h4",key:"go4c1d"}]],Mo=ae("film",AO);/**
793
+ * @license lucide-react v0.511.0 - ISC
794
+ *
795
+ * This source code is licensed under the ISC license.
796
+ * See the LICENSE file in the root directory of this source tree.
797
+ */const EO=[["path",{d:"M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z",key:"96xj49"}]],IO=ae("flame",EO);/**
798
+ * @license lucide-react v0.511.0 - ISC
799
+ *
800
+ * This source code is licensed under the ISC license.
801
+ * See the LICENSE file in the root directory of this source tree.
802
+ */const PO=[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]],_O=ae("gauge",PO);/**
803
+ * @license lucide-react v0.511.0 - ISC
804
+ *
805
+ * This source code is licensed under the ISC license.
806
+ * See the LICENSE file in the root directory of this source tree.
807
+ */const $O=[["path",{d:"M9 10h.01",key:"qbtxuw"}],["path",{d:"M15 10h.01",key:"1qmjsl"}],["path",{d:"M12 2a8 8 0 0 0-8 8v12l3-3 2.5 2.5L12 19l2.5 2.5L17 19l3 3V10a8 8 0 0 0-8-8z",key:"uwwb07"}]],nc=ae("ghost",$O);/**
808
+ * @license lucide-react v0.511.0 - ISC
809
+ *
810
+ * This source code is licensed under the ISC license.
811
+ * See the LICENSE file in the root directory of this source tree.
812
+ */const DO=[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]],LO=ae("git-branch",DO);/**
813
+ * @license lucide-react v0.511.0 - ISC
814
+ *
815
+ * This source code is licensed under the ISC license.
816
+ * See the LICENSE file in the root directory of this source tree.
817
+ */const TO=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],Ln=ae("globe",TO);/**
818
+ * @license lucide-react v0.511.0 - ISC
819
+ *
820
+ * This source code is licensed under the ISC license.
821
+ * See the LICENSE file in the root directory of this source tree.
822
+ */const RO=[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["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"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]],ga=ae("hard-drive",RO);/**
823
+ * @license lucide-react v0.511.0 - ISC
824
+ *
825
+ * This source code is licensed under the ISC license.
826
+ * See the LICENSE file in the root directory of this source tree.
827
+ */const OO=[["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-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]],BO=ae("house",OO);/**
828
+ * @license lucide-react v0.511.0 - ISC
829
+ *
830
+ * This source code is licensed under the ISC license.
831
+ * See the LICENSE file in the root directory of this source tree.
832
+ */const zO=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],rr=ae("info",zO);/**
833
+ * @license lucide-react v0.511.0 - ISC
834
+ *
835
+ * This source code is licensed under the ISC license.
836
+ * See the LICENSE file in the root directory of this source tree.
837
+ */const FO=[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]],hv=ae("key-round",FO);/**
838
+ * @license lucide-react v0.511.0 - ISC
839
+ *
840
+ * This source code is licensed under the ISC license.
841
+ * See the LICENSE file in the root directory of this source tree.
842
+ */const jO=[["path",{d:"M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z",key:"165ttr"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814",key:"1ubxi2"}]],HO=ae("key-square",jO);/**
843
+ * @license lucide-react v0.511.0 - ISC
844
+ *
845
+ * This source code is licensed under the ISC license.
846
+ * See the LICENSE file in the root directory of this source tree.
847
+ */const VO=[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]],UO=ae("key",VO);/**
848
+ * @license lucide-react v0.511.0 - ISC
849
+ *
850
+ * This source code is licensed under the ISC license.
851
+ * See the LICENSE file in the root directory of this source tree.
852
+ */const qO=[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",key:"zw3jo"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",key:"1wduqc"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",key:"kqbvx6"}]],QO=ae("layers",qO);/**
853
+ * @license lucide-react v0.511.0 - ISC
854
+ *
855
+ * This source code is licensed under the ISC license.
856
+ * See the LICENSE file in the root directory of this source tree.
857
+ */const GO=[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]],gv=ae("layout-dashboard",GO);/**
858
+ * @license lucide-react v0.511.0 - ISC
859
+ *
860
+ * This source code is licensed under the ISC license.
861
+ * See the LICENSE file in the root directory of this source tree.
862
+ */const WO=[["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"}]],KO=ae("lightbulb",WO);/**
863
+ * @license lucide-react v0.511.0 - ISC
864
+ *
865
+ * This source code is licensed under the ISC license.
866
+ * See the LICENSE file in the root directory of this source tree.
867
+ */const YO=[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]],bv=ae("link",YO);/**
868
+ * @license lucide-react v0.511.0 - ISC
869
+ *
870
+ * This source code is licensed under the ISC license.
871
+ * See the LICENSE file in the root directory of this source tree.
872
+ */const ZO=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],Ee=ae("loader-circle",ZO);/**
873
+ * @license lucide-react v0.511.0 - ISC
874
+ *
875
+ * This source code is licensed under the ISC license.
876
+ * See the LICENSE file in the root directory of this source tree.
877
+ */const XO=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]],ri=ae("lock",XO);/**
878
+ * @license lucide-react v0.511.0 - ISC
879
+ *
880
+ * This source code is licensed under the ISC license.
881
+ * See the LICENSE file in the root directory of this source tree.
882
+ */const JO=[["path",{d:"m10 17 5-5-5-5",key:"1bsop3"}],["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}]],e8=ae("log-in",JO);/**
883
+ * @license lucide-react v0.511.0 - ISC
884
+ *
885
+ * This source code is licensed under the ISC license.
886
+ * See the LICENSE file in the root directory of this source tree.
887
+ */const t8=[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]],lu=ae("log-out",t8);/**
888
+ * @license lucide-react v0.511.0 - ISC
889
+ *
890
+ * This source code is licensed under the ISC license.
891
+ * See the LICENSE file in the root directory of this source tree.
892
+ */const n8=[["path",{d:"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7",key:"132q7q"}],["rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",key:"izxlao"}]],r8=ae("mail",n8);/**
893
+ * @license lucide-react v0.511.0 - ISC
894
+ *
895
+ * This source code is licensed under the ISC license.
896
+ * See the LICENSE file in the root directory of this source tree.
897
+ */const o8=[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0",key:"1r0f0z"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]],s8=ae("map-pin",o8);/**
898
+ * @license lucide-react v0.511.0 - ISC
899
+ *
900
+ * This source code is licensed under the ISC license.
901
+ * See the LICENSE file in the root directory of this source tree.
902
+ */const a8=[["path",{d:"M6 19v-3",key:"1nvgqn"}],["path",{d:"M10 19v-3",key:"iu8nkm"}],["path",{d:"M14 19v-3",key:"kcehxu"}],["path",{d:"M18 19v-3",key:"1vh91z"}],["path",{d:"M8 11V9",key:"63erz4"}],["path",{d:"M16 11V9",key:"fru6f3"}],["path",{d:"M12 11V9",key:"ha00sb"}],["path",{d:"M2 15h20",key:"16ne18"}],["path",{d:"M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z",key:"lhddv3"}]],xv=ae("memory-stick",a8);/**
903
+ * @license lucide-react v0.511.0 - ISC
904
+ *
905
+ * This source code is licensed under the ISC license.
906
+ * See the LICENSE file in the root directory of this source tree.
907
+ */const i8=[["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 18h16",key:"19g7jn"}],["path",{d:"M4 6h16",key:"1o0s65"}]],l8=ae("menu",i8);/**
908
+ * @license lucide-react v0.511.0 - ISC
909
+ *
910
+ * This source code is licensed under the ISC license.
911
+ * See the LICENSE file in the root directory of this source tree.
912
+ */const c8=[["path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z",key:"131961"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}]],rc=ae("mic",c8);/**
913
+ * @license lucide-react v0.511.0 - ISC
914
+ *
915
+ * This source code is licensed under the ISC license.
916
+ * See the LICENSE file in the root directory of this source tree.
917
+ */const d8=[["path",{d:"M5 12h14",key:"1ays0h"}]],u8=ae("minus",d8);/**
918
+ * @license lucide-react v0.511.0 - ISC
919
+ *
920
+ * This source code is licensed under the ISC license.
921
+ * See the LICENSE file in the root directory of this source tree.
922
+ */const p8=[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]],f8=ae("monitor",p8);/**
923
+ * @license lucide-react v0.511.0 - ISC
924
+ *
925
+ * This source code is licensed under the ISC license.
926
+ * See the LICENSE file in the root directory of this source tree.
927
+ */const m8=[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]],yv=ae("moon",m8);/**
928
+ * @license lucide-react v0.511.0 - ISC
929
+ *
930
+ * This source code is licensed under the ISC license.
931
+ * See the LICENSE file in the root directory of this source tree.
932
+ */const h8=[["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"}]],Tn=ae("network",h8);/**
933
+ * @license lucide-react v0.511.0 - ISC
934
+ *
935
+ * This source code is licensed under the ISC license.
936
+ * See the LICENSE file in the root directory of this source tree.
937
+ */const g8=[["path",{d:"M12 16h.01",key:"1drbdi"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z",key:"1fd625"}]],vv=ae("octagon-alert",g8);/**
938
+ * @license lucide-react v0.511.0 - ISC
939
+ *
940
+ * This source code is licensed under the ISC license.
941
+ * See the LICENSE file in the root directory of this source tree.
942
+ */const b8=[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]],wv=ae("package",b8);/**
943
+ * @license lucide-react v0.511.0 - ISC
944
+ *
945
+ * This source code is licensed under the ISC license.
946
+ * See the LICENSE file in the root directory of this source tree.
947
+ */const x8=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],ao=ae("pencil",x8);/**
948
+ * @license lucide-react v0.511.0 - ISC
949
+ *
950
+ * This source code is licensed under the ISC license.
951
+ * See the LICENSE file in the root directory of this source tree.
952
+ */const y8=[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]],Nv=ae("pin",y8);/**
953
+ * @license lucide-react v0.511.0 - ISC
954
+ *
955
+ * This source code is licensed under the ISC license.
956
+ * See the LICENSE file in the root directory of this source tree.
957
+ */const v8=[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]],oi=ae("play",v8);/**
958
+ * @license lucide-react v0.511.0 - ISC
959
+ *
960
+ * This source code is licensed under the ISC license.
961
+ * See the LICENSE file in the root directory of this source tree.
962
+ */const w8=[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M9 8V2",key:"14iosj"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z",key:"osxo6l"}]],Bo=ae("plug",w8);/**
963
+ * @license lucide-react v0.511.0 - ISC
964
+ *
965
+ * This source code is licensed under the ISC license.
966
+ * See the LICENSE file in the root directory of this source tree.
967
+ */const N8=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],It=ae("plus",N8);/**
968
+ * @license lucide-react v0.511.0 - ISC
969
+ *
970
+ * This source code is licensed under the ISC license.
971
+ * See the LICENSE file in the root directory of this source tree.
972
+ */const k8=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],kv=ae("power",k8);/**
973
+ * @license lucide-react v0.511.0 - ISC
974
+ *
975
+ * This source code is licensed under the ISC license.
976
+ * See the LICENSE file in the root directory of this source tree.
977
+ */const S8=[["path",{d:"M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z",key:"w46dr5"}]],ba=ae("puzzle",S8);/**
978
+ * @license lucide-react v0.511.0 - ISC
979
+ *
980
+ * This source code is licensed under the ISC license.
981
+ * See the LICENSE file in the root directory of this source tree.
982
+ */const C8=[["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"}]],M8=ae("radar",C8);/**
983
+ * @license lucide-react v0.511.0 - ISC
984
+ *
985
+ * This source code is licensed under the ISC license.
986
+ * See the LICENSE file in the root directory of this source tree.
987
+ */const A8=[["path",{d:"M4.9 19.1C1 15.2 1 8.8 4.9 4.9",key:"1vaf9d"}],["path",{d:"M7.8 16.2c-2.3-2.3-2.3-6.1 0-8.5",key:"u1ii0m"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M16.2 7.8c2.3 2.3 2.3 6.1 0 8.5",key:"1j5fej"}],["path",{d:"M19.1 4.9C23 8.8 23 15.1 19.1 19",key:"10b0cb"}]],si=ae("radio",A8);/**
988
+ * @license lucide-react v0.511.0 - ISC
989
+ *
990
+ * This source code is licensed under the ISC license.
991
+ * See the LICENSE file in the root directory of this source tree.
992
+ */const E8=[["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"}]],ct=ae("refresh-cw",E8);/**
993
+ * @license lucide-react v0.511.0 - ISC
994
+ *
995
+ * This source code is licensed under the ISC license.
996
+ * See the LICENSE file in the root directory of this source tree.
997
+ */const I8=[["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"}]],Sv=ae("rotate-ccw",I8);/**
998
+ * @license lucide-react v0.511.0 - ISC
999
+ *
1000
+ * This source code is licensed under the ISC license.
1001
+ * See the LICENSE file in the root directory of this source tree.
1002
+ */const P8=[["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"}]],Yt=ae("rotate-cw",P8);/**
1003
+ * @license lucide-react v0.511.0 - ISC
1004
+ *
1005
+ * This source code is licensed under the ISC license.
1006
+ * See the LICENSE file in the root directory of this source tree.
1007
+ */const _8=[["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"}]],$8=ae("save",_8);/**
1008
+ * @license lucide-react v0.511.0 - ISC
1009
+ *
1010
+ * This source code is licensed under the ISC license.
1011
+ * See the LICENSE file in the root directory of this source tree.
1012
+ */const D8=[["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"}]],At=ae("scroll-text",D8);/**
1013
+ * @license lucide-react v0.511.0 - ISC
1014
+ *
1015
+ * This source code is licensed under the ISC license.
1016
+ * See the LICENSE file in the root directory of this source tree.
1017
+ */const L8=[["path",{d:"m13.5 8.5-5 5",key:"1cs55j"}],["path",{d:"m8.5 8.5 5 5",key:"a8mexj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]],T8=ae("search-x",L8);/**
1018
+ * @license lucide-react v0.511.0 - ISC
1019
+ *
1020
+ * This source code is licensed under the ISC license.
1021
+ * See the LICENSE file in the root directory of this source tree.
1022
+ */const R8=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],Cv=ae("search",R8);/**
1023
+ * @license lucide-react v0.511.0 - ISC
1024
+ *
1025
+ * This source code is licensed under the ISC license.
1026
+ * See the LICENSE file in the root directory of this source tree.
1027
+ */const O8=[["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"}]],Rn=ae("server",O8);/**
1028
+ * @license lucide-react v0.511.0 - ISC
1029
+ *
1030
+ * This source code is licensed under the ISC license.
1031
+ * See the LICENSE file in the root directory of this source tree.
1032
+ */const B8=[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],tn=ae("settings",B8);/**
1033
+ * @license lucide-react v0.511.0 - ISC
1034
+ *
1035
+ * This source code is licensed under the ISC license.
1036
+ * See the LICENSE file in the root directory of this source tree.
1037
+ */const z8=[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]],F8=ae("share-2",z8);/**
1038
+ * @license lucide-react v0.511.0 - ISC
1039
+ *
1040
+ * This source code is licensed under the ISC license.
1041
+ * See the LICENSE file in the root directory of this source tree.
1042
+ */const j8=[["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"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],xn=ae("shield-check",j8);/**
1043
+ * @license lucide-react v0.511.0 - ISC
1044
+ *
1045
+ * This source code is licensed under the ISC license.
1046
+ * See the LICENSE file in the root directory of this source tree.
1047
+ */const H8=[["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71",key:"1jlk70"}],["path",{d:"M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264",key:"18rp1v"}]],Wp=ae("shield-off",H8);/**
1048
+ * @license lucide-react v0.511.0 - ISC
1049
+ *
1050
+ * This source code is licensed under the ISC license.
1051
+ * See the LICENSE file in the root directory of this source tree.
1052
+ */const V8=[["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"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]],U8=ae("shield-x",V8);/**
1053
+ * @license lucide-react v0.511.0 - ISC
1054
+ *
1055
+ * This source code is licensed under the ISC license.
1056
+ * See the LICENSE file in the root directory of this source tree.
1057
+ */const q8=[["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"}]],Q8=ae("shield",q8);/**
1058
+ * @license lucide-react v0.511.0 - ISC
1059
+ *
1060
+ * This source code is licensed under the ISC license.
1061
+ * See the LICENSE file in the root directory of this source tree.
1062
+ */const G8=[["path",{d:"m12.5 17-.5-1-.5 1h1z",key:"3me087"}],["path",{d:"M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z",key:"1o5pge"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}]],Is=ae("skull",G8);/**
1063
+ * @license lucide-react v0.511.0 - ISC
1064
+ *
1065
+ * This source code is licensed under the ISC license.
1066
+ * See the LICENSE file in the root directory of this source tree.
1067
+ */const W8=[["line",{x1:"21",x2:"14",y1:"4",y2:"4",key:"obuewd"}],["line",{x1:"10",x2:"3",y1:"4",y2:"4",key:"1q6298"}],["line",{x1:"21",x2:"12",y1:"12",y2:"12",key:"1iu8h1"}],["line",{x1:"8",x2:"3",y1:"12",y2:"12",key:"ntss68"}],["line",{x1:"21",x2:"16",y1:"20",y2:"20",key:"14d8ph"}],["line",{x1:"12",x2:"3",y1:"20",y2:"20",key:"m0wm8r"}],["line",{x1:"14",x2:"14",y1:"2",y2:"6",key:"14e1ph"}],["line",{x1:"8",x2:"8",y1:"10",y2:"14",key:"1i6ji0"}],["line",{x1:"16",x2:"16",y1:"18",y2:"22",key:"1lctlv"}]],Mv=ae("sliders-horizontal",W8);/**
1068
+ * @license lucide-react v0.511.0 - ISC
1069
+ *
1070
+ * This source code is licensed under the ISC license.
1071
+ * See the LICENSE file in the root directory of this source tree.
1072
+ */const K8=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],$n=ae("smartphone",K8);/**
1073
+ * @license lucide-react v0.511.0 - ISC
1074
+ *
1075
+ * This source code is licensed under the ISC license.
1076
+ * See the LICENSE file in the root directory of this source tree.
1077
+ */const Y8=[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]],Z8=ae("sparkles",Y8);/**
1078
+ * @license lucide-react v0.511.0 - ISC
1079
+ *
1080
+ * This source code is licensed under the ISC license.
1081
+ * See the LICENSE file in the root directory of this source tree.
1082
+ */const X8=[["path",{d:"M21 10.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h12.5",key:"1uzm8b"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],Av=ae("square-check-big",X8);/**
1083
+ * @license lucide-react v0.511.0 - ISC
1084
+ *
1085
+ * This source code is licensed under the ISC license.
1086
+ * See the LICENSE file in the root directory of this source tree.
1087
+ */const J8=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],os=ae("square",J8);/**
1088
+ * @license lucide-react v0.511.0 - ISC
1089
+ *
1090
+ * This source code is licensed under the ISC license.
1091
+ * See the LICENSE file in the root directory of this source tree.
1092
+ */const e7=[["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"}]],Ki=ae("star",e7);/**
1093
+ * @license lucide-react v0.511.0 - ISC
1094
+ *
1095
+ * This source code is licensed under the ISC license.
1096
+ * See the LICENSE file in the root directory of this source tree.
1097
+ */const t7=[["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"}]],n7=ae("sun",t7);/**
1098
+ * @license lucide-react v0.511.0 - ISC
1099
+ *
1100
+ * This source code is licensed under the ISC license.
1101
+ * See the LICENSE file in the root directory of this source tree.
1102
+ */const r7=[["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"}]],o7=ae("table-2",r7);/**
1103
+ * @license lucide-react v0.511.0 - ISC
1104
+ *
1105
+ * This source code is licensed under the ISC license.
1106
+ * See the LICENSE file in the root directory of this source tree.
1107
+ */const s7=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],Ev=ae("terminal",s7);/**
1108
+ * @license lucide-react v0.511.0 - ISC
1109
+ *
1110
+ * This source code is licensed under the ISC license.
1111
+ * See the LICENSE file in the root directory of this source tree.
1112
+ */const a7=[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]],et=ae("trash-2",a7);/**
1113
+ * @license lucide-react v0.511.0 - ISC
1114
+ *
1115
+ * This source code is licensed under the ISC license.
1116
+ * See the LICENSE file in the root directory of this source tree.
1117
+ */const i7=[["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"}]],pt=ae("triangle-alert",i7);/**
1118
+ * @license lucide-react v0.511.0 - ISC
1119
+ *
1120
+ * This source code is licensed under the ISC license.
1121
+ * See the LICENSE file in the root directory of this source tree.
1122
+ */const l7=[["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"}]],ai=ae("upload",l7);/**
1123
+ * @license lucide-react v0.511.0 - ISC
1124
+ *
1125
+ * This source code is licensed under the ISC license.
1126
+ * See the LICENSE file in the root directory of this source tree.
1127
+ */const c7=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],d7=ae("users",c7);/**
1128
+ * @license lucide-react v0.511.0 - ISC
1129
+ *
1130
+ * This source code is licensed under the ISC license.
1131
+ * See the LICENSE file in the root directory of this source tree.
1132
+ */const u7=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],Iv=ae("video",u7);/**
1133
+ * @license lucide-react v0.511.0 - ISC
1134
+ *
1135
+ * This source code is licensed under the ISC license.
1136
+ * See the LICENSE file in the root directory of this source tree.
1137
+ */const p7=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z",key:"uqj9uw"}],["path",{d:"M16 9a5 5 0 0 1 0 6",key:"1q6k2b"}],["path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728",key:"ijwkga"}]],f7=ae("volume-2",p7);/**
1138
+ * @license lucide-react v0.511.0 - ISC
1139
+ *
1140
+ * This source code is licensed under the ISC license.
1141
+ * See the LICENSE file in the root directory of this source tree.
1142
+ */const m7=[["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"}]],Pv=ae("wifi-off",m7);/**
1143
+ * @license lucide-react v0.511.0 - ISC
1144
+ *
1145
+ * This source code is licensed under the ISC license.
1146
+ * See the LICENSE file in the root directory of this source tree.
1147
+ */const h7=[["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"}]],Or=ae("wifi",h7);/**
1148
+ * @license lucide-react v0.511.0 - ISC
1149
+ *
1150
+ * This source code is licensed under the ISC license.
1151
+ * See the LICENSE file in the root directory of this source tree.
1152
+ */const g7=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Ve=ae("x",g7);/**
1153
+ * @license lucide-react v0.511.0 - ISC
1154
+ *
1155
+ * This source code is licensed under the ISC license.
1156
+ * See the LICENSE file in the root directory of this source tree.
1157
+ */const b7=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",key:"cbrjhi"}]],x7=ae("wrench",b7);/**
1158
+ * @license lucide-react v0.511.0 - ISC
1159
+ *
1160
+ * This source code is licensed under the ISC license.
1161
+ * See the LICENSE file in the root directory of this source tree.
1162
+ */const y7=[["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"}]],cu=ae("zap",y7);function v7(){const e=De(),t=Me(),[n,o]=I(()=>e.isConnected()?"connected":"disconnected"),s=ne(!1),[a,i]=I(0),[l,c]=I([]);J(()=>e.subscribeConnectionEvents(m=>{o(h=>(h!=="connected"&&m==="connected"&&s.current&&i(g=>g+1),m!=="connected"&&(s.current=!0),m))}),[e]),J(()=>{a!==0&&t.invalidateQueries({queryKey:[["addons","getLastRestart"]]})},[a,t]);const{data:d}=bd(void 0,{enabled:n==="connected"&&a>0,staleTime:0,refetchOnMount:!1,refetchOnWindowFocus:!1}),p=ne(null);return J(()=>{if(d==null||d.requestedAt===p.current)return;p.current=d.requestedAt;const f=N7(d);c(h=>[...h,f]);const m=window.setTimeout(()=>{c(h=>h.filter(g=>g.id!==f.id))},6e3);return()=>window.clearTimeout(m)},[d]),r(me,{children:l.length>0&&r(w7,{toasts:l})})}function w7({toasts:e}){return r("div",{className:"fixed top-4 right-4 z-50 flex flex-col gap-2 max-w-sm w-full pointer-events-none",children:e.map(t=>u("div",{className:"pointer-events-auto flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm",children:[r(ti,{className:"w-4 h-4 shrink-0 mt-0.5 text-green-400"}),u("div",{children:[r("div",{className:"text-[11px] font-semibold text-foreground",children:t.title}),r("div",{className:"text-[10px] text-foreground-subtle mt-0.5",children:t.message})]})]},t.id))})}function N7(e){const t=`restart-${e.requestedAt}`;if(e.kind==="framework-update"&&e.packageName!==void 0&&e.toVersion!==void 0){const n=e.fromVersion!==void 0?`v${e.fromVersion} → v${e.toVersion}`:`v${e.toVersion}`;return{id:t,title:"Framework updated",message:`${e.packageName} is now ${n}.`}}return{id:t,title:"Server restarted",message:e.requestedBy!==void 0?`Manual restart by ${e.requestedBy} completed.`:"Manual restart completed."}}function k7(e){const t=De();return cr({queryKey:["field-resolver",e?.capName??"<none>",e?.methodName??"<none>",e?.input??{}],enabled:!!e,queryFn:async()=>{if(!e)throw new Error("useFieldResolver: resolver is null (enabled guard should have prevented this)");const n=i=>i!==null&&(typeof i=="object"||typeof i=="function"),o=Reflect.get(t.trpcClient,e.capName);if(!n(o))throw new Error(`useFieldResolver: no cap namespace '${e.capName}' on the tRPC client`);const s=Reflect.get(o,e.methodName);if(!n(s))throw new Error(`useFieldResolver: no method '${e.methodName}' on cap '${e.capName}'`);const a=Reflect.get(s,"query");if(typeof a!="function")throw new Error(`useFieldResolver: '${e.capName}.${e.methodName}' has no .query() (resolvers must be query methods, not mutations)`);return await a(e.input??{})}})}function S7(e){return typeof e=="string"&&e.length>0&&e!=="undefined"&&e!=="null"}function C7(e={}){const t=Me(),n=no(void 0,{staleTime:1e4,enabled:e.enabled??!0}),o=q(()=>(n.data??[]).filter(i=>S7(i.nodeId)),[n.data]),s=U(()=>{t.invalidateQueries({queryKey:["pipelineOrchestrator","listAgentSettings"]})},[t]);return{agents:o,isLoading:n.isLoading,isError:n.isError,error:n.error,refetch:()=>{n.refetch()},invalidate:s}}function M7({field:e,disabled:t}){const n=Me(),o=e.deviceId,s=k7(e.catalogResolver),a=Ad({agentNodeId:e.nodeId}),i=Id({deviceId:o}),c=dy({onSuccess:()=>{n.invalidateQueries({queryKey:[["pipelineOrchestrator","getCameraSettings"]]}),n.invalidateQueries({queryKey:[["deviceManager"]]})}}),d=s.data,p=a.data??null,f=i.data??null,m=q(()=>d?E7(d,p,f):[],[d,p,f]),h=q(()=>{if(!p)return{};const g={};for(const[x,b]of Object.entries(p.addonDefaults))g[x]=b.enabled;return g},[p]);return s.error?u("div",{className:"text-xs text-red-400",children:["Failed to load pipeline catalog for ",r("code",{children:e.nodeId}),": ",String(s.error.message??s.error)]}):s.isLoading||!d||a.isLoading?u("div",{className:"text-xs text-foreground-subtle animate-pulse",children:["Loading pipeline for ",e.nodeId,"…"]}):u("div",{className:"col-span-full space-y-4",children:[u("div",{className:"flex items-center gap-2 text-[11px] text-foreground-subtle",children:["Agent: ",r("span",{className:"text-foreground",children:e.nodeId}),u("span",{className:"ml-2",children:["Engine: ",r("span",{className:"text-foreground font-mono",children:`${d.selectedEngine.runtime}/${d.selectedEngine.backend}`})]}),u("span",{className:"ml-auto text-[10px]",children:["Model + settings edited on Pipeline → ",e.nodeId,"."]})]}),r(ud,{schema:d,steps:m,onChange:()=>{},templates:[],selectedTemplateId:null,onSelectTemplate:()=>{},onSaveTemplate:()=>{},onUpdateTemplate:()=>{},onDeleteTemplate:()=>{},readOnly:t===!0,hideTemplates:!0,toggleMode:"threeState",hideModelAndSettings:!0,overrides:f?.stepToggles??{},onOverrideChange:(g,x)=>c.mutate({deviceId:o,addonId:g,enabled:x}),inheritedEnabledByAddon:h}),r(A7,{deviceId:o,currentAgentNodeId:e.nodeId,catalog:d,pipelineByAgent:f?.pipelineByAgent??{},disabled:t===!0})]})}function A7({deviceId:e,currentAgentNodeId:t,catalog:n,pipelineByAgent:o,disabled:s}){const a=Me(),[i,l]=I(!1),[c,d]=I(t),{agents:p}=C7({enabled:i}),f=fy({deviceId:e,agentNodeId:c},{enabled:i}),h=py({onSuccess:()=>{a.invalidateQueries({queryKey:[["pipelineOrchestrator","getCameraSettings"]]}),a.invalidateQueries({queryKey:[["pipelineOrchestrator","resolvePipeline"]]})}}),g=o[c]??null,x=p,b=q(()=>g?I7(g.steps,n):[],[g,n]),y=w=>{const v=g?.audio??null;h.mutate({deviceId:e,agentNodeId:c,pipeline:{steps:P7(w),audio:v?{modelId:v.modelId,enabled:v.enabled}:null}})};return u("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("button",{type:"button",onClick:()=>l(w=>!w),className:"w-full px-4 py-2 flex items-center gap-2 hover:bg-surface-hover",children:[i?r(en,{className:"h-3 w-3"}):r(on,{className:"h-3 w-3"}),r("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide",children:"Advanced — custom pipeline per agent"}),r("span",{className:"ml-auto text-[10px] text-foreground-subtle",children:Object.keys(o).length>0?`${Object.keys(o).length} override(s) active`:"None configured"})]}),i&&u("div",{className:"border-t border-border px-4 py-3 space-y-3",children:[u("div",{className:"flex items-center gap-2 text-xs",children:[r("span",{className:"text-foreground-subtle",children:"Agent:"}),u("select",{value:c,disabled:s,onChange:w=>d(w.target.value),className:"rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary",children:[typeof t=="string"&&t.length>0&&t!=="undefined"&&u("option",{value:t,children:[t," (current)"]}),x.filter(w=>w.nodeId!==t).map(w=>r("option",{value:w.nodeId,children:w.nodeId},w.nodeId))]}),o[c]&&u("button",{type:"button",onClick:()=>{window.confirm(`Remove custom pipeline override for ${c}? The camera will revert to the agent default + step toggles.`)&&h.mutate({deviceId:e,agentNodeId:c,pipeline:null})},disabled:s||h.isPending,className:"ml-auto inline-flex items-center gap-1 px-2 py-1 text-[11px] text-red-400 hover:bg-red-500/10 rounded disabled:opacity-50",children:[r(et,{className:"h-3 w-3"}),"Remove override"]})]}),g?r(ud,{schema:n,steps:b,onChange:y,templates:[],selectedTemplateId:null,onSelectTemplate:()=>{},onSaveTemplate:()=>{},onUpdateTemplate:()=>{},onDeleteTemplate:()=>{},readOnly:s,hideTemplates:!0}):u("div",{className:"text-xs text-foreground-subtle space-y-2",children:[u("p",{children:["No custom pipeline for ",r("code",{children:c}),". The camera uses the agent's default + step toggles."]}),r("button",{type:"button",onClick:()=>{const w=f.data;w&&h.mutate({deviceId:e,agentNodeId:c,pipeline:{steps:w.steps,audio:w.audio?{modelId:w.audio.modelId,enabled:w.audio.enabled}:null}})},disabled:s||h.isPending||!f.data,className:"inline-flex items-center gap-1 px-3 py-1.5 text-xs font-medium rounded bg-primary/15 text-primary hover:bg-primary/25 disabled:opacity-50",children:"Create wholesale override from current default"})]})]})]})}function E7(e,t,n){const o=d=>{for(const p of e.slots)for(const f of p.addons)if(f.id===d)return f;return null},s=d=>{const p=t?.addonDefaults[d.id],f=p?.enabled??d.enabledByDefault??!0,m=n?.stepToggles?.[d.id],h=m!==void 0?m:f;return{addonId:d.id,addonName:d.name,slot:d.slot,inputClasses:[...d.inputClasses],outputClasses:[...d.outputClasses],enabled:h,modelId:p?.modelId??d.defaultModelId,children:[],...p?.settings&&Object.keys(p.settings).length>0?{settings:p.settings}:{}}},a=new Map;for(const d of e.slots)for(const p of d.addons)a.set(p.id,s(p));const i=[],l=new Set;for(const[d,p]of a){const f=o(d);f&&f.inputClasses.length===0&&(i.push(p),l.add(d))}let c=!0;for(;c;){c=!1;for(const[d,p]of a){if(l.has(d))continue;const f=o(d);if(f)for(const[m,h]of a){if(m===d)continue;const g=o(m);if(g&&l.has(m)&&g.outputClasses.some(x=>f.inputClasses.includes(x))){h.children.push(p),l.add(d),c=!0;break}}}}return i}function I7(e,t){const n=new Map;for(const s of t.slots)for(const a of s.addons)n.set(a.id,a);const o=s=>{const a=n.get(s.addonId);return{addonId:s.addonId,addonName:a?.name??s.addonId,slot:a?.slot??"detector",inputClasses:a?.inputClasses?[...a.inputClasses]:[],outputClasses:a?.outputClasses?[...a.outputClasses]:[],enabled:s.enabled,modelId:s.modelId,children:(s.children??[]).map(o),...s.settings?{settings:{...s.settings}}:{}}};return[...e].map(o)}function P7(e){const t=n=>({addonId:n.addonId,modelId:n.modelId,enabled:n.enabled,children:n.children.map(t),...n.settings?{settings:{...n.settings}}:{}});return e.map(t)}function _7({tabs:e,active:t,onChange:n}){return r("div",{className:"flex rounded-lg border border-border bg-surface p-0.5 gap-0.5",children:e.map(o=>r("button",{type:"button",onClick:()=>n(o.id),className:["flex-1 rounded-md px-3 py-1.5 text-xs font-medium transition-colors",t===o.id?"bg-primary/12 text-primary":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"].join(" "),children:o.label},o.id))})}function $7(e){const t=e.formats;if(!t)return"";const n=Object.values(t).filter(a=>a!==void 0&&a.sizeMB>0).map(a=>a.sizeMB);if(n.length===0)return"";const o=Math.min(...n),s=Math.max(...n);return o===s?`${o} MB`:`${o}-${s} MB`}function D7(e){return`${e.inputSize.width}x${e.inputSize.height}`}function L7(e){return e.formats?Object.keys(e.formats).filter(t=>e.formats[t]!==void 0):[]}function T7({entry:e,selected:t,onSelect:n,disabled:o}){const s=$7(e),a=D7(e),i=L7(e);return u("button",{type:"button",onClick:n,disabled:o,className:["w-full text-left rounded-lg border p-3 transition-all",t?"border-primary bg-primary/5 ring-1 ring-primary/30":"border-border bg-background hover:border-foreground-subtle/40 hover:bg-surface-hover/50",o?"opacity-50 cursor-not-allowed":"cursor-pointer"].join(" "),children:[r("div",{className:"flex items-start justify-between gap-2",children:u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-xs font-semibold text-foreground truncate",children:e.name}),t&&r(St,{className:"h-3.5 w-3.5 text-primary shrink-0"})]}),r("p",{className:"text-[10px] text-foreground-subtle mt-0.5 line-clamp-2",children:e.description})]})}),u("div",{className:"flex items-center gap-3 mt-2 flex-wrap",children:[u("span",{className:"inline-flex items-center gap-1 text-[10px] text-foreground-subtle",children:[r(jt,{className:"h-3 w-3"}),a]}),s&&r("span",{className:"text-[10px] text-foreground-subtle",children:s}),i.length>0&&r("div",{className:"flex gap-1",children:i.map(l=>r("span",{className:"text-[9px] uppercase rounded bg-surface border border-border px-1 py-0.5 text-foreground-subtle font-mono",children:l},l))}),e.labels.length>0&&u("span",{className:"text-[10px] text-foreground-subtle",children:[e.labels.length," label",e.labels.length!==1?"s":""]})]})]})}function R7({field:e,value:t,onChange:n,disabled:o}){const s=e.catalog??[],a=s.length>0,i=e.allowCustomPath!==!1||e.allowCustom===!0,l=[...a?[{id:"catalog",label:`Models (${s.length})`}]:[],...i?[{id:"custom",label:"Custom Path"}]:[]],[c,d]=I(a?"catalog":"custom"),p=t==null?"":String(t);return u("div",{className:"space-y-3",children:[l.length>1&&r(_7,{tabs:l,active:c,onChange:d}),c==="catalog"&&a&&r("div",{className:"space-y-1.5 max-h-[320px] overflow-y-auto pr-1",children:s.map(f=>r(T7,{entry:f,selected:p===f.id,onSelect:()=>n(f.id),disabled:o||e.disabled},f.id))}),c==="catalog"&&!a&&u("div",{className:"rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2",children:[r(rr,{className:"h-3.5 w-3.5 text-info shrink-0 mt-0.5"}),r("p",{className:"text-[11px] text-foreground-subtle leading-relaxed",children:"No predefined models available. Use the Custom Path tab to specify a model file path or URL."})]}),c==="custom"&&i&&u("div",{className:"space-y-2",children:[r("input",{type:"text",className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50",placeholder:"Enter path like /data/models/custom.onnx or https://...",value:p,disabled:o||e.disabled,onChange:f=>n(f.target.value)}),e.acceptFormats&&e.acceptFormats.length>0&&u("p",{className:"text-[10px] text-foreground-subtle",children:["Accepted formats: ",e.acceptFormats.join(", ")]})]}),(e.compatibilityNote||e.conversionGuideUrl)&&u("div",{className:"flex items-start justify-between gap-3 pt-1",children:[e.compatibilityNote&&u("p",{className:"flex items-start gap-1 text-[10px] text-foreground-subtle",children:[r(rr,{className:"h-3 w-3 mt-0.5 shrink-0"}),e.compatibilityNote]}),e.conversionGuideUrl&&u("a",{href:e.conversionGuideUrl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-[11px] text-primary hover:underline shrink-0",children:["How to convert your model",r(iu,{className:"h-3 w-3"})]})]})]})}function Js(e){try{const t=e.split(".");if(t.length<2||!t[1])return null;const n=JSON.parse(atob(t[1]));return{id:String(n.userId??""),username:String(n.username??"unknown"),isAdmin:!!n.isAdmin,exp:Number(n.exp??0),scopes:z7(n.scopes)}}catch{return null}}const O7=new Set(["view","create","delete"]),B7=new Set(["category","capability","addon","device"]);function z7(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){if(typeof n!="object"||n===null)continue;const o=n,{type:s,access:a}=o;if(typeof s!="string"||!B7.has(s)||!Array.isArray(a))continue;const i=a.filter(c=>typeof c=="string"&&O7.has(c));if(i.length===0)continue;if(s==="device"){const c=o.targets;if(!Array.isArray(c))continue;const d=c.filter(p=>typeof p=="string"&&p.length>0);if(d.length===0)continue;t.push({type:"device",targets:d,access:i});continue}const l=o.target;if(typeof l=="string")if(s==="category"){if(l!=="device"&&l!=="system")continue;t.push({type:s,target:l,access:i})}else s==="capability"?t.push({type:s,target:l,access:i}):t.push({type:"addon",target:l,access:i})}return t}function F7(e){const t=Js(e);return t?t.exp*1e3<Date.now():!0}const j7="changeme",_v=qe(null);function H7({children:e}){const[t,n]=I(null),[o,s]=I(!0),[a,i]=I(!1);J(()=>{if(typeof window<"u"&&window.location.hash.startsWith("#token=")){const b=new URLSearchParams(window.location.hash.slice(1)).get("token");b&&(localStorage.setItem("camstack_admin_token",b),window.history.replaceState({},"","/admin"))}const f=localStorage.getItem("camstack_admin_token");if(!f){s(!1);return}if(F7(f)){localStorage.removeItem("camstack_admin_token"),s(!1);return}const m=Js(f);if(!m){localStorage.removeItem("camstack_admin_token"),s(!1);return}Xs().trpcClient.system.info.query().then(()=>n(m)).catch(x=>{const b=x?.data?.code;b==="UNAUTHORIZED"||b==="FORBIDDEN"?(localStorage.removeItem("camstack_admin_token"),Nr()):n(m)}).finally(()=>s(!1))},[]);const l=U(async(f,m)=>{const g=await Xs().login(f,m);if(g.requiresTotp===!0)return{kind:"totp-required",challengeToken:g.token};const x=g.token;return localStorage.setItem("camstack_admin_token",x),await fetch("/api/auth/session",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({token:x})}).catch(()=>{}),Nr(),n(Js(x)),i(m===j7),{kind:"ok"}},[]),c=U(async(f,m)=>{const x=(await Xs().loginVerifyTotp(f,m)).token;localStorage.setItem("camstack_admin_token",x),await fetch("/api/auth/session",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({token:x})}).catch(()=>{}),Nr(),n(Js(x)),i(!1)},[]),d=U(()=>{localStorage.removeItem("camstack_admin_token"),fetch("/api/auth/session",{method:"DELETE"}).catch(()=>{}),Nr(),n(null),i(!1)},[]),p=U(()=>{i(!1)},[]);return r(_v.Provider,{value:{user:t,loading:o,mustChangePassword:a,login:l,verifyTotp:c,logout:d,clearMustChangePassword:p},children:e})}function sn(){const e=Ne(_v);if(!e)throw new Error("useAuth must be used within AuthProvider");return e}function Mt({children:e,requireAdmin:t}){const{user:n,loading:o,mustChangePassword:s}=sn(),a=kt();return o?r("div",{className:"flex h-screen items-center justify-center bg-background text-foreground-subtle",children:"Loading..."}):n?s&&a.pathname!=="/change-password"?r(ht,{to:"/change-password",replace:!0}):t&&!n.isAdmin?r(ht,{to:"/access-denied",replace:!0}):r(me,{children:e}):r(ht,{to:"/login",replace:!0})}var Yi={};const Ie=e=>typeof e=="string",mo=()=>{let e,t;const n=new Promise((o,s)=>{e=o,t=s});return n.resolve=e,n.reject=t,n},Kp=e=>e==null?"":""+e,V7=(e,t,n)=>{e.forEach(o=>{t[o]&&(n[o]=t[o])})},U7=/###/g,Yp=e=>e&&e.indexOf("###")>-1?e.replace(U7,"."):e,Zp=e=>!e||Ie(e),Ao=(e,t,n)=>{const o=Ie(t)?t.split("."):t;let s=0;for(;s<o.length-1;){if(Zp(e))return{};const a=Yp(o[s]);!e[a]&&n&&(e[a]=new n),Object.prototype.hasOwnProperty.call(e,a)?e=e[a]:e={},++s}return Zp(e)?{}:{obj:e,k:Yp(o[s])}},Xp=(e,t,n)=>{const{obj:o,k:s}=Ao(e,t,Object);if(o!==void 0||t.length===1){o[s]=n;return}let a=t[t.length-1],i=t.slice(0,t.length-1),l=Ao(e,i,Object);for(;l.obj===void 0&&i.length;)a=`${i[i.length-1]}.${a}`,i=i.slice(0,i.length-1),l=Ao(e,i,Object),l?.obj&&typeof l.obj[`${l.k}.${a}`]<"u"&&(l.obj=void 0);l.obj[`${l.k}.${a}`]=n},q7=(e,t,n,o)=>{const{obj:s,k:a}=Ao(e,t,Object);s[a]=s[a]||[],s[a].push(n)},xa=(e,t)=>{const{obj:n,k:o}=Ao(e,t);if(n&&Object.prototype.hasOwnProperty.call(n,o))return n[o]},Q7=(e,t,n)=>{const o=xa(e,n);return o!==void 0?o:xa(t,n)},$v=(e,t,n)=>{for(const o in t)o!=="__proto__"&&o!=="constructor"&&(o in e?Ie(e[o])||e[o]instanceof String||Ie(t[o])||t[o]instanceof String?n&&(e[o]=t[o]):$v(e[o],t[o],n):e[o]=t[o]);return e},Un=e=>e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var G7={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};const W7=e=>Ie(e)?e.replace(/[&<>"'\/]/g,t=>G7[t]):e;class K7{constructor(t){this.capacity=t,this.regExpMap=new Map,this.regExpQueue=[]}getRegExp(t){const n=this.regExpMap.get(t);if(n!==void 0)return n;const o=new RegExp(t);return this.regExpQueue.length===this.capacity&&this.regExpMap.delete(this.regExpQueue.shift()),this.regExpMap.set(t,o),this.regExpQueue.push(t),o}}const Y7=[" ",",","?","!",";"],Z7=new K7(20),X7=(e,t,n)=>{t=t||"",n=n||"";const o=Y7.filter(i=>t.indexOf(i)<0&&n.indexOf(i)<0);if(o.length===0)return!0;const s=Z7.getRegExp(`(${o.map(i=>i==="?"?"\\?":i).join("|")})`);let a=!s.test(e);if(!a){const i=e.indexOf(n);i>0&&!s.test(e.substring(0,i))&&(a=!0)}return a},oc=(e,t,n=".")=>{if(!e)return;if(e[t])return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;const o=t.split(n);let s=e;for(let a=0;a<o.length;){if(!s||typeof s!="object")return;let i,l="";for(let c=a;c<o.length;++c)if(c!==a&&(l+=n),l+=o[c],i=s[l],i!==void 0){if(["string","number","boolean"].indexOf(typeof i)>-1&&c<o.length-1)continue;a+=c-a+1;break}s=i}return s},zo=e=>e?.replace(/_/g,"-"),J7={type:"logger",log(e){this.output("log",e)},warn(e){this.output("warn",e)},error(e){this.output("error",e)},output(e,t){console?.[e]?.apply?.(console,t)}};class ya{constructor(t,n={}){this.init(t,n)}init(t,n={}){this.prefix=n.prefix||"i18next:",this.logger=t||J7,this.options=n,this.debug=n.debug}log(...t){return this.forward(t,"log","",!0)}warn(...t){return this.forward(t,"warn","",!0)}error(...t){return this.forward(t,"error","")}deprecate(...t){return this.forward(t,"warn","WARNING DEPRECATED: ",!0)}forward(t,n,o,s){return s&&!this.debug?null:(Ie(t[0])&&(t[0]=`${o}${this.prefix} ${t[0]}`),this.logger[n](t))}create(t){return new ya(this.logger,{prefix:`${this.prefix}:${t}:`,...this.options})}clone(t){return t=t||this.options,t.prefix=t.prefix||this.prefix,new ya(this.logger,t)}}var Wt=new ya;class ii{constructor(){this.observers={}}on(t,n){return t.split(" ").forEach(o=>{this.observers[o]||(this.observers[o]=new Map);const s=this.observers[o].get(n)||0;this.observers[o].set(n,s+1)}),this}off(t,n){if(this.observers[t]){if(!n){delete this.observers[t];return}this.observers[t].delete(n)}}emit(t,...n){this.observers[t]&&Array.from(this.observers[t].entries()).forEach(([s,a])=>{for(let i=0;i<a;i++)s(...n)}),this.observers["*"]&&Array.from(this.observers["*"].entries()).forEach(([s,a])=>{for(let i=0;i<a;i++)s.apply(s,[t,...n])})}}class Jp extends ii{constructor(t,n={ns:["translation"],defaultNS:"translation"}){super(),this.data=t||{},this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.options.ignoreJSONStructure===void 0&&(this.options.ignoreJSONStructure=!0)}addNamespaces(t){this.options.ns.indexOf(t)<0&&this.options.ns.push(t)}removeNamespaces(t){const n=this.options.ns.indexOf(t);n>-1&&this.options.ns.splice(n,1)}getResource(t,n,o,s={}){const a=s.keySeparator!==void 0?s.keySeparator:this.options.keySeparator,i=s.ignoreJSONStructure!==void 0?s.ignoreJSONStructure:this.options.ignoreJSONStructure;let l;t.indexOf(".")>-1?l=t.split("."):(l=[t,n],o&&(Array.isArray(o)?l.push(...o):Ie(o)&&a?l.push(...o.split(a)):l.push(o)));const c=xa(this.data,l);return!c&&!n&&!o&&t.indexOf(".")>-1&&(t=l[0],n=l[1],o=l.slice(2).join(".")),c||!i||!Ie(o)?c:oc(this.data?.[t]?.[n],o,a)}addResource(t,n,o,s,a={silent:!1}){const i=a.keySeparator!==void 0?a.keySeparator:this.options.keySeparator;let l=[t,n];o&&(l=l.concat(i?o.split(i):o)),t.indexOf(".")>-1&&(l=t.split("."),s=n,n=l[1]),this.addNamespaces(n),Xp(this.data,l,s),a.silent||this.emit("added",t,n,o,s)}addResources(t,n,o,s={silent:!1}){for(const a in o)(Ie(o[a])||Array.isArray(o[a]))&&this.addResource(t,n,a,o[a],{silent:!0});s.silent||this.emit("added",t,n,o)}addResourceBundle(t,n,o,s,a,i={silent:!1,skipCopy:!1}){let l=[t,n];t.indexOf(".")>-1&&(l=t.split("."),s=o,o=n,n=l[1]),this.addNamespaces(n);let c=xa(this.data,l)||{};i.skipCopy||(o=JSON.parse(JSON.stringify(o))),s?$v(c,o,a):c={...c,...o},Xp(this.data,l,c),i.silent||this.emit("added",t,n,o)}removeResourceBundle(t,n){this.hasResourceBundle(t,n)&&delete this.data[t][n],this.removeNamespaces(n),this.emit("removed",t,n)}hasResourceBundle(t,n){return this.getResource(t,n)!==void 0}getResourceBundle(t,n){return n||(n=this.options.defaultNS),this.getResource(t,n)}getDataByLanguage(t){return this.data[t]}hasLanguageSomeTranslations(t){const n=this.getDataByLanguage(t);return!!(n&&Object.keys(n)||[]).find(s=>n[s]&&Object.keys(n[s]).length>0)}toJSON(){return this.data}}var Dv={processors:{},addPostProcessor(e){this.processors[e.name]=e},handle(e,t,n,o,s){return e.forEach(a=>{t=this.processors[a]?.process(t,n,o,s)??t}),t}};const Lv=Symbol("i18next/PATH_KEY");function e9(){const e=[],t=Object.create(null);let n;return t.get=(o,s)=>(n?.revoke?.(),s===Lv?e:(e.push(s),n=Proxy.revocable(o,t),n.proxy)),Proxy.revocable(Object.create(null),t).proxy}function Ar(e,t){const{[Lv]:n}=e(e9()),o=t?.keySeparator??".",s=t?.nsSeparator??":";if(n.length>1&&s){const a=t?.ns,i=Array.isArray(a)?a:null;if(i&&i.length>1&&i.slice(1).includes(n[0]))return`${n[0]}${s}${n.slice(1).join(o)}`}return n.join(o)}const ef={},Zi=e=>!Ie(e)&&typeof e!="boolean"&&typeof e!="number";class va extends ii{constructor(t,n={}){super(),V7(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],t,this),this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.logger=Wt.create("translator")}changeLanguage(t){t&&(this.language=t)}exists(t,n={interpolation:{}}){const o={...n};if(t==null)return!1;const s=this.resolve(t,o);if(s?.res===void 0)return!1;const a=Zi(s.res);return!(o.returnObjects===!1&&a)}extractFromKey(t,n){let o=n.nsSeparator!==void 0?n.nsSeparator:this.options.nsSeparator;o===void 0&&(o=":");const s=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator;let a=n.ns||this.options.defaultNS||[];const i=o&&t.indexOf(o)>-1,l=!this.options.userDefinedKeySeparator&&!n.keySeparator&&!this.options.userDefinedNsSeparator&&!n.nsSeparator&&!X7(t,o,s);if(i&&!l){const c=t.match(this.interpolator.nestingRegexp);if(c&&c.length>0)return{key:t,namespaces:Ie(a)?[a]:a};const d=t.split(o);(o!==s||o===s&&this.options.ns.indexOf(d[0])>-1)&&(a=d.shift()),t=d.join(s)}return{key:t,namespaces:Ie(a)?[a]:a}}translate(t,n,o){let s=typeof n=="object"?{...n}:n;if(typeof s!="object"&&this.options.overloadTranslationOptionHandler&&(s=this.options.overloadTranslationOptionHandler(arguments)),typeof s=="object"&&(s={...s}),s||(s={}),t==null)return"";typeof t=="function"&&(t=Ar(t,{...this.options,...s})),Array.isArray(t)||(t=[String(t)]),t=t.map(O=>typeof O=="function"?Ar(O,{...this.options,...s}):String(O));const a=s.returnDetails!==void 0?s.returnDetails:this.options.returnDetails,i=s.keySeparator!==void 0?s.keySeparator:this.options.keySeparator,{key:l,namespaces:c}=this.extractFromKey(t[t.length-1],s),d=c[c.length-1];let p=s.nsSeparator!==void 0?s.nsSeparator:this.options.nsSeparator;p===void 0&&(p=":");const f=s.lng||this.language,m=s.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if(f?.toLowerCase()==="cimode")return m?a?{res:`${d}${p}${l}`,usedKey:l,exactUsedKey:l,usedLng:f,usedNS:d,usedParams:this.getUsedParamsDetails(s)}:`${d}${p}${l}`:a?{res:l,usedKey:l,exactUsedKey:l,usedLng:f,usedNS:d,usedParams:this.getUsedParamsDetails(s)}:l;const h=this.resolve(t,s);let g=h?.res;const x=h?.usedKey||l,b=h?.exactUsedKey||l,y=["[object Number]","[object Function]","[object RegExp]"],w=s.joinArrays!==void 0?s.joinArrays:this.options.joinArrays,v=!this.i18nFormat||this.i18nFormat.handleAsObject,N=s.count!==void 0&&!Ie(s.count),k=va.hasDefaultValue(s),C=N?this.pluralResolver.getSuffix(f,s.count,s):"",D=s.ordinal&&N?this.pluralResolver.getSuffix(f,s.count,{ordinal:!1}):"",M=N&&!s.ordinal&&s.count===0,_=M&&s[`defaultValue${this.options.pluralSeparator}zero`]||s[`defaultValue${C}`]||s[`defaultValue${D}`]||s.defaultValue;let $=g;v&&!g&&k&&($=_);const E=Zi($),R=Object.prototype.toString.apply($);if(v&&$&&E&&y.indexOf(R)<0&&!(Ie(w)&&Array.isArray($))){if(!s.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn("accessing an object - but returnObjects options is not enabled!");const O=this.options.returnedObjectHandler?this.options.returnedObjectHandler(x,$,{...s,ns:c}):`key '${l} (${this.language})' returned an object instead of string.`;return a?(h.res=O,h.usedParams=this.getUsedParamsDetails(s),h):O}if(i){const O=Array.isArray($),A=O?[]:{},P=O?b:x;for(const L in $)if(Object.prototype.hasOwnProperty.call($,L)){const B=`${P}${i}${L}`;k&&!g?A[L]=this.translate(B,{...s,defaultValue:Zi(_)?_[L]:void 0,joinArrays:!1,ns:c}):A[L]=this.translate(B,{...s,joinArrays:!1,ns:c}),A[L]===B&&(A[L]=$[L])}g=A}}else if(v&&Ie(w)&&Array.isArray(g))g=g.join(w),g&&(g=this.extendTranslation(g,t,s,o));else{let O=!1,A=!1;!this.isValidLookup(g)&&k&&(O=!0,g=_),this.isValidLookup(g)||(A=!0,g=l);const L=(s.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey)&&A?void 0:g,B=k&&_!==g&&this.options.updateMissing;if(A||O||B){if(this.logger.log(B?"updateKey":"missingKey",f,d,l,B?_:g),i){const H=this.resolve(l,{...s,keySeparator:!1});H&&H.res&&this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.")}let z=[];const T=this.languageUtils.getFallbackCodes(this.options.fallbackLng,s.lng||this.language);if(this.options.saveMissingTo==="fallback"&&T&&T[0])for(let H=0;H<T.length;H++)z.push(T[H]);else this.options.saveMissingTo==="all"?z=this.languageUtils.toResolveHierarchy(s.lng||this.language):z.push(s.lng||this.language);const F=(H,j,Q)=>{const G=k&&Q!==g?Q:L;this.options.missingKeyHandler?this.options.missingKeyHandler(H,d,j,G,B,s):this.backendConnector?.saveMissing&&this.backendConnector.saveMissing(H,d,j,G,B,s),this.emit("missingKey",H,d,j,g)};this.options.saveMissing&&(this.options.saveMissingPlurals&&N?z.forEach(H=>{const j=this.pluralResolver.getSuffixes(H,s);M&&s[`defaultValue${this.options.pluralSeparator}zero`]&&j.indexOf(`${this.options.pluralSeparator}zero`)<0&&j.push(`${this.options.pluralSeparator}zero`),j.forEach(Q=>{F([H],l+Q,s[`defaultValue${Q}`]||_)})}):F(z,l,_))}g=this.extendTranslation(g,t,s,h,o),A&&g===l&&this.options.appendNamespaceToMissingKey&&(g=`${d}${p}${l}`),(A||O)&&this.options.parseMissingKeyHandler&&(g=this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey?`${d}${p}${l}`:l,O?g:void 0,s))}return a?(h.res=g,h.usedParams=this.getUsedParamsDetails(s),h):g}extendTranslation(t,n,o,s,a){if(this.i18nFormat?.parse)t=this.i18nFormat.parse(t,{...this.options.interpolation.defaultVariables,...o},o.lng||this.language||s.usedLng,s.usedNS,s.usedKey,{resolved:s});else if(!o.skipInterpolation){o.interpolation&&this.interpolator.init({...o,interpolation:{...this.options.interpolation,...o.interpolation}});const c=Ie(t)&&(o?.interpolation?.skipOnVariables!==void 0?o.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables);let d;if(c){const f=t.match(this.interpolator.nestingRegexp);d=f&&f.length}let p=o.replace&&!Ie(o.replace)?o.replace:o;if(this.options.interpolation.defaultVariables&&(p={...this.options.interpolation.defaultVariables,...p}),t=this.interpolator.interpolate(t,p,o.lng||this.language||s.usedLng,o),c){const f=t.match(this.interpolator.nestingRegexp),m=f&&f.length;d<m&&(o.nest=!1)}!o.lng&&s&&s.res&&(o.lng=this.language||s.usedLng),o.nest!==!1&&(t=this.interpolator.nest(t,(...f)=>a?.[0]===f[0]&&!o.context?(this.logger.warn(`It seems you are nesting recursively key: ${f[0]} in key: ${n[0]}`),null):this.translate(...f,n),o)),o.interpolation&&this.interpolator.reset()}const i=o.postProcess||this.options.postProcess,l=Ie(i)?[i]:i;return t!=null&&l?.length&&o.applyPostProcessor!==!1&&(t=Dv.handle(l,t,n,this.options&&this.options.postProcessPassResolved?{i18nResolved:{...s,usedParams:this.getUsedParamsDetails(o)},...o}:o,this)),t}resolve(t,n={}){let o,s,a,i,l;return Ie(t)&&(t=[t]),Array.isArray(t)&&(t=t.map(c=>typeof c=="function"?Ar(c,{...this.options,...n}):c)),t.forEach(c=>{if(this.isValidLookup(o))return;const d=this.extractFromKey(c,n),p=d.key;s=p;let f=d.namespaces;this.options.fallbackNS&&(f=f.concat(this.options.fallbackNS));const m=n.count!==void 0&&!Ie(n.count),h=m&&!n.ordinal&&n.count===0,g=n.context!==void 0&&(Ie(n.context)||typeof n.context=="number")&&n.context!=="",x=n.lngs?n.lngs:this.languageUtils.toResolveHierarchy(n.lng||this.language,n.fallbackLng);f.forEach(b=>{this.isValidLookup(o)||(l=b,!ef[`${x[0]}-${b}`]&&this.utils?.hasLoadedNamespace&&!this.utils?.hasLoadedNamespace(l)&&(ef[`${x[0]}-${b}`]=!0,this.logger.warn(`key "${s}" for languages "${x.join(", ")}" won't get resolved as namespace "${l}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!")),x.forEach(y=>{if(this.isValidLookup(o))return;i=y;const w=[p];if(this.i18nFormat?.addLookupKeys)this.i18nFormat.addLookupKeys(w,p,y,b,n);else{let N;m&&(N=this.pluralResolver.getSuffix(y,n.count,n));const k=`${this.options.pluralSeparator}zero`,C=`${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;if(m&&(n.ordinal&&N.indexOf(C)===0&&w.push(p+N.replace(C,this.options.pluralSeparator)),w.push(p+N),h&&w.push(p+k)),g){const D=`${p}${this.options.contextSeparator||"_"}${n.context}`;w.push(D),m&&(n.ordinal&&N.indexOf(C)===0&&w.push(D+N.replace(C,this.options.pluralSeparator)),w.push(D+N),h&&w.push(D+k))}}let v;for(;v=w.pop();)this.isValidLookup(o)||(a=v,o=this.getResource(y,b,v,n))}))})}),{res:o,usedKey:s,exactUsedKey:a,usedLng:i,usedNS:l}}isValidLookup(t){return t!==void 0&&!(!this.options.returnNull&&t===null)&&!(!this.options.returnEmptyString&&t==="")}getResource(t,n,o,s={}){return this.i18nFormat?.getResource?this.i18nFormat.getResource(t,n,o,s):this.resourceStore.getResource(t,n,o,s)}getUsedParamsDetails(t={}){const n=["defaultValue","ordinal","context","replace","lng","lngs","fallbackLng","ns","keySeparator","nsSeparator","returnObjects","returnDetails","joinArrays","postProcess","interpolation"],o=t.replace&&!Ie(t.replace);let s=o?t.replace:t;if(o&&typeof t.count<"u"&&(s.count=t.count),this.options.interpolation.defaultVariables&&(s={...this.options.interpolation.defaultVariables,...s}),!o){s={...s};for(const a of n)delete s[a]}return s}static hasDefaultValue(t){const n="defaultValue";for(const o in t)if(Object.prototype.hasOwnProperty.call(t,o)&&n===o.substring(0,n.length)&&t[o]!==void 0)return!0;return!1}}class tf{constructor(t){this.options=t,this.supportedLngs=this.options.supportedLngs||!1,this.logger=Wt.create("languageUtils")}getScriptPartFromCode(t){if(t=zo(t),!t||t.indexOf("-")<0)return null;const n=t.split("-");return n.length===2||(n.pop(),n[n.length-1].toLowerCase()==="x")?null:this.formatLanguageCode(n.join("-"))}getLanguagePartFromCode(t){if(t=zo(t),!t||t.indexOf("-")<0)return t;const n=t.split("-");return this.formatLanguageCode(n[0])}formatLanguageCode(t){if(Ie(t)&&t.indexOf("-")>-1){let n;try{n=Intl.getCanonicalLocales(t)[0]}catch{}return n&&this.options.lowerCaseLng&&(n=n.toLowerCase()),n||(this.options.lowerCaseLng?t.toLowerCase():t)}return this.options.cleanCode||this.options.lowerCaseLng?t.toLowerCase():t}isSupportedCode(t){return(this.options.load==="languageOnly"||this.options.nonExplicitSupportedLngs)&&(t=this.getLanguagePartFromCode(t)),!this.supportedLngs||!this.supportedLngs.length||this.supportedLngs.indexOf(t)>-1}getBestMatchFromCodes(t){if(!t)return null;let n;return t.forEach(o=>{if(n)return;const s=this.formatLanguageCode(o);(!this.options.supportedLngs||this.isSupportedCode(s))&&(n=s)}),!n&&this.options.supportedLngs&&t.forEach(o=>{if(n)return;const s=this.getScriptPartFromCode(o);if(this.isSupportedCode(s))return n=s;const a=this.getLanguagePartFromCode(o);if(this.isSupportedCode(a))return n=a;n=this.options.supportedLngs.find(i=>{if(i===a)return i;if(!(i.indexOf("-")<0&&a.indexOf("-")<0)&&(i.indexOf("-")>0&&a.indexOf("-")<0&&i.substring(0,i.indexOf("-"))===a||i.indexOf(a)===0&&a.length>1))return i})}),n||(n=this.getFallbackCodes(this.options.fallbackLng)[0]),n}getFallbackCodes(t,n){if(!t)return[];if(typeof t=="function"&&(t=t(n)),Ie(t)&&(t=[t]),Array.isArray(t))return t;if(!n)return t.default||[];let o=t[n];return o||(o=t[this.getScriptPartFromCode(n)]),o||(o=t[this.formatLanguageCode(n)]),o||(o=t[this.getLanguagePartFromCode(n)]),o||(o=t.default),o||[]}toResolveHierarchy(t,n){const o=this.getFallbackCodes((n===!1?[]:n)||this.options.fallbackLng||[],t),s=[],a=i=>{i&&(this.isSupportedCode(i)?s.push(i):this.logger.warn(`rejecting language code not found in supportedLngs: ${i}`))};return Ie(t)&&(t.indexOf("-")>-1||t.indexOf("_")>-1)?(this.options.load!=="languageOnly"&&a(this.formatLanguageCode(t)),this.options.load!=="languageOnly"&&this.options.load!=="currentOnly"&&a(this.getScriptPartFromCode(t)),this.options.load!=="currentOnly"&&a(this.getLanguagePartFromCode(t))):Ie(t)&&a(this.formatLanguageCode(t)),o.forEach(i=>{s.indexOf(i)<0&&a(this.formatLanguageCode(i))}),s}}const nf={zero:0,one:1,two:2,few:3,many:4,other:5},rf={select:e=>e===1?"one":"other",resolvedOptions:()=>({pluralCategories:["one","other"]})};class t9{constructor(t,n={}){this.languageUtils=t,this.options=n,this.logger=Wt.create("pluralResolver"),this.pluralRulesCache={}}clearCache(){this.pluralRulesCache={}}getRule(t,n={}){const o=zo(t==="dev"?"en":t),s=n.ordinal?"ordinal":"cardinal",a=JSON.stringify({cleanedCode:o,type:s});if(a in this.pluralRulesCache)return this.pluralRulesCache[a];let i;try{i=new Intl.PluralRules(o,{type:s})}catch{if(typeof Intl>"u")return this.logger.error("No Intl support, please use an Intl polyfill!"),rf;if(!t.match(/-|_/))return rf;const c=this.languageUtils.getLanguagePartFromCode(t);i=this.getRule(c,n)}return this.pluralRulesCache[a]=i,i}needsPlural(t,n={}){let o=this.getRule(t,n);return o||(o=this.getRule("dev",n)),o?.resolvedOptions().pluralCategories.length>1}getPluralFormsOfKey(t,n,o={}){return this.getSuffixes(t,o).map(s=>`${n}${s}`)}getSuffixes(t,n={}){let o=this.getRule(t,n);return o||(o=this.getRule("dev",n)),o?o.resolvedOptions().pluralCategories.sort((s,a)=>nf[s]-nf[a]).map(s=>`${this.options.prepend}${n.ordinal?`ordinal${this.options.prepend}`:""}${s}`):[]}getSuffix(t,n,o={}){const s=this.getRule(t,o);return s?`${this.options.prepend}${o.ordinal?`ordinal${this.options.prepend}`:""}${s.select(n)}`:(this.logger.warn(`no plural rule found for: ${t}`),this.getSuffix("dev",n,o))}}const of=(e,t,n,o=".",s=!0)=>{let a=Q7(e,t,n);return!a&&s&&Ie(n)&&(a=oc(e,n,o),a===void 0&&(a=oc(t,n,o))),a},Xi=e=>e.replace(/\$/g,"$$$$");class sf{constructor(t={}){this.logger=Wt.create("interpolator"),this.options=t,this.format=t?.interpolation?.format||(n=>n),this.init(t)}init(t={}){t.interpolation||(t.interpolation={escapeValue:!0});const{escape:n,escapeValue:o,useRawValueToEscape:s,prefix:a,prefixEscaped:i,suffix:l,suffixEscaped:c,formatSeparator:d,unescapeSuffix:p,unescapePrefix:f,nestingPrefix:m,nestingPrefixEscaped:h,nestingSuffix:g,nestingSuffixEscaped:x,nestingOptionsSeparator:b,maxReplaces:y,alwaysFormat:w}=t.interpolation;this.escape=n!==void 0?n:W7,this.escapeValue=o!==void 0?o:!0,this.useRawValueToEscape=s!==void 0?s:!1,this.prefix=a?Un(a):i||"{{",this.suffix=l?Un(l):c||"}}",this.formatSeparator=d||",",this.unescapePrefix=p?"":f||"-",this.unescapeSuffix=this.unescapePrefix?"":p||"",this.nestingPrefix=m?Un(m):h||Un("$t("),this.nestingSuffix=g?Un(g):x||Un(")"),this.nestingOptionsSeparator=b||",",this.maxReplaces=y||1e3,this.alwaysFormat=w!==void 0?w:!1,this.resetRegExp()}reset(){this.options&&this.init(this.options)}resetRegExp(){const t=(n,o)=>n?.source===o?(n.lastIndex=0,n):new RegExp(o,"g");this.regexp=t(this.regexp,`${this.prefix}(.+?)${this.suffix}`),this.regexpUnescape=t(this.regexpUnescape,`${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`),this.nestingRegexp=t(this.nestingRegexp,`${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`)}interpolate(t,n,o,s){let a,i,l;const c=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{},d=h=>{if(h.indexOf(this.formatSeparator)<0){const y=of(n,c,h,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(y,void 0,o,{...s,...n,interpolationkey:h}):y}const g=h.split(this.formatSeparator),x=g.shift().trim(),b=g.join(this.formatSeparator).trim();return this.format(of(n,c,x,this.options.keySeparator,this.options.ignoreJSONStructure),b,o,{...s,...n,interpolationkey:x})};this.resetRegExp();const p=s?.missingInterpolationHandler||this.options.missingInterpolationHandler,f=s?.interpolation?.skipOnVariables!==void 0?s.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:h=>Xi(h)},{regex:this.regexp,safeValue:h=>this.escapeValue?Xi(this.escape(h)):Xi(h)}].forEach(h=>{for(l=0;a=h.regex.exec(t);){const g=a[1].trim();if(i=d(g),i===void 0)if(typeof p=="function"){const b=p(t,a,s);i=Ie(b)?b:""}else if(s&&Object.prototype.hasOwnProperty.call(s,g))i="";else if(f){i=a[0];continue}else this.logger.warn(`missed to pass in variable ${g} for interpolating ${t}`),i="";else!Ie(i)&&!this.useRawValueToEscape&&(i=Kp(i));const x=h.safeValue(i);if(t=t.replace(a[0],x),f?(h.regex.lastIndex+=i.length,h.regex.lastIndex-=a[0].length):h.regex.lastIndex=0,l++,l>=this.maxReplaces)break}}),t}nest(t,n,o={}){let s,a,i;const l=(c,d)=>{const p=this.nestingOptionsSeparator;if(c.indexOf(p)<0)return c;const f=c.split(new RegExp(`${Un(p)}[ ]*{`));let m=`{${f[1]}`;c=f[0],m=this.interpolate(m,i);const h=m.match(/'/g),g=m.match(/"/g);((h?.length??0)%2===0&&!g||(g?.length??0)%2!==0)&&(m=m.replace(/'/g,'"'));try{i=JSON.parse(m),d&&(i={...d,...i})}catch(x){return this.logger.warn(`failed parsing options string in nesting for key ${c}`,x),`${c}${p}${m}`}return i.defaultValue&&i.defaultValue.indexOf(this.prefix)>-1&&delete i.defaultValue,c};for(;s=this.nestingRegexp.exec(t);){let c=[];i={...o},i=i.replace&&!Ie(i.replace)?i.replace:i,i.applyPostProcessor=!1,delete i.defaultValue;const d=/{.*}/.test(s[1])?s[1].lastIndexOf("}")+1:s[1].indexOf(this.formatSeparator);if(d!==-1&&(c=s[1].slice(d).split(this.formatSeparator).map(p=>p.trim()).filter(Boolean),s[1]=s[1].slice(0,d)),a=n(l.call(this,s[1].trim(),i),i),a&&s[0]===t&&!Ie(a))return a;Ie(a)||(a=Kp(a)),a||(this.logger.warn(`missed to resolve ${s[1]} for nesting ${t}`),a=""),c.length&&(a=c.reduce((p,f)=>this.format(p,f,o.lng,{...o,interpolationkey:s[1].trim()}),a.trim())),t=t.replace(s[0],a),this.regexp.lastIndex=0}return t}}const n9=e=>{let t=e.toLowerCase().trim();const n={};if(e.indexOf("(")>-1){const o=e.split("(");t=o[0].toLowerCase().trim();const s=o[1].substring(0,o[1].length-1);t==="currency"&&s.indexOf(":")<0?n.currency||(n.currency=s.trim()):t==="relativetime"&&s.indexOf(":")<0?n.range||(n.range=s.trim()):s.split(";").forEach(i=>{if(i){const[l,...c]=i.split(":"),d=c.join(":").trim().replace(/^'+|'+$/g,""),p=l.trim();n[p]||(n[p]=d),d==="false"&&(n[p]=!1),d==="true"&&(n[p]=!0),isNaN(d)||(n[p]=parseInt(d,10))}})}return{formatName:t,formatOptions:n}},af=e=>{const t={};return(n,o,s)=>{let a=s;s&&s.interpolationkey&&s.formatParams&&s.formatParams[s.interpolationkey]&&s[s.interpolationkey]&&(a={...a,[s.interpolationkey]:void 0});const i=o+JSON.stringify(a);let l=t[i];return l||(l=e(zo(o),s),t[i]=l),l(n)}},r9=e=>(t,n,o)=>e(zo(n),o)(t);class o9{constructor(t={}){this.logger=Wt.create("formatter"),this.options=t,this.init(t)}init(t,n={interpolation:{}}){this.formatSeparator=n.interpolation.formatSeparator||",";const o=n.cacheInBuiltFormats?af:r9;this.formats={number:o((s,a)=>{const i=new Intl.NumberFormat(s,{...a});return l=>i.format(l)}),currency:o((s,a)=>{const i=new Intl.NumberFormat(s,{...a,style:"currency"});return l=>i.format(l)}),datetime:o((s,a)=>{const i=new Intl.DateTimeFormat(s,{...a});return l=>i.format(l)}),relativetime:o((s,a)=>{const i=new Intl.RelativeTimeFormat(s,{...a});return l=>i.format(l,a.range||"day")}),list:o((s,a)=>{const i=new Intl.ListFormat(s,{...a});return l=>i.format(l)})}}add(t,n){this.formats[t.toLowerCase().trim()]=n}addCached(t,n){this.formats[t.toLowerCase().trim()]=af(n)}format(t,n,o,s={}){const a=n.split(this.formatSeparator);if(a.length>1&&a[0].indexOf("(")>1&&a[0].indexOf(")")<0&&a.find(l=>l.indexOf(")")>-1)){const l=a.findIndex(c=>c.indexOf(")")>-1);a[0]=[a[0],...a.splice(1,l)].join(this.formatSeparator)}return a.reduce((l,c)=>{const{formatName:d,formatOptions:p}=n9(c);if(this.formats[d]){let f=l;try{const m=s?.formatParams?.[s.interpolationkey]||{},h=m.locale||m.lng||s.locale||s.lng||o;f=this.formats[d](l,h,{...p,...s,...m})}catch(m){this.logger.warn(m)}return f}else this.logger.warn(`there was no format function for ${d}`);return l},t)}}const s9=(e,t)=>{e.pending[t]!==void 0&&(delete e.pending[t],e.pendingCount--)};class a9 extends ii{constructor(t,n,o,s={}){super(),this.backend=t,this.store=n,this.services=o,this.languageUtils=o.languageUtils,this.options=s,this.logger=Wt.create("backendConnector"),this.waitingReads=[],this.maxParallelReads=s.maxParallelReads||10,this.readingCalls=0,this.maxRetries=s.maxRetries>=0?s.maxRetries:5,this.retryTimeout=s.retryTimeout>=1?s.retryTimeout:350,this.state={},this.queue=[],this.backend?.init?.(o,s.backend,s)}queueLoad(t,n,o,s){const a={},i={},l={},c={};return t.forEach(d=>{let p=!0;n.forEach(f=>{const m=`${d}|${f}`;!o.reload&&this.store.hasResourceBundle(d,f)?this.state[m]=2:this.state[m]<0||(this.state[m]===1?i[m]===void 0&&(i[m]=!0):(this.state[m]=1,p=!1,i[m]===void 0&&(i[m]=!0),a[m]===void 0&&(a[m]=!0),c[f]===void 0&&(c[f]=!0)))}),p||(l[d]=!0)}),(Object.keys(a).length||Object.keys(i).length)&&this.queue.push({pending:i,pendingCount:Object.keys(i).length,loaded:{},errors:[],callback:s}),{toLoad:Object.keys(a),pending:Object.keys(i),toLoadLanguages:Object.keys(l),toLoadNamespaces:Object.keys(c)}}loaded(t,n,o){const s=t.split("|"),a=s[0],i=s[1];n&&this.emit("failedLoading",a,i,n),!n&&o&&this.store.addResourceBundle(a,i,o,void 0,void 0,{skipCopy:!0}),this.state[t]=n?-1:2,n&&o&&(this.state[t]=0);const l={};this.queue.forEach(c=>{q7(c.loaded,[a],i),s9(c,t),n&&c.errors.push(n),c.pendingCount===0&&!c.done&&(Object.keys(c.loaded).forEach(d=>{l[d]||(l[d]={});const p=c.loaded[d];p.length&&p.forEach(f=>{l[d][f]===void 0&&(l[d][f]=!0)})}),c.done=!0,c.errors.length?c.callback(c.errors):c.callback())}),this.emit("loaded",l),this.queue=this.queue.filter(c=>!c.done)}read(t,n,o,s=0,a=this.retryTimeout,i){if(!t.length)return i(null,{});if(this.readingCalls>=this.maxParallelReads){this.waitingReads.push({lng:t,ns:n,fcName:o,tried:s,wait:a,callback:i});return}this.readingCalls++;const l=(d,p)=>{if(this.readingCalls--,this.waitingReads.length>0){const f=this.waitingReads.shift();this.read(f.lng,f.ns,f.fcName,f.tried,f.wait,f.callback)}if(d&&p&&s<this.maxRetries){setTimeout(()=>{this.read.call(this,t,n,o,s+1,a*2,i)},a);return}i(d,p)},c=this.backend[o].bind(this.backend);if(c.length===2){try{const d=c(t,n);d&&typeof d.then=="function"?d.then(p=>l(null,p)).catch(l):l(null,d)}catch(d){l(d)}return}return c(t,n,l)}prepareLoading(t,n,o={},s){if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),s&&s();Ie(t)&&(t=this.languageUtils.toResolveHierarchy(t)),Ie(n)&&(n=[n]);const a=this.queueLoad(t,n,o,s);if(!a.toLoad.length)return a.pending.length||s(),null;a.toLoad.forEach(i=>{this.loadOne(i)})}load(t,n,o){this.prepareLoading(t,n,{},o)}reload(t,n,o){this.prepareLoading(t,n,{reload:!0},o)}loadOne(t,n=""){const o=t.split("|"),s=o[0],a=o[1];this.read(s,a,"read",void 0,void 0,(i,l)=>{i&&this.logger.warn(`${n}loading namespace ${a} for language ${s} failed`,i),!i&&l&&this.logger.log(`${n}loaded namespace ${a} for language ${s}`,l),this.loaded(t,i,l)})}saveMissing(t,n,o,s,a,i={},l=()=>{}){if(this.services?.utils?.hasLoadedNamespace&&!this.services?.utils?.hasLoadedNamespace(n)){this.logger.warn(`did not save key "${o}" as the namespace "${n}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");return}if(!(o==null||o==="")){if(this.backend?.create){const c={...i,isUpdate:a},d=this.backend.create.bind(this.backend);if(d.length<6)try{let p;d.length===5?p=d(t,n,o,s,c):p=d(t,n,o,s),p&&typeof p.then=="function"?p.then(f=>l(null,f)).catch(l):l(null,p)}catch(p){l(p)}else d(t,n,o,s,l,c)}!t||!t[0]||this.store.addResource(t[0],n,o,s)}}}const Ji=()=>({debug:!1,initAsync:!0,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,supportedLngs:!1,nonExplicitSupportedLngs:!1,load:"all",preload:!1,simplifyPluralSuffix:!0,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",partialBundledLanguages:!1,saveMissing:!1,updateMissing:!1,saveMissingTo:"fallback",saveMissingPlurals:!0,missingKeyHandler:!1,missingInterpolationHandler:!1,postProcess:!1,postProcessPassResolved:!1,returnNull:!1,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:!1,parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,appendNamespaceToCIMode:!1,overloadTranslationOptionHandler:e=>{let t={};if(typeof e[1]=="object"&&(t=e[1]),Ie(e[1])&&(t.defaultValue=e[1]),Ie(e[2])&&(t.tDescription=e[2]),typeof e[2]=="object"||typeof e[3]=="object"){const n=e[3]||e[2];Object.keys(n).forEach(o=>{t[o]=n[o]})}return t},interpolation:{escapeValue:!0,format:e=>e,prefix:"{{",suffix:"}}",formatSeparator:",",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",nestingOptionsSeparator:",",maxReplaces:1e3,skipOnVariables:!0},cacheInBuiltFormats:!0}),lf=e=>(Ie(e.ns)&&(e.ns=[e.ns]),Ie(e.fallbackLng)&&(e.fallbackLng=[e.fallbackLng]),Ie(e.fallbackNS)&&(e.fallbackNS=[e.fallbackNS]),e.supportedLngs?.indexOf?.("cimode")<0&&(e.supportedLngs=e.supportedLngs.concat(["cimode"])),typeof e.initImmediate=="boolean"&&(e.initAsync=e.initImmediate),e),Ps=()=>{},i9=e=>{Object.getOwnPropertyNames(Object.getPrototypeOf(e)).forEach(n=>{typeof e[n]=="function"&&(e[n]=e[n].bind(e))})},Tv="__i18next_supportNoticeShown",l9=()=>!!(typeof globalThis<"u"&&globalThis[Tv]||typeof process<"u"&&Yi&&Yi.I18NEXT_NO_SUPPORT_NOTICE||typeof process<"u"&&Yi),c9=()=>{typeof globalThis<"u"&&(globalThis[Tv]=!0)},d9=e=>!!(e?.modules?.backend?.name?.indexOf("Locize")>0||e?.modules?.backend?.constructor?.name?.indexOf("Locize")>0||e?.options?.backend?.backends&&e.options.backend.backends.some(t=>t?.name?.indexOf("Locize")>0||t?.constructor?.name?.indexOf("Locize")>0)||e?.options?.backend?.projectId||e?.options?.backend?.backendOptions&&e.options.backend.backendOptions.some(t=>t?.projectId));class Eo extends ii{constructor(t={},n){if(super(),this.options=lf(t),this.services={},this.logger=Wt,this.modules={external:[]},i9(this),n&&!this.isInitialized&&!t.isClone){if(!this.options.initAsync)return this.init(t,n),this;setTimeout(()=>{this.init(t,n)},0)}}init(t={},n){this.isInitializing=!0,typeof t=="function"&&(n=t,t={}),t.defaultNS==null&&t.ns&&(Ie(t.ns)?t.defaultNS=t.ns:t.ns.indexOf("translation")<0&&(t.defaultNS=t.ns[0]));const o=Ji();this.options={...o,...this.options,...lf(t)},this.options.interpolation={...o.interpolation,...this.options.interpolation},t.keySeparator!==void 0&&(this.options.userDefinedKeySeparator=t.keySeparator),t.nsSeparator!==void 0&&(this.options.userDefinedNsSeparator=t.nsSeparator),typeof this.options.overloadTranslationOptionHandler!="function"&&(this.options.overloadTranslationOptionHandler=o.overloadTranslationOptionHandler),this.options.showSupportNotice!==!1&&!d9(this)&&!l9()&&(typeof console<"u"&&typeof console.info<"u"&&console.info("🌐 i18next is made possible by our own product, Locize — consider powering your project with managed localization (AI, CDN, integrations): https://locize.com 💙"),c9());const s=d=>d?typeof d=="function"?new d:d:null;if(!this.options.isClone){this.modules.logger?Wt.init(s(this.modules.logger),this.options):Wt.init(null,this.options);let d;this.modules.formatter?d=this.modules.formatter:d=o9;const p=new tf(this.options);this.store=new Jp(this.options.resources,this.options);const f=this.services;f.logger=Wt,f.resourceStore=this.store,f.languageUtils=p,f.pluralResolver=new t9(p,{prepend:this.options.pluralSeparator,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),this.options.interpolation.format&&this.options.interpolation.format!==o.interpolation.format&&this.logger.deprecate("init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting"),d&&(!this.options.interpolation.format||this.options.interpolation.format===o.interpolation.format)&&(f.formatter=s(d),f.formatter.init&&f.formatter.init(f,this.options),this.options.interpolation.format=f.formatter.format.bind(f.formatter)),f.interpolator=new sf(this.options),f.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},f.backendConnector=new a9(s(this.modules.backend),f.resourceStore,f,this.options),f.backendConnector.on("*",(h,...g)=>{this.emit(h,...g)}),this.modules.languageDetector&&(f.languageDetector=s(this.modules.languageDetector),f.languageDetector.init&&f.languageDetector.init(f,this.options.detection,this.options)),this.modules.i18nFormat&&(f.i18nFormat=s(this.modules.i18nFormat),f.i18nFormat.init&&f.i18nFormat.init(this)),this.translator=new va(this.services,this.options),this.translator.on("*",(h,...g)=>{this.emit(h,...g)}),this.modules.external.forEach(h=>{h.init&&h.init(this)})}if(this.format=this.options.interpolation.format,n||(n=Ps),this.options.fallbackLng&&!this.services.languageDetector&&!this.options.lng){const d=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);d.length>0&&d[0]!=="dev"&&(this.options.lng=d[0])}!this.services.languageDetector&&!this.options.lng&&this.logger.warn("init: no languageDetector is used and no lng is defined"),["getResource","hasResourceBundle","getResourceBundle","getDataByLanguage"].forEach(d=>{this[d]=(...p)=>this.store[d](...p)}),["addResource","addResources","addResourceBundle","removeResourceBundle"].forEach(d=>{this[d]=(...p)=>(this.store[d](...p),this)});const l=mo(),c=()=>{const d=(p,f)=>{this.isInitializing=!1,this.isInitialized&&!this.initializedStoreOnce&&this.logger.warn("init: i18next is already initialized. You should call init just once!"),this.isInitialized=!0,this.options.isClone||this.logger.log("initialized",this.options),this.emit("initialized",this.options),l.resolve(f),n(p,f)};if(this.languages&&!this.isInitialized)return d(null,this.t.bind(this));this.changeLanguage(this.options.lng,d)};return this.options.resources||!this.options.initAsync?c():setTimeout(c,0),l}loadResources(t,n=Ps){let o=n;const s=Ie(t)?t:this.language;if(typeof t=="function"&&(o=t),!this.options.resources||this.options.partialBundledLanguages){if(s?.toLowerCase()==="cimode"&&(!this.options.preload||this.options.preload.length===0))return o();const a=[],i=l=>{if(!l||l==="cimode")return;this.services.languageUtils.toResolveHierarchy(l).forEach(d=>{d!=="cimode"&&a.indexOf(d)<0&&a.push(d)})};s?i(s):this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach(c=>i(c)),this.options.preload?.forEach?.(l=>i(l)),this.services.backendConnector.load(a,this.options.ns,l=>{!l&&!this.resolvedLanguage&&this.language&&this.setResolvedLanguage(this.language),o(l)})}else o(null)}reloadResources(t,n,o){const s=mo();return typeof t=="function"&&(o=t,t=void 0),typeof n=="function"&&(o=n,n=void 0),t||(t=this.languages),n||(n=this.options.ns),o||(o=Ps),this.services.backendConnector.reload(t,n,a=>{s.resolve(),o(a)}),s}use(t){if(!t)throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");if(!t.type)throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");return t.type==="backend"&&(this.modules.backend=t),(t.type==="logger"||t.log&&t.warn&&t.error)&&(this.modules.logger=t),t.type==="languageDetector"&&(this.modules.languageDetector=t),t.type==="i18nFormat"&&(this.modules.i18nFormat=t),t.type==="postProcessor"&&Dv.addPostProcessor(t),t.type==="formatter"&&(this.modules.formatter=t),t.type==="3rdParty"&&this.modules.external.push(t),this}setResolvedLanguage(t){if(!(!t||!this.languages)&&!(["cimode","dev"].indexOf(t)>-1)){for(let n=0;n<this.languages.length;n++){const o=this.languages[n];if(!(["cimode","dev"].indexOf(o)>-1)&&this.store.hasLanguageSomeTranslations(o)){this.resolvedLanguage=o;break}}!this.resolvedLanguage&&this.languages.indexOf(t)<0&&this.store.hasLanguageSomeTranslations(t)&&(this.resolvedLanguage=t,this.languages.unshift(t))}}changeLanguage(t,n){this.isLanguageChangingTo=t;const o=mo();this.emit("languageChanging",t);const s=l=>{this.language=l,this.languages=this.services.languageUtils.toResolveHierarchy(l),this.resolvedLanguage=void 0,this.setResolvedLanguage(l)},a=(l,c)=>{c?this.isLanguageChangingTo===t&&(s(c),this.translator.changeLanguage(c),this.isLanguageChangingTo=void 0,this.emit("languageChanged",c),this.logger.log("languageChanged",c)):this.isLanguageChangingTo=void 0,o.resolve((...d)=>this.t(...d)),n&&n(l,(...d)=>this.t(...d))},i=l=>{!t&&!l&&this.services.languageDetector&&(l=[]);const c=Ie(l)?l:l&&l[0],d=this.store.hasLanguageSomeTranslations(c)?c:this.services.languageUtils.getBestMatchFromCodes(Ie(l)?[l]:l);d&&(this.language||s(d),this.translator.language||this.translator.changeLanguage(d),this.services.languageDetector?.cacheUserLanguage?.(d)),this.loadResources(d,p=>{a(p,d)})};return!t&&this.services.languageDetector&&!this.services.languageDetector.async?i(this.services.languageDetector.detect()):!t&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(i):this.services.languageDetector.detect(i):i(t),o}getFixedT(t,n,o){const s=(a,i,...l)=>{let c;typeof i!="object"?c=this.options.overloadTranslationOptionHandler([a,i].concat(l)):c={...i},c.lng=c.lng||s.lng,c.lngs=c.lngs||s.lngs,c.ns=c.ns||s.ns,c.keyPrefix!==""&&(c.keyPrefix=c.keyPrefix||o||s.keyPrefix);const d={...this.options,...c};typeof c.keyPrefix=="function"&&(c.keyPrefix=Ar(c.keyPrefix,d));const p=this.options.keySeparator||".";let f;return c.keyPrefix&&Array.isArray(a)?f=a.map(m=>(typeof m=="function"&&(m=Ar(m,d)),`${c.keyPrefix}${p}${m}`)):(typeof a=="function"&&(a=Ar(a,d)),f=c.keyPrefix?`${c.keyPrefix}${p}${a}`:a),this.t(f,c)};return Ie(t)?s.lng=t:s.lngs=t,s.ns=n,s.keyPrefix=o,s}t(...t){return this.translator?.translate(...t)}exists(...t){return this.translator?.exists(...t)}setDefaultNamespace(t){this.options.defaultNS=t}hasLoadedNamespace(t,n={}){if(!this.isInitialized)return this.logger.warn("hasLoadedNamespace: i18next was not initialized",this.languages),!1;if(!this.languages||!this.languages.length)return this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty",this.languages),!1;const o=n.lng||this.resolvedLanguage||this.languages[0],s=this.options?this.options.fallbackLng:!1,a=this.languages[this.languages.length-1];if(o.toLowerCase()==="cimode")return!0;const i=(l,c)=>{const d=this.services.backendConnector.state[`${l}|${c}`];return d===-1||d===0||d===2};if(n.precheck){const l=n.precheck(this,i);if(l!==void 0)return l}return!!(this.hasResourceBundle(o,t)||!this.services.backendConnector.backend||this.options.resources&&!this.options.partialBundledLanguages||i(o,t)&&(!s||i(a,t)))}loadNamespaces(t,n){const o=mo();return this.options.ns?(Ie(t)&&(t=[t]),t.forEach(s=>{this.options.ns.indexOf(s)<0&&this.options.ns.push(s)}),this.loadResources(s=>{o.resolve(),n&&n(s)}),o):(n&&n(),Promise.resolve())}loadLanguages(t,n){const o=mo();Ie(t)&&(t=[t]);const s=this.options.preload||[],a=t.filter(i=>s.indexOf(i)<0&&this.services.languageUtils.isSupportedCode(i));return a.length?(this.options.preload=s.concat(a),this.loadResources(i=>{o.resolve(),n&&n(i)}),o):(n&&n(),Promise.resolve())}dir(t){if(t||(t=this.resolvedLanguage||(this.languages?.length>0?this.languages[0]:this.language)),!t)return"rtl";try{const s=new Intl.Locale(t);if(s&&s.getTextInfo){const a=s.getTextInfo();if(a&&a.direction)return a.direction}}catch{}const n=["ar","shu","sqr","ssh","xaa","yhd","yud","aao","abh","abv","acm","acq","acw","acx","acy","adf","ads","aeb","aec","afb","ajp","apc","apd","arb","arq","ars","ary","arz","auz","avl","ayh","ayl","ayn","ayp","bbz","pga","he","iw","ps","pbt","pbu","pst","prp","prd","ug","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam","ckb"],o=this.services?.languageUtils||new tf(Ji());return t.toLowerCase().indexOf("-latn")>1?"ltr":n.indexOf(o.getLanguagePartFromCode(t))>-1||t.toLowerCase().indexOf("-arab")>1?"rtl":"ltr"}static createInstance(t={},n){const o=new Eo(t,n);return o.createInstance=Eo.createInstance,o}cloneInstance(t={},n=Ps){const o=t.forkResourceStore;o&&delete t.forkResourceStore;const s={...this.options,...t,isClone:!0},a=new Eo(s);if((t.debug!==void 0||t.prefix!==void 0)&&(a.logger=a.logger.clone(t)),["store","services","language"].forEach(l=>{a[l]=this[l]}),a.services={...this.services},a.services.utils={hasLoadedNamespace:a.hasLoadedNamespace.bind(a)},o){const l=Object.keys(this.store.data).reduce((c,d)=>(c[d]={...this.store.data[d]},c[d]=Object.keys(c[d]).reduce((p,f)=>(p[f]={...c[d][f]},p),c[d]),c),{});a.store=new Jp(l,s),a.services.resourceStore=a.store}if(t.interpolation){const c={...Ji().interpolation,...this.options.interpolation,...t.interpolation},d={...s,interpolation:c};a.services.interpolator=new sf(d)}return a.translator=new va(a.services,s),a.translator.on("*",(l,...c)=>{a.emit(l,...c)}),a.init(s,n),a.translator.options=s,a.translator.backendConnector.services.utils={hasLoadedNamespace:a.hasLoadedNamespace.bind(a)},a}toJSON(){return{options:this.options,store:this.store,language:this.language,languages:this.languages,resolvedLanguage:this.resolvedLanguage}}}const it=Eo.createInstance();it.createInstance;it.dir;it.init;it.loadResources;it.reloadResources;it.use;it.changeLanguage;it.getFixedT;it.t;it.exists;it.setDefaultNamespace;it.hasLoadedNamespace;it.loadNamespaces;it.loadLanguages;const u9=(e,t,n,o)=>{const s=[n,{code:t,...o||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(s,"warn","react-i18next::",!0);or(s[0])&&(s[0]=`react-i18next:: ${s[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...s):console?.warn&&console.warn(...s)},cf={},sc=(e,t,n,o)=>{or(n)&&cf[n]||(or(n)&&(cf[n]=new Date),u9(e,t,n,o))},Rv=(e,t)=>()=>{if(e.isInitialized)t();else{const n=()=>{setTimeout(()=>{e.off("initialized",n)},0),t()};e.on("initialized",n)}},ac=(e,t,n)=>{e.loadNamespaces(t,Rv(e,n))},df=(e,t,n,o)=>{if(or(n)&&(n=[n]),e.options.preload&&e.options.preload.indexOf(t)>-1)return ac(e,n,o);n.forEach(s=>{e.options.ns.indexOf(s)<0&&e.options.ns.push(s)}),e.loadLanguages(t,Rv(e,o))},p9=(e,t,n={})=>!t.languages||!t.languages.length?(sc(t,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:t.languages}),!0):t.hasLoadedNamespace(e,{lng:n.lng,precheck:(o,s)=>{if(n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&o.services.backendConnector.backend&&o.isLanguageChangingTo&&!s(o.isLanguageChangingTo,e))return!1}}),or=e=>typeof e=="string",f9=e=>typeof e=="object"&&e!==null,m9=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,h9={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},g9=e=>h9[e],b9=e=>e.replace(m9,g9);let ic={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:b9,transDefaultProps:void 0};const x9=(e={})=>{ic={...ic,...e}},y9=()=>ic;let Ov;const v9=e=>{Ov=e},w9=()=>Ov,N9={type:"3rdParty",init(e){x9(e.options.react),v9(e)}},k9=qe();class S9{constructor(){this.usedNamespaces={}}addUsedNamespaces(t){t.forEach(n=>{this.usedNamespaces[n]||(this.usedNamespaces[n]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}var Bv={exports:{}},zv={};/**
1163
+ * @license React
1164
+ * use-sync-external-store-shim.production.js
1165
+ *
1166
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
1167
+ *
1168
+ * This source code is licensed under the MIT license found in the
1169
+ * LICENSE file in the root directory of this source tree.
1170
+ */var Br=fh;function C9(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var M9=typeof Object.is=="function"?Object.is:C9,A9=Br.useState,E9=Br.useEffect,I9=Br.useLayoutEffect,P9=Br.useDebugValue;function _9(e,t){var n=t(),o=A9({inst:{value:n,getSnapshot:t}}),s=o[0].inst,a=o[1];return I9(function(){s.value=n,s.getSnapshot=t,el(s)&&a({inst:s})},[e,n,t]),E9(function(){return el(s)&&a({inst:s}),e(function(){el(s)&&a({inst:s})})},[e]),P9(n),n}function el(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!M9(e,n)}catch{return!0}}function $9(e,t){return t()}var D9=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?$9:_9;zv.useSyncExternalStore=Br.useSyncExternalStore!==void 0?Br.useSyncExternalStore:D9;Bv.exports=zv;var Fv=Bv.exports;const L9=(e,t)=>{if(or(t))return t;if(f9(t)&&or(t.defaultValue))return t.defaultValue;if(typeof e=="function")return"";if(Array.isArray(e)){const n=e[e.length-1];return typeof n=="function"?"":n}return e},T9={t:L9,ready:!1},R9=()=>()=>{},Ht=(e,t={})=>{const{i18n:n}=t,{i18n:o,defaultNS:s}=Ne(k9)||{},a=n||o||w9();a&&!a.reportNamespaces&&(a.reportNamespaces=new S9),a||sc(a,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const i=q(()=>({...y9(),...a?.options?.react,...t}),[a,t]),{useSuspense:l,keyPrefix:c}=i,d=s||a?.options?.defaultNS,p=or(d)?[d]:d||["translation"],f=q(()=>p,p);a?.reportNamespaces?.addUsedNamespaces?.(f);const m=ne(0),h=U(_=>{if(!a)return R9;const{bindI18n:$,bindI18nStore:E}=i,R=()=>{m.current+=1,_()};return $&&a.on($,R),E&&a.store.on(E,R),()=>{$&&$.split(" ").forEach(O=>a.off(O,R)),E&&E.split(" ").forEach(O=>a.store.off(O,R))}},[a,i]),g=ne(),x=U(()=>{if(!a)return T9;const _=!!(a.isInitialized||a.initializedStoreOnce)&&f.every(P=>p9(P,a,i)),$=t.lng||a.language,E=m.current,R=g.current;if(R&&R.ready===_&&R.lng===$&&R.keyPrefix===c&&R.revision===E)return R;const A={t:a.getFixedT($,i.nsMode==="fallback"?f:f[0],c),ready:_,lng:$,keyPrefix:c,revision:E};return g.current=A,A},[a,f,c,i,t.lng]),[b,y]=I(0),{t:w,ready:v}=Fv.useSyncExternalStore(h,x,x);J(()=>{if(a&&!v&&!l){const _=()=>y($=>$+1);t.lng?df(a,t.lng,f,_):ac(a,f,_)}},[a,t.lng,f,v,l,b]);const N=a||{},k=ne(null),C=ne(),D=_=>{const $=Object.getOwnPropertyDescriptors(_);$.__original&&delete $.__original;const E=Object.create(Object.getPrototypeOf(_),$);if(!Object.prototype.hasOwnProperty.call(E,"__original"))try{Object.defineProperty(E,"__original",{value:_,writable:!1,enumerable:!1,configurable:!1})}catch{}return E},M=q(()=>{const _=N,$=_?.language;let E=_;_&&(k.current&&k.current.__original===_?C.current!==$?(E=D(_),k.current=E,C.current=$):E=k.current:(E=D(_),k.current=E,C.current=$));const R=!v&&!l?(...A)=>(sc(a,"USE_T_BEFORE_READY","useTranslation: t was called before ready. When using useSuspense: false, make sure to check the ready flag before using t."),w(...A)):w,O=[R,E,v];return O.t=R,O.i18n=E,O.ready=v,O},[w,N,v,N.resolvedLanguage,N.language,N.languages]);if(a&&l&&!v)throw new Promise(_=>{const $=()=>_();t.lng?df(a,t.lng,f,$):ac(a,f,$)});return M},uf={info:rr,success:ti,warning:pt,error:nr},O9={info:"text-blue-400",success:"text-green-400",warning:"text-amber-400",error:"text-red-400"},pf={active:"border-l-blue-400","in-progress":"border-l-amber-400",completed:"border-l-green-400",failed:"border-l-red-400",dismissed:"border-l-foreground-subtle/30"};function B9(e){const t=Math.floor((Date.now()-e)/1e3);if(t<60)return"just now";const n=Math.floor(t/60);if(n<60)return`${String(n)}m ago`;const o=Math.floor(n/60);if(o<24)return`${String(o)}h ago`;const s=Math.floor(o/24);return`${String(s)}d ago`}function ff({alert:e,onMarkRead:t,onDismiss:n}){const o=e.severity in uf?e.severity:"info",s=e.status in pf?e.status:"active",a=uf[o],i=O9[o],l=pf[s];return u("div",{className:`flex items-start gap-2.5 px-3 py-2.5 border-l-2 ${l} ${e.read?"opacity-60":""} hover:bg-surface-hover transition-colors`,children:[r(a,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 ${i}`}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-1.5",children:[r("span",{className:`text-[11px] font-semibold ${e.read?"text-foreground-subtle":"text-foreground"}`,children:e.title}),!e.read&&r("span",{className:"h-1.5 w-1.5 rounded-full bg-primary shrink-0"})]}),r("div",{className:"text-[10px] text-foreground-subtle mt-0.5 line-clamp-2",children:e.message}),e.status==="in-progress"&&e.progress!==void 0&&u("div",{className:"mt-1.5 flex items-center gap-2",children:[r("div",{className:"flex-1 h-1 bg-surface-hover rounded-full overflow-hidden",children:r("div",{className:"h-full bg-primary rounded-full transition-all duration-300",style:{width:`${String(Math.min(100,Math.max(0,e.progress)))}%`}})}),u("span",{className:"text-[9px] text-foreground-subtle font-mono shrink-0",children:[String(Math.round(e.progress)),"%"]})]}),r("div",{className:"text-[9px] text-foreground-subtle/60 mt-1",children:B9(e.updatedAt)})]}),u("div",{className:"flex items-center gap-0.5 shrink-0",children:[!e.read&&r("button",{type:"button",onClick:c=>{c.stopPropagation(),t(e.id)},className:"p-1 rounded hover:bg-surface-hover transition-colors",title:"Mark as read",children:r(St,{className:"h-3 w-3 text-foreground-subtle"})}),e.status!=="in-progress"&&r("button",{type:"button",onClick:c=>{c.stopPropagation(),n(e.id)},className:"p-1 rounded hover:bg-surface-hover transition-colors",title:"Dismiss",children:r(Ve,{className:"h-3 w-3 text-foreground-subtle"})})]})]})}function mf({variant:e="icon",compact:t=!1}={}){const[n,o]=I(!1),[s,a]=I(!1),i=ne(null),l=ne(null),c=Me(),{data:d=0}=Eb(void 0,{staleTime:1e4,refetchInterval:3e4}),{data:p=[],isLoading:f}=Ab({limit:50},{enabled:n,staleTime:5e3}),m=s?p:p.filter($=>!$.read),h=p.filter($=>$.read).length,g=()=>{c.invalidateQueries({queryKey:[["alerts"]]})},x=Ib({onSuccess:g}),b=Pb({onSuccess:g}),y=_b({onSuccess:g});ft("alert.created",()=>{c.invalidateQueries({queryKey:[["alerts"]]})}),ft("alert.updated",()=>{c.invalidateQueries({queryKey:[["alerts"]]})}),J(()=>{if(!n)return;const $=E=>{const R=E.target;i.current&&!i.current.contains(R)&&l.current&&!l.current.contains(R)&&o(!1)};return document.addEventListener("mousedown",$),document.addEventListener("touchstart",$),()=>{document.removeEventListener("mousedown",$),document.removeEventListener("touchstart",$)}},[n]);const w=U($=>{x.mutate({alertId:$})},[x]),v=U($=>{$&&y.mutate({alertId:$})},[y]),N=U(()=>{b.mutate(void 0),o(!1)},[b]),k=m.filter($=>$.status==="in-progress"),C=m.filter($=>$.status!=="in-progress"),[D,M]=I({}),_=U(()=>{const $=l.current;if(!$)return;const E=$.getBoundingClientRect(),R=8,O=window.innerWidth,A=window.innerHeight,P=Math.min(320,O-R*2);let L=E.left;L+P>O-R&&(L=O-R-P),L<R&&(L=R);const B=A-E.bottom,z=E.top,T={position:"fixed",left:L,width:P,zIndex:9999};B>=z?(T.top=E.bottom+4,T.maxHeight=Math.max(160,B-R-4)):(T.bottom=A-E.top+4,T.maxHeight=Math.max(160,z-R-4)),M(T)},[]);return J(()=>{if(!n)return;_();const $=()=>_();return window.addEventListener("resize",$),window.addEventListener("scroll",$,!0),()=>{window.removeEventListener("resize",$),window.removeEventListener("scroll",$,!0)}},[n,_]),u("div",{children:[e==="sidebar"?u("button",{ref:l,type:"button",onClick:()=>o(!n),className:`flex w-full items-center gap-2.5 rounded-md ${t?"justify-center px-0 py-2":"px-2.5 py-1.5"} text-[12px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,title:t?`Alerts${d>0?` (${d})`:""}`:void 0,children:[u("span",{className:"relative inline-flex shrink-0",children:[r(At,{className:"h-3.5 w-3.5"}),t&&d>0&&r("span",{className:"absolute -top-1 -right-1 h-2 w-2 rounded-full bg-primary"})]}),!t&&r("span",{className:"flex-1 text-left",children:"Alerts"}),!t&&d>0&&r("span",{className:"flex items-center justify-center h-4 min-w-4 px-1 rounded-full bg-primary text-primary-foreground text-[9px] font-bold leading-none",children:d>99?"99+":String(d)})]}):u("button",{ref:l,type:"button",onClick:()=>o(!n),className:"relative p-1.5 rounded-md hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors","aria-label":"Alerts",children:[r(At,{className:"h-4.5 w-4.5"}),d>0&&r("span",{className:"absolute -top-0.5 -right-0.5 flex items-center justify-center h-4 min-w-4 px-0.5 rounded-full bg-primary text-primary-foreground text-[9px] font-bold leading-none",children:d>99?"99+":String(d)})]}),n&&Qr(u("div",{ref:i,style:D,className:"bg-surface border border-border rounded-lg shadow-xl flex flex-col overflow-hidden",children:[u("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border shrink-0",children:[r("span",{className:"text-[12px] font-semibold text-foreground",children:"Alerts"}),u("div",{className:"flex items-center gap-2",children:[h>0&&u("label",{className:"flex items-center gap-1 text-[10px] text-foreground-subtle cursor-pointer select-none",children:[r("input",{type:"checkbox",checked:s,onChange:$=>a($.target.checked),className:"h-3 w-3 rounded border-border accent-primary cursor-pointer"}),"Show read"]}),d>0&&u("button",{type:"button",onClick:N,className:"flex items-center gap-1 text-[10px] text-primary hover:text-primary/80 transition-colors",children:[r(oO,{className:"h-3 w-3"}),"Mark all read"]})]})]}),u("div",{className:"flex-1 overflow-y-auto",children:[f&&r("div",{className:"flex items-center justify-center py-8",children:r(Ee,{className:"h-4 w-4 animate-spin text-foreground-subtle"})}),!f&&m.length===0&&u("div",{className:"flex flex-col items-center justify-center py-8 text-foreground-subtle",children:[r(At,{className:"h-6 w-6 mb-2 opacity-40"}),r("span",{className:"text-[11px]",children:p.length>0?"No unread alerts":"No alerts"}),p.length>0&&!s&&u("button",{type:"button",onClick:()=>a(!0),className:"text-[10px] text-primary mt-1 hover:underline",children:["Show ",h," read alert",h!==1?"s":""]})]}),k.length>0&&u("div",{className:"border-b border-border",children:[r("div",{className:"px-3 py-1.5 bg-surface-hover/50",children:r("span",{className:"text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60",children:"In Progress"})}),k.map($=>r(ff,{alert:$,onMarkRead:w,onDismiss:v},$.id))]}),C.map($=>r(ff,{alert:$,onMarkRead:w,onDismiss:v},$.id))]})]}),document.body)]})}function jv(e){const t=new Set,n=[];for(const o of e){const s=`${o.addonId}::${o.page.id}`;t.has(s)||(t.add(s),n.push({id:o.page.id,addonId:o.addonId,label:o.page.label,icon:o.page.icon,path:o.page.path,remoteName:o.page.remoteName,bundle:o.page.bundle,bundleUrl:o.bundleUrl}))}return n}const hf=new Map,_s=new Map,gf=new Set;function z9(e){return!e||typeof e!="object"?!1:typeof e.default=="function"}async function F9(e,t){const n=hf.get(e);if(n)return n;const o=_s.get(e);if(o)return o;gf.has(e)||(Bc(),Pr.registerRemotes([{name:e,entry:t,type:"module"}],{force:!1}),gf.add(e));const s=Pr.loadRemote(`${e}/page`).then(a=>{if(!z9(a))throw new Error(`Addon page remote ${e} (${t}) does not expose a default React component on './page'`);return hf.set(e,a.default),_s.delete(e),a.default}).catch(a=>{throw _s.delete(e),a});return _s.set(e,s),s}function j9(){const{pagePath:e}=Zd(),t=De(),{data:n}=md(void 0,{staleTime:6e4}),o=q(()=>n?jv(n):void 0,[n]),s=o?.find(d=>d.path===`/addon/${e}`),[a,i]=I(null),[l,c]=I(null);return J(()=>{if(!s)return;c(null),i(null);let d=!1;return F9(s.remoteName,s.bundleUrl).then(p=>{d||i(()=>p)}).catch(p=>{if(d)return;const f=p instanceof Error?p.message:String(p);c(`Failed to load addon page: ${f}`)}),()=>{d=!0}},[s]),o?s?l?r("div",{className:"flex items-center justify-center h-full text-red-400 text-sm",children:l}):a?r(a,{trpc:t.trpcClient,theme:{isDark:document.documentElement.classList.contains("dark")},navigate:d=>{window.location.href=d}}):r("div",{className:"flex items-center justify-center h-full",children:r("div",{className:"animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full"})}):r("div",{className:"flex items-center justify-center h-full text-foreground-subtle",children:"Addon page not found"}):r("div",{className:"flex items-center justify-center h-full",children:r("div",{className:"animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full"})})}const H9={dark:yv,light:n7,system:f8},V9={gauge:_O,puzzle:ba,bot:K6,cpu:jt,terminal:Ev,box:su,wrench:x7,activity:Ja,plug:Bo};function U9(){const e=kt(),t=at(),{user:n,logout:o}=sn(),s=Yo(),{t:a}=Ht(),i=pr(),l=Ng(),c=$6(),d=c!=="connected",p=c==="connecting",[f,m]=I(!1),[h,g]=I(()=>typeof window>"u"?!1:window.localStorage.getItem("camstack:sidebar-collapsed")==="1");J(()=>{typeof window>"u"||window.localStorage.setItem("camstack:sidebar-collapsed",h?"1":"0")},[h]);const[x,b]=I(()=>{if(typeof window>"u")return new Set;try{const j=window.localStorage.getItem("camstack:sidebar-collapsed-groups");if(!j)return new Set;const Q=JSON.parse(j);return Array.isArray(Q)?new Set(Q.filter(G=>typeof G=="string")):new Set}catch{return new Set}});J(()=>{typeof window>"u"||window.localStorage.setItem("camstack:sidebar-collapsed-groups",JSON.stringify([...x]))},[x]),J(()=>{l&&window.localStorage.getItem("camstack:sidebar-collapsed")===null&&g(!0)},[l]);const{data:y=[]}=gd({nodeId:"hub"},{staleTime:3e4,refetchInterval:3e4}),w=y.length,v=Me(),N=ne(Date.now()),k=3e4,C=2e3,{data:D}=md(void 0,{staleTime:0,refetchOnMount:"always",refetchInterval:j=>{const Q=j.state.data;return Q&&Q.length>0||Date.now()-N.current>=k?!1:C}}),M=q(()=>D&&n?.isAdmin?jv(D):[],[D,n?.isAdmin]);ft("addon.page-ready",()=>{v.invalidateQueries({queryKey:[["addonPages","listPages"]]})});const _=()=>{o(),t("/login")},$=j=>!!(e.pathname===j||e.pathname.startsWith(j+"/")),R=["/pipeline","/timeline"].some(j=>e.pathname===j||e.pathname.startsWith(j+"/")),O=n?.isAdmin===!0,A=[{label:a("nav.devices","Devices"),icon:Rr,path:"/devices"},{label:a("nav.integrations"),icon:Bo,path:"/integrations"},{label:a("nav.timeline","Timeline"),icon:pv,path:"/timeline"},{label:a("nav.pipeline","Pipeline"),icon:LO,path:"/pipeline"}].filter(Boolean),L=[{label:a("system.identity","Identity & Access"),icon:ri,path:"/system/identity",adminOnly:!0},{label:a("system.network","Network"),icon:Ln,path:"/system/network",adminOnly:!0},{label:a("system.integrations","Integrations"),icon:Bo,path:"/system/integrations",adminOnly:!0},{label:a("system.data","Data"),icon:fv,path:"/system/data",adminOnly:!0},{label:a("system.cluster","Cluster"),icon:Tn,path:"/system/cluster",adminOnly:!0},{label:a("system.capabilities","Capabilities"),icon:Mv,path:"/system/capabilities",adminOnly:!0},{label:a("system.addons"),icon:ba,path:"/system/addons",adminOnly:!0},{label:a("system.addonSettings","Addon Settings"),icon:tn,path:"/system/settings",adminOnly:!0},{label:a("system.logs","Logs"),icon:At,path:"/system/logs",adminOnly:!0}].filter(j=>!j.adminOnly||O),B=s?.mode??"system",z={dark:a("theme.dark"),light:a("theme.light"),system:a("theme.system")},T=h&&!i,F=(j,Q="md")=>`flex w-full items-center gap-2.5 rounded-md ${T?"justify-center px-0 py-2":"px-2.5 py-1.5"} ${Q==="lg"?"text-[13px] font-medium":"text-[12px]"} transition-all ${j?Q==="lg"?"bg-primary/12 text-primary shadow-sm shadow-primary/5":"bg-primary/12 text-primary":"text-foreground-subtle hover:bg-surface-hover hover:text-foreground"}`,H=u(me,{children:[u("div",{className:`flex h-14 items-center border-b border-border ${T?"justify-center px-1":"pl-3 pr-4 gap-2"}`,children:[!T&&r("img",{src:s?.resolvedMode==="light"?"/brand/logo-horizontal-light.svg":"/brand/logo-horizontal-dark.svg",alt:"CamStack Admin",className:"h-9 flex-1 min-w-0"}),!i&&r("button",{onClick:()=>g(j=>!j),className:`p-1.5 rounded-md hover:bg-surface-hover text-foreground-subtle transition-colors flex-shrink-0 ${T?"":"mr-2"}`,"aria-label":h?"Expand sidebar":"Collapse sidebar",title:h?"Expand sidebar":"Collapse sidebar",children:h?r(on,{className:"h-4 w-4"}):r(au,{className:"h-4 w-4"})})]}),u("nav",{className:`flex-1 overflow-y-auto py-3 ${T?"px-1.5":"px-2"} space-y-0.5`,children:[(()=>{const j=$("/dashboard");return u("button",{"data-testid":"nav-dashboard",onClick:()=>{t("/dashboard"),m(!1)},className:F(j,"lg"),title:T?a("nav.dashboard"):void 0,children:[r(gv,{className:`h-4 w-4 shrink-0 ${j?"text-primary":""}`}),!T&&a("nav.dashboard")]})})(),!T&&r("div",{className:"pt-4 pb-1.5 px-2.5",children:r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60",children:a("nav.camerasSection","Input systems")})}),T&&r("div",{className:"pt-3 mb-1 mx-2 border-t border-border/60"}),A.map(j=>{const Q=j.icon,G=$(j.path),Z=`nav-${j.path.replace(/^\//,"").replace(/\//g,"-")}`;return u("button",{"data-testid":Z,onClick:()=>{t(j.path),m(!1)},className:F(G),title:T?j.label:void 0,children:[r(Q,{className:`h-3.5 w-3.5 shrink-0 ${G?"text-primary":""}`}),!T&&j.label]},j.path)}),!T&&r("div",{className:"pt-4 pb-1.5 px-2.5",children:r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60",children:a("system.title")})}),T&&r("div",{className:"pt-3 mb-1 mx-2 border-t border-border/60"}),L.map(j=>{const Q=j.icon,G=$(j.path),Z=j.path==="/system/addons",V=`nav-${j.path.replace(/^\//,"").replace(/\//g,"-")}`;return u("button",{"data-testid":V,onClick:()=>{t(j.path),m(!1)},className:F(G),title:T?j.label:void 0,children:[r(Q,{className:`h-3.5 w-3.5 shrink-0 ${G?"text-primary":""}`}),!T&&u(me,{children:[r("span",{className:"flex-1 text-left",children:j.label}),Z&&w>0&&r("span",{className:"ml-auto rounded-full bg-primary px-1.5 py-0.5 text-[9px] font-bold text-primary-foreground leading-none",children:w})]}),T&&Z&&w>0&&r("span",{className:"absolute mt-[-14px] ml-3 h-2 w-2 rounded-full bg-primary"})]},j.path)}),M&&M.length>0&&!T&&r("div",{className:"pt-4 pb-1.5 px-2.5",children:r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60",children:a("nav.addonPages","Addon Pages")})}),T&&M&&M.length>0&&r("div",{className:"pt-3 mb-1 mx-2 border-t border-border/60"}),M?.map(j=>{const Q=$(j.path),G=V9[j.icon]??ba;return u("button",{onClick:()=>{t(j.path),m(!1)},className:F(Q),title:T?j.label:void 0,children:[r(G,{className:`h-3.5 w-3.5 shrink-0 ${Q?"text-primary":""}`}),!T&&j.label]},j.id)})]}),u("div",{className:`border-t border-border ${T?"p-1.5":"p-2"} space-y-0.5`,children:[u("button",{onClick:()=>s?.toggleMode(),className:F(!1),title:T?z[B]:void 0,children:[(()=>{const j=H9[B];return r(j,{className:"h-3.5 w-3.5 shrink-0"})})(),!T&&r("span",{children:z[B]})]}),r(mf,{variant:"sidebar",compact:T}),u("button",{type:"button",onClick:()=>t("/system/my-access"),className:F($("/system/my-access")),title:T?a("system.myAccess","My access"):void 0,children:[r(xn,{className:"h-3.5 w-3.5 shrink-0"}),!T&&r("span",{className:"truncate",children:a("system.myAccess","My access")})]}),u("button",{onClick:_,className:F(!1).replace("hover:text-foreground","hover:text-danger"),title:T?n?.username??"Logout":void 0,children:[r(lu,{className:"h-3.5 w-3.5 shrink-0"}),!T&&r("span",{className:"truncate",children:n?.username??"User"})]}),r("div",{className:`pt-1 text-[10px] text-foreground-disabled select-none ${T?"text-center":"px-2"}`,title:"admin-ui v0.1.46",children:T?"0.1.46":"v0.1.46"})]})]});return u("div",{className:"flex h-dvh overflow-hidden bg-background text-foreground",children:[!i&&r("aside",{className:`flex flex-col border-r border-border bg-surface/80 backdrop-blur-sm shrink-0 transition-[width] duration-150 ease-out ${T?"w-12":"w-48"}`,children:H}),i&&r(Xc,{open:f,onClose:()=>m(!1),width:"w-64",children:H}),u("div",{className:"flex flex-1 flex-col min-w-0",children:[d&&u("div",{className:"flex items-center justify-center gap-2 bg-danger/90 px-3 py-2 text-[12px] font-medium text-white shrink-0",children:[r(Pv,{className:"h-3.5 w-3.5"}),r("span",{children:p?a("connection.reconnecting","Reconnecting…"):a("connection.disconnected","Server unreachable — reconnecting…")}),r(Ee,{className:"h-3.5 w-3.5 animate-spin"})]}),i&&u("header",{className:"flex items-center h-12 border-b border-border px-3 shrink-0 bg-surface/80 backdrop-blur-sm",children:[r("button",{onClick:()=>m(!0),className:"p-1.5 -ml-1.5 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors","aria-label":"Open menu",children:r(l8,{className:"h-5 w-5"})}),r("div",{className:"flex-1 flex justify-center",children:r("img",{src:s?.resolvedMode==="light"?"/brand/logo-horizontal-light.svg":"/brand/logo-horizontal-dark.svg",alt:"CamStack",className:"h-7"})}),r(mf,{})]}),r("main",{className:`relative flex-1 min-h-0 overscroll-contain bg-background ${R?"overflow-hidden":"overflow-auto"}`,children:r(UR,{})})]})]})}function q9(){const{login:e,verifyTotp:t}=sn(),n=Yo(),o=at(),s=new URLSearchParams(window.location.search).get("next"),[a,i]=I(""),[l,c]=I(""),[d,p]=I(!1),[f,m]=I(""),[h,g]=I(!1),[x,b]=I("credentials"),[y,w]=I(""),[v,N]=I(""),k=async M=>{M.preventDefault(),m(""),g(!0);try{const _=await e(a,l);if(_.kind==="totp-required"){w(_.challengeToken),b("totp");return}l==="changeme"?o("/change-password",{replace:!0}):s?window.location.assign(s):o("/dashboard",{replace:!0})}catch(_){m(_ instanceof Error?_.message:"Login failed")}finally{g(!1)}},C=async M=>{M.preventDefault(),m(""),g(!0);try{await t(y,v.trim()),s?window.location.assign(s):o("/dashboard",{replace:!0})}catch(_){m(_ instanceof Error?_.message:"TOTP verification failed"),N("")}finally{g(!1)}},D=()=>{b("credentials"),w(""),N(""),m("")};return r("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:u("div",{className:"w-full max-w-sm",children:[r("div",{className:"flex justify-center mb-8",children:r("img",{src:n?.resolvedMode==="light"?"/brand/logo-horizontal-light.svg":"/brand/logo-horizontal-dark.svg",alt:"CamStack Admin",className:"h-12"})}),x==="credentials"?u("form",{onSubmit:k,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[f&&r("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:f}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"Username"}),r("input",{"data-testid":"login-username",type:"text",placeholder:"Username",value:a,onChange:M=>i(M.target.value),className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all",autoFocus:!0})]}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"Password"}),u("div",{className:"relative",children:[r("input",{"data-testid":"login-password",type:d?"text":"password",placeholder:"Password",value:l,onChange:M=>c(M.target.value),className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all"}),r("button",{type:"button",onClick:()=>p(!d),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground transition-colors",tabIndex:-1,children:d?r(mv,{className:"h-4 w-4"}):r(ni,{className:"h-4 w-4"})})]})]}),r("button",{"data-testid":"login-submit",type:"submit",disabled:h||!a||!l,className:"w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all",children:h?u("span",{className:"flex items-center justify-center gap-2",children:[r("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary-foreground/30 border-t-primary-foreground"}),"Logging in..."]}):"Log in"})]}):u("form",{onSubmit:C,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[u("div",{className:"flex items-center gap-2 pb-1 border-b border-border",children:[r($n,{className:"h-4 w-4 text-primary"}),r("div",{className:"text-sm font-medium text-foreground",children:"Two-factor authentication"})]}),u("p",{className:"text-xs text-foreground-subtle",children:["Enter the 6-digit code from your authenticator app to finish signing in as"," ",r("span",{className:"font-mono text-foreground",children:a}),"."]}),f&&r("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:f}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"Authentication code"}),r("input",{"data-testid":"login-totp",type:"text",inputMode:"numeric",autoComplete:"one-time-code",placeholder:"123456",value:v,onChange:M=>N(M.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full rounded-lg border border-border bg-background px-3 py-3 text-center text-2xl font-mono tracking-widest text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all",autoFocus:!0})]}),r("button",{"data-testid":"login-totp-submit",type:"submit",disabled:h||v.length!==6,className:"w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all",children:h?u("span",{className:"flex items-center justify-center gap-2",children:[r("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary-foreground/30 border-t-primary-foreground"}),"Verifying..."]}):"Verify and sign in"}),u("button",{type:"button",onClick:D,className:"w-full flex items-center justify-center gap-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors",children:[r(ou,{className:"h-3 w-3"}),"Back to username + password"]})]}),x==="credentials"&&r(Q9,{}),u("p",{className:"mt-6 text-center text-[10px] text-foreground-subtle/50",children:["CamStack v","0.1.46"]})]})})}function Q9(){const t=(S.auth.listProviders.useQuery().data??[]).filter(n=>n.flowType==="redirect");return t.length===0?null:u("div",{className:"mt-6 space-y-3",children:[u("div",{className:"flex items-center gap-3",children:[r("div",{className:"h-px flex-1 bg-border"}),r("span",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:"Or continue with"}),r("div",{className:"h-px flex-1 bg-border"})]}),r("div",{className:"space-y-2",children:t.map(n=>u("a",{href:`/addon/${encodeURIComponent(n.id)}/start`,className:"flex items-center justify-center gap-2 w-full rounded-lg border border-border bg-surface px-4 py-2.5 text-sm font-medium text-foreground hover:bg-surface-hover transition-colors",children:[r(xn,{className:"h-4 w-4 text-primary"}),n.name]},n.id))})]})}const bf=8;function G9(){const{user:e,mustChangePassword:t,clearMustChangePassword:n,logout:o}=sn(),s=Yo(),a=at(),[i,l]=I(""),[c,d]=I(""),[p,f]=I(!1),[m,h]=I(""),g=Dd({onSuccess:()=>{n(),a("/dashboard",{replace:!0})},onError:b=>{h(b instanceof Error?b.message:"Could not change password")}}),x=async b=>{if(b.preventDefault(),h(""),!e){h("Not signed in");return}if(i.length<bf){h(`Password must be at least ${bf} characters`);return}if(i!==c){h("The two passwords do not match");return}if(i==="changeme"){h("Choose a password different from the seed default");return}g.mutate({id:e.id,newPassword:i})};return r("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:u("div",{className:"w-full max-w-sm",children:[r("div",{className:"flex justify-center mb-8",children:r("img",{src:s?.resolvedMode==="light"?"/brand/logo-horizontal-light.svg":"/brand/logo-horizontal-dark.svg",alt:"CamStack Admin",className:"h-12"})}),u("form",{onSubmit:x,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[u("div",{className:"space-y-1",children:[r("h1",{className:"text-sm font-semibold text-foreground",children:"Set a new password"}),r("p",{className:"text-xs text-foreground-subtle",children:t?"You must rotate the seed password before continuing.":"Choose a new password for your account."})]}),m&&r("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:m}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"New password"}),u("div",{className:"relative",children:[r("input",{"data-testid":"change-password-new",type:p?"text":"password",value:i,onChange:b=>l(b.target.value),className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all",autoFocus:!0}),r("button",{type:"button",onClick:()=>f(!p),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground transition-colors",tabIndex:-1,children:p?r(mv,{className:"h-4 w-4"}):r(ni,{className:"h-4 w-4"})})]})]}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"Confirm new password"}),r("input",{"data-testid":"change-password-confirm",type:p?"text":"password",value:c,onChange:b=>d(b.target.value),className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all"})]}),r("button",{"data-testid":"change-password-submit",type:"submit",disabled:g.isPending||!i||!c,className:"w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all",children:g.isPending?"Saving…":"Save and continue"}),t&&r("button",{type:"button",onClick:()=>{o(),a("/login",{replace:!0})},className:"w-full text-xs text-foreground-subtle hover:text-foreground transition-colors",children:"Sign out instead"})]})]})})}function W9(){const e=at();return u("div",{className:"flex flex-col items-center justify-center text-foreground py-16 px-4",children:[r("div",{className:"flex h-16 w-16 items-center justify-center rounded-2xl bg-danger/10 mb-4",children:r(U8,{className:"h-8 w-8 text-danger"})}),r("h1",{className:"text-xl font-bold",children:"Access Denied"}),r("p",{className:"mt-2 text-sm text-foreground-subtle",children:"You don't have permission to access this page."}),r("button",{onClick:()=>e("/dashboard"),className:"mt-6 rounded-lg bg-primary px-5 py-2.5 text-sm font-medium text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg transition-all",children:"Go to Dashboard"})]})}const Hv="camstack:dashboard-layout",tl={version:1,widgets:[]};function K9(){try{const e=localStorage.getItem(Hv);if(!e)return tl;const t=JSON.parse(e);return t&&t.version===1&&Array.isArray(t.widgets)?{version:1,widgets:t.widgets}:tl}catch{return tl}}function Y9(e){try{localStorage.setItem(Hv,JSON.stringify(e))}catch{}}function Z9(){const e=typeof crypto<"u"?crypto:void 0;return e?.randomUUID?e.randomUUID():`widget-${Date.now().toString(36)}-${Math.floor(Math.random()*1e6).toString(36)}`}function X9(){const[e,t]=I(K9),[n,o]=I(!1),s=Yy(),a=q(()=>s.filter(d=>d.hosts.includes("dashboard")),[s]),i=U(d=>{t(d),Y9(d)},[]),l=U(d=>{i({version:1,widgets:[...e.widgets,d]})},[e,i]),c=U(d=>{i({version:1,widgets:e.widgets.filter(p=>p.instanceId!==d)})},[e,i]);return u("div",{className:"p-4",children:[u("div",{className:"flex items-center justify-between mb-4",children:[r("h1",{className:"text-lg font-semibold text-foreground",children:"Dashboard"}),u("button",{onClick:()=>o(!0),className:"flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors",children:[r(It,{className:"h-3.5 w-3.5"}),"Add widget"]})]}),e.widgets.length===0?r(J9,{onAdd:()=>o(!0)}):r("div",{className:"grid grid-cols-12 gap-3 auto-rows-[minmax(80px,_auto)]",children:e.widgets.map(d=>r(eB,{entry:d,onRemove:()=>c(d.instanceId)},d.instanceId))}),n&&r(nB,{widgets:a,onClose:()=>o(!1),onAdd:d=>{l(d),o(!1)}})]})}function J9({onAdd:e}){return u("div",{className:"flex flex-col items-center justify-center py-24 text-foreground-subtle",children:[r("div",{className:"flex h-16 w-16 items-center justify-center rounded-2xl bg-surface border border-border mb-4",children:r(gv,{className:"h-8 w-8 text-foreground-subtle/40"})}),r("p",{className:"text-sm font-medium text-foreground/70",children:"Your dashboard is empty"}),r("p",{className:"text-xs text-foreground-subtle mt-1 mb-4",children:"Add widgets to monitor your cameras and system"}),u("button",{onClick:e,className:"flex items-center gap-1.5 rounded-lg bg-primary px-4 py-2 text-xs font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg transition-all",children:[r(It,{className:"h-3.5 w-3.5"}),"Add your first widget"]})]})}function eB({entry:e,onRemove:t}){const n=tB(e.columns),o=Math.max(1,Math.min(12,e.rows));return u("div",{className:"relative group rounded-lg border border-border bg-surface overflow-hidden flex flex-col",style:{gridColumn:`span ${n} / span ${n}`,gridRow:`span ${o} / span ${o}`},children:[r("button",{type:"button",onClick:t,title:"Remove widget",className:"absolute right-1.5 top-1.5 z-10 inline-flex h-5 w-5 items-center justify-center rounded-md border border-border/60 bg-surface/80 text-foreground-subtle opacity-0 group-hover:opacity-100 hover:bg-danger/10 hover:text-danger hover:border-danger/40 transition-all",children:r(Ve,{className:"h-3 w-3"})}),r("div",{className:"flex-1 min-h-0 overflow-auto p-2",children:r(Tr,{widgetId:e.widgetId,host:"dashboard",instanceId:e.instanceId,config:e.config,deviceId:e.deviceId,size:e.size,columns:e.columns,rows:e.rows})})]})}function tB(e){return!Number.isFinite(e)||e<1?6:Math.min(12,Math.floor(e))}function nB({widgets:e,onClose:t,onAdd:n}){const[o,s]=I(null);return r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:t,children:u("div",{className:"w-full max-w-2xl rounded-xl border border-border bg-surface p-5 shadow-2xl shadow-black/20",onClick:a=>a.stopPropagation(),children:[u("div",{className:"flex items-center justify-between mb-4",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:o?`Configure: ${o.label}`:"Add widget"}),r("button",{onClick:t,className:"p-1 rounded-md hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors",children:r(Ve,{className:"h-4 w-4"})})]}),o===null?r(rB,{widgets:e,onSelect:s}):r(oB,{widget:o,onCancel:()=>s(null),onAdd:n})]})})}function rB({widgets:e,onSelect:t}){return e.length===0?r("div",{className:"text-center py-8 text-xs text-foreground-subtle italic",children:"No dashboard-host widgets registered. Make sure the contributing addons are enabled and have rebuilt their widget bundles."}):r("div",{className:"grid grid-cols-2 gap-2 max-h-96 overflow-auto",children:e.map(n=>u("button",{onClick:()=>t(n),className:"flex flex-col rounded-lg border border-border p-3 text-left hover:bg-surface-hover hover:border-primary/30 transition-all group",children:[r("span",{className:"text-xs font-medium text-foreground block",children:n.label}),r("span",{className:"text-[10px] text-foreground-subtle truncate",title:n.widgetId,children:n.widgetId}),n.description&&r("span",{className:"text-[10px] text-foreground-subtle mt-1 line-clamp-2",children:n.description})]},n.widgetId))})}function oB({widget:e,onCancel:t,onAdd:n}){const[o,s]=I(e.defaultSize),[a,i]=I(e.defaultColumns),[l,c]=I(e.defaultRows),[d,p]=I(null),{data:f}=kn({},{enabled:e.requires.deviceContext,staleTime:3e4}),m=!e.requires.deviceContext||d!==null&&d>0,h=()=>{if(!m)return;const g={instanceId:Z9(),widgetId:e.widgetId,size:o,columns:a,rows:l,...e.requires.deviceContext&&d!==null?{deviceId:d}:{}};n(g)};return u("div",{className:"space-y-3",children:[u("div",{children:[r("label",{className:"block text-[11px] font-medium text-foreground-subtle mb-1",children:"Size"}),r("div",{className:"flex items-center gap-1",children:e.allowedSizes.map(g=>r("button",{onClick:()=>s(g),className:`px-3 py-1 rounded-md text-[11px] font-medium border transition-colors ${o===g?"bg-primary/10 text-primary border-primary/30":"border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground"}`,children:g.toUpperCase()},g))})]}),u("div",{className:"grid grid-cols-2 gap-3",children:[r(xf,{label:"Columns (1-12)",value:a,min:1,max:12,onChange:i}),r(xf,{label:"Rows (1-12)",value:l,min:1,max:12,onChange:c})]}),e.requires.deviceContext&&u("div",{children:[r("label",{className:"block text-[11px] font-medium text-foreground-subtle mb-1",children:"Device"}),u("select",{value:d??"",onChange:g=>p(g.target.value===""?null:Number(g.target.value)),className:"w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none",children:[r("option",{value:"",children:"— select a device —"}),(f??[]).map(g=>u("option",{value:g.id,children:[g.name??g.stableId," (#",g.id,")"]},g.id))]})]}),u("div",{className:"flex items-center justify-end gap-2 pt-2 border-t border-border",children:[r("button",{onClick:t,className:"px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors",children:"Back"}),r("button",{disabled:!m,onClick:h,className:"px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:"Add to dashboard"})]})]})}function xf({label:e,value:t,min:n,max:o,onChange:s}){return u("div",{children:[r("label",{className:"block text-[11px] font-medium text-foreground-subtle mb-1",children:e}),r("input",{type:"number",min:n,max:o,value:t,onChange:a=>{const i=Number(a.target.value);Number.isFinite(i)&&s(Math.max(n,Math.min(o,Math.floor(i))))},className:"w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none"})]})}function sB(){return r(X9,{})}function Zt(e,t){const n=De(),o=Me(),[s,a]=I(n.connectionVersion);J(()=>n.subscribeConnectionEvents((c,d)=>{c==="connected"&&a(d)}),[n]);const i=t.join("|"),l=JSON.stringify(e);J(()=>{const c=[],d=()=>{const p=JSON.parse(l),m=p.length===1&&Array.isArray(p[0])?p:[p];o.invalidateQueries({queryKey:m})};d();for(const p of i.split("|"))if(p)try{c.push(n.subscribeEvent(p,d))}catch{}return()=>{for(const p of c)p()}},[n,o,i,l,s])}const aB={frigate:{icon:dv,color:"#3b82f6",label:"Frigate"},scrypted:{icon:Rn,color:"#a855f7",label:"Scrypted"},reolink:{icon:si,color:"#06b6d4",label:"Reolink"},homeassistant:{icon:BO,color:"#22d3ee",label:"Home Assistant"},rtsp:{icon:Or,color:"#78716c",label:"RTSP"},onvif:{icon:Or,color:"#78716c",label:"ONVIF"}},yf={sm:"h-4 w-4",md:"h-5 w-5",lg:"h-6 w-6"},iB={sm:"h-7 w-7",md:"h-8 w-8",lg:"h-10 w-10"};function Vv(e){const t=e.toLowerCase();return t.startsWith("provider-")?t.slice(9):t}function lB(e){const t=Vv(e);return aB[t]??{icon:dv,color:"#78716c",label:e}}function cB(e){const t=Vv(e);return`/api/addon-assets/${e.toLowerCase().startsWith("provider-")?e:`provider-${t}`}/assets/icon.svg`}function yn({type:e,size:t="md",showLabel:n}){const o=lB(e),s=o.icon,[a,i]=I(!1),l=cB(e);return u("div",{className:"flex items-center gap-2",children:[r("div",{className:`flex items-center justify-center rounded-lg ${iB[t]}`,style:{backgroundColor:`${o.color}15`},children:a?r(s,{className:yf[t],style:{color:o.color}}):r("img",{src:l,alt:o.label,className:yf[t],onError:()=>i(!0)})}),n&&r("span",{className:"text-xs font-medium text-foreground-subtle",children:o.label})]})}function ot({icon:e,title:t,subtitle:n,actions:o,children:s}){const a=!!t||n!=null||o!=null;return u("div",{className:"p-4 space-y-4",children:[a&&u("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-4",children:[u("div",{className:"min-w-0",children:[t&&u("h1",{className:"text-lg font-semibold text-foreground flex items-center gap-2",children:[e&&r(e,{className:"h-4 w-4 text-foreground-subtle shrink-0"}),t]}),n&&r("p",{className:"text-xs text-foreground-subtle mt-0.5",children:n})]}),o&&r("div",{className:"shrink-0 flex items-center gap-2 flex-wrap",children:o})]}),s]})}const vf=["camera","hub","nvr","light","siren","switch","sensor","thermostat","button","generic"];function dB(){const{t:e}=Ht(),t=at(),n=De();Zt(["deviceManager"],["device.registered","device.unregistered","device.online","device.offline","device.disabled","device.enabled"]),Zt(["integrations"],["integration.enabled","integration.disabled","integration.deleted","provider.started","provider.stopped","addon.installed","addon.uninstalled","addon.started","addon.stopped"]);const{data:o}=kn({},{staleTime:3e4}),{data:s}=Cd(void 0,{staleTime:3e4}),a=q(()=>o??[],[o]),{activeDevices:i,orphanDevices:l}=q(()=>{const h=new Set((s??[]).map(k=>k.addonId)),g=k=>typeof k.addonId=="string"&&k.addonId.length>0&&!h.has(k.addonId),x=new Set;for(const k of a)g(k)&&x.add(k.id);const b=new Set(x),y=new Map;for(const k of a)y.set(k.id,k);const w=(k,C=0)=>{if(C>32)return!1;if(x.has(k.id))return!0;if(k.parentDeviceId==null)return!1;const D=y.get(k.parentDeviceId);return D?w(D,C+1):!1};for(const k of a)w(k)&&b.add(k.id);const v=[],N=[];for(const k of a)b.has(k.id)?N.push(k):v.push(k);return{activeDevices:v,orphanDevices:N}},[a,s]),c=q(()=>{const h=new Map;for(const g of a)h.set(g.id,{id:g.id,name:g.name??g.stableId??`#${String(g.id)}`});return h},[a]),d=U(h=>c.get(h)??null,[c]),p=q(()=>(s??[]).map(h=>({id:h.addonId,name:h.name??h.addonId,icon:r(yn,{type:h.addonId,size:"sm"})})),[s]),f=U(h=>r(yn,{type:h,size:"sm"}),[]),m=U(h=>t(`/devices/${String(h)}`),[t]);return u(ot,{icon:Rr,title:e("nav.devices","Devices"),children:[r(Dr,{devices:i,trpc:n.trpcClient,filters:{types:vf,addons:p},resolveIntegrationIcon:f,resolveParent:d,onNavigate:m}),l.length>0&&u("div",{className:"mt-6 space-y-2",children:[u("div",{className:"flex items-baseline gap-2",children:[r(pt,{className:"h-3.5 w-3.5 text-warning shrink-0"}),r("h2",{className:"text-sm font-semibold text-foreground",children:"Orphan devices"}),u("span",{className:"text-[10px] text-foreground-subtle",children:[l.length," device",l.length===1?"":"s"," pointing at integrations no longer registered"]})]}),u("div",{className:"rounded-lg border border-warning/30 bg-warning/5 p-2",children:[r("p",{className:"text-[11px] text-foreground-subtle px-2 pb-2",children:"These devices reference an addonId that has no matching integration. Delete them, or re-install the missing integration to bring them back online. The provider scope (`addonId`) shown beside each row is what's failing to resolve."}),r(Dr,{devices:l,trpc:n.trpcClient,filters:{types:vf,addons:p},urlScope:"nested",lsKey:"devices:orphan",resolveIntegrationIcon:f,resolveParent:d,onNavigate:m})]})]})]})}function uB({onSelect:e,onClose:t,pendingAddonId:n=null}){const{t:o}=Ht(),s=at(),{data:a,isLoading:i}=mx();if(i)return r("div",{className:"space-y-2 p-2",children:[1,2,3].map(c=>r("div",{className:"h-14 rounded-lg bg-surface animate-pulse"},c))});const l=n!==null;return u("div",{className:"space-y-2",children:[(a??[]).map(c=>{const d=c.instanceMode==="unique"&&c.existingInstances.length>0,p=n===c.addonId,f=l;return u("button",{disabled:f,onClick:()=>{if(!f)if(d){const m=c.existingInstances[0].id;t(),s(`/integrations/${m}`)}else e(c.addonId,c.instanceMode,c.discoveryMode,c.name)},className:"flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border",children:[c.iconUrl?r("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0",style:{backgroundColor:`${c.color}15`},children:r("img",{src:c.iconUrl,alt:"",className:"h-5 w-5"})}):r("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0",style:{backgroundColor:`${c.color}15`},children:r("span",{className:"text-sm",style:{color:c.color},children:"◉"})}),u("div",{className:"flex-1 min-w-0",children:[r("p",{className:"text-xs font-semibold text-foreground",children:c.name}),c.description&&r("p",{className:"text-[10px] text-foreground-subtle mt-0.5 truncate",children:c.description})]}),p?r(Ee,{className:"h-4 w-4 animate-spin text-primary flex-shrink-0"}):d?u("span",{className:"flex items-center gap-1 text-[10px] font-medium text-foreground-subtle",children:[r(tn,{className:"h-3 w-3"}),o("integrations.manage")]}):r(on,{className:"h-4 w-4 text-foreground-subtle flex-shrink-0"})]},c.addonId)}),(a??[]).length===0&&r("div",{className:"py-8 text-center text-xs text-foreground-subtle",children:o("integrations.noProviders")})]})}function pB(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function wf(e,t){if(e!==void 0)return t&&pB(e)?t(e):e}function fB({section:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,probeResults:i,onAction:l}){const[c,d]=I(e.defaultCollapsed??!1),p=e.style==="accordion";if(e.fields.reduce((b,y)=>b+(Hd(y,t,e.fields)?1:0),0)===0)return null;const m=e.columns??2,h=m===1?"grid-cols-1":m===3?"grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3":m===4?"grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4":"grid-cols-1 @[480px]:grid-cols-2",x=e.fields.length===1&&e.fields[0]?.type==="widget"||!e.title&&!e.description;return u("div",{className:"@container rounded-lg border border-border bg-surface p-3",style:{containerType:"inline-size"},children:[!x&&u("div",{className:["flex items-center justify-between mb-2",p?"cursor-pointer":""].join(" "),onClick:p?()=>d(b=>!b):void 0,children:[u("div",{children:[e.title&&r("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:wf(e.title,s)}),e.description&&r("p",{className:"text-[10px] text-foreground-subtle mt-0.5",children:wf(e.description,s)})]}),p&&r("span",{className:"text-foreground-subtle text-xs ml-2",children:c?"▸":"▾"})]}),!c&&r("div",{className:`grid ${h} gap-x-3 gap-y-2.5`,children:e.fields.map(b=>r(mr,{field:b,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i?.[b.key],allFields:e.fields,onAction:l},b.key))})]})}function On({schema:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,probeResults:i,onClearProbe:l,onAction:c}){const d=(p,f)=>{n({...t,[p]:f}),l?.(p)};return r("div",{className:"space-y-4",children:e.sections.map((p,f)=>r(fB,{section:p,values:t,onChange:d,disabled:o,translationFn:s,onTestField:a,probeResults:i,onAction:c},`${p.id}-${f}`))})}function mB({addonId:e,configSchema:t,onSave:n,onBack:o}){const{t:s}=Ht(),[a,i]=I(""),[l,c]=I({}),[d,p]=I(null),f=hx({onSuccess:m=>p(m),onError:m=>p({success:!1,error:String(m)})});return u("div",{className:"space-y-4",children:[u("div",{children:[r("label",{className:"block text-[11px] font-medium text-foreground mb-1",children:s("integrations.integrationName")}),r("input",{type:"text",value:a,onChange:m=>i(m.target.value),placeholder:s("integrations.integrationNamePlaceholder"),className:"w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50"})]}),t&&r(On,{schema:t,values:l,onChange:c}),d&&r("div",{className:`rounded-lg border px-3 py-2 text-xs ${d.success?"border-success/30 bg-success/5 text-success":"border-danger/30 bg-danger/5 text-danger"}`,children:d.success?s("integrations.connectionSuccess"):`${s("integrations.errorPrefix")} ${d.error}`}),u("div",{className:"flex items-center justify-between pt-2",children:[r("button",{onClick:o,className:"rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors",children:s("integrations.back")}),u("div",{className:"flex items-center gap-2",children:[r("button",{onClick:()=>f.mutate({addonId:e,settings:l}),disabled:f.isPending,className:"rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50",children:f.isPending?s("integrations.testing"):s("integrations.testConnection")}),r("button",{onClick:()=>n({name:a,config:l}),disabled:!a.trim(),className:"rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50",children:s("integrations.forward")})]})]})]})}function hB({providerId:e,onImport:t,onSkip:n}){const{t:o}=Ht(),[s,a]=I(new Set),i=kd(),l=i.data,c=i.isPending||!i.data&&!i.isError;J(()=>{e&&(i.isPending||i.data||i.mutate({addonId:e}))},[e,i]);function d(f){a(m=>{const h=new Set(m);return h.has(f)?h.delete(f):h.add(f),h})}if(c)return u("div",{className:"flex flex-col items-center py-12",children:[r("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent"}),r("p",{className:"mt-3 text-xs text-foreground-subtle",children:o("integrations.searchingDevices")})]});const p=l??[];return u("div",{className:"space-y-4",children:[r("p",{className:"text-xs text-foreground-subtle",children:p.length>0?o("integrations.foundDevices",{count:p.length}):o("integrations.noDevicesFound")}),p.length>0&&r("div",{className:"space-y-1.5 max-h-64 overflow-y-auto",children:p.map(f=>{const m=f.stableId,h=f.suggestedName??m,g=s.has(m);return u("button",{onClick:()=>d(m),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${g?"border-primary/40 bg-primary/5":"border-border bg-surface hover:border-foreground-subtle/30"}`,children:[r("div",{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${g?"border-primary bg-primary":"border-border"}`,children:g&&r(St,{className:"h-3 w-3 text-primary-foreground"})}),r(Rr,{className:"h-3.5 w-3.5 text-foreground-subtle flex-shrink-0"}),r("span",{className:"text-xs font-medium text-foreground truncate",children:h})]},m)})}),u("div",{className:"flex items-center justify-between pt-2",children:[r("button",{onClick:n,className:"rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors",children:o("integrations.skip")}),p.length>0&&u("button",{onClick:()=>t(Array.from(s)),disabled:s.size===0,className:"rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50",children:[o("integrations.importSelected")," (",s.size,")"]})]})]})}function gB(e){const t=n=>{if(n.type==="separator"||n.type==="info"||n.type==="button")return n;if(n.type==="group")return{...n,fields:n.fields.map(i=>t(i))};const o=n,{value:s,...a}=o;return a};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(n=>({...n,fields:n.fields.map(t)}))}}function bB({open:e,onClose:t}){const{t:n}=Ht(),o=at(),s=Me(),[a,i]=I("picker"),[l,c]=I(null),[d,p]=I(null),[f,m]=I("manual"),{data:h}=xd({addonId:l??"",nodeId:"hub"},{enabled:l!=null}),g=q(()=>h?gB(h):null,[h]),x=ux({onSuccess:()=>s.invalidateQueries({queryKey:[["integrations"]]})}),b=kd(),y=b.data;J(()=>{a!=="discovery"||!d||!l||b.isPending||b.data||b.mutate({addonId:l})},[a,d,l,b]);const w=ax({onSuccess:()=>s.invalidateQueries({queryKey:[["deviceManager"]]})});async function v(O,A,P,L){if(!x.isPending){if(c(O),m(P),A==="unique"){try{const B=await x.mutateAsync({addonId:O,name:L,settings:{}});t(),D(),o(`/integrations/${B.id}`)}catch{}return}i("config")}}async function N(O){if(l)try{const A=await x.mutateAsync({addonId:l,name:O.name,settings:O.config});p(A.id),f==="auto"||f==="both"?i("discovery"):C(A.id)}catch{}}async function k(O){if(l){for(const A of O){const P=y?.find(L=>L.stableId===A);P&&await w.mutateAsync({addonId:l,candidate:P})}C()}}function C(O){const A=O??d??l;t(),D(),A&&o(`/integrations/${A}`)}function D(){i("picker"),c(null),p(null),m("manual")}function M(){t(),D()}if(!e)return null;const _={picker:n("integrations.newIntegration"),config:n("integrations.configureIntegration"),discovery:n("integrations.importDevices")},$=x.isPending,E=$?l:null,R=x.error;return u("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[r("div",{className:"absolute inset-0 bg-black/60",onClick:$?void 0:M}),u("div",{className:"relative z-10 w-full max-w-lg rounded-xl border border-border bg-background shadow-2xl",children:[u("div",{className:"flex items-center justify-between border-b border-border px-5 py-4",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:_[a]}),r("button",{onClick:M,disabled:$,className:"rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:r(Ve,{className:"h-4 w-4"})})]}),u("div",{className:"relative px-5 py-4",children:[R&&!$&&r("div",{className:"mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:R instanceof Error?R.message:String(R)}),a==="picker"&&r(uB,{onSelect:v,onClose:M,pendingAddonId:E}),a==="config"&&l&&r(mB,{addonId:l,configSchema:g??null,onSave:N,onBack:()=>i("picker")}),a==="discovery"&&d&&r(hB,{providerId:d,onImport:k,onSkip:C}),$&&u("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background/85 backdrop-blur-sm",children:[r(Ee,{className:"h-6 w-6 animate-spin text-primary"}),r("p",{className:"text-xs font-medium text-foreground",children:n("integrations.creating",{defaultValue:"Creating integration…"})}),r("p",{className:"text-[10px] text-foreground-subtle",children:n("integrations.creatingHint",{defaultValue:"Waiting for the addon to restart and register"})})]})]})]})]})}const Nf={running:{bg:"bg-success/10",text:"text-success",dot:"bg-success",label:"Running"},stopped:{bg:"bg-foreground-subtle/10",text:"text-foreground-subtle",dot:"bg-foreground-subtle",label:"Stopped"},error:{bg:"bg-danger/10",text:"text-danger",dot:"bg-danger",label:"Error"},online:{bg:"bg-success/10",text:"text-success",dot:"bg-success",label:"Online"},offline:{bg:"bg-foreground-subtle/10",text:"text-foreground-subtle",dot:"bg-foreground-subtle",label:"Offline"},idle:{bg:"bg-info/10",text:"text-info",dot:"bg-info",label:"Idle"},disabled:{bg:"bg-warning/10",text:"text-warning",dot:"bg-warning",label:"Disabled"},enabled:{bg:"bg-success/10",text:"text-success",dot:"bg-success",label:"Enabled"}};function li({status:e}){const t=Nf[e]??Nf.stopped;return u("span",{className:`inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-[10px] font-medium ${t.bg} ${t.text}`,children:[r("span",{className:`h-1.5 w-1.5 rounded-full ${t.dot}`}),t.label]})}const nl="px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle";function xB({integrations:e,expandedAddonId:t,onToggleExpand:n,onOpenSettings:o,renderExpanded:s}){const a=U(i=>n(i),[n]);return r("div",{className:"overflow-hidden rounded-lg border border-border bg-surface",children:u("table",{className:"w-full table-fixed text-xs",children:[r("thead",{className:"bg-surface-hover/40",children:u("tr",{children:[r("th",{className:Y(nl,"w-[60%]"),children:"Integration"}),r("th",{className:Y(nl,"w-[15%]"),children:"Devices"}),r("th",{className:Y(nl,"w-[25%]"),children:"Status"})]})}),r("tbody",{children:e.map(i=>{const l=t===i.addonId;return r(yB,{integration:i,isExpanded:l,onClick:a,onOpenSettings:o,renderExpanded:s},i.id)})})]})})}function yB({integration:e,isExpanded:t,onClick:n,onOpenSettings:o,renderExpanded:s}){const a=U(c=>{c.stopPropagation(),o(e.id)},[e.id,o]),i=U(()=>{n(e.addonId)},[e.addonId,n]),l=U(c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),i())},[i]);return u(me,{children:[u("tr",{role:"button",tabIndex:0,"aria-expanded":t,className:Y("cursor-pointer border-t border-border transition-colors hover:bg-surface-hover","focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/40",t&&"bg-surface-hover/60"),onClick:i,onKeyDown:l,children:[r("td",{className:"px-3 py-2.5",children:u("div",{className:"flex items-center gap-2.5",children:[t?r(en,{className:"h-3.5 w-3.5 flex-shrink-0 text-foreground-subtle"}):r(on,{className:"h-3.5 w-3.5 flex-shrink-0 text-foreground-subtle"}),r(yn,{type:e.addonId,size:"sm"}),u("div",{className:"flex min-w-0 flex-col",children:[r("span",{className:"truncate text-xs font-semibold text-foreground",children:e.name}),r("span",{className:"truncate text-[10px] text-foreground-subtle",children:e.addonId})]})]})}),u("td",{className:"px-3 py-2.5 text-[11px] text-foreground-subtle",children:[e.deviceCount," device",e.deviceCount!==1?"s":""]}),r("td",{className:"px-3 py-2.5",children:u("div",{className:"flex items-center justify-between gap-2",children:[r(li,{status:e.status}),u("button",{type:"button",onClick:a,className:"flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary",title:"Open integration settings",children:[r(tn,{className:"h-3 w-3"}),"Settings"]})]})})]}),t&&r("tr",{className:"border-t border-border bg-surface",children:r("td",{colSpan:3,className:"px-3 py-3",children:s(e.addonId)})})]})}function vB(e){if(!e.enabled)return"disabled";switch(e.processState){case"running":return"running";case"stopped":case"crashed":case"unknown":default:return"stopped"}}const $s="expand";function wB(){const{t:e}=Ht(),t=at(),n=De(),[o]=Xa(),[s,a]=I(!1),i=U(()=>a(!0),[]),l=U(()=>a(!1),[]);Zt(["integrations"],["integration.enabled","integration.disabled","integration.deleted","provider.started","provider.stopped","addon.installed","addon.uninstalled","addon.started","addon.stopped","addon.updated"]),Zt(["deviceManager"],["device.registered","device.unregistered","device.online","device.offline","device.disabled","device.enabled"]);const{data:c,isLoading:d,refetch:p}=Cd(void 0,{staleTime:3e4}),{data:f,isLoading:m,refetch:h}=kn({},{staleTime:3e4}),g=q(()=>f??[],[f]),x=q(()=>c??[],[c]),b=q(()=>{const O=new Map;for(const A of g)O.set(A.id,{id:A.id,name:A.name??A.stableId??`#${String(A.id)}`});return O},[g]),y=q(()=>{const O=new Map;for(const A of g){if(A.parentDeviceId!==null&&A.parentDeviceId!==void 0&&!!A.role)continue;const L=A.addonId??"";L&&O.set(L,(O.get(L)??0)+1)}return O},[g]),w=q(()=>x.map(O=>({id:O.id,addonId:O.addonId,name:O.name,enabled:O.enabled,status:vB(O),deviceCount:y.get(O.addonId)??0})),[x,y]),v=o.get($s),N=U(O=>{const A=new URLSearchParams(window.location.search);A.get($s)===O?A.delete($s):A.set($s,O);const L=A.toString(),B=`${window.location.pathname}${L?`?${L}`:""}${window.location.hash}`;window.history.replaceState(window.history.state,"",B),window.dispatchEvent(new PopStateEvent("popstate"))},[]),k=U(O=>t(`/integrations/${O}`),[t]),C=U(O=>b.get(O)??null,[b]),D=U(O=>r(yn,{type:O,size:"sm"}),[]),M=U(O=>t(`/devices/${String(O)}`),[t]),_=U(O=>r(Dr,{devices:g,trpc:n.trpcClient,forceAddon:O,urlScope:"nested",lsKey:`integrations:nested:${O}`,resolveIntegrationIcon:D,resolveParent:C,onNavigate:M}),[g,n.trpcClient,D,C,M]),$=U(()=>{p(),h()},[p,h]),E=d||m,R=x.length>0;return u(ot,{icon:Bo,title:e("nav.integrations","Integrations"),actions:u(me,{children:[r("button",{onClick:$,disabled:E,className:"flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50",title:"Refresh",children:r(ct,{className:Y("h-3.5 w-3.5",E&&"animate-spin")})}),u("button",{onClick:i,className:"flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm",children:[r(It,{className:"h-3.5 w-3.5"}),"New Integration"]})]}),children:[E&&r("div",{className:"space-y-2",children:[1,2,3].map(O=>r("div",{className:"h-12 rounded-lg border border-border bg-surface animate-pulse"},O))}),!E&&!R&&u("div",{className:"flex flex-col items-center py-20 text-foreground-subtle",children:[r("p",{className:"text-sm",children:"No integrations configured."}),r("p",{className:"text-xs mt-1",children:'Click "New Integration" to connect cameras and devices.'})]}),!E&&R&&r(xB,{integrations:w,expandedAddonId:v,onToggleExpand:N,onOpenSettings:k,renderExpanded:_}),r(bB,{open:s,onClose:l})]})}function Uv(e){const t=[];for(const n of e)n.type==="probe"&&t.push(n.key),n.type==="group"&&"fields"in n&&t.push(...Uv(n.fields));return t}function NB(e,t,n){const[o,s]=I("idle"),[a,i]=I({}),l=q(()=>{const f=[];for(const m of e.sections)f.push(...Uv(m.fields));return f},[e]),c=l.length>0&&n!==void 0,d=U(f=>{i(m=>{if(!m[f])return m;const h={...m};return delete h[f],h})},[]),p=U(async()=>{if(!n)return;const f=l.filter(x=>{const b=t[x];return b!=null&&String(b).trim()!==""});if(f.length===0)return;s("testing");const m={};for(const x of f)m[x]={status:"probing"};i(m);const h=await Promise.allSettled(f.map(async x=>{try{const b=await n(x,t[x]);return{key:x,result:b}}catch(b){const w={status:"error",error:b instanceof Error?b.message:String(b)};return{key:x,result:w}}})),g={};for(const x of h)if(x.status==="fulfilled"){const{key:b,result:y}=x.value;g[b]={status:y.status==="ok"?"ok":"error",result:y}}i(g),s("idle")},[n,l,t]);return{testAllStatus:o,hasProbeFields:c,probeResults:a,handleTestAll:p,clearProbeResult:d}}function qv(e){const t=[];for(const n of e)"required"in n&&n.required===!0&&"key"in n&&n.key&&t.push(n.key),n.type==="group"&&"fields"in n&&t.push(...qv(n.fields));return t}function rl(e){return e==null?!0:typeof e=="string"?e.trim()==="":!1}function lc(e,t={}){for(const n of e){if(n.type==="group"&&"fields"in n){lc(n.fields,t);continue}"key"in n&&n.key&&"default"in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function kf(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function kB({open:e,integrationId:t,addonId:n,onClose:o}){const{t:s}=Ht(),a=Me(),[i,l]=I({}),[c,d]=I(!1),[p,f]=I(null),[m,h]=I(kf),g=ix({addonId:n,type:gt.Camera},{enabled:e}),x=g.data??null;J(()=>{if(e){const A=x?lc(x.sections.flatMap(P=>P.fields)):{};l(A),h(kf()),d(!1),f(null)}},[e,t,x]);const b=q(()=>({...i,_probeRequestId:m}),[i,m]),y=lx({onSuccess:()=>{a.invalidateQueries({queryKey:[["deviceManager"]]})}}),w=Sd(),v=U(async(A,P)=>{d(!0);const L=await w.mutateAsync({addonId:n,type:gt.Camera,key:A,value:P,formValues:b});return L.status==="ok"&&L.suggestedValues&&l(B=>{let z=!1;const T={...B};for(const[F,H]of Object.entries(L.suggestedValues??{}))rl(B[F])&&!rl(H)&&(T[F]=H,z=!0);return z?T:B}),L},[w,n,b]),{testAllStatus:N,hasProbeFields:k,probeResults:C,handleTestAll:D,clearProbeResult:M}=NB(x??{sections:[]},i,v);async function _(A){f(null);try{if(await y.mutateAsync({addonId:n,type:gt.Camera,config:i}),A){const P=x?lc(x.sections.flatMap(L=>L.fields)):{};l(P)}else o()}catch(P){f(P instanceof Error?P.message:String(P))}}if(!e)return null;const E=qv((x?.sections??[]).flatMap(A=>A.fields)).filter(A=>rl(i[A])),R=E.length===0,O=!g.isLoading&&(g.isError||x===null);return u("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[r("div",{className:"absolute inset-0 bg-black/60",onClick:o}),u("div",{className:"relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl",children:[u("div",{className:"flex items-center justify-between border-b border-border px-5 py-4 shrink-0",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:s("integrations.addDevice")}),r("button",{onClick:o,className:"rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:r(Ve,{className:"h-4 w-4"})})]}),r("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3",children:g.isLoading?r("div",{className:"flex items-center justify-center py-8",children:r(Ee,{className:"h-5 w-5 animate-spin text-primary"})}):O?u("div",{className:"flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3",children:[r(pt,{className:"h-4 w-4 text-destructive mt-0.5 shrink-0"}),u("div",{className:"space-y-1",children:[r("p",{className:"text-xs font-medium text-destructive",children:"Provider unavailable"}),u("p",{className:"text-xs text-foreground-subtle",children:["The addon ",r("span",{className:"font-mono",children:n})," is not ready or does not support manual device creation. Check that the integration is online and try again."]})]})]}):r(On,{schema:x,values:i,onChange:l,onTestField:v,probeResults:C,onClearProbe:M})}),!O&&!g.isLoading&&u("div",{className:"border-t border-border bg-surface/50 shrink-0",children:[u("button",{type:"button",onClick:()=>d(A=>!A),className:"flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:[u("span",{className:"flex items-center gap-2",children:[r(At,{className:"h-3.5 w-3.5"}),"Test logs",r("span",{className:"font-mono text-[9px] opacity-60",children:m.slice(0,14)})]}),r(en,{className:`h-3.5 w-3.5 transition-transform ${c?"rotate-180":""}`})]}),c&&r("div",{className:"border-t border-border max-h-64 overflow-hidden",children:r(rn,{addonId:n,requestId:m,limit:50,maxHeight:"max-h-64",showFilters:!1,showScope:!1,className:"border-0 rounded-none"})})]}),!O&&!g.isLoading&&(p||E.length>0)&&r("div",{className:"border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0",children:u("div",{className:"flex items-start gap-2",children:[r(pt,{className:"h-3.5 w-3.5 text-destructive mt-0.5 shrink-0"}),r("p",{className:"text-[11px] text-destructive",children:p||`Required: ${E.join(", ")}`})]})}),u("div",{className:"flex items-center justify-between border-t border-border px-5 py-3 shrink-0",children:[u("div",{className:"flex items-center gap-2",children:[r("button",{onClick:o,className:"rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors",children:s("integrations.cancel")}),!O&&k&&u("button",{type:"button",onClick:D,disabled:N==="testing",className:"inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50",children:[N==="testing"?r(Ee,{className:"h-3.5 w-3.5 animate-spin"}):r(Or,{className:"h-3.5 w-3.5"}),"Test All"]})]}),u("div",{className:"flex items-center gap-2",children:[r("button",{onClick:()=>_(!0),disabled:O||!R||y.isPending,className:"rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50",children:s("integrations.saveAndNew")}),r("button",{onClick:()=>_(!1),disabled:O||!R||y.isPending,className:"rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50",children:y.isPending?s("integrations.saving"):s("integrations.save")})]})]})]})]})}function SB(){const{t:e}=Ht(),{integrationId:t}=Zd(),n=Me(),o=at(),s=De(),[a,i]=I(!1),[l,c]=I(!1),[d,p]=I(!1),[f,m]=I(!1),{data:h,isLoading:g}=cx({id:t??""},{enabled:!!t}),{data:x}=xd({addonId:h?.addonId??"",nodeId:"hub"},{enabled:!!h?.addonId}),b=x!=null&&Array.isArray(x.sections)&&x.sections.some(R=>R.fields.length>0),{data:y}=kn({},{refetchInterval:5e3}),w=[["integrations","get"],{input:{id:t??""},type:"query"}],v=px({onMutate:async R=>{await n.cancelQueries({queryKey:w});const O=n.getQueryData(w);return O!=null&&n.setQueryData(w,{...O,enabled:R.enabled}),{previous:O}},onError:(R,O,A)=>{const P=A;P?.previous!=null&&n.setQueryData(w,P.previous)},onSettled:()=>{n.invalidateQueries({queryKey:[["integrations"]]}),n.invalidateQueries({queryKey:[["deviceManager"]]})}}),N=fx({onSuccess:()=>{n.invalidateQueries({queryKey:[["integrations"]]}),n.invalidateQueries({queryKey:[["deviceManager"]]}),p(!1),o("/integrations")}}),k=Jo({onSuccess:()=>{n.invalidateQueries({queryKey:[["integrations"]]}),n.invalidateQueries({queryKey:[["deviceManager"]]})}}),C=q(()=>y??[],[y]),D=q(()=>{const R=new Map;for(const O of C)R.set(O.id,{id:O.id,name:O.name??O.stableId??`#${String(O.id)}`});return R},[C]),M=U(R=>D.get(R)??null,[D]),_=U(R=>r(yn,{type:R,size:"sm"}),[]),$=U(R=>o(`/devices/${String(R)}`),[o]),E=q(()=>{const R=h?.addonId;if(!R)return 0;let O=0;for(const A of C)A.addonId!==R||A.parentDeviceId!==null&&A.parentDeviceId!==void 0&&A.role||(O+=1);return O},[C,h?.addonId]);return g?u("div",{className:"p-4",children:[r("div",{className:"h-16 rounded-lg bg-surface animate-pulse mb-4"}),r("div",{className:"h-40 rounded-lg bg-surface animate-pulse"})]}):h?u("div",{className:"p-4 space-y-4",children:[r(Jc,{items:[{label:"Integrations",onClick:()=>o("/integrations")},{label:h.name}]}),u("div",{className:"flex items-center justify-between",children:[u("div",{className:"flex items-center gap-3",children:[r("img",{src:`/api/addon-assets/${h.addonId}/assets/icon.svg`,alt:"",className:"h-8 w-8 rounded-lg",onError:R=>{R.target.style.display="none"}}),u("div",{children:[r("h1",{className:"text-lg font-semibold text-foreground",children:h.name}),u("p",{className:"text-[11px] text-foreground-subtle mt-0.5",children:[h.addonId," · ",E," ",e("integrations.devices")]})]})]}),u("div",{className:"flex items-center gap-3",children:[u("div",{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${v.isPending?"opacity-60":""} ${h.enabled?"border-success/30 bg-success/5":"border-border bg-surface"}`,title:e("integrations.toggleHint",{defaultValue:"Click to toggle"}),children:[r(Gc,{checked:h.enabled,onCheckedChange:R=>v.mutate({id:t,enabled:R}),disabled:v.isPending,"aria-label":h.enabled?"Disable integration":"Enable integration"}),r("span",{className:`text-[11px] font-medium ${h.enabled?"text-success":"text-foreground-subtle"}`,children:h.enabled?"Enabled":"Disabled"}),v.isPending&&r(Ee,{className:"h-3 w-3 animate-spin text-foreground-subtle"})]}),b&&u("button",{onClick:()=>c(!0),className:"flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:[r(tn,{className:"h-3 w-3"}),e("integrations.config")]}),u("button",{onClick:()=>m(!0),className:"flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",title:e("integrations.logs",{defaultValue:"View logs"}),children:[r(At,{className:"h-3 w-3"}),e("integrations.logs",{defaultValue:"Logs"})]}),r(Qd,{label:"Restart",icon:ct,title:`Restart "${h.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${E} active). Streams will reconnect automatically.`,confirmLabel:"Restart",triggerVariant:"outline",confirmVariant:"danger",disabled:k.isPending,action:()=>k.mutateAsync({addonId:h.addonId})}),u("button",{onClick:()=>p(!0),className:"flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors",title:e("integrations.delete",{defaultValue:"Delete integration"}),children:[r(et,{className:"h-3 w-3"}),e("integrations.delete",{defaultValue:"Delete"})]})]})]}),r(Dr,{devices:C,trpc:s.trpcClient,defaultView:"cards",forceAddon:h.addonId,urlScope:"root",lsKey:`integration-detail:${h.addonId}`,resolveIntegrationIcon:_,resolveParent:M,onNavigate:$}),r("button",{onClick:()=>i(!0),className:"fixed bottom-6 right-6 flex h-12 w-12 items-center justify-center rounded-full bg-primary shadow-lg shadow-primary/30 hover:shadow-primary/40 transition-shadow",title:e("integrations.addDevice"),children:r(It,{className:"h-5 w-5 text-primary-foreground"})}),a&&t&&r(kB,{open:a,integrationId:t,addonId:h.addonId,onClose:()=>i(!1)}),l&&r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>c(!1),children:u("div",{className:"rounded-xl border border-border bg-surface p-6 shadow-xl w-80",onClick:R=>R.stopPropagation(),children:[r("h2",{className:"text-sm font-semibold text-foreground mb-2",children:e("integrations.providerConfig")}),r("p",{className:"text-[11px] text-foreground-subtle",children:e("integrations.configComingSoon")}),r("button",{onClick:()=>c(!1),className:"mt-4 w-full rounded-lg bg-primary px-3 py-1.5 text-[11px] text-primary-foreground hover:bg-primary/90 transition-colors",children:"Close"})]})}),f&&r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6",onClick:()=>m(!1),children:u("div",{className:"flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]",onClick:R=>R.stopPropagation(),children:[u("div",{className:"flex items-center justify-between border-b border-border px-4 py-2.5",children:[u("div",{className:"flex items-center gap-2 min-w-0",children:[r(At,{className:"h-4 w-4 text-primary shrink-0"}),r("h2",{className:"text-sm font-semibold text-foreground truncate",children:h.name}),u("span",{className:"text-[10px] text-foreground-subtle font-mono truncate",children:[h.addonId,t?` · ${t}`:""]})]}),r("button",{onClick:()=>m(!1),className:"flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors","aria-label":"Close logs",children:r(Ve,{className:"h-4 w-4"})})]}),r("div",{className:"flex-1 min-h-0 overflow-hidden",children:r(rn,{addonId:h.addonId,limit:200,maxHeight:"max-h-full",showScope:!1,className:"h-full border-0 rounded-none"})})]})}),d&&r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>!N.isPending&&p(!1),children:u("div",{className:"rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3",onClick:R=>R.stopPropagation(),children:[u("div",{className:"flex items-start gap-3",children:[r("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0",children:r(pt,{className:"h-4 w-4 text-danger"})}),u("div",{className:"min-w-0",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:e("integrations.deleteTitle",{defaultValue:"Delete integration?"})}),r("p",{className:"mt-1 text-[11px] text-foreground-subtle",children:e("integrations.deleteWarning",{defaultValue:'This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.',name:h.name,count:E})})]})]}),N.error&&r("div",{className:"rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger",children:N.error instanceof Error?N.error.message:String(N.error)}),u("div",{className:"flex items-center justify-end gap-2 pt-1",children:[r("button",{onClick:()=>p(!1),disabled:N.isPending,className:"rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:e("integrations.cancel",{defaultValue:"Cancel"})}),r("button",{onClick:()=>N.mutate({id:t}),disabled:N.isPending,className:"inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed",children:N.isPending?u(me,{children:[r(Ee,{className:"h-3 w-3 animate-spin"}),e("integrations.deleting",{defaultValue:"Deleting…"})]}):u(me,{children:[r(et,{className:"h-3 w-3"}),e("integrations.confirmDelete",{defaultValue:"Delete integration"})]})})]})]})})]}):u("div",{className:"flex flex-col items-center justify-center py-20 px-6 text-center gap-4",children:[r("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10",children:r(T8,{className:"h-6 w-6 text-foreground-subtle"})}),u("div",{className:"space-y-1 max-w-sm",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:e("integrations.integrationNotFound",{defaultValue:"Integration not found"})}),r("p",{className:"text-[11px] text-foreground-subtle",children:e("integrations.integrationNotFoundHint",{defaultValue:'The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.',id:t??""})})]}),u("button",{onClick:()=>o("/integrations"),className:"inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors",children:[r(ou,{className:"h-3 w-3"}),e("integrations.backToList",{defaultValue:"Back to integrations"})]})]})}function CB({label:e,color:t,title:n,style:o}){return u("div",{className:"absolute top-1/2 -translate-y-1/2 -translate-x-1/2 z-10 group cursor-pointer",style:o,title:n,children:[r("div",{className:"h-2.5 w-2.5 rounded-full border-2 border-background shadow-sm transition-transform group-hover:scale-150",style:{backgroundColor:t}}),n&&r("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-1.5 hidden group-hover:block z-20 pointer-events-none",children:u("div",{className:"bg-surface border border-border rounded px-2 py-1 text-[10px] text-foreground whitespace-nowrap shadow-lg",children:[r("span",{className:"inline-block h-1.5 w-1.5 rounded-full mr-1 align-middle",style:{backgroundColor:t}}),e]})})]})}const ol=36e5;function MB(e){return String(e).padStart(2,"0")}function AB(e){const t=new Date(e);return`${MB(t.getHours())}:00`}function EB({startMs:e,endMs:t,segments:n,events:o,playheadMs:s,onSeek:a}){const i=ne(null),l=t-e,c=U(h=>Math.max(0,Math.min(100,(h-e)/l*100)),[e,l]);function d(h){if(!i.current)return;const g=i.current.getBoundingClientRect(),x=Math.max(0,Math.min(1,(h.clientX-g.left)/g.width));a(Math.round(e+x*l))}const p=[],f=Math.floor(e/ol),m=Math.ceil(t/ol);for(let h=f;h<=m;h++){const g=h*ol;g<e||g>t||p.push({percent:c(g),label:AB(g)})}return u("div",{className:"select-none",children:[r("div",{className:"relative h-5 mb-1",children:p.map(({percent:h,label:g})=>r("span",{className:"absolute -translate-x-1/2 text-[10px] text-foreground-subtle",style:{left:`${h}%`},children:g},g))}),u("div",{ref:i,className:"relative h-8 rounded bg-surface-hover cursor-pointer overflow-hidden border border-border",onClick:d,onPointerMove:h=>{h.buttons===1&&d(h)},children:[n.map((h,g)=>{const x=c(h.startMs),b=c(h.endMs)-x;return r("div",{className:"absolute top-1 bottom-1 rounded-sm bg-success/60",style:{left:`${x}%`,width:`${Math.max(b,.1)}%`}},g)}),o.map(h=>r(CB,{label:h.label,color:h.color,title:`${h.label} — ${new Date(h.timestampMs).toLocaleTimeString()}`,style:{left:`${c(h.timestampMs)}%`}},h.id)),r("div",{className:"absolute top-0 bottom-0 w-0.5 bg-danger z-20 pointer-events-none",style:{left:`${c(s)}%`},children:r("div",{className:"absolute -top-0.5 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-danger rotate-45"})})]})]})}const Sf={person:"#f59e0b",vehicle:"#3b82f6",car:"#3b82f6",face:"#a855f7",plate:"#ec4899",animal:"#10b981",motion:"#ef4444",unknown:"#6b7280"};function cc(e){return Sf[e.toLowerCase()]??Sf.unknown}function IB(e){const t=new Date(e);return t.setHours(0,0,0,0),t.getTime()}function PB(e){return new Date(e).toISOString().slice(0,10)}function _B(e){return new Date(e+"T00:00:00").getTime()}function $B(e){return[{startMs:e+0*36e5,endMs:e+4*36e5},{startMs:e+6*36e5,endMs:e+10*36e5},{startMs:e+12*36e5,endMs:e+16*36e5},{startMs:e+18*36e5,endMs:e+23*36e5}]}function DB(e){const t=["person","vehicle","face","motion"];return Array.from({length:24},(n,o)=>({id:`placeholder-${o}`,timestampMs:e+Math.floor(Math.random()*24*36e5),label:t[o%t.length],color:cc(t[o%t.length])})).sort((n,o)=>n.timestampMs-o.timestampMs)}function LB(){const{t:e}=Ht(),t=IB(new Date),[n,o]=I(t),[s,a]=I(null),[i,l]=I(t+12*36e5),c=n,d=n+24*36e5,{data:p,isLoading:f}=kn({},{staleTime:3e4}),m=p??[],h=q(()=>m.filter(N=>{const k=N.type.toLowerCase();return k==="camera"||k.includes("camera")||N.features.some(C=>C.toLowerCase().includes("video")||C.toLowerCase().includes("stream"))}).map(N=>({id:N.id,name:N.name??N.stableId})),[m]),g=s??h[0]?.id??null,{data:x}=cr({queryKey:["events",g,c],queryFn:()=>Promise.resolve(null),enabled:!!g,staleTime:6e4}),b=q(()=>{const v=Array.isArray(x)?x:(()=>{const k=Fu(x)?.events;return Array.isArray(k)?k:[]})();return v.length===0?g?DB(c):[]:v.flatMap((N,k)=>{const C=Fu(N);if(!C)return[];const D=String(C.class??C.type??C.label??"unknown").toLowerCase(),M=typeof C.timestamp=="number"?C.timestamp:c;return[{id:String(C.id??k),timestampMs:M,label:D,color:cc(D)}]})},[x,g,c]),y=q(()=>g?$B(c):[],[g,c]);function w(v){o(N=>N+v*24*36e5),l(N=>N+v*24*36e5)}return u("div",{className:"flex flex-col h-full p-4 gap-4 overflow-hidden",children:[u("div",{className:"flex items-center justify-between gap-4 shrink-0",children:[r("h1",{className:"text-lg font-semibold text-foreground",children:e("nav.timeline","Timeline")}),u("div",{className:"flex items-center gap-2",children:[r("button",{onClick:()=>w(-1),className:"p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors",children:r(au,{className:"h-4 w-4"})}),u("div",{className:"relative flex items-center",children:[r(cv,{className:"absolute left-2 h-3.5 w-3.5 text-foreground-subtle pointer-events-none"}),r("input",{type:"date",value:PB(n),onChange:v=>{if(v.target.value){const N=_B(v.target.value);o(N),l(N+12*36e5)}},className:"rounded-lg border border-border bg-surface pl-7 pr-3 py-1.5 text-xs text-foreground focus:outline-none focus:border-primary/50"})]}),r("button",{onClick:()=>w(1),className:"p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors",disabled:n>=t,children:r(on,{className:"h-4 w-4"})})]})]}),u("div",{className:"flex gap-1.5 shrink-0 overflow-x-auto pb-1",children:[f&&r("div",{className:"h-8 w-48 rounded-lg bg-surface animate-pulse"}),!f&&h.length===0&&r("span",{className:"text-xs text-foreground-subtle",children:"No cameras found"}),h.map(v=>{const N=v.id===g;return r("button",{onClick:()=>a(v.id),className:`shrink-0 rounded-lg px-3 py-1.5 text-[12px] font-medium transition-all border ${N?"bg-primary/12 text-primary border-primary/30":"bg-surface text-foreground-subtle border-border hover:bg-surface-hover hover:text-foreground"}`,children:v.name},v.id)})]}),u("div",{className:"relative w-full aspect-video rounded-xl border border-border bg-black shrink-0 overflow-hidden max-h-[45vh]",children:[u("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 text-foreground-subtle",children:[r(Mo,{className:"h-12 w-12 opacity-20"}),r("p",{className:"text-sm opacity-50",children:g?`${h.find(v=>v.id===g)?.name??g} — seek to play`:"Select a camera"})]}),r("div",{className:"absolute top-3 left-3 rounded bg-black/60 px-2 py-1 text-[11px] text-white font-mono",children:new Date(i).toLocaleTimeString()})]}),u("div",{className:"rounded-xl border border-border bg-surface px-4 pt-3 pb-4 shrink-0",children:[u("div",{className:"flex flex-wrap items-center gap-4 mb-3",children:[r("span",{className:"text-[10px] font-semibold text-foreground-subtle uppercase tracking-wider",children:"Timeline"}),u("div",{className:"flex items-center gap-1.5",children:[r("span",{className:"inline-block h-2 w-4 rounded-sm bg-success/60"}),r("span",{className:"text-[10px] text-foreground-subtle",children:"Recording"})]}),Array.from(new Set(b.map(v=>v.label))).slice(0,5).map(v=>u("div",{className:"flex items-center gap-1.5",children:[r("span",{className:"inline-block h-2.5 w-2.5 rounded-full",style:{backgroundColor:cc(v)}}),r("span",{className:"text-[10px] text-foreground-subtle capitalize",children:v})]},v))]}),g?r(EB,{startMs:c,endMs:d,segments:y,events:b,playheadMs:i,onSeek:l}):r("div",{className:"h-8 rounded bg-surface-hover flex items-center justify-center text-xs text-foreground-subtle",children:"Select a camera to view timeline"})]})]})}function TB({selectedNodeId:e,onSelect:t,refreshToken:n}){const{data:o}=Hn(void 0,{staleTime:3e4}),{data:s}=qa(void 0,{staleTime:3e4}),a=new Map;for(const d of s??[])a.set(d.agentNodeId,(a.get(d.agentNodeId)??0)+1);const i=o??[],l=i.filter(d=>d.isOnline).length,c=i.filter(d=>!d.isOnline).length;return u("div",{className:"flex flex-col h-full",children:[u("button",{type:"button",onClick:()=>t(Io),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===Io?"bg-primary/10 text-primary":"text-foreground hover:bg-surface-hover"}`,children:[r(Ln,{className:"h-4 w-4 flex-shrink-0"}),u("div",{className:"min-w-0 flex-1",children:[r("div",{className:"text-xs font-semibold truncate",children:"Cluster"}),r("div",{className:"text-[10px] text-foreground-subtle",children:"Balancer + failover + assignments"})]})]}),r("div",{className:"flex-1 overflow-y-auto",children:i.map(d=>{const p=e===d.id,f=a.get(d.id)??0,m=d.isHub?Rn:jt;return u("button",{type:"button",onClick:()=>t(d.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${p?"bg-primary/10 text-primary":"text-foreground hover:bg-surface-hover"}`,children:[r(m,{className:"h-4 w-4 flex-shrink-0"}),u("div",{className:"min-w-0 flex-1",children:[u("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-xs font-semibold truncate",children:d.name}),d.isHub&&r("span",{className:"text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5",children:"hub"}),!d.isOnline&&r("span",{className:"h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0"}),d.isOnline&&r("span",{className:"h-1.5 w-1.5 rounded-full bg-success flex-shrink-0"})]}),u("div",{className:"text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5",children:[u("span",{children:[d.cpuCores," cores"]}),r("span",{children:"•"}),u("span",{children:[Math.round(d.memoryMB/1024)," GB"]}),f>0&&u(me,{children:[r("span",{children:"•"}),u("span",{className:"inline-flex items-center gap-0.5 text-foreground",children:[r(Iv,{className:"h-2.5 w-2.5"}),f]})]})]})]})]},d.id)})}),u("div",{className:"px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between",children:[u("span",{children:[l," online"]}),c>0&&u("span",{className:"text-destructive",children:[c," offline"]})]})]})}function RB({nodeId:e,refreshToken:t}){const{data:n}=Hn(void 0,{staleTime:3e4}),o=n?.find(i=>i.id===e),a=Jr("pipeline.runner-load-snapshot",i=>i.nodeId===e)?.load??null;return o?u("div",{className:"px-6 py-4 border-b border-border",children:[u("div",{className:"flex items-center gap-2 mb-1",children:[r("h2",{className:"text-base font-semibold text-foreground",children:o.name}),o.isOnline?r("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success",children:"online"}):r("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive",children:"offline"}),o.isHub&&r("span",{className:"text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5",children:"hub"})]}),u("div",{className:"text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap",children:[r("span",{children:o.cpuModel??"CPU"}),r("span",{children:"•"}),u("span",{children:[o.cpuCores," cores"]}),r("span",{children:"•"}),u("span",{children:[Math.round(o.memoryMB/1024)," GB"]}),a&&u(me,{children:[r("span",{children:"•"}),u("span",{children:[a.attachedCameras," cameras (",a.activeCameras," active)"]}),r("span",{children:"•"}),u("span",{children:[a.avgInferenceTimeMs.toFixed(0),"ms avg inference"]}),r("span",{children:"•"}),u("span",{children:["queue ",a.queueDepthTotal]}),a.hardware.hasGpu&&u(me,{children:[r("span",{children:"•"}),r("span",{className:"text-success",children:"GPU"})]})]})]})]}):r("div",{className:"px-6 py-4 border-b border-border",children:u("div",{className:"text-xs text-foreground-subtle",children:["Node not found: ",e]})})}function Qv({refreshToken:e,nodeId:t}){const[n,o]=I(new Map),{nodes:s}=eo();ft("pipeline.camera-metrics-snapshot",f=>{const m=f.data;typeof m?.deviceId=="number"&&o(h=>{const g=new Map(h);return g.set(m.deviceId,m),g})});const{data:a}=iy(void 0,{staleTime:5e3}),i=q(()=>{const f=new Map;for(const m of a??[])f.set(m.nodeId,m.deviceCount);return f},[a]),l=q(()=>{const f=new Map,m=Date.now()-3e4;for(const h of n.values()){if(h.timestamp<m)continue;const g=h.nodeId??"hub",x=f.get(g)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};x.attachedCameras++,h.metrics.phase==="active"&&x.activeCameras++,x.totalFps+=h.metrics.actualFps,x.totalInferenceWeighted+=h.metrics.avgInferenceTimeMs,x.queueDepth+=h.metrics.queueDepth,f.set(g,x)}return f},[n]),c=q(()=>{const f=new Map;for(const m of s)f.set(m.id,m.shortName);return f},[s]),d=q(()=>{let f=0,m=0,h=0,g=0,x=0;for(const y of l.values())f+=y.attachedCameras,m+=y.activeCameras,h+=y.totalFps,g+=y.totalInferenceWeighted,x+=y.queueDepth;const b=f>0?g/f:0;return{totalAgents:s.length,onlineAgents:s.filter(y=>y.isOnline).length,attachedCameras:f,activeCameras:m,avgInferenceTimeMs:b,queueDepth:x,totalFps:h}},[l,s]);if(t){const f=l.get(t);return u("div",{className:"@container/liveload",children:[r("h3",{className:"text-sm font-semibold text-foreground mb-2",children:"Live load"}),u("div",{className:"grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3",children:[r(Ut,{label:"FPS",value:f?f.totalFps.toFixed(1):"—"}),r(Ut,{label:"Cameras",value:f?`${f.activeCameras}/${f.attachedCameras}`:"—"}),r(Ut,{label:"Avg infer ms",value:f&&f.attachedCameras>0?(f.totalInferenceWeighted/f.attachedCameras).toFixed(0):"—"}),r(Ut,{label:"Queue",value:f?String(f.queueDepth):"—"}),r(Ut,{label:"Audio",value:String(i.get(t)??"—")})]})]})}const p=[...l.entries()].sort(([f],[m])=>f==="hub"?-1:m==="hub"?1:f.localeCompare(m));return u("div",{className:"@container/liveload",children:[r("h3",{className:"text-sm font-semibold text-foreground mb-2",children:"Live load"}),u("div",{className:"grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3",children:[r(Ut,{label:"Total agents",value:`${d.onlineAgents}/${d.totalAgents}`}),r(Ut,{label:"Cameras",value:`${d.activeCameras}/${d.attachedCameras}`}),r(Ut,{label:"Total FPS",value:d.totalFps.toFixed(1)}),r(Ut,{label:"Avg inference ms",value:d.avgInferenceTimeMs.toFixed(0)}),r(Ut,{label:"Queue depth",value:String(d.queueDepth)})]}),r("div",{className:"rounded-lg border border-border overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[480px]",children:[r("thead",{className:"bg-surface",children:u("tr",{className:"text-foreground-subtle text-[10px] uppercase tracking-wider",children:[r("th",{className:"text-left px-3 py-2",children:"Agent"}),r("th",{className:"text-right px-3 py-2",children:"FPS"}),r("th",{className:"text-right px-3 py-2",children:"Cameras"}),r("th",{className:"text-right px-3 py-2",children:"Inference ms"}),r("th",{className:"text-right px-3 py-2",children:"Queue"}),r("th",{className:"text-right px-3 py-2",children:"Audio"})]})}),u("tbody",{children:[p.map(([f,m])=>u("tr",{className:"border-t border-border",children:[r("td",{className:"px-3 py-2 text-foreground font-medium",children:c.get(f)??f}),r("td",{className:"px-3 py-2 text-right text-foreground",children:m.totalFps.toFixed(1)}),r("td",{className:"px-3 py-2 text-right text-foreground",children:m.attachedCameras}),r("td",{className:"px-3 py-2 text-right text-foreground",children:m.attachedCameras>0?(m.totalInferenceWeighted/m.attachedCameras).toFixed(0):"—"}),r("td",{className:"px-3 py-2 text-right text-foreground",children:m.queueDepth}),r("td",{className:"px-3 py-2 text-right text-foreground",children:i.get(f)??"—"})]},f)),p.length===0&&r("tr",{children:r("td",{colSpan:6,className:"px-3 py-4 text-center text-foreground-subtle text-[11px]",children:"No camera metrics received yet"})})]})]})})]})}function Ut({label:e,value:t}){return u("div",{className:"rounded-lg border border-border bg-surface/60 p-3",children:[r("div",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle mb-1",children:e}),r("div",{className:"text-lg font-semibold text-foreground",children:t})]})}function Gv(e){return kn({addonId:e})}const OB=3e4,BB=2e3;function Wv(e){const t=ne(0);return t.current===0&&(t.current=Date.now()),Xb({parentDeviceId:e},{enabled:Number.isFinite(e),staleTime:0,refetchOnMount:"always",refetchInterval:n=>{const o=n.state.data;return o&&o.length>0||Date.now()-t.current>=OB?!1:BB}})}const sl={active:!1,pinned:!1,nodeId:null,reason:""},al=["pipeline.camera-assigned","pipeline.camera-unassigned","pipeline.camera-updated","agent.online","agent.offline"],zB={pipeline:jt,decoder:Mo,audio:rc},Cf={pipeline:"Pipeline",decoder:"Decoder",audio:"Audio"};function Kv({mode:e,nodeId:t,compact:n=!1}){if(e==="agent"&&!t)throw new Error('CameraAssignmentsTable: nodeId is required when mode === "agent"');const o=Me(),[s,a]=I(null),[i,l]=I(null),[c,d]=I(new Map);Zt(["pipelineOrchestrator","getPipelineAssignments"],al),Zt(["pipelineOrchestrator","getDecoderAssignments"],al),Zt(["pipelineOrchestrator","getAudioAssignments"],al);const{data:p}=qa(void 0,{staleTime:3e4}),{data:f}=oy(void 0,{staleTime:3e4}),{data:m}=ly(void 0,{staleTime:3e4}),{nodes:h}=eo(),{data:g}=Gv();ft("pipeline.camera-metrics-snapshot",E=>{const R=E.data;typeof R.deviceId=="number"&&d(O=>{const A=new Map(O);return A.set(R.deviceId,R),A})}),J(()=>{if(c.size===0)return;const E=setInterval(()=>{d(R=>{const O=Date.now()-1e4;let A=!1;const P=new Map(R);for(const[L,B]of R)B.timestamp<O&&(P.delete(L),A=!0);return A?P:R})},5e3);return()=>clearInterval(E)},[c.size]);const x=q(()=>{const E=new Map;for(const R of g??[])E.set(R.id,R.name);return E},[g]),b=q(()=>{const E=new Map,R=A=>{const P=E.get(A);if(P)return P;const L={deviceId:A,deviceName:x.get(A)??`Device ${A}`,pipeline:sl,decoder:sl,audio:sl};return E.set(A,L),L};for(const A of p??[]){const P=R(A.deviceId);E.set(A.deviceId,{...P,pipeline:{active:e==="cluster"?!0:A.agentNodeId===t,pinned:A.pinned,nodeId:A.agentNodeId,reason:A.reason??""}})}for(const A of f??[]){const P=R(A.deviceId);E.set(A.deviceId,{...P,decoder:{active:e==="cluster"?!0:A.decoderNodeId===t,pinned:A.pinned,nodeId:A.decoderNodeId,reason:A.reason??""}})}for(const A of m??[]){const P=R(A.deviceId);E.set(A.deviceId,{...P,audio:{active:e==="cluster"?!0:A.nodeId===t,pinned:A.pinned,nodeId:A.nodeId,reason:"capacity"}})}let O=[...E.values()];return e==="agent"&&(O=O.filter(A=>A.pipeline.active||A.decoder.active||A.audio.active)),O.sort((A,P)=>A.deviceId-P.deviceId),O},[p,f,m,x,e,t]),y=q(()=>(h??[]).filter(E=>E.isOnline).map(E=>({id:E.id,name:E.name})),[h]),w=()=>{o.invalidateQueries({queryKey:[["pipelineOrchestrator","getPipelineAssignments"]]}),o.invalidateQueries({queryKey:[["pipelineOrchestrator","getDecoderAssignments"]]}),o.invalidateQueries({queryKey:[["pipelineOrchestrator","getAudioAssignments"]]})},v=Yx({onSuccess:w}),N=Zx({onSuccess:w}),k=ny({onSuccess:w}),C=ry({onSuccess:w}),D=sy({onSuccess:w}),M=ay({onSuccess:w}),_=(E,R,O)=>{R==="pipeline"?v.mutate({deviceId:E,agentNodeId:O}):R==="decoder"?k.mutate({deviceId:E,nodeId:O}):D.mutate({deviceId:E,nodeId:O}),a(null)},$=(E,R)=>{R==="pipeline"?N.mutate({deviceId:E}):R==="decoder"?C.mutate({deviceId:E}):M.mutate({deviceId:E}),a(null)};return r("div",{className:"rounded-lg border border-border overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[640px]",children:[r("thead",{className:"bg-surface",children:u("tr",{className:"text-foreground-subtle text-[10px] uppercase tracking-wider",children:[!n&&r("th",{className:"w-6"}),r("th",{className:"text-left px-3 py-2 align-middle",children:"Camera"}),r("th",{className:"text-left px-3 py-2 align-middle",children:"Pipeline"}),r("th",{className:"text-left px-3 py-2 align-middle",children:"Decoder"}),r("th",{className:"text-left px-3 py-2 align-middle",children:"Audio"}),r("th",{className:"text-left px-3 py-2 align-middle",children:"Status"})]})}),u("tbody",{children:[b.map(E=>{const R=c.get(E.deviceId),O=i===E.deviceId;return u(Ze.Fragment,{children:[u("tr",{className:"border-t border-border align-middle relative",children:[!n&&r("td",{className:"px-2 py-2 align-middle",children:r("button",{type:"button",onClick:()=>l(O?null:E.deviceId),className:"p-1 rounded hover:bg-surface-hover text-foreground-subtle","aria-label":O?"Collapse broker details":"Expand broker details",children:O?r(en,{className:"h-3.5 w-3.5"}):r(on,{className:"h-3.5 w-3.5"})})}),u("td",{className:"px-3 py-2 align-middle",children:[r("div",{className:"text-foreground font-medium leading-tight",children:E.deviceName}),u("div",{className:"text-[10px] text-foreground-subtle leading-tight",children:["#",E.deviceId]})]}),r(il,{role:"pipeline",state:E.pipeline,mode:e,deviceId:E.deviceId,onlineNodes:y,isMenuOpen:s?.deviceId===E.deviceId&&s.role==="pipeline",onToggleMenu:()=>a(s?.deviceId===E.deviceId&&s.role==="pipeline"?null:{deviceId:E.deviceId,role:"pipeline"}),onCloseMenu:()=>a(null),onMove:A=>_(E.deviceId,"pipeline",A),onUnpin:()=>$(E.deviceId,"pipeline")}),r(il,{role:"decoder",state:E.decoder,mode:e,deviceId:E.deviceId,onlineNodes:y,isMenuOpen:s?.deviceId===E.deviceId&&s.role==="decoder",onToggleMenu:()=>a(s?.deviceId===E.deviceId&&s.role==="decoder"?null:{deviceId:E.deviceId,role:"decoder"}),onCloseMenu:()=>a(null),onMove:A=>_(E.deviceId,"decoder",A),onUnpin:()=>$(E.deviceId,"decoder")}),r(il,{role:"audio",state:E.audio,mode:e,deviceId:E.deviceId,onlineNodes:y,isMenuOpen:s?.deviceId===E.deviceId&&s.role==="audio",onToggleMenu:()=>a(s?.deviceId===E.deviceId&&s.role==="audio"?null:{deviceId:E.deviceId,role:"audio"}),onCloseMenu:()=>a(null),onMove:A=>_(E.deviceId,"audio",A),onUnpin:()=>$(E.deviceId,"audio")}),r("td",{className:"px-3 py-2 align-middle",children:r(HB,{snap:R})})]}),O&&!n&&u("tr",{className:"bg-surface/50",children:[r("td",{}),r("td",{colSpan:5,className:"px-3 py-2",children:r(Tr,{widgetId:"stream-broker/stream-broker-panel",host:"device-tab",deviceId:E.deviceId,instanceId:`pipeline-row/${E.deviceId}`,config:{variant:"compact",title:"Stream brokers & clients"}})})]})]},E.deviceId)}),b.length===0&&r("tr",{children:r("td",{colSpan:n?5:6,className:"px-3 py-4 text-center text-foreground-subtle text-[11px]",children:e==="agent"?"No cameras assigned to this node":"No cameras currently assigned"})})]})]})})}function il({role:e,state:t,mode:n,onlineNodes:o,isMenuOpen:s,onToggleMenu:a,onCloseMenu:i,onMove:l,onUnpin:c}){const d=zB[e],p=o.filter(h=>h.id!==(t.nodeId??"")),m=(t.active||n==="cluster")&&(p.length>0||t.pinned);return u("td",{className:"px-3 py-2 align-middle relative",children:[u("div",{className:"flex items-center gap-2",children:[n==="agent"?r(FB,{state:t,Icon:d}):r(jB,{state:t,Icon:d}),r("div",{className:"ml-auto",children:m&&r("button",{type:"button",onClick:a,className:"p-1 rounded hover:bg-surface-hover","aria-label":`${Cf[e]} actions`,children:r(kO,{className:"h-3 w-3 text-foreground-subtle"})})})]}),s&&m&&r(VB,{title:Cf[e],targets:p,pinned:t.pinned,onMove:l,onUnpin:c,onClose:i})]})}function FB({state:e,Icon:t}){const n=e.active?Av:os;return u("div",{className:"flex items-center gap-1.5",children:[r(n,{className:`h-3.5 w-3.5 ${e.active?"text-success":"text-foreground-subtle/50"}`}),r(t,{className:`h-3 w-3 ${e.active?"text-foreground-subtle":"text-foreground-subtle/40"}`}),e.pinned&&r(Nv,{className:"h-2.5 w-2.5 text-amber-400"})]})}function jB({state:e,Icon:t}){return!e.active||!e.nodeId?u("div",{className:"flex items-center gap-1.5 text-foreground-subtle/60",children:[r(t,{className:"h-3 w-3"}),r("span",{className:"text-[10px] italic",children:"—"})]}):u("div",{className:"flex items-center gap-1.5 min-w-0",children:[r(t,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),u("div",{className:"flex flex-col leading-tight min-w-0",children:[r("span",{className:"font-mono text-[11px] text-foreground truncate",children:e.nodeId}),r("span",{className:"flex items-center gap-1 text-[10px]",children:e.pinned?u("span",{className:"inline-flex items-center gap-0.5 text-amber-400",children:[r(Nv,{className:"h-2.5 w-2.5"})," manual"]}):u("span",{className:"text-foreground-subtle truncate",children:["auto · ",e.reason||"capacity"]})})]})]})}function HB({snap:e}){if(!e)return r("span",{className:"text-[10px] text-foreground-subtle italic",children:"—"});const{phase:t,actualFps:n,avgInferenceTimeMs:o,queueDepth:s,configuredFps:a}=e.metrics,i=Gr(t);return u("div",{className:"flex flex-col gap-0.5 font-mono text-[10px] tabular-nums leading-tight",children:[u("span",{className:`inline-flex items-center gap-1 ${i.textColor}`,children:[r(Ud,{phase:t,className:"h-2.5 w-2.5"}),r("span",{className:"font-semibold uppercase tracking-wider",children:i.label})]}),u("span",{className:"text-foreground-subtle",children:[r("span",{className:"text-foreground",children:n.toFixed(1)}),u("span",{children:["/",a.toFixed(0)," fps"]})]}),u("span",{className:"text-foreground-subtle",children:[r("span",{className:"text-foreground",children:o.toFixed(0)}),r("span",{children:" ms"}),s>0&&u("span",{className:"text-warning ml-1",children:["q",s]})]})]})}function VB({title:e,targets:t,pinned:n,onMove:o,onUnpin:s,onClose:a}){const i=ne(null);return J(()=>{const l=c=>{i.current?.contains(c.target)||a()};return window.addEventListener("mousedown",l),()=>window.removeEventListener("mousedown",l)},[a]),u("div",{ref:i,className:"absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left",children:[r("div",{className:"px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border",children:e}),t.length>0&&r("div",{className:"py-1",children:t.map(l=>u("button",{type:"button",onClick:()=>o(l.id),className:"block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover",children:["Move to ",l.name]},l.id))}),n&&u("button",{type:"button",onClick:s,className:"block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border",children:["Unpin ",e.toLowerCase()]}),t.length===0&&!n&&r("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle italic",children:"Already auto · no other nodes online"})]})}function UB({nodeId:e,refreshToken:t}){return u("div",{className:"space-y-6",children:[r(Qv,{refreshToken:t,nodeId:e}),u("div",{children:[r("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Cameras on this node"}),u("p",{className:"text-[11px] text-foreground-subtle",children:["Checkboxes mark the roles currently running on ",e,". Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream."]})]}),r(Kv,{mode:"agent",nodeId:e,compact:!0})]})}function qB(e,t){const n=Math.max(0,t-e),o=Math.floor(e/1e3),s=Math.floor(n/1e3);return`${o}s idle · ${s}s left`}function QB({nodeId:e,refreshToken:t}){const n=Me(),o=Kx({onSettled:()=>{n.invalidateQueries({queryKey:["pipelineExecutor","listLoadedEngines"]})}}),{data:s}=Wx({nodeId:e},{staleTime:5e3}),i=Jr("pipeline.engine-metrics-snapshot",m=>m.nodeId===e)?.engines??s??null,l=i===null;Zt(["pipelineRunner","getLocalCameras"],["pipeline.camera-assigned","pipeline.camera-unassigned"]);const{data:c}=xy({nodeId:e},{staleTime:3e4}),{values:d}=od("pipeline.camera-metrics-snapshot",m=>m.deviceId,m=>m.nodeId===e),p=q(()=>d.filter(m=>m.metrics.phase==="active").length,[d]),f=m=>{const h=c??[];h.length>0&&!window.confirm(`${h.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||o.mutate({nodeId:e,engine:m,force:h.length>0})};return u("div",{className:"space-y-6",children:[u("div",{children:[r("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Inference engines on this node"}),u("p",{className:"text-[11px] text-foreground-subtle",children:[(i??[]).length," engine(s) resident in RAM. ",(c??[]).length," camera(s) attached, ",p," actively dispatching frames. Refreshes every 5s."]})]}),r("div",{className:"rounded-lg border border-border overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[640px]",children:[r("thead",{className:"bg-surface",children:u("tr",{className:"text-foreground-subtle text-[10px] uppercase tracking-wider",children:[r("th",{className:"text-left px-3 py-2 whitespace-nowrap",children:"Kind"}),r("th",{className:"text-left px-3 py-2 whitespace-nowrap",children:"Runtime / Backend / Device"}),r("th",{className:"text-left px-3 py-2",children:"Models"}),r("th",{className:"text-right px-3 py-2 whitespace-nowrap",children:"Pool PID"}),r("th",{className:"text-right px-3 py-2 whitespace-nowrap",children:"Auto-kill"}),r("th",{className:"text-right px-3 py-2 whitespace-nowrap",children:"In use"}),r("th",{className:"w-20"})]})}),u("tbody",{children:[l&&r("tr",{children:r("td",{colSpan:7,className:"px-3 py-4 text-center text-foreground-subtle text-[11px]",children:"Loading…"})}),!l&&(i??[]).map(m=>{const h=m.kind==="warm-override";return u("tr",{className:`border-t border-border ${h?"bg-amber-500/5":""}`,children:[r("td",{className:"px-3 py-2",children:u("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${h?"bg-amber-500/15 text-amber-400":"bg-success/15 text-success"}`,children:[h?r(IO,{className:"h-3 w-3"}):r(jt,{className:"h-3 w-3"}),h?"warm":"runtime"]})}),r("td",{className:"px-3 py-2",children:u("span",{className:"inline-flex items-center gap-1 text-[11px] text-sky-400",children:[r(cu,{className:"h-3 w-3"}),m.engine.runtime,"/",m.engine.backend,m.engine.device?`/${m.engine.device}`:"",m.engine.format?` · ${m.engine.format}`:""]})}),r("td",{className:"px-3 py-2",children:m.modelsLoaded.length===0?r("span",{className:"text-foreground-subtle text-[11px]",children:"—"}):r("div",{className:"flex flex-wrap gap-1",children:m.modelsLoaded.map(g=>r("span",{className:"inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle",children:g},g))})}),r("td",{className:"px-3 py-2 text-right font-mono text-foreground",children:m.poolPid??"—"}),r("td",{className:"px-3 py-2 text-right text-[11px]",children:m.idleMs!==null&&m.idleTtlMs!==null?r("span",{className:"text-foreground-subtle",children:qB(m.idleMs,m.idleTtlMs)}):r("span",{className:"text-foreground-subtle/50",children:"never"})}),r("td",{className:"px-3 py-2 text-right text-foreground",children:h?"—":(c??[]).length}),r("td",{className:"px-3 py-2 text-right",children:u("button",{type:"button",disabled:o.isPending,onClick:()=>f(m.engine),className:"inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50",children:[r(et,{className:"h-3 w-3"}),"Kill"]})})]},m.engineKey)}),!l&&(i??[]).length===0&&r("tr",{children:r("td",{colSpan:7,className:"px-3 py-4 text-center text-foreground-subtle text-[11px]",children:"No engines resident — the factory spins up on the first pipeline run."})})]})]})}),u("div",{className:"text-[10px] text-foreground-subtle leading-relaxed",children:[r("strong",{className:"text-foreground",children:"runtime"}),": main camera-serving engine; never auto-killed while cameras attached. ",r("strong",{className:"text-foreground",children:"warm"}),": benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL."]}),o.isError&&u("div",{className:"rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive",children:["Kill failed: ",o.error instanceof Error?o.error.message:"unknown"]})]})}function Pt(e){if(!Number.isFinite(e)||e<0)return"—";if(e<1024)return`${Math.round(e)} B`;const t=["KB","MB","GB","TB","PB"];let n=e/1024,o="KB";for(const a of t){if(o=a,n<1024)break;n/=1024}return`${n>=100?Math.round(n).toString():n.toFixed(1)} ${o}`}function Yv(e){return Pt(e*1024*1024)}const GB=new Set(p2);function Mf(e){return GB.has(e)}function ll(e,t,n){return`${e}/${t}/${n}`}function dc(e){return{coreml:"CoreML",openvino:"OpenVINO",onnx:"ONNX"}[e.format]??e.format.toUpperCase()}function Af(e){return{coreml:"Apple Neural Engine / GPU — .mlpackage",openvino:"Intel CPU / GPU / NPU — .xml",onnx:"CPU, CUDA, Node.js — .onnx"}[e.format]??`.${e.format}`}function qn(e){return e.format}function WB(e,t){let n=0,o=0,s=0;for(const a of e)for(const i of a.addons)for(const l of i.models){const c=l.formats[t];c&&(n++,c.downloaded&&(o++,s+=c.sizeMB))}return{total:n,downloaded:o,downloadedSizeMB:s}}function KB({addonId:e,model:t,format:n,isActive:o,progress:s,errorMsg:a,onDownload:i,onDelete:l}){const c=t.formats[n];return c?u("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors",children:[r("div",{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?"bg-success":"bg-foreground-subtle/30"}`}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-sm font-medium text-foreground",children:t.name}),u("span",{className:"text-[10px] text-foreground-subtle font-mono",children:["(",t.id,")"]})]}),s&&s.progress>=0&&s.progress<100&&u("div",{className:"mt-1.5 flex items-center gap-2 max-w-xs",children:[r("div",{className:"flex-1 h-1 bg-surface-hover rounded-full overflow-hidden",children:r("div",{className:"bg-primary h-full rounded-full transition-all duration-300",style:{width:`${s.progress}%`}})}),u("span",{className:"text-[9px] text-primary font-mono tabular-nums shrink-0",children:[Math.round(s.progress),"%"]})]})]}),r("span",{className:"text-xs text-foreground-subtle tabular-nums shrink-0",children:Yv(c.sizeMB)}),a&&u("span",{className:"flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0",title:a,children:[r(nr,{className:"h-3 w-3 shrink-0"}),a]}),c.downloaded?u("button",{onClick:l,disabled:o,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0",children:[o?r(Ee,{className:"h-3 w-3 animate-spin"}):r(et,{className:"h-3 w-3"}),o?"Deleting...":"Delete"]}):u("button",{onClick:i,disabled:o,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0",children:[o?r(Ee,{className:"h-3 w-3 animate-spin"}):r(bn,{className:"h-3 w-3"}),o?"Downloading...":"Download"]})]}):null}function YB({engines:e,activeEngine:t,viewEngine:n,onSelect:o}){const[s,a]=I(!1);return u("div",{className:"relative",children:[u("button",{type:"button",onClick:()=>a(!s),className:"flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors",children:[r(jt,{className:"h-4 w-4 text-primary shrink-0"}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-sm font-medium text-foreground",children:dc(n)}),qn(n)===qn(t)&&r("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium",children:"Active"})]}),r("div",{className:"text-[10px] text-foreground-subtle",children:Af(n)})]}),r(en,{className:`h-4 w-4 text-foreground-subtle transition-transform ${s?"rotate-180":""}`})]}),s&&r("div",{className:"absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden",children:e.map(i=>{const l=qn(i)===qn(n),c=qn(i)===qn(t);return u("button",{type:"button",onClick:()=>{o(i),a(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${l?"bg-primary/5":"hover:bg-surface-hover"}`,children:[r(jt,{className:`h-4 w-4 shrink-0 ${l?"text-primary":"text-foreground-subtle"}`}),u("div",{className:"flex-1",children:[u("div",{className:"flex items-center gap-2",children:[r("span",{className:`text-sm font-medium ${l?"text-primary":"text-foreground"}`,children:dc(i)}),c&&r("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium",children:"Active"})]}),r("div",{className:"text-[10px] text-foreground-subtle",children:Af(i)})]}),l&&r(ti,{className:"h-4 w-4 text-primary shrink-0"})]},qn(i))})})]})}function ZB({embedded:e=!1,nodeId:t}={}){const n=Me(),o=t??"hub",[s,a]=I(null),[i,l]=I(new Set),[c,d]=I(new Map),[p,f]=I(new Map),[m,h]=I(""),{data:g=[]}=Vx({nodeId:o},{staleTime:6e4}),b=g.filter((z,T,F)=>F.findIndex(H=>H.format===z.format)===T),{data:y}=Ux({nodeId:o},{staleTime:3e4}),w=y,{data:v,isLoading:N}=es({nodeId:o},{staleTime:1e4}),k=Qx(),C=Gx();ft("model.download.progress",z=>{const T=z.data,F=typeof T.modelId=="string"?T.modelId:void 0,H=typeof T.progress=="number"?T.progress:void 0,j=typeof T.totalMB=="number"?T.totalMB:0;F===void 0||H===void 0||(d(Q=>{const G=new Map(Q);return H===100||H===-1?G.delete(F):G.set(F,{modelId:F,progress:H,totalMB:j}),G}),H===100&&n.invalidateQueries({queryKey:[["pipelineExecutor","getSchema"]]}))});const D=w??{runtime:"node",backend:"cpu",format:"onnx"},M=b.find(z=>z.format===s)??D,_=M.format,$=v?.slots??[],E=$.map(z=>({...z,addons:z.addons.map(T=>({...T,models:T.models.filter(F=>F.formats[_]!==void 0)})).filter(T=>T.models.length>0)})).filter(z=>z.addons.length>0),R=WB(E,_),O=U(async(z,T,F)=>{if(!Mf(F))return;const H=ll(z,T,F);l(j=>new Set([...j,H])),f(j=>{const Q=new Map(j);return Q.delete(H),Q});try{await k.mutateAsync({addonId:z,modelId:T,format:F,nodeId:o}),n.invalidateQueries({queryKey:[["pipelineExecutor","getSchema"]]})}catch(j){f(Q=>new Map([...Q,[H,j instanceof Error?j.message:"Download failed"]]))}finally{l(j=>{const Q=new Set(j);return Q.delete(H),Q})}},[k,n,o]),A=U(async(z,T,F)=>{if(!Mf(F))return;const H=ll(z,T,F);l(j=>new Set([...j,H])),f(j=>{const Q=new Map(j);return Q.delete(H),Q});try{await C.mutateAsync({addonId:z,modelId:T,format:F,nodeId:o}),n.invalidateQueries({queryKey:[["pipelineExecutor","getSchema"]]})}catch(j){f(Q=>new Map([...Q,[H,j instanceof Error?j.message:"Delete failed"]]))}finally{l(j=>{const Q=new Set(j);return Q.delete(H),Q})}},[C,n,o]),P=U(z=>{a(z.format)},[]),L=m.trim()?E.map(z=>({...z,addons:z.addons.map(T=>({...T,models:T.models.filter(F=>F.name.toLowerCase().includes(m.toLowerCase())||F.id.toLowerCase().includes(m.toLowerCase())||T.name.toLowerCase().includes(m.toLowerCase()))})).filter(T=>T.models.length>0)})).filter(z=>z.addons.length>0):E,B=u(me,{children:[N&&r("div",{className:"flex items-center justify-center py-16",children:r(Ee,{className:"h-5 w-5 animate-spin text-foreground-subtle"})}),!N&&$.length===0&&u("div",{className:"flex flex-col items-center justify-center py-16 text-foreground-subtle",children:[r(ga,{className:"h-8 w-8 mb-3 opacity-30"}),r("span",{className:"text-sm",children:"No pipeline steps available"}),r("span",{className:"text-xs mt-1",children:"Configure the detection pipeline to see available models."})]}),!N&&$.length>0&&u(me,{children:[r(YB,{engines:b,activeEngine:D,viewEngine:M,onSelect:P}),u("div",{className:"flex items-center gap-4 text-xs text-foreground-subtle",children:[u("span",{children:[r("span",{className:"font-semibold text-foreground tabular-nums",children:R.total}),r("span",{className:"ml-1",children:"compatible models"})]}),r("span",{className:"text-border",children:"|"}),u("span",{children:[r("span",{className:"font-semibold text-success tabular-nums",children:R.downloaded}),r("span",{className:"ml-1",children:"downloaded"})]}),r("span",{className:"text-border",children:"|"}),u("span",{className:"tabular-nums",children:[Yv(R.downloadedSizeMB),r("span",{className:"ml-1",children:"on disk"})]})]}),R.total>5&&u("div",{className:"relative",children:[r(Cv,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle"}),r("input",{type:"text",value:m,onChange:z=>h(z.target.value),placeholder:"Search models...",className:"w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary"})]}),L.map(z=>{const T=z.addons.reduce((H,j)=>H+j.models.length,0),F=z.addons.reduce((H,j)=>H+j.models.filter(Q=>Q.formats[_]?.downloaded).length,0);return u("div",{children:[u("div",{className:"flex items-center gap-2 mb-2",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:z.label}),r("div",{className:"flex-1 h-px bg-border"}),u("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:[F,"/",T]})]}),r("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:z.addons.map(H=>H.models.map(j=>{const Q=ll(H.id,j.id,_);return r(KB,{addonId:H.id,model:j,format:_,isActive:i.has(Q),progress:c.get(j.id),errorMsg:p.get(Q),onDownload:()=>O(H.id,j.id,_),onDelete:()=>A(H.id,j.id,_)},`${H.id}/${j.id}`)}))})]},z.id)}),L.length===0&&r("div",{className:"text-center py-8 text-sm text-foreground-subtle",children:m.trim()?u(me,{children:["No models matching “",m,"”"]}):u(me,{children:["No models available for ",dc(M)," format"]})})]})]});return e?r("div",{className:"space-y-4",children:B}):r(ot,{children:B})}function XB({nodeId:e,refreshToken:t}){return r(ZB,{embedded:!0,nodeId:e})}function Zv({nodeId:e,title:t}){const{data:n}=Gv(),{data:o}=qa(void 0,{staleTime:3e4}),s=q(()=>{const d=new Map;for(const p of n??[])d.set(p.id,p.name);return d},[n]),a=q(()=>{if(!e)return null;const d=new Set;for(const p of o??[])p.agentNodeId===e&&d.add(p.deviceId);return d},[e,o]),[i,l]=I(new Map);ft("pipeline.camera-metrics-snapshot",d=>{const p=d.data;typeof p.deviceId=="number"&&(e&&p.nodeId!==e||l(f=>{const m=new Map(f);return m.set(p.deviceId,p),m}))}),J(()=>{if(i.size===0)return;const d=setInterval(()=>{l(p=>{const f=Date.now()-1e4;let m=!1;const h=new Map(p);for(const[g,x]of p)x.timestamp<f&&(h.delete(g),m=!0);return m?h:p})},5e3);return()=>clearInterval(d)},[i.size]);const c=q(()=>{const d=[];for(const p of i.values())a&&!a.has(p.deviceId)||d.push(p);return d.sort((p,f)=>p.deviceId-f.deviceId),d},[i,a]);return c.length===0?u("div",{className:"rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic",children:[t??"Cameras",": no live snapshots yet"]}):u("div",{className:"rounded-md border border-border bg-surface px-3 py-2",children:[u("div",{className:"flex items-center gap-2 mb-1.5",children:[r("span",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:t??"Cameras"}),r("span",{className:"text-[10px] text-foreground-subtle",children:c.length})]}),r("div",{className:"flex flex-wrap gap-1.5",children:c.map(d=>{const p=s.get(d.deviceId)??`#${d.deviceId}`,f=Gr(d.metrics.phase);return u("div",{title:`${p} · ${f.label} · ${d.metrics.actualFps.toFixed(1)} fps · ${d.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${d.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${f.badgeClass}`,children:[r(Ud,{phase:d.metrics.phase,className:"h-2.5 w-2.5"}),r("span",{className:"font-medium text-foreground/90 max-w-[120px] truncate",children:p}),r("span",{className:"font-mono tabular-nums",children:d.metrics.actualFps.toFixed(1)}),r("span",{className:"opacity-60",children:"fps"})]},d.deviceId)})})]})}function cl(e,t){if(!e)return null;for(const n of e.slots)for(const o of n.addons)if(o.id===t)return o;return null}function JB({nodeId:e,refreshToken:t}){const n=Me(),[o,s]=I(null),[a,i]=I(null),l=es({nodeId:e},{refetchOnMount:"always"}),c=Ad({agentNodeId:e},{refetchOnMount:"always"}),d=Ed({onSuccess:()=>{n.invalidateQueries({queryKey:[["addonSettings"]]}),n.invalidateQueries({queryKey:[["pipelineOrchestrator"]]}),n.invalidateQueries({queryKey:[["pipelineExecutor"]]})}}),p=l.data??null,f=c.data,m=p?.selectedEngine.format??"coreml",h=q(()=>p?ja(p):[],[p]),g=q(()=>[{agentNodeId:e,engineLabel:m}],[e,m]),x=(C,D)=>{const M=f?.addonDefaults[C];return cl(p,C)?.models.some(E=>!!E.formats[m])?M?M.enabled?{kind:"enabled",modelId:M.modelId}:{kind:"disabled"}:{kind:"na"}:{kind:"na"}},b=o&&p?cl(p,o.addonId):null,y=C=>{const D=f?.addonDefaults[C]??null;s({addonId:C,agentNodeId:e}),i(D)},w=(C,D)=>{if(!f)return;const M=f.addonDefaults[C],_=cl(p,C);if(!M&&!_)return;const $={enabled:D,modelId:M?.modelId??_?.defaultModelId??"",settings:M?.settings??{}};d.mutate({agentNodeId:e,defaults:{...f.addonDefaults,[C]:$}})},v=()=>{s(null),i(null)},N=()=>{!a||!o||!f||d.mutate({agentNodeId:e,defaults:{...f.addonDefaults,[o.addonId]:a}},{onSuccess:v})};if(l.isLoading||c.isLoading)return r("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading pipeline…"});if(l.error)return u("div",{className:"text-xs text-red-400",children:["Failed to load catalog: ",String(l.error)]});if(!p)return r("div",{className:"text-xs text-foreground-subtle",children:"Catalog unavailable for this node (runner offline?)."});const k=o!==null&&b!==null&&a!==null;return u("div",{className:"relative h-full w-full space-y-3",children:[r(Zv,{nodeId:e}),r("div",{className:k?"pr-[360px]":"",children:h.length>0?r(td,{tree:h,agents:g,getCellState:x,onCellClick:y,selectedCell:o,onToggleEnabled:w}):r("div",{className:"text-xs text-foreground-subtle",children:"Catalog empty."})}),r(ed,{open:k,onClose:v,title:b?.name??"",subtitle:o?`${o.agentNodeId} · ${m}`:"",footer:u(me,{children:[r("button",{type:"button",className:"px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted",onClick:v,children:"Cancel"}),r("button",{type:"button",disabled:!a||!o||d.isPending,className:"px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50",onClick:N,children:d.isPending?"Saving…":"Save"})]}),children:b&&a&&o&&r(Va,{mode:"agent",addon:b,agentDefault:a,agentNodeId:o.agentNodeId,engineFormat:m,onChangeAgentConfig:C=>i(C)})})]})}function Xv({pendingCount:e,onSave:t,onDiscard:n,saving:o=!1,saveLabel:s="Save",discardLabel:a="Discard"}){return e<=0?null:u("div",{className:"sticky bottom-0 -mb-3 flex items-center justify-between gap-3 rounded-lg border border-primary/40 bg-primary/5 px-3 py-2 shadow-sm z-10",children:[u("span",{className:"text-xs text-foreground",children:[e," unsaved change",e===1?"":"s"]}),u("div",{className:"flex items-center gap-2",children:[r("button",{type:"button",onClick:n,disabled:o,className:"inline-flex items-center rounded-md border border-border px-2.5 py-1 text-xs text-foreground-subtle hover:bg-surface-hover disabled:opacity-50",children:a}),r("button",{type:"button",onClick:t,disabled:o,className:"inline-flex items-center rounded-md bg-primary px-3 py-1 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:o?"Saving…":s})]})]})}function Jv({tabs:e,activeId:t,onChange:n,countByTab:o,pendingByTab:s}){return e.length===0?null:r("div",{className:"flex flex-wrap items-center gap-1 border-b border-border shrink-0",children:e.map(a=>{const i=a.id===t,l=o?.get(a.id)??0,c=s?.get(a.id)??0;return u("button",{type:"button",onClick:()=>n(a.id),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?"text-primary border-primary bg-primary/5":"text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover"}`,children:[a.label,l>0&&u("span",{className:"ml-1.5 text-[10px] opacity-60",children:["(",l,")"]}),c>0&&r("span",{className:"ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-primary"})]},a.id)})})}function ez(e,t){for(const n of e)for(const o of n.fields){if(!("key"in o)||o.key!==t)continue;if(o.type==="button"||o.type==="separator"||o.type==="info")return!0;const s=o.immediate;return s===!0?!0:s===!1?!1:n.immediate===!0}return!1}function e1({schema:e,serverValues:t,onImmediateSave:n,onDeferredSave:o}){const[s,a]=I({}),[i,l]=I(!1),c=ne(null),d=e?.sections??[],p=Object.keys(s).length>0,f=q(()=>({...t,...s}),[t,s]);J(()=>{if(p){l(!0);return}c.current&&clearTimeout(c.current),c.current=setTimeout(()=>l(!1),500)},[p]);const m=U(()=>{l(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>l(!1),2e3)},[]),h=U(y=>{m();const w={},v={},N={...t,...s};for(const[k,C]of Object.entries(y))N[k]!==C&&(ez(d,k)?w[k]=C:v[k]=C);Object.keys(w).length>0&&n(w),a(k=>{const C={...k};for(const D of Object.keys(w))delete C[D];for(const[D,M]of Object.entries(v))C[D]=M;return C})},[m,t,s,d,n]),g=U(y=>{const w={},v={};for(const[N,k]of Object.entries(s))y.includes(N)?w[N]=k:v[N]=k;a(v),Object.keys(w).length>0&&o(w)},[s,o]),x=U(y=>{a(w=>{const v={...w};for(const N of y)delete v[N];return v})},[]),b=U(()=>{a({})},[]);return{values:f,pendingKeys:Object.keys(s),hasPendingEdits:p,editingPaused:i,handleChange:h,handleSave:g,handleDiscard:x,resetAll:b}}const tz=Ke(function({addonId:t,schema:n,serverValues:o,onImmediateSave:s,onStateChange:a,onAction:i,disabled:l},c){const d=e1({schema:n,serverValues:o,onImmediateSave:U(x=>s(t,x),[t,s]),onDeferredSave:U(()=>{},[])});e2(c,()=>({flush:()=>{const x={};for(const b of d.pendingKeys)x[b]=d.values[b];return d.handleDiscard(d.pendingKeys),x},discard:()=>d.resetAll()}),[d]);const p=d.pendingKeys,f=p.join("|"),m=q(()=>p.map(x=>`${x}=${JSON.stringify(d.values[x])}`).join(","),[p,d.values]),h=ne(a);J(()=>{h.current=a},[a]),J(()=>{const x={};for(const b of p)x[b]=d.values[b];h.current({addonId:t,pendingKeys:p,pendingValues:x})},[t,f,m]);const g=q(()=>{if(i)return(x,b,y)=>i(t,x,b,y)},[t,i]);return r(On,{schema:n,values:d.values,onChange:d.handleChange,disabled:l,onAction:g})});function t1(e,t){if(e.type==="separator"||e.type==="info"||e.type==="button")return e;if(e.type==="group"){const a=e.fields.map(i=>t1(i,t));return{...e,fields:a}}const n=e;t[e.key]=n.value;const{value:o,...s}=n;return s}function nz(e,t){return{...e,fields:e.fields.map(n=>t1(n,t))}}function rz(e){const t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(o=>nz(o,t))},values:t}}function io({nodeId:e,addonIds:t,level:n,deviceId:o,capability:s,sectionIds:a,sectionTab:i,extraTabs:l,title:c,description:d}){const p=Me(),f=De().trpcClient,m=Sb(),h=Cb(),g=qx(),x=Hb(),b=$b(),y=!!(l&&l.length>0),[w,v]=I(null);if(n==="device"&&!o)throw new Error('NodeAddonsSettingsPanel: deviceId is required when level === "device"');const N=e??"hub",k=r2({queries:t.map(ee=>({queryKey:[["addonSettings",n==="global"?"getGlobalSettings":"getDeviceSettings"],{addonId:ee,nodeId:N,deviceId:o??null,cap:s??null}],queryFn:async()=>{if(n==="global"){const de=await f.addonSettings.getGlobalSettings.query({addonId:ee,nodeId:N,...s?{cap:s}:{}});return{addonId:ee,result:de}}const re=await f.addonSettings.getDeviceSettings.query({addonId:ee,deviceId:o,nodeId:N});return{addonId:ee,result:re}},staleTime:3e4}))}),C=k.some(ee=>ee.isLoading),D=k.map(ee=>{if(!ee.data)return"-";if(ee.data.result===null)return`${ee.data.addonId}:n`;const re=[];for(const de of ee.data.result.sections){re.push(`s:${de.id}:${de.tab??"general"}`);for(const ue of de.fields){if(!("key"in ue))continue;const be="options"in ue&&Array.isArray(ue.options)?ue.options.map(Be=>Be.value).join(","):"",Se=ue.value,Oe=Se===void 0?"":typeof Se=="string"?Se:JSON.stringify(Se);re.push(`f:${ue.key}:${be}:${Oe}`)}}return`${ee.data.addonId}:${re.join("|")}`}).join("||"),M=q(()=>{const ee=new Set;for(const re of k){const de=re.data?.result?.sections;if(de)for(const ue of de)ee.add(ue.tab??"general")}return[...ee]},[D+"::"+k.map(ee=>(ee.data?.result?.sections??[]).map(re=>re.tab??"general").join(",")).join("::")]),_=q(()=>new Map((l??[]).map(ee=>[ee.id,ee])),[l]),$=q(()=>{if(!y)return[];const ee=[...new Set([...M,...(l??[]).map(de=>de.id)])],re=de=>{const ue=_.get(de);if(ue?.order!==void 0)return ue.order;const be=Al[de];return be?be.order:50};return ee.sort((de,ue)=>{const be=re(de),Se=re(ue);return be!==Se?be-Se:de.localeCompare(ue)})},[y,M,l,_]),E=q(()=>{const ee=new Map;for(const re of M){const de=Al[re];ee.set(re,de?.label??re.charAt(0).toUpperCase()+re.slice(1))}for(const re of l??[])ee.set(re.id,re.label);return ee},[M,l]),R=y?w&&$.includes(w)?w:$[0]??null:null,O=R!==null&&_.has(R),A=y?R&&!O?R:void 0:i,{data:P}=Nn(void 0,{staleTime:6e4}),L=q(()=>{const ee=new Map;for(const re of P??[]){const de=re.manifest?.id;if(!de)continue;const ue=re.manifest?.name??re.manifest?.packageDisplayName??de;ee.set(de,ue)}return ee},[P]),B=q(()=>{const ee=a?new Set(a):null,re=[];for(const de of k){if(!de.data||de.data.result===null)continue;const{schema:ue,values:be}=rz(de.data.result),Se=ue.sections.filter(He=>ee?ee.has(He.id):!0);if(Se.length===0)continue;const Oe={...de.data.result,sections:de.data.result.sections.filter(He=>ee?ee.has(He.id):!0)},Be={...ue,sections:Se};re.push({addonId:de.data.addonId,schemaWithValues:Oe,schema:Be,serverValues:be})}return re},[D,a]),[z,T]=I(new Map),F=U(ee=>{T(re=>{const de=new Map(re);return de.set(ee.addonId,ee),de})},[]),H=ne(new Map),j=U(ee=>re=>{re?H.current.set(ee,re):H.current.delete(ee)},[]),Q=U(async(ee,re)=>{n==="global"?await m.mutateAsync({addonId:ee,nodeId:N,patch:re}):await h.mutateAsync({addonId:ee,deviceId:o,nodeId:N,patch:re}),p.invalidateQueries({queryKey:[["addonSettings"]]})},[m,h,N,n,o,p]),G=U(async(ee,re,de,ue)=>{const be=N;try{switch(re){case"reprobe-engine":await g.mutateAsync({nodeId:be}),p.invalidateQueries({queryKey:[["addonSettings"]]});return;case"reprobe-hwaccel":await x.mutateAsync({nodeId:be}),p.invalidateQueries({queryKey:[["addonSettings"]]});return;case"reprobe-audio-engine":await b.mutateAsync({nodeId:be}),p.invalidateQueries({queryKey:[["addonSettings"]]});return;default:{const Se=await f.addons.custom.mutate({addonId:ee,action:re,input:ue});return p.invalidateQueries({queryKey:[["addonSettings"]]}),Se}}}catch(Se){throw console.error("[NodeAddonsSettingsPanel] action failed",{addonId:ee,action:re,err:Se}),Se}},[g,x,b,N,p,f]),Z=U((ee,re)=>{Q(ee,re)},[Q]),V=Rt({mutationFn:async()=>{const ee=[];for(const de of B){const ue=z.get(de.addonId);!ue||ue.pendingKeys.length===0||ee.push({addonId:de.addonId,patch:ue.pendingValues})}return ee.length===0?{saved:[]}:{saved:await Promise.all(ee.map(async({addonId:de,patch:ue})=>(n==="global"?await m.mutateAsync({addonId:de,nodeId:N,patch:ue}):await h.mutateAsync({addonId:de,deviceId:o,nodeId:N,patch:ue}),de)))}},onSuccess:({saved:ee})=>{for(const re of ee)H.current.get(re)?.discard();p.invalidateQueries({queryKey:[["addonSettings"]]})}}),K=U(()=>{for(const ee of H.current.values())ee.discard()},[]),X=q(()=>{let ee=0;for(const re of B){const de=z.get(re.addonId);de&&(ee+=de.pendingKeys.length)}return ee},[B,z]),te=q(()=>{const ee=new Map;for(const re of B){const de=z.get(re.addonId);if(!de||de.pendingKeys.length===0)continue;const ue=new Set(de.pendingKeys);for(const be of re.schema.sections){const Se=be.tab??"general";for(const Oe of be.fields)"key"in Oe&&ue.has(Oe.key)&&ee.set(Se,(ee.get(Se)??0)+1)}}return ee},[B,z]);if(C)return r("div",{className:"h-24 rounded-lg border border-border bg-surface animate-pulse"});const he=R&&O?_.get(R):void 0;if(!y&&B.length===0)return u("div",{className:"text-[11px] text-foreground-subtle italic",children:["No addons in ",t.length>0?`[${t.join(", ")}]`:"the current selection"," ","expose ",n,"-level settings on this node."]});const xe=V.isPending;return u("div",{className:"space-y-4",children:[(c||d)&&u("div",{className:"border-b border-border pb-2",children:[c&&r("h2",{className:"text-sm font-semibold text-foreground",children:c}),d&&r("p",{className:"text-[11px] text-foreground-subtle mt-0.5",children:d})]}),y&&r(Jv,{tabs:$.map(ee=>({id:ee,label:E.get(ee)??ee})),activeId:R,onChange:v,pendingByTab:te}),V.isError&&u("div",{className:"rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400",children:["Save failed: ",String(V.error?.message??V.error)]}),he?he.content:(()=>{const ee=A?B.reduce((ue,be)=>ue+be.schemaWithValues.sections.filter(Se=>(Se.tab??"general")===A).length,0):0,re=A!==null&&ee<=1,de=B.map(ue=>({...ue,renderedWithValues:{...ue.schemaWithValues,sections:ue.schemaWithValues.sections.filter(be=>A?(be.tab??"general")===A:!0).map(be=>re?{...be,title:"",description:void 0}:be)}})).filter(ue=>ue.renderedWithValues.sections.length>0).sort((ue,be)=>{const Se=He=>{let se=Number.POSITIVE_INFINITY;for(const W of He)typeof W.order=="number"&&W.order<se&&(se=W.order);return se},Oe=Se(ue.renderedWithValues.sections),Be=Se(be.renderedWithValues.sections);return Oe!==Be?Oe-Be:0});return de.length===0?r("div",{className:"text-[11px] text-foreground-subtle italic",children:"Nothing to configure here for this node."}):r(oz,{entries:de,paneStates:z,displayNames:L,disabled:xe,setPaneRef:j,onPaneStateChange:F,onImmediateSave:Z,onAction:G,inline:y||!!i})})(),!C&&r(Xv,{pendingCount:X,onSave:()=>V.mutate(),onDiscard:K,saving:xe})]})}function oz({entries:e,paneStates:t,displayNames:n,disabled:o,setPaneRef:s,onPaneStateChange:a,onImmediateSave:i,onAction:l,inline:c}){const d=q(()=>[...e].sort((b,y)=>{if(b.addonId==="system-config")return-1;if(y.addonId==="system-config")return 1;const w=n.get(b.addonId)??b.addonId,v=n.get(y.addonId)??y.addonId;return w.localeCompare(v)}),[e,n]),p=d[0]?.addonId??"",[f,m]=I(p);J(()=>{d.length!==0&&(d.find(b=>b.addonId===f)||m(d[0].addonId))},[d,f]);const h=d.find(b=>b.addonId===f)??d[0];if(!h)return null;const g=q(()=>l?(b,y,w,v)=>l(b,y,w,v):void 0,[l]),x=b=>r(tz,{ref:s(b.addonId),addonId:b.addonId,schema:b.renderedWithValues,serverValues:b.serverValues,onImmediateSave:i,onStateChange:a,onAction:g,disabled:o},b.addonId);return d.length===1||c?r("div",{className:"flex flex-col gap-4",children:d.map(x)}):u("div",{className:"flex flex-col gap-3",children:[r("div",{className:"flex flex-wrap items-center gap-1 border-b border-border shrink-0",children:d.map(b=>{const y=n.get(b.addonId)??b.addonId,w=b.addonId===h.addonId,v=(t.get(b.addonId)?.pendingKeys.length??0)>0;return u("button",{type:"button",onClick:()=>m(b.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${w?"text-primary border-primary bg-primary/5":"text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover"}`,children:[y,v&&r("span",{className:"ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400"})]},b.addonId)})}),r("div",{className:"space-y-2",children:d.map(b=>r("div",{style:b.addonId===h.addonId?void 0:{display:"none"},children:x(b)},b.addonId))})]})}const sz=["detection-pipeline","decoder-nodeav","audio-analyzer","pipeline-runner"];function az({nodeId:e,refreshToken:t}){return u("div",{className:"flex flex-col h-full",children:[r(RB,{nodeId:e,refreshToken:t}),r("div",{className:"flex-1 min-h-0 overflow-y-auto p-6",children:r(io,{nodeId:e,addonIds:sz,level:"global",extraTabs:[{id:"assignments",label:"Assignments",order:-10,content:r(UB,{nodeId:e,refreshToken:t})},{id:"tree",label:"Pipeline",order:39,content:r(JB,{nodeId:e,refreshToken:t})},{id:"engines",label:"Warm instances",order:180,content:r(QB,{nodeId:e,refreshToken:t})},{id:"models",label:"Models",order:200,content:r(XB,{nodeId:e,refreshToken:t})}]})})]})}function iz({refreshToken:e}){const t=Me(),n=Xx({onSuccess:()=>{t.invalidateQueries({queryKey:[["pipelineOrchestrator","getPipelineAssignments"]]}),t.invalidateQueries({queryKey:[["pipelineOrchestrator","getDecoderAssignments"]]}),t.invalidateQueries({queryKey:[["pipelineOrchestrator","getAudioAssignments"]]})}});return u("div",{className:"space-y-6",children:[r(Qv,{refreshToken:e}),u("div",{className:"flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between",children:[u("div",{className:"min-w-0",children:[r("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Placement matrix"}),r("p",{className:"text-[11px] text-foreground-subtle",children:"Pipeline · decoder · audio assignments per camera. Click the kebab to pin / unpin / move any role; expand the chevron for the per-camera broker drill-down."})]}),u("button",{type:"button",onClick:()=>n.mutate(void 0),disabled:n.isPending,className:"inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap",children:[r(cu,{className:"h-3.5 w-3.5"}),n.isPending?"Rebalancing…":"Rebalance pipelines"]})]}),r(Kv,{mode:"cluster"})]})}const lz=["pipeline-orchestrator"];function cz({refreshToken:e}){return r("div",{className:"space-y-4 max-w-3xl",children:r(io,{nodeId:"hub",addonIds:lz,level:"global",title:"Cluster settings",description:"Cluster-wide orchestration knobs: enabled nodes, load balancer thresholds, and failover policy. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab."})})}function dz({refreshToken:e}){const t=Me(),{data:n,isLoading:o}=my(),[s,a]=I(null),[i,l]=I(""),[c,d]=I(""),p=()=>{t.invalidateQueries({queryKey:[["pipelineOrchestrator","listTemplates"]]})},f=hy({onSuccess:()=>{a(null),p()}}),m=gy({onSuccess:p}),h=y=>{a(y.id),l(y.name),d(y.description??"")},g=()=>{a(null),l(""),d("")},x=()=>{if(!s)return;const y=c.trim();f.mutate({id:s,name:i.trim()||"Untitled",...y?{description:y}:{}})};if(o)return r("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading templates…"});const b=[...n??[]].sort((y,w)=>y.name.localeCompare(w.name));return r("div",{className:"space-y-6 max-w-4xl",children:u("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"border-b border-border px-4 py-3 flex items-center justify-between",children:[u("div",{children:[r("h3",{className:"text-sm font-semibold text-foreground",children:"Templates"}),r("p",{className:"text-[11px] text-foreground-subtle mt-0.5",children:"Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab."})]}),u("div",{className:"text-[11px] text-foreground-subtle",children:[b.length," template",b.length===1?"":"s"]})]}),b.length===0?u("div",{className:"px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2",children:[r(It,{className:"h-6 w-6 opacity-40"}),r("div",{children:'No templates yet. Create one from a device Pipeline tab ("Save as template").'})]}):r("ul",{className:"divide-y divide-border",children:b.map(y=>{const w=s===y.id;return r("li",{className:"px-4 py-3 text-xs",children:u("div",{className:"flex items-start gap-3",children:[r("div",{className:"flex-1 min-w-0",children:w?u("div",{className:"space-y-2",children:[r("input",{className:"w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary",value:i,onChange:v=>l(v.target.value),placeholder:"Template name",autoFocus:!0}),r("input",{className:"w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary",value:c,onChange:v=>d(v.target.value),placeholder:"Description (optional)"})]}):u(me,{children:[r("div",{className:"font-medium text-foreground",children:y.name}),y.description&&r("div",{className:"text-foreground-subtle mt-0.5",children:y.description}),u("div",{className:"mt-1 font-mono text-[10px] text-foreground-subtle",children:["engine ",y.config.engine.runtime,"/",y.config.engine.backend," · ",y.config.steps.length," step(s)",y.config.audio?.enabled?" · audio":"",u("span",{className:"ml-2",children:["updated ",new Date(y.updatedAt).toLocaleString()]})]})]})}),r("div",{className:"flex items-center gap-1 shrink-0",children:w?u(me,{children:[u("button",{type:"button",onClick:x,disabled:f.isPending,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50",children:[r(St,{className:"h-3 w-3"}),"Save"]}),u("button",{type:"button",onClick:g,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover",children:[r(Ve,{className:"h-3 w-3"}),"Cancel"]})]}):u(me,{children:[r("button",{type:"button",onClick:()=>h(y),title:"Rename",className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover",children:r(ao,{className:"h-3 w-3"})}),r("button",{type:"button",onClick:()=>{confirm(`Delete template "${y.name}"?`)&&m.mutate({id:y.id})},disabled:m.isPending,title:"Delete",className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50",children:r(et,{className:"h-3 w-3"})})]})})]})},y.id)})})]})})}function Ef(e,t){if(!e)return null;for(const n of e.slots)for(const o of n.addons)if(o.id===t)return o;return null}function uz({nodeId:e,refreshToken:t}){const n=Me(),o=De().trpcClient,[s,a]=I(null),[i,l]=I(null),c=no(void 0,{refetchOnMount:"always"});Zt(["nodes","topology"],["agent.online","agent.offline","agent.unregistered","addon.installed","addon.uninstalled","addon.updated"]);const d=Hn(void 0,{staleTime:3e4,refetchOnMount:"always"}),p=q(()=>{const _=new Set;for(const $ of d.data??[])$.isOnline&&_.add($.id);return _},[d.data]),f=es({nodeId:e},{refetchOnMount:"always"}),m=q(()=>(c.data??[]).filter(_=>p.has(_.nodeId)).map(_=>_.nodeId),[c.data,p]),h=cr({enabled:m.length>0,queryKey:[["pipelineExecutor","getSchema"],"schema-by-agent",m.join(","),t],queryFn:async()=>{const _={};for(const $ of m)try{const E=await o.pipelineExecutor.getSchema.query({nodeId:$});_[$]=E.selectedEngine.format}catch{_[$]="coreml"}return _}}),g=Ed({onSuccess:()=>{n.invalidateQueries({queryKey:[["pipelineOrchestrator"]]}),n.invalidateQueries({queryKey:[["pipelineExecutor"]]}),n.invalidateQueries({queryKey:[["addonSettings"]]})}}),x=q(()=>f.data?ja(f.data):[],[f.data]),b=q(()=>{const _=c.data??[],$=p;return($.size===0?[]:_.filter(R=>$.has(R.nodeId))).map(R=>{const O=h.data?.[R.nodeId];return{agentNodeId:R.nodeId,engineLabel:O??"(engine unknown)"}})},[c.data,h.data,p]),y=(_,$)=>{const R=c.data?.find(L=>L.nodeId===$)?.settings.addonDefaults[_],O=h.data?.[$];return Ef(f.data??null,_)?.models.some(L=>O!==void 0&&!!L.formats[O])?R?R.enabled?{kind:"enabled",modelId:R.modelId}:{kind:"disabled"}:{kind:"na"}:{kind:"na"}},w=s?c.data?.find(_=>_.nodeId===s.agentNodeId)??null:null,v=s&&f.data?Ef(f.data,s.addonId):null,N=s?h.data?.[s.agentNodeId]??"coreml":"coreml",k=()=>{a(null),l(null)},C=(_,$)=>{const R=c.data?.find(O=>O.nodeId===$)?.settings.addonDefaults[_]??null;a({addonId:_,agentNodeId:$}),l(R)},D=()=>{!i||!s||!w||g.mutate({agentNodeId:s.agentNodeId,defaults:{...w.settings.addonDefaults,[s.addonId]:i}},{onSuccess:k})};if(c.isLoading||f.isLoading)return r("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading agents…"});if(!f.data)return u("div",{className:"text-xs text-foreground-subtle",children:["Catalog unavailable for ",e,"."]});const M=s!==null&&v!==null&&i!==null;return u("div",{className:"relative h-full w-full space-y-3",children:[r(Zv,{title:"Cluster cameras"}),r("div",{className:M?"pr-[360px]":"",children:x.length>0&&b.length>0?r(td,{tree:x,agents:b,getCellState:y,onCellClick:C,selectedCell:s}):r("div",{className:"text-xs text-foreground-subtle",children:"No agents or catalog empty."})}),r(ed,{open:M,onClose:k,title:v?.name??"",subtitle:s?`${s.agentNodeId} · ${N}`:"",footer:u(me,{children:[r("button",{type:"button",className:"px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted",onClick:k,children:"Cancel"}),r("button",{type:"button",disabled:!i||!s||g.isPending,className:"px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50",onClick:D,children:g.isPending?"Saving…":"Save"})]}),children:v&&i&&s&&r(Va,{mode:"agent",addon:v,agentDefault:i,agentNodeId:s.agentNodeId,engineFormat:N,onChangeAgentConfig:_=>l(_)})})]})}const pz=[{id:"assignments",label:"Assignments"},{id:"pipeline",label:"Pipeline"},{id:"settings",label:"Settings"},{id:"templates",label:"Templates"}];function fz({refreshToken:e}){const[t,n]=I("assignments"),{data:o}=Hn(void 0,{staleTime:3e4}),s=o?.find(a=>a.isHub&&a.isOnline)?.id??o?.find(a=>a.isOnline)?.id??null;return u("div",{className:"flex flex-col h-full",children:[u("div",{className:"px-4 sm:px-6 py-4 border-b border-border",children:[r("h2",{className:"text-base font-semibold text-foreground",children:"Cluster Orchestration"}),r("div",{className:"text-[11px] text-foreground-subtle mt-1",children:"Assignments with live load, cluster-wide settings, pipeline template library, per-camera pipeline overrides."})]}),r("div",{className:"flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto",children:pz.map(a=>r("button",{type:"button",onClick:()=>n(a.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===a.id?"border-primary text-primary":"border-transparent text-foreground-subtle hover:text-foreground"}`,children:a.label},a.id))}),u("div",{className:"flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab",children:[t==="assignments"&&r(iz,{refreshToken:e}),t==="pipeline"&&(s?r(uz,{nodeId:s,refreshToken:e}):r("div",{className:"text-xs text-foreground-subtle",children:"No online node available — schema unreachable."})),t==="settings"&&r(cz,{refreshToken:e}),t==="templates"&&r(dz,{refreshToken:e})]})]})}const Io="__cluster__";function mz(){const[e,t]=Xa(),n=e.get("node")??Io,[o,s]=I(0);return J(()=>{e.get("node")||t({node:Io},{replace:!0})},[e,t]),u("div",{className:"flex flex-col h-full overflow-hidden",children:[r("div",{className:"flex items-center justify-end gap-4 px-4 py-3 border-b border-border shrink-0",children:u("button",{type:"button",onClick:()=>s(i=>i+1),title:"Refresh",className:"inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:[r(ct,{className:"h-3.5 w-3.5"}),"Refresh"]})}),u("div",{className:"flex-1 flex flex-col md:flex-row overflow-hidden min-h-0",children:[r("aside",{className:"w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border overflow-y-auto",children:r(TB,{selectedNodeId:n,onSelect:i=>{t({node:i},{replace:!0})},refreshToken:o})}),r("section",{className:"flex-1 min-h-0 overflow-hidden",children:n===Io?r(fz,{refreshToken:o}):r(az,{nodeId:n,refreshToken:o})})]})]})}const hz="device-export",dl="export",gz="Export";function uc(e){return e.type==="separator"||e.type==="info"||e.type==="object-array"||e.type==="widget"||e.type==="addon-action-button"?!1:e.type==="group"?e.fields.some(uc):e.type==="sub-tabs"?e.tabs.some(t=>t.fields.some(uc)):e.writerCapName===hz}function Fo(e){return e.fields.some(uc)}const bz={streaming:{icon:Iv,label:"Streaming"},detection:{icon:ni,label:"Detection"},recording:{icon:uv,label:"Recording"},audio:{icon:rc,label:"Audio"},snapshot:{icon:Rr,label:"Snapshot"},motion:{icon:cu,label:"Motion"},ptz:{icon:tn,label:"PTZ"},webrtc:{icon:si,label:"WebRTC"},onvif:{icon:Q8,label:"ONVIF"},analytics:{icon:jt,label:"Analytics"},"battery-operated":{icon:U6,label:"Battery"},"native-snapshot":{icon:Rr,label:"Native Snapshot"},"pan-tilt-zoom":{icon:tn,label:"PTZ"},"two-way-audio":{icon:rc,label:"Two-way Audio"},"doorbell-button":{icon:rs,label:"Doorbell"},rebootable:{icon:ct,label:"Rebootable"}},xz=su;function ci({capabilities:e,showLabels:t=!1}){return r("div",{className:"flex items-center gap-1 flex-wrap",children:e.map(n=>{const o=bz[n],s=o?.icon??xz,a=o?.label??n;return u("span",{className:"inline-flex items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-foreground-subtle",title:a,children:[r(s,{className:"h-3 w-3"}),t&&r("span",{children:a})]},n)})})}function yz(e){const t=De();return F0(t.trpcClient,e)}function vz(e){const[t,n]=I("idle"),[o,s]=I(null),a=ne(null),i=ne(null),l=ne(null),c=ne(!0),d=gx(),p=bx(),f=xx(),m=U(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(i.current){for(const x of i.current.getTracks())try{x.stop()}catch{}i.current=null}l.current=null},[]),h=U(async()=>{if(t==="idle")return;n("stopping");const x=l.current;if(x&&e!==null)try{await Promise.race([f.mutateAsync({deviceId:e,sessionId:x}),new Promise((y,w)=>setTimeout(()=>w(new Error("server stopSession timeout")),2e3))])}catch(y){console.warn("[intercom] server stopSession failed (continuing teardown)",y)}m(),c.current&&(n("idle"),s(null))},[t,e,f,m]),g=U(async()=>{if(e===null||t!=="idle"&&t!=="error")return;s(null);let x=null,b=null,y=null;try{n("requesting-mic"),x=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),i.current=x,n("starting");const w=await d.mutateAsync({deviceId:e});y=w.sessionId,l.current=y,n("connecting"),b=new RTCPeerConnection,a.current=b,b.oniceconnectionstatechange=()=>{if(!c.current)return;const k=b.iceConnectionState;k==="connected"||k==="completed"?n("talking"):(k==="failed"||k==="closed"||k==="disconnected")&&c.current&&(s(k==="failed"?"WebRTC connection failed":null),h())};for(const k of x.getAudioTracks())b.addTrack(k,x);await b.setRemoteDescription({type:"offer",sdp:w.sdpOffer});const v=await b.createAnswer();await b.setLocalDescription(v);const N=b.localDescription?.sdp??v.sdp??"";await p.mutateAsync({deviceId:e,sessionId:y,sdpAnswer:N})}catch(w){const v=w instanceof Error?w.message:String(w);if(console.warn("[intercom] start failed",w),b)try{b.close()}catch{}if(x)for(const N of x.getTracks())try{N.stop()}catch{}if(a.current=null,i.current=null,y!==null)try{await f.mutateAsync({deviceId:e,sessionId:y})}catch{}l.current=null,c.current&&(s(v),n("error"))}},[e,t,d,p,f,h]);return J(()=>(c.current=!0,()=>{c.current=!1;const x=l.current;if(x!==null&&e!==null&&f.mutate({deviceId:e,sessionId:x}),a.current){try{a.current.close()}catch{}a.current=null}if(i.current){for(const b of i.current.getTracks())try{b.stop()}catch{}i.current=null}l.current=null}),[e]),{state:t,error:o,start:g,stop:h,isTalking:t==="talking"}}let wz=0;function mt(){return++wz}function ul(e){switch(e.type){case"system":return"system";case"device":return`#${e.deviceId}`;case"provider":return e.providerId;case"addon":return e.addonId}}function Nz(e){return["","Commands"," help Show this help"," examples Show usage examples for the current scope"," context Show every available variable + full API surface"," clear Clear terminal (also Ctrl+L)","","Shortcuts"," Enter Execute expression"," Arrow Up/Down Navigate command history"," Ctrl+L Clear terminal","",`Try: ${{system:" sm.summary() // fleet overview",device:" device.state.battery.value?.sleeping // sync read",provider:" devices.map(d => d.name)",addon:" manifest.version"}[e.type]}`,"","Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …"]}function kz(e){switch(e.type){case"device":return["","── State (sync, zero round-trip) ─────────────────────────"," device.state.battery.value"," device.state.battery.value?.percentage"," device.state.motion.value?.detected","","── Actions (async, through wrapper chain) ────────────────"," await device.snapshot.getSnapshot({})"," await device.ptz.move({ direction: 'left', steps: 1 })"," await device.switch.setState({ on: true })","","── Wait for condition ───────────────────────────────────"," await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)","","── Subscribe to changes ─────────────────────────────────"," const off = device.state.battery.subscribe(s => console.log(s))","","── Quick info ───────────────────────────────────────────"," info.name device name"," info.addonId owning addon"," sm.dump(deviceId) full debug dump"];case"system":return["","── Lookups ──────────────────────────────────────────────"," sm.getDeviceById(8)"," sm.getDeviceByName('Sala da pranzo')"," sm.getDevicesByAddon('reolink')"," sm.getDevicesByType(DeviceType.Camera)","","── Filters (typed query) ────────────────────────────────"," sm.query({ addonId: 'reolink', online: true })"," sm.query({ caps: ['battery', 'snapshot'] })"," sm.query({ name: /^Cam-/ })","","── Cross-device ─────────────────────────────────────────"," sm.whereState('battery', s => s.percentage < 20).length"," sm.mapState('battery', s => s.percentage)"," sm.countByCap('snapshot')","","── Batch action ─────────────────────────────────────────"," await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })","","── Listen ───────────────────────────────────────────────"," sm.listenCap('motion', (id, s) => console.log(id, s))"," sm.onDeviceAdded((id, info) => console.log('+', info.name))","","── Diagnostics ──────────────────────────────────────────"," sm.summary()"," sm.dump(8)"];case"provider":return[""," devices.map(d => d.name)"," await getIntegration()"," sm.getDevicesByAddon('<this-addon-id>').length"];case"addon":return[""," manifest.name"," manifest.version"," declaration"]}}function Sz(e){const t=["",`Scope: ${e.type}`,""];switch(e.type){case"system":return[...t,"Primary API — sm (SystemMirror):"," sm.getDeviceById(id) DeviceProxy | null (sync)"," sm.getDeviceByName(name) DeviceProxy | null"," sm.getDeviceByStableId(sid) DeviceProxy | null"," sm.getAllDevices() readonly DeviceProxy[]"," sm.getDeviceInfo(id) DeviceInfo | null"," sm.summary() fleet stats","","Filters — sm.query({...}):"," sm.query({ addonId: 'reolink', online: true })"," sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required"," sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap"," sm.query({ name: { contains: 'sala' } }) // case-insensitive"," sm.query({ name: /^Cam-\\d+$/ })"," sm.query({ type: DeviceType.Camera })"," sm.query({ parentDeviceId: 8 }) // accessories of cam 8"," sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })","","State queries:"," sm.whereState('battery', s => s.percentage < 20)"," sm.mapState('battery', s => s.percentage)"," sm.findState('motion', s => s.detected)"," sm.countByCap('snapshot')","","Listeners (return unsubscribe fn):"," sm.listen((id, cap, slice) => …) // every state change"," sm.listenCap('motion', (id, slice) => …)"," sm.listenDevice(8, (id, cap, slice) => …)"," sm.onDeviceAdded((id, info) => …)"," sm.onDeviceRemoved((id, info) => …)","","Wait primitives:"," await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)"," await sm.waitForDevice(99, 30_000)","","Batch:"," await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })"," await sm.forEachCap('reboot', d => d.reboot.reboot({}))","","Diagnostics:"," sm.dump(8) debug dump (one device)"," sm.dump() full fleet dump"," sm.summary() breakdown by cap/addon/type","","Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()"];case"device":return[...t,"Pre-bound variables:"," device DeviceProxy for this device (sync state + async methods)"," deviceId number"," info DeviceInfo metadata (name, addonId, type, online, …)"," sm SystemMirror (full cluster view)"," rawDevice legacy IDevice instance (escape hatch)","","Reactive state (sync, zero round-trip):"," device.state.battery.value BatteryStatus | undefined"," device.state.battery.value?.sleeping"," device.state.battery.value?.percentage"," device.state.motion.value?.detected"," device.state.switch.value?.on"," device.state.brightness.value?.percentage"," device.state.doorbell.value?.lastPressedAt","","Cap actions (async, through wrapper chain):"," await device.snapshot.getSnapshot({})"," await device.snapshot.getSnapshot({ streamId: 'high' })"," await device.ptz.move({ direction: 'left', steps: 1 })"," await device.ptz.goToPreset({ presetId: 'home' })"," await device.switch.setState({ on: true })"," await device.brightness.setBrightness({ percentage: 60 })"," await device.reboot.reboot({})","","Subscribe to slice changes:"," const off = device.state.battery.subscribe(s => console.log(s))"," // off() to unsubscribe","","Wait for a state condition:"," await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)","","Diagnostics:"," info.name device name"," info.addonId which addon owns it"," info.online transport health"," sm.dump(deviceId) full debug dump (binding + state + info)"];case"provider":return[...t,"Pre-bound variables:"," devices Devices belonging to this provider (raw IDevice[])"," getIntegration() Integration metadata","","For typed device access use the SystemMirror:"," await getSystemMirror()"," sm.getDevicesByAddon('this-addon-id')"];case"addon":return[...t,"Pre-bound variables:"," manifest { name, version, ... }"," declaration addon declaration"," source addon source location","","Examples:"," manifest.name"," manifest.version"]}}function Cz({scope:e,greeting:t,className:n}){const o=De(),[s,a]=I(()=>{const v=[];return t&&v.push({id:mt(),kind:"info",text:t}),v.push({id:mt(),kind:"info",text:`scope: ${ul(e)} — type help or context for available commands`}),v}),[i,l]=I(""),[c,d]=I([]),[p,f]=I(-1),m=ne(null),h=ne(null);J(()=>{const v=h.current;v&&(v.scrollTop=v.scrollHeight)},[s]);const g=U(()=>{m.current?.focus()},[]),x=Rt({mutationFn:v=>o.trpcClient.repl.execute.mutate({code:v,scope:e}),onSuccess:v=>{const N=v??{},k=typeof N.output=="string"?N.output:v==null?"undefined":typeof v=="string"?v:JSON.stringify(v,null,2),C=N.type==="error";a(D=>[...D,{id:mt(),kind:C?"error":"result",text:k}])},onError:v=>{const N=v instanceof Error?v.message:String(v);a(k=>[...k,{id:mt(),kind:"error",text:N}])}});function b(v){const N=v.trim();if(N){if(N==="clear"){a([{id:mt(),kind:"info",text:`scope: ${ul(e)}`}]),l("");return}if(N==="help"){a(k=>[...k,{id:mt(),kind:"input",text:`> ${N}`},...Nz(e).map(C=>({id:mt(),kind:"info",text:C}))]),l("");return}if(N==="context"){a(k=>[...k,{id:mt(),kind:"input",text:`> ${N}`},...Sz(e).map(C=>({id:mt(),kind:"info",text:C}))]),l("");return}if(N==="examples"){a(k=>[...k,{id:mt(),kind:"input",text:`> ${N}`},...kz(e).map(C=>({id:mt(),kind:"info",text:C}))]),l("");return}d(k=>[...k,N]),f(-1),a(k=>[...k,{id:mt(),kind:"input",text:`> ${N}`}]),l(""),x.mutate(N)}}function y(v){if(v.key==="Enter"){v.preventDefault(),b(i);return}if(v.key==="ArrowUp"){if(v.preventDefault(),c.length===0)return;const N=p===-1?c.length-1:Math.max(0,p-1);f(N),l(c[N]??"");return}if(v.key==="ArrowDown"){if(v.preventDefault(),p===-1)return;const N=p+1;N>=c.length?(f(-1),l("")):(f(N),l(c[N]??""));return}v.ctrlKey&&v.key==="l"&&(v.preventDefault(),a([{id:mt(),kind:"info",text:`scope: ${ul(e)}`}]))}const w={input:"text-zinc-300",result:"text-emerald-300",error:"text-red-300",info:"text-zinc-400"};return u("div",{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??""}`,onClick:g,children:[u("div",{ref:h,className:"flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]",children:[s.map(v=>r("pre",{className:`whitespace-pre-wrap break-words leading-relaxed ${w[v.kind]}`,children:v.text},v.id)),x.isPending&&r("span",{className:"text-zinc-500 animate-pulse",children:"…thinking"})]}),u("div",{className:"flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]",children:[r("span",{className:"text-emerald-400 flex-shrink-0 select-none font-bold",children:">"}),r("input",{ref:m,value:i,onChange:v=>l(v.target.value),onKeyDown:y,disabled:x.isPending,placeholder:"device.state.battery.value",autoFocus:!0,className:"flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"})]})]})}function Mz({deviceId:e,intercomAvailable:t=!1}){const n=De(),o=typeof window<"u"?window.location.origin:"",s=Number.isFinite(e),a=yz(s?e:null),{streams:i,pipelineMetrics:l,createSession:c,sendAnswer:d,handleOffer:p,getIceServers:f,addIceCandidate:m,getIceCandidates:h,closeSession:g}=j0(n.trpcClient,s?e:null),x=cd(n.trpcClient,s?e:null),b=vz(s&&t?e:null),y=b.state==="requesting-mic"||b.state==="starting"||b.state==="connecting"||b.state==="stopping",w=b.isTalking||y,v=()=>{b.state==="idle"||b.state==="error"?b.start():b.state!=="stopping"&&b.stop()},N=n0(),k=N.length>0?r(me,{children:N.map(C=>r("div",{className:"absolute inset-0",children:C.node},C.id))}):null;return r(g0,{serverUrl:o,createSession:c,sendAnswer:d,handleOffer:p,getIceServers:f,addIceCandidate:m,getIceCandidates:h,closeSession:g,streams:i,pipelineMetrics:l,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:x.src,snapshotLoading:x.loading,onRefreshSnapshot:x.refresh,intercomAvailable:t,intercomShown:w,onIntercomToggle:v,extraOverlay:k,chromeless:!0,className:"h-full"})}function Az({deviceId:e}){return Number.isFinite(e)?r("div",{className:"flex flex-col h-full",children:r(rn,{deviceId:e,limit:50,maxHeight:"max-h-full",showScope:!1,showFilters:!1})}):u("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]})}function Ez({deviceId:e}){if(!Number.isFinite(e))return u("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]});const t=[`CamStack REPL — device #${e}`,""," device.state.battery.value sync state read"," await device.snapshot.getSnapshot({}) cap action",""," type 'examples' for more, 'context' for the full API"].join(`
1171
+ `);return r(Cz,{scope:{type:"device",deviceId:e},greeting:t,className:"h-full border-0 rounded-none"})}function Iz({deviceId:e}){return Number.isFinite(e)?r("div",{className:"flex flex-col h-full overflow-y-auto",children:r(hr,{deviceId:e,limit:50,maxHeight:"max-h-full"})}):u("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]})}function Pz({deviceId:e}){return Number.isFinite(e)?r("div",{className:"flex flex-col h-full overflow-y-auto",children:r(qd,{deviceId:e,limit:50,maxHeight:"max-h-full"})}):u("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]})}function _z({parentDeviceId:e}){const{t}=Ht(),n=at(),o=De(),{data:s,isLoading:a,isError:i}=Wv(e);if(a)return r("div",{className:"rounded-lg border border-border bg-surface p-3",children:r("p",{className:"text-[10px] text-foreground-subtle",children:t("common.loading",{defaultValue:"Loading…"})})});if(i)return r("div",{className:"rounded-lg border border-border bg-surface p-3",children:r("p",{className:"text-[10px] text-warning",children:t("integrations.childrenLoadError",{defaultValue:"Failed to load children"})})});const l=s??[];if(l.length===0)return null;const c=l.some(f=>!!f.role),d=l.some(f=>!f.role),p=c&&!d?t("device.accessories",{defaultValue:"Accessories"}):!c&&d?t("device.adoptedDevices",{defaultValue:"Adopted devices"}):t("device.children",{defaultValue:"Children"});return u("div",{className:"rounded-lg border border-border bg-surface p-3",children:[r("div",{className:"text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5",children:p}),r("div",{className:"space-y-1",children:l.map(f=>r(Ro,{trpc:o.trpcClient,device:f,variant:"minimal",onNavigate:m=>n(`/devices/${String(m)}`)},f.id))})]})}function pn({label:e,value:t}){return u("div",{className:`${Oh} flex items-start gap-2 sm:gap-3`,children:[r("span",{className:"w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle",children:e}),r("div",{className:"flex-1 min-w-0 text-[11px] text-foreground",children:t})]})}function $z({deviceId:e,initialName:t}){const n=Me(),[o,s]=I(!1),[a,i]=I(t),[l,c]=I(!1),d=ne(null);J(()=>{o||i(t)},[t,o]),J(()=>{o&&d.current?.focus()},[o]);const p=Kb({onSuccess:()=>{n.invalidateQueries({queryKey:[["deviceManager","getDevice"]]}),n.invalidateQueries({queryKey:[["deviceManager","listAll"]]}),n.invalidateQueries({queryKey:[["deviceManager","getDeviceAggregate"]]})}}),f=async()=>{const h=a.trim();if(h.length===0||h===t){s(!1),i(t);return}c(!0);try{await p.mutateAsync({deviceId:e,name:h}),s(!1)}catch{}finally{c(!1)}},m=()=>{i(t),s(!1)};return o?r(pn,{label:"Name",value:u("div",{className:"flex items-center gap-1",children:[r("input",{ref:d,type:"text",value:a,onChange:h=>i(h.target.value),onKeyDown:h=>{h.key==="Enter"?f():h.key==="Escape"&&m()},disabled:l,className:"flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary"}),r("button",{type:"button",onClick:()=>void f(),disabled:l,className:"p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50","aria-label":"Save",children:r(St,{className:"h-3 w-3"})}),r("button",{type:"button",onClick:m,disabled:l,className:"p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50","aria-label":"Cancel",children:r(Ve,{className:"h-3 w-3"})})]})}):r(pn,{label:"Name",value:u("div",{className:"flex items-center gap-2 group",children:[r("span",{className:"truncate",children:t}),r("button",{type:"button",onClick:()=>s(!0),className:"opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover","aria-label":"Edit name",children:r(ao,{className:"h-3 w-3 text-foreground-subtle"})})]})})}function Dz({deviceId:e,initialLocation:t}){const n=Me(),[o,s]=I(!1),[a,i]=I(t??""),[l,c]=I(!1),d=ne(null),{data:p}=Zb(void 0,{staleTime:3e4,enabled:o}),f=p??[];J(()=>{o||i(t??"")},[t,o]),J(()=>{o&&d.current?.focus()},[o]);const m=Yb({onSuccess:()=>{n.invalidateQueries({queryKey:[["deviceManager","getDevice"]]}),n.invalidateQueries({queryKey:[["deviceManager","listAll"]]}),n.invalidateQueries({queryKey:[["deviceManager","getDeviceAggregate"]]}),n.invalidateQueries({queryKey:[["deviceManager","listLocations"]]})}}),h=q(()=>{const y=a.trim().toLowerCase();return y.length===0?f:f.filter(w=>w.toLowerCase()!==y&&w.toLowerCase().includes(y))},[f,a]),g=a.trim().length>0&&!f.some(y=>y.toLowerCase()===a.trim().toLowerCase()),x=async y=>{const v=(y??a).trim(),N=v.length===0?null:v;if(N===(t??null)){s(!1);return}c(!0);try{await m.mutateAsync({deviceId:e,location:N}),s(!1)}catch{}finally{c(!1)}},b=()=>{i(t??""),s(!1)};return o?r(pn,{label:"Location",value:u("div",{className:"relative",children:[u("div",{className:"flex items-center gap-1",children:[r("input",{ref:d,type:"text",value:a,onChange:y=>i(y.target.value),onKeyDown:y=>{y.key==="Enter"?x():y.key==="Escape"&&b()},disabled:l,placeholder:"Room / area (or leave empty to clear)",className:"flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary"}),r("button",{type:"button",onClick:()=>void x(),disabled:l,className:"p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50","aria-label":"Save",children:r(St,{className:"h-3 w-3"})}),r("button",{type:"button",onClick:b,disabled:l,className:"p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50","aria-label":"Cancel",children:r(Ve,{className:"h-3 w-3"})})]}),(h.length>0||g)&&u("div",{className:"absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md",children:[h.map(y=>u("button",{type:"button",onClick:()=>{i(y),x(y)},className:"w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover",children:[r(s8,{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),r("span",{className:"truncate",children:y})]},y)),g&&u("button",{type:"button",onClick:()=>void x(),className:"w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border",children:[r("span",{className:"text-foreground-subtle",children:"Create"}),u("span",{className:"font-medium truncate",children:['"',a.trim(),'"']})]})]})]})}):r(pn,{label:"Location",value:u("div",{className:"flex items-center gap-2 group",children:[t?r("span",{className:"truncate",children:t}):r("span",{className:"italic text-foreground-subtle",children:"unset"}),r("button",{type:"button",onClick:()=>s(!0),className:"opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover","aria-label":"Edit location",children:r(ao,{className:"h-3 w-3 text-foreground-subtle"})})]})})}const If=["manufacturer","model","hardware","firmware","serialNumber","uid","mac","itemNo"];function Lz(e){return e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/^./,t=>t.toUpperCase())}function Tz(e){return e==null?"—":typeof e=="string"||typeof e=="number"||typeof e=="boolean"?String(e):JSON.stringify(e)}function Rz(){const e=fd(),t=ib(),{data:n}=Lr({deviceId:e??0},{enabled:e!==null,staleTime:3e4}),o=n??t??null,[s,a]=I("identity");if(e===null||!o)return null;const i=String(o.stableId??""),l=String(o.name??""),c=String(o.type??""),d=String(o.addonId??""),p=o.features??[],f=o.location??null,m=o.metadata??null,h=m!==null&&Object.keys(m).length>0;return u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3",children:[r("h2",{className:"text-[11px] font-semibold text-foreground uppercase tracking-wider",children:"Device Info"}),h&&u("div",{className:"flex items-center gap-1 rounded-md bg-surface-hover p-0.5",children:[r(Pf,{active:s==="identity",onClick:()=>a("identity"),label:"Identity"}),r(Pf,{active:s==="hardware",onClick:()=>a("hardware"),label:"Hardware"})]})]}),(!h||s==="identity")&&u("div",{className:"divide-y divide-border",children:[r(pn,{label:"ID",value:u("span",{className:"font-mono text-[11px] text-foreground",children:[`#${e}`,u("span",{className:"ml-1.5 text-foreground-subtle",children:["(",i,")"]})]})}),r($z,{deviceId:e,initialName:l}),r(Dz,{deviceId:e,initialLocation:f}),r(pn,{label:"Type",value:c}),r(pn,{label:"Provider",value:r(yn,{type:d,size:"sm",showLabel:!0})}),r(pn,{label:"Capabilities",value:p.length>0?r(ci,{capabilities:p,showLabels:!0}):r("span",{className:"text-[11px] text-foreground-subtle",children:"None"})})]}),h&&s==="hardware"&&r(Oz,{metadata:m})]})}function Pf({active:e,onClick:t,label:n}){return r("button",{type:"button",onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?"bg-surface text-foreground shadow-sm":"text-foreground-subtle hover:text-foreground"}`,children:n})}function Oz({metadata:e}){const t=If.filter(s=>s in e),n=Object.keys(e).filter(s=>!If.includes(s)).sort(),o=[...t,...n];return u("div",{children:[r("div",{className:"px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40",children:"Auto-populated by the driver on every connect. Read-only."}),r("div",{className:"divide-y divide-border",children:o.map(s=>r(pn,{label:Lz(s),value:r("span",{className:"font-mono text-[11px] text-foreground break-all",children:Tz(e[s])})},s))})]})}function pl(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Bz({device:e}){const t=at(),n=typeof e.id=="number"?e.id:null,o=String(e.type??""),s=o===gt.Camera,a=o===gt.Hub,i=e.features??[],{data:l}=Tx({deviceId:n??0},{enabled:n!==null&&s,refetchInterval:5e3}),c=l?.streams??{},d=Object.entries(c),p=i.includes(Qs.DoorbellButton),f=H0(p?{deviceId:n??void 0,historyLimit:10}:void 0),m=f.latest?Date.now()-f.latest.timestamp<3e4:!1;return u("div",{className:"space-y-5",children:[a&&n!==null&&r($0,{deviceId:n,onOpenChild:h=>t(`/devices/${h}`)}),s&&n!==null&&r(Tr,{widgetId:"pipeline-orchestrator/pipeline-quick-stats",host:"device-tab",deviceId:n}),p&&r(R0,{history:f.history,latestIsFresh:m}),s&&n!==null&&r(Tr,{widgetId:"stream-broker/stream-broker-panel",host:"device-tab",deviceId:n}),s&&d.length>0&&u("div",{className:"@container rounded-lg border border-border bg-surface overflow-hidden",style:{containerType:"inline-size"},children:[r("div",{className:"border-b border-border px-4 py-2",children:r("h2",{className:"text-xs font-semibold text-foreground uppercase tracking-wider",children:"Stream Network"})}),r("div",{className:"divide-y divide-border",children:d.map(([h,g])=>u("div",{className:"px-4 py-2.5",children:[u("div",{className:"flex items-center gap-2 mb-2",children:[r(Or,{className:"h-3 w-3 text-foreground-subtle"}),r("span",{className:"text-[11px] font-medium text-foreground",children:h})]}),u("div",{className:"grid grid-cols-2 @[640px]:grid-cols-4 gap-2",children:[r(Ds,{label:"Nominal",value:pl(g.nominalBitrateKbps??0)}),r(Ds,{label:"Observed",value:pl(g.observedBitrateKbps??0)}),r(Ds,{label:"Peak",value:pl(g.peakBitrateKbps??0)}),r(Ds,{label:"Packet Loss",value:`${(g.packetLossPercent??0).toFixed(2)}%`,warning:(g.packetLossPercent??0)>1})]})]},h))})]}),r(Rz,{})]})}function Ds({label:e,value:t,warning:n}){return u("div",{children:[r("p",{className:"text-[10px] text-foreground-subtle",children:e}),r("p",{className:`text-xs font-medium ${n?"text-warning":"text-foreground"}`,children:t})]})}function zz({schema:e,values:t,pendingKeys:n,onChange:o,onAction:s,onSave:a,onDiscard:i,disabled:l}){const c=e.tabs??[],d=q(()=>{const k=new Map;for(const C of e.sections){const D=C.tab??"general",M=k.get(D)??[];M.push(C),k.set(D,M)}return k},[e.sections]),p=new Set(c.map(k=>k.id)),f=[...c,...[...d.keys()].filter(k=>!p.has(k)).map(k=>({id:k,label:k,icon:"wrench",order:100}))],m=f[0]?.id??"general",[h,g]=I(m),x=d.get(h)??[],y={sections:x.length<=1?x.length===1?[{...x[0],title:""}]:x:x.every(C=>!C.title)?[{...x[0],title:"",fields:x.flatMap(C=>C.fields)}]:x},w=r(Xv,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>i(n),saving:l});if(f.length<=1)return u("div",{className:"flex flex-col gap-3",children:[r(On,{schema:e,values:t,onChange:o,onAction:s,disabled:l}),w]});const v=new Map,N=new Map;for(const[k,C]of d){v.set(k,C.length);const D=new Set,M=$=>{for(const E of $)if("key"in E&&typeof E.key=="string"&&D.add(E.key),E.type==="group")M(E.fields);else if(E.type==="sub-tabs")for(const R of E.tabs)M(R.fields)};for(const $ of C)M($.fields);const _=n.filter($=>D.has($)).length;_>0&&N.set(k,_)}return u("div",{className:"flex flex-col gap-3",children:[r(Jv,{tabs:f.map(k=>({id:k.id,label:k.label})),activeId:h,onChange:g,countByTab:v,pendingByTab:N}),r(On,{schema:y,values:t,onChange:o,onAction:s,disabled:l}),w]})}function Fz(e,t){return t&&t==="admin"?e:!0}function jz(e){if(!e)return null;const n={sections:[...e.sections].sort((o,s)=>{const a=o.tab??"general",i=s.tab??"general";return a!==i?a.localeCompare(i):Fo(o)&&Fo(s)?o.id.localeCompare(s.id):(o.order??0)-(s.order??0)})};return e.tabs?{...n,tabs:e.tabs}:n}function n1(e){return e.type==="separator"||e.type==="info"||e.type==="button"||e.type==="widget"||e.type==="addon-action-button"}function r1(e){return e.key}function Hz(e){if(!n1(e))return e.value}function o1(e){return n1(e)?null:e}function wa(e,t){for(const n of e)if(t(n),n.type==="group")wa(n.fields,t);else if(n.type==="sub-tabs")for(const o of n.tabs)wa(o.fields,t)}function Vz(e){if(!e)return{};const t={};for(const n of e.sections)wa(n.fields,o=>{const s=r1(o);s!==null&&(t[s]=Hz(o))});return t}function _f(e,t){if(!e)return null;let n=null;for(const o of e.sections)if(wa(o.fields,s=>{if(n!==null||r1(s)!==t)return;const a=o1(s);a&&a.writerCapName&&a.writerAddonId&&(n={capName:a.writerCapName,addonId:a.writerAddonId})}),n!==null)break;return n}function Uz(e){return{...e,fields:e.fields.map(s1)}}function s1(e){return e.type==="separator"||e.type==="info"||e.type==="button"||e.type==="object-array"?e:{...e,readonlyField:!0}}function qz(e,t){return e&&{...e,sections:e.sections.map(n=>({...n,fields:n.fields.map(o=>{const s=o1(o);return s?Fz(t,s.minRole)?o:s1(o):o})}))}}function pc({deviceId:e,sectionFilter:t}){const n=Me(),{user:o}=sn(),s=o?.isAdmin===!0,a=ne(!1),{data:i,isLoading:l}=Nd({deviceId:e},{refetchInterval:()=>a.current?!1:2500,staleTime:6e4,enabled:Number.isFinite(e)}),{data:c}=Lr({deviceId:e},{staleTime:6e4,enabled:Number.isFinite(e)}),d=i?.settings??null,p=i?.live??null,f=q(()=>{if(!d&&!p)return null;const R=d?.sections??[],O=(p?.sections??[]).map(Uz),A=[...R,...O],P=t?A.filter(t):A.filter(T=>T.location!=="top-tab"&&!Fo(T));if(P.length===0)return null;const L=new Set;for(const T of P)L.add(T.tab??"general");const z=[...d?.tabs??[],...(p?.tabs??[]).filter(T=>!(d?.tabs??[]).some(F=>F.id===T.id))].filter(T=>L.has(T.id));return z.length>0?{tabs:z,sections:P}:{sections:P}},[d,p,t]),m=q(()=>jz(f),[f]),h=q(()=>qz(m,s),[m,s]),g=q(()=>Vz(h),[h]),x=$y(),b=Sd(),y=sx({onSuccess:()=>{n.invalidateQueries({queryKey:[["deviceManager","getDeviceAggregate"]]})}}),w={isPending:y.isPending,mutate:R=>{y.mutate({deviceId:e,changes:[...R]})}},v=U(R=>{const O=Object.entries(R).map(([A,P])=>{const L=_f(h,A);return L?{writerCapName:L.capName,writerAddonId:L.addonId,key:A,value:P}:null}).filter(A=>A!==null);O.length>0&&w.mutate(O)},[h,w]),N=U(R=>{const O=Object.entries(R).map(([A,P])=>{const L=_f(h,A);return L?{writerCapName:L.capName,writerAddonId:L.addonId,key:A,value:P}:null}).filter(A=>A!==null);O.length>0&&w.mutate(O)},[h,w]),k=e1({schema:h,serverValues:g,onImmediateSave:v,onDeferredSave:N}),{values:C,pendingKeys:D,handleChange:M,handleSave:_,handleDiscard:$}=k;if(a.current=k.editingPaused,l)return u("div",{className:"flex items-center justify-center py-12 text-foreground-subtle",children:[r(Ee,{className:"h-4 w-4 animate-spin mr-2"}),r("span",{className:"text-xs",children:"Loading device aggregate…"})]});if(!h||h.sections.length===0)return r("div",{className:"text-xs text-foreground-subtle italic py-4 text-center",children:"No aggregate contributions for this device."});async function E(R,O,A){if(R==="regenerate-rtsp-token"){const P=["rtspUrl:","regenerateToken:"].find(z=>O.startsWith(z));if(!P)throw new Error(`regenerate-rtsp-token: unrecognised key "${O}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);const L=O.slice(P.length);if(!L)throw new Error(`regenerate-rtsp-token: key "${O}" has no streamId after prefix`);const B=`${e}/${L}`;await x.mutateAsync({brokerId:B}),n.invalidateQueries({queryKey:[["deviceManager","getDeviceAggregate"]]});return}if(R==="test-probe"){if(!c)return{status:"error",error:"Device metadata not loaded yet"};try{return await b.mutateAsync({addonId:c.addonId,type:c.type,key:O,value:A})}catch(P){return{status:"error",error:P instanceof Error?P.message:String(P)}}}if(R==="refresh-driver-data"){await y.mutateAsync({deviceId:e,changes:[{writerCapName:"device-manager",writerAddonId:"device-manager",key:O,value:Date.now()}]});return}throw new Error(`[device-aggregate] unknown action "${R}"`)}return r(zz,{schema:h,values:C,pendingKeys:D,onChange:M,onAction:E,onSave:_,onDiscard:$,disabled:w.isPending})}function Qz({deviceId:e}){return r("div",{className:"flex flex-col gap-3",children:r(pc,{deviceId:e})})}const a1=6e4,fc=60*a1,$f=24*fc;function di(e){if(e==null||e<=0)return"—";const t=Date.now()-e;return t<0||t<3e4?"just now":t<fc?`${String(Math.floor(t/a1))}m ago`:t<$f?`${String(Math.floor(t/fc))}h ago`:`${String(Math.floor(t/$f))}d ago`}function Gz(e,t=new Date){const n=new Date(e);return n.getFullYear()===t.getFullYear()&&n.getMonth()===t.getMonth()&&n.getDate()===t.getDate()}function i1({dev:e,busy:t,setBusy:n}){const o=e?.motionTrigger,s=hn(e?.state.motionTrigger),[a,i]=I(!1);if(!o)return null;const l=s?.enabled===!0,c=s!==void 0,d=async()=>{if(t||!c)return;const f=!l;n(!0),i(!0);try{await o.setMotionTrigger({enabled:f})}finally{n(!1),i(!1)}};return u("button",{type:"button",onClick:()=>{d()},disabled:t||!c,title:c?l?"Disable trigger on motion":"Enable trigger on motion":"Awaiting state…","aria-pressed":l,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${l?"border-primary/50 bg-primary/15 text-primary":"border-border bg-surface text-foreground-subtle hover:text-foreground"}`,children:[r(Ja,{className:"h-3 w-3"}),r("span",{children:a?l?"Disabling…":"Enabling…":c?l?"On motion: on":"On motion: off":"On motion: …"})]})}function l1({deviceId:e,deviceName:t,useSiren:n=!1}){const o=De(),s=wt(o.trpcClient,e),a=hn(s?.state.switch),[i,l]=I(!1),c=a?.on??!1,d=a?.lastChangedAt??null,p=a!==void 0,f=n?rs:kv,m=async()=>{if(!(i||!p||!s?.switch)){l(!0);try{await s.switch.setState({on:!c})}finally{l(!1)}}};return u("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 p-4",children:[r("button",{type:"button",onClick:()=>{m()},disabled:i||!p||!s?.switch,title:p?c?`Turn off ${t}`:`Turn on ${t}`:"Awaiting state…","aria-pressed":c,className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all disabled:cursor-not-allowed disabled:opacity-50 ${c?"border-success bg-success/20 text-success shadow-lg shadow-success/20":"border-border bg-surface text-foreground-subtle hover:border-foreground-subtle hover:text-foreground"}`,children:r(f,{className:"h-10 w-10"})}),r(i1,{dev:s,busy:i,setBusy:l}),u("div",{className:"text-center",children:[r("div",{className:`text-sm font-semibold ${c?"text-success":"text-foreground-subtle"}`,children:p?c?"On":"Off":"Unknown"}),r("div",{className:"text-[10px] text-foreground-subtle mt-0.5",children:p?`Changed ${di(d)}`:"Awaiting state…"})]})]})}function Wz({deviceId:e,deviceName:t}){const n=De(),o=wt(n.trpcClient,e),s=hn(o?.state.switch),a=hn(o?.state.brightness),i=s?.on??!1,l=s?.lastChangedAt??null,c=s!==void 0,d=a!==void 0,p=o?.brightness!==void 0,[f,m]=I(!1),[h,g]=I(a?.percentage??0);J(()=>{a?.percentage!==void 0&&g(a.percentage)},[a?.percentage]);const x=async()=>{if(!(f||!c||!o?.switch)){m(!0);try{await o.switch.setState({on:!i})}finally{m(!1)}}},b=async()=>{if(!(f||!d||!o?.brightness)){m(!0);try{await o.brightness.setBrightness({percentage:h})}finally{m(!1)}}};return u("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 p-4",children:[r("button",{type:"button",onClick:()=>{x()},disabled:f||!c||!o?.switch,title:c?i?`Turn off ${t}`:`Turn on ${t}`:"Awaiting state…","aria-pressed":i,className:`flex h-20 w-20 items-center justify-center rounded-full border-2 transition-all disabled:cursor-not-allowed disabled:opacity-50 ${i?"border-warning bg-warning/20 text-warning shadow-lg shadow-warning/30":"border-border bg-surface text-foreground-subtle hover:border-foreground-subtle hover:text-foreground"}`,children:r(KO,{className:"h-9 w-9"})}),p?u("div",{className:"flex w-full max-w-xs flex-col items-center gap-1",children:[r("input",{type:"range",min:0,max:100,step:1,value:h,disabled:f||!i||!d,onChange:y=>g(Number(y.currentTarget.value)),onPointerUp:()=>{b()},onKeyUp:y=>{y.key==="Enter"&&b()},"aria-label":"Brightness",className:"w-full accent-warning disabled:cursor-not-allowed disabled:opacity-50"}),r("div",{className:"text-[10px] text-foreground-subtle tabular-nums",children:d?`${String(h)}%`:"Brightness unavailable"})]}):null,r(i1,{dev:o,busy:f,setBusy:m}),u("div",{className:"text-center",children:[r("div",{className:`text-sm font-semibold ${i?"text-warning":"text-foreground-subtle"}`,children:c?i?"On":"Off":"Unknown"}),r("div",{className:"text-[10px] text-foreground-subtle mt-0.5",children:c?`Changed ${di(l)}`:"Awaiting state…"})]})]})}function Kz({deviceId:e}){const t=De(),n=wt(t.trpcClient,e),o=hn(n?.state.motion),s=o?.detected??!1,a=o?.lastDetectedAt??null,i=o!==void 0;return u("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 p-4",children:[r("div",{className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${s?"border-danger bg-danger/20 text-danger shadow-lg shadow-danger/30 animate-pulse":"border-border bg-surface text-foreground-subtle"}`,"aria-live":"polite",title:s?"Motion detected":"Idle",children:s?r(M8,{className:"h-10 w-10"}):r(Ja,{className:"h-10 w-10"})}),u("div",{className:"text-center",children:[r("div",{className:`text-sm font-semibold ${s?"text-danger":"text-foreground-subtle"}`,children:i?s?"Triggered":"Idle":"Unknown"}),r("div",{className:"text-[10px] text-foreground-subtle mt-0.5",children:i?`Last trip ${di(a)}`:"Awaiting state…"})]})]})}function Yz({deviceId:e}){const t=De(),n=wt(t.trpcClient,e),o=hn(n?.state.doorbell),s=o?.lastPressedAt??null,a=o!==void 0,i=s!==null&&Date.now()-s<6e4,[l,c]=I(0),[d,p]=I(null);return J(()=>{s===null||s===d||(p(s),Gz(s)&&c(f=>f+1))},[s,d]),u("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 p-4",children:[r("div",{className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${i?"border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 animate-pulse":"border-border bg-surface text-foreground-subtle"}`,"aria-live":"polite",title:i?"Just pressed":"Idle",children:r(rs,{className:"h-10 w-10"})}),u("div",{className:"text-center",children:[r("div",{className:`text-sm font-semibold ${i?"text-primary":"text-foreground-subtle"}`,children:a?`Last press ${di(s)}`:"Unknown"}),r("div",{className:"text-[10px] text-foreground-subtle mt-0.5 tabular-nums",children:a?`${String(l)} ring${l===1?"":"s"} today`:"Awaiting state…"})]})]})}function Zz({deviceName:e,deviceType:t,provider:n,isOnline:o,features:s}){return u("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center",children:[r(yn,{type:n,size:"lg"}),u("div",{children:[r("div",{className:"text-sm font-semibold text-foreground",children:e}),r("div",{className:"text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5",children:t})]}),u("div",{className:"flex items-center gap-2 flex-wrap justify-center",children:[r(li,{status:o?"online":"offline"}),s.length>0&&r(ci,{capabilities:s})]}),r("div",{className:"text-[10px] text-foreground-subtle italic max-w-xs mt-1",children:"No live view for this device type. Use the Config tab or the shortcut row to interact."})]})}function Xz({deviceId:e}){const t=Me(),n=Vb({deviceId:e},{refetchInterval:1e4,retry:!1}),o=Ub({onSuccess:()=>{t.invalidateQueries({queryKey:[["deviceDiscovery","listDiscovered"]]}),t.invalidateQueries({queryKey:[["deviceDiscovery","getStatus"]]})}}),s=q(()=>Jz(n.data??[]),[n.data]);return u("div",{className:"flex h-full w-full flex-col gap-3 p-3 sm:p-4",children:[u("div",{className:"flex flex-wrap items-stretch gap-2 sm:gap-3",children:[r(fl,{label:"Discovered",value:s.total,icon:r(Tn,{className:"h-3.5 w-3.5"})}),r(fl,{label:"Adopted",value:s.adopted,accent:"success"}),r(fl,{label:"Available",value:s.available,accent:s.available>0?"primary":void 0}),u("button",{type:"button",onClick:()=>{o.mutateAsync({deviceId:e}).catch(()=>{})},disabled:o.isPending,className:"inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0",children:[o.isPending?r(Ee,{className:"h-3.5 w-3.5 animate-spin"}):r(ct,{className:"h-3.5 w-3.5"}),r("span",{className:"hidden sm:inline",children:"Discover"})]})]}),u("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2",children:[r(Ls,{icon:r(Or,{className:"h-3 w-3 text-emerald-500"}),label:`${s.online} online`}),r(Ls,{icon:r(yv,{className:"h-3 w-3 text-amber-500"}),label:`${s.sleeping} sleeping`}),r(Ls,{icon:r(Pv,{className:"h-3 w-3 text-destructive"}),label:`${s.offline} offline`}),s.unknown>0?r(Ls,{icon:r(gO,{className:"h-3 w-3 text-foreground-subtle"}),label:`${s.unknown} unknown`}):null]})]})}function Jz(e){const t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(const n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function fl({label:e,value:t,icon:n,accent:o}){return u("div",{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${o==="success"?"bg-emerald-500/10 border-emerald-500/30 text-emerald-500":o==="primary"?"bg-primary/10 border-primary/30 text-primary":"bg-surface-hover border-border text-foreground"}`,children:[u("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate",children:[n,r("span",{className:"truncate",children:e})]}),r("div",{className:"text-xl sm:text-2xl font-semibold tabular-nums leading-none",children:t})]})}function Ls({icon:e,label:t}){return u("span",{className:"inline-flex items-center gap-1",children:[e,r("span",{children:t})]})}const eF=e=>r(l1,{...e,useSiren:!0}),tF={[gt.Switch]:l1,[gt.Siren]:eF,[gt.Light]:Wz,[gt.Sensor]:Kz,[gt.Button]:Yz,[gt.Hub]:Xz};function nF(e){const t=tF[e.deviceType]??Zz;return r(t,{...e})}function du(e){if(e<60)return`${Math.round(e)}s`;const t=Math.floor(e/60),n=Math.round(e%60);if(t<60)return n>0?`${t}m ${n}s`:`${t}m`;const o=Math.floor(t/60),s=t%60;return s>0?`${o}h ${s}m`:`${o}h`}function Na(e){return new Date(e).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function ka(e){return e.toISOString().slice(0,10)}function rF(e,t){return ka(e)===ka(t)}function vo(e){const t=new Date(e);return t.setHours(0,0,0,0),t}function oF(e){const t=new Date(e);return t.setHours(23,59,59,999),t}function Dt({className:e=""}){return r("div",{className:`animate-pulse rounded bg-foreground-subtle/10 ${e}`})}function Qn(){return u("div",{className:"flex items-center gap-3 px-4 py-3",children:[r(Dt,{className:"h-4 w-4"}),r(Dt,{className:"h-3 w-24"}),r(Dt,{className:"h-3 w-16 ml-auto"})]})}function ho({children:e,actions:t}){return u("div",{className:"border-b border-border px-4 py-2.5 flex items-center justify-between",children:[r("h2",{className:"text-xs font-semibold text-foreground uppercase tracking-wider",children:e}),t]})}function Df({icon:e,label:t,value:n}){return u("div",{className:"flex items-center gap-2",children:[r(e,{className:"h-3.5 w-3.5 text-foreground-subtle flex-shrink-0"}),u("div",{className:"min-w-0",children:[r("p",{className:"text-[10px] text-foreground-subtle leading-tight",children:t}),r("p",{className:"text-xs font-medium text-foreground leading-tight",children:n})]})]})}function sF({segments:e,selectedDate:t}){const n=vo(t).getTime(),o=1440*60*1e3,s=Array.from({length:25},(a,i)=>i);return u("div",{className:"space-y-1",children:[r("div",{className:"flex justify-between px-0.5",children:s.filter(a=>a%3===0).map(a=>r("span",{className:"text-[9px] text-foreground-subtle font-mono",children:String(a).padStart(2,"0")},a))}),u("div",{className:"relative h-6 rounded bg-background border border-border overflow-hidden",children:[e.map(a=>{const i=new Date(a.startTime).getTime()-n,l=new Date(a.endTime).getTime()-n,c=Math.max(0,i/o*100),d=Math.min(100-c,(l-i)/o*100);return d<=0?null:r("div",{className:"absolute top-0 bottom-0 bg-primary/60 hover:bg-primary/80 transition-colors",style:{left:`${c}%`,width:`${Math.max(d,.3)}%`},title:`${Na(a.startTime)} - ${Na(a.endTime)} (${du(a.duration)})`},a.id)}),s.slice(1,-1).map(a=>r("div",{className:"absolute top-0 bottom-0 w-px bg-border/50",style:{left:`${a/24*100}%`}},a))]})]})}function aF({segment:e,selected:t,onToggle:n,onPlay:o,onDownload:s,onDelete:a}){return u("div",{className:`flex items-center gap-3 px-4 py-2 border-b border-border last:border-b-0 hover:bg-background/50 transition-colors ${t?"bg-primary/5":""}`,children:[r("button",{onClick:n,className:"flex-shrink-0 text-foreground-subtle hover:text-foreground",children:t?r(Av,{className:"h-4 w-4 text-primary"}):r(os,{className:"h-4 w-4"})}),u("div",{className:"flex-1 min-w-0",children:[u("p",{className:"text-xs font-mono text-foreground",children:[Na(e.startTime)," - ",Na(e.endTime)]}),u("p",{className:"text-[10px] text-foreground-subtle",children:[du(e.duration),e.sizeBytes!=null&&` · ${Pt(e.sizeBytes)}`]})]}),u("div",{className:"flex items-center gap-1 flex-shrink-0",children:[r("button",{onClick:o,title:"Play",className:"p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle hover:text-foreground transition-colors",children:r(oi,{className:"h-3.5 w-3.5"})}),r("button",{onClick:s,title:"Download",className:"p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle hover:text-foreground transition-colors",children:r(bn,{className:"h-3.5 w-3.5"})}),r("button",{onClick:a,title:"Delete",className:"p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger transition-colors",children:r(et,{className:"h-3.5 w-3.5"})})]})]})}function iF({deviceId:e}){const t=Me(),[n,o]=I(()=>vo(new Date)),[s,a]=I(new Set),i=Ey({deviceId:e},{refetchInterval:5e3}),l=Cy({deviceId:e}),c=l.data?.streams[0]?.streamId??"stream0",d=My({deviceId:e,streamId:c,startTime:vo(n).getTime(),endTime:oF(n).getTime()}),p=Ay({deviceId:e,streamId:c},{refetchInterval:3e4}),f=Iy({deviceId:e,dataCategory:"recording:main"}),m=U(()=>{t.invalidateQueries({queryKey:["recordingEngine","getPolicyStatus"]}),t.invalidateQueries({queryKey:["recordingEngine","getSegments"]}),t.invalidateQueries({queryKey:["recordingEngine","getStorageUsage"]})},[t]),h=ky({onSuccess:m}),g={isPending:h.isPending,error:h.error,mutate:()=>{const L=l.data,B=L?{mode:L.mode,streams:L.streams,enabled:!0,preBufferSec:L.preBufferSec,postBufferSec:L.postBufferSec,scheduleRules:L.scheduleRules}:{mode:"continuous",streams:[{streamId:c,mode:"always"}],enabled:!0,preBufferSec:10,postBufferSec:5};h.mutate({deviceId:e,policy:B})}},x=Sy({onSuccess:m}),b=i.data??void 0,y=l.data??void 0,w=d.data??[],v=p.data,N=f.data??void 0,k=(b?.enabled??!1)&&(b?.activeStreams??0)>0,C=g.isPending||x.isPending,D=rF(n,new Date),M=q(()=>[...w].sort((L,B)=>new Date(B.startTime).getTime()-new Date(L.startTime).getTime()),[w]),_=q(()=>w.reduce((L,B)=>L+(B.duration??0),0),[w]),$=q(()=>w.reduce((L,B)=>L+(B.sizeBytes??0),0),[w]);function E(){k?x.mutate({deviceId:e}):g.mutate()}function R(){o(L=>{const B=new Date(L);return B.setDate(B.getDate()-1),vo(B)}),a(new Set)}function O(){D||(o(L=>{const B=new Date(L);return B.setDate(B.getDate()+1),vo(B)}),a(new Set))}function A(L){a(B=>{const z=new Set(B);return z.has(L)?z.delete(L):z.add(L),z})}function P(){s.size===M.length?a(new Set):a(new Set(M.map(L=>L.id)))}return i.isLoading&&l.isLoading?u("div",{className:"space-y-4",children:[u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r(ho,{children:"Recording Status"}),u("div",{className:"px-4 py-4 space-y-3",children:[r(Dt,{className:"h-10 w-full"}),r(Dt,{className:"h-4 w-48"})]})]}),u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r(ho,{children:"Segments"}),u("div",{className:"divide-y divide-border",children:[r(Qn,{}),r(Qn,{}),r(Qn,{})]})]})]}):u("div",{className:"space-y-4",children:[u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r(ho,{children:"Recording Status"}),u("div",{className:"px-4 py-4 flex items-center justify-between gap-4",children:[u("div",{className:"flex items-center gap-3 min-w-0",children:[r("div",{className:`flex items-center justify-center rounded-full p-2 flex-shrink-0 ${k?"bg-danger/10":"bg-foreground-subtle/10"}`,children:r(uv,{className:`h-5 w-5 ${k?"text-danger animate-pulse":"text-foreground-subtle"}`})}),u("div",{className:"min-w-0",children:[r("p",{className:`text-sm font-medium ${k?"text-danger":"text-foreground-subtle"}`,children:k?"Recording":"Not Recording"}),r("p",{className:"text-[11px] text-foreground-subtle mt-0.5 truncate",children:k&&b?`${b.mode} – ${b.activeStreams} stream(s)`:"No active recording session"})]})]}),r("button",{onClick:E,disabled:C,className:`inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors flex-shrink-0 disabled:opacity-50 ${k?"bg-danger/10 text-danger hover:bg-danger/20":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:k?u(me,{children:[r(os,{className:"h-3.5 w-3.5"}),C?"Stopping...":"Stop Recording"]}):u(me,{children:[r(oi,{className:"h-3.5 w-3.5"}),C?"Starting...":"Start Recording"]})})]}),k&&b&&u("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-[11px] text-foreground-subtle",children:[r(Mo,{className:"h-3.5 w-3.5 text-primary flex-shrink-0"}),u("span",{children:[b.activeStreams," active stream",b.activeStreams!==1?"s":""," · mode: ",b.mode]})]})]}),u("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r(ho,{children:u("span",{className:"flex items-center gap-1.5",children:[r(tn,{className:"h-3.5 w-3.5"}),"Settings"]})}),l.isLoading?u("div",{className:"px-4 py-3 space-y-2",children:[r(Dt,{className:"h-3 w-32"}),r(Dt,{className:"h-3 w-40"}),r(Dt,{className:"h-3 w-28"})]}):u("div",{className:"divide-y divide-border",children:[r(go,{label:"Stream",value:c}),r(go,{label:"Pre-buffer",value:y?`${y.preBufferSec}s`:"N/A"}),r(go,{label:"Mode",value:y?.mode??"continuous"}),r(go,{label:"Retention",value:N?.retentionDays!=null?`${N.retentionDays} days`:"N/A"}),N?.retentionGb!=null&&r(go,{label:"Max Storage",value:`${N.retentionGb} GB`})]})]}),u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r(ho,{children:u("span",{className:"flex items-center gap-1.5",children:[r(ga,{className:"h-3.5 w-3.5"}),"Storage"]})}),p.isLoading?u("div",{className:"px-4 py-3 space-y-2",children:[r(Dt,{className:"h-3 w-28"}),r(Dt,{className:"h-3 w-36"}),r(Dt,{className:"h-3 w-24"})]}):p.error?u("div",{className:"px-4 py-4 flex items-center gap-2 text-xs text-danger",children:[r(pt,{className:"h-4 w-4"}),"Failed to load storage info"]}):u("div",{className:"px-4 py-3 grid grid-cols-2 gap-3",children:[r(Df,{icon:ga,label:"Total",value:v?.totalBytes!=null?Pt(v.totalBytes):"N/A"}),r(Df,{icon:Mo,label:"Segments",value:v?.segmentCount!=null?String(v.segmentCount):"N/A"})]})]})]}),u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"border-b border-border px-4 py-2.5 flex items-center justify-between",children:[r("h2",{className:"text-xs font-semibold text-foreground uppercase tracking-wider",children:"Segment Browser"}),u("div",{className:"flex items-center gap-2",children:[r("button",{onClick:R,className:"p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle hover:text-foreground transition-colors",children:r(au,{className:"h-4 w-4"})}),u("div",{className:"flex items-center gap-1.5 text-xs text-foreground font-medium",children:[r(cv,{className:"h-3.5 w-3.5 text-foreground-subtle"}),D?"Today":ka(n)]}),r("button",{onClick:O,disabled:D,className:"p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-30 disabled:cursor-not-allowed",children:r(on,{className:"h-4 w-4"})})]})]}),u("div",{className:"px-4 py-3 border-b border-border",children:[r(sF,{segments:w,selectedDate:n}),u("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-foreground-subtle",children:[u("span",{children:[w.length," segment",w.length!==1?"s":""]}),_>0&&u("span",{children:[du(_)," recorded"]}),$>0&&r("span",{children:Pt($)})]})]}),M.length>0&&u("div",{className:"border-b border-border px-4 py-2 flex items-center justify-between",children:[r("button",{onClick:P,className:"text-[11px] text-foreground-subtle hover:text-foreground transition-colors",children:s.size===M.length?"Deselect All":"Select All"}),s.size>0&&u("div",{className:"flex items-center gap-2",children:[u("span",{className:"text-[10px] text-foreground-subtle",children:[s.size," selected"]}),u("button",{className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-[10px] font-medium bg-foreground-subtle/10 text-foreground-subtle hover:text-foreground transition-colors",title:"Download selected",children:[r(bn,{className:"h-3 w-3"}),"Download"]}),u("button",{className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-[10px] font-medium bg-danger/10 text-danger hover:bg-danger/20 transition-colors",title:"Delete selected",children:[r(et,{className:"h-3 w-3"}),"Delete"]})]})]}),d.isLoading?u("div",{className:"divide-y divide-border",children:[r(Qn,{}),r(Qn,{}),r(Qn,{}),r(Qn,{})]}):M.length===0?u("div",{className:"flex flex-col items-center justify-center py-12 text-foreground-subtle",children:[r(Mo,{className:"h-8 w-8 mb-3 opacity-30"}),r("p",{className:"text-sm",children:"No recorded segments"}),r("p",{className:"text-xs mt-1 opacity-70",children:D?"Recorded clips will appear here as they are created":`No recordings found for ${ka(n)}`})]}):r("div",{className:"max-h-[400px] overflow-y-auto",children:M.map(L=>r(aF,{segment:L,selected:s.has(L.id),onToggle:()=>A(L.id),onPlay:()=>{},onDownload:()=>{},onDelete:()=>{}},L.id))})]}),i.error&&u("div",{className:"rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 flex items-center gap-2 text-xs text-danger",children:[r(pt,{className:"h-4 w-4 flex-shrink-0"}),"Failed to load recording status. Will retry automatically."]}),(g.error||x.error)&&u("div",{className:"rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 flex items-center gap-2 text-xs text-danger",children:[r(pt,{className:"h-4 w-4 flex-shrink-0"}),g.error?`Failed to start recording: ${g.error instanceof Error?g.error.message:"Unknown error"}`:`Failed to stop recording: ${x.error instanceof Error?x.error.message:"Unknown error"}`]})]})}function go({label:e,value:t}){return u("div",{className:"flex items-center justify-between px-4 py-2.5",children:[r("span",{className:"text-xs text-foreground-subtle",children:e}),r("span",{className:"text-xs font-medium text-foreground",children:t})]})}function lF({deviceId:e}){const t=Me(),n=Number.isFinite(e),{data:o}=Lr({deviceId:e},{enabled:n}),s=typeof o?.type=="string"?o.type:"camera";Zt(["deviceManager","getBindings"],["capability.binding-changed"]);const{data:a,isLoading:i,isError:l,error:c}=nx({deviceId:e},{staleTime:3e4,enabled:n}),{data:d}=ox({deviceType:s},{staleTime:3e4,enabled:!!s}),p=rx({onSuccess:()=>{t.invalidateQueries({queryKey:[["deviceManager","getBindings"]]})}});if(i)return r("div",{className:"p-4",children:r("div",{className:"h-20 rounded-lg border border-border bg-surface animate-pulse"})});if(l)return u("div",{className:"p-4 text-xs text-red-400",children:["Failed to load bindings: ",c instanceof Error?c.message:String(c)]});const f=new Map,m={};for(const b of d??[])m[b.capName]=b.wrappers;for(const b of a?.entries??[])f.set(b.capName,{...b,wrappers:m[b.capName]??[]});for(const b of d??[])f.has(b.capName)||f.set(b.capName,{capName:b.capName,kind:"unbound",providerAddonId:"",providerNodeId:"",nativeAddonId:"",wrappers:b.wrappers});const h=[...f.values()].sort((b,y)=>b.capName.localeCompare(y.capName));if(h.length===0)return u("div",{className:"flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle",children:[r(ei,{className:"h-8 w-8 opacity-40"}),r("p",{className:"text-xs",children:"No capability providers applicable to this device yet."}),r("p",{className:"text-[10px] opacity-60",children:"Native providers show up here as soon as the owning addon registers them."})]});const g=h.filter(b=>b.kind!=="unbound").length,x=[{key:"capability",header:"Capability",render:b=>r("span",{className:"font-mono text-foreground",children:b.capName})},{key:"kind",header:"Kind",render:b=>r(cF,{kind:b.kind})},{key:"provider",header:"Active Provider",render:b=>r("span",{className:"font-mono text-foreground-subtle",children:b.providerAddonId||r("span",{className:"opacity-40",children:"—"})})},{key:"node",header:"Node",render:b=>b.providerNodeId?r(dF,{nodeId:b.providerNodeId}):r("span",{className:"text-[10px] opacity-40",children:"—"})},{key:"native",header:"Native",render:b=>r("span",{className:"font-mono text-foreground-subtle",children:b.nativeAddonId||r("span",{className:"opacity-40",children:"—"})})},{key:"wrapper",header:"Wrapper",render:b=>{const y=b.kind==="wrapped"?b.providerAddonId:null;return r(uF,{wrappers:b.wrappers,activeWrapperId:y,disabled:p.isPending,onPick:w=>{const v=y===w;p.mutate({deviceId:e,capName:b.capName,wrapperAddonId:w,active:!v})}})}}];return u("div",{className:"flex flex-col gap-3 p-1",children:[u("div",{className:"text-[11px] text-foreground-subtle",children:[r("span",{className:"font-medium text-foreground",children:g})," ","of ",h.length," capabilit",h.length===1?"y":"ies"," bound — rows marked ",r("em",{children:"unbound"})," have a wrapper available you can activate."]}),r(Fa,{columns:x,rows:h,rowKey:b=>b.capName,minWidthPx:720})]})}function cF({kind:e}){return e==="native"?u("span",{className:"inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium",children:[r(Rn,{className:"h-3 w-3"}),"native"]}):e==="wrapped"?u("span",{className:"inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium",children:[r(QO,{className:"h-3 w-3"}),"wrapped"]}):u("span",{className:"inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium",children:[r(u8,{className:"h-3 w-3"}),"unbound"]})}function dF({nodeId:e}){return r("span",{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e==="hub"?"text-foreground-subtle":"text-foreground"}`,children:e})}function uF({wrappers:e,activeWrapperId:t,disabled:n,onPick:o}){return e.length===0?r("span",{className:"text-[10px] opacity-40",children:"none available"}):r("div",{className:"flex flex-wrap gap-1",children:e.map(s=>{const a=s===t;return u("button",{disabled:n,onClick:()=>o(s),title:a?"Click to deactivate (revert to native)":`Activate wrapper ${s}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${a?"border-primary/40 bg-primary/10 text-primary":"border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,children:[a?r(St,{className:"h-3 w-3"}):r(Sv,{className:"h-3 w-3"}),s]},s)})})}function pF(e,t){if(!e)return null;for(const n of e.slots)for(const o of n.addons)if(o.id===t)return o;return null}function fF(e,t,n){const o=e?.stepOverridesByAgent?.[t]?.[n];if(o)return o.enabled===!1?"off":(o.enabled===!0,"on");const s=e?.stepToggles?.[n];return s===!1?"off":s===!0?"on":"inherit"}function mF({agents:e,currentAgent:t,onPick:n}){const[o,s]=I(!1);return u("div",{className:"relative",children:[r("button",{type:"button",className:"px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted",onClick:()=>s(a=>!a),children:"Mirror from ▾"}),o&&r("div",{className:"absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10",children:e.filter(a=>a!==t).map(a=>r("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-muted",onClick:()=>{s(!1),n(a)},children:a},a))})]})}function hF({deviceId:e,refreshToken:t}){const n=Me(),[o,s]=I(null),[a,i]=I(null),[l,c]=I(null),[d,p]=I(null),f=Id({deviceId:e}),m=no(),h=Md({deviceId:e}),g=Jx(),x=q(()=>{const P=h.data?.agentNodeId;if(P)return P;const L=g.data?.find(B=>B.online)?.nodeId;return L||"hub"},[h.data?.agentNodeId,g.data]),b=a??x,y=es({nodeId:b??""},{enabled:!!b}),w=uy({onSuccess:()=>{n.invalidateQueries({queryKey:[["pipelineOrchestrator","getCameraSettings"]]}),c(null)}}),v=q(()=>y.data?ja(y.data):[],[y.data]),N=q(()=>{const P=f.data??null,L={};for(const B of m.data??[])for(const z of Object.keys(B.settings.addonDefaults)){const T=L[z]??[];T.push({agentNodeId:B.nodeId,state:fF(P,B.nodeId,z)}),L[z]=T}return L},[f.data,m.data]),k=o?pF(y.data??null,o):null,C=b?m.data?.find(P=>P.nodeId===b)??null:null,D=o&&C?C.settings.addonDefaults[o]??null:null,M=o&&b?f.data?.stepOverridesByAgent?.[b]?.[o]??null:null,_=y.data?.selectedEngine.format??"coreml",$=P=>{i(P),c(null),p(null)},E=P=>{s(P),c(null),p(null)},R=P=>{if(!b||!o||!y.data||!m.data)return;const L=m.data.find(T=>T.nodeId===P),B=m.data.find(T=>T.nodeId===b);if(!L||!B)return;const[z]=Bh({source:{nodeId:L.nodeId,engine:{format:_},defaults:L.settings.addonDefaults},target:{nodeId:B.nodeId,engine:{format:_},defaults:B.settings.addonDefaults},catalog:y.data,addonIds:[o]});if(!z){p("no mirror result");return}if(z.outcome==="skip"){p(`skipped: ${z.reason??"no candidate"}`);return}c(z.patch),p(`${z.outcome} from ${P}`)},O=()=>{!b||!o||w.mutate({deviceId:e,agentNodeId:b,addonId:o,patch:l})},A=()=>{!b||!o||w.mutate({deviceId:e,agentNodeId:b,addonId:o,patch:null})};return m.isLoading||y.isLoading?r("div",{className:"text-xs text-foreground-subtle animate-pulse p-4",children:"Loading pipeline…"}):y.data?r("div",{className:"@container h-full",style:{containerType:"inline-size"},children:u("div",{className:"flex flex-col @[720px]:flex-row h-full",children:[r("aside",{className:"w-full @[720px]:w-[300px] @[720px]:flex-shrink-0 border-b @[720px]:border-b-0 @[720px]:border-r border-border overflow-y-auto max-h-[40vh] @[720px]:max-h-none",children:r(_g,{tree:v,selectedAddonId:o,onSelect:E,agentDots:N})}),r("section",{className:"flex-1 min-w-0 p-4 overflow-y-auto",children:!o||!k?r("div",{className:"text-sm text-foreground-subtle",children:"Select a step on the left to configure it for this camera."}):u("div",{className:"space-y-4",children:[u("div",{children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Selected step"}),r("div",{className:"text-base font-semibold",children:k.name})]}),u("div",{className:"flex items-end gap-3 flex-wrap",children:[u("div",{children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle mb-1",children:"Agent"}),r("div",{className:"flex rounded border border-border overflow-hidden",children:(m.data??[]).map(P=>r("button",{type:"button",onClick:()=>$(P.nodeId),className:`px-3 py-1 text-xs ${b===P.nodeId?"bg-primary text-primary-foreground":"bg-surface hover:bg-muted"}`,children:P.nodeId},P.nodeId))})]}),r(mF,{agents:(m.data??[]).map(P=>P.nodeId),currentAgent:b,onPick:R}),d&&r("div",{className:"text-[10px] text-foreground-subtle",children:d})]}),D&&r(Va,{mode:"device",addon:k,agentDefault:D,agentNodeId:b??"",currentPatch:l??M,engineFormat:_,onChangePatch:c}),u("div",{className:"flex items-center justify-between gap-2 pt-4 border-t border-border",children:[r("button",{type:"button",className:"px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle",disabled:!M||w.isPending,onClick:A,children:"Clear override"}),u("div",{className:"flex items-center gap-2",children:[r("button",{type:"button",className:"px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted",onClick:()=>c(null),children:"Reset draft"}),r("button",{type:"button",className:"px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50",disabled:!b||!o||w.isPending,onClick:O,children:w.isPending?"Saving…":"Save"})]})]})]})})]})}):r("div",{className:"text-xs text-foreground-subtle p-4",children:"Catalog unavailable."})}const gF=[{id:"overview",label:"Overview",cameraOnly:!1},{id:"config",label:"Config",cameraOnly:!1},{id:"pipeline",label:"Pipeline",cameraOnly:!0},{id:"bindings",label:"Bindings",cameraOnly:!0},{id:"recording",label:"Recording",cameraOnly:!0}];function bF(e){const t=e===gt.Camera;return gF.filter(n=>t||!n.cameraOnly).map(({id:n,label:o})=>({id:n,label:o}))}const xF=[{id:"logs",icon:At,label:"Logs"},{id:"repl",icon:Ev,label:"REPL"},{id:"events",icon:rs,label:"Events"},{id:"state",icon:fv,label:"State"}];function yF(){const e=Zd(),t=Number(e.deviceId),n=Number.isFinite(t),o=at(),s=Me(),a=st(),i=De(),[l,c]=I("overview"),[d,p]=I("logs"),f="device-detail.left-col-width-px",[m,h]=I(()=>{if(typeof window>"u")return null;const W=window.localStorage.getItem(f),pe=W?Number(W):NaN;return Number.isFinite(pe)&&pe>0?pe:null}),g=ne(m);g.current=m;function x(W){W.preventDefault();const pe=W.clientX,oe=W.currentTarget.previousElementSibling?.getBoundingClientRect().width??m??0,fe=280,le=Math.max(fe+50,Math.floor(window.innerWidth*.7)),ke=ie=>{const ge=Math.max(fe,Math.min(le,oe+(ie.clientX-pe)));h(ge)},ye=()=>{document.removeEventListener("mousemove",ke),document.removeEventListener("mouseup",ye);const ie=g.current;if(ie!==null)try{window.localStorage.setItem(f,String(Math.round(ie)))}catch{}document.body.style.userSelect="",document.body.style.cursor=""};document.body.style.userSelect="none",document.body.style.cursor="col-resize",document.addEventListener("mousemove",ke),document.addEventListener("mouseup",ye)}const{data:b,isLoading:y,isError:w}=Lr({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:v}=Nd({deviceId:t},{enabled:n,staleTime:3e4}),N=q(()=>{const W=v?.settings?.sections??[],pe=v?.live?.sections??[],oe=[...W,...pe],fe=new Set;for(const ke of oe)ke.location==="top-tab"&&ke.tab&&fe.add(ke.tab);return oe.some(Fo)&&fe.add(dl),[...fe].map(ke=>{if(ke===dl)return{id:ke,label:gz,isAddonContrib:!0};const ye=Al[ke];return{id:ke,label:ye?.label??ke,isAddonContrib:!0}})},[v]),k=b,C=String(k?.name??e.deviceId??"Device"),D=k?.online===!0,M=D?"online":"offline",_=String(k?.addonId??"rtsp"),$=k?.features??[],E=k?.type,R=E===gt.Camera,O=typeof k?.parentDeviceId=="number"?k.parentDeviceId:null,{data:A}=Lr({deviceId:O??0},{enabled:O!==null,staleTime:3e4}),P=pr(),L=q(()=>{const W=new Set,pe=[];for(const oe of[...bF(E),...N])W.has(oe.id)||(W.add(oe.id),pe.push(oe));return pe},[E,N]),{data:B}=Wv(n?t:0),z=(B??[]).length>0,T=q(()=>xF.filter(({featureGate:W})=>!W||$.includes(W)),[$]),{data:F}=dx({addonId:_},{enabled:!!_&&_!=="rtsp"}),H=tx({onSuccess:()=>{s.invalidateQueries({queryKey:[["deviceManager"]]}),o(F?.id?`/integrations/${F.id}`:"/integrations")}}),j=Jb({onSuccess:()=>{s.invalidateQueries({queryKey:[["deviceManager"]]})}}),Q=ex({onSuccess:()=>{s.invalidateQueries({queryKey:[["deviceManager"]]})}}),G=Ny(),Z=Jo({onSuccess:()=>{s.invalidateQueries({queryKey:[["deviceManager"]]})}}),V=$.includes(Qs.Rebootable),K=$.includes(Qs.BatteryOperated),X=ld(i.trpcClient,K&&n?t:null),[te,he]=I(!1),xe=wt(i.trpcClient,n?t:null),ee=async()=>{if(!(te||!xe)){he(!0);try{await xe.snapshot?.invalidateCache({});const W=await xe.snapshot?.getSnapshot({});if(!W)return;const pe=`data:${W.contentType};base64,${W.base64}`,oe=W.contentType.includes("png")?"png":"jpg",fe=C.replace(/[^a-zA-Z0-9_.-]+/g,"_"),le=new Date().toISOString().replace(/[:.]/g,"-"),ke=document.createElement("a");ke.href=pe,ke.download=`${fe}-${le}.${oe}`,document.body.appendChild(ke),ke.click(),document.body.removeChild(ke)}finally{he(!1)}}},re=j.isPending||Q.isPending,{data:de}=Md({deviceId:t},{enabled:n,refetchInterval:1e4}),ue=de?.agentNodeId??null,Se=typeof ue=="string"&&ue.length>0&&!ue.startsWith("addon:")?ue:void 0,{data:Oe}=by({deviceId:t,...Se?{nodeId:Se}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:Be}=Db({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),He=Be?.level?.dbfs??null;function se(){if(!n)return null;switch(l){case"overview":return r(Bz,{device:k??{}});case"config":return r(Qz,{deviceId:t});case"pipeline":return r(hF,{deviceId:t,refreshToken:0});case"bindings":return r(lF,{deviceId:t});case"recording":return r(iF,{deviceId:t});default:{const W=l;return N.some(oe=>oe.id===W)?W===dl?r(pc,{deviceId:t,sectionFilter:Fo}):r(pc,{deviceId:t,sectionFilter:oe=>oe.location==="top-tab"&&oe.tab===W}):null}}}return n?y?u("div",{className:"flex flex-col h-full",children:[u("div",{className:"border-b border-border bg-surface px-6 py-4",children:[r("div",{className:"h-4 w-48 rounded bg-surface-hover animate-pulse mb-3"}),r("div",{className:"h-8 w-64 rounded bg-surface-hover animate-pulse"})]}),r("div",{className:"flex-1 p-6",children:r("div",{className:"h-40 rounded-lg border border-border bg-surface animate-pulse"})})]}):w||!b?u("div",{className:"flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle",children:[r("p",{className:"text-lg font-semibold text-foreground",children:"Device not found"}),u("p",{className:"text-xs",children:["No device with ID ",u("code",{className:"font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]",children:["#",t]})]}),r("button",{onClick:()=>o("/integrations"),className:"mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors",children:"Back to Integrations"})]}):u("div",{className:"absolute inset-0 flex flex-col overflow-hidden",children:[u("div",{className:"border-b border-border bg-surface px-6 py-3 flex-shrink-0",children:[r("div",{className:"mb-2",children:r(Jc,{items:[{label:"Integrations",onClick:()=>o("/integrations")},{label:F?.name??_,onClick:()=>F?.id&&o(`/integrations/${F.id}`)},{label:C}]})}),u("div",{className:"flex items-center gap-2 sm:gap-3",children:[r(yn,{type:_,size:"lg"}),u("div",{className:"min-w-0 flex-1",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[r("h1",{className:"text-sm sm:text-base font-semibold text-foreground truncate",children:C}),r(li,{status:M}),K&&r(dd,{status:X,variant:"full"})]}),O!==null&&A&&u("button",{type:"button",onClick:()=>o(`/devices/${O}`),className:"text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1",title:`Open parent device ${A.name}`,children:[r("span",{children:"↑"}),r("span",{className:"truncate",children:String(A.name??`Device #${O}`)})]}),r("div",{className:"hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle",children:$.length>0&&r(ci,{capabilities:$})})]}),Oe&&r("div",{className:"hidden lg:flex",children:r(vF,{metrics:Oe,dbfs:He})}),u("div",{className:"flex items-center gap-1 shrink-0",children:[u("button",{onClick:async()=>{await a({title:`Disable "${C}"?`,message:"The device will stop processing streams and events. You can re-enable it later.",confirmLabel:"Disable",variant:"danger"})&&Q.mutate({deviceId:t})},disabled:re,title:"Disable device",className:"inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 border-success/30 text-success hover:bg-success/10",children:[r(kv,{className:"h-3.5 w-3.5"}),r("span",{className:"hidden sm:inline",children:re?"Updating…":"Enabled"})]}),r("div",{className:"hidden sm:block h-5 w-px bg-border mx-1"}),r(O0,{triggerClassName:"ml-1",items:[{id:"snapshot",label:"Take snapshot",description:"Fetch a fresh frame and download it.",icon:Rr,disabled:te,onClick:()=>{ee()}},{id:"reboot",label:"Reboot device",description:"Camera goes offline for ~30 seconds.",icon:Yt,hidden:!V,disabled:G.isPending,danger:!0,onClick:async()=>{await a({title:`Reboot "${C}"?`,message:"The camera will go offline for around 30 seconds while the firmware reboots.",confirmLabel:"Reboot",variant:"danger"})&&G.mutate({deviceId:t})}},{id:"restart-addon",label:"Restart addon",description:`Bounces every device served by ${F?.name??_}.`,icon:ct,disabled:Z.isPending,danger:!0,onClick:async()=>{await a({title:`Restart "${F?.name??_}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${C}"). Streams will reconnect automatically.`,confirmLabel:"Restart",variant:"danger"})&&Z.mutate({addonId:_})}},{id:"delete",label:"Delete device",description:"Remove the device and all its settings.",icon:et,separatorBefore:!0,disabled:H.isPending,danger:!0,onClick:async()=>{await a({title:`Delete "${C}"?`,message:"This will remove the device and all its settings. This action cannot be undone.",confirmLabel:"Delete",variant:"danger"})&&H.mutate({deviceId:t})}}]})]})]})]}),r(ab,{deviceId:t,device:k??void 0,children:r(t0,{children:r(z0,{children:u("main",{className:P?"flex-1 overflow-y-auto flex flex-col":"flex-1 min-h-0 overflow-hidden flex flex-row",children:[u("div",{className:P?"flex flex-col bg-surface":`${m===null?"w-1/2 lg:w-1/3":""} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!P&&m!==null?{width:`${String(m)}px`}:void 0,children:[r("div",{className:`flex-shrink-0 border-b border-border-subtle ${R?"bg-black":"bg-surface"}`,children:R?r(Mz,{deviceId:t,intercomAvailable:$.includes(Qs.TwoWayAudio)}):r(nF,{deviceId:t,deviceName:C,deviceType:E??"unknown",provider:_,isOnline:D,features:$})}),u("div",{className:P?"flex flex-col border-b border-border":"flex-1 min-h-0 flex flex-col overflow-hidden",children:[r("div",{className:"flex-shrink-0 border-b border-border-subtle px-2 py-1.5",children:r("div",{className:"flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5",children:T.map(({id:W,label:pe,icon:oe})=>u("button",{onClick:()=>p(W),title:pe,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${d===W?"bg-primary/15 text-primary":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,children:[r(oe,{className:"h-3 w-3"}),pe]},W))})}),u("div",{className:P?"h-72 overflow-hidden":"flex-1 min-h-0 overflow-hidden",children:[d==="logs"&&r(Az,{deviceId:t}),d==="repl"&&r(Ez,{deviceId:t}),d==="events"&&r(Iz,{deviceId:t}),d==="state"&&r(Pz,{deviceId:t})]})]})]}),!P&&r("div",{role:"separator","aria-orientation":"vertical",title:"Drag to resize",onMouseDown:x,className:"flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10",children:r("span",{className:"absolute inset-y-0 -left-1 -right-1"})}),u("div",{className:P?"flex flex-col":"flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden",children:[r("div",{className:"flex-shrink-0 border-b border-border bg-surface px-4",children:r("div",{className:"flex flex-wrap items-center gap-0",children:L.map(W=>{const pe=l===W.id;return u("button",{onClick:()=>c(W.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${pe?"text-primary":"text-foreground-subtle hover:text-foreground"}`,children:[W.label,pe&&r("span",{className:"absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary"})]},W.id)})})}),u("div",{className:P?"p-3 flex flex-col gap-3":"flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3",children:[l==="overview"&&z&&r(_z,{parentDeviceId:t}),se()]})]})]})})})})]}):u("div",{className:"flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle",children:[r("p",{className:"text-lg font-semibold text-foreground",children:"Invalid device id"}),u("p",{className:"text-xs",children:["The URL segment ",r("code",{className:"font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]",children:e.deviceId})," is not a number."]}),r("button",{onClick:()=>o("/integrations"),className:"mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors",children:"Back to Integrations"})]})}function vF({metrics:e,dbfs:t}){const n=e.phase??"idle",o=Gr(n);return u("div",{className:"flex items-center gap-3 flex-shrink-0",children:[u("div",{className:"flex items-center gap-1.5",children:[r("span",{className:`h-1.5 w-1.5 rounded-full ${o.dotClass}`}),r("span",{className:`text-[10px] font-medium ${o.textColor}`,children:o.label})]}),r("div",{className:"h-3 w-px bg-border"}),u("div",{className:"flex items-center gap-1 text-[10px] text-foreground-subtle",children:[r(Ja,{className:"h-3 w-3"}),r("span",{className:"text-foreground tabular-nums",children:(e.actualFps??0).toFixed(1)}),r("span",{children:"fps"})]}),u("div",{className:"flex items-center gap-1 text-[10px] text-foreground-subtle",children:[r(jt,{className:"h-3 w-3"}),r("span",{className:"text-foreground tabular-nums",children:(e.avgInferenceTimeMs??0).toFixed(0)}),r("span",{children:"ms"})]}),u("div",{className:"flex items-center gap-1 text-[10px] text-foreground-subtle",title:"Current audio level (dBFS)",children:[r(f7,{className:"h-3 w-3"}),r("span",{className:"text-foreground tabular-nums",children:t==null?"—":t.toFixed(0)}),r("span",{children:"dB"})]}),(e.queueDepth??0)>0&&u("span",{className:"text-[10px] text-warning tabular-nums",children:["q:",e.queueDepth]})]})}function wF({packageName:e,currentVersion:t,installSource:n,onInstall:o,onClose:s}){const a=n==="upload"||n==="local",{data:i,isLoading:l}=xb({name:e},{staleTime:5*6e4});return u("div",{className:"fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden",style:{top:"auto",bottom:"auto"},ref:c=>{if(!c)return;const d=c.parentElement?.getBoundingClientRect();if(!d)return;const p=window.innerHeight-d.bottom,f=d.top;p<280&&f>p?(c.style.bottom=`${window.innerHeight-d.top+4}px`,c.style.top="auto"):(c.style.top=`${d.bottom+4}px`,c.style.bottom="auto"),c.style.right=`${window.innerWidth-d.right}px`},onClick:c=>c.stopPropagation(),children:[u("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border",children:[r("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle font-medium",children:"Versions"}),r("button",{type:"button",onClick:s,className:"text-foreground-subtle hover:text-foreground",children:r(Ve,{className:"h-3 w-3"})})]}),a&&u("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]",children:[r(ai,{className:"h-3 w-3 mt-0.5 text-cyan-500 shrink-0"}),u("div",{className:"text-cyan-700 dark:text-cyan-200",children:[u("span",{className:"font-semibold",children:[n==="upload"?"Uploaded copy":"Local copy"," in place."]})," ","Re-install ",r("span",{className:"font-mono",children:t})," from npm to track upstream releases again."]})]}),l&&u("div",{className:"flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle",children:[r(Ee,{className:"h-3.5 w-3.5 animate-spin"}),"Loading versions..."]}),i&&r("div",{className:"max-h-64 overflow-auto divide-y divide-border",children:i.map(c=>{const d=c.version===t,p=/-(alpha|beta|rc|dev|canary|next)/i.test(c.version);return u("div",{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${d?"bg-primary/5":"hover:bg-surface-hover"} transition-colors`,children:[r("span",{className:`font-mono flex-1 ${d?"text-primary font-semibold":p?"text-amber-400":"text-foreground"}`,children:c.version}),c.distTags.map(f=>r("span",{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${f==="latest"?"bg-emerald-500/15 text-emerald-400":f==="beta"?"bg-amber-500/15 text-amber-400":"bg-gray-500/15 text-gray-400"}`,children:f},f)),c.deprecated&&r("span",{className:"text-[9px] text-red-400 line-through",children:"deprecated"}),r("span",{className:"text-[9px] text-foreground-subtle shrink-0",children:new Date(c.publishedAt).toLocaleDateString()}),d&&!a?r(St,{className:"h-3 w-3 text-primary shrink-0"}):r("button",{type:"button",onClick:()=>o(c.version),className:"shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors",title:d?`Re-install ${c.version} from npm`:`Install ${c.version}`,children:r(bn,{className:"h-3 w-3"})})]},c.version)})}),i&&i.length===0&&r("div",{className:"py-4 text-center text-[10px] text-foreground-subtle",children:"No versions found"})]})}const NF={queued:{icon:pv,bg:"bg-muted text-foreground-subtle",label:"queued"},updating:{icon:Ee,bg:"bg-primary/10 text-primary",label:"updating",spin:!0},"done-pending-restart":{icon:ct,bg:"bg-amber-500/10 text-amber-700",label:"pending restart"},done:{icon:St,bg:"bg-success/10 text-success",label:"done"},failed:{icon:vv,bg:"bg-danger/10 text-danger",label:"failed"}};function c1({item:e}){const t=NF[e.status],n=t.icon;return u("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[r(n,{className:`w-2.5 h-2.5 ${t.spin?"animate-spin":""}`}),t.label]})}const kF="device-export";function SF(e){return e.capabilities.some(t=>(typeof t=="string"?t:t.name)===kF)}function CF({isBundle:e,installSource:t,addonId:n,iconPath:o,color:s}){const[a,i]=I(!1),l=s?{backgroundColor:`${s.startsWith("#")?s:`#${s}`}26`}:void 0,c=e?"bg-indigo-500/20 text-indigo-700 dark:text-indigo-300":"bg-purple-500/20 text-purple-700 dark:text-purple-300",d=n&&o?`/api/addon-assets/${n}/${o}`:null,p=!!d&&!a;return u("div",{className:"relative flex-shrink-0",children:[r("div",{className:`h-9 w-9 rounded-lg flex items-center justify-center ${l?"":c}`,style:l,children:p?r("img",{src:d,alt:n,className:"h-5 w-5",onError:()=>i(!0)}):e?r(wv,{className:"h-4 w-4"}):r(ba,{className:"h-4 w-4"})}),t==="local"&&r("span",{className:"absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm",children:"DEV"}),t==="npm"&&r("span",{className:"absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm",children:r("svg",{viewBox:"0 0 780 250",className:"w-[11px] h-[11px]",children:r("path",{fill:"#fff",d:"M240 250h100V50h100v200h340V0H0v250z"})})}),t==="upload"&&r("span",{className:"absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm",children:r(ai,{className:"h-2.5 w-2.5 text-white"})})]})}function MF({addonId:e}){const t=Me(),{data:n="inherit"}=wb({addonId:e},{staleTime:3e4}),o=Nb({onSuccess:()=>{t.invalidateQueries({queryKey:[["addons","getAddonAutoUpdate"]]})}});return r("div",{className:"flex rounded-lg border border-border overflow-hidden text-[10px] font-medium",children:["inherit","off","latest","beta"].map(s=>r("button",{type:"button",onClick:a=>{a.stopPropagation(),o.mutate({addonId:e,channel:s})},disabled:o.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===s?s==="inherit"?"bg-gray-700/50 text-gray-700 dark:text-gray-300":s==="off"?"bg-gray-700 text-gray-700 dark:text-gray-300":s==="latest"?"bg-blue-500/20 text-blue-400":"bg-amber-500/20 text-amber-400":"bg-transparent text-foreground-subtle hover:bg-surface-hover"} ${s!=="inherit"?"border-l border-border":""}`,children:s},s))})}function mc({addon:e,agents:t=[],clusterStatus:n,hideVersion:o,availableUpdate:s,onUpdate:a,isUpdating:i,bundle:l,bulkItem:c,disabledByBulk:d}){const[p,f]=I(!1),[m,h]=I(!1),[g,x]=I(!1),[b,y]=I(!1),[w,v]=I(!1),[N,k]=I("logs"),C=Me(),D=De(),M=at(),_=st(),{manifest:$}=e,E=e.installedOn??[],R=!l&&!$.protected&&$.removable!==!1,O=!!l,A=l?.displayName??$.name,P=l?.packageName??$.packageName,L=l?.version??$.packageVersion??$.version,B=l?.installSource??e.installSource,z=l?l.bundle?.description??l.addons[0]?.manifest.description:$.description;!l&&($.components&&$.components.length>0||t.length>=2);const T=lb({onSuccess:()=>{C.invalidateQueries({queryKey:[["addons"]]}),C.invalidateQueries({queryKey:[["addonPages"]]}),C.invalidateQueries({queryKey:[["capabilities"]]})}}),F=Jo({onSuccess:()=>{C.invalidateQueries({queryKey:[["addons"]]})}}),H=hd({onSuccess:()=>{C.invalidateQueries({queryKey:[["addons"]]}),C.invalidateQueries({queryKey:[["addonPages"]]}),C.invalidateQueries({queryKey:[["capabilities"]]}),C.invalidateQueries({queryKey:[["integrations"]]})}}),j=yb({onSuccess:()=>{C.invalidateQueries({queryKey:[["addons"]]}),C.invalidateQueries({queryKey:[["alerts"]]})}}),Q=e.health,G=Q?.phase==="failed"&&!Q.inGracePeriod,Z=G&&Q?.nextRetryAt&&!Q.retrying;return u("div",{className:`rounded-lg border bg-surface overflow-hidden ${G?"border-red-500/50":"border-border"}`,children:[G&&Q&&u("div",{className:"bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5",children:[r(vv,{className:"h-4 w-4 text-danger shrink-0 mt-0.5"}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"text-xs font-semibold text-danger",children:["Failed to load (attempt #",Q.retryCount,")"]}),r("div",{className:"text-[11px] text-foreground mt-0.5 break-words font-mono",children:Q.lastError?.message??"Unknown error"}),Z&&Q.nextRetryAt&&u("div",{className:"text-[10px] text-foreground-subtle mt-1",children:["Auto-retry at ",new Date(Q.nextRetryAt).toLocaleTimeString()]})]}),u("button",{type:"button",disabled:j.isPending||Q.retrying,onClick:V=>{V.stopPropagation(),j.mutate({packageName:P})},className:"inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0",title:"Reset retry counter and force immediate reload",children:[r(ct,{className:`h-3 w-3 ${j.isPending||Q.retrying?"animate-spin":""}`}),"Retry now"]})]}),u("div",{className:"flex items-start gap-3 px-4 py-3",children:[r(CF,{isBundle:O||!!$.components&&$.components.length>1,installSource:B,addonId:O?l.addons[0]?.manifest.id:$.id,iconPath:O?l.bundle?.icon??l.addons[0]?.manifest.icon:$.icon,color:O?l.addons[0]?.manifest.color:$.color}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-sm font-semibold text-foreground truncate",children:A}),u("span",{className:"text-[10px] text-foreground-subtle font-mono shrink-0",children:["(",P,")"]}),O&&u("span",{className:"text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1",children:[r(wv,{className:"h-3 w-3"}),l.addons.length]}),c!=null&&r(c1,{item:c})]}),z&&r("p",{className:"text-[10px] text-foreground-subtle mt-0.5 line-clamp-1",children:z}),!O&&e.process&&u("div",{className:"flex items-center gap-1.5 mt-1",children:[r("span",{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode==="forked"?"bg-blue-500/15 text-blue-400":"bg-gray-500/15 text-gray-400"}`,children:e.process.mode==="forked"?"forked":"in-process"}),e.process.pid!=null&&u("span",{className:"text-[9px] font-mono text-foreground-subtle",children:["PID ",e.process.pid]}),r("span",{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state==="running"?"bg-emerald-500/15 text-emerald-400":e.process.state==="crashed"||e.process.state==="failed"?"bg-red-500/15 text-red-400":"bg-gray-500/15 text-gray-400"}`,children:e.process.state})]})]}),!o&&u("div",{className:"relative inline-flex items-center gap-1.5 shrink-0 pt-0.5",children:[i?u("span",{className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400",children:[r(Ee,{className:"h-3 w-3 animate-spin"}),"Updating to ",s,"…"]}):s&&a?u("button",{type:"button",onClick:V=>{V.stopPropagation(),a()},disabled:d,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-semibold border border-primary/40 bg-primary/10 text-primary hover:bg-primary/20 transition-colors animate-pulse disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to ${s}`,children:[r(bn,{className:"h-3 w-3"}),s]}):null,u("button",{type:"button",onClick:V=>{V.stopPropagation(),x(K=>!K)},disabled:d,className:["inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed",B==="local"?"border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20":s?"border-amber-500/30 bg-amber-500/10 text-amber-400 hover:bg-amber-500/20":"border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20"].join(" "),title:s?`Current ${L} — newer ${s} available`:"View all versions",children:[L,r(en,{className:"h-3 w-3 opacity-50"})]}),g&&r(wF,{packageName:P,currentVersion:L,...B?{installSource:B}:{},onInstall:V=>{x(!1),H.mutate({packageName:P,version:V})},onClose:()=>x(!1)})]})]}),!O&&u("div",{className:"flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20",children:[u("button",{type:"button",onClick:V=>{V.stopPropagation(),F.mutate({addonId:$.id})},disabled:F.isPending||d,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors",children:[r(ct,{className:`h-3 w-3 ${F.isPending?"animate-spin":""}`}),"Restart"]}),u("button",{type:"button",onClick:V=>{V.stopPropagation(),y(K=>!K)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${b?"border-primary/30 bg-primary/10 text-primary":"border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10"}`,children:[r(At,{className:"h-3 w-3"}),"Logs"]}),!O&&u("button",{type:"button",onClick:V=>{V.stopPropagation(),v(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${w?"border-primary/30 bg-primary/10 text-primary":"border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10"}`,children:[r(tn,{className:"h-3 w-3"}),"Settings"]}),r("div",{className:"flex-1"}),R&&u("button",{type:"button",onClick:async V=>{V.stopPropagation(),await _({title:`Uninstall ${$.name}?`,message:"This will remove the addon package and all its data. This action cannot be undone.",confirmLabel:"Uninstall",variant:"danger"})&&T.mutate({packageName:$.packageName})},disabled:T.isPending||d,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors",children:[r(et,{className:"h-3 w-3"}),T.isPending?"Removing...":"Uninstall"]})]}),n&&n.nodes.length>1&&!O&&u("div",{className:"border-t border-border px-4 py-2 bg-muted/10",children:[r("div",{className:"text-[10px] font-medium text-foreground-subtle mb-1.5",children:"Cluster Deployment"}),r("div",{className:"space-y-1",children:n.nodes.map(V=>u("div",{className:"flex items-center gap-2 text-[10px]",children:[r("div",{className:`h-1.5 w-1.5 rounded-full shrink-0 ${V.status==="offline"?"bg-muted-foreground/30":V.synced?"bg-success":"bg-amber-500"}`}),r("span",{className:"font-medium text-foreground min-w-[60px]",children:V.name}),r("span",{className:"font-mono text-foreground-subtle",children:V.version}),!V.synced&&V.status!=="offline"&&r("span",{className:"text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20",children:"outdated"}),V.status==="offline"&&r("span",{className:"text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground",children:"offline"}),V.synced&&V.status!=="offline"&&r("span",{className:"text-[9px] text-success",children:"synced"})]},V.nodeId))})]}),b&&!O&&u("div",{className:"border-t border-border",children:[u("div",{className:"flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50",children:[u("div",{className:"flex rounded border border-border overflow-hidden text-[9px]",children:[r("button",{type:"button",onClick:()=>k("logs"),className:`px-2 py-0.5 transition-colors ${N==="logs"?"bg-primary/10 text-primary":"text-foreground-subtle hover:bg-surface-hover"}`,children:"Logs"}),r("button",{type:"button",onClick:()=>k("events"),className:`px-2 py-0.5 border-l border-border transition-colors ${N==="events"?"bg-primary/10 text-primary":"text-foreground-subtle hover:bg-surface-hover"}`,children:"Events"})]}),r("div",{className:"flex-1"}),r("button",{type:"button",onClick:V=>{V.stopPropagation(),y(!1)},className:"text-foreground-subtle hover:text-foreground",children:r(Ve,{className:"h-3.5 w-3.5"})})]}),N==="logs"&&r(rn,{addonId:$.id,maxHeight:"max-h-64",showFilters:!1}),N==="events"&&r(hr,{addonId:$.id,category:"addon.*",maxHeight:"max-h-64"})]}),O&&u(me,{children:[r("button",{type:"button",onClick:()=>f(V=>!V),className:"w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors",children:p?r(dO,{className:"h-3.5 w-3.5 text-foreground-subtle"}):r(en,{className:"h-3.5 w-3.5 text-foreground-subtle"})}),p&&r("div",{className:"border-t border-border px-3 py-2 space-y-2",children:l.addons.map(V=>r(mc,{addon:V,agents:t,hideVersion:!0},V.manifest.id))})]}),w&&!O&&r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",onClick:()=>v(!1),children:u("div",{className:"w-full max-w-lg max-h-[80vh] rounded-xl border border-border bg-surface shadow-2xl flex flex-col overflow-hidden",onClick:V=>V.stopPropagation(),children:[u("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0",children:[u("div",{className:"flex items-center gap-2",children:[r(tn,{className:"h-4 w-4 text-primary"}),u("h2",{className:"text-sm font-semibold text-foreground",children:[A," Settings"]})]}),r("button",{onClick:()=>v(!1),className:"text-foreground-subtle hover:text-foreground transition-colors p-1 rounded",children:r(Ve,{className:"h-4 w-4"})})]}),u("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-4",children:[r(io,{nodeId:"hub",addonIds:[$.id],level:"global"}),SF($)&&u("div",{children:[r("div",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:"Device export"}),r(Vd,{addonId:$.id,trpc:D.trpcClient,onOpenDevice:V=>M(`/devices/${V}`)})]}),B==="npm"&&u("div",{children:[r("div",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:"Auto-Update"}),r(MF,{addonId:$.id})]}),$.components&&$.components.length>0&&u("div",{children:[u("div",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:["Components (",$.components.length,")"]}),r("div",{className:"flex flex-wrap gap-1",children:$.components.map(V=>r("span",{className:"text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono",children:V},V))})]}),t.length>=2&&u("div",{children:[r("div",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:"Installed on"}),u("div",{className:"flex items-center gap-1.5 flex-wrap",children:[E.length===0&&r("span",{className:"text-[10px] text-foreground-subtle",children:"Hub (local)"}),E.map(V=>r("span",{className:"rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle",children:V},V)),u("div",{className:"relative",children:[u("button",{type:"button",onClick:V=>{V.stopPropagation(),h(K=>!K)},className:"inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors",title:"Install on more agents",children:[r(It,{className:"h-3 w-3"}),"Add agent"]}),m&&u("div",{className:"absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden",children:[t.filter(V=>!V.isHub&&!E.includes(V.name)).map(V=>r("button",{type:"button",onClick:K=>{K.stopPropagation(),h(!1)},className:"w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors",children:V.name},V.id)),t.filter(V=>!V.isHub&&!E.includes(V.name)).length===0&&r("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle",children:"No available agents"})]})]})]})]})]}),r("div",{className:"flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0",children:r("button",{type:"button",onClick:()=>v(!1),className:"rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:"Close"})})]})})]})}function AF({addon:e,bulkItem:t,disabledByBulk:n,latestVersion:o,onUpdate:s,onRestart:a,onUninstall:i}){const{isSystem:l}=e,c=o!==null&&o!==e.currentVersion;return u("tr",{className:l?"bg-amber-500/5":"",children:[r("td",{className:"px-2 py-1.5",children:u("div",{className:"flex items-center gap-2",children:[l&&r(ri,{className:"w-3 h-3 text-amber-700","aria-label":"System package"}),r("span",{className:"font-mono text-xs",children:e.name}),l&&r("span",{className:"text-[9px] px-1 py-0.5 rounded bg-amber-500/15 text-amber-800 font-medium",children:"SYSTEM"})]})}),r("td",{className:"px-2 py-1.5",children:r("span",{className:"font-mono text-xs",children:e.currentVersion})}),r("td",{className:"px-2 py-1.5",children:r("span",{className:"font-mono text-xs",children:o??"—"})}),r("td",{className:"px-2 py-1.5",children:t!==null&&r(c1,{item:t})}),r("td",{className:"px-2 py-1.5",children:u("div",{className:"flex items-center gap-1",children:[c&&r("button",{type:"button",disabled:n,onClick:()=>s(o),className:"text-[10px] px-2 py-0.5 rounded bg-primary/10 text-primary hover:bg-primary/20 disabled:opacity-40",children:"Update"}),r("button",{type:"button",disabled:n,onClick:a,className:"text-[10px] px-2 py-0.5 rounded bg-muted text-muted-foreground hover:bg-muted/80 disabled:opacity-40",children:"Restart"}),!l&&r("button",{type:"button",disabled:n,onClick:i,className:"text-[10px] px-2 py-0.5 rounded bg-danger/10 text-danger hover:bg-danger/20 disabled:opacity-40",children:"Uninstall"})]})})]})}const EF=".tgz,.tar.gz,.zip";function IF({onUploadSuccess:e}){const[t,n]=I(!1),o=ne(null),s=U(async i=>{n(!0);const l=new FormData;l.append("file",i);const c=localStorage.getItem("camstack_admin_token")??"";try{(await(await fetch("/api/addons/upload",{method:"POST",headers:{Authorization:`Bearer ${c}`},body:l})).json()).success&&e()}finally{n(!1)}},[e]),a=U(i=>{const l=i.target.files?.[0];l&&s(l),i.target.value=""},[s]);return u(me,{children:[r("input",{ref:o,type:"file",accept:EF,onChange:a,className:"hidden"}),u("button",{type:"button",onClick:()=>o.current?.click(),disabled:t,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors",children:[t?r(Ee,{className:"w-3.5 h-3.5 animate-spin"}):r(ai,{className:"w-3.5 h-3.5"}),t?"Uploading...":"Upload"]})]})}const PF={regular:"Updating addons",system:"Updating system packages",restarting:"Restarting hub… (~10s)",finalizing:"Finalizing"};function _F({state:e,onCancel:t}){const n=e.total===0?0:Math.round(e.completed/e.total*100),o=e.phase!=="restarting"&&!e.cancelled&&e.completedAtMs===void 0;return u("div",{className:"sticky top-0 z-30 bg-surface border-b border-border px-3 py-2 space-y-1.5",children:[u("div",{className:"flex items-center gap-2 text-xs",children:[r(Ee,{className:"w-3.5 h-3.5 animate-spin text-primary"}),r("span",{className:"font-medium",children:PF[e.phase]}),r("span",{className:"text-foreground-subtle",children:"·"}),u("span",{className:"text-foreground-subtle",children:[e.completed,"/",e.total]}),e.current!==null&&u(me,{children:[r("span",{className:"text-foreground-subtle",children:"·"}),r("span",{className:"font-mono text-foreground-subtle truncate",children:e.current})]}),u("div",{className:"ml-auto flex items-center gap-2",children:[e.failed>0&&u("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-danger/10 text-danger",children:[e.failed," failed"]}),r("button",{type:"button",onClick:t,disabled:!o,className:"text-[10px] px-2 py-0.5 rounded border border-border hover:bg-surface-hover disabled:opacity-40",children:"Cancel"})]})]}),r("div",{className:"h-1 bg-muted rounded overflow-hidden",children:r("div",{className:"h-full bg-primary transition-[width] duration-200",style:{width:`${n}%`}})}),e.phase==="system"&&u("div",{className:"text-[10px] text-amber-700 flex items-center gap-1",children:[r(pt,{className:"w-3 h-3"}),"System phase: the hub will restart once at the end (~10s)."]})]})}function $F({pending:e,onCancel:t,onConfirm:n,isPending:o,error:s}){return r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",children:u("div",{className:"bg-surface border border-border rounded-md shadow-xl p-5 max-w-md w-full mx-4 space-y-3",children:[u("div",{className:"flex items-center gap-2",children:[r(pt,{className:"w-4 h-4 text-amber-700"}),r("h3",{className:"text-sm font-medium text-foreground",children:"Update system package?"})]}),u("div",{className:"space-y-2 text-[11px] text-foreground-subtle",children:[u("div",{children:[r("span",{className:"font-mono text-foreground",children:e.packageName}),r("span",{className:"mx-1",children:"·"}),u("span",{className:"font-mono",children:["v",e.fromVersion]}),r("span",{className:"mx-1",children:"→"}),u("span",{className:"font-mono text-amber-700",children:["v",e.toVersion]})]}),r("div",{className:"rounded border border-amber-500/30 bg-amber-500/10 p-2 text-amber-800",children:"The hub will restart immediately after the install. Any in-flight requests will be dropped. The reconnect typically takes ~10 seconds."}),s!==null&&r("div",{className:"rounded border border-danger/40 bg-danger/10 p-2 text-danger",children:s})]}),u("div",{className:"flex justify-end gap-2 pt-1",children:[r("button",{type:"button",onClick:t,disabled:o,className:"px-3 py-1.5 text-[11px] rounded bg-surface hover:bg-surface-hover border border-border disabled:opacity-50",children:"Cancel"}),u("button",{type:"button",onClick:n,disabled:o,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] rounded bg-amber-500/20 text-amber-800 hover:bg-amber-500/30 border border-amber-500/40 font-medium disabled:opacity-50",children:[o?r(Ee,{className:"w-3 h-3 animate-spin"}):r(bn,{className:"w-3 h-3"}),"Update & restart"]})]})]})})}function DF(e,t){const n=e??"hub-only";return n==="any-node"?!0:n==="hub-only"?t:!t}function LF(e){const t=e;if(!t?.manifest)return null;const n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??"0.0.0",capabilities:t.manifest.capabilities??[]},o=t.process,s=o?{pid:o.pid,mode:o.mode==="forked"?"forked":"in-process",state:o.state??"unknown"}:void 0,a=t.health,i=t.declaration?.execution,l=t.manifest.execution,c=i?.placement??l?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...s?{process:s}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function TF(e){const t=new Map,n=[];for(const s of e){const a=s.manifest.packageName;if(!a){n.push(s);continue}const i=t.get(a);if(i)i.addons.push(s);else{const l=s.manifest.bundle,c={packageName:a,displayName:l?.displayName??s.manifest.packageDisplayName??s.manifest.name,version:s.manifest.packageVersion,addons:[s],...s.installSource!==void 0?{installSource:s.installSource}:{},...l!==void 0?{bundle:l}:{}};t.set(a,c)}}const o=[];for(const s of t.values())s.bundle!==void 0||s.addons.length>=2?o.push({bundle:s,representative:s.addons[0]}):o.push(s.addons[0]);return o.push(...n),o}function cn(e){return"bundle"in e}function RF({addons:e,clusterStatus:t,selectedNode:n,onRefresh:o,isRefreshing:s}){const a=Me(),[i,l]=I(""),c=t2(i),[d,p]=I(!1),f=ne(null);J(()=>{if(!d)return;const se=W=>{f.current&&!f.current.contains(W.target)&&p(!1)};return document.addEventListener("mousedown",se),()=>document.removeEventListener("mousedown",se)},[d]);const{data:m}=gd({nodeId:n.id},{staleTime:5*6e4}),h=q(()=>{const se=new Map;for(const W of m??[])se.set(W.name,W.latestVersion);return se},[m]),[g,x]=I(null),[b,y]=I(null),w=Hl({onMutate:se=>{x(se.name),y(null)},onSuccess:(se,W)=>{x(null);const pe=se;if(pe&&pe.success===!1){y({name:W.name,message:pe.error??"Update failed (no error message returned by server)"});return}a.invalidateQueries({queryKey:[["addons"]]}),a.invalidateQueries({queryKey:[["addons","listUpdates"]]})},onError:(se,W)=>{x(null),y({name:W.name,message:se instanceof Error?se.message:String(se)})}}),{data:v}=vb(void 0,{staleTime:3e4}),N=kb({onSuccess:()=>{a.invalidateQueries({queryKey:[["addons","getAutoUpdateSettings"]]})}}),{data:k,isFetching:C}=db({query:c||void 0},{enabled:d,staleTime:6e4}),{data:D}=bb({nodeId:n.id},{staleTime:1/0}),[M,_]=I(null);ft("AddonsBulkUpdateProgress",se=>{se.data?.nodeId===n.id&&_(se.data)});const $=q(()=>M!==null?M:(D??[])[0]??null,[M,D]),E=$!==null&&$.completedAtMs===void 0,R=q(()=>$===null?new Map:new Map($.items.map(se=>[se.name,se])),[$]),O=hb(),A=gb(),{data:P}=bd(void 0,{staleTime:6e4}),L=P?.requestedAt,[B,z]=I(null),[T,F]=I(!1);J(()=>{if(P?.kind==="framework-bulk-update"&&P.requestedAt!==B){z(P.requestedAt),F(!0);const se=window.setTimeout(()=>F(!1),6e3);return()=>window.clearTimeout(se)}},[L,B,P]);const{data:H}=fb(void 0,{staleTime:6e4}),[j,Q]=I(null),[G,Z]=I(null),V=Hl({onSuccess:()=>{Q(null),a.invalidateQueries({queryKey:[["addons"]]})},onError:se=>{Z(se instanceof Error?se.message:String(se))}}),K=U(async()=>{const se=m??[];if(se.length===0)return;const W=se.map(pe=>({name:pe.name,version:pe.latestVersion,isSystem:pe.isSystem}));await O.mutateAsync({nodeId:n.id,items:W})},[m,n.id,O]),X=hd({onSuccess:()=>{a.invalidateQueries({queryKey:[["addons"]]}),a.invalidateQueries({queryKey:[["addonPages"]]}),a.invalidateQueries({queryKey:[["capabilities"]]}),a.invalidateQueries({queryKey:[["integrations"]]})}}),[te,he]=I("type"),[xe,ee]=I(()=>typeof window>"u"?"grouped":window.localStorage.getItem("camstack.addons.viewMode")==="flat"?"flat":"grouped"),re=se=>{ee(se),typeof window<"u"&&window.localStorage.setItem("camstack.addons.viewMode",se)},[de,ue]=Xa(),be=de.get("capability"),Se=q(()=>{let se=n.isHub?e:e.filter(W=>DF(W.placement,n.isHub));return be&&(se=se.filter(W=>(W.manifest.capabilities??[]).some(oe=>(typeof oe=="string"?oe:oe.name)===be))),se},[e,n.isHub,be]),Oe=()=>{const se=new URLSearchParams(de);se.delete("capability"),ue(se,{replace:!0})},Be=xe==="flat"?Se:TF(Se),He=q(()=>{const se=[...Be];switch(te){case"type":se.sort((W,pe)=>{const oe=cn(W)?0:1,fe=cn(pe)?0:1;if(oe!==fe)return oe-fe;const le=cn(W)?W.bundle.displayName:W.manifest.name,ke=cn(pe)?pe.bundle.displayName:pe.manifest.name;return le.localeCompare(ke)});break;case"name":se.sort((W,pe)=>{const oe=cn(W)?W.bundle.displayName:W.manifest.name,fe=cn(pe)?pe.bundle.displayName:pe.manifest.name;return oe.localeCompare(fe)});break;case"source":se.sort((W,pe)=>{const oe=cn(W)?W.bundle.installSource??"":W.installSource??"",fe=cn(pe)?pe.bundle.installSource??"":pe.installSource??"";return oe.localeCompare(fe)});break}return se},[Be,te]);return u("div",{className:"space-y-4",children:[b&&r("div",{className:"rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]",children:u("div",{className:"flex items-start justify-between gap-3",children:[u("div",{className:"space-y-0.5",children:[u("div",{className:"font-medium text-danger",children:["Failed to update ",b.name]}),r("div",{className:"text-foreground-subtle font-mono",children:b.message})]}),r("button",{type:"button",onClick:()=>y(null),className:"text-foreground-subtle hover:text-foreground text-[10px]",children:"dismiss"})]})}),u("div",{className:"flex items-center gap-2 flex-wrap",children:[u("div",{className:"flex items-center gap-1.5",children:[r("span",{className:"text-[10px] text-foreground-subtle",children:"Sort:"}),u("select",{value:te,onChange:se=>he(se.target.value),className:"rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground focus:outline-none focus:border-primary/50",children:[r("option",{value:"type",children:"Bundles first"}),r("option",{value:"name",children:"Name"}),r("option",{value:"source",children:"Install source"})]})]}),u("div",{className:"flex items-center gap-1.5",children:[r("span",{className:"text-[10px] text-foreground-subtle",children:"View:"}),r("div",{className:"flex rounded-md border border-border overflow-hidden text-[10px] font-medium",children:["grouped","flat"].map(se=>r("button",{type:"button",onClick:()=>re(se),className:`px-2.5 py-1.5 transition-colors capitalize ${xe===se?"bg-primary/10 text-primary":"bg-transparent text-foreground-subtle hover:bg-surface-hover"}`,title:se==="grouped"?"Group multi-addon packages into a bundle card":"Show every addon as its own card",children:se},se))})]}),n.isHub&&u("div",{className:"flex items-center gap-1.5",children:[r(ct,{className:"h-3 w-3 text-foreground-subtle"}),r("span",{className:"text-[10px] text-foreground-subtle",children:"Auto-Update:"}),r("div",{className:"flex rounded-md border border-border overflow-hidden text-[10px] font-medium",children:["off","latest","beta"].map(se=>r("button",{type:"button",onClick:()=>N.mutate({channel:se}),disabled:N.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${v?.channel===se?se==="off"?"bg-gray-700 text-gray-200":se==="latest"?"bg-blue-500/20 text-blue-400":"bg-amber-500/20 text-amber-400":"bg-transparent text-foreground-subtle hover:bg-surface-hover"} ${se!=="off"?"border-l border-border":""}`,children:se},se))})]}),(m?.length??0)>0&&u("button",{type:"button",onClick:()=>void K(),disabled:O.isPending||E,className:"flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium",children:[r(bn,{className:`w-3 h-3 ${O.isPending?"animate-bounce":""}`}),"Update All (",m.length,")"]}),u("button",{type:"button",onClick:o,disabled:s||E,className:"flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors",children:[r(ct,{className:`w-3 h-3 ${s?"animate-spin":""}`}),"Refresh"]})]}),u("div",{className:"flex items-center gap-3",children:[u("div",{className:"relative flex-1 min-w-[200px]",ref:f,children:[r(Cv,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle"}),r("input",{type:"text",value:i,onChange:se=>{l(se.target.value),p(!0)},onFocus:()=>p(!0),placeholder:"Search addons on npm...",disabled:E,className:"w-full rounded-lg border border-border bg-background pl-9 pr-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed"}),C&&r(Ee,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin"}),d&&k&&k.length>0&&u("div",{className:"absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden",children:[k.length>0&&u("div",{className:"px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border",children:["npm results (",k.length,")"]}),k&&k.length>0&&r("div",{className:"max-h-72 overflow-auto divide-y divide-border",children:k.map(se=>u("div",{className:"flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors",children:[r("div",{className:"w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0",children:se.name.replace("@camstack/addon-","").charAt(0).toUpperCase()}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-[11px] font-semibold truncate",children:se.name}),u("span",{className:"text-[10px] text-foreground-subtle",children:["v",se.version]})]}),se.description&&r("div",{className:"text-[10px] text-foreground-subtle truncate",children:se.description})]}),se.installed?u("span",{className:"inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md border border-emerald-500/30 bg-emerald-500/10 text-emerald-400 shrink-0",children:[r(St,{className:"h-3 w-3"}),se.installedVersion??"Installed"]}):u("button",{type:"button",onClick:()=>X.mutate({packageName:se.name}),disabled:X.isPending,className:"inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0",children:[X.isPending?r(Ee,{className:"h-3 w-3 animate-spin"}):r(bn,{className:"h-3 w-3"}),"Install"]})]},se.name))})]})]}),r(IF,{onUploadSuccess:()=>{a.invalidateQueries({queryKey:[["addons"]]}),o()}})]}),be&&u("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm",children:[r("span",{className:"text-foreground-subtle",children:"Filtering by capability:"}),r("span",{className:"font-mono text-primary font-semibold",children:be}),r("button",{type:"button",onClick:Oe,className:"ml-auto text-xs text-foreground-subtle hover:text-foreground underline",children:"Clear"})]}),$!==null&&r(_F,{state:$,onCancel:()=>A.mutate({id:$.id})}),T&&u("div",{className:"fixed top-4 right-4 z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto",children:[r(ti,{className:"w-4 h-4 shrink-0 mt-0.5 text-green-400"}),u("div",{children:[r("div",{className:"text-[11px] font-semibold text-foreground",children:"Bulk update completed"}),r("div",{className:"text-[10px] text-foreground-subtle mt-0.5",children:"System packages updated — hub restarted successfully."})]})]}),Se.length===0&&(H??[]).length===0&&r("div",{className:"text-xs text-foreground-subtle",children:e.length===0?"No addons installed":be?`No installed addons declare the "${be}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${n.name} (placement filter active)`}),r("div",{className:"space-y-2",children:He.map(se=>{if(cn(se)){const oe=se.bundle.packageName,fe=h.get(oe);return r(mc,{addon:se.representative,clusterStatus:t?.[se.representative.manifest.id],bundle:se.bundle,availableUpdate:fe,isUpdating:g===oe,onUpdate:fe?()=>w.mutate({name:oe,version:fe,nodeId:n.id}):void 0,bulkItem:R.get(oe)??null,disabledByBulk:E},oe)}const W=se.manifest.packageName,pe=h.get(W);return r(mc,{addon:se,clusterStatus:t?.[se.manifest.id],availableUpdate:pe,isUpdating:g===W,onUpdate:pe?()=>w.mutate({name:se.manifest.packageName,version:pe,nodeId:n.id}):void 0,bulkItem:R.get(W)??null,disabledByBulk:E},se.manifest.id)})}),n.isHub&&(H??[]).length>0&&r("div",{className:"rounded-md border border-border overflow-x-auto",children:u("table",{className:"w-full text-xs",children:[r("thead",{className:"bg-muted/40",children:u("tr",{className:"text-left text-foreground-subtle",children:[r("th",{className:"px-2 py-1.5 font-medium",children:"Name"}),r("th",{className:"px-2 py-1.5 font-medium",children:"Current"}),r("th",{className:"px-2 py-1.5 font-medium",children:"Latest"}),r("th",{className:"px-2 py-1.5 font-medium",children:"Status"}),r("th",{className:"px-2 py-1.5 font-medium",children:"Actions"})]})}),r("tbody",{children:(H??[]).map(se=>r(AF,{addon:{name:se.packageName,currentVersion:se.currentVersion,isSystem:!0},bulkItem:R.get(se.packageName)??null,disabledByBulk:E,latestVersion:se.latestVersion,onUpdate:W=>{Q({packageName:se.packageName,fromVersion:se.currentVersion,toVersion:W})},onRestart:()=>{},onUninstall:()=>{}},se.packageName))})]})}),j!==null&&r($F,{pending:j,onCancel:()=>{Q(null),Z(null)},onConfirm:()=>{Z(null),V.mutate({name:j.packageName,version:j.toVersion})},isPending:V.isPending,error:G})]})}function OF(){const e=Me(),{data:t,isLoading:n,isError:o}=Nn(),{data:s}=zx(void 0,{staleTime:15e3}),{data:a}=Hn(void 0,{staleTime:3e4,refetchInterval:1e4}),i=q(()=>{const b=new Map;b.set("hub",{id:"hub",name:"Hub",isHub:!0});for(const y of a??[]){const w=String(y.id??"");w&&b.set(w,{id:w,name:String(y.name??w),isHub:!!y.isHub})}return[...b.values()]},[a]),[l,c]=I("hub"),d=i.find(b=>b.id===l)??i[0],p=ub(),f=cb(),m=p.isPending||f.isPending,h=async()=>{await p.mutateAsync({nodeId:l}),await f.mutateAsync(),e.invalidateQueries({queryKey:[["addons"]]})},g=ne(p);g.current=p,J(()=>{g.current.mutate({nodeId:"hub"})},[]);const x=(t??[]).map(LF).filter(b=>b!==null);return u(ot,{children:[u("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[r(Lg,{selectedNodeId:l,onSelect:c}),u("div",{className:"flex items-center gap-3 flex-wrap",children:[!n&&!o&&u("span",{className:"text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium",children:[x.length," installed"]}),u("button",{type:"button",onClick:()=>void h(),disabled:m,className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors",title:"Re-fetch addons + check npm for new versions",children:[r(ct,{className:`w-3 h-3 ${m?"animate-spin":""}`}),"Check for updates"]})]})]}),!d.isHub&&u("div",{className:"rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle",children:["Showing only addons compatible with"," ",r("span",{className:"font-medium text-foreground",children:d.name})," ","— agents only run ",r("code",{className:"font-mono",children:"agent-only"})," and"," ",r("code",{className:"font-mono",children:"any-node"})," addons. Install / uninstall is hub-driven; agents auto-sync from the hub."]}),n&&r("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading…"}),o&&r("div",{className:"text-xs text-danger",children:"Failed to load addons"}),!n&&!o&&r(RF,{addons:x,clusterStatus:s,selectedNode:d,onRefresh:()=>void h(),isRefreshing:m})]})}function BF({value:e,size:t=192}){const[n,o]=I(null),[s,a]=I(null);if(J(()=>{let d=!1;return v2(()=>import("./browser-BXdiCFWD.js").then(p=>p.b),[]).then(async p=>{if(d)return;const f=p.create;if(typeof f!="function"){a("qrcode.create() unavailable in installed version");return}try{const m=f(e,{errorCorrectionLevel:"M"});d||o(m)}catch(m){d||a(m instanceof Error?m.message:"QR generation failed")}}).catch(()=>{d||a("qrcode library not installed")}),()=>{d=!0}},[e]),s)return r("div",{className:"flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4",style:{width:t,height:t},children:"QR rendering unavailable — use the secret below."});if(!n)return r("div",{className:"flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse",style:{width:t,height:t},children:"Generating…"});const i=n.modules.size,l=t/i,c=[];for(let d=0;d<i;d++)for(let p=0;p<i;p++)n.modules.data[d*i+p]&&c.push(r("rect",{x:p*l,y:d*l,width:l,height:l,fill:"currentColor"},`${p}-${d}`));return u("svg",{width:t,height:t,viewBox:`0 0 ${t} ${t}`,className:"text-black",children:[r("rect",{x:0,y:0,width:t,height:t,fill:"white"}),c]})}const zF={view:{icon:ni,cls:"bg-foreground-subtle/15 text-foreground-subtle"},create:{icon:ao,cls:"bg-primary/15 text-primary"},delete:{icon:et,cls:"bg-danger/15 text-danger"}};function FF(){const{user:e,logout:t}=sn();if(!e)return r(ot,{children:r("div",{className:"text-xs text-foreground-subtle",children:"Not signed in."})});const n=e.isAdmin,o=e.scopes??[];return u(ot,{children:[u("div",{className:"rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3",children:[r("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base",children:e.username.slice(0,1).toUpperCase()}),u("div",{className:"flex-1 min-w-0",children:[r("div",{className:"text-sm font-semibold text-foreground truncate",children:e.username}),u("div",{className:"text-[11px] text-foreground-subtle",children:[n?"Administrator":"User"," · session id ",u("span",{className:"font-mono",children:[e.id.slice(0,8),"…"]})]})]})]}),n&&u("div",{className:"rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5",children:[r(rr,{className:"h-4 w-4 text-primary mt-0.5 shrink-0"}),u("div",{children:[r("div",{className:"font-semibold text-foreground",children:"Unrestricted access"}),r("p",{className:"text-foreground-subtle mt-0.5",children:"Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below."})]})]}),r(jF,{}),r(HF,{username:e.username}),o.length>0&&u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"px-4 py-2 border-b border-border",children:[r("div",{className:"text-xs font-semibold text-foreground",children:"Granted scopes"}),r("div",{className:"text-[10px] text-foreground-subtle",children:"Baked into your session token at login; sign out + back in to refresh after changes."})]}),u("div",{className:"grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border",children:[r("div",{children:"Type"}),r("div",{children:"Target"}),r("div",{children:"Access"})]}),r("ul",{className:"divide-y divide-border",children:o.map((s,a)=>u("li",{className:"grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs",children:[r("span",{className:"font-mono text-foreground-subtle",children:s.type}),r("span",{className:"font-mono text-foreground",children:s.type==="device"?s.targets.join(", "):s.target}),r("div",{className:"flex items-center gap-1",children:["view","create","delete"].map(i=>{const l=s.access.includes(i),{icon:c,cls:d}=zF[i];return u("span",{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${l?d:"bg-transparent text-foreground-subtle/40 line-through"}`,title:l?`Can ${i}`:`Cannot ${i}`,children:[r(c,{className:"h-3 w-3"}),i]},i)})})]},a))})]}),r("div",{className:"flex justify-end",children:u("button",{onClick:t,className:"inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors",children:[r(lu,{className:"h-3 w-3"}),"Sign out"]})})]})}function jF(){const e=De(),[t,n]=I(""),[o,s]=I(""),[a,i]=I(""),[l,c]=I(null),d=Rt({mutationFn:h=>e.changeOwnPassword(h),onSuccess:()=>{c({kind:"success",msg:"Password updated."}),n(""),s(""),i("")},onError:h=>{c({kind:"error",msg:h instanceof Error?h.message:"Update failed"})}}),p=o.length>0&&a.length>0&&o!==a,f=o.length>0&&o.length<8,m=t.length>=1&&o.length>=8&&o===a;return u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"px-4 py-2.5 border-b border-border flex items-center gap-2",children:[r(hv,{className:"h-3.5 w-3.5 text-foreground-subtle"}),r("div",{className:"text-xs font-semibold text-foreground",children:"Change password"})]}),u("div",{className:"p-4 space-y-3",children:[r(ml,{label:"Current password",value:t,onChange:n,autoComplete:"current-password"}),r(ml,{label:"New password",value:o,onChange:s,autoComplete:"new-password",hint:"At least 8 characters."}),r(ml,{label:"Confirm new password",value:a,onChange:i,autoComplete:"new-password"}),(p||f)&&r("div",{className:"text-[11px] text-danger",children:p?"Passwords do not match.":"New password must be at least 8 characters."}),l&&u("div",{className:`text-[11px] flex items-center gap-1 ${l.kind==="success"?"text-emerald-500":"text-danger"}`,children:[l.kind==="success"?r(Zn,{className:"h-3 w-3"}):r(nr,{className:"h-3 w-3"}),l.msg]}),r("div",{className:"flex justify-end",children:u("button",{onClick:()=>{c(null),d.mutate({currentPassword:t,newPassword:o})},disabled:!m||d.isPending,className:"inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[d.isPending?r(Ee,{className:"h-3 w-3 animate-spin"}):r(ri,{className:"h-3 w-3"}),"Update password"]})})]})]})}function ml({label:e,value:t,onChange:n,autoComplete:o,hint:s}){return u("div",{className:"space-y-1",children:[r("label",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:e}),r("input",{type:"password",value:t,onChange:a=>n(a.target.value),autoComplete:o,className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary"}),s&&r("div",{className:"text-[10px] text-foreground-subtle",children:s})]})}function HF({username:e}){const t=De(),n=cr({queryKey:["auth","getOwnTotpStatus"],queryFn:()=>t.getOwnTotpStatus()}),o=n.data,[s,a]=I(null),[i,l]=I(""),[c,d]=I(null),[p,f]=I(!1),m=Rt({mutationFn:()=>t.setupOwnTotp(),onSuccess:y=>{a({secret:y.secret,otpauthUrl:y.otpauthUrl}),l(""),d(null)},onError:y=>d(y instanceof Error?y.message:"Setup failed")}),h=Rt({mutationFn:y=>t.confirmOwnTotp(y),onSuccess:()=>{a(null),l(""),d(null),n.refetch()},onError:y=>d(y instanceof Error?y.message:"Confirmation failed — code did not match")}),g=Rt({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{d(null),n.refetch()},onError:y=>d(y instanceof Error?y.message:"Disable failed")});J(()=>{if(!p)return;const y=setTimeout(()=>f(!1),1500);return()=>clearTimeout(y)},[p]);const x=q(()=>n.isLoading?"loading":s?"setup_in_progress":o?.enabled?"enrolled":"not_enrolled",[n.isLoading,o?.enabled,s]),b=()=>{s&&navigator.clipboard.writeText(s.secret).then(()=>f(!0))};return u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"px-4 py-2.5 border-b border-border flex items-center gap-2",children:[r($n,{className:"h-3.5 w-3.5 text-foreground-subtle"}),r("div",{className:"text-xs font-semibold text-foreground",children:"Two-factor authentication"})]}),u("div",{className:"p-4 space-y-3",children:[x==="loading"&&u("div",{className:"flex items-center gap-2 text-xs text-foreground-subtle",children:[r(Ee,{className:"h-3.5 w-3.5 animate-spin"}),"Checking status…"]}),x==="not_enrolled"&&u(me,{children:[r("div",{className:"text-xs text-foreground-subtle",children:"2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login."}),r("div",{className:"flex justify-end",children:u("button",{onClick:()=>{d(null),m.mutate()},disabled:m.isPending,className:"inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[m.isPending?r(Ee,{className:"h-3 w-3 animate-spin"}):r($n,{className:"h-3 w-3"}),"Enable 2FA"]})})]}),x==="setup_in_progress"&&s&&u(me,{children:[u("div",{className:"text-[11px] text-foreground-subtle",children:["Scan the QR code (or enter the secret manually) into your authenticator app for ",r("span",{className:"font-mono",children:e}),", then enter the 6-digit code below to confirm."]}),u("div",{className:"flex flex-col items-center gap-3",children:[r("div",{className:"rounded-lg border border-border bg-white p-3",children:r(BF,{value:s.otpauthUrl,size:180})}),u("div",{className:"w-full",children:[r("div",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle mb-1",children:"Secret (manual entry)"}),u("div",{className:"flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5",children:[r("code",{className:"text-[11px] font-mono text-foreground break-all flex-1",children:s.secret}),u("button",{onClick:b,className:"inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground",children:[p?r(Zn,{className:"h-3 w-3 text-emerald-500"}):r(ha,{className:"h-3 w-3"}),p?"Copied":"Copy"]})]})]})]}),u("div",{className:"space-y-1",children:[r("label",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:"6-digit code"}),r("input",{type:"text",inputMode:"numeric",autoComplete:"one-time-code",placeholder:"123456",value:i,onChange:y=>l(y.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary"})]}),c&&u("div",{className:"text-[11px] text-danger flex items-center gap-1",children:[r(nr,{className:"h-3 w-3"}),c]}),u("div",{className:"flex justify-end gap-2",children:[r("button",{onClick:()=>{a(null),d(null),l("")},className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),u("button",{onClick:()=>{d(null),h.mutate({code:i})},disabled:h.isPending||i.length!==6,className:"inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[h.isPending?r(Ee,{className:"h-3 w-3 animate-spin"}):r(Zn,{className:"h-3 w-3"}),"Confirm"]})]})]}),x==="enrolled"&&o&&u(me,{children:[u("div",{className:"rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5",children:[r(Zn,{className:"h-4 w-4 mt-0.5 text-emerald-500 shrink-0"}),u("div",{className:"text-xs text-foreground space-y-0.5",children:[r("div",{className:"font-medium",children:"2FA is active"}),u("div",{className:"text-foreground-subtle",children:["Enrolled on ",o.confirmedAt?new Date(o.confirmedAt).toLocaleString():"—"]})]})]}),c&&u("div",{className:"text-[11px] text-danger flex items-center gap-1",children:[r(nr,{className:"h-3 w-3"}),c]}),r("div",{className:"flex justify-end",children:u("button",{onClick:()=>{d(null),g.mutate()},disabled:g.isPending,className:"rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1",children:[g.isPending?r(Ee,{className:"h-3 w-3 animate-spin"}):r($n,{className:"h-3 w-3"}),"Disable 2FA"]})})]})]})]})}function VF(){return r(ot,{children:r("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:r(rn,{limit:500,maxHeight:"max-h-[calc(100vh-250px)]",showScope:!0,showFilters:!0})})})}function ui({tabs:e,defaultTab:t}){const[n,o]=Xa(),s=n.get("tab"),a=t??e[0]?.id??"",i=e.some(d=>d.id===s)?s:a,l=e.find(d=>d.id===i)??e[0],c=d=>{const p=new URLSearchParams(n);p.set("tab",d),o(p,{replace:!0})};return u("div",{className:"space-y-3",children:[r("div",{className:"flex border-b border-border overflow-x-auto",children:e.map(d=>{const p=d.icon,f=d.id===i;return u("button",{onClick:()=>c(d.id),className:`flex shrink-0 items-center gap-1.5 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${f?"border-primary text-primary":"border-transparent text-foreground-subtle hover:text-foreground"}`,children:[p&&r(p,{className:"h-3.5 w-3.5"}),d.label]},d.id)})}),r("div",{children:l?.content})]})}function UF({userId:e,username:t,onClose:n}){const o=Me(),s=st(),a=Uy({userId:e}),i=a.data,l=()=>o.invalidateQueries({queryKey:[["userManagement","getTotpStatus"]]}),c=Vy({onSuccess:()=>{l(),n()}}),d=a.isLoading?"loading":i?.enabled?"enrolled":"not_enrolled",p=async()=>{await s({title:"Remove 2FA",message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:"Remove",variant:"danger"})&&c.mutate({userId:e})};return r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4",children:u("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden",children:[u("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[u("div",{className:"flex items-center gap-2",children:[r($n,{className:"h-4 w-4 text-primary"}),u("div",{children:[r("div",{className:"text-sm font-medium text-foreground",children:"Two-factor authentication"}),u("div",{className:"text-[11px] text-foreground-subtle",children:["User: ",r("span",{className:"font-mono",children:t})]})]})]}),r("button",{onClick:n,className:"p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle",children:r(Ve,{className:"h-4 w-4"})})]}),u("div",{className:"p-4 space-y-4",children:[d==="loading"&&u("div",{className:"flex items-center gap-2 text-xs text-foreground-subtle",children:[r(Ee,{className:"h-3.5 w-3.5 animate-spin"}),"Checking status…"]}),d==="not_enrolled"&&u("div",{className:"rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle",children:[r(rr,{className:"h-4 w-4 mt-0.5 shrink-0"}),u("div",{children:[r("div",{className:"font-medium text-foreground",children:"2FA not enrolled"}),r("p",{className:"mt-0.5",children:"Only the user themselves can enable 2FA, from their own profile page."})]})]}),d==="enrolled"&&i&&u(me,{children:[u("div",{className:"rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5",children:[r(Zn,{className:"h-4 w-4 mt-0.5 text-emerald-500 shrink-0"}),u("div",{className:"text-xs text-foreground space-y-0.5",children:[r("div",{className:"font-medium",children:"2FA is active"}),u("div",{className:"text-foreground-subtle",children:["Enrolled on ",i.confirmedAt?new Date(i.confirmedAt).toLocaleString():"—"]})]})]}),r("div",{className:"text-[11px] text-foreground-subtle",children:"Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards."}),u("div",{className:"flex justify-end gap-2",children:[r(Ue,{onClick:n,variant:"secondary",children:"Close"}),u("button",{onClick:p,disabled:c.isPending,className:"rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1",children:[c.isPending?r(Ee,{className:"h-3 w-3 animate-spin"}):r(Ve,{className:"h-3 w-3"}),"Remove 2FA"]})]})]})]})]})})}function qF(){const e=Me(),{user:t}=sn(),[n,o]=I(!1),[s,a]=I(""),[i,l]=I(""),[c,d]=I(!1),[p,f]=I(null),{data:m,isLoading:h,isError:g}=$d(),x=st(),b=()=>e.invalidateQueries({queryKey:[["userManagement","listUsers"]]}),y=Ly({onSuccess:()=>{b(),o(!1),a(""),l(""),d(!1),f(null)},onError:P=>{f(P instanceof Error?P.message:"Failed to create user")}}),w=Ry({onSuccess:b}),v=Ty({onSuccess:b}),N=Dd({onSuccess:b}),k=Oy({onSuccess:()=>{b(),D(null)}}),[C,D]=I(null),[M,_]=I(null),$=m??[];async function E(P){await x({title:"Delete user",message:`Permanently delete user "${P.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:"Delete",variant:"danger"})&&w.mutate({id:P.id})}async function R(P){const L=window.prompt(`New password for "${P.username}":`);if(!L)return;if(L.length<8){window.alert("Password must be at least 8 characters.");return}await x({title:"Reset password",message:`Reset the password for "${P.username}"? They will need to use the new password on their next login.`,confirmLabel:"Reset"})&&N.mutate({id:P.id,newPassword:L})}function O(P,L){L!==P.isAdmin&&v.mutate({id:P.id,isAdmin:L})}function A(P){return P?new Date(typeof P=="number"?P:String(P)).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"}):"—"}return u(ot,{children:[r("div",{className:"flex items-center justify-end",children:u("button",{onClick:()=>o(!0),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 hover:bg-primary/90",children:[r(It,{className:"h-3.5 w-3.5"}),"Create User"]})}),n&&u("div",{className:"rounded-lg border border-border bg-surface p-4 space-y-3",children:[u("div",{className:"flex items-center justify-between",children:[r("span",{className:"text-xs font-medium text-foreground",children:"New User"}),r("button",{onClick:()=>o(!1),className:"text-foreground-subtle hover:text-foreground",children:r(Ve,{className:"h-4 w-4"})})]}),u("div",{className:"grid grid-cols-3 gap-3",children:[u("div",{className:"space-y-1",children:[r("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Username"}),r("input",{type:"text",value:s,onChange:P=>a(P.target.value),placeholder:"john",className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary"})]}),u("div",{className:"space-y-1",children:[r("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Password"}),r("input",{type:"password",value:i,onChange:P=>l(P.target.value),placeholder:"••••••••",className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary"})]}),u("div",{className:"space-y-1",children:[r("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Admin"}),u("label",{className:"flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer",children:[r("input",{type:"checkbox",checked:c,onChange:P=>d(P.target.checked),className:"rounded border-border focus:ring-primary"}),r("span",{className:"text-foreground-subtle",children:"Unrestricted access"})]})]})]}),p&&r("p",{className:"text-[10px] text-danger",children:p}),u("div",{className:"flex justify-end gap-2",children:[r("button",{onClick:()=>o(!1),className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),r("button",{onClick:()=>y.mutate({username:s,password:i,isAdmin:c}),disabled:y.isPending||!s||!i,className:"rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:y.isPending?"Creating...":"Create"})]})]}),h&&r("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading..."}),g&&r("div",{className:"text-xs text-danger",children:"Failed to load"}),!h&&!g&&$.length===0&&r("div",{className:"text-xs text-foreground-subtle",children:"No data"}),(()=>{const P=B=>w.isPending&&w.variables?.id===B.id||v.isPending&&v.variables?.id===B.id||N.isPending&&N.variables?.id===B.id;return r(Fa,{columns:[{key:"username",header:"Username",render:B=>B.username},{key:"isAdmin",header:"Admin",render:B=>u("label",{className:"inline-flex items-center gap-1.5 text-xs cursor-pointer",children:[r("input",{type:"checkbox",checked:B.isAdmin,onChange:z=>O(B,z.target.checked),disabled:P(B),className:"rounded border-border focus:ring-primary disabled:opacity-50"}),r("span",{className:B.isAdmin?"text-primary font-medium":"text-foreground-subtle",children:B.isAdmin?"Admin":"Regular"})]})},{key:"scopes",header:"Scopes",render:B=>{if(B.isAdmin)return r("span",{className:"text-[10px] text-foreground-subtle italic",children:"unscoped"});const z=B.scopes??[];return u("button",{onClick:()=>D(B),className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground",title:"Edit scope grants",children:[r(xn,{className:"h-3 w-3"}),z.length===0?"no access":`${z.length} grant${z.length===1?"":"s"}`]})}},{key:"createdAt",header:"Created",render:B=>r("span",{className:"text-foreground-subtle",children:A(B.createdAt)})},{key:"actions",header:"Actions",align:"right",render:B=>{const z=P(B),T=B.id!==t?.id&&B.totpEnabled;return u("div",{className:"flex items-center justify-end gap-1",children:[T&&u("button",{onClick:()=>_(B),disabled:z,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50",title:"Remove two-factor authentication",children:[r($n,{className:"h-3 w-3"}),"Remove 2FA"]}),u("button",{onClick:()=>R(B),disabled:z,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50",title:"Reset password",children:[r(UO,{className:"h-3 w-3"}),"Reset password"]}),u("button",{onClick:()=>E(B),disabled:z,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50",title:"Delete user",children:[z?r(Ee,{className:"h-3 w-3 animate-spin"}):r(et,{className:"h-3 w-3"}),"Delete"]})]})}}],rows:$,rowKey:B=>B.id,minWidthPx:560})})(),M&&r(UF,{userId:M.id,username:M.username,onClose:()=>_(null)}),C&&r(QF,{user:C,onClose:()=>D(null),onSubmit:P=>k.mutate({userId:C.id,scopes:P}),submitting:k.isPending})]})}function QF(e){const{user:t}=sn(),n=t?.isAdmin===!0;return r(GF,{...e,callerScopes:n?null:t?.scopes??[]})}function GF({user:e,onClose:t,onSubmit:n,submitting:o,callerScopes:s}){const a=q(()=>(e.scopes??[]).map(d=>({...d,access:[...d.access]})),[e.scopes]),[i,l]=I(a),c=Wd(i);return r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",children:u("div",{className:"w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl",children:[u("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[u("div",{children:[u("div",{className:"text-sm font-semibold text-foreground",children:["Edit scopes — ",e.username]}),r("div",{className:"text-[10px] text-foreground-subtle",children:e.isAdmin?"Admin users bypass the scope check; this list is ignored.":"Pick which capabilities this user can call, and which access flavours within each."})]}),r("button",{onClick:t,className:"text-foreground-subtle hover:text-foreground",children:r(Ve,{className:"h-4 w-4"})})]}),u("div",{className:"px-4 py-4",children:[r(Gd,{value:i,onChange:l,clampToParent:s,emptyHint:u(me,{children:["No scopes granted. ",r("span",{className:"font-medium text-foreground",children:e.username})," cannot call any protected endpoint until a scope is added."]})}),c&&r("p",{className:"mt-2 text-[10px] text-danger",children:c})]}),u("div",{className:"flex items-center justify-end gap-2 border-t border-border px-4 py-3",children:[r("button",{onClick:t,className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),r("button",{onClick:()=>n(i),disabled:o||c!==null,className:"rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:o?r(Ee,{className:"h-3 w-3 animate-spin"}):"Save scopes"})]})]})})}const WF="bg-primary/10 text-primary",KF="bg-foreground-subtle/10 text-foreground-subtle";function Po(e){if(!e)return"—";const t=new Date(e);return Number.isNaN(t.getTime())?"—":t.toLocaleString()}function YF(e){return e?e==="*"?"*":e.join(", "):""}function ZF(){const e=Me(),t=st(),{data:n,isLoading:o}=By(),{data:s}=$d(),a=q(()=>n??[],[n]),i=q(()=>s??[],[s]),l=()=>e.invalidateQueries({queryKey:[["userManagement","listApiKeys"]]}),c=()=>e.invalidateQueries({queryKey:[["userManagement","listScopedTokens"]]}),[d,p]=I(!1),[f,m]=I(null),h=zy({onSuccess:l}),g=Fy({onSuccess:({token:w,record:v})=>{c(),p(!1),m({token:w,label:v.name})}}),x=jy({onSuccess:c}),b=async(w,v)=>{await t({title:`Revoke "${v}"?`,message:"Any client using this token will lose access immediately. This cannot be undone.",confirmLabel:"Revoke",variant:"danger"})&&h.mutate({id:w})},y=async(w,v)=>{await t({title:`Revoke "${v}"?`,message:"The scoped token will be invalid on its next use.",confirmLabel:"Revoke",variant:"danger"})&&x.mutate({id:w})};return u(ot,{children:[u("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[r("p",{className:"text-xs text-foreground-subtle max-w-2xl",children:"Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius."}),u("button",{onClick:()=>p(!0),className:"inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",disabled:i.length===0,title:i.length===0?"Create a user first":"Issue a scoped token",children:[r(xn,{className:"h-3.5 w-3.5"}),"New token"]})]}),u(Lf,{title:"Scoped tokens",subtitle:"Grouped per user",children:[i.length===0&&r(JF,{text:"No users yet — scoped tokens are issued on behalf of an existing user."}),i.map(w=>r(ej,{userId:w.id,username:w.username,onRevoke:(v,N)=>{y(v,N)},revokePending:x.isPending,revokeId:x.variables?.id},w.id))]}),a.length>0&&r(Lf,{title:"Legacy API keys",subtitle:`${a.length} pre-existing — revoke only`,children:r(d1,{headers:["Label","Admin","Prefix","Allowed providers","Created","Last used",""],rows:a.map(w=>{const v=!!w.isAdmin,N=h.isPending&&h.variables?.id===w.id;return u("tr",{className:"hover:bg-primary/5",children:[r("td",{className:"px-3 py-2 text-foreground border-b border-border font-medium",children:w.label}),r("td",{className:"px-3 py-2 text-foreground border-b border-border",children:r("span",{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${v?WF:KF}`,children:v?"admin":"regular"})}),u("td",{className:"px-3 py-2 text-foreground border-b border-border font-mono text-[11px]",children:[w.tokenPrefix,"…"]}),r("td",{className:"px-3 py-2 text-foreground border-b border-border text-foreground-subtle",children:YF(w.allowedProviders)||"all"}),r("td",{className:"px-3 py-2 text-foreground-subtle border-b border-border",children:Po(w.createdAt)}),r("td",{className:"px-3 py-2 text-foreground-subtle border-b border-border",children:Po(w.lastUsedAt)}),r("td",{className:"px-3 py-2 border-b border-border text-right",children:u("button",{onClick:()=>{b(w.id,w.label)},disabled:N,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50",title:"Revoke",children:[N?r(Ee,{className:"h-3 w-3 animate-spin"}):r(et,{className:"h-3 w-3"}),"Revoke"]})})]},w.id)})})}),o&&r(XF,{}),d&&r(tj,{users:i.map(w=>({id:w.id,username:w.username})),onClose:()=>p(!1),onSubmit:w=>g.mutate({userId:w.userId,name:w.name,scopes:w.scopes,...w.expiresAt!==void 0?{expiresAt:w.expiresAt}:{}}),submitting:g.isPending}),f&&r(nj,{token:f.token,label:f.label,onClose:()=>m(null)})]})}function Lf({title:e,subtitle:t,children:n}){return u("div",{className:"space-y-2",children:[u("div",{className:"flex items-baseline justify-between",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:e}),t&&r("span",{className:"text-[10px] text-foreground-subtle",children:t})]}),n]})}function XF(){return r("div",{className:"space-y-2",children:[1,2].map(e=>r("div",{className:"h-10 rounded border border-border bg-surface animate-pulse"},e))})}function JF({text:e}){return r("div",{className:"rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center",children:e})}function d1({headers:e,rows:t}){return r("div",{className:"rounded-lg border border-border bg-surface overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[640px]",children:[r("thead",{children:r("tr",{children:e.map((n,o)=>r("th",{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${o===e.length-1?"text-right":"text-left"}`,children:n},o))})}),r("tbody",{children:t})]})})}function ej({userId:e,username:t,onRevoke:n,revokePending:o,revokeId:s}){const{data:a,isLoading:i}=Hy({userId:e}),l=a??[];return i||l.length===0?null:u("div",{className:"space-y-1.5",children:[r("div",{className:"text-[11px] font-medium text-foreground",children:t}),r(d1,{headers:["Name","Prefix","Scopes","Expires","Last used","Created",""],rows:l.map(c=>{const d=o&&s===c.id;return u("tr",{className:"hover:bg-primary/5",children:[r("td",{className:"px-3 py-2 text-foreground border-b border-border font-medium",children:c.name}),u("td",{className:"px-3 py-2 text-foreground border-b border-border font-mono text-[11px]",children:[c.tokenPrefix,"…"]}),r("td",{className:"px-3 py-2 text-foreground border-b border-border",children:r("div",{className:"flex flex-wrap gap-1",children:c.scopes.map((p,f)=>u("span",{className:"inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono",children:[p.type,":",p.type==="device"?`[${p.targets.join(",")}]`:p.target]},f))})}),r("td",{className:"px-3 py-2 text-foreground-subtle border-b border-border",children:Po(c.expiresAt)}),r("td",{className:"px-3 py-2 text-foreground-subtle border-b border-border",children:Po(c.lastUsedAt)}),r("td",{className:"px-3 py-2 text-foreground-subtle border-b border-border",children:Po(c.createdAt)}),r("td",{className:"px-3 py-2 border-b border-border text-right",children:u("button",{onClick:()=>n(c.id,c.name),disabled:d,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50",children:[d?r(Ee,{className:"h-3 w-3 animate-spin"}):r(et,{className:"h-3 w-3"}),"Revoke"]})})]},c.id)})})]})}function tj({users:e,onClose:t,onSubmit:n,submitting:o}){const{user:s}=sn(),i=s?.isAdmin===!0?null:s?.scopes??[],[l,c]=I(e[0]?.id??""),[d,p]=I(""),[f,m]=I([{type:"capability",target:"",access:["view","create"]}]),[h,g]=I(""),x=Wd(f),b=l!==""&&d.trim().length>0&&f.length>0&&x===null&&!o,y=()=>{const w=parseInt(h,10),v=Number.isFinite(w)&&w>0?Date.now()+w*864e5:void 0;n({userId:l,name:d.trim(),scopes:f,expiresAt:v})};return u(u1,{title:"Create scoped token",onClose:t,children:[u("div",{className:"space-y-3",children:[r(Ts,{label:"On behalf of user",children:r("select",{value:l,onChange:w=>c(w.target.value),className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary",children:e.map(w=>r("option",{value:w.id,children:w.username},w.id))})}),r(Ts,{label:"Name",children:r("input",{value:d,onChange:w=>p(w.target.value),placeholder:"cloudflare-tunnel-route",className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary"})}),u(Ts,{label:"Scopes",hint:"Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.",children:[r(Gd,{value:f,onChange:m,clampToParent:i}),x&&r("p",{className:"mt-1 text-[10px] text-danger",children:x})]}),r(Ts,{label:"Expires in (days)",hint:"Leave blank for non-expiring.",children:r("input",{type:"number",min:1,value:h,onChange:w=>g(w.target.value),placeholder:"30",className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary"})})]}),u(p1,{children:[r("button",{onClick:t,className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),u("button",{onClick:y,disabled:!b,className:"inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[o?r(Ee,{className:"h-3.5 w-3.5 animate-spin"}):r(xn,{className:"h-3.5 w-3.5"}),"Issue token"]})]})]})}function nj({token:e,label:t,onClose:n}){const[o,s]=I(!1),a=async()=>{try{await navigator.clipboard.writeText(e),s(!0)}catch{}};return u(u1,{title:`Token: ${t}`,onClose:n,children:[u("div",{className:"space-y-3",children:[r("div",{className:"rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning",children:"Copy this token now. Once you close this dialog the secret cannot be displayed again."}),r("div",{className:"rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all",children:e})]}),u(p1,{children:[u("button",{onClick:()=>{a()},className:"inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30",children:[o?r(St,{className:"h-3.5 w-3.5 text-primary"}):r(ha,{className:"h-3.5 w-3.5"}),o?"Copied":"Copy"]}),r("button",{onClick:n,className:"rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:"Done"})]})]})}function u1({title:e,onClose:t,children:n}){return r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:t,children:u("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl",onClick:o=>o.stopPropagation(),children:[u("div",{className:"flex items-start justify-between border-b border-border px-4 py-3",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:e}),r("button",{onClick:t,className:"text-foreground-subtle hover:text-foreground",children:r(Ve,{className:"h-4 w-4"})})]}),r("div",{className:"p-4",children:n})]})})}function p1({children:e}){return r("div",{className:"flex justify-end gap-2 border-t border-border px-4 py-3",children:e})}function Ts({label:e,hint:t,children:n}){return u("div",{className:"space-y-1",children:[r("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:e}),n,t&&r("p",{className:"text-[10px] text-foreground-subtle",children:t})]})}function hl(e){if(!e)return"—";const t=new Date(e);return Number.isNaN(t.getTime())?"—":t.toLocaleString()}function rj(e){if(e.type==="category"){const n=e.target??"";return n==="device"?"all devices":`all ${n}`}if(e.type==="device")return`device:[${(e.targets??[]).join(",")}]`;const t=e;return`${t.type}:${t.target??""}`}function oj(){return r("div",{className:"space-y-2",children:[1,2].map(e=>r("div",{className:"h-10 rounded border border-border bg-surface animate-pulse"},e))})}function sj({text:e}){return r("div",{className:"rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center",children:e})}function aj({headers:e,rows:t}){return r("div",{className:"rounded-lg border border-border bg-surface overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[640px]",children:[r("thead",{children:r("tr",{children:e.map((n,o)=>r("th",{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${o===e.length-1?"text-right":"text-left"}`,children:n},o))})}),r("tbody",{children:t})]})})}function ij(){const e=Me(),t=st(),{data:n,isLoading:o}=qy(),s=q(()=>n??[],[n]),i=Qy({onSuccess:()=>e.invalidateQueries({queryKey:[["userManagement","listOauthSessions"]]})}),l=async(c,d)=>{await t({title:`Revoke "${d}" session?`,message:"This integration will lose access immediately on its next API call. This cannot be undone.",confirmLabel:"Revoke",variant:"danger"})&&i.mutate({id:c})};return u(ot,{icon:bv,title:"Linked Sessions",subtitle:"External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.",children:[o&&r(oj,{}),!o&&s.length===0&&r(sj,{text:"No linked sessions — once an external integration completes the OAuth flow its session will appear here."}),!o&&s.length>0&&r(aj,{headers:["Integration","User","Scopes","Created","Last used","Status",""],rows:s.map(c=>{const d=c.revokedAt!==null,f=(i.isPending?i.variables?.id:void 0)===c.id;return u("tr",{className:"hover:bg-primary/5",children:[r("td",{className:"px-3 py-2 text-foreground border-b border-border font-medium",children:c.integrationId}),r("td",{className:"px-3 py-2 text-foreground border-b border-border",children:c.username}),r("td",{className:"px-3 py-2 text-foreground border-b border-border",children:r("div",{className:"flex flex-wrap gap-1",children:c.scopes.map((m,h)=>r("span",{className:"inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono",children:rj(m)},h))})}),r("td",{className:"px-3 py-2 text-foreground-subtle border-b border-border",children:hl(c.createdAt)}),r("td",{className:"px-3 py-2 text-foreground-subtle border-b border-border",children:hl(c.lastUsedAt)}),r("td",{className:"px-3 py-2 border-b border-border",children:d?u("span",{className:"inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle",children:["Revoked ",hl(c.revokedAt)]}):r("span",{className:"inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300",children:"Active"})}),r("td",{className:"px-3 py-2 border-b border-border text-right",children:!d&&u("button",{onClick:()=>{l(c.id,c.integrationId)},disabled:f,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50",title:"Revoke",children:[f?r(Ee,{className:"h-3 w-3 animate-spin"}):r(et,{className:"h-3 w-3"}),"Revoke"]})})]},c.id)})})]})}function lj({addonId:e,fallback:t,tileClassName:n,iconPath:o="assets/icon.svg"}){const[s,a]=I(!1),i=`/api/addon-assets/${e}/${o}`;return r("div",{className:`h-10 w-10 rounded-lg flex items-center justify-center shrink-0 ${n}`,children:s?r(t,{className:"h-5 w-5"}):r("img",{src:i,alt:e,className:"h-7 w-7 rounded-md bg-white p-1 ring-1 ring-black/5",onError:()=>a(!0)})})}function cj({addonId:e,defaultActivity:t,showActivity:n=!0,maxHeight:o="max-h-64",defaultTab:s,capability:a}){const i=t??(s==="events"?"events":"logs"),[l,c]=I(i);return u("div",{className:"flex flex-col gap-4",children:[r(io,{nodeId:"hub",addonIds:[e],level:"global",capability:a}),n&&u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border bg-surface-hover/20",children:[r("span",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide",children:"Activity"}),u("div",{className:"flex items-center gap-1",children:[r(Tf,{kind:"logs",active:l==="logs",onClick:()=>c("logs")}),r(Tf,{kind:"events",active:l==="events",onClick:()=>c("events")})]})]}),l==="logs"?r(rn,{addonId:e,maxHeight:o,showFilters:!1}):r(hr,{addonId:e,category:"addon.*",maxHeight:o})]})]})}function Tf({kind:e,active:t,onClick:n}){return u("button",{onClick:n,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t?"bg-primary/10 text-primary":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,children:[r(e==="logs"?At:rs,{className:"h-3 w-3"}),e==="logs"?"Logs":"Events"]})}function ss(e){const{title:t,subtitle:n,pageIcon:o,itemIcon:s,capability:a,installButtonLabel:i="Add addon",items:l,isLoading:c,emptyTitle:d="No addons installed for this capability",emptyDescription:p,itemIconColor:f,renderStatusBadges:m,renderPrimaryAction:h,itemError:g,renderExpandedPanel:x,workspaceMaxHeight:b="max-h-72",trailing:y,showChrome:w=!1}=e,v=l.length>1,[N,k]=I(()=>l[0]?.addonId??null);J(()=>{N&&(l.some(M=>M.addonId===N)||k(l[0]?.addonId??null))},[l,N]);const C=M=>k(_=>_===M?null:M),D=`/system/addons?capability=${encodeURIComponent(a)}`;return r(ot,{icon:w?o:void 0,title:w?t:void 0,subtitle:w?n:void 0,actions:w?r(ma,{to:D,children:u(Ue,{variant:"primary",size:"sm",children:[r(It,{className:"h-3.5 w-3.5 mr-1"}),i]})}):void 0,children:c?r(mn,{children:r("div",{className:"p-6 text-sm text-foreground-subtle",children:"Loading…"})}):l.length===0?r(mn,{children:r(sd,{title:d,description:p??`Install an addon that declares the "${a}" capability to get started.`,action:w?r(ma,{to:D,children:u(Ue,{variant:"primary",size:"sm",children:[r(It,{className:"h-3.5 w-3.5 mr-1"}),i]})}):void 0})}):u("div",{className:"flex flex-col gap-4",children:[l.map(M=>{const _=!v||N===M.addonId,$=f?.(M)??(M.isActive?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-foreground-subtle/15 text-foreground-subtle"),E=g?.(M)??null;return u(mn,{children:[u("div",{className:`flex flex-col gap-3 p-4 sm:flex-row sm:items-center ${_?"border-b border-border":""}`,children:[u("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[v&&r("button",{type:"button",onClick:()=>C(M.addonId),"aria-label":_?"Collapse":"Expand",className:"shrink-0 p-1 rounded hover:bg-foreground-subtle/10 transition-colors",children:r(en,{className:`h-4 w-4 text-foreground-subtle transition-transform ${_?"rotate-180":""}`})}),u("button",{type:"button",onClick:()=>v&&C(M.addonId),className:`flex items-center gap-4 flex-1 min-w-0 text-left ${v?"hover:opacity-80 transition-opacity":""}`,disabled:!v,children:[r(lj,{addonId:M.addonId,fallback:s,tileClassName:$}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[r("span",{className:"font-semibold text-foreground",children:M.displayName}),r(dj,{isActive:M.isActive}),m?.(M)]}),u("div",{className:"text-xs text-foreground-subtle mt-1 font-mono break-all",children:["@camstack/addon-",M.addonId]})]})]})]}),u("div",{className:"flex items-center gap-1 shrink-0 flex-wrap justify-end",children:[h?.(M),r(uj,{capName:a,addonId:M.addonId,isActive:M.isActive}),r(pj,{addonId:M.addonId,displayName:M.displayName})]})]}),_&&u("div",{className:"p-4 flex flex-col gap-3",children:[E!==null&&r(Zo,{message:E}),x?.(M),r(cj,{addonId:M.addonId,maxHeight:b,capability:a})]})]},M.addonId)}),y]})})}function dj({isActive:e}){return r("span",{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${e?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-foreground-subtle/15 text-foreground-subtle"}`,children:e?"Enabled":"Disabled"})}function uj({capName:e,addonId:t,isActive:n}){const o=Me(),s=mb({onSuccess:()=>{o.invalidateQueries({queryKey:[["addons","listCapabilityProviders"]]})}}),a=s.isPending;return u(Ue,{size:"sm",variant:n?"secondary":"primary",disabled:a,onClick:()=>s.mutate({capName:e,addonId:t,enabled:!n}),children:[a?r(Ee,{className:"h-3 w-3 animate-spin"}):n?r(os,{className:"h-3 w-3"}):r(oi,{className:"h-3 w-3"}),n?"Disable":"Enable"]})}function pj({addonId:e,displayName:t}){const n=Me(),o=Jo({onSuccess:()=>{n.invalidateQueries({queryKey:[["addons","listCapabilityProviders"]]})}});return r(Qd,{label:"Restart",icon:ct,size:"sm",title:`Restart "${t}"?`,description:"Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.",confirmLabel:"Restart",triggerVariant:"ghost",confirmVariant:"danger",disabled:o.isPending,action:()=>o.mutateAsync({addonId:e})})}const Rf=3e4;function fj(e){const t=new Map;for(const n of e){const o=n?.manifest;o?.id&&t.set(o.id,o.packageDisplayName??o.name??o.id)}return t}function mj(e){return e==="local-auth"?{headline:"Username + password (local).",icon:HO,bullets:["Users live in the hub’s SQLite database — no IdP roundtrip.","TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).","API keys + scoped tokens are managed from the API Keys page."],setupSteps:["Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).","Hand out either passwords or scoped tokens — both validate through this provider."]}:e.startsWith("auth-oidc")?{headline:"OpenID Connect (Google, Microsoft, Okta, Keycloak, …).",icon:Ln,bullets:["Three-leg redirect flow with PKCE S256 + nonce.","id_token is signature-verified against the IdP’s JWKS — no implicit trust.","First-time sign-ins are auto-provisioned with the configured Default Role."],setupSteps:["Register a web app at your IdP and copy the client_id + client_secret.","Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.","Paste issuer + credentials in the Settings panel below — saves on every change."]}:e.startsWith("auth-saml")?{headline:"SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).",icon:Ln,bullets:["Heavier handshake than OIDC — exchange metadata XML with your IdP.","Group → role mapping via SAML assertions."]}:e.startsWith("auth-webauthn")||e.startsWith("auth-passkey")?{headline:"Passkeys / WebAuthn — passwordless second factor.",icon:$n,bullets:["Enroll a YubiKey, Touch ID, or platform passkey per user.","Resistant to phishing — the browser binds the credential to your hub origin."]}:e.startsWith("auth-totp")||e.startsWith("auth-magic-link")?{headline:"TOTP / magic-link — second factor or passwordless sign-in.",icon:$n,bullets:["Codes / links delivered out-of-band (RFC 6238 for TOTP).","Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc."]}:{headline:"Authentication provider.",icon:xn,bullets:["Generic authentication provider. No additional hints registered."]}}function hj(){const e=Xo({capName:"auth-provider"},{refetchInterval:Rf}),t=Nn(void 0,{refetchInterval:Rf}),n=q(()=>fj(t.data??[]),[t.data]),o=q(()=>(e.data??[]).map(s=>({addonId:s.addonId,displayName:n.get(s.addonId)??s.addonId,isActive:s.isActive})),[e.data,n]);return r(ss,{title:"Authentication",subtitle:"Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.",pageIcon:xn,itemIcon:xn,capability:"auth-provider",installButtonLabel:"Add provider",items:o,isLoading:e.isLoading,emptyTitle:"No authentication providers registered",emptyDescription:"Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.",renderExpandedPanel:s=>r(gj,{addonId:s.addonId})})}function gj({addonId:e}){const t=mj(e),n=t.icon;return u("div",{className:"rounded-lg border border-border bg-surface p-4 space-y-3",children:[u("div",{className:"flex items-start gap-2.5",children:[r(n,{className:"h-4 w-4 mt-0.5 text-primary shrink-0"}),r("div",{className:"text-xs text-foreground font-medium",children:t.headline})]}),r("ul",{className:"text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc",children:t.bullets.map((o,s)=>r("li",{children:o},s))}),t.setupSteps&&t.setupSteps.length>0&&u("div",{className:"rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5",children:[u("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide",children:[r(G6,{className:"h-3 w-3"}),"Setup steps"]}),r("ol",{className:"text-xs text-foreground space-y-0.5 pl-4 list-decimal",children:t.setupSteps.map((o,s)=>r("li",{children:o},s))})]}),e==="local-auth"&&u("div",{className:"rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground",children:[r(rr,{className:"h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0"}),u("span",{children:["TOTP / 2FA settings are exposed per-user from the"," ",r("a",{href:"/system/users",className:"underline text-primary",children:"Users"})," page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”."]})]})]})}function bj(){return r("div",{className:"flex flex-col p-4",children:r(ui,{tabs:[{id:"users",label:"Users",icon:d7,content:r(qF,{})},{id:"api-keys",label:"Tokens",icon:hv,content:r(ZF,{})},{id:"linked-sessions",label:"Linked Sessions",icon:bv,content:r(ij,{})},{id:"authentication",label:"Authentication",icon:xn,content:r(hj,{})}]})})}const hc=5e3,xj={connected:!1,endpoint:null};function yj(e){const t=new Map;for(const n of e){const o=n?.manifest;o?.id&&t.set(o.id,o.packageDisplayName??o.name??o.id)}return t}function vj(){const e=Me(),t=Xo({capName:"network-access"},{refetchInterval:hc}),n=Nn(void 0,{refetchInterval:hc}),o=q(()=>yj(n.data??[]),[n.data]),s=q(()=>(t.data??[]).map(h=>({addonId:h.addonId,displayName:o.get(h.addonId)??h.addonId,isActive:h.isActive})),[t.data,o]),[a,i]=I(null),[l,c]=I({}),d=(h,g)=>{const x=g?.addonId;e.invalidateQueries({queryKey:[["networkAccess","getStatus"],{input:{addonId:x},type:"query"}]}),i(null),c(b=>{const y=g?.addonId;if(y===void 0||!(y in b))return b;const w={...b};return delete w[y],w})},p=(h,g)=>{i(null);const x=g?.addonId;if(x===void 0)return;const b=h instanceof Error?h.message:String(h);c(y=>({...y,[x]:b}))},f=$x({onSuccess:d,onError:p}),m=Dx({onSuccess:d,onError:p});return r(ss,{title:"Remote Access",subtitle:"Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.",pageIcon:Ln,itemIcon:Ln,capability:"network-access",installButtonLabel:"Add tunnel",items:s,isLoading:t.isLoading,emptyTitle:"No remote-access providers installed",emptyDescription:"Install a tunnel addon (e.g. @camstack/addon-cloudflare-tunnel) to expose this hub publicly.",renderStatusBadges:h=>r(wj,{addonId:h.addonId}),itemError:h=>l[h.addonId]??null,renderPrimaryAction:h=>r(Nj,{addonId:h.addonId,busyId:a,onStart:g=>{i(g),f.mutate({addonId:g})},onStop:g=>{i(g),m.mutate({addonId:g})}})})}function f1(e){const{data:t}=Lx({addonId:e},{refetchInterval:hc,retry:!1}),n=t?f2.safeParse(t):null;return n?.success?n.data:xj}function wj({addonId:e}){const t=f1(e);return u(me,{children:[r("span",{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-foreground-subtle/15 text-foreground-subtle"}`,children:t.connected?"Connected":"Disconnected"}),t.endpoint&&u("a",{href:t.endpoint.url,target:"_blank",rel:"noopener noreferrer",onClick:n=>n.stopPropagation(),className:"text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1",children:[r(iu,{className:"h-3 w-3"}),t.endpoint.url]})]})}function Nj({addonId:e,busyId:t,onStart:n,onStop:o}){const s=f1(e),a=t===e;return s.connected?u(Ue,{size:"sm",variant:"secondary",disabled:a,onClick:()=>o(e),children:[a?r(Ee,{className:"h-3 w-3 animate-spin"}):r(os,{className:"h-3 w-3"}),"Stop"]}):u(Ue,{size:"sm",variant:"primary",disabled:a,onClick:()=>n(e),children:[a?r(Ee,{className:"h-3 w-3 animate-spin"}):r(oi,{className:"h-3 w-3"}),"Start"]})}const Of=3e4;function kj(e){const t=new Map;for(const n of e){const o=n?.manifest;o?.id&&t.set(o.id,o.packageDisplayName??o.name??o.id)}return t}function Sj(e){const t=[];for(const n of e)typeof n.urls=="string"?t.push(n.urls):t.push(...n.urls);return t}function Cj(){const e=Xo({capName:"turn-provider"},{refetchInterval:Of}),t=Nn(void 0,{refetchInterval:Of}),n=_d(),o=n.data??[],s=q(()=>kj(t.data??[]),[t.data]),a=q(()=>(e.data??[]).map(i=>({addonId:i.addonId,displayName:s.get(i.addonId)??i.addonId,isActive:i.isActive})),[e.data,s]);return r(ss,{title:"TURN Servers",subtitle:"ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.",pageIcon:Tn,itemIcon:Tn,capability:"turn-provider",installButtonLabel:"Add provider",items:a,isLoading:e.isLoading,emptyTitle:"No TURN providers installed",emptyDescription:"Install a TURN addon (e.g. @camstack/addon-cloudflare-turn) to enable WebRTC behind restrictive NATs.",renderExpandedPanel:i=>r(Mj,{addonId:i.addonId,enabled:i.isActive}),trailing:u(mn,{children:[u("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between",children:[u("div",{children:[r("div",{className:"text-sm font-semibold",children:"Combined ICE server list"}),r("div",{className:"text-xs text-foreground-subtle",children:"What the WebRTC layer fetches per-session."})]}),r(Ue,{size:"sm",variant:"secondary",onClick:()=>n.refetch(),disabled:n.isFetching,children:"Refresh"})]}),r("div",{className:"p-4",children:o.length===0?r("div",{className:"text-xs text-foreground-subtle",children:"No servers from enabled providers."}):r("div",{className:"flex flex-col gap-3",children:o.map((i,l)=>{const c=Array.isArray(i.urls)?i.urls:[i.urls];return u("div",{className:"rounded border border-border bg-surface",children:[(i.username||i.credential)&&u("div",{className:"px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3",children:[i.username&&u("span",{children:[r("span",{className:"text-foreground-subtle",children:"user:"})," ",r("span",{className:"text-foreground",children:i.username})]}),i.credential&&u("span",{children:[r("span",{className:"text-foreground-subtle",children:"credential:"})," ",r("span",{className:"text-foreground",children:"••••••••"})]})]}),r("ul",{className:"divide-y divide-border",children:c.map(d=>r("li",{className:"px-3 py-1.5 font-mono text-xs text-foreground break-all",children:d},d))})]},l)})})})]})})}function Mj({addonId:e,enabled:t}){const n=_d({addonId:e},{enabled:t,retry:!1}),o=q(()=>Sj(n.data??[]),[n.data]);return!t||o.length===0?null:u("div",{className:"rounded-lg border border-border bg-surface p-3",children:[u("div",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2",children:["Discovered ICE servers (",o.length,")"]}),r("div",{className:"flex flex-wrap gap-1",children:o.map(s=>r("span",{className:"inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground",children:s},s))})]})}const Aj={lan:Tn,wifi:Or,docker:ei,vpn:ri,loopback:Rn,other:Rn},Ej={lan:"LAN",wifi:"Wi-Fi",docker:"Docker",vpn:"VPN",loopback:"Loopback",other:"Other"},Ij=["lan","wifi","vpn","docker","other","loopback"];function Pj(e){const{interfaces:t,disabled:n,hideLoopback:o,ipv4Only:s,emptyMessage:a}=e,i=q(()=>t.filter(p=>!(o&&p.kind==="loopback"||s&&p.family!=="IPv4")),[t,o,s]),l=q(()=>{const p=new Map;for(const f of i){const m=p.get(f.kind)??[];m.push(f),p.set(f.kind,m)}return Ij.filter(f=>p.has(f)).map(f=>({kind:f,items:p.get(f)}))},[i]),c=p=>e.mode==="single"?e.value===p:e.value.includes(p),d=p=>{if(n||p.kind==="loopback")return;if(e.mode==="single"){e.onChange(e.value===p.address?null:p.address);return}const f=new Set(e.value);f.has(p.address)?f.delete(p.address):f.add(p.address),e.onChange([...f])};return i.length===0?r("div",{className:"text-xs text-foreground-subtle italic",children:a??"No addresses available."}):r("div",{className:"flex flex-col gap-3",children:l.map(({kind:p,items:f})=>{const m=Aj[p]??Rn;return u("div",{className:"rounded-md border border-border overflow-hidden",children:[u("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border",children:[r(m,{className:"h-3.5 w-3.5 text-foreground-subtle"}),r("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle",children:Ej[p]??p}),u("span",{className:"text-[10px] text-foreground-subtle",children:["· ",f.length]})]}),r("ul",{className:"divide-y divide-border",children:f.map(h=>{const g=c(h.address),x=h.kind==="loopback",b=!h.plausible&&!x;return u("li",{className:`flex items-center gap-3 px-3 py-2 ${x?"opacity-60 cursor-not-allowed":n?"opacity-60":b?"cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]":"cursor-pointer hover:bg-surface-hover/30"}`,onClick:()=>d(h),children:[r("span",{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode==="single"?"rounded-full":"rounded"} border ${g?"border-primary bg-primary text-primary-foreground":"border-border bg-surface"}`,children:g&&r(St,{className:"h-3 w-3"})}),u("div",{className:`flex-1 min-w-0 ${b?"text-foreground-subtle":""}`,children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[r("span",{className:`font-mono text-xs font-semibold ${b?"text-foreground-subtle":"text-foreground"}`,children:h.name}),r("span",{className:"text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono",children:h.family}),h.preferred&&r("span",{className:"text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary",children:"Auto-preferred"}),x&&r("span",{className:"text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle",children:"Always included"}),b&&u("span",{className:"inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300",title:h.plausibleReason||void 0,children:[r(pt,{className:"h-2.5 w-2.5"}),"Unlikely usable"]})]}),u("div",{className:"text-xs text-foreground-subtle mt-0.5 font-mono break-all",children:[h.address,h.cidr&&h.cidr!==h.address?` (${h.cidr})`:""]})]})]},`${h.name}-${h.family}-${h.address}`)})})]},p)})})}const Bf={"lan-ipv4":"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300","lan-ipv6":"bg-violet-500/15 text-violet-700 dark:text-violet-300",public:"bg-blue-500/15 text-blue-700 dark:text-blue-300",loopback:"bg-foreground-subtle/15 text-foreground-subtle"};function _j(){const e=Me(),t=De(),n=yx(void 0,{refetchInterval:3e4}),o=wx(void 0),s=Nx({onSuccess:()=>{e.invalidateQueries({queryKey:[["localNetwork"]]})}}),a=kx({onSuccess:C=>{f(C.addresses),e.invalidateQueries({queryKey:[["localNetwork"]]})}}),i=q(()=>n.data?.interfaces??[],[n.data]),l=typeof window<"u"?Number(window.location.port)||(window.location.protocol==="https:"?443:80):4e3,c=typeof window<"u"&&window.location.protocol==="https:"?"https":"http",d=vx({port:l,scheme:c},{refetchInterval:3e4}),[p,f]=I([]),[m,h]=I(!1);J(()=>{!m&&o.data&&(f(o.data.addresses),h(!0))},[o.data,m]);const g=o.data?.addresses??[],x=q(()=>{if(p.length!==g.length)return!0;const C=[...p].sort(),D=[...g].sort();return C.some((M,_)=>M!==D[_])},[p,g]),b=()=>{s.mutate({addresses:[...p]})},y=()=>{f(g)},w=()=>{f([])},v=()=>{n.refetch(),d.refetch(),o.refetch()},N=async()=>{try{const C=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info("[network-addresses] race result",C)}catch(C){console.warn("[network-addresses] race failed",C)}},k=d.data?.endpoints??[];return u(ot,{children:[u("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[r("p",{className:"text-xs text-foreground-subtle max-w-2xl",children:"Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate."}),u("div",{className:"flex items-center gap-2 shrink-0",children:[u(Ue,{size:"sm",variant:"secondary",onClick:v,disabled:n.isLoading,children:[r(ct,{className:`h-3 w-3 ${n.isLoading?"animate-spin":""}`}),"Refresh"]}),r(Ue,{size:"sm",variant:"secondary",onClick:N,children:"Probe race"})]})]}),u("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[u(mn,{children:[u("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between",children:[u("div",{children:[r("div",{className:"text-sm font-semibold",children:"Allowed addresses"}),r("div",{className:"text-xs text-foreground-subtle",children:p.length===0?"Auto — every non-loopback / non-link-local interface participates.":`${p.length} pinned`})]}),u("div",{className:"flex items-center gap-1",children:[u(Ue,{size:"sm",variant:"secondary",onClick:()=>a.mutate(void 0),disabled:a.isPending||s.isPending,title:"Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.",children:[r(Z8,{className:"h-3 w-3"}),a.isPending?"Detecting…":"Best match"]}),u(Ue,{size:"sm",variant:"secondary",onClick:w,disabled:p.length===0||s.isPending,children:[r(Sv,{className:"h-3 w-3"}),"Clear"]}),x&&r(Ue,{size:"sm",variant:"secondary",onClick:y,disabled:s.isPending,children:"Discard"}),u(Ue,{size:"sm",variant:"primary",onClick:b,disabled:!x||s.isPending,children:[r($8,{className:"h-3 w-3"}),s.isPending?"Saving…":"Save"]})]})]}),r("div",{className:"p-4",children:r(Pj,{mode:"multiple",interfaces:i,value:p,onChange:f,disabled:s.isPending,emptyMessage:n.isLoading?"Loading interfaces…":"No interfaces detected."})})]}),u(mn,{children:[u("div",{className:"px-4 py-3 border-b border-border",children:[r("div",{className:"text-sm font-semibold",children:"Connection endpoints — priority order"}),r("div",{className:"text-xs text-foreground-subtle",children:"Live preview of the ranked candidate list the SDK would race against. Updates with each Save."})]}),r("div",{className:"p-4",children:k.length===0?r("div",{className:"text-xs text-foreground-subtle italic",children:d.isLoading?"Loading…":"No endpoints available."}):r("ul",{className:"space-y-1 text-xs",children:k.map(C=>u("li",{className:`flex items-center gap-2 flex-wrap ${C.plausible?"":"opacity-80"}`,children:[r("span",{className:"font-mono text-[10px] w-10 text-foreground-subtle",children:String(C.priority).padStart(4,"0")}),r("span",{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Bf[C.kind]??Bf.loopback}`,children:C.kind}),C.interfaceKind!=="lan"&&C.interfaceKind!=="public"&&r("span",{className:"text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase",children:C.interfaceKind}),!C.plausible&&C.interfaceKind!=="loopback"&&u("span",{className:"inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300",title:C.plausibleReason||void 0,children:[r(pt,{className:"h-2.5 w-2.5"}),"Unlikely usable"]}),r("span",{className:`font-mono break-all ${C.plausible?"text-foreground":"text-foreground-subtle"}`,children:C.baseUrl}),u("span",{className:"text-foreground-subtle",children:["— ",C.label]})]},`${C.priority}-${C.baseUrl}`))})})]})]})]})}const $j={mesh:"bg-violet-500/15 text-violet-700 dark:text-violet-300",public:"bg-blue-500/15 text-blue-700 dark:text-blue-300"},gc=5e3,Dj=3e4,Lj={joined:!1,meshIp:"",magicDnsHostname:"",peerCount:0,endpoints:[],tenantName:"",magicDnsSuffix:"",userLogin:null,controlPlaneUrl:"",keyExpiry:null};function Tj(e){const t=new Map;for(const n of e){const o=n?.manifest;o?.id&&t.set(o.id,o.packageDisplayName??o.name??o.id)}return t}function Rj(){const e=Xo({capName:"mesh-network"},{refetchInterval:gc}),t=Nn(void 0,{refetchInterval:gc}),n=q(()=>Tj(t.data??[]),[t.data]),o=q(()=>(e.data??[]).map(s=>({addonId:s.addonId,displayName:n.get(s.addonId)??s.addonId,isActive:s.isActive})),[e.data,n]);return r(ss,{title:"Mesh Networks",subtitle:"Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).",pageIcon:ei,itemIcon:Tn,capability:"mesh-network",installButtonLabel:"Add mesh",items:o,isLoading:e.isLoading,emptyTitle:"No mesh-network providers installed",emptyDescription:"Install a mesh addon (e.g. @camstack/addon-tailscale-client) to join this hub into a private VPN mesh.",renderStatusBadges:s=>r(Oj,{addonId:s.addonId}),renderPrimaryAction:s=>r(Bj,{addonId:s.addonId}),renderExpandedPanel:s=>r(zj,{addonId:s.addonId})})}function uu(e){const{data:t,isLoading:n}=Sx({addonId:e},{refetchInterval:gc,retry:!1}),o=t?dh.safeParse(t):null;return{status:o?.success?o.data:Lj,isLoading:n}}function Oj({addonId:e}){const{status:t}=uu(e);return u(me,{children:[r("span",{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-foreground-subtle/15 text-foreground-subtle"}`,children:t.joined?"Joined":"Not joined"}),t.joined&&u("span",{className:"text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle",children:[t.peerCount," peer",t.peerCount===1?"":"s"]})]})}function Bj({addonId:e}){const t=Me(),[n,o]=I(!1),[s,a]=I(null),i=De(),{status:l}=uu(e),c=U(()=>{t.invalidateQueries({queryKey:[["meshNetwork"]]})},[t]),d=Cx(),p=Mx({onSuccess:c}),f=Ax({onSuccess:c}),m=U(async()=>{o(!0);const g={cancelled:!1};a(g);try{const x=await d.mutateAsync({addonId:e});if(g.cancelled)return;x.loginUrl&&window.open(x.loginUrl,"_blank","noopener,noreferrer");const b=Date.now(),y=10*6e4;for(;!g.cancelled&&(await Uj(2e3),!g.cancelled);){const w=await i.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),v=w?dh.safeParse(w):null;if(v?.success&&v.data.joined){c();break}if(Date.now()-b>y)break}}finally{o(!1),a(null)}},[e,c,d,i]),h=U(()=>{s&&(s.cancelled=!0),o(!1),a(null)},[s]);return r(me,{children:l.joined?u(me,{children:[u(Ue,{size:"sm",variant:"secondary",disabled:p.isPending,onClick:()=>p.mutate({addonId:e}),children:[p.isPending?r(Ee,{className:"h-3 w-3 animate-spin"}):r(lu,{className:"h-3 w-3"}),"Disconnect"]}),u(Ue,{size:"sm",variant:"ghost",disabled:f.isPending,onClick:()=>f.mutate({addonId:e}),children:[f.isPending?r(Ee,{className:"h-3 w-3 animate-spin"}):r(Wp,{className:"h-3 w-3"}),"Log out"]})]}):n?u(Ue,{size:"sm",variant:"ghost",onClick:h,children:[r(Ve,{className:"h-3 w-3 mr-1"})," Cancel"]}):u(me,{children:[u(Ue,{size:"sm",variant:"primary",onClick:()=>void m(),children:[r(e8,{className:"h-3 w-3"}),"Connect"]}),u(Ue,{size:"sm",variant:"ghost",disabled:f.isPending,onClick:()=>f.mutate({addonId:e}),children:[f.isPending?r(Ee,{className:"h-3 w-3 animate-spin"}):r(Wp,{className:"h-3 w-3"}),"Log out"]})]})})}function zj({addonId:e}){const{status:t}=uu(e),n=Ex({addonId:e},{refetchInterval:Dj,retry:!1});return u("div",{className:"rounded-lg border border-border bg-surface",children:[u("div",{className:"p-4 space-y-4",children:[t.error&&r(Zo,{message:t.error}),r(Fj,{status:t}),t.endpoints.length>0&&u("div",{className:"space-y-1.5",children:[r("div",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide",children:"Endpoints"}),t.endpoints.map(o=>u("div",{className:"flex items-center gap-2 text-xs flex-wrap",children:[u("span",{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${$j[o.scope]??"bg-foreground-subtle/15 text-foreground-subtle"}`,children:[o.scope==="public"?r(Ln,{className:"inline h-2.5 w-2.5 mr-0.5"}):null,o.label]}),u("a",{href:o.url,target:"_blank",rel:"noopener noreferrer",onClick:s=>s.stopPropagation(),className:"text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1",children:[r(iu,{className:"h-3 w-3 shrink-0"}),o.url]})]},o.id))]})]}),r("div",{className:"border-t border-border",children:r(Hj,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function Fj({status:e}){const t=[{label:"Tenant",value:e.tenantName||"—"},{label:"User",value:e.userLogin??"—"},{label:"Control plane",value:e.controlPlaneUrl||"—"},{label:"Mesh IP",value:e.meshIp||"—",mono:!0},{label:"MagicDNS",value:e.magicDnsHostname||"—",mono:!0},{label:"DNS suffix",value:e.magicDnsSuffix||"—",mono:!0},{label:"Peers",value:String(e.peerCount)},{label:"Key expiry",value:e.keyExpiry?jj(e.keyExpiry):"—"}];return r("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5",children:t.map(n=>u("div",{className:"flex items-baseline justify-between gap-3 text-xs",children:[r("span",{className:"text-foreground-subtle shrink-0",children:n.label}),r("span",{className:`text-foreground truncate ${n.mono?"font-mono":""}`,children:n.value})]},n.label))})}function jj(e){const t=e-Date.now();if(t<0)return`Expired ${m1(e)}`;const n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;const o=Math.floor(t/36e5);return o>1?`in ${o}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Hj({peers:e,loading:t}){const n=q(()=>e.map(a=>({...a,_id:a.id})),[e]),o=U(a=>{a&&navigator.clipboard?.writeText(a)},[]),s=q(()=>[{key:"hostname",header:"Hostname",render:a=>u("div",{className:"flex flex-col",children:[u("div",{className:"flex items-center gap-1.5",children:[r("span",{className:"font-medium text-foreground",children:a.hostname||"(unknown)"}),a.isSelf&&r(Kt,{variant:"info",children:"self"}),a.exitNodeOption&&r(Kt,{variant:"warning",children:"exit-node"})]}),a.userLogin&&r("div",{className:"text-[10px] text-foreground-subtle truncate",children:a.userLogin})]})},{key:"magicDns",header:"MagicDNS",render:a=>a.magicDns?u("div",{className:"flex items-center gap-1",children:[r("span",{className:"font-mono text-xs truncate",children:a.magicDns}),r("button",{onClick:()=>o(a.magicDns),className:"p-0.5 hover:bg-foreground-subtle/10 rounded","aria-label":"Copy MagicDNS",children:r(ha,{className:"h-3 w-3 text-foreground-subtle"})})]}):r("span",{className:"text-foreground-subtle",children:"—"})},{key:"addresses",header:"IP",render:a=>{const i=a.addresses[0]??"";return i?u("div",{className:"flex items-center gap-1",children:[r("span",{className:"font-mono text-xs",children:i}),r("button",{onClick:()=>o(i),className:"p-0.5 hover:bg-foreground-subtle/10 rounded","aria-label":"Copy IP",children:r(ha,{className:"h-3 w-3 text-foreground-subtle"})})]}):r("span",{className:"text-foreground-subtle",children:"—"})}},{key:"connection",header:"Connection",render:a=>u("div",{className:"flex items-center gap-1.5",children:[r(Kt,{variant:Vj(a.connection),children:a.connection}),a.relay&&r("span",{className:"text-[10px] text-foreground-subtle font-mono",children:a.relay})]})},{key:"routes",header:"Routes",render:a=>a.advertisedRoutes.length>0?r("span",{className:"text-[10px] font-mono text-foreground-subtle truncate",children:a.advertisedRoutes.join(", ")}):r("span",{className:"text-foreground-subtle",children:"—"})},{key:"tx",header:"TX / RX",render:a=>u("span",{className:"text-[10px] text-foreground-subtle font-mono",children:["↑ ",zf(a.txBytes)," · ↓ ",zf(a.rxBytes)]})},{key:"lastSeen",header:"Last seen",render:a=>r("span",{className:"text-[10px] text-foreground-subtle",children:a.lastSeenMs>0?m1(a.lastSeenMs):"—"})}],[o]);return t&&e.length===0?u("div",{className:"p-4 text-xs text-foreground-subtle",children:[r(Ee,{className:"h-3 w-3 animate-spin inline mr-1"})," Loading peers…"]}):e.length===0?r("div",{className:"p-4 text-xs text-foreground-subtle",children:"No peers visible — your tailnet may be empty or the host is not joined."}):r("div",{className:"p-4",children:r(Fa,{columns:s,rows:n,rowKey:a=>a._id,minWidthPx:820})})}function Vj(e){return e==="direct"?"success":e==="relay"?"warning":"info"}function zf(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function m1(e){const t=Date.now()-e;return t<6e4?"just now":t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function Uj(e){return new Promise(t=>setTimeout(t,e))}function qj(){return r("div",{className:"flex flex-col p-4",children:r(ui,{tabs:[{id:"addresses",label:"Network Addresses",icon:Rn,content:r(_j,{})},{id:"remote-access",label:"Remote Access",icon:Ln,content:r(vj,{})},{id:"mesh",label:"Mesh Networks",icon:ei,content:r(Rj,{})},{id:"turn",label:"TURN Servers",icon:Tn,content:r(Cj,{})}]})})}const Qj=[{kind:"device-export",tabId:"device-export",title:"Device export",subtitle:"Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).",icon:F8,emptyTitle:"No device-export providers installed",emptyDescription:"Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …",addLabel:"Add export"},{kind:"email",tabId:"email",title:"Email providers",subtitle:"Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).",icon:r8,emptyTitle:"No email providers installed",emptyDescription:"Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.",addLabel:"Add email provider"},{kind:"broker",tabId:"broker",title:"Brokers",subtitle:"Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).",icon:si,emptyTitle:"No brokers installed",emptyDescription:"Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.",addLabel:"Add broker"}];function Gj(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){const t=e.name;if(typeof t=="string")return t}return null}function Wj(e){const t=e,n=t?.manifest;if(!n?.id)return null;const o=[];for(const i of n.capabilities??[]){const l=Gj(i);l!==null&&o.push(l)}const s=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:s,isActive:a==="running",packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:o,processState:a}}function Kj(e,t){const n=new Set(t);return e.filter(o=>o.capNames.some(s=>n.has(s)))}function Yj(e){for(const[t,n]of Object.entries(ph))if(n===e)return t;return null}function Zj(e){return e==="running"?{label:"Running",className:"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300"}:e==="crashed"||e==="failed"?{label:e==="failed"?"Failed":"Crashed",className:"bg-danger/15 text-danger"}:e==="stopped"||e==="disabled"?{label:"Stopped",className:"bg-foreground-subtle/15 text-foreground-subtle"}:{label:e??"Unknown",className:"bg-foreground-subtle/15 text-foreground-subtle"}}function pu({label:e,className:t}){return r("span",{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function Xj({addonId:e}){const{data:t,isLoading:n}=_x({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;const o=m2.safeParse(t);if(!o.success)return null;const s=o.data,a=`${s.brokerCount} broker${s.brokerCount===1?"":"s"}${s.embeddedRunning?" • embedded up":""}`;return r(pu,{label:a,className:"bg-primary/10 text-primary"})}function Jj({addonId:e}){const{data:t,isLoading:n}=wd({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;const o=ch.safeParse(t);if(!o.success)return null;const s=o.data,a=s.linkState==="linked"?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":s.linkState==="error"?"bg-danger/15 text-danger":"bg-foreground-subtle/15 text-foreground-subtle",i=`${s.linkState} • ${s.exposedDeviceCount} exposed`;return r(pu,{label:i,className:a})}function eH({kind:e,addonId:t}){return e==="broker"?r(Xj,{addonId:t}):e==="device-export"?r(Jj,{addonId:t}):null}function tH({descriptor:e,rows:t,isLoading:n}){const o=Yj(e.kind),s=e.kind==="device-export",a=De(),i=at();return r(ss,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:o??e.kind,installButtonLabel:e.addLabel,items:t,isLoading:n,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:l=>{const c=Zj(l.processState);return u(me,{children:[r(pu,{label:c.label,className:c.className}),r(eH,{kind:e.kind,addonId:l.addonId})]})},renderExpandedPanel:s?l=>r(Vd,{addonId:l.addonId,trpc:a.trpcClient,onOpenDevice:c=>i(`/devices/${c}`)}):void 0,showChrome:!0})}function nH(){const e=Nn(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(Wj).filter(o=>o!==null),n=Qj.map(o=>{const s=Object.entries(ph).filter(([,a])=>a===o.kind).map(([a])=>a);return{id:o.tabId,label:o.title,icon:o.icon,content:r(tH,{descriptor:o,rows:Kj(t,s),isLoading:e.isLoading})}});return r(ot,{icon:Bo,title:"External systems",subtitle:"External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.",children:r(ui,{tabs:n})})}function rH(e){const t=e.basePath;if(typeof t=="string"&&t.length>0)return t;const n=Object.keys(e);return n.length===0?"":n.join(", ")}function oH({location:e,onEdit:t,onDelete:n,onSetDefault:o}){const s=rH(e.config);return u("div",{className:"flex items-center gap-3 px-3 py-2 border-t border-border first:border-t-0 hover:bg-primary/5",children:[u("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[r("div",{className:"w-[88px] shrink-0",children:e.isDefault?u("span",{className:"inline-flex items-center gap-0.5 rounded bg-primary/10 border border-primary/20 px-1.5 py-0.5 text-[10px] font-semibold text-primary uppercase tracking-wide",title:"Default location for this type",children:[r(Ki,{className:"h-2.5 w-2.5 fill-primary"}),"Default"]}):u("button",{onClick:()=>o(e),className:"inline-flex items-center gap-0.5 rounded border border-border px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 hover:border-primary/30 uppercase tracking-wide",title:"Promote to default for this type",children:[r(Ki,{className:"h-2.5 w-2.5"}),"Set default"]})}),r("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono",children:e.providerId}),e.isSystem&&r("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5",title:"System-managed location — cannot be deleted; edit config to relocate",children:"system"}),u("div",{className:"min-w-0",children:[r("div",{className:"text-xs font-medium text-foreground truncate",children:e.displayName}),s&&r("div",{className:"text-[10px] text-foreground-subtle truncate font-mono",children:s})]})]}),u("div",{className:"flex items-center gap-1 shrink-0",children:[!e.isDefault&&u("button",{onClick:()=>o(e),className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10",title:"Set as default for this type",children:[r(Ki,{className:"h-3 w-3"}),"Set default"]}),u("button",{onClick:()=>t(e),className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10",children:[r(ao,{className:"h-3 w-3"}),"Edit"]}),!e.isSystem&&Gs[e.type]!=="singleton"&&r("button",{onClick:()=>n(e),className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10",title:"Delete location",children:r(et,{className:"h-3 w-3"})})]})]})}function sH({type:e,displayName:t,description:n,locations:o,onAdd:s,onEdit:a,onDelete:i,onSetDefault:l}){const c=q(()=>{const d=[...o];return d.sort((p,f)=>p.isDefault!==f.isDefault?p.isDefault?-1:1:p.displayName.localeCompare(f.displayName)),d},[o]);return u("div",{className:"rounded-lg border border-border bg-surface",children:[u("div",{className:"flex items-start justify-between border-b border-border px-3 py-2",children:[u("div",{className:"space-y-0.5",children:[u("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-sm font-semibold text-foreground capitalize",children:t}),r("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono",children:e})]}),n&&r("p",{className:"text-[11px] text-foreground-subtle",children:n}),Gs[e]==="singleton"&&r("p",{className:"text-[10px] text-foreground-subtle italic",children:"Singleton — one location per type. Edit the existing entry; it can't be split."})]}),Gs[e]==="multi"&&u("button",{onClick:()=>s(e),className:"inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90",children:[r(It,{className:"h-3 w-3"}),"Add"]})]}),c.length===0?r("div",{className:"px-3 py-4 text-center text-[11px] text-foreground-subtle italic",children:Gs[e]==="multi"?'No location registered. Click "Add" to register one.':"No location registered yet — should be auto-seeded at next boot."}):r("div",{children:c.map(d=>r(oH,{location:d,onEdit:a,onDelete:i,onSetDefault:l},d.id))})]})}function aH(e){const t=e.trim().toLowerCase();return t.length===0?"":t.replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ff(e,t){const n=aH(t),o=n.length>0?n:"default";return`${e}:${o}`}function h1({initialType:e,onClose:t,onCreated:n}){const o=Me(),s=De().trpcClient,[a,i]=I("picker"),[l,c]=I(e),[d,p]=I(null),[f,m]=I({}),[h,g]=I(""),[x,b]=I(null),[y,w]=I(!1),[v,N]=I(null),[k,C]=I(!1),D=Pd(),M=q(()=>{const P=D.data;return Array.isArray(P)?P.filter(B=>B.supportedLocationTypes.includes(l)):[]},[D.data,l]),_=D.isLoading,$=Qa({onSuccess:()=>{o.invalidateQueries({queryKey:[["storage","listLocations"]]}),n()}}),E=q(()=>x!==null&&x.length>0?x:Ff(l,h),[l,h,x]),R=async()=>{if(d){C(!0),N(null);try{const B=await(z=>s.storage.testConfig.query(z))({providerId:d.providerId,config:f});N(B)}catch(P){N({ok:!1,error:P instanceof Error?P.message:String(P)})}finally{C(!1)}}},O=()=>{d&&$.mutate({id:E,type:l,displayName:h.trim(),providerId:d.providerId,config:f,isDefault:y})},A={picker:"Add Location — Pick provider",config:`Add Location — ${d?.displayName??""}`,naming:"Add Location — Name & defaults"};return r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:t,children:u("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl",onClick:P=>P.stopPropagation(),children:[u("div",{className:"flex items-start justify-between border-b border-border px-4 py-3",children:[u("div",{className:"space-y-0.5",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:A[a]}),u("p",{className:"text-xs text-foreground-subtle",children:["Type: ",r("span",{className:"font-mono",children:l})]})]}),r("button",{onClick:t,className:"text-foreground-subtle hover:text-foreground",children:r(Ve,{className:"h-4 w-4"})})]}),a==="picker"&&u("div",{className:"p-4 space-y-2",children:[_&&r("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading providers…"}),!_&&M.length===0&&u("div",{className:"rounded border border-border bg-background px-3 py-4 text-center text-xs text-foreground-subtle",children:['No storage-provider supports type "',l,'". Install a compatible addon (e.g. ',r("code",{className:"font-mono",children:"remote-storage"}),") to enable it."]}),M.map(P=>u("button",{onClick:()=>{p(P),i("config")},className:"flex w-full items-center gap-3 rounded-lg border border-border bg-background p-3 text-left hover:border-primary/40 hover:bg-primary/5 transition-colors",children:[u("div",{className:"flex-1 min-w-0",children:[r("p",{className:"text-xs font-semibold text-foreground",children:P.displayName}),r("p",{className:"text-[10px] text-foreground-subtle font-mono mt-0.5 truncate",children:P.providerId})]}),r(on,{className:"h-4 w-4 text-foreground-subtle flex-shrink-0"})]},P.providerId))]}),a==="config"&&d&&u("div",{className:"p-4 space-y-3 max-h-[60vh] overflow-y-auto",children:[r(On,{schema:d.configSchema,values:f,onChange:m}),v&&r("div",{className:`rounded border px-3 py-2 text-[11px] ${v.ok?"border-success/30 bg-success/5 text-success":"border-danger/30 bg-danger/5 text-danger"}`,children:v.ok?"Connection OK.":`Test failed: ${v.error??"unknown error"}`}),u("div",{className:"flex items-center justify-between pt-1",children:[r("button",{onClick:()=>i("picker"),className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Back"}),u("div",{className:"flex items-center gap-2",children:[r("button",{onClick:()=>{R()},disabled:k,className:"rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50",children:k?"Testing…":"Test connection"}),r("button",{onClick:()=>i("naming"),className:"rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:"Next"})]})]})]}),a==="naming"&&d&&u("div",{className:"p-4 space-y-3",children:[u("div",{className:"space-y-1",children:[r("label",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:"Display name"}),r("input",{type:"text",value:h,onChange:P=>g(P.target.value),placeholder:`${l} on ${d.displayName}`,className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary"})]}),u("div",{className:"space-y-1",children:[u("label",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:["Id ",r("span",{className:"lowercase tracking-normal text-foreground-subtle",children:"— auto-derived; override if needed"})]}),r("input",{type:"text",value:E,onChange:P=>b(P.target.value),placeholder:Ff(l,h),className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground font-mono focus:outline-none focus:ring-1 focus:ring-primary"}),u("p",{className:"text-[10px] text-foreground-subtle",children:["Format: ",r("code",{className:"font-mono",children:"<type>:<slug>"}),". Lowercase letters, digits, and hyphens only."]})]}),u("label",{className:"flex items-start gap-2 rounded border border-border bg-background px-3 py-2 cursor-pointer hover:bg-primary/5",children:[r("input",{type:"checkbox",checked:y,onChange:P=>w(P.target.checked),className:"accent-primary mt-0.5"}),u("div",{className:"space-y-0.5",children:[u("div",{className:"text-xs font-medium text-foreground",children:['Mark as default for type "',l,'"']}),u("div",{className:"text-[10px] text-foreground-subtle",children:["Setting this as default will demote the current default for this type. References like"," ",u("code",{className:"font-mono",children:['"',l,'"']})," resolve to whichever location is the default."]})]})]}),$.isError&&r("div",{className:"rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]",children:$.error instanceof Error?$.error.message:String($.error)}),u("div",{className:"flex items-center justify-between pt-1",children:[r("button",{onClick:()=>i("config"),className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Back"}),u("div",{className:"flex items-center gap-2",children:[r("button",{onClick:()=>{c(e),p(null),m({}),g(""),b(null),w(!1),N(null),i("picker")},className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Reset"}),u("button",{onClick:O,disabled:$.isPending||h.trim().length===0,className:"inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[$.isPending?r(Ee,{className:"h-3.5 w-3.5 animate-spin"}):null,$.isPending?"Saving…":"Save"]})]})]})]})]})})}function iH({location:e,onClose:t,onSaved:n}){const o=Me(),s=De().trpcClient,[a,i]=I({...e.config}),[l,c]=I(e.displayName),[d,p]=I(null),[f,m]=I(!1),h=Pd(),g=q(()=>{const w=h.data;return Array.isArray(w)?w.find(N=>N.providerId===e.providerId)??null:null},[h.data,e.providerId]),x=Qa({onSuccess:()=>{o.invalidateQueries({queryKey:[["storage","listLocations"]]}),n()}}),b=async()=>{m(!0),p(null);try{const v=await(N=>s.storage.testConfig.query(N))({providerId:e.providerId,config:a});p(v)}catch(w){p({ok:!1,error:w instanceof Error?w.message:String(w)})}finally{m(!1)}},y=()=>{x.mutate({id:e.id,type:e.type,providerId:e.providerId,isDefault:e.isDefault,displayName:l.trim(),config:a})};return r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:t,children:u("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl",onClick:w=>w.stopPropagation(),children:[u("div",{className:"flex items-start justify-between border-b border-border px-4 py-3",children:[u("div",{className:"space-y-0.5",children:[u("h2",{className:"text-sm font-semibold text-foreground",children:["Edit ",e.displayName]}),u("p",{className:"text-xs text-foreground-subtle",children:[r("span",{className:"font-mono",children:e.id})," · ",g?.displayName??e.providerId]})]}),r("button",{onClick:t,className:"text-foreground-subtle hover:text-foreground",children:r(Ve,{className:"h-4 w-4"})})]}),u("div",{className:"p-4 space-y-3 max-h-[60vh] overflow-y-auto",children:[u("div",{className:"space-y-1",children:[r("label",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:"Display name"}),r("input",{type:"text",value:l,onChange:w=>c(w.target.value),className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary"})]}),g&&r(On,{schema:g.configSchema,values:a,onChange:i}),!g&&!h.isLoading&&u("div",{className:"rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300",children:["Provider ",r("code",{className:"font-mono",children:e.providerId})," is no longer registered. Field schema unavailable; raw config is preserved on save."]}),d&&r("div",{className:`rounded border px-3 py-2 text-[11px] ${d.ok?"border-success/30 bg-success/5 text-success":"border-danger/30 bg-danger/5 text-danger"}`,children:d.ok?"Connection OK.":`Test failed: ${d.error??"unknown error"}`}),x.isError&&r("div",{className:"rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]",children:x.error instanceof Error?x.error.message:String(x.error)})]}),u("div",{className:"flex items-center justify-between gap-2 border-t border-border px-4 py-3",children:[r("button",{onClick:t,className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),u("div",{className:"flex items-center gap-2",children:[r("button",{onClick:()=>{b()},disabled:f||!g,className:"rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50",children:f?"Testing…":"Test connection"}),u("button",{onClick:y,disabled:x.isPending||l.trim().length===0,className:"inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[x.isPending?r(Ee,{className:"h-3.5 w-3.5 animate-spin"}):null,x.isPending?"Saving…":"Save"]})]})]})]})})}const lH={data:"Data",media:"Media",recordings:"Recordings","recordings-high":"Recordings (High)","recordings-low":"Recordings (Low)","recordings-clips":"Recordings (Clips)","event-images":"Event Images",models:"Models","addons-data":"Addons Data",cache:"Cache",logs:"Logs",backups:"Backups"},cH={backups:"Snapshot archives. Default landing for `backup-orchestrator`.",recordings:"Continuous recordings (combined high + low + clips when no slot is specified).","recordings-high":"High-quality continuous recordings.","recordings-low":"Low-quality continuous recordings.","recordings-clips":"Event clips (motion / detection triggers).","event-images":"Detection snapshots, thumbnails, and crops.",models:"ML model files. Read by inference-engine addons.",logs:"Long-term log archives."};function dH(){const e=Me(),t=st(),{data:n,isLoading:o,isError:s}=Py({}),[a,i]=I(null),[l,c]=I(null),d=_y({onSuccess:()=>{e.invalidateQueries({queryKey:[["storage","listLocations"]]})}}),p=Qa({onSuccess:()=>{e.invalidateQueries({queryKey:[["storage","listLocations"]]})}}),f=g=>{g.isDefault||p.mutate({id:g.id,type:g.type,providerId:g.providerId,displayName:g.displayName,config:g.config,isDefault:!0})},m=async g=>{if(g.isDefault){await t({title:"Cannot delete default location",message:`"${g.displayName}" is the default for type "${g.type}". Mark another location as default first, then delete this one.`,confirmLabel:"OK",variant:"warning"});return}await t({title:`Delete location "${g.displayName}"?`,message:"This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.",confirmLabel:"Delete",variant:"danger"})&&d.mutate({id:g.id})},h=q(()=>{const g=new Map;for(const x of ju)g.set(x,[]);for(const x of n??[]){const b=g.get(x.type);b?b.push(x):g.set(x.type,[x])}return g},[n]);return u(ot,{children:[o&&r("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading locations…"}),s&&r("div",{className:"text-xs text-danger",children:"Failed to load storage locations."}),!o&&!s&&r("div",{className:"space-y-3",children:ju.map(g=>r(sH,{type:g,displayName:lH[g],description:cH[g],locations:h.get(g)??[],onAdd:x=>i(x),onEdit:x=>c(x),onDelete:x=>{m(x)},onSetDefault:x=>f(x)},g))}),a!==null&&r(h1,{initialType:a,onClose:()=>i(null),onCreated:()=>{e.invalidateQueries({queryKey:[["storage","listLocations"]]}),i(null)}}),l!==null&&r(iH,{location:l,onClose:()=>c(null),onSaved:()=>{e.invalidateQueries({queryKey:[["storage","listLocations"]]}),c(null)}})]})}const uH=[["backup","listDestinations"]],pH=["backup","listArchives"];function fH({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){const o=Me(),s=st(),{data:a,isLoading:i,isError:l}=vd({destinationId:e}),c=a??[],d=Bb({onSuccess:()=>{o.invalidateQueries({queryKey:[[...pH]]}),o.invalidateQueries({queryKey:uH})}}),p=U(async x=>{await s({title:"Delete this archive?",message:`Permanently deletes "${x.label??x.id}" and frees ${Pt(x.sizeBytes)}.`,confirmLabel:"Delete",variant:"danger"})&&d.mutate({destinationId:e,backupId:x.id})},[s,e,d]),[f,m]=I(null),h=U(async x=>{m(x.id);try{const b=localStorage.getItem("camstack_admin_token"),y={};b&&(y.Authorization=`Bearer ${b}`);const w=await fetch(mH(e,x.id),{headers:y});if(!w.ok)throw new Error(`download failed: ${w.status} ${w.statusText}`);const v=await w.blob(),N=URL.createObjectURL(v),k=document.createElement("a");k.href=N,k.download=`${x.label??x.id}.tar.gz`,document.body.appendChild(k),k.click(),k.remove(),URL.revokeObjectURL(N)}finally{m(null)}},[e]),g=q(()=>[...c].sort((x,b)=>b.createdAt-x.createdAt),[c]);return i?r("div",{className:"text-xs text-foreground-subtle animate-pulse py-2",children:"Loading archives…"}):l?r("div",{className:"text-xs text-danger py-2",children:"Failed to read manifest for this destination"}):g.length===0?r("div",{className:"text-xs text-foreground-subtle italic py-2",children:"No archives at this destination yet."}):r("div",{className:"rounded border border-border bg-surface overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[640px]",children:[r("thead",{children:u("tr",{className:"text-foreground-subtle bg-background/30",children:[r("th",{className:"text-left px-3 py-1.5 font-medium",children:"When"}),r("th",{className:"text-left px-3 py-1.5 font-medium",children:"Label"}),r("th",{className:"text-left px-3 py-1.5 font-medium",children:"Includes"}),r("th",{className:"text-right px-3 py-1.5 font-medium",children:"Size"}),r("th",{className:"text-right px-3 py-1.5 font-medium w-52",children:"Actions"})]})}),r("tbody",{children:g.map(x=>u("tr",{className:"border-t border-border hover:bg-primary/5",children:[r("td",{className:"px-3 py-1.5 text-foreground tabular-nums",children:hH(x.createdAt)}),r("td",{className:"px-3 py-1.5 text-foreground",children:x.label??r("span",{className:"text-foreground-subtle italic",children:"—"})}),r("td",{className:"px-3 py-1.5 text-foreground-subtle",children:x.locations.join(", ")}),r("td",{className:"px-3 py-1.5 text-foreground text-right tabular-nums",children:Pt(x.sizeBytes)}),r("td",{className:"px-3 py-1.5",children:u("div",{className:"flex items-center justify-end gap-1",children:[u("button",{onClick:()=>{h(x)},disabled:f===x.id,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50",title:"Download archive",children:[f===x.id?r(Ee,{className:"h-3 w-3 animate-spin"}):r(bn,{className:"h-3 w-3"}),"Download"]}),t&&n&&u("button",{onClick:()=>n({destinationId:e,archiveId:x.id}),className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10",title:"Restore from this archive",children:[r(Yt,{className:"h-3 w-3"}),"Restore"]}),r("button",{onClick:()=>{p(x)},disabled:d.isPending,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50",title:"Delete archive",children:d.isPending?r(Ee,{className:"h-3 w-3 animate-spin"}):r(et,{className:"h-3 w-3"})})]})})]},x.id))})]})})}function mH(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function hH(e){return new Date(e).toLocaleString(void 0,{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})}const g1=[{id:"manual",label:"Manual only",cron:""},{id:"hourly",label:"Every hour",cron:"0 * * * *",description:"On the hour"},{id:"every-3h",label:"Every 3 hours",cron:"0 */3 * * *",description:"00:00, 03:00, 06:00, 09:00 …"},{id:"every-6h",label:"Every 6 hours",cron:"0 */6 * * *",description:"00:00, 06:00, 12:00, 18:00"},{id:"daily-3am",label:"Daily at 03:00",cron:"0 3 * * *",description:"Every night at 3 AM"},{id:"weekly-sun",label:"Weekly Sunday 03:00",cron:"0 3 * * 0",description:"Sunday morning at 3 AM"}];function gH(e){const t=e.trim();for(const n of g1)if(n.cron===t)return n.id;return"custom"}function bH({value:e,onChange:t,previewCount:n=5,disabled:o=!1}){const s=gH(e),[a,i]=I(s==="custom");J(()=>{s!=="custom"&&i(!1)},[s]);const l=vH(e,250),c=Fb({cron:l,count:n},{enabled:l.trim().length>0}),d=c.data??null,p=m=>{i(!1),t(m.cron)},f=a||s==="custom";return u("div",{className:"space-y-3",children:[u("div",{className:"space-y-1",children:[r("div",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:"Schedule preset"}),u("div",{className:"flex flex-wrap gap-1.5",children:[g1.map(m=>{const h=!a&&s===m.id;return r("button",{type:"button",onClick:()=>p(m),disabled:o,className:"rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 "+(h?"border-primary bg-primary/10 text-primary":"border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground"),title:m.description??m.label,children:m.label},m.id)}),r("button",{type:"button",onClick:()=>{i(!0),e.trim().length===0&&t("0 3 * * *")},disabled:o,className:"rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 "+(f?"border-primary bg-primary/10 text-primary":"border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground"),children:"Custom…"})]})]}),f&&u("div",{className:"space-y-1",children:[r("div",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:"Cron expression (5-field POSIX)"}),r("input",{type:"text",value:e,onChange:m=>t(m.target.value),disabled:o,placeholder:"0 3 * * *",spellCheck:!1,className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary"}),u("p",{className:"text-[10px] text-foreground-subtle",children:["Format: ",r("span",{className:"font-mono",children:"minute hour day-of-month month day-of-week"})," · all times server-local"]})]}),r(xH,{cron:l,preview:d,loading:c.isFetching})]})}function xH({cron:e,preview:t,loading:n}){return n&&t===null?u("div",{className:"flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle",children:[r(Ee,{className:"h-3 w-3 animate-spin"}),"Validating…"]}):t===null?null:t.ok?t.nextRuns.length===0?r("div",{className:"rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle",children:"No future runs match this expression."}):u("div",{className:"space-y-1",children:[r("div",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:"Next runs"}),r("ul",{className:"rounded border border-border bg-background/40 divide-y divide-border",children:t.nextRuns.map((o,s)=>u("li",{className:"flex items-center justify-between px-3 py-1.5 text-[11px]",children:[r("span",{className:"text-foreground tabular-nums",children:new Date(o).toLocaleString()}),r("span",{className:"text-foreground-subtle text-[10px] tabular-nums",children:yH(o)})]},`${o}-${s}`))})]}):r("div",{className:"rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger",children:t.error??"Invalid cron expression"})}function yH(e){const t=e-Date.now();if(t<=0)return"now";const n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;const o=Math.floor(n/60);if(o<60)return`in ${o}m`;const s=Math.floor(o/60);return s<24?`in ${s}h`:`in ${Math.floor(s/24)}d`}function vH(e,t){const[n,o]=I(e),s=q(()=>e,[e]);return J(()=>{const a=setTimeout(()=>o(s),t);return()=>clearTimeout(a)},[s,t]),n}const wH=[["backup","listDestinations"]];function NH({onCreateAt:e,onOpenRestoreWizard:t}){const{data:n,isLoading:o,isError:s}=yd(),a=n??[],[i,l]=I(null),c=p=>{l(f=>f===p?null:p)},d=AH();return o?r("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading destinations…"}):s?r("div",{className:"text-xs text-danger",children:"Failed to load destinations"}):a.length===0?r("div",{className:"rounded-lg border border-border bg-surface px-4 py-8 text-center",children:r("p",{className:"text-xs text-foreground-subtle",children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):r("div",{className:"rounded-lg border border-border bg-surface overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[720px]",children:[r("thead",{children:u("tr",{className:"text-foreground-subtle border-b border-border bg-background/40",children:[r("th",{className:"text-left px-3 py-2 font-medium w-6"}),r("th",{className:"text-left px-3 py-2 font-medium",children:"Destination"}),r("th",{className:"text-left px-3 py-2 font-medium w-20",children:"Enabled"}),r("th",{className:"text-left px-3 py-2 font-medium w-28",children:"Retention"}),r("th",{className:"text-left px-3 py-2 font-medium w-56",children:"Schedule"}),r("th",{className:"text-left px-3 py-2 font-medium w-44",children:"Last success"}),r("th",{className:"text-right px-3 py-2 font-medium w-44",children:"Actions"})]})}),r("tbody",{children:a.map(p=>{const f=d.get(p.id);return r(kH,{row:p,isOpen:i===p.id,onToggle:()=>c(p.id),onCreateAt:e,liveLastSuccessAt:f?.at,liveLastSuccessSizeBytes:f?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},p.id)})})]})})}function kH({row:e,isOpen:t,onToggle:n,onCreateAt:o,onOpenRestoreWizard:s,liveLastSuccessAt:a,liveLastSuccessSizeBytes:i}){const l=Me(),c=zb({onSuccess:()=>{l.invalidateQueries({queryKey:wH})}}),[d,p]=I(String(e.retentionCount));J(()=>{p(String(e.retentionCount))},[e.retentionCount]);const[f,m]=I(!1),h=U(b=>{c.mutate({locationId:e.id,enabled:b,retentionCount:e.retentionCount,...e.label!==void 0?{label:e.label}:{},...e.cron!==void 0?{cron:e.cron}:{}})},[c,e.id,e.retentionCount,e.label,e.cron]),g=U(()=>{const b=Number.parseInt(d,10);if(Number.isNaN(b)||b<1){p(String(e.retentionCount));return}b!==e.retentionCount&&c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:b,...e.label!==void 0?{label:e.label}:{},...e.cron!==void 0?{cron:e.cron}:{}})},[c,d,e.id,e.enabled,e.retentionCount,e.label,e.cron]),x=U(b=>{c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label!==void 0?{label:e.label}:{},cron:b},{onSuccess:()=>{m(!1)}})},[c,e.id,e.enabled,e.retentionCount,e.label]);return u(me,{children:[u("tr",{className:"border-t border-border first:border-t-0 hover:bg-primary/5",children:[r("td",{className:"px-2 py-2",children:r("button",{onClick:n,className:"inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground",title:t?"Hide archives":"Show archives",children:t?r(en,{className:"h-3.5 w-3.5"}):r(on,{className:"h-3.5 w-3.5"})})}),r("td",{className:"px-3 py-2",children:u("button",{onClick:n,className:"text-left hover:underline focus:outline-none",title:"View archives",children:[r("div",{className:"text-foreground font-medium",children:e.displayName}),u("div",{className:"flex items-center gap-1.5 mt-0.5",children:[r("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5",children:e.kind}),r("span",{className:"text-[10px] text-foreground-subtle font-mono",children:e.id})]})]})}),r("td",{className:"px-3 py-2",children:r("label",{className:"inline-flex items-center cursor-pointer",children:r("input",{type:"checkbox",className:"accent-primary",checked:e.enabled,disabled:c.isPending,onChange:b=>h(b.target.checked)})})}),r("td",{className:"px-3 py-2",children:r("input",{type:"number",min:1,max:1e3,value:d,disabled:c.isPending,onChange:b=>p(b.target.value),onBlur:g,onKeyDown:b=>{b.key==="Enter"&&b.target.blur(),b.key==="Escape"&&p(String(e.retentionCount))},className:"w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary"})}),r("td",{className:"px-3 py-2",children:r(SH,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>m(!0),disabled:c.isPending})}),r("td",{className:"px-3 py-2 text-foreground-subtle",children:(()=>{const b=EH(a,e.lastSuccessAt),y=b===a?i:e.lastSuccessSizeBytes;return b!==void 0?r(IH,{at:b,sizeBytes:y}):r("span",{className:"italic",children:"Never"})})()}),r("td",{className:"px-3 py-2",children:r("div",{className:"flex items-center justify-end gap-1.5",children:e.triggerSupported&&u("button",{onClick:()=>o(e),className:"inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90",children:[r(It,{className:"h-3 w-3"}),"Create here"]})})})]}),t&&r("tr",{className:"border-t border-border bg-background/30",children:r("td",{colSpan:7,className:"px-4 py-3",children:r(fH,{destinationId:e.id,restoreSupported:e.restoreSupported,...s?{onOpenRestoreWizard:s}:{}})})}),f&&r(MH,{destinationName:e.displayName,currentCron:e.cron??"",onSave:x,onClose:()=>m(!1),saving:c.isPending,saveError:c.error instanceof Error?c.error.message:null})]})}function SH({cron:e,nextRunAt:t,onEdit:n,disabled:o}){const s=typeof e=="string"&&e.trim().length>0;return u("button",{type:"button",onClick:n,disabled:o,className:"group flex flex-col items-start gap-0.5 text-left rounded px-1.5 py-1 -mx-1.5 hover:bg-primary/5 disabled:opacity-50",title:"Edit schedule",children:[u("div",{className:"flex items-center gap-1.5",children:[r(J6,{className:"h-3 w-3 text-foreground-subtle group-hover:text-foreground"}),r("span",{className:s?"font-mono text-foreground":"italic text-foreground-subtle",children:s?e:"Manual"})]}),s&&t!==void 0&&u("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:["next ",CH(t)]})]})}function CH(e){const t=e-Date.now();if(t<=0)return"imminent";const n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;const o=Math.floor(n/60);if(o<60)return`in ${o}m`;const s=Math.floor(o/60);return s<24?`in ${s}h`:`in ${Math.floor(s/24)}d`}function MH({destinationName:e,currentCron:t,onSave:n,onClose:o,saving:s,saveError:a}){const[i,l]=I(t);return r("tr",{children:r("td",{colSpan:7,className:"p-0",children:r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:o,children:u("div",{className:"w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl",onClick:c=>c.stopPropagation(),children:[u("div",{className:"flex items-start justify-between border-b border-border px-4 py-3",children:[u("div",{className:"space-y-0.5",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:"Schedule"}),u("p",{className:"text-xs text-foreground-subtle",children:["→ ",e]})]}),r("button",{onClick:o,className:"text-foreground-subtle hover:text-foreground",title:"Close",children:r(Ve,{className:"h-4 w-4"})})]}),u("div",{className:"p-4",children:[r(bH,{value:i,onChange:l,disabled:s}),a!==null&&r("div",{className:"mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger",children:a})]}),u("div",{className:"flex justify-end gap-2 border-t border-border px-4 py-3",children:[r("button",{onClick:o,disabled:s,className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground disabled:opacity-50",children:"Cancel"}),r("button",{onClick:()=>n(i.trim()),disabled:s||i.trim()===t.trim(),className:"inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:s?"Saving…":"Save"})]})]})})})})}function AH(){const{map:e}=od(Ce.BackupCompleted,t=>t.destinationId);return q(()=>{const t=new Map;for(const[n,o]of e)t.set(n,{at:Date.now(),sizeBytes:o.sizeMB*1024*1024});return t},[e])}function EH(e,t){return e===void 0?t:t===void 0||e>t?e:t}function IH({at:e,sizeBytes:t}){const n=PH(e),o=q(()=>new Date(e).toLocaleString(),[e]);return u("span",{title:o,className:"text-foreground tabular-nums",children:[n,t!==void 0&&u("span",{className:"ml-1 text-foreground-subtle",children:["· ",Pt(t)]})]})}function PH(e){const[,t]=I(0);return J(()=>{const n=setInterval(()=>t(o=>o+1),3e4);return()=>clearInterval(n)},[]),_H(e)}function _H(e){const t=Math.max(0,Date.now()-e),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const o=Math.floor(n/60);if(o<60)return`${o}m ago`;const s=Math.floor(o/60);if(s<24)return`${s}h ago`;const a=Math.floor(s/24);if(a<30)return`${a}d ago`;const i=Math.floor(a/30);return i<12?`${i}mo ago`:`${Math.floor(a/365)}y ago`}const $H=[["backup","list"]];function DH({initialDestinationId:e,initialArchiveId:t,onClose:n,onScheduled:o}){const s=Me(),[a,i]=I(e&&t?2:1),[l,c]=I(e),[d,p]=I(t),[f,m]=I(new Set),{data:h}=yd(),g=h??[],{data:x,isLoading:b}=vd({destinationId:l??""},{enabled:!!l}),y=x??[];J(()=>{if(l!==void 0)return;const $=g.filter(E=>E.restoreSupported);$.length===1&&c($[0].id)},[l,g]);const{data:w}=Rb({destinationId:l??"",backupId:d??""},{enabled:!!l&&!!d}),v=q(()=>w?.locations??[],[w]);J(()=>{v.length!==0&&m($=>$.size===0?new Set(v):$)},[v]);const N=Ob({onSuccess:()=>{s.invalidateQueries({queryKey:$H}),o(),n()}}),k=$=>{m(E=>{const R=new Set(E);return R.has($)?R.delete($):R.add($),R})},C=!!l&&!!d,D=f.size>0,M=C&&D&&!N.isPending,_=()=>{!l||!d||N.mutate({destinationId:l,backupId:d,locations:[...f]})};return r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:n,children:u("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl",onClick:$=>$.stopPropagation(),children:[u("div",{className:"flex items-start justify-between border-b border-border px-4 py-3",children:[u("div",{className:"space-y-0.5",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:"Restore Backup"}),u("p",{className:"text-xs text-foreground-subtle",children:["Step ",a," of 3 — ",a===1?"pick source":a===2?"pick locations":"confirm"]})]}),r("button",{onClick:n,className:"text-foreground-subtle hover:text-foreground",children:r(Ve,{className:"h-4 w-4"})})]}),a===1&&r(LH,{destinations:g,destinationId:l,onPickDestination:$=>{c($),p(void 0),m(new Set)},archives:y,archivesLoading:b,archiveId:d,onPickArchive:p}),a===2&&r(TH,{locations:v,picked:f,onToggle:k}),a===3&&r(RH,{destinationName:g.find($=>$.id===l)?.displayName??l??"",archive:y.find($=>$.id===d),picked:[...f]}),u("div",{className:"flex justify-between gap-2 border-t border-border px-4 py-3",children:[r("div",{children:a>1&&u("button",{onClick:()=>i($=>$===3?2:1),className:"inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:[r(ou,{className:"h-3 w-3"}),"Back"]})}),u("div",{className:"flex items-center gap-2",children:[r("button",{onClick:n,className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),a<3?u("button",{disabled:a===1&&!C||a===2&&!D,onClick:()=>i($=>$===1?2:3),className:"inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:["Next",r(H6,{className:"h-3 w-3"})]}):u("button",{onClick:_,disabled:!M,className:"inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[N.isPending?r(Ee,{className:"h-3.5 w-3.5 animate-spin"}):r(Yt,{className:"h-3.5 w-3.5"}),"Schedule Restore"]})]})]})]})})}function LH({destinations:e,destinationId:t,onPickDestination:n,archives:o,archivesLoading:s,archiveId:a,onPickArchive:i}){const l=e.filter(c=>c.restoreSupported);return u("div",{className:"p-4 space-y-3",children:[u("div",{className:"space-y-1.5",children:[r("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Destination"}),u("select",{value:t??"",onChange:c=>n(c.target.value),className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary",children:[r("option",{value:"",disabled:!0,children:"Select destination…"}),l.map(c=>u("option",{value:c.id,children:[c.displayName," (",c.kind,")"]},c.id))]})]}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Archive"}),!t&&r("div",{className:"text-xs text-foreground-subtle italic",children:"Pick a destination first."}),t&&s&&r("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Reading archives…"}),t&&!s&&o.length===0&&r("div",{className:"text-xs text-foreground-subtle italic",children:"No archives available at this destination."}),t&&o.length>0&&r("div",{className:"rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto",children:o.map(c=>{const d=a===c.id;return u("label",{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${d?"bg-primary/10":"hover:bg-primary/5"}`,children:[u("div",{className:"flex items-center gap-2",children:[r("input",{type:"radio",name:"archive",checked:d,onChange:()=>i(c.id),className:"accent-primary"}),u("div",{children:[r("div",{className:"font-medium text-foreground",children:c.label??c.id}),r("div",{className:"text-[10px] text-foreground-subtle",children:new Date(c.createdAt).toLocaleString()})]})]}),r("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:Pt(c.sizeBytes)})]},c.id)})})]})]})}function TH({locations:e,picked:t,onToggle:n}){return e.length===0?r("div",{className:"p-4",children:r("div",{className:"text-xs text-foreground-subtle",children:"Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball."})}):u("div",{className:"p-4 space-y-3",children:[r("div",{className:"rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300",children:"Selected entries will overwrite live data on the next server restart. Unchecked entries stay current."}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Apply"}),r("div",{className:"rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto",children:e.map(o=>u("label",{className:"flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer",children:[r("input",{type:"checkbox",checked:t.has(o),onChange:()=>n(o),className:"accent-primary"}),r("span",{className:"font-mono text-foreground",children:o}),r("span",{className:"ml-auto text-[10px] text-foreground-subtle",children:BH(o)})]},o))})]})]})}function RH({destinationName:e,archive:t,picked:n}){return u("div",{className:"p-4 space-y-3 text-xs",children:[r("div",{className:"rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300",children:"Restore is applied at next server boot. Active connections will drop when you restart."}),u("dl",{className:"space-y-1.5",children:[r(Rs,{term:"Destination",value:e}),r(Rs,{term:"Archive",value:t?.label??t?.id??"—"}),t&&r(Rs,{term:"Created",value:`${new Date(t.createdAt).toLocaleString()} · ${Pt(t.sizeBytes)}`}),r(Rs,{term:"Locations",value:n.length>0?n.join(", "):"— (full archive)"})]})]})}function Rs({term:e,value:t}){return u("div",{className:"flex justify-between gap-3",children:[r("dt",{className:"text-foreground-subtle",children:e}),r("dd",{className:"text-foreground font-mono text-right truncate",children:t})]})}const OH={db:"Database",addons:"Addon configs","addons-data":"Addon data",tls:"TLS certificates",cache:"Cache",data:"Top-level data"};function BH(e){return OH[e]??""}const zH=[["backup","list"]],FH=[["backup","listLocations"]];function jH(){const e=Me(),t=st(),{data:n}=Tb(),o=Lb({onSuccess:()=>{e.invalidateQueries({queryKey:zH}),e.invalidateQueries({queryKey:[["backup","listDestinations"]]}),e.invalidateQueries({queryKey:[["backup","listArchives"]]})}}),s=pb(),[a,i]=I(null),[l,c]=I(null),[d,p]=I(!1),[f,m]=I(!1),[h,g]=I(!1),x=async()=>{await t({title:"Restart server now?",message:"Active connections will drop and the apply-backup hook will run before boot.",confirmLabel:"Restart",variant:"warning"})&&s.mutate({confirm:!0})};return u(ot,{children:[u("div",{className:"flex items-center justify-end gap-2 flex-wrap",children:[u("button",{onClick:()=>p(!0),className:"inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30",children:[r(Yt,{className:"h-3.5 w-3.5"}),"Restore…"]}),u("button",{onClick:()=>g(!0),className:"inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:[r(It,{className:"h-3.5 w-3.5"}),"Add destination"]})]}),f&&r("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300",children:u("div",{className:"flex items-center justify-between gap-3",children:[u("div",{className:"flex items-center gap-2",children:[r(Yt,{className:"h-3.5 w-3.5"}),r("span",{children:"Restore scheduled. Restart the server to apply."})]}),u("button",{onClick:()=>{x()},disabled:s.isPending,className:"inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50",children:[s.isPending?r(Ee,{className:"h-3.5 w-3.5 animate-spin"}):r(Yt,{className:"h-3.5 w-3.5"}),"Restart Now"]})]})}),r(NH,{onCreateAt:b=>i(b),onOpenRestoreWizard:b=>c(b)}),a&&r(HH,{destination:a,locations:n??[],onClose:()=>i(null),onSubmit:(b,y)=>{o.mutate({destinations:[a.id],locations:b,label:y||void 0},{onSuccess:()=>{i(null),e.invalidateQueries({queryKey:FH})}})},submitting:o.isPending}),(l||d)&&r(DH,{...l?{initialDestinationId:l.destinationId,initialArchiveId:l.archiveId}:{},onClose:()=>{c(null),p(!1)},onScheduled:()=>m(!0)}),h&&r(h1,{initialType:"backups",onClose:()=>g(!1),onCreated:()=>{g(!1),e.invalidateQueries({queryKey:[["backup","listDestinations"]]})}})]})}function HH({destination:e,locations:t,onClose:n,onSubmit:o,submitting:s}){const a=t.filter(f=>f.present),[i,l]=I(""),[c,d]=I(()=>new Set(a.map(f=>f.name))),p=f=>{d(m=>{const h=new Set(m);return h.has(f)?h.delete(f):h.add(f),h})};return r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:n,children:u("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl",onClick:f=>f.stopPropagation(),children:[u("div",{className:"flex items-start justify-between border-b border-border px-4 py-3",children:[u("div",{className:"space-y-0.5",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:"Create Backup"}),u("p",{className:"text-xs text-foreground-subtle",children:["→ ",e.displayName]})]}),r("button",{onClick:n,className:"text-foreground-subtle hover:text-foreground",children:r(Ve,{className:"h-4 w-4"})})]}),u("div",{className:"p-4 space-y-3",children:[u("div",{className:"space-y-1",children:[r("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Label (optional)"}),r("input",{type:"text",value:i,onChange:f=>l(f.target.value),placeholder:"pre-upgrade",className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary"})]}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Include"}),u("div",{className:"rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto",children:[a.length===0&&r("div",{className:"px-3 py-2 text-xs text-foreground-subtle italic",children:"Nothing to back up."}),a.map(f=>u("label",{className:"flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer",children:[u("div",{className:"flex items-center gap-2",children:[r("input",{type:"checkbox",checked:c.has(f.name),onChange:()=>p(f.name),className:"accent-primary"}),r("span",{className:"font-mono text-foreground",children:f.name})]}),u("div",{className:"text-[10px] text-foreground-subtle tabular-nums",children:[Pt(f.sizeBytes)," · ",f.fileCount," files"]})]},f.name))]})]})]}),u("div",{className:"flex justify-end gap-2 border-t border-border px-4 py-3",children:[r("button",{onClick:n,className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),u("button",{onClick:()=>o(Array.from(c),i.trim()),disabled:s||c.size===0,className:"inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[s?r(Ee,{className:"h-3.5 w-3.5 animate-spin"}):r(lv,{className:"h-3.5 w-3.5"}),s?"Creating…":"Create"]})]})]})})}function VH(){return r("div",{className:"flex flex-col p-4",children:r(ui,{tabs:[{id:"storage",label:"Storage",icon:ga,content:r(dH,{})},{id:"backup",label:"Backup",icon:lv,content:r(jH,{})}]})})}function UH(){const{data:e,isLoading:t}=Hn(void 0,{staleTime:3e4}),n=(e??[]).find(s=>s.isHub&&s.isOnline),o=n?.addons.map(s=>s.id)??[];return r(ot,{children:t?r("div",{className:"text-muted-foreground text-sm py-12 text-center",children:"Loading hub topology…"}):n?o.length===0?r("div",{className:"text-muted-foreground text-sm py-12 text-center",children:"No addons installed on the hub yet."}):r(io,{nodeId:n.id,addonIds:o,level:"global"}):u("div",{className:"flex flex-col items-center justify-center text-muted-foreground text-sm gap-2 py-12",children:[r(tn,{className:"h-8 w-8 opacity-30"}),r("p",{children:"No online hub node found."}),r("p",{className:"text-xs",children:"Settings will appear once the hub is reachable."})]})})}function qH(e){const t=new FormData;return t.append("file",e.file,e.file.name),t.append("nodeId",e.nodeId),e.addonId&&t.append("addonId",e.addonId),new Promise((n,o)=>{const s=new XMLHttpRequest;s.open("POST","/api/addons/upload"),e.token&&s.setRequestHeader("Authorization",`Bearer ${e.token}`),s.upload.addEventListener("progress",a=>{a.lengthComputable&&e.onProgress(Math.round(a.loaded/a.total*100))}),s.addEventListener("load",()=>{let a;try{a=JSON.parse(s.responseText)}catch{o(new Error(`HTTP ${s.status}`));return}s.status>=200&&s.status<300?n(a):o(new Error(a.error??`HTTP ${s.status}`))}),s.addEventListener("error",()=>o(new Error("Network error during upload"))),s.addEventListener("abort",()=>o(new Error("Upload aborted"))),s.send(t)})}function QH({nodeId:e,addons:t,isHub:n}){const o=Me(),s=st(),[a,i]=I(null),[l,c]=I(null),[d,p]=I(!1),[f,m]=I(null),[h,g]=I(0),x=ne(null),b=Ua(),y=Rx(),w=jx({nodeId:e}),v=w.data??[],N=new Map(t.map(E=>[E.id,E.capabilities])),k=v.length>0?v.map(E=>({id:E.id,status:E.status,capabilities:N.get(E.id)??[],version:E.version,packageName:E.packageName})):t.map(E=>({id:E.id,status:E.status,capabilities:E.capabilities,version:void 0,packageName:void 0})),C=()=>{o.invalidateQueries({queryKey:[["nodes","topology"]]}),w.refetch()},D=async E=>{i(E);try{await b.mutateAsync({nodeId:e,addonId:E}),C()}catch(R){console.error("Failed to restart addon:",R)}finally{i(null)}},M=async E=>{if(await s({title:"Uninstall addon",message:`Remove "${E}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:"Uninstall",variant:"danger"})){c(E);try{await y.mutateAsync({nodeId:e,addonId:E}),C()}catch(O){console.error("Failed to uninstall addon:",O)}finally{c(null)}}},$=u("div",{className:"flex items-center gap-2 mb-2",children:[r("input",{ref:x,type:"file",accept:".tgz,.tar.gz",className:"hidden",onChange:async E=>{const R=E.target.files?.[0];if(R){E.target.value="",m(null),p(!0),g(0);try{const O=localStorage.getItem("camstack_admin_token");await qH({file:R,nodeId:e,token:O,onProgress:g}),C()}catch(O){m(O instanceof Error?O.message:String(O))}finally{p(!1),g(0)}}}}),u("button",{onClick:()=>x.current?.click(),disabled:d,className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50",children:[d?r(Ee,{className:"h-3 w-3 animate-spin"}):r(ai,{className:"h-3 w-3"}),d?`Uploading… ${h}%`:"Upload addon (.tgz)"]}),d&&r("div",{className:"flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]",children:r("div",{className:"h-full bg-primary transition-all",style:{width:`${h}%`}})}),f&&r("span",{className:"text-[10px] text-destructive",children:f})]});return k.length===0?u("div",{children:[$,r("div",{className:"py-4 text-xs text-muted-foreground text-center",children:w.isLoading?"Loading addons…":"No addons on this node"})]}):u("div",{children:[$,u("table",{className:"w-full text-xs",children:[r("thead",{children:u("tr",{className:"text-muted-foreground text-left",children:[r("th",{className:"py-2 font-medium",children:"Addon"}),r("th",{className:"py-2 font-medium",children:"Version"}),r("th",{className:"py-2 font-medium",children:"Capabilities"}),r("th",{className:"py-2 font-medium",children:"Status"}),r("th",{className:"py-2 font-medium w-16"})]})}),r("tbody",{children:k.map(E=>u("tr",{className:"border-t border-border/50",children:[u("td",{className:"py-2 font-medium",children:[r("div",{children:E.id}),E.packageName&&r("div",{className:"text-[9px] text-muted-foreground",children:E.packageName})]}),r("td",{className:"py-2 text-muted-foreground",children:E.version??"—"}),r("td",{className:"py-2",children:r("div",{className:"flex flex-wrap gap-1",children:E.capabilities.length>0?E.capabilities.map(R=>r("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400",children:R},R)):r("span",{className:"text-muted-foreground",children:"—"})})}),r("td",{className:"py-2",children:r("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full ${E.status==="running"?"bg-success/10 text-success":E.status==="error"?"bg-destructive/10 text-destructive":"bg-muted text-muted-foreground"}`,children:E.status})}),r("td",{className:"py-2",children:u("div",{className:"flex items-center gap-1 justify-end",children:[r("button",{onClick:()=>D(E.id),disabled:a===E.id||l===E.id,className:"p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",title:`Restart ${E.id}`,children:r(Yt,{className:`h-3 w-3 ${a===E.id?"animate-spin":""}`})}),r("button",{onClick:()=>M(E.id),disabled:a===E.id||l===E.id,className:"p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50",title:`Uninstall ${E.id}`,children:l===E.id?r(Ee,{className:"h-3 w-3 animate-spin"}):r(et,{className:"h-3 w-3"})})]})})]},E.id))})]})]})}function GH(e){if(e<60)return`${e}s`;const t=Math.floor(e/60);if(t<60)return`${t}m`;const n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function WH({state:e}){return r("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e==="running"?"bg-success/10 text-success":e==="crashed"||e==="failed"?"bg-destructive/10 text-destructive":"bg-muted text-muted-foreground"}`,children:e})}const KH=["trace","debug","info","warn","error"];function YH({proc:e,nodeId:t,defaultExpanded:n,activePanel:o,onTogglePanel:s}){const a=e.services??[],i=a.length===1,[l,c]=I(i||n),[d,p]=I(null),[f,m]=I("info"),h=e.name.includes("(core)"),g=Ua(),x=Ox(),b=Hx(),y=async N=>{p(N);try{await g.mutateAsync({nodeId:t,addonId:N})}catch(k){console.error("Failed to restart addon:",k)}finally{p(null)}},w=async()=>{p(e.name);try{await x.mutateAsync({nodeId:t,processName:e.name})}catch(N){console.error("Failed to restart process:",N)}finally{p(null)}},v=async N=>{const k=`${t}/${e.name}`;try{await b.mutateAsync({nodeId:k,level:N}),m(N)}catch(C){console.error("Failed to set log level:",C)}};return u("div",{className:"border border-border/50 rounded-lg overflow-hidden",children:[u("div",{role:i?void 0:"button",tabIndex:i?void 0:0,onClick:i?void 0:()=>c(!l),onKeyDown:i?void 0:N=>{(N.key==="Enter"||N.key===" ")&&c(!l)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${i?"":"hover:bg-muted/40 cursor-pointer"}`,children:[i?r("span",{className:"h-3 w-3 shrink-0"}):l?r(en,{className:"h-3 w-3 text-muted-foreground shrink-0"}):r(on,{className:"h-3 w-3 text-muted-foreground shrink-0"}),h?r(Rn,{className:"h-3.5 w-3.5 text-primary shrink-0"}):r(su,{className:"h-3.5 w-3.5 text-amber-500 shrink-0"}),r("span",{className:"text-xs font-semibold flex-1",children:e.name}),u("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:["PID ",e.pid]}),r(WH,{state:e.state}),u("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:[e.cpuPercent,"% CPU"]}),r("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:Pt(e.memoryRss)}),r("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:GH(e.uptimeSeconds)}),!h&&u("div",{className:"flex items-center gap-1",onClick:N=>N.stopPropagation(),children:[u(fg,{children:[r(mg,{className:"text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono",title:"Set log level",children:f}),r(hg,{align:"end",className:"min-w-[70px] py-0.5",children:KH.map(N=>r(gg,{onClick:()=>v(N),className:`h-auto px-2 py-1 text-[10px] font-mono ${N===f?"text-primary font-semibold":""}`,children:N},N))})]}),r("button",{onClick:w,disabled:d===e.name,className:"p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",title:"Restart process",children:r(Yt,{className:`h-3 w-3 ${d===e.name?"animate-spin":""}`})})]})]}),l&&a.length>0&&r("div",{className:"divide-y divide-border/30",children:a.map(N=>u("div",{children:[u("div",{className:"flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors",children:[r("div",{className:`h-1.5 w-1.5 rounded-full shrink-0 ${N.status==="running"?"bg-success":"bg-muted-foreground/30"}`}),r("span",{className:"text-xs font-medium flex-1 min-w-0 truncate",children:N.addonId}),N.capabilities.length>0&&u("div",{className:"flex gap-1 flex-shrink-0",children:[N.capabilities.slice(0,3).map(k=>r("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]",children:k},k)),N.capabilities.length>3&&u("span",{className:"text-[9px] text-muted-foreground",children:["+",N.capabilities.length-3]})]}),u("div",{className:"flex items-center gap-1 shrink-0",children:[r("button",{onClick:()=>s(N.addonId,"logs"),className:`p-0.5 rounded transition-colors ${o?.addonId===N.addonId&&o.type==="logs"?"bg-primary/10 text-primary":"hover:bg-muted text-muted-foreground hover:text-foreground"}`,title:`Show logs for ${N.addonId}`,children:r(At,{className:"h-3 w-3"})}),r("button",{onClick:()=>s(N.addonId,"events"),className:`p-0.5 rounded transition-colors ${o?.addonId===N.addonId&&o.type==="events"?"bg-primary/10 text-primary":"hover:bg-muted text-muted-foreground hover:text-foreground"}`,title:`Show events for ${N.addonId}`,children:r(si,{className:"h-3 w-3"})}),r("button",{onClick:()=>y(N.addonId),disabled:d===N.addonId,className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",title:`Restart ${N.addonId}`,children:r(Yt,{className:`h-3 w-3 ${d===N.addonId?"animate-spin":""}`})})]})]}),o?.addonId===N.addonId&&o.type==="logs"&&r("div",{className:"border-t border-border/40 bg-muted/5",children:r(rn,{addonId:N.addonId,agentId:t,maxHeight:"max-h-48",showFilters:!1,onClose:()=>s(N.addonId,"logs")})}),o?.addonId===N.addonId&&o.type==="events"&&r("div",{className:"border-t border-border/40 bg-muted/5",children:r(hr,{addonId:N.addonId,category:"addon.*",maxHeight:"max-h-48",onClose:()=>s(N.addonId,"events")})})]},N.addonId))}),l&&a.length===0&&r("div",{className:"px-3 py-2 pl-9 text-[10px] text-muted-foreground",children:"No services"})]})}function ZH({nodeId:e,processes:t}){const[n,o]=I(null),s=(a,i)=>{o(l=>l?.addonId===a&&l.type===i?null:{addonId:a,type:i})};return t.length===0?r("div",{className:"py-4 text-xs text-muted-foreground text-center",children:"No processes on this node"}):r("div",{className:"space-y-2 py-1",children:t.map((a,i)=>r(YH,{proc:a,nodeId:e,defaultExpanded:i===0,activePanel:n,onTogglePanel:s},a.name))})}function XH(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function JH(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function eV({nodeId:e}){const t=Me(),n=st(),[o,s]=I("all"),a=Jr("metrics.node-processes-snapshot",k=>k.nodeId===e),{data:i}=Ix({nodeId:e},{staleTime:6e4}),l=a?.processes??i,c=q(()=>l?[...l]:[],[l]),d=q(()=>o==="ghost"?c.filter(k=>k.classification==="ghost"):c,[c,o]),p=q(()=>{const k=c.filter(D=>D.classification==="ghost"),C=new Map;for(const D of k)C.has(D.ppid)||C.set(D.ppid,[]),C.get(D.ppid).push(D);return[...C.entries()].filter(([,D])=>D.length>1).map(([D,M])=>({ppid:D,children:M})).sort((D,M)=>M.children.length-D.children.length)},[c]),f=Px({onSettled:()=>{t.invalidateQueries({queryKey:[["metricsProvider","listNodeProcesses"]]})}}),m=q(()=>{const k=new Map;for(const C of c)k.set(C.pid,C.classification);return k},[c]),h=async(k,C)=>{if(k.classification==="root"||k.classification==="system")return;const D=k.classification==="ghost"?"ghost":k.addonId??"process",M=C?"SIGKILL":"SIGTERM";await n({title:`Send ${M}?`,message:`Target pid ${k.pid} (${D}) on node ${e}.`,confirmLabel:`Send ${M}`,variant:"danger"})&&f.mutate({nodeId:e,pid:k.pid,force:C})},g=async(k,C)=>{try{await f.mutateAsync({nodeId:e,pid:k,force:C})}catch{}},x=async k=>{const C=m.get(k.ppid);if(C==="root"||C==="system"){await n({title:"Cannot kill protected ancestor",message:C==="root"?`pid ${k.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${k.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:"OK",cancelLabel:"Close",variant:"warning"});return}await n({title:`Kill ghost parent + ${k.children.length} child(ren)?`,message:`SIGKILL parent pid ${k.ppid} and SIGTERM ${k.children.length} ghost child(ren) on node ${e}.`,confirmLabel:"Kill all",variant:"danger"})&&(await Promise.all([g(k.ppid,!0),...k.children.map(M=>g(M.pid,!1))]),t.invalidateQueries({queryKey:[["metricsProvider","listNodeProcesses"]]}))},b=async()=>{const k=c.filter(D=>D.classification==="ghost");k.length===0||!await n({title:`Kill all ${k.length} ghost process(es)?`,message:`SIGKILL ${k.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:"Kill all",variant:"danger"})||(await Promise.all(k.map(D=>g(D.pid,!0))),t.invalidateQueries({queryKey:[["metricsProvider","listNodeProcesses"]]}))},y=c.filter(k=>k.classification==="ghost").length,w=c.filter(k=>k.classification==="managed").length,v=c.filter(k=>k.classification==="root").length,N=c.filter(k=>k.classification==="system").length;return u("div",{className:"space-y-4",children:[u("div",{className:"flex items-start justify-between gap-4",children:[u("p",{className:"text-[11px] text-foreground-subtle",children:["ps"," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),u("button",{type:"button",onClick:()=>t.invalidateQueries({queryKey:[["metricsProvider","listNodeProcesses"]]}),className:"inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover",children:[r(ct,{className:"h-3 w-3"})," Refresh"]})]}),u("div",{className:"grid grid-cols-4 gap-3",children:[u("div",{className:"rounded-lg border border-border p-3",children:[r("div",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:"Root"}),r("div",{className:"text-xl font-semibold text-foreground",children:v})]}),u("div",{className:"rounded-lg border border-border p-3",children:[r("div",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:"Managed"}),r("div",{className:"text-xl font-semibold text-foreground",children:w})]}),u("div",{className:"rounded-lg border border-border p-3",children:[r("div",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:"System"}),r("div",{className:"text-xl font-semibold text-foreground",children:N})]}),u("div",{className:`rounded-lg border p-3 ${y>0?"border-destructive/40 bg-destructive/5":"border-border"}`,children:[u("div",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1",children:[y>0&&r(Is,{className:"h-3 w-3 text-destructive"})," Ghosts"]}),r("div",{className:`text-xl font-semibold ${y>0?"text-destructive":"text-foreground"}`,children:y})]})]}),p.length>0&&u("div",{className:"rounded-lg border border-amber-500/40 bg-amber-500/5 p-3",children:[u("div",{className:"flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2",children:[r(pt,{className:"h-3 w-3"})," Recurring ghost parents (",p.length,")"]}),r("div",{className:"space-y-1.5",children:p.map(k=>u("div",{className:"text-[11px] text-foreground flex items-center justify-between gap-2",children:[u("div",{className:"flex items-center gap-2",children:[u("span",{className:"font-mono text-foreground-subtle",children:["ppid ",k.ppid]}),u("span",{children:["→ ",k.children.length," ghost(s)"]})]}),u("button",{type:"button",disabled:f.isPending,onClick:()=>{x(k)},className:"inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30",children:[r(Is,{className:"h-3 w-3"})," Kill parent + ",k.children.length]})]},k.ppid))})]}),u("div",{className:"flex items-center justify-between gap-2 text-[11px]",children:[u("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-foreground-subtle",children:"Filter:"}),u("button",{type:"button",className:`px-2 py-0.5 rounded ${o==="all"?"bg-primary text-primary-foreground":"border border-border text-foreground hover:bg-surface-hover"}`,onClick:()=>s("all"),children:["All (",c.length,")"]}),u("button",{type:"button",className:`px-2 py-0.5 rounded ${o==="ghost"?"bg-destructive text-destructive-foreground":"border border-border text-foreground hover:bg-surface-hover"}`,onClick:()=>s("ghost"),children:["Ghost only (",y,")"]})]}),y>0&&u("button",{type:"button",disabled:f.isPending,onClick:()=>{b()},className:"inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30",children:[r(Is,{className:"h-3 w-3"})," Kill all ",y," ghost(s)"]})]}),r("div",{className:"rounded-lg border border-border overflow-x-auto",children:u("table",{className:"w-full text-xs",children:[r("thead",{className:"bg-surface",children:u("tr",{className:"text-foreground-subtle text-[10px] uppercase tracking-wider",children:[r("th",{className:"text-left px-3 py-2",children:"Class"}),r("th",{className:"text-right px-3 py-2",children:"PID"}),r("th",{className:"text-right px-3 py-2",children:"PPID"}),r("th",{className:"text-left px-3 py-2",children:"Addon"}),r("th",{className:"text-left px-3 py-2",children:"Command"}),r("th",{className:"text-right px-3 py-2",children:"CPU%"}),r("th",{className:"text-right px-3 py-2",children:"RSS"}),r("th",{className:"text-right px-3 py-2",children:"Uptime"}),r("th",{className:"w-44"})]})}),u("tbody",{children:[d.length===0&&r("tr",{children:r("td",{colSpan:9,className:"px-3 py-4 text-center text-foreground-subtle text-[11px]",children:o==="ghost"?"No ghost processes detected.":"Scanning…"})}),d.map(k=>u("tr",{className:`border-t border-border ${k.classification==="ghost"?"bg-destructive/5":""}`,children:[r("td",{className:"px-3 py-2",children:r("span",{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${k.classification==="ghost"?"bg-destructive/20 text-destructive":k.classification==="root"?"bg-sky-500/20 text-sky-400":k.classification==="system"?"bg-foreground-subtle/20 text-foreground-subtle":"bg-success/20 text-success"}`,children:k.classification})}),r("td",{className:"px-3 py-2 text-right font-mono text-foreground",children:k.pid}),u("td",{className:"px-3 py-2 text-right font-mono text-foreground-subtle",children:[k.ppid,k.orphaned?" ⚠":""]}),r("td",{className:"px-3 py-2 text-foreground-subtle text-[11px]",children:k.addonId??"—"}),r("td",{className:"px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all",children:JH(k.command)}),r("td",{className:"px-3 py-2 text-right text-foreground",children:k.cpuPercent.toFixed(1)}),r("td",{className:"px-3 py-2 text-right text-foreground",children:Pt(k.memoryRssBytes)}),r("td",{className:"px-3 py-2 text-right text-foreground-subtle",children:XH(k.uptimeSec)}),r("td",{className:"px-3 py-2 text-right",children:u("div",{className:"inline-flex gap-1",children:[u("button",{type:"button",disabled:f.isPending||k.classification==="root"||k.classification==="system",onClick:()=>{h(k,!1)},title:"SIGTERM",className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30",children:[r(et,{className:"h-3 w-3"})," Term"]}),u("button",{type:"button",disabled:f.isPending||k.classification==="root"||k.classification==="system",onClick:()=>{h(k,!0)},title:"SIGKILL",className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30",children:[r(Is,{className:"h-3 w-3"})," Kill"]})]})})]},k.pid))]})]})}),f.isError&&u("div",{className:"rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive",children:["Kill failed: ",f.error instanceof Error?f.error.message:"unknown"]})]})}function tV({nodeId:e,addonIds:t}){return t.length===0?r("div",{className:"py-4 text-xs text-muted-foreground text-center",children:"No addons on this node"}):r("div",{className:"w-full py-2",children:r(io,{nodeId:e,addonIds:t,level:"global"})})}function nV({nodeId:e,addons:t}){const n=Me(),{data:o,isLoading:s}=ey({nodeId:e}),a=q(()=>{const l=new Map;for(const c of t)for(const d of c.capabilities){const p=l.get(d)??[];p.push(c.id),l.set(d,p)}return[...l.entries()].sort(([c],[d])=>c.localeCompare(d)).map(([c,d])=>({capName:c,providers:d}))},[t]),i=ty({onSuccess:()=>{n.invalidateQueries({queryKey:[["pipelineOrchestrator","getCapabilityBindings"]]})}});return a.length===0?r("div",{className:"py-4 text-xs text-muted-foreground text-center",children:"No capabilities on this node"}):u("table",{className:"w-full text-xs",children:[r("thead",{children:u("tr",{className:"text-muted-foreground text-left",children:[r("th",{className:"py-2 font-medium w-1/2",children:"Capability"}),r("th",{className:"py-2 font-medium",children:"Bound provider"})]})}),r("tbody",{children:a.map(({capName:l,providers:c})=>{const p=o?.[l]??c[0]??"",f=c.length===1;return u("tr",{className:"border-t border-border/50",children:[r("td",{className:"py-2 font-medium",children:l}),r("td",{className:"py-2",children:r("select",{value:p,onChange:m=>i.mutate({nodeId:e,capName:l,addonId:m.target.value}),disabled:f||i.isPending||s,className:"w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60",title:f?"Only one provider installed — choice becomes available once a second addon registers this capability":void 0,children:c.map(m=>r("option",{value:m,children:m},m))})})]},l)})})]})}function rV(e){if(e==null)return"—";const t=Math.floor(e/1e3),n=Math.floor(t/86400),o=Math.floor(t%86400/3600),s=Math.floor(t%3600/60);return n>0?`${n}d ${o}h ${s}m`:o>0?`${o}h ${s}m`:`${s}m`}function oV(e){const[t,n]=I(!1),[o,s]=I(e.name),a=Me(),i=Bx({onSuccess:()=>{a.invalidateQueries({queryKey:[["nodes","topology"]]})}}),l=(e.localIps??[]).filter(f=>!f.includes(":")),c=(e.localIps??[]).filter(f=>f.includes(":")),d=async()=>{if(!o.trim()||o===e.name){n(!1);return}try{await i.mutateAsync({nodeId:e.nodeId,name:o.trim()}),n(!1)}catch(f){console.error("Rename failed:",f)}},p=[["Node ID",r("span",{className:"font-mono text-xs",children:e.nodeId})],["Display Name",t?u("div",{className:"flex items-center gap-1.5",children:[r("input",{type:"text",className:"flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary",value:o,onChange:f=>s(f.target.value),onKeyDown:f=>{f.key==="Enter"&&d(),f.key==="Escape"&&n(!1)},disabled:i.isPending,autoFocus:!0}),r("button",{onClick:()=>void d(),disabled:i.isPending,className:"p-0.5 text-success hover:bg-success/10 rounded",title:"Save",children:r(St,{className:"h-3.5 w-3.5"})}),r("button",{onClick:()=>n(!1),className:"p-0.5 text-muted-foreground hover:bg-muted rounded",title:"Cancel",children:r(Ve,{className:"h-3.5 w-3.5"})})]}):u("div",{className:"flex items-center gap-1.5",children:[r("span",{className:"text-xs",children:e.name}),!e.isHub&&r("button",{onClick:()=>{s(e.name),n(!0)},className:"p-0.5 text-muted-foreground hover:text-primary rounded",title:"Rename",children:r(ao,{className:"h-3 w-3"})})]})],["Hostname",r("span",{className:"text-xs",children:e.hostname})],["Role",e.isHub?r("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium",children:"Hub"}):r("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium",children:"Agent"})],["Platform",u("span",{className:"text-xs",children:[e.platform," / ",e.arch]})],["CPU",u("span",{className:"text-xs",children:[e.cpuModel??"—"," (",e.cpuCores," cores)"]})],["Memory",r("span",{className:"text-xs",children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:"—"})],["Uptime",r("span",{className:"text-xs",children:rV(e.uptime)})],["Engines",e.engines.length>0?r("div",{className:"flex flex-wrap gap-1",children:e.engines.map(f=>r("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium",children:f},f))}):r("span",{className:"text-xs text-muted-foreground",children:"—"})]];return l.length>0&&p.push(["IPv4",r("div",{className:"flex flex-wrap gap-1.5",children:l.map((f,m)=>r("span",{className:"font-mono text-xs px-1.5 py-0.5 rounded bg-muted",children:f},`${f}-${m}`))})]),c.length>0&&p.push(["IPv6",r("div",{className:"flex flex-wrap gap-1.5",children:c.map((f,m)=>r("span",{className:"font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]",title:f,children:f},`${f}-${m}`))})]),r("div",{className:"py-2",children:r("table",{className:"w-full text-sm",children:r("tbody",{children:p.map(([f,m],h)=>u("tr",{className:h%2===0?"bg-muted/20":"",children:[r("td",{className:"py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap",children:f}),r("td",{className:"py-1.5 px-2",children:m})]},f))})})})}function sV({node:e}){const[t,n]=I("info"),o=e.processes??[],s=e.addons.map(a=>a.id);return e.isOnline?u("div",{className:"border border-border rounded-xl overflow-hidden",children:[u("div",{className:"flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border",children:[r("div",{className:"w-2.5 h-2.5 rounded-full bg-success"}),r("span",{className:"text-sm font-semibold",children:e.name}),u("span",{className:"text-xs text-muted-foreground",children:[e.cpuModel??e.platform," · ",e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:""," · ",e.arch]}),e.engines.map(a=>r("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium",children:a},a)),u("div",{className:"ml-auto flex gap-3 text-xs text-muted-foreground",children:[u("span",{className:"flex items-center gap-1",children:[r(jt,{className:"h-3 w-3"})," ",e.cpuPercent,"%"]}),u("span",{className:"flex items-center gap-1",children:[r(xv,{className:"h-3 w-3"})," ",e.memoryPercent,"%"]})]})]}),r("div",{className:"flex border-b border-border px-4",children:["info","addons","forks","processes","settings","capabilities"].map(a=>r("button",{onClick:()=>n(a),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===a?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground"}`,children:a==="info"?"Info":a==="addons"?`Addons (${e.addons.length})`:a==="forks"?`Forks (${o.length})`:a==="processes"?"Processes":a==="settings"?"Settings":"Capabilities"},a))}),u("div",{className:"px-4 py-2",children:[t==="info"&&r(oV,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps}),t==="addons"&&r(QH,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),t==="forks"&&r(ZH,{nodeId:e.id,processes:o}),t==="processes"&&r(eV,{nodeId:e.id}),t==="settings"&&r(tV,{nodeId:e.id,addonIds:s}),t==="capabilities"&&r(nV,{nodeId:e.id,addons:e.addons})]})]}):u("div",{className:"border border-border rounded-xl overflow-hidden opacity-60",children:[u("div",{className:"flex items-center gap-3 px-4 py-3 bg-muted/30",children:[r("div",{className:"w-2.5 h-2.5 rounded-full bg-destructive"}),r("span",{className:"text-sm font-semibold",children:e.name}),u("span",{className:"text-xs text-muted-foreground",children:[e.cpuModel??e.platform," · ",e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:""," · ",e.arch]}),e.engines.map(a=>r("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium",children:a},a)),r("span",{className:"ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive",children:"offline"})]}),u("div",{className:"px-4 py-3 text-xs text-muted-foreground",children:[e.addons.length," addon",e.addons.length!==1?"s":""," assigned — will resume when node reconnects"]})]})}function aV({nodes:e}){const t=[...e].sort((n,o)=>n.isHub?-1:o.isHub?1:n.isOnline&&!o.isOnline?-1:!n.isOnline&&o.isOnline?1:n.name.localeCompare(o.name));return r("div",{className:"flex flex-col gap-4",children:t.map(n=>r(sV,{node:n},n.id))})}const bc=[{id:"providers",label:"Providers",color:"#3b82f6"},{id:"pipeline",label:"Pipeline",color:"#8b5cf6"},{id:"analytics",label:"Analytics",color:"#06b6d4"},{id:"exports",label:"Exports",color:"#10b981"},{id:"messaging",label:"Messaging",color:"#f59e0b"},{id:"networking",label:"Networking",color:"#ef4444"},{id:"system",label:"System",color:"#6b7280"}],jf=bc[bc.length-1];function iV(e){return e==null||e===""?jf:bc.find(n=>n.id===e)??jf}function lV(e,t){return e===0?"healthy":t===0?"failed":t<e?"degraded":"healthy"}function cV({category:e,total:t,healthy:n,onSelect:o}){const s=iV(e),a=lV(t,n),i=t>0,l=U(()=>{i&&o(e)},[i,o,e]),c=t===0?0:Math.round(n/t*100),d=u(me,{children:[u("div",{className:"flex items-baseline justify-between",children:[r("span",{className:"text-[10px] font-medium",style:{color:s.color},children:s.label}),u("span",{className:"text-[10px] tabular-nums text-muted-foreground",children:[n,"/",t]})]}),r("div",{"data-testid":"health-bar","data-state":a,className:"mt-1 h-[3px] w-full rounded-full bg-muted overflow-hidden","aria-hidden":"true",children:r("div",{className:a==="healthy"?"h-full bg-success":a==="degraded"?"h-full bg-gradient-to-r from-success to-amber-500":"h-full bg-gradient-to-r from-success to-destructive",style:{width:`${c}%`}})})]});return i?r("button",{type:"button",onClick:l,className:"rounded-md px-2 py-1.5 cursor-pointer text-left hover:bg-muted/50 transition-colors","aria-label":`${s.label}: ${n}/${t}`,children:d}):r("div",{className:"rounded-md px-2 py-1.5 opacity-50 select-none",children:d})}const dV=je(cV);function uV({node:e,onSelectCategory:t}){const n=U(i=>{t(i)},[t]),o="border-2 border-dashed border-muted-foreground/30 opacity-50",s=e.isHub?"border-2 border-success":"border-2 border-dashed border-primary/60 bg-primary/5",a=(e.localIps??[]).filter(i=>!i.includes(":"));return u("div",{className:`rounded-xl bg-surface px-3 py-2.5 min-w-[260px] max-w-[320px] ${e.isOnline?s:o}`,"data-node-id":e.id,children:[u("div",{className:"flex items-center gap-1.5 mb-1.5",children:[r("div",{className:`w-2 h-2 rounded-full ${e.isOnline?"bg-success":"bg-destructive"}`}),r("span",{className:"text-xs font-semibold truncate flex-1",children:e.name}),e.isHub?r("span",{className:"text-[8px] px-1 py-0.5 rounded bg-primary/10 text-primary font-medium",children:"HUB"}):r("span",{className:"text-[8px] px-1 py-0.5 rounded bg-muted text-muted-foreground font-medium",children:"AGENT"})]}),(e.hostname||a.length>0)&&u("div",{className:"text-[9px] text-muted-foreground mb-1.5 space-y-0.5",children:[e.hostname&&r("div",{className:"truncate",children:e.hostname}),a.length>0&&r("div",{className:"truncate font-mono opacity-70",children:a.join(", ")})]}),e.isOnline&&u("div",{className:"flex items-center gap-3 text-[10px] text-muted-foreground mb-2",children:[u("span",{className:"flex items-center gap-0.5",children:[r(jt,{className:"h-2.5 w-2.5"}),e.cpuPercent,"%"]}),u("span",{className:"flex items-center gap-0.5",children:[r(xv,{className:"h-2.5 w-2.5"}),e.memoryPercent,"%"]})]}),r("div",{className:"grid grid-cols-3 gap-1",children:e.categories.map(i=>r(dV,{category:i.category,total:i.total,healthy:i.healthy,onSelect:n},i.category))})]})}const pV=je(uV);function fV({mode:e,onClose:t,onModeChange:n,renderCategoryDetail:o}){const s=(a,i)=>{n({kind:"log",agentId:a,addonId:i})};return u("div",{className:"fixed bottom-0 left-0 right-0 h-[180px] border-t border-border bg-background shadow-lg z-40 flex flex-col",children:[u("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border",children:[r("span",{className:"text-xs font-semibold text-muted-foreground",children:e.kind==="log"?`Logs · ${e.addonId??e.agentId}`:`${e.category} · ${e.nodeId}`}),r("button",{type:"button",onClick:t,className:"p-1 rounded hover:bg-muted text-muted-foreground","aria-label":"Close dock",children:r(Ve,{className:"h-3 w-3"})})]}),r("div",{className:"flex-1 overflow-hidden",children:e.kind==="log"?r(_0,{addonId:e.addonId,agentId:e.agentId,showScope:!0,onClose:t}):o({nodeId:e.nodeId,category:e.category,switchToLog:s})})]})}const mV=je(fV);function hV(e){return`${Math.round(e/1024/1024)}MB`}function gV({nodeId:e,category:t,addons:n,onShowLog:o,onRestartAddon:s}){const a=U(l=>o(e,l),[e,o]),i=U(l=>s(e,l),[e,s]);return r("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2 p-3 overflow-auto","data-category":t,children:n.map(l=>{const c=l.status==="running";return u("div",{"data-testid":"addon-tile","data-addon-id":l.id,className:"rounded-md border border-border px-2 py-1.5 text-[10px] flex items-center gap-2",children:[r("div",{"data-status":l.status,className:`w-2 h-2 rounded-full ${c?"bg-success":"bg-destructive"}`}),u("div",{className:"flex-1 min-w-0",children:[r("div",{className:"font-medium truncate",children:l.id}),u("div",{className:"text-muted-foreground",children:[l.cpuPercent,"% · ",hV(l.memoryRss)]})]}),r("button",{type:"button",onClick:()=>a(l.id),"aria-label":`Show logs for ${l.id}`,className:"p-1 rounded hover:bg-muted text-muted-foreground",children:r(At,{className:"h-3 w-3"})}),r("button",{type:"button",onClick:()=>i(l.id),"aria-label":`Restart ${l.id}`,className:"p-1 rounded hover:bg-muted text-muted-foreground",children:r(Yt,{className:"h-3 w-3"})})]},l.id)})})}const bV=je(gV);function xV({topology:e}){const[t,n]=I(null),o=Ua(),s=e.filter(d=>d.isOnline),a=U((d,p)=>{n({kind:"category-detail",nodeId:d,category:p})},[]),i=U(()=>n(null),[]),l=U((d,p)=>e.find(h=>h.id===d)?.categories.find(h=>h.category===p)?.addons??[],[e]),c=U((d,p)=>{o.mutateAsync({nodeId:d,addonId:p})},[o]);return u("div",{className:"flex flex-col flex-1 min-h-0",children:[r("div",{className:"flex flex-wrap gap-4 p-4 overflow-auto flex-1",children:s.map(d=>r(pV,{node:d,onSelectCategory:p=>a(d.id,p)},d.id))}),t&&r(mV,{mode:t,onClose:i,onModeChange:n,renderCategoryDetail:({nodeId:d,category:p,switchToLog:f})=>r(bV,{nodeId:d,category:p,addons:l(d,p),onShowLog:(m,h)=>f(m,h),onRestartAddon:c})})]})}function tt(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,o;n<e.length;n++)(o=tt(e[n]))!==""&&(t+=(t&&" ")+o);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var yV={value:()=>{}};function pi(){for(var e=0,t=arguments.length,n={},o;e<t;++e){if(!(o=arguments[e]+"")||o in n||/[\s.]/.test(o))throw new Error("illegal type: "+o);n[o]=[]}return new ea(n)}function ea(e){this._=e}function vV(e,t){return e.trim().split(/^|\s+/).map(function(n){var o="",s=n.indexOf(".");if(s>=0&&(o=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:o}})}ea.prototype=pi.prototype={constructor:ea,on:function(e,t){var n=this._,o=vV(e+"",n),s,a=-1,i=o.length;if(arguments.length<2){for(;++a<i;)if((s=(e=o[a]).type)&&(s=wV(n[s],e.name)))return s;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++a<i;)if(s=(e=o[a]).type)n[s]=Hf(n[s],e.name,t);else if(t==null)for(s in n)n[s]=Hf(n[s],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new ea(e)},call:function(e,t){if((s=arguments.length-2)>0)for(var n=new Array(s),o=0,s,a;o<s;++o)n[o]=arguments[o+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(a=this._[e],o=0,s=a.length;o<s;++o)a[o].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var o=this._[e],s=0,a=o.length;s<a;++s)o[s].value.apply(t,n)}};function wV(e,t){for(var n=0,o=e.length,s;n<o;++n)if((s=e[n]).name===t)return s.value}function Hf(e,t,n){for(var o=0,s=e.length;o<s;++o)if(e[o].name===t){e[o]=yV,e=e.slice(0,o).concat(e.slice(o+1));break}return n!=null&&e.push({name:t,value:n}),e}var xc="http://www.w3.org/1999/xhtml";const Vf={svg:"http://www.w3.org/2000/svg",xhtml:xc,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function fi(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),Vf.hasOwnProperty(t)?{space:Vf[t],local:e}:e}function NV(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===xc&&t.documentElement.namespaceURI===xc?t.createElement(e):t.createElementNS(n,e)}}function kV(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function b1(e){var t=fi(e);return(t.local?kV:NV)(t)}function SV(){}function fu(e){return e==null?SV:function(){return this.querySelector(e)}}function CV(e){typeof e!="function"&&(e=fu(e));for(var t=this._groups,n=t.length,o=new Array(n),s=0;s<n;++s)for(var a=t[s],i=a.length,l=o[s]=new Array(i),c,d,p=0;p<i;++p)(c=a[p])&&(d=e.call(c,c.__data__,p,a))&&("__data__"in c&&(d.__data__=c.__data__),l[p]=d);return new vt(o,this._parents)}function MV(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function AV(){return[]}function x1(e){return e==null?AV:function(){return this.querySelectorAll(e)}}function EV(e){return function(){return MV(e.apply(this,arguments))}}function IV(e){typeof e=="function"?e=EV(e):e=x1(e);for(var t=this._groups,n=t.length,o=[],s=[],a=0;a<n;++a)for(var i=t[a],l=i.length,c,d=0;d<l;++d)(c=i[d])&&(o.push(e.call(c,c.__data__,d,i)),s.push(c));return new vt(o,s)}function y1(e){return function(){return this.matches(e)}}function v1(e){return function(t){return t.matches(e)}}var PV=Array.prototype.find;function _V(e){return function(){return PV.call(this.children,e)}}function $V(){return this.firstElementChild}function DV(e){return this.select(e==null?$V:_V(typeof e=="function"?e:v1(e)))}var LV=Array.prototype.filter;function TV(){return Array.from(this.children)}function RV(e){return function(){return LV.call(this.children,e)}}function OV(e){return this.selectAll(e==null?TV:RV(typeof e=="function"?e:v1(e)))}function BV(e){typeof e!="function"&&(e=y1(e));for(var t=this._groups,n=t.length,o=new Array(n),s=0;s<n;++s)for(var a=t[s],i=a.length,l=o[s]=[],c,d=0;d<i;++d)(c=a[d])&&e.call(c,c.__data__,d,a)&&l.push(c);return new vt(o,this._parents)}function w1(e){return new Array(e.length)}function zV(){return new vt(this._enter||this._groups.map(w1),this._parents)}function Sa(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Sa.prototype={constructor:Sa,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function FV(e){return function(){return e}}function jV(e,t,n,o,s,a){for(var i=0,l,c=t.length,d=a.length;i<d;++i)(l=t[i])?(l.__data__=a[i],o[i]=l):n[i]=new Sa(e,a[i]);for(;i<c;++i)(l=t[i])&&(s[i]=l)}function HV(e,t,n,o,s,a,i){var l,c,d=new Map,p=t.length,f=a.length,m=new Array(p),h;for(l=0;l<p;++l)(c=t[l])&&(m[l]=h=i.call(c,c.__data__,l,t)+"",d.has(h)?s[l]=c:d.set(h,c));for(l=0;l<f;++l)h=i.call(e,a[l],l,a)+"",(c=d.get(h))?(o[l]=c,c.__data__=a[l],d.delete(h)):n[l]=new Sa(e,a[l]);for(l=0;l<p;++l)(c=t[l])&&d.get(m[l])===c&&(s[l]=c)}function VV(e){return e.__data__}function UV(e,t){if(!arguments.length)return Array.from(this,VV);var n=t?HV:jV,o=this._parents,s=this._groups;typeof e!="function"&&(e=FV(e));for(var a=s.length,i=new Array(a),l=new Array(a),c=new Array(a),d=0;d<a;++d){var p=o[d],f=s[d],m=f.length,h=qV(e.call(p,p&&p.__data__,d,o)),g=h.length,x=l[d]=new Array(g),b=i[d]=new Array(g),y=c[d]=new Array(m);n(p,f,x,b,y,h,t);for(var w=0,v=0,N,k;w<g;++w)if(N=x[w]){for(w>=v&&(v=w+1);!(k=b[v])&&++v<g;);N._next=k||null}}return i=new vt(i,o),i._enter=l,i._exit=c,i}function qV(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function QV(){return new vt(this._exit||this._groups.map(w1),this._parents)}function GV(e,t,n){var o=this.enter(),s=this,a=this.exit();return typeof e=="function"?(o=e(o),o&&(o=o.selection())):o=o.append(e+""),t!=null&&(s=t(s),s&&(s=s.selection())),n==null?a.remove():n(a),o&&s?o.merge(s).order():s}function WV(e){for(var t=e.selection?e.selection():e,n=this._groups,o=t._groups,s=n.length,a=o.length,i=Math.min(s,a),l=new Array(s),c=0;c<i;++c)for(var d=n[c],p=o[c],f=d.length,m=l[c]=new Array(f),h,g=0;g<f;++g)(h=d[g]||p[g])&&(m[g]=h);for(;c<s;++c)l[c]=n[c];return new vt(l,this._parents)}function KV(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var o=e[t],s=o.length-1,a=o[s],i;--s>=0;)(i=o[s])&&(a&&i.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(i,a),a=i);return this}function YV(e){e||(e=ZV);function t(f,m){return f&&m?e(f.__data__,m.__data__):!f-!m}for(var n=this._groups,o=n.length,s=new Array(o),a=0;a<o;++a){for(var i=n[a],l=i.length,c=s[a]=new Array(l),d,p=0;p<l;++p)(d=i[p])&&(c[p]=d);c.sort(t)}return new vt(s,this._parents).order()}function ZV(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function XV(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function JV(){return Array.from(this)}function eU(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var o=e[t],s=0,a=o.length;s<a;++s){var i=o[s];if(i)return i}return null}function tU(){let e=0;for(const t of this)++e;return e}function nU(){return!this.node()}function rU(e){for(var t=this._groups,n=0,o=t.length;n<o;++n)for(var s=t[n],a=0,i=s.length,l;a<i;++a)(l=s[a])&&e.call(l,l.__data__,a,s);return this}function oU(e){return function(){this.removeAttribute(e)}}function sU(e){return function(){this.removeAttributeNS(e.space,e.local)}}function aU(e,t){return function(){this.setAttribute(e,t)}}function iU(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function lU(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function cU(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function dU(e,t){var n=fi(e);if(arguments.length<2){var o=this.node();return n.local?o.getAttributeNS(n.space,n.local):o.getAttribute(n)}return this.each((t==null?n.local?sU:oU:typeof t=="function"?n.local?cU:lU:n.local?iU:aU)(n,t))}function N1(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function uU(e){return function(){this.style.removeProperty(e)}}function pU(e,t,n){return function(){this.style.setProperty(e,t,n)}}function fU(e,t,n){return function(){var o=t.apply(this,arguments);o==null?this.style.removeProperty(e):this.style.setProperty(e,o,n)}}function mU(e,t,n){return arguments.length>1?this.each((t==null?uU:typeof t=="function"?fU:pU)(e,t,n??"")):zr(this.node(),e)}function zr(e,t){return e.style.getPropertyValue(t)||N1(e).getComputedStyle(e,null).getPropertyValue(t)}function hU(e){return function(){delete this[e]}}function gU(e,t){return function(){this[e]=t}}function bU(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function xU(e,t){return arguments.length>1?this.each((t==null?hU:typeof t=="function"?bU:gU)(e,t)):this.node()[e]}function k1(e){return e.trim().split(/^|\s+/)}function mu(e){return e.classList||new S1(e)}function S1(e){this._node=e,this._names=k1(e.getAttribute("class")||"")}S1.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function C1(e,t){for(var n=mu(e),o=-1,s=t.length;++o<s;)n.add(t[o])}function M1(e,t){for(var n=mu(e),o=-1,s=t.length;++o<s;)n.remove(t[o])}function yU(e){return function(){C1(this,e)}}function vU(e){return function(){M1(this,e)}}function wU(e,t){return function(){(t.apply(this,arguments)?C1:M1)(this,e)}}function NU(e,t){var n=k1(e+"");if(arguments.length<2){for(var o=mu(this.node()),s=-1,a=n.length;++s<a;)if(!o.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?wU:t?yU:vU)(n,t))}function kU(){this.textContent=""}function SU(e){return function(){this.textContent=e}}function CU(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function MU(e){return arguments.length?this.each(e==null?kU:(typeof e=="function"?CU:SU)(e)):this.node().textContent}function AU(){this.innerHTML=""}function EU(e){return function(){this.innerHTML=e}}function IU(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function PU(e){return arguments.length?this.each(e==null?AU:(typeof e=="function"?IU:EU)(e)):this.node().innerHTML}function _U(){this.nextSibling&&this.parentNode.appendChild(this)}function $U(){return this.each(_U)}function DU(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function LU(){return this.each(DU)}function TU(e){var t=typeof e=="function"?e:b1(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function RU(){return null}function OU(e,t){var n=typeof e=="function"?e:b1(e),o=t==null?RU:typeof t=="function"?t:fu(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),o.apply(this,arguments)||null)})}function BU(){var e=this.parentNode;e&&e.removeChild(this)}function zU(){return this.each(BU)}function FU(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function jU(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function HU(e){return this.select(e?jU:FU)}function VU(e){return arguments.length?this.property("__data__",e):this.node().__data__}function UU(e){return function(t){e.call(this,t,this.__data__)}}function qU(e){return e.trim().split(/^|\s+/).map(function(t){var n="",o=t.indexOf(".");return o>=0&&(n=t.slice(o+1),t=t.slice(0,o)),{type:t,name:n}})}function QU(e){return function(){var t=this.__on;if(t){for(var n=0,o=-1,s=t.length,a;n<s;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++o]=a;++o?t.length=o:delete this.__on}}}function GU(e,t,n){return function(){var o=this.__on,s,a=UU(t);if(o){for(var i=0,l=o.length;i<l;++i)if((s=o[i]).type===e.type&&s.name===e.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=a,s.options=n),s.value=t;return}}this.addEventListener(e.type,a,n),s={type:e.type,name:e.name,value:t,listener:a,options:n},o?o.push(s):this.__on=[s]}}function WU(e,t,n){var o=qU(e+""),s,a=o.length,i;if(arguments.length<2){var l=this.node().__on;if(l){for(var c=0,d=l.length,p;c<d;++c)for(s=0,p=l[c];s<a;++s)if((i=o[s]).type===p.type&&i.name===p.name)return p.value}return}for(l=t?GU:QU,s=0;s<a;++s)this.each(l(o[s],t,n));return this}function A1(e,t,n){var o=N1(e),s=o.CustomEvent;typeof s=="function"?s=new s(t,n):(s=o.document.createEvent("Event"),n?(s.initEvent(t,n.bubbles,n.cancelable),s.detail=n.detail):s.initEvent(t,!1,!1)),e.dispatchEvent(s)}function KU(e,t){return function(){return A1(this,e,t)}}function YU(e,t){return function(){return A1(this,e,t.apply(this,arguments))}}function ZU(e,t){return this.each((typeof t=="function"?YU:KU)(e,t))}function*XU(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var o=e[t],s=0,a=o.length,i;s<a;++s)(i=o[s])&&(yield i)}var E1=[null];function vt(e,t){this._groups=e,this._parents=t}function as(){return new vt([[document.documentElement]],E1)}function JU(){return this}vt.prototype=as.prototype={constructor:vt,select:CV,selectAll:IV,selectChild:DV,selectChildren:OV,filter:BV,data:UV,enter:zV,exit:QV,join:GV,merge:WV,selection:JU,order:KV,sort:YV,call:XV,nodes:JV,node:eU,size:tU,empty:nU,each:rU,attr:dU,style:mU,property:xU,classed:NU,text:MU,html:PU,raise:$U,lower:LU,append:TU,insert:OU,remove:zU,clone:HU,datum:VU,on:WU,dispatch:ZU,[Symbol.iterator]:XU};function bt(e){return typeof e=="string"?new vt([[document.querySelector(e)]],[document.documentElement]):new vt([[e]],E1)}function eq(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Lt(e,t){if(e=eq(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var o=n.createSVGPoint();return o.x=e.clientX,o.y=e.clientY,o=o.matrixTransform(t.getScreenCTM().inverse()),[o.x,o.y]}if(t.getBoundingClientRect){var s=t.getBoundingClientRect();return[e.clientX-s.left-t.clientLeft,e.clientY-s.top-t.clientTop]}}return[e.pageX,e.pageY]}const tq={passive:!1},jo={capture:!0,passive:!1};function gl(e){e.stopImmediatePropagation()}function Er(e){e.preventDefault(),e.stopImmediatePropagation()}function I1(e){var t=e.document.documentElement,n=bt(e).on("dragstart.drag",Er,jo);"onselectstart"in t?n.on("selectstart.drag",Er,jo):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function P1(e,t){var n=e.document.documentElement,o=bt(e).on("dragstart.drag",null);t&&(o.on("click.drag",Er,jo),setTimeout(function(){o.on("click.drag",null)},0)),"onselectstart"in n?o.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const Os=e=>()=>e;function yc(e,{sourceEvent:t,subject:n,target:o,identifier:s,active:a,x:i,y:l,dx:c,dy:d,dispatch:p}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:o,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:l,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:d,enumerable:!0,configurable:!0},_:{value:p}})}yc.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function nq(e){return!e.ctrlKey&&!e.button}function rq(){return this.parentNode}function oq(e,t){return t??{x:e.x,y:e.y}}function sq(){return navigator.maxTouchPoints||"ontouchstart"in this}function _1(){var e=nq,t=rq,n=oq,o=sq,s={},a=pi("start","drag","end"),i=0,l,c,d,p,f=0;function m(N){N.on("mousedown.drag",h).filter(o).on("touchstart.drag",b).on("touchmove.drag",y,tq).on("touchend.drag touchcancel.drag",w).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function h(N,k){if(!(p||!e.call(this,N,k))){var C=v(this,t.call(this,N,k),N,k,"mouse");C&&(bt(N.view).on("mousemove.drag",g,jo).on("mouseup.drag",x,jo),I1(N.view),gl(N),d=!1,l=N.clientX,c=N.clientY,C("start",N))}}function g(N){if(Er(N),!d){var k=N.clientX-l,C=N.clientY-c;d=k*k+C*C>f}s.mouse("drag",N)}function x(N){bt(N.view).on("mousemove.drag mouseup.drag",null),P1(N.view,d),Er(N),s.mouse("end",N)}function b(N,k){if(e.call(this,N,k)){var C=N.changedTouches,D=t.call(this,N,k),M=C.length,_,$;for(_=0;_<M;++_)($=v(this,D,N,k,C[_].identifier,C[_]))&&(gl(N),$("start",N,C[_]))}}function y(N){var k=N.changedTouches,C=k.length,D,M;for(D=0;D<C;++D)(M=s[k[D].identifier])&&(Er(N),M("drag",N,k[D]))}function w(N){var k=N.changedTouches,C=k.length,D,M;for(p&&clearTimeout(p),p=setTimeout(function(){p=null},500),D=0;D<C;++D)(M=s[k[D].identifier])&&(gl(N),M("end",N,k[D]))}function v(N,k,C,D,M,_){var $=a.copy(),E=Lt(_||C,k),R,O,A;if((A=n.call(N,new yc("beforestart",{sourceEvent:C,target:m,identifier:M,active:i,x:E[0],y:E[1],dx:0,dy:0,dispatch:$}),D))!=null)return R=A.x-E[0]||0,O=A.y-E[1]||0,function P(L,B,z){var T=E,F;switch(L){case"start":s[M]=P,F=i++;break;case"end":delete s[M],--i;case"drag":E=Lt(z||B,k),F=i;break}$.call(L,N,new yc(L,{sourceEvent:B,subject:A,target:m,identifier:M,active:F,x:E[0]+R,y:E[1]+O,dx:E[0]-T[0],dy:E[1]-T[1],dispatch:$}),D)}}return m.filter=function(N){return arguments.length?(e=typeof N=="function"?N:Os(!!N),m):e},m.container=function(N){return arguments.length?(t=typeof N=="function"?N:Os(N),m):t},m.subject=function(N){return arguments.length?(n=typeof N=="function"?N:Os(N),m):n},m.touchable=function(N){return arguments.length?(o=typeof N=="function"?N:Os(!!N),m):o},m.on=function(){var N=a.on.apply(a,arguments);return N===a?m:N},m.clickDistance=function(N){return arguments.length?(f=(N=+N)*N,m):Math.sqrt(f)},m}function hu(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function $1(e,t){var n=Object.create(e.prototype);for(var o in t)n[o]=t[o];return n}function is(){}var Ho=.7,Ca=1/Ho,Ir="\\s*([+-]?\\d+)\\s*",Vo="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Xt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",aq=/^#([0-9a-f]{3,8})$/,iq=new RegExp(`^rgb\\(${Ir},${Ir},${Ir}\\)$`),lq=new RegExp(`^rgb\\(${Xt},${Xt},${Xt}\\)$`),cq=new RegExp(`^rgba\\(${Ir},${Ir},${Ir},${Vo}\\)$`),dq=new RegExp(`^rgba\\(${Xt},${Xt},${Xt},${Vo}\\)$`),uq=new RegExp(`^hsl\\(${Vo},${Xt},${Xt}\\)$`),pq=new RegExp(`^hsla\\(${Vo},${Xt},${Xt},${Vo}\\)$`),Uf={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};hu(is,sr,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:qf,formatHex:qf,formatHex8:fq,formatHsl:mq,formatRgb:Qf,toString:Qf});function qf(){return this.rgb().formatHex()}function fq(){return this.rgb().formatHex8()}function mq(){return D1(this).formatHsl()}function Qf(){return this.rgb().formatRgb()}function sr(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=aq.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Gf(t):n===3?new ut(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Bs(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Bs(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=iq.exec(e))?new ut(t[1],t[2],t[3],1):(t=lq.exec(e))?new ut(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=cq.exec(e))?Bs(t[1],t[2],t[3],t[4]):(t=dq.exec(e))?Bs(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=uq.exec(e))?Yf(t[1],t[2]/100,t[3]/100,1):(t=pq.exec(e))?Yf(t[1],t[2]/100,t[3]/100,t[4]):Uf.hasOwnProperty(e)?Gf(Uf[e]):e==="transparent"?new ut(NaN,NaN,NaN,0):null}function Gf(e){return new ut(e>>16&255,e>>8&255,e&255,1)}function Bs(e,t,n,o){return o<=0&&(e=t=n=NaN),new ut(e,t,n,o)}function hq(e){return e instanceof is||(e=sr(e)),e?(e=e.rgb(),new ut(e.r,e.g,e.b,e.opacity)):new ut}function vc(e,t,n,o){return arguments.length===1?hq(e):new ut(e,t,n,o??1)}function ut(e,t,n,o){this.r=+e,this.g=+t,this.b=+n,this.opacity=+o}hu(ut,vc,$1(is,{brighter(e){return e=e==null?Ca:Math.pow(Ca,e),new ut(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Ho:Math.pow(Ho,e),new ut(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new ut(Xn(this.r),Xn(this.g),Xn(this.b),Ma(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Wf,formatHex:Wf,formatHex8:gq,formatRgb:Kf,toString:Kf}));function Wf(){return`#${Yn(this.r)}${Yn(this.g)}${Yn(this.b)}`}function gq(){return`#${Yn(this.r)}${Yn(this.g)}${Yn(this.b)}${Yn((isNaN(this.opacity)?1:this.opacity)*255)}`}function Kf(){const e=Ma(this.opacity);return`${e===1?"rgb(":"rgba("}${Xn(this.r)}, ${Xn(this.g)}, ${Xn(this.b)}${e===1?")":`, ${e})`}`}function Ma(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Xn(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Yn(e){return e=Xn(e),(e<16?"0":"")+e.toString(16)}function Yf(e,t,n,o){return o<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Tt(e,t,n,o)}function D1(e){if(e instanceof Tt)return new Tt(e.h,e.s,e.l,e.opacity);if(e instanceof is||(e=sr(e)),!e)return new Tt;if(e instanceof Tt)return e;e=e.rgb();var t=e.r/255,n=e.g/255,o=e.b/255,s=Math.min(t,n,o),a=Math.max(t,n,o),i=NaN,l=a-s,c=(a+s)/2;return l?(t===a?i=(n-o)/l+(n<o)*6:n===a?i=(o-t)/l+2:i=(t-n)/l+4,l/=c<.5?a+s:2-a-s,i*=60):l=c>0&&c<1?0:i,new Tt(i,l,c,e.opacity)}function bq(e,t,n,o){return arguments.length===1?D1(e):new Tt(e,t,n,o??1)}function Tt(e,t,n,o){this.h=+e,this.s=+t,this.l=+n,this.opacity=+o}hu(Tt,bq,$1(is,{brighter(e){return e=e==null?Ca:Math.pow(Ca,e),new Tt(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Ho:Math.pow(Ho,e),new Tt(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,o=n+(n<.5?n:1-n)*t,s=2*n-o;return new ut(bl(e>=240?e-240:e+120,s,o),bl(e,s,o),bl(e<120?e+240:e-120,s,o),this.opacity)},clamp(){return new Tt(Zf(this.h),zs(this.s),zs(this.l),Ma(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Ma(this.opacity);return`${e===1?"hsl(":"hsla("}${Zf(this.h)}, ${zs(this.s)*100}%, ${zs(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Zf(e){return e=(e||0)%360,e<0?e+360:e}function zs(e){return Math.max(0,Math.min(1,e||0))}function bl(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const gu=e=>()=>e;function xq(e,t){return function(n){return e+n*t}}function yq(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(o){return Math.pow(e+o*t,n)}}function vq(e){return(e=+e)==1?L1:function(t,n){return n-t?yq(t,n,e):gu(isNaN(t)?n:t)}}function L1(e,t){var n=t-e;return n?xq(e,n):gu(isNaN(e)?t:e)}const Aa=(function e(t){var n=vq(t);function o(s,a){var i=n((s=vc(s)).r,(a=vc(a)).r),l=n(s.g,a.g),c=n(s.b,a.b),d=L1(s.opacity,a.opacity);return function(p){return s.r=i(p),s.g=l(p),s.b=c(p),s.opacity=d(p),s+""}}return o.gamma=e,o})(1);function wq(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,o=t.slice(),s;return function(a){for(s=0;s<n;++s)o[s]=e[s]*(1-a)+t[s]*a;return o}}function Nq(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function kq(e,t){var n=t?t.length:0,o=e?Math.min(n,e.length):0,s=new Array(o),a=new Array(n),i;for(i=0;i<o;++i)s[i]=_o(e[i],t[i]);for(;i<n;++i)a[i]=t[i];return function(l){for(i=0;i<o;++i)a[i]=s[i](l);return a}}function Sq(e,t){var n=new Date;return e=+e,t=+t,function(o){return n.setTime(e*(1-o)+t*o),n}}function qt(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function Cq(e,t){var n={},o={},s;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(s in t)s in e?n[s]=_o(e[s],t[s]):o[s]=t[s];return function(a){for(s in n)o[s]=n[s](a);return o}}var wc=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,xl=new RegExp(wc.source,"g");function Mq(e){return function(){return e}}function Aq(e){return function(t){return e(t)+""}}function T1(e,t){var n=wc.lastIndex=xl.lastIndex=0,o,s,a,i=-1,l=[],c=[];for(e=e+"",t=t+"";(o=wc.exec(e))&&(s=xl.exec(t));)(a=s.index)>n&&(a=t.slice(n,a),l[i]?l[i]+=a:l[++i]=a),(o=o[0])===(s=s[0])?l[i]?l[i]+=s:l[++i]=s:(l[++i]=null,c.push({i,x:qt(o,s)})),n=xl.lastIndex;return n<t.length&&(a=t.slice(n),l[i]?l[i]+=a:l[++i]=a),l.length<2?c[0]?Aq(c[0].x):Mq(t):(t=c.length,function(d){for(var p=0,f;p<t;++p)l[(f=c[p]).i]=f.x(d);return l.join("")})}function _o(e,t){var n=typeof t,o;return t==null||n==="boolean"?gu(t):(n==="number"?qt:n==="string"?(o=sr(t))?(t=o,Aa):T1:t instanceof sr?Aa:t instanceof Date?Sq:Nq(t)?wq:Array.isArray(t)?kq:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?Cq:qt)(e,t)}var Xf=180/Math.PI,Nc={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function R1(e,t,n,o,s,a){var i,l,c;return(i=Math.sqrt(e*e+t*t))&&(e/=i,t/=i),(c=e*n+t*o)&&(n-=e*c,o-=t*c),(l=Math.sqrt(n*n+o*o))&&(n/=l,o/=l,c/=l),e*o<t*n&&(e=-e,t=-t,c=-c,i=-i),{translateX:s,translateY:a,rotate:Math.atan2(t,e)*Xf,skewX:Math.atan(c)*Xf,scaleX:i,scaleY:l}}var Fs;function Eq(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Nc:R1(t.a,t.b,t.c,t.d,t.e,t.f)}function Iq(e){return e==null||(Fs||(Fs=document.createElementNS("http://www.w3.org/2000/svg","g")),Fs.setAttribute("transform",e),!(e=Fs.transform.baseVal.consolidate()))?Nc:(e=e.matrix,R1(e.a,e.b,e.c,e.d,e.e,e.f))}function O1(e,t,n,o){function s(d){return d.length?d.pop()+" ":""}function a(d,p,f,m,h,g){if(d!==f||p!==m){var x=h.push("translate(",null,t,null,n);g.push({i:x-4,x:qt(d,f)},{i:x-2,x:qt(p,m)})}else(f||m)&&h.push("translate("+f+t+m+n)}function i(d,p,f,m){d!==p?(d-p>180?p+=360:p-d>180&&(d+=360),m.push({i:f.push(s(f)+"rotate(",null,o)-2,x:qt(d,p)})):p&&f.push(s(f)+"rotate("+p+o)}function l(d,p,f,m){d!==p?m.push({i:f.push(s(f)+"skewX(",null,o)-2,x:qt(d,p)}):p&&f.push(s(f)+"skewX("+p+o)}function c(d,p,f,m,h,g){if(d!==f||p!==m){var x=h.push(s(h)+"scale(",null,",",null,")");g.push({i:x-4,x:qt(d,f)},{i:x-2,x:qt(p,m)})}else(f!==1||m!==1)&&h.push(s(h)+"scale("+f+","+m+")")}return function(d,p){var f=[],m=[];return d=e(d),p=e(p),a(d.translateX,d.translateY,p.translateX,p.translateY,f,m),i(d.rotate,p.rotate,f,m),l(d.skewX,p.skewX,f,m),c(d.scaleX,d.scaleY,p.scaleX,p.scaleY,f,m),d=p=null,function(h){for(var g=-1,x=m.length,b;++g<x;)f[(b=m[g]).i]=b.x(h);return f.join("")}}}var Pq=O1(Eq,"px, ","px)","deg)"),_q=O1(Iq,", ",")",")"),$q=1e-12;function Jf(e){return((e=Math.exp(e))+1/e)/2}function Dq(e){return((e=Math.exp(e))-1/e)/2}function Lq(e){return((e=Math.exp(2*e))-1)/(e+1)}const ta=(function e(t,n,o){function s(a,i){var l=a[0],c=a[1],d=a[2],p=i[0],f=i[1],m=i[2],h=p-l,g=f-c,x=h*h+g*g,b,y;if(x<$q)y=Math.log(m/d)/t,b=function(D){return[l+D*h,c+D*g,d*Math.exp(t*D*y)]};else{var w=Math.sqrt(x),v=(m*m-d*d+o*x)/(2*d*n*w),N=(m*m-d*d-o*x)/(2*m*n*w),k=Math.log(Math.sqrt(v*v+1)-v),C=Math.log(Math.sqrt(N*N+1)-N);y=(C-k)/t,b=function(D){var M=D*y,_=Jf(k),$=d/(n*w)*(_*Lq(t*M+k)-Dq(k));return[l+$*h,c+$*g,d*_/Jf(t*M+k)]}}return b.duration=y*1e3*t/Math.SQRT2,b}return s.rho=function(a){var i=Math.max(.001,+a),l=i*i,c=l*l;return e(i,l,c)},s})(Math.SQRT2,2,4);var Fr=0,wo=0,bo=0,B1=1e3,Ea,No,Ia=0,ar=0,mi=0,Uo=typeof performance=="object"&&performance.now?performance:Date,z1=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function bu(){return ar||(z1(Tq),ar=Uo.now()+mi)}function Tq(){ar=0}function Pa(){this._call=this._time=this._next=null}Pa.prototype=F1.prototype={constructor:Pa,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?bu():+n)+(t==null?0:+t),!this._next&&No!==this&&(No?No._next=this:Ea=this,No=this),this._call=e,this._time=n,kc()},stop:function(){this._call&&(this._call=null,this._time=1/0,kc())}};function F1(e,t,n){var o=new Pa;return o.restart(e,t,n),o}function Rq(){bu(),++Fr;for(var e=Ea,t;e;)(t=ar-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Fr}function em(){ar=(Ia=Uo.now())+mi,Fr=wo=0;try{Rq()}finally{Fr=0,Bq(),ar=0}}function Oq(){var e=Uo.now(),t=e-Ia;t>B1&&(mi-=t,Ia=e)}function Bq(){for(var e,t=Ea,n,o=1/0;t;)t._call?(o>t._time&&(o=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Ea=n);No=e,kc(o)}function kc(e){if(!Fr){wo&&(wo=clearTimeout(wo));var t=e-ar;t>24?(e<1/0&&(wo=setTimeout(em,e-Uo.now()-mi)),bo&&(bo=clearInterval(bo))):(bo||(Ia=Uo.now(),bo=setInterval(Oq,B1)),Fr=1,z1(em))}}function tm(e,t,n){var o=new Pa;return t=t==null?0:+t,o.restart(s=>{o.stop(),e(s+t)},t,n),o}var zq=pi("start","end","cancel","interrupt"),Fq=[],j1=0,nm=1,Sc=2,na=3,rm=4,Cc=5,ra=6;function hi(e,t,n,o,s,a){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;jq(e,n,{name:t,index:o,group:s,on:zq,tween:Fq,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:j1})}function xu(e,t){var n=Vt(e,t);if(n.state>j1)throw new Error("too late; already scheduled");return n}function an(e,t){var n=Vt(e,t);if(n.state>na)throw new Error("too late; already running");return n}function Vt(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function jq(e,t,n){var o=e.__transition,s;o[t]=n,n.timer=F1(a,0,n.time);function a(d){n.state=nm,n.timer.restart(i,n.delay,n.time),n.delay<=d&&i(d-n.delay)}function i(d){var p,f,m,h;if(n.state!==nm)return c();for(p in o)if(h=o[p],h.name===n.name){if(h.state===na)return tm(i);h.state===rm?(h.state=ra,h.timer.stop(),h.on.call("interrupt",e,e.__data__,h.index,h.group),delete o[p]):+p<t&&(h.state=ra,h.timer.stop(),h.on.call("cancel",e,e.__data__,h.index,h.group),delete o[p])}if(tm(function(){n.state===na&&(n.state=rm,n.timer.restart(l,n.delay,n.time),l(d))}),n.state=Sc,n.on.call("start",e,e.__data__,n.index,n.group),n.state===Sc){for(n.state=na,s=new Array(m=n.tween.length),p=0,f=-1;p<m;++p)(h=n.tween[p].value.call(e,e.__data__,n.index,n.group))&&(s[++f]=h);s.length=f+1}}function l(d){for(var p=d<n.duration?n.ease.call(null,d/n.duration):(n.timer.restart(c),n.state=Cc,1),f=-1,m=s.length;++f<m;)s[f].call(e,p);n.state===Cc&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=ra,n.timer.stop(),delete o[t];for(var d in o)return;delete e.__transition}}function oa(e,t){var n=e.__transition,o,s,a=!0,i;if(n){t=t==null?null:t+"";for(i in n){if((o=n[i]).name!==t){a=!1;continue}s=o.state>Sc&&o.state<Cc,o.state=ra,o.timer.stop(),o.on.call(s?"interrupt":"cancel",e,e.__data__,o.index,o.group),delete n[i]}a&&delete e.__transition}}function Hq(e){return this.each(function(){oa(this,e)})}function Vq(e,t){var n,o;return function(){var s=an(this,e),a=s.tween;if(a!==n){o=n=a;for(var i=0,l=o.length;i<l;++i)if(o[i].name===t){o=o.slice(),o.splice(i,1);break}}s.tween=o}}function Uq(e,t,n){var o,s;if(typeof n!="function")throw new Error;return function(){var a=an(this,e),i=a.tween;if(i!==o){s=(o=i).slice();for(var l={name:t,value:n},c=0,d=s.length;c<d;++c)if(s[c].name===t){s[c]=l;break}c===d&&s.push(l)}a.tween=s}}function qq(e,t){var n=this._id;if(e+="",arguments.length<2){for(var o=Vt(this.node(),n).tween,s=0,a=o.length,i;s<a;++s)if((i=o[s]).name===e)return i.value;return null}return this.each((t==null?Vq:Uq)(n,e,t))}function yu(e,t,n){var o=e._id;return e.each(function(){var s=an(this,o);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return Vt(s,o).value[t]}}function H1(e,t){var n;return(typeof t=="number"?qt:t instanceof sr?Aa:(n=sr(t))?(t=n,Aa):T1)(e,t)}function Qq(e){return function(){this.removeAttribute(e)}}function Gq(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Wq(e,t,n){var o,s=n+"",a;return function(){var i=this.getAttribute(e);return i===s?null:i===o?a:a=t(o=i,n)}}function Kq(e,t,n){var o,s=n+"",a;return function(){var i=this.getAttributeNS(e.space,e.local);return i===s?null:i===o?a:a=t(o=i,n)}}function Yq(e,t,n){var o,s,a;return function(){var i,l=n(this),c;return l==null?void this.removeAttribute(e):(i=this.getAttribute(e),c=l+"",i===c?null:i===o&&c===s?a:(s=c,a=t(o=i,l)))}}function Zq(e,t,n){var o,s,a;return function(){var i,l=n(this),c;return l==null?void this.removeAttributeNS(e.space,e.local):(i=this.getAttributeNS(e.space,e.local),c=l+"",i===c?null:i===o&&c===s?a:(s=c,a=t(o=i,l)))}}function Xq(e,t){var n=fi(e),o=n==="transform"?_q:H1;return this.attrTween(e,typeof t=="function"?(n.local?Zq:Yq)(n,o,yu(this,"attr."+e,t)):t==null?(n.local?Gq:Qq)(n):(n.local?Kq:Wq)(n,o,t))}function Jq(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function eQ(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function tQ(e,t){var n,o;function s(){var a=t.apply(this,arguments);return a!==o&&(n=(o=a)&&eQ(e,a)),n}return s._value=t,s}function nQ(e,t){var n,o;function s(){var a=t.apply(this,arguments);return a!==o&&(n=(o=a)&&Jq(e,a)),n}return s._value=t,s}function rQ(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var o=fi(e);return this.tween(n,(o.local?tQ:nQ)(o,t))}function oQ(e,t){return function(){xu(this,e).delay=+t.apply(this,arguments)}}function sQ(e,t){return t=+t,function(){xu(this,e).delay=t}}function aQ(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?oQ:sQ)(t,e)):Vt(this.node(),t).delay}function iQ(e,t){return function(){an(this,e).duration=+t.apply(this,arguments)}}function lQ(e,t){return t=+t,function(){an(this,e).duration=t}}function cQ(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?iQ:lQ)(t,e)):Vt(this.node(),t).duration}function dQ(e,t){if(typeof t!="function")throw new Error;return function(){an(this,e).ease=t}}function uQ(e){var t=this._id;return arguments.length?this.each(dQ(t,e)):Vt(this.node(),t).ease}function pQ(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;an(this,e).ease=n}}function fQ(e){if(typeof e!="function")throw new Error;return this.each(pQ(this._id,e))}function mQ(e){typeof e!="function"&&(e=y1(e));for(var t=this._groups,n=t.length,o=new Array(n),s=0;s<n;++s)for(var a=t[s],i=a.length,l=o[s]=[],c,d=0;d<i;++d)(c=a[d])&&e.call(c,c.__data__,d,a)&&l.push(c);return new vn(o,this._parents,this._name,this._id)}function hQ(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,o=t.length,s=n.length,a=Math.min(o,s),i=new Array(o),l=0;l<a;++l)for(var c=t[l],d=n[l],p=c.length,f=i[l]=new Array(p),m,h=0;h<p;++h)(m=c[h]||d[h])&&(f[h]=m);for(;l<o;++l)i[l]=t[l];return new vn(i,this._parents,this._name,this._id)}function gQ(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function bQ(e,t,n){var o,s,a=gQ(t)?xu:an;return function(){var i=a(this,e),l=i.on;l!==o&&(s=(o=l).copy()).on(t,n),i.on=s}}function xQ(e,t){var n=this._id;return arguments.length<2?Vt(this.node(),n).on.on(e):this.each(bQ(n,e,t))}function yQ(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function vQ(){return this.on("end.remove",yQ(this._id))}function wQ(e){var t=this._name,n=this._id;typeof e!="function"&&(e=fu(e));for(var o=this._groups,s=o.length,a=new Array(s),i=0;i<s;++i)for(var l=o[i],c=l.length,d=a[i]=new Array(c),p,f,m=0;m<c;++m)(p=l[m])&&(f=e.call(p,p.__data__,m,l))&&("__data__"in p&&(f.__data__=p.__data__),d[m]=f,hi(d[m],t,n,m,d,Vt(p,n)));return new vn(a,this._parents,t,n)}function NQ(e){var t=this._name,n=this._id;typeof e!="function"&&(e=x1(e));for(var o=this._groups,s=o.length,a=[],i=[],l=0;l<s;++l)for(var c=o[l],d=c.length,p,f=0;f<d;++f)if(p=c[f]){for(var m=e.call(p,p.__data__,f,c),h,g=Vt(p,n),x=0,b=m.length;x<b;++x)(h=m[x])&&hi(h,t,n,x,m,g);a.push(m),i.push(p)}return new vn(a,i,t,n)}var kQ=as.prototype.constructor;function SQ(){return new kQ(this._groups,this._parents)}function CQ(e,t){var n,o,s;return function(){var a=zr(this,e),i=(this.style.removeProperty(e),zr(this,e));return a===i?null:a===n&&i===o?s:s=t(n=a,o=i)}}function V1(e){return function(){this.style.removeProperty(e)}}function MQ(e,t,n){var o,s=n+"",a;return function(){var i=zr(this,e);return i===s?null:i===o?a:a=t(o=i,n)}}function AQ(e,t,n){var o,s,a;return function(){var i=zr(this,e),l=n(this),c=l+"";return l==null&&(c=l=(this.style.removeProperty(e),zr(this,e))),i===c?null:i===o&&c===s?a:(s=c,a=t(o=i,l))}}function EQ(e,t){var n,o,s,a="style."+t,i="end."+a,l;return function(){var c=an(this,e),d=c.on,p=c.value[a]==null?l||(l=V1(t)):void 0;(d!==n||s!==p)&&(o=(n=d).copy()).on(i,s=p),c.on=o}}function IQ(e,t,n){var o=(e+="")=="transform"?Pq:H1;return t==null?this.styleTween(e,CQ(e,o)).on("end.style."+e,V1(e)):typeof t=="function"?this.styleTween(e,AQ(e,o,yu(this,"style."+e,t))).each(EQ(this._id,e)):this.styleTween(e,MQ(e,o,t),n).on("end.style."+e,null)}function PQ(e,t,n){return function(o){this.style.setProperty(e,t.call(this,o),n)}}function _Q(e,t,n){var o,s;function a(){var i=t.apply(this,arguments);return i!==s&&(o=(s=i)&&PQ(e,i,n)),o}return a._value=t,a}function $Q(e,t,n){var o="style."+(e+="");if(arguments.length<2)return(o=this.tween(o))&&o._value;if(t==null)return this.tween(o,null);if(typeof t!="function")throw new Error;return this.tween(o,_Q(e,t,n??""))}function DQ(e){return function(){this.textContent=e}}function LQ(e){return function(){var t=e(this);this.textContent=t??""}}function TQ(e){return this.tween("text",typeof e=="function"?LQ(yu(this,"text",e)):DQ(e==null?"":e+""))}function RQ(e){return function(t){this.textContent=e.call(this,t)}}function OQ(e){var t,n;function o(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&RQ(s)),t}return o._value=e,o}function BQ(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,OQ(e))}function zQ(){for(var e=this._name,t=this._id,n=U1(),o=this._groups,s=o.length,a=0;a<s;++a)for(var i=o[a],l=i.length,c,d=0;d<l;++d)if(c=i[d]){var p=Vt(c,t);hi(c,e,n,d,i,{time:p.time+p.delay+p.duration,delay:0,duration:p.duration,ease:p.ease})}return new vn(o,this._parents,e,n)}function FQ(){var e,t,n=this,o=n._id,s=n.size();return new Promise(function(a,i){var l={value:i},c={value:function(){--s===0&&a()}};n.each(function(){var d=an(this,o),p=d.on;p!==e&&(t=(e=p).copy(),t._.cancel.push(l),t._.interrupt.push(l),t._.end.push(c)),d.on=t}),s===0&&a()})}var jQ=0;function vn(e,t,n,o){this._groups=e,this._parents=t,this._name=n,this._id=o}function U1(){return++jQ}var dn=as.prototype;vn.prototype={constructor:vn,select:wQ,selectAll:NQ,selectChild:dn.selectChild,selectChildren:dn.selectChildren,filter:mQ,merge:hQ,selection:SQ,transition:zQ,call:dn.call,nodes:dn.nodes,node:dn.node,size:dn.size,empty:dn.empty,each:dn.each,on:xQ,attr:Xq,attrTween:rQ,style:IQ,styleTween:$Q,text:TQ,textTween:BQ,remove:vQ,tween:qq,delay:aQ,duration:cQ,ease:uQ,easeVarying:fQ,end:FQ,[Symbol.iterator]:dn[Symbol.iterator]};function HQ(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var VQ={time:null,delay:0,duration:250,ease:HQ};function UQ(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function qQ(e){var t,n;e instanceof vn?(t=e._id,e=e._name):(t=U1(),(n=VQ).time=bu(),e=e==null?null:e+"");for(var o=this._groups,s=o.length,a=0;a<s;++a)for(var i=o[a],l=i.length,c,d=0;d<l;++d)(c=i[d])&&hi(c,e,t,d,i,n||UQ(c,t));return new vn(o,this._parents,e,t)}as.prototype.interrupt=Hq;as.prototype.transition=qQ;const js=e=>()=>e;function QQ(e,{sourceEvent:t,target:n,transform:o,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:o,enumerable:!0,configurable:!0},_:{value:s}})}function fn(e,t,n){this.k=e,this.x=t,this.y=n}fn.prototype={constructor:fn,scale:function(e){return e===1?this:new fn(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new fn(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var gi=new fn(1,0,0);q1.prototype=fn.prototype;function q1(e){for(;!e.__zoom;)if(!(e=e.parentNode))return gi;return e.__zoom}function yl(e){e.stopImmediatePropagation()}function xo(e){e.preventDefault(),e.stopImmediatePropagation()}function GQ(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function WQ(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function om(){return this.__zoom||gi}function KQ(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function YQ(){return navigator.maxTouchPoints||"ontouchstart"in this}function ZQ(e,t,n){var o=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(s>o?(o+s)/2:Math.min(0,o)||Math.max(0,s),i>a?(a+i)/2:Math.min(0,a)||Math.max(0,i))}function Q1(){var e=GQ,t=WQ,n=ZQ,o=KQ,s=YQ,a=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],l=250,c=ta,d=pi("start","zoom","end"),p,f,m,h=500,g=150,x=0,b=10;function y(A){A.property("__zoom",om).on("wheel.zoom",M,{passive:!1}).on("mousedown.zoom",_).on("dblclick.zoom",$).filter(s).on("touchstart.zoom",E).on("touchmove.zoom",R).on("touchend.zoom touchcancel.zoom",O).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}y.transform=function(A,P,L,B){var z=A.selection?A.selection():A;z.property("__zoom",om),A!==z?k(A,P,L,B):z.interrupt().each(function(){C(this,arguments).event(B).start().zoom(null,typeof P=="function"?P.apply(this,arguments):P).end()})},y.scaleBy=function(A,P,L,B){y.scaleTo(A,function(){var z=this.__zoom.k,T=typeof P=="function"?P.apply(this,arguments):P;return z*T},L,B)},y.scaleTo=function(A,P,L,B){y.transform(A,function(){var z=t.apply(this,arguments),T=this.__zoom,F=L==null?N(z):typeof L=="function"?L.apply(this,arguments):L,H=T.invert(F),j=typeof P=="function"?P.apply(this,arguments):P;return n(v(w(T,j),F,H),z,i)},L,B)},y.translateBy=function(A,P,L,B){y.transform(A,function(){return n(this.__zoom.translate(typeof P=="function"?P.apply(this,arguments):P,typeof L=="function"?L.apply(this,arguments):L),t.apply(this,arguments),i)},null,B)},y.translateTo=function(A,P,L,B,z){y.transform(A,function(){var T=t.apply(this,arguments),F=this.__zoom,H=B==null?N(T):typeof B=="function"?B.apply(this,arguments):B;return n(gi.translate(H[0],H[1]).scale(F.k).translate(typeof P=="function"?-P.apply(this,arguments):-P,typeof L=="function"?-L.apply(this,arguments):-L),T,i)},B,z)};function w(A,P){return P=Math.max(a[0],Math.min(a[1],P)),P===A.k?A:new fn(P,A.x,A.y)}function v(A,P,L){var B=P[0]-L[0]*A.k,z=P[1]-L[1]*A.k;return B===A.x&&z===A.y?A:new fn(A.k,B,z)}function N(A){return[(+A[0][0]+ +A[1][0])/2,(+A[0][1]+ +A[1][1])/2]}function k(A,P,L,B){A.on("start.zoom",function(){C(this,arguments).event(B).start()}).on("interrupt.zoom end.zoom",function(){C(this,arguments).event(B).end()}).tween("zoom",function(){var z=this,T=arguments,F=C(z,T).event(B),H=t.apply(z,T),j=L==null?N(H):typeof L=="function"?L.apply(z,T):L,Q=Math.max(H[1][0]-H[0][0],H[1][1]-H[0][1]),G=z.__zoom,Z=typeof P=="function"?P.apply(z,T):P,V=c(G.invert(j).concat(Q/G.k),Z.invert(j).concat(Q/Z.k));return function(K){if(K===1)K=Z;else{var X=V(K),te=Q/X[2];K=new fn(te,j[0]-X[0]*te,j[1]-X[1]*te)}F.zoom(null,K)}})}function C(A,P,L){return!L&&A.__zooming||new D(A,P)}function D(A,P){this.that=A,this.args=P,this.active=0,this.sourceEvent=null,this.extent=t.apply(A,P),this.taps=0}D.prototype={event:function(A){return A&&(this.sourceEvent=A),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(A,P){return this.mouse&&A!=="mouse"&&(this.mouse[1]=P.invert(this.mouse[0])),this.touch0&&A!=="touch"&&(this.touch0[1]=P.invert(this.touch0[0])),this.touch1&&A!=="touch"&&(this.touch1[1]=P.invert(this.touch1[0])),this.that.__zoom=P,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(A){var P=bt(this.that).datum();d.call(A,this.that,new QQ(A,{sourceEvent:this.sourceEvent,target:y,transform:this.that.__zoom,dispatch:d}),P)}};function M(A,...P){if(!e.apply(this,arguments))return;var L=C(this,P).event(A),B=this.__zoom,z=Math.max(a[0],Math.min(a[1],B.k*Math.pow(2,o.apply(this,arguments)))),T=Lt(A);if(L.wheel)(L.mouse[0][0]!==T[0]||L.mouse[0][1]!==T[1])&&(L.mouse[1]=B.invert(L.mouse[0]=T)),clearTimeout(L.wheel);else{if(B.k===z)return;L.mouse=[T,B.invert(T)],oa(this),L.start()}xo(A),L.wheel=setTimeout(F,g),L.zoom("mouse",n(v(w(B,z),L.mouse[0],L.mouse[1]),L.extent,i));function F(){L.wheel=null,L.end()}}function _(A,...P){if(m||!e.apply(this,arguments))return;var L=A.currentTarget,B=C(this,P,!0).event(A),z=bt(A.view).on("mousemove.zoom",j,!0).on("mouseup.zoom",Q,!0),T=Lt(A,L),F=A.clientX,H=A.clientY;I1(A.view),yl(A),B.mouse=[T,this.__zoom.invert(T)],oa(this),B.start();function j(G){if(xo(G),!B.moved){var Z=G.clientX-F,V=G.clientY-H;B.moved=Z*Z+V*V>x}B.event(G).zoom("mouse",n(v(B.that.__zoom,B.mouse[0]=Lt(G,L),B.mouse[1]),B.extent,i))}function Q(G){z.on("mousemove.zoom mouseup.zoom",null),P1(G.view,B.moved),xo(G),B.event(G).end()}}function $(A,...P){if(e.apply(this,arguments)){var L=this.__zoom,B=Lt(A.changedTouches?A.changedTouches[0]:A,this),z=L.invert(B),T=L.k*(A.shiftKey?.5:2),F=n(v(w(L,T),B,z),t.apply(this,P),i);xo(A),l>0?bt(this).transition().duration(l).call(k,F,B,A):bt(this).call(y.transform,F,B,A)}}function E(A,...P){if(e.apply(this,arguments)){var L=A.touches,B=L.length,z=C(this,P,A.changedTouches.length===B).event(A),T,F,H,j;for(yl(A),F=0;F<B;++F)H=L[F],j=Lt(H,this),j=[j,this.__zoom.invert(j),H.identifier],z.touch0?!z.touch1&&z.touch0[2]!==j[2]&&(z.touch1=j,z.taps=0):(z.touch0=j,T=!0,z.taps=1+!!p);p&&(p=clearTimeout(p)),T&&(z.taps<2&&(f=j[0],p=setTimeout(function(){p=null},h)),oa(this),z.start())}}function R(A,...P){if(this.__zooming){var L=C(this,P).event(A),B=A.changedTouches,z=B.length,T,F,H,j;for(xo(A),T=0;T<z;++T)F=B[T],H=Lt(F,this),L.touch0&&L.touch0[2]===F.identifier?L.touch0[0]=H:L.touch1&&L.touch1[2]===F.identifier&&(L.touch1[0]=H);if(F=L.that.__zoom,L.touch1){var Q=L.touch0[0],G=L.touch0[1],Z=L.touch1[0],V=L.touch1[1],K=(K=Z[0]-Q[0])*K+(K=Z[1]-Q[1])*K,X=(X=V[0]-G[0])*X+(X=V[1]-G[1])*X;F=w(F,Math.sqrt(K/X)),H=[(Q[0]+Z[0])/2,(Q[1]+Z[1])/2],j=[(G[0]+V[0])/2,(G[1]+V[1])/2]}else if(L.touch0)H=L.touch0[0],j=L.touch0[1];else return;L.zoom("touch",n(v(F,H,j),L.extent,i))}}function O(A,...P){if(this.__zooming){var L=C(this,P).event(A),B=A.changedTouches,z=B.length,T,F;for(yl(A),m&&clearTimeout(m),m=setTimeout(function(){m=null},h),T=0;T<z;++T)F=B[T],L.touch0&&L.touch0[2]===F.identifier?delete L.touch0:L.touch1&&L.touch1[2]===F.identifier&&delete L.touch1;if(L.touch1&&!L.touch0&&(L.touch0=L.touch1,delete L.touch1),L.touch0)L.touch0[1]=this.__zoom.invert(L.touch0[0]);else if(L.end(),L.taps===2&&(F=Lt(F,this),Math.hypot(f[0]-F[0],f[1]-F[1])<b)){var H=bt(this).on("dblclick.zoom");H&&H.apply(this,arguments)}}}return y.wheelDelta=function(A){return arguments.length?(o=typeof A=="function"?A:js(+A),y):o},y.filter=function(A){return arguments.length?(e=typeof A=="function"?A:js(!!A),y):e},y.touchable=function(A){return arguments.length?(s=typeof A=="function"?A:js(!!A),y):s},y.extent=function(A){return arguments.length?(t=typeof A=="function"?A:js([[+A[0][0],+A[0][1]],[+A[1][0],+A[1][1]]]),y):t},y.scaleExtent=function(A){return arguments.length?(a[0]=+A[0],a[1]=+A[1],y):[a[0],a[1]]},y.translateExtent=function(A){return arguments.length?(i[0][0]=+A[0][0],i[1][0]=+A[1][0],i[0][1]=+A[0][1],i[1][1]=+A[1][1],y):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},y.constrain=function(A){return arguments.length?(n=A,y):n},y.duration=function(A){return arguments.length?(l=+A,y):l},y.interpolate=function(A){return arguments.length?(c=A,y):c},y.on=function(){var A=d.on.apply(d,arguments);return A===d?y:A},y.clickDistance=function(A){return arguments.length?(x=(A=+A)*A,y):Math.sqrt(x)},y.tapDistance=function(A){return arguments.length?(b=+A,y):b},y}const nn={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:o})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:o}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."},qo=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],G1=["Enter"," ","Escape"],W1={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var jr;(function(e){e.Strict="strict",e.Loose="loose"})(jr||(jr={}));var Jn;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Jn||(Jn={}));var Qo;(function(e){e.Partial="partial",e.Full="full"})(Qo||(Qo={}));const K1={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var In;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(In||(In={}));var _a;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(_a||(_a={}));var Ae;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(Ae||(Ae={}));const sm={[Ae.Left]:Ae.Right,[Ae.Right]:Ae.Left,[Ae.Top]:Ae.Bottom,[Ae.Bottom]:Ae.Top};function Y1(e){return e===null?null:e?"valid":"invalid"}const Z1=e=>"id"in e&&"source"in e&&"target"in e,XQ=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),vu=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),ls=(e,t=[0,0])=>{const{width:n,height:o}=Sn(e),s=e.origin??t,a=n*s[0],i=o*s[1];return{x:e.position.x-a,y:e.position.y-i}},JQ=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((o,s)=>{const a=typeof s=="string";let i=!t.nodeLookup&&!a?s:void 0;t.nodeLookup&&(i=a?t.nodeLookup.get(s):vu(s)?s:t.nodeLookup.get(s.id));const l=i?$a(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return bi(o,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return xi(n)},cs=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},o=!1;return e.forEach(s=>{(t.filter===void 0||t.filter(s))&&(n=bi(n,$a(s)),o=!0)}),o?xi(n):{x:0,y:0,width:0,height:0}},wu=(e,t,[n,o,s]=[0,0,1],a=!1,i=!1)=>{const l={...us(t,[n,o,s]),width:t.width/s,height:t.height/s},c=[];for(const d of e.values()){const{measured:p,selectable:f=!0,hidden:m=!1}=d;if(i&&!f||m)continue;const h=p.width??d.width??d.initialWidth??null,g=p.height??d.height??d.initialHeight??null,x=Go(l,Vr(d)),b=(h??0)*(g??0),y=a&&x>0;(!d.internals.handleBounds||y||x>=b||d.dragging)&&c.push(d)}return c},eG=(e,t)=>{const n=new Set;return e.forEach(o=>{n.add(o.id)}),t.filter(o=>n.has(o.source)||n.has(o.target))};function tG(e,t){const n=new Map,o=t?.nodes?new Set(t.nodes.map(s=>s.id)):null;return e.forEach(s=>{s.measured.width&&s.measured.height&&(t?.includeHiddenNodes||!s.hidden)&&(!o||o.has(s.id))&&n.set(s.id,s)}),n}async function nG({nodes:e,width:t,height:n,panZoom:o,minZoom:s,maxZoom:a},i){if(e.size===0)return Promise.resolve(!0);const l=tG(e,i),c=cs(l),d=Nu(c,t,n,i?.minZoom??s,i?.maxZoom??a,i?.padding??.1);return await o.setViewport(d,{duration:i?.duration,ease:i?.ease,interpolate:i?.interpolate}),Promise.resolve(!0)}function X1({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:o=[0,0],nodeExtent:s,onError:a}){const i=n.get(e),l=i.parentId?n.get(i.parentId):void 0,{x:c,y:d}=l?l.internals.positionAbsolute:{x:0,y:0},p=i.origin??o;let f=i.extent||s;if(i.extent==="parent"&&!i.expandParent)if(!l)a?.("005",nn.error005());else{const h=l.measured.width,g=l.measured.height;h&&g&&(f=[[c,d],[c+h,d+g]])}else l&&Ur(i.extent)&&(f=[[i.extent[0][0]+c,i.extent[0][1]+d],[i.extent[1][0]+c,i.extent[1][1]+d]]);const m=Ur(f)?ir(t,f,i.measured):t;return(i.measured.width===void 0||i.measured.height===void 0)&&a?.("015",nn.error015()),{position:{x:m.x-c+(i.measured.width??0)*p[0],y:m.y-d+(i.measured.height??0)*p[1]},positionAbsolute:m}}async function rG({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:o,onBeforeDelete:s}){const a=new Set(e.map(m=>m.id)),i=[];for(const m of n){if(m.deletable===!1)continue;const h=a.has(m.id),g=!h&&m.parentId&&i.find(x=>x.id===m.parentId);(h||g)&&i.push(m)}const l=new Set(t.map(m=>m.id)),c=o.filter(m=>m.deletable!==!1),p=eG(i,c);for(const m of c)l.has(m.id)&&!p.find(g=>g.id===m.id)&&p.push(m);if(!s)return{edges:p,nodes:i};const f=await s({nodes:i,edges:p});return typeof f=="boolean"?f?{edges:p,nodes:i}:{edges:[],nodes:[]}:f}const Hr=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),ir=(e={x:0,y:0},t,n)=>({x:Hr(e.x,t[0][0],t[1][0]-(n?.width??0)),y:Hr(e.y,t[0][1],t[1][1]-(n?.height??0))});function J1(e,t,n){const{width:o,height:s}=Sn(n),{x:a,y:i}=n.internals.positionAbsolute;return ir(e,[[a,i],[a+o,i+s]],t)}const am=(e,t,n)=>e<t?Hr(Math.abs(e-t),1,t)/t:e>n?-Hr(Math.abs(e-n),1,t)/t:0,ew=(e,t,n=15,o=40)=>{const s=am(e.x,o,t.width-o)*n,a=am(e.y,o,t.height-o)*n;return[s,a]},bi=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Mc=({x:e,y:t,width:n,height:o})=>({x:e,y:t,x2:e+n,y2:t+o}),xi=({x:e,y:t,x2:n,y2:o})=>({x:e,y:t,width:n-e,height:o-t}),Vr=(e,t=[0,0])=>{const{x:n,y:o}=vu(e)?e.internals.positionAbsolute:ls(e,t);return{x:n,y:o,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},$a=(e,t=[0,0])=>{const{x:n,y:o}=vu(e)?e.internals.positionAbsolute:ls(e,t);return{x:n,y:o,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:o+(e.measured?.height??e.height??e.initialHeight??0)}},tw=(e,t)=>xi(bi(Mc(e),Mc(t))),Go=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),o=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*o)},im=e=>Ot(e.width)&&Ot(e.height)&&Ot(e.x)&&Ot(e.y),Ot=e=>!isNaN(e)&&isFinite(e),oG=(e,t)=>{},ds=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),us=({x:e,y:t},[n,o,s],a=!1,i=[1,1])=>{const l={x:(e-n)/s,y:(t-o)/s};return a?ds(l,i):l},Da=({x:e,y:t},[n,o,s])=>({x:e*s+n,y:t*s+o});function xr(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function sG(e,t,n){if(typeof e=="string"||typeof e=="number"){const o=xr(e,n),s=xr(e,t);return{top:o,right:s,bottom:o,left:s,x:s*2,y:o*2}}if(typeof e=="object"){const o=xr(e.top??e.y??0,n),s=xr(e.bottom??e.y??0,n),a=xr(e.left??e.x??0,t),i=xr(e.right??e.x??0,t);return{top:o,right:i,bottom:s,left:a,x:a+i,y:o+s}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function aG(e,t,n,o,s,a){const{x:i,y:l}=Da(e,[t,n,o]),{x:c,y:d}=Da({x:e.x+e.width,y:e.y+e.height},[t,n,o]),p=s-c,f=a-d;return{left:Math.floor(i),top:Math.floor(l),right:Math.floor(p),bottom:Math.floor(f)}}const Nu=(e,t,n,o,s,a)=>{const i=sG(a,t,n),l=(t-i.x)/e.width,c=(n-i.y)/e.height,d=Math.min(l,c),p=Hr(d,o,s),f=e.x+e.width/2,m=e.y+e.height/2,h=t/2-f*p,g=n/2-m*p,x=aG(e,h,g,p,t,n),b={left:Math.min(x.left-i.left,0),top:Math.min(x.top-i.top,0),right:Math.min(x.right-i.right,0),bottom:Math.min(x.bottom-i.bottom,0)};return{x:h-b.left+b.right,y:g-b.top+b.bottom,zoom:p}},Wo=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Ur(e){return e!=null&&e!=="parent"}function Sn(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function nw(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function rw(e,t={width:0,height:0},n,o,s){const a={...e},i=o.get(n);if(i){const l=i.origin||s;a.x+=i.internals.positionAbsolute.x-(t.width??0)*l[0],a.y+=i.internals.positionAbsolute.y-(t.height??0)*l[1]}return a}function lm(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function iG(){let e,t;return{promise:new Promise((o,s)=>{e=o,t=s}),resolve:e,reject:t}}function lG(e){return{...W1,...e||{}}}function $o(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:o,containerBounds:s}){const{x:a,y:i}=Bt(e),l=us({x:a-(s?.left??0),y:i-(s?.top??0)},o),{x:c,y:d}=n?ds(l,t):l;return{xSnapped:c,ySnapped:d,...l}}const ku=e=>({width:e.offsetWidth,height:e.offsetHeight}),ow=e=>e?.getRootNode?.()||window?.document,cG=["INPUT","SELECT","TEXTAREA"];function sw(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:cG.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const aw=e=>"clientX"in e,Bt=(e,t)=>{const n=aw(e),o=n?e.clientX:e.touches?.[0].clientX,s=n?e.clientY:e.touches?.[0].clientY;return{x:o-(t?.left??0),y:s-(t?.top??0)}},cm=(e,t,n,o,s)=>{const a=t.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(i=>{const l=i.getBoundingClientRect();return{id:i.getAttribute("data-handleid"),type:e,nodeId:s,position:i.getAttribute("data-handlepos"),x:(l.left-n.left)/o,y:(l.top-n.top)/o,...ku(i)}})};function iw({sourceX:e,sourceY:t,targetX:n,targetY:o,sourceControlX:s,sourceControlY:a,targetControlX:i,targetControlY:l}){const c=e*.125+s*.375+i*.375+n*.125,d=t*.125+a*.375+l*.375+o*.125,p=Math.abs(c-e),f=Math.abs(d-t);return[c,d,p,f]}function Hs(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function dm({pos:e,x1:t,y1:n,x2:o,y2:s,c:a}){switch(e){case Ae.Left:return[t-Hs(t-o,a),n];case Ae.Right:return[t+Hs(o-t,a),n];case Ae.Top:return[t,n-Hs(n-s,a)];case Ae.Bottom:return[t,n+Hs(s-n,a)]}}function lw({sourceX:e,sourceY:t,sourcePosition:n=Ae.Bottom,targetX:o,targetY:s,targetPosition:a=Ae.Top,curvature:i=.25}){const[l,c]=dm({pos:n,x1:e,y1:t,x2:o,y2:s,c:i}),[d,p]=dm({pos:a,x1:o,y1:s,x2:e,y2:t,c:i}),[f,m,h,g]=iw({sourceX:e,sourceY:t,targetX:o,targetY:s,sourceControlX:l,sourceControlY:c,targetControlX:d,targetControlY:p});return[`M${e},${t} C${l},${c} ${d},${p} ${o},${s}`,f,m,h,g]}function cw({sourceX:e,sourceY:t,targetX:n,targetY:o}){const s=Math.abs(n-e)/2,a=n<e?n+s:n-s,i=Math.abs(o-t)/2,l=o<t?o+i:o-i;return[a,l,s,i]}function dG({sourceNode:e,targetNode:t,selected:n=!1,zIndex:o=0,elevateOnSelect:s=!1,zIndexMode:a="basic"}){if(a==="manual")return o;const i=s&&n?o+1e3:o,l=Math.max(e.parentId||s&&e.selected?e.internals.z:0,t.parentId||s&&t.selected?t.internals.z:0);return i+l}function uG({sourceNode:e,targetNode:t,width:n,height:o,transform:s}){const a=bi($a(e),$a(t));a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1);const i={x:-s[0]/s[2],y:-s[1]/s[2],width:n/s[2],height:o/s[2]};return Go(i,xi(a))>0}const pG=({source:e,sourceHandle:t,target:n,targetHandle:o})=>`xy-edge__${e}${t||""}-${n}${o||""}`,fG=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),mG=(e,t,n={})=>{if(!e.source||!e.target)return t;const o=n.getEdgeId||pG;let s;return Z1(e)?s={...e}:s={...e,id:o(e)},fG(s,t)?t:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,t.concat(s))};function dw({sourceX:e,sourceY:t,targetX:n,targetY:o}){const[s,a,i,l]=cw({sourceX:e,sourceY:t,targetX:n,targetY:o});return[`M ${e},${t}L ${n},${o}`,s,a,i,l]}const um={[Ae.Left]:{x:-1,y:0},[Ae.Right]:{x:1,y:0},[Ae.Top]:{x:0,y:-1},[Ae.Bottom]:{x:0,y:1}},hG=({source:e,sourcePosition:t=Ae.Bottom,target:n})=>t===Ae.Left||t===Ae.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},pm=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function gG({source:e,sourcePosition:t=Ae.Bottom,target:n,targetPosition:o=Ae.Top,center:s,offset:a,stepPosition:i}){const l=um[t],c=um[o],d={x:e.x+l.x*a,y:e.y+l.y*a},p={x:n.x+c.x*a,y:n.y+c.y*a},f=hG({source:d,sourcePosition:t,target:p}),m=f.x!==0?"x":"y",h=f[m];let g=[],x,b;const y={x:0,y:0},w={x:0,y:0},[,,v,N]=cw({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(l[m]*c[m]===-1){m==="x"?(x=s.x??d.x+(p.x-d.x)*i,b=s.y??(d.y+p.y)/2):(x=s.x??(d.x+p.x)/2,b=s.y??d.y+(p.y-d.y)*i);const M=[{x,y:d.y},{x,y:p.y}],_=[{x:d.x,y:b},{x:p.x,y:b}];l[m]===h?g=m==="x"?M:_:g=m==="x"?_:M}else{const M=[{x:d.x,y:p.y}],_=[{x:p.x,y:d.y}];if(m==="x"?g=l.x===h?_:M:g=l.y===h?M:_,t===o){const A=Math.abs(e[m]-n[m]);if(A<=a){const P=Math.min(a-1,a-A);l[m]===h?y[m]=(d[m]>e[m]?-1:1)*P:w[m]=(p[m]>n[m]?-1:1)*P}}if(t!==o){const A=m==="x"?"y":"x",P=l[m]===c[A],L=d[A]>p[A],B=d[A]<p[A];(l[m]===1&&(!P&&L||P&&B)||l[m]!==1&&(!P&&B||P&&L))&&(g=m==="x"?M:_)}const $={x:d.x+y.x,y:d.y+y.y},E={x:p.x+w.x,y:p.y+w.y},R=Math.max(Math.abs($.x-g[0].x),Math.abs(E.x-g[0].x)),O=Math.max(Math.abs($.y-g[0].y),Math.abs(E.y-g[0].y));R>=O?(x=($.x+E.x)/2,b=g[0].y):(x=g[0].x,b=($.y+E.y)/2)}const k={x:d.x+y.x,y:d.y+y.y},C={x:p.x+w.x,y:p.y+w.y};return[[e,...k.x!==g[0].x||k.y!==g[0].y?[k]:[],...g,...C.x!==g[g.length-1].x||C.y!==g[g.length-1].y?[C]:[],n],x,b,v,N]}function bG(e,t,n,o){const s=Math.min(pm(e,t)/2,pm(t,n)/2,o),{x:a,y:i}=t;if(e.x===a&&a===n.x||e.y===i&&i===n.y)return`L${a} ${i}`;if(e.y===i){const d=e.x<n.x?-1:1,p=e.y<n.y?1:-1;return`L ${a+s*d},${i}Q ${a},${i} ${a},${i+s*p}`}const l=e.x<n.x?1:-1,c=e.y<n.y?-1:1;return`L ${a},${i+s*c}Q ${a},${i} ${a+s*l},${i}`}function Ac({sourceX:e,sourceY:t,sourcePosition:n=Ae.Bottom,targetX:o,targetY:s,targetPosition:a=Ae.Top,borderRadius:i=5,centerX:l,centerY:c,offset:d=20,stepPosition:p=.5}){const[f,m,h,g,x]=gG({source:{x:e,y:t},sourcePosition:n,target:{x:o,y:s},targetPosition:a,center:{x:l,y:c},offset:d,stepPosition:p});let b=`M${f[0].x} ${f[0].y}`;for(let y=1;y<f.length-1;y++)b+=bG(f[y-1],f[y],f[y+1],i);return b+=`L${f[f.length-1].x} ${f[f.length-1].y}`,[b,m,h,g,x]}function fm(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function xG(e){const{sourceNode:t,targetNode:n}=e;if(!fm(t)||!fm(n))return null;const o=t.internals.handleBounds||mm(t.handles),s=n.internals.handleBounds||mm(n.handles),a=hm(o?.source??[],e.sourceHandle),i=hm(e.connectionMode===jr.Strict?s?.target??[]:(s?.target??[]).concat(s?.source??[]),e.targetHandle);if(!a||!i)return e.onError?.("008",nn.error008(a?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=a?.position||Ae.Bottom,c=i?.position||Ae.Top,d=lr(t,a,l),p=lr(n,i,c);return{sourceX:d.x,sourceY:d.y,targetX:p.x,targetY:p.y,sourcePosition:l,targetPosition:c}}function mm(e){if(!e)return null;const t=[],n=[];for(const o of e)o.width=o.width??1,o.height=o.height??1,o.type==="source"?t.push(o):o.type==="target"&&n.push(o);return{source:t,target:n}}function lr(e,t,n=Ae.Left,o=!1){const s=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:i,height:l}=t??Sn(e);if(o)return{x:s+i/2,y:a+l/2};switch(t?.position??n){case Ae.Top:return{x:s+i/2,y:a};case Ae.Right:return{x:s+i,y:a+l/2};case Ae.Bottom:return{x:s+i/2,y:a+l};case Ae.Left:return{x:s,y:a+l/2}}}function hm(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function Ec(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(o=>`${o}=${e[o]}`).join("&")}`:""}function yG(e,{id:t,defaultColor:n,defaultMarkerStart:o,defaultMarkerEnd:s}){const a=new Set;return e.reduce((i,l)=>([l.markerStart||o,l.markerEnd||s].forEach(c=>{if(c&&typeof c=="object"){const d=Ec(c,t);a.has(d)||(i.push({id:d,color:c.color||n,...c}),a.add(d))}}),i),[]).sort((i,l)=>i.id.localeCompare(l.id))}const uw=1e3,vG=10,Su={nodeOrigin:[0,0],nodeExtent:qo,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},wG={...Su,checkEquality:!0};function Cu(e,t){const n={...e};for(const o in t)t[o]!==void 0&&(n[o]=t[o]);return n}function NG(e,t,n){const o=Cu(Su,n);for(const s of e.values())if(s.parentId)Au(s,e,t,o);else{const a=ls(s,o.nodeOrigin),i=Ur(s.extent)?s.extent:o.nodeExtent,l=ir(a,i,Sn(s));s.internals.positionAbsolute=l}}function kG(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;const n=[],o=[];for(const s of e.handles){const a={id:s.id,width:s.width??1,height:s.height??1,nodeId:e.id,x:s.x,y:s.y,position:s.position,type:s.type};s.type==="source"?n.push(a):s.type==="target"&&o.push(a)}return{source:n,target:o}}function Mu(e){return e==="manual"}function Ic(e,t,n,o={}){const s=Cu(wG,o),a={i:0},i=new Map(t),l=s?.elevateNodesOnSelect&&!Mu(s.zIndexMode)?uw:0;let c=e.length>0,d=!1;t.clear(),n.clear();for(const p of e){let f=i.get(p.id);if(s.checkEquality&&p===f?.internals.userNode)t.set(p.id,f);else{const m=ls(p,s.nodeOrigin),h=Ur(p.extent)?p.extent:s.nodeExtent,g=ir(m,h,Sn(p));f={...s.defaults,...p,measured:{width:p.measured?.width,height:p.measured?.height},internals:{positionAbsolute:g,handleBounds:kG(p,f),z:pw(p,l,s.zIndexMode),userNode:p}},t.set(p.id,f)}(f.measured===void 0||f.measured.width===void 0||f.measured.height===void 0)&&!f.hidden&&(c=!1),p.parentId&&Au(f,t,n,o,a),d||=p.selected??!1}return{nodesInitialized:c,hasSelectedNodes:d}}function SG(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function Au(e,t,n,o,s){const{elevateNodesOnSelect:a,nodeOrigin:i,nodeExtent:l,zIndexMode:c}=Cu(Su,o),d=e.parentId,p=t.get(d);if(!p){console.warn(`Parent node ${d} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}SG(e,n),s&&!p.parentId&&p.internals.rootParentIndex===void 0&&c==="auto"&&(p.internals.rootParentIndex=++s.i,p.internals.z=p.internals.z+s.i*vG),s&&p.internals.rootParentIndex!==void 0&&(s.i=p.internals.rootParentIndex);const f=a&&!Mu(c)?uw:0,{x:m,y:h,z:g}=CG(e,p,i,l,f,c),{positionAbsolute:x}=e.internals,b=m!==x.x||h!==x.y;(b||g!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:b?{x:m,y:h}:x,z:g}})}function pw(e,t,n){const o=Ot(e.zIndex)?e.zIndex:0;return Mu(n)?o:o+(e.selected?t:0)}function CG(e,t,n,o,s,a){const{x:i,y:l}=t.internals.positionAbsolute,c=Sn(e),d=ls(e,n),p=Ur(e.extent)?ir(d,e.extent,c):d;let f=ir({x:i+p.x,y:l+p.y},o,c);e.extent==="parent"&&(f=J1(f,c,t));const m=pw(e,s,a),h=t.internals.z??0;return{x:f.x,y:f.y,z:h>=m?h+1:m}}function Eu(e,t,n,o=[0,0]){const s=[],a=new Map;for(const i of e){const l=t.get(i.parentId);if(!l)continue;const c=a.get(i.parentId)?.expandedRect??Vr(l),d=tw(c,i.rect);a.set(i.parentId,{expandedRect:d,parent:l})}return a.size>0&&a.forEach(({expandedRect:i,parent:l},c)=>{const d=l.internals.positionAbsolute,p=Sn(l),f=l.origin??o,m=i.x<d.x?Math.round(Math.abs(d.x-i.x)):0,h=i.y<d.y?Math.round(Math.abs(d.y-i.y)):0,g=Math.max(p.width,Math.round(i.width)),x=Math.max(p.height,Math.round(i.height)),b=(g-p.width)*f[0],y=(x-p.height)*f[1];(m>0||h>0||b||y)&&(s.push({id:c,type:"position",position:{x:l.position.x-m+b,y:l.position.y-h+y}}),n.get(c)?.forEach(w=>{e.some(v=>v.id===w.id)||s.push({id:w.id,type:"position",position:{x:w.position.x+m,y:w.position.y+h}})})),(p.width<i.width||p.height<i.height||m||h)&&s.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:g+(m?f[0]*m-b:0),height:x+(h?f[1]*h-y:0)}})}),s}function MG(e,t,n,o,s,a,i){const l=o?.querySelector(".xyflow__viewport");let c=!1;if(!l)return{changes:[],updatedInternals:c};const d=[],p=window.getComputedStyle(l),{m22:f}=new window.DOMMatrixReadOnly(p.transform),m=[];for(const h of e.values()){const g=t.get(h.id);if(!g)continue;if(g.hidden){t.set(g.id,{...g,internals:{...g.internals,handleBounds:void 0}}),c=!0;continue}const x=ku(h.nodeElement),b=g.measured.width!==x.width||g.measured.height!==x.height;if(!!(x.width&&x.height&&(b||!g.internals.handleBounds||h.force))){const w=h.nodeElement.getBoundingClientRect(),v=Ur(g.extent)?g.extent:a;let{positionAbsolute:N}=g.internals;g.parentId&&g.extent==="parent"?N=J1(N,x,t.get(g.parentId)):v&&(N=ir(N,v,x));const k={...g,measured:x,internals:{...g.internals,positionAbsolute:N,handleBounds:{source:cm("source",h.nodeElement,w,f,g.id),target:cm("target",h.nodeElement,w,f,g.id)}}};t.set(g.id,k),g.parentId&&Au(k,t,n,{nodeOrigin:s,zIndexMode:i}),c=!0,b&&(d.push({id:g.id,type:"dimensions",dimensions:x}),g.expandParent&&g.parentId&&m.push({id:g.id,parentId:g.parentId,rect:Vr(k,s)}))}}if(m.length>0){const h=Eu(m,t,n,s);d.push(...h)}return{changes:d,updatedInternals:c}}async function AG({delta:e,panZoom:t,transform:n,translateExtent:o,width:s,height:a}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);const i=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[s,a]],o),l=!!i&&(i.x!==n[0]||i.y!==n[1]||i.k!==n[2]);return Promise.resolve(l)}function gm(e,t,n,o,s,a){let i=s;const l=o.get(i)||new Map;o.set(i,l.set(n,t)),i=`${s}-${e}`;const c=o.get(i)||new Map;if(o.set(i,c.set(n,t)),a){i=`${s}-${e}-${a}`;const d=o.get(i)||new Map;o.set(i,d.set(n,t))}}function fw(e,t,n){e.clear(),t.clear();for(const o of n){const{source:s,target:a,sourceHandle:i=null,targetHandle:l=null}=o,c={edgeId:o.id,source:s,target:a,sourceHandle:i,targetHandle:l},d=`${s}-${i}--${a}-${l}`,p=`${a}-${l}--${s}-${i}`;gm("source",c,p,e,s,i),gm("target",c,d,e,a,l),t.set(o.id,o)}}function mw(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:mw(n,t):!1}function bm(e,t,n){let o=e;do{if(o?.matches?.(t))return!0;if(o===n)return!1;o=o?.parentElement}while(o);return!1}function EG(e,t,n,o){const s=new Map;for(const[a,i]of e)if((i.selected||i.id===o)&&(!i.parentId||!mw(i,e))&&(i.draggable||t&&typeof i.draggable>"u")){const l=e.get(a);l&&s.set(a,{id:a,position:l.position||{x:0,y:0},distance:{x:n.x-l.internals.positionAbsolute.x,y:n.y-l.internals.positionAbsolute.y},extent:l.extent,parentId:l.parentId,origin:l.origin,expandParent:l.expandParent,internals:{positionAbsolute:l.internals.positionAbsolute||{x:0,y:0}},measured:{width:l.measured.width??0,height:l.measured.height??0}})}return s}function vl({nodeId:e,dragItems:t,nodeLookup:n,dragging:o=!0}){const s=[];for(const[i,l]of t){const c=n.get(i)?.internals.userNode;c&&s.push({...c,position:l.position,dragging:o})}if(!e)return[s[0],s];const a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:o}:s[0],s]}function IG({dragItems:e,snapGrid:t,x:n,y:o}){const s=e.values().next().value;if(!s)return null;const a={x:n-s.distance.x,y:o-s.distance.y},i=ds(a,t);return{x:i.x-a.x,y:i.y-a.y}}function PG({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:o,onDragStop:s}){let a={x:null,y:null},i=0,l=new Map,c=!1,d={x:0,y:0},p=null,f=!1,m=null,h=!1,g=!1,x=null;function b({noDragClassName:w,handleSelector:v,domNode:N,isSelectable:k,nodeId:C,nodeClickDistance:D=0}){m=bt(N);function M({x:R,y:O}){const{nodeLookup:A,nodeExtent:P,snapGrid:L,snapToGrid:B,nodeOrigin:z,onNodeDrag:T,onSelectionDrag:F,onError:H,updateNodePositions:j}=t();a={x:R,y:O};let Q=!1;const G=l.size>1,Z=G&&P?Mc(cs(l)):null,V=G&&B?IG({dragItems:l,snapGrid:L,x:R,y:O}):null;for(const[K,X]of l){if(!A.has(K))continue;let te={x:R-X.distance.x,y:O-X.distance.y};B&&(te=V?{x:Math.round(te.x+V.x),y:Math.round(te.y+V.y)}:ds(te,L));let he=null;if(G&&P&&!X.extent&&Z){const{positionAbsolute:re}=X.internals,de=re.x-Z.x+P[0][0],ue=re.x+X.measured.width-Z.x2+P[1][0],be=re.y-Z.y+P[0][1],Se=re.y+X.measured.height-Z.y2+P[1][1];he=[[de,be],[ue,Se]]}const{position:xe,positionAbsolute:ee}=X1({nodeId:K,nextPosition:te,nodeLookup:A,nodeExtent:he||P,nodeOrigin:z,onError:H});Q=Q||X.position.x!==xe.x||X.position.y!==xe.y,X.position=xe,X.internals.positionAbsolute=ee}if(g=g||Q,!!Q&&(j(l,!0),x&&(o||T||!C&&F))){const[K,X]=vl({nodeId:C,dragItems:l,nodeLookup:A});o?.(x,l,K,X),T?.(x,K,X),C||F?.(x,X)}}async function _(){if(!p)return;const{transform:R,panBy:O,autoPanSpeed:A,autoPanOnNodeDrag:P}=t();if(!P){c=!1,cancelAnimationFrame(i);return}const[L,B]=ew(d,p,A);(L!==0||B!==0)&&(a.x=(a.x??0)-L/R[2],a.y=(a.y??0)-B/R[2],await O({x:L,y:B})&&M(a)),i=requestAnimationFrame(_)}function $(R){const{nodeLookup:O,multiSelectionActive:A,nodesDraggable:P,transform:L,snapGrid:B,snapToGrid:z,selectNodesOnDrag:T,onNodeDragStart:F,onSelectionDragStart:H,unselectNodesAndEdges:j}=t();f=!0,(!T||!k)&&!A&&C&&(O.get(C)?.selected||j()),k&&T&&C&&e?.(C);const Q=$o(R.sourceEvent,{transform:L,snapGrid:B,snapToGrid:z,containerBounds:p});if(a=Q,l=EG(O,P,Q,C),l.size>0&&(n||F||!C&&H)){const[G,Z]=vl({nodeId:C,dragItems:l,nodeLookup:O});n?.(R.sourceEvent,l,G,Z),F?.(R.sourceEvent,G,Z),C||H?.(R.sourceEvent,Z)}}const E=_1().clickDistance(D).on("start",R=>{const{domNode:O,nodeDragThreshold:A,transform:P,snapGrid:L,snapToGrid:B}=t();p=O?.getBoundingClientRect()||null,h=!1,g=!1,x=R.sourceEvent,A===0&&$(R),a=$o(R.sourceEvent,{transform:P,snapGrid:L,snapToGrid:B,containerBounds:p}),d=Bt(R.sourceEvent,p)}).on("drag",R=>{const{autoPanOnNodeDrag:O,transform:A,snapGrid:P,snapToGrid:L,nodeDragThreshold:B,nodeLookup:z}=t(),T=$o(R.sourceEvent,{transform:A,snapGrid:P,snapToGrid:L,containerBounds:p});if(x=R.sourceEvent,(R.sourceEvent.type==="touchmove"&&R.sourceEvent.touches.length>1||C&&!z.has(C))&&(h=!0),!h){if(!c&&O&&f&&(c=!0,_()),!f){const F=Bt(R.sourceEvent,p),H=F.x-d.x,j=F.y-d.y;Math.sqrt(H*H+j*j)>B&&$(R)}(a.x!==T.xSnapped||a.y!==T.ySnapped)&&l&&f&&(d=Bt(R.sourceEvent,p),M(T))}}).on("end",R=>{if(!(!f||h)&&(c=!1,f=!1,cancelAnimationFrame(i),l.size>0)){const{nodeLookup:O,updateNodePositions:A,onNodeDragStop:P,onSelectionDragStop:L}=t();if(g&&(A(l,!1),g=!1),s||P||!C&&L){const[B,z]=vl({nodeId:C,dragItems:l,nodeLookup:O,dragging:!1});s?.(R.sourceEvent,l,B,z),P?.(R.sourceEvent,B,z),C||L?.(R.sourceEvent,z)}}}).filter(R=>{const O=R.target;return!R.button&&(!w||!bm(O,`.${w}`,N))&&(!v||bm(O,v,N))});m.call(E)}function y(){m?.on(".drag",null)}return{update:b,destroy:y}}function _G(e,t,n){const o=[],s={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const a of t.values())Go(s,Vr(a))>0&&o.push(a);return o}const $G=250;function DG(e,t,n,o){let s=[],a=1/0;const i=_G(e,n,t+$G);for(const l of i){const c=[...l.internals.handleBounds?.source??[],...l.internals.handleBounds?.target??[]];for(const d of c){if(o.nodeId===d.nodeId&&o.type===d.type&&o.id===d.id)continue;const{x:p,y:f}=lr(l,d,d.position,!0),m=Math.sqrt(Math.pow(p-e.x,2)+Math.pow(f-e.y,2));m>t||(m<a?(s=[{...d,x:p,y:f}],a=m):m===a&&s.push({...d,x:p,y:f}))}}if(!s.length)return null;if(s.length>1){const l=o.type==="source"?"target":"source";return s.find(c=>c.type===l)??s[0]}return s[0]}function hw(e,t,n,o,s,a=!1){const i=o.get(e);if(!i)return null;const l=s==="strict"?i.internals.handleBounds?.[t]:[...i.internals.handleBounds?.source??[],...i.internals.handleBounds?.target??[]],c=(n?l?.find(d=>d.id===n):l?.[0])??null;return c&&a?{...c,...lr(i,c,c.position,!0)}:c}function gw(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function LG(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const bw=()=>!0;function TG(e,{connectionMode:t,connectionRadius:n,handleId:o,nodeId:s,edgeUpdaterType:a,isTarget:i,domNode:l,nodeLookup:c,lib:d,autoPanOnConnect:p,flowId:f,panBy:m,cancelConnection:h,onConnectStart:g,onConnect:x,onConnectEnd:b,isValidConnection:y=bw,onReconnectEnd:w,updateConnection:v,getTransform:N,getFromHandle:k,autoPanSpeed:C,dragThreshold:D=1,handleDomNode:M}){const _=ow(e.target);let $=0,E;const{x:R,y:O}=Bt(e),A=gw(a,M),P=l?.getBoundingClientRect();let L=!1;if(!P||!A)return;const B=hw(s,A,o,c,t);if(!B)return;let z=Bt(e,P),T=!1,F=null,H=!1,j=null;function Q(){if(!p||!P)return;const[xe,ee]=ew(z,P,C);m({x:xe,y:ee}),$=requestAnimationFrame(Q)}const G={...B,nodeId:s,type:A,position:B.position},Z=c.get(s);let K={inProgress:!0,isValid:null,from:lr(Z,G,Ae.Left,!0),fromHandle:G,fromPosition:G.position,fromNode:Z,to:z,toHandle:null,toPosition:sm[G.position],toNode:null,pointer:z};function X(){L=!0,v(K),g?.(e,{nodeId:s,handleId:o,handleType:A})}D===0&&X();function te(xe){if(!L){const{x:Se,y:Oe}=Bt(xe),Be=Se-R,He=Oe-O;if(!(Be*Be+He*He>D*D))return;X()}if(!k()||!G){he(xe);return}const ee=N();z=Bt(xe,P),E=DG(us(z,ee,!1,[1,1]),n,c,G),T||(Q(),T=!0);const re=xw(xe,{handle:E,connectionMode:t,fromNodeId:s,fromHandleId:o,fromType:i?"target":"source",isValidConnection:y,doc:_,lib:d,flowId:f,nodeLookup:c});j=re.handleDomNode,F=re.connection,H=LG(!!E,re.isValid);const de=c.get(s),ue=de?lr(de,G,Ae.Left,!0):K.from,be={...K,from:ue,isValid:H,to:re.toHandle&&H?Da({x:re.toHandle.x,y:re.toHandle.y},ee):z,toHandle:re.toHandle,toPosition:H&&re.toHandle?re.toHandle.position:sm[G.position],toNode:re.toHandle?c.get(re.toHandle.nodeId):null,pointer:z};v(be),K=be}function he(xe){if(!("touches"in xe&&xe.touches.length>0)){if(L){(E||j)&&F&&H&&x?.(F);const{inProgress:ee,...re}=K,de={...re,toPosition:K.toHandle?K.toPosition:null};b?.(xe,de),a&&w?.(xe,de)}h(),cancelAnimationFrame($),T=!1,H=!1,F=null,j=null,_.removeEventListener("mousemove",te),_.removeEventListener("mouseup",he),_.removeEventListener("touchmove",te),_.removeEventListener("touchend",he)}}_.addEventListener("mousemove",te),_.addEventListener("mouseup",he),_.addEventListener("touchmove",te),_.addEventListener("touchend",he)}function xw(e,{handle:t,connectionMode:n,fromNodeId:o,fromHandleId:s,fromType:a,doc:i,lib:l,flowId:c,isValidConnection:d=bw,nodeLookup:p}){const f=a==="target",m=t?i.querySelector(`.${l}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:h,y:g}=Bt(e),x=i.elementFromPoint(h,g),b=x?.classList.contains(`${l}-flow__handle`)?x:m,y={handleDomNode:b,isValid:!1,connection:null,toHandle:null};if(b){const w=gw(void 0,b),v=b.getAttribute("data-nodeid"),N=b.getAttribute("data-handleid"),k=b.classList.contains("connectable"),C=b.classList.contains("connectableend");if(!v||!w)return y;const D={source:f?v:o,sourceHandle:f?N:s,target:f?o:v,targetHandle:f?s:N};y.connection=D;const _=k&&C&&(n===jr.Strict?f&&w==="source"||!f&&w==="target":v!==o||N!==s);y.isValid=_&&d(D),y.toHandle=hw(v,w,N,p,n,!0)}return y}const Pc={onPointerDown:TG,isValid:xw};function RG({domNode:e,panZoom:t,getTransform:n,getViewScale:o}){const s=bt(e);function a({translateExtent:l,width:c,height:d,zoomStep:p=1,pannable:f=!0,zoomable:m=!0,inversePan:h=!1}){const g=v=>{if(v.sourceEvent.type!=="wheel"||!t)return;const N=n(),k=v.sourceEvent.ctrlKey&&Wo()?10:1,C=-v.sourceEvent.deltaY*(v.sourceEvent.deltaMode===1?.05:v.sourceEvent.deltaMode?1:.002)*p,D=N[2]*Math.pow(2,C*k);t.scaleTo(D)};let x=[0,0];const b=v=>{(v.sourceEvent.type==="mousedown"||v.sourceEvent.type==="touchstart")&&(x=[v.sourceEvent.clientX??v.sourceEvent.touches[0].clientX,v.sourceEvent.clientY??v.sourceEvent.touches[0].clientY])},y=v=>{const N=n();if(v.sourceEvent.type!=="mousemove"&&v.sourceEvent.type!=="touchmove"||!t)return;const k=[v.sourceEvent.clientX??v.sourceEvent.touches[0].clientX,v.sourceEvent.clientY??v.sourceEvent.touches[0].clientY],C=[k[0]-x[0],k[1]-x[1]];x=k;const D=o()*Math.max(N[2],Math.log(N[2]))*(h?-1:1),M={x:N[0]-C[0]*D,y:N[1]-C[1]*D},_=[[0,0],[c,d]];t.setViewportConstrained({x:M.x,y:M.y,zoom:N[2]},_,l)},w=Q1().on("start",b).on("zoom",f?y:null).on("zoom.wheel",m?g:null);s.call(w,{})}function i(){s.on("zoom",null)}return{update:a,destroy:i,pointer:Lt}}const yi=e=>({x:e.x,y:e.y,zoom:e.k}),wl=({x:e,y:t,zoom:n})=>gi.translate(e,t).scale(n),kr=(e,t)=>e.target.closest(`.${t}`),yw=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),OG=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Nl=(e,t=0,n=OG,o=()=>{})=>{const s=typeof t=="number"&&t>0;return s||o(),s?e.transition().duration(t).ease(n).on("end",o):e},vw=e=>{const t=e.ctrlKey&&Wo()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function BG({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:o,panOnScrollMode:s,panOnScrollSpeed:a,zoomOnPinch:i,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:d}){return p=>{if(kr(p,t))return p.ctrlKey&&p.preventDefault(),!1;p.preventDefault(),p.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(p.ctrlKey&&i){const b=Lt(p),y=vw(p),w=f*Math.pow(2,y);o.scaleTo(n,w,b,p);return}const m=p.deltaMode===1?20:1;let h=s===Jn.Vertical?0:p.deltaX*m,g=s===Jn.Horizontal?0:p.deltaY*m;!Wo()&&p.shiftKey&&s!==Jn.Vertical&&(h=p.deltaY*m,g=0),o.translateBy(n,-(h/f)*a,-(g/f)*a,{internal:!0});const x=yi(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(p,x),e.panScrollTimeout=setTimeout(()=>{d?.(p,x),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(p,x))}}function zG({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(o,s){const a=o.type==="wheel",i=!t&&a&&!o.ctrlKey,l=kr(o,e);if(o.ctrlKey&&a&&l&&o.preventDefault(),i||l)return null;o.preventDefault(),n.call(this,o,s)}}function FG({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return o=>{if(o.sourceEvent?.internal)return;const s=yi(o.transform);e.mouseButton=o.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=s,o.sourceEvent?.type==="mousedown"&&t(!0),n&&n?.(o.sourceEvent,s)}}function jG({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:o,onPanZoom:s}){return a=>{e.usedRightMouseButton=!!(n&&yw(t,e.mouseButton??0)),a.sourceEvent?.sync||o([a.transform.x,a.transform.y,a.transform.k]),s&&!a.sourceEvent?.internal&&s?.(a.sourceEvent,yi(a.transform))}}function HG({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:o,onPanZoomEnd:s,onPaneContextMenu:a}){return i=>{if(!i.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&yw(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&a(i.sourceEvent),e.usedRightMouseButton=!1,o(!1),s)){const l=yi(i.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s?.(i.sourceEvent,l)},n?150:0)}}}function VG({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:o,panOnScroll:s,zoomOnDoubleClick:a,userSelectionActive:i,noWheelClassName:l,noPanClassName:c,lib:d,connectionInProgress:p}){return f=>{const m=e||t,h=n&&f.ctrlKey,g=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(kr(f,`${d}-flow__node`)||kr(f,`${d}-flow__edge`)))return!0;if(!o&&!m&&!s&&!a&&!n||i||p&&!g||kr(f,l)&&g||kr(f,c)&&(!g||s&&g&&!e)||!n&&f.ctrlKey&&g)return!1;if(!n&&f.type==="touchstart"&&f.touches?.length>1)return f.preventDefault(),!1;if(!m&&!s&&!h&&g||!o&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(o)&&!o.includes(f.button)&&f.type==="mousedown")return!1;const x=Array.isArray(o)&&o.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||g)&&x}}function UG({domNode:e,minZoom:t,maxZoom:n,translateExtent:o,viewport:s,onPanZoom:a,onPanZoomStart:i,onPanZoomEnd:l,onDraggingChange:c}){const d={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},p=e.getBoundingClientRect(),f=Q1().scaleExtent([t,n]).translateExtent(o),m=bt(e).call(f);w({x:s.x,y:s.y,zoom:Hr(s.zoom,t,n)},[[0,0],[p.width,p.height]],o);const h=m.on("wheel.zoom"),g=m.on("dblclick.zoom");f.wheelDelta(vw);function x(E,R){return m?new Promise(O=>{f?.interpolate(R?.interpolate==="linear"?_o:ta).transform(Nl(m,R?.duration,R?.ease,()=>O(!0)),E)}):Promise.resolve(!1)}function b({noWheelClassName:E,noPanClassName:R,onPaneContextMenu:O,userSelectionActive:A,panOnScroll:P,panOnDrag:L,panOnScrollMode:B,panOnScrollSpeed:z,preventScrolling:T,zoomOnPinch:F,zoomOnScroll:H,zoomOnDoubleClick:j,zoomActivationKeyPressed:Q,lib:G,onTransformChange:Z,connectionInProgress:V,paneClickDistance:K,selectionOnDrag:X}){A&&!d.isZoomingOrPanning&&y();const te=P&&!Q&&!A;f.clickDistance(X?1/0:!Ot(K)||K<0?0:K);const he=te?BG({zoomPanValues:d,noWheelClassName:E,d3Selection:m,d3Zoom:f,panOnScrollMode:B,panOnScrollSpeed:z,zoomOnPinch:F,onPanZoomStart:i,onPanZoom:a,onPanZoomEnd:l}):zG({noWheelClassName:E,preventScrolling:T,d3ZoomHandler:h});if(m.on("wheel.zoom",he,{passive:!1}),!A){const ee=FG({zoomPanValues:d,onDraggingChange:c,onPanZoomStart:i});f.on("start",ee);const re=jG({zoomPanValues:d,panOnDrag:L,onPaneContextMenu:!!O,onPanZoom:a,onTransformChange:Z});f.on("zoom",re);const de=HG({zoomPanValues:d,panOnDrag:L,panOnScroll:P,onPaneContextMenu:O,onPanZoomEnd:l,onDraggingChange:c});f.on("end",de)}const xe=VG({zoomActivationKeyPressed:Q,panOnDrag:L,zoomOnScroll:H,panOnScroll:P,zoomOnDoubleClick:j,zoomOnPinch:F,userSelectionActive:A,noPanClassName:R,noWheelClassName:E,lib:G,connectionInProgress:V});f.filter(xe),j?m.on("dblclick.zoom",g):m.on("dblclick.zoom",null)}function y(){f.on("zoom",null)}async function w(E,R,O){const A=wl(E),P=f?.constrain()(A,R,O);return P&&await x(P),new Promise(L=>L(P))}async function v(E,R){const O=wl(E);return await x(O,R),new Promise(A=>A(O))}function N(E){if(m){const R=wl(E),O=m.property("__zoom");(O.k!==E.zoom||O.x!==E.x||O.y!==E.y)&&f?.transform(m,R,null,{sync:!0})}}function k(){const E=m?q1(m.node()):{x:0,y:0,k:1};return{x:E.x,y:E.y,zoom:E.k}}function C(E,R){return m?new Promise(O=>{f?.interpolate(R?.interpolate==="linear"?_o:ta).scaleTo(Nl(m,R?.duration,R?.ease,()=>O(!0)),E)}):Promise.resolve(!1)}function D(E,R){return m?new Promise(O=>{f?.interpolate(R?.interpolate==="linear"?_o:ta).scaleBy(Nl(m,R?.duration,R?.ease,()=>O(!0)),E)}):Promise.resolve(!1)}function M(E){f?.scaleExtent(E)}function _(E){f?.translateExtent(E)}function $(E){const R=!Ot(E)||E<0?0:E;f?.clickDistance(R)}return{update:b,destroy:y,setViewport:v,setViewportConstrained:w,getViewport:k,scaleTo:C,scaleBy:D,setScaleExtent:M,setTranslateExtent:_,syncViewport:N,setClickDistance:$}}var qr;(function(e){e.Line="line",e.Handle="handle"})(qr||(qr={}));function qG({width:e,prevWidth:t,height:n,prevHeight:o,affectsX:s,affectsY:a}){const i=e-t,l=n-o,c=[i>0?1:i<0?-1:0,l>0?1:l<0?-1:0];return i&&s&&(c[0]=c[0]*-1),l&&a&&(c[1]=c[1]*-1),c}function xm(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),o=e.includes("left"),s=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:o,affectsY:s}}function An(e,t){return Math.max(0,t-e)}function En(e,t){return Math.max(0,e-t)}function Vs(e,t,n){return Math.max(0,t-e,e-n)}function ym(e,t){return e?!t:t}function QG(e,t,n,o,s,a,i,l){let{affectsX:c,affectsY:d}=t;const{isHorizontal:p,isVertical:f}=t,m=p&&f,{xSnapped:h,ySnapped:g}=n,{minWidth:x,maxWidth:b,minHeight:y,maxHeight:w}=o,{x:v,y:N,width:k,height:C,aspectRatio:D}=e;let M=Math.floor(p?h-e.pointerX:0),_=Math.floor(f?g-e.pointerY:0);const $=k+(c?-M:M),E=C+(d?-_:_),R=-a[0]*k,O=-a[1]*C;let A=Vs($,x,b),P=Vs(E,y,w);if(i){let z=0,T=0;c&&M<0?z=An(v+M+R,i[0][0]):!c&&M>0&&(z=En(v+$+R,i[1][0])),d&&_<0?T=An(N+_+O,i[0][1]):!d&&_>0&&(T=En(N+E+O,i[1][1])),A=Math.max(A,z),P=Math.max(P,T)}if(l){let z=0,T=0;c&&M>0?z=En(v+M,l[0][0]):!c&&M<0&&(z=An(v+$,l[1][0])),d&&_>0?T=En(N+_,l[0][1]):!d&&_<0&&(T=An(N+E,l[1][1])),A=Math.max(A,z),P=Math.max(P,T)}if(s){if(p){const z=Vs($/D,y,w)*D;if(A=Math.max(A,z),i){let T=0;!c&&!d||c&&!d&&m?T=En(N+O+$/D,i[1][1])*D:T=An(N+O+(c?M:-M)/D,i[0][1])*D,A=Math.max(A,T)}if(l){let T=0;!c&&!d||c&&!d&&m?T=An(N+$/D,l[1][1])*D:T=En(N+(c?M:-M)/D,l[0][1])*D,A=Math.max(A,T)}}if(f){const z=Vs(E*D,x,b)/D;if(P=Math.max(P,z),i){let T=0;!c&&!d||d&&!c&&m?T=En(v+E*D+R,i[1][0])/D:T=An(v+(d?_:-_)*D+R,i[0][0])/D,P=Math.max(P,T)}if(l){let T=0;!c&&!d||d&&!c&&m?T=An(v+E*D,l[1][0])/D:T=En(v+(d?_:-_)*D,l[0][0])/D,P=Math.max(P,T)}}}_=_+(_<0?P:-P),M=M+(M<0?A:-A),s&&(m?$>E*D?_=(ym(c,d)?-M:M)/D:M=(ym(c,d)?-_:_)*D:p?(_=M/D,d=c):(M=_*D,c=d));const L=c?v+M:v,B=d?N+_:N;return{width:k+(c?-M:M),height:C+(d?-_:_),x:a[0]*M*(c?-1:1)+L,y:a[1]*_*(d?-1:1)+B}}const ww={width:0,height:0,x:0,y:0},GG={...ww,pointerX:0,pointerY:0,aspectRatio:1};function WG(e){return[[0,0],[e.measured.width,e.measured.height]]}function KG(e,t,n){const o=t.position.x+e.position.x,s=t.position.y+e.position.y,a=e.measured.width??0,i=e.measured.height??0,l=n[0]*a,c=n[1]*i;return[[o-l,s-c],[o+a-l,s+i-c]]}function YG({domNode:e,nodeId:t,getStoreItems:n,onChange:o,onEnd:s}){const a=bt(e);let i={controlDirection:xm("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function l({controlPosition:d,boundaries:p,keepAspectRatio:f,resizeDirection:m,onResizeStart:h,onResize:g,onResizeEnd:x,shouldResize:b}){let y={...ww},w={...GG};i={boundaries:p,resizeDirection:m,keepAspectRatio:f,controlDirection:xm(d)};let v,N=null,k=[],C,D,M,_=!1;const $=_1().on("start",E=>{const{nodeLookup:R,transform:O,snapGrid:A,snapToGrid:P,nodeOrigin:L,paneDomNode:B}=n();if(v=R.get(t),!v)return;N=B?.getBoundingClientRect()??null;const{xSnapped:z,ySnapped:T}=$o(E.sourceEvent,{transform:O,snapGrid:A,snapToGrid:P,containerBounds:N});y={width:v.measured.width??0,height:v.measured.height??0,x:v.position.x??0,y:v.position.y??0},w={...y,pointerX:z,pointerY:T,aspectRatio:y.width/y.height},C=void 0,v.parentId&&(v.extent==="parent"||v.expandParent)&&(C=R.get(v.parentId),D=C&&v.extent==="parent"?WG(C):void 0),k=[],M=void 0;for(const[F,H]of R)if(H.parentId===t&&(k.push({id:F,position:{...H.position},extent:H.extent}),H.extent==="parent"||H.expandParent)){const j=KG(H,v,H.origin??L);M?M=[[Math.min(j[0][0],M[0][0]),Math.min(j[0][1],M[0][1])],[Math.max(j[1][0],M[1][0]),Math.max(j[1][1],M[1][1])]]:M=j}h?.(E,{...y})}).on("drag",E=>{const{transform:R,snapGrid:O,snapToGrid:A,nodeOrigin:P}=n(),L=$o(E.sourceEvent,{transform:R,snapGrid:O,snapToGrid:A,containerBounds:N}),B=[];if(!v)return;const{x:z,y:T,width:F,height:H}=y,j={},Q=v.origin??P,{width:G,height:Z,x:V,y:K}=QG(w,i.controlDirection,L,i.boundaries,i.keepAspectRatio,Q,D,M),X=G!==F,te=Z!==H,he=V!==z&&X,xe=K!==T&&te;if(!he&&!xe&&!X&&!te)return;if((he||xe||Q[0]===1||Q[1]===1)&&(j.x=he?V:y.x,j.y=xe?K:y.y,y.x=j.x,y.y=j.y,k.length>0)){const ue=V-z,be=K-T;for(const Se of k)Se.position={x:Se.position.x-ue+Q[0]*(G-F),y:Se.position.y-be+Q[1]*(Z-H)},B.push(Se)}if((X||te)&&(j.width=X&&(!i.resizeDirection||i.resizeDirection==="horizontal")?G:y.width,j.height=te&&(!i.resizeDirection||i.resizeDirection==="vertical")?Z:y.height,y.width=j.width,y.height=j.height),C&&v.expandParent){const ue=Q[0]*(j.width??0);j.x&&j.x<ue&&(y.x=ue,w.x=w.x-(j.x-ue));const be=Q[1]*(j.height??0);j.y&&j.y<be&&(y.y=be,w.y=w.y-(j.y-be))}const ee=qG({width:y.width,prevWidth:F,height:y.height,prevHeight:H,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),re={...y,direction:ee};b?.(E,re)!==!1&&(_=!0,g?.(E,re),o(j,B))}).on("end",E=>{_&&(x?.(E,{...y}),s?.({...y}),_=!1)});a.call($)}function c(){a.on(".drag",null)}return{update:l,destroy:c}}var Nw={exports:{}},kw={};/**
1172
+ * @license React
1173
+ * use-sync-external-store-shim/with-selector.production.js
1174
+ *
1175
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
1176
+ *
1177
+ * This source code is licensed under the MIT license found in the
1178
+ * LICENSE file in the root directory of this source tree.
1179
+ */var vi=fh,ZG=Fv;function XG(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var JG=typeof Object.is=="function"?Object.is:XG,eW=ZG.useSyncExternalStore,tW=vi.useRef,nW=vi.useEffect,rW=vi.useMemo,oW=vi.useDebugValue;kw.useSyncExternalStoreWithSelector=function(e,t,n,o,s){var a=tW(null);if(a.current===null){var i={hasValue:!1,value:null};a.current=i}else i=a.current;a=rW(function(){function c(h){if(!d){if(d=!0,p=h,h=o(h),s!==void 0&&i.hasValue){var g=i.value;if(s(g,h))return f=g}return f=h}if(g=f,JG(p,h))return g;var x=o(h);return s!==void 0&&s(g,x)?(p=h,g):(p=h,f=x)}var d=!1,p,f,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,o,s]);var l=eW(e,a[0],a[1]);return nW(function(){i.hasValue=!0,i.value=l},[l]),oW(l),l};Nw.exports=kw;var sW=Nw.exports;const aW=YN(sW),iW={},vm=e=>{let t;const n=new Set,o=(p,f)=>{const m=typeof p=="function"?p(t):p;if(!Object.is(m,t)){const h=t;t=f??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(g=>g(t,h))}},s=()=>t,c={setState:o,getState:s,getInitialState:()=>d,subscribe:p=>(n.add(p),()=>n.delete(p)),destroy:()=>{(iW?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},d=t=e(o,s,c);return c},lW=e=>e?vm(e):vm,{useDebugValue:cW}=Ze,{useSyncExternalStoreWithSelector:dW}=aW,uW=e=>e;function Sw(e,t=uW,n){const o=dW(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return cW(o),o}const wm=(e,t)=>{const n=lW(e),o=(s,a=t)=>Sw(n,s,a);return Object.assign(o,n),o},pW=(e,t)=>e?wm(e,t):wm;function Ge(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[o,s]of e)if(!Object.is(s,t.get(o)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const o of e)if(!t.has(o))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!Object.is(e[o],t[o]))return!1;return!0}const wi=qe(null),fW=wi.Provider,Cw=nn.error001();function Re(e,t){const n=Ne(wi);if(n===null)throw new Error(Cw);return Sw(n,e,t)}function We(){const e=Ne(wi);if(e===null)throw new Error(Cw);return q(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const Nm={display:"none"},mW={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Mw="react-flow__node-desc",Aw="react-flow__edge-desc",hW="react-flow__aria-live",gW=e=>e.ariaLiveMessage,bW=e=>e.ariaLabelConfig;function xW({rfId:e}){const t=Re(gW);return r("div",{id:`${hW}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:mW,children:t})}function yW({rfId:e,disableKeyboardA11y:t}){const n=Re(bW);return u(me,{children:[r("div",{id:`${Mw}-${e}`,style:Nm,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),r("div",{id:`${Aw}-${e}`,style:Nm,children:n["edge.a11yDescription.default"]}),!t&&r(xW,{rfId:e})]})}const Ni=Ke(({position:e="top-left",children:t,className:n,style:o,...s},a)=>{const i=`${e}`.split("-");return r("div",{className:tt(["react-flow__panel",n,...i]),style:o,ref:a,...s,children:t})});Ni.displayName="Panel";function vW({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:r(Ni,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:r("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const wW=e=>{const t=[],n=[];for(const[,o]of e.nodeLookup)o.selected&&t.push(o.internals.userNode);for(const[,o]of e.edgeLookup)o.selected&&n.push(o);return{selectedNodes:t,selectedEdges:n}},Us=e=>e.id;function NW(e,t){return Ge(e.selectedNodes.map(Us),t.selectedNodes.map(Us))&&Ge(e.selectedEdges.map(Us),t.selectedEdges.map(Us))}function kW({onSelectionChange:e}){const t=We(),{selectedNodes:n,selectedEdges:o}=Re(wW,NW);return J(()=>{const s={nodes:n,edges:o};e?.(s),t.getState().onSelectionChangeHandlers.forEach(a=>a(s))},[n,o,e]),null}const SW=e=>!!e.onSelectionChangeHandlers;function CW({onSelectionChange:e}){const t=Re(SW);return e||t?r(kW,{onSelectionChange:e}):null}const _c=typeof window<"u"?Ra:J,Ew=[0,0],MW={x:0,y:0,zoom:1},AW=["nodes","edges","defaultNodes","defaultEdges","onConnect","onConnectStart","onConnectEnd","onClickConnectStart","onClickConnectEnd","nodesDraggable","autoPanOnNodeFocus","nodesConnectable","nodesFocusable","edgesFocusable","edgesReconnectable","elevateNodesOnSelect","elevateEdgesOnSelect","minZoom","maxZoom","nodeExtent","onNodesChange","onEdgesChange","elementsSelectable","connectionMode","snapGrid","snapToGrid","translateExtent","connectOnClick","defaultEdgeOptions","fitView","fitViewOptions","onNodesDelete","onEdgesDelete","onDelete","onNodeDrag","onNodeDragStart","onNodeDragStop","onSelectionDrag","onSelectionDragStart","onSelectionDragStop","onMoveStart","onMove","onMoveEnd","noPanClassName","nodeOrigin","autoPanOnConnect","autoPanOnNodeDrag","onError","connectionRadius","isValidConnection","selectNodesOnDrag","nodeDragThreshold","connectionDragThreshold","onBeforeDelete","debug","autoPanSpeed","ariaLabelConfig","zIndexMode"],km=[...AW,"rfId"],EW=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),Sm={translateExtent:qo,nodeOrigin:Ew,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function IW(e){const{setNodes:t,setEdges:n,setMinZoom:o,setMaxZoom:s,setTranslateExtent:a,setNodeExtent:i,reset:l,setDefaultNodesAndEdges:c}=Re(EW,Ge),d=We();_c(()=>(c(e.defaultNodes,e.defaultEdges),()=>{p.current=Sm,l()}),[]);const p=ne(Sm);return _c(()=>{for(const f of km){const m=e[f],h=p.current[f];m!==h&&(typeof e[f]>"u"||(f==="nodes"?t(m):f==="edges"?n(m):f==="minZoom"?o(m):f==="maxZoom"?s(m):f==="translateExtent"?a(m):f==="nodeExtent"?i(m):f==="ariaLabelConfig"?d.setState({ariaLabelConfig:lG(m)}):f==="fitView"?d.setState({fitViewQueued:m}):f==="fitViewOptions"?d.setState({fitViewOptions:m}):d.setState({[f]:m})))}p.current=e},km.map(f=>e[f])),null}function Cm(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function PW(e){const[t,n]=I(e==="system"?null:e);return J(()=>{if(e!=="system"){n(e);return}const o=Cm(),s=()=>n(o?.matches?"dark":"light");return s(),o?.addEventListener("change",s),()=>{o?.removeEventListener("change",s)}},[e]),t!==null?t:Cm()?.matches?"dark":"light"}const Mm=typeof document<"u"?document:null;function Ko(e=null,t={target:Mm,actInsideInputWithModifier:!0}){const[n,o]=I(!1),s=ne(!1),a=ne(new Set([])),[i,l]=q(()=>{if(e!==null){const d=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace("+",`
1180
+ `).replace(`
1181
+
1182
+ `,`
1183
+ +`).split(`
1184
+ `)),p=d.reduce((f,m)=>f.concat(...m),[]);return[d,p]}return[[],[]]},[e]);return J(()=>{const c=t?.target??Mm,d=t?.actInsideInputWithModifier??!0;if(e!==null){const p=h=>{if(s.current=h.ctrlKey||h.metaKey||h.shiftKey||h.altKey,(!s.current||s.current&&!d)&&sw(h))return!1;const x=Em(h.code,l);if(a.current.add(h[x]),Am(i,a.current,!1)){const b=h.composedPath?.()?.[0]||h.target,y=b?.nodeName==="BUTTON"||b?.nodeName==="A";t.preventDefault!==!1&&(s.current||!y)&&h.preventDefault(),o(!0)}},f=h=>{const g=Em(h.code,l);Am(i,a.current,!0)?(o(!1),a.current.clear()):a.current.delete(h[g]),h.key==="Meta"&&a.current.clear(),s.current=!1},m=()=>{a.current.clear(),o(!1)};return c?.addEventListener("keydown",p),c?.addEventListener("keyup",f),window.addEventListener("blur",m),window.addEventListener("contextmenu",m),()=>{c?.removeEventListener("keydown",p),c?.removeEventListener("keyup",f),window.removeEventListener("blur",m),window.removeEventListener("contextmenu",m)}}},[e,o]),n}function Am(e,t,n){return e.filter(o=>n||o.length===t.size).some(o=>o.every(s=>t.has(s)))}function Em(e,t){return t.includes(e)?"code":"key"}const _W=()=>{const e=We();return q(()=>({zoomIn:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):Promise.resolve(!1)},zoomOut:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):Promise.resolve(!1)},zoomTo:(t,n)=>{const{panZoom:o}=e.getState();return o?o.scaleTo(t,n):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[o,s,a],panZoom:i}=e.getState();return i?(await i.setViewport({x:t.x??o,y:t.y??s,zoom:t.zoom??a},n),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[t,n,o]=e.getState().transform;return{x:t,y:n,zoom:o}},setCenter:async(t,n,o)=>e.getState().setCenter(t,n,o),fitBounds:async(t,n)=>{const{width:o,height:s,minZoom:a,maxZoom:i,panZoom:l}=e.getState(),c=Nu(t,o,s,a,i,n?.padding??.1);return l?(await l.setViewport(c,{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(t,n={})=>{const{transform:o,snapGrid:s,snapToGrid:a,domNode:i}=e.getState();if(!i)return t;const{x:l,y:c}=i.getBoundingClientRect(),d={x:t.x-l,y:t.y-c},p=n.snapGrid??s,f=n.snapToGrid??a;return us(d,o,f,p)},flowToScreenPosition:t=>{const{transform:n,domNode:o}=e.getState();if(!o)return t;const{x:s,y:a}=o.getBoundingClientRect(),i=Da(t,n);return{x:i.x+s,y:i.y+a}}}),[])};function Iw(e,t){const n=[],o=new Map,s=[];for(const a of e)if(a.type==="add"){s.push(a);continue}else if(a.type==="remove"||a.type==="replace")o.set(a.id,[a]);else{const i=o.get(a.id);i?i.push(a):o.set(a.id,[a])}for(const a of t){const i=o.get(a.id);if(!i){n.push(a);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const l={...a};for(const c of i)$W(c,l);n.push(l)}return s.length&&s.forEach(a=>{a.index!==void 0?n.splice(a.index,0,{...a.item}):n.push({...a.item})}),n}function $W(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(t.resizing=e.resizing);break}}}function DW(e,t){return Iw(e,t)}function LW(e,t){return Iw(e,t)}function Kn(e,t){return{id:e,type:"select",selected:t}}function Sr(e,t=new Set,n=!1){const o=[];for(const[s,a]of e){const i=t.has(s);!(a.selected===void 0&&!i)&&a.selected!==i&&(n&&(a.selected=i),o.push(Kn(a.id,i)))}return o}function Im({items:e=[],lookup:t}){const n=[],o=new Map(e.map(s=>[s.id,s]));for(const[s,a]of e.entries()){const i=t.get(a.id),l=i?.internals?.userNode??i;l!==void 0&&l!==a&&n.push({id:a.id,item:a,type:"replace"}),l===void 0&&n.push({item:a,type:"add",index:s})}for(const[s]of t)o.get(s)===void 0&&n.push({id:s,type:"remove"});return n}function Pm(e){return{id:e.id,type:"remove"}}const _m=e=>XQ(e),TW=e=>Z1(e);function Pw(e){return Ke(e)}function $m(e){const[t,n]=I(BigInt(0)),[o]=I(()=>RW(()=>n(s=>s+BigInt(1))));return _c(()=>{const s=o.get();s.length&&(e(s),o.reset())},[t]),o}function RW(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const _w=qe(null);function OW({children:e}){const t=We(),n=U(l=>{const{nodes:c=[],setNodes:d,hasDefaultNodes:p,onNodesChange:f,nodeLookup:m,fitViewQueued:h,onNodesChangeMiddlewareMap:g}=t.getState();let x=c;for(const y of l)x=typeof y=="function"?y(x):y;let b=Im({items:x,lookup:m});for(const y of g.values())b=y(b);p&&d(x),b.length>0?f?.(b):h&&window.requestAnimationFrame(()=>{const{fitViewQueued:y,nodes:w,setNodes:v}=t.getState();y&&v(w)})},[]),o=$m(n),s=U(l=>{const{edges:c=[],setEdges:d,hasDefaultEdges:p,onEdgesChange:f,edgeLookup:m}=t.getState();let h=c;for(const g of l)h=typeof g=="function"?g(h):g;p?d(h):f&&f(Im({items:h,lookup:m}))},[]),a=$m(s),i=q(()=>({nodeQueue:o,edgeQueue:a}),[]);return r(_w.Provider,{value:i,children:e})}function BW(){const e=Ne(_w);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const zW=e=>!!e.panZoom;function Iu(){const e=_W(),t=We(),n=BW(),o=Re(zW),s=q(()=>{const a=f=>t.getState().nodeLookup.get(f),i=f=>{n.nodeQueue.push(f)},l=f=>{n.edgeQueue.push(f)},c=f=>{const{nodeLookup:m,nodeOrigin:h}=t.getState(),g=_m(f)?f:m.get(f.id),x=g.parentId?rw(g.position,g.measured,g.parentId,m,h):g.position,b={...g,position:x,width:g.measured?.width??g.width,height:g.measured?.height??g.height};return Vr(b)},d=(f,m,h={replace:!1})=>{i(g=>g.map(x=>{if(x.id===f){const b=typeof m=="function"?m(x):m;return h.replace&&_m(b)?b:{...x,...b}}return x}))},p=(f,m,h={replace:!1})=>{l(g=>g.map(x=>{if(x.id===f){const b=typeof m=="function"?m(x):m;return h.replace&&TW(b)?b:{...x,...b}}return x}))};return{getNodes:()=>t.getState().nodes.map(f=>({...f})),getNode:f=>a(f)?.internals.userNode,getInternalNode:a,getEdges:()=>{const{edges:f=[]}=t.getState();return f.map(m=>({...m}))},getEdge:f=>t.getState().edgeLookup.get(f),setNodes:i,setEdges:l,addNodes:f=>{const m=Array.isArray(f)?f:[f];n.nodeQueue.push(h=>[...h,...m])},addEdges:f=>{const m=Array.isArray(f)?f:[f];n.edgeQueue.push(h=>[...h,...m])},toObject:()=>{const{nodes:f=[],edges:m=[],transform:h}=t.getState(),[g,x,b]=h;return{nodes:f.map(y=>({...y})),edges:m.map(y=>({...y})),viewport:{x:g,y:x,zoom:b}}},deleteElements:async({nodes:f=[],edges:m=[]})=>{const{nodes:h,edges:g,onNodesDelete:x,onEdgesDelete:b,triggerNodeChanges:y,triggerEdgeChanges:w,onDelete:v,onBeforeDelete:N}=t.getState(),{nodes:k,edges:C}=await rG({nodesToRemove:f,edgesToRemove:m,nodes:h,edges:g,onBeforeDelete:N}),D=C.length>0,M=k.length>0;if(D){const _=C.map(Pm);b?.(C),w(_)}if(M){const _=k.map(Pm);x?.(k),y(_)}return(M||D)&&v?.({nodes:k,edges:C}),{deletedNodes:k,deletedEdges:C}},getIntersectingNodes:(f,m=!0,h)=>{const g=im(f),x=g?f:c(f),b=h!==void 0;return x?(h||t.getState().nodes).filter(y=>{const w=t.getState().nodeLookup.get(y.id);if(w&&!g&&(y.id===f.id||!w.internals.positionAbsolute))return!1;const v=Vr(b?y:w),N=Go(v,x);return m&&N>0||N>=v.width*v.height||N>=x.width*x.height}):[]},isNodeIntersecting:(f,m,h=!0)=>{const x=im(f)?f:c(f);if(!x)return!1;const b=Go(x,m);return h&&b>0||b>=m.width*m.height||b>=x.width*x.height},updateNode:d,updateNodeData:(f,m,h={replace:!1})=>{d(f,g=>{const x=typeof m=="function"?m(g):m;return h.replace?{...g,data:x}:{...g,data:{...g.data,...x}}},h)},updateEdge:p,updateEdgeData:(f,m,h={replace:!1})=>{p(f,g=>{const x=typeof m=="function"?m(g):m;return h.replace?{...g,data:x}:{...g,data:{...g.data,...x}}},h)},getNodesBounds:f=>{const{nodeLookup:m,nodeOrigin:h}=t.getState();return JQ(f,{nodeLookup:m,nodeOrigin:h})},getHandleConnections:({type:f,id:m,nodeId:h})=>Array.from(t.getState().connectionLookup.get(`${h}-${f}${m?`-${m}`:""}`)?.values()??[]),getNodeConnections:({type:f,handleId:m,nodeId:h})=>Array.from(t.getState().connectionLookup.get(`${h}${f?m?`-${f}-${m}`:`-${f}`:""}`)?.values()??[]),fitView:async f=>{const m=t.getState().fitViewResolver??iG();return t.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:m}),n.nodeQueue.push(h=>[...h]),m.promise}}},[]);return q(()=>({...s,...e,viewportInitialized:o}),[o])}const Dm=e=>e.selected,FW=typeof window<"u"?window:void 0;function jW({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=We(),{deleteElements:o}=Iu(),s=Ko(e,{actInsideInputWithModifier:!1}),a=Ko(t,{target:FW});J(()=>{if(s){const{edges:i,nodes:l}=n.getState();o({nodes:l.filter(Dm),edges:i.filter(Dm)}),n.setState({nodesSelectionActive:!1})}},[s]),J(()=>{n.setState({multiSelectionActive:a})},[a])}function HW(e){const t=We();J(()=>{const n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const o=ku(e.current);(o.height===0||o.width===0)&&t.getState().onError?.("004",nn.error004()),t.setState({width:o.width||500,height:o.height||500})};if(e.current){n(),window.addEventListener("resize",n);const o=new ResizeObserver(()=>n());return o.observe(e.current),()=>{window.removeEventListener("resize",n),o&&e.current&&o.unobserve(e.current)}}},[])}const ki={position:"absolute",width:"100%",height:"100%",top:0,left:0},VW=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function UW({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:o=!1,panOnScrollSpeed:s=.5,panOnScrollMode:a=Jn.Free,zoomOnDoubleClick:i=!0,panOnDrag:l=!0,defaultViewport:c,translateExtent:d,minZoom:p,maxZoom:f,zoomActivationKeyCode:m,preventScrolling:h=!0,children:g,noWheelClassName:x,noPanClassName:b,onViewportChange:y,isControlledViewport:w,paneClickDistance:v,selectionOnDrag:N}){const k=We(),C=ne(null),{userSelectionActive:D,lib:M,connectionInProgress:_}=Re(VW,Ge),$=Ko(m),E=ne();HW(C);const R=U(O=>{y?.({x:O[0],y:O[1],zoom:O[2]}),w||k.setState({transform:O})},[y,w]);return J(()=>{if(C.current){E.current=UG({domNode:C.current,minZoom:p,maxZoom:f,translateExtent:d,viewport:c,onDraggingChange:L=>k.setState(B=>B.paneDragging===L?B:{paneDragging:L}),onPanZoomStart:(L,B)=>{const{onViewportChangeStart:z,onMoveStart:T}=k.getState();T?.(L,B),z?.(B)},onPanZoom:(L,B)=>{const{onViewportChange:z,onMove:T}=k.getState();T?.(L,B),z?.(B)},onPanZoomEnd:(L,B)=>{const{onViewportChangeEnd:z,onMoveEnd:T}=k.getState();T?.(L,B),z?.(B)}});const{x:O,y:A,zoom:P}=E.current.getViewport();return k.setState({panZoom:E.current,transform:[O,A,P],domNode:C.current.closest(".react-flow")}),()=>{E.current?.destroy()}}},[]),J(()=>{E.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:o,panOnScrollSpeed:s,panOnScrollMode:a,zoomOnDoubleClick:i,panOnDrag:l,zoomActivationKeyPressed:$,preventScrolling:h,noPanClassName:b,userSelectionActive:D,noWheelClassName:x,lib:M,onTransformChange:R,connectionInProgress:_,selectionOnDrag:N,paneClickDistance:v})},[e,t,n,o,s,a,i,l,$,h,b,D,x,M,R,_,N,v]),r("div",{className:"react-flow__renderer",ref:C,style:ki,children:g})}const qW=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function QW(){const{userSelectionActive:e,userSelectionRect:t}=Re(qW,Ge);return e&&t?r("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}const kl=(e,t)=>n=>{n.target===t.current&&e?.(n)},GW=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function WW({isSelecting:e,selectionKeyPressed:t,selectionMode:n=Qo.Full,panOnDrag:o,paneClickDistance:s,selectionOnDrag:a,onSelectionStart:i,onSelectionEnd:l,onPaneClick:c,onPaneContextMenu:d,onPaneScroll:p,onPaneMouseEnter:f,onPaneMouseMove:m,onPaneMouseLeave:h,children:g}){const x=We(),{userSelectionActive:b,elementsSelectable:y,dragging:w,connectionInProgress:v}=Re(GW,Ge),N=y&&(e||b),k=ne(null),C=ne(),D=ne(new Set),M=ne(new Set),_=ne(!1),$=z=>{if(_.current||v){_.current=!1;return}c?.(z),x.getState().resetSelectedElements(),x.setState({nodesSelectionActive:!1})},E=z=>{if(Array.isArray(o)&&o?.includes(2)){z.preventDefault();return}d?.(z)},R=p?z=>p(z):void 0,O=z=>{_.current&&(z.stopPropagation(),_.current=!1)},A=z=>{const{domNode:T}=x.getState();if(C.current=T?.getBoundingClientRect(),!C.current)return;const F=z.target===k.current;if(!F&&!!z.target.closest(".nokey")||!e||!(a&&F||t)||z.button!==0||!z.isPrimary)return;z.target?.setPointerCapture?.(z.pointerId),_.current=!1;const{x:Q,y:G}=Bt(z.nativeEvent,C.current);x.setState({userSelectionRect:{width:0,height:0,startX:Q,startY:G,x:Q,y:G}}),F||(z.stopPropagation(),z.preventDefault())},P=z=>{const{userSelectionRect:T,transform:F,nodeLookup:H,edgeLookup:j,connectionLookup:Q,triggerNodeChanges:G,triggerEdgeChanges:Z,defaultEdgeOptions:V,resetSelectedElements:K}=x.getState();if(!C.current||!T)return;const{x:X,y:te}=Bt(z.nativeEvent,C.current),{startX:he,startY:xe}=T;if(!_.current){const be=t?0:s;if(Math.hypot(X-he,te-xe)<=be)return;K(),i?.(z)}_.current=!0;const ee={startX:he,startY:xe,x:X<he?X:he,y:te<xe?te:xe,width:Math.abs(X-he),height:Math.abs(te-xe)},re=D.current,de=M.current;D.current=new Set(wu(H,ee,F,n===Qo.Partial,!0).map(be=>be.id)),M.current=new Set;const ue=V?.selectable??!0;for(const be of D.current){const Se=Q.get(be);if(Se)for(const{edgeId:Oe}of Se.values()){const Be=j.get(Oe);Be&&(Be.selectable??ue)&&M.current.add(Oe)}}if(!lm(re,D.current)){const be=Sr(H,D.current,!0);G(be)}if(!lm(de,M.current)){const be=Sr(j,M.current);Z(be)}x.setState({userSelectionRect:ee,userSelectionActive:!0,nodesSelectionActive:!1})},L=z=>{z.button===0&&(z.target?.releasePointerCapture?.(z.pointerId),!b&&z.target===k.current&&x.getState().userSelectionRect&&$?.(z),x.setState({userSelectionActive:!1,userSelectionRect:null}),_.current&&(l?.(z),x.setState({nodesSelectionActive:D.current.size>0})))},B=o===!0||Array.isArray(o)&&o.includes(0);return u("div",{className:tt(["react-flow__pane",{draggable:B,dragging:w,selection:e}]),onClick:N?void 0:kl($,k),onContextMenu:kl(E,k),onWheel:kl(R,k),onPointerEnter:N?void 0:f,onPointerMove:N?P:m,onPointerUp:N?L:void 0,onPointerDownCapture:N?A:void 0,onClickCapture:N?O:void 0,onPointerLeave:h,ref:k,style:ki,children:[g,r(QW,{})]})}function $c({id:e,store:t,unselect:n=!1,nodeRef:o}){const{addSelectedNodes:s,unselectNodesAndEdges:a,multiSelectionActive:i,nodeLookup:l,onError:c}=t.getState(),d=l.get(e);if(!d){c?.("012",nn.error012(e));return}t.setState({nodesSelectionActive:!1}),d.selected?(n||d.selected&&i)&&(a({nodes:[d],edges:[]}),requestAnimationFrame(()=>o?.current?.blur())):s([e])}function $w({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:o,nodeId:s,isSelectable:a,nodeClickDistance:i}){const l=We(),[c,d]=I(!1),p=ne();return J(()=>{p.current=PG({getStoreItems:()=>l.getState(),onNodeMouseDown:f=>{$c({id:f,store:l,nodeRef:e})},onDragStart:()=>{d(!0)},onDragStop:()=>{d(!1)}})},[]),J(()=>{if(!(t||!e.current||!p.current))return p.current.update({noDragClassName:n,handleSelector:o,domNode:e.current,isSelectable:a,nodeId:s,nodeClickDistance:i}),()=>{p.current?.destroy()}},[n,o,t,a,e,s,i]),c}const KW=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function Dw(){const e=We();return U(n=>{const{nodeExtent:o,snapToGrid:s,snapGrid:a,nodesDraggable:i,onError:l,updateNodePositions:c,nodeLookup:d,nodeOrigin:p}=e.getState(),f=new Map,m=KW(i),h=s?a[0]:5,g=s?a[1]:5,x=n.direction.x*h*n.factor,b=n.direction.y*g*n.factor;for(const[,y]of d){if(!m(y))continue;let w={x:y.internals.positionAbsolute.x+x,y:y.internals.positionAbsolute.y+b};s&&(w=ds(w,a));const{position:v,positionAbsolute:N}=X1({nodeId:y.id,nextPosition:w,nodeLookup:d,nodeExtent:o,nodeOrigin:p,onError:l});y.position=v,y.internals.positionAbsolute=N,f.set(y.id,y)}c(f)},[])}const Pu=qe(null),YW=Pu.Provider;Pu.Consumer;const Lw=()=>Ne(Pu),ZW=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),XW=(e,t,n)=>o=>{const{connectionClickStartHandle:s,connectionMode:a,connection:i}=o,{fromHandle:l,toHandle:c,isValid:d}=i,p=c?.nodeId===e&&c?.id===t&&c?.type===n;return{connectingFrom:l?.nodeId===e&&l?.id===t&&l?.type===n,connectingTo:p,clickConnecting:s?.nodeId===e&&s?.id===t&&s?.type===n,isPossibleEndHandle:a===jr.Strict?l?.type!==n:e!==l?.nodeId||t!==l?.id,connectionInProcess:!!l,clickConnectionInProcess:!!s,valid:p&&d}};function JW({type:e="source",position:t=Ae.Top,isValidConnection:n,isConnectable:o=!0,isConnectableStart:s=!0,isConnectableEnd:a=!0,id:i,onConnect:l,children:c,className:d,onMouseDown:p,onTouchStart:f,...m},h){const g=i||null,x=e==="target",b=We(),y=Lw(),{connectOnClick:w,noPanClassName:v,rfId:N}=Re(ZW,Ge),{connectingFrom:k,connectingTo:C,clickConnecting:D,isPossibleEndHandle:M,connectionInProcess:_,clickConnectionInProcess:$,valid:E}=Re(XW(y,g,e),Ge);y||b.getState().onError?.("010",nn.error010());const R=P=>{const{defaultEdgeOptions:L,onConnect:B,hasDefaultEdges:z}=b.getState(),T={...L,...P};if(z){const{edges:F,setEdges:H}=b.getState();H(mG(T,F))}B?.(T),l?.(T)},O=P=>{if(!y)return;const L=aw(P.nativeEvent);if(s&&(L&&P.button===0||!L)){const B=b.getState();Pc.onPointerDown(P.nativeEvent,{handleDomNode:P.currentTarget,autoPanOnConnect:B.autoPanOnConnect,connectionMode:B.connectionMode,connectionRadius:B.connectionRadius,domNode:B.domNode,nodeLookup:B.nodeLookup,lib:B.lib,isTarget:x,handleId:g,nodeId:y,flowId:B.rfId,panBy:B.panBy,cancelConnection:B.cancelConnection,onConnectStart:B.onConnectStart,onConnectEnd:(...z)=>b.getState().onConnectEnd?.(...z),updateConnection:B.updateConnection,onConnect:R,isValidConnection:n||((...z)=>b.getState().isValidConnection?.(...z)??!0),getTransform:()=>b.getState().transform,getFromHandle:()=>b.getState().connection.fromHandle,autoPanSpeed:B.autoPanSpeed,dragThreshold:B.connectionDragThreshold})}L?p?.(P):f?.(P)},A=P=>{const{onClickConnectStart:L,onClickConnectEnd:B,connectionClickStartHandle:z,connectionMode:T,isValidConnection:F,lib:H,rfId:j,nodeLookup:Q,connection:G}=b.getState();if(!y||!z&&!s)return;if(!z){L?.(P.nativeEvent,{nodeId:y,handleId:g,handleType:e}),b.setState({connectionClickStartHandle:{nodeId:y,type:e,id:g}});return}const Z=ow(P.target),V=n||F,{connection:K,isValid:X}=Pc.isValid(P.nativeEvent,{handle:{nodeId:y,id:g,type:e},connectionMode:T,fromNodeId:z.nodeId,fromHandleId:z.id||null,fromType:z.type,isValidConnection:V,flowId:j,doc:Z,lib:H,nodeLookup:Q});X&&K&&R(K);const te=structuredClone(G);delete te.inProgress,te.toPosition=te.toHandle?te.toHandle.position:null,B?.(P,te),b.setState({connectionClickStartHandle:null})};return r("div",{"data-handleid":g,"data-nodeid":y,"data-handlepos":t,"data-id":`${N}-${y}-${g}-${e}`,className:tt(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",v,d,{source:!x,target:x,connectable:o,connectablestart:s,connectableend:a,clickconnecting:D,connectingfrom:k,connectingto:C,valid:E,connectionindicator:o&&(!_||M)&&(_||$?a:s)}]),onMouseDown:O,onTouchStart:O,onClick:w?A:void 0,ref:h,...m,children:c})}const La=je(Pw(JW));function eK({data:e,isConnectable:t,sourcePosition:n=Ae.Bottom}){return u(me,{children:[e?.label,r(La,{type:"source",position:n,isConnectable:t})]})}function tK({data:e,isConnectable:t,targetPosition:n=Ae.Top,sourcePosition:o=Ae.Bottom}){return u(me,{children:[r(La,{type:"target",position:n,isConnectable:t}),e?.label,r(La,{type:"source",position:o,isConnectable:t})]})}function nK(){return null}function rK({data:e,isConnectable:t,targetPosition:n=Ae.Top}){return u(me,{children:[r(La,{type:"target",position:n,isConnectable:t}),e?.label]})}const Ta={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Lm={input:eK,default:tK,output:rK,group:nK};function oK(e){return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??e.style?.width,height:e.height??e.initialHeight??e.style?.height}:{width:e.width??e.style?.width,height:e.height??e.style?.height}}const sK=e=>{const{width:t,height:n,x:o,y:s}=cs(e.nodeLookup,{filter:a=>!!a.selected});return{width:Ot(t)?t:null,height:Ot(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${o}px,${s}px)`}};function aK({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const o=We(),{width:s,height:a,transformString:i,userSelectionActive:l}=Re(sK,Ge),c=Dw(),d=ne(null);J(()=>{n||d.current?.focus({preventScroll:!0})},[n]);const p=!l&&s!==null&&a!==null;if($w({nodeRef:d,disabled:!p}),!p)return null;const f=e?h=>{const g=o.getState().nodes.filter(x=>x.selected);e(h,g)}:void 0,m=h=>{Object.prototype.hasOwnProperty.call(Ta,h.key)&&(h.preventDefault(),c({direction:Ta[h.key],factor:h.shiftKey?4:1}))};return r("div",{className:tt(["react-flow__nodesselection","react-flow__container",t]),style:{transform:i},children:r("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:f,tabIndex:n?void 0:-1,onKeyDown:n?void 0:m,style:{width:s,height:a}})})}const Tm=typeof window<"u"?window:void 0,iK=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Tw({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:o,onPaneMouseLeave:s,onPaneContextMenu:a,onPaneScroll:i,paneClickDistance:l,deleteKeyCode:c,selectionKeyCode:d,selectionOnDrag:p,selectionMode:f,onSelectionStart:m,onSelectionEnd:h,multiSelectionKeyCode:g,panActivationKeyCode:x,zoomActivationKeyCode:b,elementsSelectable:y,zoomOnScroll:w,zoomOnPinch:v,panOnScroll:N,panOnScrollSpeed:k,panOnScrollMode:C,zoomOnDoubleClick:D,panOnDrag:M,defaultViewport:_,translateExtent:$,minZoom:E,maxZoom:R,preventScrolling:O,onSelectionContextMenu:A,noWheelClassName:P,noPanClassName:L,disableKeyboardA11y:B,onViewportChange:z,isControlledViewport:T}){const{nodesSelectionActive:F,userSelectionActive:H}=Re(iK,Ge),j=Ko(d,{target:Tm}),Q=Ko(x,{target:Tm}),G=Q||M,Z=Q||N,V=p&&G!==!0,K=j||H||V;return jW({deleteKeyCode:c,multiSelectionKeyCode:g}),r(UW,{onPaneContextMenu:a,elementsSelectable:y,zoomOnScroll:w,zoomOnPinch:v,panOnScroll:Z,panOnScrollSpeed:k,panOnScrollMode:C,zoomOnDoubleClick:D,panOnDrag:!j&&G,defaultViewport:_,translateExtent:$,minZoom:E,maxZoom:R,zoomActivationKeyCode:b,preventScrolling:O,noWheelClassName:P,noPanClassName:L,onViewportChange:z,isControlledViewport:T,paneClickDistance:l,selectionOnDrag:V,children:u(WW,{onSelectionStart:m,onSelectionEnd:h,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:o,onPaneMouseLeave:s,onPaneContextMenu:a,onPaneScroll:i,panOnDrag:G,isSelecting:!!K,selectionMode:f,selectionKeyPressed:j,paneClickDistance:l,selectionOnDrag:V,children:[e,F&&r(aK,{onSelectionContextMenu:A,noPanClassName:L,disableKeyboardA11y:B})]})})}Tw.displayName="FlowRenderer";const lK=je(Tw),cK=e=>t=>e?wu(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(n=>n.id):Array.from(t.nodeLookup.keys());function dK(e){return Re(U(cK(e),[e]),Ge)}const uK=e=>e.updateNodeInternals;function pK(){const e=Re(uK),[t]=I(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const o=new Map;n.forEach(s=>{const a=s.target.getAttribute("data-id");o.set(a,{id:a,nodeElement:s.target,force:!0})}),e(o)}));return J(()=>()=>{t?.disconnect()},[t]),t}function fK({node:e,nodeType:t,hasDimensions:n,resizeObserver:o}){const s=We(),a=ne(null),i=ne(null),l=ne(e.sourcePosition),c=ne(e.targetPosition),d=ne(t),p=n&&!!e.internals.handleBounds;return J(()=>{a.current&&!e.hidden&&(!p||i.current!==a.current)&&(i.current&&o?.unobserve(i.current),o?.observe(a.current),i.current=a.current)},[p,e.hidden]),J(()=>()=>{i.current&&(o?.unobserve(i.current),i.current=null)},[]),J(()=>{if(a.current){const f=d.current!==t,m=l.current!==e.sourcePosition,h=c.current!==e.targetPosition;(f||m||h)&&(d.current=t,l.current=e.sourcePosition,c.current=e.targetPosition,s.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:a.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),a}function mK({id:e,onClick:t,onMouseEnter:n,onMouseMove:o,onMouseLeave:s,onContextMenu:a,onDoubleClick:i,nodesDraggable:l,elementsSelectable:c,nodesConnectable:d,nodesFocusable:p,resizeObserver:f,noDragClassName:m,noPanClassName:h,disableKeyboardA11y:g,rfId:x,nodeTypes:b,nodeClickDistance:y,onError:w}){const{node:v,internals:N,isParent:k}=Re(X=>{const te=X.nodeLookup.get(e),he=X.parentLookup.has(e);return{node:te,internals:te.internals,isParent:he}},Ge);let C=v.type||"default",D=b?.[C]||Lm[C];D===void 0&&(w?.("003",nn.error003(C)),C="default",D=b?.default||Lm.default);const M=!!(v.draggable||l&&typeof v.draggable>"u"),_=!!(v.selectable||c&&typeof v.selectable>"u"),$=!!(v.connectable||d&&typeof v.connectable>"u"),E=!!(v.focusable||p&&typeof v.focusable>"u"),R=We(),O=nw(v),A=fK({node:v,nodeType:C,hasDimensions:O,resizeObserver:f}),P=$w({nodeRef:A,disabled:v.hidden||!M,noDragClassName:m,handleSelector:v.dragHandle,nodeId:e,isSelectable:_,nodeClickDistance:y}),L=Dw();if(v.hidden)return null;const B=Sn(v),z=oK(v),T=_||M||t||n||o||s,F=n?X=>n(X,{...N.userNode}):void 0,H=o?X=>o(X,{...N.userNode}):void 0,j=s?X=>s(X,{...N.userNode}):void 0,Q=a?X=>a(X,{...N.userNode}):void 0,G=i?X=>i(X,{...N.userNode}):void 0,Z=X=>{const{selectNodesOnDrag:te,nodeDragThreshold:he}=R.getState();_&&(!te||!M||he>0)&&$c({id:e,store:R,nodeRef:A}),t&&t(X,{...N.userNode})},V=X=>{if(!(sw(X.nativeEvent)||g)){if(G1.includes(X.key)&&_){const te=X.key==="Escape";$c({id:e,store:R,unselect:te,nodeRef:A})}else if(M&&v.selected&&Object.prototype.hasOwnProperty.call(Ta,X.key)){X.preventDefault();const{ariaLabelConfig:te}=R.getState();R.setState({ariaLiveMessage:te["node.a11yDescription.ariaLiveMessage"]({direction:X.key.replace("Arrow","").toLowerCase(),x:~~N.positionAbsolute.x,y:~~N.positionAbsolute.y})}),L({direction:Ta[X.key],factor:X.shiftKey?4:1})}}},K=()=>{if(g||!A.current?.matches(":focus-visible"))return;const{transform:X,width:te,height:he,autoPanOnNodeFocus:xe,setCenter:ee}=R.getState();if(!xe)return;wu(new Map([[e,v]]),{x:0,y:0,width:te,height:he},X,!0).length>0||ee(v.position.x+B.width/2,v.position.y+B.height/2,{zoom:X[2]})};return r("div",{className:tt(["react-flow__node",`react-flow__node-${C}`,{[h]:M},v.className,{selected:v.selected,selectable:_,parent:k,draggable:M,dragging:P}]),ref:A,style:{zIndex:N.z,transform:`translate(${N.positionAbsolute.x}px,${N.positionAbsolute.y}px)`,pointerEvents:T?"all":"none",visibility:O?"visible":"hidden",...v.style,...z},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:F,onMouseMove:H,onMouseLeave:j,onContextMenu:Q,onClick:Z,onDoubleClick:G,onKeyDown:E?V:void 0,tabIndex:E?0:void 0,onFocus:E?K:void 0,role:v.ariaRole??(E?"group":void 0),"aria-roledescription":"node","aria-describedby":g?void 0:`${Mw}-${x}`,"aria-label":v.ariaLabel,...v.domAttributes,children:r(YW,{value:e,children:r(D,{id:e,data:v.data,type:C,positionAbsoluteX:N.positionAbsolute.x,positionAbsoluteY:N.positionAbsolute.y,selected:v.selected??!1,selectable:_,draggable:M,deletable:v.deletable??!0,isConnectable:$,sourcePosition:v.sourcePosition,targetPosition:v.targetPosition,dragging:P,dragHandle:v.dragHandle,zIndex:N.z,parentId:v.parentId,...B})})})}var hK=je(mK);const gK=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function Rw(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:o,elementsSelectable:s,onError:a}=Re(gK,Ge),i=dK(e.onlyRenderVisibleElements),l=pK();return r("div",{className:"react-flow__nodes",style:ki,children:i.map(c=>r(hK,{id:c,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:l,nodesDraggable:t,nodesConnectable:n,nodesFocusable:o,elementsSelectable:s,nodeClickDistance:e.nodeClickDistance,onError:a},c))})}Rw.displayName="NodeRenderer";const bK=je(Rw);function xK(e){return Re(U(n=>{if(!e)return n.edges.map(s=>s.id);const o=[];if(n.width&&n.height)for(const s of n.edges){const a=n.nodeLookup.get(s.source),i=n.nodeLookup.get(s.target);a&&i&&uG({sourceNode:a,targetNode:i,width:n.width,height:n.height,transform:n.transform})&&o.push(s.id)}return o},[e]),Ge)}const yK=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return r("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},vK=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return r("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},Rm={[_a.Arrow]:yK,[_a.ArrowClosed]:vK};function wK(e){const t=We();return q(()=>Object.prototype.hasOwnProperty.call(Rm,e)?Rm[e]:(t.getState().onError?.("009",nn.error009(e)),null),[e])}const NK=({id:e,type:t,color:n,width:o=12.5,height:s=12.5,markerUnits:a="strokeWidth",strokeWidth:i,orient:l="auto-start-reverse"})=>{const c=wK(t);return c?r("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${o}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:a,orient:l,refX:"0",refY:"0",children:r(c,{color:n,strokeWidth:i})}):null},Ow=({defaultColor:e,rfId:t})=>{const n=Re(a=>a.edges),o=Re(a=>a.defaultEdgeOptions),s=q(()=>yG(n,{id:t,defaultColor:e,defaultMarkerStart:o?.markerStart,defaultMarkerEnd:o?.markerEnd}),[n,o,t,e]);return s.length?r("svg",{className:"react-flow__marker","aria-hidden":"true",children:r("defs",{children:s.map(a=>r(NK,{id:a.id,type:a.type,color:a.color,width:a.width,height:a.height,markerUnits:a.markerUnits,strokeWidth:a.strokeWidth,orient:a.orient},a.id))})}):null};Ow.displayName="MarkerDefinitions";var kK=je(Ow);function Bw({x:e,y:t,label:n,labelStyle:o,labelShowBg:s=!0,labelBgStyle:a,labelBgPadding:i=[2,4],labelBgBorderRadius:l=2,children:c,className:d,...p}){const[f,m]=I({x:1,y:0,width:0,height:0}),h=tt(["react-flow__edge-textwrapper",d]),g=ne(null);return J(()=>{if(g.current){const x=g.current.getBBox();m({x:x.x,y:x.y,width:x.width,height:x.height})}},[n]),n?u("g",{transform:`translate(${e-f.width/2} ${t-f.height/2})`,className:h,visibility:f.width?"visible":"hidden",...p,children:[s&&r("rect",{width:f.width+2*i[0],x:-i[0],y:-i[1],height:f.height+2*i[1],className:"react-flow__edge-textbg",style:a,rx:l,ry:l}),r("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:g,style:o,children:n}),c]}):null}Bw.displayName="EdgeText";const SK=je(Bw);function Si({path:e,labelX:t,labelY:n,label:o,labelStyle:s,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c,interactionWidth:d=20,...p}){return u(me,{children:[r("path",{...p,d:e,fill:"none",className:tt(["react-flow__edge-path",p.className])}),d?r("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:d,className:"react-flow__edge-interaction"}):null,o&&Ot(t)&&Ot(n)?r(SK,{x:t,y:n,label:o,labelStyle:s,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c}):null]})}function Om({pos:e,x1:t,y1:n,x2:o,y2:s}){return e===Ae.Left||e===Ae.Right?[.5*(t+o),n]:[t,.5*(n+s)]}function zw({sourceX:e,sourceY:t,sourcePosition:n=Ae.Bottom,targetX:o,targetY:s,targetPosition:a=Ae.Top}){const[i,l]=Om({pos:n,x1:e,y1:t,x2:o,y2:s}),[c,d]=Om({pos:a,x1:o,y1:s,x2:e,y2:t}),[p,f,m,h]=iw({sourceX:e,sourceY:t,targetX:o,targetY:s,sourceControlX:i,sourceControlY:l,targetControlX:c,targetControlY:d});return[`M${e},${t} C${i},${l} ${c},${d} ${o},${s}`,p,f,m,h]}function Fw(e){return je(({id:t,sourceX:n,sourceY:o,targetX:s,targetY:a,sourcePosition:i,targetPosition:l,label:c,labelStyle:d,labelShowBg:p,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:h,style:g,markerEnd:x,markerStart:b,interactionWidth:y})=>{const[w,v,N]=zw({sourceX:n,sourceY:o,sourcePosition:i,targetX:s,targetY:a,targetPosition:l}),k=e.isInternal?void 0:t;return r(Si,{id:k,path:w,labelX:v,labelY:N,label:c,labelStyle:d,labelShowBg:p,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:h,style:g,markerEnd:x,markerStart:b,interactionWidth:y})})}const CK=Fw({isInternal:!1}),jw=Fw({isInternal:!0});CK.displayName="SimpleBezierEdge";jw.displayName="SimpleBezierEdgeInternal";function Hw(e){return je(({id:t,sourceX:n,sourceY:o,targetX:s,targetY:a,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:p,labelBgBorderRadius:f,style:m,sourcePosition:h=Ae.Bottom,targetPosition:g=Ae.Top,markerEnd:x,markerStart:b,pathOptions:y,interactionWidth:w})=>{const[v,N,k]=Ac({sourceX:n,sourceY:o,sourcePosition:h,targetX:s,targetY:a,targetPosition:g,borderRadius:y?.borderRadius,offset:y?.offset,stepPosition:y?.stepPosition}),C=e.isInternal?void 0:t;return r(Si,{id:C,path:v,labelX:N,labelY:k,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:p,labelBgBorderRadius:f,style:m,markerEnd:x,markerStart:b,interactionWidth:w})})}const Vw=Hw({isInternal:!1}),Uw=Hw({isInternal:!0});Vw.displayName="SmoothStepEdge";Uw.displayName="SmoothStepEdgeInternal";function qw(e){return je(({id:t,...n})=>{const o=e.isInternal?void 0:t;return r(Vw,{...n,id:o,pathOptions:q(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}const MK=qw({isInternal:!1}),Qw=qw({isInternal:!0});MK.displayName="StepEdge";Qw.displayName="StepEdgeInternal";function Gw(e){return je(({id:t,sourceX:n,sourceY:o,targetX:s,targetY:a,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:p,labelBgBorderRadius:f,style:m,markerEnd:h,markerStart:g,interactionWidth:x})=>{const[b,y,w]=dw({sourceX:n,sourceY:o,targetX:s,targetY:a}),v=e.isInternal?void 0:t;return r(Si,{id:v,path:b,labelX:y,labelY:w,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:p,labelBgBorderRadius:f,style:m,markerEnd:h,markerStart:g,interactionWidth:x})})}const AK=Gw({isInternal:!1}),Ww=Gw({isInternal:!0});AK.displayName="StraightEdge";Ww.displayName="StraightEdgeInternal";function Kw(e){return je(({id:t,sourceX:n,sourceY:o,targetX:s,targetY:a,sourcePosition:i=Ae.Bottom,targetPosition:l=Ae.Top,label:c,labelStyle:d,labelShowBg:p,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:h,style:g,markerEnd:x,markerStart:b,pathOptions:y,interactionWidth:w})=>{const[v,N,k]=lw({sourceX:n,sourceY:o,sourcePosition:i,targetX:s,targetY:a,targetPosition:l,curvature:y?.curvature}),C=e.isInternal?void 0:t;return r(Si,{id:C,path:v,labelX:N,labelY:k,label:c,labelStyle:d,labelShowBg:p,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:h,style:g,markerEnd:x,markerStart:b,interactionWidth:w})})}const EK=Kw({isInternal:!1}),Yw=Kw({isInternal:!0});EK.displayName="BezierEdge";Yw.displayName="BezierEdgeInternal";const Bm={default:Yw,straight:Ww,step:Qw,smoothstep:Uw,simplebezier:jw},zm={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},IK=(e,t,n)=>n===Ae.Left?e-t:n===Ae.Right?e+t:e,PK=(e,t,n)=>n===Ae.Top?e-t:n===Ae.Bottom?e+t:e,Fm="react-flow__edgeupdater";function jm({position:e,centerX:t,centerY:n,radius:o=10,onMouseDown:s,onMouseEnter:a,onMouseOut:i,type:l}){return r("circle",{onMouseDown:s,onMouseEnter:a,onMouseOut:i,className:tt([Fm,`${Fm}-${l}`]),cx:IK(t,o,e),cy:PK(n,o,e),r:o,stroke:"transparent",fill:"transparent"})}function _K({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:o,sourceY:s,targetX:a,targetY:i,sourcePosition:l,targetPosition:c,onReconnect:d,onReconnectStart:p,onReconnectEnd:f,setReconnecting:m,setUpdateHover:h}){const g=We(),x=(N,k)=>{if(N.button!==0)return;const{autoPanOnConnect:C,domNode:D,connectionMode:M,connectionRadius:_,lib:$,onConnectStart:E,cancelConnection:R,nodeLookup:O,rfId:A,panBy:P,updateConnection:L}=g.getState(),B=k.type==="target",z=(H,j)=>{m(!1),f?.(H,n,k.type,j)},T=H=>d?.(n,H),F=(H,j)=>{m(!0),p?.(N,n,k.type),E?.(H,j)};Pc.onPointerDown(N.nativeEvent,{autoPanOnConnect:C,connectionMode:M,connectionRadius:_,domNode:D,handleId:k.id,nodeId:k.nodeId,nodeLookup:O,isTarget:B,edgeUpdaterType:k.type,lib:$,flowId:A,cancelConnection:R,panBy:P,isValidConnection:(...H)=>g.getState().isValidConnection?.(...H)??!0,onConnect:T,onConnectStart:F,onConnectEnd:(...H)=>g.getState().onConnectEnd?.(...H),onReconnectEnd:z,updateConnection:L,getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,dragThreshold:g.getState().connectionDragThreshold,handleDomNode:N.currentTarget})},b=N=>x(N,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),y=N=>x(N,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),w=()=>h(!0),v=()=>h(!1);return u(me,{children:[(e===!0||e==="source")&&r(jm,{position:l,centerX:o,centerY:s,radius:t,onMouseDown:b,onMouseEnter:w,onMouseOut:v,type:"source"}),(e===!0||e==="target")&&r(jm,{position:c,centerX:a,centerY:i,radius:t,onMouseDown:y,onMouseEnter:w,onMouseOut:v,type:"target"})]})}function $K({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:o,onClick:s,onDoubleClick:a,onContextMenu:i,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,reconnectRadius:p,onReconnect:f,onReconnectStart:m,onReconnectEnd:h,rfId:g,edgeTypes:x,noPanClassName:b,onError:y,disableKeyboardA11y:w}){let v=Re(ee=>ee.edgeLookup.get(e));const N=Re(ee=>ee.defaultEdgeOptions);v=N?{...N,...v}:v;let k=v.type||"default",C=x?.[k]||Bm[k];C===void 0&&(y?.("011",nn.error011(k)),k="default",C=x?.default||Bm.default);const D=!!(v.focusable||t&&typeof v.focusable>"u"),M=typeof f<"u"&&(v.reconnectable||n&&typeof v.reconnectable>"u"),_=!!(v.selectable||o&&typeof v.selectable>"u"),$=ne(null),[E,R]=I(!1),[O,A]=I(!1),P=We(),{zIndex:L,sourceX:B,sourceY:z,targetX:T,targetY:F,sourcePosition:H,targetPosition:j}=Re(U(ee=>{const re=ee.nodeLookup.get(v.source),de=ee.nodeLookup.get(v.target);if(!re||!de)return{zIndex:v.zIndex,...zm};const ue=xG({id:e,sourceNode:re,targetNode:de,sourceHandle:v.sourceHandle||null,targetHandle:v.targetHandle||null,connectionMode:ee.connectionMode,onError:y});return{zIndex:dG({selected:v.selected,zIndex:v.zIndex,sourceNode:re,targetNode:de,elevateOnSelect:ee.elevateEdgesOnSelect,zIndexMode:ee.zIndexMode}),...ue||zm}},[v.source,v.target,v.sourceHandle,v.targetHandle,v.selected,v.zIndex]),Ge),Q=q(()=>v.markerStart?`url('#${Ec(v.markerStart,g)}')`:void 0,[v.markerStart,g]),G=q(()=>v.markerEnd?`url('#${Ec(v.markerEnd,g)}')`:void 0,[v.markerEnd,g]);if(v.hidden||B===null||z===null||T===null||F===null)return null;const Z=ee=>{const{addSelectedEdges:re,unselectNodesAndEdges:de,multiSelectionActive:ue}=P.getState();_&&(P.setState({nodesSelectionActive:!1}),v.selected&&ue?(de({nodes:[],edges:[v]}),$.current?.blur()):re([e])),s&&s(ee,v)},V=a?ee=>{a(ee,{...v})}:void 0,K=i?ee=>{i(ee,{...v})}:void 0,X=l?ee=>{l(ee,{...v})}:void 0,te=c?ee=>{c(ee,{...v})}:void 0,he=d?ee=>{d(ee,{...v})}:void 0,xe=ee=>{if(!w&&G1.includes(ee.key)&&_){const{unselectNodesAndEdges:re,addSelectedEdges:de}=P.getState();ee.key==="Escape"?($.current?.blur(),re({edges:[v]})):de([e])}};return r("svg",{style:{zIndex:L},children:u("g",{className:tt(["react-flow__edge",`react-flow__edge-${k}`,v.className,b,{selected:v.selected,animated:v.animated,inactive:!_&&!s,updating:E,selectable:_}]),onClick:Z,onDoubleClick:V,onContextMenu:K,onMouseEnter:X,onMouseMove:te,onMouseLeave:he,onKeyDown:D?xe:void 0,tabIndex:D?0:void 0,role:v.ariaRole??(D?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":v.ariaLabel===null?void 0:v.ariaLabel||`Edge from ${v.source} to ${v.target}`,"aria-describedby":D?`${Aw}-${g}`:void 0,ref:$,...v.domAttributes,children:[!O&&r(C,{id:e,source:v.source,target:v.target,type:v.type,selected:v.selected,animated:v.animated,selectable:_,deletable:v.deletable??!0,label:v.label,labelStyle:v.labelStyle,labelShowBg:v.labelShowBg,labelBgStyle:v.labelBgStyle,labelBgPadding:v.labelBgPadding,labelBgBorderRadius:v.labelBgBorderRadius,sourceX:B,sourceY:z,targetX:T,targetY:F,sourcePosition:H,targetPosition:j,data:v.data,style:v.style,sourceHandleId:v.sourceHandle,targetHandleId:v.targetHandle,markerStart:Q,markerEnd:G,pathOptions:"pathOptions"in v?v.pathOptions:void 0,interactionWidth:v.interactionWidth}),M&&r(_K,{edge:v,isReconnectable:M,reconnectRadius:p,onReconnect:f,onReconnectStart:m,onReconnectEnd:h,sourceX:B,sourceY:z,targetX:T,targetY:F,sourcePosition:H,targetPosition:j,setUpdateHover:R,setReconnecting:A})]})})}var DK=je($K);const LK=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Zw({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:o,noPanClassName:s,onReconnect:a,onEdgeContextMenu:i,onEdgeMouseEnter:l,onEdgeMouseMove:c,onEdgeMouseLeave:d,onEdgeClick:p,reconnectRadius:f,onEdgeDoubleClick:m,onReconnectStart:h,onReconnectEnd:g,disableKeyboardA11y:x}){const{edgesFocusable:b,edgesReconnectable:y,elementsSelectable:w,onError:v}=Re(LK,Ge),N=xK(t);return u("div",{className:"react-flow__edges",children:[r(kK,{defaultColor:e,rfId:n}),N.map(k=>r(DK,{id:k,edgesFocusable:b,edgesReconnectable:y,elementsSelectable:w,noPanClassName:s,onReconnect:a,onContextMenu:i,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,onClick:p,reconnectRadius:f,onDoubleClick:m,onReconnectStart:h,onReconnectEnd:g,rfId:n,onError:v,edgeTypes:o,disableKeyboardA11y:x},k))]})}Zw.displayName="EdgeRenderer";const TK=je(Zw),RK=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function OK({children:e}){const t=Re(RK);return r("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function BK(e){const t=Iu(),n=ne(!1);J(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const zK=e=>e.panZoom?.syncViewport;function FK(e){const t=Re(zK),n=We();return J(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function jK(e){return e.connection.inProgress?{...e.connection,to:us(e.connection.to,e.transform)}:{...e.connection}}function HK(e){return jK}function VK(e){const t=HK();return Re(t,Ge)}const UK=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function qK({containerStyle:e,style:t,type:n,component:o}){const{nodesConnectable:s,width:a,height:i,isValid:l,inProgress:c}=Re(UK,Ge);return!(a&&s&&c)?null:r("svg",{style:e,width:a,height:i,className:"react-flow__connectionline react-flow__container",children:r("g",{className:tt(["react-flow__connection",Y1(l)]),children:r(Xw,{style:t,type:n,CustomComponent:o,isValid:l})})})}const Xw=({style:e,type:t=In.Bezier,CustomComponent:n,isValid:o})=>{const{inProgress:s,from:a,fromNode:i,fromHandle:l,fromPosition:c,to:d,toNode:p,toHandle:f,toPosition:m,pointer:h}=VK();if(!s)return;if(n)return r(n,{connectionLineType:t,connectionLineStyle:e,fromNode:i,fromHandle:l,fromX:a.x,fromY:a.y,toX:d.x,toY:d.y,fromPosition:c,toPosition:m,connectionStatus:Y1(o),toNode:p,toHandle:f,pointer:h});let g="";const x={sourceX:a.x,sourceY:a.y,sourcePosition:c,targetX:d.x,targetY:d.y,targetPosition:m};switch(t){case In.Bezier:[g]=lw(x);break;case In.SimpleBezier:[g]=zw(x);break;case In.Step:[g]=Ac({...x,borderRadius:0});break;case In.SmoothStep:[g]=Ac(x);break;default:[g]=dw(x)}return r("path",{d:g,fill:"none",className:"react-flow__connection-path",style:e})};Xw.displayName="ConnectionLine";const QK={};function Hm(e=QK){ne(e),We(),J(()=>{},[e])}function GK(){We(),ne(!1),J(()=>{},[])}function Jw({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:o,onEdgeClick:s,onNodeDoubleClick:a,onEdgeDoubleClick:i,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:p,onSelectionContextMenu:f,onSelectionStart:m,onSelectionEnd:h,connectionLineType:g,connectionLineStyle:x,connectionLineComponent:b,connectionLineContainerStyle:y,selectionKeyCode:w,selectionOnDrag:v,selectionMode:N,multiSelectionKeyCode:k,panActivationKeyCode:C,zoomActivationKeyCode:D,deleteKeyCode:M,onlyRenderVisibleElements:_,elementsSelectable:$,defaultViewport:E,translateExtent:R,minZoom:O,maxZoom:A,preventScrolling:P,defaultMarkerColor:L,zoomOnScroll:B,zoomOnPinch:z,panOnScroll:T,panOnScrollSpeed:F,panOnScrollMode:H,zoomOnDoubleClick:j,panOnDrag:Q,onPaneClick:G,onPaneMouseEnter:Z,onPaneMouseMove:V,onPaneMouseLeave:K,onPaneScroll:X,onPaneContextMenu:te,paneClickDistance:he,nodeClickDistance:xe,onEdgeContextMenu:ee,onEdgeMouseEnter:re,onEdgeMouseMove:de,onEdgeMouseLeave:ue,reconnectRadius:be,onReconnect:Se,onReconnectStart:Oe,onReconnectEnd:Be,noDragClassName:He,noWheelClassName:se,noPanClassName:W,disableKeyboardA11y:pe,nodeExtent:oe,rfId:fe,viewport:le,onViewportChange:ke}){return Hm(e),Hm(t),GK(),BK(n),FK(le),r(lK,{onPaneClick:G,onPaneMouseEnter:Z,onPaneMouseMove:V,onPaneMouseLeave:K,onPaneContextMenu:te,onPaneScroll:X,paneClickDistance:he,deleteKeyCode:M,selectionKeyCode:w,selectionOnDrag:v,selectionMode:N,onSelectionStart:m,onSelectionEnd:h,multiSelectionKeyCode:k,panActivationKeyCode:C,zoomActivationKeyCode:D,elementsSelectable:$,zoomOnScroll:B,zoomOnPinch:z,zoomOnDoubleClick:j,panOnScroll:T,panOnScrollSpeed:F,panOnScrollMode:H,panOnDrag:Q,defaultViewport:E,translateExtent:R,minZoom:O,maxZoom:A,onSelectionContextMenu:f,preventScrolling:P,noDragClassName:He,noWheelClassName:se,noPanClassName:W,disableKeyboardA11y:pe,onViewportChange:ke,isControlledViewport:!!le,children:u(OK,{children:[r(TK,{edgeTypes:t,onEdgeClick:s,onEdgeDoubleClick:i,onReconnect:Se,onReconnectStart:Oe,onReconnectEnd:Be,onlyRenderVisibleElements:_,onEdgeContextMenu:ee,onEdgeMouseEnter:re,onEdgeMouseMove:de,onEdgeMouseLeave:ue,reconnectRadius:be,defaultMarkerColor:L,noPanClassName:W,disableKeyboardA11y:pe,rfId:fe}),r(qK,{style:x,type:g,component:b,containerStyle:y}),r("div",{className:"react-flow__edgelabel-renderer"}),r(bK,{nodeTypes:e,onNodeClick:o,onNodeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:p,nodeClickDistance:xe,onlyRenderVisibleElements:_,noPanClassName:W,noDragClassName:He,disableKeyboardA11y:pe,nodeExtent:oe,rfId:fe}),r("div",{className:"react-flow__viewport-portal"})]})})}Jw.displayName="GraphView";const WK=je(Jw),Vm=({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:s,height:a,fitView:i,fitViewOptions:l,minZoom:c=.5,maxZoom:d=2,nodeOrigin:p,nodeExtent:f,zIndexMode:m="basic"}={})=>{const h=new Map,g=new Map,x=new Map,b=new Map,y=o??t??[],w=n??e??[],v=p??[0,0],N=f??qo;fw(x,b,y);const{nodesInitialized:k}=Ic(w,h,g,{nodeOrigin:v,nodeExtent:N,zIndexMode:m});let C=[0,0,1];if(i&&s&&a){const D=cs(h,{filter:E=>!!((E.width||E.initialWidth)&&(E.height||E.initialHeight))}),{x:M,y:_,zoom:$}=Nu(D,s,a,c,d,l?.padding??.1);C=[M,_,$]}return{rfId:"1",width:s??0,height:a??0,transform:C,nodes:w,nodesInitialized:k,nodeLookup:h,parentLookup:g,edges:y,edgeLookup:b,connectionLookup:x,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:o!==void 0,panZoom:null,minZoom:c,maxZoom:d,translateExtent:qo,nodeExtent:N,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:jr.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:v,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:i??!1,fitViewOptions:l,fitViewResolver:null,connection:{...K1},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:oG,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:W1,zIndexMode:m,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},KK=({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:s,height:a,fitView:i,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:p,nodeExtent:f,zIndexMode:m})=>pW((h,g)=>{async function x(){const{nodeLookup:b,panZoom:y,fitViewOptions:w,fitViewResolver:v,width:N,height:k,minZoom:C,maxZoom:D}=g();y&&(await nG({nodes:b,width:N,height:k,panZoom:y,minZoom:C,maxZoom:D},w),v?.resolve(!0),h({fitViewResolver:null}))}return{...Vm({nodes:e,edges:t,width:s,height:a,fitView:i,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:p,nodeExtent:f,defaultNodes:n,defaultEdges:o,zIndexMode:m}),setNodes:b=>{const{nodeLookup:y,parentLookup:w,nodeOrigin:v,elevateNodesOnSelect:N,fitViewQueued:k,zIndexMode:C,nodesSelectionActive:D}=g(),{nodesInitialized:M,hasSelectedNodes:_}=Ic(b,y,w,{nodeOrigin:v,nodeExtent:f,elevateNodesOnSelect:N,checkEquality:!0,zIndexMode:C}),$=D&&_;k&&M?(x(),h({nodes:b,nodesInitialized:M,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:$})):h({nodes:b,nodesInitialized:M,nodesSelectionActive:$})},setEdges:b=>{const{connectionLookup:y,edgeLookup:w}=g();fw(y,w,b),h({edges:b})},setDefaultNodesAndEdges:(b,y)=>{if(b){const{setNodes:w}=g();w(b),h({hasDefaultNodes:!0})}if(y){const{setEdges:w}=g();w(y),h({hasDefaultEdges:!0})}},updateNodeInternals:b=>{const{triggerNodeChanges:y,nodeLookup:w,parentLookup:v,domNode:N,nodeOrigin:k,nodeExtent:C,debug:D,fitViewQueued:M,zIndexMode:_}=g(),{changes:$,updatedInternals:E}=MG(b,w,v,N,k,C,_);E&&(NG(w,v,{nodeOrigin:k,nodeExtent:C,zIndexMode:_}),M?(x(),h({fitViewQueued:!1,fitViewOptions:void 0})):h({}),$?.length>0&&(D&&console.log("React Flow: trigger node changes",$),y?.($)))},updateNodePositions:(b,y=!1)=>{const w=[];let v=[];const{nodeLookup:N,triggerNodeChanges:k,connection:C,updateConnection:D,onNodesChangeMiddlewareMap:M}=g();for(const[_,$]of b){const E=N.get(_),R=!!(E?.expandParent&&E?.parentId&&$?.position),O={id:_,type:"position",position:R?{x:Math.max(0,$.position.x),y:Math.max(0,$.position.y)}:$.position,dragging:y};if(E&&C.inProgress&&C.fromNode.id===E.id){const A=lr(E,C.fromHandle,Ae.Left,!0);D({...C,from:A})}R&&E.parentId&&w.push({id:_,parentId:E.parentId,rect:{...$.internals.positionAbsolute,width:$.measured.width??0,height:$.measured.height??0}}),v.push(O)}if(w.length>0){const{parentLookup:_,nodeOrigin:$}=g(),E=Eu(w,N,_,$);v.push(...E)}for(const _ of M.values())v=_(v);k(v)},triggerNodeChanges:b=>{const{onNodesChange:y,setNodes:w,nodes:v,hasDefaultNodes:N,debug:k}=g();if(b?.length){if(N){const C=DW(b,v);w(C)}k&&console.log("React Flow: trigger node changes",b),y?.(b)}},triggerEdgeChanges:b=>{const{onEdgesChange:y,setEdges:w,edges:v,hasDefaultEdges:N,debug:k}=g();if(b?.length){if(N){const C=LW(b,v);w(C)}k&&console.log("React Flow: trigger edge changes",b),y?.(b)}},addSelectedNodes:b=>{const{multiSelectionActive:y,edgeLookup:w,nodeLookup:v,triggerNodeChanges:N,triggerEdgeChanges:k}=g();if(y){const C=b.map(D=>Kn(D,!0));N(C);return}N(Sr(v,new Set([...b]),!0)),k(Sr(w))},addSelectedEdges:b=>{const{multiSelectionActive:y,edgeLookup:w,nodeLookup:v,triggerNodeChanges:N,triggerEdgeChanges:k}=g();if(y){const C=b.map(D=>Kn(D,!0));k(C);return}k(Sr(w,new Set([...b]))),N(Sr(v,new Set,!0))},unselectNodesAndEdges:({nodes:b,edges:y}={})=>{const{edges:w,nodes:v,nodeLookup:N,triggerNodeChanges:k,triggerEdgeChanges:C}=g(),D=b||v,M=y||w,_=[];for(const E of D){if(!E.selected)continue;const R=N.get(E.id);R&&(R.selected=!1),_.push(Kn(E.id,!1))}const $=[];for(const E of M)E.selected&&$.push(Kn(E.id,!1));k(_),C($)},setMinZoom:b=>{const{panZoom:y,maxZoom:w}=g();y?.setScaleExtent([b,w]),h({minZoom:b})},setMaxZoom:b=>{const{panZoom:y,minZoom:w}=g();y?.setScaleExtent([w,b]),h({maxZoom:b})},setTranslateExtent:b=>{g().panZoom?.setTranslateExtent(b),h({translateExtent:b})},resetSelectedElements:()=>{const{edges:b,nodes:y,triggerNodeChanges:w,triggerEdgeChanges:v,elementsSelectable:N}=g();if(!N)return;const k=y.reduce((D,M)=>M.selected?[...D,Kn(M.id,!1)]:D,[]),C=b.reduce((D,M)=>M.selected?[...D,Kn(M.id,!1)]:D,[]);w(k),v(C)},setNodeExtent:b=>{const{nodes:y,nodeLookup:w,parentLookup:v,nodeOrigin:N,elevateNodesOnSelect:k,nodeExtent:C,zIndexMode:D}=g();b[0][0]===C[0][0]&&b[0][1]===C[0][1]&&b[1][0]===C[1][0]&&b[1][1]===C[1][1]||(Ic(y,w,v,{nodeOrigin:N,nodeExtent:b,elevateNodesOnSelect:k,checkEquality:!1,zIndexMode:D}),h({nodeExtent:b}))},panBy:b=>{const{transform:y,width:w,height:v,panZoom:N,translateExtent:k}=g();return AG({delta:b,panZoom:N,transform:y,translateExtent:k,width:w,height:v})},setCenter:async(b,y,w)=>{const{width:v,height:N,maxZoom:k,panZoom:C}=g();if(!C)return Promise.resolve(!1);const D=typeof w?.zoom<"u"?w.zoom:k;return await C.setViewport({x:v/2-b*D,y:N/2-y*D,zoom:D},{duration:w?.duration,ease:w?.ease,interpolate:w?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{h({connection:{...K1}})},updateConnection:b=>{h({connection:b})},reset:()=>h({...Vm()})}},Object.is);function YK({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:o,initialWidth:s,initialHeight:a,initialMinZoom:i,initialMaxZoom:l,initialFitViewOptions:c,fitView:d,nodeOrigin:p,nodeExtent:f,zIndexMode:m,children:h}){const[g]=I(()=>KK({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:s,height:a,fitView:d,minZoom:i,maxZoom:l,fitViewOptions:c,nodeOrigin:p,nodeExtent:f,zIndexMode:m}));return r(fW,{value:g,children:r(OW,{children:h})})}function ZK({children:e,nodes:t,edges:n,defaultNodes:o,defaultEdges:s,width:a,height:i,fitView:l,fitViewOptions:c,minZoom:d,maxZoom:p,nodeOrigin:f,nodeExtent:m,zIndexMode:h}){return Ne(wi)?r(me,{children:e}):r(YK,{initialNodes:t,initialEdges:n,defaultNodes:o,defaultEdges:s,initialWidth:a,initialHeight:i,fitView:l,initialFitViewOptions:c,initialMinZoom:d,initialMaxZoom:p,nodeOrigin:f,nodeExtent:m,zIndexMode:h,children:e})}const XK={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function JK({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,className:s,nodeTypes:a,edgeTypes:i,onNodeClick:l,onEdgeClick:c,onInit:d,onMove:p,onMoveStart:f,onMoveEnd:m,onConnect:h,onConnectStart:g,onConnectEnd:x,onClickConnectStart:b,onClickConnectEnd:y,onNodeMouseEnter:w,onNodeMouseMove:v,onNodeMouseLeave:N,onNodeContextMenu:k,onNodeDoubleClick:C,onNodeDragStart:D,onNodeDrag:M,onNodeDragStop:_,onNodesDelete:$,onEdgesDelete:E,onDelete:R,onSelectionChange:O,onSelectionDragStart:A,onSelectionDrag:P,onSelectionDragStop:L,onSelectionContextMenu:B,onSelectionStart:z,onSelectionEnd:T,onBeforeDelete:F,connectionMode:H,connectionLineType:j=In.Bezier,connectionLineStyle:Q,connectionLineComponent:G,connectionLineContainerStyle:Z,deleteKeyCode:V="Backspace",selectionKeyCode:K="Shift",selectionOnDrag:X=!1,selectionMode:te=Qo.Full,panActivationKeyCode:he="Space",multiSelectionKeyCode:xe=Wo()?"Meta":"Control",zoomActivationKeyCode:ee=Wo()?"Meta":"Control",snapToGrid:re,snapGrid:de,onlyRenderVisibleElements:ue=!1,selectNodesOnDrag:be,nodesDraggable:Se,autoPanOnNodeFocus:Oe,nodesConnectable:Be,nodesFocusable:He,nodeOrigin:se=Ew,edgesFocusable:W,edgesReconnectable:pe,elementsSelectable:oe=!0,defaultViewport:fe=MW,minZoom:le=.5,maxZoom:ke=2,translateExtent:ye=qo,preventScrolling:ie=!0,nodeExtent:ge,defaultMarkerColor:Pe="#b1b1b7",zoomOnScroll:ze=!0,zoomOnPinch:Fe=!0,panOnScroll:lt=!1,panOnScrollSpeed:$t=.5,panOnScrollMode:Xe=Jn.Free,zoomOnDoubleClick:gr=!0,panOnDrag:ps=!0,onPaneClick:fs,onPaneMouseEnter:lo,onPaneMouseMove:oN,onPaneMouseLeave:sN,onPaneScroll:aN,onPaneContextMenu:iN,paneClickDistance:lN=1,nodeClickDistance:cN=0,children:dN,onReconnect:uN,onReconnectStart:pN,onReconnectEnd:fN,onEdgeContextMenu:mN,onEdgeDoubleClick:hN,onEdgeMouseEnter:gN,onEdgeMouseMove:bN,onEdgeMouseLeave:xN,reconnectRadius:yN=10,onNodesChange:vN,onEdgesChange:wN,noDragClassName:NN="nodrag",noWheelClassName:kN="nowheel",noPanClassName:_u="nopan",fitView:$u,fitViewOptions:Du,connectOnClick:SN,attributionPosition:CN,proOptions:MN,defaultEdgeOptions:AN,elevateNodesOnSelect:EN=!0,elevateEdgesOnSelect:IN=!1,disableKeyboardA11y:Lu=!1,autoPanOnConnect:PN,autoPanOnNodeDrag:_N,autoPanSpeed:$N,connectionRadius:DN,isValidConnection:LN,onError:TN,style:RN,id:Tu,nodeDragThreshold:ON,connectionDragThreshold:BN,viewport:zN,onViewportChange:FN,width:jN,height:HN,colorMode:VN="light",debug:UN,onScroll:Ru,ariaLabelConfig:qN,zIndexMode:Ou="basic",...QN},GN){const Ci=Tu||"1",WN=PW(VN),KN=U(Bu=>{Bu.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),Ru?.(Bu)},[Ru]);return r("div",{"data-testid":"rf__wrapper",...QN,onScroll:KN,style:{...RN,...XK},ref:GN,className:tt(["react-flow",s,WN]),id:Tu,role:"application",children:u(ZK,{nodes:e,edges:t,width:jN,height:HN,fitView:$u,fitViewOptions:Du,minZoom:le,maxZoom:ke,nodeOrigin:se,nodeExtent:ge,zIndexMode:Ou,children:[r(IW,{nodes:e,edges:t,defaultNodes:n,defaultEdges:o,onConnect:h,onConnectStart:g,onConnectEnd:x,onClickConnectStart:b,onClickConnectEnd:y,nodesDraggable:Se,autoPanOnNodeFocus:Oe,nodesConnectable:Be,nodesFocusable:He,edgesFocusable:W,edgesReconnectable:pe,elementsSelectable:oe,elevateNodesOnSelect:EN,elevateEdgesOnSelect:IN,minZoom:le,maxZoom:ke,nodeExtent:ge,onNodesChange:vN,onEdgesChange:wN,snapToGrid:re,snapGrid:de,connectionMode:H,translateExtent:ye,connectOnClick:SN,defaultEdgeOptions:AN,fitView:$u,fitViewOptions:Du,onNodesDelete:$,onEdgesDelete:E,onDelete:R,onNodeDragStart:D,onNodeDrag:M,onNodeDragStop:_,onSelectionDrag:P,onSelectionDragStart:A,onSelectionDragStop:L,onMove:p,onMoveStart:f,onMoveEnd:m,noPanClassName:_u,nodeOrigin:se,rfId:Ci,autoPanOnConnect:PN,autoPanOnNodeDrag:_N,autoPanSpeed:$N,onError:TN,connectionRadius:DN,isValidConnection:LN,selectNodesOnDrag:be,nodeDragThreshold:ON,connectionDragThreshold:BN,onBeforeDelete:F,debug:UN,ariaLabelConfig:qN,zIndexMode:Ou}),r(WK,{onInit:d,onNodeClick:l,onEdgeClick:c,onNodeMouseEnter:w,onNodeMouseMove:v,onNodeMouseLeave:N,onNodeContextMenu:k,onNodeDoubleClick:C,nodeTypes:a,edgeTypes:i,connectionLineType:j,connectionLineStyle:Q,connectionLineComponent:G,connectionLineContainerStyle:Z,selectionKeyCode:K,selectionOnDrag:X,selectionMode:te,deleteKeyCode:V,multiSelectionKeyCode:xe,panActivationKeyCode:he,zoomActivationKeyCode:ee,onlyRenderVisibleElements:ue,defaultViewport:fe,translateExtent:ye,minZoom:le,maxZoom:ke,preventScrolling:ie,zoomOnScroll:ze,zoomOnPinch:Fe,zoomOnDoubleClick:gr,panOnScroll:lt,panOnScrollSpeed:$t,panOnScrollMode:Xe,panOnDrag:ps,onPaneClick:fs,onPaneMouseEnter:lo,onPaneMouseMove:oN,onPaneMouseLeave:sN,onPaneScroll:aN,onPaneContextMenu:iN,paneClickDistance:lN,nodeClickDistance:cN,onSelectionContextMenu:B,onSelectionStart:z,onSelectionEnd:T,onReconnect:uN,onReconnectStart:pN,onReconnectEnd:fN,onEdgeContextMenu:mN,onEdgeDoubleClick:hN,onEdgeMouseEnter:gN,onEdgeMouseMove:bN,onEdgeMouseLeave:xN,reconnectRadius:yN,defaultMarkerColor:Pe,noDragClassName:NN,noWheelClassName:kN,noPanClassName:_u,rfId:Ci,disableKeyboardA11y:Lu,nodeExtent:ge,viewport:zN,onViewportChange:FN}),r(CW,{onSelectionChange:O}),dN,r(vW,{proOptions:MN,position:CN}),r(yW,{rfId:Ci,disableKeyboardA11y:Lu})]})})}var eY=Pw(JK);function tY({dimensions:e,lineWidth:t,variant:n,className:o}){return r("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:tt(["react-flow__background-pattern",n,o])})}function nY({radius:e,className:t}){return r("circle",{cx:e,cy:e,r:e,className:tt(["react-flow__background-pattern","dots",t])})}var Dn;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Dn||(Dn={}));const rY={[Dn.Dots]:1,[Dn.Lines]:1,[Dn.Cross]:6},oY=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function eN({id:e,variant:t=Dn.Dots,gap:n=20,size:o,lineWidth:s=1,offset:a=0,color:i,bgColor:l,style:c,className:d,patternClassName:p}){const f=ne(null),{transform:m,patternId:h}=Re(oY,Ge),g=o||rY[t],x=t===Dn.Dots,b=t===Dn.Cross,y=Array.isArray(n)?n:[n,n],w=[y[0]*m[2]||1,y[1]*m[2]||1],v=g*m[2],N=Array.isArray(a)?a:[a,a],k=b?[v,v]:w,C=[N[0]*m[2]||1+k[0]/2,N[1]*m[2]||1+k[1]/2],D=`${h}${e||""}`;return u("svg",{className:tt(["react-flow__background",d]),style:{...c,...ki,"--xy-background-color-props":l,"--xy-background-pattern-color-props":i},ref:f,"data-testid":"rf__background",children:[r("pattern",{id:D,x:m[0]%w[0],y:m[1]%w[1],width:w[0],height:w[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${C[0]},-${C[1]})`,children:x?r(nY,{radius:v/2,className:p}):r(tY,{dimensions:k,lineWidth:s,variant:t,className:p})}),r("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${D})`})]})}eN.displayName="Background";const sY=je(eN);function aY(){return r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:r("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function iY(){return r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:r("path",{d:"M0 0h32v4.2H0z"})})}function lY(){return r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:r("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function cY(){return r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:r("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function dY(){return r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:r("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function qs({children:e,className:t,...n}){return r("button",{type:"button",className:tt(["react-flow__controls-button",t]),...n,children:e})}const uY=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function tN({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:o=!0,fitViewOptions:s,onZoomIn:a,onZoomOut:i,onFitView:l,onInteractiveChange:c,className:d,children:p,position:f="bottom-left",orientation:m="vertical","aria-label":h}){const g=We(),{isInteractive:x,minZoomReached:b,maxZoomReached:y,ariaLabelConfig:w}=Re(uY,Ge),{zoomIn:v,zoomOut:N,fitView:k}=Iu(),C=()=>{v(),a?.()},D=()=>{N(),i?.()},M=()=>{k(s),l?.()},_=()=>{g.setState({nodesDraggable:!x,nodesConnectable:!x,elementsSelectable:!x}),c?.(!x)};return u(Ni,{className:tt(["react-flow__controls",m==="horizontal"?"horizontal":"vertical",d]),position:f,style:e,"data-testid":"rf__controls","aria-label":h??w["controls.ariaLabel"],children:[t&&u(me,{children:[r(qs,{onClick:C,className:"react-flow__controls-zoomin",title:w["controls.zoomIn.ariaLabel"],"aria-label":w["controls.zoomIn.ariaLabel"],disabled:y,children:r(aY,{})}),r(qs,{onClick:D,className:"react-flow__controls-zoomout",title:w["controls.zoomOut.ariaLabel"],"aria-label":w["controls.zoomOut.ariaLabel"],disabled:b,children:r(iY,{})})]}),n&&r(qs,{className:"react-flow__controls-fitview",onClick:M,title:w["controls.fitView.ariaLabel"],"aria-label":w["controls.fitView.ariaLabel"],children:r(lY,{})}),o&&r(qs,{className:"react-flow__controls-interactive",onClick:_,title:w["controls.interactive.ariaLabel"],"aria-label":w["controls.interactive.ariaLabel"],children:x?r(dY,{}):r(cY,{})}),p]})}tN.displayName="Controls";const pY=je(tN);function fY({id:e,x:t,y:n,width:o,height:s,style:a,color:i,strokeColor:l,strokeWidth:c,className:d,borderRadius:p,shapeRendering:f,selected:m,onClick:h}){const{background:g,backgroundColor:x}=a||{},b=i||g||x;return r("rect",{className:tt(["react-flow__minimap-node",{selected:m},d]),x:t,y:n,rx:p,ry:p,width:o,height:s,style:{fill:b,stroke:l,strokeWidth:c},shapeRendering:f,onClick:h?y=>h(y,e):void 0})}const mY=je(fY),hY=e=>e.nodes.map(t=>t.id),Sl=e=>e instanceof Function?e:()=>e;function gY({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:o=5,nodeStrokeWidth:s,nodeComponent:a=mY,onClick:i}){const l=Re(hY,Ge),c=Sl(t),d=Sl(e),p=Sl(n),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return r(me,{children:l.map(m=>r(xY,{id:m,nodeColorFunc:c,nodeStrokeColorFunc:d,nodeClassNameFunc:p,nodeBorderRadius:o,nodeStrokeWidth:s,NodeComponent:a,onClick:i,shapeRendering:f},m))})}function bY({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:o,nodeBorderRadius:s,nodeStrokeWidth:a,shapeRendering:i,NodeComponent:l,onClick:c}){const{node:d,x:p,y:f,width:m,height:h}=Re(g=>{const x=g.nodeLookup.get(e);if(!x)return{node:void 0,x:0,y:0,width:0,height:0};const b=x.internals.userNode,{x:y,y:w}=x.internals.positionAbsolute,{width:v,height:N}=Sn(b);return{node:b,x:y,y:w,width:v,height:N}},Ge);return!d||d.hidden||!nw(d)?null:r(l,{x:p,y:f,width:m,height:h,style:d.style,selected:!!d.selected,className:o(d),color:t(d),borderRadius:s,strokeColor:n(d),strokeWidth:a,shapeRendering:i,onClick:c,id:d.id})}const xY=je(bY);var yY=je(gY);const vY=200,wY=150,NY=e=>!e.hidden,kY=e=>{const t={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:t,boundingRect:e.nodeLookup.size>0?tw(cs(e.nodeLookup,{filter:NY}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},SY="react-flow__minimap-desc";function nN({style:e,className:t,nodeStrokeColor:n,nodeColor:o,nodeClassName:s="",nodeBorderRadius:a=5,nodeStrokeWidth:i,nodeComponent:l,bgColor:c,maskColor:d,maskStrokeColor:p,maskStrokeWidth:f,position:m="bottom-right",onClick:h,onNodeClick:g,pannable:x=!1,zoomable:b=!1,ariaLabel:y,inversePan:w,zoomStep:v=1,offsetScale:N=5}){const k=We(),C=ne(null),{boundingRect:D,viewBB:M,rfId:_,panZoom:$,translateExtent:E,flowWidth:R,flowHeight:O,ariaLabelConfig:A}=Re(kY,Ge),P=e?.width??vY,L=e?.height??wY,B=D.width/P,z=D.height/L,T=Math.max(B,z),F=T*P,H=T*L,j=N*T,Q=D.x-(F-D.width)/2-j,G=D.y-(H-D.height)/2-j,Z=F+j*2,V=H+j*2,K=`${SY}-${_}`,X=ne(0),te=ne();X.current=T,J(()=>{if(C.current&&$)return te.current=RG({domNode:C.current,panZoom:$,getTransform:()=>k.getState().transform,getViewScale:()=>X.current}),()=>{te.current?.destroy()}},[$]),J(()=>{te.current?.update({translateExtent:E,width:R,height:O,inversePan:w,pannable:x,zoomStep:v,zoomable:b})},[x,b,w,v,E,R,O]);const he=h?re=>{const[de,ue]=te.current?.pointer(re)||[0,0];h(re,{x:de,y:ue})}:void 0,xe=g?U((re,de)=>{const ue=k.getState().nodeLookup.get(de).internals.userNode;g(re,ue)},[]):void 0,ee=y??A["minimap.ariaLabel"];return r(Ni,{position:m,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-color-props":typeof p=="string"?p:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*T:void 0,"--xy-minimap-node-background-color-props":typeof o=="string"?o:void 0,"--xy-minimap-node-stroke-color-props":typeof n=="string"?n:void 0,"--xy-minimap-node-stroke-width-props":typeof i=="number"?i:void 0},className:tt(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:u("svg",{width:P,height:L,viewBox:`${Q} ${G} ${Z} ${V}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":K,ref:C,onClick:he,children:[ee&&r("title",{id:K,children:ee}),r(yY,{onClick:xe,nodeColor:o,nodeStrokeColor:n,nodeBorderRadius:a,nodeClassName:s,nodeStrokeWidth:i,nodeComponent:l}),r("path",{className:"react-flow__minimap-mask",d:`M${Q-j},${G-j}h${Z+j*2}v${V+j*2}h${-Z-j*2}z
1185
+ M${M.x},${M.y}h${M.width}v${M.height}h${-M.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}nN.displayName="MiniMap";je(nN);const CY=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,MY={[qr.Line]:"right",[qr.Handle]:"bottom-right"};function AY({nodeId:e,position:t,variant:n=qr.Handle,className:o,style:s=void 0,children:a,color:i,minWidth:l=10,minHeight:c=10,maxWidth:d=Number.MAX_VALUE,maxHeight:p=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:m,autoScale:h=!0,shouldResize:g,onResizeStart:x,onResize:b,onResizeEnd:y}){const w=Lw(),v=typeof e=="string"?e:w,N=We(),k=ne(null),C=n===qr.Handle,D=Re(U(CY(C&&h),[C,h]),Ge),M=ne(null),_=t??MY[n];J(()=>{if(!(!k.current||!v))return M.current||(M.current=YG({domNode:k.current,nodeId:v,getStoreItems:()=>{const{nodeLookup:E,transform:R,snapGrid:O,snapToGrid:A,nodeOrigin:P,domNode:L}=N.getState();return{nodeLookup:E,transform:R,snapGrid:O,snapToGrid:A,nodeOrigin:P,paneDomNode:L}},onChange:(E,R)=>{const{triggerNodeChanges:O,nodeLookup:A,parentLookup:P,nodeOrigin:L}=N.getState(),B=[],z={x:E.x,y:E.y},T=A.get(v);if(T&&T.expandParent&&T.parentId){const F=T.origin??L,H=E.width??T.measured.width??0,j=E.height??T.measured.height??0,Q={id:T.id,parentId:T.parentId,rect:{width:H,height:j,...rw({x:E.x??T.position.x,y:E.y??T.position.y},{width:H,height:j},T.parentId,A,F)}},G=Eu([Q],A,P,L);B.push(...G),z.x=E.x?Math.max(F[0]*H,E.x):void 0,z.y=E.y?Math.max(F[1]*j,E.y):void 0}if(z.x!==void 0&&z.y!==void 0){const F={id:v,type:"position",position:{...z}};B.push(F)}if(E.width!==void 0&&E.height!==void 0){const H={id:v,type:"dimensions",resizing:!0,setAttributes:m?m==="horizontal"?"width":"height":!0,dimensions:{width:E.width,height:E.height}};B.push(H)}for(const F of R){const H={...F,type:"position"};B.push(H)}O(B)},onEnd:({width:E,height:R})=>{const O={id:v,type:"dimensions",resizing:!1,dimensions:{width:E,height:R}};N.getState().triggerNodeChanges([O])}})),M.current.update({controlPosition:_,boundaries:{minWidth:l,minHeight:c,maxWidth:d,maxHeight:p},keepAspectRatio:f,resizeDirection:m,onResizeStart:x,onResize:b,onResizeEnd:y,shouldResize:g}),()=>{M.current?.destroy()}},[_,l,c,d,p,f,x,b,y,g]);const $=_.split("-");return r("div",{className:tt(["react-flow__resize-control","nodrag",...$,n,o]),ref:k,style:{...s,scale:D,...i&&{[C?"backgroundColor":"borderColor"]:i}},children:a})}je(AY);function EY({availableCaps:e,selectedCaps:t,onChange:n}){const[o,s]=I(""),a=q(()=>{const c=new Set(t),d=o.trim().toLowerCase();return e.filter(p=>!c.has(p)&&(d===""||p.toLowerCase().includes(d)))},[e,t,o]),i=U(c=>{n([...t,c]),s("")},[t,n]),l=U(c=>{n(t.filter(d=>d!==c))},[t,n]);return u("div",{className:"flex flex-wrap items-center gap-1 border border-border rounded-md px-2 py-1",children:[t.map(c=>u("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-primary/10 text-primary text-[10px]",children:[c,r("button",{type:"button","aria-label":`Remove ${c}`,onClick:()=>l(c),className:"rounded hover:bg-primary/20",children:r(Ve,{className:"h-2.5 w-2.5"})})]},c)),u("div",{className:"relative flex-1 min-w-[160px]",children:[r("input",{type:"text",placeholder:"Filter caps…",value:o,onChange:c=>s(c.target.value),className:"w-full bg-transparent text-xs outline-none"}),o.length>0&&a.length>0&&r("ul",{role:"listbox",className:"absolute z-10 left-0 right-0 mt-1 max-h-48 overflow-auto rounded-md border border-border bg-surface",children:a.map(c=>r("li",{children:r("button",{type:"button",role:"option","aria-selected":!1,onClick:()=>i(c),className:"w-full text-left px-2 py-1 text-xs hover:bg-muted",children:c})},c))})]})]})}const IY=je(EY),PY=5e3,Cl={consumer:0,cap:400,provider:800},Ml=80,Um=4;function _Y({initialSelectedCaps:e=[],windowSeconds:t=60}){const[n,o]=I(e),{data:s,isLoading:a}=Fx({windowSeconds:t},{refetchInterval:PY}),i=q(()=>{const c=s??[];return Array.from(new Set(c.map(d=>d.capName))).sort()},[s]),l=q(()=>{if(n.length===0)return{nodes:[],edges:[]};const c=new Set(n),p=(s??[]).filter(b=>c.has(b.capName)),f=Array.from(new Set(p.map(b=>b.callerAddonId))).sort(),m=Array.from(new Set(p.map(b=>b.providerAddonId))).sort(),h=[];f.forEach((b,y)=>h.push({id:`consumer:${b}`,position:{x:Cl.consumer,y:y*Ml},data:{label:b}})),n.forEach((b,y)=>h.push({id:`cap:${b}`,position:{x:Cl.cap,y:y*Ml},data:{label:b},style:{background:"#3b82f6",color:"white"}})),m.forEach((b,y)=>h.push({id:`provider:${b}`,position:{x:Cl.provider,y:y*Ml},data:{label:b}}));const g=Math.max(1,...p.map(b=>b.callsPerMin)),x=[];for(const b of p){const y=Math.max(1,Math.min(Um,b.callsPerMin/g*Um));x.push({id:`${b.callerAddonId}→${b.capName}`,source:`consumer:${b.callerAddonId}`,target:`cap:${b.capName}`,style:{strokeWidth:y}}),x.push({id:`${b.capName}→${b.providerAddonId}`,source:`cap:${b.capName}`,target:`provider:${b.providerAddonId}`,style:{strokeWidth:y}})}return{nodes:h,edges:x}},[s,n]);return u("div",{className:"flex flex-col flex-1 min-h-0 gap-2 p-3",children:[r(IY,{availableCaps:i,selectedCaps:n,onChange:o}),n.length===0?r("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-xs",children:"Select 1+ capability to see who uses it."}):a?r("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-xs",children:"Loading…"}):r("div",{className:"flex-1 min-h-0 border border-border rounded-md overflow-hidden",children:u(eY,{nodes:[...l.nodes],edges:[...l.edges],fitView:!0,proOptions:{hideAttribution:!0},children:[r(sY,{gap:20,size:1}),r(pY,{showInteractive:!1})]})})]})}function $Y({onlineNodeIds:e}){const t=Me(),n=st(),{data:o,isLoading:s}=no(),a=cy({onSuccess:()=>{t.invalidateQueries({queryKey:[["pipelineOrchestrator","listAgentSettings"]]})}}),i=q(()=>{if(!o)return[];const c=new Set(e);return c.add("hub"),o.filter(d=>!c.has(d.nodeId))},[o,e]);if(s)return r("section",{className:"rounded-lg border border-border bg-surface p-6 text-xs text-muted-foreground animate-pulse",children:"Loading persisted agent settings…"});const l=async c=>{await n({title:"Remove offline agent?",message:`Drop the persisted orchestrator settings for "${c}". This won't affect a node that comes back online — it just clears stale addonDefaults so it stops cluttering the cluster view.`,confirmLabel:"Remove",cancelLabel:"Keep",variant:"danger"})&&a.mutate({agentNodeId:c})};return i.length===0?r("section",{className:"rounded-lg border border-border bg-surface p-6",children:u("div",{className:"flex flex-col items-center gap-2 text-center text-muted-foreground",children:[r(nc,{className:"h-6 w-6 opacity-40"}),r("p",{className:"text-xs",children:"No stale agent entries."}),r("p",{className:"text-[11px] opacity-60",children:"Every persisted nodeId matches a node currently online in the cluster."})]})}):u("section",{className:"rounded-lg border border-border bg-surface",children:[u("header",{className:"flex items-center gap-2 px-4 py-3 border-b border-border",children:[r(nc,{className:"h-4 w-4 text-muted-foreground"}),r("h2",{className:"text-sm font-semibold",children:"Offline agents"}),u("span",{className:"ml-auto text-[11px] text-muted-foreground",children:[i.length," stale ",i.length===1?"entry":"entries"]})]}),r("p",{className:"px-4 pt-3 text-[11px] text-muted-foreground",children:"Persisted orchestrator settings for nodes not currently in the live topology. Remove entries you don't expect to come back — leftover from data-dir resets, env-driven nodeId changes, or decommissioned hosts."}),r("ul",{className:"divide-y divide-border",children:i.map(c=>{const d=Object.keys(c.settings.addonDefaults??{}).length,p=Object.values(c.settings.addonDefaults??{}).filter(f=>f?.enabled).length;return u("li",{className:"flex items-center gap-3 px-4 py-2 text-xs",children:[r("span",{className:"font-mono text-foreground",children:c.nodeId}),u("span",{className:"text-muted-foreground",children:[d," addons configured",d>0&&u(me,{children:[" · ",p," enabled"]})]}),u("button",{type:"button",onClick:()=>{l(c.nodeId)},disabled:a.isPending,className:"ml-auto flex items-center gap-1 px-2 py-1 rounded text-destructive hover:bg-destructive/10 disabled:opacity-50",children:[r(et,{className:"h-3 w-3"}),"Remove"]})]},c.nodeId)})})]})}function DY(e){const[t,n]=I(()=>typeof window<"u"?window.matchMedia(e).matches:!1);return J(()=>{const o=window.matchMedia(e),s=a=>n(a.matches);return o.addEventListener("change",s),()=>o.removeEventListener("change",s)},[e]),t}function LY(){const{data:e,isLoading:t}=Hn(void 0,{staleTime:1/0}),[n,o]=I(null);return ft("cluster.topology-snapshot",a=>{const i=a.data?.nodes;Array.isArray(i)&&o(i)}),{nodes:q(()=>n??e??[],[n,e]),isLoading:t&&!n}}function TY(){const[e,t]=I("diagram"),[n,o]=I("topology"),s=DY("(max-width: 767px)"),a=s&&e==="diagram"?"table":e,{nodes:i,isLoading:l}=LY(),c=i.filter(g=>g.isOnline).length,d=i.filter(g=>!g.isOnline).length,p=q(()=>i.map(g=>g.id??"").filter(Boolean),[i]),{data:f}=no(),m=q(()=>{if(!f)return 0;const g=new Set(p);return g.add("hub"),f.filter(x=>!g.has(x.nodeId)).length},[f,p]),h=(g,x,b,y)=>u("button",{onClick:()=>t(g),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${e===g?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,children:[r(b,{className:"h-3.5 w-3.5"}),x,y!==void 0&&y>0&&r("span",{className:`ml-1 inline-flex h-4 min-w-[1rem] items-center justify-center rounded-full px-1 text-[10px] font-semibold ${e===g?"bg-primary-foreground/20 text-primary-foreground":"bg-destructive/15 text-destructive"}`,children:y})]});return u("div",{className:"flex flex-col h-full gap-4 p-4",children:[u("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[u("div",{className:"flex items-center gap-2",children:[c>0&&u("span",{className:"text-xs px-2 py-0.5 rounded-full bg-success/10 text-success",children:[c," online"]}),d>0&&u("span",{className:"text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive",children:[d," offline"]})]}),u("div",{className:"flex gap-0.5 p-1 rounded-lg bg-muted",children:[!s&&h("diagram","Diagram",Tn),h("table","Table",o7),h("offline-agents","Offline agents",nc,m)]})]}),a==="diagram"&&u("div",{className:"flex gap-1 p-1 rounded-lg bg-muted self-start",children:[r("button",{type:"button",onClick:()=>o("topology"),className:`px-2 py-1 rounded text-xs ${n==="topology"?"bg-primary text-primary-foreground":"text-muted-foreground"}`,children:"Topology"}),r("button",{type:"button",onClick:()=>o("capability-flow"),className:`px-2 py-1 rounded text-xs ${n==="capability-flow"?"bg-primary text-primary-foreground":"text-muted-foreground"}`,children:"Capability Flow"})]}),l?r("div",{className:"flex items-center justify-center flex-1 text-muted-foreground",children:"Loading cluster topology..."}):a==="diagram"?n==="topology"?r(xV,{topology:i}):r(_Y,{}):a==="table"?r("div",{className:"flex-1 overflow-auto",children:r(aV,{nodes:i})}):r("div",{className:"flex-1 overflow-auto",children:r($Y,{onlineNodeIds:p})})]})}const RY={detection:"border-green-500",detector:"border-green-500",streaming:"border-blue-500",decode:"border-blue-500",decoder:"border-blue-500",recording:"border-orange-500",recorder:"border-orange-500",transcoding:"border-purple-500",transcoder:"border-purple-500",restream:"border-cyan-500",restreamer:"border-cyan-500",storage:"border-yellow-500",notification:"border-pink-500",notifier:"border-pink-500",faces:"border-indigo-500"},OY={detection:"bg-green-500/5",detector:"bg-green-500/5",streaming:"bg-blue-500/5",decode:"bg-blue-500/5",decoder:"bg-blue-500/5",recording:"bg-orange-500/5",recorder:"bg-orange-500/5",transcoding:"bg-purple-500/5",transcoder:"bg-purple-500/5",restream:"bg-cyan-500/5",restreamer:"bg-cyan-500/5",storage:"bg-yellow-500/5",notification:"bg-pink-500/5",notifier:"bg-pink-500/5",faces:"bg-indigo-500/5"};function BY({entry:e,actions:t}){const n=e.name.toLowerCase(),o=RY[n]??"border-primary",s=OY[n]??"bg-primary/5",a=e.providers.find(l=>l.active),i=t?.pendingCapability===e.name;return u("div",{className:`rounded-lg border-t-2 border border-border ${o} ${s} p-3 space-y-2`,children:[u("div",{className:"flex items-center justify-between gap-2",children:[u("span",{className:"text-xs font-semibold text-foreground capitalize flex items-center gap-1.5",children:[e.name,i&&r(Ee,{className:"h-3 w-3 animate-spin text-primary"})]}),r("span",{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode==="singleton"?"bg-primary/10 text-primary":"bg-info/10 text-info"}`,children:e.mode})]}),e.mode==="singleton"?r(zY,{entry:e,actions:t,activeProvider:a,isPending:i}):r(FY,{entry:e,actions:t,isPending:i})]})}function zY({entry:e,actions:t,activeProvider:n,isPending:o}){if(!t)return r("div",{children:n?u("div",{className:"flex items-center gap-1.5 text-[10px] text-foreground",children:[r(Zn,{className:"h-3 w-3 text-green-400 shrink-0"}),r("span",{className:"font-medium",children:n.addonName}),r("span",{className:"rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto",children:"ACTIVE"})]}):r("div",{className:"text-[10px] text-foreground-subtle italic",children:"No active provider"})});if(e.providers.length===0)return r("div",{className:"text-[10px] text-foreground-subtle italic",children:"No providers"});const s="__inherit__";return u("div",{className:"space-y-2",children:[r("div",{className:"space-y-1",children:e.providers.map(a=>{const i=a.active;return u("button",{type:"button",disabled:o||i,onClick:()=>t.onSelectSingleton(e.name,a.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${i?"bg-green-500/10 text-foreground cursor-default":"text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50"}`,children:[r("span",{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${i?"border-green-400 bg-green-400":"border-border"}`}),r("span",{className:"font-medium truncate",children:a.addonName}),i&&r("span",{className:"rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0",children:"ACTIVE"})]},a.addonId)})}),e.perNode&&e.perNode.length>0&&r("div",{className:"space-y-2 pt-1 border-t border-border/40",children:e.perNode.map(a=>{const i=a.hasOverride&&a.resolvedActive?a.resolvedActive:s,l=[{value:s,label:`Inherit global${a.resolvedActive?` (${a.resolvedActive})`:""}`},...a.providers.map(p=>({value:p,label:p}))],c=p=>{p===s?t.onClearNodeSingleton(e.name,a.nodeId):t.onSelectNodeSingleton(e.name,a.nodeId,p)},d=o;return u("div",{className:"space-y-0.5",children:[u("div",{className:"text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5",children:[a.nodeId,a.hasOverride&&r("span",{className:"ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium",children:"override"})]}),l.map(p=>{const f=i===p.value;return u("button",{type:"button",disabled:d||f,onClick:()=>c(p.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${f?"bg-green-500/10 text-foreground cursor-default":"text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50"}`,children:[r("span",{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${f?"border-green-400 bg-green-400":"border-border"}`}),r("span",{className:"font-medium truncate",children:p.label}),f&&p.value!==s&&r("span",{className:"rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0",children:"ACTIVE"})]},p.value)})]},a.nodeId)})})]})}function FY({entry:e,actions:t,isPending:n}){if(e.providers.length===0)return r("div",{className:"text-[10px] text-foreground-subtle italic",children:"No providers"});if(!t)return r("div",{className:"space-y-1",children:e.providers.map(a=>u("div",{className:"flex items-center justify-between gap-2 text-[10px]",children:[r("span",{className:"text-foreground-subtle",children:a.addonName}),a.active&&r("span",{className:"rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium",children:"ACTIVE"})]},a.addonId))});const o=e.providers.filter(a=>a.active).map(a=>a.addonId),s=(a,i)=>{const l=i?[...new Set([...o,a])]:o.filter(c=>c!==a);t.onToggleCollection(e.name,l)};return r("div",{className:"space-y-1",children:e.providers.map(a=>u("label",{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${n?"opacity-50":"hover:bg-surface-hover cursor-pointer"}`,children:[u("span",{className:"flex items-center gap-1.5 min-w-0",children:[r("input",{type:"checkbox",checked:a.active,disabled:n,onChange:i=>s(a.addonId,i.target.checked),className:"h-3 w-3 accent-green-500 shrink-0"}),r("span",{className:"text-foreground truncate",children:a.addonName})]}),a.active&&r("span",{className:"rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0",children:"ACTIVE"})]},a.addonId))})}function qm({capabilities:e,actions:t}){return e.length===0?r("div",{className:"text-xs text-foreground-subtle text-center py-8",children:"No capabilities registered"}):r("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3",children:e.map(n=>r(BY,{entry:n,actions:t},n.name))})}const jY=["capabilities","listCapabilities"];function HY(e){return e==="singleton"||e==="collection"}function VY(e){const t=e.indexOf("@");return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function UY(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:VY(n),active:t==="singleton"?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t==="singleton"&&e.perNode?{perNode:e.perNode}:{}}}function qY(){const e=De(),[t,n]=I(null),[o,s]=I(null),a=cr({queryKey:jY,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),i=q(()=>{const g=(a.data??[]).flatMap(y=>HY(y.mode)?[UY(y,y.mode)]:[]),x=g.filter(y=>y.mode==="singleton").sort((y,w)=>y.name.localeCompare(w.name)),b=g.filter(y=>y.mode==="collection").sort((y,w)=>y.name.localeCompare(w.name));return[...x,...b]},[a.data]),l=q(()=>i.filter(g=>g.mode==="singleton"),[i]),c=q(()=>i.filter(g=>g.mode==="collection"),[i]),d=Rt({mutationFn:g=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:g.capName,addonId:g.addonId}),onMutate:g=>{n(g.capName),s(null)},onSuccess:async(g,x)=>{s({kind:"success",message:`${x.capName} → ${x.addonId} is now active.`}),await a.refetch()},onError:(g,x)=>{s({kind:"error",message:`Failed to set ${x.capName}: ${g instanceof Error?g.message:"unknown error"}`})},onSettled:()=>n(null)}),p=Rt({mutationFn:g=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:g.capName,addonId:g.addonId,nodeId:g.nodeId}),onMutate:g=>{n(g.capName),s(null)},onSuccess:async(g,x)=>{s({kind:"success",message:`${x.capName} @ ${x.nodeId} → ${x.addonId}.`}),await a.refetch()},onError:(g,x)=>{s({kind:"error",message:`Failed to set ${x.capName} @ ${x.nodeId}: ${g instanceof Error?g.message:"unknown error"}`})},onSettled:()=>n(null)}),f=Rt({mutationFn:g=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:g.capName,nodeId:g.nodeId}),onMutate:g=>{n(g.capName),s(null)},onSuccess:async(g,x)=>{s({kind:"success",message:`${x.capName} @ ${x.nodeId} now inherits the global default.`}),await a.refetch()},onError:(g,x)=>{s({kind:"error",message:`Failed to clear ${x.capName} @ ${x.nodeId}: ${g instanceof Error?g.message:"unknown error"}`})},onSettled:()=>n(null)}),m=Rt({mutationFn:g=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:g.capName,enabledAddonIds:[...g.enabledAddonIds]}),onMutate:g=>{n(g.capName),s(null)},onSuccess:async(g,x)=>{s({kind:"success",message:`${x.capName}: ${x.enabledAddonIds.length} provider(s) enabled.`}),await a.refetch()},onError:(g,x)=>{s({kind:"error",message:`Failed to update ${x.capName}: ${g instanceof Error?g.message:"unknown error"}`})},onSettled:()=>n(null)}),h={onSelectSingleton:(g,x)=>d.mutate({capName:g,addonId:x}),onSelectNodeSingleton:(g,x,b)=>p.mutate({capName:g,nodeId:x,addonId:b}),onClearNodeSingleton:(g,x)=>f.mutate({capName:g,nodeId:x}),onToggleCollection:(g,x)=>m.mutate({capName:g,enabledAddonIds:x}),pendingCapability:t};return u(ot,{icon:Mv,title:"Capabilities",subtitle:"Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.",children:[o&&u("div",{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${o.kind==="success"?"border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300":"border-danger/40 bg-danger/10 text-danger"}`,children:[o.kind==="success"?r(Zn,{className:"h-3.5 w-3.5 shrink-0"}):r(nr,{className:"h-3.5 w-3.5 shrink-0"}),r("span",{children:o.message})]}),a.isLoading&&r("div",{className:"flex items-center justify-center py-16",children:r("div",{className:"animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full"})}),a.isError&&!a.isLoading&&r(Zo,{title:"Failed to load capabilities",message:a.error instanceof Error?a.error.message:"Unknown error",onRetry:()=>void a.refetch()}),!a.isLoading&&!a.isError&&i.length===0&&r("div",{className:"text-xs text-foreground-subtle text-center py-16",children:"No capabilities registered."}),!a.isLoading&&!a.isError&&i.length>0&&u("div",{className:"space-y-6",children:[l.length>0&&u("section",{className:"space-y-2",children:[r("h2",{className:"text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70",children:"Singleton — pick one provider"}),r(qm,{capabilities:l,actions:h})]}),c.length>0&&u("section",{className:"space-y-2",children:[r("h2",{className:"text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70",children:"Collection — enable a set"}),r(qm,{capabilities:c,actions:h})]})]})]})}function un({title:e,children:t}){return u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r("div",{className:"border-b border-border px-4 py-2.5",children:r("h2",{className:"text-xs font-semibold text-foreground uppercase tracking-wider",children:e})}),r("div",{className:"p-4",children:t})]})}function dt({name:e,cssVar:t,hex:n}){const o=t?`var(${t})`:n;return u("div",{className:"flex flex-col items-center gap-1.5",children:[r("div",{className:"h-10 w-10 rounded-lg border border-border shadow-inner",style:{backgroundColor:o}}),r("span",{className:"text-[10px] text-foreground-subtle text-center leading-tight",children:e})]})}const QY={sections:[{id:"demo",title:"Demo Fields",columns:2,fields:[{key:"name",type:"text",label:"Name",placeholder:"Enter name"},{key:"count",type:"number",label:"Count",min:0,max:100,unit:"items"},{key:"enabled",type:"boolean",label:"Enabled"},{key:"mode",type:"select",label:"Mode",options:[{value:"a",label:"Alpha"},{value:"b",label:"Beta"}]},{key:"tags",type:"tags",label:"Tags",span:2,suggestions:["camera","zone","alert"]},{key:"confidence",type:"slider",label:"Confidence",min:0,max:100,step:5,unit:"%",span:2},{key:"info",type:"info",label:"Note",content:"This is an informational message for the user.",variant:"info"}]}]};function GY(){const[e,t]=I({name:"Example",count:10,enabled:!0,mode:"a",tags:["camera"],confidence:60});return u("div",{className:"p-6 space-y-6 max-w-5xl mx-auto",children:[u("div",{className:"mb-6",children:[r("h1",{className:"text-xl font-bold text-foreground",children:"Component Showroom"}),r("p",{className:"text-sm text-foreground-subtle mt-1",children:"All UI components at a glance"})]}),r(un,{title:"Typography",children:u("div",{className:"space-y-3",children:[r("h1",{className:"text-2xl font-bold text-foreground",children:"Heading 1 — Display title"}),r("h2",{className:"text-xl font-semibold text-foreground",children:"Heading 2 — Section title"}),r("h3",{className:"text-base font-semibold text-foreground",children:"Heading 3 — Card title"}),r("h4",{className:"text-sm font-semibold text-foreground",children:"Heading 4 — Sub-section"}),r("p",{className:"text-sm text-foreground",children:"Body text — Regular paragraph content goes here. It uses the foreground color."}),r("p",{className:"text-sm text-foreground-subtle",children:"Subtle text — Secondary/descriptive text with reduced emphasis."}),r("p",{className:"text-xs text-foreground-subtle uppercase tracking-wider font-semibold",children:"Label / Caption"}),r("p",{className:"text-xs text-foreground-disabled",children:"Disabled / placeholder text"})]})}),r(un,{title:"Colors",children:u("div",{className:"flex flex-wrap gap-4",children:[r(dt,{name:"primary",cssVar:"--color-primary"}),r(dt,{name:"background",cssVar:"--color-background"}),r(dt,{name:"surface",cssVar:"--color-surface"}),r(dt,{name:"foreground",cssVar:"--color-foreground"}),r(dt,{name:"success",cssVar:"--color-success"}),r(dt,{name:"warning",cssVar:"--color-warning"}),r(dt,{name:"danger",cssVar:"--color-danger"}),r(dt,{name:"info",cssVar:"--color-info"}),r(dt,{name:"border",cssVar:"--color-border"}),r("div",{className:"w-px"}),r(dt,{name:"frigate",hex:"#3b82f6"}),r(dt,{name:"scrypted",hex:"#a855f7"}),r(dt,{name:"reolink",hex:"#06b6d4"}),r(dt,{name:"ha",hex:"#22d3ee"}),r(dt,{name:"rtsp",hex:"#78716c"})]})}),r(un,{title:"Buttons",children:u("div",{className:"flex flex-wrap gap-3",children:[r("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-4 py-2 text-sm font-medium text-white hover:opacity-90 transition-opacity",children:"Primary"}),r("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border bg-surface px-4 py-2 text-sm font-medium text-foreground hover:bg-surface-hover transition-colors",children:"Secondary"}),r("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-danger/40 bg-danger/10 px-4 py-2 text-sm font-medium text-danger hover:bg-danger/20 transition-colors",children:"Danger"}),r("button",{disabled:!0,className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-4 py-2 text-sm font-medium text-white opacity-40 cursor-not-allowed",children:"Disabled"}),r("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-warning/40 bg-warning/10 px-4 py-2 text-sm font-medium text-warning hover:bg-warning/20 transition-colors",children:"Warning"}),r("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-success/40 bg-success/10 px-4 py-2 text-sm font-medium text-success hover:bg-success/20 transition-colors",children:"Success"})]})}),r(un,{title:"Inputs",children:u("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u("div",{children:[r("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Text input"}),r("input",{type:"text",className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30",placeholder:"Type something..."})]}),u("div",{children:[r("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Number input"}),r("input",{type:"number",className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30",placeholder:"0"})]}),u("div",{children:[r("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Password input"}),r("input",{type:"password",className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30",placeholder:"••••••••"})]}),u("div",{children:[r("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Select"}),u("select",{className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30",children:[r("option",{children:"Option A"}),r("option",{children:"Option B"}),r("option",{children:"Option C"})]})]}),u("div",{className:"md:col-span-2",children:[r("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Textarea"}),r("textarea",{className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30 resize-y min-h-[60px]",placeholder:"Enter multi-line text...",rows:3})]}),r("div",{children:u("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[r("input",{type:"checkbox",className:"h-3.5 w-3.5 rounded border-border accent-primary",defaultChecked:!0}),r("span",{className:"text-xs font-medium text-foreground",children:"Checkbox (checked)"})]})}),r("div",{children:u("div",{className:"flex items-center justify-between",children:[r("span",{className:"text-xs font-medium text-foreground",children:"Toggle switch"}),r(WY,{})]})}),u("div",{children:[r("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Slider"}),r("input",{type:"range",className:"w-full h-1 accent-primary cursor-pointer",min:0,max:100,defaultValue:60})]}),u("div",{children:[r("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Tags example"}),r("div",{className:"flex flex-wrap gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 min-h-[38px]",children:["camera","zone","alert"].map(n=>r("span",{className:"inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:n},n))})]})]})}),r(un,{title:"Badges",children:u("div",{className:"space-y-3",children:[u("div",{children:[r("p",{className:"text-xs text-foreground-subtle mb-2",children:"StatusBadge"}),r("div",{className:"flex flex-wrap gap-2",children:["running","stopped","error","online","offline","idle"].map(n=>r(li,{status:n},n))})]}),u("div",{children:[r("p",{className:"text-xs text-foreground-subtle mb-2",children:"CapabilityBadges"}),r(ci,{capabilities:["streaming","detection","recording","audio"]})]})]})}),r(un,{title:"Cards",children:u("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u("div",{className:"rounded-lg bg-surface p-4",children:[r("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Surface card"}),r("p",{className:"text-xs text-foreground-subtle",children:"Uses `bg-surface`. Default card background."})]}),u("div",{className:"rounded-lg border border-border bg-surface p-4",children:[r("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Bordered card"}),r("p",{className:"text-xs text-foreground-subtle",children:"Uses `border border-border bg-surface`."})]}),u("div",{className:"rounded-lg border border-primary/30 bg-primary/5 p-4",children:[r("h3",{className:"text-sm font-semibold text-primary mb-1",children:"Accent card"}),r("p",{className:"text-xs text-foreground-subtle",children:"Highlighted with primary color."})]}),u("div",{className:"rounded-lg bg-background p-4",children:[r("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Background card"}),r("p",{className:"text-xs text-foreground-subtle",children:"Uses `bg-background`. Inset card."})]})]})}),r(un,{title:"Provider Icons",children:r("div",{className:"flex flex-wrap gap-4",children:["frigate","scrypted","reolink","homeassistant","rtsp","onvif"].map(n=>r(yn,{type:n,size:"lg",showLabel:!0},n))})}),u(un,{title:"Form Builder Demo",children:[r(On,{schema:QY,values:e,onChange:t}),u("details",{className:"mt-3",children:[r("summary",{className:"text-[10px] text-foreground-subtle cursor-pointer hover:text-foreground",children:"View current values"}),r("pre",{className:"mt-2 rounded-md bg-background p-3 text-[10px] text-foreground-subtle overflow-auto",children:JSON.stringify(e,null,2)})]})]}),r(un,{title:"Info Boxes",children:r("div",{className:"space-y-2",children:[{variant:"info",label:"Info",content:"This is an informational message. Use it for tips and hints."},{variant:"warning",label:"Warning",content:"This action may have side effects. Proceed with caution."},{variant:"success",label:"Success",content:"Operation completed successfully. All systems are green."},{variant:"danger",label:"Danger",content:"This operation is irreversible. Data will be permanently deleted."}].map(({variant:n,label:o,content:s})=>{const i={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"}}[n];return u("div",{className:`rounded-md border-l-4 px-3 py-2.5 ${i.border} ${i.bg}`,children:[r("p",{className:`text-xs font-semibold mb-0.5 ${i.text}`,children:o}),r("p",{className:"text-xs text-foreground-subtle leading-relaxed",children:s})]},n)})})})]})}function WY(){const[e,t]=I(!0);return r("button",{type:"button",role:"switch","aria-checked":e,onClick:()=>t(n=>!n),className:["relative inline-flex h-4 w-8 shrink-0 items-center rounded-full transition-colors duration-150 cursor-pointer",e?"bg-primary":"bg-foreground-subtle/30"].join(" "),children:r("span",{className:["inline-block h-3 w-3 rounded-full bg-white shadow transition-transform duration-150",e?"translate-x-4":"translate-x-0.5"].join(" ")})})}const Qm={info:{bg:"bg-blue-500/10",border:"border-blue-500/30",icon:rr},warning:{bg:"bg-orange-500/10",border:"border-orange-500/30",icon:pt},critical:{bg:"bg-red-500/10",border:"border-red-500/30",icon:nr}};function KY({toast:e,onDismiss:t}){const n=Qm[e.severity]??Qm.info,o=n.icon;return J(()=>{const s=e.duration??5e3;if(s<=0)return;const a=setTimeout(()=>t(e.id),s);return()=>clearTimeout(a)},[e.id,e.duration,t]),u("div",{className:`flex items-start gap-3 px-4 py-3 rounded-lg border ${n.border} ${n.bg} shadow-lg backdrop-blur-sm animate-in slide-in-from-right-5 fade-in duration-200`,children:[r(o,{className:"h-4 w-4 shrink-0 mt-0.5 text-foreground-subtle"}),u("div",{className:"flex-1 min-w-0",children:[r("div",{className:"text-xs font-semibold text-foreground",children:e.title}),r("div",{className:"text-[11px] text-foreground-subtle mt-0.5",children:e.message})]}),r("button",{type:"button",onClick:()=>t(e.id),className:"shrink-0 p-0.5 rounded hover:bg-surface-hover transition-colors",children:r(Ve,{className:"h-3.5 w-3.5 text-foreground-subtle"})})]})}function YY(){const[e,t]=I([]),n=U(o=>{t(s=>s.filter(a=>a.id!==o))},[]);return Dy(void 0,{onData:o=>{const s=o,a=`toast-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;t(i=>[...i,{...s,id:a,timestamp:Date.now()}])}}),e.length===0?null:r("div",{className:"fixed bottom-4 right-4 z-50 flex flex-col gap-2 max-w-sm w-full pointer-events-none",children:e.map(o=>r("div",{className:"pointer-events-auto",children:r(KY,{toast:o,onDismiss:n})},o.id))})}const Dc=new Jm({defaultOptions:{queries:{staleTime:3e4,retry:!1,refetchOnWindowFocus:!1}}});function ZY({field:e,value:t,onChange:n,disabled:o}){return r(M7,{field:e,value:t,onChange:n,disabled:o})}function XY({field:e,value:t,onChange:n,disabled:o}){return r(R7,{field:e,value:t,onChange:n,disabled:o})}const JY={"pipeline-editor":ZY,"model-selector":XY};function eZ({children:e}){const{user:t}=sn(),[n,o]=I(0),s=ne(t?.username??null);J(()=>{const f=t?.username??null;f!==s.current&&(s.current=f,Nr(),o(m=>m+1))},[t]);const a=q(()=>Xs(),[n]),[i,l]=I(!1),[c,d]=I(null);J(()=>{if(l(!1),d(null),!t){l(!0);return}let f=!1;return a.init().then(()=>{f||l(!0)},m=>{if(f)return;const h=m instanceof Error?m.message:String(m);d(h),l(!0)}),()=>{f=!0}},[a,t]);const p=U(()=>{Nr(),o(f=>f+1),Dc.invalidateQueries()},[]);return E6(p),r(rd,{system:a,children:r(S.Provider,{client:a.trpcClient,queryClient:Dc,children:u(Wy,{children:[i?e:r(tZ,{}),i&&r(v7,{}),c!==null&&i&&u("div",{className:"fixed bottom-4 right-4 z-50 max-w-sm rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning shadow-lg",children:["Boot probe failed: ",c,". Retrying in background."]})]})})})}function tZ(){return r("div",{className:"flex min-h-screen items-center justify-center bg-background",children:u("div",{className:"flex items-center gap-3 text-sm text-foreground-subtle",children:[r("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary/30 border-t-primary"}),"Connecting…"]})})}function nZ(){return r(aa,{defaultMode:"dark",children:r(eh,{client:Dc,children:r(H7,{children:r(eZ,{children:r(Og,{children:u(ob,{renderers:JY,children:[r(b6,{children:u(QR,{children:[r(Te,{path:"/login",element:r(q9,{})}),r(Te,{path:"/change-password",element:r(Mt,{children:r(G9,{})})}),r(Te,{path:"/showroom",element:r(GY,{})}),u(Te,{element:r(Mt,{children:r(U9,{})}),children:[r(Te,{index:!0,element:r(ht,{to:"/dashboard",replace:!0})}),r(Te,{path:"/access-denied",element:r(W9,{})}),r(Te,{path:"/dashboard",element:r(sB,{})}),r(Te,{path:"/devices",element:r(dB,{})}),r(Te,{path:"/cameras",element:r(ht,{to:"/devices",replace:!0})}),r(Te,{path:"/integrations",element:r(wB,{})}),r(Te,{path:"/integrations/:integrationId",element:r(SB,{})}),r(Te,{path:"/timeline",element:r(LB,{})}),r(Te,{path:"/pipeline",element:r(mz,{})}),r(Te,{path:"/devices/:deviceId",element:r(yF,{})}),r(Te,{path:"/system/logs",element:r(Mt,{requireAdmin:!0,children:r(VF,{})})}),r(Te,{path:"/system/addons",element:r(Mt,{requireAdmin:!0,children:r(OF,{})})}),r(Te,{path:"/system/settings",element:r(Mt,{requireAdmin:!0,children:r(UH,{})})}),r(Te,{path:"/system/cluster",element:r(Mt,{requireAdmin:!0,children:r(TY,{})})}),r(Te,{path:"/system/capabilities",element:r(Mt,{requireAdmin:!0,children:r(qY,{})})}),r(Te,{path:"/system/identity",element:r(Mt,{requireAdmin:!0,children:r(bj,{})})}),r(Te,{path:"/system/my-access",element:r(FF,{})}),r(Te,{path:"/system/network",element:r(Mt,{requireAdmin:!0,children:r(qj,{})})}),r(Te,{path:"/system/integrations",element:r(Mt,{requireAdmin:!0,children:r(nH,{})})}),r(Te,{path:"/system/data",element:r(Mt,{requireAdmin:!0,children:r(VH,{})})}),r(Te,{path:"/system/users",element:r(ht,{to:"/system/identity?tab=users",replace:!0})}),r(Te,{path:"/system/api-keys",element:r(ht,{to:"/system/identity?tab=api-keys",replace:!0})}),r(Te,{path:"/system/authentication",element:r(ht,{to:"/system/identity?tab=authentication",replace:!0})}),r(Te,{path:"/system/linked-sessions",element:r(ht,{to:"/system/identity?tab=linked-sessions",replace:!0})}),r(Te,{path:"/system/remote-access",element:r(ht,{to:"/system/network?tab=remote-access",replace:!0})}),r(Te,{path:"/system/turn",element:r(ht,{to:"/system/network?tab=turn",replace:!0})}),r(Te,{path:"/system/storage",element:r(ht,{to:"/system/data?tab=storage",replace:!0})}),r(Te,{path:"/system/backup",element:r(ht,{to:"/system/data?tab=backup",replace:!0})}),r(Te,{path:"/addon/:pagePath",element:r(Mt,{requireAdmin:!0,children:r(j9,{})})})]})]})}),r(YY,{})]})})})})})})}const rZ={dashboard:"Dashboard",integrations:"Integrations",metrics:"Metrics",camerasSection:"Input systems"},oZ={title:"System",addons:"Addons",agents:"Agents",processes:"Processes",logs:"Logs",users:"Users",settings:"Settings",repl:"REPL",models:"Models",integrations:"External systems"},sZ={save:"Save",cancel:"Cancel",delete:"Delete",enable:"Enable",disable:"Disable",edit:"Edit",add:"Add",remove:"Remove",confirm:"Confirm",close:"Close",back:"Back",next:"Next",search:"Search",filter:"Filter",reset:"Reset",apply:"Apply",submit:"Submit",loading:"Loading…",error:"Error",success:"Success",warning:"Warning",info:"Info",noData:"No data available",noResults:"No results found",retry:"Retry",refresh:"Refresh",copy:"Copy",copied:"Copied!",yes:"Yes",no:"No"},aZ={disconnected:"Server unreachable — reconnecting…",connected:"Connected"},iZ={online:"Online",offline:"Offline",connecting:"Connecting",error:"Error",disabled:"Disabled",enabled:"Enabled",active:"Active",inactive:"Inactive",running:"Running",stopped:"Stopped",pending:"Pending",unknown:"Unknown"},lZ={login:"Login",logout:"Logout",username:"Username",password:"Password",signIn:"Sign In",invalidCredentials:"Invalid username or password"},cZ={dark:"Dark",light:"Light",system:"System"},dZ={select:"Language",en:"English",it:"Italian"},uZ={dashboard:{title:"Dashboard",subtitle:"Overview of all devices and their status"},integrations:{title:"Integrations",subtitle:"Manage camera sources and provider connections"},metrics:{title:"Metrics",subtitle:"System performance and usage statistics"},agents:{title:"Agents",subtitle:"Manage distributed processing agents"},addons:{title:"Addons",subtitle:"Extend functionality with addon modules"},settings:{title:"Settings",subtitle:"Configure system-wide preferences"},users:{title:"Users",subtitle:"Manage user accounts and permissions"},logs:{title:"Logs",subtitle:"View system and device logs"}},pZ={preview:"Preview",snapshotUnavailable:"Snapshot unavailable",noSnapshot:"No snapshot",lastSnapshot:"Last snapshot:",offline:"Offline",active:"Active",available:"Available",noDevices:"No devices.",addFirstDevice:"Add your first device to get started.",import:"+ Import",noProviders:"No providers available. Install a provider addon.",manage:"Manage",integrationName:"Integration name",integrationNamePlaceholder:"e.g. Garage Server",connectionSuccess:"Connection successful!",errorPrefix:"Error:",back:"Back",testing:"Testing...",testConnection:"Test connection",forward:"Next",searchingDevices:"Searching for devices...",foundDevices:"Found {{count}} devices. Select the ones to import.",noDevicesFound:"No devices found.",skip:"Skip",importSelected:"Import selected",newIntegration:"New Integration",configureIntegration:"Configure Integration",importDevices:"Import Devices",addDevice:"Add device",name:"Name",namePlaceholder:"e.g. Entrance Camera",snapshotUrlOptional:"Snapshot URL (optional)",streamUrls:"Stream URLs",addStream:"Add stream",cancel:"Cancel",saving:"Saving...",save:"Save",saveAndNew:"Save and new",test:"Test",stream:"Stream {{number}}:",devices:"devices",rediscover:"Rediscover",config:"Config",integrationNotFound:"Integration not found.",configComingSoon:"Config coming soon.",providerConfig:"Provider Config"},fZ={nav:rZ,system:oZ,common:sZ,connection:aZ,status:iZ,auth:lZ,theme:cZ,language:dZ,pages:uZ,integrations:pZ},mZ={dashboard:"Dashboard",integrations:"Integrazioni",metrics:"Metriche",camerasSection:"Sistemi in input"},hZ={title:"Sistema",addons:"Addon",agents:"Agenti",processes:"Processi",logs:"Log",users:"Utenti",settings:"Impostazioni",repl:"REPL",models:"Modelli",integrations:"Sistemi esterni"},gZ={save:"Salva",cancel:"Annulla",delete:"Elimina",enable:"Abilita",disable:"Disabilita",edit:"Modifica",add:"Aggiungi",remove:"Rimuovi",confirm:"Conferma",close:"Chiudi",back:"Indietro",next:"Avanti",search:"Cerca",filter:"Filtra",reset:"Reimposta",apply:"Applica",submit:"Invia",loading:"Caricamento…",error:"Errore",success:"Successo",warning:"Avviso",info:"Info",noData:"Nessun dato disponibile",noResults:"Nessun risultato trovato",retry:"Riprova",refresh:"Aggiorna",copy:"Copia",copied:"Copiato!",yes:"Sì",no:"No"},bZ={disconnected:"Server non raggiungibile — riconnessione in corso…",connected:"Connesso"},xZ={online:"Online",offline:"Offline",connecting:"Connessione in corso",error:"Errore",disabled:"Disabilitato",enabled:"Abilitato",active:"Attivo",inactive:"Inattivo",running:"In esecuzione",stopped:"Fermato",pending:"In attesa",unknown:"Sconosciuto"},yZ={login:"Accesso",logout:"Esci",username:"Nome utente",password:"Password",signIn:"Accedi",invalidCredentials:"Nome utente o password non validi"},vZ={dark:"Scuro",light:"Chiaro",system:"Sistema"},wZ={select:"Lingua",en:"Inglese",it:"Italiano"},NZ={dashboard:{title:"Dashboard",subtitle:"Panoramica di tutti i dispositivi e il loro stato"},integrations:{title:"Integrazioni",subtitle:"Gestisci le sorgenti video e le connessioni ai provider"},metrics:{title:"Metriche",subtitle:"Statistiche di prestazioni e utilizzo del sistema"},agents:{title:"Agenti",subtitle:"Gestisci gli agenti di elaborazione distribuita"},addons:{title:"Addon",subtitle:"Estendi le funzionalità con moduli addon"},settings:{title:"Impostazioni",subtitle:"Configura le preferenze di sistema"},users:{title:"Utenti",subtitle:"Gestisci gli account utente e i permessi"},logs:{title:"Log",subtitle:"Visualizza i log di sistema e dei dispositivi"}},kZ={preview:"Anteprima",snapshotUnavailable:"Snapshot non disponibile",noSnapshot:"Nessuno snapshot",lastSnapshot:"Ultimo snapshot:",offline:"Offline",active:"Attivi",available:"Disponibili",noDevices:"Nessun dispositivo.",addFirstDevice:"Aggiungi il primo dispositivo per iniziare.",import:"+ Importa",noProviders:"Nessun provider disponibile. Installa un addon provider.",manage:"Gestisci",integrationName:"Nome integrazione",integrationNamePlaceholder:"es. Server Garage",connectionSuccess:"Connessione riuscita!",errorPrefix:"Errore:",back:"Indietro",testing:"Test...",testConnection:"Test connessione",forward:"Avanti",searchingDevices:"Ricerca dispositivi in corso...",foundDevices:"Trovati {{count}} dispositivi. Seleziona quelli da importare.",noDevicesFound:"Nessun dispositivo trovato.",skip:"Salta",importSelected:"Importa selezionati",newIntegration:"Nuova Integrazione",configureIntegration:"Configura Integrazione",importDevices:"Importa Dispositivi",addDevice:"Aggiungi dispositivo",name:"Nome",namePlaceholder:"es. Camera Ingresso",snapshotUrlOptional:"Snapshot URL (opzionale)",streamUrls:"Stream URLs",addStream:"Aggiungi stream",cancel:"Annulla",saving:"Salvataggio...",save:"Salva",saveAndNew:"Salva e nuova",test:"Test",stream:"Stream {{number}}:",devices:"dispositivi",rediscover:"Riscopri",config:"Config",integrationNotFound:"Integrazione non trovata.",configComingSoon:"Config coming soon.",providerConfig:"Provider Config"},SZ={nav:mZ,system:hZ,common:gZ,connection:bZ,status:xZ,auth:yZ,theme:vZ,language:wZ,pages:NZ,integrations:kZ},rN="camstack_language",CZ=localStorage.getItem(rN)??"en";it.use(N9).init({resources:{en:{translation:fZ},it:{translation:SZ}},lng:CZ,fallbackLng:"en",interpolation:{escapeValue:!1}});it.on("languageChanged",e=>{localStorage.setItem(rN,e)});window.__camstackUiLibrary=qT;window.__camstackSdk=x2;window.__camstackTypes=y2;Zm(document.getElementById("root")).render(r(n2,{children:r(nZ,{})}));