@camstack/addon-admin-ui 0.1.15 → 0.1.16

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 (51) hide show
  1. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs-CKfGBI-Z.js → __mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs-CeLhKMin.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-CykPKLuU.js → __mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs_commonjs-proxy-DXPQtD9p.js} +1 -1
  3. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs-xMlwAAY4.js → __mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs-OcRSBqRe.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-Clpxla3F.js → __mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs_commonjs-proxy-GvBGLFI2.js} +1 -1
  5. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs-B_akQFxJ.js → __mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs-Dl4u0xYE.js} +1 -1
  6. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs_commonjs-proxy-BZBxNMgx.js → __mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs_commonjs-proxy-CSyOECfO.js} +1 -1
  7. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs-CCRqQaXq.js → __mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs-CzO_Esxm.js} +1 -1
  8. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-B5D3mvYP.js → __mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-xw6c6JeS.js} +1 -1
  9. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs-CRHuTm5p.js → __mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs-DNpf5SLz.js} +1 -1
  10. package/dist/assets/{__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs_commonjs-proxy-XIS4Ck9-.js → __mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs_commonjs-proxy-BEKtiDI3.js} +1 -1
  11. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D4TBsvIB.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DlquBRmD.js} +1 -1
  12. package/dist/assets/auth-records-BEfan3dC.js +1 -0
  13. package/dist/assets/capability-router-map-B3jHfbHt.js +1 -0
  14. package/dist/assets/devices-CVfa8e_5.js +1 -0
  15. package/dist/assets/{hostInit-DpSCsYyA.js → hostInit-Bq0J4U4L.js} +1 -1
  16. package/dist/assets/index-B3BmQjhl.js +1 -0
  17. package/dist/assets/index-BYRl5bfb.js +1 -0
  18. package/dist/assets/index-Bftw8yZ0.js +80 -0
  19. package/dist/assets/index-BqEwAQt-.js +1098 -0
  20. package/dist/assets/index-ByDDdVKJ.css +1 -0
  21. package/dist/assets/index-C5--Sp9A.js +80 -0
  22. package/dist/assets/index-CJH_U_aT.js +1 -0
  23. package/dist/assets/index-CLnkxPD7.js +1 -0
  24. package/dist/assets/index-gZlh9vZc.js +1 -0
  25. package/dist/assets/index-o6URf7uT.js +1 -0
  26. package/dist/assets/index-otlbS_ZJ.js +1 -0
  27. package/dist/assets/{remoteEntry-0zDoMSWf.js → remoteEntry-qFyESaJr.js} +1 -1
  28. package/dist/assets/{schemas-BOzikgNT.js → schemas-XgIEoUz3.js} +1 -1
  29. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BnGk9xo_.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-cGbq1Btt.js} +2 -2
  30. package/dist/index.html +7 -8
  31. package/dist/mf-entry-bootstrap-0.js +2 -2
  32. package/dist/server/addon.js +11 -25
  33. package/dist/server/addon.js.map +1 -1
  34. package/dist/sw.js +1 -1
  35. package/package.json +4 -3
  36. package/dist/assets/capability-router-map-Bqwnkkax.js +0 -1
  37. package/dist/assets/devices-CFL4MLSo.js +0 -511
  38. package/dist/assets/index-BP0PcGIN.js +0 -1
  39. package/dist/assets/index-BQVATbZy.js +0 -5
  40. package/dist/assets/index-BZhZ3Jvf.js +0 -1
  41. package/dist/assets/index-BfdtdylV.js +0 -533
  42. package/dist/assets/index-BkJ1uzOh.js +0 -8420
  43. package/dist/assets/index-BuajxCgS.js +0 -1
  44. package/dist/assets/index-CKMQgnc3.js +0 -1
  45. package/dist/assets/index-DAq7g5_U.js +0 -1
  46. package/dist/assets/index-DRebE_bu.js +0 -22
  47. package/dist/assets/index-DUjRaULz.js +0 -1
  48. package/dist/assets/index-OcuNiGT5.js +0 -34
  49. package/dist/assets/index-R6tzT59K.css +0 -1
  50. package/dist/assets/index-pmj5N6Ix.js +0 -5
  51. package/dist/server/addon.d.ts +0 -12
@@ -1,533 +0,0 @@
1
- import"./virtualExposes-_ivNhQLP.js";import{d as Un}from"./virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BnGk9xo_.js";import{c as r,a as Ef,d as f,e as ye,g as Dy}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_1_jsx_mf_2_runtime__loadShare__.mjs-C_6K4VBY.js";import{b as $e,e as L,h as q,c as X,f as Q,d as ge,a as Pf,j as Oe,i as ee,k as Qn,l as vs,g as ws,R as Wi,m as Se,n as Ki,o as _y,p as Ty,q as Gn,r as Te,s as Ry,t as Ly,u as Oy,v as By}from"./__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs-B_akQFxJ.js";import{t as zy,c as Fy,a as In,u as Hy,g as jy,b as Vy,d as qy,e as Uy,f as aa}from"./index-DRebE_bu.js";import{a as Af,b as Kr}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs-CCRqQaXq.js";import{a as $f,b as Df}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs-CRHuTm5p.js";import{_ as _f,m as En,n as ke,o as Tf,p as Rf,h as Yi,j as Qy}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs-CKfGBI-Z.js";import{_ as Lf,c as Of,s as Bf,n as Gy,B as Wy,F as Ky}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_client__loadShare__.mjs-DIkg6-MH.js";import{_ as zf,a as Yy}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs-xMlwAAY4.js";import{C as Zy,H as Ff,R as Xy,S as Jy,a as ev,b as Hf,c as Ns,d as tv,e as nv,f as Pn,g as Ut,X as Ve,M as Vc,h as qc,G as rv,i as ov,T as sv,j as av,k as Yr,l as nn,m as _r,n as iv,o as lv,A as jf,p as Vf,q as cv,E as dv,r as qf,D as Uf,s as Qf,t as Zi,u as Gf,v as uv,w as Wf,x as Kf,L as Yf,B as Ss,W as Xi,y as fv,z as pv,F as hv,N as Za,I as Ji,J as Zf,K as Xf,O as Jt,P as mv,Q as Jf,U as gv,V as ep,Y as bv,Z as xv,_ as yv,$ as vv,a0 as ks,a1 as wv,a2 as Nv,a3 as Sv,a4 as kv,a5 as Cv,a6 as Mv,a7 as Iv,a8 as zt,a9 as Ev,aa as tp,ab as el,ac as Pv,ad as Mt,ae as Av,af as np,ag as rp,ah as Xa,ai as op,aj as tl,ak as $v,al as Dv,am as Zr,an as nl,ao as _v,ap as Tv,aq as sp,ar as ap,as as Uc,at as Ja,au as Qc,av as Gc,aw as Rv,ax as Lv,ay as Ov,az as Bv,aA as zv,aB as Fv,aC as Hv,aD as jv,aE as Vv}from"./devices-CFL4MLSo.js";import{c as qv,S as ei,D as mn,a as Ye,M as Uv,W as ti}from"./index-BP0PcGIN.js";import{E as xe,A as Qv}from"./capability-router-map-Bqwnkkax.js";import{s as Gv}from"./index-CKMQgnc3.js";import{a as Wc,s as Wv}from"./index-BZhZ3Jvf.js";import{r as ip}from"./__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs_commonjs-proxy-BZBxNMgx.js";import"./preload-helper-BlTxHScW.js";import"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-B5D3mvYP.js";import"./schemas-BOzikgNT.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 lp={frigate:"#3b82f6",scrypted:"#a855f7",reolink:"#06b6d4",homeAssistant:"#22d3ee",rtsp:"#78716c"},cp={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:lp},dp={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:lp},ni={colors:{dark:cp,light:dp},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 up(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]=up(a,s):s!==void 0&&(n[o]=s)}return n}function Kv(e){return e?up(structuredClone(ni),e):structuredClone(ni)}function fp(e){return e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function Yv(e){return`--color-${fp(e)}`}function Kc(e){const t=[];for(const[n,o]of Object.entries(e))n!=="provider"&&t.push(` ${Yv(n)}: ${o};`);return t.join(`
2
- `)}function Zv(e){const t=[];for(const[n,o]of Object.entries(e))t.push(` --color-provider-${fp(n)}: ${o};`);return t.join(`
3
- `)}function Xv(e){const t=[];for(const[n,o]of Object.entries(e))t.push(` --spacing-${n}: ${o}px;`);return t.join(`
4
- `)}function Jv(e){const t=[];for(const[n,o]of Object.entries(e))t.push(` --radius-${n}: ${o}px;`);return t.join(`
5
- `)}function e1(e){const t=Kc(e.colors.dark),n=Kc(e.colors.light),o=Zv(e.colors.dark.provider),s=Xv(e.spacing),a=Jv(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 pp=$e(null),ia=["dark","light","system"];function hp(){return typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function t1(e,t){if(typeof window>"u")return t;const n=localStorage.getItem(e);return n==="dark"||n==="light"||n==="system"?n:t}function Yc(e){return e==="system"?hp():e}function Go({children:e,defaultMode:t="system",storageKey:n="camstack-theme-mode"}){const[o,s]=L(()=>t1(n,t)),[a,i]=L(()=>Yc(o)),l=q(p=>{s(p),i(Yc(p)),typeof window<"u"&&localStorage.setItem(n,p)},[n]),c=q(()=>{const u=(ia.indexOf(o)+1)%ia.length;l(ia[u]??"dark")},[o,l]);X(()=>{if(typeof document>"u")return;const p=document.documentElement;p.classList.remove("dark","light"),p.classList.add(a)},[o,a]),X(()=>{if(typeof window>"u"||o!=="system")return;const p=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{i(hp())};return p.addEventListener("change",u),()=>p.removeEventListener("change",u)},[o]);const d=Q(()=>({mode:o,resolvedMode:a,setMode:l,toggleMode:c}),[o,a,l,c]);return r(pp.Provider,{value:d,children:e})}function Xr(){const e=ge(pp);if(!e)throw new Error("useThemeMode must be used within a ThemeProvider");return e}function U(...e){return zy(Fy(e))}const n1="rounded-lg border border-border bg-surface overflow-hidden",r1="border-b border-border px-3 sm:px-4 py-1.5 sm:py-2",o1="p-2 sm:p-3 lg:p-4",mp="space-y-3 sm:space-y-4",gp="gap-2 sm:gap-3",bp="px-3 sm:px-4 py-1.5 sm:py-2",s1="grid grid-cols-2 sm:grid-cols-2 lg:grid-cols-4",a1="grid grid-cols-1 lg:grid-cols-2",i1="flex flex-col-reverse md:flex-row",l1="w-full md:w-44 lg:w-52 md:flex-shrink-0 border-b md:border-b-0 md:border-l border-border",c1="text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider",d1="text-[11px] sm:text-xs text-foreground",Wo="text-[10px] text-foreground-subtle",u1="text-[11px] sm:text-xs font-medium text-foreground",ri="text-base sm:text-lg font-semibold leading-tight text-foreground",f1="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",p1="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",h1="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",m1="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",g1="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",b1="inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors",x1="border-primary/50 bg-primary/15 text-primary",y1="border-border bg-surface text-foreground-subtle hover:bg-surface-hover";function v1(e,t){for(const n of e.slots)for(const o of n.addons)if(o.id===t)return o;return null}function w1(e,t){return e.models.find(n=>n.id===t)??null}function N1(e,t){return e.models.find(n=>!!n.formats[t])??null}function S1(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 xp(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=v1(o,i);if(!c){a.push({addonId:i,outcome:"skip",modelId:null,reason:"addon not in target catalog",patch:null});continue}const d=w1(c,l.modelId),p=d!==null&&!!d.formats[n.engine.format];let u,h;if(p)u=l.modelId,h="exact";else{const g=N1(c,n.engine.format);if(!g){a.push({addonId:i,outcome:"skip",modelId:null,reason:"no compatible model for target format",patch:null});continue}u=g.id,h="mapped"}const m={enabled:l.enabled,modelId:u,settings:S1(l.settings,c)};a.push({addonId:i,outcome:h,modelId:u,patch:m})}return a}const oi={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 An(e){return oi[e]??oi.watching}function Qt(e,t){if(typeof globalThis>"u")return $e(t);const n=globalThis.__camstackSharedContexts,o=n??new Map;n||(globalThis.__camstackSharedContexts=o);const s=o.get(e);if(s)return s;const a=$e(t);return o.set(e,a),a}function zn(e){const n=(typeof globalThis<"u"?globalThis:void 0)?.[e];return n&&typeof n=="object"?n:{}}const k1={singleton:!0,requiredVersion:!1,eager:!0},vt=e=>({version:"0.0.0",scope:"default",lib:e,shareConfig:k1}),Zc="__mf_module_cache__";function C1(){const e=globalThis,t=e[Zc];if(t&&typeof t=="object"){const o=t;return o.share??={},o.remote??={},o}const n={share:{},remote:{}};return e[Zc]=n,n}function M1(){const e=C1();e.share.react??=Pf,e.share["react-dom"]??=Af,e.share["react-dom/client"]??=$f,e.share["react/jsx-runtime"]??=Ef,e.share["@tanstack/react-query"]??=_f,e.share["@trpc/client"]??=Lf,e.share["@trpc/react-query"]??=zf,e.share["@camstack/ui-library"]??=zn("__camstackUiLibrary"),e.share["@camstack/sdk"]??=zn("__camstackSdk"),e.share["@camstack/types"]??=zn("__camstackTypes")}function rl(){M1(),Un.getInstance()===null&&Un.init({name:"admin_ui_host",remotes:[],shared:{react:vt(()=>Pf),"react-dom":vt(()=>Af),"react-dom/client":vt(()=>$f),"react/jsx-runtime":vt(()=>Ef),"@tanstack/react-query":vt(()=>_f),"@trpc/client":vt(()=>Lf),"@trpc/react-query":vt(()=>zf),"@camstack/ui-library":vt(()=>zn("__camstackUiLibrary")),"@camstack/sdk":vt(()=>zn("__camstackSdk")),"@camstack/types":vt(()=>zn("__camstackTypes"))}})}const I1={frigate:ev,scrypted:Jy,reolink:Xy,homeAssistant:Ff,rtsp:Zy},E1={online:nv,offline:tv,degraded:Ns,unknown:Hf},P1=In("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"}}),kr=Oe(({className:e,variant:t,size:n,...o},s)=>r("button",{ref:s,className:U(P1({variant:t,size:n}),e),...o}));kr.displayName="Button";const A1=In("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"}}),Tr=Oe(({className:e,variant:t,size:n,icon:o,...s},a)=>r("button",{ref:a,className:U(A1({variant:t,size:n}),e),...s,children:r(o,{className:"h-4 w-4"})}));Tr.displayName="IconButton";const $1=In("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"}}),Fn=Oe(({className:e,variant:t,style:n,...o},s)=>r("span",{ref:s,className:U($1({variant:t,styleVariant:n}),e),...o}));Fn.displayName="Badge";const D1=In("rounded-lg p-3",{variants:{variant:{flat:"bg-surface",bordered:"bg-surface border border-border"}},defaultVariants:{variant:"bordered"}}),ol=Oe(({className:e,variant:t,...n},o)=>r("div",{ref:o,className:U(D1({variant:t}),e),...n}));ol.displayName="Card";function yp({expanded:e,onExpandedChange:t,header:n,children:o,dimmed:s=!1,hideChevron:a=!1,className:i}){return f("div",{className:U("rounded-lg border border-border bg-surface overflow-hidden",s&&"opacity-[0.45]",i),children:[f("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(Pn,{className:"h-4 w-4"}):r(Ut,{className:"h-4 w-4"})}),n]}),e&&o&&r("div",{className:"border-t border-border px-3 py-3",children:o})]})}const sl=Oe(({className:e,...t},n)=>r("label",{ref:n,className:U("text-[10px] uppercase tracking-wider text-foreground-muted font-medium",e),...t}));sl.displayName="Label";const _1=In("",{variants:{orientation:{horizontal:"h-px w-full bg-border-subtle",vertical:"w-px h-full bg-border-subtle"}},defaultVariants:{orientation:"horizontal"}}),al=Oe(({className:e,orientation:t,...n},o)=>r("div",{ref:o,role:"separator",className:U(_1({orientation:t}),e),...n}));al.displayName="Separator";const Hn=Oe(({className:e,...t},n)=>r("div",{ref:n,className:U("animate-pulse bg-surface-hover rounded-md h-4 w-full",e),...t}));Hn.displayName="Skeleton";const Xc=In("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"}}),Ko=Oe(({className:e,state:t,leftSlot:n,rightSlot:o,...s},a)=>n||o?f("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:U(Xc({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:U(Xc({state:t}),e),...s}));Ko.displayName="Input";const Rr=Oe(({className:e,options:t,...n},o)=>f("div",{className:"relative w-full",children:[r("select",{ref:o,className:U("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(Pn,{className:"h-3.5 w-3.5"})})]}));Rr.displayName="Select";const Yo=Oe(({className:e,...t},n)=>r("input",{ref:n,type:"checkbox",className:U("w-3.5 h-3.5 rounded-sm border border-border accent-primary",e),...t}));Yo.displayName="Checkbox";const il=Oe(({className:e,checked:t,onCheckedChange:n,label:o,...s},a)=>f("button",{ref:a,role:"switch","aria-checked":t,type:"button",onClick:()=>n(!t),className:U("inline-flex items-center gap-2",e),...s,children:[r("span",{className:U("w-8 h-4 rounded-full transition-colors",t?"bg-primary":"bg-surface-hover"),children:r("span",{className:U("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})]}));il.displayName="Switch";const vp=$e(null);function wp(){const e=ge(vp);if(!e)throw new Error("Dialog compound components must be used within <Dialog>");return e}function Np({children:e,open:t,onOpenChange:n}){const[o,s]=L(!1),a=t??o,i=Qn(),l=q(c=>{n?.(c),t===void 0&&s(c)},[t,n]);return r(vp.Provider,{value:{open:a,setOpen:l,contentId:i},children:e})}function T1({children:e,...t}){const{setOpen:n}=wp();return r("button",{type:"button",onClick:()=>n(!0),...t,children:e})}const R1=In("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"}}),ll=Oe(({className:e,width:t,children:n,...o},s)=>{const{open:a,setOpen:i,contentId:l}=wp(),c=ee(null),d=s??c;X(()=>{const u=d.current;u&&(a&&!u.open&&u.showModal(),!a&&u.open&&u.close())},[a,d]);const p=u=>{u.target===u.currentTarget&&i(!1)};return r("dialog",{ref:d,id:l,className:U(R1({width:t}),"w-full",e),onClick:p,onClose:()=>i(!1),...o,children:n})});ll.displayName="DialogContent";function Sp({className:e,...t}){return r("div",{className:U("flex flex-col gap-1 mb-3",e),...t})}function kp({className:e,...t}){return r("div",{className:U("flex justify-end gap-2 mt-4",e),...t})}function Cp({className:e,...t}){return r("h2",{className:U("text-sm font-semibold text-foreground",e),...t})}function Mp({className:e,...t}){return r("p",{className:U("text-xs text-foreground-muted",e),...t})}const Ip=$e(null);function cl(){const e=ge(Ip);if(!e)throw new Error("Dropdown compound components must be used within <Dropdown>");return e}function dl({children:e}){const[t,n]=L(!1),o=Qn(),s=Qn(),a=ee(null);return r(Ip.Provider,{value:{open:t,setOpen:n,triggerId:o,contentId:s,triggerRef:a},children:r("div",{className:"relative inline-block",children:e})})}function ul({children:e,...t}){const{open:n,setOpen:o,triggerId:s,contentId:a,triggerRef:i}=cl();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 fl({className:e,children:t,align:n="start",offset:o=4,...s}){const{open:a,setOpen:i,contentId:l,triggerId:c,triggerRef:d}=cl(),p=ee(null),[u,h]=L(null);if(vs(()=>{if(!a){h(null);return}const g=()=>{const b=d.current;if(!b)return;const x=b.getBoundingClientRect(),y=n==="end"?x.right:x.left;h({top:x.bottom+o,left:y,minWidth:x.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]),X(()=>{if(!a)return;const g=x=>{const y=p.current,w=d.current;y&&!y.contains(x.target)&&!w?.contains(x.target)&&i(!1)},b=x=>{x.key==="Escape"&&i(!1)};return document.addEventListener("mousedown",g),document.addEventListener("keydown",b),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",b)}},[a,i,d]),!a||!u||typeof document>"u")return null;const m={position:"fixed",top:u.top,...n==="end"?{right:window.innerWidth-u.left}:{left:u.left},minWidth:u.minWidth};return Kr(r("div",{ref:p,id:l,role:"menu","aria-labelledby":c,style:m,className:U("z-50 bg-background-elevated border border-border rounded-md shadow-lg py-1 min-w-[160px]",e),...s,children:t}),document.body)}function pl({className:e,icon:t,variant:n="default",children:o,onClick:s,...a}){const{setOpen:i}=cl(),l=q(c=>{s?.(c),i(!1)},[s,i]);return f("button",{type:"button",role:"menuitem",className:U("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 Ep=$e(null);function Pp(){const e=ge(Ep);if(!e)throw new Error("Tooltip compound components must be used within <Tooltip>");return e}function L1({children:e}){const[t,n]=L(!1),o=ee(null),s=Qn(),a=()=>{o.current=setTimeout(()=>n(!0),300)},i=()=>{o.current&&clearTimeout(o.current),n(!1)};return r(Ep.Provider,{value:{open:t,show:a,hide:i,tooltipId:s},children:r("div",{className:"relative inline-block",children:e})})}function O1({children:e,...t}){const{show:n,hide:o,tooltipId:s,open:a}=Pp();return r("div",{onMouseEnter:n,onMouseLeave:o,onFocus:n,onBlur:o,"aria-describedby":a?s:void 0,...t,children:e})}function B1({className:e,children:t,...n}){const{open:o,tooltipId:s}=Pp();return r("div",{id:s,role:"tooltip",className:U("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 Jc="(max-width: 767px)",ed="(min-width: 768px) and (max-width: 1023px)";function Ap(e){return t=>{const n=window.matchMedia(e);return n.addEventListener("change",t),()=>n.removeEventListener("change",t)}}function $p(e){return()=>window.matchMedia(e).matches}function Dp(){return!1}function rn(){return ws(Ap(Jc),$p(Jc),Dp)}function _p(){return ws(Ap(ed),$p(ed),Dp)}function hl({open:e,onClose:t,title:n,children:o,className:s}){return X(()=>{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]),f(ye,{children:[r("div",{className:U("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"}),f("div",{role:"dialog","aria-modal":"true",className:U("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&&f("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(Ve,{className:"h-4 w-4"})})]}),r("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:o})]})]})}const Tp=$e(null);function Rp(){const e=ge(Tp);if(!e)throw new Error("Popover compound components must be used within <Popover>");return e}function Lp({children:e,open:t,onOpenChange:n}){const[o,s]=L(!1),a=t??o,i=Qn(),l=Qn(),c=q(d=>{n?.(d),t===void 0&&s(d)},[t,n]);return r(Tp.Provider,{value:{open:a,setOpen:c,triggerId:i,contentId:l},children:r("div",{className:"relative inline-block",children:e})})}function Op({children:e,...t}){const{open:n,setOpen:o,triggerId:s,contentId:a}=Rp();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 Bp({className:e,children:t,...n}){const{open:o,setOpen:s,contentId:a,triggerId:i}=Rp(),l=rn(),c=ee(null);return X(()=>{if(!o||l)return;const d=u=>{const h=c.current,m=document.getElementById(i);h&&!h.contains(u.target)&&!m?.contains(u.target)&&s(!1)},p=u=>{u.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(hl,{open:o,onClose:()=>s(!1),children:t}):r("div",{ref:c,id:a,role:"dialog","aria-labelledby":i,className:U("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 zp=$e(null);function Fp(){const e=ge(zp);if(!e)throw new Error("Tabs compound components must be used within <Tabs>");return e}function z1({value:e,onValueChange:t,defaultValue:n="",className:o,...s}){const[a,i]=L(n),l=e??a,c=q(d=>{t?.(d),e===void 0&&i(d)},[e,t]);return r(zp.Provider,{value:{value:l,setValue:c},children:r("div",{className:o,...s})})}function F1({className:e,...t}){return r("div",{role:"tablist",className:U("flex flex-row border-b border-border-subtle",e),...t})}function H1({value:e,className:t,...n}){const{value:o,setValue:s}=Fp(),a=e===o,i=`tabpanel-${e}`;return r("button",{type:"button",role:"tab","aria-selected":a,"aria-controls":i,tabIndex:a?0:-1,className:U("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 j1({value:e,className:t,...n}){const{value:o}=Fp();return e!==o?null:r("div",{role:"tabpanel",id:`tabpanel-${e}`,className:U("pt-3",t),...n})}const ml=Oe(({className:e,...t},n)=>r("div",{ref:n,className:U("overflow-auto [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-surface-hover [&::-webkit-scrollbar-thumb]:rounded-full",e),...t}));ml.displayName="ScrollArea";function V1({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]=L({x:80+l*30,y:80+l*30}),[u,h]=L({w:o,h:s}),[m,g]=L(!1),b=ee(!1),x=ee(!1),y=ee({x:0,y:0}),w=rn(),v=q(S=>{S.preventDefault(),b.current=!0,y.current={x:S.clientX-d.x,y:S.clientY-d.y}},[d]),N=q(S=>{S.preventDefault(),S.stopPropagation(),x.current=!0,y.current={x:S.clientX,y:S.clientY}},[]);return X(()=>{const S=M=>{if(b.current&&p({x:M.clientX-y.current.x,y:M.clientY-y.current.y}),x.current){const D=M.clientX-y.current.x,E=M.clientY-y.current.y;y.current={x:M.clientX,y:M.clientY},h(B=>({w:Math.max(a,B.w+D),h:Math.max(i,B.h+E)}))}},k=()=>{b.current=!1,x.current=!1};return window.addEventListener("mousemove",S),window.addEventListener("mouseup",k),()=>{window.removeEventListener("mousemove",S),window.removeEventListener("mouseup",k)}},[a,i]),w?f("div",{className:U("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:[f("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}),f("div",{className:"flex items-center gap-1 shrink-0",children:[r("button",{onClick:()=>g(!m),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",children:m?r(Vc,{size:12}):r(qc,{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(Ve,{size:12})})]})]}),!m&&r("div",{className:"flex-1 min-h-0 overflow-y-auto",children:n})]}):f("div",{className:U("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:m?280:u.w,height:m?"auto":u.h},children:[f("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:[f("div",{className:"flex items-center gap-2 min-w-0",children:[r(rv,{size:12,className:"text-foreground-subtle shrink-0"}),r("span",{className:"text-[11px] font-medium truncate",children:e})]}),f("div",{className:"flex items-center gap-1 shrink-0",children:[r("button",{onClick:()=>g(!m),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",title:m?"Restore":"Minimize",children:m?r(Vc,{size:12}):r(qc,{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(Ve,{size:12})})]})]}),!m&&f("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 gl({open:e,onClose:t,children:n,className:o,width:s="w-64"}){const a=ee(null);return X(()=>{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]),f(ye,{children:[r("div",{className:U("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:U("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 bl({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 f(Wi.Fragment,{children:[o>0&&r(Ut,{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)})})}function xl({open:e,onClose:t,title:n,subtitle:o,footer:s,children:a,widthClass:i="w-[360px]"}){return X(()=>{if(!e)return;const l=c=>{c.key==="Escape"&&t()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e,t]),e?f("aside",{className:U("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:[f("header",{className:"flex items-start justify-between gap-2 px-4 py-3 border-b border-border",children:[f("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(Ve,{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 q1={inherit:"bg-muted",on:"bg-emerald-500",off:"bg-orange-500",na:"bg-gray-300 opacity-50"};function Hp({node:e,depth:t,selectedAddonId:n,onSelect:o,agentDots:s}){const a=e.addonId===n,i=s?.[e.addonId]??[];return f("div",{children:[f("button",{type:"button",onClick:()=>o(e.addonId),className:U("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:U("w-2 h-2 rounded-full",q1[l.state])},l.agentNodeId))})]}),e.children.map(l=>r(Hp,{node:l,depth:t+1,selectedAddonId:n,onSelect:o,agentDots:s},l.addonId))]})}function jp({tree:e,selectedAddonId:t,onSelect:n,agentDots:o,className:s}){return r("div",{className:U("flex flex-col py-2",s),children:e.map(a=>r(Hp,{node:a,depth:0,selectedAddonId:t,onSelect:n,agentDots:o},a.addonId))})}function Cs(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 U1(e){return e?e.models.map(t=>({id:t.id,name:t.name})):[]}function Bo({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:u=!1}){const[h,m]=L(!1),g=U1(t);if(g.length>0&&!g.some(x=>x.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 b=f(ye,{children:[f("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}),f("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(x=>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:x},x)),e.inputClasses.length>0&&e.outputClasses.length>0&&r("span",{className:"text-foreground-subtle/40 text-[10px]",children:"→"}),e.outputClasses.map(x=>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:x},x))]})]}),!i&&l==="simple"&&r("button",{onClick:x=>{x.stopPropagation(),s({...e,enabled:!e.enabled})},className:U("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:U("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&&f("div",{className:"flex items-center gap-0.5 rounded-md border border-border p-0.5",onClick:x=>x.stopPropagation(),children:[r(la,{label:"Inherit",active:c===null,variant:"inherit",subtext:p===void 0?void 0:p?"on":"off",onClick:()=>d(null)}),r(la,{label:"On",active:c===!0,variant:"on",onClick:()=>d(!0)}),r(la,{label:"Off",active:c===!1,variant:"off",onClick:()=>d(!1)})]})]});return r(yp,{expanded:h,onExpandedChange:m,dimmed:!e.enabled,header:b,children:u?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."}):f("div",{className:"space-y-3",children:[r(si,{label:"Model",value:e.modelId,disabled:i,options:g.map(x=>({value:x.id,label:x.name})),onChange:x=>s({...e,modelId:x})}),e.slot==="audio-classifier"&&e.engine&&r(si,{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:x=>{const[y,w]=x.split("/");s({...e,engine:{runtime:y,backend:w,format:w==="coreml"?"coreml":"onnx"}})}}),t?.configSchema?.map(x=>r(Ms,{field:x,allFields:t.configSchema??[],step:e,disabled:i,onChange:s},x.key))]})})}function si({label:e,value:t,options:n,disabled:o,onChange:s}){return f("div",{children:[r("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e}),f("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 Q1({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 f("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:U("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 G1(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 Ms({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:u}=a,h=G1(l,n,t);if(c!==void 0&&h!==c||d!==void 0&&h===d||p!==void 0&&!p.includes(h)||u!==void 0&&u.includes(h))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(si,{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(Q1,{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,u=e.max??1,h=e.step??.01,m=e.type==="slider"?e.showValue:!0,g="unit"in e?e.unit:void 0,b=e.type==="slider"?e.displayScale:void 0,x=b?d/b:d;return f("div",{children:[f("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}),m&&f("span",{className:"text-xs font-medium text-foreground tabular-nums",children:[typeof x=="number"?x.toFixed(2).replace(/\.?0+$/,""):x,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:u,step:h,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 f("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 f("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 la({label:e,active:t,variant:n,subtext:o,onClick:s}){return f("button",{type:"button",onClick:s,className:U("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&&f("span",{className:"ml-1 opacity-60",children:["(",o,")"]})]})}function Vp(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 W1(e,t,n){return n?{enabled:n.enabled??t.enabled,modelId:n.modelId??t.modelId,settings:n.settings??t.settings}:t}function K1({addon:e,agentDefault:t,modelsForFormat:n,onChangeAgentConfig:o}){const s=a=>{o?.({...t,...a})};return f("div",{className:"space-y-4 text-xs",children:[f("label",{className:"flex items-center gap-2",children:[r("input",{type:"checkbox",checked:t.enabled,onChange:a=>s({enabled:a.target.checked})}),f("span",{children:["Enabled on this agent (",e.name,")"]})]}),f("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&&f("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(Ms,{field:a,allFields:e.configSchema??[],step:Vp(e,t),disabled:!1,onChange:i=>s({settings:{...i.settings}})},a.key))]})]})}function Y1({addon:e,agentDefault:t,agentNodeId:n,currentPatch:o,modelsForFormat:s,onChangePatch:a}){const i=W1("device",t,o),l=m=>{const g=m.enabled!==void 0||m.modelId!==void 0||m.settings!==void 0;a?.(g?m:null)},c=m=>{const{enabled:g,...b}=o??{},x=m==="inherit"?b:{...b,enabled:m==="on"};l(x)},d=m=>{const{modelId:g,...b}=o??{},x=m===void 0?b:{...b,modelId:m};l(x)},p=m=>{const{settings:g,...b}=o??{},x=m===void 0?b:{...b,settings:m};l(x)},u=o?.enabled===void 0?"inherit":o.enabled?"on":"off",h=o?.modelId!==void 0;return f("div",{className:"space-y-4 text-xs",children:[f("div",{className:"flex items-center gap-1",children:[["inherit","on","off"].map(m=>r("button",{type:"button",onClick:()=>c(m),className:U("px-3 py-1 border border-border rounded text-xs capitalize",u===m?"bg-primary text-primary-foreground border-primary":"bg-surface text-foreground hover:bg-muted"),children:m},m)),f("span",{className:"ml-2 text-[10px] text-foreground-subtle",children:["agent default: ",r("span",{className:"font-semibold",children:t.enabled?"on":"off"})]})]}),f("div",{children:[f("div",{className:"flex items-center justify-between mb-1",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Model"}),h?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:!h,className:"w-full bg-surface border border-border rounded px-2 py-1 text-xs disabled:opacity-50",value:h?o?.modelId??t.modelId:t.modelId,onChange:m=>d(m.target.value),children:s.map(m=>r("option",{value:m.id,children:m.name},m.id))}),!h&&f("div",{className:"text-[10px] text-foreground-subtle mt-1",children:["inherits from ",n]})]}),(e.configSchema?.length??0)>0&&(()=>{const m=o?.settings!==void 0;return f("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[f("div",{className:"flex items-center justify-between",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),m?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(Ms,{field:g,allFields:e.configSchema??[],step:Vp(e,i),disabled:!m,onChange:b=>p({...b.settings})},g.key)),!m&&f("div",{className:"text-[10px] text-foreground-subtle",children:["inherits from ",n]})]})})(),f("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"}),f("div",{className:"font-mono truncate",children:[e.id," · model: ",i.modelId," · ",i.enabled?"on":"off"]})]})]})}function Is(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(K1,{addon:n,agentDefault:o,modelsForFormat:d,onChangeAgentConfig:i}):r(Y1,{addon:n,agentDefault:o,agentNodeId:s,currentPatch:a,modelsForFormat:d,onChangePatch:l})}function Z1(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 td={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 X1({slot:e}){const t=td[e]??td.classifier;return r("span",{className:U("text-[9px] font-semibold uppercase tracking-widest leading-none",t.className),children:t.label})}const nd="inline-flex items-center rounded bg-muted px-1.5 py-px text-[9px] font-medium text-foreground-subtle";function J1({inputs:e,outputs:t}){return e.length===0&&t.length===0?null:f("span",{className:"inline-flex items-center gap-1 flex-wrap",children:[e.map(n=>r("span",{className:U(nd,"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:U(nd,"bg-emerald-500/10 text-emerald-500"),children:n},`out-${n}`))]})}function ew({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:U("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:U("inline-block h-3 w-3 rounded-full bg-white shadow transition-transform",e?"translate-x-3.5":"translate-x-0.5")})})}function tw(e){return e.kind==="enabled"?f("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"?f("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"]}):f("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 nw({node:e,depth:t,agents:n,getCellState:o,onCellClick:s,selectedCell:a,toggleProps:i}){return f(ye,{children:[f("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:[f("div",{className:"flex flex-col gap-1 min-w-0 flex-1",children:[r(X1,{slot:e.slot}),f("div",{className:"flex items-center gap-2 flex-wrap",children:[r("span",{className:"font-semibold truncate",children:e.addonName}),r(J1,{inputs:e.inputClasses,outputs:e.outputClasses})]})]}),i&&r("span",{className:"pl-2 pt-0.5 shrink-0",children:r(ew,{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:U("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:tw(c)},l.agentNodeId)})]})}function yl({tree:e,agents:t,getCellState:n,onCellClick:o,selectedCell:s,onToggleEnabled:a}){const i=Q(()=>Z1(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:f("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=>f("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:u})=>{const h=c&&d!==void 0?n(p.addonId,d):null,m=c&&h!==null?{enabled:h.kind==="enabled",onChange:g=>a?.(p.addonId,g),disabled:h.kind==="na"}:void 0;return r(nw,{node:p,depth:u,agents:t,getCellState:n,onCellClick:o,selectedCell:s,toggleProps:m},p.addonId)})]})})}const qp=typeof globalThis<"u"?globalThis.__camstackTrpcReact:void 0,C=qp??Yy();typeof globalThis<"u"&&!qp&&(globalThis.__camstackTrpcReact=C);const vl=Qt("camstack:system",null);function wl({system:e,children:t}){return r(vl.Provider,{value:e,children:t})}function Ae(){const e=ge(vl);if(!e)throw new Error("useSystem(): no <SystemProvider> in tree");return e}function rw(){return ge(vl)}function et(e,t){const n=Ae(),o=ee(t);o.current=t;const[s,a]=L(n.connectionVersion);X(()=>n.subscribeConnectionEvents((i,l)=>{i==="connected"&&a(l)}),[n]),X(()=>n.subscribeEvent(e,l=>{o.current(l)}),[n,e,s])}function ai(e){const t=ee(e);return t.current=e,t}function or(e,t){const[n,o]=L(null),s=ai(t);return et(e,a=>{const i=a.data,l=s.current;l&&!l(i)||o(i)}),n}function Up(e,t,n){const[o,s]=L(()=>new Map),a=ai(t),i=ai(n);et(e,c=>{const d=c.data,p=i.current;if(p&&!p(d))return;const u=a.current(d);s(h=>{const m=new Map(h);return m.set(u,d),m})});const l=Q(()=>Array.from(o.values()),[o]);return{map:o,values:l}}function sr(){const{data:e,isLoading:t}=C.nodes.topology.useQuery(void 0,{staleTime:6e4}),o=or("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 Qp({selectedNodeId:e,onSelect:t,label:n="Node",hideIcon:o=!1,alwaysShow:s=!1}){const{nodes:a}=sr();return!s&&a.length<=1?null:f("div",{className:"flex items-center gap-1.5",children:[!o&&r(ov,{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:U("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 ow={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 sw({status:e,showDot:t=!0,showLabel:n=!0,size:o="sm",className:s}){const a=ow[e];return f("span",{className:U("inline-flex items-center gap-1.5",o==="sm"?"text-xs":"text-sm",s),children:[t&&r("span",{className:U("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 aw={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 iw({provider:e,showLabel:t=!0,className:n}){const o=aw[e];return f("span",{className:U("inline-flex items-center gap-1.5 text-xs",n),children:[r("span",{className:U("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 lw={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 Gp({children:e,variant:t="neutral",mono:n,className:o}){return r("span",{className:U("inline-flex items-center rounded-md px-2 py-0.5 text-[11px] font-bold leading-tight",n&&"font-mono",lw[t],o),children:e})}function cw({version:e,preRelease:t,className:n}){const o=t??/-(alpha|beta|rc|dev|canary|next)/i.test(e);return r(Gp,{variant:o?"warning":"success",mono:!0,className:n,children:e})}function dw({label:e,description:t,error:n,required:o,children:s,orientation:a="vertical",className:i}){const l=a==="horizontal";return f("div",{className:U("flex gap-2",l?"flex-row items-center justify-between":"flex-col",i),children:[f("div",{className:U(l?"flex-1":""),children:[f(sl,{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:U(l?"shrink-0":""),children:s}),n&&r("p",{className:"text-danger text-xs",children:n})]})}function uw({title:e,subtitle:t,actions:n,className:o}){return f("div",{className:U("flex flex-col gap-2 mb-3 sm:flex-row sm:items-center sm:justify-between",o),children:[f("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 fw({icon:e,title:t,description:n,action:o,className:s}){return f("div",{className:U("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"}),f("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 Wp=Qt("camstack:confirm-dialog",null);function on(){const e=ge(Wp);if(!e)throw new Error("useConfirm must be used within ConfirmDialogProvider");return e.confirm}function Kp({children:e}){const[t,n]=L(null),o=q(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 f(Wp.Provider,{value:{confirm:o},children:[e,t&&f("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}),f("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:[f("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})]}),f("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 pw({value:e,label:t,trend:n,className:o}){return f(ol,{className:U("flex flex-col gap-1",o),children:[f("div",{className:"flex items-baseline gap-2",children:[r("span",{className:"text-2xl font-semibold text-foreground",children:e}),n&&f("span",{className:U("inline-flex items-center gap-0.5 text-xs font-medium",n.direction==="up"?"text-success":"text-danger"),children:[n.direction==="up"?r(sv,{className:"h-3 w-3"}):r(av,{className:"h-3 w-3"}),n.value,"%"]})]}),r("span",{className:"text-xs text-foreground-muted",children:t})]})}function hw({items:e,className:t}){return r("dl",{className:U("flex flex-col",t),children:e.map(n=>f("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 mw({children:e,maxHeight:t=300,className:n}){const[o,s]=L(!1),a=q(()=>{navigator.clipboard.writeText(e).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)})},[e]);return f("div",{className:U("relative group",n),children:[r(ml,{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(Tr,{icon:o?Yr:nn,"aria-label":"Copy code",variant:"ghost",size:"sm",onClick:a})})]})}function gw({filters:e,values:t,onChange:n,className:o}){const s=rn(),[a,i]=L(!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(u=>u.type==="search"),p=e.some(u=>u.type!=="search");return f("div",{className:U("flex items-center gap-2",o),children:[d&&r(Ko,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:u=>l(d.key,u.target.value),leftSlot:r(_r,{className:"h-3 w-3 text-foreground-subtle"}),className:"flex-1"}),p&&f(ye,{children:[f("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(iv,{className:"h-3.5 w-3.5"}),"Filters",c>0&&r(Fn,{variant:"info",className:"ml-1 text-[10px] px-1 py-0",children:c})]}),r(hl,{open:a,onClose:()=>i(!1),title:"Filters",children:r("div",{className:"flex flex-col gap-3",children:e.filter(u=>u.type!=="search").map(u=>{switch(u.type){case"select":return f("div",{children:[r("label",{className:"text-xs text-foreground-muted mb-1 block",children:u.label}),r(Rr,{options:u.options,value:t[u.key]??"",onChange:h=>l(u.key,h.target.value),className:"w-full"})]},u.key);case"badge-toggle":return r("div",{className:"flex items-center gap-1 flex-wrap",children:u.options.map(h=>{const g=t[u.key]===h.value;return r("button",{type:"button",onClick:()=>l(u.key,g?void 0:h.value),children:r(Fn,{variant:g?"info":"default",className:"cursor-pointer",children:h.label})},h.value)})},u.key);default:return null}})})})]})]})}return r("div",{className:U("flex items-center gap-2 flex-wrap",o),children:e.map(d=>{switch(d.type){case"search":return r(Ko,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:p=>l(d.key,p.target.value),leftSlot:r(_r,{className:"h-3 w-3 text-foreground-subtle"}),className:"w-48"},d.key);case"select":return r(Rr,{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 h=t[d.key]===p.value;return r("button",{type:"button",onClick:()=>l(d.key,h?void 0:p.value),children:r(Fn,{variant:h?"info":"default",className:"cursor-pointer",children:p.label})},p.value)})},d.key);default:return null}})})}function ii({label:e,icon:t,href:n,badge:o,active:s=!1,className:a}){return f("a",{href:n,className:U("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(Fn,{className:"ml-auto text-[10px] px-1.5 py-0",children:o})]})}function li({logo:e,sections:t,footer:n,onNavigate:o,className:s}){return f("nav",{className:U("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)=>f("div",{className:U(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(ii,{...l},l.href))})]},i))}),n&&n.length>0&&f("div",{className:"shrink-0 px-1 pb-1",children:[r(al,{className:"mb-1"}),r("div",{className:"flex flex-col gap-0.5",onClick:o,children:n.map(a=>r(ii,{...a},a.href))})]})]})}function bw({sidebar:e,header:t,mobileLogo:n,mobileActions:o,children:s,className:a}){const i=rn(),[l,c]=L(!1);return f("div",{className:U("flex h-screen",a),children:[!i&&r(li,{...e,className:U("w-44",e.className)}),i&&r(gl,{open:l,onClose:()=>c(!1),width:"w-64",children:r(li,{...e,onNavigate:()=>c(!1),className:"w-full border-r-0"})}),f("div",{className:"flex flex-1 flex-col min-w-0",children:[i&&f("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(lv,{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&&f("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 u=p===t.breadcrumbs.length-1;return f("span",{className:"flex items-center gap-1",children:[p>0&&r(Ut,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),d.href&&!u?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})]})]})}function xw({headerGroups:e,onSortingChange:t,stickyHeader:n,flexRender:o}){return r("thead",{className:U(n&&"sticky top-0 z-10 bg-background"),children:e.map(s=>r("tr",{className:"h-6",children:s.headers.map(a=>r(yw,{header:a,sortable:a.column.getCanSort()&&!!t,flexRender:o},a.id))},s.id))})}function yw({header:e,sortable:t,flexRender:n}){const o=e.column.getIsSorted(),s=o==="asc"?jf:o==="desc"?Vf:cv;return r("th",{className:U("px-2 py-1 text-left text-[10px] text-foreground-subtle uppercase tracking-wider font-medium",t&&"cursor-pointer select-none"),onClick:t?e.column.getToggleSortingHandler():void 0,children:f("span",{className:"inline-flex items-center gap-1",children:[e.isPlaceholder?null:n(e.column.columnDef.header,e.getContext()),t&&r(s,{className:"h-3 w-3"})]})})}function vw({row:e,onRowClick:t,rowActions:n,flexRender:o}){const s=n?n(e.original):[];return f("tr",{className:U("h-7 border-b border-border/50",t&&"cursor-pointer","hover:bg-surface-hover"),onClick:t?()=>t(e.original):void 0,children:[e.getVisibleCells().map(a=>r(ww,{cell:a,flexRender:o},a.id)),s.length>0&&r("td",{className:"px-2 py-1.5 w-8",children:f(dl,{children:[r(ul,{className:"p-0.5 rounded hover:bg-surface-hover",onClick:a=>a.stopPropagation(),children:r(dv,{className:"h-3.5 w-3.5 text-foreground-muted"})}),r(fl,{className:"right-0 left-auto",children:s.map(a=>r(pl,{icon:a.icon,variant:a.variant,onClick:i=>{i.stopPropagation(),a.onClick()},children:a.label},a.label))})]})})]})}function ww({cell:e,flexRender:t}){return r("td",{className:"px-2 py-1.5 text-xs text-foreground",children:t(e.column.columnDef.cell,e.getContext())})}const Nw=[{value:"10",label:"10"},{value:"25",label:"25"},{value:"50",label:"50"},{value:"100",label:"100"}];function rd({page:e,pageSize:t,total:n,onPaginationChange:o}){const s=Math.max(1,Math.ceil(n/t)),a=e+1;return f("div",{className:"flex items-center justify-between px-2 py-2 text-xs text-foreground-muted",children:[f("div",{className:"flex items-center gap-2",children:[r("span",{children:"Rows per page"}),r("div",{className:"w-16",children:r(Rr,{options:Nw,value:String(t),onChange:i=>o?.({pageIndex:0,pageSize:Number(i.target.value)})})})]}),f("div",{className:"flex items-center gap-2",children:[f("span",{children:["Page ",a," of ",s]}),r(Tr,{icon:qf,"aria-label":"Previous page",variant:"ghost",size:"sm",disabled:e<=0,onClick:()=>o?.({pageIndex:e-1,pageSize:t})}),r(Tr,{icon:Ut,"aria-label":"Next page",variant:"ghost",size:"sm",disabled:a>=s,onClick:()=>o?.({pageIndex:e+1,pageSize:t})})]})]})}function Sw({data:e,columns:t,sorting:n,onSortingChange:o,filtering:s,onFilteringChange:a,pagination:i,onPaginationChange:l,loading:c=!1,emptyState:d,rowActions:p,onRowClick:u,selectable:h=!1,compact:m=!0,stickyHeader:g=!1,className:b,mobileMode:x="scroll"}){const y=Q(()=>h?[{id:"__select",header:({table:M})=>r(Yo,{checked:M.getIsAllPageRowsSelected(),onChange:M.getToggleAllPageRowsSelectedHandler(),"aria-label":"Select all"}),cell:({row:M})=>r(Yo,{checked:M.getIsSelected(),onChange:M.getToggleSelectedHandler(),"aria-label":"Select row"}),enableSorting:!1},...t]:t,[t,h]),w=Hy({data:e,columns:y,state:{...n!==void 0&&{sorting:n},...s!==void 0&&{columnFilters:s},...i!==void 0&&{pagination:{pageIndex:i.page,pageSize:i.pageSize}}},onSortingChange:o?k=>{const M=typeof k=="function"?k(n??[]):k;o(M)}:void 0,onColumnFiltersChange:a?k=>{const M=typeof k=="function"?k(s??[]):k;a(M)}:void 0,getCoreRowModel:Uy(),getSortedRowModel:qy(),getFilteredRowModel:Vy(),getPaginationRowModel:i?jy():void 0,manualPagination:i!==void 0,pageCount:i?Math.ceil(i.total/i.pageSize):void 0}),v=!!p;if(rn()&&x==="cards"){const k=w.getRowModel().rows;return c?r("div",{className:U("space-y-2",b),children:Array.from({length:3}).map((M,D)=>f("div",{className:"rounded-lg border border-border bg-surface p-3 space-y-2",children:[r(Hn,{className:"h-3 w-3/4"}),r(Hn,{className:"h-3 w-1/2"}),r(Hn,{className:"h-3 w-2/3"})]},D))}):k.length===0?r("div",{className:U("text-center py-8 text-xs text-foreground-muted",b),children:d??"No data"}):f("div",{className:U("space-y-2",b),children:[k.map(M=>f("div",{className:U("rounded-lg border border-border bg-surface p-3 space-y-1.5",u&&"cursor-pointer hover:bg-surface-hover transition-colors"),onClick:u?()=>u(M.original):void 0,children:[M.getVisibleCells().filter(D=>D.column.id!=="__select").map(D=>{const E=D.column.columnDef.header,B=typeof E=="string"?E:D.column.id;return f("div",{className:"flex items-baseline justify-between gap-2 text-xs",children:[r("span",{className:"text-foreground-muted shrink-0",children:B}),r("span",{className:"text-foreground text-right truncate",children:aa(D.column.columnDef.cell,D.getContext())})]},D.id)}),p&&r("div",{className:"flex items-center gap-1 pt-1 border-t border-border mt-1.5",children:p(M.original).map((D,E)=>r("button",{onClick:B=>{B.stopPropagation(),D.onClick()},className:U("text-[11px] px-2 py-1 rounded-md transition-colors",D.variant==="danger"?"text-danger hover:bg-danger/10":"text-foreground-muted hover:bg-surface-hover"),children:D.label},E))})]},M.id)),i&&r(rd,{page:i.page,pageSize:i.pageSize,total:i.total,onPaginationChange:l})]})}return f("div",{className:U("overflow-x-auto",b),children:[f("table",{className:"w-full border-collapse",children:[r(xw,{headerGroups:w.getHeaderGroups(),onSortingChange:o,stickyHeader:g,flexRender:aa}),r("tbody",{children:c?r(kw,{colSpan:y.length+(v?1:0),compact:m}):w.getRowModel().rows.length===0?r("tr",{children:r("td",{colSpan:y.length+(v?1:0),className:"text-center py-8 text-xs text-foreground-muted",children:d??"No data"})}):w.getRowModel().rows.map(k=>r(vw,{row:k,onRowClick:u,rowActions:p,flexRender:aa},k.id))})]}),i&&r(rd,{page:i.page,pageSize:i.pageSize,total:i.total,onPaginationChange:l})]})}function kw({colSpan:e,compact:t}){return r(ye,{children:Array.from({length:5}).map((n,o)=>r("tr",{className:t?"h-7":"h-9",children:Array.from({length:e}).map((s,a)=>r("td",{className:"px-2 py-1.5",children:r(Hn,{className:"h-3 w-full"})},a))},o))})}const Cw={online:"bg-success",offline:"bg-danger",warning:"bg-warning",unknown:"bg-foreground-subtle"};function Mw({title:e,subtitle:t,status:n,selected:o,onClick:s,badges:a,actions:i,offlineAction:l,className:c}){const d=n==="offline";return f("div",{onClick:s,className:U("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:[f("div",{className:"flex items-center justify-between mb-2",children:[r("span",{className:"text-sm font-medium truncate",children:e}),n&&r("span",{className:U("h-2 w-2 rounded-full shrink-0",Cw[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,u)=>{const h=U("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?f("button",{onClick:m=>{m.stopPropagation(),p.onClick()},className:h,children:[p.icon,p.label]},u):f("span",{className:h,children:[p.icon,p.label]},u)})}),!d&&i&&i.length>0&&r("div",{className:"flex items-center gap-0.5 mt-2 -mb-1",children:i.map((p,u)=>r("button",{onClick:h=>{h.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},u))}),d&&l&&r("div",{className:"mt-2",onClick:p=>p.stopPropagation(),children:l})]})}function Iw({children:e,minCardWidth:t=220,gap:n=3,className:o}){return r("div",{className:U("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 Ew="capability.binding-changed";function lt(e,t){const[n,o]=L(null);return X(()=>{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:Ew},{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?qv(e,n):null,[e,n])}function Ft(e){const t=q(o=>e?e.subscribe(()=>o()):()=>{},[e]),n=q(()=>e?.value,[e]);return ws(t,n,n)}function Yp(e,t,n){const o=lt(e,t),s=o?n(o.state):void 0;return Ft(s)}function ar(e){const t=lt(e.trpc,e.deviceId),n=t!==null?e.slice(t):void 0,o=Ft(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 Pw(e){return e.parentDeviceId===null?"top-level":e.role?"accessory":"adopted"}const Aw={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 $w(e){const t=Aw[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 Dw={siren:Ss,floodlight:Yf,spotlight:Kf,"pir-sensor":Wf,chime:uv,autotrack:Gf,nightvision:Zi,"privacy-mask":Qf,doorbell:Uf},_w={camera:Ji,hub:Za,nvr:Za,light:Yf,siren:Ss,switch:hv,sensor:Wf,thermostat:pv,button:fv,generic:Xi};function Zp(e){return e.role?Dw[e.role]??Xi:_w[e.type.toLowerCase()]??Ji}const Xp={"native-snapshot":gv,"two-way-audio":Jf,"pan-tilt-zoom":Gf,"ptz-autotrack":mv,"doorbell-button":Uf,"motion-trigger":Jt,"battery-operated":Xf,rebootable:Zf},Jp={"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"},Tw={"native-snapshot":"snapshot",rebootable:"reboot","pan-tilt-zoom":"ptz","ptz-autotrack":"ptz-autotrack","two-way-audio":"intercom","motion-trigger":"motion-trigger"},eh=new Set(["camera","hub","nvr"]);function th(e){return!eh.has(e.type.toLowerCase())}function od(e){return e.role?!0:!eh.has(e.type.toLowerCase())}function nh(e){return(e.features??[]).includes("motion-trigger")}function Rw(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 Lw({trpc:e,accessoryChildren:t,adoptedChildren:n,onNavigate:o}){return f("div",{className:"border-t border-border-subtle/50",children:[n.length>0&&r(sd,{trpc:e,label:"Adopted devices",rows:n,onNavigate:o}),t.length>0&&r(sd,{trpc:e,label:"Accessories",rows:t,onNavigate:o})]})}function sd({trpc:e,label:t,rows:n,onNavigate:o}){return f("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(Ow,{trpc:e,child:s,onNavigate:o},s.id))})]})}function Ow({trpc:e,child:t,onNavigate:n}){const o=!t.disabled,s=o&&th(t),a=o&&nh(t),i=Zp(t);return r("li",{children:f("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(zw,{trpc:e,deviceId:t.id,features:t.features}),s&&r(Bw,{trpc:e,deviceId:t.id}),r("span",{className:U("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 Bw({trpc:e,deviceId:t}){const{dev:n,cap:o,slice:s,available:a}=ar({trpc:e,deviceId:t,cap:u=>u.switch,slice:u=>u.state.switch}),[i,l]=L(!1);if(n!==null&&!o)return null;const c=s?.on===!0,d={transform:c?"translateX(14px)":"translateX(2px)"},p=async u=>{if(u.stopPropagation(),!(i||!a||!o)){l(!0);try{await o.setState({on:!c})}finally{l(!1)}}};return r("button",{type:"button",onClick:u=>{p(u)},disabled:i||!a,className:U("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:U("absolute h-3 w-3 rounded-full transition-all",c?"bg-success":"bg-foreground-subtle"),style:d})})}function zw({trpc:e,deviceId:t,features:n}){const{dev:o,cap:s,slice:a,available:i}=ar({trpc:e,deviceId:t,cap:u=>u.motionTrigger,slice:u=>u.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:n}),[l,c]=L(!1);if(o!==null&&!s)return null;const d=a?.enabled===!0,p=async u=>{if(u.stopPropagation(),!(l||!i||!s)){c(!0);try{await s.setMotionTrigger({enabled:!d})}finally{c(!1)}}};return r("button",{type:"button",onClick:u=>{p(u)},disabled:l||!i,className:U("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(Jt,{className:"h-2.5 w-2.5"})})}function rh({trpc:e,device:t,flags:n}){if(!!t.disabled)return null;const s=t.type.toLowerCase(),a=n.showSwitchToggle&&th(t),i=nh(t),l=s==="hub"||s==="nvr",c=(t.features??[]).includes("rebootable"),d=l&&c;return f(ye,{children:[i&&r(Hw,{trpc:e,deviceId:t.id,features:t.features}),a&&r(Fw,{trpc:e,deviceId:t.id}),d&&r(Vw,{trpc:e,deviceId:t.id})]})}function Fw({trpc:e,deviceId:t}){const{dev:n,cap:o,slice:s,available:a}=ar({trpc:e,deviceId:t,cap:u=>u.switch,slice:u=>u.state.switch}),[i,l]=L(!1);if(n!==null&&!o)return null;const c=s?.on===!0,d={transform:c?"translateX(14px)":"translateX(2px)"},p=async u=>{if(u.stopPropagation(),!(i||!a||!o)){l(!0);try{await o.setState({on:!c})}finally{l(!1)}}};return r("button",{type:"button",onClick:u=>{p(u)},disabled:i||!a,className:U("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:U("absolute h-3 w-3 rounded-full transition-all",c?"bg-success":"bg-foreground-subtle"),style:d})})}function Hw({trpc:e,deviceId:t,features:n}){const{dev:o,cap:s,slice:a,available:i}=ar({trpc:e,deviceId:t,cap:u=>u.motionTrigger,slice:u=>u.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:n}),[l,c]=L(!1);if(o!==null&&!s)return null;const d=a?.enabled===!0,p=async u=>{if(u.stopPropagation(),!(l||!i||!s)){c(!0);try{await s.setMotionTrigger({enabled:!d})}finally{c(!1)}}};return r("button",{type:"button",onClick:u=>{p(u)},disabled:l||!i,className:U("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(Jt,{className:"h-2.5 w-2.5"})})}const ca=168,jw=4;function Vw({trpc:e,deviceId:t}){const{dev:n,cap:o}=ar({trpc:e,deviceId:t,cap:x=>x.reboot,slice:()=>{}}),s=ee(null),a=ee(null),[i,l]=L(null),[c,d]=L(!1),p=n!==null&&o!==void 0&&o!==null,u=i!==null,h=()=>l(null),m=()=>{const x=s.current;if(!x)return;const y=x.getBoundingClientRect(),w=y.right-ca,v=Math.max(8,Math.min(w,window.innerWidth-ca-8)),N=y.bottom+jw;l({top:N,left:v})};if(X(()=>{if(!u)return;const x=w=>{const v=s.current,N=a.current,S=w.target;S!==null&&(v&&v.contains(S)||N&&N.contains(S)||h())},y=w=>{w.key==="Escape"&&(w.stopPropagation(),h())};return document.addEventListener("mousedown",x),document.addEventListener("keydown",y),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",y)}},[u]),n!==null&&!o)return null;const g=x=>{x.stopPropagation(),u?h():m()},b=async()=>{if(!(c||!p||!o)){d(!0),h();try{await o.reboot({})}finally{d(!1)}}};return f(ye,{children:[r("button",{ref:s,type:"button",onClick:g,disabled:c||!p,className:U("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",u&&"bg-surface-hover text-foreground"),title:"More actions","aria-label":"More actions","aria-haspopup":"menu","aria-expanded":u,children:r(ep,{className:"h-3 w-3"})}),i&&Kr(r("div",{ref:a,role:"menu",style:{position:"fixed",top:i.top,left:i.left,width:ca},className:"z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-1",onClick:x=>x.stopPropagation(),children:f("button",{type:"button",role:"menuitem",onClick:()=>{b()},disabled:c||!p,className:U("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(Zf,{className:"h-3 w-3 shrink-0 text-foreground-subtle"}),r("span",{children:"Reboot device"})]})}),document.body)]})}const qw=Object.freeze([]);function Uw(e){return e==="native"?"native":"enhanced"}function Qw(e){return e.map(t=>({kind:"marker",feature:t}))}function Gw(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=Tw[a];if(i===void 0){s.push({kind:"marker",feature:a});continue}const l=n.get(i);l&&s.push({kind:Uw(l.kind),feature:a,capName:i})}return s}function Ww(e,t,n){const[o,s]=L(null),[a,i]=L(!1),[l,c]=L(!0);return X(()=>{if(t===null){s(null),i(!1),c(!1);return}let d=!1;c(!0),i(!1);const p=async()=>{try{const h=await e.deviceManager.getBindings.query({deviceId:t});if(d)return;s(h),c(!1)}catch{if(d)return;i(!0),c(!1)}};p();const u=e.live?.onEvent.subscribe({category:"capability.binding-changed"},{onData:h=>{const m=h.data?.source;if(!m){p();return}m.type==="device"&&m.id===t&&p()}});return()=>{d=!0,u?.unsubscribe()}},[e,t]),n.length===0?{loading:l,resolved:qw}:l||a||!o?{loading:l,resolved:Qw(n)}:{loading:!1,resolved:Gw(n,o)}}const Kw=[];function oh({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??Kw,d=a&&c.length>0,{resolved:p}=Ww(e,d?t.id:null,c),u=d&&p.length>0;return!l&&!u?null:f("div",{className:"flex items-center gap-1.5 flex-nowrap whitespace-nowrap min-w-0",children:[l&&r(Yw,{accessoryCount:o,adoptedCount:s}),u&&r(Zw,{resolved:p})]})}function Yw({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 f("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 sh=240,ad=200;function Zw({resolved:e}){const t=ee(null),[n,o]=L(null);return f("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>=ad?l.bottom+4:l.top-ad-4,u=Math.max(8,Math.min(l.left,window.innerWidth-sh-8));o({top:p,left:u})},onMouseLeave:()=>o(null),children:[e.map(i=>{const l=Xp[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:Jp[i.feature]??i.feature,children:r(l,{className:"h-2.5 w-2.5"})},i.feature):null}),n&&Kr(r(Xw,{resolved:e,position:n}),document.body)]})}function Xw({resolved:e,position:t}){return f("div",{style:{position:"fixed",top:t.top,left:t.left,width:sh,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(Jw,{entry:n},n.feature))})]})}function Jw({entry:e}){const t=Xp[e.feature],n=Jp[e.feature]??e.feature;return f("li",{className:"flex items-center justify-between gap-2 text-[10px]",children:[f("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(eN,{kind:e.kind})]})}function eN({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:U("text-[8.5px] px-1 rounded",e==="native"?"bg-success/15 text-success":"bg-primary/15 text-primary"),children:e})}function ah({device:e,variant:t,flags:n,parent:o,integrationIcon:s,hasChildren:a,expanded:i,onToggleExpand:l,onNavigateToParent:c}){const d=Zp(e);return f("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(Pn,{className:"h-3 w-3"}):r(Ut,{className:"h-3 w-3"})}):n.showChildrenAccordion?r("span",{className:"h-3.5 w-3.5 flex-shrink-0"}):null,r(d,{className:U("text-foreground-subtle flex-shrink-0",t==="minimal"?"h-3 w-3":"h-3.5 w-3.5")}),f("div",{className:"flex-1 min-w-0",children:[f("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:U("font-semibold text-foreground truncate",t==="minimal"?"text-[10.5px]":"text-[11px]"),title:e.name,children:e.name})]}),(n.showId||n.showStableId)&&f("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&&f("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:Rw(e.stableId)})]}),n.showParentBadge&&o&&f("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(Za,{className:"h-2.5 w-2.5 shrink-0"}),f("span",{className:"truncate",children:["Under: ",o.name]})]})]})]})}function Nl(e,t){return Yp(e,t,o=>o.battery)??null}function Sl(e,t){const n=lt(e,t),o=ee(!1),{data:s,isLoading:a,isFetching:i,refetch:l}=En({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 tN(e){return e<=10?xv:e<=30?yv:e>=95?vv:Xf}function nN(e,t){return t!=="none"?"text-emerald-400":e<=10?"text-rose-400":e<=30?"text-amber-400":"text-foreground-subtle"}function kl({status:e,variant:t="compact",className:n}){if(!e)return null;const o=tN(e.percentage),s=nN(e.percentage,e.charging),a=e.charging==="solar"?Kf:e.charging==="dc"?bv:null,i=e.sleeping;return f("span",{className:U("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"}),f("span",{children:[Math.round(e.percentage),"%"]}),a&&r(a,{className:"h-3 w-3"}),i&&r(Zi,{className:"h-3 w-3 text-blue-300"}),t==="full"&&e.charging!=="none"&&r("span",{className:"text-foreground-subtle",children:e.charging})]})}function ih({trpc:e,device:t,status:n,enabled:o,showStatusPills:s=!1}){const a=o&&t.online,i=Sl(e,a?t.id:null),l=(t.features??[]).includes("battery-operated"),c=s&&l&&!t.disabled,d=Nl(e,c?t.id:null);return!o&&!c?null:f("span",{className:"inline-flex items-center gap-1.5 flex-nowrap whitespace-nowrap",children:[c&&d&&r(kl,{status:d}),o&&r(rN,{deviceName:t.name,snapshotUrl:i.src,status:n})]})}const da=288,id=196,ua=8;function rN({deviceName:e,snapshotUrl:t,status:n}){const o=ee(null),[s,a]=L(null),i=n==="offline"||n==="disabled",l=()=>{const d=o.current;if(!d)return;const p=d.getBoundingClientRect(),u=p.top,h=window.innerHeight-p.bottom,m=u<id+ua&&h>u,g=m?p.bottom+ua:p.top-id-ua,b=p.right-da,x=Math.max(8,Math.min(b,window.innerWidth-da-8));a({top:g,left:x,placeBelow:m})},c=()=>a(null);return f(ye,{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(ks,{className:"h-3.5 w-3.5"})}),s&&Kr(f("div",{style:{position:"fixed",top:s.top,left:s.left,width:da,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 lh({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:U("h-1.5 w-1.5 rounded-full flex-shrink-0",t),title:n})}function Lr(e){const{trpc:t,device:n,parent:o,integrationIcon:s,onNavigate:a,className:i}=e,l=$w(e),c=e.variant??"compact",d=e.view??"card",p=!n.disabled,u=n.isCamera??n.type.toLowerCase()==="camera",h=e.children??[],m=h.filter(od),g=h.filter(M=>!od(M)),b=h.length>0,[x,y]=L(!1),w=e.expanded??x,v=e.onToggleExpand??(()=>y(M=>!M)),N=M=>{a?.(M)},S=e.indentLevel??(e.isAccessoryRow?2:0),k=p?n.online?"online":"offline":"disabled";return d==="table"?r(sN,{trpc:t,device:n,variant:c,flags:l,parent:o??null,integrationIcon:s??null,accessoryCount:m.length,adoptedCount:g.length,hasChildren:b,expanded:w,onToggleExpand:v,onNavigate:N,displayStatus:k,isCamera:u,showSnapshot:l.showSnapshot&&u,isAccessoryRow:e.isAccessoryRow??!1,indentLevel:S,className:i}):f("div",{className:U("rounded-lg border border-border bg-surface transition-colors",!p&&"opacity-60",i),children:[f("div",{onClick:()=>N(n.id),className:U("flex items-center gap-2 cursor-pointer hover:border-foreground-subtle/30 w-full",c==="minimal"?"px-2.5 py-1.5":"px-3 py-2.5"),children:[r(ah,{device:n,variant:c,flags:l,parent:o??null,integrationIcon:s??null,hasChildren:b,expanded:w,onToggleExpand:v,onNavigateToParent:N}),r(oh,{trpc:t,device:n,flags:l,accessoryCount:m.length,adoptedCount:g.length,showFeatureRow:!1}),r(ih,{trpc:t,device:n,status:k,enabled:l.showSnapshot&&u,showStatusPills:!0}),r(rh,{trpc:t,device:n,flags:l}),r(lh,{status:k})]}),w&&b&&r(Lw,{trpc:t,accessoryChildren:m,adoptedChildren:g,onNavigate:N})]})}const oN={0:"pl-2",1:"pl-6",2:"pl-8"};function sN(e){const{trpc:t,device:n,variant:o,flags:s,parent:a,integrationIcon:i,accessoryCount:l,adoptedCount:c,hasChildren:d,expanded:p,onToggleExpand:u,onNavigate:h,displayStatus:m,isCamera:g,showSnapshot:b,isAccessoryRow:x,indentLevel:y,className:w}=e;return f("tr",{onClick:()=>h(n.id),className:U("cursor-pointer hover:bg-surface-hover transition-colors",!s.showChildrenAccordion&&"border-b border-border-subtle/40",x&&"bg-foreground-subtle/[0.03]",w),children:[r("td",{className:U("py-2 align-middle pr-2",oN[y]),children:r(ah,{device:n,variant:o,flags:s,parent:a,integrationIcon:i,hasChildren:d,expanded:p,onToggleExpand:u,onNavigateToParent:h})}),r("td",{className:"px-2 py-2 align-middle text-[10px] text-foreground-subtle whitespace-nowrap",children:n.type}),r("td",{className:"px-2 py-2 align-middle",children:r(oh,{trpc:t,device:n,flags:s,accessoryCount:l,adoptedCount:c,showFeatureRow:!0})}),r("td",{className:"px-2 py-2 align-middle",children:r(ih,{trpc:t,device:n,status:m,enabled:b&&g,showStatusPills:!0})}),r("td",{className:"px-2 py-2 align-middle text-right whitespace-nowrap",children:f("span",{className:"inline-flex items-center gap-1.5",children:[r(rh,{trpc:t,device:n,flags:s}),r(lh,{status:m})]})})]})}function ch(e,t){const[n,o]=L(e);return X(()=>{const s=setTimeout(()=>o(e),t);return()=>clearTimeout(s)},[e,t]),n}const aN=new Set(["hub","nvr"]);function iN(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(aN.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 ld=2;function lN(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-ld),s=Math.min(t-1,e+ld);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 cN({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=lN(e,a);return f("div",{className:"flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle",children:[f("span",{children:["Showing ",i,"–",l," of ",t," ",s]}),f("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:U("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(qf,{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 u=d.n===e;return r("button",{type:"button",onClick:()=>o(d.n),className:U("inline-flex items-center justify-center h-7 min-w-7 px-1.5 rounded border text-[10.5px] font-medium transition-colors",u?"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:U("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(Ut,{className:"h-3 w-3"})})]})]})}function dN({view:e,onViewChange:t,types:n,currentType:o,onTypeChange:s,addons:a,currentAddon:i,onAddonChange:l,hideAddons:c=!1}){return f("div",{className:"flex items-center gap-2 flex-wrap",children:[f("span",{className:"inline-flex border border-border rounded-md overflow-hidden",children:[r("button",{type:"button",onClick:()=>t("cards"),className:U("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(wv,{className:"h-3.5 w-3.5"})}),r("button",{type:"button",onClick:()=>t("table"),className:U("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(Nv,{className:"h-3.5 w-3.5"})})]}),n&&n.length>0&&f(ye,{children:[r(cd,{children:"Type"}),r(fa,{active:o===null,onClick:()=>s(null),children:"All"}),n.map(d=>r(fa,{active:o===d,onClick:()=>s(o===d?null:d),children:uN(d)},d))]}),!c&&a&&a.length>0&&f(ye,{children:[r(cd,{children:"Integration"}),a.map(d=>r(fa,{active:i===d.id,icon:d.icon,onClick:()=>l(i===d.id?null:d.id),showClearIcon:i===d.id,children:d.name},d.id))]})]})}function cd({children:e}){return r("span",{className:"text-[10px] font-medium uppercase tracking-wider text-foreground-subtle ml-1",children:e})}function fa({active:e,icon:t,onClick:n,showClearIcon:o,children:s}){return f("button",{type:"button",onClick:n,className:U("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:s}),e&&o&&r(Ve,{className:"h-2.5 w-2.5 opacity-70"})]})}function uN(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function fN({variant:e,onClearFilters:t}){return f("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[r(Sv,{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 St(e,t){if(e==="root")return t;switch(t){case"view":return"deviceView";case"page":return"devicePage";case"type":return"deviceType";case"q":return"deviceQ";case"addon":return"deviceAddon"}}function dd(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 pN(e,t){try{localStorage.setItem(`camstack:${e}:lastFilters`,JSON.stringify(t))}catch{}}function ud(e,t,n){const o=new URLSearchParams(window.location.search),s=o.get(St(e,"view")),a=s==="cards"||s==="table"?s:n.view??t,i=o.get(St(e,"page")),l=i?parseInt(i,10):1,c=Number.isFinite(l)&&l>=1?l:1,d=o.get(St(e,"addon"))??n.addon??null,p=o.get(St(e,"type"))??n.type??null,u=o.get(St(e,"q"))??n.q??"";return{view:a,page:c,addon:d,type:p,q:u}}function hN(e,t,n){const o=new URLSearchParams(window.location.search),s=(l,c)=>{c===null||c===""?o.delete(l):o.set(l,c)};s(St(e,"view"),t.view===n?null:t.view),s(St(e,"page"),t.page===1?null:String(t.page)),s(St(e,"addon"),t.addon),s(St(e,"type"),t.type),s(St(e,"q"),t.q||null);const a=o.toString(),i=a?`${window.location.pathname}?${a}`:window.location.pathname;window.history.replaceState(null,"",i)}function mN(e){const{scope:t,defaultView:n,lsKey:o}=e,[s,a]=L(()=>{const g=dd(o);return ud(t,n,g)}),i=ee(s);i.current=s,X(()=>{const g=()=>{const b=dd(o),x=ud(t,n,b);i.current=x,a(x)};return window.addEventListener("popstate",g),()=>window.removeEventListener("popstate",g)},[t,n,o]);const l=q(g=>{const b=g(i.current);i.current=b,a(b),hN(t,b,n),pN(o,{view:b.view,addon:b.addon,type:b.type,q:b.q})},[t,n,o]),c=q(g=>l(b=>({...b,view:g})),[l]),d=q(g=>l(b=>({...b,page:g})),[l]),p=q(g=>l(b=>({...b,addon:g,page:1})),[l]),u=q(g=>l(b=>({...b,type:g,page:1})),[l]),h=q(g=>l(b=>({...b,q:g,page:1})),[l]),m=q(()=>l(g=>({...g,addon:null,type:null,q:"",page:1})),[l]);return{state:s,setView:c,setPage:d,setAddon:p,setType:u,setQ:h,clearFilters:m}}const gN={cards:24,table:50};function Es(e){const{devices:t,trpc:n,defaultView:o="table",filters:s,forceAddon:a,resolveIntegrationIcon:i,resolveParent:l,onNavigate:c,pageSize:d=gN,urlScope:p="root",lsKey:u=p==="root"?"devices":"integrations:nested"}=e,h=mN({scope:p,defaultView:o,lsKey:u}),m=h.state.view,g=m==="cards"?d.cards:d.table,[b,x]=L(h.state.q),y=ch(b,300);X(()=>{y!==h.state.q&&h.setQ(y)},[y]);const w=a??h.state.addon,v=Q(()=>{const $=h.state.q.toLowerCase().trim();return t.filter(I=>!(w&&I.addonId!==w||h.state.type&&I.type!==h.state.type||$&&!I.name.toLowerCase().includes($)&&!I.stableId.toLowerCase().includes($)))},[t,w,h.state.type,h.state.q]),N=Q(()=>iN(v),[v]),S=Q(()=>{if(h.state.q.trim()==="")return new Set;const $=h.state.q.toLowerCase().trim(),I=new Set;for(const[_,P]of N.accessoriesByParent.entries())P.some(T=>T.name.toLowerCase().includes($)||T.stableId.toLowerCase().includes($))&&I.add(_);return I},[N.accessoriesByParent,h.state.q]),k=N.topLevel.length,M=Math.max(1,Math.ceil(k/g)),D=Math.min(h.state.page,M),E=(D-1)*g,B=N.topLevel.slice(E,E+g);X(()=>{D!==h.state.page&&h.setPage(D)},[D]),NN();const A=w!=null||h.state.type!==null||h.state.q!=="",O=k===0;return f("div",{className:"flex flex-col gap-3",children:[f("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[r(dN,{view:m,onViewChange:h.setView,types:s?.types,currentType:h.state.type,onTypeChange:h.setType,addons:s?.addons,currentAddon:h.state.addon,onAddonChange:h.setAddon,hideAddons:a!==void 0}),f("div",{className:"relative",children:[r(_r,{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:$=>x($.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(fN,{variant:A?"filtered":"nofilter",onClearFilters:A?h.clearFilters:void 0}):m==="cards"?r(bN,{rows:B,accessoriesByParent:N.accessoriesByParent,trpc:n,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:c??null}):r(vN,{rows:B,accessoriesByParent:N.accessoriesByParent,autoExpandedParents:S,devices:v,trpc:n,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:c??null}),r(cN,{currentPage:D,totalItems:k,pageSize:g,onPageChange:h.setPage}),a===void 0&&A&&k>0&&f("p",{className:"text-[11px] text-foreground-subtle",children:["Showing ",k," of ",t.length," devices",w&&f(ye,{children:[" ","· filtered by"," ",r("strong",{className:"text-primary",children:s?.addons?.find($=>$.id===w)?.name??w})]})]})]})}function bN({rows:e,accessoriesByParent:t,trpc:n,resolveIntegrationIcon:o,resolveParent:s,onNavigate:a}){return r("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:e.map(i=>{const l=t.get(i.id)??[];return r(Lr,{trpc:n,device:i,view:"card",integrationIcon:o?.(i.addonId)??null,parent:i.parentDeviceId!==null?s?.(i.parentDeviceId)??null:null,children:l,onNavigate:a??void 0},i.id)})})}const xN=new Set(["hub","nvr"]);function yN(e,t){return e.parentDeviceId===null||t===null?0:xN.has(t.toLowerCase())?1:0}function vN({rows:e,accessoriesByParent:t,autoExpandedParents:n,devices:o,trpc:s,resolveIntegrationIcon:a,resolveParent:i,onNavigate:l}){const c=Q(()=>{const d=new Map;for(const p of o)d.set(p.id,p.type);return d},[o]);return r("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:f("table",{className:"w-full border-collapse",children:[r("thead",{children:f("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:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-24",children:"Type"}),r("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Features"}),r("th",{className:"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(d=>{const p=t.get(d.id)??[],u=p.length>0,h=n.has(d.id),m=d.parentDeviceId!==null?i?.(d.parentDeviceId)??null:null,g=d.parentDeviceId!==null?c.get(d.parentDeviceId)??null:null;return r(wN,{parent:d,accessories:p,hasAccessories:u,forceExpanded:h,trpc:s,integrationIcon:a?.(d.addonId)??null,parentRowParent:m,indentLevel:yN(d,g),onNavigate:l??null},d.id)})})]})})}function wN({parent:e,accessories:t,hasAccessories:n,forceExpanded:o,trpc:s,integrationIcon:a,parentRowParent:i,indentLevel:l,onNavigate:c}){const[d,p]=L(o),u=ee(o);return X(()=>{u.current!==o&&(p(o),u.current=o)},[o]),f(ye,{children:[r(Lr,{trpc:s,device:e,view:"table",integrationIcon:a,parent:i,children:t,onNavigate:c??void 0,showChildrenAccordion:n,expanded:d,onToggleExpand:()=>p(g=>!g),indentLevel:l}),n&&d&&t.map(g=>r(Lr,{trpc:s,device:g,view:"table",integrationIcon:null,parent:null,isAccessoryRow:!0,showChildrenAccordion:!1,onNavigate:c??void 0},g.id))]})}function NN(){ke()}function SN({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 f("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(kv,{className:"h-3.5 w-3.5 shrink-0"}),o.label,o.isBest&&f("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(Cv,{className:"h-2.5 w-2.5"}),"Best"]}),o.platformScore!=null&&f("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 kN(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 CN(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 pa(e){return{addonId:e.id,addonName:e.name,slot:e.slot,inputClasses:[...e.inputClasses],outputClasses:[...e.outputClasses],enabled:!0,modelId:e.defaultModelId,children:[]}}function ha({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:f("div",{className:"flex items-center gap-3",children:[r(Ev,{className:"h-[18px] w-[18px] text-foreground-subtle/30 group-hover:text-primary/60 shrink-0"}),f("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}),f("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 Cl({schema:e,steps:t,onChange:n,templates:o,selectedTemplateId:s,onSelectTemplate:a,onSaveTemplate:i,onUpdateTemplate:l,onDeleteTemplate:c,readOnly:d=!1,excludeAddons:p=[],hideTemplates:u=!1,showOnlyEnabled:h=!1,showSlotLabels:m=!1,toggleMode:g="simple",overrides:b={},onOverrideChange:x,inheritedEnabledByAddon:y={},hideModelAndSettings:w=!1}){const v=F=>({toggleMode:g,hideModelAndSettings:w,...g==="threeState"?{overrideState:b[F]!==void 0?b[F]:null,onOverrideChange:x?j=>x(F,j):void 0,inheritedEnabled:y[F]}:{}}),N=Q(()=>new Set(p),[p]),S=Q(()=>CN(e),[e]),[k,M]=L([]),D=s?JSON.stringify(t)!==JSON.stringify(o.find(F=>F.id===s)?.steps):!1;function E(F){const j=F.target.value||null;if(j){const J=o.find(W=>W.id===j);if(J){const W=kN(J.steps,e);M([...W.warnings])}}else M([]);a(j)}function B(){s&&l(s,t)}function A(){const F=window.prompt("Template name:");F?.trim()&&i(F.trim(),t)}function O(){if(!s)return;const F=o.find(j=>j.id===s);F&&window.confirm(`Delete template "${F.name}"?`)&&c(s)}function $(F){n(t.map(j=>j.addonId!==F.addonId?j:I(F)))}function I(F){const j=F.children.some(J=>J.enabled||J.children.some(W=>W.enabled));return{...F,enabled:F.enabled||j,children:F.children.map(J=>{const W=J.children.some(ne=>ne.enabled);return{...J,enabled:J.enabled||W}})}}function _(F,j){const J=pa(j);n(t.map(W=>W.addonId!==F?W:{...W,children:[...W.children,J]}))}function P(F){const j=new Set;for(const J of F){j.add(J.addonId);for(const ne of J.children)j.add(ne.addonId);const W=P(J.children);for(const ne of W)j.add(ne)}return j}const T=P(t);function R(F){const j=S.get(F.addonId);if(!j)return[];const W=e.slots.find(K=>K.id===j.slot)?.parentSlot==null,ne=j.childSlots,de=new Set(F.children.map(K=>K.addonId)),te=[];for(const K of e.slots)if(ne.includes(K.id))for(const oe of K.addons){if(de.has(oe.id)||N.has(oe.id))continue;const me=oe.inputClasses.length===0;if(me&&!W)continue;(me||oe.inputClasses.some(G=>F.outputClasses.includes(G)))&&te.push(oe)}return te}function z(F){const j=h?{...F,children:F.children.filter(W=>W.enabled).map(W=>({...W,children:W.children.filter(ne=>ne.enabled)}))}:F,J=h?[]:R(j);return f("div",{className:"space-y-1.5",children:[r(Bo,{step:j,schema:S.get(j.addonId)??null,allSchemas:S,onChange:$,onDelete:d?void 0:W=>n(t.filter(ne=>ne.addonId!==W)),readOnly:d,...v(j.addonId)}),(j.children.length>0||J.length>0)&&f("div",{className:"ml-4 pl-3 border-l border-border/60 space-y-1.5",children:[m&&r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/40",children:"Slot: Cropper / Classifier"}),j.children.map(W=>{const ne=R(W);return f("div",{className:"space-y-1.5",children:[r(Bo,{step:W,schema:S.get(W.addonId)??null,allSchemas:S,depth:1,onChange:de=>{$({...j,children:j.children.map(te=>te.addonId===de.addonId?de:te)})},onDelete:d?void 0:de=>{$({...j,children:j.children.filter(te=>te.addonId!==de)})},readOnly:d,...v(W.addonId)}),(W.children.length>0||ne.length>0)&&f("div",{className:"ml-4 pl-3 border-l border-border/40 space-y-1.5",children:[m&&r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/30",children:"Slot: Recognizer"}),W.children.map(de=>r(Bo,{step:de,schema:S.get(de.addonId)??null,allSchemas:S,depth:2,onChange:te=>{$({...j,children:j.children.map(K=>K.addonId===W.addonId?{...K,children:K.children.map(oe=>oe.addonId===te.addonId?te:oe)}:K)})},onDelete:d?void 0:te=>{$({...j,children:j.children.map(K=>K.addonId===W.addonId?{...K,children:K.children.filter(oe=>oe.addonId!==te)}:K)})},readOnly:d,...v(de.addonId)},de.addonId)),!d&&ne.map(de=>r(ha,{addon:de,onClick:()=>{const te=pa(de);$({...j,children:j.children.map(K=>K.addonId===W.addonId?{...K,children:[...K.children,te]}:K)})}},de.id))]})]},W.addonId)}),!d&&J.map(W=>r(ha,{addon:W,onClick:()=>_(j.addonId,W)},W.id))]})]},j.addonId)}const H=e.slots.filter(F=>F.parentSlot===null).sort((F,j)=>F.priority-j.priority);return f("div",{className:"space-y-4",children:[!u&&r("div",{className:"rounded-lg border border-border bg-surface p-3",children:f("div",{className:"flex items-center gap-2",children:[r("div",{className:"relative flex-1 min-w-0",children:f("select",{value:s??"",onChange:E,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(F=>r("option",{value:F.id,children:F.name},F.id))]})}),D&&r("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500 shrink-0"}),r("button",{onClick:B,disabled:!s||d,title:"Save",className:U("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(Mv,{className:"h-4 w-4"})}),r("button",{onClick:A,disabled:d,title:"Save As",className:U("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(Iv,{className:"h-4 w-4"})}),r("button",{onClick:O,disabled:!s||d,title:"Delete",className:U("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(zt,{className:"h-4 w-4"})})]})}),k.length>0&&f("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 text-xs text-amber-400 space-y-1",children:[f("div",{className:"flex items-center justify-between",children:[r("span",{className:"font-medium",children:"Template loaded with warnings:"}),r("button",{onClick:()=>M([]),className:"text-amber-400/60 hover:text-amber-400",children:r(Ve,{className:"h-3.5 w-3.5"})})]}),k.map((F,j)=>f("div",{children:["• ",F]},j))]}),H.map(F=>{const j=t.filter(te=>te.slot===F.id&&!N.has(te.addonId)),J=h?j.filter(te=>te.enabled):j,W=h?[]:F.addons.filter(te=>!T.has(te.id)&&!N.has(te.id)),ne=new Map,de=[];for(const te of J)te.group?(ne.has(te.group)||ne.set(te.group,[]),ne.get(te.group).push(te)):de.push(te);return f("div",{className:"space-y-2",children:[m&&f("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50",children:["Slot: ",F.label]}),de.map(te=>z(te)),[...ne.entries()].map(([te,K])=>f("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:te}),K.map(oe=>z(oe))]},te)),!d&&W.map(te=>r(ha,{addon:te,onClick:()=>{n([...t,pa(te)])}},te.id))]},F.id)})]})}const vr={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"},fd=["#ef4444","#8b5cf6","#06b6d4","#f97316","#10b981","#6366f1","#e11d48","#0891b2","#7c3aed","#059669"],dh="#f59e42";function Je(e,t){if(t?.[e])return t[e];if(t?.[e.toLowerCase()])return t[e.toLowerCase()];if(vr[e])return vr[e];if(vr[e.toLowerCase()])return vr[e.toLowerCase()];let n=0;for(let o=0;o<e.length;o++)n=n*31+(e.codePointAt(o)??0)>>>0;return fd[n%fd.length]??dh}function MN({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 u(y){return Je(y,s)}const h=a??(t&&n?`${t}/${n}`:"16/9"),m=o.filter(y=>y.score>=d),g=m.filter(y=>y.kind==="first-level"),b=m.filter(y=>y.kind==="detail"),x=PN(b,y=>y.parentId??"");return r("div",{className:U("rounded-lg border border-border bg-surface overflow-hidden relative",i),style:{aspectRatio:h},children:e?f(ye,{children:[r("img",{src:e,className:"absolute inset-0 w-full h-full object-fill",alt:""}),m.map((y,w)=>y.debug?.mask&&y.debug.maskWidth&&y.debug.maskHeight?r(IN,{mask:y.debug.mask,maskWidth:y.debug.maskWidth,maskHeight:y.debug.maskHeight,bbox:y.bbox,imageWidth:t,imageHeight:n,color:u(y.macroClass)},`mask-${w}`):null),g.map(y=>{const w=x.get(y.id)??[];return r(pd,{detection:y,imageWidth:t,imageHeight:n,color:u(y.macroClass),showConfidence:c,borderWidth:y.debug?.mask?1:p,children:w.map(v=>r(EN,{child:v,parentBbox:y.bbox,color:u(v.macroClass),showConfidence:c},`child-${v.id}`))},`det-${y.id}`)}),b.filter(y=>!y.parentId||!g.some(w=>w.id===y.parentId)).map(y=>r(pd,{detection:y,imageWidth:t,imageHeight:n,color:u(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 pd({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,u=f("div",{className:"absolute left-0 flex flex-col items-start gap-px",style:{bottom:"100%",marginBottom:"2px"},children:[f("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((h,m)=>f("span",{className:"text-[9px] font-semibold px-1 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:Je(h.label)},children:[h.label," ",(h.score*100).toFixed(0),"%"]},`${e.id}-lbl-${m}`))]});return f("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:[u,i]})}function IN({mask:e,maskWidth:t,maskHeight:n,bbox:o,imageWidth:s,imageHeight:a,color:i}){const l=ee(null);return X(()=>{const c=l.current;if(!c)return;const d=c.getContext("2d");if(!d)return;const p=atob(e),u=new Uint8Array(p.length);for(let y=0;y<p.length;y++)u[y]=p.charCodeAt(y);const h=parseInt(i.slice(1,3),16),m=parseInt(i.slice(3,5),16),g=parseInt(i.slice(5,7),16);c.width=t,c.height=n;const b=d.createImageData(t,n),x=t*n;for(let y=0;y<x;y++){const w=y<u.length?u[y]:0,v=y*4;w>0&&(b.data[v]=h,b.data[v+1]=m,b.data[v+2]=g,b.data[v+3]=120)}d.putImageData(b,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 EN({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:f("div",{className:"absolute left-0 flex flex-col items-start gap-px",style:{bottom:"100%",marginBottom:"1px"},children:[f("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)=>f("span",{className:"text-[8px] font-semibold px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:Je(c.label)},children:[c.label," ",(c.score*100).toFixed(0),"%"]},`${e.id}-lbl-${d}`))]})})}function PN(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 AN({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 u=c.get(p.parentId)??[];u.push(p),c.set(p.parentId,u)}const d=l.filter(p=>!p.parentId||!i.some(u=>u.id===p.parentId));return f("div",{className:n,children:[f("div",{className:"text-xs font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:["Detections (",e.length,")"]}),f("div",{className:"space-y-2",children:[i.map(p=>r(hd,{detection:p,children_:c.get(p.id)??[],colors:a,hiddenKeys:o,onToggleVisibility:s},p.id)),d.map(p=>r(hd,{detection:p,children_:[],colors:a,hiddenKeys:o,onToggleVisibility:s},p.id))]})]})}function hd({detection:e,children_:t,colors:n,hiddenKeys:o,onToggleVisibility:s}){const a=Je(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 f("div",{className:`rounded-md border border-border bg-surface p-3 space-y-1 ${i?"":"opacity-40"}`,children:[f("div",{className:"flex justify-between items-center",children:[f("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&&f("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",c,"x",d]})]}),r(_N,{confidence:e.score})]}),f("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((u,h)=>f("span",{className:"inline-flex items-center gap-1 text-[10px] font-medium px-1.5 py-0.5 rounded-full",style:{backgroundColor:Je(u.label,n)+"20",color:Je(u.label,n)},children:[u.label,f("span",{className:"opacity-60",children:[(u.score*100).toFixed(0),"%"]}),u.detectionId&&f("span",{className:"opacity-40 text-[8px]",children:["→ ",u.detectionId]})]},h))}),p&&Object.keys(p).length>0&&r(DN,{alternateLabels:p,colors:n}),t.length>0&&r($N,{items:t,colors:n,hiddenKeys:o,onToggleVisibility:s})]})}function $N({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=Je(s.macroClass,t),i=!n?.has(s.id),l=s.debug?.mask,c=s.debug?.maskWidth,d=s.debug?.maskHeight;return f("div",{className:`text-xs space-y-0.5 ${i?"":"opacity-40"}`,children:[f("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}),f("span",{className:"text-foreground-subtle",children:[(s.score*100).toFixed(0),"%"]}),l&&c&&d&&f("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,u)=>f("span",{className:"inline-flex items-center gap-0.5 text-[9px] font-medium px-1 py-0.5 rounded-full",style:{backgroundColor:Je(p.label,t)+"20",color:Je(p.label,t)},children:[p.label," ",f("span",{className:"opacity-60",children:[(p.score*100).toFixed(0),"%"]})]},u))})]},s.id)})})}function DN({alternateLabels:e,colors:t}){const[n,o]=L(!1),s=Object.keys(e);return f("div",{className:"mt-1",children:[f("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:f("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)=>f("span",{className:"inline-flex items-center gap-0.5 text-[9px] px-1 py-0.5 rounded-full",style:{backgroundColor:Je(a,t)+"10",color:Je(a,t),opacity:Math.max(.4,l.score)},children:[l.label,f("span",{className:"opacity-60",children:[(l.score*100).toFixed(1),"%"]})]},c))})]},a)})})]})}function _N({confidence:e}){const t=e>=.8?"bg-success/10 text-success":e>=.5?"bg-warning/10 text-warning":"bg-danger/10 text-danger";return f("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${t}`,children:[(e*100).toFixed(1),"%"]})}function TN({timings:e,totalMs:t,className:n}){const o=Object.entries(e);return o.length===0&&t===void 0?null:f("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"}),f("div",{className:"space-y-1 text-xs",children:[o.map(([s,a])=>f("div",{className:"flex justify-between",children:[r("span",{className:"text-foreground-subtle",children:s}),f("span",{className:"font-mono text-foreground",children:[a.toFixed(1),"ms"]})]},s)),t!==void 0&&f("div",{className:"flex justify-between pt-1 border-t border-border font-medium text-foreground",children:[r("span",{children:"Total"}),f("span",{className:"font-mono",children:[t.toFixed(1),"ms"]})]})]})]})}function RN({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 u=new FileReader;u.onload=()=>{const h=u.result,m=h.split(",")[1];m&&s(m,p.name,h)},u.readAsDataURL(p)},d.click()};return f("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 po="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 LN({runtime:e,backend:t,modelId:n,agentId:o="hub",runtimes:s,backends:a,models:i,agents:l=[],onRuntimeChange:c,onBackendChange:d,onModelChange:p,onAgentChange:u,layout:h="grid",className:m,showAgent:g=!1}){return f("div",{className:`${h==="grid"?"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4":h==="horizontal"?"flex flex-wrap items-end gap-4":"space-y-3"} ${m??""}`,children:[g&&l.length>0&&f("label",{className:"space-y-1",children:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Agent"}),r("select",{value:o,onChange:x=>u?.(x.target.value),className:po,children:l.map(x=>f("option",{value:x.id,children:[x.name," (",x.status,")"]},x.id))})]}),f("label",{className:"space-y-1",children:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Runtime"}),r("select",{value:e,onChange:x=>c(x.target.value),className:po,children:s.map(x=>f("option",{value:x.value,disabled:!x.available,children:[x.label,x.available?"":" (unavailable)"]},x.value))})]}),f("label",{className:"space-y-1",children:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Backend"}),r("select",{value:t,onChange:x=>d(x.target.value),className:po,children:a.map(x=>f("option",{value:x.id,disabled:!x.available,children:[x.label,x.available?"":" (unavailable)"]},x.id))})]}),f("label",{className:"space-y-1",children:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Model"}),r("select",{value:n,onChange:x=>p(x.target.value),className:po,children:i.length===0?r("option",{value:"",children:"No compatible models"}):i.map(x=>f("option",{value:x.id,children:[x.name,x.downloaded?" ✓":""]},x.id))})]})]})}function ON({className:e}){return f("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 BN({className:e}){return f("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 zN({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 uh({onLogin:e,serverUrl:t,logoSrc:n,error:o,className:s}){const[a,i]=L(""),[l,c]=L(""),[d,p]=L(!1),[u,h]=L(!1),[m,g]=L(null),b=o??m,x=async y=>{if(y.preventDefault(),!u){g(null),h(!0);try{await e(a,l)}catch(w){const v=w instanceof Error?w.message:"Login failed. Please try again.";g(v)}finally{h(!1)}}};return r("div",{className:U("flex min-h-screen items-center justify-center bg-background p-4",s),children:f("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}),f("form",{onSubmit:x,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[b&&r("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:b}),f("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"})]}),f("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"Password"}),f("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(BN,{className:"h-4 w-4"}):r(ON,{className:"h-4 w-4"})})]})]}),f("button",{type:"submit",disabled:u,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:[u&&r(zN,{className:"h-4 w-4 animate-spin"}),u?"Logging in...":"Log in"]})]})]})})}const ci="camstack_dev_token",fh=$e(null);function FN(){const e=ge(fh);if(!e)throw new Error("useDevShell must be used within a DevShell");return e}function HN(){return typeof window>"u"?null:localStorage.getItem(ci)}function jN({className:e}){return f("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 VN({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 qN({children:e,serverUrl:t,title:n,token:o,onLogout:s}){const a=Xr(),i=Q(()=>{const h=t.replace(/^http/,"ws")+"/trpc",m=Gy({url:h,connectionParams:()=>({token:o})});return[Wy({condition:g=>g.type==="subscription",true:Ky({client:m,transformer:ei}),false:Bf({url:`${t}/trpc`,transformer:ei,headers:()=>({authorization:`Bearer ${o}`})})})]},[t,o]),l=Q(()=>Of({links:i}),[i]),c=Q(()=>C.createClient({links:i}),[i]),d=Q(()=>tp({serverUrl:t,token:o}),[t,o]);X(()=>(d.init().catch(()=>{}),()=>{d.close()}),[d]);const p=Q(()=>new Tf,[]),u=Q(()=>({trpc:l,token:o,logout:s}),[l,o,s]);return r(wl,{system:d,children:r(C.Provider,{client:c,queryClient:p,children:r(Rf,{client:p,children:r(fh.Provider,{value:u,children:f("div",{className:"min-h-screen bg-background text-foreground",children:[f("div",{className:"flex items-center justify-between border-b border-border bg-surface px-4 py-2",children:[f("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})]}),f("div",{className:"flex items-center gap-2",children:[f("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(jN,{className:"h-3.5 w-3.5"}):r(VN,{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 ph({children:e,serverUrl:t="https://localhost:4443",title:n}){const[o,s]=L(HN),a=q(async(l,c)=>{const u=await Of({links:[Bf({url:`${t}/trpc`,transformer:ei})]}).auth.login.mutate({username:l,password:c});if(!u.token)throw new Error("No token returned");localStorage.setItem(ci,u.token),s(u.token)},[t]),i=q(()=>{localStorage.removeItem(ci),s(null)},[]);return o?r(Go,{children:r(qN,{serverUrl:t,title:n,token:o,onLogout:i,children:e})}):r(Go,{children:r(uh,{onLogin:a,serverUrl:t})})}function UN(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}Df(a).render(Se(ph,{serverUrl:n,title:o,children:({trpc:i,theme:l})=>Se(e,{trpc:i,theme:{isDark:l.resolvedMode==="dark"},navigate:c=>{console.log("[dev] navigate:",c)}})}))}const hh=Qt("camstack:custom-field-renderers",{});function mh({renderers:e,children:t}){return r(hh.Provider,{value:e,children:t})}function gh(e){return ge(hh)[e]??null}const Ml=Qt("camstack:device-context",null);function bh({deviceId:e,device:t,children:n}){const o={deviceId:e,device:t??null};return r(Ml.Provider,{value:o,children:n})}function Gt(){return ge(Ml)?.deviceId??null}function Il(){return ge(Ml)?.device??null}const QN=C.accessories.getStatus.useQuery,El=C.addonPages.listPages.useQuery,Pl=C.addons.list.useQuery,GN=C.addons.getLogs.useQuery,WN=C.addons.listPackages.useQuery,Al=C.addons.installPackage.useMutation,KN=C.addons.installFromWorkspace.useMutation,YN=C.addons.isWorkspaceAvailable.useQuery,ZN=C.addons.listWorkspacePackages.useQuery,xh=C.addons.uninstallPackage.useMutation,yh=C.addons.reloadPackages.useMutation,vh=C.addons.searchAvailable.useQuery,$l=C.addons.listUpdates.useQuery,di=C.addons.updatePackage.useMutation,wh=C.addons.forceRefresh.useMutation,XN=C.addons.restartServer.useMutation,Nh=C.addons.getVersions.useQuery,Ps=C.addons.restartAddon.useMutation,Sh=C.addons.getAutoUpdateSettings.useQuery,JN=C.addons.setAutoUpdateSettings.useMutation,kh=C.addons.getAddonAutoUpdate.useQuery,Ch=C.addons.setAddonAutoUpdate.useMutation,Mh=C.addons.applyAutoUpdateToAll.useMutation,e2=C.addons.custom.useMutation,t2=C.addons.onAddonLogs.useSubscription,Dl=C.addonSettings.getGlobalSettings.useQuery,Ih=C.addonSettings.updateGlobalSettings.useMutation,n2=C.addonSettings.getDeviceSettings.useQuery,Eh=C.addonSettings.updateDeviceSettings.useMutation,Ph=C.addonWidgets.listWidgets.useQuery,r2=C.alerts.emit.useMutation,o2=C.alerts.update.useMutation,Ah=C.alerts.list.useQuery,$h=C.alerts.getUnreadCount.useQuery,Dh=C.alerts.markRead.useMutation,_h=C.alerts.markAllRead.useMutation,Th=C.alerts.dismiss.useMutation,s2=C.audioAnalysis.resolveDeviceSettings.useQuery,a2=C.audioAnalysis.getDeviceSettingsContribution.useQuery,i2=C.audioAnalysis.getDeviceLiveContribution.useQuery,l2=C.audioAnalysis.applyDeviceSettingsPatch.useMutation,c2=C.audioAnalyzer.analyseChunk.useMutation,d2=C.audioAnalyzer.classify.useQuery,u2=C.audioAnalyzer.isReady.useQuery,f2=C.audioAnalyzer.dispose.useMutation,Rh=C.audioAnalyzer.reprobeAudioEngine.useMutation,p2=C.audioCodec.listSupportedCodecs.useQuery,h2=C.audioCodec.canHandle.useQuery,m2=C.audioCodec.createDecodeSession.useMutation,g2=C.audioCodec.createEncodeSession.useMutation,b2=C.audioCodec.closeSession.useMutation,x2=C.audioCodec.pushEncodedFrame.useMutation,y2=C.audioCodec.pullPcm.useQuery,v2=C.audioCodec.pushPcm.useMutation,w2=C.audioCodec.pullEncoded.useQuery,N2=C.audioCodec.flushEncode.useMutation,S2=C.audioCodec.listActiveSessions.useQuery,k2=C.audioMetrics.getCurrentSnapshot.useQuery,C2=C.audioMetrics.getHistory.useQuery,M2=C.backup.trigger.useMutation,I2=C.backup.list.useQuery,E2=C.backup.restore.useMutation,P2=C.backup.delete.useMutation,A2=C.battery.getStatus.useQuery,$2=C.brightness.setBrightness.useMutation,D2=C.brightness.getStatus.useQuery,_2=C.cameraStreams.getCameraStreams.useQuery,T2=C.cameraStreams.getBrokerStreams.useQuery,R2=C.cameraStreams.getRtspEntries.useQuery,L2=C.decoder.supportsCodec.useQuery,O2=C.decoder.getInfo.useQuery,B2=C.decoder.createSession.useQuery,z2=C.decoder.destroySession.useQuery,F2=C.decoder.pushPacket.useQuery,H2=C.decoder.openStream.useQuery,j2=C.decoder.pullFrames.useQuery,V2=C.decoder.updateConfig.useQuery,q2=C.decoder.getStats.useQuery,U2=C.decoder.listActiveSessions.useQuery,Lh=C.decoder.reprobeHwaccel.useMutation,Q2=C.detectionPipeline.getDeviceSettingsContribution.useQuery,G2=C.detectionPipeline.getDeviceLiveContribution.useQuery,W2=C.detectionPipeline.applyDeviceSettingsPatch.useMutation,Oh=C.deviceDiscovery.listDiscovered.useQuery,Bh=C.deviceDiscovery.refreshDiscovery.useMutation,K2=C.deviceDiscovery.adoptDevice.useMutation,Y2=C.deviceDiscovery.releaseDevice.useMutation,Z2=C.deviceDiscovery.getStatus.useQuery,X2=C.deviceManager.allocateDeviceId.useMutation,J2=C.deviceManager.registerDevice.useMutation,eS=C.deviceManager.removeDevice.useMutation,tS=C.deviceManager.persistConfig.useMutation,nS=C.deviceManager.loadConfig.useQuery,rS=C.deviceManager.loadRuntimeState.useQuery,oS=C.deviceManager.loadMeta.useQuery,zh=C.deviceManager.setName.useMutation,Fh=C.deviceManager.setLocation.useMutation,sS=C.deviceManager.setMetadata.useMutation,Hh=C.deviceManager.listLocations.useQuery,aS=C.deviceManager.addLocation.useMutation,iS=C.deviceManager.removeLocation.useMutation,lS=C.deviceManager.setDisabled.useMutation,cS=C.deviceManager.listPersistedByAddon.useQuery,$n=C.deviceManager.listAll.useQuery,yn=C.deviceManager.getDevice.useQuery,jh=C.deviceManager.getChildren.useQuery,dS=C.deviceManager.getStreamSources.useQuery,uS=C.deviceManager.getConfigSchema.useQuery,fS=C.deviceManager.getSettingsSchema.useQuery,pS=C.deviceManager.updateConfig.useMutation,Vh=C.deviceManager.enable.useMutation,qh=C.deviceManager.disable.useMutation,Uh=C.deviceManager.remove.useMutation,hS=C.deviceManager.getStreamProfileMap.useQuery,mS=C.deviceManager.setStreamProfileMap.useMutation,gS=C.deviceManager.probeStreams.useMutation,Qh=C.deviceManager.getBindings.useQuery,bS=C.deviceManager.getAllBindings.useQuery,Gh=C.deviceManager.setWrapperActive.useMutation,xS=C.deviceManager.listWrappersForCap.useQuery,Wh=C.deviceManager.listBindableCapsForDeviceType.useQuery,yS=C.deviceManager.getDeviceSettingsAggregate.useQuery,vS=C.deviceManager.getDeviceLiveInfoAggregate.useQuery,_l=C.deviceManager.getDeviceAggregate.useQuery,wS=C.deviceManager.updateDeviceField.useMutation,Kh=C.deviceManager.updateDeviceFieldsBatch.useMutation,Tl=C.deviceManager.discoverDevices.useMutation,Yh=C.deviceManager.adoptDevice.useMutation,Zh=C.deviceManager.getCreationSchema.useQuery,Xh=C.deviceManager.createDevice.useMutation,Rl=C.deviceManager.testCreationField.useMutation,NS=C.deviceManager.testField.useMutation,SS=C.deviceManager.getDeviceStatusAggregate.useQuery,kS=C.deviceOps.getStreamSources.useQuery,CS=C.deviceOps.getConfigEntries.useQuery,MS=C.deviceOps.setConfig.useMutation,IS=C.deviceOps.removeDevice.useMutation,ES=C.deviceOps.getSettingsSchema.useQuery,PS=C.deviceProvider.start.useMutation,AS=C.deviceProvider.stop.useMutation,$S=C.deviceProvider.getStatus.useQuery,DS=C.deviceProvider.getDevices.useQuery,_S=C.deviceProvider.supportsDiscovery.useQuery,TS=C.deviceProvider.discoverDevices.useMutation,RS=C.deviceProvider.adoptDiscoveredDevice.useMutation,LS=C.deviceProvider.supportsManualCreation.useQuery,OS=C.deviceProvider.getChildCreationSchema.useQuery,BS=C.deviceProvider.createDevice.useMutation,zS=C.deviceProvider.testCreationField.useMutation,FS=C.deviceState.getSnapshot.useQuery,HS=C.deviceState.getCapSlice.useQuery,jS=C.deviceState.getAllSnapshots.useQuery,VS=C.deviceState.setCapSlice.useMutation,qS=C.doorbell.getStatus.useQuery,US=C.events.getEvents.useQuery,QS=C.events.getEventThumbnail.useQuery,GS=C.events.getEventClipUrl.useQuery,Ll=C.integrations.list.useQuery,Jh=C.integrations.get.useQuery,em=C.integrations.getByAddonId.useQuery,tm=C.integrations.create.useMutation,nm=C.integrations.update.useMutation,rm=C.integrations.delete.useMutation,WS=C.integrations.getSettings.useQuery,KS=C.integrations.setSettings.useMutation,om=C.integrations.getAvailableTypes.useQuery,sm=C.integrations.testConnection.useMutation,am=C.intercom.startSession.useMutation,im=C.intercom.handleAnswer.useMutation,lm=C.intercom.stopSession.useMutation,YS=C.intercom.getStatus.useQuery,ZS=C.metricsProvider.collectSnapshot.useQuery,XS=C.metricsProvider.getCached.useQuery,JS=C.metricsProvider.getCurrent.useQuery,ek=C.metricsProvider.getDiskSpace.useQuery,tk=C.metricsProvider.getGpuInfo.useQuery,nk=C.metricsProvider.getCpuTemperature.useQuery,rk=C.metricsProvider.getProcessStats.useQuery,ok=C.metricsProvider.listAddonInstances.useQuery,sk=C.metricsProvider.getAddonStats.useQuery,cm=C.metricsProvider.listNodeProcesses.useQuery,dm=C.metricsProvider.killProcess.useMutation,ak=C.motion.isDetected.useQuery,ik=C.motion.getStatus.useQuery,lk=C.motionDetection.analyze.useMutation,ck=C.motionDetection.removeCamera.useMutation,dk=C.motionDetection.reset.useMutation,uk=C.motionDetection.getDeviceSettingsContribution.useQuery,fk=C.motionDetection.getDeviceLiveContribution.useQuery,pk=C.motionDetection.applyDeviceSettingsPatch.useMutation,hk=C.motionTrigger.setMotionTrigger.useMutation,mk=C.motionTrigger.getStatus.useQuery,gk=C.nativeObjectDetection.getStatus.useQuery,Ol=C.networkQuality.getDeviceStats.useQuery,bk=C.networkQuality.getAllStats.useQuery,xk=C.networkQuality.reportClientStats.useMutation,sn=C.nodes.topology.useQuery,yk=C.nodes.deployAddon.useMutation,um=C.nodes.undeployAddon.useMutation,As=C.nodes.restartAddon.useMutation,fm=C.nodes.restartProcess.useMutation,pm=C.nodes.restartNode.useMutation,vk=C.nodes.shutdownNode.useMutation,hm=C.nodes.renameNode.useMutation,mm=C.nodes.clusterAddonStatus.useQuery,gm=C.nodes.setProcessLogLevel.useMutation,wk=C.nodes.executeQuery.useMutation,Nk=C.notificationOutput.send.useMutation,Sk=C.notificationOutput.sendTest.useMutation,kk=C.osd.setOverlay.useMutation,Ck=C.osd.getStatus.useQuery,Mk=C.pipelineAnalytics.getActiveTracks.useQuery,Ik=C.pipelineAnalytics.getTrack.useQuery,Ek=C.pipelineAnalytics.listTracks.useQuery,Pk=C.pipelineAnalytics.clearTracks.useMutation,Ak=C.pipelineAnalytics.getMotionEvents.useQuery,$k=C.pipelineAnalytics.getObjectEvents.useQuery,Dk=C.pipelineAnalytics.getAudioEvents.useQuery,_k=C.pipelineAnalytics.getEventMedia.useQuery,Tk=C.pipelineAnalytics.getTrackMedia.useQuery,Rk=C.pipelineAnalytics.getDeviceSettingsContribution.useQuery,Lk=C.pipelineAnalytics.getDeviceLiveContribution.useQuery,Ok=C.pipelineAnalytics.applyDeviceSettingsPatch.useMutation,bm=C.pipelineExecutor.getAvailableEngines.useQuery,xm=C.pipelineExecutor.getSelectedEngine.useQuery,Bk=C.pipelineExecutor.getDefaultSteps.useQuery,ym=C.pipelineExecutor.reprobeEngine.useMutation,zk=C.pipelineExecutor.getVideoPipelineSteps.useQuery,Fk=C.pipelineExecutor.setVideoPipelineSteps.useMutation,Jr=C.pipelineExecutor.getSchema.useQuery,Hk=C.pipelineExecutor.getGlobalSteps.useQuery,jk=C.pipelineExecutor.getGlobalPipelineConfig.useQuery,Vk=C.pipelineExecutor.getOrchestratorConfigSchema.useQuery,qk=C.pipelineExecutor.listTemplates.useQuery,Uk=C.pipelineExecutor.saveTemplate.useMutation,Qk=C.pipelineExecutor.updateTemplate.useMutation,Gk=C.pipelineExecutor.deleteTemplate.useMutation,Wk=C.pipelineExecutor.getCapabilities.useQuery,Kk=C.pipelineExecutor.getAddonModels.useQuery,vm=C.pipelineExecutor.downloadModel.useMutation,wm=C.pipelineExecutor.deleteModel.useMutation,Yk=C.pipelineExecutor.detect.useQuery,Zk=C.pipelineExecutor.runPipeline.useMutation,Xk=C.pipelineExecutor.runPipelineBatch.useMutation,Jk=C.pipelineExecutor.cacheFrameInPool.useMutation,eC=C.pipelineExecutor.inferCached.useMutation,tC=C.pipelineExecutor.uncacheFrame.useMutation,nC=C.pipelineExecutor.getEffectiveTuning.useQuery,Nm=C.pipelineExecutor.listLoadedEngines.useQuery,rC=C.pipelineExecutor.spinEngine.useMutation,Sm=C.pipelineExecutor.killEngine.useMutation,oC=C.pipelineExecutor.listReferenceImages.useQuery,sC=C.pipelineExecutor.getReferenceImage.useQuery,aC=C.pipelineExecutor.getReferenceAudioFiles.useQuery,iC=C.pipelineExecutor.getReferenceAudio.useQuery,lC=C.pipelineExecutor.getAudioCapabilities.useQuery,cC=C.pipelineExecutor.runAudioTest.useMutation,dC=C.pipelineExecutor.getDetectionConfigSchema.useQuery,km=C.pipelineOrchestrator.assignPipeline.useMutation,Cm=C.pipelineOrchestrator.unassignPipeline.useMutation,Mm=C.pipelineOrchestrator.rebalance.useMutation,$s=C.pipelineOrchestrator.getPipelineAssignments.useQuery,Ds=C.pipelineOrchestrator.getPipelineAssignment.useQuery,Im=C.pipelineOrchestrator.getAgentLoad.useQuery,uC=C.pipelineOrchestrator.getGlobalMetrics.useQuery,fC=C.pipelineOrchestrator.getCameraMetrics.useQuery,Em=C.pipelineOrchestrator.getCapabilityBindings.useQuery,Pm=C.pipelineOrchestrator.setCapabilityBinding.useMutation,Am=C.pipelineOrchestrator.assignDecoder.useMutation,$m=C.pipelineOrchestrator.unassignDecoder.useMutation,Dm=C.pipelineOrchestrator.getDecoderAssignments.useQuery,_m=C.pipelineOrchestrator.assignAudio.useMutation,Tm=C.pipelineOrchestrator.unassignAudio.useMutation,pC=C.pipelineOrchestrator.getAudioAssignment.useQuery,Rm=C.pipelineOrchestrator.getAudioNodeLoad.useQuery,Lm=C.pipelineOrchestrator.getAudioAssignments.useQuery,hC=C.pipelineOrchestrator.getDecoderAssignment.useQuery,Bl=C.pipelineOrchestrator.getAgentSettings.useQuery,ir=C.pipelineOrchestrator.listAgentSettings.useQuery,zl=C.pipelineOrchestrator.setAgentAddonDefaults.useMutation,Om=C.pipelineOrchestrator.removeAgentSettings.useMutation,Fl=C.pipelineOrchestrator.getCameraSettings.useQuery,Bm=C.pipelineOrchestrator.setCameraStepToggle.useMutation,mC=C.pipelineOrchestrator.getCameraStepOverrides.useQuery,zm=C.pipelineOrchestrator.setCameraStepOverride.useMutation,Fm=C.pipelineOrchestrator.setCameraPipelineForAgent.useMutation,Hm=C.pipelineOrchestrator.resolvePipeline.useQuery,jm=C.pipelineOrchestrator.listTemplates.useQuery,gC=C.pipelineOrchestrator.saveTemplate.useMutation,Vm=C.pipelineOrchestrator.updateTemplate.useMutation,qm=C.pipelineOrchestrator.deleteTemplate.useMutation,bC=C.pipelineOrchestrator.getDeviceSettingsContribution.useQuery,xC=C.pipelineOrchestrator.getDeviceLiveContribution.useQuery,yC=C.pipelineOrchestrator.applyDeviceSettingsPatch.useMutation,vC=C.pipelineRunner.attachCamera.useMutation,wC=C.pipelineRunner.detachCamera.useMutation,NC=C.pipelineRunner.reportMotion.useMutation,SC=C.pipelineRunner.getLocalLoad.useQuery,kC=C.pipelineRunner.getLocalMetrics.useQuery,Hl=C.pipelineRunner.getCameraMetrics.useQuery,CC=C.pipelineRunner.getAllCameraMetrics.useQuery,Um=C.pipelineRunner.getLocalCameras.useQuery,MC=C.platformProbe.getCapabilities.useQuery,IC=C.platformProbe.getHardware.useQuery,EC=C.platformProbe.resolveInferenceConfig.useQuery,PC=C.platformProbe.resolveHwAccel.useQuery,AC=C.ptz.move.useMutation,$C=C.ptz.continuousMove.useMutation,DC=C.ptz.stop.useMutation,_C=C.ptz.getPresets.useQuery,TC=C.ptz.goToPreset.useMutation,RC=C.ptz.goHome.useMutation,LC=C.ptz.getPosition.useQuery,OC=C.ptz.getStatus.useQuery,Qm=C.ptzAutotrack.getStatus.useQuery,Gm=C.ptzAutotrack.setEnabled.useMutation,BC=C.ptzAutotrack.getSettings.useQuery,Wm=C.ptzAutotrack.setSettings.useMutation,Km=C.reboot.reboot.useMutation,zC=C.recording.getSegments.useQuery,FC=C.recording.getPlaybackUrl.useQuery,HC=C.recording.getThumbnailAt.useQuery,jC=C.recordingEngine.getStatus.useQuery,Ym=C.recordingEngine.enable.useMutation,Zm=C.recordingEngine.disable.useMutation,Xm=C.recordingEngine.getConfig.useQuery,VC=C.recordingEngine.updateConfig.useMutation,qC=C.recordingEngine.getPlaylist.useQuery,UC=C.recordingEngine.getThumbnail.useQuery,Jm=C.recordingEngine.getSegments.useQuery,QC=C.recordingEngine.getAvailability.useQuery,GC=C.recordingEngine.estimateStorage.useQuery,WC=C.recordingEngine.estimateGlobalStorage.useQuery,eg=C.recordingEngine.getStorageUsage.useQuery,KC=C.recordingEngine.setPolicy.useMutation,YC=C.recordingEngine.getPolicy.useQuery,tg=C.recordingEngine.getPolicyStatus.useQuery,ng=C.recordingEngine.getRetentionConfig.useQuery,ZC=C.recordingEngine.updateRetentionConfig.useMutation,XC=C.recordingEngine.getMotionStats.useQuery,JC=C.settingsStore.get.useQuery,e5=C.settingsStore.set.useMutation,t5=C.settingsStore.query.useQuery,n5=C.settingsStore.insert.useMutation,r5=C.settingsStore.update.useMutation,o5=C.settingsStore.delete.useMutation,s5=C.settingsStore.count.useQuery,a5=C.settingsStore.isEmpty.useQuery,i5=C.settingsStore.declareCollection.useMutation,l5=C.snapshot.getSnapshot.useQuery,c5=C.snapshot.invalidateCache.useMutation,d5=C.snapshot.getStatus.useQuery,u5=C.snapshot.getDeviceSettingsContribution.useQuery,f5=C.snapshot.getDeviceLiveContribution.useQuery,p5=C.snapshot.applyDeviceSettingsPatch.useMutation,h5=C.snapshotProvider.supportsDevice.useQuery,m5=C.snapshotProvider.getSnapshot.useQuery,g5=C.storage.resolve.useQuery,b5=C.storage.write.useMutation,x5=C.storage.read.useQuery,y5=C.storage.exists.useQuery,v5=C.storage.list.useQuery,w5=C.storage.delete.useMutation,N5=C.storage.getAvailableSpace.useQuery,S5=C.streamBroker.publishCameraStream.useMutation,k5=C.streamBroker.retractCameraStream.useMutation,C5=C.streamBroker.assignProfile.useMutation,M5=C.streamBroker.unassignProfile.useMutation,I5=C.streamBroker.listAllCameraStreams.useQuery,E5=C.streamBroker.listAllProfileSlots.useQuery,P5=C.streamBroker.getBrokerStats.useQuery,A5=C.streamBroker.listClients.useQuery,$5=C.streamBroker.killClient.useMutation,D5=C.streamBroker.restartProfile.useMutation,_5=C.streamBroker.getStreamUrl.useQuery,T5=C.streamBroker.getBroker.useQuery,R5=C.streamBroker.setPreBufferDuration.useMutation,L5=C.streamBroker.getPreBufferInfo.useQuery,O5=C.streamBroker.getRtspPort.useQuery,B5=C.streamBroker.getAllRtspEntries.useQuery,z5=C.streamBroker.getRtspEntry.useQuery,rg=C.streamBroker.regenerateRtspToken.useMutation,F5=C.streamBroker.setRtspEnabled.useMutation,H5=C.streamBroker.isRtspEnabled.useQuery,j5=C.streamBroker.getDeviceSettingsContribution.useQuery,V5=C.streamBroker.getDeviceLiveContribution.useQuery,q5=C.streamBroker.applyDeviceSettingsPatch.useMutation,U5=C.switch.setState.useMutation,Q5=C.switch.getStatus.useQuery,G5=C.system.info.useQuery,W5=C.system.health.useQuery,K5=C.system.featureFlags.useQuery,Y5=C.system.networkAddresses.useQuery,Z5=C.system.getRetentionConfig.useQuery,X5=C.system.setRetentionConfig.useMutation,J5=C.system.forceRetentionCleanup.useMutation,og=C.toast.onToast.useSubscription,e3=C.turnProvider.getTurnServers.useQuery,sg=C.userManagement.listUsers.useQuery,ag=C.userManagement.createUser.useMutation,t3=C.userManagement.updateUser.useMutation,n3=C.userManagement.deleteUser.useMutation,r3=C.userManagement.resetPassword.useMutation,o3=C.userManagement.validateCredentials.useMutation,s3=C.userManagement.listApiKeys.useQuery,a3=C.userManagement.createApiKey.useMutation,i3=C.userManagement.revokeApiKey.useMutation,l3=C.userManagement.validateApiKey.useMutation,c3=C.userManagement.createScopedToken.useMutation,d3=C.userManagement.revokeScopedToken.useMutation,u3=C.userManagement.validateScopedToken.useQuery,f3=C.userManagement.listScopedTokens.useQuery,p3=C.webrtcSession.listStreams.useQuery,h3=C.webrtcSession.createSession.useMutation,m3=C.webrtcSession.handleAnswer.useMutation,g3=C.webrtcSession.closeSession.useMutation,b3=C.webrtcSession.hasAdaptiveBitrate.useQuery,x3=C.zoneAnalytics.getCurrentSnapshot.useQuery,y3=C.zoneAnalytics.getZoneHistory.useQuery,v3=C.zoneAnalytics.getCameraHistory.useQuery,w3=C.zoneAnalytics.getUnzonedHistory.useQuery,N3=C.zoneRules.listRules.useQuery,S3=C.zoneRules.setRules.useMutation,k3=C.zones.listZones.useQuery,C3=C.zones.addZone.useMutation,M3=C.zones.removeZone.useMutation,I3=C.zones.updateZone.useMutation,ig=Qt("camstack:widget-registry",null),Zo=new Map,ho=new Map,md=new Set;function E3(e){if(!e||typeof e!="object")return!1;const t=e.default;return t!==null&&typeof t=="object"}function P3(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 A3(e,t){const n=Zo.get(e);if(n)return n;const o=ho.get(e);if(o)return o;md.has(e)||(rl(),Un.registerRemotes([{name:e,entry:t,type:"module"}],{force:!1}),md.add(e));const s=Un.loadRemote(`${e}/widgets`).then(a=>{if(!E3(a)){const l=P3(a);throw new Error(`Widget remote ${e} (${t}) does not expose a default record on './widgets'. Got: ${JSON.stringify(l)}`)}const i=a.default;return Zo.set(e,i),ho.delete(e),i}).catch(a=>{throw ho.delete(e),a});return ho.set(e,s),s}const $3=3e4,D3=2e3;function lg({children:e}){const t=ke(),n=ee(Date.now()),{data:o}=Ph(void 0,{staleTime:0,refetchOnMount:"always",refetchInterval:l=>{const c=l.state.data;return c&&c.length>0||Date.now()-n.current>=$3?!1:D3}});et("addon.widget-ready",()=>{t.invalidateQueries({queryKey:[["addonWidgets","listWidgets"]]})});const[s,a]=L(0);X(()=>{if(!o)return;let l=!1;const c=new Set;for(const d of o){if(c.has(d.remoteName)||(c.add(d.remoteName),Zo.has(d.remoteName)))continue;const p=d.bundleUrl;A3(d.remoteName,p).then(()=>{l||a(u=>u+1)}).catch(u=>{const h=u instanceof Error?u.message:String(u);(typeof globalThis<"u"?globalThis.console:void 0)?.error?.("[WidgetRegistry] Failed to load widget remote",{remoteName:d.remoteName,entryUrl:p,reason:h})})}return()=>{l=!0}},[o]);const i=Q(()=>{const l=o??[],c=new Map;for(const p of l)c.set(`${p.addonId}/${p.stableId}`,p);const d=(p,u)=>({widgetId:p,addonId:u.addonId,stableId:u.stableId,label:u.label,description:u.description,icon:u.icon,remoteName:u.remoteName,bundleUrl:u.bundleUrl,hosts:u.hosts,requires:u.requires,defaultSize:u.defaultSize,allowedSizes:u.allowedSizes,defaultColumns:u.defaultColumns,defaultRows:u.defaultRows});return{resolve:p=>{const u=c.get(p);if(!u)return;const h=Zo.get(u.remoteName);if(!h)return null;const m=h[u.stableId];if(m)return m},metadata:p=>{const u=c.get(p);if(u)return d(p,u)},listAll:()=>{const p=[];for(const[u,h]of c)p.push(d(u,h));return p}}},[o,s]);return r(ig.Provider,{value:i,children:e})}function cg(e){return _s().resolve(e)}function dg(e){return _s().metadata(e)}function ug(){return _s().listAll()}function _s(){const e=fg();if(!e)throw new Error("useWidgetRegistry(): no <WidgetRegistryProvider> in tree");return e}function fg(){return _3(ig)}function _3(e){return ge(e)}function Ze(e){const{widgetId:t,host:n="device-tab",config:o,deviceId:s,integrationId:a,instanceId:i,size:l,columns:c,rows:d}=e,p=cg(t),u=dg(t),h=Q(()=>i??t,[i,t]);if(p===void 0&&u===void 0)return r(mo,{widgetId:t,reason:"unknown"});if(p===void 0)return r(mo,{widgetId:t,reason:"missing-export"});if(p===null)return r(T3,{});if(u){if(u.requires.deviceContext&&s===void 0)return r(mo,{widgetId:t,reason:"missing-device-context"});if(u.requires.integrationContext&&a===void 0)return r(mo,{widgetId:t,reason:"missing-integration-context"})}return r(p,{instanceId:h,host:n,config:o,deviceId:s,integrationId:a,size:l,columns:c,rows:d})}function T3(){return f("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 mo({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 Dn="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",Ts="block text-[11px] font-medium text-foreground mb-1",R3="text-[10px] text-foreground-subtle mt-0.5";function Fe({label:e,description:t,required:n,span:o,children:s,translationFn:a}){const i=o===2?"col-span-2":o===3?"col-span-3":o===4?"col-span-4":"col-span-1",l=Ht(e,a),c=Ht(t,a);return f("div",{className:i,children:[l!==void 0&&l!==""&&f("label",{className:Ts,children:[l,n&&r("span",{className:"text-danger ml-0.5",children:"*"})]}),s,c&&r("p",{className:R3,children:c})]})}function L3({field:e,value:t,onChange:n,disabled:o,translationFn:s}){return r(Fe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("input",{type:e.inputType??"text",className:Dn,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 O3({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const[a,i]=L(t==null?"":String(t)),l=ee(!1);X(()=>{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(Fe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:f("div",{className:"flex items-center gap-1",children:[r("input",{type:"number",className:Dn,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 B3({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=!!t,i=o||e.disabled;return e.style==="checkbox"?r(Fe,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:s,children:f("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:Ht(e.label,s)}),e.required&&r("span",{className:"text-danger",children:"*"})]})}):r(Fe,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:s,children:f("div",{className:"flex items-center justify-between",children:[f("span",{className:Ts+" mb-0",children:[Ht(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 z3({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=e.options.some(i=>i.value==="");return r(Fe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:f("select",{className:Dn,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 F3({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(Fe,{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 f("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 H3({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const[a,i]=L(!1),l=e.showToggle!==!1;return r(Fe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:f("div",{className:"relative",children:[r("input",{type:a?"text":"password",className:Dn+(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(Qf,{className:"h-3.5 w-3.5"}):r(ks,{className:"h-3.5 w-3.5"})})]})})}function j3({field:e,value:t,onChange:n,disabled:o,translationFn:s}){return r(Fe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("textarea",{className:Dn+" 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 V3({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,u=e.displayScale??1,h=e.min/u,m=e.max/u,g=l/u,b=(e.step??1)/u;if(i&&a)return r(Fe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:f("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 x=e.showStepper===!0&&c,y=v=>{const N=l+v*(e.step??1),S=Math.min(e.max,Math.max(e.min,N));S!==l&&n(S)},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(Fe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:f("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[f("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:h}),r("input",{type:"range",className:"min-w-0 flex-1 h-1 accent-primary cursor-pointer disabled:opacity-50",min:h,max:m,step:b,value:g,disabled:p,onChange:v=>n(Number(v.target.value)*u)}),r("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:m})]}),(c||i||e.unit)&&f("div",{className:"flex shrink-0 items-center gap-2",children:[x&&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(Pv,{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:h,max:m,step:b,value:g,disabled:p,onChange:v=>{if(v.target.value===""){n(i?null:e.min);return}const N=Number(v.target.value)*u,S=e.step??1,k=N-e.min,M=e.min+Math.round(k/S)*S;n(Math.min(e.max,Math.max(e.min,M)))}}),x&&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(el,{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 q3({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=Array.isArray(t)?t:[],[i,l]=L(""),c=ee(null),d=q(m=>{const g=m.trim();!g||a.includes(g)||e.maxTags!==void 0&&a.length>=e.maxTags||(n([...a,g]),l(""))},[a,e.maxTags,n]),p=m=>n(a.filter(g=>g!==m)),u=m=>{m.key==="Enter"||m.key===","?(m.preventDefault(),d(i)):m.key==="Backspace"&&i===""&&a.length>0&&p(a[a.length-1])},h=o||e.disabled;return r(Fe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:f("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",h?"opacity-50 cursor-not-allowed":""].join(" "),onClick:()=>!h&&c.current?.focus(),children:[a.map(m=>f("span",{className:"inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[m,!h&&r("button",{type:"button",onClick:()=>p(m),className:"hover:text-danger",children:r(Ve,{className:"h-2.5 w-2.5"})})]},m)),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:h,list:`tags-suggestions-${e.key}`,onChange:m=>l(m.target.value),onKeyDown:u,onBlur:()=>{i.trim()&&d(i)}}),e.suggestions&&r("datalist",{id:`tags-suggestions-${e.key}`,children:e.suggestions.map(m=>r("option",{value:m},m))})]})})}function pg({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const{nodes:a}=sr(),i=typeof t=="string"?t:"",l=e.showOffline?a:a.filter(c=>c.isOnline);return r(Fe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:f("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=>f("option",{value:c.id,disabled:!c.isOnline,children:[c.shortName,c.isOnline?"":" (offline)"]},c.id))]})})}function hg({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const{nodes:a}=sr(),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(Fe,{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 U3({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=t==null?"#000000":String(t);return f(Fe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:[f("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:Dn+" 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 Q3({field:e,value:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i,externalProbe:l}){const[c,d]=L("idle"),[p,u]=L(null),h=l?.status??c,m=l?.result??p,g=!!a||!!i,b=q(async()=>{if(g){d("probing"),u(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"};u(v),d(v.status==="ok"?"ok":"error")}catch(w){u({status:"error",error:w instanceof Error?w.message:String(w)}),d("error")}}},[a,i,e.key,t,g]),x=h==="probing"?"border-primary/40 bg-primary/10 text-primary":h==="ok"?"border-success/40 bg-success/10 text-success hover:bg-success/15":h==="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=h==="probing"?r(Mt,{className:"h-3 w-3 animate-spin"}):h==="ok"?r(Av,{className:"h-3 w-3"}):h==="error"?r(Ns,{className:"h-3 w-3"}):r(np,{className:"h-3 w-3"});return f(Fe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:[f("div",{className:"@container flex items-center gap-2",style:{containerType:"inline-size"},children:[f("button",{type:"button",onClick:b,title:"Test",disabled:e.disabled||h==="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 ${x}`,children:[y,r("span",{className:"hidden @[280px]:inline",children:"Test"})]}),r("input",{type:e.inputType??"url",className:Dn+" 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"),u(null))}})]}),h==="ok"&&m?.labels&&m.labels.length>0&&r("div",{className:"flex flex-wrap gap-1 mt-1.5",children:m.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))}),h==="error"&&m?.error&&r("p",{className:"text-xs text-danger mt-1 truncate",title:m.error,children:m.error})]})}function G3({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a}){const[i,l]=L(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,children:f("div",{className:"rounded-lg border border-border bg-surface/50 overflow-hidden",children:[f("div",{className:["px-3 py-2 flex items-center justify-between",c?"cursor-pointer hover:bg-surface":""].join(" "),onClick:c?()=>l(p=>!p):void 0,children:[r("span",{className:"text-xs font-semibold text-foreground",children:Ht(e.label,s)}),c&&r("span",{className:"text-foreground-subtle text-xs",children:i?"▸":"▾"})]}),!i&&r("div",{className:"px-3 pb-3 grid grid-cols-2 gap-x-4 gap-y-3",children:e.fields.map(p=>r(lr,{field:p,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a},p.key))})]})})}function W3({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i}){const l=e.tabs[0]?.id??"",[c,d]=L(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:f("div",{className:p,children:[e.label&&r("div",{className:Ts,children:Ht(e.label,s)}),f("div",{className:"rounded-lg border border-border-subtle bg-surface-hover/40 overflow-hidden",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(u=>{const h=u.id===c;return f("button",{type:"button",role:"tab","aria-selected":h,onClick:()=>d(u.id),className:`inline-flex items-center gap-1.5 whitespace-nowrap rounded-md px-2.5 py-1 text-[11px] transition-colors ${h?"bg-primary text-primary-foreground font-medium shadow-sm":"bg-transparent text-foreground-subtle hover:bg-surface hover:text-foreground"}`,children:[r("span",{children:Ht(u.label,s)}),u.badge&&r("span",{className:`text-[9px] px-1 py-0.5 rounded-full font-medium ${h?"bg-primary-foreground/20 text-primary-foreground":"bg-primary/10 text-primary"}`,children:u.badge})]},u.id)})}),e.tabs.map(u=>u.id!==c?null:r("div",{role:"tabpanel",className:"px-3 pb-3 pt-2 grid grid-cols-2 gap-x-4 gap-y-3",children:u.fields.map((h,m)=>{const g="key"in h&&typeof h.key=="string"?h.key:`__${u.id}__${m}`;return r(lr,{field:h,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i},g)})},u.id))]})]})}function K3({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 gd={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 Y3({field:e}){const t=e.variant??"info",n=gd[t]??gd.info;return r("div",{className:"col-span-full",children:f("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}),r("p",{className:"text-xs text-foreground-subtle leading-relaxed",children:e.content})]})})}const bd={ok:"bg-success",warn:"bg-amber-500",danger:"bg-danger",idle:"bg-foreground-subtle/40",unknown:"bg-foreground-subtle/40"};function Z3(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 X3(e){return!Number.isFinite(e)||e<=0?"—":new Date(e).toLocaleTimeString()}function J3({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=bd[n]??bd.unknown;return f("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:Z3(t)}):e==="timestamp"&&typeof t=="number"?r("span",{className:"font-mono text-[11px]",children:X3(t)}):r("span",{children:String(t)})}function eM({field:e}){const t=e.value??[],n=e.description;return f("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:f("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(J3,{kind:a.kind,value:o[a.key]})},a.key))},s))})]})})]})}function tM({field:e,disabled:t,onAction:n}){const[o,s]=L(!1),a=on(),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(Fe,{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 nM({field:e}){const t=Gt();return r(Fe,{label:e.label,description:e.description,required:e.required,span:e.span,children:r(Ze,{widgetId:e.widgetId,host:"device-tab",config:e.widgetConfig,deviceId:t??void 0,instanceId:e.key})})}function rM(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 oM({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=rM(i,l),d="label"in e?e.label:void 0,p="description"in e?e.description:void 0,u="span"in e?e.span:void 0,h="actions"in e?e.actions??[]:[];return r(Fe,{label:d,description:p,span:u,translationFn:o,children:f("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}),h.length>0&&r("div",{className:"flex items-center gap-1",children:h.map(m=>r(aM,{action:m,fieldKey:s,value:i,onAction:n},m.action))})]})})}function sM({name:e}){const t="h-3.5 w-3.5";switch(e){case"copy":return r(nn,{className:t});case"refresh-cw":return r(tl,{className:t});case"external-link":return r(op,{className:t});case"trash-2":return r(zt,{className:t});case"download":return r(Xa,{className:t});case"upload":return r(rp,{className:t});default:return r(Xi,{className:t})}}function aM({action:e,fieldKey:t,value:n,onAction:o}){const s=on(),[a,i]=L(!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(sM,{name:e.icon})})}function iM(e){return"multiple"in e&&e.multiple!=null}function lM({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,u=d.max,h=t[e.key],g=[...Array.isArray(h)?h:h!=null?[h]:[]],b=d.itemDefault!==void 0?d.itemDefault:"default"in e&&e.default!==void 0?e.default:"";for(;g.length<p;)g.push(b);const x=S=>n(e.key,[...S]),y=(S,k)=>{const M=[...g];M[S]=k,x(M)},w=()=>{g.length>=u||x([...g,b])},v=S=>{g.length<=p||x(g.filter((k,M)=>M!==S))},N=()=>{const{multiple:S,...k}=e;return{...k,...{label:void 0,description:void 0,required:!1}}};return r(Fe,{label:e.label,description:e.description,required:p>0?e.required:!1,span:e.span,translationFn:s,children:f("div",{className:"space-y-2",children:[g.map((S,k)=>{const M=d.itemLabel?.replace("${n}",String(k+1));return f("div",{className:"space-y-1",children:[M&&r("div",{className:Ts,children:M}),f("div",{className:"flex items-center gap-2",children:[r("div",{className:"flex-1 min-w-0",children:r(lr,{field:N(),values:{...t,[e.key]:S},onChange:(D,E)=>y(k,E),disabled:o,translationFn:s,onTestField:a,onAction:c,allFields:l})}),g.length>p&&r("button",{type:"button",onClick:()=>v(k),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(zt,{className:"h-3.5 w-3.5"})})]})]},k)}),f("div",{className:"flex items-center justify-between pt-1",children:[g.length<u?f("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(el,{className:"h-3 w-3"}),d.addLabel??"Add"]}):r("span",{}),f("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:[g.length,"/",u]})]})]})})}function jl(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 lr({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c}){if(iM(e))return r(lM,{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(oM,{field:e,values:t,onAction:c,translationFn:s});if(!jl(e,t,l))return null;const d=t[e.key],p=d!==void 0?d:"default"in e?e.default:void 0,u=m=>n(e.key,m),h=gh(e.type);switch(e.type){case"text":return r(L3,{field:e,value:p,onChange:u,disabled:o,translationFn:s});case"number":return r(O3,{field:e,value:p,onChange:u,disabled:o,translationFn:s});case"boolean":return r(B3,{field:e,value:p,onChange:u,disabled:o,translationFn:s});case"select":return r(z3,{field:e,value:p,onChange:u,disabled:o,translationFn:s});case"multiselect":return r(F3,{field:e,value:p,onChange:u,disabled:o,translationFn:s});case"password":return r(H3,{field:e,value:p,onChange:u,disabled:o,translationFn:s});case"textarea":return r(j3,{field:e,value:p,onChange:u,disabled:o,translationFn:s});case"slider":return r(V3,{field:e,value:p,onChange:u,disabled:o,translationFn:s});case"tags":return r(q3,{field:e,value:p,onChange:u,disabled:o,translationFn:s});case"color":return r(U3,{field:e,value:p,onChange:u,disabled:o,translationFn:s});case"node-select":return r(pg,{field:e,value:p,onChange:u,disabled:o,translationFn:s});case"node-multiselect":return r(hg,{field:e,value:p,onChange:u,disabled:o,translationFn:s});case"probe":return r(Q3,{field:e,value:p,onChange:u,disabled:o,translationFn:s,onTestField:a,onAction:c,externalProbe:i});case"group":return r(G3,{field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a});case"sub-tabs":return r(W3,{field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:c});case"separator":return r(K3,{});case"info":return r(Y3,{field:e});case"object-array":return r(eM,{field:e});case"button":return r(tM,{field:e,disabled:o,onAction:c});case"widget":return r(nM,{field:e});default:return h?r(h,{field:e,value:p,onChange:u,disabled:o}):null}}function cM(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function Ht(e,t){if(e!==void 0)return t&&cM(e)?t(e):e}function dM({section:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,probeResults:i}){const[l,c]=L(e.defaultCollapsed??!1),d=e.style==="accordion",p=e.columns??2,u=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 @[640px]:grid-cols-2";return f("div",{className:"@container rounded-lg border border-border bg-surface p-3",style:{containerType:"inline-size"},children:[f("div",{className:["flex items-center justify-between mb-2",d?"cursor-pointer":""].join(" "),onClick:d?()=>c(h=>!h):void 0,children:[f("div",{children:[r("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:Ht(e.title,s)}),e.description&&r("p",{className:"text-[10px] text-foreground-subtle mt-0.5",children:Ht(e.description,s)})]}),d&&r("span",{className:"text-foreground-subtle text-xs ml-2",children:l?"▸":"▾"})]}),!l&&r("div",{className:`grid ${u} gap-x-3 gap-y-2.5`,children:e.fields.map(h=>r(lr,{field:h,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i?.[h.key]},h.key))})]})}function mg({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(dM,{section:d,values:t,onChange:c,disabled:o,translationFn:s,onTestField:a,probeResults:i},d.id))})}const uM=({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 xd(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 fM(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 pM({trpc:e,addonId:t,nodeId:n,title:o,disabled:s,onAfterChange:a,refreshToken:i,collapsible:l,defaultOpen:c,mode:d,onOverrideChange:p}){const u=d??"persist",[h,m]=L(null),[g,b]=L(!0),[x,y]=L(null),[w,v]=L(!1),[N,S]=L(c??!1),[k,M]=L({}),[D,E]=L(null);X(()=>{E(null),M({})},[e,t,n,i,u]);const B=JSON.stringify(k);X(()=>{let P=!1;b(!0),y(null);const T=u==="override"&&Object.keys(k).length>0?k:void 0;return e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n,...T?{overlay:T}:{}}).then(R=>{P||(m(R),T||E(xd(R)),b(!1))}).catch(R=>{P||(y(R instanceof Error?R.message:String(R)),b(!1))}),()=>{P=!0}},[e,t,n,i,u,B]);const A=Q(()=>xd(h),[h]),O=Q(()=>h?fM(h):null,[h]),$=async P=>{if(u==="override"){const R=D??A,z={};for(const F of Object.keys(P))P[F]!==R[F]&&(z[F]=P[F]);const H={...R,...z};M(z),p?.(z,H);return}const T={};for(const R of Object.keys(P))P[R]!==A[R]&&(T[R]=P[R]);if(Object.keys(T).length!==0){v(!0);try{await e.addonSettings.updateGlobalSettings.mutate({addonId:t,nodeId:n,patch:T});const R=await e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n});m(R),a?.()}catch(R){y(R instanceof Error?R.message:String(R))}finally{v(!1)}}};if(g)return f("div",{className:"text-xs text-foreground-subtle animate-pulse",children:["Loading ",o??t,"…"]});if(x)return f("div",{className:"text-xs text-red-400",children:[o??t,": ",x]});if(!h||!O)return f("div",{className:"text-xs text-foreground-subtle",children:[o??t," not available on ",n,"."]});const I=u==="override"?{...A,...k}:A,_=f(ye,{children:[u==="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(mg,{schema:O,values:I,onChange:$,disabled:s===!0||w})]});return l===!0?f("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[f("button",{type:"button",onClick:()=>S(P=>!P),className:"w-full px-4 py-2 flex items-center gap-2 hover:bg-surface-hover text-left","aria-expanded":N,children:[r(uM,{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:_}):null]}):o?f("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:_})]}):r("div",{children:_})}function gg({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:f("div",{className:"absolute inset-0 pointer-events-none z-10",children:[l&&r(hM,{phase:o}),d&&r(mM,{raw:t}),c&&r(gM,{motion:e}),p&&r(bM,{detections:n.detections,frameWidth:n.frameWidth,frameHeight:n.frameHeight})]})}function hM({phase:e}){const t=An(e);return f("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 mM({raw:e}){return e.frameWidth===0||e.frameHeight===0?null:r(ye,{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,u=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, ${u})`}},`mr-${n}`)})})}function gM({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(ye,{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 bM({detections:e,frameWidth:t,frameHeight:n}){return t===0||n===0?null:r(ye,{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,u=l/n*100,h=Je(o.macroClass),m=[`${o.macroClass} ${(o.score*100).toFixed(0)}%`];for(const g of o.labels)m.push(g.label);return r("div",{className:"absolute border-2 rounded-sm",style:{left:`${c}%`,top:`${d}%`,width:`${p}%`,height:`${u}%`,borderColor:h},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:h},children:m.join(" | ")})},`det-${o.id}`)})})}function xM(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 yM=3e3,vM=5;function bg({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:u,closeSession:h,hintsOverride:m}){const g=ee(null),b=ee(null),x=ee(null),y=ee(new Set),w=ee(null),v=ee(null),N=ee(0),S=ee(!0),[k,M]=L("idle"),[D,E]=L(""),[B,A]=L(s),[O,$]=L(!1),[I,_]=L(!1),P=ee(null),T=ee(!1);(u||p)&&(T.current=!0);const R=T.current,z=q(G=>{M(G),l?.(G)},[l]),H=q(()=>{if(w.current?.abort(),w.current=null,v.current&&(clearTimeout(v.current),v.current=null),x.current&&(x.current.close(),x.current=null),h&&y.current.size>0){for(const G of y.current)h(G).catch(()=>{});y.current.clear()}g.current&&(g.current.srcObject=null)},[h]),F=q(async()=>{if(!S.current||!p||!u)return;H(),z("connecting");const G=new AbortController;w.current=G;try{const re={...xM(b.current),...m},{sessionId:pe,sdpOffer:he}=await p(re);if(y.current.add(pe),!S.current||G.signal.aborted){h?.(pe).catch(()=>{}),y.current.delete(pe);return}const V=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]});x.current=V;const se=new MediaStream;V.ontrack=ue=>{console.debug("[WebRTC] ontrack",ue.track.kind,ue.track.readyState),se.addTrack(ue.track),g.current&&(g.current.srcObject=se,g.current.play().catch(()=>{}))},V.oniceconnectionstatechange=()=>{if(!S.current)return;const ue=V.iceConnectionState;console.debug("[WebRTC] ICE state:",ue),ue==="connected"||ue==="completed"?(N.current=0,z("playing"),g.current?.paused&&(console.debug("[WebRTC] video was paused at ICE connected — calling play()"),g.current.play().catch(()=>{}))):(ue==="failed"||ue==="disconnected"||ue==="closed")&&(z("disconnected"),ne())},V.onicecandidateerror=ue=>{console.debug("[WebRTC] ICE candidate error:",ue)},console.debug("[WebRTC] Setting remote description (server offer)..."),await V.setRemoteDescription({type:"offer",sdp:he});const ce=await V.createAnswer();if(await V.setLocalDescription(ce),console.debug("[WebRTC] Local description set, waiting for ICE gathering..."),await yd(V),!S.current)return;const ie=(V.localDescription?.sdp??"").split(`
31
- `).filter(ue=>ue.startsWith("a=candidate:")).length;console.debug("[WebRTC] Sending answer to server",{localCandidates:ie,sessionId:pe.slice(0,8)}),await u(pe,V.localDescription?.sdp??""),console.debug("[WebRTC] Answer sent successfully");const ae=V,ve=()=>{const ue=ae.connectionState;if(ue==="closed"||ue==="failed")return;const Ne=g.current;Ne&&Ne.readyState===0&&console.log(`[WebRTC] no video data yet (ice=${ae.iceConnectionState})`)};setTimeout(ve,3e3),setTimeout(ve,8e3)}catch(Z){if(!S.current)return;const re=Z instanceof Error?Z.message:String(Z);E(re),z("error"),c?.(re),ne()}},[e,t,p,u,H,z,c,m]),j=q(async()=>{if(S.current){H(),z("connecting");try{const G=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]});x.current=G,G.addTransceiver("video",{direction:"recvonly"}),G.addTransceiver("audio",{direction:"recvonly"});const Z=new MediaStream;G.ontrack=se=>{Z.addTrack(se.track),g.current&&(g.current.srcObject=Z,g.current.play().catch(()=>{}))},G.oniceconnectionstatechange=()=>{if(!S.current)return;const se=G.iceConnectionState;se==="connected"||se==="completed"?(N.current=0,z("playing"),g.current?.paused&&g.current.play().catch(()=>{})):(se==="failed"||se==="disconnected"||se==="closed")&&(z("disconnected"),ne())};const re=await G.createOffer();if(await G.setLocalDescription(re),await yd(G),!S.current)return;const pe=`${e}/api/webrtc?src=${encodeURIComponent(t)}`,he=await fetch(pe,{method:"POST",headers:{"Content-Type":"application/sdp"},body:G.localDescription?.sdp??""});if(!he.ok)throw new Error(`WHEP ${he.status}: ${he.statusText}`);const V=await he.text();await G.setRemoteDescription({type:"answer",sdp:V})}catch(G){if(!S.current)return;const Z=G instanceof Error?G.message:String(G);E(Z),z("error"),c?.(Z),ne()}}},[e,t,H,z,c]),J=R?F:j,W=ee(()=>{});W.current=J;const ne=q(()=>{S.current&&(N.current>=vM||(N.current+=1,v.current=setTimeout(()=>{S.current&&W.current()},yM)))},[]);X(()=>(S.current=!0,N.current=0,o&&J(),()=>{S.current=!1,H()}),[e,t]);const de=ee(!1);X(()=>{!o||!R||!p||!u||de.current||x.current||(de.current=!0,J())},[o,R,p,u,J]);const te=()=>{N.current=0,J()},K=()=>{g.current&&(g.current.muted=!g.current.muted,A(g.current.muted))},oe=async()=>{if(b.current)try{document.fullscreenElement?await document.exitFullscreen():await b.current.requestFullscreen()}catch(G){console.warn(`Fullscreen toggle failed: ${G instanceof Error?G.message:G}`)}},me=()=>{if(!g.current)return;const G=document.createElement("canvas");G.width=g.current.videoWidth||1280,G.height=g.current.videoHeight||720;const Z=G.getContext("2d");if(!Z)return;Z.drawImage(g.current,0,0);const re=document.createElement("a");re.download=`${t.replace(/[/:]/g,"-")}-${Date.now()}.jpg`,re.href=G.toDataURL("image/jpeg",.92),re.click()};X(()=>{const G=()=>$(!!document.fullscreenElement);return document.addEventListener("fullscreenchange",G),()=>document.removeEventListener("fullscreenchange",G)},[]);const Y=()=>{_(!0),P.current&&clearTimeout(P.current),P.current=setTimeout(()=>_(!1),3e3)};return f("div",{ref:b,className:`relative bg-black overflow-hidden group ${i}`,onMouseMove:Y,onMouseEnter:Y,children:[r("video",{ref:g,autoPlay:o,muted:B,playsInline:!0,className:"w-full h-full object-contain"}),n&&k==="playing"&&r("div",{className:"absolute top-2 left-2 px-2 py-0.5 rounded bg-black/60 text-[10px] text-white font-medium",children:n}),d,k==="connecting"&&f("div",{className:"absolute inset-0 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…"})]}),(k==="error"||k==="disconnected")&&f("div",{className:"absolute inset-0 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:k==="error"?D||"Connection failed":"Disconnected"}),r("button",{onClick:te,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&&k==="playing"&&f("div",{className:`absolute bottom-0 inset-x-0 flex items-center justify-between px-3 py-1.5 bg-gradient-to-t from-black/80 to-transparent transition-opacity duration-200 ${I?"opacity-100":"opacity-0"}`,children:[r("div",{className:"flex items-center gap-1",children:r(ma,{onClick:K,title:B?"Unmute":"Mute",children:B?f("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"})]}):f("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"})]})})}),f("div",{className:"flex items-center gap-1",children:[r(ma,{onClick:me,title:"Take snapshot",children:f("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"})]})}),r(ma,{onClick:oe,title:O?"Exit fullscreen":"Fullscreen",children:O?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 ma({onClick:e,title:t,children:n}){return r("button",{onClick:e,title:t,className:"rounded-full p-1.5 text-white/80 hover:text-white hover:bg-white/20 transition-colors",children:n})}async function yd(e){if(e.iceGatheringState!=="complete")return new Promise(t=>{const n=()=>{e.iceGatheringState==="complete"&&(e.removeEventListener("icegatheringstatechange",n),t())};e.addEventListener("icegatheringstatechange",n),setTimeout(t,5e3)})}const Vl=Qt("camstack:player-overlays-state",null),ql=Qt("camstack:player-overlays-actions",null);function xg({children:e}){const[t,n]=L(()=>new Map),[o,s]=L(()=>new Map),a=q(u=>{n(h=>{const m=new Map(h);return m.set(u.id,u),m})},[]),i=q(u=>{n(h=>{if(!h.has(u))return h;const m=new Map(h);return m.delete(u),m})},[]),l=q(u=>{s(h=>{const m=new Map(h);return m.set(u.id,u),m})},[]),c=q(u=>{s(h=>{if(!h.has(u))return h;const m=new Map(h);return m.delete(u),m})},[]),d=Q(()=>({layers:t,buttons:o}),[t,o]),p=Q(()=>({setLayer:a,removeLayer:i,setButton:l,removeButton:c}),[a,i,l,c]);return r(Vl.Provider,{value:d,children:r(ql.Provider,{value:p,children:e})})}function yg(){const e=ge(Vl);return Q(()=>e?[...e.layers.values()].sort((t,n)=>t.order-n.order):[],[e])}function vg(){const e=ge(Vl);return Q(()=>e?[...e.buttons.values()].sort((t,n)=>t.order-n.order):[],[e])}function wM(e){const t=ge(ql);X(()=>{if(!(!t||!e))return t.setLayer(e),()=>t.removeLayer(e.id)},[t,e])}function NM(e){const t=ge(ql);X(()=>{if(!(!t||!e))return t.setButton(e),()=>t.removeButton(e.id)},[t,e])}function SM(e){return e==="streaming"?"bg-emerald-500":e==="connecting"?"bg-amber-500":e==="error"?"bg-rose-500":"bg-zinc-500"}function kM(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 ui({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 CM({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 MM({className:e}){return f("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 IM({className:e}){return f("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 ga({label:e,active:t,onClick:n}){return f("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 wg({className:e}){return f("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 EM({className:e}){return f("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 Ul({serverUrl:e,createSession:t,sendAnswer:n,closeSession:o,streams:s,activeStreamId:a,onStreamChange:i,deviceName:l,phase:c,pipelineMetrics:d,detections:p,defaultShowDetections:u=!0,defaultShowMotion:h=!1,streamStats:m,autoPlay:g=!1,showPlayStop:b=!1,snapshotSrc:x,snapshotLoading:y=!1,onRefreshSnapshot:w,showStreamStats:v=!1,children:N,extraOverlay:S,ptzAvailable:k=!1,ptzShown:M=!1,ptzOverlay:D,onPtzToggle:E,intercomAvailable:B=!1,intercomShown:A=!1,onIntercomToggle:O,chromeless:$=!1,className:I}){const _=vg(),[P,T]=L(g),[R,z]=L(u),[H,F]=L(h),[j,J]=L(null),[W,ne]=L(!1),de=ee(null);X(()=>{if(!W)return;function ae(ve){de.current&&!de.current.contains(ve.target)&&ne(!1)}return document.addEventListener("mousedown",ae),()=>document.removeEventListener("mousedown",ae)},[W]);const te=a??j??s?.[0]?.id??"",K=s?.find(ae=>ae.id===te)??s?.[0],oe=K?.inputFps!=null?{status:K.status??"unknown",inputFps:K.inputFps,bitrateKbps:K.bitrateKbps??0}:null,me=ae=>{J(ae),i?.(ae),P&&b&&(T(!1),setTimeout(()=>T(!0),50))},Y=Q(()=>{const ae=K?.target;if(ae)return ve=>t(ae,ve)},[t,K]),G=s,Z=()=>T(!0),re=()=>T(!1),pe=d?.phase??c,he=pe==="active",V=!!p,se=V&&(R||H),ce=k&&M&&!!D,ie=b?P:!0;return f("div",{className:`overflow-hidden ${$?"":"rounded-xl border border-border bg-surface"} ${I??""}`,children:[f("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border",children:[f("div",{className:"flex items-center gap-2",children:[(m??oe)&&r("span",{className:`w-2 h-2 rounded-full ${SM((m??oe).status)}`}),l&&r("span",{className:"text-xs font-medium text-foreground",children:l}),G&&G.length>1&&f("div",{className:"relative",children:[r("select",{"data-testid":"stream-profile-select",value:te,onChange:ae=>me(ae.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:G.map(ae=>r("option",{value:ae.id,children:ae.label},ae.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"})})})]})]}),f("div",{className:"flex items-center gap-1.5",children:[B&&f("button",{"data-testid":"stream-intercom-toggle","data-intercom-shown":A?"true":"false",onClick:O,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors ${A?"bg-primary/15 text-primary":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,title:A?"Close intercom":"Open intercom",children:[r(MM,{className:"h-3 w-3"}),r("span",{className:"hidden xl:inline",children:"Intercom"})]}),_.map(ae=>{const ue=ae.tone==="primary"?"bg-primary text-primary-foreground":"bg-primary/15 text-primary";return f("button",{type:"button","data-toolbar-button-id":ae.id,"data-toolbar-button-active":ae.active?"true":"false",onClick:ae.onClick,disabled:ae.disabled,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors disabled:opacity-50 ${ae.active?ue:"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,title:ae.title??ae.label,children:[ae.icon,r("span",{className:"hidden xl:inline",children:ae.label})]},ae.id)}),b&&f("button",{"data-testid":"stream-play-toggle","data-stream-playing":ie?"true":"false",onClick:ie?re:Z,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors ${ie?"bg-danger/10 text-danger hover:bg-danger/20":"bg-primary/10 text-primary hover:bg-primary/20"}`,title:ie?"Stop stream":"Start stream",children:[ie?r(CM,{className:"h-3 w-3"}):r(ui,{className:"h-3 w-3"}),r("span",{className:"hidden xl:inline",children:ie?"Stop":"Play"})]}),w&&f("button",{"data-testid":"stream-snapshot-refresh",onClick:w,disabled:y,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50",title:"Force snapshot refresh",children:[r(wg,{className:`h-3 w-3 ${y?"animate-spin":""}`}),r("span",{className:"hidden xl:inline",children:"Snapshot"})]}),(V||k||d||pe||m||oe&&oe.inputFps>0)&&f("div",{ref:de,className:"relative",children:[r("button",{onClick:()=>ne(ae=>!ae),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(IM,{className:"h-3.5 w-3.5"})}),W&&f("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:[v&&m&&f("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[f("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Input"}),f("span",{className:"tabular-nums text-foreground",children:[m.inputFps.toFixed(1)," fps"]})]}),f("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Decode"}),f("span",{className:"tabular-nums text-foreground",children:[m.decodeFps.toFixed(1)," fps"]})]}),f("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Uptime"}),r("span",{className:"tabular-nums text-foreground",children:kM(m.uptimeMs)})]})]}),!v&&oe&&oe.inputFps>0&&f("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[f("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Input"}),f("span",{className:"tabular-nums text-foreground",children:[oe.inputFps.toFixed(1)," fps"]})]}),oe.bitrateKbps>0&&f("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Bitrate"}),f("span",{className:"tabular-nums text-foreground",children:[oe.bitrateKbps," kbps"]})]})]}),(d||V&&pe)&&f("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[f("div",{className:"flex justify-between gap-3 items-center",children:[r("span",{children:"Phase"}),f("span",{className:`flex items-center gap-1 font-semibold uppercase tracking-wider ${he?"text-red-400":"text-emerald-400"}`,children:[r("span",{className:`w-1.5 h-1.5 rounded-full ${he?"bg-red-500 animate-pulse":"bg-emerald-500"}`}),he?"Active":"Watching"]})]}),d&&d.detectionFps>0&&f("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Detection"}),f("span",{className:"tabular-nums text-foreground",children:[d.detectionFps.toFixed(1)," det/s"]})]}),d&&d.avgInferenceMs>0&&f("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Inference"}),f("span",{className:"tabular-nums text-foreground",children:[d.avgInferenceMs.toFixed(0)," ms"]})]})]}),V&&f(ye,{children:[r(ga,{label:"Show detections",active:R,onClick:()=>z(ae=>!ae)}),r(ga,{label:"Show motion",active:H,onClick:()=>F(ae=>!ae)})]}),k&&r(ga,{label:"PTZ controls",active:M,onClick:()=>{E?.(),ne(!1)}})]})]})]})]}),ie?r("div",{className:"aspect-video relative",children:r(bg,{serverUrl:e,streamKey:te,autoPlay:!0,className:"w-full h-full",createSession:Y,sendAnswer:n,closeSession:o,overlay:se||S||ce?f(ye,{children:[se&&r(gg,{detections:p,showPhaseIndicator:!1,showMotionZones:H,showMotionRaw:H,showDetections:R}),S,ce&&D]}):void 0},te)}):r(PM,{src:x??null,isLoading:y,onPlay:Z,onRetry:w,extraOverlay:S||ce?f(ye,{children:[S,ce&&D]}):null,suppressPlayHover:!!S||ce}),N]})}function PM({src:e,isLoading:t,onPlay:n,onRetry:o,extraOverlay:s,suppressPlayHover:a=!1}){return e?f("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(ui,{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:f("div",{className:"flex flex-col items-center gap-2 text-white/40",children:[r(EM,{className:"h-8 w-8"}),r("span",{className:"text-xs",children:"No snapshot available"}),f("div",{className:"flex items-center gap-2 mt-1",children:[o&&f("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(wg,{className:"h-3 w-3"}),"Retry"]}),f("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(ui,{className:"h-3 w-3"}),"Play Live"]})]})]})})}function AM({samples:e,sampleRate:t=16e3,height:n=96,className:o="",color:s="#3b82f6",bgColor:a="transparent"}){const i=ee(null),l=ee(null),c=q(()=>{const u=i.current,h=l.current;if(!u||!h||!e||e.length===0)return;const m=h.clientWidth;if(m===0)return;const g=window.devicePixelRatio||1;u.width=m*g,u.height=n*g,u.style.width=`${m}px`,u.style.height=`${n}px`;const b=u.getContext("2d");if(!b)return;b.scale(g,g),a!=="transparent"?(b.fillStyle=a,b.fillRect(0,0,m,n)):b.clearRect(0,0,m,n);const x=e.length/m,y=n/2;b.fillStyle=s,b.globalAlpha=.7;for(let w=0;w<m;w++){const v=Math.floor(w*x),N=Math.min(Math.floor((w+1)*x),e.length);let S=0,k=0;for(let B=v;B<N;B++){const A=e[B];A<S&&(S=A),A>k&&(k=A)}const M=y-k*y,D=y-S*y,E=Math.max(1,D-M);b.fillRect(w,M,1,E)}b.globalAlpha=1,b.strokeStyle=s,b.globalAlpha=.2,b.lineWidth=1,b.beginPath(),b.moveTo(0,y),b.lineTo(m,y),b.stroke(),b.globalAlpha=1},[e,n,s,a]);X(()=>{c()},[c]),X(()=>{const u=new ResizeObserver(()=>c()),h=l.current;return h&&u.observe(h),()=>u.disconnect()},[c]);const p=((e&&t?Math.round(e.length/t*1e3):0)/1e3).toFixed(1);return f("div",{ref:l,className:`relative ${o}`,children:[r("canvas",{ref:i,className:"w-full rounded-md"}),e&&e.length>0&&f("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 $M({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=ee(null),p=ee(null),[u,h]=L([]);X(()=>{e!==null&&h(b=>{const x=[...b,{dbfs:e,timestamp:Date.now()}];return x.length>n?x.slice(-n):x})},[e,n]);const m=q(()=>{const b=d.current,x=p.current;if(!b||!x)return;const y=x.clientWidth;if(y===0)return;const w=window.devicePixelRatio||1;b.width=y*w,b.height=o*w,b.style.width=`${y}px`,b.style.height=`${o}px`;const v=b.getContext("2d");if(!v||(v.scale(w,w),v.clearRect(0,0,y,o),u.length===0))return;const N=u[u.length-1].timestamp,S=t*1e3,k=N-S,M=u.filter(A=>A.timestamp>=k);if(M.length===0)return;const D=Math.max(1,Math.floor(y/(t*2))),E=Math.abs(c);for(const A of M){const O=A.timestamp-k,$=Math.floor(O/S*y),_=(Math.max(c,Math.min(0,A.dbfs))-c)/E,P=Math.max(1,_*o),T=A.dbfs>=l;v.fillStyle=T?i:a,v.globalAlpha=.8,v.fillRect($,o-P,D,P)}v.globalAlpha=1;const B=o-(l-c)/E*o;v.strokeStyle=i,v.globalAlpha=.25,v.lineWidth=1,v.setLineDash([4,4]),v.beginPath(),v.moveTo(0,B),v.lineTo(y,B),v.stroke(),v.setLineDash([]),v.globalAlpha=1},[u,t,o,a,i,l,c]);X(()=>{m()},[m]),X(()=>{const b=new ResizeObserver(()=>m()),x=p.current;return x&&b.observe(x),()=>b.disconnect()},[m]);const g=u.length>0?u[u.length-1].dbfs:null;return f("div",{ref:p,className:`relative ${s}`,children:[r("canvas",{ref:d,className:"w-full rounded-md"}),f("div",{className:"absolute top-1 left-2 text-[9px] text-foreground-subtle/50 font-mono",children:[t,"s"]}),g!==null&&f("div",{className:"absolute bottom-1 right-2 text-[9px] text-foreground-subtle/50 font-mono",children:[g.toFixed(1)," dBFS · ",u.length," samples"]})]})}function DM(e){return e>=.8?"bg-emerald-500":e>=.5?"bg-amber-500":e>=.3?"bg-orange-500":"bg-zinc-500"}function _M(e){return e>=.8?"text-emerald-400":e>=.5?"text-amber-400":e>=.3?"text-orange-400":"text-zinc-400"}function TM({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"})}):f("div",{className:`rounded-xl border border-border bg-surface overflow-hidden ${s}`,children:[f("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"}),f("div",{className:"flex items-center gap-3 text-[10px] text-foreground-subtle",children:[a.length<e.length&&f("span",{children:["showing ",a.length," of ",e.length]}),n!==void 0&&f("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 f("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 ${DM(l.score)}`,style:{width:`${d}%`}})}),f("span",{className:`text-xs font-mono font-semibold w-14 text-right ${_M(l.score)}`,children:[(l.score*100).toFixed(1),"%"]})]},`${l.className}-${c}`)})})]})}function RM({data:e,label:t="Response",className:n=""}){const[o,s]=L(!1);if(!e)return null;const a=JSON.stringify(e,null,2);return f("div",{className:`rounded-xl border border-border bg-surface overflow-hidden ${n}`,children:[f("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:[f("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 LM={Activity:Jt,Eye:ks,AlertTriangle:Zr,PauseCircle:Dv,PowerOff:$v};function Ql({phase:e,...t}){const n=An(e),o=LM[n.icon];return r(o,{...t})}function gn(e){const[t,n]=L([]),o=q(a=>{n(i=>{const l=[...i,a];return l.length>e?l.slice(-e):l})},[e]),s=q(()=>{n([])},[]);return Q(()=>({entries:t,append:o,reset:s}),[t,o,s])}function vd(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 wd={error:{icon:Ns,color:"text-red-400"},warn:{icon:Zr,color:"text-amber-400"},info:{icon:Tv,color:"text-blue-400"},debug:{icon:_v,color:"text-gray-500"}},Nd={debug:0,info:1,warn:2,error:3},OM=["all","debug","info","warn","error"],BM=500;function zM(e,t){return t?(Nd[e]??0)>=(Nd[t]??0):!0}function Wt({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:u,className:h}){const[m,g]=L(""),[b,x]=L(""),[y,w]=L(a),v=e,N=t??(m||void 0),S=n??(b?Number(b):void 0),k=o,M=s,D=Q(()=>{const V={};return v&&(V.agentId=v),N&&(V.addonId=N),S!==void 0&&Number.isFinite(S)&&(V.deviceId=S),k&&(V.integrationId=k),M&&(V.requestId=M),Object.keys(V).length>0?V:void 0},[v,N,S,k,M]),E=gn(BM),B=p??E,A=B.entries,[O,$]=L(0),[I,_]=L(!1),[P,T]=L(!1),[R,z]=L(new Set),[H,F]=L(""),j=ee(null),J=`${v??""}:${N??""}:${String(S??"")}:${k??""}:${M??""}`,W=ee(J);X(()=>{W.current!==J&&(W.current=J,B.reset(),$(0),z(new Set))},[J,B]);const{data:ne,isLoading:de}=C.logs.query.useQuery({...D?{tags:D}:{},limit:d},{staleTime:3e4});C.logs.subscribe.useSubscription({...D?{tags:D}:{}},{onData:V=>{B.append(V)}});const te=ee(A.length);X(()=>{const V=j.current;if(!V){te.current=A.length;return}const se=te.current;if(te.current=A.length,!(A.length<=se)){if(I&&V.scrollTop<=8)V.scrollTo({top:0});else if(!I&&V.scrollTop>0){const ce=V.querySelector("tbody tr"),ie=ce instanceof HTMLElement?ce.offsetHeight:24;V.scrollTop+=ie*(A.length-se)}}},[A.length,I]);const K=Q(()=>{const V=(ne??[]).map(ue=>({timestamp:ue.timestamp,level:ue.level,message:ue.message,scope:ue.scope,tags:ue.tags,meta:ue.meta})),se=new Set,ce=[];for(const ue of[...A].reverse()){const Ne=`${ue.timestamp}|${ue.level}|${ue.scope??""}|${ue.message}`;se.has(Ne)||(se.add(Ne),ce.push(ue))}for(const ue of V){const Ne=`${ue.timestamp}|${ue.level}|${ue.scope??""}|${ue.message}`;se.has(Ne)||(se.add(Ne),ce.push(ue))}const ae=(O>0?ce.filter(ue=>new Date(ue.timestamp).getTime()>O):ce).filter(ue=>zM(ue.level,y)),ve=H.trim().toLowerCase();return ve?ae.filter(ue=>{if(ue.message.toLowerCase().includes(ve)||ue.scope&&ue.scope.toLowerCase().includes(ve))return!0;if(ue.tags){for(const Ne of Object.values(ue.tags))if(Ne!==void 0&&String(Ne).toLowerCase().includes(ve))return!0}if(ue.meta){for(const Ne of Object.values(ue.meta))if(Ne!=null&&vd(Ne).toLowerCase().includes(ve))return!0}return!1}):ae},[ne,A,y,O,H]),oe=q(()=>{const V=K.map(se=>{const ce=new Date(se.timestamp).toLocaleTimeString(),ie=se.tags?" "+Object.entries(se.tags).filter(([,ae])=>ae).map(([ae,ve])=>`${ae}=${ve}`).join(" "):"";return`${ce} [${se.level.toUpperCase()}]${se.scope?` [${se.scope}]`:""}${ie} ${se.message}`});navigator.clipboard.writeText(V.join(`
32
- `)).then(()=>{T(!0),setTimeout(()=>T(!1),1500)})},[K]),me=C.logs.clear.useMutation(),Y=q(()=>{$(Date.now()),B.reset(),me.mutate({...D?{tags:D}:{}})},[B,me,D]),G=q(V=>{z(se=>{const ce=new Set(se);return ce.has(V)?ce.delete(V):ce.add(V),ce})},[]),[Z,re]=L(null),pe=q((V,se)=>{const ce=new Date(V.timestamp).toISOString(),ie=V.tags?" "+Object.entries(V.tags).filter(([,ue])=>ue).map(([ue,Ne])=>`${ue}=${Ne}`).join(" "):"",ae=V.meta&&Object.keys(V.meta).length>0?` meta=${JSON.stringify(V.meta)}`:"",ve=`${ce} [${V.level.toUpperCase()}]${V.scope?` [${V.scope}]`:""}${ie} ${V.message}${ae}`;navigator.clipboard.writeText(ve).then(()=>{re(se),setTimeout(()=>re(ue=>ue===se?null:ue),1200)})},[]),he=q(V=>`${V.timestamp}|${V.level}|${V.scope??""}|${V.message}`,[]);return f("div",{className:U("h-full min-h-0 flex flex-col",h),onClick:V=>V.stopPropagation(),children:[f("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0",children:[f("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(ba,{label:"agent",value:v}),N&&r(ba,{label:"addon",value:N}),S!==void 0&&r(ba,{label:"device",value:`#${S}`}),r("div",{className:"flex rounded border border-border overflow-hidden text-[9px]",children:OM.map(V=>f("button",{type:"button",onClick:()=>w(V==="all"?void 0:V),className:U("px-1.5 py-0.5 capitalize transition-colors",V==="all"&&!y||y===V?"bg-primary/10 text-primary":"text-foreground-subtle hover:bg-surface-hover",V!=="all"&&"border-l border-border"),children:[V,V!=="all"?"+":""]},V))}),r(xa,{icon:nl,label:I?"Auto":"Paused",active:!I,onClick:()=>{_(V=>!V),!I&&j.current&&j.current.scrollTo({top:0,behavior:"smooth"})}}),r(xa,{icon:nn,label:P?"Copied!":"Copy",onClick:oe,disabled:K.length===0}),r(xa,{icon:zt,label:"Clear",onClick:Y}),f("div",{className:"relative",children:[r("input",{type:"text",value:H,onChange:V=>F(V.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"}),H&&r("button",{type:"button",onClick:()=>F(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",title:"Clear search",children:r(Ve,{className:"h-2.5 w-2.5"})})]}),A.length>0&&f("span",{className:"text-[9px] text-emerald-400 font-medium",children:["+",A.length," live"]})]}),u&&r("button",{type:"button",onClick:u,className:"text-foreground-subtle hover:text-foreground",children:r(Ve,{className:"h-3.5 w-3.5"})})]}),c&&(!t||!n)&&f("div",{className:"flex items-center gap-2 px-3 py-1 border-b border-border/50 bg-surface/50 text-[10px]",children:[!t&&f("label",{className:"flex items-center gap-1",children:[r("span",{className:"text-foreground-subtle",children:"Addon:"}),r("input",{type:"text",value:m,onChange:V=>g(V.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&&f("label",{className:"flex items-center gap-1",children:[r("span",{className:"text-foreground-subtle",children:"Device:"}),r("input",{type:"text",inputMode:"numeric",value:b,onChange:V=>x(V.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"})]})]}),f("div",{ref:j,className:U("flex-1 min-h-0 overflow-auto font-mono text-[10px]",i),children:[de&&f("div",{className:"flex items-center justify-center gap-2 py-6 text-foreground-subtle",children:[r(Mt,{className:"h-3.5 w-3.5 animate-spin"}),"Loading logs..."]}),!de&&K.length===0&&r("div",{className:"py-4 text-center text-foreground-subtle",children:"No logs found"}),K.length>0&&r("table",{className:"w-full",children:r("tbody",{children:K.map(V=>{const se=wd[V.level]??wd.info,ce=se.icon,ie=he(V),ae=R.has(ie),ve=V.tags&&Object.keys(V.tags).length>0,ue=V.meta&&Object.keys(V.meta).length>0,Ne=ve||ue;return f("tr",{className:U("hover:bg-surface-hover/30 border-b border-border/30",Ne&&"cursor-pointer"),onClick:Ne?()=>G(ie):void 0,children:[r("td",{className:"px-2 py-1 text-foreground-subtle whitespace-nowrap align-top w-[70px]",children:new Date(V.timestamp).toLocaleTimeString()}),r("td",{className:U("px-1 py-1 align-top w-5",se.color),children:r(ce,{className:"h-3 w-3"})}),l&&r("td",{className:"px-2 py-1 text-foreground-subtle align-top truncate max-w-[120px]",title:V.scope,children:V.scope?.replace(/^addon:/,"")??""}),r("td",{className:"px-2 py-1 text-foreground break-all",children:f("div",{className:"flex items-start gap-1",children:[Ne&&(ae?r(Pn,{className:"h-3 w-3 text-foreground-subtle shrink-0 mt-0.5"}):r(Ut,{className:"h-3 w-3 text-foreground-subtle shrink-0 mt-0.5"})),f("div",{className:"flex-1 min-w-0",children:[V.message,ae&&Ne&&f("div",{className:"mt-1 text-[9px] text-foreground-subtle bg-surface rounded px-2 py-1 space-y-0.5",children:[ue&&Object.entries(V.meta).filter(([,Ee])=>Ee!==void 0&&Ee!=="").map(([Ee,He])=>f("div",{children:[r("span",{className:"text-amber-400/80 font-medium",children:Ee}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground break-all",children:vd(He)})]},`m-${Ee}`)),ve&&Object.entries(V.tags).filter(([,Ee])=>Ee!==void 0).map(([Ee,He])=>f("div",{children:[r("span",{className:"text-primary/70 font-medium",children:Ee}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground",children:He})]},`t-${Ee}`))]})]})]})}),r("td",{className:"px-1 py-1 align-top w-5",children:r(FM,{copied:Z===ie,onCopy:()=>pe(V,ie)})})]},ie)})})})]})]})}function Ng({position:e="bottom",className:t,...n}){return r("div",{className:U(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(Wt,{maxHeight:"max-h-48",...n})})}function ba({label:e,value:t}){return f("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium",children:[e,": ",t]})}function FM({copied:e,onCopy:t}){return r("button",{type:"button",title:"Copy this row",onClick:n=>{n.stopPropagation(),t()},className:U("rounded p-0.5 transition-colors",e?"text-emerald-400":"text-foreground-subtle/60 hover:text-foreground hover:bg-surface-hover"),children:e?r(Yr,{className:"h-3 w-3"}):r(nn,{className:"h-3 w-3"})})}function xa({icon:e,label:t,onClick:n,disabled:o,active:s}){return f("button",{type:"button",onClick:n,disabled:o,className:U("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 HM(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 jM={[xe.AddonStarted]:{icon:Ja,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Started"},[xe.AddonInstalled]:{icon:Xa,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Installed"},[xe.AddonRestarted]:{icon:tl,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Restarted"},[xe.AddonUpdated]:{icon:rp,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Updated"},[xe.AddonStopped]:{icon:Uc,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"Stopped"},[xe.AddonUninstalled]:{icon:zt,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"Uninstalled"},[xe.AddonCrashed]:{icon:Ns,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Crashed"},[xe.AddonError]:{icon:Zr,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Error"},[xe.DetectionPhaseTransition]:{icon:Jt,color:"bg-violet-500/15 text-violet-400 border-violet-500/30",label:"Phase"},[xe.DetectionResult]:{icon:Rv,color:"bg-purple-500/15 text-purple-400 border-purple-500/30",label:"Detection"},[xe.DetectionEvent]:{icon:ks,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Event"},[xe.DetectionCameraNative]:{icon:Qc,color:"bg-cyan-500/15 text-cyan-400 border-cyan-500/30",label:"Camera AI"},[xe.ProviderMotion]:{icon:Gc,color:"bg-orange-500/15 text-orange-400 border-orange-500/30",label:"Motion"},[xe.MotionOnMotionChanged]:{icon:Gc,color:"bg-orange-500/15 text-orange-400 border-orange-500/30",label:"Motion"},[xe.MotionAnalysis]:{icon:Jt,color:"bg-orange-500/10 text-orange-300 border-orange-500/20",label:"Motion analysis"},[xe.MotionZonesRaw]:{icon:Jt,color:"bg-orange-500/10 text-orange-300 border-orange-500/20",label:"Motion zones"},[xe.ProviderDetection]:{icon:Qc,color:"bg-cyan-500/15 text-cyan-400 border-cyan-500/30",label:"Provider Det"},[xe.PipelineAudioInferenceResult]:{icon:Jf,color:"bg-pink-500/15 text-pink-400 border-pink-500/30",label:"Audio"},[xe.AgentOnline]:{icon:Ja,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Agent Online"},[xe.AgentOffline]:{icon:Uc,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Agent Offline"},[xe.DeviceRegistered]:{icon:Xa,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Registered"},[xe.DeviceUnregistered]:{icon:zt,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Unregistered"},[xe.DeviceStateChanged]:{icon:Jt,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"State"}};function fi(e,t){const n=jM[e]??{icon:Ja,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:e.split(".").pop()??e};if(e===xe.DeviceStateChanged&&t&&typeof t.capName=="string"){const o=t.capName;return{...n,label:o}}return n}const Ln=Object.freeze([...new Set(Object.values(xe))].sort()),VM=Object.freeze([xe.PipelineCameraMetricsSnapshot,xe.PipelineRunnerLoadSnapshot,xe.PipelineEngineMetricsSnapshot,xe.PipelineInferenceResult,xe.PipelineTrace,xe.PipelineProgress,xe.StreamBrokerMetricsSnapshot,xe.MetricsNodeResourcesSnapshot,xe.MetricsNodeProcessesSnapshot,xe.ClusterTopologySnapshot,xe.MotionAnalysis,xe.MotionZonesRaw,xe.DetectionResult,xe.PipelineAudioInferenceResult,xe.PlatformProbePhase,xe.BenchmarkProgress,xe.ModelDownloadProgress]),qM=new Set(VM),UM=Object.freeze(Ln.filter(e=>!qM.has(e)));function zo(e,t){if(e===xe.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===xe.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===xe.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===xe.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===xe.ProviderMotion)return t.active===!0?"motion start":"motion stop";if(e===xe.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===xe.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===xe.ProviderDetection||e===xe.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 QM(e){const t=e.category;return t===xe.DetectionResult||t===xe.PipelineAudioInferenceResult?zo(t,e.data)!==null:!0}const GM=300;function cr({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:u,className:h}){const m=Q(()=>o??s??UM,[o,s]),g=Q(()=>[...m].sort().join(","),[m]),[b,x]=L(()=>new Set(m)),y=ee(g);X(()=>{y.current!==g&&(y.current=g,x(new Set(m)))},[g,m]);const w=gn(GM),v=p??w,N=v.entries,[S,k]=L(!0),[M,D]=L(new Set),[E,B]=L(""),[A,O]=L(!1),[$,I]=L(""),[_,P]=L(0),T=ee(null),R=ee(null),z=`${e??""}:${t??""}:${String(n??"")}:${a??""}`,H=ee(z);X(()=>{H.current!==z&&(H.current=z,v.reset(),D(new Set),P(0))},[z,v]),X(()=>{if(!A)return;const fe=Ce=>{const Ie=R.current;Ie&&Ce.target instanceof Node&&!Ie.contains(Ce.target)&&O(!1)};return document.addEventListener("mousedown",fe),()=>{document.removeEventListener("mousedown",fe)}},[A]);const F=Q(()=>{const fe={};return e&&(fe.agentId=e),t&&(fe.addonId=t),n!==void 0&&(fe.deviceId=n),a&&(fe.category=a),fe},[e,t,n,a]),j=Q(()=>[...b].sort(),[b]),J=Q(()=>j.join(","),[j]),W=Q(()=>{const fe={...F,limit:l};return j.length>0&&j.length<Ln.length&&(fe.category=j),fe},[F,l,J,j]),{data:ne,isLoading:de}=C.systemEvents.getRecent.useQuery(W,{staleTime:3e4}),te=ee(b);X(()=>{te.current=b},[b]);const K=F;C.systemEvents.subscribe.useSubscription(K,{onData:fe=>{const Ce=fe;Ce?.id&&HM(Ce,e,t,n)&&te.current.has(Ce.category)&&v.append(Ce)}});const oe=ee(N.length);X(()=>{const fe=T.current;if(!fe){oe.current=N.length;return}const Ce=oe.current;if(oe.current=N.length,!(N.length<=Ce)){if(S&&fe.scrollTop<=8)fe.scrollTo({top:0});else if(!S&&fe.scrollTop>0){const Ie=fe.firstElementChild?.firstElementChild,Pe=Ie instanceof HTMLElement?Ie.offsetHeight:28;fe.scrollTop+=Pe*(N.length-Ce)}}},[N.length,S]);const me=Q(()=>{const fe=new Map;for(const Pe of ne??[])fe.set(Pe.id,Pe);for(const Pe of N)fe.set(Pe.id,Pe);let Ce=[...fe.values()].filter(Pe=>b.has(Pe.category)).filter(QM);_>0&&(Ce=Ce.filter(Pe=>new Date(Pe.timestamp).getTime()>_));const Ie=E.trim().toLowerCase();return Ie&&(Ce=Ce.filter(Pe=>{if(Pe.category.toLowerCase().includes(Ie)||fi(Pe.category,Pe.data).label.toLowerCase().includes(Ie))return!0;const ln=zo(Pe.category,Pe.data);if(ln&&ln.toLowerCase().includes(Ie))return!0;try{if(new Date(Pe.timestamp).toLocaleTimeString().toLowerCase().includes(Ie))return!0}catch{}try{if(JSON.stringify(Pe.data).toLowerCase().includes(Ie)||JSON.stringify(Pe.source).toLowerCase().includes(Ie))return!0}catch{}return!1})),Ce.sort((Pe,an)=>new Date(an.timestamp).getTime()-new Date(Pe.timestamp).getTime())},[ne,N,b,E,_]),Y=q(fe=>{D(Ce=>{const Ie=new Set(Ce);return Ie.has(fe)?Ie.delete(fe):Ie.add(fe),Ie})},[]),G=q(fe=>{x(Ce=>{const Ie=new Set(Ce);return Ie.has(fe)?Ie.delete(fe):Ie.add(fe),Ie})},[]),Z=q(()=>{x(new Set(m)),B(""),P(0)},[m]),re=q(()=>{P(Date.now()),v.reset()},[v]),[pe,he]=L(!1),[V,se]=L(null),ce=q(fe=>{const Ce=new Date(fe.timestamp).toISOString(),Ie=zo(fe.category,fe.data)??"",Pe=Ie?` ${Ie}`:"";return`${Ce} [${fe.category}]${Pe} data=${JSON.stringify(fe.data)}`},[]),ie=q(()=>{const fe=me.map(ce);navigator.clipboard.writeText(fe.join(`
33
- `)).then(()=>{he(!0),setTimeout(()=>he(!1),1500)})},[me,ce]),ae=q(fe=>{navigator.clipboard.writeText(ce(fe)).then(()=>{se(fe.id),setTimeout(()=>se(Ce=>Ce===fe.id?null:Ce),1200)})},[ce]),ve=q(()=>{x(new Set(Ln))},[]),ue=q(()=>{x(new Set)},[]),Ne=Q(()=>{const fe=$.trim().toLowerCase();return fe?Ln.filter(Ce=>Ce.toLowerCase().includes(fe)):Ln},[$]),Ee=Ln.length,He=b.size,We=He===Ee,Tn=We?"All":`${He}/${Ee}`;return f("div",{className:U("h-full min-h-0 flex flex-col",h),onClick:fe=>fe.stopPropagation(),children:[f("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0",children:[f("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(go,{label:"agent",value:e}),t&&r(go,{label:"addon",value:t}),n!==void 0&&r(go,{label:"device",value:`#${n}`}),a&&r(go,{label:"category",value:a}),f("button",{type:"button",onClick:()=>{k(fe=>!fe),!S&&T.current&&T.current.scrollTo({top:0,behavior:"smooth"})},className:U("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",S?"border-border text-foreground-subtle hover:text-foreground":"border-amber-500/30 bg-amber-500/10 text-amber-400"),children:[r(nl,{className:"h-2.5 w-2.5"}),S?"Auto":"Paused"]}),c&&f("div",{className:"relative",ref:R,children:[f("button",{type:"button",onClick:()=>O(fe=>!fe),className:U("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",We?"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(sp,{className:"h-2.5 w-2.5"}),"Filter (",Tn,")"]}),A&&r(WM,{search:$,onSearchChange:I,categories:Ne,active:b,onToggle:G,onSelectAll:ve,onSelectNone:ue,onResetDefaults:Z})]}),f("button",{type:"button",onClick:Z,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(ap,{className:"h-2.5 w-2.5"}),"Reset"]}),f("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:"Clear visible entries",children:[r(zt,{className:"h-2.5 w-2.5"}),"Clear"]}),f("button",{type:"button",onClick:ie,disabled:me.length===0,className:U("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",pe?"border-emerald-500/30 bg-emerald-500/10 text-emerald-400":"border-border text-foreground-subtle hover:text-foreground",me.length===0&&"opacity-40 cursor-not-allowed"),title:"Copy all visible events",children:[r(nn,{className:"h-2.5 w-2.5"}),pe?"Copied!":"Copy"]}),f("div",{className:"relative",children:[r("input",{type:"text",value:E,onChange:fe=>B(fe.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"}),E&&r("button",{type:"button",onClick:()=>B(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",title:"Clear search",children:r(Ve,{className:"h-2.5 w-2.5"})})]}),N.length>0&&f("span",{className:"text-[9px] text-emerald-400 font-medium",children:["+",N.length," live"]})]}),u&&r("button",{type:"button",onClick:u,className:"text-foreground-subtle hover:text-foreground",children:r(Ve,{className:"h-3.5 w-3.5"})})]}),f("div",{ref:T,className:U("flex-1 min-h-0 overflow-auto text-[10px]",i),children:[de&&f("div",{className:"flex items-center justify-center gap-2 py-6 text-foreground-subtle",children:[r(Mt,{className:"h-3.5 w-3.5 animate-spin"}),"Loading events..."]}),!de&&me.length===0&&r("div",{className:"py-4 text-center text-foreground-subtle",children:"No events found"}),me.length>0&&r("div",{className:"divide-y divide-border/30",children:me.map(fe=>{const Ce=fi(fe.category,fe.data),Ie=Ce.icon,Pe=zo(fe.category,fe.data),an=M.has(fe.id);return f("div",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-surface-hover/30 cursor-pointer",onClick:()=>Y(fe.id),children:[r("span",{className:"text-foreground-subtle whitespace-nowrap w-[70px] shrink-0 pt-0.5",children:new Date(fe.timestamp).toLocaleTimeString()}),r(YM,{copied:V===fe.id,onCopy:()=>ae(fe)}),f("div",{className:"flex-1 min-w-0",children:[f("div",{className:"flex items-center gap-1.5",children:[an?r(Pn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}):r(Ut,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),f("span",{className:U("inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[9px] font-medium",Ce.color),children:[r(Ie,{className:"h-2.5 w-2.5"}),Ce.label]}),fe.source.nodeId&&fe.source.nodeId!=="hub"&&r("span",{className:"text-[9px] px-1 py-0.5 rounded bg-foreground-subtle/10 text-foreground-subtle font-mono",children:fe.source.nodeId})]}),Pe&&r("p",{className:"text-foreground-subtle text-[10px] mt-0.5 ml-5",children:Pe}),an&&f("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:[f("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(fe.source)})]}),f("div",{children:[r("span",{className:"text-primary/70",children:"category"}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground",children:fe.category})]}),Object.entries(fe.data).map(([ln,pr])=>f("div",{children:[r("span",{className:"text-primary/70",children:ln}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground break-all",children:typeof pr=="object"?JSON.stringify(pr):String(pr)})]},ln))]})]})]},fe.id)})})]})]})}function WM({search:e,onSearchChange:t,categories:n,active:o,onToggle:s,onSelectAll:a,onSelectNone:i,onResetDefaults:l}){return f("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:[f("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border/50",children:[r(_r,{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(Ve,{className:"h-2.5 w-2.5"})})]}),f("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"})]}),f("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=fi(c),u=p.icon;return f("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"}),f("span",{className:U("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(u,{className:"h-2.5 w-2.5"}),p.label]}),r("span",{className:"text-foreground-subtle font-mono truncate",children:c})]},c)})]})]})}function KM({position:e="bottom",className:t,...n}){return r("div",{className:U(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(cr,{maxHeight:"max-h-48",...n})})}function go({label:e,value:t}){return f("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium",children:[e,": ",t]})}function YM({copied:e,onCopy:t}){return r("button",{type:"button",title:"Copy this event",onClick:n=>{n.stopPropagation(),t()},className:U("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(Yr,{className:"h-3 w-3"}):r(nn,{className:"h-3 w-3"})})}function Sg({deviceId:e,className:t="",onOpenChild:n}){const o=C.useUtils(),s=C.deviceDiscovery.listDiscovered.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),a=C.deviceDiscovery.getStatus.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),i=C.deviceDiscovery.refreshDiscovery.useMutation({onSuccess:()=>{o.deviceDiscovery.listDiscovered.invalidate({deviceId:e}),o.deviceDiscovery.getStatus.invalidate({deviceId:e})}}),l=C.deviceDiscovery.adoptDevice.useMutation({onSuccess:()=>{o.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),c=C.deviceDiscovery.releaseDevice.useMutation({onSuccess:()=>{o.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),[d,p]=L(null),{available:u,adopted:h}=Q(()=>{const v=s.data??[],N=k=>typeof k.metadata.rtspChannel=="number"?k.metadata.rtspChannel:Number.POSITIVE_INFINITY,S=(k,M)=>{const D=N(k),E=N(M);return D!==E?D-E:k.name.localeCompare(M.name)};return{available:v.filter(k=>!k.alreadyAdopted).sort(S),adopted:v.filter(k=>k.alreadyAdopted).sort(S)}},[s.data]),m=a.data,g=m?.lastError??null,b=m?.lastDiscoveryAt??null;async function x(){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 f("div",{className:`rounded-xl border border-border bg-surface ${t}`,children:[f("div",{className:"flex items-start justify-between gap-2 border-b border-border px-3 py-2 sm:px-5 sm:py-3",children:[f("div",{className:"min-w-0",children:[r("h3",{className:"text-sm font-semibold text-foreground",children:"Discovered devices"}),f("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."]})]}),f("button",{type:"button",onClick:x,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(Mt,{className:"h-3.5 w-3.5 animate-spin"}):r(tl,{className:"h-3.5 w-3.5"}),r("span",{className:"hidden sm:inline",children:"Refresh"})]})]}),g?f("div",{className:"flex items-start gap-2 border-b border-border bg-destructive/10 px-5 py-2 text-[11px] text-destructive",children:[r(Zr,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),f("span",{children:["Last refresh failed: ",g]})]}):null,s.isLoading?r("div",{className:"flex items-center justify-center py-8 text-foreground-subtle",children:r(Mt,{className:"h-5 w-5 animate-spin"})}):u.length===0&&h.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."}):f(ye,{children:[u.length>0?r(Sd,{title:"Available to add",count:u.length,tone:"primary",children:u.map(v=>r(kd,{child:v,busy:d===v.childNativeId,onAdopt:y,onRelease:w,onOpenChild:n},v.childNativeId))}):null,h.length>0?r(Sd,{title:"Already adopted",count:h.length,tone:"muted",children:h.map(v=>r(kd,{child:v,busy:d===v.childNativeId,onAdopt:y,onRelease:w,onOpenChild:n},v.childNativeId))}):null]}),b!=null?f("div",{className:"border-t border-border px-5 py-2 text-[10px] text-foreground-subtle",children:["Last refreshed ",new Date(b).toLocaleString()]}):null]})}function Sd({title:e,count:t,tone:n,children:o}){return f("div",{className:"border-t border-border",children:[f("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 kd({child:e,busy:t,onAdopt:n,onRelease:o,onOpenChild:s}){return f("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:[f("div",{className:"min-w-0 flex-1",children:[f("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[r(ZM,{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]}),f("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"?f("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?f("span",{className:"font-mono truncate max-w-[140px]",children:[e.metadata.uid.slice(0,12),"…"]}):null]})]}),e.alreadyAdopted?f("div",{className:"flex items-center gap-2",children:[s&&e.adoptedDeviceId!==null?f("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(op,{className:"h-3.5 w-3.5"}),"Open"]}):null,f("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(Mt,{className:"h-3.5 w-3.5 animate-spin"}):r(zt,{className:"h-3.5 w-3.5"}),"Remove"]})]}):f("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(Mt,{className:"h-3.5 w-3.5 animate-spin"}):r(el,{className:"h-3.5 w-3.5"}),"Add"]})]})}function ZM({status:e}){switch(e){case"online":return f("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(np,{className:"h-2.5 w-2.5"})," online"]});case"sleeping":return f("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(Zi,{className:"h-2.5 w-2.5"})," sleeping"]});case"offline":return f("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(Lv,{className:"h-2.5 w-2.5"})," offline"]});case"unknown":default:return f("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(Hf,{className:"h-2.5 w-2.5"})," unknown"]})}}function XM(e,t){if(!e||typeof e!="object")return!1;const n=e;if(n.category!==xe.DeviceStateChanged)return!1;const o=n.data;return!(!o||typeof o!="object"||o.deviceId!==t||typeof o.capName!="string"||!o.slice||typeof o.slice!="object")}function ya(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.id=="string"?t.id:null,o=typeof t.timestamp=="string"?t.timestamp:null,s=t.data;return!n||!o||!s||typeof s!="object"||typeof s.capName!="string"||!s.slice||typeof s.slice!="object"?null:{id:n,timestamp:o,capName:s.capName,slice:s.slice}}const JM=300,eI=Object.freeze([...new Set(Qv.filter(e=>e.scope==="device").map(e=>e.name))].sort());function Gl({deviceId:e,defaultCaps:t,maxHeight:n="max-h-96",limit:o=50,liveBuffer:s,onClose:a,className:i}){const l=Q(()=>new Set(t??[]),[t]),[c,d]=L(l),[p,u]=L(""),[h,m]=L(!0),[g,b]=L(new Set),[x,y]=L(0),[w,v]=L(!1),[N,S]=L(""),k=ee(null),M=gn(JM),D=s??M,E=D.entries,B=ee(null),A=ee(e);X(()=>{A.current!==e&&(A.current=e,D.reset(),b(new Set),y(0))},[e,D]);const O=Q(()=>({deviceId:e,category:xe.DeviceStateChanged,limit:o}),[e,o]),{data:$,isLoading:I}=C.systemEvents.getRecent.useQuery(O,{staleTime:3e4}),_=ee(c);X(()=>{_.current=c},[c]),C.systemEvents.subscribe.useSubscription({deviceId:e,category:xe.DeviceStateChanged},{onData:V=>{if(!XM(V,e))return;const se=ya(V);if(!se)return;const ce=_.current;ce.size>0&&!ce.has(se.capName)||D.append(se)}});const P=ee(E.length);X(()=>{const V=B.current;if(!V){P.current=E.length;return}const se=P.current;if(P.current=E.length,!(E.length<=se)){if(h&&V.scrollTop<=8)V.scrollTo({top:0});else if(!h&&V.scrollTop>0){const ce=V.firstElementChild?.firstElementChild,ie=ce instanceof HTMLElement?ce.offsetHeight:28,ae=E.length-se;V.scrollTop+=ie*ae}}},[E.length,h]);const T=Q(()=>{const V=new Map;for(const ie of $??[]){const ae=ya(ie);ae&&V.set(ae.id,ae)}for(const ie of E)V.set(ie.id,ie);let se=[...V.values()];x>0&&(se=se.filter(ie=>new Date(ie.timestamp).getTime()>x)),c.size>0&&(se=se.filter(ie=>c.has(ie.capName)));const ce=p.trim().toLowerCase();return ce&&(se=se.filter(ie=>{if(ie.capName.toLowerCase().includes(ce))return!0;try{if(new Date(ie.timestamp).toLocaleTimeString().toLowerCase().includes(ce))return!0}catch{}try{if(Object.entries(ie.slice).map(([ve,ue])=>`${ve}=${va(ue)}`).join(" · ").toLowerCase().includes(ce))return!0}catch{}try{if(JSON.stringify(ie.slice).toLowerCase().includes(ce))return!0}catch{}return!1})),se.sort((ie,ae)=>new Date(ae.timestamp).getTime()-new Date(ie.timestamp).getTime())},[$,E,c,p,x]),R=Q(()=>{const V=new Set(eI);for(const se of $??[]){const ce=ya(se);ce&&V.add(ce.capName)}for(const se of E)V.add(se.capName);return[...V].sort()},[$,E]),z=q(V=>{b(se=>{const ce=new Set(se);return ce.has(V)?ce.delete(V):ce.add(V),ce})},[]),H=q(V=>{d(se=>{const ce=new Set(se);return ce.has(V)?ce.delete(V):ce.add(V),ce})},[]),F=q(()=>{d(new Set(t??[])),u("")},[t]),j=q(()=>{y(Date.now()),D.reset()},[D]),[J,W]=L(!1),[ne,de]=L(null),te=q(V=>`${new Date(V.timestamp).toISOString()} [${V.capName}] slice=${JSON.stringify(V.slice)}`,[]),K=q(()=>{const V=T.map(te);navigator.clipboard.writeText(V.join(`
34
- `)).then(()=>{W(!0),setTimeout(()=>W(!1),1500)})},[T,te]),oe=q(V=>{navigator.clipboard.writeText(te(V)).then(()=>{de(V.id),setTimeout(()=>de(se=>se===V.id?null:se),1200)})},[te]),me=q(()=>{d(new Set(R))},[R]),Y=q(()=>{d(new Set)},[]),G=Q(()=>{const V=N.trim().toLowerCase();return V?R.filter(se=>se.toLowerCase().includes(V)):R},[N,R]),Z=R.length,re=c.size,pe=re===0||re===Z,he=pe?"All":`${re}/${Z}`;return X(()=>{if(!w)return;const V=se=>{const ce=k.current;ce&&!ce.contains(se.target)&&v(!1)};return document.addEventListener("mousedown",V),()=>document.removeEventListener("mousedown",V)},[w]),f("div",{className:U("h-full min-h-0 flex flex-col",i),onClick:V=>V.stopPropagation(),children:[f("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0",children:[f("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(tI,{label:"device",value:`#${e}`}),f("button",{type:"button",onClick:()=>{m(V=>!V),!h&&B.current&&B.current.scrollTo({top:0,behavior:"smooth"})},className:U("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",h?"border-border text-foreground-subtle hover:text-foreground":"border-amber-500/30 bg-amber-500/10 text-amber-400"),children:[r(nl,{className:"h-2.5 w-2.5"}),h?"Auto":"Paused"]}),f("div",{className:"relative",ref:k,children:[f("button",{type:"button",onClick:()=>v(V=>!V),className:U("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",pe?"border-border text-foreground-subtle hover:text-foreground":"border-violet-500/30 bg-violet-500/10 text-violet-400"),title:"Pick caps to track",children:[r(sp,{className:"h-2.5 w-2.5"}),"Filter (",he,")"]}),w&&r(nI,{search:N,onSearchChange:S,caps:G,active:c,onToggle:H,onSelectAll:me,onSelectNone:Y,onResetDefaults:F})]}),f("button",{type:"button",onClick:F,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(ap,{className:"h-2.5 w-2.5"}),"Reset"]}),f("button",{type:"button",onClick:j,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(zt,{className:"h-2.5 w-2.5"}),"Clear"]}),f("button",{type:"button",onClick:K,disabled:T.length===0,className:U("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",J?"border-emerald-500/30 bg-emerald-500/10 text-emerald-400":"border-border text-foreground-subtle hover:text-foreground",T.length===0&&"opacity-40 cursor-not-allowed"),title:"Copy all visible state changes",children:[r(nn,{className:"h-2.5 w-2.5"}),J?"Copied!":"Copy"]}),f("div",{className:"relative",children:[r("input",{type:"text",value:p,onChange:V=>u(V.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"}),p&&r("button",{type:"button",onClick:()=>u(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",title:"Clear search",children:r(Ve,{className:"h-2.5 w-2.5"})})]}),E.length>0&&f("span",{className:"text-[9px] text-emerald-400 font-medium",children:["+",E.length," live"]})]}),a&&r("button",{type:"button",onClick:a,className:"text-foreground-subtle hover:text-foreground",children:r(Ve,{className:"h-3.5 w-3.5"})})]}),f("div",{ref:B,className:U("flex-1 min-h-0 overflow-auto text-[10px]",n),children:[I&&f("div",{className:"flex items-center justify-center gap-2 py-6 text-foreground-subtle",children:[r(Mt,{className:"h-3.5 w-3.5 animate-spin"}),"Loading state changes..."]}),!I&&T.length===0&&r("div",{className:"py-4 text-center text-foreground-subtle",children:"No state changes"}),T.length>0&&r("div",{className:"divide-y divide-border/30",children:T.map(V=>{const se=g.has(V.id),ce=Object.entries(V.slice),ie=ce.slice(0,3).map(([ae,ve])=>`${ae}=${va(ve)}`).join(" · ");return f("div",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-surface-hover/30 cursor-pointer",onClick:()=>z(V.id),children:[r("span",{className:"text-foreground-subtle whitespace-nowrap w-[70px] shrink-0 pt-0.5",children:new Date(V.timestamp).toLocaleTimeString()}),r(rI,{copied:ne===V.id,onCopy:()=>oe(V)}),f("div",{className:"flex-1 min-w-0",children:[f("div",{className:"flex items-center gap-1.5",children:[se?r(Pn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}):r(Ut,{className:"h-3 w-3 text-foreground-subtle shrink-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",children:V.capName}),ce.length>3&&f("span",{className:"text-[9px] text-foreground-subtle",children:["+",ce.length-3," more"]})]}),ie&&r("p",{className:"text-foreground-subtle text-[10px] mt-0.5 ml-5 truncate",children:ie}),se&&r("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:ce.length===0?r("div",{className:"text-foreground-subtle italic",children:"empty slice"}):ce.map(([ae,ve])=>f("div",{children:[r("span",{className:"text-primary/70",children:ae}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground break-all",children:va(ve)})]},ae))})]})]},V.id)})})]})]})}function va(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 tI({label:e,value:t}){return f("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium",children:[e,": ",t]})}function nI({search:e,onSearchChange:t,caps:n,active:o,onToggle:s,onSelectAll:a,onSelectNone:i,onResetDefaults:l}){return f("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:[f("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border/50",children:[r(_r,{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(Ve,{className:"h-2.5 w-2.5"})})]}),f("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"})]}),f("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 f("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)})]})]})}function rI({copied:e,onCopy:t}){return r("button",{type:"button",title:"Copy this state change",onClick:n=>{n.stopPropagation(),t()},className:U("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(Yr,{className:"h-3 w-3"}):r(nn,{className:"h-3 w-3"})})}const wa=500,oI=[{id:"logs",label:"Logs",icon:Ov},{id:"events",label:"Events",icon:Ss},{id:"state",label:"State",icon:Bv}];function sI({deviceId:e,defaultEventCategories:t,defaultStateCaps:n,initialTab:o="events",className:s,maxHeight:a="max-h-96"}){const[i,l]=L(o),c=gn(wa),d=gn(wa),p=gn(wa),u=c.reset,h=d.reset,m=p.reset;return X(()=>{u(),h(),m()},[e,u,h,m]),f("div",{className:U("flex flex-col h-full min-h-0",s),children:[r("div",{className:"flex items-center gap-1 mb-2 shrink-0",children:oI.map(({id:g,label:b,icon:x})=>f("button",{type:"button",onClick:()=>l(g),className:U("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(x,{className:"h-3.5 w-3.5"}),b]},g))}),f("div",{className:"flex-1 min-h-0 overflow-hidden",children:[i==="logs"&&r(Wt,{deviceId:e,maxHeight:a,showFilters:!1,liveBuffer:c}),i==="events"&&r(cr,{deviceId:e,defaultCategories:t,maxHeight:a,showCategoryFilter:!0,liveBuffer:d}),i==="state"&&r(Gl,{deviceId:e,defaultCaps:n,maxHeight:a,liveBuffer:p})]})]})}function kg({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:u}){const[h,m]=L(!1),[g,b]=L(!1),[x,y]=L(null),w=async()=>{y(null),b(!0);try{const v=await p();u?.(v),m(!1)}catch(v){y(v instanceof Error?v.message:String(v))}finally{b(!1)}};return f(ye,{children:[f(kr,{type:"button",variant:a,size:l,disabled:c,onClick:()=>{y(null),m(!0)},className:d,children:[t&&r(t,{className:"h-3.5 w-3.5"}),e]}),r(Np,{open:h,onOpenChange:v=>!g&&m(v),children:f(ll,{children:[f(Sp,{children:[f(Cp,{className:"flex items-center gap-2",children:[r(Zr,{className:"h-4 w-4 text-amber-400"}),n]}),typeof o=="string"?r(Mp,{children:o}):o]}),x&&r("div",{className:U("mt-2 px-3 py-2 rounded border border-danger/40 bg-danger/10","text-xs text-danger"),children:x}),f(kp,{children:[r(kr,{type:"button",variant:"ghost",size:l,disabled:g,onClick:()=>m(!1),children:"Cancel"}),f(kr,{type:"button",variant:i,size:l,disabled:g,onClick:()=>{w()},children:[g&&r(Mt,{className:"h-3.5 w-3.5 animate-spin"}),s??e]})]})]})})]})}function bo({direction:e,icon:t,disabled:n,className:o,variant:s,onMove:a,onStart:i,onStop:l}){const[c,d]=L(null),[p,u]=L(!1),h=q(w=>{if(n)return;w.currentTarget.setPointerCapture(w.pointerId),d(Date.now()),u(!1);const v=setTimeout(()=>{u(!0),i(e)},250);w.currentTarget.dataset.timer=String(v)},[e,n,i]),m=q(w=>{const v=Number(w.currentTarget.dataset.timer);v&&clearTimeout(v),w.currentTarget.dataset.timer="",p?l():c!==null&&a(e),d(null),u(!1)},[p,e,a,l,c]),g=q(w=>{const v=Number(w.currentTarget.dataset.timer);v&&clearTimeout(v),w.currentTarget.dataset.timer="",p&&l(),d(null),u(!1)},[p,l]),b=s==="panel"?"h-9 w-9":"h-7 w-7",x=s==="panel"?"h-4 w-4":"h-3.5 w-3.5";return r("button",{type:"button",disabled:n,onPointerDown:h,onPointerUp:m,onPointerCancel:g,className:U("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",b,o),title:e,children:r(t,{className:x})})}function Wl({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:u,presets:h,busy:m,error:g}=e,[b,x]=L(!1),y=(n??h.length>0)&&h.length>0,w=t==="panel",v=w?"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",N=U(w?"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",m&&"ring-1 ring-primary/40"),S=w?"h-9 w-9":"h-7 w-7",k=w?"h-4 w-4":"h-3.5 w-3.5",M=w?"text-foreground hover:bg-surface-hover":"text-white hover:bg-white/15",D=w?"h-12 w-px bg-border mx-1":"h-12 w-px bg-white/15 mx-1";return f("div",{className:U(v,a),children:[g&&f("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: ",g]}),f("div",{className:U(N,w&&"justify-center"),children:[f("div",{className:"grid grid-cols-3 gap-0.5",children:[r("span",{"aria-hidden":!0,className:w?"h-9 w-9":"h-7 w-7"}),r(bo,{direction:"up",icon:jf,variant:t,onMove:i,onStart:l,onStop:c}),r("span",{"aria-hidden":!0,className:w?"h-9 w-9":"h-7 w-7"}),r(bo,{direction:"left",icon:zv,variant:t,onMove:i,onStart:l,onStop:c}),r("span",{"aria-hidden":!0,className:w?"h-9 w-9":"h-7 w-7"}),r(bo,{direction:"right",icon:Fv,variant:t,onMove:i,onStart:l,onStop:c}),r("span",{"aria-hidden":!0,className:w?"h-9 w-9":"h-7 w-7"}),r(bo,{direction:"down",icon:Vf,variant:t,onMove:i,onStart:l,onStop:c}),r("span",{"aria-hidden":!0,className:w?"h-9 w-9":"h-7 w-7"})]}),(o||s)&&r("div",{className:D}),f("div",{className:"flex flex-col gap-0.5",children:[o&&f(ye,{children:[r("button",{type:"button",onClick:()=>d("in"),disabled:m,title:"Zoom in",className:U("flex items-center justify-center rounded disabled:opacity-40",S,M),children:r(Hv,{className:k})}),r("button",{type:"button",onClick:()=>d("out"),disabled:m,title:"Zoom out",className:U("flex items-center justify-center rounded disabled:opacity-40",S,M),children:r(jv,{className:k})})]}),s&&r("button",{type:"button",onClick:()=>p(),disabled:m,title:"Go home",className:U("flex items-center justify-center rounded disabled:opacity-40",S,M),children:r(Ff,{className:k})})]}),y&&f("div",{className:"relative",children:[f("button",{type:"button",onClick:()=>x(E=>!E),disabled:m,className:U("flex items-center gap-1 rounded px-2 text-[10px] disabled:opacity-40",w?"h-9 text-foreground hover:bg-surface-hover":"h-7 text-white hover:bg-white/15"),title:"Presets",children:["Presets",r(Pn,{className:U("h-3 w-3 transition-transform",b&&"rotate-180")})]}),b&&r("div",{className:U("absolute right-0 min-w-[140px] rounded-lg shadow-xl py-1 z-20",w?"bottom-full mb-1 bg-surface border border-border":"top-full mt-1 border border-white/30 bg-zinc-900/95 backdrop-blur-md"),children:h.map(E=>r("button",{type:"button",onClick:()=>{u(E.id),x(!1)},disabled:m,className:U("block w-full px-3 py-1.5 text-left text-[10px] disabled:opacity-40",w?"text-foreground hover:bg-surface-hover":"text-white hover:bg-white/15"),children:E.name||E.id},E.id))})]})]})]})}function aI(e,t){const n=document.createElement("a");n.href=t,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n)}function iI({trpc:e,deviceId:t,deviceName:n,size:o="sm",className:s}){const[a,i]=L(!1),[l,c]=L(!1),[d,p]=L(null),u=n.replace(/[^a-zA-Z0-9_.-]+/g,"_"),h=q(async S=>{i(!0),p(null),c(!1);try{const k=await e.snapshot.getSnapshot.query({deviceId:t,force:!0});if(!k)throw new Error("No snapshot available");const M=`data:${k.contentType};base64,${k.base64}`;if(S==="copy")try{await navigator.clipboard.writeText(M)}catch{throw new Error("Clipboard unavailable")}else{const D=k.contentType.includes("png")?"png":"jpg",E=new Date().toISOString().replace(/[:.]/g,"-");aI(`${u}-${E}.${D}`,M)}c(!0),setTimeout(()=>c(!1),1500)}catch(k){p(k instanceof Error?k.message:String(k))}finally{i(!1)}},[e,t,u]),m=o==="md"?"h-9 px-3 text-sm gap-2":"h-7 px-2.5 text-[11px] gap-1.5",[g,b]=L(null),[x,y]=L(!1),w=()=>{y(!1);const S=setTimeout(()=>{y(!0),h("copy")},600);b(S)},v=()=>{g&&(clearTimeout(g),b(null)),x||h("download")},N=()=>{g&&(clearTimeout(g),b(null))};return f("button",{type:"button",title:"Click to download · long-press to copy",disabled:a,onPointerDown:w,onPointerUp:v,onPointerLeave:N,onPointerCancel:N,className:U("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",m,d&&"border-danger/40 text-danger",s),children:[a?r(Mt,{className:"h-3.5 w-3.5 animate-spin"}):l?r(Yr,{className:"h-3.5 w-3.5 text-success"}):r(Ji,{className:"h-3.5 w-3.5"}),"Snapshot"]})}function lI(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 Kl({history:e,limit:t=5,latestIsFresh:n,className:o}){if(e.length===0)return null;const s=n?Vv:Ss,a=e.slice(0,t);return f("div",{className:U("rounded-lg border border-border bg-surface px-3 py-2",o),children:[f("div",{className:"flex items-center gap-2 mb-2",children:[r(s,{className:U("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=>f("li",{className:"flex items-center justify-between text-[11px]",title:new Date(i.timestamp).toLocaleString(),children:[r("span",{className:"text-foreground",children:lI(i.timestamp)}),r("span",{className:"text-foreground-subtle font-mono text-[10px]",children:new Date(i.timestamp).toLocaleTimeString()})]},`${i.deviceId}-${i.timestamp}`))})]})}function Cg({items:e,header:t,triggerClassName:n,title:o="More actions"}){const[s,a]=L(!1),i=e.filter(l=>!l.hidden);return i.length===0?null:f(Lp,{open:s,onOpenChange:a,children:[r(Op,{title:o,className:U("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(ep,{className:"h-4 w-4"})}),f(Bp,{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)=>f("li",{children:[l.separatorBefore&&c>0&&r("div",{className:"my-1 h-px bg-border"}),f("button",{type:"button",disabled:l.disabled,onClick:()=>{l.disabled||(l.onClick(),a(!1))},className:U("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:U("h-3.5 w-3.5 shrink-0 mt-0.5",l.danger&&"text-danger/80")}),f("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 Mg=Qt("camstack:zone-editing",null);function Ig({children:e}){const[t,n]=L(!1),[o,s]=L(null),[a,i]=L(null),[l,c]=L(null),d=q(w=>{n(w),w||(s(null),i(null),c(null))},[]),p=q(w=>{s(w)},[]),u=q(w=>{i(w)},[]),h=q(w=>{n(!0),i(null),s(w),c(null)},[]),m=q(()=>{n(!1),s(null),i(null),c(null)},[]),g=q(w=>{i(w.id),c(w)},[]),b=q(w=>{c(v=>v===null?v:{...v,...w})},[]),x=q(()=>{c(null)},[]),y=Q(()=>({editing:t,drawingKind:o,selectedZoneId:a,editingDraft:l,setEditing:d,setDrawingKind:p,setSelectedZoneId:u,startDrawing:h,exitEditing:m,enterDraft:g,updateDraft:b,discardDraft:x}),[t,o,a,l,d,p,u,h,m,g,b,x]);return r(Mg.Provider,{value:y,children:e})}function cI(){return ge(Mg)}const Cd=500,dI=800;function xo(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 yo(e,t){return e?.id===t}function Eg(e,t){const[n,o]=L(null),[s,a]=L(null),[i,l]=L(null),[c,d]=L("watching"),p=ee(void 0),u=ee(void 0),h=ee(void 0);return X(()=>{if(t===null)return;const m=xo(e,"detection.motion-analysis",g=>{const b=g;if(!yo(b?.source,t))return;const x=b.data;!x?.regions||x.regions.length===0||(o({zones:x.regions.map(y=>({...y.bbox,intensity:y.intensity})),frameWidth:x.frameWidth,frameHeight:x.frameHeight}),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>o(null),Cd))});return()=>{m?.unsubscribe(),p.current&&clearTimeout(p.current)}},[e,t]),X(()=>{if(t===null)return;const m=xo(e,"detection.motion-zones-raw",g=>{const b=g;if(!yo(b?.source,t))return;const x=b.data;x?.zones&&(a({boxes:x.zones.map(y=>({bbox:y.bbox,changeScore:y.changeScore})),frameWidth:x.frameSize?.width??0,frameHeight:x.frameSize?.height??0,motionScore:x.zones.length>0?x.zones.reduce((y,w)=>y+w.changeScore,0)/x.zones.length:0}),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>a(null),Cd))});return()=>{m?.unsubscribe(),u.current&&clearTimeout(u.current)}},[e,t]),X(()=>{if(t===null)return;const m=xo(e,"detection.result",g=>{const b=g;if(!yo(b?.source,t))return;const x=b.data?.frame;x?.detections?.length&&(l({detections:x.detections,frameWidth:x.width,frameHeight:x.height}),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>l(null),dI))});return()=>{m?.unsubscribe(),h.current&&clearTimeout(h.current)}},[e,t]),X(()=>{if(t===null)return;const m=xo(e,"detection.phase-transition",g=>{const b=g;yo(b?.source,t)&&b.data?.to&&d(b.data.to)});return()=>{m?.unsubscribe()}},[e,t]),{motion:n,motionRaw:s,detection:i,phase:c}}function Yl(e,t,n=5e3){const[o,s]=L([]);X(()=>{if(t===null)return;let h=!1;const m=()=>{e.webrtcSession.listStreams.query({deviceId:t}).then(b=>{h||s(b)}).catch(()=>{})};m();const g=setInterval(m,n);return()=>{h=!0,clearInterval(g)}},[e,t,n]);const[a,i]=L(null);X(()=>{if(t===null)return;let h=!1;return e.pipelineOrchestrator&&e.pipelineOrchestrator.getCameraMetrics.query({deviceId:t}).then(m=>{h||!m||i({phase:m.phase,detectionFps:m.actualFps,avgInferenceMs:m.avgInferenceTimeMs,droppedFrames:m.droppedFrames})}).catch(()=>{}),()=>{h=!0}},[e,t]),et("pipeline.camera-metrics-snapshot",h=>{if(t===null)return;const m=h.data;m.deviceId!==t||!m.metrics||i({phase:m.metrics.phase,detectionFps:m.metrics.actualFps,avgInferenceMs:m.metrics.avgInferenceTimeMs,droppedFrames:m.metrics.droppedFrames})});const{streams:l,hasWebrtc:c}=Q(()=>t===null||o.length===0?{streams:[],hasWebrtc:!1}:{streams:o.map(m=>({id:m.id,label:m.label,target:m.target,status:m.status,inputFps:m.inputFps,decodeFps:m.decodeFps,bitrateKbps:m.bitrateKbps})),hasWebrtc:!0},[t,o]),d=q(async(h,m)=>{if(t===null)throw new Error("No device selected");const g=await e.webrtcSession.createSession.mutate({deviceId:t,target:h,hints:m});return{sessionId:g.sessionId,sdpOffer:g.sdpOffer}},[e,t]),p=q(async(h,m)=>{if(t===null)throw new Error("No device selected");await e.webrtcSession.handleAnswer.mutate({deviceId:t,sessionId:h,sdpAnswer:m})},[e,t]),u=q(async h=>{t!==null&&await e.webrtcSession.closeSession.mutate({deviceId:t,sessionId:h}).catch(()=>{})},[e,t]);return{streams:l,hasWebrtc:c,pipelineMetrics:a,createSession:d,sendAnswer:p,closeSession:u}}const Md={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 Zl(e,t,n){const o=n?.defaultSpeed??.5,s=n?.pulseMs??250,a=n?.enabled??!0,l=lt(e,a?t:null)?.ptz,[c,d]=L([]),[p,u]=L(!1),[h,m]=L(null),g=q(async()=>{if(!(!a||!l))try{const k=await l.getPresets({});d(k)}catch(k){const M=k instanceof Error?k.message:String(k);if(M.includes("provider not available")||M.includes("no 'ptz' binding"))return;m(M)}},[l,a]);X(()=>{g()},[g]);const b=q(async k=>{if(!(!a||!l)){m(null),u(!0);try{return await k()}catch(M){m(M instanceof Error?M.message:String(M));return}finally{u(!1)}}},[a,l]),x=q(async(k,M)=>{if(!l)return;const D=Md[k],E=M??o;await b(async()=>{await l.move({pan:D.pan,tilt:D.tilt,speed:E}),await new Promise(B=>setTimeout(B,s)),await l.stop({})})},[l,o,s,b]),y=q(async(k,M)=>{if(!l)return;const D=Md[k],E=M??o;await b(()=>l.continuousMove({pan:D.pan,tilt:D.tilt,speed:E}))},[l,o,b]),w=q(async()=>{l&&await b(()=>l.stop({}))},[l,b]),v=q(async(k,M)=>{if(!l)return;const D=k==="in"?1:-1,E=M??o;await b(async()=>{await l.move({zoom:D,speed:E}),await new Promise(B=>setTimeout(B,s)),await l.stop({})})},[l,o,s,b]),N=q(async()=>{l&&await b(()=>l.goHome({}))},[l,b]),S=q(async k=>{l&&await b(()=>l.goToPreset({presetId:k}))},[l,b]);return{move:x,startContinuous:y,stopContinuous:w,zoom:v,goHome:N,goToPreset:S,presets:c,refreshPresets:g,busy:p,error:h}}function Xl(e){const t=e?.deviceId??null,n=e?.historyLimit??20,o=or("doorbell.onPressed",t!==null?i=>i.deviceId===t:void 0),[s,a]=L([]);return X(()=>{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 uI(e){const t=Ae(),n=Q(()=>e?JSON.stringify(e):"",[e]),[o,s]=L(()=>t.listDevices(e));return X(()=>{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 fI(e){const t=Ae(),[n,o]=L(()=>e===null?null:t.getDevice(e));return X(()=>{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 pI(e,t,n){const o=Ae();return En({queryKey:e,queryFn:()=>t(o)(),...n})}function hI(e,t){const n=Ae();return Yi({mutationFn:o=>e(n)(o),...t})}function mI(e,t){const n=Ae(),o=ke(),[s,a]=L(n.connectionVersion);X(()=>n.subscribeConnectionEvents((c,d)=>{c==="connected"&&a(d)}),[n]);const i=t.join("|"),l=JSON.stringify(e);X(()=>{const c=[],d=()=>{const p=JSON.parse(l),h=p.length===1&&Array.isArray(p[0])?p:[p];o.invalidateQueries({queryKey:h})};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 gI=Object.freeze(Object.defineProperty({__proto__:null,AddonGlobalSettingsForm:pM,AgentStepEditor:Is,AppShell:bw,AudioClassificationList:TM,AudioLevelWaveform:$M,AudioWaveform:AM,BTN_COMPACT:f1,BTN_COMPACT_DANGER:h1,BTN_COMPACT_PRIMARY:p1,BTN_COMPACT_WARNING:m1,Badge:Fn,BatteryBadge:kl,BottomSheet:hl,Breadcrumb:bl,Button:kr,CHIP_ACTIVE:x1,CHIP_BASE:b1,CHIP_INACTIVE:y1,CLASS_COLORS:vr,CameraStreamPlayer:bg,Card:ol,Checkbox:Yo,CodeBlock:mw,CollapsibleCard:yp,ConfigFormBuilder:mg,ConfigFormField:lr,ConfigSchemaField:Ms,ConfirmActionButton:kg,ConfirmDialogProvider:Kp,CustomFieldRenderersProvider:mh,DEFAULT_COLOR:dh,DataTable:Sw,DetectionCanvas:MN,DetectionOverlay:gg,DetectionResultTree:AN,DevShell:ph,DeviceActivityPanel:sI,DeviceCard:Mw,DeviceContextProvider:bh,DeviceGrid:Iw,DeviceItem:Lr,DeviceList:Es,Dialog:Np,DialogContent:ll,DialogDescription:Mp,DialogFooter:kp,DialogHeader:Sp,DialogTitle:Cp,DialogTrigger:T1,DiscoveryPanel:Sg,DoorbellRecentPanel:Kl,Dropdown:dl,DropdownContent:fl,DropdownItem:pl,DropdownTrigger:ul,EmptyState:fw,EventStream:cr,FilterBar:gw,FloatingEventStream:KM,FloatingLogStream:Ng,FloatingPanel:V1,FormField:dw,GRID_GAP:gp,GRID_PAIRED:a1,GRID_QUICK_STATS:s1,INPUT_COMPACT:g1,IconButton:Tr,ImageSelector:RN,InferenceConfigSelector:LN,Input:Ko,KebabMenu:Cg,KeyValueList:hw,LIST_ROW:bp,Label:sl,LogStream:Wt,LoginForm:uh,MobileDrawer:gl,NodeMultiSelectField:hg,NodePicker:Qp,NodeSelectField:pg,PHASE_CONFIG:oi,PTZOverlay:Wl,PageHeader:uw,PhaseIcon:Ql,PipelineBuilder:Cl,PipelineRuntimeSelector:SN,PipelineStep:Bo,PipelineTreeMatrix:yl,PlayerOverlaysProvider:xg,Popover:Lp,PopoverContent:Bp,PopoverTrigger:Op,ProviderBadge:iw,ResponseLog:RM,SECTION_BODY:o1,SECTION_CARD:n1,SECTION_HEADER:r1,SPLIT_PANEL_OUTER:i1,SPLIT_PANEL_SIDE:l1,STACK_GAP:mp,ScrollArea:ml,Select:Rr,SemanticBadge:Gp,Separator:al,Sidebar:li,SidebarItem:ii,Skeleton:Hn,SlideOverPanel:xl,SnapshotButton:iI,StatCard:pw,StateValuesStream:Gl,StatusBadge:sw,StepTimings:TN,StepTreeMaster:jp,StreamPanel:Ul,Switch:il,SystemProvider:wl,TEXT_FIELD_LABEL:d1,TEXT_HINT:Wo,TEXT_METRIC:ri,TEXT_SECTION_LABEL:c1,TEXT_VALUE:u1,Tabs:z1,TabsContent:j1,TabsList:F1,TabsTrigger:H1,ThemeProvider:Go,Tooltip:L1,TooltipContent:B1,TooltipTrigger:O1,VersionBadge:cw,WidgetRegistryProvider:lg,WidgetSlot:Ze,ZoneEditingProvider:Ig,buildStepTreeFromSchema:Cs,cn:U,createSharedContext:Qt,createTheme:Kv,darkColors:cp,defaultTheme:ni,deriveDeviceKind:Pw,ensureMfHostInit:rl,getClassColor:Je,getPhaseVisual:An,isFieldVisible:jl,lightColors:dp,mirror:xp,mountAddonPage:UN,providerIcons:I1,statusIcons:E1,themeToCss:e1,trpc:C,useAccessoriesGetStatus:QN,useAddonPagesListPages:El,useAddonSettingsGetDeviceSettings:n2,useAddonSettingsGetGlobalSettings:Dl,useAddonSettingsUpdateDeviceSettings:Eh,useAddonSettingsUpdateGlobalSettings:Ih,useAddonWidgetsListWidgets:Ph,useAddonsApplyAutoUpdateToAll:Mh,useAddonsCustom:e2,useAddonsForceRefresh:wh,useAddonsGetAddonAutoUpdate:kh,useAddonsGetAutoUpdateSettings:Sh,useAddonsGetLogs:GN,useAddonsGetVersions:Nh,useAddonsInstallFromWorkspace:KN,useAddonsInstallPackage:Al,useAddonsIsWorkspaceAvailable:YN,useAddonsList:Pl,useAddonsListPackages:WN,useAddonsListUpdates:$l,useAddonsListWorkspacePackages:ZN,useAddonsOnAddonLogs:t2,useAddonsReloadPackages:yh,useAddonsRestartAddon:Ps,useAddonsRestartServer:XN,useAddonsSearchAvailable:vh,useAddonsSetAddonAutoUpdate:Ch,useAddonsSetAutoUpdateSettings:JN,useAddonsUninstallPackage:xh,useAddonsUpdatePackage:di,useAlertsDismiss:Th,useAlertsEmit:r2,useAlertsGetUnreadCount:$h,useAlertsList:Ah,useAlertsMarkAllRead:_h,useAlertsMarkRead:Dh,useAlertsUpdate:o2,useAllWidgets:ug,useAudioAnalysisApplyDeviceSettingsPatch:l2,useAudioAnalysisGetDeviceLiveContribution:i2,useAudioAnalysisGetDeviceSettingsContribution:a2,useAudioAnalysisResolveDeviceSettings:s2,useAudioAnalyzerAnalyseChunk:c2,useAudioAnalyzerClassify:d2,useAudioAnalyzerDispose:f2,useAudioAnalyzerIsReady:u2,useAudioAnalyzerReprobeAudioEngine:Rh,useAudioCodecCanHandle:h2,useAudioCodecCloseSession:b2,useAudioCodecCreateDecodeSession:m2,useAudioCodecCreateEncodeSession:g2,useAudioCodecFlushEncode:N2,useAudioCodecListActiveSessions:S2,useAudioCodecListSupportedCodecs:p2,useAudioCodecPullEncoded:w2,useAudioCodecPullPcm:y2,useAudioCodecPushEncodedFrame:x2,useAudioCodecPushPcm:v2,useAudioMetricsGetCurrentSnapshot:k2,useAudioMetricsGetHistory:C2,useBackupDelete:P2,useBackupList:I2,useBackupRestore:E2,useBackupTrigger:M2,useBatteryGetStatus:A2,useBrightnessGetStatus:D2,useBrightnessSetBrightness:$2,useCameraStreamsGetBrokerStreams:T2,useCameraStreamsGetCameraStreams:_2,useCameraStreamsGetRtspEntries:R2,useClusterNodes:sr,useConfirm:on,useCustomFieldRenderer:gh,useDebouncedString:ch,useDecoderCreateSession:B2,useDecoderDestroySession:z2,useDecoderGetInfo:O2,useDecoderGetStats:q2,useDecoderListActiveSessions:U2,useDecoderOpenStream:H2,useDecoderPullFrames:j2,useDecoderPushPacket:F2,useDecoderReprobeHwaccel:Lh,useDecoderSupportsCodec:L2,useDecoderUpdateConfig:V2,useDetectionPipelineApplyDeviceSettingsPatch:W2,useDetectionPipelineGetDeviceLiveContribution:G2,useDetectionPipelineGetDeviceSettingsContribution:Q2,useDevShell:FN,useDevice:fI,useDeviceBattery:Nl,useDeviceCapability:ar,useDeviceDetections:Eg,useDeviceDiscoveryAdoptDevice:K2,useDeviceDiscoveryGetStatus:Z2,useDeviceDiscoveryListDiscovered:Oh,useDeviceDiscoveryRefreshDiscovery:Bh,useDeviceDiscoveryReleaseDevice:Y2,useDeviceId:Gt,useDeviceManagerAddLocation:aS,useDeviceManagerAdoptDevice:Yh,useDeviceManagerAllocateDeviceId:X2,useDeviceManagerCreateDevice:Xh,useDeviceManagerDisable:qh,useDeviceManagerDiscoverDevices:Tl,useDeviceManagerEnable:Vh,useDeviceManagerGetAllBindings:bS,useDeviceManagerGetBindings:Qh,useDeviceManagerGetChildren:jh,useDeviceManagerGetConfigSchema:uS,useDeviceManagerGetCreationSchema:Zh,useDeviceManagerGetDevice:yn,useDeviceManagerGetDeviceAggregate:_l,useDeviceManagerGetDeviceLiveInfoAggregate:vS,useDeviceManagerGetDeviceSettingsAggregate:yS,useDeviceManagerGetDeviceStatusAggregate:SS,useDeviceManagerGetSettingsSchema:fS,useDeviceManagerGetStreamProfileMap:hS,useDeviceManagerGetStreamSources:dS,useDeviceManagerListAll:$n,useDeviceManagerListBindableCapsForDeviceType:Wh,useDeviceManagerListLocations:Hh,useDeviceManagerListPersistedByAddon:cS,useDeviceManagerListWrappersForCap:xS,useDeviceManagerLoadConfig:nS,useDeviceManagerLoadMeta:oS,useDeviceManagerLoadRuntimeState:rS,useDeviceManagerPersistConfig:tS,useDeviceManagerProbeStreams:gS,useDeviceManagerRegisterDevice:J2,useDeviceManagerRemove:Uh,useDeviceManagerRemoveDevice:eS,useDeviceManagerRemoveLocation:iS,useDeviceManagerSetDisabled:lS,useDeviceManagerSetLocation:Fh,useDeviceManagerSetMetadata:sS,useDeviceManagerSetName:zh,useDeviceManagerSetStreamProfileMap:mS,useDeviceManagerSetWrapperActive:Gh,useDeviceManagerTestCreationField:Rl,useDeviceManagerTestField:NS,useDeviceManagerUpdateConfig:pS,useDeviceManagerUpdateDeviceField:wS,useDeviceManagerUpdateDeviceFieldsBatch:Kh,useDeviceOpsGetConfigEntries:CS,useDeviceOpsGetSettingsSchema:ES,useDeviceOpsGetStreamSources:kS,useDeviceOpsRemoveDevice:IS,useDeviceOpsSetConfig:MS,useDeviceProviderAdoptDiscoveredDevice:RS,useDeviceProviderCreateDevice:BS,useDeviceProviderDiscoverDevices:TS,useDeviceProviderGetChildCreationSchema:OS,useDeviceProviderGetDevices:DS,useDeviceProviderGetStatus:$S,useDeviceProviderStart:PS,useDeviceProviderStop:AS,useDeviceProviderSupportsDiscovery:_S,useDeviceProviderSupportsManualCreation:LS,useDeviceProviderTestCreationField:zS,useDeviceProxy:lt,useDeviceSnapshot:Il,useDeviceSnapshotImage:Sl,useDeviceState:Yp,useDeviceStateGetAllSnapshots:jS,useDeviceStateGetCapSlice:HS,useDeviceStateGetSnapshot:FS,useDeviceStateSetCapSlice:VS,useDeviceStateSlice:Ft,useDeviceWebrtc:Yl,useDevices:uI,useDoorbellEvents:Xl,useDoorbellGetStatus:qS,useEventInvalidation:mI,useEventStreamLatest:or,useEventStreamMap:Up,useEventsGetEventClipUrl:GS,useEventsGetEventThumbnail:QS,useEventsGetEvents:US,useIntegrationsCreate:tm,useIntegrationsDelete:rm,useIntegrationsGet:Jh,useIntegrationsGetAvailableTypes:om,useIntegrationsGetByAddonId:em,useIntegrationsGetSettings:WS,useIntegrationsList:Ll,useIntegrationsSetSettings:KS,useIntegrationsTestConnection:sm,useIntegrationsUpdate:nm,useIntercomGetStatus:YS,useIntercomHandleAnswer:im,useIntercomStartSession:am,useIntercomStopSession:lm,useIsMidWidth:_p,useIsMobile:rn,useLiveBuffer:gn,useLiveEvent:et,useMetricsProviderCollectSnapshot:ZS,useMetricsProviderGetAddonStats:sk,useMetricsProviderGetCached:XS,useMetricsProviderGetCpuTemperature:nk,useMetricsProviderGetCurrent:JS,useMetricsProviderGetDiskSpace:ek,useMetricsProviderGetGpuInfo:tk,useMetricsProviderGetProcessStats:rk,useMetricsProviderKillProcess:dm,useMetricsProviderListAddonInstances:ok,useMetricsProviderListNodeProcesses:cm,useMotionDetectionAnalyze:lk,useMotionDetectionApplyDeviceSettingsPatch:pk,useMotionDetectionGetDeviceLiveContribution:fk,useMotionDetectionGetDeviceSettingsContribution:uk,useMotionDetectionRemoveCamera:ck,useMotionDetectionReset:dk,useMotionGetStatus:ik,useMotionIsDetected:ak,useMotionTriggerGetStatus:mk,useMotionTriggerSetMotionTrigger:hk,useNativeObjectDetectionGetStatus:gk,useNetworkQualityGetAllStats:bk,useNetworkQualityGetDeviceStats:Ol,useNetworkQualityReportClientStats:xk,useNodesClusterAddonStatus:mm,useNodesDeployAddon:yk,useNodesExecuteQuery:wk,useNodesRenameNode:hm,useNodesRestartAddon:As,useNodesRestartNode:pm,useNodesRestartProcess:fm,useNodesSetProcessLogLevel:gm,useNodesShutdownNode:vk,useNodesTopology:sn,useNodesUndeployAddon:um,useNotificationOutputSend:Nk,useNotificationOutputSendTest:Sk,useOptionalSystem:rw,useOptionalWidgetRegistry:fg,useOsdGetStatus:Ck,useOsdSetOverlay:kk,usePTZ:Zl,usePipelineAnalyticsApplyDeviceSettingsPatch:Ok,usePipelineAnalyticsClearTracks:Pk,usePipelineAnalyticsGetActiveTracks:Mk,usePipelineAnalyticsGetAudioEvents:Dk,usePipelineAnalyticsGetDeviceLiveContribution:Lk,usePipelineAnalyticsGetDeviceSettingsContribution:Rk,usePipelineAnalyticsGetEventMedia:_k,usePipelineAnalyticsGetMotionEvents:Ak,usePipelineAnalyticsGetObjectEvents:$k,usePipelineAnalyticsGetTrack:Ik,usePipelineAnalyticsGetTrackMedia:Tk,usePipelineAnalyticsListTracks:Ek,usePipelineExecutorCacheFrameInPool:Jk,usePipelineExecutorDeleteModel:wm,usePipelineExecutorDeleteTemplate:Gk,usePipelineExecutorDetect:Yk,usePipelineExecutorDownloadModel:vm,usePipelineExecutorGetAddonModels:Kk,usePipelineExecutorGetAudioCapabilities:lC,usePipelineExecutorGetAvailableEngines:bm,usePipelineExecutorGetCapabilities:Wk,usePipelineExecutorGetDefaultSteps:Bk,usePipelineExecutorGetDetectionConfigSchema:dC,usePipelineExecutorGetEffectiveTuning:nC,usePipelineExecutorGetGlobalPipelineConfig:jk,usePipelineExecutorGetGlobalSteps:Hk,usePipelineExecutorGetOrchestratorConfigSchema:Vk,usePipelineExecutorGetReferenceAudio:iC,usePipelineExecutorGetReferenceAudioFiles:aC,usePipelineExecutorGetReferenceImage:sC,usePipelineExecutorGetSchema:Jr,usePipelineExecutorGetSelectedEngine:xm,usePipelineExecutorGetVideoPipelineSteps:zk,usePipelineExecutorInferCached:eC,usePipelineExecutorKillEngine:Sm,usePipelineExecutorListLoadedEngines:Nm,usePipelineExecutorListReferenceImages:oC,usePipelineExecutorListTemplates:qk,usePipelineExecutorReprobeEngine:ym,usePipelineExecutorRunAudioTest:cC,usePipelineExecutorRunPipeline:Zk,usePipelineExecutorRunPipelineBatch:Xk,usePipelineExecutorSaveTemplate:Uk,usePipelineExecutorSetVideoPipelineSteps:Fk,usePipelineExecutorSpinEngine:rC,usePipelineExecutorUncacheFrame:tC,usePipelineExecutorUpdateTemplate:Qk,usePipelineOrchestratorApplyDeviceSettingsPatch:yC,usePipelineOrchestratorAssignAudio:_m,usePipelineOrchestratorAssignDecoder:Am,usePipelineOrchestratorAssignPipeline:km,usePipelineOrchestratorDeleteTemplate:qm,usePipelineOrchestratorGetAgentLoad:Im,usePipelineOrchestratorGetAgentSettings:Bl,usePipelineOrchestratorGetAudioAssignment:pC,usePipelineOrchestratorGetAudioAssignments:Lm,usePipelineOrchestratorGetAudioNodeLoad:Rm,usePipelineOrchestratorGetCameraMetrics:fC,usePipelineOrchestratorGetCameraSettings:Fl,usePipelineOrchestratorGetCameraStepOverrides:mC,usePipelineOrchestratorGetCapabilityBindings:Em,usePipelineOrchestratorGetDecoderAssignment:hC,usePipelineOrchestratorGetDecoderAssignments:Dm,usePipelineOrchestratorGetDeviceLiveContribution:xC,usePipelineOrchestratorGetDeviceSettingsContribution:bC,usePipelineOrchestratorGetGlobalMetrics:uC,usePipelineOrchestratorGetPipelineAssignment:Ds,usePipelineOrchestratorGetPipelineAssignments:$s,usePipelineOrchestratorListAgentSettings:ir,usePipelineOrchestratorListTemplates:jm,usePipelineOrchestratorRebalance:Mm,usePipelineOrchestratorRemoveAgentSettings:Om,usePipelineOrchestratorResolvePipeline:Hm,usePipelineOrchestratorSaveTemplate:gC,usePipelineOrchestratorSetAgentAddonDefaults:zl,usePipelineOrchestratorSetCameraPipelineForAgent:Fm,usePipelineOrchestratorSetCameraStepOverride:zm,usePipelineOrchestratorSetCameraStepToggle:Bm,usePipelineOrchestratorSetCapabilityBinding:Pm,usePipelineOrchestratorUnassignAudio:Tm,usePipelineOrchestratorUnassignDecoder:$m,usePipelineOrchestratorUnassignPipeline:Cm,usePipelineOrchestratorUpdateTemplate:Vm,usePipelineRunnerAttachCamera:vC,usePipelineRunnerDetachCamera:wC,usePipelineRunnerGetAllCameraMetrics:CC,usePipelineRunnerGetCameraMetrics:Hl,usePipelineRunnerGetLocalCameras:Um,usePipelineRunnerGetLocalLoad:SC,usePipelineRunnerGetLocalMetrics:kC,usePipelineRunnerReportMotion:NC,usePlatformProbeGetCapabilities:MC,usePlatformProbeGetHardware:IC,usePlatformProbeResolveHwAccel:PC,usePlatformProbeResolveInferenceConfig:EC,usePlayerOverlayLayer:wM,usePlayerOverlayLayers:yg,usePlayerToolbarButton:NM,usePlayerToolbarButtons:vg,usePtzAutotrackGetSettings:BC,usePtzAutotrackGetStatus:Qm,usePtzAutotrackSetEnabled:Gm,usePtzAutotrackSetSettings:Wm,usePtzContinuousMove:$C,usePtzGetPosition:LC,usePtzGetPresets:_C,usePtzGetStatus:OC,usePtzGoHome:RC,usePtzGoToPreset:TC,usePtzMove:AC,usePtzStop:DC,useRebootReboot:Km,useRecordingEngineDisable:Zm,useRecordingEngineEnable:Ym,useRecordingEngineEstimateGlobalStorage:WC,useRecordingEngineEstimateStorage:GC,useRecordingEngineGetAvailability:QC,useRecordingEngineGetConfig:Xm,useRecordingEngineGetMotionStats:XC,useRecordingEngineGetPlaylist:qC,useRecordingEngineGetPolicy:YC,useRecordingEngineGetPolicyStatus:tg,useRecordingEngineGetRetentionConfig:ng,useRecordingEngineGetSegments:Jm,useRecordingEngineGetStatus:jC,useRecordingEngineGetStorageUsage:eg,useRecordingEngineGetThumbnail:UC,useRecordingEngineSetPolicy:KC,useRecordingEngineUpdateConfig:VC,useRecordingEngineUpdateRetentionConfig:ZC,useRecordingGetPlaybackUrl:FC,useRecordingGetSegments:zC,useRecordingGetThumbnailAt:HC,useSettingsStoreCount:s5,useSettingsStoreDeclareCollection:i5,useSettingsStoreDelete:o5,useSettingsStoreGet:JC,useSettingsStoreInsert:n5,useSettingsStoreIsEmpty:a5,useSettingsStoreQuery:t5,useSettingsStoreSet:e5,useSettingsStoreUpdate:r5,useSnapshotApplyDeviceSettingsPatch:p5,useSnapshotGetDeviceLiveContribution:f5,useSnapshotGetDeviceSettingsContribution:u5,useSnapshotGetSnapshot:l5,useSnapshotGetStatus:d5,useSnapshotInvalidateCache:c5,useSnapshotProviderGetSnapshot:m5,useSnapshotProviderSupportsDevice:h5,useStorageDelete:w5,useStorageExists:y5,useStorageGetAvailableSpace:N5,useStorageList:v5,useStorageRead:x5,useStorageResolve:g5,useStorageWrite:b5,useStreamBrokerApplyDeviceSettingsPatch:q5,useStreamBrokerAssignProfile:C5,useStreamBrokerGetAllRtspEntries:B5,useStreamBrokerGetBroker:T5,useStreamBrokerGetBrokerStats:P5,useStreamBrokerGetDeviceLiveContribution:V5,useStreamBrokerGetDeviceSettingsContribution:j5,useStreamBrokerGetPreBufferInfo:L5,useStreamBrokerGetRtspEntry:z5,useStreamBrokerGetRtspPort:O5,useStreamBrokerGetStreamUrl:_5,useStreamBrokerIsRtspEnabled:H5,useStreamBrokerKillClient:$5,useStreamBrokerListAllCameraStreams:I5,useStreamBrokerListAllProfileSlots:E5,useStreamBrokerListClients:A5,useStreamBrokerPublishCameraStream:S5,useStreamBrokerRegenerateRtspToken:rg,useStreamBrokerRestartProfile:D5,useStreamBrokerRetractCameraStream:k5,useStreamBrokerSetPreBufferDuration:R5,useStreamBrokerSetRtspEnabled:F5,useStreamBrokerUnassignProfile:M5,useSwitchGetStatus:Q5,useSwitchSetState:U5,useSystem:Ae,useSystemFeatureFlags:K5,useSystemForceRetentionCleanup:J5,useSystemGetRetentionConfig:Z5,useSystemHealth:W5,useSystemInfo:G5,useSystemMutation:hI,useSystemNetworkAddresses:Y5,useSystemQuery:pI,useSystemSetRetentionConfig:X5,useThemeMode:Xr,useToastOnToast:og,useTurnProviderGetTurnServers:e3,useUserManagementCreateApiKey:a3,useUserManagementCreateScopedToken:c3,useUserManagementCreateUser:ag,useUserManagementDeleteUser:n3,useUserManagementListApiKeys:s3,useUserManagementListScopedTokens:f3,useUserManagementListUsers:sg,useUserManagementResetPassword:r3,useUserManagementRevokeApiKey:i3,useUserManagementRevokeScopedToken:d3,useUserManagementUpdateUser:t3,useUserManagementValidateApiKey:l3,useUserManagementValidateCredentials:o3,useUserManagementValidateScopedToken:u3,useWebrtcSessionCloseSession:g3,useWebrtcSessionCreateSession:h3,useWebrtcSessionHandleAnswer:m3,useWebrtcSessionHasAdaptiveBitrate:b3,useWebrtcSessionListStreams:p3,useWidget:cg,useWidgetMetadata:dg,useWidgetRegistry:_s,useZoneAnalyticsGetCameraHistory:v3,useZoneAnalyticsGetCurrentSnapshot:x3,useZoneAnalyticsGetUnzonedHistory:w3,useZoneAnalyticsGetZoneHistory:y3,useZoneEditing:cI,useZoneRulesListRules:N3,useZoneRulesSetRules:S3,useZonesAddZone:C3,useZonesListZones:k3,useZonesRemoveZone:M3,useZonesUpdateZone:I3},Symbol.toStringTag,{value:"Module"}));/**
35
- * react-router v7.15.0
36
- *
37
- * Copyright (c) Remix Software Inc.
38
- *
39
- * This source code is licensed under the MIT license found in the
40
- * LICENSE.md file in the root directory of this source tree.
41
- *
42
- * @license MIT
43
- */var Id="popstate";function Ed(e){return typeof e=="object"&&e!=null&&"pathname"in e&&"search"in e&&"hash"in e&&"state"in e&&"key"in e}function bI(e={}){function t(o,s){let a=s.state?.masked,{pathname:i,search:l,hash:c}=a||o.location;return pi("",{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:Or(s)}return yI(t,n,null,e)}function De(e,t){if(e===!1||e===null||typeof e>"u")throw new Error(t)}function it(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}function xI(){return Math.random().toString(36).substring(2,10)}function Pd(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 pi(e,t,n=null,o,s){return{pathname:typeof e=="string"?e:e.pathname,search:"",hash:"",...typeof t=="string"?dr(t):t,state:n,key:t&&t.key||o||xI(),mask:s}}function Or({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 dr(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 yI(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 u(){l="POP";let x=p(),y=x==null?null:x-d;d=x,c&&c({action:l,location:b.location,delta:y})}function h(x,y){l="PUSH";let w=Ed(x)?x:pi(b.location,x,y);d=p()+1;let v=Pd(w,d),N=b.createHref(w.mask||w);try{i.pushState(v,"",N)}catch(S){if(S instanceof DOMException&&S.name==="DataCloneError")throw S;s.location.assign(N)}a&&c&&c({action:l,location:b.location,delta:1})}function m(x,y){l="REPLACE";let w=Ed(x)?x:pi(b.location,x,y);d=p();let v=Pd(w,d),N=b.createHref(w.mask||w);i.replaceState(v,"",N),a&&c&&c({action:l,location:b.location,delta:0})}function g(x){return vI(x)}let b={get action(){return l},get location(){return e(s,i)},listen(x){if(c)throw new Error("A history only accepts one active listener");return s.addEventListener(Id,u),c=x,()=>{s.removeEventListener(Id,u),c=null}},createHref(x){return t(s,x)},createURL:g,encodeLocation(x){let y=g(x);return{pathname:y.pathname,search:y.search,hash:y.hash}},push:h,replace:m,go(x){return i.go(x)}};return b}function vI(e,t=!1){let n="http://localhost";typeof window<"u"&&(n=window.location.origin!=="null"?window.location.origin:window.location.href),De(n,"No window.location.(origin|href) available to create URL");let o=typeof e=="string"?e:Or(e);return o=o.replace(/ $/,"%20"),!t&&o.startsWith("//")&&(o=n+o),new URL(o,n)}function Pg(e,t,n="/"){return wI(e,t,n,!1)}function wI(e,t,n,o,s){let a=typeof t=="string"?dr(t):t,i=jt(a.pathname||"/",n);if(i==null)return null;let l=NI(e),c=null,d=TI(i);for(let p=0;c==null&&p<l.length;++p)c=DI(l[p],d,o);return c}function NI(e){let t=Ag(e);return SI(t),t}function Ag(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;De(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 u=gt([o,p.relativePath]),h=n.concat(p);i.children&&i.children.length>0&&(De(i.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${u}".`),Ag(i.children,t,h,u,c)),!(i.path==null&&!i.index)&&t.push({path:u,score:AI(u,i.index),routesMeta:h})};return e.forEach((i,l)=>{if(i.path===""||!i.path?.includes("?"))a(i,l);else for(let c of $g(i.path))a(i,l,!0,c)}),t}function $g(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=$g(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 SI(e){e.sort((t,n)=>t.score!==n.score?n.score-t.score:$I(t.routesMeta.map(o=>o.childrenIndex),n.routesMeta.map(o=>o.childrenIndex)))}var kI=/^:[\w-]+$/,CI=3,MI=2,II=1,EI=10,PI=-2,Ad=e=>e==="*";function AI(e,t){let n=e.split("/"),o=n.length;return n.some(Ad)&&(o+=PI),t&&(o+=MI),n.filter(s=>!Ad(s)).reduce((s,a)=>s+(kI.test(a)?CI:a===""?II:EI),o)}function $I(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 DI(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)||"/",u=Xo({path:c.relativePath,caseSensitive:c.caseSensitive,end:d},p),h=c.route;if(!u&&d&&n&&!o[o.length-1].route.index&&(u=Xo({path:c.relativePath,caseSensitive:c.caseSensitive,end:!1},p)),!u)return null;Object.assign(s,u.params),i.push({params:s,pathname:gt([a,u.pathname]),pathnameBase:BI(gt([a,u.pathnameBase])),route:h}),u.pathnameBase!=="/"&&(a=gt([a,u.pathnameBase]))}return i}function Xo(e,t){typeof e=="string"&&(e={path:e,caseSensitive:!1,end:!0});let[n,o]=_I(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:u},h)=>{if(p==="*"){let g=l[h]||"";i=a.slice(0,a.length-g.length).replace(/(.)\/+$/,"$1")}const m=l[h];return u&&!m?d[p]=void 0:d[p]=(m||"").replace(/%2F/g,"/"),d},{}),pathname:a,pathnameBase:i,pattern:e}}function _I(e,t=!1,n=!0){it(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 u=p.charAt(d+i.length);return u&&u!=="/"?"/([^\\/]*)":"(?:/([^\\/]*))?"}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 TI(e){try{return e.split("/").map(t=>decodeURIComponent(t).replace(/\//g,"%2F")).join("/")}catch(t){return it(!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 jt(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 RI=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;function LI(e,t="/"){let{pathname:n,search:o="",hash:s=""}=typeof e=="string"?dr(e):e,a;return n?(n=Dg(n),n.startsWith("/")?a=$d(n.substring(1),"/"):a=$d(n,t)):a=t,{pathname:a,search:zI(o),hash:FI(s)}}function $d(e,t){let n=Jo(t).split("/");return e.split("/").forEach(s=>{s===".."?n.length>1&&n.pop():s!=="."&&n.push(s)}),n.length>1?n.join("/"):"/"}function Na(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 OI(e){return e.filter((t,n)=>n===0||t.route.path&&t.route.path.length>0)}function Jl(e){let t=OI(e);return t.map((n,o)=>o===t.length-1?n.pathname:n.pathnameBase)}function Rs(e,t,n,o=!1){let s;typeof e=="string"?s=dr(e):(s={...e},De(!s.pathname||!s.pathname.includes("?"),Na("?","pathname","search",s)),De(!s.pathname||!s.pathname.includes("#"),Na("#","pathname","hash",s)),De(!s.search||!s.search.includes("#"),Na("#","search","hash",s)));let a=e===""||s.pathname==="",i=a?"/":s.pathname,l;if(i==null)l=n;else{let u=t.length-1;if(!o&&i.startsWith("..")){let h=i.split("/");for(;h[0]==="..";)h.shift(),u-=1;s.pathname=h.join("/")}l=u>=0?t[u]:"/"}let c=LI(s,l),d=i&&i!=="/"&&i.endsWith("/"),p=(a||i===".")&&n.endsWith("/");return!c.pathname.endsWith("/")&&(d||p)&&(c.pathname+="/"),c}var Dg=e=>e.replace(/\/\/+/g,"/"),gt=e=>Dg(e.join("/")),Jo=e=>e.replace(/\/+$/,""),BI=e=>Jo(e).replace(/^\/*/,"/"),zI=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,FI=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e,HI=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 jI(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}function VI(e){let t=e.map(n=>n.route.path).filter(Boolean);return gt(t)||"/"}var _g=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Tg(e,t){let n=e;if(typeof n!="string"||!RI.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let o=n,s=!1;if(_g)try{let a=new URL(window.location.href),i=n.startsWith("//")?new URL(a.protocol+n):new URL(n),l=jt(i.pathname,t);i.origin===a.origin&&l!=null?n=l+i.search+i.hash:s=!0}catch{it(!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 Rg=["POST","PUT","PATCH","DELETE"];new Set(Rg);var qI=["GET",...Rg];new Set(qI);var ur=$e(null);ur.displayName="DataRouter";var Ls=$e(null);Ls.displayName="DataRouterState";var Lg=$e(!1);function UI(){return ge(Lg)}var Og=$e({isTransitioning:!1});Og.displayName="ViewTransition";var QI=$e(new Map);QI.displayName="Fetchers";var GI=$e(null);GI.displayName="Await";var ot=$e(null);ot.displayName="Navigation";var eo=$e(null);eo.displayName="Location";var ct=$e({outlet:null,matches:[],isDataRoute:!1});ct.displayName="Route";var ec=$e(null);ec.displayName="RouteError";var Bg="REACT_ROUTER_ERROR",WI="REDIRECT",KI="ROUTE_ERROR_RESPONSE";function YI(e){if(e.startsWith(`${Bg}:${WI}:{`))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 ZI(e){if(e.startsWith(`${Bg}:${KI}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t=="object"&&t&&typeof t.status=="number"&&typeof t.statusText=="string")return new HI(t.status,t.statusText,t.data)}catch{}}function XI(e,{relative:t}={}){De(fr(),"useHref() may be used only in the context of a <Router> component.");let{basename:n,navigator:o}=ge(ot),{hash:s,pathname:a,search:i}=to(e,{relative:t}),l=a;return n!=="/"&&(l=a==="/"?n:gt([n,a])),o.createHref({pathname:l,search:i,hash:s})}function fr(){return ge(eo)!=null}function dt(){return De(fr(),"useLocation() may be used only in the context of a <Router> component."),ge(eo).location}var zg="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function Fg(e){ge(ot).static||vs(e)}function Ge(){let{isDataRoute:e}=ge(ct);return e?pE():JI()}function JI(){De(fr(),"useNavigate() may be used only in the context of a <Router> component.");let e=ge(ur),{basename:t,navigator:n}=ge(ot),{matches:o}=ge(ct),{pathname:s}=dt(),a=JSON.stringify(Jl(o)),i=ee(!1);return Fg(()=>{i.current=!0}),q((c,d={})=>{if(it(i.current,zg),!i.current)return;if(typeof c=="number"){n.go(c);return}let p=Rs(c,JSON.parse(a),s,d.relative==="path");e==null&&t!=="/"&&(p.pathname=p.pathname==="/"?t:gt([t,p.pathname])),(d.replace?n.replace:n.push)(p,d.state,d)},[t,n,a,s,e])}var eE=$e(null);function tE(e){let t=ge(ct).outlet;return Q(()=>t&&Se(eE.Provider,{value:e},t),[t,e])}function tc(){let{matches:e}=ge(ct);return e[e.length-1]?.params??{}}function to(e,{relative:t}={}){let{matches:n}=ge(ct),{pathname:o}=dt(),s=JSON.stringify(Jl(n));return Q(()=>Rs(e,JSON.parse(s),o,t==="path"),[e,s,o,t])}function nE(e,t){return Hg(e,t)}function Hg(e,t,n){De(fr(),"useRoutes() may be used only in the context of a <Router> component.");let{navigator:o}=ge(ot),{matches:s}=ge(ct),a=s[s.length-1],i=a?a.params:{},l=a?a.pathname:"/",c=a?a.pathnameBase:"/",d=a&&a.route;{let x=d&&d.path||"";Vg(l,!d||x.endsWith("*")||x.endsWith("*?"),`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${l}" (under <Route path="${x}">) 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.
44
-
45
- Please change the parent <Route path="${x}"> to <Route path="${x==="/"?"*":`${x}/*`}">.`)}let p=dt(),u;if(t){let x=typeof t=="string"?dr(t):t;De(c==="/"||x.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 "${x.pathname}" was given in the \`location\` prop.`),u=x}else u=p;let h=u.pathname||"/",m=h;if(c!=="/"){let x=c.replace(/^\//,"").split("/");m="/"+h.replace(/^\//,"").split("/").slice(x.length).join("/")}let g=n&&n.state.matches.length?n.state.matches.map(x=>Object.assign(x,{route:n.manifest[x.route.id]||x.route})):Pg(e,{pathname:m});it(d||g!=null,`No routes matched location "${u.pathname}${u.search}${u.hash}" `),it(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 "${u.pathname}${u.search}${u.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 b=iE(g&&g.map(x=>Object.assign({},x,{params:Object.assign({},i,x.params),pathname:gt([c,o.encodeLocation?o.encodeLocation(x.pathname.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:x.pathname]),pathnameBase:x.pathnameBase==="/"?c:gt([c,o.encodeLocation?o.encodeLocation(x.pathnameBase.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:x.pathnameBase])})),s,n);return t&&b?Se(eo.Provider,{value:{location:{pathname:"/",search:"",hash:"",state:null,key:"default",mask:void 0,...u},navigationType:"POP"}},b):b}function rE(){let e=fE(),t=jI(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=Se(Gn,null,Se("p",null,"💿 Hey developer 👋"),Se("p",null,"You can provide a way better UX than this when your app throws errors by providing your own ",Se("code",{style:a},"ErrorBoundary")," or"," ",Se("code",{style:a},"errorElement")," prop on your route.")),Se(Gn,null,Se("h2",null,"Unexpected Application Error!"),Se("h3",{style:{fontStyle:"italic"}},t),n?Se("pre",{style:s},n):null,i)}var oE=Se(rE,null),jg=class extends Ry{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=ZI(e.digest);n&&(e=n)}let t=e!==void 0?Se(ct.Provider,{value:this.props.routeContext},Se(ec.Provider,{value:e,children:this.props.component})):this.props.children;return this.context?Se(sE,{error:e},t):t}};jg.contextType=Lg;var Sa=new WeakMap;function sE({children:e,error:t}){let{basename:n}=ge(ot);if(typeof t=="object"&&t&&"digest"in t&&typeof t.digest=="string"){let o=YI(t.digest);if(o){let s=Sa.get(t);if(s)throw s;let a=Tg(o.location,n);if(_g&&!Sa.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 Sa.set(t,i),i}return Se("meta",{httpEquiv:"refresh",content:`0;url=${a.absoluteURL||a.to}`})}}return e}function aE({routeContext:e,match:t,children:n}){let o=ge(ur);return o&&o.static&&o.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(o.staticContext._deepestRenderedBoundaryId=t.route.id),Se(ct.Provider,{value:e},n)}function iE(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(u=>u.route.id&&a?.[u.route.id]!==void 0);De(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 u=s[p];if((u.route.HydrateFallback||u.route.hydrateFallbackElement)&&(l=p),u.route.id){let{loaderData:h,errors:m}=o,g=u.route.loader&&!h.hasOwnProperty(u.route.id)&&(!m||m[u.route.id]===void 0);if(u.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,u)=>{c(p,{location:o.location,params:o.matches?.[0]?.params??{},pattern:VI(o.matches),errorInfo:u})}:void 0;return s.reduceRight((p,u,h)=>{let m,g=!1,b=null,x=null;o&&(m=a&&u.route.id?a[u.route.id]:void 0,b=u.route.errorElement||oE,i&&(l<0&&h===0?(Vg("route-fallback",!1,"No `HydrateFallback` element provided to render during initial hydration"),g=!0,x=null):l===h&&(g=!0,x=u.route.hydrateFallbackElement||null)));let y=t.concat(s.slice(0,h+1)),w=()=>{let v;return m?v=b:g?v=x:u.route.Component?v=Se(u.route.Component,null):u.route.element?v=u.route.element:v=p,Se(aE,{match:u,routeContext:{outlet:p,matches:y,isDataRoute:o!=null},children:v})};return o&&(u.route.ErrorBoundary||u.route.errorElement||h===0)?Se(jg,{location:o.location,revalidation:o.revalidation,component:b,error:m,children:w(),routeContext:{outlet:null,matches:y,isDataRoute:!0},onError:d}):w()},null)}function nc(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function lE(e){let t=ge(ur);return De(t,nc(e)),t}function cE(e){let t=ge(Ls);return De(t,nc(e)),t}function dE(e){let t=ge(ct);return De(t,nc(e)),t}function rc(e){let t=dE(e),n=t.matches[t.matches.length-1];return De(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function uE(){return rc("useRouteId")}function fE(){let e=ge(ec),t=cE("useRouteError"),n=rc("useRouteError");return e!==void 0?e:t.errors?.[n]}function pE(){let{router:e}=lE("useNavigate"),t=rc("useNavigate"),n=ee(!1);return Fg(()=>{n.current=!0}),q(async(s,a={})=>{it(n.current,zg),n.current&&(typeof s=="number"?await e.navigate(s):await e.navigate(s,{fromRouteId:t,...a}))},[e,t])}var Dd={};function Vg(e,t,n){!t&&!Dd[e]&&(Dd[e]=!0,it(!1,n))}Te(hE);function hE({routes:e,manifest:t,future:n,state:o,isStatic:s,onError:a}){return Hg(e,void 0,{manifest:t,state:o,isStatic:s,onError:a})}function es({to:e,replace:t,state:n,relative:o}){De(fr(),"<Navigate> may be used only in the context of a <Router> component.");let{static:s}=ge(ot);it(!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}=ge(ct),{pathname:i}=dt(),l=Ge(),c=Rs(e,Jl(a),i,o==="path"),d=JSON.stringify(c);return X(()=>{l(JSON.parse(d),{replace:t,state:n,relative:o})},[l,d,o,t,n]),null}function mE(e){return tE(e.context)}function Be(e){De(!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 gE({basename:e="/",children:t=null,location:n,navigationType:o="POP",navigator:s,static:a=!1,useTransitions:i}){De(!fr(),"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=dr(n));let{pathname:d="/",search:p="",hash:u="",state:h=null,key:m="default",mask:g}=n,b=Q(()=>{let x=jt(d,l);return x==null?null:{location:{pathname:x,search:p,hash:u,state:h,key:m,mask:g},navigationType:o}},[l,d,p,u,h,m,o,g]);return it(b!=null,`<Router basename="${l}"> is not able to match the URL "${d}${p}${u}" because it does not start with the basename, so the <Router> won't render anything.`),b==null?null:Se(ot.Provider,{value:c},Se(eo.Provider,{children:t,value:b}))}function bE({children:e,location:t}){return nE(hi(e),t)}function hi(e,t=[]){let n=[];return _y.forEach(e,(o,s)=>{if(!Ty(o))return;let a=[...t,s];if(o.type===Gn){n.push.apply(n,hi(o.props.children,a));return}De(o.type===Be,`[${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>`),De(!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=hi(o.props.children,a)),n.push(i)}),n}var Fo="get",Ho="application/x-www-form-urlencoded";function Os(e){return typeof HTMLElement<"u"&&e instanceof HTMLElement}function xE(e){return Os(e)&&e.tagName.toLowerCase()==="button"}function yE(e){return Os(e)&&e.tagName.toLowerCase()==="form"}function vE(e){return Os(e)&&e.tagName.toLowerCase()==="input"}function wE(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function NE(e,t){return e.button===0&&(!t||t==="_self")&&!wE(e)}function mi(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 SE(e,t){let n=mi(e);return t&&t.forEach((o,s)=>{n.has(s)||t.getAll(s).forEach(a=>{n.append(s,a)})}),n}var vo=null;function kE(){if(vo===null)try{new FormData(document.createElement("form"),0),vo=!1}catch{vo=!0}return vo}var CE=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function ka(e){return e!=null&&!CE.has(e)?(it(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Ho}"`),null):e}function ME(e,t){let n,o,s,a,i;if(yE(e)){let l=e.getAttribute("action");o=l?jt(l,t):null,n=e.getAttribute("method")||Fo,s=ka(e.getAttribute("enctype"))||Ho,a=new FormData(e)}else if(xE(e)||vE(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?jt(c,t):null,n=e.getAttribute("formmethod")||l.getAttribute("method")||Fo,s=ka(e.getAttribute("formenctype"))||ka(l.getAttribute("enctype"))||Ho,a=new FormData(l,e),!kE()){let{name:d,type:p,value:u}=e;if(p==="image"){let h=d?`${d}.`:"";a.append(`${h}x`,"0"),a.append(`${h}y`,"0")}else d&&a.append(d,u)}}else{if(Os(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');n=Fo,o=null,s=Ho,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 oc(e,t){if(e===!1||e===null||typeof e>"u")throw new Error(t)}function qg(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&&jt(s.pathname,t)==="/"?s.pathname=`${Jo(t)}/_root.${o}`:s.pathname=`${Jo(s.pathname)}.${o}`,s}async function IE(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 EE(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 PE(e,t,n){let o=await Promise.all(e.map(async s=>{let a=t.routes[s.route.id];if(a){let i=await IE(a,n);return i.links?i.links():[]}return[]}));return _E(o.flat(1).filter(EE).filter(s=>s.rel==="stylesheet"||s.rel==="preload").map(s=>s.rel==="stylesheet"?{...s,rel:"prefetch",as:"style"}:{...s,rel:"prefetch"}))}function _d(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 u=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 u=="boolean")return u}return!0}):[]}function AE(e,t,{includeHydrateFallback:n}={}){return $E(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 $E(e){return[...new Set(e)]}function DE(e){let t={},n=Object.keys(e).sort();for(let o of n)t[o]=e[o];return t}function _E(e,t){let n=new Set;return new Set(t),e.reduce((o,s)=>{let a=JSON.stringify(DE(s));return n.has(a)||(n.add(a),o.push({key:a,link:s})),o},[])}function sc(){let e=ge(ur);return oc(e,"You must render this element inside a <DataRouterContext.Provider> element"),e}function TE(){let e=ge(Ls);return oc(e,"You must render this element inside a <DataRouterStateContext.Provider> element"),e}var ac=$e(void 0);ac.displayName="FrameworkContext";function ic(){let e=ge(ac);return oc(e,"You must render this element inside a <HydratedRouter> element"),e}function RE(e,t){let n=ge(ac),[o,s]=L(!1),[a,i]=L(!1),{onFocus:l,onBlur:c,onMouseEnter:d,onMouseLeave:p,onTouchStart:u}=t,h=ee(null);X(()=>{if(e==="render"&&i(!0),e==="viewport"){let b=y=>{y.forEach(w=>{i(w.isIntersecting)})},x=new IntersectionObserver(b,{threshold:.5});return h.current&&x.observe(h.current),()=>{x.disconnect()}}},[e]),X(()=>{if(o){let b=setTimeout(()=>{i(!0)},100);return()=>{clearTimeout(b)}}},[o]);let m=()=>{s(!0)},g=()=>{s(!1),i(!1)};return n?e!=="intent"?[a,h,{}]:[a,h,{onFocus:hr(l,m),onBlur:hr(c,g),onMouseEnter:hr(d,m),onMouseLeave:hr(p,g),onTouchStart:hr(u,m)}]:[!1,h,{}]}function hr(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function LE({page:e,...t}){let n=UI(),{router:o}=sc(),s=Q(()=>Pg(o.routes,e,o.basename),[o.routes,e,o.basename]);return s?n?Se(BE,{page:e,matches:s,...t}):Se(zE,{page:e,matches:s,...t}):null}function OE(e){let{manifest:t,routeModules:n}=ic(),[o,s]=L([]);return X(()=>{let a=!1;return PE(e,t,n).then(i=>{a||s(i)}),()=>{a=!0}},[e,t,n]),o}function BE({page:e,matches:t,...n}){let o=dt(),{future:s}=ic(),{basename:a}=sc(),i=Q(()=>{if(e===o.pathname+o.search+o.hash)return[];let l=qg(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 Se(Gn,null,i.map(l=>Se("link",{key:l,rel:"prefetch",as:"fetch",href:l,...n})))}function zE({page:e,matches:t,...n}){let o=dt(),{future:s,manifest:a,routeModules:i}=ic(),{basename:l}=sc(),{loaderData:c,matches:d}=TE(),p=Q(()=>_d(e,t,d,a,o,"data"),[e,t,d,a,o]),u=Q(()=>_d(e,t,d,a,o,"assets"),[e,t,d,a,o]),h=Q(()=>{if(e===o.pathname+o.search+o.hash)return[];let b=new Set,x=!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?x=!0:b.add(w.route.id))}),b.size===0)return[];let y=qg(e,l,s.unstable_trailingSlashAwareDataRequests,"data");return x&&b.size>0&&y.searchParams.set("_routes",t.filter(w=>b.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]),m=Q(()=>AE(u,a),[u,a]),g=OE(u);return Se(Gn,null,h.map(b=>Se("link",{key:b,rel:"prefetch",as:"fetch",href:b,...n})),m.map(b=>Se("link",{key:b,rel:"modulepreload",href:b,...n})),g.map(({key:b,link:x})=>Se("link",{key:b,nonce:n.nonce,...x,crossOrigin:x.crossOrigin??n.crossOrigin})))}function FE(...e){return t=>{e.forEach(n=>{typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var HE=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";try{HE&&(window.__reactRouterVersion="7.15.0")}catch{}function jE({basename:e,children:t,useTransitions:n,window:o}){let s=ee();s.current==null&&(s.current=bI({window:o,v5Compat:!0}));let a=s.current,[i,l]=L({action:a.action,location:a.location}),c=q(d=>{n===!1?l(d):Ki(()=>l(d))},[n]);return vs(()=>a.listen(c),[a,c]),Se(gE,{basename:e,children:t,location:i.location,navigationType:i.action,navigator:a,useTransitions:n})}var Ug=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Qg=Oe(function({onClick:t,discover:n="render",prefetch:o="none",relative:s,reloadDocument:a,replace:i,mask:l,state:c,target:d,to:p,preventScrollReset:u,viewTransition:h,defaultShouldRevalidate:m,...g},b){let{basename:x,navigator:y,useTransitions:w}=ge(ot),v=typeof p=="string"&&Ug.test(p),N=Tg(p,x);p=N.to;let S=XI(p,{relative:s}),k=dt(),M=null;if(l){let _=Rs(l,[],k.mask?k.mask.pathname:"/",!0);x!=="/"&&(_.pathname=_.pathname==="/"?x:gt([x,_.pathname])),M=y.createHref(_)}let[D,E,B]=RE(o,g),A=QE(p,{replace:i,mask:l,state:c,target:d,preventScrollReset:u,relative:s,viewTransition:h,defaultShouldRevalidate:m,useTransitions:w});function O(_){t&&t(_),_.defaultPrevented||A(_)}let $=!(N.isExternal||a),I=Se("a",{...g,...B,href:($?M:void 0)||N.absoluteURL||S,onClick:$?O:t,ref:FE(b,E),target:d,"data-discover":!v&&n==="render"?"true":void 0});return D&&!v?Se(Gn,null,I,Se(LE,{page:S})):I});Qg.displayName="Link";var VE=Oe(function({"aria-current":t="page",caseSensitive:n=!1,className:o="",end:s=!1,style:a,to:i,viewTransition:l,children:c,...d},p){let u=to(i,{relative:d.relative}),h=dt(),m=ge(Ls),{navigator:g,basename:b}=ge(ot),x=m!=null&&ZE(u)&&l===!0,y=g.encodeLocation?g.encodeLocation(u).pathname:u.pathname,w=h.pathname,v=m&&m.navigation&&m.navigation.location?m.navigation.location.pathname:null;n||(w=w.toLowerCase(),v=v?v.toLowerCase():null,y=y.toLowerCase()),v&&b&&(v=jt(v,b)||v);const N=y!=="/"&&y.endsWith("/")?y.length-1:y.length;let S=w===y||!s&&w.startsWith(y)&&w.charAt(N)==="/",k=v!=null&&(v===y||!s&&v.startsWith(y)&&v.charAt(y.length)==="/"),M={isActive:S,isPending:k,isTransitioning:x},D=S?t:void 0,E;typeof o=="function"?E=o(M):E=[o,S?"active":null,k?"pending":null,x?"transitioning":null].filter(Boolean).join(" ");let B=typeof a=="function"?a(M):a;return Se(Qg,{...d,"aria-current":D,className:E,ref:p,style:B,to:i,viewTransition:l},typeof c=="function"?c(M):c)});VE.displayName="NavLink";var qE=Oe(({discover:e="render",fetcherKey:t,navigate:n,reloadDocument:o,replace:s,state:a,method:i=Fo,action:l,onSubmit:c,relative:d,preventScrollReset:p,viewTransition:u,defaultShouldRevalidate:h,...m},g)=>{let{useTransitions:b}=ge(ot),x=KE(),y=YE(l,{relative:d}),w=i.toLowerCase()==="get"?"get":"post",v=typeof l=="string"&&Ug.test(l);return Se("form",{ref:g,method:w,action:y,onSubmit:o?c:S=>{if(c&&c(S),S.defaultPrevented)return;S.preventDefault();let k=S.nativeEvent.submitter,M=k?.getAttribute("formmethod")||i,D=()=>x(k||S.currentTarget,{fetcherKey:t,method:M,navigate:n,replace:s,state:a,relative:d,preventScrollReset:p,viewTransition:u,defaultShouldRevalidate:h});b&&n!==!1?Ki(()=>D()):D()},...m,"data-discover":!v&&e==="render"?"true":void 0})});qE.displayName="Form";function UE(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Gg(e){let t=ge(ur);return De(t,UE(e)),t}function QE(e,{target:t,replace:n,mask:o,state:s,preventScrollReset:a,relative:i,viewTransition:l,defaultShouldRevalidate:c,useTransitions:d}={}){let p=Ge(),u=dt(),h=to(e,{relative:i});return q(m=>{if(NE(m,t)){m.preventDefault();let g=n!==void 0?n:Or(u)===Or(h),b=()=>p(e,{replace:g,mask:o,state:s,preventScrollReset:a,relative:i,viewTransition:l,defaultShouldRevalidate:c});d?Ki(()=>b()):b()}},[u,p,h,n,o,s,t,e,a,i,l,c,d])}function Wg(e){it(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=ee(mi(e)),n=ee(!1),o=dt(),s=Q(()=>SE(o.search,n.current?null:t.current),[o.search]),a=Ge(),i=q((l,c)=>{const d=mi(typeof l=="function"?l(new URLSearchParams(s)):l);n.current=!0,a("?"+d,c)},[a,s]);return[s,i]}var GE=0,WE=()=>`__${String(++GE)}__`;function KE(){let{router:e}=Gg("useSubmit"),{basename:t}=ge(ot),n=uE(),o=e.fetch,s=e.navigate;return q(async(a,i={})=>{let{action:l,method:c,encType:d,formData:p,body:u}=ME(a,t);if(i.navigate===!1){let h=i.fetcherKey||WE();await o(h,n,i.action||l,{defaultShouldRevalidate:i.defaultShouldRevalidate,preventScrollReset:i.preventScrollReset,formData:p,body:u,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:u,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 YE(e,{relative:t}={}){let{basename:n}=ge(ot),o=ge(ct);De(o,"useFormAction must be used inside a RouteContext");let[s]=o.matches.slice(-1),a={...to(e||".",{relative:t})},i=dt();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(u=>u).forEach(u=>l.append("index",u));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:gt([n,a.pathname])),Or(a)}function ZE(e,{relative:t}={}){let n=ge(Og);De(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:o}=Gg("useViewTransitionState"),s=to(e,{relative:t});if(!n.isTransitioning)return!1;let a=jt(n.currentLocation.pathname,o)||n.currentLocation.pathname,i=jt(n.nextLocation.pathname,o)||n.nextLocation.pathname;return Xo(s.pathname,i)!=null||Xo(s.pathname,a)!=null}const XE=3e4;function JE(e){const t=ee(e);t.current=e,X(()=>{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>=XE&&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 gi="disconnected";const bi=new Set;function eP(){for(const e of bi)e()}function tP(e){gi!==e&&(gi=e,eP())}function nP(e){return bi.add(e),()=>{bi.delete(e)}}function Td(){return gi}function rP(){return ws(nP,Td,Td)}let Cr=null;function xi(){if(!Cr){const e=window.location.origin,t=localStorage.getItem("camstack_admin_token")??void 0;Cr=tp({serverUrl:e,token:t,onConnectionChange:n=>tP(n)})}return Cr}function Mr(){Cr?.close(),Cr=null}function oP(e){const t=Gt();return t===null?r("div",{className:"rounded-md border border-warning/40 bg-warning/10 p-3 text-xs text-warning",children:"zone-editor: no DeviceContext — declare this field inside a top-tab section rendered from a device-detail page."}):r(Ze,{widgetId:"pipeline-orchestrator/zone-editor",host:"device-tab",deviceId:t})}function sP({deviceId:e}){return f("div",{className:mp,children:[f("div",{className:`grid ${gp}`,style:{gridTemplateColumns:"repeat(auto-fit, minmax(min(100%, 340px), 1fr))"},children:[r(Ze,{widgetId:"pipeline-analytics/live-occupancy-panel",host:"device-tab",deviceId:e}),r(Ze,{widgetId:"pipeline-analytics/audio-metrics-panel",host:"device-tab",deviceId:e})]}),r(Ze,{widgetId:"pipeline-analytics/audio-history-chart",host:"device-tab",deviceId:e}),r(Ze,{widgetId:"pipeline-analytics/occupancy-history-chart",host:"device-tab",deviceId:e}),r(Ze,{widgetId:"pipeline-analytics/motion-history-chart",host:"device-tab",deviceId:e}),r(Ze,{widgetId:"pipeline-analytics/detection-history-chart",host:"device-tab",deviceId:e})]})}function aP(e){const t=Gt();return t===null?r("div",{className:"rounded-md border border-warning/40 bg-warning/10 p-3 text-xs text-warning",children:"live-stats: no DeviceContext — declare this field inside a top-tab section rendered from a device-detail page."}):r(sP,{deviceId:t})}/**
46
- * @license lucide-react v0.511.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 iP=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),lP=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,o)=>o?o.toUpperCase():n.toLowerCase()),Rd=e=>{const t=lP(e);return t.charAt(0).toUpperCase()+t.slice(1)},Kg=(...e)=>e.filter((t,n,o)=>!!t&&t.trim()!==""&&o.indexOf(t)===n).join(" ").trim(),cP=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};/**
51
- * @license lucide-react v0.511.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 dP={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.511.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 uP=Oe(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:o,className:s="",children:a,iconNode:i,...l},c)=>Se("svg",{ref:c,...dP,width:t,height:t,stroke:e,strokeWidth:o?Number(n)*24/Number(t):n,className:Kg("lucide",s),...!a&&!cP(l)&&{"aria-hidden":"true"},...l},[...i.map(([d,p])=>Se(d,p)),...Array.isArray(a)?a:[a]]));/**
61
- * @license lucide-react v0.511.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 le=(e,t)=>{const n=Oe(({className:o,...s},a)=>Se(uP,{ref:a,iconNode:t,className:Kg(`lucide-${iP(Rd(e))}`,`lucide-${e}`,o),...s}));return n.displayName=Rd(e),n};/**
66
- * @license lucide-react v0.511.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 fP=[["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"}]],no=le("activity",fP);/**
71
- * @license lucide-react v0.511.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 pP=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],hP=le("arrow-left",pP);/**
76
- * @license lucide-react v0.511.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 mP=[["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"}]],gP=le("battery-full",mP);/**
81
- * @license lucide-react v0.511.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 bP=[["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"}]],Bs=le("bell",bP);/**
86
- * @license lucide-react v0.511.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 xP=[["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"}]],yP=le("bot",xP);/**
91
- * @license lucide-react v0.511.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 vP=[["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"}]],zs=le("box",vP);/**
96
- * @license lucide-react v0.511.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 wP=[["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"}]],NP=le("boxes",wP);/**
101
- * @license lucide-react v0.511.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 SP=[["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"}]],Yg=le("calendar",SP);/**
106
- * @license lucide-react v0.511.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 kP=[["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"}]],Br=le("camera",kP);/**
111
- * @license lucide-react v0.511.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 CP=[["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"}]],Zg=le("cctv",CP);/**
116
- * @license lucide-react v0.511.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 MP=[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]],IP=le("check-check",MP);/**
121
- * @license lucide-react v0.511.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 EP=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],At=le("check",EP);/**
126
- * @license lucide-react v0.511.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 PP=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],It=le("chevron-down",PP);/**
131
- * @license lucide-react v0.511.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 AP=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],lc=le("chevron-left",AP);/**
136
- * @license lucide-react v0.511.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 $P=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],$t=le("chevron-right",$P);/**
141
- * @license lucide-react v0.511.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 DP=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],_P=le("chevron-up",DP);/**
146
- * @license lucide-react v0.511.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 TP=[["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"}]],Fs=le("circle-alert",TP);/**
151
- * @license lucide-react v0.511.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 RP=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],Xg=le("circle-check",RP);/**
156
- * @license lucide-react v0.511.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 LP=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]],Jg=le("circle-dot",LP);/**
161
- * @license lucide-react v0.511.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 OP=[["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"}]],BP=le("circle-help",OP);/**
166
- * @license lucide-react v0.511.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 zP=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]],FP=le("clock",zP);/**
171
- * @license lucide-react v0.511.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 HP=[["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"}]],tt=le("cpu",HP);/**
176
- * @license lucide-react v0.511.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 jP=[["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"}]],VP=le("crosshair",jP);/**
181
- * @license lucide-react v0.511.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 qP=[["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"}]],UP=le("database",qP);/**
186
- * @license lucide-react v0.511.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 QP=[["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"}]],vn=le("download",QP);/**
191
- * @license lucide-react v0.511.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 GP=[["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"}]],WP=le("ellipsis-vertical",GP);/**
196
- * @license lucide-react v0.511.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 KP=[["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"}]],YP=le("external-link",KP);/**
201
- * @license lucide-react v0.511.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 ZP=[["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"}]],XP=le("eye-off",ZP);/**
206
- * @license lucide-react v0.511.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 JP=[["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"}]],cc=le("eye",JP);/**
211
- * @license lucide-react v0.511.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 e4=[["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"}]],Ir=le("film",e4);/**
216
- * @license lucide-react v0.511.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 t4=[["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"}]],n4=le("flame",t4);/**
221
- * @license lucide-react v0.511.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 r4=[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]],eb=le("gauge",r4);/**
226
- * @license lucide-react v0.511.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 o4=[["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"}]],yi=le("ghost",o4);/**
231
- * @license lucide-react v0.511.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 s4=[["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"}]],tb=le("git-branch",s4);/**
236
- * @license lucide-react v0.511.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 a4=[["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"}]],i4=le("globe",a4);/**
241
- * @license lucide-react v0.511.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 l4=[["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"}]],vi=le("hard-drive",l4);/**
246
- * @license lucide-react v0.511.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 c4=[["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"}]],d4=le("house",c4);/**
251
- * @license lucide-react v0.511.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 u4=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],ts=le("info",u4);/**
256
- * @license lucide-react v0.511.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 f4=[["path",{d:"m5 8 6 6",key:"1wu5hv"}],["path",{d:"m4 14 6-6 2-3",key:"1k1g8d"}],["path",{d:"M2 5h12",key:"or177f"}],["path",{d:"M7 2h1",key:"1t2jsx"}],["path",{d:"m22 22-5-10-5 10",key:"don7ne"}],["path",{d:"M14 18h6",key:"1m8k6r"}]],p4=le("languages",f4);/**
261
- * @license lucide-react v0.511.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 h4=[["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"}]],m4=le("layers",h4);/**
266
- * @license lucide-react v0.511.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 g4=[["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"}]],nb=le("layout-dashboard",g4);/**
271
- * @license lucide-react v0.511.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 b4=[["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"}]],x4=le("lightbulb",b4);/**
276
- * @license lucide-react v0.511.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 y4=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],Le=le("loader-circle",y4);/**
281
- * @license lucide-react v0.511.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 v4=[["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"}]],w4=le("log-out",v4);/**
286
- * @license lucide-react v0.511.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 N4=[["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"}]],S4=le("map-pin",N4);/**
291
- * @license lucide-react v0.511.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 k4=[["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"}]],dc=le("memory-stick",k4);/**
296
- * @license lucide-react v0.511.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 C4=[["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 18h16",key:"19g7jn"}],["path",{d:"M4 6h16",key:"1o0s65"}]],M4=le("menu",C4);/**
301
- * @license lucide-react v0.511.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 I4=[["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"}]],wi=le("mic",I4);/**
306
- * @license lucide-react v0.511.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 E4=[["path",{d:"M5 12h14",key:"1ays0h"}]],P4=le("minus",E4);/**
311
- * @license lucide-react v0.511.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 A4=[["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"}]],$4=le("monitor",A4);/**
316
- * @license lucide-react v0.511.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 D4=[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]],rb=le("moon",D4);/**
321
- * @license lucide-react v0.511.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 _4=[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m19 9 3 3-3 3",key:"1mg7y2"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m5 9-3 3 3 3",key:"j64kie"}],["path",{d:"m9 5 3-3 3 3",key:"l8vdw6"}]],T4=le("move",_4);/**
326
- * @license lucide-react v0.511.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 R4=[["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"}]],uc=le("network",R4);/**
331
- * @license lucide-react v0.511.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 L4=[["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"}]],ob=le("package",L4);/**
336
- * @license lucide-react v0.511.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 O4=[["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"}]],Hs=le("pencil",O4);/**
341
- * @license lucide-react v0.511.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 B4=[["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"}]],sb=le("pin",B4);/**
346
- * @license lucide-react v0.511.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 z4=[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]],ab=le("play",z4);/**
351
- * @license lucide-react v0.511.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 F4=[["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"}]],ib=le("plug",F4);/**
356
- * @license lucide-react v0.511.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 H4=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],_n=le("plus",H4);/**
361
- * @license lucide-react v0.511.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 j4=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],lb=le("power",j4);/**
366
- * @license lucide-react v0.511.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 V4=[["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"}]],ns=le("puzzle",V4);/**
371
- * @license lucide-react v0.511.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 q4=[["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"}]],U4=le("radar",q4);/**
376
- * @license lucide-react v0.511.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 Q4=[["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"}]],fc=le("radio",Q4);/**
381
- * @license lucide-react v0.511.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 G4=[["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"}]],Et=le("refresh-cw",G4);/**
386
- * @license lucide-react v0.511.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 W4=[["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"}]],K4=le("rotate-ccw",W4);/**
391
- * @license lucide-react v0.511.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 Y4=[["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"}]],wn=le("rotate-cw",Y4);/**
396
- * @license lucide-react v0.511.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 Z4=[["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"}]],st=le("scroll-text",Z4);/**
401
- * @license lucide-react v0.511.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 X4=[["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"}]],J4=le("search-x",X4);/**
406
- * @license lucide-react v0.511.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 eA=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],cb=le("search",eA);/**
411
- * @license lucide-react v0.511.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 tA=[["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"}]],ro=le("server",tA);/**
416
- * @license lucide-react v0.511.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 nA=[["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"}]],bt=le("settings",nA);/**
421
- * @license lucide-react v0.511.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 rA=[["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"}]],oA=le("shield-x",rA);/**
426
- * @license lucide-react v0.511.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 sA=[["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"}]],aA=le("shield",sA);/**
431
- * @license lucide-react v0.511.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 iA=[["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"}]],wo=le("skull",iA);/**
436
- * @license lucide-react v0.511.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 lA=[["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"}]],db=le("square-check-big",lA);/**
441
- * @license lucide-react v0.511.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 cA=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],pc=le("square",cA);/**
446
- * @license lucide-react v0.511.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 dA=[["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"}]],uA=le("sun",dA);/**
451
- * @license lucide-react v0.511.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 fA=[["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"}]],pA=le("table-2",fA);/**
456
- * @license lucide-react v0.511.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 hA=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],ub=le("terminal",hA);/**
461
- * @license lucide-react v0.511.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 mA=[["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"}]],nt=le("trash-2",mA);/**
466
- * @license lucide-react v0.511.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 gA=[["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"}]],Bt=le("triangle-alert",gA);/**
471
- * @license lucide-react v0.511.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 bA=[["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"}]],hc=le("upload",bA);/**
476
- * @license lucide-react v0.511.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 xA=[["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"}]],yA=le("users",xA);/**
481
- * @license lucide-react v0.511.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 vA=[["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"}]],fb=le("video",vA);/**
486
- * @license lucide-react v0.511.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 wA=[["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"}]],pb=le("wifi-off",wA);/**
491
- * @license lucide-react v0.511.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 NA=[["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"}]],Wn=le("wifi",NA);/**
496
- * @license lucide-react v0.511.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 SA=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],qe=le("x",SA);/**
501
- * @license lucide-react v0.511.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 kA=[["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"}]],CA=le("wrench",kA);/**
506
- * @license lucide-react v0.511.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 MA=[["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"}]],mc=le("zap",MA);function IA(e){const t=Ae();return En({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 EA(e){return typeof e=="string"&&e.length>0&&e!=="undefined"&&e!=="null"}function PA(e={}){const t=ke(),n=ir(void 0,{staleTime:1e4,enabled:e.enabled??!0}),o=Q(()=>(n.data??[]).filter(i=>EA(i.nodeId)),[n.data]),s=q(()=>{t.invalidateQueries({queryKey:["pipelineOrchestrator","listAgentSettings"]})},[t]);return{agents:o,isLoading:n.isLoading,isError:n.isError,error:n.error,refetch:()=>{n.refetch()},invalidate:s}}function AA({field:e,disabled:t}){const n=ke(),o=e.deviceId,s=IA(e.catalogResolver),a=Bl({agentNodeId:e.nodeId}),i=Fl({deviceId:o}),c=Bm({onSuccess:()=>{n.invalidateQueries({queryKey:[["pipelineOrchestrator","getCameraSettings"]]}),n.invalidateQueries({queryKey:[["deviceManager"]]})}}),d=s.data,p=a.data??null,u=i.data??null,h=Q(()=>d?DA(d,p,u):[],[d,p,u]),m=Q(()=>{if(!p)return{};const g={};for(const[b,x]of Object.entries(p.addonDefaults))g[b]=x.enabled;return g},[p]);return s.error?f("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?f("div",{className:"text-xs text-foreground-subtle animate-pulse",children:["Loading pipeline for ",e.nodeId,"…"]}):f("div",{className:"col-span-full space-y-4",children:[f("div",{className:"flex items-center gap-2 text-[11px] text-foreground-subtle",children:["Agent: ",r("span",{className:"text-foreground",children:e.nodeId}),f("span",{className:"ml-2",children:["Engine: ",r("span",{className:"text-foreground font-mono",children:`${d.selectedEngine.runtime}/${d.selectedEngine.backend}`})]}),f("span",{className:"ml-auto text-[10px]",children:["Model + settings edited on Pipeline → ",e.nodeId,"."]})]}),r(Cl,{schema:d,steps:h,onChange:()=>{},templates:[],selectedTemplateId:null,onSelectTemplate:()=>{},onSaveTemplate:()=>{},onUpdateTemplate:()=>{},onDeleteTemplate:()=>{},readOnly:t===!0,hideTemplates:!0,toggleMode:"threeState",hideModelAndSettings:!0,overrides:u?.stepToggles??{},onOverrideChange:(g,b)=>c.mutate({deviceId:o,addonId:g,enabled:b}),inheritedEnabledByAddon:m}),r($A,{deviceId:o,currentAgentNodeId:e.nodeId,catalog:d,pipelineByAgent:u?.pipelineByAgent??{},disabled:t===!0})]})}function $A({deviceId:e,currentAgentNodeId:t,catalog:n,pipelineByAgent:o,disabled:s}){const a=ke(),[i,l]=L(!1),[c,d]=L(t),{agents:p}=PA({enabled:i}),u=Hm({deviceId:e,agentNodeId:c},{enabled:i}),m=Fm({onSuccess:()=>{a.invalidateQueries({queryKey:[["pipelineOrchestrator","getCameraSettings"]]}),a.invalidateQueries({queryKey:[["pipelineOrchestrator","resolvePipeline"]]})}}),g=o[c]??null,b=p,x=Q(()=>g?_A(g.steps,n):[],[g,n]),y=w=>{const v=g?.audio??null;m.mutate({deviceId:e,agentNodeId:c,pipeline:{steps:TA(w),audio:v?{modelId:v.modelId,enabled:v.enabled}:null}})};return f("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[f("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(It,{className:"h-3 w-3"}):r($t,{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&&f("div",{className:"border-t border-border px-4 py-3 space-y-3",children:[f("div",{className:"flex items-center gap-2 text-xs",children:[r("span",{className:"text-foreground-subtle",children:"Agent:"}),f("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"&&f("option",{value:t,children:[t," (current)"]}),b.filter(w=>w.nodeId!==t).map(w=>r("option",{value:w.nodeId,children:w.nodeId},w.nodeId))]}),o[c]&&f("button",{type:"button",onClick:()=>{window.confirm(`Remove custom pipeline override for ${c}? The camera will revert to the agent default + step toggles.`)&&m.mutate({deviceId:e,agentNodeId:c,pipeline:null})},disabled:s||m.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(nt,{className:"h-3 w-3"}),"Remove override"]})]}),g?r(Cl,{schema:n,steps:x,onChange:y,templates:[],selectedTemplateId:null,onSelectTemplate:()=>{},onSaveTemplate:()=>{},onUpdateTemplate:()=>{},onDeleteTemplate:()=>{},readOnly:s,hideTemplates:!0}):f("div",{className:"text-xs text-foreground-subtle space-y-2",children:[f("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=u.data;w&&m.mutate({deviceId:e,agentNodeId:c,pipeline:{steps:w.steps,audio:w.audio?{modelId:w.audio.modelId,enabled:w.audio.enabled}:null}})},disabled:s||m.isPending||!u.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 DA(e,t,n){const o=d=>{for(const p of e.slots)for(const u of p.addons)if(u.id===d)return u;return null},s=d=>{const p=t?.addonDefaults[d.id],u=p?.enabled??d.enabledByDefault??!0,h=n?.stepToggles?.[d.id],m=h!==void 0?h:u;return{addonId:d.id,addonName:d.name,slot:d.slot,inputClasses:[...d.inputClasses],outputClasses:[...d.outputClasses],enabled:m,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 u=o(d);u&&u.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 u=o(d);if(u)for(const[h,m]of a){if(h===d)continue;const g=o(h);if(g&&l.has(h)&&g.outputClasses.some(b=>u.inputClasses.includes(b))){m.children.push(p),l.add(d),c=!0;break}}}}return i}function _A(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 TA(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 RA({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 LA(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 OA(e){return`${e.inputSize.width}x${e.inputSize.height}`}function BA(e){return e.formats?Object.keys(e.formats).filter(t=>e.formats[t]!==void 0):[]}function zA({entry:e,selected:t,onSelect:n,disabled:o}){const s=LA(e),a=OA(e),i=BA(e);return f("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:f("div",{className:"flex-1 min-w-0",children:[f("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-xs font-semibold text-foreground truncate",children:e.name}),t&&r(At,{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})]})}),f("div",{className:"flex items-center gap-3 mt-2 flex-wrap",children:[f("span",{className:"inline-flex items-center gap-1 text-[10px] text-foreground-subtle",children:[r(tt,{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&&f("span",{className:"text-[10px] text-foreground-subtle",children:[e.labels.length," label",e.labels.length!==1?"s":""]})]})]})}function FA({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]=L(a?"catalog":"custom"),p=t==null?"":String(t);return f("div",{className:"space-y-3",children:[l.length>1&&r(RA,{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(u=>r(zA,{entry:u,selected:p===u.id,onSelect:()=>n(u.id),disabled:o||e.disabled},u.id))}),c==="catalog"&&!a&&f("div",{className:"rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2",children:[r(ts,{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&&f("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:u=>n(u.target.value)}),e.acceptFormats&&e.acceptFormats.length>0&&f("p",{className:"text-[10px] text-foreground-subtle",children:["Accepted formats: ",e.acceptFormats.join(", ")]})]}),(e.compatibilityNote||e.conversionGuideUrl)&&f("div",{className:"flex items-start justify-between gap-3 pt-1",children:[e.compatibilityNote&&f("p",{className:"flex items-start gap-1 text-[10px] text-foreground-subtle",children:[r(ts,{className:"h-3 w-3 mt-0.5 shrink-0"}),e.compatibilityNote]}),e.conversionGuideUrl&&f("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(YP,{className:"h-3 w-3"})]})]})]})}function hb(e){const t=Ae();return Eg(t.trpcClient,e)}function HA({deviceId:e,deviceName:t,hasPTZ:n=!1,className:o}){const s=Ae(),a=typeof window<"u"?window.location.origin:"",i=Number.isFinite(e),[l,c]=L(!1),d=i&&n&&l,p=lt(s.trpcClient,i?e:null),u=ee(!1),{data:h,isLoading:m,isFetching:g,refetch:b}=En({queryKey:["device",e,"snapshot.getSnapshot"],queryFn:()=>{const E=u.current;return u.current=!1,p?.snapshot?.getSnapshot({force:E})??null},enabled:!!p&&i,staleTime:5e3,retry:!1}),x=()=>{u.current=!0,b()},{streams:y,pipelineMetrics:w,createSession:v,sendAnswer:N,closeSession:S}=Yl(s.trpcClient,i?e:null),k=hb(i?e:null),M=Zl(s.trpcClient,i?e:0,{enabled:d}),D=h?`data:${h.contentType};base64,${h.base64}`:null;return r(Ul,{serverUrl:a,createSession:v,sendAnswer:N,closeSession:S,streams:y,pipelineMetrics:w,deviceName:t,phase:k.phase,detections:k,defaultShowDetections:!1,defaultShowMotion:!1,autoPlay:!1,showPlayStop:!0,snapshotSrc:D,snapshotLoading:m||g,onRefreshSnapshot:x,ptzAvailable:i&&n,ptzShown:d,onPtzToggle:()=>c(E=>!E),ptzOverlay:d?r(Wl,{controls:M}):void 0,className:o})}function jA(){const e=Gt(),t=Il();if(e===null)return null;const n=typeof t?.name=="string"?t.name:"",s=(t?.features??[]).includes(mn.PanTiltZoom);return r(HA,{deviceId:e,deviceName:n,hasPTZ:s})}function at(e,t){const n=Ae(),o=ke(),[s,a]=L(n.connectionVersion);X(()=>n.subscribeConnectionEvents((c,d)=>{c==="connected"&&a(d)}),[n]);const i=t.join("|"),l=JSON.stringify(e);X(()=>{const c=[],d=()=>{const p=JSON.parse(l),h=p.length===1&&Array.isArray(p[0])?p:[p];o.invalidateQueries({queryKey:h})};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])}function No({icon:e,label:t,value:n,subtext:o,color:s}){return f("div",{className:"rounded-lg border border-border bg-surface p-2 sm:p-2.5 min-w-0",children:[f("div",{className:"flex items-center gap-1.5 mb-0.5 min-w-0",children:[r(e,{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),r("span",{className:`${Wo} uppercase tracking-wider whitespace-nowrap overflow-hidden text-ellipsis min-w-0`,children:t})]}),r("p",{className:`${s?`${ri.replace("text-foreground","")} ${s}`:ri} whitespace-nowrap overflow-hidden text-ellipsis`,children:n}),o&&r("p",{className:`${Wo} mt-0.5 truncate`,children:o})]})}function So({label:e,value:t,warning:n}){return f("div",{className:"min-w-0",children:[r("p",{className:`${Wo} truncate`,children:e}),r("p",{className:`text-[11px] font-medium truncate ${n?"text-warning":"text-foreground"}`,children:t})]})}function Lt({label:e,value:t}){return f("div",{className:`${bp} 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 VA(){const e=Gt();at(["pipelineOrchestrator","getPipelineAssignment"],["pipeline.camera-assigned","pipeline.camera-unassigned","pipeline.camera-updated"]),at(["pipelineRunner","getCameraMetrics"],["pipeline.camera-metrics-snapshot"]);const{data:t}=Ds({deviceId:e??0},{enabled:e!==null,staleTime:3e4}),n=t?.agentNodeId??null,s=typeof n=="string"&&n.length>0&&!n.startsWith("addon:")?n:void 0,{data:a}=Hl({deviceId:e??0,...s?{nodeId:s}:{}},{enabled:e!==null,staleTime:2e3,retry:!1}),i=Ae(),l=lt(i.trpcClient,e),{data:c}=En({queryKey:["device",e,"pipelineAnalytics.getActiveTracks"],queryFn:()=>l?.pipelineAnalytics?.getActiveTracks({})??[],enabled:!!l&&e!==null,refetchInterval:5e3,retry:!1});if(e===null)return null;const d=a?.phase??null,p=a?.detectionMode??null,u=Number(a?.actualFps??0),h=Number(a?.configuredFps??0),m=Number(a?.avgInferenceTimeMs??0),g=Number(a?.queueDepth??0),b=Number(a?.droppedFrames??0),x=An(d??"watching"),y=c?.length??0;return f("div",{className:"grid grid-cols-2 sm:grid-cols-2 lg:grid-cols-4 gap-2 sm:gap-3",children:[r(No,{icon:no,label:"Phase",value:x.label,color:x.textColor,subtext:p??void 0}),r(No,{icon:eb,label:"Detection FPS",value:`${u.toFixed(1)}`,subtext:h>0?`target: ${h}`:void 0}),r(No,{icon:tt,label:"Inference",value:`${m.toFixed(1)} ms`,subtext:g>0?`queue: ${g}`:void 0}),r(No,{icon:cc,label:"Active Tracks",value:String(y),subtext:b>0?`dropped: ${b}`:void 0})]})}function Ca(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function qA(){const e=Gt(),{data:t}=Ol({deviceId:e??0},{enabled:e!==null,refetchInterval:5e3});if(e===null)return null;const n=t?.streams??{},o=Object.entries(n);return o.length===0?null:f("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r("div",{className:"border-b border-border px-3 sm:px-4 py-2",children:r("h2",{className:"text-[11px] font-semibold text-foreground uppercase tracking-wider",children:"Stream Network"})}),r("div",{className:"divide-y divide-border",children:o.map(([s,a])=>f("div",{className:"px-3 sm:px-4 py-2",children:[f("div",{className:"flex items-center gap-1.5 mb-1.5",children:[r(Wn,{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),r("span",{className:"text-[11px] font-medium text-foreground truncate",children:s})]}),f("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-2",children:[r(So,{label:"Nominal",value:Ca(a.nominalBitrateKbps??0)}),r(So,{label:"Observed",value:Ca(a.observedBitrateKbps??0)}),r(So,{label:"Peak",value:Ca(a.peakBitrateKbps??0)}),r(So,{label:"Packet Loss",value:`${(a.packetLossPercent??0).toFixed(2)}%`,warning:(a.packetLossPercent??0)>1})]})]},s))})]})}const UA=3e4;function QA({field:e}){const t=Gt(),n=e.type==="doorbell-recent"&&typeof e.historyLimit=="number"?e.historyLimit:10,o=Xl({deviceId:t??void 0,historyLimit:n});if(t===null)return null;const s=o.latest?Date.now()-o.latest.timestamp<UA:!1;return r(Kl,{history:o.history,latestIsFresh:s})}const GA={streaming:{icon:fb,label:"Streaming"},detection:{icon:cc,label:"Detection"},recording:{icon:Jg,label:"Recording"},audio:{icon:wi,label:"Audio"},snapshot:{icon:Br,label:"Snapshot"},motion:{icon:mc,label:"Motion"},ptz:{icon:bt,label:"PTZ"},webrtc:{icon:fc,label:"WebRTC"},onvif:{icon:aA,label:"ONVIF"},analytics:{icon:tt,label:"Analytics"},"battery-operated":{icon:gP,label:"Battery"},"native-snapshot":{icon:Br,label:"Native Snapshot"},"pan-tilt-zoom":{icon:bt,label:"PTZ"},"two-way-audio":{icon:wi,label:"Two-way Audio"},"doorbell-button":{icon:Bs,label:"Doorbell"},rebootable:{icon:Et,label:"Rebootable"}},WA=zs;function js({capabilities:e,showLabels:t=!1}){return r("div",{className:"flex items-center gap-1 flex-wrap",children:e.map(n=>{const o=GA[n],s=o?.icon??WA,a=o?.label??n;return f("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)})})}const KA={frigate:{icon:Zg,color:"#3b82f6",label:"Frigate"},scrypted:{icon:ro,color:"#a855f7",label:"Scrypted"},reolink:{icon:fc,color:"#06b6d4",label:"Reolink"},homeassistant:{icon:d4,color:"#22d3ee",label:"Home Assistant"},rtsp:{icon:Wn,color:"#78716c",label:"RTSP"},onvif:{icon:Wn,color:"#78716c",label:"ONVIF"}},Ld={sm:"h-4 w-4",md:"h-5 w-5",lg:"h-6 w-6"},YA={sm:"h-7 w-7",md:"h-8 w-8",lg:"h-10 w-10"};function mb(e){const t=e.toLowerCase();return t.startsWith("provider-")?t.slice(9):t}function ZA(e){const t=mb(e);return KA[t]??{icon:Zg,color:"#78716c",label:e}}function XA(e){const t=mb(e);return`/api/addon-assets/${e.toLowerCase().startsWith("provider-")?e:`provider-${t}`}/assets/icon.svg`}function Vt({type:e,size:t="md",showLabel:n}){const o=ZA(e),s=o.icon,[a,i]=L(!1),l=XA(e);return f("div",{className:"flex items-center gap-2",children:[r("div",{className:`flex items-center justify-center rounded-lg ${YA[t]}`,style:{backgroundColor:`${o.color}15`},children:a?r(s,{className:Ld[t],style:{color:o.color}}):r("img",{src:l,alt:o.label,className:Ld[t],onError:()=>i(!0)})}),n&&r("span",{className:"text-xs font-medium text-foreground-subtle",children:o.label})]})}function JA({deviceId:e,initialName:t}){const n=ke(),[o,s]=L(!1),[a,i]=L(t),[l,c]=L(!1),d=ee(null);X(()=>{o||i(t)},[t,o]),X(()=>{o&&d.current?.focus()},[o]);const p=zh({onSuccess:()=>{n.invalidateQueries({queryKey:[["deviceManager","getDevice"]]}),n.invalidateQueries({queryKey:[["deviceManager","listAll"]]}),n.invalidateQueries({queryKey:[["deviceManager","getDeviceAggregate"]]})}}),u=async()=>{const m=a.trim();if(m.length===0||m===t){s(!1),i(t);return}c(!0);try{await p.mutateAsync({deviceId:e,name:m}),s(!1)}catch{}finally{c(!1)}},h=()=>{i(t),s(!1)};return o?r(Lt,{label:"Name",value:f("div",{className:"flex items-center gap-1",children:[r("input",{ref:d,type:"text",value:a,onChange:m=>i(m.target.value),onKeyDown:m=>{m.key==="Enter"?u():m.key==="Escape"&&h()},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 u(),disabled:l,className:"p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50","aria-label":"Save",children:r(At,{className:"h-3 w-3"})}),r("button",{type:"button",onClick:h,disabled:l,className:"p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50","aria-label":"Cancel",children:r(qe,{className:"h-3 w-3"})})]})}):r(Lt,{label:"Name",value:f("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(Hs,{className:"h-3 w-3 text-foreground-subtle"})})]})})}function e$({deviceId:e,initialLocation:t}){const n=ke(),[o,s]=L(!1),[a,i]=L(t??""),[l,c]=L(!1),d=ee(null),{data:p}=Hh(void 0,{staleTime:3e4,enabled:o}),u=p??[];X(()=>{o||i(t??"")},[t,o]),X(()=>{o&&d.current?.focus()},[o]);const h=Fh({onSuccess:()=>{n.invalidateQueries({queryKey:[["deviceManager","getDevice"]]}),n.invalidateQueries({queryKey:[["deviceManager","listAll"]]}),n.invalidateQueries({queryKey:[["deviceManager","getDeviceAggregate"]]}),n.invalidateQueries({queryKey:[["deviceManager","listLocations"]]})}}),m=Q(()=>{const y=a.trim().toLowerCase();return y.length===0?u:u.filter(w=>w.toLowerCase()!==y&&w.toLowerCase().includes(y))},[u,a]),g=a.trim().length>0&&!u.some(y=>y.toLowerCase()===a.trim().toLowerCase()),b=async y=>{const v=(y??a).trim(),N=v.length===0?null:v;if(N===(t??null)){s(!1);return}c(!0);try{await h.mutateAsync({deviceId:e,location:N}),s(!1)}catch{}finally{c(!1)}},x=()=>{i(t??""),s(!1)};return o?r(Lt,{label:"Location",value:f("div",{className:"relative",children:[f("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"?b():y.key==="Escape"&&x()},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 b(),disabled:l,className:"p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50","aria-label":"Save",children:r(At,{className:"h-3 w-3"})}),r("button",{type:"button",onClick:x,disabled:l,className:"p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50","aria-label":"Cancel",children:r(qe,{className:"h-3 w-3"})})]}),(m.length>0||g)&&f("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:[m.map(y=>f("button",{type:"button",onClick:()=>{i(y),b(y)},className:"w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover",children:[r(S4,{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),r("span",{className:"truncate",children:y})]},y)),g&&f("button",{type:"button",onClick:()=>void b(),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"}),f("span",{className:"font-medium truncate",children:['"',a.trim(),'"']})]})]})]})}):r(Lt,{label:"Location",value:f("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(Hs,{className:"h-3 w-3 text-foreground-subtle"})})]})})}const Od=["manufacturer","model","hardware","firmware","serialNumber","uid","mac","itemNo"];function t$(e){return e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/^./,t=>t.toUpperCase())}function n$(e){return e==null?"—":typeof e=="string"||typeof e=="number"||typeof e=="boolean"?String(e):JSON.stringify(e)}function gb(){const e=Gt(),t=Il(),{data:n}=yn({deviceId:e??0},{enabled:e!==null,staleTime:3e4}),o=n??t??null,[s,a]=L("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??[],u=o.location??null,h=o.metadata??null,m=h!==null&&Object.keys(h).length>0;return f("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[f("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"}),m&&f("div",{className:"flex items-center gap-1 rounded-md bg-surface-hover p-0.5",children:[r(Bd,{active:s==="identity",onClick:()=>a("identity"),label:"Identity"}),r(Bd,{active:s==="hardware",onClick:()=>a("hardware"),label:"Hardware"})]})]}),(!m||s==="identity")&&f("div",{className:"divide-y divide-border",children:[r(Lt,{label:"ID",value:f("span",{className:"font-mono text-[11px] text-foreground",children:[`#${e}`,f("span",{className:"ml-1.5 text-foreground-subtle",children:["(",i,")"]})]})}),r(JA,{deviceId:e,initialName:l}),r(e$,{deviceId:e,initialLocation:u}),r(Lt,{label:"Type",value:c}),r(Lt,{label:"Provider",value:r(Vt,{type:d,size:"sm",showLabel:!0})}),r(Lt,{label:"Capabilities",value:p.length>0?r(js,{capabilities:p,showLabels:!0}):r("span",{className:"text-[11px] text-foreground-subtle",children:"None"})})]}),m&&s==="hardware"&&r(r$,{metadata:h})]})}function Bd({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 r$({metadata:e}){const t=Od.filter(s=>s in e),n=Object.keys(e).filter(s=>!Od.includes(s)).sort(),o=[...t,...n];return f("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(Lt,{label:t$(s),value:r("span",{className:"font-mono text-[11px] text-foreground break-all",children:n$(e[s])})},s))})]})}function Ni(e){try{const t=e.split(".");if(t.length<2||!t[1])return null;const n=JSON.parse(atob(t[1]));return{username:String(n.username??"unknown"),role:String(n.role??"viewer"),exp:Number(n.exp??0)}}catch{return null}}function o$(e){const t=Ni(e);return t?t.exp*1e3<Date.now():!0}const bb=$e(null);function s$({children:e}){const[t,n]=L(null),[o,s]=L(!0);X(()=>{const l=localStorage.getItem("camstack_admin_token");if(!l){s(!1);return}if(o$(l)){localStorage.removeItem("camstack_admin_token"),s(!1);return}const c=Ni(l);if(!c){localStorage.removeItem("camstack_admin_token"),s(!1);return}xi().trpcClient.system.info.query().then(()=>n(c)).catch(u=>{const h=u?.data?.code;h==="UNAUTHORIZED"||h==="FORBIDDEN"?(localStorage.removeItem("camstack_admin_token"),Mr()):n(c)}).finally(()=>s(!1))},[]);const a=q(async(l,c)=>{const u=(await xi().login(l,c)).token;localStorage.setItem("camstack_admin_token",u),Mr(),n(Ni(u))},[]),i=q(()=>{localStorage.removeItem("camstack_admin_token"),Mr(),n(null)},[]);return r(bb.Provider,{value:{user:t,loading:o,login:a,logout:i},children:e})}function oo(){const e=ge(bb);if(!e)throw new Error("useAuth must be used within AuthProvider");return e}function cn({children:e,requiredRole:t}){const{user:n,loading:o}=oo();return o?r("div",{className:"flex h-screen items-center justify-center bg-background text-foreground-subtle",children:"Loading..."}):n?t==="admin"&&n.role!=="admin"&&n.role!=="super_admin"?r(es,{to:"/access-denied",replace:!0}):r(ye,{children:e}):r(es,{to:"/login",replace:!0})}var Ma={};const we=e=>typeof e=="string",mr=()=>{let e,t;const n=new Promise((o,s)=>{e=o,t=s});return n.resolve=e,n.reject=t,n},zd=e=>e==null?"":""+e,a$=(e,t,n)=>{e.forEach(o=>{t[o]&&(n[o]=t[o])})},i$=/###/g,Fd=e=>e&&e.indexOf("###")>-1?e.replace(i$,"."):e,Hd=e=>!e||we(e),Er=(e,t,n)=>{const o=we(t)?t.split("."):t;let s=0;for(;s<o.length-1;){if(Hd(e))return{};const a=Fd(o[s]);!e[a]&&n&&(e[a]=new n),Object.prototype.hasOwnProperty.call(e,a)?e=e[a]:e={},++s}return Hd(e)?{}:{obj:e,k:Fd(o[s])}},jd=(e,t,n)=>{const{obj:o,k:s}=Er(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=Er(e,i,Object);for(;l.obj===void 0&&i.length;)a=`${i[i.length-1]}.${a}`,i=i.slice(0,i.length-1),l=Er(e,i,Object),l?.obj&&typeof l.obj[`${l.k}.${a}`]<"u"&&(l.obj=void 0);l.obj[`${l.k}.${a}`]=n},l$=(e,t,n,o)=>{const{obj:s,k:a}=Er(e,t,Object);s[a]=s[a]||[],s[a].push(n)},rs=(e,t)=>{const{obj:n,k:o}=Er(e,t);if(n&&Object.prototype.hasOwnProperty.call(n,o))return n[o]},c$=(e,t,n)=>{const o=rs(e,n);return o!==void 0?o:rs(t,n)},xb=(e,t,n)=>{for(const o in t)o!=="__proto__"&&o!=="constructor"&&(o in e?we(e[o])||e[o]instanceof String||we(t[o])||t[o]instanceof String?n&&(e[o]=t[o]):xb(e[o],t[o],n):e[o]=t[o]);return e},dn=e=>e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var d$={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};const u$=e=>we(e)?e.replace(/[&<>"'\/]/g,t=>d$[t]):e;class f${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 p$=[" ",",","?","!",";"],h$=new f$(20),m$=(e,t,n)=>{t=t||"",n=n||"";const o=p$.filter(i=>t.indexOf(i)<0&&n.indexOf(i)<0);if(o.length===0)return!0;const s=h$.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},Si=(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},zr=e=>e?.replace(/_/g,"-"),g$={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 os{constructor(t,n={}){this.init(t,n)}init(t,n={}){this.prefix=n.prefix||"i18next:",this.logger=t||g$,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:(we(t[0])&&(t[0]=`${o}${this.prefix} ${t[0]}`),this.logger[n](t))}create(t){return new os(this.logger,{prefix:`${this.prefix}:${t}:`,...this.options})}clone(t){return t=t||this.options,t.prefix=t.prefix||this.prefix,new os(this.logger,t)}}var kt=new os;class Vs{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 Vd extends Vs{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):we(o)&&a?l.push(...o.split(a)):l.push(o)));const c=rs(this.data,l);return!c&&!n&&!o&&t.indexOf(".")>-1&&(t=l[0],n=l[1],o=l.slice(2).join(".")),c||!i||!we(o)?c:Si(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),jd(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)(we(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=rs(this.data,l)||{};i.skipCopy||(o=JSON.parse(JSON.stringify(o))),s?xb(c,o,a):c={...c,...o},jd(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 yb={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 vb=Symbol("i18next/PATH_KEY");function b$(){const e=[],t=Object.create(null);let n;return t.get=(o,s)=>(n?.revoke?.(),s===vb?e:(e.push(s),n=Proxy.revocable(o,t),n.proxy)),Proxy.revocable(Object.create(null),t).proxy}function jn(e,t){const{[vb]:n}=e(b$()),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 qd={},Ia=e=>!we(e)&&typeof e!="boolean"&&typeof e!="number";class ss extends Vs{constructor(t,n={}){super(),a$(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],t,this),this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.logger=kt.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=Ia(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&&!m$(t,o,s);if(i&&!l){const c=t.match(this.interpolator.nestingRegexp);if(c&&c.length>0)return{key:t,namespaces:we(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:we(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=jn(t,{...this.options,...s})),Array.isArray(t)||(t=[String(t)]),t=t.map($=>typeof $=="function"?jn($,{...this.options,...s}):String($));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 u=s.lng||this.language,h=s.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if(u?.toLowerCase()==="cimode")return h?a?{res:`${d}${p}${l}`,usedKey:l,exactUsedKey:l,usedLng:u,usedNS:d,usedParams:this.getUsedParamsDetails(s)}:`${d}${p}${l}`:a?{res:l,usedKey:l,exactUsedKey:l,usedLng:u,usedNS:d,usedParams:this.getUsedParamsDetails(s)}:l;const m=this.resolve(t,s);let g=m?.res;const b=m?.usedKey||l,x=m?.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&&!we(s.count),S=ss.hasDefaultValue(s),k=N?this.pluralResolver.getSuffix(u,s.count,s):"",M=s.ordinal&&N?this.pluralResolver.getSuffix(u,s.count,{ordinal:!1}):"",D=N&&!s.ordinal&&s.count===0,E=D&&s[`defaultValue${this.options.pluralSeparator}zero`]||s[`defaultValue${k}`]||s[`defaultValue${M}`]||s.defaultValue;let B=g;v&&!g&&S&&(B=E);const A=Ia(B),O=Object.prototype.toString.apply(B);if(v&&B&&A&&y.indexOf(O)<0&&!(we(w)&&Array.isArray(B))){if(!s.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn("accessing an object - but returnObjects options is not enabled!");const $=this.options.returnedObjectHandler?this.options.returnedObjectHandler(b,B,{...s,ns:c}):`key '${l} (${this.language})' returned an object instead of string.`;return a?(m.res=$,m.usedParams=this.getUsedParamsDetails(s),m):$}if(i){const $=Array.isArray(B),I=$?[]:{},_=$?x:b;for(const P in B)if(Object.prototype.hasOwnProperty.call(B,P)){const T=`${_}${i}${P}`;S&&!g?I[P]=this.translate(T,{...s,defaultValue:Ia(E)?E[P]:void 0,joinArrays:!1,ns:c}):I[P]=this.translate(T,{...s,joinArrays:!1,ns:c}),I[P]===T&&(I[P]=B[P])}g=I}}else if(v&&we(w)&&Array.isArray(g))g=g.join(w),g&&(g=this.extendTranslation(g,t,s,o));else{let $=!1,I=!1;!this.isValidLookup(g)&&S&&($=!0,g=E),this.isValidLookup(g)||(I=!0,g=l);const P=(s.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey)&&I?void 0:g,T=S&&E!==g&&this.options.updateMissing;if(I||$||T){if(this.logger.log(T?"updateKey":"missingKey",u,d,l,T?E:g),i){const F=this.resolve(l,{...s,keySeparator:!1});F&&F.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 R=[];const z=this.languageUtils.getFallbackCodes(this.options.fallbackLng,s.lng||this.language);if(this.options.saveMissingTo==="fallback"&&z&&z[0])for(let F=0;F<z.length;F++)R.push(z[F]);else this.options.saveMissingTo==="all"?R=this.languageUtils.toResolveHierarchy(s.lng||this.language):R.push(s.lng||this.language);const H=(F,j,J)=>{const W=S&&J!==g?J:P;this.options.missingKeyHandler?this.options.missingKeyHandler(F,d,j,W,T,s):this.backendConnector?.saveMissing&&this.backendConnector.saveMissing(F,d,j,W,T,s),this.emit("missingKey",F,d,j,g)};this.options.saveMissing&&(this.options.saveMissingPlurals&&N?R.forEach(F=>{const j=this.pluralResolver.getSuffixes(F,s);D&&s[`defaultValue${this.options.pluralSeparator}zero`]&&j.indexOf(`${this.options.pluralSeparator}zero`)<0&&j.push(`${this.options.pluralSeparator}zero`),j.forEach(J=>{H([F],l+J,s[`defaultValue${J}`]||E)})}):H(R,l,E))}g=this.extendTranslation(g,t,s,m,o),I&&g===l&&this.options.appendNamespaceToMissingKey&&(g=`${d}${p}${l}`),(I||$)&&this.options.parseMissingKeyHandler&&(g=this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey?`${d}${p}${l}`:l,$?g:void 0,s))}return a?(m.res=g,m.usedParams=this.getUsedParamsDetails(s),m):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=we(t)&&(o?.interpolation?.skipOnVariables!==void 0?o.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables);let d;if(c){const u=t.match(this.interpolator.nestingRegexp);d=u&&u.length}let p=o.replace&&!we(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 u=t.match(this.interpolator.nestingRegexp),h=u&&u.length;d<h&&(o.nest=!1)}!o.lng&&s&&s.res&&(o.lng=this.language||s.usedLng),o.nest!==!1&&(t=this.interpolator.nest(t,(...u)=>a?.[0]===u[0]&&!o.context?(this.logger.warn(`It seems you are nesting recursively key: ${u[0]} in key: ${n[0]}`),null):this.translate(...u,n),o)),o.interpolation&&this.interpolator.reset()}const i=o.postProcess||this.options.postProcess,l=we(i)?[i]:i;return t!=null&&l?.length&&o.applyPostProcessor!==!1&&(t=yb.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 we(t)&&(t=[t]),Array.isArray(t)&&(t=t.map(c=>typeof c=="function"?jn(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 u=d.namespaces;this.options.fallbackNS&&(u=u.concat(this.options.fallbackNS));const h=n.count!==void 0&&!we(n.count),m=h&&!n.ordinal&&n.count===0,g=n.context!==void 0&&(we(n.context)||typeof n.context=="number")&&n.context!=="",b=n.lngs?n.lngs:this.languageUtils.toResolveHierarchy(n.lng||this.language,n.fallbackLng);u.forEach(x=>{this.isValidLookup(o)||(l=x,!qd[`${b[0]}-${x}`]&&this.utils?.hasLoadedNamespace&&!this.utils?.hasLoadedNamespace(l)&&(qd[`${b[0]}-${x}`]=!0,this.logger.warn(`key "${s}" for languages "${b.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!!!")),b.forEach(y=>{if(this.isValidLookup(o))return;i=y;const w=[p];if(this.i18nFormat?.addLookupKeys)this.i18nFormat.addLookupKeys(w,p,y,x,n);else{let N;h&&(N=this.pluralResolver.getSuffix(y,n.count,n));const S=`${this.options.pluralSeparator}zero`,k=`${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;if(h&&(n.ordinal&&N.indexOf(k)===0&&w.push(p+N.replace(k,this.options.pluralSeparator)),w.push(p+N),m&&w.push(p+S)),g){const M=`${p}${this.options.contextSeparator||"_"}${n.context}`;w.push(M),h&&(n.ordinal&&N.indexOf(k)===0&&w.push(M+N.replace(k,this.options.pluralSeparator)),w.push(M+N),m&&w.push(M+S))}}let v;for(;v=w.pop();)this.isValidLookup(o)||(a=v,o=this.getResource(y,x,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&&!we(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 Ud{constructor(t){this.options=t,this.supportedLngs=this.options.supportedLngs||!1,this.logger=kt.create("languageUtils")}getScriptPartFromCode(t){if(t=zr(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=zr(t),!t||t.indexOf("-")<0)return t;const n=t.split("-");return this.formatLanguageCode(n[0])}formatLanguageCode(t){if(we(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)),we(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 we(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))):we(t)&&a(this.formatLanguageCode(t)),o.forEach(i=>{s.indexOf(i)<0&&a(this.formatLanguageCode(i))}),s}}const Qd={zero:0,one:1,two:2,few:3,many:4,other:5},Gd={select:e=>e===1?"one":"other",resolvedOptions:()=>({pluralCategories:["one","other"]})};class x${constructor(t,n={}){this.languageUtils=t,this.options=n,this.logger=kt.create("pluralResolver"),this.pluralRulesCache={}}clearCache(){this.pluralRulesCache={}}getRule(t,n={}){const o=zr(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!"),Gd;if(!t.match(/-|_/))return Gd;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)=>Qd[s]-Qd[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 Wd=(e,t,n,o=".",s=!0)=>{let a=c$(e,t,n);return!a&&s&&we(n)&&(a=Si(e,n,o),a===void 0&&(a=Si(t,n,o))),a},Ea=e=>e.replace(/\$/g,"$$$$");class Kd{constructor(t={}){this.logger=kt.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:u,nestingPrefix:h,nestingPrefixEscaped:m,nestingSuffix:g,nestingSuffixEscaped:b,nestingOptionsSeparator:x,maxReplaces:y,alwaysFormat:w}=t.interpolation;this.escape=n!==void 0?n:u$,this.escapeValue=o!==void 0?o:!0,this.useRawValueToEscape=s!==void 0?s:!1,this.prefix=a?dn(a):i||"{{",this.suffix=l?dn(l):c||"}}",this.formatSeparator=d||",",this.unescapePrefix=p?"":u||"-",this.unescapeSuffix=this.unescapePrefix?"":p||"",this.nestingPrefix=h?dn(h):m||dn("$t("),this.nestingSuffix=g?dn(g):b||dn(")"),this.nestingOptionsSeparator=x||",",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=m=>{if(m.indexOf(this.formatSeparator)<0){const y=Wd(n,c,m,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(y,void 0,o,{...s,...n,interpolationkey:m}):y}const g=m.split(this.formatSeparator),b=g.shift().trim(),x=g.join(this.formatSeparator).trim();return this.format(Wd(n,c,b,this.options.keySeparator,this.options.ignoreJSONStructure),x,o,{...s,...n,interpolationkey:b})};this.resetRegExp();const p=s?.missingInterpolationHandler||this.options.missingInterpolationHandler,u=s?.interpolation?.skipOnVariables!==void 0?s.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:m=>Ea(m)},{regex:this.regexp,safeValue:m=>this.escapeValue?Ea(this.escape(m)):Ea(m)}].forEach(m=>{for(l=0;a=m.regex.exec(t);){const g=a[1].trim();if(i=d(g),i===void 0)if(typeof p=="function"){const x=p(t,a,s);i=we(x)?x:""}else if(s&&Object.prototype.hasOwnProperty.call(s,g))i="";else if(u){i=a[0];continue}else this.logger.warn(`missed to pass in variable ${g} for interpolating ${t}`),i="";else!we(i)&&!this.useRawValueToEscape&&(i=zd(i));const b=m.safeValue(i);if(t=t.replace(a[0],b),u?(m.regex.lastIndex+=i.length,m.regex.lastIndex-=a[0].length):m.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 u=c.split(new RegExp(`${dn(p)}[ ]*{`));let h=`{${u[1]}`;c=u[0],h=this.interpolate(h,i);const m=h.match(/'/g),g=h.match(/"/g);((m?.length??0)%2===0&&!g||(g?.length??0)%2!==0)&&(h=h.replace(/'/g,'"'));try{i=JSON.parse(h),d&&(i={...d,...i})}catch(b){return this.logger.warn(`failed parsing options string in nesting for key ${c}`,b),`${c}${p}${h}`}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&&!we(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&&!we(a))return a;we(a)||(a=zd(a)),a||(this.logger.warn(`missed to resolve ${s[1]} for nesting ${t}`),a=""),c.length&&(a=c.reduce((p,u)=>this.format(p,u,o.lng,{...o,interpolationkey:s[1].trim()}),a.trim())),t=t.replace(s[0],a),this.regexp.lastIndex=0}return t}}const y$=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}},Yd=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(zr(o),s),t[i]=l),l(n)}},v$=e=>(t,n,o)=>e(zr(n),o)(t);class w${constructor(t={}){this.logger=kt.create("formatter"),this.options=t,this.init(t)}init(t,n={interpolation:{}}){this.formatSeparator=n.interpolation.formatSeparator||",";const o=n.cacheInBuiltFormats?Yd:v$;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()]=Yd(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}=y$(c);if(this.formats[d]){let u=l;try{const h=s?.formatParams?.[s.interpolationkey]||{},m=h.locale||h.lng||s.locale||s.lng||o;u=this.formats[d](l,m,{...p,...s,...h})}catch(h){this.logger.warn(h)}return u}else this.logger.warn(`there was no format function for ${d}`);return l},t)}}const N$=(e,t)=>{e.pending[t]!==void 0&&(delete e.pending[t],e.pendingCount--)};class S$ extends Vs{constructor(t,n,o,s={}){super(),this.backend=t,this.store=n,this.services=o,this.languageUtils=o.languageUtils,this.options=s,this.logger=kt.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(u=>{const h=`${d}|${u}`;!o.reload&&this.store.hasResourceBundle(d,u)?this.state[h]=2:this.state[h]<0||(this.state[h]===1?i[h]===void 0&&(i[h]=!0):(this.state[h]=1,p=!1,i[h]===void 0&&(i[h]=!0),a[h]===void 0&&(a[h]=!0),c[u]===void 0&&(c[u]=!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=>{l$(c.loaded,[a],i),N$(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(u=>{l[d][u]===void 0&&(l[d][u]=!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 u=this.waitingReads.shift();this.read(u.lng,u.ns,u.fcName,u.tried,u.wait,u.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();we(t)&&(t=this.languageUtils.toResolveHierarchy(t)),we(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(u=>l(null,u)).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 Pa=()=>({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]),we(e[1])&&(t.defaultValue=e[1]),we(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}),Zd=e=>(we(e.ns)&&(e.ns=[e.ns]),we(e.fallbackLng)&&(e.fallbackLng=[e.fallbackLng]),we(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),ko=()=>{},k$=e=>{Object.getOwnPropertyNames(Object.getPrototypeOf(e)).forEach(n=>{typeof e[n]=="function"&&(e[n]=e[n].bind(e))})},wb="__i18next_supportNoticeShown",C$=()=>!!(typeof globalThis<"u"&&globalThis[wb]||typeof process<"u"&&Ma&&Ma.I18NEXT_NO_SUPPORT_NOTICE||typeof process<"u"&&Ma),M$=()=>{typeof globalThis<"u"&&(globalThis[wb]=!0)},I$=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 Pr extends Vs{constructor(t={},n){if(super(),this.options=Zd(t),this.services={},this.logger=kt,this.modules={external:[]},k$(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&&(we(t.ns)?t.defaultNS=t.ns:t.ns.indexOf("translation")<0&&(t.defaultNS=t.ns[0]));const o=Pa();this.options={...o,...this.options,...Zd(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&&!I$(this)&&!C$()&&(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 💙"),M$());const s=d=>d?typeof d=="function"?new d:d:null;if(!this.options.isClone){this.modules.logger?kt.init(s(this.modules.logger),this.options):kt.init(null,this.options);let d;this.modules.formatter?d=this.modules.formatter:d=w$;const p=new Ud(this.options);this.store=new Vd(this.options.resources,this.options);const u=this.services;u.logger=kt,u.resourceStore=this.store,u.languageUtils=p,u.pluralResolver=new x$(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)&&(u.formatter=s(d),u.formatter.init&&u.formatter.init(u,this.options),this.options.interpolation.format=u.formatter.format.bind(u.formatter)),u.interpolator=new Kd(this.options),u.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},u.backendConnector=new S$(s(this.modules.backend),u.resourceStore,u,this.options),u.backendConnector.on("*",(m,...g)=>{this.emit(m,...g)}),this.modules.languageDetector&&(u.languageDetector=s(this.modules.languageDetector),u.languageDetector.init&&u.languageDetector.init(u,this.options.detection,this.options)),this.modules.i18nFormat&&(u.i18nFormat=s(this.modules.i18nFormat),u.i18nFormat.init&&u.i18nFormat.init(this)),this.translator=new ss(this.services,this.options),this.translator.on("*",(m,...g)=>{this.emit(m,...g)}),this.modules.external.forEach(m=>{m.init&&m.init(this)})}if(this.format=this.options.interpolation.format,n||(n=ko),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=mr(),c=()=>{const d=(p,u)=>{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(u),n(p,u)};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=ko){let o=n;const s=we(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=mr();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=ko),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"&&yb.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=mr();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=we(l)?l:l&&l[0],d=this.store.hasLanguageSomeTranslations(c)?c:this.services.languageUtils.getBestMatchFromCodes(we(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=jn(c.keyPrefix,d));const p=this.options.keySeparator||".";let u;return c.keyPrefix&&Array.isArray(a)?u=a.map(h=>(typeof h=="function"&&(h=jn(h,d)),`${c.keyPrefix}${p}${h}`)):(typeof a=="function"&&(a=jn(a,d)),u=c.keyPrefix?`${c.keyPrefix}${p}${a}`:a),this.t(u,c)};return we(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=mr();return this.options.ns?(we(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=mr();we(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 Ud(Pa());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 Pr(t,n);return o.createInstance=Pr.createInstance,o}cloneInstance(t={},n=ko){const o=t.forkResourceStore;o&&delete t.forkResourceStore;const s={...this.options,...t,isClone:!0},a=new Pr(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,u)=>(p[u]={...c[d][u]},p),c[d]),c),{});a.store=new Vd(l,s),a.services.resourceStore=a.store}if(t.interpolation){const c={...Pa().interpolation,...this.options.interpolation,...t.interpolation},d={...s,interpolation:c};a.services.interpolator=new Kd(d)}return a.translator=new ss(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 je=Pr.createInstance();je.createInstance;je.dir;je.init;je.loadResources;je.reloadResources;je.use;je.changeLanguage;je.getFixedT;je.t;je.exists;je.setDefaultNamespace;je.hasLoadedNamespace;je.loadNamespaces;je.loadLanguages;const E$=(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);Nn(s[0])&&(s[0]=`react-i18next:: ${s[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...s):console?.warn&&console.warn(...s)},Xd={},ki=(e,t,n,o)=>{Nn(n)&&Xd[n]||(Nn(n)&&(Xd[n]=new Date),E$(e,t,n,o))},Nb=(e,t)=>()=>{if(e.isInitialized)t();else{const n=()=>{setTimeout(()=>{e.off("initialized",n)},0),t()};e.on("initialized",n)}},Ci=(e,t,n)=>{e.loadNamespaces(t,Nb(e,n))},Jd=(e,t,n,o)=>{if(Nn(n)&&(n=[n]),e.options.preload&&e.options.preload.indexOf(t)>-1)return Ci(e,n,o);n.forEach(s=>{e.options.ns.indexOf(s)<0&&e.options.ns.push(s)}),e.loadLanguages(t,Nb(e,o))},P$=(e,t,n={})=>!t.languages||!t.languages.length?(ki(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}}),Nn=e=>typeof e=="string",A$=e=>typeof e=="object"&&e!==null,$$=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,D$={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},_$=e=>D$[e],T$=e=>e.replace($$,_$);let Mi={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:T$,transDefaultProps:void 0};const R$=(e={})=>{Mi={...Mi,...e}},L$=()=>Mi;let Sb;const O$=e=>{Sb=e},B$=()=>Sb,z$={type:"3rdParty",init(e){R$(e.options.react),O$(e)}},F$=$e();class H${constructor(){this.usedNamespaces={}}addUsedNamespaces(t){t.forEach(n=>{this.usedNamespaces[n]||(this.usedNamespaces[n]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}var kb={exports:{}},Cb={};/**
511
- * @license React
512
- * use-sync-external-store-shim.production.js
513
- *
514
- * Copyright (c) Meta Platforms, Inc. and affiliates.
515
- *
516
- * This source code is licensed under the MIT license found in the
517
- * LICENSE file in the root directory of this source tree.
518
- */var Kn=ip;function j$(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var V$=typeof Object.is=="function"?Object.is:j$,q$=Kn.useState,U$=Kn.useEffect,Q$=Kn.useLayoutEffect,G$=Kn.useDebugValue;function W$(e,t){var n=t(),o=q$({inst:{value:n,getSnapshot:t}}),s=o[0].inst,a=o[1];return Q$(function(){s.value=n,s.getSnapshot=t,Aa(s)&&a({inst:s})},[e,n,t]),U$(function(){return Aa(s)&&a({inst:s}),e(function(){Aa(s)&&a({inst:s})})},[e]),G$(n),n}function Aa(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!V$(e,n)}catch{return!0}}function K$(e,t){return t()}var Y$=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?K$:W$;Cb.useSyncExternalStore=Kn.useSyncExternalStore!==void 0?Kn.useSyncExternalStore:Y$;kb.exports=Cb;var Mb=kb.exports;const Z$=(e,t)=>{if(Nn(t))return t;if(A$(t)&&Nn(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},X$={t:Z$,ready:!1},J$=()=>()=>{},xt=(e,t={})=>{const{i18n:n}=t,{i18n:o,defaultNS:s}=ge(F$)||{},a=n||o||B$();a&&!a.reportNamespaces&&(a.reportNamespaces=new H$),a||ki(a,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const i=Q(()=>({...L$(),...a?.options?.react,...t}),[a,t]),{useSuspense:l,keyPrefix:c}=i,d=s||a?.options?.defaultNS,p=Nn(d)?[d]:d||["translation"],u=Q(()=>p,p);a?.reportNamespaces?.addUsedNamespaces?.(u);const h=ee(0),m=q(E=>{if(!a)return J$;const{bindI18n:B,bindI18nStore:A}=i,O=()=>{h.current+=1,E()};return B&&a.on(B,O),A&&a.store.on(A,O),()=>{B&&B.split(" ").forEach($=>a.off($,O)),A&&A.split(" ").forEach($=>a.store.off($,O))}},[a,i]),g=ee(),b=q(()=>{if(!a)return X$;const E=!!(a.isInitialized||a.initializedStoreOnce)&&u.every(_=>P$(_,a,i)),B=t.lng||a.language,A=h.current,O=g.current;if(O&&O.ready===E&&O.lng===B&&O.keyPrefix===c&&O.revision===A)return O;const I={t:a.getFixedT(B,i.nsMode==="fallback"?u:u[0],c),ready:E,lng:B,keyPrefix:c,revision:A};return g.current=I,I},[a,u,c,i,t.lng]),[x,y]=L(0),{t:w,ready:v}=Mb.useSyncExternalStore(m,b,b);X(()=>{if(a&&!v&&!l){const E=()=>y(B=>B+1);t.lng?Jd(a,t.lng,u,E):Ci(a,u,E)}},[a,t.lng,u,v,l,x]);const N=a||{},S=ee(null),k=ee(),M=E=>{const B=Object.getOwnPropertyDescriptors(E);B.__original&&delete B.__original;const A=Object.create(Object.getPrototypeOf(E),B);if(!Object.prototype.hasOwnProperty.call(A,"__original"))try{Object.defineProperty(A,"__original",{value:E,writable:!1,enumerable:!1,configurable:!1})}catch{}return A},D=Q(()=>{const E=N,B=E?.language;let A=E;E&&(S.current&&S.current.__original===E?k.current!==B?(A=M(E),S.current=A,k.current=B):A=S.current:(A=M(E),S.current=A,k.current=B));const O=!v&&!l?(...I)=>(ki(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(...I)):w,$=[O,A,v];return $.t=O,$.i18n=A,$.ready=v,$},[w,N,v,N.resolvedLanguage,N.language,N.languages]);if(a&&l&&!v)throw new Promise(E=>{const B=()=>E();t.lng?Jd(a,t.lng,u,B):Ci(a,u,B)});return D},eu={info:ts,success:Xg,warning:Bt,error:Fs},eD={info:"text-blue-400",success:"text-green-400",warning:"text-amber-400",error:"text-red-400"},tu={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 tD(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 nu({alert:e,onMarkRead:t,onDismiss:n}){const o=e.severity in eu?e.severity:"info",s=e.status in tu?e.status:"active",a=eu[o],i=eD[o],l=tu[s];return f("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}`}),f("div",{className:"flex-1 min-w-0",children:[f("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&&f("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)))}%`}})}),f("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:tD(e.updatedAt)})]}),f("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(At,{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(qe,{className:"h-3 w-3 text-foreground-subtle"})})]})]})}function ru({variant:e="icon",compact:t=!1}={}){const[n,o]=L(!1),[s,a]=L(!1),i=ee(null),l=ee(null),c=ke(),{data:d=0}=$h(void 0,{staleTime:1e4,refetchInterval:3e4}),{data:p=[],isLoading:u}=Ah({limit:50},{enabled:n,staleTime:5e3}),h=s?p:p.filter(E=>!E.read),m=p.filter(E=>E.read).length,g=()=>{c.invalidateQueries({queryKey:[["alerts"]]})},b=Dh({onSuccess:g}),x=_h({onSuccess:g}),y=Th({onSuccess:g});et("alert.created",()=>{c.invalidateQueries({queryKey:[["alerts"]]})}),et("alert.updated",()=>{c.invalidateQueries({queryKey:[["alerts"]]})}),X(()=>{if(!n)return;const E=B=>{const A=B.target;i.current&&!i.current.contains(A)&&l.current&&!l.current.contains(A)&&o(!1)};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[n]);const w=q(E=>{b.mutate({alertId:E})},[b]),v=q(E=>{E&&y.mutate({alertId:E})},[y]),N=q(()=>{x.mutate(void 0),o(!1)},[x]),S=h.filter(E=>E.status==="in-progress"),k=h.filter(E=>E.status!=="in-progress"),[M,D]=L({});return X(()=>{if(n&&l.current){const E=l.current.getBoundingClientRect();D({position:"fixed",left:E.left,bottom:window.innerHeight-E.top+4,zIndex:9999})}},[n]),f("div",{children:[e==="sidebar"?f("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:[f("span",{className:"relative inline-flex shrink-0",children:[r(st,{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)})]}):f("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(st,{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&&Kr(f("div",{ref:i,style:M,className:"w-80 max-h-[28rem] bg-surface border border-border rounded-lg shadow-xl flex flex-col overflow-hidden",children:[f("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"}),f("div",{className:"flex items-center gap-2",children:[m>0&&f("label",{className:"flex items-center gap-1 text-[10px] text-foreground-subtle cursor-pointer select-none",children:[r("input",{type:"checkbox",checked:s,onChange:E=>a(E.target.checked),className:"h-3 w-3 rounded border-border accent-primary cursor-pointer"}),"Show read"]}),d>0&&f("button",{type:"button",onClick:N,className:"flex items-center gap-1 text-[10px] text-primary hover:text-primary/80 transition-colors",children:[r(IP,{className:"h-3 w-3"}),"Mark all read"]})]})]}),f("div",{className:"flex-1 overflow-y-auto",children:[u&&r("div",{className:"flex items-center justify-center py-8",children:r(Le,{className:"h-4 w-4 animate-spin text-foreground-subtle"})}),!u&&h.length===0&&f("div",{className:"flex flex-col items-center justify-center py-8 text-foreground-subtle",children:[r(st,{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&&f("button",{type:"button",onClick:()=>a(!0),className:"text-[10px] text-primary mt-1 hover:underline",children:["Show ",m," read alert",m!==1?"s":""]})]}),S.length>0&&f("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"})}),S.map(E=>r(nu,{alert:E,onMarkRead:w,onDismiss:v},E.id))]}),k.map(E=>r(nu,{alert:E,onMarkRead:w,onDismiss:v},E.id))]})]}),document.body)]})}function Ib(e){return e.map(t=>({id:t.page.id,addonId:t.addonId,label:t.page.label,icon:t.page.icon,path:t.page.path,remoteName:t.page.remoteName,bundle:t.page.bundle,bundleUrl:t.bundleUrl}))}const ou=new Map,Co=new Map,su=new Set;function nD(e){return!e||typeof e!="object"?!1:typeof e.default=="function"}async function rD(e,t){const n=ou.get(e);if(n)return n;const o=Co.get(e);if(o)return o;su.has(e)||(rl(),Un.registerRemotes([{name:e,entry:t,type:"module"}],{force:!1}),su.add(e));const s=Un.loadRemote(`${e}/page`).then(a=>{if(!nD(a))throw new Error(`Addon page remote ${e} (${t}) does not expose a default React component on './page'`);return ou.set(e,a.default),Co.delete(e),a.default}).catch(a=>{throw Co.delete(e),a});return Co.set(e,s),s}function oD(){const{pagePath:e}=tc(),t=Ae(),{data:n}=El(void 0,{staleTime:6e4}),o=Q(()=>n?Ib(n):void 0,[n]),s=o?.find(d=>d.path===`/addon/${e}`),[a,i]=L(null),[l,c]=L(null);return X(()=>{if(!s)return;c(null),i(null);let d=!1;return rD(s.remoteName,s.bundleUrl).then(p=>{d||i(()=>p)}).catch(p=>{if(d)return;const u=p instanceof Error?p.message:String(p);c(`Failed to load addon page: ${u}`)}),()=>{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 sD={dark:rb,light:uA,system:$4},aD={gauge:eb,puzzle:ns,bot:yP,cpu:tt,terminal:ub,box:zs,wrench:CA,activity:no,plug:ib};function iD(){const e=dt(),t=Ge(),{user:n,logout:o}=oo(),s=Xr(),{t:a,i18n:i}=xt(),l=rn(),c=_p(),d=rP(),p=d!=="connected",u=d==="connecting",[h,m]=L(!1),[g,b]=L(()=>typeof window>"u"?!1:window.localStorage.getItem("camstack:sidebar-collapsed")==="1");X(()=>{typeof window>"u"||window.localStorage.setItem("camstack:sidebar-collapsed",g?"1":"0")},[g]),X(()=>{c&&window.localStorage.getItem("camstack:sidebar-collapsed")===null&&b(!0)},[c]);const{data:x=[]}=$l(void 0,{staleTime:3e4,refetchInterval:3e4}),y=x.length,w=ke(),v=ee(Date.now()),N=3e4,S=2e3,{data:k}=El(void 0,{staleTime:0,refetchOnMount:"always",refetchInterval:H=>{const F=H.state.data;return F&&F.length>0||Date.now()-v.current>=N?!1:S}}),M=Q(()=>k?Ib(k):[],[k]);et("addon.page-ready",()=>{w.invalidateQueries({queryKey:[["addonPages","listPages"]]})});const D=()=>{o(),t("/login")},E=H=>!!(e.pathname===H||e.pathname.startsWith(H+"/")),A=["/pipeline","/timeline","/devices"].some(H=>e.pathname===H||e.pathname.startsWith(H+"/")),O=()=>{const H=i.language==="en"?"it":"en";i.changeLanguage(H)},$=[{label:a("nav.devices","Devices"),icon:Br,path:"/devices"},{label:a("nav.integrations"),icon:ib,path:"/integrations"},{label:a("nav.timeline","Timeline"),icon:FP,path:"/timeline"},{label:a("nav.pipeline","Pipeline"),icon:tb,path:"/pipeline"}],I=[{label:a("system.settings","Settings"),icon:bt,path:"/system/settings"},{label:a("system.addons"),icon:ns,path:"/system/addons"},{label:a("system.cluster","Cluster"),icon:uc,path:"/system/cluster"},{label:a("system.users"),icon:yA,path:"/system/users"}],_=s?.mode??"system",P={dark:a("theme.dark"),light:a("theme.light"),system:a("theme.system")},T=g&&!l,R=(H,F="md")=>`flex w-full items-center gap-2.5 rounded-md ${T?"justify-center px-0 py-2":"px-2.5 py-1.5"} ${F==="lg"?"text-[13px] font-medium":"text-[12px]"} transition-all ${H?F==="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"}`,z=f(ye,{children:[f("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"}),!l&&r("button",{onClick:()=>b(H=>!H),className:`p-1.5 rounded-md hover:bg-surface-hover text-foreground-subtle transition-colors flex-shrink-0 ${T?"":"mr-2"}`,"aria-label":g?"Expand sidebar":"Collapse sidebar",title:g?"Expand sidebar":"Collapse sidebar",children:g?r($t,{className:"h-4 w-4"}):r(lc,{className:"h-4 w-4"})})]}),f("nav",{className:`flex-1 overflow-y-auto py-3 ${T?"px-1.5":"px-2"} space-y-0.5`,children:[(()=>{const H=E("/dashboard");return f("button",{"data-testid":"nav-dashboard",onClick:()=>{t("/dashboard"),m(!1)},className:R(H,"lg"),title:T?a("nav.dashboard"):void 0,children:[r(nb,{className:`h-4 w-4 shrink-0 ${H?"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","Cameras")})}),T&&r("div",{className:"pt-3 mb-1 mx-2 border-t border-border/60"}),$.map(H=>{const F=H.icon,j=E(H.path),J=`nav-${H.path.replace(/^\//,"").replace(/\//g,"-")}`;return f("button",{"data-testid":J,onClick:()=>{t(H.path),m(!1)},className:R(j),title:T?H.label:void 0,children:[r(F,{className:`h-3.5 w-3.5 shrink-0 ${j?"text-primary":""}`}),!T&&H.label]},H.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"}),I.map(H=>{const F=H.icon,j=E(H.path),J=H.path==="/system/addons",W=`nav-${H.path.replace(/^\//,"").replace(/\//g,"-")}`;return f("button",{"data-testid":W,onClick:()=>{t(H.path),m(!1)},className:R(j),title:T?H.label:void 0,children:[r(F,{className:`h-3.5 w-3.5 shrink-0 ${j?"text-primary":""}`}),!T&&f(ye,{children:[r("span",{className:"flex-1 text-left",children:H.label}),J&&y>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:y})]}),T&&J&&y>0&&r("span",{className:"absolute mt-[-14px] ml-3 h-2 w-2 rounded-full bg-primary"})]},H.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(H=>{const F=E(H.path),j=aD[H.icon]??ns;return f("button",{onClick:()=>{t(H.path),m(!1)},className:R(F),title:T?H.label:void 0,children:[r(j,{className:`h-3.5 w-3.5 shrink-0 ${F?"text-primary":""}`}),!T&&H.label]},H.id)})]}),f("div",{className:`border-t border-border ${T?"p-1.5":"p-2"} space-y-0.5`,children:[f("button",{onClick:O,title:a("language.select"),className:R(!1),children:[r(p4,{className:"h-3.5 w-3.5 shrink-0"}),!T&&r("span",{children:i.language==="en"?a("language.en"):a("language.it")})]}),f("button",{onClick:()=>s?.toggleMode(),className:R(!1),title:T?P[_]:void 0,children:[(()=>{const H=sD[_];return r(H,{className:"h-3.5 w-3.5 shrink-0"})})(),!T&&r("span",{children:P[_]})]}),r(ru,{variant:"sidebar",compact:T}),f("button",{onClick:D,className:R(!1).replace("hover:text-foreground","hover:text-danger"),title:T?n?.username??"Logout":void 0,children:[r(w4,{className:"h-3.5 w-3.5 shrink-0"}),!T&&r("span",{className:"truncate",children:n?.username??"User"})]})]})]});return f("div",{className:"flex h-screen bg-background text-foreground",children:[!l&&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:z}),l&&r(gl,{open:h,onClose:()=>m(!1),width:"w-64",children:z}),f("div",{className:"flex flex-1 flex-col min-w-0",children:[p&&f("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(pb,{className:"h-3.5 w-3.5"}),r("span",{children:u?a("connection.reconnecting","Reconnecting…"):a("connection.disconnected","Server unreachable — reconnecting…")}),r(Le,{className:"h-3.5 w-3.5 animate-spin"})]}),l&&f("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(M4,{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(ru,{})]}),f("main",{className:`relative flex-1 min-h-0 bg-background ${A?"overflow-hidden":"overflow-auto"}`,children:[p&&r("div",{className:"absolute inset-0 z-40 bg-background/60 backdrop-blur-[2px]"}),r(mE,{})]})]})]})}function lD(){const{login:e}=oo(),t=Xr(),n=Ge(),[o,s]=L(""),[a,i]=L(""),[l,c]=L(!1),[d,p]=L(""),[u,h]=L(!1),m=async g=>{g.preventDefault(),p(""),h(!0);try{await e(o,a),n("/dashboard",{replace:!0})}catch(b){p(b instanceof Error?b.message:"Login failed")}finally{h(!1)}};return r("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:f("div",{className:"w-full max-w-sm",children:[r("div",{className:"flex justify-center mb-8",children:r("img",{src:t?.resolvedMode==="light"?"/brand/logo-horizontal-light.svg":"/brand/logo-horizontal-dark.svg",alt:"CamStack Admin",className:"h-12"})}),f("form",{onSubmit:m,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[d&&r("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:d}),f("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:"admin",value:o,onChange:g=>s(g.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})]}),f("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"Password"}),f("div",{className:"relative",children:[r("input",{"data-testid":"login-password",type:l?"text":"password",placeholder:"Enter password",value:a,onChange:g=>i(g.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:()=>c(!l),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground transition-colors",tabIndex:-1,children:l?r(XP,{className:"h-4 w-4"}):r(cc,{className:"h-4 w-4"})})]})]}),r("button",{"data-testid":"login-submit",type:"submit",disabled:u||!o||!a,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:u?f("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"})]}),r("p",{className:"mt-6 text-center text-[10px] text-foreground-subtle/50",children:"CamStack v0.1.0"})]})})}function cD(){const e=Ge();return f("div",{className:"flex min-h-screen flex-col items-center justify-center bg-background text-foreground p-4",children:[r("div",{className:"flex h-16 w-16 items-center justify-center rounded-2xl bg-danger/10 mb-4",children:r(oA,{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 Eb="camstack:dashboard-layout",$a={version:1,widgets:[]};function dD(){try{const e=localStorage.getItem(Eb);if(!e)return $a;const t=JSON.parse(e);return t&&t.version===1&&Array.isArray(t.widgets)?{version:1,widgets:t.widgets}:$a}catch{return $a}}function uD(e){try{localStorage.setItem(Eb,JSON.stringify(e))}catch{}}function fD(){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 pD(){const[e,t]=L(dD),[n,o]=L(!1),s=ug(),a=Q(()=>s.filter(d=>d.hosts.includes("dashboard")),[s]),i=q(d=>{t(d),uD(d)},[]),l=q(d=>{i({version:1,widgets:[...e.widgets,d]})},[e,i]),c=q(d=>{i({version:1,widgets:e.widgets.filter(p=>p.instanceId!==d)})},[e,i]);return f("div",{className:"p-4",children:[f("div",{className:"flex items-center justify-between mb-4",children:[r("h1",{className:"text-lg font-semibold text-foreground",children:"Dashboard"}),f("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(_n,{className:"h-3.5 w-3.5"}),"Add widget"]})]}),e.widgets.length===0?r(hD,{onAdd:()=>o(!0)}):r("div",{className:"grid grid-cols-12 gap-3 auto-rows-[minmax(80px,_auto)]",children:e.widgets.map(d=>r(mD,{entry:d,onRemove:()=>c(d.instanceId)},d.instanceId))}),n&&r(bD,{widgets:a,onClose:()=>o(!1),onAdd:d=>{l(d),o(!1)}})]})}function hD({onAdd:e}){return f("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(nb,{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"}),f("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(_n,{className:"h-3.5 w-3.5"}),"Add your first widget"]})]})}function mD({entry:e,onRemove:t}){const n=gD(e.columns),o=Math.max(1,Math.min(12,e.rows));return f("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(qe,{className:"h-3 w-3"})}),r("div",{className:"flex-1 min-h-0 overflow-auto p-2",children:r(Ze,{widgetId:e.widgetId,host:"dashboard",instanceId:e.instanceId,config:e.config,deviceId:e.deviceId,size:e.size,columns:e.columns,rows:e.rows})})]})}function gD(e){return!Number.isFinite(e)||e<1?6:Math.min(12,Math.floor(e))}function bD({widgets:e,onClose:t,onAdd:n}){const[o,s]=L(null);return r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:t,children:f("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:[f("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(qe,{className:"h-4 w-4"})})]}),o===null?r(xD,{widgets:e,onSelect:s}):r(yD,{widget:o,onCancel:()=>s(null),onAdd:n})]})})}function xD({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=>f("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 yD({widget:e,onCancel:t,onAdd:n}){const[o,s]=L(e.defaultSize),[a,i]=L(e.defaultColumns),[l,c]=L(e.defaultRows),[d,p]=L(null),{data:u}=$n({},{enabled:e.requires.deviceContext,staleTime:3e4}),h=!e.requires.deviceContext||d!==null&&d>0,m=()=>{if(!h)return;const g={instanceId:fD(),widgetId:e.widgetId,size:o,columns:a,rows:l,...e.requires.deviceContext&&d!==null?{deviceId:d}:{}};n(g)};return f("div",{className:"space-y-3",children:[f("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))})]}),f("div",{className:"grid grid-cols-2 gap-3",children:[r(au,{label:"Columns (1-12)",value:a,min:1,max:12,onChange:i}),r(au,{label:"Rows (1-12)",value:l,min:1,max:12,onChange:c})]}),e.requires.deviceContext&&f("div",{children:[r("label",{className:"block text-[11px] font-medium text-foreground-subtle mb-1",children:"Device"}),f("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 —"}),(u??[]).map(g=>f("option",{value:g.id,children:[g.name??g.stableId," (#",g.id,")"]},g.id))]})]}),f("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:!h,onClick:m,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 au({label:e,value:t,min:n,max:o,onChange:s}){return f("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 vD(){return r(pD,{})}const wD=["camera","hub","nvr","light","siren","switch","sensor","thermostat","button","generic"];function ND(){const{t:e}=xt(),t=Ge(),n=Ae();at(["deviceManager"],["device.registered","device.unregistered","device.online","device.offline","device.disabled","device.enabled"]),at(["integrations"],["integration.enabled","integration.disabled","integration.deleted","provider.started","provider.stopped","addon.installed","addon.uninstalled","addon.started","addon.stopped"]);const{data:o}=$n({},{staleTime:3e4}),{data:s}=Ll(void 0,{staleTime:3e4}),a=Q(()=>o??[],[o]),i=Q(()=>{const u=new Map;for(const h of a)u.set(h.id,{id:h.id,name:h.name??h.stableId??`#${String(h.id)}`});return u},[a]),l=q(u=>i.get(u)??null,[i]),c=Q(()=>(s??[]).map(u=>({id:u.addonId,name:u.name??u.addonId,icon:r(Vt,{type:u.addonId,size:"sm"})})),[s]),d=q(u=>r(Vt,{type:u,size:"sm"}),[]),p=q(u=>t(`/devices/${String(u)}`),[t]);return f("div",{className:"p-6 space-y-4",children:[r("h1",{className:"text-lg font-semibold text-foreground",children:e("nav.devices","Devices")}),r(Es,{devices:a,trpc:n.trpcClient,filters:{types:wD,addons:c},resolveIntegrationIcon:d,resolveParent:l,onNavigate:p})]})}function SD({onSelect:e,onClose:t,pendingAddonId:n=null}){const{t:o}=xt(),s=Ge(),{data:a,isLoading:i}=om();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 f("div",{className:"space-y-2",children:[(a??[]).map(c=>{const d=c.instanceMode==="unique"&&c.existingInstances.length>0,p=n===c.addonId,u=l;return f("button",{disabled:u,onClick:()=>{if(!u)if(d){const h=c.existingInstances[0].id;t(),s(`/integrations/${h}`)}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:"◉"})}),f("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(Le,{className:"h-4 w-4 animate-spin text-primary flex-shrink-0"}):d?f("span",{className:"flex items-center gap-1 text-[10px] font-medium text-foreground-subtle",children:[r(bt,{className:"h-3 w-3"}),o("integrations.manage")]}):r($t,{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 kD(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function iu(e,t){if(e!==void 0)return t&&kD(e)?t(e):e}function CD({section:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,probeResults:i,onAction:l}){const[c,d]=L(e.defaultCollapsed??!1),p=e.style==="accordion";if(e.fields.reduce((b,x)=>b+(jl(x,t,e.fields)?1:0),0)===0)return null;const h=e.columns??2,m=h===1?"grid-cols-1":h===3?"grid-cols-1 @[420px]:grid-cols-2 @[680px]:grid-cols-3":h===4?"grid-cols-1 @[420px]:grid-cols-2 @[900px]:grid-cols-4":"grid-cols-1 @[480px]:grid-cols-2",g=!e.title&&!e.description;return f("div",{className:"@container rounded-lg border border-border bg-surface p-3",style:{containerType:"inline-size"},children:[!g&&f("div",{className:["flex items-center justify-between mb-2",p?"cursor-pointer":""].join(" "),onClick:p?()=>d(b=>!b):void 0,children:[f("div",{children:[e.title&&r("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:iu(e.title,s)}),e.description&&r("p",{className:"text-[10px] text-foreground-subtle mt-0.5",children:iu(e.description,s)})]}),p&&r("span",{className:"text-foreground-subtle text-xs ml-2",children:c?"▸":"▾"})]}),!c&&r("div",{className:`grid ${m} gap-x-3 gap-y-2.5`,children:e.fields.map(b=>r(lr,{field:b,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i?.[b.key],allFields:e.fields,onAction:l},b.key))})]})}function Yn({schema:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,probeResults:i,onClearProbe:l,onAction:c}){const d=(p,u)=>{n({...t,[p]:u}),l?.(p)};return r("div",{className:"space-y-4",children:e.sections.map((p,u)=>r(CD,{section:p,values:t,onChange:d,disabled:o,translationFn:s,onTestField:a,probeResults:i,onAction:c},`${p.id}-${u}`))})}function MD({addonId:e,configSchema:t,onSave:n,onBack:o}){const{t:s}=xt(),[a,i]=L(""),[l,c]=L({}),[d,p]=L(null),u=sm({onSuccess:h=>p(h),onError:h=>p({success:!1,error:String(h)})});return f("div",{className:"space-y-4",children:[f("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:h=>i(h.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(Yn,{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}`}),f("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")}),f("div",{className:"flex items-center gap-2",children:[r("button",{onClick:()=>u.mutate({addonId:e,settings:l}),disabled:u.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:u.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 ID({providerId:e,onImport:t,onSkip:n}){const{t:o}=xt(),[s,a]=L(new Set),i=Tl(),l=i.data,c=i.isPending||!i.data&&!i.isError;X(()=>{e&&(i.isPending||i.data||i.mutate({addonId:e}))},[e,i]);function d(u){a(h=>{const m=new Set(h);return m.has(u)?m.delete(u):m.add(u),m})}if(c)return f("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 f("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(u=>{const h=u.stableId,m=u.suggestedName??h,g=s.has(h);return f("button",{onClick:()=>d(h),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(At,{className:"h-3 w-3 text-primary-foreground"})}),r(Br,{className:"h-3.5 w-3.5 text-foreground-subtle flex-shrink-0"}),r("span",{className:"text-xs font-medium text-foreground truncate",children:m})]},h)})}),f("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&&f("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 ED(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 PD({open:e,onClose:t}){const{t:n}=xt(),o=Ge(),s=ke(),[a,i]=L("picker"),[l,c]=L(null),[d,p]=L(null),[u,h]=L("manual"),{data:m}=Dl({addonId:l??"",nodeId:"hub"},{enabled:l!=null}),g=Q(()=>m?ED(m):null,[m]),b=tm({onSuccess:()=>s.invalidateQueries({queryKey:[["integrations"]]})}),x=Tl(),y=x.data;X(()=>{a!=="discovery"||!d||!l||x.isPending||x.data||x.mutate({addonId:l})},[a,d,l,x]);const w=Yh({onSuccess:()=>s.invalidateQueries({queryKey:[["deviceManager"]]})});async function v($,I,_,P){if(!b.isPending){if(c($),h(_),I==="unique"){try{const T=await b.mutateAsync({addonId:$,name:P,settings:{}});t(),M(),o(`/integrations/${T.id}`)}catch{}return}i("config")}}async function N($){if(l)try{const I=await b.mutateAsync({addonId:l,name:$.name,settings:$.config});p(I.id),u==="auto"||u==="both"?i("discovery"):k(I.id)}catch{}}async function S($){if(l){for(const I of $){const _=y?.find(P=>P.stableId===I);_&&await w.mutateAsync({addonId:l,candidate:_})}k()}}function k($){const I=$??d??l;t(),M(),I&&o(`/integrations/${I}`)}function M(){i("picker"),c(null),p(null),h("manual")}function D(){t(),M()}if(!e)return null;const E={picker:n("integrations.newIntegration"),config:n("integrations.configureIntegration"),discovery:n("integrations.importDevices")},B=b.isPending,A=B?l:null,O=b.error;return f("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[r("div",{className:"absolute inset-0 bg-black/60",onClick:B?void 0:D}),f("div",{className:"relative z-10 w-full max-w-lg rounded-xl border border-border bg-background shadow-2xl",children:[f("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:E[a]}),r("button",{onClick:D,disabled:B,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(qe,{className:"h-4 w-4"})})]}),f("div",{className:"relative px-5 py-4",children:[O&&!B&&r("div",{className:"mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:O instanceof Error?O.message:String(O)}),a==="picker"&&r(SD,{onSelect:v,onClose:D,pendingAddonId:A}),a==="config"&&l&&r(MD,{addonId:l,configSchema:g??null,onSave:N,onBack:()=>i("picker")}),a==="discovery"&&d&&r(ID,{providerId:d,onImport:S,onSkip:k}),B&&f("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background/85 backdrop-blur-sm",children:[r(Le,{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 lu={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 qs({status:e}){const t=lu[e]??lu.stopped;return f("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 Da="px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle";function AD({integrations:e,expandedAddonId:t,onToggleExpand:n,onOpenSettings:o,renderExpanded:s}){const a=q(i=>n(i),[n]);return r("div",{className:"overflow-hidden rounded-lg border border-border bg-surface",children:f("table",{className:"w-full table-fixed text-xs",children:[r("thead",{className:"bg-surface-hover/40",children:f("tr",{children:[r("th",{className:U(Da,"w-[60%]"),children:"Integration"}),r("th",{className:U(Da,"w-[15%]"),children:"Devices"}),r("th",{className:U(Da,"w-[25%]"),children:"Status"})]})}),r("tbody",{children:e.map(i=>{const l=t===i.addonId;return r($D,{integration:i,isExpanded:l,onClick:a,onOpenSettings:o,renderExpanded:s},i.id)})})]})})}function $D({integration:e,isExpanded:t,onClick:n,onOpenSettings:o,renderExpanded:s}){const a=q(c=>{c.stopPropagation(),o(e.id)},[e.id,o]),i=q(()=>{n(e.addonId)},[e.addonId,n]),l=q(c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),i())},[i]);return f(ye,{children:[f("tr",{role:"button",tabIndex:0,"aria-expanded":t,className:U("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:f("div",{className:"flex items-center gap-2.5",children:[t?r(It,{className:"h-3.5 w-3.5 flex-shrink-0 text-foreground-subtle"}):r($t,{className:"h-3.5 w-3.5 flex-shrink-0 text-foreground-subtle"}),r(Vt,{type:e.addonId,size:"sm"}),f("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})]})]})}),f("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:f("div",{className:"flex items-center justify-between gap-2",children:[r(qs,{status:e.status}),f("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(bt,{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 DD(e){if(!e.enabled)return"disabled";switch(e.processState){case"running":return"running";case"stopped":case"crashed":case"unknown":default:return"stopped"}}const Mo="expand";function _D(){const{t:e}=xt(),t=Ge(),n=Ae(),[o]=Wg(),[s,a]=L(!1),i=q(()=>a(!0),[]),l=q(()=>a(!1),[]);at(["integrations"],["integration.enabled","integration.disabled","integration.deleted","provider.started","provider.stopped","addon.installed","addon.uninstalled","addon.started","addon.stopped","addon.updated"]),at(["deviceManager"],["device.registered","device.unregistered","device.online","device.offline","device.disabled","device.enabled"]);const{data:c,isLoading:d,refetch:p}=Ll(void 0,{staleTime:3e4}),{data:u,isLoading:h,refetch:m}=$n({},{staleTime:3e4}),g=Q(()=>u??[],[u]),b=Q(()=>c??[],[c]),x=Q(()=>{const $=new Map;for(const I of g)$.set(I.id,{id:I.id,name:I.name??I.stableId??`#${String(I.id)}`});return $},[g]),y=Q(()=>{const $=new Map;for(const I of g){if(I.parentDeviceId!==null&&I.parentDeviceId!==void 0&&!!I.role)continue;const P=I.addonId??"";P&&$.set(P,($.get(P)??0)+1)}return $},[g]),w=Q(()=>b.map($=>({id:$.id,addonId:$.addonId,name:$.name,enabled:$.enabled,status:DD($),deviceCount:y.get($.addonId)??0})),[b,y]),v=o.get(Mo),N=q($=>{const I=new URLSearchParams(window.location.search);I.get(Mo)===$?I.delete(Mo):I.set(Mo,$);const P=I.toString(),T=`${window.location.pathname}${P?`?${P}`:""}${window.location.hash}`;window.history.replaceState(window.history.state,"",T),window.dispatchEvent(new PopStateEvent("popstate"))},[]),S=q($=>t(`/integrations/${$}`),[t]),k=q($=>x.get($)??null,[x]),M=q($=>r(Vt,{type:$,size:"sm"}),[]),D=q($=>t(`/devices/${String($)}`),[t]),E=q($=>r(Es,{devices:g,trpc:n.trpcClient,forceAddon:$,urlScope:"nested",lsKey:`integrations:nested:${$}`,resolveIntegrationIcon:M,resolveParent:k,onNavigate:D}),[g,n.trpcClient,M,k,D]),B=q(()=>{p(),m()},[p,m]),A=d||h,O=b.length>0;return f("div",{className:"p-6 space-y-4",children:[f("div",{className:"flex items-center justify-between gap-4",children:[r("h1",{className:"text-lg font-semibold text-foreground",children:e("nav.integrations","Integrations")}),f("div",{className:"flex items-center gap-2",children:[r("button",{onClick:B,disabled:A,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(Et,{className:U("h-3.5 w-3.5",A&&"animate-spin")})}),f("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(_n,{className:"h-3.5 w-3.5"}),"New Integration"]})]})]}),A&&r("div",{className:"space-y-2",children:[1,2,3].map($=>r("div",{className:"h-12 rounded-lg border border-border bg-surface animate-pulse"},$))}),!A&&!O&&f("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.'})]}),!A&&O&&r(AD,{integrations:w,expandedAddonId:v,onToggleExpand:N,onOpenSettings:S,renderExpanded:E}),r(PD,{open:s,onClose:l})]})}function Pb(e){const t=[];for(const n of e)n.type==="probe"&&t.push(n.key),n.type==="group"&&"fields"in n&&t.push(...Pb(n.fields));return t}function TD(e,t,n){const[o,s]=L("idle"),[a,i]=L({}),l=Q(()=>{const u=[];for(const h of e.sections)u.push(...Pb(h.fields));return u},[e]),c=l.length>0&&n!==void 0,d=q(u=>{i(h=>{if(!h[u])return h;const m={...h};return delete m[u],m})},[]),p=q(async()=>{if(!n)return;const u=l.filter(b=>{const x=t[b];return x!=null&&String(x).trim()!==""});if(u.length===0)return;s("testing");const h={};for(const b of u)h[b]={status:"probing"};i(h);const m=await Promise.allSettled(u.map(async b=>{try{const x=await n(b,t[b]);return{key:b,result:x}}catch(x){const w={status:"error",error:x instanceof Error?x.message:String(x)};return{key:b,result:w}}})),g={};for(const b of m)if(b.status==="fulfilled"){const{key:x,result:y}=b.value;g[x]={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 Ab(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(...Ab(n.fields));return t}function RD(e){return e==null?!0:typeof e=="string"?e.trim()==="":!1}function cu(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function LD({open:e,integrationId:t,addonId:n,onClose:o}){const{t:s}=xt(),a=ke(),[i,l]=L({}),[c,d]=L(!1),[p,u]=L(null),[h,m]=L(cu),g=Zh({addonId:n,type:Ye.Camera},{enabled:e}),b=g.data??null;X(()=>{e&&(l({}),m(cu()),d(!1),u(null))},[e,t]);const x=Q(()=>({...i,_probeRequestId:h}),[i,h]),y=Xh({onSuccess:()=>{a.invalidateQueries({queryKey:[["deviceManager"]]})}}),w=Rl(),v=q(async(I,_)=>(d(!0),await w.mutateAsync({addonId:n,type:Ye.Camera,key:I,value:_,formValues:x})),[w,n,x]),{testAllStatus:N,hasProbeFields:S,probeResults:k,handleTestAll:M,clearProbeResult:D}=TD(b??{sections:[]},i,v);async function E(I){u(null);try{await y.mutateAsync({addonId:n,type:Ye.Camera,config:i}),I?l({}):o()}catch(_){u(_ instanceof Error?_.message:String(_))}}if(!e)return null;const A=Ab((b?.sections??[]).flatMap(I=>I.fields)).filter(I=>RD(i[I])),O=A.length===0,$=!g.isLoading&&(g.isError||b===null);return f("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[r("div",{className:"absolute inset-0 bg-black/60",onClick:o}),f("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:[f("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(qe,{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(Le,{className:"h-5 w-5 animate-spin text-primary"})}):$?f("div",{className:"flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3",children:[r(Bt,{className:"h-4 w-4 text-destructive mt-0.5 shrink-0"}),f("div",{className:"space-y-1",children:[r("p",{className:"text-xs font-medium text-destructive",children:"Provider unavailable"}),f("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(Yn,{schema:b,values:i,onChange:l,onTestField:v,probeResults:k,onClearProbe:D})}),!$&&!g.isLoading&&f("div",{className:"border-t border-border bg-surface/50 shrink-0",children:[f("button",{type:"button",onClick:()=>d(I=>!I),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:[f("span",{className:"flex items-center gap-2",children:[r(st,{className:"h-3.5 w-3.5"}),"Test logs",r("span",{className:"font-mono text-[9px] opacity-60",children:h.slice(0,14)})]}),r(It,{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(Wt,{addonId:n,requestId:h,limit:50,maxHeight:"max-h-64",showFilters:!1,showScope:!1,className:"border-0 rounded-none"})})]}),!$&&!g.isLoading&&(p||A.length>0)&&r("div",{className:"border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0",children:f("div",{className:"flex items-start gap-2",children:[r(Bt,{className:"h-3.5 w-3.5 text-destructive mt-0.5 shrink-0"}),r("p",{className:"text-[11px] text-destructive",children:p||`Required: ${A.join(", ")}`})]})}),f("div",{className:"flex items-center justify-between border-t border-border px-5 py-3 shrink-0",children:[f("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")}),!$&&S&&f("button",{type:"button",onClick:M,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(Le,{className:"h-3.5 w-3.5 animate-spin"}):r(Wn,{className:"h-3.5 w-3.5"}),"Test All"]})]}),f("div",{className:"flex items-center gap-2",children:[r("button",{onClick:()=>E(!0),disabled:$||!O||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:()=>E(!1),disabled:$||!O||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 OD(){const{t:e}=xt(),{integrationId:t}=tc(),n=ke(),o=Ge(),s=Ae(),[a,i]=L(!1),[l,c]=L(!1),[d,p]=L(!1),[u,h]=L(!1),{data:m,isLoading:g}=Jh({id:t??""},{enabled:!!t}),{data:b}=Dl({addonId:m?.addonId??"",nodeId:"hub"},{enabled:!!m?.addonId}),x=b!=null&&Array.isArray(b.sections)&&b.sections.some(O=>O.fields.length>0),{data:y}=$n({},{refetchInterval:5e3}),w=[["integrations","get"],{input:{id:t??""},type:"query"}],v=nm({onMutate:async O=>{await n.cancelQueries({queryKey:w});const $=n.getQueryData(w);return $!=null&&n.setQueryData(w,{...$,enabled:O.enabled}),{previous:$}},onError:(O,$,I)=>{const _=I;_?.previous!=null&&n.setQueryData(w,_.previous)},onSettled:()=>{n.invalidateQueries({queryKey:[["integrations"]]}),n.invalidateQueries({queryKey:[["deviceManager"]]})}}),N=rm({onSuccess:()=>{n.invalidateQueries({queryKey:[["integrations"]]}),n.invalidateQueries({queryKey:[["deviceManager"]]}),p(!1),o("/integrations")}}),S=Ps({onSuccess:()=>{n.invalidateQueries({queryKey:[["integrations"]]}),n.invalidateQueries({queryKey:[["deviceManager"]]})}}),k=Q(()=>y??[],[y]),M=Q(()=>{const O=new Map;for(const $ of k)O.set($.id,{id:$.id,name:$.name??$.stableId??`#${String($.id)}`});return O},[k]),D=q(O=>M.get(O)??null,[M]),E=q(O=>r(Vt,{type:O,size:"sm"}),[]),B=q(O=>o(`/devices/${String(O)}`),[o]),A=Q(()=>{const O=m?.addonId;if(!O)return 0;let $=0;for(const I of k)I.addonId!==O||I.parentDeviceId!==null&&I.parentDeviceId!==void 0&&I.role||($+=1);return $},[k,m?.addonId]);return g?f("div",{className:"p-6",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"})]}):m?f("div",{className:"p-6 space-y-5",children:[r(bl,{items:[{label:"Integrations",onClick:()=>o("/integrations")},{label:m.name}]}),f("div",{className:"flex items-center justify-between",children:[f("div",{className:"flex items-center gap-3",children:[r("img",{src:`/api/addon-assets/${m.addonId}/assets/icon.svg`,alt:"",className:"h-8 w-8 rounded-lg",onError:O=>{O.target.style.display="none"}}),f("div",{children:[r("h1",{className:"text-lg font-semibold text-foreground",children:m.name}),f("p",{className:"text-[11px] text-foreground-subtle mt-0.5",children:[m.addonId," · ",A," ",e("integrations.devices")]})]})]}),f("div",{className:"flex items-center gap-3",children:[f("div",{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${v.isPending?"opacity-60":""} ${m.enabled?"border-success/30 bg-success/5":"border-border bg-surface"}`,title:e("integrations.toggleHint",{defaultValue:"Click to toggle"}),children:[r(il,{checked:m.enabled,onCheckedChange:O=>v.mutate({id:t,enabled:O}),disabled:v.isPending,"aria-label":m.enabled?"Disable integration":"Enable integration"}),r("span",{className:`text-[11px] font-medium ${m.enabled?"text-success":"text-foreground-subtle"}`,children:m.enabled?"Enabled":"Disabled"}),v.isPending&&r(Le,{className:"h-3 w-3 animate-spin text-foreground-subtle"})]}),x&&f("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(bt,{className:"h-3 w-3"}),e("integrations.config")]}),f("button",{onClick:()=>h(!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(st,{className:"h-3 w-3"}),e("integrations.logs",{defaultValue:"Logs"})]}),r(kg,{label:"Restart",icon:Et,title:`Restart "${m.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${A} active). Streams will reconnect automatically.`,confirmLabel:"Restart",triggerVariant:"outline",confirmVariant:"danger",disabled:S.isPending,action:()=>S.mutateAsync({addonId:m.addonId})}),f("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(nt,{className:"h-3 w-3"}),e("integrations.delete",{defaultValue:"Delete"})]})]})]}),r(Es,{devices:k,trpc:s.trpcClient,defaultView:"cards",forceAddon:m.addonId,urlScope:"root",lsKey:`integration-detail:${m.addonId}`,resolveIntegrationIcon:E,resolveParent:D,onNavigate:B}),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(_n,{className:"h-5 w-5 text-primary-foreground"})}),a&&t&&r(LD,{open:a,integrationId:t,addonId:m.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:f("div",{className:"rounded-xl border border-border bg-surface p-6 shadow-xl w-80",onClick:O=>O.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"})]})}),u&&r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6",onClick:()=>h(!1),children:f("div",{className:"flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]",onClick:O=>O.stopPropagation(),children:[f("div",{className:"flex items-center justify-between border-b border-border px-4 py-2.5",children:[f("div",{className:"flex items-center gap-2 min-w-0",children:[r(st,{className:"h-4 w-4 text-primary shrink-0"}),r("h2",{className:"text-sm font-semibold text-foreground truncate",children:m.name}),f("span",{className:"text-[10px] text-foreground-subtle font-mono truncate",children:[m.addonId,t?` · ${t}`:""]})]}),r("button",{onClick:()=>h(!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(qe,{className:"h-4 w-4"})})]}),r("div",{className:"flex-1 min-h-0 overflow-hidden",children:r(Wt,{addonId:m.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:f("div",{className:"rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3",onClick:O=>O.stopPropagation(),children:[f("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(Bt,{className:"h-4 w-4 text-danger"})}),f("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:m.name,count:A})})]})]}),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)}),f("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?f(ye,{children:[r(Le,{className:"h-3 w-3 animate-spin"}),e("integrations.deleting",{defaultValue:"Deleting…"})]}):f(ye,{children:[r(nt,{className:"h-3 w-3"}),e("integrations.confirmDelete",{defaultValue:"Delete integration"})]})})]})]})})]}):f("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(J4,{className:"h-6 w-6 text-foreground-subtle"})}),f("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??""})})]}),f("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(hP,{className:"h-3 w-3"}),e("integrations.backToList",{defaultValue:"Back to integrations"})]})]})}function BD({label:e,color:t,title:n,style:o}){return f("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:f("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 _a=36e5;function zD(e){return String(e).padStart(2,"0")}function FD(e){const t=new Date(e);return`${zD(t.getHours())}:00`}function HD({startMs:e,endMs:t,segments:n,events:o,playheadMs:s,onSeek:a}){const i=ee(null),l=t-e,c=q(m=>Math.max(0,Math.min(100,(m-e)/l*100)),[e,l]);function d(m){if(!i.current)return;const g=i.current.getBoundingClientRect(),b=Math.max(0,Math.min(1,(m.clientX-g.left)/g.width));a(Math.round(e+b*l))}const p=[],u=Math.floor(e/_a),h=Math.ceil(t/_a);for(let m=u;m<=h;m++){const g=m*_a;g<e||g>t||p.push({percent:c(g),label:FD(g)})}return f("div",{className:"select-none",children:[r("div",{className:"relative h-5 mb-1",children:p.map(({percent:m,label:g})=>r("span",{className:"absolute -translate-x-1/2 text-[10px] text-foreground-subtle",style:{left:`${m}%`},children:g},g))}),f("div",{ref:i,className:"relative h-8 rounded bg-surface-hover cursor-pointer overflow-hidden border border-border",onClick:d,onPointerMove:m=>{m.buttons===1&&d(m)},children:[n.map((m,g)=>{const b=c(m.startMs),x=c(m.endMs)-b;return r("div",{className:"absolute top-1 bottom-1 rounded-sm bg-success/60",style:{left:`${b}%`,width:`${Math.max(x,.1)}%`}},g)}),o.map(m=>r(BD,{label:m.label,color:m.color,title:`${m.label} — ${new Date(m.timestampMs).toLocaleTimeString()}`,style:{left:`${c(m.timestampMs)}%`}},m.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 du={person:"#f59e0b",vehicle:"#3b82f6",car:"#3b82f6",face:"#a855f7",plate:"#ec4899",animal:"#10b981",motion:"#ef4444",unknown:"#6b7280"};function Ii(e){return du[e.toLowerCase()]??du.unknown}function jD(e){const t=new Date(e);return t.setHours(0,0,0,0),t.getTime()}function VD(e){return new Date(e).toISOString().slice(0,10)}function qD(e){return new Date(e+"T00:00:00").getTime()}function UD(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 QD(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:Ii(t[o%t.length])})).sort((n,o)=>n.timestampMs-o.timestampMs)}function GD(){const{t:e}=xt(),t=jD(new Date),[n,o]=L(t),[s,a]=L(null),[i,l]=L(t+12*36e5),c=n,d=n+24*36e5,{data:p,isLoading:u}=$n({},{staleTime:3e4}),h=p??[],m=Q(()=>h.filter(N=>{const S=N.type.toLowerCase();return S==="camera"||S.includes("camera")||N.features.some(k=>k.toLowerCase().includes("video")||k.toLowerCase().includes("stream"))}).map(N=>({id:N.id,name:N.name??N.stableId})),[h]),g=s??m[0]?.id??null,{data:b}=En({queryKey:["events",g,c],queryFn:()=>Promise.resolve(null),enabled:!!g,staleTime:6e4}),x=Q(()=>{const v=Array.isArray(b)?b:(()=>{const S=Wc(b)?.events;return Array.isArray(S)?S:[]})();return v.length===0?g?QD(c):[]:v.flatMap((N,S)=>{const k=Wc(N);if(!k)return[];const M=String(k.class??k.type??k.label??"unknown").toLowerCase(),D=typeof k.timestamp=="number"?k.timestamp:c;return[{id:String(k.id??S),timestampMs:D,label:M,color:Ii(M)}]})},[b,g,c]),y=Q(()=>g?UD(c):[],[g,c]);function w(v){o(N=>N+v*24*36e5),l(N=>N+v*24*36e5)}return f("div",{className:"flex flex-col h-full p-6 gap-5 overflow-hidden",children:[f("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")}),f("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(lc,{className:"h-4 w-4"})}),f("div",{className:"relative flex items-center",children:[r(Yg,{className:"absolute left-2 h-3.5 w-3.5 text-foreground-subtle pointer-events-none"}),r("input",{type:"date",value:VD(n),onChange:v=>{if(v.target.value){const N=qD(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($t,{className:"h-4 w-4"})})]})]}),f("div",{className:"flex gap-1.5 shrink-0 overflow-x-auto pb-1",children:[u&&r("div",{className:"h-8 w-48 rounded-lg bg-surface animate-pulse"}),!u&&m.length===0&&r("span",{className:"text-xs text-foreground-subtle",children:"No cameras found"}),m.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)})]}),f("div",{className:"relative w-full aspect-video rounded-xl border border-border bg-black shrink-0 overflow-hidden max-h-[45vh]",children:[f("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 text-foreground-subtle",children:[r(Ir,{className:"h-12 w-12 opacity-20"}),r("p",{className:"text-sm opacity-50",children:g?`${m.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()})]}),f("div",{className:"rounded-xl border border-border bg-surface px-4 pt-3 pb-4 shrink-0",children:[f("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"}),f("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(x.map(v=>v.label))).slice(0,5).map(v=>f("div",{className:"flex items-center gap-1.5",children:[r("span",{className:"inline-block h-2.5 w-2.5 rounded-full",style:{backgroundColor:Ii(v)}}),r("span",{className:"text-[10px] text-foreground-subtle capitalize",children:v})]},v))]}),g?r(HD,{startMs:c,endMs:d,segments:y,events:x,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 WD({selectedNodeId:e,onSelect:t,refreshToken:n}){const{data:o}=sn(void 0,{staleTime:3e4}),{data:s}=$s(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 f("div",{className:"flex flex-col h-full",children:[f("button",{type:"button",onClick:()=>t(Ar),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===Ar?"bg-primary/10 text-primary":"text-foreground hover:bg-surface-hover"}`,children:[r(i4,{className:"h-4 w-4 flex-shrink-0"}),f("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,u=a.get(d.id)??0,h=d.isHub?ro:tt;return f("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(h,{className:"h-4 w-4 flex-shrink-0"}),f("div",{className:"min-w-0 flex-1",children:[f("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"})]}),f("div",{className:"text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5",children:[f("span",{children:[d.cpuCores," cores"]}),r("span",{children:"•"}),f("span",{children:[Math.round(d.memoryMB/1024)," GB"]}),u>0&&f(ye,{children:[r("span",{children:"•"}),f("span",{className:"inline-flex items-center gap-0.5 text-foreground",children:[r(fb,{className:"h-2.5 w-2.5"}),u]})]})]})]})]},d.id)})}),f("div",{className:"px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between",children:[f("span",{children:[l," online"]}),c>0&&f("span",{className:"text-destructive",children:[c," offline"]})]})]})}function KD({nodeId:e,refreshToken:t}){const{data:n}=sn(void 0,{staleTime:3e4}),o=n?.find(i=>i.id===e),a=or("pipeline.runner-load-snapshot",i=>i.nodeId===e)?.load??null;return o?f("div",{className:"px-6 py-4 border-b border-border",children:[f("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"})]}),f("div",{className:"text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap",children:[r("span",{children:o.cpuModel??"CPU"}),r("span",{children:"•"}),f("span",{children:[o.cpuCores," cores"]}),r("span",{children:"•"}),f("span",{children:[Math.round(o.memoryMB/1024)," GB"]}),a&&f(ye,{children:[r("span",{children:"•"}),f("span",{children:[a.attachedCameras," cameras (",a.activeCameras," active)"]}),r("span",{children:"•"}),f("span",{children:[a.avgInferenceTimeMs.toFixed(0),"ms avg inference"]}),r("span",{children:"•"}),f("span",{children:["queue ",a.queueDepthTotal]}),a.hardware.hasGpu&&f(ye,{children:[r("span",{children:"•"}),r("span",{className:"text-success",children:"GPU"})]})]})]})]}):r("div",{className:"px-6 py-4 border-b border-border",children:f("div",{className:"text-xs text-foreground-subtle",children:["Node not found: ",e]})})}function $b({refreshToken:e,nodeId:t}){const[n,o]=L(new Map),{nodes:s}=sr();et("pipeline.camera-metrics-snapshot",u=>{const h=u.data;typeof h?.deviceId=="number"&&o(m=>{const g=new Map(m);return g.set(h.deviceId,h),g})});const{data:a}=Rm(void 0,{staleTime:5e3}),i=Q(()=>{const u=new Map;for(const h of a??[])u.set(h.nodeId,h.deviceCount);return u},[a]),l=Q(()=>{const u=new Map,h=Date.now()-3e4;for(const m of n.values()){if(m.timestamp<h)continue;const g=m.nodeId??"hub",b=u.get(g)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};b.attachedCameras++,m.metrics.phase==="active"&&b.activeCameras++,b.totalFps+=m.metrics.actualFps,b.totalInferenceWeighted+=m.metrics.avgInferenceTimeMs,b.queueDepth+=m.metrics.queueDepth,u.set(g,b)}return u},[n]),c=Q(()=>{const u=new Map;for(const h of s)u.set(h.id,h.shortName);return u},[s]),d=Q(()=>{let u=0,h=0,m=0,g=0,b=0;for(const y of l.values())u+=y.attachedCameras,h+=y.activeCameras,m+=y.totalFps,g+=y.totalInferenceWeighted,b+=y.queueDepth;const x=u>0?g/u:0;return{totalAgents:s.length,onlineAgents:s.filter(y=>y.isOnline).length,attachedCameras:u,activeCameras:h,avgInferenceTimeMs:x,queueDepth:b,totalFps:m}},[l,s]);if(t){const u=l.get(t);return f("div",{className:"@container/liveload",children:[r("h3",{className:"text-sm font-semibold text-foreground mb-2",children:"Live load"}),f("div",{className:"grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3",children:[r(wt,{label:"FPS",value:u?u.totalFps.toFixed(1):"—"}),r(wt,{label:"Cameras",value:u?`${u.activeCameras}/${u.attachedCameras}`:"—"}),r(wt,{label:"Avg infer ms",value:u&&u.attachedCameras>0?(u.totalInferenceWeighted/u.attachedCameras).toFixed(0):"—"}),r(wt,{label:"Queue",value:u?String(u.queueDepth):"—"}),r(wt,{label:"Audio",value:String(i.get(t)??"—")})]})]})}const p=[...l.entries()].sort(([u],[h])=>u==="hub"?-1:h==="hub"?1:u.localeCompare(h));return f("div",{className:"@container/liveload",children:[r("h3",{className:"text-sm font-semibold text-foreground mb-2",children:"Live load"}),f("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(wt,{label:"Total agents",value:`${d.onlineAgents}/${d.totalAgents}`}),r(wt,{label:"Cameras",value:`${d.activeCameras}/${d.attachedCameras}`}),r(wt,{label:"Total FPS",value:d.totalFps.toFixed(1)}),r(wt,{label:"Avg inference ms",value:d.avgInferenceTimeMs.toFixed(0)}),r(wt,{label:"Queue depth",value:String(d.queueDepth)})]}),r("div",{className:"rounded-lg border border-border overflow-x-auto",children:f("table",{className:"w-full text-xs min-w-[480px]",children:[r("thead",{className:"bg-surface",children:f("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"})]})}),f("tbody",{children:[p.map(([u,h])=>f("tr",{className:"border-t border-border",children:[r("td",{className:"px-3 py-2 text-foreground font-medium",children:c.get(u)??u}),r("td",{className:"px-3 py-2 text-right text-foreground",children:h.totalFps.toFixed(1)}),r("td",{className:"px-3 py-2 text-right text-foreground",children:h.attachedCameras}),r("td",{className:"px-3 py-2 text-right text-foreground",children:h.attachedCameras>0?(h.totalInferenceWeighted/h.attachedCameras).toFixed(0):"—"}),r("td",{className:"px-3 py-2 text-right text-foreground",children:h.queueDepth}),r("td",{className:"px-3 py-2 text-right text-foreground",children:i.get(u)??"—"})]},u)),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 wt({label:e,value:t}){return f("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 Db(e){return $n({addonId:e})}function YD(e){return yn({deviceId:e},{enabled:Number.isFinite(e)})}const ZD=3e4,XD=2e3;function _b(e){const t=ee(0);return t.current===0&&(t.current=Date.now()),jh({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>=ZD?!1:XD}})}const Ta={active:!1,pinned:!1,nodeId:null,reason:""},Ra=["pipeline.camera-assigned","pipeline.camera-unassigned","pipeline.camera-updated","agent.online","agent.offline"],JD={pipeline:tt,decoder:Ir,audio:wi},uu={pipeline:"Pipeline",decoder:"Decoder",audio:"Audio"};function Tb({mode:e,nodeId:t,compact:n=!1}){if(e==="agent"&&!t)throw new Error('CameraAssignmentsTable: nodeId is required when mode === "agent"');const o=ke(),[s,a]=L(null),[i,l]=L(null),[c,d]=L(new Map);at(["pipelineOrchestrator","getPipelineAssignments"],Ra),at(["pipelineOrchestrator","getDecoderAssignments"],Ra),at(["pipelineOrchestrator","getAudioAssignments"],Ra);const{data:p}=$s(void 0,{staleTime:3e4}),{data:u}=Dm(void 0,{staleTime:3e4}),{data:h}=Lm(void 0,{staleTime:3e4}),{nodes:m}=sr(),{data:g}=Db();et("pipeline.camera-metrics-snapshot",A=>{const O=A.data;typeof O.deviceId=="number"&&d($=>{const I=new Map($);return I.set(O.deviceId,O),I})}),X(()=>{if(c.size===0)return;const A=setInterval(()=>{d(O=>{const $=Date.now()-1e4;let I=!1;const _=new Map(O);for(const[P,T]of O)T.timestamp<$&&(_.delete(P),I=!0);return I?_:O})},5e3);return()=>clearInterval(A)},[c.size]);const b=Q(()=>{const A=new Map;for(const O of g??[])A.set(O.id,O.name);return A},[g]),x=Q(()=>{const A=new Map,O=I=>{const _=A.get(I);if(_)return _;const P={deviceId:I,deviceName:b.get(I)??`Device ${I}`,pipeline:Ta,decoder:Ta,audio:Ta};return A.set(I,P),P};for(const I of p??[]){const _=O(I.deviceId);A.set(I.deviceId,{..._,pipeline:{active:e==="cluster"?!0:I.agentNodeId===t,pinned:I.pinned,nodeId:I.agentNodeId,reason:I.reason??""}})}for(const I of u??[]){const _=O(I.deviceId);A.set(I.deviceId,{..._,decoder:{active:e==="cluster"?!0:I.decoderNodeId===t,pinned:I.pinned,nodeId:I.decoderNodeId,reason:I.reason??""}})}for(const I of h??[]){const _=O(I.deviceId);A.set(I.deviceId,{..._,audio:{active:e==="cluster"?!0:I.nodeId===t,pinned:I.pinned,nodeId:I.nodeId,reason:"capacity"}})}let $=[...A.values()];return e==="agent"&&($=$.filter(I=>I.pipeline.active||I.decoder.active||I.audio.active)),$.sort((I,_)=>I.deviceId-_.deviceId),$},[p,u,h,b,e,t]),y=Q(()=>(m??[]).filter(A=>A.isOnline).map(A=>({id:A.id,name:A.name})),[m]),w=()=>{o.invalidateQueries({queryKey:[["pipelineOrchestrator","getPipelineAssignments"]]}),o.invalidateQueries({queryKey:[["pipelineOrchestrator","getDecoderAssignments"]]}),o.invalidateQueries({queryKey:[["pipelineOrchestrator","getAudioAssignments"]]})},v=km({onSuccess:w}),N=Cm({onSuccess:w}),S=Am({onSuccess:w}),k=$m({onSuccess:w}),M=_m({onSuccess:w}),D=Tm({onSuccess:w}),E=(A,O,$)=>{O==="pipeline"?v.mutate({deviceId:A,agentNodeId:$}):O==="decoder"?S.mutate({deviceId:A,nodeId:$}):M.mutate({deviceId:A,nodeId:$}),a(null)},B=(A,O)=>{O==="pipeline"?N.mutate({deviceId:A}):O==="decoder"?k.mutate({deviceId:A}):D.mutate({deviceId:A}),a(null)};return r("div",{className:"rounded-lg border border-border overflow-x-auto",children:f("table",{className:"w-full text-xs min-w-[640px]",children:[r("thead",{className:"bg-surface",children:f("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"})]})}),f("tbody",{children:[x.map(A=>{const O=c.get(A.deviceId),$=i===A.deviceId;return f(Wi.Fragment,{children:[f("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($?null:A.deviceId),className:"p-1 rounded hover:bg-surface-hover text-foreground-subtle","aria-label":$?"Collapse broker details":"Expand broker details",children:$?r(It,{className:"h-3.5 w-3.5"}):r($t,{className:"h-3.5 w-3.5"})})}),f("td",{className:"px-3 py-2 align-middle",children:[r("div",{className:"text-foreground font-medium leading-tight",children:A.deviceName}),f("div",{className:"text-[10px] text-foreground-subtle leading-tight",children:["#",A.deviceId]})]}),r(La,{role:"pipeline",state:A.pipeline,mode:e,deviceId:A.deviceId,onlineNodes:y,isMenuOpen:s?.deviceId===A.deviceId&&s.role==="pipeline",onToggleMenu:()=>a(s?.deviceId===A.deviceId&&s.role==="pipeline"?null:{deviceId:A.deviceId,role:"pipeline"}),onCloseMenu:()=>a(null),onMove:I=>E(A.deviceId,"pipeline",I),onUnpin:()=>B(A.deviceId,"pipeline")}),r(La,{role:"decoder",state:A.decoder,mode:e,deviceId:A.deviceId,onlineNodes:y,isMenuOpen:s?.deviceId===A.deviceId&&s.role==="decoder",onToggleMenu:()=>a(s?.deviceId===A.deviceId&&s.role==="decoder"?null:{deviceId:A.deviceId,role:"decoder"}),onCloseMenu:()=>a(null),onMove:I=>E(A.deviceId,"decoder",I),onUnpin:()=>B(A.deviceId,"decoder")}),r(La,{role:"audio",state:A.audio,mode:e,deviceId:A.deviceId,onlineNodes:y,isMenuOpen:s?.deviceId===A.deviceId&&s.role==="audio",onToggleMenu:()=>a(s?.deviceId===A.deviceId&&s.role==="audio"?null:{deviceId:A.deviceId,role:"audio"}),onCloseMenu:()=>a(null),onMove:I=>E(A.deviceId,"audio",I),onUnpin:()=>B(A.deviceId,"audio")}),r("td",{className:"px-3 py-2 align-middle",children:r(n_,{snap:O})})]}),$&&!n&&f("tr",{className:"bg-surface/50",children:[r("td",{}),r("td",{colSpan:5,className:"px-3 py-2",children:r(Ze,{widgetId:"stream-broker/stream-broker-panel",host:"device-tab",deviceId:A.deviceId,instanceId:`pipeline-row/${A.deviceId}`,config:{variant:"compact",title:"Stream brokers & clients"}})})]})]},A.deviceId)}),x.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 La({role:e,state:t,mode:n,onlineNodes:o,isMenuOpen:s,onToggleMenu:a,onCloseMenu:i,onMove:l,onUnpin:c}){const d=JD[e],p=o.filter(m=>m.id!==(t.nodeId??"")),h=(t.active||n==="cluster")&&(p.length>0||t.pinned);return f("td",{className:"px-3 py-2 align-middle relative",children:[f("div",{className:"flex items-center gap-2",children:[n==="agent"?r(e_,{state:t,Icon:d}):r(t_,{state:t,Icon:d}),r("div",{className:"ml-auto",children:h&&r("button",{type:"button",onClick:a,className:"p-1 rounded hover:bg-surface-hover","aria-label":`${uu[e]} actions`,children:r(WP,{className:"h-3 w-3 text-foreground-subtle"})})})]}),s&&h&&r(r_,{title:uu[e],targets:p,pinned:t.pinned,onMove:l,onUnpin:c,onClose:i})]})}function e_({state:e,Icon:t}){const n=e.active?db:pc;return f("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(sb,{className:"h-2.5 w-2.5 text-amber-400"})]})}function t_({state:e,Icon:t}){return!e.active||!e.nodeId?f("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:"—"})]}):f("div",{className:"flex items-center gap-1.5 min-w-0",children:[r(t,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),f("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?f("span",{className:"inline-flex items-center gap-0.5 text-amber-400",children:[r(sb,{className:"h-2.5 w-2.5"})," manual"]}):f("span",{className:"text-foreground-subtle truncate",children:["auto · ",e.reason||"capacity"]})})]})]})}function n_({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=An(t);return f("div",{className:"flex flex-col gap-0.5 font-mono text-[10px] tabular-nums leading-tight",children:[f("span",{className:`inline-flex items-center gap-1 ${i.textColor}`,children:[r(Ql,{phase:t,className:"h-2.5 w-2.5"}),r("span",{className:"font-semibold uppercase tracking-wider",children:i.label})]}),f("span",{className:"text-foreground-subtle",children:[r("span",{className:"text-foreground",children:n.toFixed(1)}),f("span",{children:["/",a.toFixed(0)," fps"]})]}),f("span",{className:"text-foreground-subtle",children:[r("span",{className:"text-foreground",children:o.toFixed(0)}),r("span",{children:" ms"}),s>0&&f("span",{className:"text-warning ml-1",children:["q",s]})]})]})}function r_({title:e,targets:t,pinned:n,onMove:o,onUnpin:s,onClose:a}){const i=ee(null);return X(()=>{const l=c=>{i.current?.contains(c.target)||a()};return window.addEventListener("mousedown",l),()=>window.removeEventListener("mousedown",l)},[a]),f("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=>f("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&&f("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 o_({nodeId:e,refreshToken:t}){return f("div",{className:"space-y-6",children:[r($b,{refreshToken:t,nodeId:e}),f("div",{children:[r("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Cameras on this node"}),f("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(Tb,{mode:"agent",nodeId:e,compact:!0})]})}function s_(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 a_({nodeId:e,refreshToken:t}){const n=ke(),o=Sm({onSettled:()=>{n.invalidateQueries({queryKey:["pipelineExecutor","listLoadedEngines"]})}}),{data:s}=Nm({nodeId:e},{staleTime:5e3}),i=or("pipeline.engine-metrics-snapshot",h=>h.nodeId===e)?.engines??s??null,l=i===null;at(["pipelineRunner","getLocalCameras"],["pipeline.camera-assigned","pipeline.camera-unassigned"]);const{data:c}=Um({nodeId:e},{staleTime:3e4}),{values:d}=Up("pipeline.camera-metrics-snapshot",h=>h.deviceId,h=>h.nodeId===e),p=Q(()=>d.filter(h=>h.metrics.phase==="active").length,[d]),u=h=>{const m=c??[];m.length>0&&!window.confirm(`${m.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||o.mutate({nodeId:e,engine:h,force:m.length>0})};return f("div",{className:"space-y-6",children:[f("div",{children:[r("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Inference engines on this node"}),f("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-hidden",children:f("table",{className:"w-full text-xs",children:[r("thead",{className:"bg-surface",children:f("tr",{className:"text-foreground-subtle text-[10px] uppercase tracking-wider",children:[r("th",{className:"text-left px-3 py-2",children:"Kind"}),r("th",{className:"text-left px-3 py-2",children:"Runtime / Backend / Device"}),r("th",{className:"text-left px-3 py-2",children:"Models"}),r("th",{className:"text-right px-3 py-2",children:"Pool PID"}),r("th",{className:"text-right px-3 py-2",children:"Auto-kill"}),r("th",{className:"text-right px-3 py-2",children:"In use"}),r("th",{className:"w-24"})]})}),f("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(h=>{const m=h.kind==="warm-override";return f("tr",{className:`border-t border-border ${m?"bg-amber-500/5":""}`,children:[r("td",{className:"px-3 py-2",children:f("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${m?"bg-amber-500/15 text-amber-400":"bg-success/15 text-success"}`,children:[m?r(n4,{className:"h-3 w-3"}):r(tt,{className:"h-3 w-3"}),m?"warm":"runtime"]})}),r("td",{className:"px-3 py-2",children:f("span",{className:"inline-flex items-center gap-1 text-[11px] text-sky-400",children:[r(mc,{className:"h-3 w-3"}),h.engine.runtime,"/",h.engine.backend,h.engine.device?`/${h.engine.device}`:"",h.engine.format?` · ${h.engine.format}`:""]})}),r("td",{className:"px-3 py-2",children:h.modelsLoaded.length===0?r("span",{className:"text-foreground-subtle text-[11px]",children:"—"}):r("div",{className:"flex flex-wrap gap-1",children:h.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:h.poolPid??"—"}),r("td",{className:"px-3 py-2 text-right text-[11px]",children:h.idleMs!==null&&h.idleTtlMs!==null?r("span",{className:"text-foreground-subtle",children:s_(h.idleMs,h.idleTtlMs)}):r("span",{className:"text-foreground-subtle/50",children:"never"})}),r("td",{className:"px-3 py-2 text-right text-foreground",children:m?"—":(c??[]).length}),r("td",{className:"px-3 py-2 text-right",children:f("button",{type:"button",disabled:o.isPending,onClick:()=>u(h.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(nt,{className:"h-3 w-3"}),"Kill"]})})]},h.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."})})]})]})}),f("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&&f("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"]})]})}const i_=new Set(Uv);function fu(e){return i_.has(e)}function Oa(e,t,n){return`${e}/${t}/${n}`}function Ei(e){return{coreml:"CoreML",openvino:"OpenVINO",onnx:"ONNX"}[e.format]??e.format.toUpperCase()}function pu(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 un(e){return e.format}function l_(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 c_({addonId:e,model:t,format:n,isActive:o,progress:s,errorMsg:a,onDownload:i,onDelete:l}){const c=t.formats[n];return c?f("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"}`}),f("div",{className:"flex-1 min-w-0",children:[f("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-sm font-medium text-foreground",children:t.name}),f("span",{className:"text-[10px] text-foreground-subtle font-mono",children:["(",t.id,")"]})]}),s&&s.progress>=0&&s.progress<100&&f("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}%`}})}),f("span",{className:"text-[9px] text-primary font-mono tabular-nums shrink-0",children:[Math.round(s.progress),"%"]})]})]}),f("span",{className:"text-xs text-foreground-subtle tabular-nums shrink-0",children:[c.sizeMB.toFixed(1)," MB"]}),a&&f("span",{className:"flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0",title:a,children:[r(Fs,{className:"h-3 w-3 shrink-0"}),a]}),c.downloaded?f("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(Le,{className:"h-3 w-3 animate-spin"}):r(nt,{className:"h-3 w-3"}),o?"Deleting...":"Delete"]}):f("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(Le,{className:"h-3 w-3 animate-spin"}):r(vn,{className:"h-3 w-3"}),o?"Downloading...":"Download"]})]}):null}function d_({engines:e,activeEngine:t,viewEngine:n,onSelect:o}){const[s,a]=L(!1);return f("div",{className:"relative",children:[f("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(tt,{className:"h-4 w-4 text-primary shrink-0"}),f("div",{className:"flex-1 min-w-0",children:[f("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-sm font-medium text-foreground",children:Ei(n)}),un(n)===un(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:pu(n)})]}),r(It,{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=un(i)===un(n),c=un(i)===un(t);return f("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(tt,{className:`h-4 w-4 shrink-0 ${l?"text-primary":"text-foreground-subtle"}`}),f("div",{className:"flex-1",children:[f("div",{className:"flex items-center gap-2",children:[r("span",{className:`text-sm font-medium ${l?"text-primary":"text-foreground"}`,children:Ei(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:pu(i)})]}),l&&r(Xg,{className:"h-4 w-4 text-primary shrink-0"})]},un(i))})})]})}function u_({embedded:e=!1,nodeId:t}={}){const n=ke(),o=t??"hub",[s,a]=L(null),[i,l]=L(new Set),[c,d]=L(new Map),[p,u]=L(new Map),[h,m]=L(""),{data:g=[]}=bm({nodeId:o},{staleTime:6e4}),x=g.filter((T,R,z)=>z.findIndex(H=>H.format===T.format)===R),{data:y}=xm({nodeId:o},{staleTime:3e4}),w=y,{data:v,isLoading:N}=Jr({nodeId:o},{staleTime:1e4}),S=vm(),k=wm();et("model.download.progress",T=>{const R=T.data,z=typeof R.modelId=="string"?R.modelId:void 0,H=typeof R.progress=="number"?R.progress:void 0,F=typeof R.totalMB=="number"?R.totalMB:0;z===void 0||H===void 0||(d(j=>{const J=new Map(j);return H===100||H===-1?J.delete(z):J.set(z,{modelId:z,progress:H,totalMB:F}),J}),H===100&&n.invalidateQueries({queryKey:[["pipelineExecutor","getSchema"]]}))});const M=w??{runtime:"node",backend:"cpu",format:"onnx"},D=x.find(T=>T.format===s)??M,E=D.format,B=v?.slots??[],A=B.map(T=>({...T,addons:T.addons.map(R=>({...R,models:R.models.filter(z=>z.formats[E]!==void 0)})).filter(R=>R.models.length>0)})).filter(T=>T.addons.length>0),O=l_(A,E),$=q(async(T,R,z)=>{if(!fu(z))return;const H=Oa(T,R,z);l(F=>new Set([...F,H])),u(F=>{const j=new Map(F);return j.delete(H),j});try{await S.mutateAsync({addonId:T,modelId:R,format:z,nodeId:o}),n.invalidateQueries({queryKey:[["pipelineExecutor","getSchema"]]})}catch(F){u(j=>new Map([...j,[H,F instanceof Error?F.message:"Download failed"]]))}finally{l(F=>{const j=new Set(F);return j.delete(H),j})}},[S,n,o]),I=q(async(T,R,z)=>{if(!fu(z))return;const H=Oa(T,R,z);l(F=>new Set([...F,H])),u(F=>{const j=new Map(F);return j.delete(H),j});try{await k.mutateAsync({addonId:T,modelId:R,format:z,nodeId:o}),n.invalidateQueries({queryKey:[["pipelineExecutor","getSchema"]]})}catch(F){u(j=>new Map([...j,[H,F instanceof Error?F.message:"Delete failed"]]))}finally{l(F=>{const j=new Set(F);return j.delete(H),j})}},[k,n,o]),_=q(T=>{a(T.format)},[]),P=h.trim()?A.map(T=>({...T,addons:T.addons.map(R=>({...R,models:R.models.filter(z=>z.name.toLowerCase().includes(h.toLowerCase())||z.id.toLowerCase().includes(h.toLowerCase())||R.name.toLowerCase().includes(h.toLowerCase()))})).filter(R=>R.models.length>0)})).filter(T=>T.addons.length>0):A;return f("div",{className:e?"space-y-4":"p-6 space-y-6 max-w-5xl mx-auto",children:[!e&&f("div",{children:[r("h1",{className:"text-lg font-bold text-foreground",children:"Models"}),r("p",{className:"text-xs text-foreground-subtle mt-0.5",children:"Manage ML models for the detection pipeline. Select an engine to see its compatible models."})]}),N&&r("div",{className:"flex items-center justify-center py-16",children:r(Le,{className:"h-5 w-5 animate-spin text-foreground-subtle"})}),!N&&B.length===0&&f("div",{className:"flex flex-col items-center justify-center py-16 text-foreground-subtle",children:[r(vi,{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&&B.length>0&&f(ye,{children:[r(d_,{engines:x,activeEngine:M,viewEngine:D,onSelect:_}),f("div",{className:"flex items-center gap-4 text-xs text-foreground-subtle",children:[f("span",{children:[r("span",{className:"font-semibold text-foreground tabular-nums",children:O.total}),r("span",{className:"ml-1",children:"compatible models"})]}),r("span",{className:"text-border",children:"|"}),f("span",{children:[r("span",{className:"font-semibold text-success tabular-nums",children:O.downloaded}),r("span",{className:"ml-1",children:"downloaded"})]}),r("span",{className:"text-border",children:"|"}),f("span",{className:"tabular-nums",children:[O.downloadedSizeMB>=1024?`${(O.downloadedSizeMB/1024).toFixed(1)} GB`:`${Math.round(O.downloadedSizeMB)} MB`,r("span",{className:"ml-1",children:"on disk"})]})]}),O.total>5&&f("div",{className:"relative",children:[r(cb,{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:h,onChange:T=>m(T.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"})]}),P.map(T=>{const R=T.addons.reduce((H,F)=>H+F.models.length,0),z=T.addons.reduce((H,F)=>H+F.models.filter(j=>j.formats[E]?.downloaded).length,0);return f("div",{children:[f("div",{className:"flex items-center gap-2 mb-2",children:[r("h2",{className:"text-sm font-semibold text-foreground",children:T.label}),r("div",{className:"flex-1 h-px bg-border"}),f("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:[z,"/",R]})]}),r("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:T.addons.map(H=>H.models.map(F=>{const j=Oa(H.id,F.id,E);return r(c_,{addonId:H.id,model:F,format:E,isActive:i.has(j),progress:c.get(F.id),errorMsg:p.get(j),onDownload:()=>$(H.id,F.id,E),onDelete:()=>I(H.id,F.id,E)},`${H.id}/${F.id}`)}))})]},T.id)}),P.length===0&&r("div",{className:"text-center py-8 text-sm text-foreground-subtle",children:h.trim()?f(ye,{children:["No models matching “",h,"”"]}):f(ye,{children:["No models available for ",Ei(D)," format"]})})]})]})}function f_({nodeId:e,refreshToken:t}){return r(u_,{embedded:!0,nodeId:e})}function Rb({nodeId:e,title:t}){const{data:n}=Db(),{data:o}=$s(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]=L(new Map);et("pipeline.camera-metrics-snapshot",d=>{const p=d.data;typeof p.deviceId=="number"&&(e&&p.nodeId!==e||l(u=>{const h=new Map(u);return h.set(p.deviceId,p),h}))}),X(()=>{if(i.size===0)return;const d=setInterval(()=>{l(p=>{const u=Date.now()-1e4;let h=!1;const m=new Map(p);for(const[g,b]of p)b.timestamp<u&&(m.delete(g),h=!0);return h?m: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,u)=>p.deviceId-u.deviceId),d},[i,a]);return c.length===0?f("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"]}):f("div",{className:"rounded-md border border-border bg-surface px-3 py-2",children:[f("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}`,u=An(d.metrics.phase);return f("div",{title:`${p} · ${u.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] ${u.badgeClass}`,children:[r(Ql,{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 Ba(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 p_({nodeId:e,refreshToken:t}){const n=ke(),[o,s]=L(null),[a,i]=L(null),l=Jr({nodeId:e},{refetchOnMount:"always"}),c=Bl({agentNodeId:e},{refetchOnMount:"always"}),d=zl({onSuccess:()=>{n.invalidateQueries({queryKey:[["addonSettings"]]}),n.invalidateQueries({queryKey:[["pipelineOrchestrator"]]}),n.invalidateQueries({queryKey:[["pipelineExecutor"]]})}}),p=l.data??null,u=c.data,h=p?.selectedEngine.format??"coreml",m=Q(()=>p?Cs(p):[],[p]),g=Q(()=>[{agentNodeId:e,engineLabel:h}],[e,h]),b=(k,M)=>{const D=u?.addonDefaults[k];return Ba(p,k)?.models.some(A=>!!A.formats[h])?D?D.enabled?{kind:"enabled",modelId:D.modelId}:{kind:"disabled"}:{kind:"na"}:{kind:"na"}},x=o&&p?Ba(p,o.addonId):null,y=k=>{const M=u?.addonDefaults[k]??null;s({addonId:k,agentNodeId:e}),i(M)},w=(k,M)=>{if(!u)return;const D=u.addonDefaults[k],E=Ba(p,k);if(!D&&!E)return;const B={enabled:M,modelId:D?.modelId??E?.defaultModelId??"",settings:D?.settings??{}};d.mutate({agentNodeId:e,defaults:{...u.addonDefaults,[k]:B}})},v=()=>{s(null),i(null)},N=()=>{!a||!o||!u||d.mutate({agentNodeId:e,defaults:{...u.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 f("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 S=o!==null&&x!==null&&a!==null;return f("div",{className:"relative h-full w-full space-y-3",children:[r(Rb,{nodeId:e}),r("div",{className:S?"pr-[360px]":"",children:m.length>0?r(yl,{tree:m,agents:g,getCellState:b,onCellClick:y,selectedCell:o,onToggleEnabled:w}):r("div",{className:"text-xs text-foreground-subtle",children:"Catalog empty."})}),r(xl,{open:S,onClose:v,title:x?.name??"",subtitle:o?`${o.agentNodeId} · ${h}`:"",footer:f(ye,{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:x&&a&&o&&r(Is,{mode:"agent",addon:x,agentDefault:a,agentNodeId:o.agentNodeId,engineFormat:h,onChangeAgentConfig:k=>i(k)})})]})}function Lb({pendingCount:e,onSave:t,onDiscard:n,saving:o=!1,saveLabel:s="Save",discardLabel:a="Discard"}){return e<=0?null:f("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:[f("span",{className:"text-xs text-foreground",children:[e," unsaved change",e===1?"":"s"]}),f("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 Ob({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 f("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&&f("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 h_(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 Bb({schema:e,serverValues:t,onImmediateSave:n,onDeferredSave:o}){const[s,a]=L({}),[i,l]=L(!1),c=ee(null),d=e?.sections??[],p=Object.keys(s).length>0,u=Q(()=>({...t,...s}),[t,s]);X(()=>{if(p){l(!0);return}c.current&&clearTimeout(c.current),c.current=setTimeout(()=>l(!1),500)},[p]);const h=q(()=>{l(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>l(!1),2e3)},[]),m=q(y=>{h();const w={},v={},N={...t,...s};for(const[S,k]of Object.entries(y))N[S]!==k&&(h_(d,S)?w[S]=k:v[S]=k);Object.keys(w).length>0&&n(w),a(S=>{const k={...S};for(const M of Object.keys(w))delete k[M];for(const[M,D]of Object.entries(v))k[M]=D;return k})},[h,t,s,d,n]),g=q(y=>{const w={},v={};for(const[N,S]of Object.entries(s))y.includes(N)?w[N]=S:v[N]=S;a(v),Object.keys(w).length>0&&o(w)},[s,o]),b=q(y=>{a(w=>{const v={...w};for(const N of y)delete v[N];return v})},[]),x=q(()=>{a({})},[]);return{values:u,pendingKeys:Object.keys(s),hasPendingEdits:p,editingPaused:i,handleChange:m,handleSave:g,handleDiscard:b,resetAll:x}}const m_=Oe(function({addonId:t,schema:n,serverValues:o,onImmediateSave:s,onStateChange:a,onAction:i,disabled:l},c){const d=Bb({schema:n,serverValues:o,onImmediateSave:q(b=>s(t,b),[t,s]),onDeferredSave:q(()=>{},[])});Ly(c,()=>({flush:()=>{const b={};for(const x of d.pendingKeys)b[x]=d.values[x];return d.handleDiscard(d.pendingKeys),b},discard:()=>d.resetAll()}),[d]);const p=d.pendingKeys,u=p.join("|"),h=Q(()=>p.map(b=>`${b}=${JSON.stringify(d.values[b])}`).join(","),[p,d.values]),m=ee(a);X(()=>{m.current=a},[a]),X(()=>{const b={};for(const x of p)b[x]=d.values[x];m.current({addonId:t,pendingKeys:p,pendingValues:b})},[t,u,h]);const g=Q(()=>{if(i)return(b,x,y)=>i(t,b,x,y)},[t,i]);return r(Yn,{schema:n,values:d.values,onChange:d.handleChange,disabled:l,onAction:g})});function zb(e,t){if(e.type==="separator"||e.type==="info"||e.type==="button")return e;if(e.type==="group"){const a=e.fields.map(i=>zb(i,t));return{...e,fields:a}}const n=e;t[e.key]=n.value;const{value:o,...s}=n;return s}function g_(e,t){return{...e,fields:e.fields.map(n=>zb(n,t))}}function b_(e){const t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(o=>g_(o,t))},values:t}}function so({nodeId:e,addonIds:t,level:n,deviceId:o,sectionIds:s,sectionTab:a,extraTabs:i,title:l,description:c}){const d=ke(),p=Ae().trpcClient,u=Ih(),h=Eh(),m=ym(),g=Lh(),b=Rh(),x=!!(i&&i.length>0),[y,w]=L(null);if(n==="device"&&!o)throw new Error('NodeAddonsSettingsPanel: deviceId is required when level === "device"');const v=e??"hub",N=Qy({queries:t.map(Y=>({queryKey:[["addonSettings",n==="global"?"getGlobalSettings":"getDeviceSettings"],{addonId:Y,nodeId:v,deviceId:o??null}],queryFn:async()=>{if(n==="global"){const Z=await p.addonSettings.getGlobalSettings.query({addonId:Y,nodeId:v});return{addonId:Y,result:Z}}const G=await p.addonSettings.getDeviceSettings.query({addonId:Y,deviceId:o,nodeId:v});return{addonId:Y,result:G}},staleTime:3e4}))}),S=N.some(Y=>Y.isLoading),k=N.map(Y=>{if(!Y.data)return"-";if(Y.data.result===null)return`${Y.data.addonId}:n`;const G=[];for(const Z of Y.data.result.sections){G.push(`s:${Z.id}:${Z.tab??"general"}`);for(const re of Z.fields){if(!("key"in re))continue;const pe="options"in re&&Array.isArray(re.options)?re.options.map(se=>se.value).join(","):"",he=re.value,V=he===void 0?"":typeof he=="string"?he:JSON.stringify(he);G.push(`f:${re.key}:${pe}:${V}`)}}return`${Y.data.addonId}:${G.join("|")}`}).join("||"),M=Q(()=>{const Y=new Set;for(const G of N){const Z=G.data?.result?.sections;if(Z)for(const re of Z)Y.add(re.tab??"general")}return[...Y]},[k+"::"+N.map(Y=>(Y.data?.result?.sections??[]).map(G=>G.tab??"general").join(",")).join("::")]),D=Q(()=>new Map((i??[]).map(Y=>[Y.id,Y])),[i]),E=Q(()=>{if(!x)return[];const Y=[...new Set([...M,...(i??[]).map(Z=>Z.id)])],G=Z=>{const re=D.get(Z);if(re?.order!==void 0)return re.order;const pe=ti[Z];return pe?pe.order:50};return Y.sort((Z,re)=>{const pe=G(Z),he=G(re);return pe!==he?pe-he:Z.localeCompare(re)})},[x,M,i,D]),B=Q(()=>{const Y=new Map;for(const G of M){const Z=ti[G];Y.set(G,Z?.label??G.charAt(0).toUpperCase()+G.slice(1))}for(const G of i??[])Y.set(G.id,G.label);return Y},[M,i]),A=x?y&&E.includes(y)?y:E[0]??null:null,O=A!==null&&D.has(A),$=x?A&&!O?A:void 0:a,{data:I}=Pl(void 0,{staleTime:6e4}),_=Q(()=>{const Y=new Map;for(const G of I??[]){const Z=G.manifest?.id;if(!Z)continue;const re=G.manifest?.name??G.manifest?.packageDisplayName??Z;Y.set(Z,re)}return Y},[I]),P=Q(()=>{const Y=s?new Set(s):null,G=[];for(const Z of N){if(!Z.data||Z.data.result===null)continue;const{schema:re,values:pe}=b_(Z.data.result),he=re.sections.filter(ce=>Y?Y.has(ce.id):!0);if(he.length===0)continue;const V={...Z.data.result,sections:Z.data.result.sections.filter(ce=>Y?Y.has(ce.id):!0)},se={...re,sections:he};G.push({addonId:Z.data.addonId,schemaWithValues:V,schema:se,serverValues:pe})}return G},[k,s]),[T,R]=L(new Map),z=q(Y=>{R(G=>{const Z=new Map(G);return Z.set(Y.addonId,Y),Z})},[]),H=ee(new Map),F=q(Y=>G=>{G?H.current.set(Y,G):H.current.delete(Y)},[]),j=q(async(Y,G)=>{n==="global"?await u.mutateAsync({addonId:Y,nodeId:v,patch:G}):await h.mutateAsync({addonId:Y,deviceId:o,nodeId:v,patch:G}),d.invalidateQueries({queryKey:[["addonSettings"]]})},[u,h,v,n,o,d]),J=q(async(Y,G,Z)=>{const re=v;try{switch(G){case"reprobe-engine":await m.mutateAsync({nodeId:re});break;case"reprobe-hwaccel":await g.mutateAsync({nodeId:re});break;case"reprobe-audio-engine":await b.mutateAsync({nodeId:re});break;default:console.warn("[NodeAddonsSettingsPanel] unhandled field action",{addonId:Y,action:G});return}d.invalidateQueries({queryKey:[["addonSettings"]]})}catch(pe){console.error("[NodeAddonsSettingsPanel] action failed",{addonId:Y,action:G,err:pe})}},[m,g,b,v,d]),W=q((Y,G)=>{j(Y,G)},[j]),ne=Yi({mutationFn:async()=>{const Y=[];for(const Z of P){const re=T.get(Z.addonId);!re||re.pendingKeys.length===0||Y.push({addonId:Z.addonId,patch:re.pendingValues})}return Y.length===0?{saved:[]}:{saved:await Promise.all(Y.map(async({addonId:Z,patch:re})=>(n==="global"?await u.mutateAsync({addonId:Z,nodeId:v,patch:re}):await h.mutateAsync({addonId:Z,deviceId:o,nodeId:v,patch:re}),Z)))}},onSuccess:({saved:Y})=>{for(const G of Y)H.current.get(G)?.discard();d.invalidateQueries({queryKey:[["addonSettings"]]})}}),de=q(()=>{for(const Y of H.current.values())Y.discard()},[]),te=Q(()=>{let Y=0;for(const G of P){const Z=T.get(G.addonId);Z&&(Y+=Z.pendingKeys.length)}return Y},[P,T]),K=Q(()=>{const Y=new Map;for(const G of P){const Z=T.get(G.addonId);if(!Z||Z.pendingKeys.length===0)continue;const re=new Set(Z.pendingKeys);for(const pe of G.schema.sections){const he=pe.tab??"general";for(const V of pe.fields)"key"in V&&re.has(V.key)&&Y.set(he,(Y.get(he)??0)+1)}}return Y},[P,T]);if(S)return r("div",{className:"h-24 rounded-lg border border-border bg-surface animate-pulse"});const oe=A&&O?D.get(A):void 0;if(!x&&P.length===0)return f("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 me=ne.isPending;return f("div",{className:"space-y-4",children:[(l||c)&&f("div",{className:"border-b border-border pb-2",children:[l&&r("h2",{className:"text-sm font-semibold text-foreground",children:l}),c&&r("p",{className:"text-[11px] text-foreground-subtle mt-0.5",children:c})]}),x&&r(Ob,{tabs:E.map(Y=>({id:Y,label:B.get(Y)??Y})),activeId:A,onChange:w,pendingByTab:K}),ne.isError&&f("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(ne.error?.message??ne.error)]}),oe?oe.content:(()=>{const Y=$?P.reduce((re,pe)=>re+pe.schemaWithValues.sections.filter(he=>(he.tab??"general")===$).length,0):0,G=$!==null&&Y<=1,Z=P.map(re=>({...re,renderedWithValues:{...re.schemaWithValues,sections:re.schemaWithValues.sections.filter(pe=>$?(pe.tab??"general")===$:!0).map(pe=>G?{...pe,title:"",description:void 0}:pe)}})).filter(re=>re.renderedWithValues.sections.length>0).sort((re,pe)=>{const he=ce=>{let ie=Number.POSITIVE_INFINITY;for(const ae of ce)typeof ae.order=="number"&&ae.order<ie&&(ie=ae.order);return ie},V=he(re.renderedWithValues.sections),se=he(pe.renderedWithValues.sections);return V!==se?V-se:0});return Z.length===0?r("div",{className:"text-[11px] text-foreground-subtle italic",children:"Nothing to configure here for this node."}):r(x_,{entries:Z,paneStates:T,displayNames:_,disabled:me,setPaneRef:F,onPaneStateChange:z,onImmediateSave:W,onAction:J,inline:x||!!a})})(),!S&&r(Lb,{pendingCount:te,onSave:()=>ne.mutate(),onDiscard:de,saving:me})]})}function x_({entries:e,paneStates:t,displayNames:n,disabled:o,setPaneRef:s,onPaneStateChange:a,onImmediateSave:i,onAction:l,inline:c}){const d=Q(()=>[...e].sort((x,y)=>{if(x.addonId==="system-config")return-1;if(y.addonId==="system-config")return 1;const w=n.get(x.addonId)??x.addonId,v=n.get(y.addonId)??y.addonId;return w.localeCompare(v)}),[e,n]),p=d[0]?.addonId??"",[u,h]=L(p);X(()=>{d.length!==0&&(d.find(x=>x.addonId===u)||h(d[0].addonId))},[d,u]);const m=d.find(x=>x.addonId===u)??d[0];if(!m)return null;const g=l?(x,y,w)=>l(x,y,w):void 0,b=x=>r(m_,{ref:s(x.addonId),addonId:x.addonId,schema:x.renderedWithValues,serverValues:x.serverValues,onImmediateSave:i,onStateChange:a,onAction:g,disabled:o},x.addonId);return d.length===1||c?r("div",{className:"flex flex-col gap-4",children:d.map(b)}):f("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(x=>{const y=n.get(x.addonId)??x.addonId,w=x.addonId===m.addonId,v=(t.get(x.addonId)?.pendingKeys.length??0)>0;return f("button",{type:"button",onClick:()=>h(x.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"})]},x.addonId)})}),r("div",{className:"space-y-2",children:d.map(x=>r("div",{style:x.addonId===m.addonId?void 0:{display:"none"},children:b(x)},x.addonId))})]})}const y_=["detection-pipeline","decoder-nodeav","audio-analyzer","pipeline-runner"];function v_({nodeId:e,refreshToken:t}){return f("div",{className:"flex flex-col h-full",children:[r(KD,{nodeId:e,refreshToken:t}),r("div",{className:"flex-1 min-h-0 overflow-y-auto p-6",children:r(so,{nodeId:e,addonIds:y_,level:"global",extraTabs:[{id:"assignments",label:"Assignments",order:-10,content:r(o_,{nodeId:e,refreshToken:t})},{id:"tree",label:"Pipeline",order:39,content:r(p_,{nodeId:e,refreshToken:t})},{id:"engines",label:"Warm instances",order:180,content:r(a_,{nodeId:e,refreshToken:t})},{id:"models",label:"Models",order:200,content:r(f_,{nodeId:e,refreshToken:t})}]})})]})}function w_({refreshToken:e}){const t=ke(),n=Mm({onSuccess:()=>{t.invalidateQueries({queryKey:[["pipelineOrchestrator","getPipelineAssignments"]]}),t.invalidateQueries({queryKey:[["pipelineOrchestrator","getDecoderAssignments"]]}),t.invalidateQueries({queryKey:[["pipelineOrchestrator","getAudioAssignments"]]})}});return f("div",{className:"space-y-6",children:[r($b,{refreshToken:e}),f("div",{className:"flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between",children:[f("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."})]}),f("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(mc,{className:"h-3.5 w-3.5"}),n.isPending?"Rebalancing…":"Rebalance pipelines"]})]}),r(Tb,{mode:"cluster"})]})}const N_=["pipeline-orchestrator"];function S_({refreshToken:e}){return r("div",{className:"space-y-4 max-w-3xl",children:r(so,{nodeId:"hub",addonIds:N_,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 k_({refreshToken:e}){const t=ke(),{data:n,isLoading:o}=jm(),[s,a]=L(null),[i,l]=L(""),[c,d]=L(""),p=()=>{t.invalidateQueries({queryKey:[["pipelineOrchestrator","listTemplates"]]})},u=Vm({onSuccess:()=>{a(null),p()}}),h=qm({onSuccess:p}),m=y=>{a(y.id),l(y.name),d(y.description??"")},g=()=>{a(null),l(""),d("")},b=()=>{if(!s)return;const y=c.trim();u.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 x=[...n??[]].sort((y,w)=>y.name.localeCompare(w.name));return r("div",{className:"space-y-6 max-w-4xl",children:f("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[f("div",{className:"border-b border-border px-4 py-3 flex items-center justify-between",children:[f("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."})]}),f("div",{className:"text-[11px] text-foreground-subtle",children:[x.length," template",x.length===1?"":"s"]})]}),x.length===0?f("div",{className:"px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2",children:[r(_n,{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:x.map(y=>{const w=s===y.id;return r("li",{className:"px-4 py-3 text-xs",children:f("div",{className:"flex items-start gap-3",children:[r("div",{className:"flex-1 min-w-0",children:w?f("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)"})]}):f(ye,{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}),f("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":"",f("span",{className:"ml-2",children:["updated ",new Date(y.updatedAt).toLocaleString()]})]})]})}),r("div",{className:"flex items-center gap-1 shrink-0",children:w?f(ye,{children:[f("button",{type:"button",onClick:b,disabled:u.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(At,{className:"h-3 w-3"}),"Save"]}),f("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(qe,{className:"h-3 w-3"}),"Cancel"]})]}):f(ye,{children:[r("button",{type:"button",onClick:()=>m(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(Hs,{className:"h-3 w-3"})}),r("button",{type:"button",onClick:()=>{confirm(`Delete template "${y.name}"?`)&&h.mutate({id:y.id})},disabled:h.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(nt,{className:"h-3 w-3"})})]})})]})},y.id)})})]})})}function hu(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 C_({nodeId:e,refreshToken:t}){const n=ke(),o=Ae().trpcClient,[s,a]=L(null),[i,l]=L(null),c=ir(void 0,{refetchOnMount:"always"});at(["nodes","topology"],["agent.online","agent.offline","agent.unregistered","addon.installed","addon.uninstalled","addon.updated"]);const d=sn(void 0,{staleTime:3e4,refetchOnMount:"always"}),p=Q(()=>{const E=new Set;for(const B of d.data??[])B.isOnline&&E.add(B.id);return E},[d.data]),u=Jr({nodeId:e},{refetchOnMount:"always"}),h=Q(()=>(c.data??[]).filter(E=>p.has(E.nodeId)).map(E=>E.nodeId),[c.data,p]),m=En({enabled:h.length>0,queryKey:[["pipelineExecutor","getSchema"],"schema-by-agent",h.join(","),t],queryFn:async()=>{const E={};for(const B of h)try{const A=await o.pipelineExecutor.getSchema.query({nodeId:B});E[B]=A.selectedEngine.format}catch{E[B]="coreml"}return E}}),g=zl({onSuccess:()=>{n.invalidateQueries({queryKey:[["pipelineOrchestrator"]]}),n.invalidateQueries({queryKey:[["pipelineExecutor"]]}),n.invalidateQueries({queryKey:[["addonSettings"]]})}}),b=Q(()=>u.data?Cs(u.data):[],[u.data]),x=Q(()=>{const E=c.data??[],B=p;return(B.size===0?[]:E.filter(O=>B.has(O.nodeId))).map(O=>{const $=m.data?.[O.nodeId];return{agentNodeId:O.nodeId,engineLabel:$??"(engine unknown)"}})},[c.data,m.data,p]),y=(E,B)=>{const O=c.data?.find(P=>P.nodeId===B)?.settings.addonDefaults[E],$=m.data?.[B];return hu(u.data??null,E)?.models.some(P=>$!==void 0&&!!P.formats[$])?O?O.enabled?{kind:"enabled",modelId:O.modelId}:{kind:"disabled"}:{kind:"na"}:{kind:"na"}},w=s?c.data?.find(E=>E.nodeId===s.agentNodeId)??null:null,v=s&&u.data?hu(u.data,s.addonId):null,N=s?m.data?.[s.agentNodeId]??"coreml":"coreml",S=()=>{a(null),l(null)},k=(E,B)=>{const O=c.data?.find($=>$.nodeId===B)?.settings.addonDefaults[E]??null;a({addonId:E,agentNodeId:B}),l(O)},M=()=>{!i||!s||!w||g.mutate({agentNodeId:s.agentNodeId,defaults:{...w.settings.addonDefaults,[s.addonId]:i}},{onSuccess:S})};if(c.isLoading||u.isLoading)return r("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading agents…"});if(!u.data)return f("div",{className:"text-xs text-foreground-subtle",children:["Catalog unavailable for ",e,"."]});const D=s!==null&&v!==null&&i!==null;return f("div",{className:"relative h-full w-full space-y-3",children:[r(Rb,{title:"Cluster cameras"}),r("div",{className:D?"pr-[360px]":"",children:b.length>0&&x.length>0?r(yl,{tree:b,agents:x,getCellState:y,onCellClick:k,selectedCell:s}):r("div",{className:"text-xs text-foreground-subtle",children:"No agents or catalog empty."})}),r(xl,{open:D,onClose:S,title:v?.name??"",subtitle:s?`${s.agentNodeId} · ${N}`:"",footer:f(ye,{children:[r("button",{type:"button",className:"px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted",onClick:S,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:M,children:g.isPending?"Saving…":"Save"})]}),children:v&&i&&s&&r(Is,{mode:"agent",addon:v,agentDefault:i,agentNodeId:s.agentNodeId,engineFormat:N,onChangeAgentConfig:E=>l(E)})})]})}const M_=[{id:"assignments",label:"Assignments"},{id:"pipeline",label:"Pipeline"},{id:"settings",label:"Settings"},{id:"templates",label:"Templates"}];function I_({refreshToken:e}){const[t,n]=L("assignments"),{data:o}=sn(void 0,{staleTime:3e4}),s=o?.find(a=>a.isHub&&a.isOnline)?.id??o?.find(a=>a.isOnline)?.id??null;return f("div",{className:"flex flex-col h-full",children:[f("div",{className:"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-6 border-b border-border",children:M_.map(a=>r("button",{type:"button",onClick:()=>n(a.id),className:`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))}),f("div",{className:"flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab",children:[t==="assignments"&&r(w_,{refreshToken:e}),t==="pipeline"&&(s?r(C_,{nodeId:s,refreshToken:e}):r("div",{className:"text-xs text-foreground-subtle",children:"No online node available — schema unreachable."})),t==="settings"&&r(S_,{refreshToken:e}),t==="templates"&&r(k_,{refreshToken:e})]})]})}const Ar="__cluster__";function E_(){const[e,t]=Wg(),n=e.get("node")??Ar,[o,s]=L(0);return X(()=>{e.get("node")||t({node:Ar},{replace:!0})},[e,t]),f("div",{className:"flex flex-col h-full overflow-hidden",children:[f("div",{className:"flex items-center justify-between gap-4 px-6 py-4 border-b border-border shrink-0",children:[f("div",{className:"flex items-center gap-2",children:[r(tb,{className:"h-4 w-4 text-foreground-subtle"}),r("h1",{className:"text-lg font-semibold text-foreground",children:"Pipeline"})]}),f("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(Et,{className:"h-3.5 w-3.5"}),"Refresh"]})]}),f("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(WD,{selectedNodeId:n,onSelect:i=>{t({node:i},{replace:!0})},refreshToken:o})}),r("section",{className:"flex-1 min-h-0 overflow-hidden",children:n===Ar?r(I_,{refreshToken:o}):r(v_,{nodeId:n,refreshToken:o})})]})]})}function P_(e){const[t,n]=L("idle"),[o,s]=L(null),a=ee(null),i=ee(null),l=ee(null),c=ee(!0),d=am(),p=im(),u=lm(),h=q(()=>{if(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},[]),m=q(async()=>{if(t==="idle")return;n("stopping");const b=l.current;if(b&&e!==null)try{await Promise.race([u.mutateAsync({deviceId:e,sessionId:b}),new Promise((y,w)=>setTimeout(()=>w(new Error("server stopSession timeout")),2e3))])}catch(y){console.warn("[intercom] server stopSession failed (continuing teardown)",y)}h(),c.current&&(n("idle"),s(null))},[t,e,u,h]),g=q(async()=>{if(e===null||t!=="idle"&&t!=="error")return;s(null);let b=null,x=null,y=null;try{n("requesting-mic"),b=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),i.current=b,n("starting");const w=await d.mutateAsync({deviceId:e});y=w.sessionId,l.current=y,n("connecting"),x=new RTCPeerConnection,a.current=x,x.oniceconnectionstatechange=()=>{if(!c.current)return;const S=x.iceConnectionState;S==="connected"||S==="completed"?n("talking"):(S==="failed"||S==="closed"||S==="disconnected")&&c.current&&(s(S==="failed"?"WebRTC connection failed":null),m())};for(const S of b.getAudioTracks())x.addTrack(S,b);await x.setRemoteDescription({type:"offer",sdp:w.sdpOffer});const v=await x.createAnswer();await x.setLocalDescription(v);const N=x.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),x)try{x.close()}catch{}if(b)for(const N of b.getTracks())try{N.stop()}catch{}if(a.current=null,i.current=null,y!==null)try{await u.mutateAsync({deviceId:e,sessionId:y})}catch{}l.current=null,c.current&&(s(v),n("error"))}},[e,t,d,p,u,m]);return X(()=>(c.current=!0,()=>{c.current=!1;const b=l.current;if(b!==null&&e!==null&&u.mutate({deviceId:e,sessionId:b}),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}),[e]),{state:t,error:o,start:g,stop:m,isTalking:t==="talking"}}let A_=0;function Ke(){return++A_}function za(e){switch(e.type){case"system":return"system";case"device":return`#${e.deviceId}`;case"provider":return e.providerId;case"addon":return e.addonId}}function $_(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 D_(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 __(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 T_({scope:e,greeting:t,className:n}){const o=Ae(),[s,a]=L(()=>{const v=[];return t&&v.push({id:Ke(),kind:"info",text:t}),v.push({id:Ke(),kind:"info",text:`scope: ${za(e)} — type help or context for available commands`}),v}),[i,l]=L(""),[c,d]=L([]),[p,u]=L(-1),h=ee(null),m=ee(null);X(()=>{const v=m.current;v&&(v.scrollTop=v.scrollHeight)},[s]);const g=q(()=>{h.current?.focus()},[]),b=Yi({mutationFn:v=>o.trpcClient.repl.execute.mutate({code:v,scope:e}),onSuccess:v=>{const N=v??{},S=typeof N.output=="string"?N.output:v==null?"undefined":typeof v=="string"?v:JSON.stringify(v,null,2),k=N.type==="error";a(M=>[...M,{id:Ke(),kind:k?"error":"result",text:S}])},onError:v=>{const N=v instanceof Error?v.message:String(v);a(S=>[...S,{id:Ke(),kind:"error",text:N}])}});function x(v){const N=v.trim();if(N){if(N==="clear"){a([{id:Ke(),kind:"info",text:`scope: ${za(e)}`}]),l("");return}if(N==="help"){a(S=>[...S,{id:Ke(),kind:"input",text:`> ${N}`},...$_(e).map(k=>({id:Ke(),kind:"info",text:k}))]),l("");return}if(N==="context"){a(S=>[...S,{id:Ke(),kind:"input",text:`> ${N}`},...__(e).map(k=>({id:Ke(),kind:"info",text:k}))]),l("");return}if(N==="examples"){a(S=>[...S,{id:Ke(),kind:"input",text:`> ${N}`},...D_(e).map(k=>({id:Ke(),kind:"info",text:k}))]),l("");return}d(S=>[...S,N]),u(-1),a(S=>[...S,{id:Ke(),kind:"input",text:`> ${N}`}]),l(""),b.mutate(N)}}function y(v){if(v.key==="Enter"){v.preventDefault(),x(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);u(N),l(c[N]??"");return}if(v.key==="ArrowDown"){if(v.preventDefault(),p===-1)return;const N=p+1;N>=c.length?(u(-1),l("")):(u(N),l(c[N]??""));return}v.ctrlKey&&v.key==="l"&&(v.preventDefault(),a([{id:Ke(),kind:"info",text:`scope: ${za(e)}`}]))}const w={input:"text-zinc-300",result:"text-emerald-300",error:"text-red-300",info:"text-zinc-400"};return f("div",{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??""}`,onClick:g,children:[f("div",{ref:m,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)),b.isPending&&r("span",{className:"text-zinc-500 animate-pulse",children:"…thinking"})]}),f("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:h,value:i,onChange:v=>l(v.target.value),onKeyDown:y,disabled:b.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 R_(e){const t=ke(),n=e!==null&&Number.isFinite(e),o=Qm({deviceId:e??0},{enabled:n,refetchInterval:5e3,retry:1}),s=Gm({onSuccess:()=>{t.invalidateQueries({queryKey:[["ptzAutotrack"]]})}}),a=Wm({onSuccess:()=>{t.invalidateQueries({queryKey:[["ptzAutotrack"]]})}}),i=q(async d=>{e!==null&&await s.mutateAsync({deviceId:e,enabled:d})},[e,s]),l=q(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 L_({deviceId:e}){const{status:t,isLoading:n,isPending:o,error:s,setEnabled:a,setSettings:i}=R_(Number.isFinite(e)?e:null),[l,c]=L({targetType:"",stopDelaySeconds:30,disappearDelaySeconds:15}),[d,p]=L(!1);return X(()=>{if(d)return;const u=t?.currentSettings;u&&c({targetType:u.targetType,stopDelaySeconds:u.stopDelaySeconds,disappearDelaySeconds:u.disappearDelaySeconds})},[t,d]),n&&!t?f("div",{className:"flex items-center gap-2 px-3 py-2 text-[10.5px] text-foreground-subtle",children:[r(Le,{className:"h-3 w-3 animate-spin"}),"Loading autotrack…"]}):f("div",{className:"border-t border-border/40 mt-2 pt-2 px-1 space-y-2",children:[f("div",{className:"flex items-center justify-between px-2",children:[f("div",{className:"flex items-center gap-1.5 text-[10.5px] font-semibold text-foreground",children:[r(VP,{className:"h-3 w-3 text-primary"}),"Autotracking"]}),f("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&&f("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(Fs,{className:"h-3 w-3 flex-shrink-0 mt-0.5"}),r("span",{className:"leading-snug break-words",children:s})]}),f("div",{className:"grid grid-cols-2 gap-2 px-2",children:[(t?.supportedTargetTypes?.length??0)>0&&f("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:u=>c(h=>({...h,targetType:u.target.value})),onBlur:()=>{p(!1);const u=t?.currentSettings?.targetType??"";l.targetType!==u&&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(u=>r("option",{value:u.value,children:u.label},u.value))})]}),f("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:u=>c(h=>({...h,stopDelaySeconds:Number(u.target.value)||0})),onBlur:()=>{p(!1);const u=t?.currentSettings?.stopDelaySeconds??30;l.stopDelaySeconds!==u&&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"})]}),f("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:u=>c(h=>({...h,disappearDelaySeconds:Number(u.target.value)||0})),onBlur:()=>{p(!1);const u=t?.currentSettings?.disappearDelaySeconds??15;l.disappearDelaySeconds!==u&&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)."})]})}function O_({deviceId:e,intercomAvailable:t=!1}){const n=Ae(),o=typeof window<"u"?window.location.origin:"",s=Number.isFinite(e),a=hb(s?e:null),{streams:i,pipelineMetrics:l,createSession:c,sendAnswer:d,closeSession:p}=Yl(n.trpcClient,s?e:null),u=Sl(n.trpcClient,s?e:null),h=P_(s&&t?e:null),m=h.state==="requesting-mic"||h.state==="starting"||h.state==="connecting"||h.state==="stopping",g=h.isTalking||m,b=()=>{h.state==="idle"||h.state==="error"?h.start():h.state!=="stopping"&&h.stop()},x=yg(),y=x.length>0?r(ye,{children:x.map(w=>r("div",{className:"absolute inset-0",children:w.node},w.id))}):null;return r(Ul,{serverUrl:o,createSession:c,sendAnswer:d,closeSession:p,streams:i,pipelineMetrics:l,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:u.src,snapshotLoading:u.loading,onRefreshSnapshot:u.refresh,intercomAvailable:t,intercomShown:g,onIntercomToggle:b,extraOverlay:y,chromeless:!0,className:"h-full"})}function B_({deviceId:e}){return Number.isFinite(e)?r("div",{className:"flex flex-col h-full",children:r(Wt,{deviceId:e,limit:50,maxHeight:"max-h-full",showScope:!1,showFilters:!1})}):f("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]})}function z_({deviceId:e}){if(!Number.isFinite(e))return f("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(`
519
- `);return r(T_,{scope:{type:"device",deviceId:e},greeting:t,className:"h-full border-0 rounded-none"})}function F_({deviceId:e}){const t=Ae(),n=Number.isFinite(e),o=Zl(t.trpcClient,n?e:0,{enabled:n}),{data:s}=YD(n?e:0);if(!n)return f("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]});const a=(s?.features??[]).includes(mn.PtzAutotrack);return f("div",{className:"flex flex-col h-full overflow-y-auto",children:[r(Wl,{controls:o,mode:"panel"}),a&&r(L_,{deviceId:e})]})}function H_({deviceId:e}){return Number.isFinite(e)?r("div",{className:"flex flex-col h-full overflow-y-auto",children:r(cr,{deviceId:e,limit:50,maxHeight:"max-h-full"})}):f("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]})}function j_({deviceId:e}){return Number.isFinite(e)?r("div",{className:"flex flex-col h-full overflow-y-auto",children:r(Gl,{deviceId:e,limit:50,maxHeight:"max-h-full"})}):f("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]})}function V_({parentDeviceId:e}){const{t}=xt(),n=Ge(),o=Ae(),{data:s,isLoading:a,isError:i}=_b(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(u=>!!u.role),d=l.some(u=>!u.role),p=c&&!d?t("device.accessories",{defaultValue:"Accessories"}):!c&&d?t("device.adoptedDevices",{defaultValue:"Adopted devices"}):t("device.children",{defaultValue:"Children"});return f("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(u=>r(Lr,{trpc:o.trpcClient,device:u,variant:"minimal",onNavigate:h=>n(`/devices/${String(h)}`)},u.id))})]})}function Fa(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function q_({device:e}){const t=Ge(),n=typeof e.id=="number"?e.id:null,o=String(e.type??""),s=o===Ye.Camera,a=o===Ye.Hub,i=e.features??[],{data:l}=Ol({deviceId:n??0},{enabled:n!==null&&s,refetchInterval:5e3}),c=l?.streams??{},d=Object.entries(c),p=i.includes(mn.DoorbellButton),u=Xl(p?{deviceId:n??void 0,historyLimit:10}:void 0),h=u.latest?Date.now()-u.latest.timestamp<3e4:!1;return f("div",{className:"space-y-5",children:[a&&n!==null&&r(Sg,{deviceId:n,onOpenChild:m=>t(`/devices/${m}`)}),s&&n!==null&&r(Ze,{widgetId:"pipeline-orchestrator/pipeline-quick-stats",host:"device-tab",deviceId:n}),p&&r(Kl,{history:u.history,latestIsFresh:h}),s&&n!==null&&r(Ze,{widgetId:"stream-broker/stream-broker-panel",host:"device-tab",deviceId:n}),s&&d.length>0&&f("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(([m,g])=>f("div",{className:"px-4 py-2.5",children:[f("div",{className:"flex items-center gap-2 mb-2",children:[r(Wn,{className:"h-3 w-3 text-foreground-subtle"}),r("span",{className:"text-[11px] font-medium text-foreground",children:m})]}),f("div",{className:"grid grid-cols-2 @[640px]:grid-cols-4 gap-2",children:[r(Io,{label:"Nominal",value:Fa(g.nominalBitrateKbps??0)}),r(Io,{label:"Observed",value:Fa(g.observedBitrateKbps??0)}),r(Io,{label:"Peak",value:Fa(g.peakBitrateKbps??0)}),r(Io,{label:"Packet Loss",value:`${(g.packetLossPercent??0).toFixed(2)}%`,warning:(g.packetLossPercent??0)>1})]})]},m))})]}),r(gb,{})]})}function Io({label:e,value:t,warning:n}){return f("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 U_({schema:e,values:t,pendingKeys:n,onChange:o,onAction:s,onSave:a,onDiscard:i,disabled:l}){const c=e.tabs??[],d=Q(()=>{const S=new Map;for(const k of e.sections){const M=k.tab??"general",D=S.get(M)??[];D.push(k),S.set(M,D)}return S},[e.sections]),p=new Set(c.map(S=>S.id)),u=[...c,...[...d.keys()].filter(S=>!p.has(S)).map(S=>({id:S,label:S,icon:"wrench",order:100}))],h=u[0]?.id??"general",[m,g]=L(h),b=d.get(m)??[],y={sections:b.length<=1?b.length===1?[{...b[0],title:""}]:b:b.every(k=>!k.title)?[{...b[0],title:"",fields:b.flatMap(k=>k.fields)}]:b},w=r(Lb,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>i(n),saving:l});if(u.length<=1)return f("div",{className:"flex flex-col gap-3",children:[r(Yn,{schema:e,values:t,onChange:o,onAction:s,disabled:l}),w]});const v=new Map,N=new Map;for(const[S,k]of d){v.set(S,k.length);const M=new Set,D=B=>{for(const A of B)if("key"in A&&typeof A.key=="string"&&M.add(A.key),A.type==="group")D(A.fields);else if(A.type==="sub-tabs")for(const O of A.tabs)D(O.fields)};for(const B of k)D(B.fields);const E=n.filter(B=>M.has(B)).length;E>0&&N.set(S,E)}return f("div",{className:"flex flex-col gap-3",children:[r(Ob,{tabs:u.map(S=>({id:S.id,label:S.label})),activeId:m,onChange:g,countByTab:v,pendingByTab:N}),r(Yn,{schema:y,values:t,onChange:o,onAction:s,disabled:l}),w]})}const mu={viewer:10,admin:20,super_admin:30};function Q_(e,t){if(!t)return!0;const n=mu[t];return n===void 0?!0:(e?mu[e]??0:0)>=n}function G_(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):(o.order??0)-(s.order??0)})};return e.tabs?{...n,tabs:e.tabs}:n}function Fb(e){return e.type==="separator"||e.type==="info"||e.type==="button"||e.type==="widget"}function Hb(e){return e.key}function W_(e){if(!Fb(e))return e.value}function jb(e){return Fb(e)?null:e}function as(e,t){for(const n of e)if(t(n),n.type==="group")as(n.fields,t);else if(n.type==="sub-tabs")for(const o of n.tabs)as(o.fields,t)}function K_(e){if(!e)return{};const t={};for(const n of e.sections)as(n.fields,o=>{const s=Hb(o);s!==null&&(t[s]=W_(o))});return t}function gu(e,t){if(!e)return null;let n=null;for(const o of e.sections)if(as(o.fields,s=>{if(n!==null||Hb(s)!==t)return;const a=jb(s);a&&a.writerCapName&&a.writerAddonId&&(n={capName:a.writerCapName,addonId:a.writerAddonId})}),n!==null)break;return n}function Y_(e){return{...e,fields:e.fields.map(Vb)}}function Vb(e){return e.type==="separator"||e.type==="info"||e.type==="button"||e.type==="object-array"?e:{...e,readonlyField:!0}}function Z_(e,t){return e&&{...e,sections:e.sections.map(n=>({...n,fields:n.fields.map(o=>{const s=jb(o);return s?Q_(t,s.minRole)?o:Vb(o):o})}))}}function qb({deviceId:e,sectionFilter:t}){const n=ke(),{user:o}=oo(),s=o?.role,a=ee(!1),{data:i,isLoading:l}=_l({deviceId:e},{refetchInterval:()=>a.current?!1:2500,staleTime:6e4,enabled:Number.isFinite(e)}),{data:c}=yn({deviceId:e},{staleTime:6e4,enabled:Number.isFinite(e)}),d=i?.settings??null,p=i?.live??null,u=Q(()=>{if(!d&&!p)return null;const O=d?.sections??[],$=(p?.sections??[]).map(Y_),I=[...O,...$],_=t?I.filter(t):I.filter(z=>z.location!=="top-tab");if(_.length===0)return null;const P=new Set;for(const z of _)P.add(z.tab??"general");const R=[...d?.tabs??[],...(p?.tabs??[]).filter(z=>!(d?.tabs??[]).some(H=>H.id===z.id))].filter(z=>P.has(z.id));return R.length>0?{tabs:R,sections:_}:{sections:_}},[d,p,t]),h=Q(()=>G_(u),[u]),m=Q(()=>Z_(h,s),[h,s]),g=Q(()=>K_(m),[m]),b=rg(),x=Rl(),y=Kh({onSuccess:()=>{n.invalidateQueries({queryKey:[["deviceManager","getDeviceAggregate"]]})}}),w={isPending:y.isPending,mutate:O=>{y.mutate({deviceId:e,changes:[...O]})}},v=q(O=>{const $=Object.entries(O).map(([I,_])=>{const P=gu(m,I);return P?{writerCapName:P.capName,writerAddonId:P.addonId,key:I,value:_}:null}).filter(I=>I!==null);$.length>0&&w.mutate($)},[m,w]),N=q(O=>{const $=Object.entries(O).map(([I,_])=>{const P=gu(m,I);return P?{writerCapName:P.capName,writerAddonId:P.addonId,key:I,value:_}:null}).filter(I=>I!==null);$.length>0&&w.mutate($)},[m,w]),S=Bb({schema:m,serverValues:g,onImmediateSave:v,onDeferredSave:N}),{values:k,pendingKeys:M,handleChange:D,handleSave:E,handleDiscard:B}=S;if(a.current=S.editingPaused,l)return f("div",{className:"flex items-center justify-center py-12 text-foreground-subtle",children:[r(Le,{className:"h-4 w-4 animate-spin mr-2"}),r("span",{className:"text-xs",children:"Loading device aggregate…"})]});if(!m||m.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 A(O,$,I){if(O==="regenerate-rtsp-token"){const _=["rtspUrl:","regenerateToken:"].find(R=>$.startsWith(R));if(!_)throw new Error(`regenerate-rtsp-token: unrecognised key "${$}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);const P=$.slice(_.length);if(!P)throw new Error(`regenerate-rtsp-token: key "${$}" has no streamId after prefix`);const T=`${e}/${P}`;await b.mutateAsync({brokerId:T}),n.invalidateQueries({queryKey:[["deviceManager","getDeviceAggregate"]]});return}if(O==="test-probe"){if(!c)return{status:"error",error:"Device metadata not loaded yet"};try{return await x.mutateAsync({addonId:c.addonId,type:c.type,key:$,value:I})}catch(_){return{status:"error",error:_ instanceof Error?_.message:String(_)}}}if(O==="refresh-driver-data"){await y.mutateAsync({deviceId:e,changes:[{writerCapName:"device-manager",writerAddonId:"device-manager",key:$,value:Date.now()}]});return}throw new Error(`[device-aggregate] unknown action "${O}"`)}return r(U_,{schema:m,values:k,pendingKeys:M,onChange:D,onAction:A,onSave:E,onDiscard:B,disabled:w.isPending})}function X_({deviceId:e}){return r(qb,{deviceId:e})}const Ub=6e4,Pi=60*Ub,bu=24*Pi;function Us(e){if(e==null||e<=0)return"—";const t=Date.now()-e;return t<0||t<3e4?"just now":t<Pi?`${String(Math.floor(t/Ub))}m ago`:t<bu?`${String(Math.floor(t/Pi))}h ago`:`${String(Math.floor(t/bu))}d ago`}function J_(e,t=new Date){const n=new Date(e);return n.getFullYear()===t.getFullYear()&&n.getMonth()===t.getMonth()&&n.getDate()===t.getDate()}function Qb({dev:e,busy:t,setBusy:n}){const o=e?.motionTrigger,s=Ft(e?.state.motionTrigger),[a,i]=L(!1);if(!o)return null;const l=s?.enabled===!0,c=s!==void 0,d=async()=>{if(t||!c)return;const u=!l;n(!0),i(!0);try{await o.setMotionTrigger({enabled:u})}finally{n(!1),i(!1)}};return f("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(no,{className:"h-3 w-3"}),r("span",{children:a?l?"Disabling…":"Enabling…":c?l?"On motion: on":"On motion: off":"On motion: …"})]})}function Gb({deviceId:e,deviceName:t,useSiren:n=!1}){const o=Ae(),s=lt(o.trpcClient,e),a=Ft(s?.state.switch),[i,l]=L(!1),c=a?.on??!1,d=a?.lastChangedAt??null,p=a!==void 0,u=n?Bs:lb,h=async()=>{if(!(i||!p||!s?.switch)){l(!0);try{await s.switch.setState({on:!c})}finally{l(!1)}}};return f("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 p-4",children:[r("button",{type:"button",onClick:()=>{h()},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(u,{className:"h-10 w-10"})}),r(Qb,{dev:s,busy:i,setBusy:l}),f("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 ${Us(d)}`:"Awaiting state…"})]})]})}function eT({deviceId:e,deviceName:t}){const n=Ae(),o=lt(n.trpcClient,e),s=Ft(o?.state.switch),a=Ft(o?.state.brightness),i=s?.on??!1,l=s?.lastChangedAt??null,c=s!==void 0,d=a!==void 0,p=o?.brightness!==void 0,[u,h]=L(!1),[m,g]=L(a?.percentage??0);X(()=>{a?.percentage!==void 0&&g(a.percentage)},[a?.percentage]);const b=async()=>{if(!(u||!c||!o?.switch)){h(!0);try{await o.switch.setState({on:!i})}finally{h(!1)}}},x=async()=>{if(!(u||!d||!o?.brightness)){h(!0);try{await o.brightness.setBrightness({percentage:m})}finally{h(!1)}}};return f("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 p-4",children:[r("button",{type:"button",onClick:()=>{b()},disabled:u||!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(x4,{className:"h-9 w-9"})}),p?f("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:m,disabled:u||!i||!d,onChange:y=>g(Number(y.currentTarget.value)),onPointerUp:()=>{x()},onKeyUp:y=>{y.key==="Enter"&&x()},"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(m)}%`:"Brightness unavailable"})]}):null,r(Qb,{dev:o,busy:u,setBusy:h}),f("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 ${Us(l)}`:"Awaiting state…"})]})]})}function tT({deviceId:e}){const t=Ae(),n=lt(t.trpcClient,e),o=Ft(n?.state.motion),s=o?.detected??!1,a=o?.lastDetectedAt??null,i=o!==void 0;return f("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(U4,{className:"h-10 w-10"}):r(no,{className:"h-10 w-10"})}),f("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 ${Us(a)}`:"Awaiting state…"})]})]})}function nT({deviceId:e}){const t=Ae(),n=lt(t.trpcClient,e),o=Ft(n?.state.doorbell),s=o?.lastPressedAt??null,a=o!==void 0,i=s!==null&&Date.now()-s<6e4,[l,c]=L(0),[d,p]=L(null);return X(()=>{s===null||s===d||(p(s),J_(s)&&c(u=>u+1))},[s,d]),f("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(Bs,{className:"h-10 w-10"})}),f("div",{className:"text-center",children:[r("div",{className:`text-sm font-semibold ${i?"text-primary":"text-foreground-subtle"}`,children:a?`Last press ${Us(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 rT({deviceName:e,deviceType:t,provider:n,isOnline:o,features:s}){return f("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(Vt,{type:n,size:"lg"}),f("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})]}),f("div",{className:"flex items-center gap-2 flex-wrap justify-center",children:[r(qs,{status:o?"online":"offline"}),s.length>0&&r(js,{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 oT({deviceId:e}){const t=ke(),n=Oh({deviceId:e},{refetchInterval:1e4,retry:!1}),o=Bh({onSuccess:()=>{t.invalidateQueries({queryKey:[["deviceDiscovery","listDiscovered"]]}),t.invalidateQueries({queryKey:[["deviceDiscovery","getStatus"]]})}}),s=Q(()=>sT(n.data??[]),[n.data]);return f("div",{className:"flex h-full w-full flex-col gap-3 p-3 sm:p-4",children:[f("div",{className:"flex flex-wrap items-stretch gap-2 sm:gap-3",children:[r(Ha,{label:"Discovered",value:s.total,icon:r(uc,{className:"h-3.5 w-3.5"})}),r(Ha,{label:"Adopted",value:s.adopted,accent:"success"}),r(Ha,{label:"Available",value:s.available,accent:s.available>0?"primary":void 0}),f("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(Le,{className:"h-3.5 w-3.5 animate-spin"}):r(Et,{className:"h-3.5 w-3.5"}),r("span",{className:"hidden sm:inline",children:"Discover"})]})]}),f("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(Eo,{icon:r(Wn,{className:"h-3 w-3 text-emerald-500"}),label:`${s.online} online`}),r(Eo,{icon:r(rb,{className:"h-3 w-3 text-amber-500"}),label:`${s.sleeping} sleeping`}),r(Eo,{icon:r(pb,{className:"h-3 w-3 text-destructive"}),label:`${s.offline} offline`}),s.unknown>0?r(Eo,{icon:r(BP,{className:"h-3 w-3 text-foreground-subtle"}),label:`${s.unknown} unknown`}):null]})]})}function sT(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 Ha({label:e,value:t,icon:n,accent:o}){return f("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:[f("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 Eo({icon:e,label:t}){return f("span",{className:"inline-flex items-center gap-1",children:[e,r("span",{children:t})]})}const aT=e=>r(Gb,{...e,useSiren:!0}),iT={[Ye.Switch]:Gb,[Ye.Siren]:aT,[Ye.Light]:eT,[Ye.Sensor]:tT,[Ye.Button]:nT,[Ye.Hub]:oT};function lT(e){const t=iT[e.deviceType]??rT;return r(t,{...e})}function Ai(e){if(e===0)return"0 B";const t=["B","KB","MB","GB","TB"],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/Math.pow(1024,n)).toFixed(n>1?1:0)} ${t[n]}`}function gc(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 is(e){return new Date(e).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function ls(e){return e.toISOString().slice(0,10)}function cT(e,t){return ls(e)===ls(t)}function wr(e){const t=new Date(e);return t.setHours(0,0,0,0),t}function dT(e){const t=new Date(e);return t.setHours(23,59,59,999),t}function ut({className:e=""}){return r("div",{className:`animate-pulse rounded bg-foreground-subtle/10 ${e}`})}function fn(){return f("div",{className:"flex items-center gap-3 px-4 py-3",children:[r(ut,{className:"h-4 w-4"}),r(ut,{className:"h-3 w-24"}),r(ut,{className:"h-3 w-16 ml-auto"})]})}function gr({children:e,actions:t}){return f("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 xu({icon:e,label:t,value:n}){return f("div",{className:"flex items-center gap-2",children:[r(e,{className:"h-3.5 w-3.5 text-foreground-subtle flex-shrink-0"}),f("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 uT({segments:e,selectedDate:t}){const n=wr(t).getTime(),o=1440*60*1e3,s=Array.from({length:25},(a,i)=>i);return f("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))}),f("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:`${is(a.startTime)} - ${is(a.endTime)} (${gc(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 fT({segment:e,selected:t,onToggle:n,onPlay:o,onDownload:s,onDelete:a}){return f("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(db,{className:"h-4 w-4 text-primary"}):r(pc,{className:"h-4 w-4"})}),f("div",{className:"flex-1 min-w-0",children:[f("p",{className:"text-xs font-mono text-foreground",children:[is(e.startTime)," - ",is(e.endTime)]}),f("p",{className:"text-[10px] text-foreground-subtle",children:[gc(e.duration),e.sizeBytes!=null&&` · ${Ai(e.sizeBytes)}`]})]}),f("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(ab,{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(vn,{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(nt,{className:"h-3.5 w-3.5"})})]})]})}function pT({deviceId:e}){const t=ke(),[n,o]=L(()=>wr(new Date)),[s,a]=L(new Set),i=tg({deviceId:e},{refetchInterval:5e3}),l=Xm({deviceId:e}),c=l.data?.streams[0]?.streamId??"stream0",d=Jm({deviceId:e,streamId:c,startTime:wr(n).getTime(),endTime:dT(n).getTime()}),p=eg({deviceId:e,streamId:c},{refetchInterval:3e4}),u=ng({deviceId:e,dataCategory:"recording:main"}),h=q(()=>{t.invalidateQueries({queryKey:["recordingEngine","getPolicyStatus"]}),t.invalidateQueries({queryKey:["recordingEngine","getSegments"]}),t.invalidateQueries({queryKey:["recordingEngine","getStorageUsage"]})},[t]),m=Ym({onSuccess:h}),g={isPending:m.isPending,error:m.error,mutate:()=>{const P=l.data,T=P?{mode:P.mode,streams:P.streams,enabled:!0,preBufferSec:P.preBufferSec,postBufferSec:P.postBufferSec,scheduleRules:P.scheduleRules}:{mode:"continuous",streams:[{streamId:c,mode:"always"}],enabled:!0,preBufferSec:10,postBufferSec:5};m.mutate({deviceId:e,policy:T})}},b=Zm({onSuccess:h}),x=i.data??void 0,y=l.data??void 0,w=d.data??[],v=p.data,N=u.data??void 0,S=(x?.enabled??!1)&&(x?.activeStreams??0)>0,k=g.isPending||b.isPending,M=cT(n,new Date),D=Q(()=>[...w].sort((P,T)=>new Date(T.startTime).getTime()-new Date(P.startTime).getTime()),[w]),E=Q(()=>w.reduce((P,T)=>P+(T.duration??0),0),[w]),B=Q(()=>w.reduce((P,T)=>P+(T.sizeBytes??0),0),[w]);function A(){S?b.mutate({deviceId:e}):g.mutate()}function O(){o(P=>{const T=new Date(P);return T.setDate(T.getDate()-1),wr(T)}),a(new Set)}function $(){M||(o(P=>{const T=new Date(P);return T.setDate(T.getDate()+1),wr(T)}),a(new Set))}function I(P){a(T=>{const R=new Set(T);return R.has(P)?R.delete(P):R.add(P),R})}function _(){s.size===D.length?a(new Set):a(new Set(D.map(P=>P.id)))}return i.isLoading&&l.isLoading?f("div",{className:"space-y-4",children:[f("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r(gr,{children:"Recording Status"}),f("div",{className:"px-4 py-4 space-y-3",children:[r(ut,{className:"h-10 w-full"}),r(ut,{className:"h-4 w-48"})]})]}),f("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r(gr,{children:"Segments"}),f("div",{className:"divide-y divide-border",children:[r(fn,{}),r(fn,{}),r(fn,{})]})]})]}):f("div",{className:"space-y-4",children:[f("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r(gr,{children:"Recording Status"}),f("div",{className:"px-4 py-4 flex items-center justify-between gap-4",children:[f("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 ${S?"bg-danger/10":"bg-foreground-subtle/10"}`,children:r(Jg,{className:`h-5 w-5 ${S?"text-danger animate-pulse":"text-foreground-subtle"}`})}),f("div",{className:"min-w-0",children:[r("p",{className:`text-sm font-medium ${S?"text-danger":"text-foreground-subtle"}`,children:S?"Recording":"Not Recording"}),r("p",{className:"text-[11px] text-foreground-subtle mt-0.5 truncate",children:S&&x?`${x.mode} – ${x.activeStreams} stream(s)`:"No active recording session"})]})]}),r("button",{onClick:A,disabled:k,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 ${S?"bg-danger/10 text-danger hover:bg-danger/20":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:S?f(ye,{children:[r(pc,{className:"h-3.5 w-3.5"}),k?"Stopping...":"Stop Recording"]}):f(ye,{children:[r(ab,{className:"h-3.5 w-3.5"}),k?"Starting...":"Start Recording"]})})]}),S&&x&&f("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-[11px] text-foreground-subtle",children:[r(Ir,{className:"h-3.5 w-3.5 text-primary flex-shrink-0"}),f("span",{children:[x.activeStreams," active stream",x.activeStreams!==1?"s":""," · mode: ",x.mode]})]})]}),f("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[f("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r(gr,{children:f("span",{className:"flex items-center gap-1.5",children:[r(bt,{className:"h-3.5 w-3.5"}),"Settings"]})}),l.isLoading?f("div",{className:"px-4 py-3 space-y-2",children:[r(ut,{className:"h-3 w-32"}),r(ut,{className:"h-3 w-40"}),r(ut,{className:"h-3 w-28"})]}):f("div",{className:"divide-y divide-border",children:[r(br,{label:"Stream",value:c}),r(br,{label:"Pre-buffer",value:y?`${y.preBufferSec}s`:"N/A"}),r(br,{label:"Mode",value:y?.mode??"continuous"}),r(br,{label:"Retention",value:N?.retentionDays!=null?`${N.retentionDays} days`:"N/A"}),N?.retentionGb!=null&&r(br,{label:"Max Storage",value:`${N.retentionGb} GB`})]})]}),f("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r(gr,{children:f("span",{className:"flex items-center gap-1.5",children:[r(vi,{className:"h-3.5 w-3.5"}),"Storage"]})}),p.isLoading?f("div",{className:"px-4 py-3 space-y-2",children:[r(ut,{className:"h-3 w-28"}),r(ut,{className:"h-3 w-36"}),r(ut,{className:"h-3 w-24"})]}):p.error?f("div",{className:"px-4 py-4 flex items-center gap-2 text-xs text-danger",children:[r(Bt,{className:"h-4 w-4"}),"Failed to load storage info"]}):f("div",{className:"px-4 py-3 grid grid-cols-2 gap-3",children:[r(xu,{icon:vi,label:"Total",value:v?.totalBytes!=null?Ai(v.totalBytes):"N/A"}),r(xu,{icon:Ir,label:"Segments",value:v?.segmentCount!=null?String(v.segmentCount):"N/A"})]})]})]}),f("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[f("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"}),f("div",{className:"flex items-center gap-2",children:[r("button",{onClick:O,className:"p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle hover:text-foreground transition-colors",children:r(lc,{className:"h-4 w-4"})}),f("div",{className:"flex items-center gap-1.5 text-xs text-foreground font-medium",children:[r(Yg,{className:"h-3.5 w-3.5 text-foreground-subtle"}),M?"Today":ls(n)]}),r("button",{onClick:$,disabled:M,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($t,{className:"h-4 w-4"})})]})]}),f("div",{className:"px-4 py-3 border-b border-border",children:[r(uT,{segments:w,selectedDate:n}),f("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-foreground-subtle",children:[f("span",{children:[w.length," segment",w.length!==1?"s":""]}),E>0&&f("span",{children:[gc(E)," recorded"]}),B>0&&r("span",{children:Ai(B)})]})]}),D.length>0&&f("div",{className:"border-b border-border px-4 py-2 flex items-center justify-between",children:[r("button",{onClick:_,className:"text-[11px] text-foreground-subtle hover:text-foreground transition-colors",children:s.size===D.length?"Deselect All":"Select All"}),s.size>0&&f("div",{className:"flex items-center gap-2",children:[f("span",{className:"text-[10px] text-foreground-subtle",children:[s.size," selected"]}),f("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(vn,{className:"h-3 w-3"}),"Download"]}),f("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(nt,{className:"h-3 w-3"}),"Delete"]})]})]}),d.isLoading?f("div",{className:"divide-y divide-border",children:[r(fn,{}),r(fn,{}),r(fn,{}),r(fn,{})]}):D.length===0?f("div",{className:"flex flex-col items-center justify-center py-12 text-foreground-subtle",children:[r(Ir,{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:M?"Recorded clips will appear here as they are created":`No recordings found for ${ls(n)}`})]}):r("div",{className:"max-h-[400px] overflow-y-auto",children:D.map(P=>r(fT,{segment:P,selected:s.has(P.id),onToggle:()=>I(P.id),onPlay:()=>{},onDownload:()=>{},onDelete:()=>{}},P.id))})]}),i.error&&f("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(Bt,{className:"h-4 w-4 flex-shrink-0"}),"Failed to load recording status. Will retry automatically."]}),(g.error||b.error)&&f("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(Bt,{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: ${b.error instanceof Error?b.error.message:"Unknown error"}`]})]})}function br({label:e,value:t}){return f("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 hT({deviceId:e}){const t=ke(),n=Number.isFinite(e),{data:o}=yn({deviceId:e},{enabled:n}),s=typeof o?.type=="string"?o.type:"camera";at(["deviceManager","getBindings"],["capability.binding-changed"]);const{data:a,isLoading:i,isError:l,error:c}=Qh({deviceId:e},{staleTime:3e4,enabled:n}),{data:d}=Wh({deviceType:s},{staleTime:3e4,enabled:!!s}),p=Gh({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 f("div",{className:"p-4 text-xs text-red-400",children:["Failed to load bindings: ",c instanceof Error?c.message:String(c)]});const u=new Map,h={};for(const b of d??[])h[b.capName]=b.wrappers;for(const b of a?.entries??[])u.set(b.capName,{...b,wrappers:h[b.capName]??[]});for(const b of d??[])u.has(b.capName)||u.set(b.capName,{capName:b.capName,kind:"unbound",providerAddonId:"",providerNodeId:"",nativeAddonId:"",wrappers:b.wrappers});const m=[...u.values()].sort((b,x)=>b.capName.localeCompare(x.capName));if(m.length===0)return f("div",{className:"flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle",children:[r(NP,{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=m.filter(b=>b.kind!=="unbound").length;return f("div",{className:"flex flex-col gap-3 p-1",children:[f("div",{className:"text-[11px] text-foreground-subtle",children:[r("span",{className:"font-medium text-foreground",children:g})," ","of ",m.length," capabilit",m.length===1?"y":"ies"," bound — rows marked ",r("em",{children:"unbound"})," have a wrapper available you can activate."]}),r("div",{className:"overflow-hidden rounded-lg border border-border bg-surface",children:f("table",{className:"w-full border-collapse text-[11px]",children:[r("thead",{children:f("tr",{className:"bg-surface-hover/50 text-left text-[10px] uppercase tracking-wide text-foreground-subtle",children:[r("th",{className:"px-3 py-2 font-medium",children:"Capability"}),r("th",{className:"px-3 py-2 font-medium",children:"Kind"}),r("th",{className:"px-3 py-2 font-medium",children:"Active Provider"}),r("th",{className:"px-3 py-2 font-medium",children:"Node"}),r("th",{className:"px-3 py-2 font-medium",children:"Native"}),r("th",{className:"px-3 py-2 font-medium",children:"Wrapper"})]})}),r("tbody",{children:m.map(b=>{const x=b.kind==="wrapped"?b.providerAddonId:null;return f("tr",{className:"border-t border-border align-middle",children:[r("td",{className:"px-3 py-2 font-mono text-foreground",children:b.capName}),r("td",{className:"px-3 py-2",children:r(mT,{kind:b.kind})}),r("td",{className:"px-3 py-2 font-mono text-foreground-subtle",children:b.providerAddonId||r("span",{className:"opacity-40",children:"—"})}),r("td",{className:"px-3 py-2",children:b.providerNodeId?r(gT,{nodeId:b.providerNodeId}):r("span",{className:"text-[10px] opacity-40",children:"—"})}),r("td",{className:"px-3 py-2 font-mono text-foreground-subtle",children:b.nativeAddonId||r("span",{className:"opacity-40",children:"—"})}),r("td",{className:"px-3 py-2",children:r(bT,{wrappers:b.wrappers,activeWrapperId:x,disabled:p.isPending,onPick:y=>{const w=x===y;p.mutate({deviceId:e,capName:b.capName,wrapperAddonId:y,active:!w})}})})]},b.capName)})})]})})]})}function mT({kind:e}){return e==="native"?f("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(ro,{className:"h-3 w-3"}),"native"]}):e==="wrapped"?f("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(m4,{className:"h-3 w-3"}),"wrapped"]}):f("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(P4,{className:"h-3 w-3"}),"unbound"]})}function gT({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 bT({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 f("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(At,{className:"h-3 w-3"}):r(K4,{className:"h-3 w-3"}),s]},s)})})}function xT(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 yT(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 vT({agents:e,currentAgent:t,onPick:n}){const[o,s]=L(!1);return f("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 wT({deviceId:e,refreshToken:t}){const n=ke(),[o,s]=L(null),[a,i]=L(null),[l,c]=L(null),[d,p]=L(null),u=Fl({deviceId:e}),h=ir(),m=Ds({deviceId:e}),g=Im(),b=Q(()=>{const _=m.data?.agentNodeId;if(_)return _;const P=g.data?.find(T=>T.online)?.nodeId;return P||"hub"},[m.data?.agentNodeId,g.data]),x=a??b,y=Jr({nodeId:x??""},{enabled:!!x}),w=zm({onSuccess:()=>{n.invalidateQueries({queryKey:[["pipelineOrchestrator","getCameraSettings"]]}),c(null)}}),v=Q(()=>y.data?Cs(y.data):[],[y.data]),N=Q(()=>{const _=u.data??null,P={};for(const T of h.data??[])for(const R of Object.keys(T.settings.addonDefaults)){const z=P[R]??[];z.push({agentNodeId:T.nodeId,state:yT(_,T.nodeId,R)}),P[R]=z}return P},[u.data,h.data]),S=o?xT(y.data??null,o):null,k=x?h.data?.find(_=>_.nodeId===x)??null:null,M=o&&k?k.settings.addonDefaults[o]??null:null,D=o&&x?u.data?.stepOverridesByAgent?.[x]?.[o]??null:null,E=y.data?.selectedEngine.format??"coreml",B=_=>{i(_),c(null),p(null)},A=_=>{s(_),c(null),p(null)},O=_=>{if(!x||!o||!y.data||!h.data)return;const P=h.data.find(z=>z.nodeId===_),T=h.data.find(z=>z.nodeId===x);if(!P||!T)return;const[R]=xp({source:{nodeId:P.nodeId,engine:{format:E},defaults:P.settings.addonDefaults},target:{nodeId:T.nodeId,engine:{format:E},defaults:T.settings.addonDefaults},catalog:y.data,addonIds:[o]});if(!R){p("no mirror result");return}if(R.outcome==="skip"){p(`skipped: ${R.reason??"no candidate"}`);return}c(R.patch),p(`${R.outcome} from ${_}`)},$=()=>{!x||!o||w.mutate({deviceId:e,agentNodeId:x,addonId:o,patch:l})},I=()=>{!x||!o||w.mutate({deviceId:e,agentNodeId:x,addonId:o,patch:null})};return h.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:f("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(jp,{tree:v,selectedAddonId:o,onSelect:A,agentDots:N})}),r("section",{className:"flex-1 min-w-0 p-4 overflow-y-auto",children:!o||!S?r("div",{className:"text-sm text-foreground-subtle",children:"Select a step on the left to configure it for this camera."}):f("div",{className:"space-y-4",children:[f("div",{children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Selected step"}),r("div",{className:"text-base font-semibold",children:S.name})]}),f("div",{className:"flex items-end gap-3 flex-wrap",children:[f("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:(h.data??[]).map(_=>r("button",{type:"button",onClick:()=>B(_.nodeId),className:`px-3 py-1 text-xs ${x===_.nodeId?"bg-primary text-primary-foreground":"bg-surface hover:bg-muted"}`,children:_.nodeId},_.nodeId))})]}),r(vT,{agents:(h.data??[]).map(_=>_.nodeId),currentAgent:x,onPick:O}),d&&r("div",{className:"text-[10px] text-foreground-subtle",children:d})]}),M&&r(Is,{mode:"device",addon:S,agentDefault:M,agentNodeId:x??"",currentPatch:l??D,engineFormat:E,onChangePatch:c}),f("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:!D||w.isPending,onClick:I,children:"Clear override"}),f("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:!x||!o||w.isPending,onClick:$,children:w.isPending?"Saving…":"Save"})]})]})]})})]})}):r("div",{className:"text-xs text-foreground-subtle p-4",children:"Catalog unavailable."})}const NT=[{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 ST(e){const t=e===Ye.Camera;return NT.filter(n=>t||!n.cameraOnly).map(({id:n,label:o})=>({id:n,label:o}))}const kT=[{id:"logs",icon:st,label:"Logs"},{id:"repl",icon:ub,label:"REPL"},{id:"events",icon:Bs,label:"Events"},{id:"state",icon:UP,label:"State"},{id:"ptz",icon:T4,label:"PTZ",featureGate:mn.PanTiltZoom}];function CT(){const e=tc(),t=Number(e.deviceId),n=Number.isFinite(t),o=Ge(),s=ke(),a=on(),i=Ae(),[l,c]=L("overview"),[d,p]=L("logs"),u="device-detail.left-col-width-px",[h,m]=L(()=>{if(typeof window>"u")return null;const ie=window.localStorage.getItem(u),ae=ie?Number(ie):NaN;return Number.isFinite(ae)&&ae>0?ae:null}),g=ee(h);g.current=h;function b(ie){ie.preventDefault();const ae=ie.clientX,ve=ie.currentTarget.previousElementSibling?.getBoundingClientRect().width??h??0,ue=280,Ne=Math.max(ue+50,Math.floor(window.innerWidth*.7)),Ee=We=>{const Tn=Math.max(ue,Math.min(Ne,ve+(We.clientX-ae)));m(Tn)},He=()=>{document.removeEventListener("mousemove",Ee),document.removeEventListener("mouseup",He);const We=g.current;if(We!==null)try{window.localStorage.setItem(u,String(Math.round(We)))}catch{}document.body.style.userSelect="",document.body.style.cursor=""};document.body.style.userSelect="none",document.body.style.cursor="col-resize",document.addEventListener("mousemove",Ee),document.addEventListener("mouseup",He)}const{data:x,isLoading:y,isError:w}=yn({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:v}=_l({deviceId:t},{enabled:n,staleTime:3e4}),N=Q(()=>{const ie=v?.settings?.sections??[],ae=v?.live?.sections??[],ve=[...ie,...ae],ue=new Set;for(const Ne of ve)Ne.location==="top-tab"&&Ne.tab&&ue.add(Ne.tab);return[...ue].map(Ne=>{const Ee=ti[Ne];return{id:Ne,label:Ee?.label??Ne,isAddonContrib:!0}})},[v]),S=x,k=String(S?.name??e.deviceId??"Device"),M=S?.online===!0,D=M?"online":"offline",E=String(S?.addonId??"rtsp"),B=S?.features??[],A=S?.type,O=A===Ye.Camera,$=typeof S?.parentDeviceId=="number"?S.parentDeviceId:null,{data:I}=yn({deviceId:$??0},{enabled:$!==null,staleTime:3e4}),_=rn(),P=Q(()=>[...ST(A),...N],[A,N]),{data:T}=_b(n?t:0),R=(T??[]).length>0,z=Q(()=>kT.filter(({featureGate:ie})=>!ie||B.includes(ie)),[B]),{data:H}=em({addonId:E},{enabled:!!E&&E!=="rtsp"}),F=Uh({onSuccess:()=>{s.invalidateQueries({queryKey:[["deviceManager"]]}),o(H?.id?`/integrations/${H.id}`:"/integrations")}}),j=Vh({onSuccess:()=>{s.invalidateQueries({queryKey:[["deviceManager"]]})}}),J=qh({onSuccess:()=>{s.invalidateQueries({queryKey:[["deviceManager"]]})}}),W=Km(),ne=Ps({onSuccess:()=>{s.invalidateQueries({queryKey:[["deviceManager"]]})}}),de=B.includes(mn.Rebootable),te=B.includes(mn.BatteryOperated),K=Nl(i.trpcClient,te&&n?t:null),[oe,me]=L(!1),Y=lt(i.trpcClient,n?t:null),G=async()=>{if(!(oe||!Y)){me(!0);try{await Y.snapshot?.invalidateCache({});const ie=await Y.snapshot?.getSnapshot({});if(!ie)return;const ae=`data:${ie.contentType};base64,${ie.base64}`,ve=ie.contentType.includes("png")?"png":"jpg",ue=k.replace(/[^a-zA-Z0-9_.-]+/g,"_"),Ne=new Date().toISOString().replace(/[:.]/g,"-"),Ee=document.createElement("a");Ee.href=ae,Ee.download=`${ue}-${Ne}.${ve}`,document.body.appendChild(Ee),Ee.click(),document.body.removeChild(Ee)}finally{me(!1)}}},Z=j.isPending||J.isPending,{data:re}=Ds({deviceId:t},{enabled:n,refetchInterval:1e4}),pe=re?.agentNodeId??null,V=typeof pe=="string"&&pe.length>0&&!pe.startsWith("addon:")?pe:void 0,{data:se}=Hl({deviceId:t,...V?{nodeId:V}:{}},{enabled:n,refetchInterval:3e3,retry:!1});function ce(){if(!n)return null;switch(l){case"overview":return r(q_,{device:S??{}});case"config":return r(X_,{deviceId:t});case"pipeline":return r(wT,{deviceId:t,refreshToken:0});case"bindings":return r(hT,{deviceId:t});case"recording":return r(pT,{deviceId:t});default:{const ie=l;return N.some(ve=>ve.id===ie)?r(qb,{deviceId:t,sectionFilter:ve=>ve.location==="top-tab"&&ve.tab===ie}):null}}}return n?y?f("div",{className:"flex flex-col h-full",children:[f("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||!x?f("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"}),f("p",{className:"text-xs",children:["No device with ID ",f("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"})]}):f("div",{className:"absolute inset-0 flex flex-col overflow-hidden",children:[f("div",{className:"border-b border-border bg-surface px-6 py-3 flex-shrink-0",children:[r("div",{className:"mb-2",children:r(bl,{items:[{label:"Integrations",onClick:()=>o("/integrations")},{label:H?.name??E,onClick:()=>H?.id&&o(`/integrations/${H.id}`)},{label:k}]})}),f("div",{className:"flex items-center gap-2 sm:gap-3",children:[r(Vt,{type:E,size:"lg"}),f("div",{className:"min-w-0 flex-1",children:[f("div",{className:"flex items-center gap-2 flex-wrap",children:[r("h1",{className:"text-sm sm:text-base font-semibold text-foreground truncate",children:k}),r(qs,{status:D}),te&&r(kl,{status:K,variant:"full"})]}),$!==null&&I&&f("button",{type:"button",onClick:()=>o(`/devices/${$}`),className:"text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1",title:`Open parent device ${I.name}`,children:[r("span",{children:"↑"}),r("span",{className:"truncate",children:String(I.name??`Device #${$}`)})]}),r("div",{className:"hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle",children:B.length>0&&r(js,{capabilities:B})})]}),se&&r("div",{className:"hidden lg:flex",children:r(MT,{metrics:se})}),f("div",{className:"flex items-center gap-1 shrink-0",children:[f("button",{onClick:async()=>{await a({title:`Disable "${k}"?`,message:"The device will stop processing streams and events. You can re-enable it later.",confirmLabel:"Disable",variant:"danger"})&&J.mutate({deviceId:t})},disabled:Z,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(lb,{className:"h-3.5 w-3.5"}),r("span",{className:"hidden sm:inline",children:Z?"Updating…":"Enabled"})]}),r("div",{className:"hidden sm:block h-5 w-px bg-border mx-1"}),r(Cg,{triggerClassName:"ml-1",items:[{id:"snapshot",label:"Take snapshot",description:"Fetch a fresh frame and download it.",icon:Br,disabled:oe,onClick:()=>{G()}},{id:"reboot",label:"Reboot device",description:"Camera goes offline for ~30 seconds.",icon:wn,hidden:!de,disabled:W.isPending,danger:!0,onClick:async()=>{await a({title:`Reboot "${k}"?`,message:"The camera will go offline for around 30 seconds while the firmware reboots.",confirmLabel:"Reboot",variant:"danger"})&&W.mutate({deviceId:t})}},{id:"restart-addon",label:"Restart addon",description:`Bounces every device served by ${H?.name??E}.`,icon:Et,disabled:ne.isPending,danger:!0,onClick:async()=>{await a({title:`Restart "${H?.name??E}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${k}"). Streams will reconnect automatically.`,confirmLabel:"Restart",variant:"danger"})&&ne.mutate({addonId:E})}},{id:"delete",label:"Delete device",description:"Remove the device and all its settings.",icon:nt,separatorBefore:!0,disabled:F.isPending,danger:!0,onClick:async()=>{await a({title:`Delete "${k}"?`,message:"This will remove the device and all its settings. This action cannot be undone.",confirmLabel:"Delete",variant:"danger"})&&F.mutate({deviceId:t})}}]})]})]})]}),r(bh,{deviceId:t,device:S??void 0,children:r(xg,{children:r(Ig,{children:f("main",{className:_?"flex-1 overflow-y-auto flex flex-col":"flex-1 min-h-0 overflow-hidden flex flex-row",children:[f("div",{className:_?"flex flex-col bg-surface":`${h===null?"w-1/2 lg:w-1/3":""} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!_&&h!==null?{width:`${String(h)}px`}:void 0,children:[r("div",{className:`flex-shrink-0 border-b border-border-subtle ${O?"aspect-video bg-black":"bg-surface"}`,children:O?r(O_,{deviceId:t,intercomAvailable:B.includes(mn.TwoWayAudio)}):r(lT,{deviceId:t,deviceName:k,deviceType:A??"unknown",provider:E,isOnline:M,features:B})}),f("div",{className:_?"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:z.map(({id:ie,label:ae,icon:ve})=>f("button",{onClick:()=>p(ie),title:ae,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${d===ie?"bg-primary/15 text-primary":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,children:[r(ve,{className:"h-3 w-3"}),ae]},ie))})}),f("div",{className:_?"h-72 overflow-hidden":"flex-1 min-h-0 overflow-hidden",children:[d==="logs"&&r(B_,{deviceId:t}),d==="repl"&&r(z_,{deviceId:t}),d==="events"&&r(H_,{deviceId:t}),d==="state"&&r(j_,{deviceId:t}),d==="ptz"&&r(F_,{deviceId:t})]})]})]}),!_&&r("div",{role:"separator","aria-orientation":"vertical",title:"Drag to resize",onMouseDown:b,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"})}),f("div",{className:_?"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:P.map(ie=>{const ae=l===ie.id;return f("button",{onClick:()=>c(ie.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${ae?"text-primary":"text-foreground-subtle hover:text-foreground"}`,children:[ie.label,ae&&r("span",{className:"absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary"})]},ie.id)})})}),f("div",{className:_?"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"&&R&&r(V_,{parentDeviceId:t}),ce()]})]})]})})})})]}):f("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"}),f("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 MT({metrics:e}){const t=e.phase??"idle",n=An(t);return f("div",{className:"flex items-center gap-3 flex-shrink-0",children:[f("div",{className:"flex items-center gap-1.5",children:[r("span",{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),r("span",{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),r("div",{className:"h-3 w-px bg-border"}),f("div",{className:"flex items-center gap-1 text-[10px] text-foreground-subtle",children:[r(no,{className:"h-3 w-3"}),r("span",{className:"text-foreground tabular-nums",children:(e.actualFps??0).toFixed(1)}),r("span",{children:"fps"})]}),f("div",{className:"flex items-center gap-1 text-[10px] text-foreground-subtle",children:[r(tt,{className:"h-3 w-3"}),r("span",{className:"text-foreground tabular-nums",children:(e.avgInferenceTimeMs??0).toFixed(0)}),r("span",{children:"ms"})]}),(e.queueDepth??0)>0&&f("span",{className:"text-[10px] text-warning tabular-nums",children:["q:",e.queueDepth]})]})}function IT({packageName:e,currentVersion:t,onInstall:n,onClose:o}){const{data:s,isLoading:a}=Nh({name:e},{staleTime:3e5});return f("div",{className:"fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden",style:{top:"auto",bottom:"auto"},ref:i=>{if(!i)return;const l=i.parentElement?.getBoundingClientRect();if(!l)return;const c=window.innerHeight-l.bottom,d=l.top;c<280&&d>c?(i.style.bottom=`${window.innerHeight-l.top+4}px`,i.style.top="auto"):(i.style.top=`${l.bottom+4}px`,i.style.bottom="auto"),i.style.right=`${window.innerWidth-l.right}px`},onClick:i=>i.stopPropagation(),children:[f("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:o,className:"text-foreground-subtle hover:text-foreground",children:r(qe,{className:"h-3 w-3"})})]}),a&&f("div",{className:"flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle",children:[r(Le,{className:"h-3.5 w-3.5 animate-spin"}),"Loading versions..."]}),s&&r("div",{className:"max-h-64 overflow-auto divide-y divide-border",children:s.map(i=>{const l=i.version===t,c=/-(alpha|beta|rc|dev|canary|next)/i.test(i.version);return f("div",{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${l?"bg-primary/5":"hover:bg-surface-hover"} transition-colors`,children:[r("span",{className:`font-mono flex-1 ${l?"text-primary font-semibold":c?"text-amber-400":"text-foreground"}`,children:i.version}),i.distTags.map(d=>r("span",{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${d==="latest"?"bg-emerald-500/15 text-emerald-400":d==="beta"?"bg-amber-500/15 text-amber-400":"bg-gray-500/15 text-gray-400"}`,children:d},d)),i.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(i.publishedAt).toLocaleDateString()}),l?r(At,{className:"h-3 w-3 text-primary shrink-0"}):r("button",{type:"button",onClick:()=>n(i.version),className:"shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors",title:`Install ${i.version}`,children:r(vn,{className:"h-3 w-3"})})]},i.version)})}),s&&s.length===0&&r("div",{className:"py-4 text-center text-[10px] text-foreground-subtle",children:"No versions found"})]})}function ET({isBundle:e,installSource:t}){return f("div",{className:"relative flex-shrink-0",children:[r("div",{className:`h-9 w-9 rounded-lg flex items-center justify-center ${e?"bg-indigo-500/20 text-indigo-300":"bg-purple-500/20 text-purple-300"}`,children:e?r(ob,{className:"h-4 w-4"}):r(ns,{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(hc,{className:"h-2.5 w-2.5 text-white"})})]})}function PT({addonId:e}){const t=ke(),{data:n="inherit"}=kh({addonId:e},{staleTime:3e4}),o=Ch({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-300":s==="off"?"bg-gray-700 text-gray-200":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 $i({addon:e,agents:t=[],clusterStatus:n,hideVersion:o,availableUpdate:s,onUpdate:a,isUpdating:i,bundle:l}){const[c,d]=L(!1),[p,u]=L(!1),[h,m]=L(!1),[g,b]=L(!1),[x,y]=L(!1),[w,v]=L("logs"),N=ke(),S=on(),{manifest:k}=e,M=e.installedOn??[],D=!l&&!k.protected&&k.removable!==!1,E=!!l,B=l?.displayName??k.name,A=l?.packageName??k.packageName,O=l?.version??k.packageVersion??k.version,$=l?.installSource??e.installSource,I=l?l.addons[0]?.manifest.description:k.description;!l&&(k.components&&k.components.length>0||t.length>=2);const _=xh({onSuccess:()=>{N.invalidateQueries({queryKey:[["addons"]]}),N.invalidateQueries({queryKey:[["addonPages"]]}),N.invalidateQueries({queryKey:[["capabilities"]]})}}),P=Ps({onSuccess:()=>{N.invalidateQueries({queryKey:[["addons"]]})}}),T=Al({onSuccess:()=>{N.invalidateQueries({queryKey:[["addons"]]}),N.invalidateQueries({queryKey:[["addonPages"]]}),N.invalidateQueries({queryKey:[["capabilities"]]}),N.invalidateQueries({queryKey:[["integrations"]]})}});return f("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[f("div",{className:"flex items-start gap-3 px-4 py-3",children:[r(ET,{isBundle:E||!!k.components&&k.components.length>1,installSource:$}),f("div",{className:"flex-1 min-w-0",children:[f("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-sm font-semibold text-foreground truncate",children:B}),f("span",{className:"text-[10px] text-foreground-subtle font-mono shrink-0",children:["(",A,")"]}),E&&f("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(ob,{className:"h-3 w-3"}),l.addons.length]})]}),I&&r("p",{className:"text-[10px] text-foreground-subtle mt-0.5 line-clamp-1",children:I}),!E&&e.process&&f("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&&f("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"?"bg-red-500/15 text-red-400":"bg-gray-500/15 text-gray-400"}`,children:e.process.state})]})]}),!o&&f("div",{className:"relative inline-flex items-center shrink-0 pt-0.5",children:[f("button",{type:"button",onClick:R=>{R.stopPropagation(),m(z=>!z)},className:["inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors",$==="local"?"border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20":s?"border-border text-foreground-subtle hover:text-foreground hover:border-primary/30":"border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20"].join(" "),title:"View all versions",children:[O,r(It,{className:"h-3 w-3 opacity-50"})]}),h&&r(IT,{packageName:A,currentVersion:O,onInstall:R=>{m(!1),T.mutate({packageName:A,version:R})},onClose:()=>m(!1)})]})]}),!E&&!o&&f("div",{className:"flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20",children:[f("button",{type:"button",onClick:R=>{R.stopPropagation(),P.mutate({addonId:k.id})},disabled:P.isPending,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(Et,{className:`h-3 w-3 ${P.isPending?"animate-spin":""}`}),"Restart"]}),f("button",{type:"button",onClick:R=>{R.stopPropagation(),b(z=>!z)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${g?"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(st,{className:"h-3 w-3"}),"Logs"]}),i?f("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(Le,{className:"h-3 w-3 animate-spin"}),"Updating..."]}):s&&a?f("button",{type:"button",onClick:R=>{R.stopPropagation(),a()},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 hover:bg-blue-500/20 transition-colors",children:[r(vn,{className:"h-3 w-3"}),"Update to ",s]}):null,!E&&f("button",{type:"button",onClick:R=>{R.stopPropagation(),y(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${x?"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(bt,{className:"h-3 w-3"}),"Settings"]}),r("div",{className:"flex-1"}),D&&f("button",{type:"button",onClick:async R=>{R.stopPropagation(),await S({title:`Uninstall ${k.name}?`,message:"This will remove the addon package and all its data. This action cannot be undone.",confirmLabel:"Uninstall",variant:"danger"})&&_.mutate({packageName:k.packageName})},disabled:_.isPending,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(nt,{className:"h-3 w-3"}),_.isPending?"Removing...":"Uninstall"]})]}),n&&n.nodes.length>1&&!E&&f("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(R=>f("div",{className:"flex items-center gap-2 text-[10px]",children:[r("div",{className:`h-1.5 w-1.5 rounded-full shrink-0 ${R.status==="offline"?"bg-muted-foreground/30":R.synced?"bg-success":"bg-amber-500"}`}),r("span",{className:"font-medium text-foreground min-w-[60px]",children:R.name}),r("span",{className:"font-mono text-foreground-subtle",children:R.version}),!R.synced&&R.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"}),R.status==="offline"&&r("span",{className:"text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground",children:"offline"}),R.synced&&R.status!=="offline"&&r("span",{className:"text-[9px] text-success",children:"synced"})]},R.nodeId))})]}),g&&!E&&f("div",{className:"border-t border-border",children:[f("div",{className:"flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50",children:[f("div",{className:"flex rounded border border-border overflow-hidden text-[9px]",children:[r("button",{type:"button",onClick:()=>v("logs"),className:`px-2 py-0.5 transition-colors ${w==="logs"?"bg-primary/10 text-primary":"text-foreground-subtle hover:bg-surface-hover"}`,children:"Logs"}),r("button",{type:"button",onClick:()=>v("events"),className:`px-2 py-0.5 border-l border-border transition-colors ${w==="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:R=>{R.stopPropagation(),b(!1)},className:"text-foreground-subtle hover:text-foreground",children:r(qe,{className:"h-3.5 w-3.5"})})]}),w==="logs"&&r(Wt,{addonId:k.id,maxHeight:"max-h-64",showFilters:!1}),w==="events"&&r(cr,{addonId:k.id,category:"addon.*",maxHeight:"max-h-64"})]}),E&&f(ye,{children:[r("button",{type:"button",onClick:()=>d(R=>!R),className:"w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors",children:c?r(_P,{className:"h-3.5 w-3.5 text-foreground-subtle"}):r(It,{className:"h-3.5 w-3.5 text-foreground-subtle"})}),c&&r("div",{className:"border-t border-border px-3 py-2 space-y-2",children:l.addons.map(R=>r($i,{addon:R,agents:t,hideVersion:!0},R.manifest.id))})]}),x&&!E&&r("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",onClick:()=>y(!1),children:f("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:R=>R.stopPropagation(),children:[f("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0",children:[f("div",{className:"flex items-center gap-2",children:[r(bt,{className:"h-4 w-4 text-primary"}),f("h2",{className:"text-sm font-semibold text-foreground",children:[B," Settings"]})]}),r("button",{onClick:()=>y(!1),className:"text-foreground-subtle hover:text-foreground transition-colors p-1 rounded",children:r(qe,{className:"h-4 w-4"})})]}),f("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-4",children:[r(so,{nodeId:"hub",addonIds:[k.id],level:"global"}),$==="npm"&&f("div",{children:[r("div",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:"Auto-Update"}),r(PT,{addonId:k.id})]}),k.components&&k.components.length>0&&f("div",{children:[f("div",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:["Components (",k.components.length,")"]}),r("div",{className:"flex flex-wrap gap-1",children:k.components.map(R=>r("span",{className:"text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono",children:R},R))})]}),t.length>=2&&f("div",{children:[r("div",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:"Installed on"}),f("div",{className:"flex items-center gap-1.5 flex-wrap",children:[M.length===0&&r("span",{className:"text-[10px] text-foreground-subtle",children:"Hub (local)"}),M.map(R=>r("span",{className:"rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle",children:R},R)),f("div",{className:"relative",children:[f("button",{type:"button",onClick:R=>{R.stopPropagation(),u(z=>!z)},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(_n,{className:"h-3 w-3"}),"Add agent"]}),p&&f("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(R=>!R.isHub&&!M.includes(R.name)).map(R=>r("button",{type:"button",onClick:z=>{z.stopPropagation(),u(!1)},className:"w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors",children:R.name},R.id)),t.filter(R=>!R.isHub&&!M.includes(R.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:()=>y(!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"})})]})})]})}const AT=".tgz,.tar.gz,.zip";function $T({onUploadSuccess:e}){const[t,n]=L(!1),o=ee(null),s=q(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=q(i=>{const l=i.target.files?.[0];l&&s(l),i.target.value=""},[s]);return f(ye,{children:[r("input",{ref:o,type:"file",accept:AT,onChange:a,className:"hidden"}),f("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(Le,{className:"w-3.5 h-3.5 animate-spin"}):r(hc,{className:"w-3.5 h-3.5"}),t?"Uploading...":"Upload"]})]})}function DT(e,t){const n=e??"hub-only";return n==="any-node"?!0:n==="hub-only"?t:!t}function _T(e){const t=e;return t?.manifest?{manifest:{...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??"0.0.0",capabilities:t.manifest.capabilities??[]},enabled:!0,source:t.source,installSource:t.installSource,installedOn:[]}:null}function TT(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);i?i.addons.push(s):t.set(a,{packageName:a,displayName:s.manifest.packageDisplayName??s.manifest.name,version:s.manifest.packageVersion,installSource:s.installSource,addons:[s]})}const o=[];for(const s of t.values())s.addons.length>=2?o.push({bundle:s,representative:s.addons[0]}):o.push(s.addons[0]);return o.push(...n),o}function _t(e){return"bundle"in e}function RT({addons:e,clusterStatus:t,selectedNode:n,onRefresh:o,isRefreshing:s}){const a=ke(),[i,l]=L(""),c=Oy(i),[d,p]=L(!1),u=ee(null);X(()=>{if(!d)return;const $=I=>{u.current&&!u.current.contains(I.target)&&p(!1)};return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[d]);const{data:h}=$l(void 0,{staleTime:5*6e4}),m=Q(()=>{const $=new Map;for(const I of h??[])$.set(I.name,I.latestVersion);return $},[h]),[g,b]=L(null),x=di({onMutate:$=>{b($.name)},onSuccess:()=>{b(null),a.invalidateQueries({queryKey:[["addons"]]})},onError:()=>{b(null)}}),{data:y}=Sh(void 0,{staleTime:3e4}),w=Mh({onSuccess:()=>{a.invalidateQueries({queryKey:[["addons","getAutoUpdateSettings"]]})}}),{data:v,isFetching:N}=vh({query:c||void 0},{enabled:d,staleTime:6e4}),S=di(),k=async()=>{const $=h??[];for(const I of $)await S.mutateAsync({name:I.name,version:I.latestVersion});a.invalidateQueries({queryKey:[["addons"]]})},M=Al({onSuccess:()=>{a.invalidateQueries({queryKey:[["addons"]]}),a.invalidateQueries({queryKey:[["addonPages"]]}),a.invalidateQueries({queryKey:[["capabilities"]]}),a.invalidateQueries({queryKey:[["integrations"]]})}}),[D,E]=L("type"),B=Q(()=>n.isHub?e:e.filter($=>{const I=$.manifest.execution;return DT(I?.placement,n.isHub)}),[e,n.isHub]),A=TT(B),O=Q(()=>{const $=[...A];switch(D){case"type":$.sort((I,_)=>{const P=_t(I)?0:1,T=_t(_)?0:1;if(P!==T)return P-T;const R=_t(I)?I.bundle.displayName:I.manifest.name,z=_t(_)?_.bundle.displayName:_.manifest.name;return R.localeCompare(z)});break;case"name":$.sort((I,_)=>{const P=_t(I)?I.bundle.displayName:I.manifest.name,T=_t(_)?_.bundle.displayName:_.manifest.name;return P.localeCompare(T)});break;case"source":$.sort((I,_)=>{const P=_t(I)?I.bundle.installSource??"":I.installSource??"",T=_t(_)?_.bundle.installSource??"":_.installSource??"";return P.localeCompare(T)});break}return $},[A,D]);return f("div",{className:"space-y-4",children:[f("div",{className:"flex items-center gap-2 flex-wrap",children:[f("div",{className:"flex items-center gap-1.5",children:[r("span",{className:"text-[10px] text-foreground-subtle",children:"Sort:"}),f("select",{value:D,onChange:$=>E($.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"})]})]}),f("div",{className:"flex items-center gap-1.5",children:[r(Et,{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($=>r("button",{type:"button",onClick:()=>w.mutate({channel:$}),disabled:w.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${y?.channel===$?$==="off"?"bg-gray-700 text-gray-200":$==="latest"?"bg-blue-500/20 text-blue-400":"bg-amber-500/20 text-amber-400":"bg-transparent text-foreground-subtle hover:bg-surface-hover"} ${$!=="off"?"border-l border-border":""}`,children:$},$))})]}),(h?.length??0)>0&&f("button",{type:"button",onClick:()=>void k(),disabled:S.isPending,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(vn,{className:`w-3 h-3 ${S.isPending?"animate-bounce":""}`}),"Update All (",h.length,")"]}),f("button",{type:"button",onClick:o,disabled:s,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(Et,{className:`w-3 h-3 ${s?"animate-spin":""}`}),"Refresh"]})]}),f("div",{className:"flex items-center gap-3",children:[f("div",{className:"relative flex-1 min-w-[200px]",ref:u,children:[r(cb,{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:$=>{l($.target.value),p(!0)},onFocus:()=>p(!0),placeholder:"Search addons on npm...",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"}),N&&r(Le,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin"}),d&&v&&v.length>0&&f("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:[v.length>0&&f("div",{className:"px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border",children:["npm results (",v.length,")"]}),v&&v.length>0&&r("div",{className:"max-h-72 overflow-auto divide-y divide-border",children:v.map($=>f("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:$.name.replace("@camstack/addon-","").charAt(0).toUpperCase()}),f("div",{className:"flex-1 min-w-0",children:[f("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-[11px] font-semibold truncate",children:$.name}),f("span",{className:"text-[10px] text-foreground-subtle",children:["v",$.version]})]}),$.description&&r("div",{className:"text-[10px] text-foreground-subtle truncate",children:$.description})]}),$.installed?f("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(At,{className:"h-3 w-3"}),$.installedVersion??"Installed"]}):f("button",{type:"button",onClick:()=>M.mutate({packageName:$.name}),disabled:M.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:[M.isPending?r(Le,{className:"h-3 w-3 animate-spin"}):r(vn,{className:"h-3 w-3"}),"Install"]})]},$.name))})]})]}),r($T,{onUploadSuccess:()=>{a.invalidateQueries({queryKey:[["addons"]]}),o()}})]}),B.length===0&&r("div",{className:"text-xs text-foreground-subtle",children:e.length===0?"No addons installed":`No addons compatible with ${n.name} (placement filter active)`}),r("div",{className:"space-y-2",children:O.map($=>{if(_t($)){const P=$.bundle.packageName,T=m.get(P);return r($i,{addon:$.representative,clusterStatus:t?.[$.representative.manifest.id],bundle:$.bundle,availableUpdate:T,isUpdating:g===P,onUpdate:T?()=>x.mutate({name:P,version:T}):void 0},P)}const I=$.manifest.packageName,_=m.get(I);return r($i,{addon:$,clusterStatus:t?.[$.manifest.id],availableUpdate:_,isUpdating:g===I,onUpdate:_?()=>x.mutate({name:$.manifest.packageName,version:_}):void 0},$.manifest.id)})})]})}function LT(){const e=ke(),{data:t,isLoading:n,isError:o}=Pl(),{data:s}=mm(void 0,{staleTime:15e3}),{data:a}=sn(void 0,{staleTime:3e4,refetchInterval:1e4}),i=Q(()=>{const b=new Map;b.set("hub",{id:"hub",name:"Hub",isHub:!0});for(const x of a??[]){const y=String(x.id??"");y&&b.set(y,{id:y,name:String(x.name??y),isHub:!!x.isHub})}return[...b.values()]},[a]),[l,c]=L("hub"),d=i.find(b=>b.id===l)??i[0],p=wh(),u=yh(),h=p.isPending||u.isPending,m=async()=>{await p.mutateAsync(),await u.mutateAsync(),e.invalidateQueries({queryKey:[["addons"]]})},g=(t??[]).map(_T).filter(b=>b!==null);return f("div",{className:"p-6 space-y-5",children:[f("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[f("div",{children:[r("h1",{className:"text-lg font-semibold text-foreground",children:"Addons"}),r("p",{className:"text-xs text-foreground-subtle mt-0.5",children:"Manage installed addons and explore capability providers."})]}),f("div",{className:"flex items-center gap-3 flex-wrap",children:[r(Qp,{selectedNodeId:l,onSelect:c}),!n&&!o&&f("span",{className:"text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium",children:[g.length," installed"]})]})]}),!d.isHub&&f("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(RT,{addons:g,clusterStatus:s,selectedNode:d,onRefresh:()=>void m(),isRefreshing:h})]})}function OT(){return f("div",{className:"p-6 space-y-4",children:[r("h1",{className:"text-lg font-semibold text-foreground",children:"Logs"}),r("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:r(Wt,{limit:500,maxHeight:"max-h-[calc(100vh-250px)]",showScope:!0,showFilters:!0})})]})}const yu={super_admin:"bg-danger/10 text-danger",admin:"bg-primary/10 text-primary",viewer:"bg-foreground-subtle/10 text-foreground-subtle"};function BT(){const e=ke(),[t,n]=L(!1),[o,s]=L(""),[a,i]=L(""),[l,c]=L("viewer"),[d,p]=L(null),{data:u,isLoading:h,isError:m}=sg(),g=ag({onSuccess:()=>{e.invalidateQueries({queryKey:[["userManagement","listUsers"]]}),n(!1),s(""),i(""),c("viewer"),p(null)},onError:y=>{p(y instanceof Error?y.message:"Failed to create user")}}),b=u??[];function x(y){return y?new Date(typeof y=="number"?y:String(y)).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"}):"—"}return f("div",{className:"p-6 space-y-4",children:[f("div",{className:"flex items-center justify-between",children:[r("h1",{className:"text-lg font-semibold text-foreground",children:"Users"}),f("button",{onClick:()=>n(!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(_n,{className:"h-3.5 w-3.5"}),"Create User"]})]}),t&&f("div",{className:"rounded-lg border border-border bg-surface p-4 space-y-3",children:[f("div",{className:"flex items-center justify-between",children:[r("span",{className:"text-xs font-medium text-foreground",children:"New User"}),r("button",{onClick:()=>n(!1),className:"text-foreground-subtle hover:text-foreground",children:r(qe,{className:"h-4 w-4"})})]}),f("div",{className:"grid grid-cols-3 gap-3",children:[f("div",{className:"space-y-1",children:[r("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Username"}),r("input",{type:"text",value:o,onChange:y=>s(y.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"})]}),f("div",{className:"space-y-1",children:[r("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Password"}),r("input",{type:"password",value:a,onChange:y=>i(y.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"})]}),f("div",{className:"space-y-1",children:[r("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Role"}),f("select",{value:l,onChange:y=>c(y.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:"viewer",children:"Viewer"}),r("option",{value:"admin",children:"Admin"}),r("option",{value:"super_admin",children:"Super Admin"})]})]})]}),d&&r("p",{className:"text-[10px] text-danger",children:d}),f("div",{className:"flex justify-end gap-2",children:[r("button",{onClick:()=>n(!1),className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),r("button",{onClick:()=>g.mutate({username:o,password:a,role:l}),disabled:g.isPending||!o||!a,className:"rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:g.isPending?"Creating...":"Create"})]})]}),h&&r("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading..."}),m&&r("div",{className:"text-xs text-danger",children:"Failed to load"}),!h&&!m&&b.length===0&&r("div",{className:"text-xs text-foreground-subtle",children:"No data"}),b.length>0&&r("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:f("table",{className:"w-full text-xs",children:[r("thead",{children:f("tr",{children:[r("th",{className:"text-left px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border",children:"Username"}),r("th",{className:"text-left px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border",children:"Role"}),r("th",{className:"text-left px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border",children:"Created"})]})}),r("tbody",{children:b.map(y=>{const w=y.role??"viewer",v=yu[w]??yu.viewer;return f("tr",{className:"hover:bg-primary/5",children:[r("td",{className:"px-3 py-2 text-foreground border-b border-border",children:y.username}),r("td",{className:"px-3 py-2 text-foreground border-b border-border",children:r("span",{className:`inline-flex rounded-full px-2 py-0.5 text-[10px] font-medium ${v}`,children:w.replace("_"," ")})}),r("td",{className:"px-3 py-2 text-foreground border-b border-border text-foreground-subtle",children:x(y.createdAt)})]},y.id)})})]})})]})}function zT(){const{data:e,isLoading:t}=sn(void 0,{staleTime:3e4}),n=(e??[]).find(s=>s.isHub&&s.isOnline),o=n?.addons.map(s=>s.id)??[];return f("div",{className:"flex flex-col h-full gap-4 p-4",children:[f("div",{className:"flex items-center gap-3",children:[r(bt,{className:"h-5 w-5 text-muted-foreground"}),r("h1",{className:"text-xl font-semibold",children:"Settings"}),n&&f("span",{className:"text-xs px-2 py-0.5 rounded-full bg-muted text-muted-foreground",children:["hub: ",n.name]})]}),t?r("div",{className:"flex items-center justify-center flex-1 text-muted-foreground text-sm",children:"Loading hub topology…"}):n?o.length===0?r("div",{className:"flex items-center justify-center flex-1 text-muted-foreground text-sm",children:"No addons installed on the hub yet."}):r("div",{className:"w-full",children:r(so,{nodeId:n.id,addonIds:o,level:"global"})}):f("div",{className:"flex flex-col items-center justify-center flex-1 text-muted-foreground text-sm gap-2",children:[r(bt,{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 FT(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 HT({nodeId:e,addons:t,isHub:n}){const o=ke(),s=on(),[a,i]=L(null),[l,c]=L(null),[d,p]=L(!1),[u,h]=L(null),[m,g]=L(0),b=ee(null),x=As(),y=um(),w=()=>{o.invalidateQueries({queryKey:[["nodes","topology"]]})},v=async M=>{i(M);try{await x.mutateAsync({nodeId:e,addonId:M}),w()}catch(D){console.error("Failed to restart addon:",D)}finally{i(null)}},N=async M=>{if(await s({title:"Uninstall addon",message:`Remove "${M}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:"Uninstall",variant:"danger"})){c(M);try{await y.mutateAsync({nodeId:e,addonId:M}),w()}catch(E){console.error("Failed to uninstall addon:",E)}finally{c(null)}}},k=f("div",{className:"flex items-center gap-2 mb-2",children:[r("input",{ref:b,type:"file",accept:".tgz,.tar.gz",className:"hidden",onChange:async M=>{const D=M.target.files?.[0];if(D){M.target.value="",h(null),p(!0),g(0);try{const E=localStorage.getItem("camstack_admin_token");await FT({file:D,nodeId:e,token:E,onProgress:g}),w()}catch(E){h(E instanceof Error?E.message:String(E))}finally{p(!1),g(0)}}}}),f("button",{onClick:()=>b.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(Le,{className:"h-3 w-3 animate-spin"}):r(hc,{className:"h-3 w-3"}),d?`Uploading… ${m}%`:"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:`${m}%`}})}),u&&r("span",{className:"text-[10px] text-destructive",children:u})]});return t.length===0?f("div",{children:[k,r("div",{className:"py-4 text-xs text-muted-foreground text-center",children:"No addons on this node"})]}):f("div",{children:[k,f("table",{className:"w-full text-xs",children:[r("thead",{children:f("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:"Capabilities"}),r("th",{className:"py-2 font-medium",children:"Status"}),r("th",{className:"py-2 font-medium w-16"})]})}),r("tbody",{children:t.map(M=>f("tr",{className:"border-t border-border/50",children:[r("td",{className:"py-2 font-medium",children:M.id}),r("td",{className:"py-2",children:r("div",{className:"flex flex-wrap gap-1",children:M.capabilities.length>0?M.capabilities.map(D=>r("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400",children:D},D)):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 ${M.status==="running"?"bg-success/10 text-success":M.status==="error"?"bg-destructive/10 text-destructive":"bg-muted text-muted-foreground"}`,children:M.status})}),r("td",{className:"py-2",children:f("div",{className:"flex items-center gap-1 justify-end",children:[r("button",{onClick:()=>v(M.id),disabled:a===M.id||l===M.id,className:"p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",title:`Restart ${M.id}`,children:r(wn,{className:`h-3 w-3 ${a===M.id?"animate-spin":""}`})}),r("button",{onClick:()=>N(M.id),disabled:a===M.id||l===M.id,className:"p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50",title:`Uninstall ${M.id}`,children:l===M.id?r(Le,{className:"h-3 w-3 animate-spin"}):r(nt,{className:"h-3 w-3"})})]})})]},M.id))})]})]})}function jT(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 VT(e){return e===0?"0":e<1024*1024?`${Math.round(e/1024)} KB`:e<1024*1024*1024?`${Math.round(e/(1024*1024))} MB`:`${(e/(1024*1024*1024)).toFixed(1)} GB`}function qT({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"?"bg-destructive/10 text-destructive":"bg-muted text-muted-foreground"}`,children:e})}const UT=["trace","debug","info","warn","error"];function QT({proc:e,nodeId:t,defaultExpanded:n,activePanel:o,onTogglePanel:s}){const a=e.services??[],i=a.length===1,[l,c]=L(i||n),[d,p]=L(null),[u,h]=L("info"),m=e.name.includes("(core)"),g=As(),b=fm(),x=gm(),y=async N=>{p(N);try{await g.mutateAsync({nodeId:t,addonId:N})}catch(S){console.error("Failed to restart addon:",S)}finally{p(null)}},w=async()=>{p(e.name);try{await b.mutateAsync({nodeId:t,processName:e.name})}catch(N){console.error("Failed to restart process:",N)}finally{p(null)}},v=async N=>{const S=`${t}/${e.name}`;try{await x.mutateAsync({nodeId:S,level:N}),h(N)}catch(k){console.error("Failed to set log level:",k)}};return f("div",{className:"border border-border/50 rounded-lg overflow-hidden",children:[f("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(It,{className:"h-3 w-3 text-muted-foreground shrink-0"}):r($t,{className:"h-3 w-3 text-muted-foreground shrink-0"}),m?r(ro,{className:"h-3.5 w-3.5 text-primary shrink-0"}):r(zs,{className:"h-3.5 w-3.5 text-amber-500 shrink-0"}),r("span",{className:"text-xs font-semibold flex-1",children:e.name}),f("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:["PID ",e.pid]}),r(qT,{state:e.state}),f("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:[e.cpuPercent,"% CPU"]}),r("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:VT(e.memoryRss)}),r("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:jT(e.uptimeSeconds)}),!m&&f("div",{className:"flex items-center gap-1",onClick:N=>N.stopPropagation(),children:[f(dl,{children:[r(ul,{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:u}),r(fl,{align:"end",className:"min-w-[70px] py-0.5",children:UT.map(N=>r(pl,{onClick:()=>v(N),className:`h-auto px-2 py-1 text-[10px] font-mono ${N===u?"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(wn,{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=>f("div",{children:[f("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&&f("div",{className:"flex gap-1 flex-shrink-0",children:[N.capabilities.slice(0,3).map(S=>r("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]",children:S},S)),N.capabilities.length>3&&f("span",{className:"text-[9px] text-muted-foreground",children:["+",N.capabilities.length-3]})]}),f("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(st,{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(fc,{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(wn,{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(Wt,{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(cr,{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 GT({nodeId:e,processes:t}){const[n,o]=L(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(QT,{proc:a,nodeId:e,defaultExpanded:i===0,activePanel:n,onTogglePanel:s},a.name))})}function WT(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(0)}KB`:`${(e/1024/1024).toFixed(1)}MB`}function KT(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 YT(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function ZT({nodeId:e}){const t=ke(),n=on(),[o,s]=L("all"),a=or("metrics.node-processes-snapshot",S=>S.nodeId===e),{data:i}=cm({nodeId:e},{staleTime:6e4}),l=a?.processes??i,c=Q(()=>l?[...l]:[],[l]),d=Q(()=>o==="ghost"?c.filter(S=>S.classification==="ghost"):c,[c,o]),p=Q(()=>{const S=c.filter(M=>M.classification==="ghost"),k=new Map;for(const M of S)k.has(M.ppid)||k.set(M.ppid,[]),k.get(M.ppid).push(M);return[...k.entries()].filter(([,M])=>M.length>1).map(([M,D])=>({ppid:M,children:D})).sort((M,D)=>D.children.length-M.children.length)},[c]),u=dm({onSettled:()=>{t.invalidateQueries({queryKey:[["metricsProvider","listNodeProcesses"]]})}}),h=Q(()=>{const S=new Map;for(const k of c)S.set(k.pid,k.classification);return S},[c]),m=async(S,k)=>{if(S.classification==="root"||S.classification==="system")return;const M=S.classification==="ghost"?"ghost":S.addonId??"process",D=k?"SIGKILL":"SIGTERM";await n({title:`Send ${D}?`,message:`Target pid ${S.pid} (${M}) on node ${e}.`,confirmLabel:`Send ${D}`,variant:"danger"})&&u.mutate({nodeId:e,pid:S.pid,force:k})},g=async(S,k)=>{try{await u.mutateAsync({nodeId:e,pid:S,force:k})}catch{}},b=async S=>{const k=h.get(S.ppid);if(k==="root"||k==="system"){await n({title:"Cannot kill protected ancestor",message:k==="root"?`pid ${S.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${S.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 + ${S.children.length} child(ren)?`,message:`SIGKILL parent pid ${S.ppid} and SIGTERM ${S.children.length} ghost child(ren) on node ${e}.`,confirmLabel:"Kill all",variant:"danger"})&&(await Promise.all([g(S.ppid,!0),...S.children.map(D=>g(D.pid,!1))]),t.invalidateQueries({queryKey:[["metricsProvider","listNodeProcesses"]]}))},x=async()=>{const S=c.filter(M=>M.classification==="ghost");S.length===0||!await n({title:`Kill all ${S.length} ghost process(es)?`,message:`SIGKILL ${S.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:"Kill all",variant:"danger"})||(await Promise.all(S.map(M=>g(M.pid,!0))),t.invalidateQueries({queryKey:[["metricsProvider","listNodeProcesses"]]}))},y=c.filter(S=>S.classification==="ghost").length,w=c.filter(S=>S.classification==="managed").length,v=c.filter(S=>S.classification==="root").length,N=c.filter(S=>S.classification==="system").length;return f("div",{className:"space-y-4",children:[f("div",{className:"flex items-start justify-between gap-4",children:[f("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."]}),f("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(Et,{className:"h-3 w-3"})," Refresh"]})]}),f("div",{className:"grid grid-cols-4 gap-3",children:[f("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})]}),f("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})]}),f("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})]}),f("div",{className:`rounded-lg border p-3 ${y>0?"border-destructive/40 bg-destructive/5":"border-border"}`,children:[f("div",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1",children:[y>0&&r(wo,{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&&f("div",{className:"rounded-lg border border-amber-500/40 bg-amber-500/5 p-3",children:[f("div",{className:"flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2",children:[r(Bt,{className:"h-3 w-3"})," Recurring ghost parents (",p.length,")"]}),r("div",{className:"space-y-1.5",children:p.map(S=>f("div",{className:"text-[11px] text-foreground flex items-center justify-between gap-2",children:[f("div",{className:"flex items-center gap-2",children:[f("span",{className:"font-mono text-foreground-subtle",children:["ppid ",S.ppid]}),f("span",{children:["→ ",S.children.length," ghost(s)"]})]}),f("button",{type:"button",disabled:u.isPending,onClick:()=>{b(S)},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(wo,{className:"h-3 w-3"})," Kill parent + ",S.children.length]})]},S.ppid))})]}),f("div",{className:"flex items-center justify-between gap-2 text-[11px]",children:[f("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-foreground-subtle",children:"Filter:"}),f("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,")"]}),f("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&&f("button",{type:"button",disabled:u.isPending,onClick:()=>{x()},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(wo,{className:"h-3 w-3"})," Kill all ",y," ghost(s)"]})]}),r("div",{className:"rounded-lg border border-border overflow-hidden",children:f("table",{className:"w-full text-xs",children:[r("thead",{className:"bg-surface",children:f("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"})]})}),f("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(S=>f("tr",{className:`border-t border-border ${S.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 ${S.classification==="ghost"?"bg-destructive/20 text-destructive":S.classification==="root"?"bg-sky-500/20 text-sky-400":S.classification==="system"?"bg-foreground-subtle/20 text-foreground-subtle":"bg-success/20 text-success"}`,children:S.classification})}),r("td",{className:"px-3 py-2 text-right font-mono text-foreground",children:S.pid}),f("td",{className:"px-3 py-2 text-right font-mono text-foreground-subtle",children:[S.ppid,S.orphaned?" ⚠":""]}),r("td",{className:"px-3 py-2 text-foreground-subtle text-[11px]",children:S.addonId??"—"}),r("td",{className:"px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all",children:YT(S.command)}),r("td",{className:"px-3 py-2 text-right text-foreground",children:S.cpuPercent.toFixed(1)}),r("td",{className:"px-3 py-2 text-right text-foreground",children:WT(S.memoryRssBytes)}),r("td",{className:"px-3 py-2 text-right text-foreground-subtle",children:KT(S.uptimeSec)}),r("td",{className:"px-3 py-2 text-right",children:f("div",{className:"inline-flex gap-1",children:[f("button",{type:"button",disabled:u.isPending||S.classification==="root"||S.classification==="system",onClick:()=>{m(S,!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(nt,{className:"h-3 w-3"})," Term"]}),f("button",{type:"button",disabled:u.isPending||S.classification==="root"||S.classification==="system",onClick:()=>{m(S,!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(wo,{className:"h-3 w-3"})," Kill"]})]})})]},S.pid))]})]})}),u.isError&&f("div",{className:"rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive",children:["Kill failed: ",u.error instanceof Error?u.error.message:"unknown"]})]})}function XT({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(so,{nodeId:e,addonIds:t,level:"global"})})}function JT({nodeId:e,addons:t}){const n=ke(),{data:o,isLoading:s}=Em({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=Pm({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"}):f("table",{className:"w-full text-xs",children:[r("thead",{children:f("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]??"",u=c.length===1;return f("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:h=>i.mutate({nodeId:e,capName:l,addonId:h.target.value}),disabled:u||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:u?"Only one provider installed — choice becomes available once a second addon registers this capability":void 0,children:c.map(h=>r("option",{value:h,children:h},h))})})]},l)})})]})}function eR(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 tR(e){const[t,n]=L(!1),[o,s]=L(e.name),a=ke(),i=hm({onSuccess:()=>{a.invalidateQueries({queryKey:[["nodes","topology"]]})}}),l=(e.localIps??[]).filter(u=>!u.includes(":")),c=(e.localIps??[]).filter(u=>u.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(u){console.error("Rename failed:",u)}},p=[["Node ID",r("span",{className:"font-mono text-xs",children:e.nodeId})],["Display Name",t?f("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:u=>s(u.target.value),onKeyDown:u=>{u.key==="Enter"&&d(),u.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(At,{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(qe,{className:"h-3.5 w-3.5"})})]}):f("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(Hs,{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",f("span",{className:"text-xs",children:[e.platform," / ",e.arch]})],["CPU",f("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:eR(e.uptime)})],["Engines",e.engines.length>0?r("div",{className:"flex flex-wrap gap-1",children:e.engines.map(u=>r("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium",children:u},u))}):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((u,h)=>r("span",{className:"font-mono text-xs px-1.5 py-0.5 rounded bg-muted",children:u},`${u}-${h}`))})]),c.length>0&&p.push(["IPv6",r("div",{className:"flex flex-wrap gap-1.5",children:c.map((u,h)=>r("span",{className:"font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]",title:u,children:u},`${u}-${h}`))})]),r("div",{className:"py-2",children:r("table",{className:"w-full text-sm",children:r("tbody",{children:p.map(([u,h],m)=>f("tr",{className:m%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:u}),r("td",{className:"py-1.5 px-2",children:h})]},u))})})})}function nR({node:e}){const[t,n]=L("info"),o=e.processes??[],s=e.addons.map(a=>a.id);return e.isOnline?f("div",{className:"border border-border rounded-xl overflow-hidden",children:[f("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}),f("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)),f("div",{className:"ml-auto flex gap-3 text-xs text-muted-foreground",children:[f("span",{className:"flex items-center gap-1",children:[r(tt,{className:"h-3 w-3"})," ",e.cpuPercent,"%"]}),f("span",{className:"flex items-center gap-1",children:[r(dc,{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))}),f("div",{className:"px-4 py-2",children:[t==="info"&&r(tR,{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(HT,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),t==="forks"&&r(GT,{nodeId:e.id,processes:o}),t==="processes"&&r(ZT,{nodeId:e.id}),t==="settings"&&r(XT,{nodeId:e.id,addonIds:s}),t==="capabilities"&&r(JT,{nodeId:e.id,addons:e.addons})]})]}):f("div",{className:"border border-border rounded-xl overflow-hidden opacity-60",children:[f("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}),f("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"})]}),f("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 rR({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(nR,{node:n},n.id))})}function ze(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=ze(e[n]))!==""&&(t+=(t&&" ")+o);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var oR={value:()=>{}};function Qs(){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 jo(n)}function jo(e){this._=e}function sR(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}})}jo.prototype=Qs.prototype={constructor:jo,on:function(e,t){var n=this._,o=sR(e+"",n),s,a=-1,i=o.length;if(arguments.length<2){for(;++a<i;)if((s=(e=o[a]).type)&&(s=aR(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]=vu(n[s],e.name,t);else if(t==null)for(s in n)n[s]=vu(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 jo(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 aR(e,t){for(var n=0,o=e.length,s;n<o;++n)if((s=e[n]).name===t)return s.value}function vu(e,t,n){for(var o=0,s=e.length;o<s;++o)if(e[o].name===t){e[o]=oR,e=e.slice(0,o).concat(e.slice(o+1));break}return n!=null&&e.push({name:t,value:n}),e}var Di="http://www.w3.org/1999/xhtml";const wu={svg:"http://www.w3.org/2000/svg",xhtml:Di,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Gs(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),wu.hasOwnProperty(t)?{space:wu[t],local:e}:e}function iR(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===Di&&t.documentElement.namespaceURI===Di?t.createElement(e):t.createElementNS(n,e)}}function lR(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Wb(e){var t=Gs(e);return(t.local?lR:iR)(t)}function cR(){}function bc(e){return e==null?cR:function(){return this.querySelector(e)}}function dR(e){typeof e!="function"&&(e=bc(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 rt(o,this._parents)}function uR(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function fR(){return[]}function Kb(e){return e==null?fR:function(){return this.querySelectorAll(e)}}function pR(e){return function(){return uR(e.apply(this,arguments))}}function hR(e){typeof e=="function"?e=pR(e):e=Kb(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 rt(o,s)}function Yb(e){return function(){return this.matches(e)}}function Zb(e){return function(t){return t.matches(e)}}var mR=Array.prototype.find;function gR(e){return function(){return mR.call(this.children,e)}}function bR(){return this.firstElementChild}function xR(e){return this.select(e==null?bR:gR(typeof e=="function"?e:Zb(e)))}var yR=Array.prototype.filter;function vR(){return Array.from(this.children)}function wR(e){return function(){return yR.call(this.children,e)}}function NR(e){return this.selectAll(e==null?vR:wR(typeof e=="function"?e:Zb(e)))}function SR(e){typeof e!="function"&&(e=Yb(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 rt(o,this._parents)}function Xb(e){return new Array(e.length)}function kR(){return new rt(this._enter||this._groups.map(Xb),this._parents)}function cs(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}cs.prototype={constructor:cs,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 CR(e){return function(){return e}}function MR(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 cs(e,a[i]);for(;i<c;++i)(l=t[i])&&(s[i]=l)}function IR(e,t,n,o,s,a,i){var l,c,d=new Map,p=t.length,u=a.length,h=new Array(p),m;for(l=0;l<p;++l)(c=t[l])&&(h[l]=m=i.call(c,c.__data__,l,t)+"",d.has(m)?s[l]=c:d.set(m,c));for(l=0;l<u;++l)m=i.call(e,a[l],l,a)+"",(c=d.get(m))?(o[l]=c,c.__data__=a[l],d.delete(m)):n[l]=new cs(e,a[l]);for(l=0;l<p;++l)(c=t[l])&&d.get(h[l])===c&&(s[l]=c)}function ER(e){return e.__data__}function PR(e,t){if(!arguments.length)return Array.from(this,ER);var n=t?IR:MR,o=this._parents,s=this._groups;typeof e!="function"&&(e=CR(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],u=s[d],h=u.length,m=AR(e.call(p,p&&p.__data__,d,o)),g=m.length,b=l[d]=new Array(g),x=i[d]=new Array(g),y=c[d]=new Array(h);n(p,u,b,x,y,m,t);for(var w=0,v=0,N,S;w<g;++w)if(N=b[w]){for(w>=v&&(v=w+1);!(S=x[v])&&++v<g;);N._next=S||null}}return i=new rt(i,o),i._enter=l,i._exit=c,i}function AR(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function $R(){return new rt(this._exit||this._groups.map(Xb),this._parents)}function DR(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 _R(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],u=d.length,h=l[c]=new Array(u),m,g=0;g<u;++g)(m=d[g]||p[g])&&(h[g]=m);for(;c<s;++c)l[c]=n[c];return new rt(l,this._parents)}function TR(){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 RR(e){e||(e=LR);function t(u,h){return u&&h?e(u.__data__,h.__data__):!u-!h}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 rt(s,this._parents).order()}function LR(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function OR(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function BR(){return Array.from(this)}function zR(){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 FR(){let e=0;for(const t of this)++e;return e}function HR(){return!this.node()}function jR(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 VR(e){return function(){this.removeAttribute(e)}}function qR(e){return function(){this.removeAttributeNS(e.space,e.local)}}function UR(e,t){return function(){this.setAttribute(e,t)}}function QR(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function GR(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function WR(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 KR(e,t){var n=Gs(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?qR:VR:typeof t=="function"?n.local?WR:GR:n.local?QR:UR)(n,t))}function Jb(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function YR(e){return function(){this.style.removeProperty(e)}}function ZR(e,t,n){return function(){this.style.setProperty(e,t,n)}}function XR(e,t,n){return function(){var o=t.apply(this,arguments);o==null?this.style.removeProperty(e):this.style.setProperty(e,o,n)}}function JR(e,t,n){return arguments.length>1?this.each((t==null?YR:typeof t=="function"?XR:ZR)(e,t,n??"")):Zn(this.node(),e)}function Zn(e,t){return e.style.getPropertyValue(t)||Jb(e).getComputedStyle(e,null).getPropertyValue(t)}function eL(e){return function(){delete this[e]}}function tL(e,t){return function(){this[e]=t}}function nL(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function rL(e,t){return arguments.length>1?this.each((t==null?eL:typeof t=="function"?nL:tL)(e,t)):this.node()[e]}function ex(e){return e.trim().split(/^|\s+/)}function xc(e){return e.classList||new tx(e)}function tx(e){this._node=e,this._names=ex(e.getAttribute("class")||"")}tx.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 nx(e,t){for(var n=xc(e),o=-1,s=t.length;++o<s;)n.add(t[o])}function rx(e,t){for(var n=xc(e),o=-1,s=t.length;++o<s;)n.remove(t[o])}function oL(e){return function(){nx(this,e)}}function sL(e){return function(){rx(this,e)}}function aL(e,t){return function(){(t.apply(this,arguments)?nx:rx)(this,e)}}function iL(e,t){var n=ex(e+"");if(arguments.length<2){for(var o=xc(this.node()),s=-1,a=n.length;++s<a;)if(!o.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?aL:t?oL:sL)(n,t))}function lL(){this.textContent=""}function cL(e){return function(){this.textContent=e}}function dL(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function uL(e){return arguments.length?this.each(e==null?lL:(typeof e=="function"?dL:cL)(e)):this.node().textContent}function fL(){this.innerHTML=""}function pL(e){return function(){this.innerHTML=e}}function hL(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function mL(e){return arguments.length?this.each(e==null?fL:(typeof e=="function"?hL:pL)(e)):this.node().innerHTML}function gL(){this.nextSibling&&this.parentNode.appendChild(this)}function bL(){return this.each(gL)}function xL(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function yL(){return this.each(xL)}function vL(e){var t=typeof e=="function"?e:Wb(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function wL(){return null}function NL(e,t){var n=typeof e=="function"?e:Wb(e),o=t==null?wL:typeof t=="function"?t:bc(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),o.apply(this,arguments)||null)})}function SL(){var e=this.parentNode;e&&e.removeChild(this)}function kL(){return this.each(SL)}function CL(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function ML(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function IL(e){return this.select(e?ML:CL)}function EL(e){return arguments.length?this.property("__data__",e):this.node().__data__}function PL(e){return function(t){e.call(this,t,this.__data__)}}function AL(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 $L(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 DL(e,t,n){return function(){var o=this.__on,s,a=PL(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 _L(e,t,n){var o=AL(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?DL:$L,s=0;s<a;++s)this.each(l(o[s],t,n));return this}function ox(e,t,n){var o=Jb(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 TL(e,t){return function(){return ox(this,e,t)}}function RL(e,t){return function(){return ox(this,e,t.apply(this,arguments))}}function LL(e,t){return this.each((typeof t=="function"?RL:TL)(e,t))}function*OL(){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 sx=[null];function rt(e,t){this._groups=e,this._parents=t}function ao(){return new rt([[document.documentElement]],sx)}function BL(){return this}rt.prototype=ao.prototype={constructor:rt,select:dR,selectAll:hR,selectChild:xR,selectChildren:NR,filter:SR,data:PR,enter:kR,exit:$R,join:DR,merge:_R,selection:BL,order:TR,sort:RR,call:OR,nodes:BR,node:zR,size:FR,empty:HR,each:jR,attr:KR,style:JR,property:rL,classed:iL,text:uL,html:mL,raise:bL,lower:yL,append:vL,insert:NL,remove:kL,clone:IL,datum:EL,on:_L,dispatch:LL,[Symbol.iterator]:OL};function Xe(e){return typeof e=="string"?new rt([[document.querySelector(e)]],[document.documentElement]):new rt([[e]],sx)}function zL(e){let t;for(;t=e.sourceEvent;)e=t;return e}function ft(e,t){if(e=zL(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 FL={passive:!1},Fr={capture:!0,passive:!1};function ja(e){e.stopImmediatePropagation()}function Vn(e){e.preventDefault(),e.stopImmediatePropagation()}function ax(e){var t=e.document.documentElement,n=Xe(e).on("dragstart.drag",Vn,Fr);"onselectstart"in t?n.on("selectstart.drag",Vn,Fr):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function ix(e,t){var n=e.document.documentElement,o=Xe(e).on("dragstart.drag",null);t&&(o.on("click.drag",Vn,Fr),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 Po=e=>()=>e;function _i(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}})}_i.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function HL(e){return!e.ctrlKey&&!e.button}function jL(){return this.parentNode}function VL(e,t){return t??{x:e.x,y:e.y}}function qL(){return navigator.maxTouchPoints||"ontouchstart"in this}function lx(){var e=HL,t=jL,n=VL,o=qL,s={},a=Qs("start","drag","end"),i=0,l,c,d,p,u=0;function h(N){N.on("mousedown.drag",m).filter(o).on("touchstart.drag",x).on("touchmove.drag",y,FL).on("touchend.drag touchcancel.drag",w).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function m(N,S){if(!(p||!e.call(this,N,S))){var k=v(this,t.call(this,N,S),N,S,"mouse");k&&(Xe(N.view).on("mousemove.drag",g,Fr).on("mouseup.drag",b,Fr),ax(N.view),ja(N),d=!1,l=N.clientX,c=N.clientY,k("start",N))}}function g(N){if(Vn(N),!d){var S=N.clientX-l,k=N.clientY-c;d=S*S+k*k>u}s.mouse("drag",N)}function b(N){Xe(N.view).on("mousemove.drag mouseup.drag",null),ix(N.view,d),Vn(N),s.mouse("end",N)}function x(N,S){if(e.call(this,N,S)){var k=N.changedTouches,M=t.call(this,N,S),D=k.length,E,B;for(E=0;E<D;++E)(B=v(this,M,N,S,k[E].identifier,k[E]))&&(ja(N),B("start",N,k[E]))}}function y(N){var S=N.changedTouches,k=S.length,M,D;for(M=0;M<k;++M)(D=s[S[M].identifier])&&(Vn(N),D("drag",N,S[M]))}function w(N){var S=N.changedTouches,k=S.length,M,D;for(p&&clearTimeout(p),p=setTimeout(function(){p=null},500),M=0;M<k;++M)(D=s[S[M].identifier])&&(ja(N),D("end",N,S[M]))}function v(N,S,k,M,D,E){var B=a.copy(),A=ft(E||k,S),O,$,I;if((I=n.call(N,new _i("beforestart",{sourceEvent:k,target:h,identifier:D,active:i,x:A[0],y:A[1],dx:0,dy:0,dispatch:B}),M))!=null)return O=I.x-A[0]||0,$=I.y-A[1]||0,function _(P,T,R){var z=A,H;switch(P){case"start":s[D]=_,H=i++;break;case"end":delete s[D],--i;case"drag":A=ft(R||T,S),H=i;break}B.call(P,N,new _i(P,{sourceEvent:T,subject:I,target:h,identifier:D,active:H,x:A[0]+O,y:A[1]+$,dx:A[0]-z[0],dy:A[1]-z[1],dispatch:B}),M)}}return h.filter=function(N){return arguments.length?(e=typeof N=="function"?N:Po(!!N),h):e},h.container=function(N){return arguments.length?(t=typeof N=="function"?N:Po(N),h):t},h.subject=function(N){return arguments.length?(n=typeof N=="function"?N:Po(N),h):n},h.touchable=function(N){return arguments.length?(o=typeof N=="function"?N:Po(!!N),h):o},h.on=function(){var N=a.on.apply(a,arguments);return N===a?h:N},h.clickDistance=function(N){return arguments.length?(u=(N=+N)*N,h):Math.sqrt(u)},h}function yc(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function cx(e,t){var n=Object.create(e.prototype);for(var o in t)n[o]=t[o];return n}function io(){}var Hr=.7,ds=1/Hr,qn="\\s*([+-]?\\d+)\\s*",jr="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Ct="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",UL=/^#([0-9a-f]{3,8})$/,QL=new RegExp(`^rgb\\(${qn},${qn},${qn}\\)$`),GL=new RegExp(`^rgb\\(${Ct},${Ct},${Ct}\\)$`),WL=new RegExp(`^rgba\\(${qn},${qn},${qn},${jr}\\)$`),KL=new RegExp(`^rgba\\(${Ct},${Ct},${Ct},${jr}\\)$`),YL=new RegExp(`^hsl\\(${jr},${Ct},${Ct}\\)$`),ZL=new RegExp(`^hsla\\(${jr},${Ct},${Ct},${jr}\\)$`),Nu={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};yc(io,Sn,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Su,formatHex:Su,formatHex8:XL,formatHsl:JL,formatRgb:ku,toString:ku});function Su(){return this.rgb().formatHex()}function XL(){return this.rgb().formatHex8()}function JL(){return dx(this).formatHsl()}function ku(){return this.rgb().formatRgb()}function Sn(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=UL.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Cu(t):n===3?new Qe(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Ao(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Ao(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=QL.exec(e))?new Qe(t[1],t[2],t[3],1):(t=GL.exec(e))?new Qe(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=WL.exec(e))?Ao(t[1],t[2],t[3],t[4]):(t=KL.exec(e))?Ao(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=YL.exec(e))?Eu(t[1],t[2]/100,t[3]/100,1):(t=ZL.exec(e))?Eu(t[1],t[2]/100,t[3]/100,t[4]):Nu.hasOwnProperty(e)?Cu(Nu[e]):e==="transparent"?new Qe(NaN,NaN,NaN,0):null}function Cu(e){return new Qe(e>>16&255,e>>8&255,e&255,1)}function Ao(e,t,n,o){return o<=0&&(e=t=n=NaN),new Qe(e,t,n,o)}function eO(e){return e instanceof io||(e=Sn(e)),e?(e=e.rgb(),new Qe(e.r,e.g,e.b,e.opacity)):new Qe}function Ti(e,t,n,o){return arguments.length===1?eO(e):new Qe(e,t,n,o??1)}function Qe(e,t,n,o){this.r=+e,this.g=+t,this.b=+n,this.opacity=+o}yc(Qe,Ti,cx(io,{brighter(e){return e=e==null?ds:Math.pow(ds,e),new Qe(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Hr:Math.pow(Hr,e),new Qe(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Qe(bn(this.r),bn(this.g),bn(this.b),us(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:Mu,formatHex:Mu,formatHex8:tO,formatRgb:Iu,toString:Iu}));function Mu(){return`#${hn(this.r)}${hn(this.g)}${hn(this.b)}`}function tO(){return`#${hn(this.r)}${hn(this.g)}${hn(this.b)}${hn((isNaN(this.opacity)?1:this.opacity)*255)}`}function Iu(){const e=us(this.opacity);return`${e===1?"rgb(":"rgba("}${bn(this.r)}, ${bn(this.g)}, ${bn(this.b)}${e===1?")":`, ${e})`}`}function us(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function bn(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function hn(e){return e=bn(e),(e<16?"0":"")+e.toString(16)}function Eu(e,t,n,o){return o<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new pt(e,t,n,o)}function dx(e){if(e instanceof pt)return new pt(e.h,e.s,e.l,e.opacity);if(e instanceof io||(e=Sn(e)),!e)return new pt;if(e instanceof pt)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 pt(i,l,c,e.opacity)}function nO(e,t,n,o){return arguments.length===1?dx(e):new pt(e,t,n,o??1)}function pt(e,t,n,o){this.h=+e,this.s=+t,this.l=+n,this.opacity=+o}yc(pt,nO,cx(io,{brighter(e){return e=e==null?ds:Math.pow(ds,e),new pt(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Hr:Math.pow(Hr,e),new pt(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 Qe(Va(e>=240?e-240:e+120,s,o),Va(e,s,o),Va(e<120?e+240:e-120,s,o),this.opacity)},clamp(){return new pt(Pu(this.h),$o(this.s),$o(this.l),us(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=us(this.opacity);return`${e===1?"hsl(":"hsla("}${Pu(this.h)}, ${$o(this.s)*100}%, ${$o(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Pu(e){return e=(e||0)%360,e<0?e+360:e}function $o(e){return Math.max(0,Math.min(1,e||0))}function Va(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 vc=e=>()=>e;function rO(e,t){return function(n){return e+n*t}}function oO(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 sO(e){return(e=+e)==1?ux:function(t,n){return n-t?oO(t,n,e):vc(isNaN(t)?n:t)}}function ux(e,t){var n=t-e;return n?rO(e,n):vc(isNaN(e)?t:e)}const fs=(function e(t){var n=sO(t);function o(s,a){var i=n((s=Ti(s)).r,(a=Ti(a)).r),l=n(s.g,a.g),c=n(s.b,a.b),d=ux(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 aO(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 iO(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function lO(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]=$r(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 cO(e,t){var n=new Date;return e=+e,t=+t,function(o){return n.setTime(e*(1-o)+t*o),n}}function Nt(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function dO(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]=$r(e[s],t[s]):o[s]=t[s];return function(a){for(s in n)o[s]=n[s](a);return o}}var Ri=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,qa=new RegExp(Ri.source,"g");function uO(e){return function(){return e}}function fO(e){return function(t){return e(t)+""}}function fx(e,t){var n=Ri.lastIndex=qa.lastIndex=0,o,s,a,i=-1,l=[],c=[];for(e=e+"",t=t+"";(o=Ri.exec(e))&&(s=qa.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:Nt(o,s)})),n=qa.lastIndex;return n<t.length&&(a=t.slice(n),l[i]?l[i]+=a:l[++i]=a),l.length<2?c[0]?fO(c[0].x):uO(t):(t=c.length,function(d){for(var p=0,u;p<t;++p)l[(u=c[p]).i]=u.x(d);return l.join("")})}function $r(e,t){var n=typeof t,o;return t==null||n==="boolean"?vc(t):(n==="number"?Nt:n==="string"?(o=Sn(t))?(t=o,fs):fx:t instanceof Sn?fs:t instanceof Date?cO:iO(t)?aO:Array.isArray(t)?lO:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?dO:Nt)(e,t)}var Au=180/Math.PI,Li={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function px(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)*Au,skewX:Math.atan(c)*Au,scaleX:i,scaleY:l}}var Do;function pO(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Li:px(t.a,t.b,t.c,t.d,t.e,t.f)}function hO(e){return e==null||(Do||(Do=document.createElementNS("http://www.w3.org/2000/svg","g")),Do.setAttribute("transform",e),!(e=Do.transform.baseVal.consolidate()))?Li:(e=e.matrix,px(e.a,e.b,e.c,e.d,e.e,e.f))}function hx(e,t,n,o){function s(d){return d.length?d.pop()+" ":""}function a(d,p,u,h,m,g){if(d!==u||p!==h){var b=m.push("translate(",null,t,null,n);g.push({i:b-4,x:Nt(d,u)},{i:b-2,x:Nt(p,h)})}else(u||h)&&m.push("translate("+u+t+h+n)}function i(d,p,u,h){d!==p?(d-p>180?p+=360:p-d>180&&(d+=360),h.push({i:u.push(s(u)+"rotate(",null,o)-2,x:Nt(d,p)})):p&&u.push(s(u)+"rotate("+p+o)}function l(d,p,u,h){d!==p?h.push({i:u.push(s(u)+"skewX(",null,o)-2,x:Nt(d,p)}):p&&u.push(s(u)+"skewX("+p+o)}function c(d,p,u,h,m,g){if(d!==u||p!==h){var b=m.push(s(m)+"scale(",null,",",null,")");g.push({i:b-4,x:Nt(d,u)},{i:b-2,x:Nt(p,h)})}else(u!==1||h!==1)&&m.push(s(m)+"scale("+u+","+h+")")}return function(d,p){var u=[],h=[];return d=e(d),p=e(p),a(d.translateX,d.translateY,p.translateX,p.translateY,u,h),i(d.rotate,p.rotate,u,h),l(d.skewX,p.skewX,u,h),c(d.scaleX,d.scaleY,p.scaleX,p.scaleY,u,h),d=p=null,function(m){for(var g=-1,b=h.length,x;++g<b;)u[(x=h[g]).i]=x.x(m);return u.join("")}}}var mO=hx(pO,"px, ","px)","deg)"),gO=hx(hO,", ",")",")"),bO=1e-12;function $u(e){return((e=Math.exp(e))+1/e)/2}function xO(e){return((e=Math.exp(e))-1/e)/2}function yO(e){return((e=Math.exp(2*e))-1)/(e+1)}const Vo=(function e(t,n,o){function s(a,i){var l=a[0],c=a[1],d=a[2],p=i[0],u=i[1],h=i[2],m=p-l,g=u-c,b=m*m+g*g,x,y;if(b<bO)y=Math.log(h/d)/t,x=function(M){return[l+M*m,c+M*g,d*Math.exp(t*M*y)]};else{var w=Math.sqrt(b),v=(h*h-d*d+o*b)/(2*d*n*w),N=(h*h-d*d-o*b)/(2*h*n*w),S=Math.log(Math.sqrt(v*v+1)-v),k=Math.log(Math.sqrt(N*N+1)-N);y=(k-S)/t,x=function(M){var D=M*y,E=$u(S),B=d/(n*w)*(E*yO(t*D+S)-xO(S));return[l+B*m,c+B*g,d*E/$u(t*D+S)]}}return x.duration=y*1e3*t/Math.SQRT2,x}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 Xn=0,Nr=0,xr=0,mx=1e3,ps,Sr,hs=0,kn=0,Ws=0,Vr=typeof performance=="object"&&performance.now?performance:Date,gx=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function wc(){return kn||(gx(vO),kn=Vr.now()+Ws)}function vO(){kn=0}function ms(){this._call=this._time=this._next=null}ms.prototype=bx.prototype={constructor:ms,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?wc():+n)+(t==null?0:+t),!this._next&&Sr!==this&&(Sr?Sr._next=this:ps=this,Sr=this),this._call=e,this._time=n,Oi()},stop:function(){this._call&&(this._call=null,this._time=1/0,Oi())}};function bx(e,t,n){var o=new ms;return o.restart(e,t,n),o}function wO(){wc(),++Xn;for(var e=ps,t;e;)(t=kn-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Xn}function Du(){kn=(hs=Vr.now())+Ws,Xn=Nr=0;try{wO()}finally{Xn=0,SO(),kn=0}}function NO(){var e=Vr.now(),t=e-hs;t>mx&&(Ws-=t,hs=e)}function SO(){for(var e,t=ps,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:ps=n);Sr=e,Oi(o)}function Oi(e){if(!Xn){Nr&&(Nr=clearTimeout(Nr));var t=e-kn;t>24?(e<1/0&&(Nr=setTimeout(Du,e-Vr.now()-Ws)),xr&&(xr=clearInterval(xr))):(xr||(hs=Vr.now(),xr=setInterval(NO,mx)),Xn=1,gx(Du))}}function _u(e,t,n){var o=new ms;return t=t==null?0:+t,o.restart(s=>{o.stop(),e(s+t)},t,n),o}var kO=Qs("start","end","cancel","interrupt"),CO=[],xx=0,Tu=1,Bi=2,qo=3,Ru=4,zi=5,Uo=6;function Ks(e,t,n,o,s,a){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;MO(e,n,{name:t,index:o,group:s,on:kO,tween:CO,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:xx})}function Nc(e,t){var n=yt(e,t);if(n.state>xx)throw new Error("too late; already scheduled");return n}function Dt(e,t){var n=yt(e,t);if(n.state>qo)throw new Error("too late; already running");return n}function yt(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function MO(e,t,n){var o=e.__transition,s;o[t]=n,n.timer=bx(a,0,n.time);function a(d){n.state=Tu,n.timer.restart(i,n.delay,n.time),n.delay<=d&&i(d-n.delay)}function i(d){var p,u,h,m;if(n.state!==Tu)return c();for(p in o)if(m=o[p],m.name===n.name){if(m.state===qo)return _u(i);m.state===Ru?(m.state=Uo,m.timer.stop(),m.on.call("interrupt",e,e.__data__,m.index,m.group),delete o[p]):+p<t&&(m.state=Uo,m.timer.stop(),m.on.call("cancel",e,e.__data__,m.index,m.group),delete o[p])}if(_u(function(){n.state===qo&&(n.state=Ru,n.timer.restart(l,n.delay,n.time),l(d))}),n.state=Bi,n.on.call("start",e,e.__data__,n.index,n.group),n.state===Bi){for(n.state=qo,s=new Array(h=n.tween.length),p=0,u=-1;p<h;++p)(m=n.tween[p].value.call(e,e.__data__,n.index,n.group))&&(s[++u]=m);s.length=u+1}}function l(d){for(var p=d<n.duration?n.ease.call(null,d/n.duration):(n.timer.restart(c),n.state=zi,1),u=-1,h=s.length;++u<h;)s[u].call(e,p);n.state===zi&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=Uo,n.timer.stop(),delete o[t];for(var d in o)return;delete e.__transition}}function Qo(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>Bi&&o.state<zi,o.state=Uo,o.timer.stop(),o.on.call(s?"interrupt":"cancel",e,e.__data__,o.index,o.group),delete n[i]}a&&delete e.__transition}}function IO(e){return this.each(function(){Qo(this,e)})}function EO(e,t){var n,o;return function(){var s=Dt(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 PO(e,t,n){var o,s;if(typeof n!="function")throw new Error;return function(){var a=Dt(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 AO(e,t){var n=this._id;if(e+="",arguments.length<2){for(var o=yt(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?EO:PO)(n,e,t))}function Sc(e,t,n){var o=e._id;return e.each(function(){var s=Dt(this,o);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return yt(s,o).value[t]}}function yx(e,t){var n;return(typeof t=="number"?Nt:t instanceof Sn?fs:(n=Sn(t))?(t=n,fs):fx)(e,t)}function $O(e){return function(){this.removeAttribute(e)}}function DO(e){return function(){this.removeAttributeNS(e.space,e.local)}}function _O(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 TO(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 RO(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 LO(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 OO(e,t){var n=Gs(e),o=n==="transform"?gO:yx;return this.attrTween(e,typeof t=="function"?(n.local?LO:RO)(n,o,Sc(this,"attr."+e,t)):t==null?(n.local?DO:$O)(n):(n.local?TO:_O)(n,o,t))}function BO(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function zO(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function FO(e,t){var n,o;function s(){var a=t.apply(this,arguments);return a!==o&&(n=(o=a)&&zO(e,a)),n}return s._value=t,s}function HO(e,t){var n,o;function s(){var a=t.apply(this,arguments);return a!==o&&(n=(o=a)&&BO(e,a)),n}return s._value=t,s}function jO(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=Gs(e);return this.tween(n,(o.local?FO:HO)(o,t))}function VO(e,t){return function(){Nc(this,e).delay=+t.apply(this,arguments)}}function qO(e,t){return t=+t,function(){Nc(this,e).delay=t}}function UO(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?VO:qO)(t,e)):yt(this.node(),t).delay}function QO(e,t){return function(){Dt(this,e).duration=+t.apply(this,arguments)}}function GO(e,t){return t=+t,function(){Dt(this,e).duration=t}}function WO(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?QO:GO)(t,e)):yt(this.node(),t).duration}function KO(e,t){if(typeof t!="function")throw new Error;return function(){Dt(this,e).ease=t}}function YO(e){var t=this._id;return arguments.length?this.each(KO(t,e)):yt(this.node(),t).ease}function ZO(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Dt(this,e).ease=n}}function XO(e){if(typeof e!="function")throw new Error;return this.each(ZO(this._id,e))}function JO(e){typeof e!="function"&&(e=Yb(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 qt(o,this._parents,this._name,this._id)}function e6(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,u=i[l]=new Array(p),h,m=0;m<p;++m)(h=c[m]||d[m])&&(u[m]=h);for(;l<o;++l)i[l]=t[l];return new qt(i,this._parents,this._name,this._id)}function t6(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 n6(e,t,n){var o,s,a=t6(t)?Nc:Dt;return function(){var i=a(this,e),l=i.on;l!==o&&(s=(o=l).copy()).on(t,n),i.on=s}}function r6(e,t){var n=this._id;return arguments.length<2?yt(this.node(),n).on.on(e):this.each(n6(n,e,t))}function o6(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function s6(){return this.on("end.remove",o6(this._id))}function a6(e){var t=this._name,n=this._id;typeof e!="function"&&(e=bc(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,u,h=0;h<c;++h)(p=l[h])&&(u=e.call(p,p.__data__,h,l))&&("__data__"in p&&(u.__data__=p.__data__),d[h]=u,Ks(d[h],t,n,h,d,yt(p,n)));return new qt(a,this._parents,t,n)}function i6(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Kb(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,u=0;u<d;++u)if(p=c[u]){for(var h=e.call(p,p.__data__,u,c),m,g=yt(p,n),b=0,x=h.length;b<x;++b)(m=h[b])&&Ks(m,t,n,b,h,g);a.push(h),i.push(p)}return new qt(a,i,t,n)}var l6=ao.prototype.constructor;function c6(){return new l6(this._groups,this._parents)}function d6(e,t){var n,o,s;return function(){var a=Zn(this,e),i=(this.style.removeProperty(e),Zn(this,e));return a===i?null:a===n&&i===o?s:s=t(n=a,o=i)}}function vx(e){return function(){this.style.removeProperty(e)}}function u6(e,t,n){var o,s=n+"",a;return function(){var i=Zn(this,e);return i===s?null:i===o?a:a=t(o=i,n)}}function f6(e,t,n){var o,s,a;return function(){var i=Zn(this,e),l=n(this),c=l+"";return l==null&&(c=l=(this.style.removeProperty(e),Zn(this,e))),i===c?null:i===o&&c===s?a:(s=c,a=t(o=i,l))}}function p6(e,t){var n,o,s,a="style."+t,i="end."+a,l;return function(){var c=Dt(this,e),d=c.on,p=c.value[a]==null?l||(l=vx(t)):void 0;(d!==n||s!==p)&&(o=(n=d).copy()).on(i,s=p),c.on=o}}function h6(e,t,n){var o=(e+="")=="transform"?mO:yx;return t==null?this.styleTween(e,d6(e,o)).on("end.style."+e,vx(e)):typeof t=="function"?this.styleTween(e,f6(e,o,Sc(this,"style."+e,t))).each(p6(this._id,e)):this.styleTween(e,u6(e,o,t),n).on("end.style."+e,null)}function m6(e,t,n){return function(o){this.style.setProperty(e,t.call(this,o),n)}}function g6(e,t,n){var o,s;function a(){var i=t.apply(this,arguments);return i!==s&&(o=(s=i)&&m6(e,i,n)),o}return a._value=t,a}function b6(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,g6(e,t,n??""))}function x6(e){return function(){this.textContent=e}}function y6(e){return function(){var t=e(this);this.textContent=t??""}}function v6(e){return this.tween("text",typeof e=="function"?y6(Sc(this,"text",e)):x6(e==null?"":e+""))}function w6(e){return function(t){this.textContent=e.call(this,t)}}function N6(e){var t,n;function o(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&w6(s)),t}return o._value=e,o}function S6(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,N6(e))}function k6(){for(var e=this._name,t=this._id,n=wx(),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=yt(c,t);Ks(c,e,n,d,i,{time:p.time+p.delay+p.duration,delay:0,duration:p.duration,ease:p.ease})}return new qt(o,this._parents,e,n)}function C6(){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=Dt(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 M6=0;function qt(e,t,n,o){this._groups=e,this._parents=t,this._name=n,this._id=o}function wx(){return++M6}var Tt=ao.prototype;qt.prototype={constructor:qt,select:a6,selectAll:i6,selectChild:Tt.selectChild,selectChildren:Tt.selectChildren,filter:JO,merge:e6,selection:c6,transition:k6,call:Tt.call,nodes:Tt.nodes,node:Tt.node,size:Tt.size,empty:Tt.empty,each:Tt.each,on:r6,attr:OO,attrTween:jO,style:h6,styleTween:b6,text:v6,textTween:S6,remove:s6,tween:AO,delay:UO,duration:WO,ease:YO,easeVarying:XO,end:C6,[Symbol.iterator]:Tt[Symbol.iterator]};function I6(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var E6={time:null,delay:0,duration:250,ease:I6};function P6(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 A6(e){var t,n;e instanceof qt?(t=e._id,e=e._name):(t=wx(),(n=E6).time=wc(),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])&&Ks(c,e,t,d,i,n||P6(c,t));return new qt(o,this._parents,e,t)}ao.prototype.interrupt=IO;ao.prototype.transition=A6;const _o=e=>()=>e;function $6(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 Ot(e,t,n){this.k=e,this.x=t,this.y=n}Ot.prototype={constructor:Ot,scale:function(e){return e===1?this:new Ot(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Ot(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 Ys=new Ot(1,0,0);Nx.prototype=Ot.prototype;function Nx(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Ys;return e.__zoom}function Ua(e){e.stopImmediatePropagation()}function yr(e){e.preventDefault(),e.stopImmediatePropagation()}function D6(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function _6(){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 Lu(){return this.__zoom||Ys}function T6(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function R6(){return navigator.maxTouchPoints||"ontouchstart"in this}function L6(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 Sx(){var e=D6,t=_6,n=L6,o=T6,s=R6,a=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],l=250,c=Vo,d=Qs("start","zoom","end"),p,u,h,m=500,g=150,b=0,x=10;function y(I){I.property("__zoom",Lu).on("wheel.zoom",D,{passive:!1}).on("mousedown.zoom",E).on("dblclick.zoom",B).filter(s).on("touchstart.zoom",A).on("touchmove.zoom",O).on("touchend.zoom touchcancel.zoom",$).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}y.transform=function(I,_,P,T){var R=I.selection?I.selection():I;R.property("__zoom",Lu),I!==R?S(I,_,P,T):R.interrupt().each(function(){k(this,arguments).event(T).start().zoom(null,typeof _=="function"?_.apply(this,arguments):_).end()})},y.scaleBy=function(I,_,P,T){y.scaleTo(I,function(){var R=this.__zoom.k,z=typeof _=="function"?_.apply(this,arguments):_;return R*z},P,T)},y.scaleTo=function(I,_,P,T){y.transform(I,function(){var R=t.apply(this,arguments),z=this.__zoom,H=P==null?N(R):typeof P=="function"?P.apply(this,arguments):P,F=z.invert(H),j=typeof _=="function"?_.apply(this,arguments):_;return n(v(w(z,j),H,F),R,i)},P,T)},y.translateBy=function(I,_,P,T){y.transform(I,function(){return n(this.__zoom.translate(typeof _=="function"?_.apply(this,arguments):_,typeof P=="function"?P.apply(this,arguments):P),t.apply(this,arguments),i)},null,T)},y.translateTo=function(I,_,P,T,R){y.transform(I,function(){var z=t.apply(this,arguments),H=this.__zoom,F=T==null?N(z):typeof T=="function"?T.apply(this,arguments):T;return n(Ys.translate(F[0],F[1]).scale(H.k).translate(typeof _=="function"?-_.apply(this,arguments):-_,typeof P=="function"?-P.apply(this,arguments):-P),z,i)},T,R)};function w(I,_){return _=Math.max(a[0],Math.min(a[1],_)),_===I.k?I:new Ot(_,I.x,I.y)}function v(I,_,P){var T=_[0]-P[0]*I.k,R=_[1]-P[1]*I.k;return T===I.x&&R===I.y?I:new Ot(I.k,T,R)}function N(I){return[(+I[0][0]+ +I[1][0])/2,(+I[0][1]+ +I[1][1])/2]}function S(I,_,P,T){I.on("start.zoom",function(){k(this,arguments).event(T).start()}).on("interrupt.zoom end.zoom",function(){k(this,arguments).event(T).end()}).tween("zoom",function(){var R=this,z=arguments,H=k(R,z).event(T),F=t.apply(R,z),j=P==null?N(F):typeof P=="function"?P.apply(R,z):P,J=Math.max(F[1][0]-F[0][0],F[1][1]-F[0][1]),W=R.__zoom,ne=typeof _=="function"?_.apply(R,z):_,de=c(W.invert(j).concat(J/W.k),ne.invert(j).concat(J/ne.k));return function(te){if(te===1)te=ne;else{var K=de(te),oe=J/K[2];te=new Ot(oe,j[0]-K[0]*oe,j[1]-K[1]*oe)}H.zoom(null,te)}})}function k(I,_,P){return!P&&I.__zooming||new M(I,_)}function M(I,_){this.that=I,this.args=_,this.active=0,this.sourceEvent=null,this.extent=t.apply(I,_),this.taps=0}M.prototype={event:function(I){return I&&(this.sourceEvent=I),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(I,_){return this.mouse&&I!=="mouse"&&(this.mouse[1]=_.invert(this.mouse[0])),this.touch0&&I!=="touch"&&(this.touch0[1]=_.invert(this.touch0[0])),this.touch1&&I!=="touch"&&(this.touch1[1]=_.invert(this.touch1[0])),this.that.__zoom=_,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(I){var _=Xe(this.that).datum();d.call(I,this.that,new $6(I,{sourceEvent:this.sourceEvent,target:y,transform:this.that.__zoom,dispatch:d}),_)}};function D(I,..._){if(!e.apply(this,arguments))return;var P=k(this,_).event(I),T=this.__zoom,R=Math.max(a[0],Math.min(a[1],T.k*Math.pow(2,o.apply(this,arguments)))),z=ft(I);if(P.wheel)(P.mouse[0][0]!==z[0]||P.mouse[0][1]!==z[1])&&(P.mouse[1]=T.invert(P.mouse[0]=z)),clearTimeout(P.wheel);else{if(T.k===R)return;P.mouse=[z,T.invert(z)],Qo(this),P.start()}yr(I),P.wheel=setTimeout(H,g),P.zoom("mouse",n(v(w(T,R),P.mouse[0],P.mouse[1]),P.extent,i));function H(){P.wheel=null,P.end()}}function E(I,..._){if(h||!e.apply(this,arguments))return;var P=I.currentTarget,T=k(this,_,!0).event(I),R=Xe(I.view).on("mousemove.zoom",j,!0).on("mouseup.zoom",J,!0),z=ft(I,P),H=I.clientX,F=I.clientY;ax(I.view),Ua(I),T.mouse=[z,this.__zoom.invert(z)],Qo(this),T.start();function j(W){if(yr(W),!T.moved){var ne=W.clientX-H,de=W.clientY-F;T.moved=ne*ne+de*de>b}T.event(W).zoom("mouse",n(v(T.that.__zoom,T.mouse[0]=ft(W,P),T.mouse[1]),T.extent,i))}function J(W){R.on("mousemove.zoom mouseup.zoom",null),ix(W.view,T.moved),yr(W),T.event(W).end()}}function B(I,..._){if(e.apply(this,arguments)){var P=this.__zoom,T=ft(I.changedTouches?I.changedTouches[0]:I,this),R=P.invert(T),z=P.k*(I.shiftKey?.5:2),H=n(v(w(P,z),T,R),t.apply(this,_),i);yr(I),l>0?Xe(this).transition().duration(l).call(S,H,T,I):Xe(this).call(y.transform,H,T,I)}}function A(I,..._){if(e.apply(this,arguments)){var P=I.touches,T=P.length,R=k(this,_,I.changedTouches.length===T).event(I),z,H,F,j;for(Ua(I),H=0;H<T;++H)F=P[H],j=ft(F,this),j=[j,this.__zoom.invert(j),F.identifier],R.touch0?!R.touch1&&R.touch0[2]!==j[2]&&(R.touch1=j,R.taps=0):(R.touch0=j,z=!0,R.taps=1+!!p);p&&(p=clearTimeout(p)),z&&(R.taps<2&&(u=j[0],p=setTimeout(function(){p=null},m)),Qo(this),R.start())}}function O(I,..._){if(this.__zooming){var P=k(this,_).event(I),T=I.changedTouches,R=T.length,z,H,F,j;for(yr(I),z=0;z<R;++z)H=T[z],F=ft(H,this),P.touch0&&P.touch0[2]===H.identifier?P.touch0[0]=F:P.touch1&&P.touch1[2]===H.identifier&&(P.touch1[0]=F);if(H=P.that.__zoom,P.touch1){var J=P.touch0[0],W=P.touch0[1],ne=P.touch1[0],de=P.touch1[1],te=(te=ne[0]-J[0])*te+(te=ne[1]-J[1])*te,K=(K=de[0]-W[0])*K+(K=de[1]-W[1])*K;H=w(H,Math.sqrt(te/K)),F=[(J[0]+ne[0])/2,(J[1]+ne[1])/2],j=[(W[0]+de[0])/2,(W[1]+de[1])/2]}else if(P.touch0)F=P.touch0[0],j=P.touch0[1];else return;P.zoom("touch",n(v(H,F,j),P.extent,i))}}function $(I,..._){if(this.__zooming){var P=k(this,_).event(I),T=I.changedTouches,R=T.length,z,H;for(Ua(I),h&&clearTimeout(h),h=setTimeout(function(){h=null},m),z=0;z<R;++z)H=T[z],P.touch0&&P.touch0[2]===H.identifier?delete P.touch0:P.touch1&&P.touch1[2]===H.identifier&&delete P.touch1;if(P.touch1&&!P.touch0&&(P.touch0=P.touch1,delete P.touch1),P.touch0)P.touch0[1]=this.__zoom.invert(P.touch0[0]);else if(P.end(),P.taps===2&&(H=ft(H,this),Math.hypot(u[0]-H[0],u[1]-H[1])<x)){var F=Xe(this).on("dblclick.zoom");F&&F.apply(this,arguments)}}}return y.wheelDelta=function(I){return arguments.length?(o=typeof I=="function"?I:_o(+I),y):o},y.filter=function(I){return arguments.length?(e=typeof I=="function"?I:_o(!!I),y):e},y.touchable=function(I){return arguments.length?(s=typeof I=="function"?I:_o(!!I),y):s},y.extent=function(I){return arguments.length?(t=typeof I=="function"?I:_o([[+I[0][0],+I[0][1]],[+I[1][0],+I[1][1]]]),y):t},y.scaleExtent=function(I){return arguments.length?(a[0]=+I[0],a[1]=+I[1],y):[a[0],a[1]]},y.translateExtent=function(I){return arguments.length?(i[0][0]=+I[0][0],i[1][0]=+I[1][0],i[0][1]=+I[0][1],i[1][1]=+I[1][1],y):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},y.constrain=function(I){return arguments.length?(n=I,y):n},y.duration=function(I){return arguments.length?(l=+I,y):l},y.interpolate=function(I){return arguments.length?(c=I,y):c},y.on=function(){var I=d.on.apply(d,arguments);return I===d?y:I},y.clickDistance=function(I){return arguments.length?(b=(I=+I)*I,y):Math.sqrt(b)},y.tapDistance=function(I){return arguments.length?(x=+I,y):x},y}const Pt={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."},qr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],kx=["Enter"," ","Escape"],Cx={"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 Jn;(function(e){e.Strict="strict",e.Loose="loose"})(Jn||(Jn={}));var xn;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(xn||(xn={}));var Ur;(function(e){e.Partial="partial",e.Full="full"})(Ur||(Ur={}));const Mx={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Xt;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Xt||(Xt={}));var gs;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(gs||(gs={}));var be;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(be||(be={}));const Ou={[be.Left]:be.Right,[be.Right]:be.Left,[be.Top]:be.Bottom,[be.Bottom]:be.Top};function Ix(e){return e===null?null:e?"valid":"invalid"}const Ex=e=>"id"in e&&"source"in e&&"target"in e,O6=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),kc=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),lo=(e,t=[0,0])=>{const{width:n,height:o}=Kt(e),s=e.origin??t,a=n*s[0],i=o*s[1];return{x:e.position.x-a,y:e.position.y-i}},B6=(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):kc(s)?s:t.nodeLookup.get(s.id));const l=i?bs(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Zs(o,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Xs(n)},co=(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=Zs(n,bs(s)),o=!0)}),o?Xs(n):{x:0,y:0,width:0,height:0}},Cc=(e,t,[n,o,s]=[0,0,1],a=!1,i=!1)=>{const l={...fo(t,[n,o,s]),width:t.width/s,height:t.height/s},c=[];for(const d of e.values()){const{measured:p,selectable:u=!0,hidden:h=!1}=d;if(i&&!u||h)continue;const m=p.width??d.width??d.initialWidth??null,g=p.height??d.height??d.initialHeight??null,b=Qr(l,tr(d)),x=(m??0)*(g??0),y=a&&b>0;(!d.internals.handleBounds||y||b>=x||d.dragging)&&c.push(d)}return c},z6=(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 F6(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 H6({nodes:e,width:t,height:n,panZoom:o,minZoom:s,maxZoom:a},i){if(e.size===0)return Promise.resolve(!0);const l=F6(e,i),c=co(l),d=Mc(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 Px({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 u=i.extent||s;if(i.extent==="parent"&&!i.expandParent)if(!l)a?.("005",Pt.error005());else{const m=l.measured.width,g=l.measured.height;m&&g&&(u=[[c,d],[c+m,d+g]])}else l&&nr(i.extent)&&(u=[[i.extent[0][0]+c,i.extent[0][1]+d],[i.extent[1][0]+c,i.extent[1][1]+d]]);const h=nr(u)?Cn(t,u,i.measured):t;return(i.measured.width===void 0||i.measured.height===void 0)&&a?.("015",Pt.error015()),{position:{x:h.x-c+(i.measured.width??0)*p[0],y:h.y-d+(i.measured.height??0)*p[1]},positionAbsolute:h}}async function j6({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:o,onBeforeDelete:s}){const a=new Set(e.map(h=>h.id)),i=[];for(const h of n){if(h.deletable===!1)continue;const m=a.has(h.id),g=!m&&h.parentId&&i.find(b=>b.id===h.parentId);(m||g)&&i.push(h)}const l=new Set(t.map(h=>h.id)),c=o.filter(h=>h.deletable!==!1),p=z6(i,c);for(const h of c)l.has(h.id)&&!p.find(g=>g.id===h.id)&&p.push(h);if(!s)return{edges:p,nodes:i};const u=await s({nodes:i,edges:p});return typeof u=="boolean"?u?{edges:p,nodes:i}:{edges:[],nodes:[]}:u}const er=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Cn=(e={x:0,y:0},t,n)=>({x:er(e.x,t[0][0],t[1][0]-(n?.width??0)),y:er(e.y,t[0][1],t[1][1]-(n?.height??0))});function Ax(e,t,n){const{width:o,height:s}=Kt(n),{x:a,y:i}=n.internals.positionAbsolute;return Cn(e,[[a,i],[a+o,i+s]],t)}const Bu=(e,t,n)=>e<t?er(Math.abs(e-t),1,t)/t:e>n?-er(Math.abs(e-n),1,t)/t:0,$x=(e,t,n=15,o=40)=>{const s=Bu(e.x,o,t.width-o)*n,a=Bu(e.y,o,t.height-o)*n;return[s,a]},Zs=(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)}),Fi=({x:e,y:t,width:n,height:o})=>({x:e,y:t,x2:e+n,y2:t+o}),Xs=({x:e,y:t,x2:n,y2:o})=>({x:e,y:t,width:n-e,height:o-t}),tr=(e,t=[0,0])=>{const{x:n,y:o}=kc(e)?e.internals.positionAbsolute:lo(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}},bs=(e,t=[0,0])=>{const{x:n,y:o}=kc(e)?e.internals.positionAbsolute:lo(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)}},Dx=(e,t)=>Xs(Zs(Fi(e),Fi(t))),Qr=(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)},zu=e=>ht(e.width)&&ht(e.height)&&ht(e.x)&&ht(e.y),ht=e=>!isNaN(e)&&isFinite(e),V6=(e,t)=>{},uo=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),fo=({x:e,y:t},[n,o,s],a=!1,i=[1,1])=>{const l={x:(e-n)/s,y:(t-o)/s};return a?uo(l,i):l},xs=({x:e,y:t},[n,o,s])=>({x:e*s+n,y:t*s+o});function Rn(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 q6(e,t,n){if(typeof e=="string"||typeof e=="number"){const o=Rn(e,n),s=Rn(e,t);return{top:o,right:s,bottom:o,left:s,x:s*2,y:o*2}}if(typeof e=="object"){const o=Rn(e.top??e.y??0,n),s=Rn(e.bottom??e.y??0,n),a=Rn(e.left??e.x??0,t),i=Rn(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 U6(e,t,n,o,s,a){const{x:i,y:l}=xs(e,[t,n,o]),{x:c,y:d}=xs({x:e.x+e.width,y:e.y+e.height},[t,n,o]),p=s-c,u=a-d;return{left:Math.floor(i),top:Math.floor(l),right:Math.floor(p),bottom:Math.floor(u)}}const Mc=(e,t,n,o,s,a)=>{const i=q6(a,t,n),l=(t-i.x)/e.width,c=(n-i.y)/e.height,d=Math.min(l,c),p=er(d,o,s),u=e.x+e.width/2,h=e.y+e.height/2,m=t/2-u*p,g=n/2-h*p,b=U6(e,m,g,p,t,n),x={left:Math.min(b.left-i.left,0),top:Math.min(b.top-i.top,0),right:Math.min(b.right-i.right,0),bottom:Math.min(b.bottom-i.bottom,0)};return{x:m-x.left+x.right,y:g-x.top+x.bottom,zoom:p}},Gr=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function nr(e){return e!=null&&e!=="parent"}function Kt(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function _x(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function Tx(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 Fu(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function Q6(){let e,t;return{promise:new Promise((o,s)=>{e=o,t=s}),resolve:e,reject:t}}function G6(e){return{...Cx,...e||{}}}function Dr(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:o,containerBounds:s}){const{x:a,y:i}=mt(e),l=fo({x:a-(s?.left??0),y:i-(s?.top??0)},o),{x:c,y:d}=n?uo(l,t):l;return{xSnapped:c,ySnapped:d,...l}}const Ic=e=>({width:e.offsetWidth,height:e.offsetHeight}),Rx=e=>e?.getRootNode?.()||window?.document,W6=["INPUT","SELECT","TEXTAREA"];function Lx(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:W6.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const Ox=e=>"clientX"in e,mt=(e,t)=>{const n=Ox(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)}},Hu=(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,...Ic(i)}})};function Bx({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),u=Math.abs(d-t);return[c,d,p,u]}function To(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function ju({pos:e,x1:t,y1:n,x2:o,y2:s,c:a}){switch(e){case be.Left:return[t-To(t-o,a),n];case be.Right:return[t+To(o-t,a),n];case be.Top:return[t,n-To(n-s,a)];case be.Bottom:return[t,n+To(s-n,a)]}}function zx({sourceX:e,sourceY:t,sourcePosition:n=be.Bottom,targetX:o,targetY:s,targetPosition:a=be.Top,curvature:i=.25}){const[l,c]=ju({pos:n,x1:e,y1:t,x2:o,y2:s,c:i}),[d,p]=ju({pos:a,x1:o,y1:s,x2:e,y2:t,c:i}),[u,h,m,g]=Bx({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}`,u,h,m,g]}function Fx({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 K6({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 Y6({sourceNode:e,targetNode:t,width:n,height:o,transform:s}){const a=Zs(bs(e),bs(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 Qr(i,Xs(a))>0}const Z6=({source:e,sourceHandle:t,target:n,targetHandle:o})=>`xy-edge__${e}${t||""}-${n}${o||""}`,X6=(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)),J6=(e,t,n={})=>{if(!e.source||!e.target)return t;const o=n.getEdgeId||Z6;let s;return Ex(e)?s={...e}:s={...e,id:o(e)},X6(s,t)?t:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,t.concat(s))};function Hx({sourceX:e,sourceY:t,targetX:n,targetY:o}){const[s,a,i,l]=Fx({sourceX:e,sourceY:t,targetX:n,targetY:o});return[`M ${e},${t}L ${n},${o}`,s,a,i,l]}const Vu={[be.Left]:{x:-1,y:0},[be.Right]:{x:1,y:0},[be.Top]:{x:0,y:-1},[be.Bottom]:{x:0,y:1}},eB=({source:e,sourcePosition:t=be.Bottom,target:n})=>t===be.Left||t===be.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},qu=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function tB({source:e,sourcePosition:t=be.Bottom,target:n,targetPosition:o=be.Top,center:s,offset:a,stepPosition:i}){const l=Vu[t],c=Vu[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},u=eB({source:d,sourcePosition:t,target:p}),h=u.x!==0?"x":"y",m=u[h];let g=[],b,x;const y={x:0,y:0},w={x:0,y:0},[,,v,N]=Fx({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(l[h]*c[h]===-1){h==="x"?(b=s.x??d.x+(p.x-d.x)*i,x=s.y??(d.y+p.y)/2):(b=s.x??(d.x+p.x)/2,x=s.y??d.y+(p.y-d.y)*i);const D=[{x:b,y:d.y},{x:b,y:p.y}],E=[{x:d.x,y:x},{x:p.x,y:x}];l[h]===m?g=h==="x"?D:E:g=h==="x"?E:D}else{const D=[{x:d.x,y:p.y}],E=[{x:p.x,y:d.y}];if(h==="x"?g=l.x===m?E:D:g=l.y===m?D:E,t===o){const I=Math.abs(e[h]-n[h]);if(I<=a){const _=Math.min(a-1,a-I);l[h]===m?y[h]=(d[h]>e[h]?-1:1)*_:w[h]=(p[h]>n[h]?-1:1)*_}}if(t!==o){const I=h==="x"?"y":"x",_=l[h]===c[I],P=d[I]>p[I],T=d[I]<p[I];(l[h]===1&&(!_&&P||_&&T)||l[h]!==1&&(!_&&T||_&&P))&&(g=h==="x"?D:E)}const B={x:d.x+y.x,y:d.y+y.y},A={x:p.x+w.x,y:p.y+w.y},O=Math.max(Math.abs(B.x-g[0].x),Math.abs(A.x-g[0].x)),$=Math.max(Math.abs(B.y-g[0].y),Math.abs(A.y-g[0].y));O>=$?(b=(B.x+A.x)/2,x=g[0].y):(b=g[0].x,x=(B.y+A.y)/2)}const S={x:d.x+y.x,y:d.y+y.y},k={x:p.x+w.x,y:p.y+w.y};return[[e,...S.x!==g[0].x||S.y!==g[0].y?[S]:[],...g,...k.x!==g[g.length-1].x||k.y!==g[g.length-1].y?[k]:[],n],b,x,v,N]}function nB(e,t,n,o){const s=Math.min(qu(e,t)/2,qu(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 Hi({sourceX:e,sourceY:t,sourcePosition:n=be.Bottom,targetX:o,targetY:s,targetPosition:a=be.Top,borderRadius:i=5,centerX:l,centerY:c,offset:d=20,stepPosition:p=.5}){const[u,h,m,g,b]=tB({source:{x:e,y:t},sourcePosition:n,target:{x:o,y:s},targetPosition:a,center:{x:l,y:c},offset:d,stepPosition:p});let x=`M${u[0].x} ${u[0].y}`;for(let y=1;y<u.length-1;y++)x+=nB(u[y-1],u[y],u[y+1],i);return x+=`L${u[u.length-1].x} ${u[u.length-1].y}`,[x,h,m,g,b]}function Uu(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function rB(e){const{sourceNode:t,targetNode:n}=e;if(!Uu(t)||!Uu(n))return null;const o=t.internals.handleBounds||Qu(t.handles),s=n.internals.handleBounds||Qu(n.handles),a=Gu(o?.source??[],e.sourceHandle),i=Gu(e.connectionMode===Jn.Strict?s?.target??[]:(s?.target??[]).concat(s?.source??[]),e.targetHandle);if(!a||!i)return e.onError?.("008",Pt.error008(a?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=a?.position||be.Bottom,c=i?.position||be.Top,d=Mn(t,a,l),p=Mn(n,i,c);return{sourceX:d.x,sourceY:d.y,targetX:p.x,targetY:p.y,sourcePosition:l,targetPosition:c}}function Qu(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 Mn(e,t,n=be.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??Kt(e);if(o)return{x:s+i/2,y:a+l/2};switch(t?.position??n){case be.Top:return{x:s+i/2,y:a};case be.Right:return{x:s+i,y:a+l/2};case be.Bottom:return{x:s+i/2,y:a+l};case be.Left:return{x:s,y:a+l/2}}}function Gu(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function ji(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(o=>`${o}=${e[o]}`).join("&")}`:""}function oB(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=ji(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 jx=1e3,sB=10,Ec={nodeOrigin:[0,0],nodeExtent:qr,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},aB={...Ec,checkEquality:!0};function Pc(e,t){const n={...e};for(const o in t)t[o]!==void 0&&(n[o]=t[o]);return n}function iB(e,t,n){const o=Pc(Ec,n);for(const s of e.values())if(s.parentId)$c(s,e,t,o);else{const a=lo(s,o.nodeOrigin),i=nr(s.extent)?s.extent:o.nodeExtent,l=Cn(a,i,Kt(s));s.internals.positionAbsolute=l}}function lB(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 Ac(e){return e==="manual"}function Vi(e,t,n,o={}){const s=Pc(aB,o),a={i:0},i=new Map(t),l=s?.elevateNodesOnSelect&&!Ac(s.zIndexMode)?jx:0;let c=e.length>0,d=!1;t.clear(),n.clear();for(const p of e){let u=i.get(p.id);if(s.checkEquality&&p===u?.internals.userNode)t.set(p.id,u);else{const h=lo(p,s.nodeOrigin),m=nr(p.extent)?p.extent:s.nodeExtent,g=Cn(h,m,Kt(p));u={...s.defaults,...p,measured:{width:p.measured?.width,height:p.measured?.height},internals:{positionAbsolute:g,handleBounds:lB(p,u),z:Vx(p,l,s.zIndexMode),userNode:p}},t.set(p.id,u)}(u.measured===void 0||u.measured.width===void 0||u.measured.height===void 0)&&!u.hidden&&(c=!1),p.parentId&&$c(u,t,n,o,a),d||=p.selected??!1}return{nodesInitialized:c,hasSelectedNodes:d}}function cB(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 $c(e,t,n,o,s){const{elevateNodesOnSelect:a,nodeOrigin:i,nodeExtent:l,zIndexMode:c}=Pc(Ec,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}cB(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*sB),s&&p.internals.rootParentIndex!==void 0&&(s.i=p.internals.rootParentIndex);const u=a&&!Ac(c)?jx:0,{x:h,y:m,z:g}=dB(e,p,i,l,u,c),{positionAbsolute:b}=e.internals,x=h!==b.x||m!==b.y;(x||g!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:x?{x:h,y:m}:b,z:g}})}function Vx(e,t,n){const o=ht(e.zIndex)?e.zIndex:0;return Ac(n)?o:o+(e.selected?t:0)}function dB(e,t,n,o,s,a){const{x:i,y:l}=t.internals.positionAbsolute,c=Kt(e),d=lo(e,n),p=nr(e.extent)?Cn(d,e.extent,c):d;let u=Cn({x:i+p.x,y:l+p.y},o,c);e.extent==="parent"&&(u=Ax(u,c,t));const h=Vx(e,s,a),m=t.internals.z??0;return{x:u.x,y:u.y,z:m>=h?m+1:h}}function Dc(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??tr(l),d=Dx(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=Kt(l),u=l.origin??o,h=i.x<d.x?Math.round(Math.abs(d.x-i.x)):0,m=i.y<d.y?Math.round(Math.abs(d.y-i.y)):0,g=Math.max(p.width,Math.round(i.width)),b=Math.max(p.height,Math.round(i.height)),x=(g-p.width)*u[0],y=(b-p.height)*u[1];(h>0||m>0||x||y)&&(s.push({id:c,type:"position",position:{x:l.position.x-h+x,y:l.position.y-m+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+h,y:w.position.y+m}})})),(p.width<i.width||p.height<i.height||h||m)&&s.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:g+(h?u[0]*h-x:0),height:b+(m?u[1]*m-y:0)}})}),s}function uB(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:u}=new window.DOMMatrixReadOnly(p.transform),h=[];for(const m of e.values()){const g=t.get(m.id);if(!g)continue;if(g.hidden){t.set(g.id,{...g,internals:{...g.internals,handleBounds:void 0}}),c=!0;continue}const b=Ic(m.nodeElement),x=g.measured.width!==b.width||g.measured.height!==b.height;if(!!(b.width&&b.height&&(x||!g.internals.handleBounds||m.force))){const w=m.nodeElement.getBoundingClientRect(),v=nr(g.extent)?g.extent:a;let{positionAbsolute:N}=g.internals;g.parentId&&g.extent==="parent"?N=Ax(N,b,t.get(g.parentId)):v&&(N=Cn(N,v,b));const S={...g,measured:b,internals:{...g.internals,positionAbsolute:N,handleBounds:{source:Hu("source",m.nodeElement,w,u,g.id),target:Hu("target",m.nodeElement,w,u,g.id)}}};t.set(g.id,S),g.parentId&&$c(S,t,n,{nodeOrigin:s,zIndexMode:i}),c=!0,x&&(d.push({id:g.id,type:"dimensions",dimensions:b}),g.expandParent&&g.parentId&&h.push({id:g.id,parentId:g.parentId,rect:tr(S,s)}))}}if(h.length>0){const m=Dc(h,t,n,s);d.push(...m)}return{changes:d,updatedInternals:c}}async function fB({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 Wu(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 qx(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}`;Wu("source",c,p,e,s,i),Wu("target",c,d,e,a,l),t.set(o.id,o)}}function Ux(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:Ux(n,t):!1}function Ku(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 pB(e,t,n,o){const s=new Map;for(const[a,i]of e)if((i.selected||i.id===o)&&(!i.parentId||!Ux(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 Qa({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 hB({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=uo(a,t);return{x:i.x-a.x,y:i.y-a.y}}function mB({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,u=!1,h=null,m=!1,g=!1,b=null;function x({noDragClassName:w,handleSelector:v,domNode:N,isSelectable:S,nodeId:k,nodeClickDistance:M=0}){h=Xe(N);function D({x:O,y:$}){const{nodeLookup:I,nodeExtent:_,snapGrid:P,snapToGrid:T,nodeOrigin:R,onNodeDrag:z,onSelectionDrag:H,onError:F,updateNodePositions:j}=t();a={x:O,y:$};let J=!1;const W=l.size>1,ne=W&&_?Fi(co(l)):null,de=W&&T?hB({dragItems:l,snapGrid:P,x:O,y:$}):null;for(const[te,K]of l){if(!I.has(te))continue;let oe={x:O-K.distance.x,y:$-K.distance.y};T&&(oe=de?{x:Math.round(oe.x+de.x),y:Math.round(oe.y+de.y)}:uo(oe,P));let me=null;if(W&&_&&!K.extent&&ne){const{positionAbsolute:Z}=K.internals,re=Z.x-ne.x+_[0][0],pe=Z.x+K.measured.width-ne.x2+_[1][0],he=Z.y-ne.y+_[0][1],V=Z.y+K.measured.height-ne.y2+_[1][1];me=[[re,he],[pe,V]]}const{position:Y,positionAbsolute:G}=Px({nodeId:te,nextPosition:oe,nodeLookup:I,nodeExtent:me||_,nodeOrigin:R,onError:F});J=J||K.position.x!==Y.x||K.position.y!==Y.y,K.position=Y,K.internals.positionAbsolute=G}if(g=g||J,!!J&&(j(l,!0),b&&(o||z||!k&&H))){const[te,K]=Qa({nodeId:k,dragItems:l,nodeLookup:I});o?.(b,l,te,K),z?.(b,te,K),k||H?.(b,K)}}async function E(){if(!p)return;const{transform:O,panBy:$,autoPanSpeed:I,autoPanOnNodeDrag:_}=t();if(!_){c=!1,cancelAnimationFrame(i);return}const[P,T]=$x(d,p,I);(P!==0||T!==0)&&(a.x=(a.x??0)-P/O[2],a.y=(a.y??0)-T/O[2],await $({x:P,y:T})&&D(a)),i=requestAnimationFrame(E)}function B(O){const{nodeLookup:$,multiSelectionActive:I,nodesDraggable:_,transform:P,snapGrid:T,snapToGrid:R,selectNodesOnDrag:z,onNodeDragStart:H,onSelectionDragStart:F,unselectNodesAndEdges:j}=t();u=!0,(!z||!S)&&!I&&k&&($.get(k)?.selected||j()),S&&z&&k&&e?.(k);const J=Dr(O.sourceEvent,{transform:P,snapGrid:T,snapToGrid:R,containerBounds:p});if(a=J,l=pB($,_,J,k),l.size>0&&(n||H||!k&&F)){const[W,ne]=Qa({nodeId:k,dragItems:l,nodeLookup:$});n?.(O.sourceEvent,l,W,ne),H?.(O.sourceEvent,W,ne),k||F?.(O.sourceEvent,ne)}}const A=lx().clickDistance(M).on("start",O=>{const{domNode:$,nodeDragThreshold:I,transform:_,snapGrid:P,snapToGrid:T}=t();p=$?.getBoundingClientRect()||null,m=!1,g=!1,b=O.sourceEvent,I===0&&B(O),a=Dr(O.sourceEvent,{transform:_,snapGrid:P,snapToGrid:T,containerBounds:p}),d=mt(O.sourceEvent,p)}).on("drag",O=>{const{autoPanOnNodeDrag:$,transform:I,snapGrid:_,snapToGrid:P,nodeDragThreshold:T,nodeLookup:R}=t(),z=Dr(O.sourceEvent,{transform:I,snapGrid:_,snapToGrid:P,containerBounds:p});if(b=O.sourceEvent,(O.sourceEvent.type==="touchmove"&&O.sourceEvent.touches.length>1||k&&!R.has(k))&&(m=!0),!m){if(!c&&$&&u&&(c=!0,E()),!u){const H=mt(O.sourceEvent,p),F=H.x-d.x,j=H.y-d.y;Math.sqrt(F*F+j*j)>T&&B(O)}(a.x!==z.xSnapped||a.y!==z.ySnapped)&&l&&u&&(d=mt(O.sourceEvent,p),D(z))}}).on("end",O=>{if(!(!u||m)&&(c=!1,u=!1,cancelAnimationFrame(i),l.size>0)){const{nodeLookup:$,updateNodePositions:I,onNodeDragStop:_,onSelectionDragStop:P}=t();if(g&&(I(l,!1),g=!1),s||_||!k&&P){const[T,R]=Qa({nodeId:k,dragItems:l,nodeLookup:$,dragging:!1});s?.(O.sourceEvent,l,T,R),_?.(O.sourceEvent,T,R),k||P?.(O.sourceEvent,R)}}}).filter(O=>{const $=O.target;return!O.button&&(!w||!Ku($,`.${w}`,N))&&(!v||Ku($,v,N))});h.call(A)}function y(){h?.on(".drag",null)}return{update:x,destroy:y}}function gB(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())Qr(s,tr(a))>0&&o.push(a);return o}const bB=250;function xB(e,t,n,o){let s=[],a=1/0;const i=gB(e,n,t+bB);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:u}=Mn(l,d,d.position,!0),h=Math.sqrt(Math.pow(p-e.x,2)+Math.pow(u-e.y,2));h>t||(h<a?(s=[{...d,x:p,y:u}],a=h):h===a&&s.push({...d,x:p,y:u}))}}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 Qx(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,...Mn(i,c,c.position,!0)}:c}function Gx(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function yB(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const Wx=()=>!0;function vB(e,{connectionMode:t,connectionRadius:n,handleId:o,nodeId:s,edgeUpdaterType:a,isTarget:i,domNode:l,nodeLookup:c,lib:d,autoPanOnConnect:p,flowId:u,panBy:h,cancelConnection:m,onConnectStart:g,onConnect:b,onConnectEnd:x,isValidConnection:y=Wx,onReconnectEnd:w,updateConnection:v,getTransform:N,getFromHandle:S,autoPanSpeed:k,dragThreshold:M=1,handleDomNode:D}){const E=Rx(e.target);let B=0,A;const{x:O,y:$}=mt(e),I=Gx(a,D),_=l?.getBoundingClientRect();let P=!1;if(!_||!I)return;const T=Qx(s,I,o,c,t);if(!T)return;let R=mt(e,_),z=!1,H=null,F=!1,j=null;function J(){if(!p||!_)return;const[Y,G]=$x(R,_,k);h({x:Y,y:G}),B=requestAnimationFrame(J)}const W={...T,nodeId:s,type:I,position:T.position},ne=c.get(s);let te={inProgress:!0,isValid:null,from:Mn(ne,W,be.Left,!0),fromHandle:W,fromPosition:W.position,fromNode:ne,to:R,toHandle:null,toPosition:Ou[W.position],toNode:null,pointer:R};function K(){P=!0,v(te),g?.(e,{nodeId:s,handleId:o,handleType:I})}M===0&&K();function oe(Y){if(!P){const{x:V,y:se}=mt(Y),ce=V-O,ie=se-$;if(!(ce*ce+ie*ie>M*M))return;K()}if(!S()||!W){me(Y);return}const G=N();R=mt(Y,_),A=xB(fo(R,G,!1,[1,1]),n,c,W),z||(J(),z=!0);const Z=Kx(Y,{handle:A,connectionMode:t,fromNodeId:s,fromHandleId:o,fromType:i?"target":"source",isValidConnection:y,doc:E,lib:d,flowId:u,nodeLookup:c});j=Z.handleDomNode,H=Z.connection,F=yB(!!A,Z.isValid);const re=c.get(s),pe=re?Mn(re,W,be.Left,!0):te.from,he={...te,from:pe,isValid:F,to:Z.toHandle&&F?xs({x:Z.toHandle.x,y:Z.toHandle.y},G):R,toHandle:Z.toHandle,toPosition:F&&Z.toHandle?Z.toHandle.position:Ou[W.position],toNode:Z.toHandle?c.get(Z.toHandle.nodeId):null,pointer:R};v(he),te=he}function me(Y){if(!("touches"in Y&&Y.touches.length>0)){if(P){(A||j)&&H&&F&&b?.(H);const{inProgress:G,...Z}=te,re={...Z,toPosition:te.toHandle?te.toPosition:null};x?.(Y,re),a&&w?.(Y,re)}m(),cancelAnimationFrame(B),z=!1,F=!1,H=null,j=null,E.removeEventListener("mousemove",oe),E.removeEventListener("mouseup",me),E.removeEventListener("touchmove",oe),E.removeEventListener("touchend",me)}}E.addEventListener("mousemove",oe),E.addEventListener("mouseup",me),E.addEventListener("touchmove",oe),E.addEventListener("touchend",me)}function Kx(e,{handle:t,connectionMode:n,fromNodeId:o,fromHandleId:s,fromType:a,doc:i,lib:l,flowId:c,isValidConnection:d=Wx,nodeLookup:p}){const u=a==="target",h=t?i.querySelector(`.${l}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:m,y:g}=mt(e),b=i.elementFromPoint(m,g),x=b?.classList.contains(`${l}-flow__handle`)?b:h,y={handleDomNode:x,isValid:!1,connection:null,toHandle:null};if(x){const w=Gx(void 0,x),v=x.getAttribute("data-nodeid"),N=x.getAttribute("data-handleid"),S=x.classList.contains("connectable"),k=x.classList.contains("connectableend");if(!v||!w)return y;const M={source:u?v:o,sourceHandle:u?N:s,target:u?o:v,targetHandle:u?s:N};y.connection=M;const E=S&&k&&(n===Jn.Strict?u&&w==="source"||!u&&w==="target":v!==o||N!==s);y.isValid=E&&d(M),y.toHandle=Qx(v,w,N,p,n,!0)}return y}const qi={onPointerDown:vB,isValid:Kx};function wB({domNode:e,panZoom:t,getTransform:n,getViewScale:o}){const s=Xe(e);function a({translateExtent:l,width:c,height:d,zoomStep:p=1,pannable:u=!0,zoomable:h=!0,inversePan:m=!1}){const g=v=>{if(v.sourceEvent.type!=="wheel"||!t)return;const N=n(),S=v.sourceEvent.ctrlKey&&Gr()?10:1,k=-v.sourceEvent.deltaY*(v.sourceEvent.deltaMode===1?.05:v.sourceEvent.deltaMode?1:.002)*p,M=N[2]*Math.pow(2,k*S);t.scaleTo(M)};let b=[0,0];const x=v=>{(v.sourceEvent.type==="mousedown"||v.sourceEvent.type==="touchstart")&&(b=[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 S=[v.sourceEvent.clientX??v.sourceEvent.touches[0].clientX,v.sourceEvent.clientY??v.sourceEvent.touches[0].clientY],k=[S[0]-b[0],S[1]-b[1]];b=S;const M=o()*Math.max(N[2],Math.log(N[2]))*(m?-1:1),D={x:N[0]-k[0]*M,y:N[1]-k[1]*M},E=[[0,0],[c,d]];t.setViewportConstrained({x:D.x,y:D.y,zoom:N[2]},E,l)},w=Sx().on("start",x).on("zoom",u?y:null).on("zoom.wheel",h?g:null);s.call(w,{})}function i(){s.on("zoom",null)}return{update:a,destroy:i,pointer:ft}}const Js=e=>({x:e.x,y:e.y,zoom:e.k}),Ga=({x:e,y:t,zoom:n})=>Ys.translate(e,t).scale(n),On=(e,t)=>e.target.closest(`.${t}`),Yx=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),NB=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Wa=(e,t=0,n=NB,o=()=>{})=>{const s=typeof t=="number"&&t>0;return s||o(),s?e.transition().duration(t).ease(n).on("end",o):e},Zx=e=>{const t=e.ctrlKey&&Gr()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function SB({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:o,panOnScrollMode:s,panOnScrollSpeed:a,zoomOnPinch:i,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:d}){return p=>{if(On(p,t))return p.ctrlKey&&p.preventDefault(),!1;p.preventDefault(),p.stopImmediatePropagation();const u=n.property("__zoom").k||1;if(p.ctrlKey&&i){const x=ft(p),y=Zx(p),w=u*Math.pow(2,y);o.scaleTo(n,w,x,p);return}const h=p.deltaMode===1?20:1;let m=s===xn.Vertical?0:p.deltaX*h,g=s===xn.Horizontal?0:p.deltaY*h;!Gr()&&p.shiftKey&&s!==xn.Vertical&&(m=p.deltaY*h,g=0),o.translateBy(n,-(m/u)*a,-(g/u)*a,{internal:!0});const b=Js(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(p,b),e.panScrollTimeout=setTimeout(()=>{d?.(p,b),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(p,b))}}function kB({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(o,s){const a=o.type==="wheel",i=!t&&a&&!o.ctrlKey,l=On(o,e);if(o.ctrlKey&&a&&l&&o.preventDefault(),i||l)return null;o.preventDefault(),n.call(this,o,s)}}function CB({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return o=>{if(o.sourceEvent?.internal)return;const s=Js(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 MB({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:o,onPanZoom:s}){return a=>{e.usedRightMouseButton=!!(n&&Yx(t,e.mouseButton??0)),a.sourceEvent?.sync||o([a.transform.x,a.transform.y,a.transform.k]),s&&!a.sourceEvent?.internal&&s?.(a.sourceEvent,Js(a.transform))}}function IB({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:o,onPanZoomEnd:s,onPaneContextMenu:a}){return i=>{if(!i.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&Yx(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&a(i.sourceEvent),e.usedRightMouseButton=!1,o(!1),s)){const l=Js(i.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s?.(i.sourceEvent,l)},n?150:0)}}}function EB({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:o,panOnScroll:s,zoomOnDoubleClick:a,userSelectionActive:i,noWheelClassName:l,noPanClassName:c,lib:d,connectionInProgress:p}){return u=>{const h=e||t,m=n&&u.ctrlKey,g=u.type==="wheel";if(u.button===1&&u.type==="mousedown"&&(On(u,`${d}-flow__node`)||On(u,`${d}-flow__edge`)))return!0;if(!o&&!h&&!s&&!a&&!n||i||p&&!g||On(u,l)&&g||On(u,c)&&(!g||s&&g&&!e)||!n&&u.ctrlKey&&g)return!1;if(!n&&u.type==="touchstart"&&u.touches?.length>1)return u.preventDefault(),!1;if(!h&&!s&&!m&&g||!o&&(u.type==="mousedown"||u.type==="touchstart")||Array.isArray(o)&&!o.includes(u.button)&&u.type==="mousedown")return!1;const b=Array.isArray(o)&&o.includes(u.button)||!u.button||u.button<=1;return(!u.ctrlKey||g)&&b}}function PB({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(),u=Sx().scaleExtent([t,n]).translateExtent(o),h=Xe(e).call(u);w({x:s.x,y:s.y,zoom:er(s.zoom,t,n)},[[0,0],[p.width,p.height]],o);const m=h.on("wheel.zoom"),g=h.on("dblclick.zoom");u.wheelDelta(Zx);function b(A,O){return h?new Promise($=>{u?.interpolate(O?.interpolate==="linear"?$r:Vo).transform(Wa(h,O?.duration,O?.ease,()=>$(!0)),A)}):Promise.resolve(!1)}function x({noWheelClassName:A,noPanClassName:O,onPaneContextMenu:$,userSelectionActive:I,panOnScroll:_,panOnDrag:P,panOnScrollMode:T,panOnScrollSpeed:R,preventScrolling:z,zoomOnPinch:H,zoomOnScroll:F,zoomOnDoubleClick:j,zoomActivationKeyPressed:J,lib:W,onTransformChange:ne,connectionInProgress:de,paneClickDistance:te,selectionOnDrag:K}){I&&!d.isZoomingOrPanning&&y();const oe=_&&!J&&!I;u.clickDistance(K?1/0:!ht(te)||te<0?0:te);const me=oe?SB({zoomPanValues:d,noWheelClassName:A,d3Selection:h,d3Zoom:u,panOnScrollMode:T,panOnScrollSpeed:R,zoomOnPinch:H,onPanZoomStart:i,onPanZoom:a,onPanZoomEnd:l}):kB({noWheelClassName:A,preventScrolling:z,d3ZoomHandler:m});if(h.on("wheel.zoom",me,{passive:!1}),!I){const G=CB({zoomPanValues:d,onDraggingChange:c,onPanZoomStart:i});u.on("start",G);const Z=MB({zoomPanValues:d,panOnDrag:P,onPaneContextMenu:!!$,onPanZoom:a,onTransformChange:ne});u.on("zoom",Z);const re=IB({zoomPanValues:d,panOnDrag:P,panOnScroll:_,onPaneContextMenu:$,onPanZoomEnd:l,onDraggingChange:c});u.on("end",re)}const Y=EB({zoomActivationKeyPressed:J,panOnDrag:P,zoomOnScroll:F,panOnScroll:_,zoomOnDoubleClick:j,zoomOnPinch:H,userSelectionActive:I,noPanClassName:O,noWheelClassName:A,lib:W,connectionInProgress:de});u.filter(Y),j?h.on("dblclick.zoom",g):h.on("dblclick.zoom",null)}function y(){u.on("zoom",null)}async function w(A,O,$){const I=Ga(A),_=u?.constrain()(I,O,$);return _&&await b(_),new Promise(P=>P(_))}async function v(A,O){const $=Ga(A);return await b($,O),new Promise(I=>I($))}function N(A){if(h){const O=Ga(A),$=h.property("__zoom");($.k!==A.zoom||$.x!==A.x||$.y!==A.y)&&u?.transform(h,O,null,{sync:!0})}}function S(){const A=h?Nx(h.node()):{x:0,y:0,k:1};return{x:A.x,y:A.y,zoom:A.k}}function k(A,O){return h?new Promise($=>{u?.interpolate(O?.interpolate==="linear"?$r:Vo).scaleTo(Wa(h,O?.duration,O?.ease,()=>$(!0)),A)}):Promise.resolve(!1)}function M(A,O){return h?new Promise($=>{u?.interpolate(O?.interpolate==="linear"?$r:Vo).scaleBy(Wa(h,O?.duration,O?.ease,()=>$(!0)),A)}):Promise.resolve(!1)}function D(A){u?.scaleExtent(A)}function E(A){u?.translateExtent(A)}function B(A){const O=!ht(A)||A<0?0:A;u?.clickDistance(O)}return{update:x,destroy:y,setViewport:v,setViewportConstrained:w,getViewport:S,scaleTo:k,scaleBy:M,setScaleExtent:D,setTranslateExtent:E,syncViewport:N,setClickDistance:B}}var rr;(function(e){e.Line="line",e.Handle="handle"})(rr||(rr={}));function AB({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 Yu(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 Yt(e,t){return Math.max(0,t-e)}function Zt(e,t){return Math.max(0,e-t)}function Ro(e,t,n){return Math.max(0,t-e,e-n)}function Zu(e,t){return e?!t:t}function $B(e,t,n,o,s,a,i,l){let{affectsX:c,affectsY:d}=t;const{isHorizontal:p,isVertical:u}=t,h=p&&u,{xSnapped:m,ySnapped:g}=n,{minWidth:b,maxWidth:x,minHeight:y,maxHeight:w}=o,{x:v,y:N,width:S,height:k,aspectRatio:M}=e;let D=Math.floor(p?m-e.pointerX:0),E=Math.floor(u?g-e.pointerY:0);const B=S+(c?-D:D),A=k+(d?-E:E),O=-a[0]*S,$=-a[1]*k;let I=Ro(B,b,x),_=Ro(A,y,w);if(i){let R=0,z=0;c&&D<0?R=Yt(v+D+O,i[0][0]):!c&&D>0&&(R=Zt(v+B+O,i[1][0])),d&&E<0?z=Yt(N+E+$,i[0][1]):!d&&E>0&&(z=Zt(N+A+$,i[1][1])),I=Math.max(I,R),_=Math.max(_,z)}if(l){let R=0,z=0;c&&D>0?R=Zt(v+D,l[0][0]):!c&&D<0&&(R=Yt(v+B,l[1][0])),d&&E>0?z=Zt(N+E,l[0][1]):!d&&E<0&&(z=Yt(N+A,l[1][1])),I=Math.max(I,R),_=Math.max(_,z)}if(s){if(p){const R=Ro(B/M,y,w)*M;if(I=Math.max(I,R),i){let z=0;!c&&!d||c&&!d&&h?z=Zt(N+$+B/M,i[1][1])*M:z=Yt(N+$+(c?D:-D)/M,i[0][1])*M,I=Math.max(I,z)}if(l){let z=0;!c&&!d||c&&!d&&h?z=Yt(N+B/M,l[1][1])*M:z=Zt(N+(c?D:-D)/M,l[0][1])*M,I=Math.max(I,z)}}if(u){const R=Ro(A*M,b,x)/M;if(_=Math.max(_,R),i){let z=0;!c&&!d||d&&!c&&h?z=Zt(v+A*M+O,i[1][0])/M:z=Yt(v+(d?E:-E)*M+O,i[0][0])/M,_=Math.max(_,z)}if(l){let z=0;!c&&!d||d&&!c&&h?z=Yt(v+A*M,l[1][0])/M:z=Zt(v+(d?E:-E)*M,l[0][0])/M,_=Math.max(_,z)}}}E=E+(E<0?_:-_),D=D+(D<0?I:-I),s&&(h?B>A*M?E=(Zu(c,d)?-D:D)/M:D=(Zu(c,d)?-E:E)*M:p?(E=D/M,d=c):(D=E*M,c=d));const P=c?v+D:v,T=d?N+E:N;return{width:S+(c?-D:D),height:k+(d?-E:E),x:a[0]*D*(c?-1:1)+P,y:a[1]*E*(d?-1:1)+T}}const Xx={width:0,height:0,x:0,y:0},DB={...Xx,pointerX:0,pointerY:0,aspectRatio:1};function _B(e){return[[0,0],[e.measured.width,e.measured.height]]}function TB(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 RB({domNode:e,nodeId:t,getStoreItems:n,onChange:o,onEnd:s}){const a=Xe(e);let i={controlDirection:Yu("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:u,resizeDirection:h,onResizeStart:m,onResize:g,onResizeEnd:b,shouldResize:x}){let y={...Xx},w={...DB};i={boundaries:p,resizeDirection:h,keepAspectRatio:u,controlDirection:Yu(d)};let v,N=null,S=[],k,M,D,E=!1;const B=lx().on("start",A=>{const{nodeLookup:O,transform:$,snapGrid:I,snapToGrid:_,nodeOrigin:P,paneDomNode:T}=n();if(v=O.get(t),!v)return;N=T?.getBoundingClientRect()??null;const{xSnapped:R,ySnapped:z}=Dr(A.sourceEvent,{transform:$,snapGrid:I,snapToGrid:_,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:R,pointerY:z,aspectRatio:y.width/y.height},k=void 0,v.parentId&&(v.extent==="parent"||v.expandParent)&&(k=O.get(v.parentId),M=k&&v.extent==="parent"?_B(k):void 0),S=[],D=void 0;for(const[H,F]of O)if(F.parentId===t&&(S.push({id:H,position:{...F.position},extent:F.extent}),F.extent==="parent"||F.expandParent)){const j=TB(F,v,F.origin??P);D?D=[[Math.min(j[0][0],D[0][0]),Math.min(j[0][1],D[0][1])],[Math.max(j[1][0],D[1][0]),Math.max(j[1][1],D[1][1])]]:D=j}m?.(A,{...y})}).on("drag",A=>{const{transform:O,snapGrid:$,snapToGrid:I,nodeOrigin:_}=n(),P=Dr(A.sourceEvent,{transform:O,snapGrid:$,snapToGrid:I,containerBounds:N}),T=[];if(!v)return;const{x:R,y:z,width:H,height:F}=y,j={},J=v.origin??_,{width:W,height:ne,x:de,y:te}=$B(w,i.controlDirection,P,i.boundaries,i.keepAspectRatio,J,M,D),K=W!==H,oe=ne!==F,me=de!==R&&K,Y=te!==z&&oe;if(!me&&!Y&&!K&&!oe)return;if((me||Y||J[0]===1||J[1]===1)&&(j.x=me?de:y.x,j.y=Y?te:y.y,y.x=j.x,y.y=j.y,S.length>0)){const pe=de-R,he=te-z;for(const V of S)V.position={x:V.position.x-pe+J[0]*(W-H),y:V.position.y-he+J[1]*(ne-F)},T.push(V)}if((K||oe)&&(j.width=K&&(!i.resizeDirection||i.resizeDirection==="horizontal")?W:y.width,j.height=oe&&(!i.resizeDirection||i.resizeDirection==="vertical")?ne:y.height,y.width=j.width,y.height=j.height),k&&v.expandParent){const pe=J[0]*(j.width??0);j.x&&j.x<pe&&(y.x=pe,w.x=w.x-(j.x-pe));const he=J[1]*(j.height??0);j.y&&j.y<he&&(y.y=he,w.y=w.y-(j.y-he))}const G=AB({width:y.width,prevWidth:H,height:y.height,prevHeight:F,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),Z={...y,direction:G};x?.(A,Z)!==!1&&(E=!0,g?.(A,Z),o(j,T))}).on("end",A=>{E&&(b?.(A,{...y}),s?.({...y}),E=!1)});a.call(B)}function c(){a.on(".drag",null)}return{update:l,destroy:c}}var Jx={exports:{}},e0={};/**
520
- * @license React
521
- * use-sync-external-store-shim/with-selector.production.js
522
- *
523
- * Copyright (c) Meta Platforms, Inc. and affiliates.
524
- *
525
- * This source code is licensed under the MIT license found in the
526
- * LICENSE file in the root directory of this source tree.
527
- */var ea=ip,LB=Mb;function OB(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var BB=typeof Object.is=="function"?Object.is:OB,zB=LB.useSyncExternalStore,FB=ea.useRef,HB=ea.useEffect,jB=ea.useMemo,VB=ea.useDebugValue;e0.useSyncExternalStoreWithSelector=function(e,t,n,o,s){var a=FB(null);if(a.current===null){var i={hasValue:!1,value:null};a.current=i}else i=a.current;a=jB(function(){function c(m){if(!d){if(d=!0,p=m,m=o(m),s!==void 0&&i.hasValue){var g=i.value;if(s(g,m))return u=g}return u=m}if(g=u,BB(p,m))return g;var b=o(m);return s!==void 0&&s(g,b)?(p=m,g):(p=m,u=b)}var d=!1,p,u,h=n===void 0?null:n;return[function(){return c(t())},h===null?void 0:function(){return c(h())}]},[t,n,o,s]);var l=zB(e,a[0],a[1]);return HB(function(){i.hasValue=!0,i.value=l},[l]),VB(l),l};Jx.exports=e0;var qB=Jx.exports;const UB=Dy(qB),QB={},Xu=e=>{let t;const n=new Set,o=(p,u)=>{const h=typeof p=="function"?p(t):p;if(!Object.is(h,t)){const m=t;t=u??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(g=>g(t,m))}},s=()=>t,c={setState:o,getState:s,getInitialState:()=>d,subscribe:p=>(n.add(p),()=>n.delete(p)),destroy:()=>{(QB?"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},GB=e=>e?Xu(e):Xu,{useDebugValue:WB}=Wi,{useSyncExternalStoreWithSelector:KB}=UB,YB=e=>e;function t0(e,t=YB,n){const o=KB(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return WB(o),o}const Ju=(e,t)=>{const n=GB(e),o=(s,a=t)=>t0(n,s,a);return Object.assign(o,n),o},ZB=(e,t)=>e?Ju(e,t):Ju;function _e(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 ta=$e(null),XB=ta.Provider,n0=Pt.error001();function Me(e,t){const n=ge(ta);if(n===null)throw new Error(n0);return t0(n,e,t)}function Re(){const e=ge(ta);if(e===null)throw new Error(n0);return Q(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const ef={display:"none"},JB={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},r0="react-flow__node-desc",o0="react-flow__edge-desc",e8="react-flow__aria-live",t8=e=>e.ariaLiveMessage,n8=e=>e.ariaLabelConfig;function r8({rfId:e}){const t=Me(t8);return r("div",{id:`${e8}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:JB,children:t})}function o8({rfId:e,disableKeyboardA11y:t}){const n=Me(n8);return f(ye,{children:[r("div",{id:`${r0}-${e}`,style:ef,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),r("div",{id:`${o0}-${e}`,style:ef,children:n["edge.a11yDescription.default"]}),!t&&r(r8,{rfId:e})]})}const na=Oe(({position:e="top-left",children:t,className:n,style:o,...s},a)=>{const i=`${e}`.split("-");return r("div",{className:ze(["react-flow__panel",n,...i]),style:o,ref:a,...s,children:t})});na.displayName="Panel";function s8({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:r(na,{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 a8=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}},Lo=e=>e.id;function i8(e,t){return _e(e.selectedNodes.map(Lo),t.selectedNodes.map(Lo))&&_e(e.selectedEdges.map(Lo),t.selectedEdges.map(Lo))}function l8({onSelectionChange:e}){const t=Re(),{selectedNodes:n,selectedEdges:o}=Me(a8,i8);return X(()=>{const s={nodes:n,edges:o};e?.(s),t.getState().onSelectionChangeHandlers.forEach(a=>a(s))},[n,o,e]),null}const c8=e=>!!e.onSelectionChangeHandlers;function d8({onSelectionChange:e}){const t=Me(c8);return e||t?r(l8,{onSelectionChange:e}):null}const Ui=typeof window<"u"?vs:X,s0=[0,0],u8={x:0,y:0,zoom:1},f8=["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"],tf=[...f8,"rfId"],p8=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}),nf={translateExtent:qr,nodeOrigin:s0,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function h8(e){const{setNodes:t,setEdges:n,setMinZoom:o,setMaxZoom:s,setTranslateExtent:a,setNodeExtent:i,reset:l,setDefaultNodesAndEdges:c}=Me(p8,_e),d=Re();Ui(()=>(c(e.defaultNodes,e.defaultEdges),()=>{p.current=nf,l()}),[]);const p=ee(nf);return Ui(()=>{for(const u of tf){const h=e[u],m=p.current[u];h!==m&&(typeof e[u]>"u"||(u==="nodes"?t(h):u==="edges"?n(h):u==="minZoom"?o(h):u==="maxZoom"?s(h):u==="translateExtent"?a(h):u==="nodeExtent"?i(h):u==="ariaLabelConfig"?d.setState({ariaLabelConfig:G6(h)}):u==="fitView"?d.setState({fitViewQueued:h}):u==="fitViewOptions"?d.setState({fitViewOptions:h}):d.setState({[u]:h})))}p.current=e},tf.map(u=>e[u])),null}function rf(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function m8(e){const[t,n]=L(e==="system"?null:e);return X(()=>{if(e!=="system"){n(e);return}const o=rf(),s=()=>n(o?.matches?"dark":"light");return s(),o?.addEventListener("change",s),()=>{o?.removeEventListener("change",s)}},[e]),t!==null?t:rf()?.matches?"dark":"light"}const of=typeof document<"u"?document:null;function Wr(e=null,t={target:of,actInsideInputWithModifier:!0}){const[n,o]=L(!1),s=ee(!1),a=ee(new Set([])),[i,l]=Q(()=>{if(e!==null){const d=(Array.isArray(e)?e:[e]).filter(u=>typeof u=="string").map(u=>u.replace("+",`
528
- `).replace(`
529
-
530
- `,`
531
- +`).split(`
532
- `)),p=d.reduce((u,h)=>u.concat(...h),[]);return[d,p]}return[[],[]]},[e]);return X(()=>{const c=t?.target??of,d=t?.actInsideInputWithModifier??!0;if(e!==null){const p=m=>{if(s.current=m.ctrlKey||m.metaKey||m.shiftKey||m.altKey,(!s.current||s.current&&!d)&&Lx(m))return!1;const b=af(m.code,l);if(a.current.add(m[b]),sf(i,a.current,!1)){const x=m.composedPath?.()?.[0]||m.target,y=x?.nodeName==="BUTTON"||x?.nodeName==="A";t.preventDefault!==!1&&(s.current||!y)&&m.preventDefault(),o(!0)}},u=m=>{const g=af(m.code,l);sf(i,a.current,!0)?(o(!1),a.current.clear()):a.current.delete(m[g]),m.key==="Meta"&&a.current.clear(),s.current=!1},h=()=>{a.current.clear(),o(!1)};return c?.addEventListener("keydown",p),c?.addEventListener("keyup",u),window.addEventListener("blur",h),window.addEventListener("contextmenu",h),()=>{c?.removeEventListener("keydown",p),c?.removeEventListener("keyup",u),window.removeEventListener("blur",h),window.removeEventListener("contextmenu",h)}}},[e,o]),n}function sf(e,t,n){return e.filter(o=>n||o.length===t.size).some(o=>o.every(s=>t.has(s)))}function af(e,t){return t.includes(e)?"code":"key"}const g8=()=>{const e=Re();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=Mc(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,u=n.snapToGrid??a;return fo(d,o,u,p)},flowToScreenPosition:t=>{const{transform:n,domNode:o}=e.getState();if(!o)return t;const{x:s,y:a}=o.getBoundingClientRect(),i=xs(t,n);return{x:i.x+s,y:i.y+a}}}),[])};function a0(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)b8(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 b8(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 x8(e,t){return a0(e,t)}function y8(e,t){return a0(e,t)}function pn(e,t){return{id:e,type:"select",selected:t}}function Bn(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(pn(a.id,i)))}return o}function lf({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 cf(e){return{id:e.id,type:"remove"}}const df=e=>O6(e),v8=e=>Ex(e);function i0(e){return Oe(e)}function uf(e){const[t,n]=L(BigInt(0)),[o]=L(()=>w8(()=>n(s=>s+BigInt(1))));return Ui(()=>{const s=o.get();s.length&&(e(s),o.reset())},[t]),o}function w8(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const l0=$e(null);function N8({children:e}){const t=Re(),n=q(l=>{const{nodes:c=[],setNodes:d,hasDefaultNodes:p,onNodesChange:u,nodeLookup:h,fitViewQueued:m,onNodesChangeMiddlewareMap:g}=t.getState();let b=c;for(const y of l)b=typeof y=="function"?y(b):y;let x=lf({items:b,lookup:h});for(const y of g.values())x=y(x);p&&d(b),x.length>0?u?.(x):m&&window.requestAnimationFrame(()=>{const{fitViewQueued:y,nodes:w,setNodes:v}=t.getState();y&&v(w)})},[]),o=uf(n),s=q(l=>{const{edges:c=[],setEdges:d,hasDefaultEdges:p,onEdgesChange:u,edgeLookup:h}=t.getState();let m=c;for(const g of l)m=typeof g=="function"?g(m):g;p?d(m):u&&u(lf({items:m,lookup:h}))},[]),a=uf(s),i=Q(()=>({nodeQueue:o,edgeQueue:a}),[]);return r(l0.Provider,{value:i,children:e})}function S8(){const e=ge(l0);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const k8=e=>!!e.panZoom;function _c(){const e=g8(),t=Re(),n=S8(),o=Me(k8),s=Q(()=>{const a=u=>t.getState().nodeLookup.get(u),i=u=>{n.nodeQueue.push(u)},l=u=>{n.edgeQueue.push(u)},c=u=>{const{nodeLookup:h,nodeOrigin:m}=t.getState(),g=df(u)?u:h.get(u.id),b=g.parentId?Tx(g.position,g.measured,g.parentId,h,m):g.position,x={...g,position:b,width:g.measured?.width??g.width,height:g.measured?.height??g.height};return tr(x)},d=(u,h,m={replace:!1})=>{i(g=>g.map(b=>{if(b.id===u){const x=typeof h=="function"?h(b):h;return m.replace&&df(x)?x:{...b,...x}}return b}))},p=(u,h,m={replace:!1})=>{l(g=>g.map(b=>{if(b.id===u){const x=typeof h=="function"?h(b):h;return m.replace&&v8(x)?x:{...b,...x}}return b}))};return{getNodes:()=>t.getState().nodes.map(u=>({...u})),getNode:u=>a(u)?.internals.userNode,getInternalNode:a,getEdges:()=>{const{edges:u=[]}=t.getState();return u.map(h=>({...h}))},getEdge:u=>t.getState().edgeLookup.get(u),setNodes:i,setEdges:l,addNodes:u=>{const h=Array.isArray(u)?u:[u];n.nodeQueue.push(m=>[...m,...h])},addEdges:u=>{const h=Array.isArray(u)?u:[u];n.edgeQueue.push(m=>[...m,...h])},toObject:()=>{const{nodes:u=[],edges:h=[],transform:m}=t.getState(),[g,b,x]=m;return{nodes:u.map(y=>({...y})),edges:h.map(y=>({...y})),viewport:{x:g,y:b,zoom:x}}},deleteElements:async({nodes:u=[],edges:h=[]})=>{const{nodes:m,edges:g,onNodesDelete:b,onEdgesDelete:x,triggerNodeChanges:y,triggerEdgeChanges:w,onDelete:v,onBeforeDelete:N}=t.getState(),{nodes:S,edges:k}=await j6({nodesToRemove:u,edgesToRemove:h,nodes:m,edges:g,onBeforeDelete:N}),M=k.length>0,D=S.length>0;if(M){const E=k.map(cf);x?.(k),w(E)}if(D){const E=S.map(cf);b?.(S),y(E)}return(D||M)&&v?.({nodes:S,edges:k}),{deletedNodes:S,deletedEdges:k}},getIntersectingNodes:(u,h=!0,m)=>{const g=zu(u),b=g?u:c(u),x=m!==void 0;return b?(m||t.getState().nodes).filter(y=>{const w=t.getState().nodeLookup.get(y.id);if(w&&!g&&(y.id===u.id||!w.internals.positionAbsolute))return!1;const v=tr(x?y:w),N=Qr(v,b);return h&&N>0||N>=v.width*v.height||N>=b.width*b.height}):[]},isNodeIntersecting:(u,h,m=!0)=>{const b=zu(u)?u:c(u);if(!b)return!1;const x=Qr(b,h);return m&&x>0||x>=h.width*h.height||x>=b.width*b.height},updateNode:d,updateNodeData:(u,h,m={replace:!1})=>{d(u,g=>{const b=typeof h=="function"?h(g):h;return m.replace?{...g,data:b}:{...g,data:{...g.data,...b}}},m)},updateEdge:p,updateEdgeData:(u,h,m={replace:!1})=>{p(u,g=>{const b=typeof h=="function"?h(g):h;return m.replace?{...g,data:b}:{...g,data:{...g.data,...b}}},m)},getNodesBounds:u=>{const{nodeLookup:h,nodeOrigin:m}=t.getState();return B6(u,{nodeLookup:h,nodeOrigin:m})},getHandleConnections:({type:u,id:h,nodeId:m})=>Array.from(t.getState().connectionLookup.get(`${m}-${u}${h?`-${h}`:""}`)?.values()??[]),getNodeConnections:({type:u,handleId:h,nodeId:m})=>Array.from(t.getState().connectionLookup.get(`${m}${u?h?`-${u}-${h}`:`-${u}`:""}`)?.values()??[]),fitView:async u=>{const h=t.getState().fitViewResolver??Q6();return t.setState({fitViewQueued:!0,fitViewOptions:u,fitViewResolver:h}),n.nodeQueue.push(m=>[...m]),h.promise}}},[]);return Q(()=>({...s,...e,viewportInitialized:o}),[o])}const ff=e=>e.selected,C8=typeof window<"u"?window:void 0;function M8({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=Re(),{deleteElements:o}=_c(),s=Wr(e,{actInsideInputWithModifier:!1}),a=Wr(t,{target:C8});X(()=>{if(s){const{edges:i,nodes:l}=n.getState();o({nodes:l.filter(ff),edges:i.filter(ff)}),n.setState({nodesSelectionActive:!1})}},[s]),X(()=>{n.setState({multiSelectionActive:a})},[a])}function I8(e){const t=Re();X(()=>{const n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const o=Ic(e.current);(o.height===0||o.width===0)&&t.getState().onError?.("004",Pt.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 ra={position:"absolute",width:"100%",height:"100%",top:0,left:0},E8=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function P8({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:o=!1,panOnScrollSpeed:s=.5,panOnScrollMode:a=xn.Free,zoomOnDoubleClick:i=!0,panOnDrag:l=!0,defaultViewport:c,translateExtent:d,minZoom:p,maxZoom:u,zoomActivationKeyCode:h,preventScrolling:m=!0,children:g,noWheelClassName:b,noPanClassName:x,onViewportChange:y,isControlledViewport:w,paneClickDistance:v,selectionOnDrag:N}){const S=Re(),k=ee(null),{userSelectionActive:M,lib:D,connectionInProgress:E}=Me(E8,_e),B=Wr(h),A=ee();I8(k);const O=q($=>{y?.({x:$[0],y:$[1],zoom:$[2]}),w||S.setState({transform:$})},[y,w]);return X(()=>{if(k.current){A.current=PB({domNode:k.current,minZoom:p,maxZoom:u,translateExtent:d,viewport:c,onDraggingChange:P=>S.setState(T=>T.paneDragging===P?T:{paneDragging:P}),onPanZoomStart:(P,T)=>{const{onViewportChangeStart:R,onMoveStart:z}=S.getState();z?.(P,T),R?.(T)},onPanZoom:(P,T)=>{const{onViewportChange:R,onMove:z}=S.getState();z?.(P,T),R?.(T)},onPanZoomEnd:(P,T)=>{const{onViewportChangeEnd:R,onMoveEnd:z}=S.getState();z?.(P,T),R?.(T)}});const{x:$,y:I,zoom:_}=A.current.getViewport();return S.setState({panZoom:A.current,transform:[$,I,_],domNode:k.current.closest(".react-flow")}),()=>{A.current?.destroy()}}},[]),X(()=>{A.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:o,panOnScrollSpeed:s,panOnScrollMode:a,zoomOnDoubleClick:i,panOnDrag:l,zoomActivationKeyPressed:B,preventScrolling:m,noPanClassName:x,userSelectionActive:M,noWheelClassName:b,lib:D,onTransformChange:O,connectionInProgress:E,selectionOnDrag:N,paneClickDistance:v})},[e,t,n,o,s,a,i,l,B,m,x,M,b,D,O,E,N,v]),r("div",{className:"react-flow__renderer",ref:k,style:ra,children:g})}const A8=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function $8(){const{userSelectionActive:e,userSelectionRect:t}=Me(A8,_e);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 Ka=(e,t)=>n=>{n.target===t.current&&e?.(n)},D8=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function _8({isSelecting:e,selectionKeyPressed:t,selectionMode:n=Ur.Full,panOnDrag:o,paneClickDistance:s,selectionOnDrag:a,onSelectionStart:i,onSelectionEnd:l,onPaneClick:c,onPaneContextMenu:d,onPaneScroll:p,onPaneMouseEnter:u,onPaneMouseMove:h,onPaneMouseLeave:m,children:g}){const b=Re(),{userSelectionActive:x,elementsSelectable:y,dragging:w,connectionInProgress:v}=Me(D8,_e),N=y&&(e||x),S=ee(null),k=ee(),M=ee(new Set),D=ee(new Set),E=ee(!1),B=R=>{if(E.current||v){E.current=!1;return}c?.(R),b.getState().resetSelectedElements(),b.setState({nodesSelectionActive:!1})},A=R=>{if(Array.isArray(o)&&o?.includes(2)){R.preventDefault();return}d?.(R)},O=p?R=>p(R):void 0,$=R=>{E.current&&(R.stopPropagation(),E.current=!1)},I=R=>{const{domNode:z}=b.getState();if(k.current=z?.getBoundingClientRect(),!k.current)return;const H=R.target===S.current;if(!H&&!!R.target.closest(".nokey")||!e||!(a&&H||t)||R.button!==0||!R.isPrimary)return;R.target?.setPointerCapture?.(R.pointerId),E.current=!1;const{x:J,y:W}=mt(R.nativeEvent,k.current);b.setState({userSelectionRect:{width:0,height:0,startX:J,startY:W,x:J,y:W}}),H||(R.stopPropagation(),R.preventDefault())},_=R=>{const{userSelectionRect:z,transform:H,nodeLookup:F,edgeLookup:j,connectionLookup:J,triggerNodeChanges:W,triggerEdgeChanges:ne,defaultEdgeOptions:de,resetSelectedElements:te}=b.getState();if(!k.current||!z)return;const{x:K,y:oe}=mt(R.nativeEvent,k.current),{startX:me,startY:Y}=z;if(!E.current){const he=t?0:s;if(Math.hypot(K-me,oe-Y)<=he)return;te(),i?.(R)}E.current=!0;const G={startX:me,startY:Y,x:K<me?K:me,y:oe<Y?oe:Y,width:Math.abs(K-me),height:Math.abs(oe-Y)},Z=M.current,re=D.current;M.current=new Set(Cc(F,G,H,n===Ur.Partial,!0).map(he=>he.id)),D.current=new Set;const pe=de?.selectable??!0;for(const he of M.current){const V=J.get(he);if(V)for(const{edgeId:se}of V.values()){const ce=j.get(se);ce&&(ce.selectable??pe)&&D.current.add(se)}}if(!Fu(Z,M.current)){const he=Bn(F,M.current,!0);W(he)}if(!Fu(re,D.current)){const he=Bn(j,D.current);ne(he)}b.setState({userSelectionRect:G,userSelectionActive:!0,nodesSelectionActive:!1})},P=R=>{R.button===0&&(R.target?.releasePointerCapture?.(R.pointerId),!x&&R.target===S.current&&b.getState().userSelectionRect&&B?.(R),b.setState({userSelectionActive:!1,userSelectionRect:null}),E.current&&(l?.(R),b.setState({nodesSelectionActive:M.current.size>0})))},T=o===!0||Array.isArray(o)&&o.includes(0);return f("div",{className:ze(["react-flow__pane",{draggable:T,dragging:w,selection:e}]),onClick:N?void 0:Ka(B,S),onContextMenu:Ka(A,S),onWheel:Ka(O,S),onPointerEnter:N?void 0:u,onPointerMove:N?_:h,onPointerUp:N?P:void 0,onPointerDownCapture:N?I:void 0,onClickCapture:N?$:void 0,onPointerLeave:m,ref:S,style:ra,children:[g,r($8,{})]})}function Qi({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",Pt.error012(e));return}t.setState({nodesSelectionActive:!1}),d.selected?(n||d.selected&&i)&&(a({nodes:[d],edges:[]}),requestAnimationFrame(()=>o?.current?.blur())):s([e])}function c0({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:o,nodeId:s,isSelectable:a,nodeClickDistance:i}){const l=Re(),[c,d]=L(!1),p=ee();return X(()=>{p.current=mB({getStoreItems:()=>l.getState(),onNodeMouseDown:u=>{Qi({id:u,store:l,nodeRef:e})},onDragStart:()=>{d(!0)},onDragStop:()=>{d(!1)}})},[]),X(()=>{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 T8=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function d0(){const e=Re();return q(n=>{const{nodeExtent:o,snapToGrid:s,snapGrid:a,nodesDraggable:i,onError:l,updateNodePositions:c,nodeLookup:d,nodeOrigin:p}=e.getState(),u=new Map,h=T8(i),m=s?a[0]:5,g=s?a[1]:5,b=n.direction.x*m*n.factor,x=n.direction.y*g*n.factor;for(const[,y]of d){if(!h(y))continue;let w={x:y.internals.positionAbsolute.x+b,y:y.internals.positionAbsolute.y+x};s&&(w=uo(w,a));const{position:v,positionAbsolute:N}=Px({nodeId:y.id,nextPosition:w,nodeLookup:d,nodeExtent:o,nodeOrigin:p,onError:l});y.position=v,y.internals.positionAbsolute=N,u.set(y.id,y)}c(u)},[])}const Tc=$e(null),R8=Tc.Provider;Tc.Consumer;const u0=()=>ge(Tc),L8=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),O8=(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===Jn.Strict?l?.type!==n:e!==l?.nodeId||t!==l?.id,connectionInProcess:!!l,clickConnectionInProcess:!!s,valid:p&&d}};function B8({type:e="source",position:t=be.Top,isValidConnection:n,isConnectable:o=!0,isConnectableStart:s=!0,isConnectableEnd:a=!0,id:i,onConnect:l,children:c,className:d,onMouseDown:p,onTouchStart:u,...h},m){const g=i||null,b=e==="target",x=Re(),y=u0(),{connectOnClick:w,noPanClassName:v,rfId:N}=Me(L8,_e),{connectingFrom:S,connectingTo:k,clickConnecting:M,isPossibleEndHandle:D,connectionInProcess:E,clickConnectionInProcess:B,valid:A}=Me(O8(y,g,e),_e);y||x.getState().onError?.("010",Pt.error010());const O=_=>{const{defaultEdgeOptions:P,onConnect:T,hasDefaultEdges:R}=x.getState(),z={...P,..._};if(R){const{edges:H,setEdges:F}=x.getState();F(J6(z,H))}T?.(z),l?.(z)},$=_=>{if(!y)return;const P=Ox(_.nativeEvent);if(s&&(P&&_.button===0||!P)){const T=x.getState();qi.onPointerDown(_.nativeEvent,{handleDomNode:_.currentTarget,autoPanOnConnect:T.autoPanOnConnect,connectionMode:T.connectionMode,connectionRadius:T.connectionRadius,domNode:T.domNode,nodeLookup:T.nodeLookup,lib:T.lib,isTarget:b,handleId:g,nodeId:y,flowId:T.rfId,panBy:T.panBy,cancelConnection:T.cancelConnection,onConnectStart:T.onConnectStart,onConnectEnd:(...R)=>x.getState().onConnectEnd?.(...R),updateConnection:T.updateConnection,onConnect:O,isValidConnection:n||((...R)=>x.getState().isValidConnection?.(...R)??!0),getTransform:()=>x.getState().transform,getFromHandle:()=>x.getState().connection.fromHandle,autoPanSpeed:T.autoPanSpeed,dragThreshold:T.connectionDragThreshold})}P?p?.(_):u?.(_)},I=_=>{const{onClickConnectStart:P,onClickConnectEnd:T,connectionClickStartHandle:R,connectionMode:z,isValidConnection:H,lib:F,rfId:j,nodeLookup:J,connection:W}=x.getState();if(!y||!R&&!s)return;if(!R){P?.(_.nativeEvent,{nodeId:y,handleId:g,handleType:e}),x.setState({connectionClickStartHandle:{nodeId:y,type:e,id:g}});return}const ne=Rx(_.target),de=n||H,{connection:te,isValid:K}=qi.isValid(_.nativeEvent,{handle:{nodeId:y,id:g,type:e},connectionMode:z,fromNodeId:R.nodeId,fromHandleId:R.id||null,fromType:R.type,isValidConnection:de,flowId:j,doc:ne,lib:F,nodeLookup:J});K&&te&&O(te);const oe=structuredClone(W);delete oe.inProgress,oe.toPosition=oe.toHandle?oe.toHandle.position:null,T?.(_,oe),x.setState({connectionClickStartHandle:null})};return r("div",{"data-handleid":g,"data-nodeid":y,"data-handlepos":t,"data-id":`${N}-${y}-${g}-${e}`,className:ze(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",v,d,{source:!b,target:b,connectable:o,connectablestart:s,connectableend:a,clickconnecting:M,connectingfrom:S,connectingto:k,valid:A,connectionindicator:o&&(!E||D)&&(E||B?a:s)}]),onMouseDown:$,onTouchStart:$,onClick:w?I:void 0,ref:m,...h,children:c})}const tn=Te(i0(B8));function z8({data:e,isConnectable:t,sourcePosition:n=be.Bottom}){return f(ye,{children:[e?.label,r(tn,{type:"source",position:n,isConnectable:t})]})}function F8({data:e,isConnectable:t,targetPosition:n=be.Top,sourcePosition:o=be.Bottom}){return f(ye,{children:[r(tn,{type:"target",position:n,isConnectable:t}),e?.label,r(tn,{type:"source",position:o,isConnectable:t})]})}function H8(){return null}function j8({data:e,isConnectable:t,targetPosition:n=be.Top}){return f(ye,{children:[r(tn,{type:"target",position:n,isConnectable:t}),e?.label]})}const ys={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},pf={input:z8,default:F8,output:j8,group:H8};function V8(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 q8=e=>{const{width:t,height:n,x:o,y:s}=co(e.nodeLookup,{filter:a=>!!a.selected});return{width:ht(t)?t:null,height:ht(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 U8({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const o=Re(),{width:s,height:a,transformString:i,userSelectionActive:l}=Me(q8,_e),c=d0(),d=ee(null);X(()=>{n||d.current?.focus({preventScroll:!0})},[n]);const p=!l&&s!==null&&a!==null;if(c0({nodeRef:d,disabled:!p}),!p)return null;const u=e?m=>{const g=o.getState().nodes.filter(b=>b.selected);e(m,g)}:void 0,h=m=>{Object.prototype.hasOwnProperty.call(ys,m.key)&&(m.preventDefault(),c({direction:ys[m.key],factor:m.shiftKey?4:1}))};return r("div",{className:ze(["react-flow__nodesselection","react-flow__container",t]),style:{transform:i},children:r("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:u,tabIndex:n?void 0:-1,onKeyDown:n?void 0:h,style:{width:s,height:a}})})}const hf=typeof window<"u"?window:void 0,Q8=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function f0({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:o,onPaneMouseLeave:s,onPaneContextMenu:a,onPaneScroll:i,paneClickDistance:l,deleteKeyCode:c,selectionKeyCode:d,selectionOnDrag:p,selectionMode:u,onSelectionStart:h,onSelectionEnd:m,multiSelectionKeyCode:g,panActivationKeyCode:b,zoomActivationKeyCode:x,elementsSelectable:y,zoomOnScroll:w,zoomOnPinch:v,panOnScroll:N,panOnScrollSpeed:S,panOnScrollMode:k,zoomOnDoubleClick:M,panOnDrag:D,defaultViewport:E,translateExtent:B,minZoom:A,maxZoom:O,preventScrolling:$,onSelectionContextMenu:I,noWheelClassName:_,noPanClassName:P,disableKeyboardA11y:T,onViewportChange:R,isControlledViewport:z}){const{nodesSelectionActive:H,userSelectionActive:F}=Me(Q8,_e),j=Wr(d,{target:hf}),J=Wr(b,{target:hf}),W=J||D,ne=J||N,de=p&&W!==!0,te=j||F||de;return M8({deleteKeyCode:c,multiSelectionKeyCode:g}),r(P8,{onPaneContextMenu:a,elementsSelectable:y,zoomOnScroll:w,zoomOnPinch:v,panOnScroll:ne,panOnScrollSpeed:S,panOnScrollMode:k,zoomOnDoubleClick:M,panOnDrag:!j&&W,defaultViewport:E,translateExtent:B,minZoom:A,maxZoom:O,zoomActivationKeyCode:x,preventScrolling:$,noWheelClassName:_,noPanClassName:P,onViewportChange:R,isControlledViewport:z,paneClickDistance:l,selectionOnDrag:de,children:f(_8,{onSelectionStart:h,onSelectionEnd:m,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:o,onPaneMouseLeave:s,onPaneContextMenu:a,onPaneScroll:i,panOnDrag:W,isSelecting:!!te,selectionMode:u,selectionKeyPressed:j,paneClickDistance:l,selectionOnDrag:de,children:[e,H&&r(U8,{onSelectionContextMenu:I,noPanClassName:P,disableKeyboardA11y:T})]})})}f0.displayName="FlowRenderer";const G8=Te(f0),W8=e=>t=>e?Cc(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 K8(e){return Me(q(W8(e),[e]),_e)}const Y8=e=>e.updateNodeInternals;function Z8(){const e=Me(Y8),[t]=L(()=>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 X(()=>()=>{t?.disconnect()},[t]),t}function X8({node:e,nodeType:t,hasDimensions:n,resizeObserver:o}){const s=Re(),a=ee(null),i=ee(null),l=ee(e.sourcePosition),c=ee(e.targetPosition),d=ee(t),p=n&&!!e.internals.handleBounds;return X(()=>{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]),X(()=>()=>{i.current&&(o?.unobserve(i.current),i.current=null)},[]),X(()=>{if(a.current){const u=d.current!==t,h=l.current!==e.sourcePosition,m=c.current!==e.targetPosition;(u||h||m)&&(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 J8({id:e,onClick:t,onMouseEnter:n,onMouseMove:o,onMouseLeave:s,onContextMenu:a,onDoubleClick:i,nodesDraggable:l,elementsSelectable:c,nodesConnectable:d,nodesFocusable:p,resizeObserver:u,noDragClassName:h,noPanClassName:m,disableKeyboardA11y:g,rfId:b,nodeTypes:x,nodeClickDistance:y,onError:w}){const{node:v,internals:N,isParent:S}=Me(K=>{const oe=K.nodeLookup.get(e),me=K.parentLookup.has(e);return{node:oe,internals:oe.internals,isParent:me}},_e);let k=v.type||"default",M=x?.[k]||pf[k];M===void 0&&(w?.("003",Pt.error003(k)),k="default",M=x?.default||pf.default);const D=!!(v.draggable||l&&typeof v.draggable>"u"),E=!!(v.selectable||c&&typeof v.selectable>"u"),B=!!(v.connectable||d&&typeof v.connectable>"u"),A=!!(v.focusable||p&&typeof v.focusable>"u"),O=Re(),$=_x(v),I=X8({node:v,nodeType:k,hasDimensions:$,resizeObserver:u}),_=c0({nodeRef:I,disabled:v.hidden||!D,noDragClassName:h,handleSelector:v.dragHandle,nodeId:e,isSelectable:E,nodeClickDistance:y}),P=d0();if(v.hidden)return null;const T=Kt(v),R=V8(v),z=E||D||t||n||o||s,H=n?K=>n(K,{...N.userNode}):void 0,F=o?K=>o(K,{...N.userNode}):void 0,j=s?K=>s(K,{...N.userNode}):void 0,J=a?K=>a(K,{...N.userNode}):void 0,W=i?K=>i(K,{...N.userNode}):void 0,ne=K=>{const{selectNodesOnDrag:oe,nodeDragThreshold:me}=O.getState();E&&(!oe||!D||me>0)&&Qi({id:e,store:O,nodeRef:I}),t&&t(K,{...N.userNode})},de=K=>{if(!(Lx(K.nativeEvent)||g)){if(kx.includes(K.key)&&E){const oe=K.key==="Escape";Qi({id:e,store:O,unselect:oe,nodeRef:I})}else if(D&&v.selected&&Object.prototype.hasOwnProperty.call(ys,K.key)){K.preventDefault();const{ariaLabelConfig:oe}=O.getState();O.setState({ariaLiveMessage:oe["node.a11yDescription.ariaLiveMessage"]({direction:K.key.replace("Arrow","").toLowerCase(),x:~~N.positionAbsolute.x,y:~~N.positionAbsolute.y})}),P({direction:ys[K.key],factor:K.shiftKey?4:1})}}},te=()=>{if(g||!I.current?.matches(":focus-visible"))return;const{transform:K,width:oe,height:me,autoPanOnNodeFocus:Y,setCenter:G}=O.getState();if(!Y)return;Cc(new Map([[e,v]]),{x:0,y:0,width:oe,height:me},K,!0).length>0||G(v.position.x+T.width/2,v.position.y+T.height/2,{zoom:K[2]})};return r("div",{className:ze(["react-flow__node",`react-flow__node-${k}`,{[m]:D},v.className,{selected:v.selected,selectable:E,parent:S,draggable:D,dragging:_}]),ref:I,style:{zIndex:N.z,transform:`translate(${N.positionAbsolute.x}px,${N.positionAbsolute.y}px)`,pointerEvents:z?"all":"none",visibility:$?"visible":"hidden",...v.style,...R},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:H,onMouseMove:F,onMouseLeave:j,onContextMenu:J,onClick:ne,onDoubleClick:W,onKeyDown:A?de:void 0,tabIndex:A?0:void 0,onFocus:A?te:void 0,role:v.ariaRole??(A?"group":void 0),"aria-roledescription":"node","aria-describedby":g?void 0:`${r0}-${b}`,"aria-label":v.ariaLabel,...v.domAttributes,children:r(R8,{value:e,children:r(M,{id:e,data:v.data,type:k,positionAbsoluteX:N.positionAbsolute.x,positionAbsoluteY:N.positionAbsolute.y,selected:v.selected??!1,selectable:E,draggable:D,deletable:v.deletable??!0,isConnectable:B,sourcePosition:v.sourcePosition,targetPosition:v.targetPosition,dragging:_,dragHandle:v.dragHandle,zIndex:N.z,parentId:v.parentId,...T})})})}var e9=Te(J8);const t9=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function p0(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:o,elementsSelectable:s,onError:a}=Me(t9,_e),i=K8(e.onlyRenderVisibleElements),l=Z8();return r("div",{className:"react-flow__nodes",style:ra,children:i.map(c=>r(e9,{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))})}p0.displayName="NodeRenderer";const n9=Te(p0);function r9(e){return Me(q(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&&Y6({sourceNode:a,targetNode:i,width:n.width,height:n.height,transform:n.transform})&&o.push(s.id)}return o},[e]),_e)}const o9=({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"})},s9=({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"})},mf={[gs.Arrow]:o9,[gs.ArrowClosed]:s9};function a9(e){const t=Re();return Q(()=>Object.prototype.hasOwnProperty.call(mf,e)?mf[e]:(t.getState().onError?.("009",Pt.error009(e)),null),[e])}const i9=({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=a9(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},h0=({defaultColor:e,rfId:t})=>{const n=Me(a=>a.edges),o=Me(a=>a.defaultEdgeOptions),s=Q(()=>oB(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(i9,{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};h0.displayName="MarkerDefinitions";var l9=Te(h0);function m0({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[u,h]=L({x:1,y:0,width:0,height:0}),m=ze(["react-flow__edge-textwrapper",d]),g=ee(null);return X(()=>{if(g.current){const b=g.current.getBBox();h({x:b.x,y:b.y,width:b.width,height:b.height})}},[n]),n?f("g",{transform:`translate(${e-u.width/2} ${t-u.height/2})`,className:m,visibility:u.width?"visible":"hidden",...p,children:[s&&r("rect",{width:u.width+2*i[0],x:-i[0],y:-i[1],height:u.height+2*i[1],className:"react-flow__edge-textbg",style:a,rx:l,ry:l}),r("text",{className:"react-flow__edge-text",y:u.height/2,dy:"0.3em",ref:g,style:o,children:n}),c]}):null}m0.displayName="EdgeText";const c9=Te(m0);function oa({path:e,labelX:t,labelY:n,label:o,labelStyle:s,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c,interactionWidth:d=20,...p}){return f(ye,{children:[r("path",{...p,d:e,fill:"none",className:ze(["react-flow__edge-path",p.className])}),d?r("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:d,className:"react-flow__edge-interaction"}):null,o&&ht(t)&&ht(n)?r(c9,{x:t,y:n,label:o,labelStyle:s,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c}):null]})}function gf({pos:e,x1:t,y1:n,x2:o,y2:s}){return e===be.Left||e===be.Right?[.5*(t+o),n]:[t,.5*(n+s)]}function g0({sourceX:e,sourceY:t,sourcePosition:n=be.Bottom,targetX:o,targetY:s,targetPosition:a=be.Top}){const[i,l]=gf({pos:n,x1:e,y1:t,x2:o,y2:s}),[c,d]=gf({pos:a,x1:o,y1:s,x2:e,y2:t}),[p,u,h,m]=Bx({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,u,h,m]}function b0(e){return Te(({id:t,sourceX:n,sourceY:o,targetX:s,targetY:a,sourcePosition:i,targetPosition:l,label:c,labelStyle:d,labelShowBg:p,labelBgStyle:u,labelBgPadding:h,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:x,interactionWidth:y})=>{const[w,v,N]=g0({sourceX:n,sourceY:o,sourcePosition:i,targetX:s,targetY:a,targetPosition:l}),S=e.isInternal?void 0:t;return r(oa,{id:S,path:w,labelX:v,labelY:N,label:c,labelStyle:d,labelShowBg:p,labelBgStyle:u,labelBgPadding:h,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:x,interactionWidth:y})})}const d9=b0({isInternal:!1}),x0=b0({isInternal:!0});d9.displayName="SimpleBezierEdge";x0.displayName="SimpleBezierEdgeInternal";function y0(e){return Te(({id:t,sourceX:n,sourceY:o,targetX:s,targetY:a,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:p,labelBgBorderRadius:u,style:h,sourcePosition:m=be.Bottom,targetPosition:g=be.Top,markerEnd:b,markerStart:x,pathOptions:y,interactionWidth:w})=>{const[v,N,S]=Hi({sourceX:n,sourceY:o,sourcePosition:m,targetX:s,targetY:a,targetPosition:g,borderRadius:y?.borderRadius,offset:y?.offset,stepPosition:y?.stepPosition}),k=e.isInternal?void 0:t;return r(oa,{id:k,path:v,labelX:N,labelY:S,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:p,labelBgBorderRadius:u,style:h,markerEnd:b,markerStart:x,interactionWidth:w})})}const v0=y0({isInternal:!1}),w0=y0({isInternal:!0});v0.displayName="SmoothStepEdge";w0.displayName="SmoothStepEdgeInternal";function N0(e){return Te(({id:t,...n})=>{const o=e.isInternal?void 0:t;return r(v0,{...n,id:o,pathOptions:Q(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}const u9=N0({isInternal:!1}),S0=N0({isInternal:!0});u9.displayName="StepEdge";S0.displayName="StepEdgeInternal";function k0(e){return Te(({id:t,sourceX:n,sourceY:o,targetX:s,targetY:a,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:p,labelBgBorderRadius:u,style:h,markerEnd:m,markerStart:g,interactionWidth:b})=>{const[x,y,w]=Hx({sourceX:n,sourceY:o,targetX:s,targetY:a}),v=e.isInternal?void 0:t;return r(oa,{id:v,path:x,labelX:y,labelY:w,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:p,labelBgBorderRadius:u,style:h,markerEnd:m,markerStart:g,interactionWidth:b})})}const f9=k0({isInternal:!1}),C0=k0({isInternal:!0});f9.displayName="StraightEdge";C0.displayName="StraightEdgeInternal";function M0(e){return Te(({id:t,sourceX:n,sourceY:o,targetX:s,targetY:a,sourcePosition:i=be.Bottom,targetPosition:l=be.Top,label:c,labelStyle:d,labelShowBg:p,labelBgStyle:u,labelBgPadding:h,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:x,pathOptions:y,interactionWidth:w})=>{const[v,N,S]=zx({sourceX:n,sourceY:o,sourcePosition:i,targetX:s,targetY:a,targetPosition:l,curvature:y?.curvature}),k=e.isInternal?void 0:t;return r(oa,{id:k,path:v,labelX:N,labelY:S,label:c,labelStyle:d,labelShowBg:p,labelBgStyle:u,labelBgPadding:h,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:x,interactionWidth:w})})}const p9=M0({isInternal:!1}),I0=M0({isInternal:!0});p9.displayName="BezierEdge";I0.displayName="BezierEdgeInternal";const bf={default:I0,straight:C0,step:S0,smoothstep:w0,simplebezier:x0},xf={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},h9=(e,t,n)=>n===be.Left?e-t:n===be.Right?e+t:e,m9=(e,t,n)=>n===be.Top?e-t:n===be.Bottom?e+t:e,yf="react-flow__edgeupdater";function vf({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:ze([yf,`${yf}-${l}`]),cx:h9(t,o,e),cy:m9(n,o,e),r:o,stroke:"transparent",fill:"transparent"})}function g9({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:o,sourceY:s,targetX:a,targetY:i,sourcePosition:l,targetPosition:c,onReconnect:d,onReconnectStart:p,onReconnectEnd:u,setReconnecting:h,setUpdateHover:m}){const g=Re(),b=(N,S)=>{if(N.button!==0)return;const{autoPanOnConnect:k,domNode:M,connectionMode:D,connectionRadius:E,lib:B,onConnectStart:A,cancelConnection:O,nodeLookup:$,rfId:I,panBy:_,updateConnection:P}=g.getState(),T=S.type==="target",R=(F,j)=>{h(!1),u?.(F,n,S.type,j)},z=F=>d?.(n,F),H=(F,j)=>{h(!0),p?.(N,n,S.type),A?.(F,j)};qi.onPointerDown(N.nativeEvent,{autoPanOnConnect:k,connectionMode:D,connectionRadius:E,domNode:M,handleId:S.id,nodeId:S.nodeId,nodeLookup:$,isTarget:T,edgeUpdaterType:S.type,lib:B,flowId:I,cancelConnection:O,panBy:_,isValidConnection:(...F)=>g.getState().isValidConnection?.(...F)??!0,onConnect:z,onConnectStart:H,onConnectEnd:(...F)=>g.getState().onConnectEnd?.(...F),onReconnectEnd:R,updateConnection:P,getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,dragThreshold:g.getState().connectionDragThreshold,handleDomNode:N.currentTarget})},x=N=>b(N,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),y=N=>b(N,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),w=()=>m(!0),v=()=>m(!1);return f(ye,{children:[(e===!0||e==="source")&&r(vf,{position:l,centerX:o,centerY:s,radius:t,onMouseDown:x,onMouseEnter:w,onMouseOut:v,type:"source"}),(e===!0||e==="target")&&r(vf,{position:c,centerX:a,centerY:i,radius:t,onMouseDown:y,onMouseEnter:w,onMouseOut:v,type:"target"})]})}function b9({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:o,onClick:s,onDoubleClick:a,onContextMenu:i,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,reconnectRadius:p,onReconnect:u,onReconnectStart:h,onReconnectEnd:m,rfId:g,edgeTypes:b,noPanClassName:x,onError:y,disableKeyboardA11y:w}){let v=Me(G=>G.edgeLookup.get(e));const N=Me(G=>G.defaultEdgeOptions);v=N?{...N,...v}:v;let S=v.type||"default",k=b?.[S]||bf[S];k===void 0&&(y?.("011",Pt.error011(S)),S="default",k=b?.default||bf.default);const M=!!(v.focusable||t&&typeof v.focusable>"u"),D=typeof u<"u"&&(v.reconnectable||n&&typeof v.reconnectable>"u"),E=!!(v.selectable||o&&typeof v.selectable>"u"),B=ee(null),[A,O]=L(!1),[$,I]=L(!1),_=Re(),{zIndex:P,sourceX:T,sourceY:R,targetX:z,targetY:H,sourcePosition:F,targetPosition:j}=Me(q(G=>{const Z=G.nodeLookup.get(v.source),re=G.nodeLookup.get(v.target);if(!Z||!re)return{zIndex:v.zIndex,...xf};const pe=rB({id:e,sourceNode:Z,targetNode:re,sourceHandle:v.sourceHandle||null,targetHandle:v.targetHandle||null,connectionMode:G.connectionMode,onError:y});return{zIndex:K6({selected:v.selected,zIndex:v.zIndex,sourceNode:Z,targetNode:re,elevateOnSelect:G.elevateEdgesOnSelect,zIndexMode:G.zIndexMode}),...pe||xf}},[v.source,v.target,v.sourceHandle,v.targetHandle,v.selected,v.zIndex]),_e),J=Q(()=>v.markerStart?`url('#${ji(v.markerStart,g)}')`:void 0,[v.markerStart,g]),W=Q(()=>v.markerEnd?`url('#${ji(v.markerEnd,g)}')`:void 0,[v.markerEnd,g]);if(v.hidden||T===null||R===null||z===null||H===null)return null;const ne=G=>{const{addSelectedEdges:Z,unselectNodesAndEdges:re,multiSelectionActive:pe}=_.getState();E&&(_.setState({nodesSelectionActive:!1}),v.selected&&pe?(re({nodes:[],edges:[v]}),B.current?.blur()):Z([e])),s&&s(G,v)},de=a?G=>{a(G,{...v})}:void 0,te=i?G=>{i(G,{...v})}:void 0,K=l?G=>{l(G,{...v})}:void 0,oe=c?G=>{c(G,{...v})}:void 0,me=d?G=>{d(G,{...v})}:void 0,Y=G=>{if(!w&&kx.includes(G.key)&&E){const{unselectNodesAndEdges:Z,addSelectedEdges:re}=_.getState();G.key==="Escape"?(B.current?.blur(),Z({edges:[v]})):re([e])}};return r("svg",{style:{zIndex:P},children:f("g",{className:ze(["react-flow__edge",`react-flow__edge-${S}`,v.className,x,{selected:v.selected,animated:v.animated,inactive:!E&&!s,updating:A,selectable:E}]),onClick:ne,onDoubleClick:de,onContextMenu:te,onMouseEnter:K,onMouseMove:oe,onMouseLeave:me,onKeyDown:M?Y:void 0,tabIndex:M?0:void 0,role:v.ariaRole??(M?"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":M?`${o0}-${g}`:void 0,ref:B,...v.domAttributes,children:[!$&&r(k,{id:e,source:v.source,target:v.target,type:v.type,selected:v.selected,animated:v.animated,selectable:E,deletable:v.deletable??!0,label:v.label,labelStyle:v.labelStyle,labelShowBg:v.labelShowBg,labelBgStyle:v.labelBgStyle,labelBgPadding:v.labelBgPadding,labelBgBorderRadius:v.labelBgBorderRadius,sourceX:T,sourceY:R,targetX:z,targetY:H,sourcePosition:F,targetPosition:j,data:v.data,style:v.style,sourceHandleId:v.sourceHandle,targetHandleId:v.targetHandle,markerStart:J,markerEnd:W,pathOptions:"pathOptions"in v?v.pathOptions:void 0,interactionWidth:v.interactionWidth}),D&&r(g9,{edge:v,isReconnectable:D,reconnectRadius:p,onReconnect:u,onReconnectStart:h,onReconnectEnd:m,sourceX:T,sourceY:R,targetX:z,targetY:H,sourcePosition:F,targetPosition:j,setUpdateHover:O,setReconnecting:I})]})})}var x9=Te(b9);const y9=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function E0({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:o,noPanClassName:s,onReconnect:a,onEdgeContextMenu:i,onEdgeMouseEnter:l,onEdgeMouseMove:c,onEdgeMouseLeave:d,onEdgeClick:p,reconnectRadius:u,onEdgeDoubleClick:h,onReconnectStart:m,onReconnectEnd:g,disableKeyboardA11y:b}){const{edgesFocusable:x,edgesReconnectable:y,elementsSelectable:w,onError:v}=Me(y9,_e),N=r9(t);return f("div",{className:"react-flow__edges",children:[r(l9,{defaultColor:e,rfId:n}),N.map(S=>r(x9,{id:S,edgesFocusable:x,edgesReconnectable:y,elementsSelectable:w,noPanClassName:s,onReconnect:a,onContextMenu:i,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,onClick:p,reconnectRadius:u,onDoubleClick:h,onReconnectStart:m,onReconnectEnd:g,rfId:n,onError:v,edgeTypes:o,disableKeyboardA11y:b},S))]})}E0.displayName="EdgeRenderer";const v9=Te(E0),w9=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function N9({children:e}){const t=Me(w9);return r("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function S9(e){const t=_c(),n=ee(!1);X(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const k9=e=>e.panZoom?.syncViewport;function C9(e){const t=Me(k9),n=Re();return X(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function M9(e){return e.connection.inProgress?{...e.connection,to:fo(e.connection.to,e.transform)}:{...e.connection}}function I9(e){return M9}function E9(e){const t=I9();return Me(t,_e)}const P9=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function A9({containerStyle:e,style:t,type:n,component:o}){const{nodesConnectable:s,width:a,height:i,isValid:l,inProgress:c}=Me(P9,_e);return!(a&&s&&c)?null:r("svg",{style:e,width:a,height:i,className:"react-flow__connectionline react-flow__container",children:r("g",{className:ze(["react-flow__connection",Ix(l)]),children:r(P0,{style:t,type:n,CustomComponent:o,isValid:l})})})}const P0=({style:e,type:t=Xt.Bezier,CustomComponent:n,isValid:o})=>{const{inProgress:s,from:a,fromNode:i,fromHandle:l,fromPosition:c,to:d,toNode:p,toHandle:u,toPosition:h,pointer:m}=E9();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:h,connectionStatus:Ix(o),toNode:p,toHandle:u,pointer:m});let g="";const b={sourceX:a.x,sourceY:a.y,sourcePosition:c,targetX:d.x,targetY:d.y,targetPosition:h};switch(t){case Xt.Bezier:[g]=zx(b);break;case Xt.SimpleBezier:[g]=g0(b);break;case Xt.Step:[g]=Hi({...b,borderRadius:0});break;case Xt.SmoothStep:[g]=Hi(b);break;default:[g]=Hx(b)}return r("path",{d:g,fill:"none",className:"react-flow__connection-path",style:e})};P0.displayName="ConnectionLine";const $9={};function wf(e=$9){ee(e),Re(),X(()=>{},[e])}function D9(){Re(),ee(!1),X(()=>{},[])}function A0({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:o,onEdgeClick:s,onNodeDoubleClick:a,onEdgeDoubleClick:i,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:p,onSelectionContextMenu:u,onSelectionStart:h,onSelectionEnd:m,connectionLineType:g,connectionLineStyle:b,connectionLineComponent:x,connectionLineContainerStyle:y,selectionKeyCode:w,selectionOnDrag:v,selectionMode:N,multiSelectionKeyCode:S,panActivationKeyCode:k,zoomActivationKeyCode:M,deleteKeyCode:D,onlyRenderVisibleElements:E,elementsSelectable:B,defaultViewport:A,translateExtent:O,minZoom:$,maxZoom:I,preventScrolling:_,defaultMarkerColor:P,zoomOnScroll:T,zoomOnPinch:R,panOnScroll:z,panOnScrollSpeed:H,panOnScrollMode:F,zoomOnDoubleClick:j,panOnDrag:J,onPaneClick:W,onPaneMouseEnter:ne,onPaneMouseMove:de,onPaneMouseLeave:te,onPaneScroll:K,onPaneContextMenu:oe,paneClickDistance:me,nodeClickDistance:Y,onEdgeContextMenu:G,onEdgeMouseEnter:Z,onEdgeMouseMove:re,onEdgeMouseLeave:pe,reconnectRadius:he,onReconnect:V,onReconnectStart:se,onReconnectEnd:ce,noDragClassName:ie,noWheelClassName:ae,noPanClassName:ve,disableKeyboardA11y:ue,nodeExtent:Ne,rfId:Ee,viewport:He,onViewportChange:We}){return wf(e),wf(t),D9(),S9(n),C9(He),r(G8,{onPaneClick:W,onPaneMouseEnter:ne,onPaneMouseMove:de,onPaneMouseLeave:te,onPaneContextMenu:oe,onPaneScroll:K,paneClickDistance:me,deleteKeyCode:D,selectionKeyCode:w,selectionOnDrag:v,selectionMode:N,onSelectionStart:h,onSelectionEnd:m,multiSelectionKeyCode:S,panActivationKeyCode:k,zoomActivationKeyCode:M,elementsSelectable:B,zoomOnScroll:T,zoomOnPinch:R,zoomOnDoubleClick:j,panOnScroll:z,panOnScrollSpeed:H,panOnScrollMode:F,panOnDrag:J,defaultViewport:A,translateExtent:O,minZoom:$,maxZoom:I,onSelectionContextMenu:u,preventScrolling:_,noDragClassName:ie,noWheelClassName:ae,noPanClassName:ve,disableKeyboardA11y:ue,onViewportChange:We,isControlledViewport:!!He,children:f(N9,{children:[r(v9,{edgeTypes:t,onEdgeClick:s,onEdgeDoubleClick:i,onReconnect:V,onReconnectStart:se,onReconnectEnd:ce,onlyRenderVisibleElements:E,onEdgeContextMenu:G,onEdgeMouseEnter:Z,onEdgeMouseMove:re,onEdgeMouseLeave:pe,reconnectRadius:he,defaultMarkerColor:P,noPanClassName:ve,disableKeyboardA11y:ue,rfId:Ee}),r(A9,{style:b,type:g,component:x,containerStyle:y}),r("div",{className:"react-flow__edgelabel-renderer"}),r(n9,{nodeTypes:e,onNodeClick:o,onNodeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:p,nodeClickDistance:Y,onlyRenderVisibleElements:E,noPanClassName:ve,noDragClassName:ie,disableKeyboardA11y:ue,nodeExtent:Ne,rfId:Ee}),r("div",{className:"react-flow__viewport-portal"})]})})}A0.displayName="GraphView";const _9=Te(A0),Nf=({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:u,zIndexMode:h="basic"}={})=>{const m=new Map,g=new Map,b=new Map,x=new Map,y=o??t??[],w=n??e??[],v=p??[0,0],N=u??qr;qx(b,x,y);const{nodesInitialized:S}=Vi(w,m,g,{nodeOrigin:v,nodeExtent:N,zIndexMode:h});let k=[0,0,1];if(i&&s&&a){const M=co(m,{filter:A=>!!((A.width||A.initialWidth)&&(A.height||A.initialHeight))}),{x:D,y:E,zoom:B}=Mc(M,s,a,c,d,l?.padding??.1);k=[D,E,B]}return{rfId:"1",width:s??0,height:a??0,transform:k,nodes:w,nodesInitialized:S,nodeLookup:m,parentLookup:g,edges:y,edgeLookup:x,connectionLookup:b,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:o!==void 0,panZoom:null,minZoom:c,maxZoom:d,translateExtent:qr,nodeExtent:N,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Jn.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:{...Mx},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:V6,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:Cx,zIndexMode:h,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},T9=({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:s,height:a,fitView:i,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:p,nodeExtent:u,zIndexMode:h})=>ZB((m,g)=>{async function b(){const{nodeLookup:x,panZoom:y,fitViewOptions:w,fitViewResolver:v,width:N,height:S,minZoom:k,maxZoom:M}=g();y&&(await H6({nodes:x,width:N,height:S,panZoom:y,minZoom:k,maxZoom:M},w),v?.resolve(!0),m({fitViewResolver:null}))}return{...Nf({nodes:e,edges:t,width:s,height:a,fitView:i,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:p,nodeExtent:u,defaultNodes:n,defaultEdges:o,zIndexMode:h}),setNodes:x=>{const{nodeLookup:y,parentLookup:w,nodeOrigin:v,elevateNodesOnSelect:N,fitViewQueued:S,zIndexMode:k,nodesSelectionActive:M}=g(),{nodesInitialized:D,hasSelectedNodes:E}=Vi(x,y,w,{nodeOrigin:v,nodeExtent:u,elevateNodesOnSelect:N,checkEquality:!0,zIndexMode:k}),B=M&&E;S&&D?(b(),m({nodes:x,nodesInitialized:D,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:B})):m({nodes:x,nodesInitialized:D,nodesSelectionActive:B})},setEdges:x=>{const{connectionLookup:y,edgeLookup:w}=g();qx(y,w,x),m({edges:x})},setDefaultNodesAndEdges:(x,y)=>{if(x){const{setNodes:w}=g();w(x),m({hasDefaultNodes:!0})}if(y){const{setEdges:w}=g();w(y),m({hasDefaultEdges:!0})}},updateNodeInternals:x=>{const{triggerNodeChanges:y,nodeLookup:w,parentLookup:v,domNode:N,nodeOrigin:S,nodeExtent:k,debug:M,fitViewQueued:D,zIndexMode:E}=g(),{changes:B,updatedInternals:A}=uB(x,w,v,N,S,k,E);A&&(iB(w,v,{nodeOrigin:S,nodeExtent:k,zIndexMode:E}),D?(b(),m({fitViewQueued:!1,fitViewOptions:void 0})):m({}),B?.length>0&&(M&&console.log("React Flow: trigger node changes",B),y?.(B)))},updateNodePositions:(x,y=!1)=>{const w=[];let v=[];const{nodeLookup:N,triggerNodeChanges:S,connection:k,updateConnection:M,onNodesChangeMiddlewareMap:D}=g();for(const[E,B]of x){const A=N.get(E),O=!!(A?.expandParent&&A?.parentId&&B?.position),$={id:E,type:"position",position:O?{x:Math.max(0,B.position.x),y:Math.max(0,B.position.y)}:B.position,dragging:y};if(A&&k.inProgress&&k.fromNode.id===A.id){const I=Mn(A,k.fromHandle,be.Left,!0);M({...k,from:I})}O&&A.parentId&&w.push({id:E,parentId:A.parentId,rect:{...B.internals.positionAbsolute,width:B.measured.width??0,height:B.measured.height??0}}),v.push($)}if(w.length>0){const{parentLookup:E,nodeOrigin:B}=g(),A=Dc(w,N,E,B);v.push(...A)}for(const E of D.values())v=E(v);S(v)},triggerNodeChanges:x=>{const{onNodesChange:y,setNodes:w,nodes:v,hasDefaultNodes:N,debug:S}=g();if(x?.length){if(N){const k=x8(x,v);w(k)}S&&console.log("React Flow: trigger node changes",x),y?.(x)}},triggerEdgeChanges:x=>{const{onEdgesChange:y,setEdges:w,edges:v,hasDefaultEdges:N,debug:S}=g();if(x?.length){if(N){const k=y8(x,v);w(k)}S&&console.log("React Flow: trigger edge changes",x),y?.(x)}},addSelectedNodes:x=>{const{multiSelectionActive:y,edgeLookup:w,nodeLookup:v,triggerNodeChanges:N,triggerEdgeChanges:S}=g();if(y){const k=x.map(M=>pn(M,!0));N(k);return}N(Bn(v,new Set([...x]),!0)),S(Bn(w))},addSelectedEdges:x=>{const{multiSelectionActive:y,edgeLookup:w,nodeLookup:v,triggerNodeChanges:N,triggerEdgeChanges:S}=g();if(y){const k=x.map(M=>pn(M,!0));S(k);return}S(Bn(w,new Set([...x]))),N(Bn(v,new Set,!0))},unselectNodesAndEdges:({nodes:x,edges:y}={})=>{const{edges:w,nodes:v,nodeLookup:N,triggerNodeChanges:S,triggerEdgeChanges:k}=g(),M=x||v,D=y||w,E=[];for(const A of M){if(!A.selected)continue;const O=N.get(A.id);O&&(O.selected=!1),E.push(pn(A.id,!1))}const B=[];for(const A of D)A.selected&&B.push(pn(A.id,!1));S(E),k(B)},setMinZoom:x=>{const{panZoom:y,maxZoom:w}=g();y?.setScaleExtent([x,w]),m({minZoom:x})},setMaxZoom:x=>{const{panZoom:y,minZoom:w}=g();y?.setScaleExtent([w,x]),m({maxZoom:x})},setTranslateExtent:x=>{g().panZoom?.setTranslateExtent(x),m({translateExtent:x})},resetSelectedElements:()=>{const{edges:x,nodes:y,triggerNodeChanges:w,triggerEdgeChanges:v,elementsSelectable:N}=g();if(!N)return;const S=y.reduce((M,D)=>D.selected?[...M,pn(D.id,!1)]:M,[]),k=x.reduce((M,D)=>D.selected?[...M,pn(D.id,!1)]:M,[]);w(S),v(k)},setNodeExtent:x=>{const{nodes:y,nodeLookup:w,parentLookup:v,nodeOrigin:N,elevateNodesOnSelect:S,nodeExtent:k,zIndexMode:M}=g();x[0][0]===k[0][0]&&x[0][1]===k[0][1]&&x[1][0]===k[1][0]&&x[1][1]===k[1][1]||(Vi(y,w,v,{nodeOrigin:N,nodeExtent:x,elevateNodesOnSelect:S,checkEquality:!1,zIndexMode:M}),m({nodeExtent:x}))},panBy:x=>{const{transform:y,width:w,height:v,panZoom:N,translateExtent:S}=g();return fB({delta:x,panZoom:N,transform:y,translateExtent:S,width:w,height:v})},setCenter:async(x,y,w)=>{const{width:v,height:N,maxZoom:S,panZoom:k}=g();if(!k)return Promise.resolve(!1);const M=typeof w?.zoom<"u"?w.zoom:S;return await k.setViewport({x:v/2-x*M,y:N/2-y*M,zoom:M},{duration:w?.duration,ease:w?.ease,interpolate:w?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{m({connection:{...Mx}})},updateConnection:x=>{m({connection:x})},reset:()=>m({...Nf()})}},Object.is);function R9({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:o,initialWidth:s,initialHeight:a,initialMinZoom:i,initialMaxZoom:l,initialFitViewOptions:c,fitView:d,nodeOrigin:p,nodeExtent:u,zIndexMode:h,children:m}){const[g]=L(()=>T9({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:s,height:a,fitView:d,minZoom:i,maxZoom:l,fitViewOptions:c,nodeOrigin:p,nodeExtent:u,zIndexMode:h}));return r(XB,{value:g,children:r(N8,{children:m})})}function L9({children:e,nodes:t,edges:n,defaultNodes:o,defaultEdges:s,width:a,height:i,fitView:l,fitViewOptions:c,minZoom:d,maxZoom:p,nodeOrigin:u,nodeExtent:h,zIndexMode:m}){return ge(ta)?r(ye,{children:e}):r(R9,{initialNodes:t,initialEdges:n,defaultNodes:o,defaultEdges:s,initialWidth:a,initialHeight:i,fitView:l,initialFitViewOptions:c,initialMinZoom:d,initialMaxZoom:p,nodeOrigin:u,nodeExtent:h,zIndexMode:m,children:e})}const O9={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function B9({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,className:s,nodeTypes:a,edgeTypes:i,onNodeClick:l,onEdgeClick:c,onInit:d,onMove:p,onMoveStart:u,onMoveEnd:h,onConnect:m,onConnectStart:g,onConnectEnd:b,onClickConnectStart:x,onClickConnectEnd:y,onNodeMouseEnter:w,onNodeMouseMove:v,onNodeMouseLeave:N,onNodeContextMenu:S,onNodeDoubleClick:k,onNodeDragStart:M,onNodeDrag:D,onNodeDragStop:E,onNodesDelete:B,onEdgesDelete:A,onDelete:O,onSelectionChange:$,onSelectionDragStart:I,onSelectionDrag:_,onSelectionDragStop:P,onSelectionContextMenu:T,onSelectionStart:R,onSelectionEnd:z,onBeforeDelete:H,connectionMode:F,connectionLineType:j=Xt.Bezier,connectionLineStyle:J,connectionLineComponent:W,connectionLineContainerStyle:ne,deleteKeyCode:de="Backspace",selectionKeyCode:te="Shift",selectionOnDrag:K=!1,selectionMode:oe=Ur.Full,panActivationKeyCode:me="Space",multiSelectionKeyCode:Y=Gr()?"Meta":"Control",zoomActivationKeyCode:G=Gr()?"Meta":"Control",snapToGrid:Z,snapGrid:re,onlyRenderVisibleElements:pe=!1,selectNodesOnDrag:he,nodesDraggable:V,autoPanOnNodeFocus:se,nodesConnectable:ce,nodesFocusable:ie,nodeOrigin:ae=s0,edgesFocusable:ve,edgesReconnectable:ue,elementsSelectable:Ne=!0,defaultViewport:Ee=u8,minZoom:He=.5,maxZoom:We=2,translateExtent:Tn=qr,preventScrolling:fe=!0,nodeExtent:Ce,defaultMarkerColor:Ie="#b1b1b7",zoomOnScroll:Pe=!0,zoomOnPinch:an=!0,panOnScroll:ln=!1,panOnScrollSpeed:pr=.5,panOnScrollMode:R0=xn.Free,zoomOnDoubleClick:L0=!0,panOnDrag:O0=!0,onPaneClick:B0,onPaneMouseEnter:z0,onPaneMouseMove:F0,onPaneMouseLeave:H0,onPaneScroll:j0,onPaneContextMenu:V0,paneClickDistance:q0=1,nodeClickDistance:U0=0,children:Q0,onReconnect:G0,onReconnectStart:W0,onReconnectEnd:K0,onEdgeContextMenu:Y0,onEdgeDoubleClick:Z0,onEdgeMouseEnter:X0,onEdgeMouseMove:J0,onEdgeMouseLeave:ey,reconnectRadius:ty=10,onNodesChange:ny,onEdgesChange:ry,noDragClassName:oy="nodrag",noWheelClassName:sy="nowheel",noPanClassName:Rc="nopan",fitView:Lc,fitViewOptions:Oc,connectOnClick:ay,attributionPosition:iy,proOptions:ly,defaultEdgeOptions:cy,elevateNodesOnSelect:dy=!0,elevateEdgesOnSelect:uy=!1,disableKeyboardA11y:Bc=!1,autoPanOnConnect:fy,autoPanOnNodeDrag:py,autoPanSpeed:hy,connectionRadius:my,isValidConnection:gy,onError:by,style:xy,id:zc,nodeDragThreshold:yy,connectionDragThreshold:vy,viewport:wy,onViewportChange:Ny,width:Sy,height:ky,colorMode:Cy="light",debug:My,onScroll:Fc,ariaLabelConfig:Iy,zIndexMode:Hc="basic",...Ey},Py){const sa=zc||"1",Ay=m8(Cy),$y=q(jc=>{jc.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),Fc?.(jc)},[Fc]);return r("div",{"data-testid":"rf__wrapper",...Ey,onScroll:$y,style:{...xy,...O9},ref:Py,className:ze(["react-flow",s,Ay]),id:zc,role:"application",children:f(L9,{nodes:e,edges:t,width:Sy,height:ky,fitView:Lc,fitViewOptions:Oc,minZoom:He,maxZoom:We,nodeOrigin:ae,nodeExtent:Ce,zIndexMode:Hc,children:[r(h8,{nodes:e,edges:t,defaultNodes:n,defaultEdges:o,onConnect:m,onConnectStart:g,onConnectEnd:b,onClickConnectStart:x,onClickConnectEnd:y,nodesDraggable:V,autoPanOnNodeFocus:se,nodesConnectable:ce,nodesFocusable:ie,edgesFocusable:ve,edgesReconnectable:ue,elementsSelectable:Ne,elevateNodesOnSelect:dy,elevateEdgesOnSelect:uy,minZoom:He,maxZoom:We,nodeExtent:Ce,onNodesChange:ny,onEdgesChange:ry,snapToGrid:Z,snapGrid:re,connectionMode:F,translateExtent:Tn,connectOnClick:ay,defaultEdgeOptions:cy,fitView:Lc,fitViewOptions:Oc,onNodesDelete:B,onEdgesDelete:A,onDelete:O,onNodeDragStart:M,onNodeDrag:D,onNodeDragStop:E,onSelectionDrag:_,onSelectionDragStart:I,onSelectionDragStop:P,onMove:p,onMoveStart:u,onMoveEnd:h,noPanClassName:Rc,nodeOrigin:ae,rfId:sa,autoPanOnConnect:fy,autoPanOnNodeDrag:py,autoPanSpeed:hy,onError:by,connectionRadius:my,isValidConnection:gy,selectNodesOnDrag:he,nodeDragThreshold:yy,connectionDragThreshold:vy,onBeforeDelete:H,debug:My,ariaLabelConfig:Iy,zIndexMode:Hc}),r(_9,{onInit:d,onNodeClick:l,onEdgeClick:c,onNodeMouseEnter:w,onNodeMouseMove:v,onNodeMouseLeave:N,onNodeContextMenu:S,onNodeDoubleClick:k,nodeTypes:a,edgeTypes:i,connectionLineType:j,connectionLineStyle:J,connectionLineComponent:W,connectionLineContainerStyle:ne,selectionKeyCode:te,selectionOnDrag:K,selectionMode:oe,deleteKeyCode:de,multiSelectionKeyCode:Y,panActivationKeyCode:me,zoomActivationKeyCode:G,onlyRenderVisibleElements:pe,defaultViewport:Ee,translateExtent:Tn,minZoom:He,maxZoom:We,preventScrolling:fe,zoomOnScroll:Pe,zoomOnPinch:an,zoomOnDoubleClick:L0,panOnScroll:ln,panOnScrollSpeed:pr,panOnScrollMode:R0,panOnDrag:O0,onPaneClick:B0,onPaneMouseEnter:z0,onPaneMouseMove:F0,onPaneMouseLeave:H0,onPaneScroll:j0,onPaneContextMenu:V0,paneClickDistance:q0,nodeClickDistance:U0,onSelectionContextMenu:T,onSelectionStart:R,onSelectionEnd:z,onReconnect:G0,onReconnectStart:W0,onReconnectEnd:K0,onEdgeContextMenu:Y0,onEdgeDoubleClick:Z0,onEdgeMouseEnter:X0,onEdgeMouseMove:J0,onEdgeMouseLeave:ey,reconnectRadius:ty,defaultMarkerColor:Ie,noDragClassName:oy,noWheelClassName:sy,noPanClassName:Rc,rfId:sa,disableKeyboardA11y:Bc,nodeExtent:Ce,viewport:wy,onViewportChange:Ny}),r(d8,{onSelectionChange:$}),Q0,r(s8,{proOptions:ly,position:iy}),r(o8,{rfId:sa,disableKeyboardA11y:Bc})]})})}var z9=i0(B9);function F9({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:ze(["react-flow__background-pattern",n,o])})}function H9({radius:e,className:t}){return r("circle",{cx:e,cy:e,r:e,className:ze(["react-flow__background-pattern","dots",t])})}var en;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(en||(en={}));const j9={[en.Dots]:1,[en.Lines]:1,[en.Cross]:6},V9=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function $0({id:e,variant:t=en.Dots,gap:n=20,size:o,lineWidth:s=1,offset:a=0,color:i,bgColor:l,style:c,className:d,patternClassName:p}){const u=ee(null),{transform:h,patternId:m}=Me(V9,_e),g=o||j9[t],b=t===en.Dots,x=t===en.Cross,y=Array.isArray(n)?n:[n,n],w=[y[0]*h[2]||1,y[1]*h[2]||1],v=g*h[2],N=Array.isArray(a)?a:[a,a],S=x?[v,v]:w,k=[N[0]*h[2]||1+S[0]/2,N[1]*h[2]||1+S[1]/2],M=`${m}${e||""}`;return f("svg",{className:ze(["react-flow__background",d]),style:{...c,...ra,"--xy-background-color-props":l,"--xy-background-pattern-color-props":i},ref:u,"data-testid":"rf__background",children:[r("pattern",{id:M,x:h[0]%w[0],y:h[1]%w[1],width:w[0],height:w[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${k[0]},-${k[1]})`,children:b?r(H9,{radius:v/2,className:p}):r(F9,{dimensions:S,lineWidth:s,variant:t,className:p})}),r("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${M})`})]})}$0.displayName="Background";const q9=Te($0);function U9(){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 Q9(){return r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:r("path",{d:"M0 0h32v4.2H0z"})})}function G9(){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 W9(){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 K9(){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 Oo({children:e,className:t,...n}){return r("button",{type:"button",className:ze(["react-flow__controls-button",t]),...n,children:e})}const Y9=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function D0({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:u="bottom-left",orientation:h="vertical","aria-label":m}){const g=Re(),{isInteractive:b,minZoomReached:x,maxZoomReached:y,ariaLabelConfig:w}=Me(Y9,_e),{zoomIn:v,zoomOut:N,fitView:S}=_c(),k=()=>{v(),a?.()},M=()=>{N(),i?.()},D=()=>{S(s),l?.()},E=()=>{g.setState({nodesDraggable:!b,nodesConnectable:!b,elementsSelectable:!b}),c?.(!b)};return f(na,{className:ze(["react-flow__controls",h==="horizontal"?"horizontal":"vertical",d]),position:u,style:e,"data-testid":"rf__controls","aria-label":m??w["controls.ariaLabel"],children:[t&&f(ye,{children:[r(Oo,{onClick:k,className:"react-flow__controls-zoomin",title:w["controls.zoomIn.ariaLabel"],"aria-label":w["controls.zoomIn.ariaLabel"],disabled:y,children:r(U9,{})}),r(Oo,{onClick:M,className:"react-flow__controls-zoomout",title:w["controls.zoomOut.ariaLabel"],"aria-label":w["controls.zoomOut.ariaLabel"],disabled:x,children:r(Q9,{})})]}),n&&r(Oo,{className:"react-flow__controls-fitview",onClick:D,title:w["controls.fitView.ariaLabel"],"aria-label":w["controls.fitView.ariaLabel"],children:r(G9,{})}),o&&r(Oo,{className:"react-flow__controls-interactive",onClick:E,title:w["controls.interactive.ariaLabel"],"aria-label":w["controls.interactive.ariaLabel"],children:b?r(K9,{}):r(W9,{})}),p]})}D0.displayName="Controls";const Z9=Te(D0);function X9({id:e,x:t,y:n,width:o,height:s,style:a,color:i,strokeColor:l,strokeWidth:c,className:d,borderRadius:p,shapeRendering:u,selected:h,onClick:m}){const{background:g,backgroundColor:b}=a||{},x=i||g||b;return r("rect",{className:ze(["react-flow__minimap-node",{selected:h},d]),x:t,y:n,rx:p,ry:p,width:o,height:s,style:{fill:x,stroke:l,strokeWidth:c},shapeRendering:u,onClick:m?y=>m(y,e):void 0})}const J9=Te(X9),ez=e=>e.nodes.map(t=>t.id),Ya=e=>e instanceof Function?e:()=>e;function tz({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:o=5,nodeStrokeWidth:s,nodeComponent:a=J9,onClick:i}){const l=Me(ez,_e),c=Ya(t),d=Ya(e),p=Ya(n),u=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return r(ye,{children:l.map(h=>r(rz,{id:h,nodeColorFunc:c,nodeStrokeColorFunc:d,nodeClassNameFunc:p,nodeBorderRadius:o,nodeStrokeWidth:s,NodeComponent:a,onClick:i,shapeRendering:u},h))})}function nz({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:o,nodeBorderRadius:s,nodeStrokeWidth:a,shapeRendering:i,NodeComponent:l,onClick:c}){const{node:d,x:p,y:u,width:h,height:m}=Me(g=>{const b=g.nodeLookup.get(e);if(!b)return{node:void 0,x:0,y:0,width:0,height:0};const x=b.internals.userNode,{x:y,y:w}=b.internals.positionAbsolute,{width:v,height:N}=Kt(x);return{node:x,x:y,y:w,width:v,height:N}},_e);return!d||d.hidden||!_x(d)?null:r(l,{x:p,y:u,width:h,height:m,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 rz=Te(nz);var oz=Te(tz);const sz=200,az=150,iz=e=>!e.hidden,lz=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?Dx(co(e.nodeLookup,{filter:iz}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},cz="react-flow__minimap-desc";function _0({style:e,className:t,nodeStrokeColor:n,nodeColor:o,nodeClassName:s="",nodeBorderRadius:a=5,nodeStrokeWidth:i,nodeComponent:l,bgColor:c,maskColor:d,maskStrokeColor:p,maskStrokeWidth:u,position:h="bottom-right",onClick:m,onNodeClick:g,pannable:b=!1,zoomable:x=!1,ariaLabel:y,inversePan:w,zoomStep:v=1,offsetScale:N=5}){const S=Re(),k=ee(null),{boundingRect:M,viewBB:D,rfId:E,panZoom:B,translateExtent:A,flowWidth:O,flowHeight:$,ariaLabelConfig:I}=Me(lz,_e),_=e?.width??sz,P=e?.height??az,T=M.width/_,R=M.height/P,z=Math.max(T,R),H=z*_,F=z*P,j=N*z,J=M.x-(H-M.width)/2-j,W=M.y-(F-M.height)/2-j,ne=H+j*2,de=F+j*2,te=`${cz}-${E}`,K=ee(0),oe=ee();K.current=z,X(()=>{if(k.current&&B)return oe.current=wB({domNode:k.current,panZoom:B,getTransform:()=>S.getState().transform,getViewScale:()=>K.current}),()=>{oe.current?.destroy()}},[B]),X(()=>{oe.current?.update({translateExtent:A,width:O,height:$,inversePan:w,pannable:b,zoomStep:v,zoomable:x})},[b,x,w,v,A,O,$]);const me=m?Z=>{const[re,pe]=oe.current?.pointer(Z)||[0,0];m(Z,{x:re,y:pe})}:void 0,Y=g?q((Z,re)=>{const pe=S.getState().nodeLookup.get(re).internals.userNode;g(Z,pe)},[]):void 0,G=y??I["minimap.ariaLabel"];return r(na,{position:h,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 u=="number"?u*z: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:ze(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:f("svg",{width:_,height:P,viewBox:`${J} ${W} ${ne} ${de}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":te,ref:k,onClick:me,children:[G&&r("title",{id:te,children:G}),r(oz,{onClick:Y,nodeColor:o,nodeStrokeColor:n,nodeBorderRadius:a,nodeClassName:s,nodeStrokeWidth:i,nodeComponent:l}),r("path",{className:"react-flow__minimap-mask",d:`M${J-j},${W-j}h${ne+j*2}v${de+j*2}h${-ne-j*2}z
533
- M${D.x},${D.y}h${D.width}v${D.height}h${-D.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}_0.displayName="MiniMap";Te(_0);const dz=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,uz={[rr.Line]:"right",[rr.Handle]:"bottom-right"};function fz({nodeId:e,position:t,variant:n=rr.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:u=!1,resizeDirection:h,autoScale:m=!0,shouldResize:g,onResizeStart:b,onResize:x,onResizeEnd:y}){const w=u0(),v=typeof e=="string"?e:w,N=Re(),S=ee(null),k=n===rr.Handle,M=Me(q(dz(k&&m),[k,m]),_e),D=ee(null),E=t??uz[n];X(()=>{if(!(!S.current||!v))return D.current||(D.current=RB({domNode:S.current,nodeId:v,getStoreItems:()=>{const{nodeLookup:A,transform:O,snapGrid:$,snapToGrid:I,nodeOrigin:_,domNode:P}=N.getState();return{nodeLookup:A,transform:O,snapGrid:$,snapToGrid:I,nodeOrigin:_,paneDomNode:P}},onChange:(A,O)=>{const{triggerNodeChanges:$,nodeLookup:I,parentLookup:_,nodeOrigin:P}=N.getState(),T=[],R={x:A.x,y:A.y},z=I.get(v);if(z&&z.expandParent&&z.parentId){const H=z.origin??P,F=A.width??z.measured.width??0,j=A.height??z.measured.height??0,J={id:z.id,parentId:z.parentId,rect:{width:F,height:j,...Tx({x:A.x??z.position.x,y:A.y??z.position.y},{width:F,height:j},z.parentId,I,H)}},W=Dc([J],I,_,P);T.push(...W),R.x=A.x?Math.max(H[0]*F,A.x):void 0,R.y=A.y?Math.max(H[1]*j,A.y):void 0}if(R.x!==void 0&&R.y!==void 0){const H={id:v,type:"position",position:{...R}};T.push(H)}if(A.width!==void 0&&A.height!==void 0){const F={id:v,type:"dimensions",resizing:!0,setAttributes:h?h==="horizontal"?"width":"height":!0,dimensions:{width:A.width,height:A.height}};T.push(F)}for(const H of O){const F={...H,type:"position"};T.push(F)}$(T)},onEnd:({width:A,height:O})=>{const $={id:v,type:"dimensions",resizing:!1,dimensions:{width:A,height:O}};N.getState().triggerNodeChanges([$])}})),D.current.update({controlPosition:E,boundaries:{minWidth:l,minHeight:c,maxWidth:d,maxHeight:p},keepAspectRatio:u,resizeDirection:h,onResizeStart:b,onResize:x,onResizeEnd:y,shouldResize:g}),()=>{D.current?.destroy()}},[E,l,c,d,p,u,b,x,y,g]);const B=E.split("-");return r("div",{className:ze(["react-flow__resize-control","nodrag",...B,n,o]),ref:S,style:{...s,scale:M,...i&&{[k?"backgroundColor":"borderColor"]:i}},children:a})}Te(fz);function pz({data:e,selected:t}){const n=e.isOnline,o=e.isHub,s=e.engines??[],a=e.addons??[],i=e.processes??[],l=e.name,c=e.hostname,d=e.localIps??[],p=e.cpuPercent,u=e.memoryPercent,h=e.isExpanded,m=e.onToggleExpand,g=e.onShowNodeLogs,b=e.onRestartNode,x=e.id,y=i.length,w=q(M=>{M.stopPropagation(),m?.()},[m]),v=q(M=>{M.stopPropagation(),g?.()},[g]),N=q(M=>{M.stopPropagation(),b?.()},[b]);return f("div",{className:`rounded-xl bg-surface px-3 py-2.5 min-w-[180px] max-w-[260px] transition-all duration-200 ${n?o?"border-2 border-success":"border-2 border-dashed border-primary/60 bg-primary/5":"border-2 border-dashed border-muted-foreground/30 opacity-50"} ${t?"ring-2 ring-primary ring-offset-1":""}`,children:[r(tn,{type:"target",position:be.Top,className:"!bg-border !w-2 !h-2"}),f("div",{className:"flex items-center gap-1.5 mb-1.5",children:[r("div",{className:`w-2 h-2 rounded-full ${n?"bg-success":"bg-destructive"}`}),r("span",{className:"text-xs font-semibold truncate flex-1",children:l}),o?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"})]}),(c||d.length>0)&&(()=>{const M=d.filter(D=>!D.includes(":"));return f("div",{className:"text-[9px] text-muted-foreground mb-1 space-y-0.5",title:[c,...d].filter(Boolean).join(", "),children:[c&&r("div",{className:"truncate",children:c}),M.length>0&&r("div",{className:"truncate font-mono opacity-70",children:M.join(", ")})]})})(),s.length>0&&r("div",{className:"flex flex-wrap gap-1 mb-1.5",children:s.map(M=>r("span",{className:"text-[8px] px-1 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium",children:M},M))}),a.length>0&&f("div",{className:"text-[9px] text-muted-foreground mb-1",children:[a.length," addon",a.length!==1?"s":""," in-process"]}),n&&f("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground",children:[f("span",{className:"flex items-center gap-0.5",children:[r(tt,{className:"h-2.5 w-2.5"}),p,"%"]}),f("span",{className:"flex items-center gap-0.5",children:[r(dc,{className:"h-2.5 w-2.5"}),u,"%"]}),f("div",{className:"flex items-center gap-1 ml-auto",children:[y>0&&f("button",{onClick:w,className:"flex items-center gap-0.5 px-1 py-0.5 rounded hover:bg-amber-500/10 text-amber-500 transition-colors",title:h?"Collapse processes":`Expand ${y} process${y!==1?"es":""}`,children:[h?r(It,{className:"h-3 w-3"}):r($t,{className:"h-3 w-3"}),r("span",{className:"text-[9px] font-medium",children:y})]}),r("button",{onClick:v,className:"p-0.5 rounded hover:bg-primary/10 text-muted-foreground hover:text-primary transition-colors",title:`Logs: ${x}`,children:r(st,{className:"h-3 w-3"})}),r("button",{onClick:N,className:"p-0.5 rounded hover:bg-primary/10 text-muted-foreground hover:text-primary transition-colors",title:"Restart all processes",children:r(wn,{className:"h-3 w-3"})})]})]}),!n&&r("div",{className:"text-[10px] text-muted-foreground",children:"offline"}),r(tn,{type:"source",position:be.Bottom,className:"!bg-border !w-2 !h-2"})]})}const hz=Te(pz);function mz(e){return e===0?"0":e<1024*1024?`${Math.round(e/1024)}K`:e<1024*1024*1024?`${Math.round(e/(1024*1024))}M`:`${(e/(1024*1024*1024)).toFixed(1)}G`}function gz({data:e}){const t=e.name,n=e.state,o=e.pid,s=e.cpuPercent,a=e.memoryRss,i=e.addonId,l=e.services??[],c=e.isExpanded,d=e.onToggleServices,p=e.parentNodeId,u=e.onShowLogs,h=e.onRestartAddon,m=n==="running",g=t.includes("(core)"),b=!g&&l.length===1,x=b?l[0]:null,y=p??"hub",w=`${y}/${t}`,v=q(M=>{M.stopPropagation(),d?.()},[d]),N=g?ro:zs,S=g?"border-primary/50":m?"border-amber-500/50":"border-destructive/50",k=g?"text-primary":"text-amber-500";return f("div",{className:`rounded-lg bg-surface min-w-[150px] border ${S} ${c?"max-w-[240px]":"max-w-[210px]"}`,children:[r(tn,{type:"target",position:be.Top,className:`!w-1.5 !h-1.5 ${g?"!bg-primary":"!bg-amber-500"}`}),f("div",{className:"px-2.5 pt-2 pb-1.5",children:[f("div",{className:"flex items-start gap-1.5 mb-1.5",children:[r(N,{className:`h-3 w-3 ${k} shrink-0 mt-0.5`}),r("span",{className:"text-[10px] font-semibold truncate flex-1",children:g?"core":i??t}),r("span",{className:"text-[8px] text-muted-foreground/60 tabular-nums shrink-0",children:o})]}),f("div",{className:"flex items-center gap-2 text-[9px] text-muted-foreground",children:[r("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${m?"bg-success":"bg-destructive"}`}),f("span",{className:"flex items-center gap-0.5",children:[r(tt,{className:"h-2 w-2"}),s,"%"]}),f("span",{className:"flex items-center gap-0.5",children:[r(dc,{className:"h-2 w-2"}),mz(a)]}),b&&x?f("div",{className:"flex items-center gap-0.5 ml-auto",children:[r("button",{onClick:M=>{M.stopPropagation(),u?.(x.addonId,y)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors",title:`Logs: ${x.addonId}`,children:r(st,{className:"h-2.5 w-2.5"})}),r("button",{onClick:M=>{M.stopPropagation(),h?.(x.addonId,w)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors",title:`Restart: ${x.addonId}`,children:r(wn,{className:"h-2.5 w-2.5"})})]}):l.length>0?f("button",{onClick:v,className:"flex items-center gap-0.5 ml-auto px-0.5 rounded hover:bg-blue-500/10 text-blue-400 transition-colors",title:c?"Hide addons":`Show ${l.length} addon${l.length!==1?"s":""}`,children:[c?r(It,{className:"h-2.5 w-2.5"}):r($t,{className:"h-2.5 w-2.5"}),r("span",{className:"text-[8px] font-medium",children:l.length})]}):null]})]}),c&&l.length>0&&!b&&r("div",{className:"border-t border-border/40 px-2 py-1 space-y-0.5 max-h-[200px] overflow-y-auto",children:l.map(M=>{const D=g?y:`${y}/${t}`;return f("div",{className:"flex items-center gap-1 py-0.5",children:[r("div",{className:`w-1 h-1 rounded-full shrink-0 ${M.status==="running"?"bg-success":"bg-muted-foreground/30"}`}),r("span",{className:"text-[9px] truncate flex-1",children:M.addonId}),r("button",{onClick:E=>{E.stopPropagation(),u?.(M.addonId,y)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors",title:`Logs: ${M.addonId}`,children:r(st,{className:"h-2.5 w-2.5"})}),r("button",{onClick:E=>{E.stopPropagation(),h?.(M.addonId,D)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors",title:`Restart: ${M.addonId}`,children:r(wn,{className:"h-2.5 w-2.5"})})]},M.addonId)})}),r(tn,{type:"source",position:be.Bottom,className:`!w-1.5 !h-1.5 ${g?"!bg-primary":"!bg-amber-500"}`})]})}const bz=Te(gz),xz={clusterNode:hz,processNode:bz},Sf=280,kf=40,Cf=280,Mf=200,yz=150;function vz({topology:e}){const{resolvedMode:t}=Xr(),n=pm(),o=As(),[,s]=L(null),[a,i]=L(()=>e.length<=1?new Set(e.map(M=>M.id)):new Set),[l,c]=L(null),[d,p]=L(null),u=q((M,D)=>{p(E=>E?.addonId===M&&E?.agentId===D?null:{addonId:M,agentId:D})},[]),h=q(M=>{p(D=>D?.agentId===M&&!D?.addonId?null:{agentId:M})},[]),m=q(async M=>{try{await n.mutateAsync({nodeId:M})}catch(D){console.error("Failed to restart node:",D)}},[n]),g=q(async(M,D)=>{try{await o.mutateAsync({nodeId:D,addonId:M})}catch(E){console.error("Failed to restart addon:",E)}},[o]),b=q(M=>{i(D=>{const E=new Set(D);return E.has(M)?E.delete(M):E.add(M),E})},[]),x=q(M=>{c(D=>D===M?null:M)},[]),y=q(M=>{s(M)},[]),w=Q(()=>{const M=e.filter(_=>_.isHub),D=e.filter(_=>!_.isHub),E=[],B=[],A=M[0]?.id,O=A?a.has(A):!1;function $(_,P,T,R){const z=[...R];if(z.length===0)return;const H=(z.length-1)*Mf,F=P-H/2,j=T+yz;for(let J=0;J<z.length;J++){const W=z[J],ne=`proc:${_}/${W.name}`,de=W.services??[],te=l===ne;E.push({id:ne,type:"processNode",position:{x:F+J*Mf,y:j},data:{...W,addonId:W.name.includes("(core)")?void 0:de.length>1?W.name:de[0]?.addonId??W.name,parentNodeId:_,services:de,isExpanded:te,onToggleServices:()=>x(ne),onShowLogs:u,onRestartAddon:g}}),B.push({id:`edge:${_}-${ne}`,source:_,target:ne,animated:!0,style:{stroke:"var(--amber-500, #f59e0b)",strokeWidth:1,strokeDasharray:"4 4"}})}}for(const _ of M){const P=Math.max(0,(D.length-1)*Sf)/2;E.push({id:_.id,type:"clusterNode",position:{x:P,y:kf},data:{..._,label:_.name,isExpanded:a.has(_.id),onToggleExpand:()=>b(_.id),onShowDetail:()=>y(_.id),onShowNodeLogs:()=>h(_.id),onRestartNode:()=>m(_.id)}}),a.has(_.id)&&$(_.id,P,kf,_.processes??[])}const I=O?Cf+120:Cf;for(let _=0;_<D.length;_++){const P=D[_],T=_*Sf;E.push({id:P.id,type:"clusterNode",position:{x:T,y:I},data:{...P,label:P.name,isExpanded:a.has(P.id),onToggleExpand:()=>b(P.id),onShowDetail:()=>y(P.id),onShowNodeLogs:()=>h(P.id),onRestartNode:()=>m(P.id)}}),A&&P.isOnline&&B.push({id:`${A}-${P.id}`,source:A,target:P.id,animated:!0,style:{stroke:"var(--border)",strokeWidth:1.5}}),a.has(P.id)&&$(P.id,T,I,P.processes??[])}return{nodes:E,edges:B}},[e,a,l,b,x,y,u,h,m,g]),v=ee(new Map),N=Q(()=>{const M=v.current;return w.nodes.map(E=>({...E,position:M.get(E.id)??E.position}))},[w.nodes]),S=q(M=>{for(const D of M)D.type==="position"&&D.position&&v.current.set(D.id,D.position)},[]),k=q(()=>s(null),[]);return r("div",{className:"flex flex-col gap-4 flex-1",children:f("div",{className:"relative flex-1 min-h-[350px] border border-border rounded-xl overflow-hidden",children:[f(z9,{nodes:N,edges:w.edges,onNodesChange:S,onPaneClick:k,nodeTypes:xz,nodesConnectable:!1,fitView:!0,fitViewOptions:{padding:.2,maxZoom:1.2},proOptions:{hideAttribution:!0},className:"bg-background",colorMode:t,children:[r(q9,{gap:20,size:1}),r(Z9,{showInteractive:!1})]}),d&&r(Ng,{addonId:d.addonId,agentId:d.agentId,showScope:!0,onClose:()=>p(null)})]})})}function wz({onlineNodeIds:e}){const t=ke(),n=on(),{data:o,isLoading:s}=ir(),a=Om({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:f("div",{className:"flex flex-col items-center gap-2 text-center text-muted-foreground",children:[r(yi,{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."})]})}):f("section",{className:"rounded-lg border border-border bg-surface",children:[f("header",{className:"flex items-center gap-2 px-4 py-3 border-b border-border",children:[r(yi,{className:"h-4 w-4 text-muted-foreground"}),r("h2",{className:"text-sm font-semibold",children:"Offline agents"}),f("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(u=>u?.enabled).length;return f("li",{className:"flex items-center gap-3 px-4 py-2 text-xs",children:[r("span",{className:"font-mono text-foreground",children:c.nodeId}),f("span",{className:"text-muted-foreground",children:[d," addons configured",d>0&&f(ye,{children:[" · ",p," enabled"]})]}),f("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(nt,{className:"h-3 w-3"}),"Remove"]})]},c.nodeId)})})]})}function Nz(e){const[t,n]=L(()=>typeof window<"u"?window.matchMedia(e).matches:!1);return X(()=>{const o=window.matchMedia(e),s=a=>n(a.matches);return o.addEventListener("change",s),()=>o.removeEventListener("change",s)},[e]),t}function Sz(){const{data:e,isLoading:t}=sn(void 0,{staleTime:1/0}),[n,o]=L(null);return et("cluster.topology-snapshot",a=>{const i=a.data?.nodes;Array.isArray(i)&&o(i)}),{nodes:Q(()=>n??e??[],[n,e]),isLoading:t&&!n}}function kz(){const[e,t]=L("diagram"),n=Nz("(max-width: 767px)"),o=n&&e==="diagram"?"table":e,{nodes:s,isLoading:a}=Sz(),i=s.filter(h=>h.isOnline).length,l=s.filter(h=>!h.isOnline).length,c=Q(()=>s.map(h=>h.id??"").filter(Boolean),[s]),{data:d}=ir(),p=Q(()=>{if(!d)return 0;const h=new Set(c);return h.add("hub"),d.filter(m=>!h.has(m.nodeId)).length},[d,c]),u=(h,m,g,b)=>f("button",{onClick:()=>t(h),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${e===h?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,children:[r(g,{className:"h-3.5 w-3.5"}),m,b!==void 0&&b>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===h?"bg-primary-foreground/20 text-primary-foreground":"bg-destructive/15 text-destructive"}`,children:b})]});return f("div",{className:"flex flex-col h-full gap-4 p-4",children:[f("div",{className:"flex items-center justify-between",children:[f("div",{className:"flex items-center gap-3",children:[r("h1",{className:"text-xl font-semibold",children:"Cluster"}),i>0&&f("span",{className:"text-xs px-2 py-0.5 rounded-full bg-success/10 text-success",children:[i," online"]}),l>0&&f("span",{className:"text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive",children:[l," offline"]})]}),f("div",{className:"flex gap-0.5 p-1 rounded-lg bg-muted",children:[!n&&u("diagram","Diagram",uc),u("table","Table",pA),u("offline-agents","Offline agents",yi,p)]})]}),a?r("div",{className:"flex items-center justify-center flex-1 text-muted-foreground",children:"Loading cluster topology..."}):o==="diagram"?r(vz,{topology:s}):o==="table"?r("div",{className:"flex-1 overflow-auto",children:r(rR,{nodes:s})}):r("div",{className:"flex-1 overflow-auto",children:r(wz,{onlineNodeIds:c})})]})}function Rt({title:e,children:t}){return f("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 Ue({name:e,cssVar:t,hex:n}){const o=t?`var(${t})`:n;return f("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 Cz={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 Mz(){const[e,t]=L({name:"Example",count:10,enabled:!0,mode:"a",tags:["camera"],confidence:60});return f("div",{className:"p-6 space-y-6 max-w-5xl mx-auto",children:[f("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(Rt,{title:"Typography",children:f("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(Rt,{title:"Colors",children:f("div",{className:"flex flex-wrap gap-4",children:[r(Ue,{name:"primary",cssVar:"--color-primary"}),r(Ue,{name:"background",cssVar:"--color-background"}),r(Ue,{name:"surface",cssVar:"--color-surface"}),r(Ue,{name:"foreground",cssVar:"--color-foreground"}),r(Ue,{name:"success",cssVar:"--color-success"}),r(Ue,{name:"warning",cssVar:"--color-warning"}),r(Ue,{name:"danger",cssVar:"--color-danger"}),r(Ue,{name:"info",cssVar:"--color-info"}),r(Ue,{name:"border",cssVar:"--color-border"}),r("div",{className:"w-px"}),r(Ue,{name:"frigate",hex:"#3b82f6"}),r(Ue,{name:"scrypted",hex:"#a855f7"}),r(Ue,{name:"reolink",hex:"#06b6d4"}),r(Ue,{name:"ha",hex:"#22d3ee"}),r(Ue,{name:"rtsp",hex:"#78716c"})]})}),r(Rt,{title:"Buttons",children:f("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(Rt,{title:"Inputs",children:f("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[f("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..."})]}),f("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"})]}),f("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:"••••••••"})]}),f("div",{children:[r("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Select"}),f("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"})]})]}),f("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:f("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:f("div",{className:"flex items-center justify-between",children:[r("span",{className:"text-xs font-medium text-foreground",children:"Toggle switch"}),r(Iz,{})]})}),f("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})]}),f("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(Rt,{title:"Badges",children:f("div",{className:"space-y-3",children:[f("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(qs,{status:n},n))})]}),f("div",{children:[r("p",{className:"text-xs text-foreground-subtle mb-2",children:"CapabilityBadges"}),r(js,{capabilities:["streaming","detection","recording","audio"]})]})]})}),r(Rt,{title:"Cards",children:f("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[f("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."})]}),f("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`."})]}),f("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."})]}),f("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(Rt,{title:"Provider Icons",children:r("div",{className:"flex flex-wrap gap-4",children:["frigate","scrypted","reolink","homeassistant","rtsp","onvif"].map(n=>r(Vt,{type:n,size:"lg",showLabel:!0},n))})}),f(Rt,{title:"Form Builder Demo",children:[r(Yn,{schema:Cz,values:e,onChange:t}),f("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(Rt,{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 f("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 Iz(){const[e,t]=L(!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 If={info:{bg:"bg-blue-500/10",border:"border-blue-500/30",icon:ts},warning:{bg:"bg-orange-500/10",border:"border-orange-500/30",icon:Bt},critical:{bg:"bg-red-500/10",border:"border-red-500/30",icon:Fs}};function Ez({toast:e,onDismiss:t}){const n=If[e.severity]??If.info,o=n.icon;return X(()=>{const s=e.duration??5e3;if(s<=0)return;const a=setTimeout(()=>t(e.id),s);return()=>clearTimeout(a)},[e.id,e.duration,t]),f("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"}),f("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(qe,{className:"h-3.5 w-3.5 text-foreground-subtle"})})]})}function Pz(){const[e,t]=L([]),n=q(o=>{t(s=>s.filter(a=>a.id!==o))},[]);return og(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(Ez,{toast:o,onDismiss:n})},o.id))})}const Gi=new Tf({defaultOptions:{queries:{staleTime:3e4,retry:!1,refetchOnWindowFocus:!1}}});function Az({field:e,value:t,onChange:n,disabled:o}){return r(AA,{field:e,value:t,onChange:n,disabled:o})}function $z({field:e,value:t,onChange:n,disabled:o}){return r(FA,{field:e,value:t,onChange:n,disabled:o})}const Dz={"zone-editor":oP,"live-stats":aP,"pipeline-editor":Az,"model-selector":$z,"live-stream-viewer":jA,"pipeline-stats":VA,"stream-network-stats":qA,"doorbell-recent":QA,"device-info":gb};function _z({children:e}){const{user:t}=oo(),[n,o]=L(0),s=ee(t?.username??null);X(()=>{const u=t?.username??null;u!==s.current&&(s.current=u,Mr(),o(h=>h+1))},[t]);const a=Q(()=>xi(),[n]),[i,l]=L(!1),[c,d]=L(null);X(()=>{if(l(!1),d(null),!t){l(!0);return}let u=!1;return a.init().then(()=>{u||l(!0)},h=>{if(u)return;const m=h instanceof Error?h.message:String(h);d(m),l(!0)}),()=>{u=!0}},[a,t]);const p=q(()=>{Mr(),o(u=>u+1),Gi.invalidateQueries()},[]);return JE(p),r(wl,{system:a,children:r(C.Provider,{client:a.trpcClient,queryClient:Gi,children:f(lg,{children:[i?e:r(Tz,{}),c!==null&&i&&f("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:f("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 Rz(){return r(Go,{defaultMode:"dark",children:r(Rf,{client:Gi,children:r(s$,{children:r(_z,{children:r(Kp,{children:f(mh,{renderers:Dz,children:[r(jE,{children:f(bE,{children:[r(Be,{path:"/login",element:r(lD,{})}),r(Be,{path:"/access-denied",element:r(cD,{})}),r(Be,{path:"/showroom",element:r(Mz,{})}),f(Be,{element:r(cn,{children:r(iD,{})}),children:[r(Be,{index:!0,element:r(es,{to:"/dashboard",replace:!0})}),r(Be,{path:"/dashboard",element:r(vD,{})}),r(Be,{path:"/devices",element:r(ND,{})}),r(Be,{path:"/cameras",element:r(es,{to:"/devices",replace:!0})}),r(Be,{path:"/integrations",element:r(_D,{})}),r(Be,{path:"/integrations/:integrationId",element:r(OD,{})}),r(Be,{path:"/timeline",element:r(GD,{})}),r(Be,{path:"/pipeline",element:r(E_,{})}),r(Be,{path:"/devices/:deviceId",element:r(CT,{})}),r(Be,{path:"/system/logs",element:r(cn,{requiredRole:"admin",children:r(OT,{})})}),r(Be,{path:"/system/users",element:r(cn,{requiredRole:"admin",children:r(BT,{})})}),r(Be,{path:"/system/addons",element:r(cn,{requiredRole:"admin",children:r(LT,{})})}),r(Be,{path:"/system/settings",element:r(cn,{requiredRole:"admin",children:r(zT,{})})}),r(Be,{path:"/system/cluster",element:r(cn,{requiredRole:"admin",children:r(kz,{})})}),r(Be,{path:"/addon/:pagePath",element:r(cn,{requiredRole:"admin",children:r(oD,{})})})]})]})}),r(Pz,{})]})})})})})})}const Lz={dashboard:"Dashboard",integrations:"Integrations",metrics:"Metrics"},Oz={title:"System",addons:"Addons",agents:"Agents",processes:"Processes",logs:"Logs",users:"Users",settings:"Settings",repl:"REPL",models:"Models"},Bz={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"},zz={disconnected:"Server unreachable — reconnecting…",connected:"Connected"},Fz={online:"Online",offline:"Offline",connecting:"Connecting",error:"Error",disabled:"Disabled",enabled:"Enabled",active:"Active",inactive:"Inactive",running:"Running",stopped:"Stopped",pending:"Pending",unknown:"Unknown"},Hz={login:"Login",logout:"Logout",username:"Username",password:"Password",signIn:"Sign In",invalidCredentials:"Invalid username or password"},jz={dark:"Dark",light:"Light",system:"System"},Vz={select:"Language",en:"English",it:"Italian"},qz={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"}},Uz={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"},Qz={nav:Lz,system:Oz,common:Bz,connection:zz,status:Fz,auth:Hz,theme:jz,language:Vz,pages:qz,integrations:Uz},Gz={dashboard:"Dashboard",integrations:"Integrazioni",metrics:"Metriche"},Wz={title:"Sistema",addons:"Addon",agents:"Agenti",processes:"Processi",logs:"Log",users:"Utenti",settings:"Impostazioni",repl:"REPL",models:"Modelli"},Kz={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"},Yz={disconnected:"Server non raggiungibile — riconnessione in corso…",connected:"Connesso"},Zz={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"},Xz={login:"Accesso",logout:"Esci",username:"Nome utente",password:"Password",signIn:"Accedi",invalidCredentials:"Nome utente o password non validi"},Jz={dark:"Scuro",light:"Chiaro",system:"Sistema"},eF={select:"Lingua",en:"Inglese",it:"Italiano"},tF={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"}},nF={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"},rF={nav:Gz,system:Wz,common:Kz,connection:Yz,status:Zz,auth:Xz,theme:Jz,language:eF,pages:tF,integrations:nF},T0="camstack_language",oF=localStorage.getItem(T0)??"en";je.use(z$).init({resources:{en:{translation:Qz},it:{translation:rF}},lng:oF,fallbackLng:"en",interpolation:{escapeValue:!1}});je.on("languageChanged",e=>{localStorage.setItem(T0,e)});window.__camstackUiLibrary=gI;window.__camstackSdk=Gv;window.__camstackTypes=Wv;Df(document.getElementById("root")).render(r(By,{children:r(Rz,{})}));