@camstack/addon-admin-ui 0.1.32 → 0.1.33

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 (33) hide show
  1. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BvoC1uIr.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DJQnlBBe.js} +1 -1
  2. package/dist/assets/devices-BnLu5dxg.js +1 -0
  3. package/dist/assets/{hostInit-CD-dnMZ2.js → hostInit-DQ5UjxJa.js} +1 -1
  4. package/dist/assets/{index-BNUjZ59A.js → index-BmzE49kT.js} +1 -1
  5. package/dist/assets/index-CMxz0koW.js +1 -0
  6. package/dist/assets/{index-C8aWpOFF.js → index-DFRMwfPq.js} +1 -1
  7. package/dist/assets/{index-Dof0D05-.js → index-DIIqKU3D.js} +1 -1
  8. package/dist/assets/index-DRW7rVhn.js +1133 -0
  9. package/dist/assets/index-DYSrVZ4G.js +1 -0
  10. package/dist/assets/index-DeVjiPqm.js +1 -0
  11. package/dist/assets/index-DuHBxCOe.js +1 -0
  12. package/dist/assets/{index-CKhqqfAc.js → index-Dv0-1gwL.js} +16 -16
  13. package/dist/assets/{index-Dq8saJUq.js → index-NNW--T4H.js} +18 -18
  14. package/dist/assets/index-dePEzy7t.js +1 -0
  15. package/dist/assets/index-n9RexO7D.css +1 -0
  16. package/dist/assets/method-access-map-OoQznstl.js +1 -0
  17. package/dist/assets/{remoteEntry-E_9jWgvF.js → remoteEntry-D28y34bi.js} +1 -1
  18. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-FAYxIu3o.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BXwMMqlX.js} +2 -2
  19. package/dist/index.html +6 -6
  20. package/dist/mf-entry-bootstrap-0.js +2 -2
  21. package/dist/server/addon.js +13478 -1
  22. package/dist/server/addon.js.map +1 -1
  23. package/dist/sw.js +1 -1
  24. package/package.json +1 -1
  25. package/dist/assets/devices-CcY42G4T.js +0 -1
  26. package/dist/assets/index-BpxWBuRz.js +0 -1
  27. package/dist/assets/index-C9g_lFQt.css +0 -1
  28. package/dist/assets/index-CC-f1IDN.js +0 -1
  29. package/dist/assets/index-DSlV9M7V.js +0 -1
  30. package/dist/assets/index-Dyl6moOt.js +0 -1128
  31. package/dist/assets/index-XLuKU1k9.js +0 -1
  32. package/dist/assets/index-dYszggWP.js +0 -1
  33. package/dist/assets/method-access-map-DMzoJQA1.js +0 -1
@@ -1,1128 +0,0 @@
1
- import"./virtualExposes-_ivNhQLP.js";import{d as kr}from"./virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-FAYxIu3o.js";import{c as o,a as Nh,d as u,e as me,g as hN}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_1_jsx_mf_2_runtime__loadShare__.mjs-C_6K4VBY.js";import{b as Be,e as P,h as U,c as Y,f as q,d as ve,a as kh,j as qe,k as Me,i as ne,l as Qn,m as ba,g as xa,R as ic,n as lc,o as mN,p as gN,q as Sr,r as He,s as bN,t as xN,u as yN,v as vN}from"./__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs-Dl4u0xYE.js";import{a as Sh,b as Lo}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs-CzO_Esxm.js";import{a as Ch,b as Mh}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs-DNpf5SLz.js";import{_ as Eh,m as tr,n as ke,o as Ih,p as Ah,h as cc,j as wN}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs-CeLhKMin.js";import{_ as Ph,c as _h,s as $h,n as NN,B as kN,F as SN}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_client__loadShare__.mjs-DIkg6-MH.js";import{_ as Dh,a as CN}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs-OcRSBqRe.js";import{c as MN,D as Hn,a as it,M as EN,W as cl,S as IN,b as AN,d as _s}from"./index-BpxWBuRz.js";import{S as dl,c as Th}from"./devices-CcY42G4T.js";import{E as Ne,A as PN,K as _N}from"./method-access-map-DMzoJQA1.js";import{s as $N}from"./index-BNUjZ59A.js";import{a as pu,C as DN,S as fu,s as TN}from"./index-C8aWpOFF.js";import{r as Lh}from"./__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs_commonjs-proxy-CSyOECfO.js";import{_ as LN}from"./preload-helper-BlTxHScW.js";import"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-xw6c6JeS.js";import"./schemas-DZqswtjx.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"]'))r(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"&&r(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 r(s){if(s.ep)return;s.ep=!0;const a=n(s);fetch(s.href,a)}})();const Rh={frigate:"#3b82f6",scrypted:"#a855f7",reolink:"#06b6d4",homeAssistant:"#22d3ee",rtsp:"#78716c"},Oh={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:Rh},Bh={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:Rh},ul={colors:{dark:Oh,light:Bh},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 zh(e,t){const n={...e};for(const r in t){const s=t[r],a=e[r];s!==void 0&&typeof s=="object"&&s!==null&&!Array.isArray(s)&&typeof a=="object"&&a!==null?n[r]=zh(a,s):s!==void 0&&(n[r]=s)}return n}function RN(e){return e?zh(structuredClone(ul),e):structuredClone(ul)}function Fh(e){return e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function ON(e){return`--color-${Fh(e)}`}function hu(e){const t=[];for(const[n,r]of Object.entries(e))n!=="provider"&&t.push(` ${ON(n)}: ${r};`);return t.join(`
2
- `)}function BN(e){const t=[];for(const[n,r]of Object.entries(e))t.push(` --color-provider-${Fh(n)}: ${r};`);return t.join(`
3
- `)}function zN(e){const t=[];for(const[n,r]of Object.entries(e))t.push(` --spacing-${n}: ${r}px;`);return t.join(`
4
- `)}function FN(e){const t=[];for(const[n,r]of Object.entries(e))t.push(` --radius-${n}: ${r}px;`);return t.join(`
5
- `)}function jN(e){const t=hu(e.colors.dark),n=hu(e.colors.light),r=BN(e.colors.dark.provider),s=zN(e.spacing),a=FN(e.radius);return`@theme {
6
- ${r}
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 jh=Be(null),li=["dark","light","system"];function Hh(){return typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function HN(e,t){if(typeof window>"u")return t;const n=localStorage.getItem(e);return n==="dark"||n==="light"||n==="system"?n:t}function mu(e){return e==="system"?Hh():e}function Vs({children:e,defaultMode:t="system",storageKey:n="camstack-theme-mode"}){const[r,s]=P(()=>HN(n,t)),[a,i]=P(()=>mu(r)),l=U(f=>{s(f),i(mu(f)),typeof window<"u"&&localStorage.setItem(n,f)},[n]),c=U(()=>{const p=(li.indexOf(r)+1)%li.length;l(li[p]??"dark")},[r,l]);Y(()=>{if(typeof document>"u")return;const f=document.documentElement;f.classList.remove("dark","light"),f.classList.add(a)},[r,a]),Y(()=>{if(typeof window>"u"||r!=="system")return;const f=window.matchMedia("(prefers-color-scheme: dark)"),p=()=>{i(Hh())};return f.addEventListener("change",p),()=>f.removeEventListener("change",p)},[r]);const d=q(()=>({mode:r,resolvedMode:a,setMode:l,toggleMode:c}),[r,a,l,c]);return o(jh.Provider,{value:d,children:e})}function Or(){const e=ve(jh);if(!e)throw new Error("useThemeMode must be used within a ThemeProvider");return e}function Vh(e){var t,n,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var s=e.length;for(t=0;t<s;t++)e[t]&&(n=Vh(e[t]))&&(r&&(r+=" "),r+=n)}else for(n in e)e[n]&&(r&&(r+=" "),r+=n);return r}function qh(){for(var e,t,n=0,r="",s=arguments.length;n<s;n++)(e=arguments[n])&&(t=Vh(e))&&(r&&(r+=" "),r+=t);return r}const VN=(e,t)=>{const n=new Array(e.length+t.length);for(let r=0;r<e.length;r++)n[r]=e[r];for(let r=0;r<t.length;r++)n[e.length+r]=t[r];return n},qN=(e,t)=>({classGroupId:e,validator:t}),Uh=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),qs="-",gu=[],UN="arbitrary..",QN=e=>{const t=KN(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:i=>{if(i.startsWith("[")&&i.endsWith("]"))return GN(i);const l=i.split(qs),c=l[0]===""&&l.length>1?1:0;return Qh(l,c,t)},getConflictingClassGroupIds:(i,l)=>{if(l){const c=r[i],d=n[i];return c?d?VN(d,c):c:d||gu}return n[i]||gu}}},Qh=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;const s=e[t],a=n.nextPart.get(s);if(a){const d=Qh(e,t+1,a);if(d)return d}const i=n.validators;if(i===null)return;const l=t===0?e.join(qs):e.slice(t).join(qs),c=i.length;for(let d=0;d<c;d++){const f=i[d];if(f.validator(l))return f.classGroupId}},GN=e=>e.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const t=e.slice(1,-1),n=t.indexOf(":"),r=t.slice(0,n);return r?UN+r:void 0})(),KN=e=>{const{theme:t,classGroups:n}=e;return WN(n,t)},WN=(e,t)=>{const n=Uh();for(const r in e){const s=e[r];dc(s,n,r,t)}return n},dc=(e,t,n,r)=>{const s=e.length;for(let a=0;a<s;a++){const i=e[a];YN(i,t,n,r)}},YN=(e,t,n,r)=>{if(typeof e=="string"){ZN(e,t,n);return}if(typeof e=="function"){XN(e,t,n,r);return}JN(e,t,n,r)},ZN=(e,t,n)=>{const r=e===""?t:Gh(t,e);r.classGroupId=n},XN=(e,t,n,r)=>{if(e2(e)){dc(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(qN(n,e))},JN=(e,t,n,r)=>{const s=Object.entries(e),a=s.length;for(let i=0;i<a;i++){const[l,c]=s[i];dc(c,Gh(t,l),n,r)}},Gh=(e,t)=>{let n=e;const r=t.split(qs),s=r.length;for(let a=0;a<s;a++){const i=r[a];let l=n.nextPart.get(i);l||(l=Uh(),n.nextPart.set(i,l)),n=l}return n},e2=e=>"isThemeGetter"in e&&e.isThemeGetter===!0,t2=e=>{if(e<1)return{get:()=>{},set:()=>{}};let t=0,n=Object.create(null),r=Object.create(null);const s=(a,i)=>{n[a]=i,t++,t>e&&(t=0,r=n,n=Object.create(null))};return{get(a){let i=n[a];if(i!==void 0)return i;if((i=r[a])!==void 0)return s(a,i),i},set(a,i){a in n?n[a]=i:s(a,i)}}},pl="!",bu=":",n2=[],xu=(e,t,n,r,s)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:s}),r2=e=>{const{prefix:t,experimentalParseClassName:n}=e;let r=s=>{const a=[];let i=0,l=0,c=0,d;const f=s.length;for(let b=0;b<f;b++){const x=s[b];if(i===0&&l===0){if(x===bu){a.push(s.slice(c,b)),c=b+1;continue}if(x==="/"){d=b;continue}}x==="["?i++:x==="]"?i--:x==="("?l++:x===")"&&l--}const p=a.length===0?s:s.slice(c);let h=p,m=!1;p.endsWith(pl)?(h=p.slice(0,-1),m=!0):p.startsWith(pl)&&(h=p.slice(1),m=!0);const g=d&&d>c?d-c:void 0;return xu(a,m,h,g)};if(t){const s=t+bu,a=r;r=i=>i.startsWith(s)?a(i.slice(s.length)):xu(n2,!1,i,void 0,!0)}if(n){const s=r;r=a=>n({className:a,parseClassName:s})}return r},o2=e=>{const t=new Map;return e.orderSensitiveModifiers.forEach((n,r)=>{t.set(n,1e6+r)}),n=>{const r=[];let s=[];for(let a=0;a<n.length;a++){const i=n[a],l=i[0]==="[",c=t.has(i);l||c?(s.length>0&&(s.sort(),r.push(...s),s=[]),r.push(i)):s.push(i)}return s.length>0&&(s.sort(),r.push(...s)),r}},s2=e=>({cache:t2(e.cacheSize),parseClassName:r2(e),sortModifiers:o2(e),...QN(e)}),a2=/\s+/,i2=(e,t)=>{const{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:s,sortModifiers:a}=t,i=[],l=e.trim().split(a2);let c="";for(let d=l.length-1;d>=0;d-=1){const f=l[d],{isExternal:p,modifiers:h,hasImportantModifier:m,baseClassName:g,maybePostfixModifierPosition:b}=n(f);if(p){c=f+(c.length>0?" "+c:c);continue}let x=!!b,y=r(x?g.substring(0,b):g);if(!y){if(!x){c=f+(c.length>0?" "+c:c);continue}if(y=r(g),!y){c=f+(c.length>0?" "+c:c);continue}x=!1}const w=h.length===0?"":h.length===1?h[0]:a(h).join(":"),v=m?w+pl:w,N=v+y;if(i.indexOf(N)>-1)continue;i.push(N);const k=s(y,x);for(let C=0;C<k.length;++C){const E=k[C];i.push(v+E)}c=f+(c.length>0?" "+c:c)}return c},l2=(...e)=>{let t=0,n,r,s="";for(;t<e.length;)(n=e[t++])&&(r=Kh(n))&&(s&&(s+=" "),s+=r);return s},Kh=e=>{if(typeof e=="string")return e;let t,n="";for(let r=0;r<e.length;r++)e[r]&&(t=Kh(e[r]))&&(n&&(n+=" "),n+=t);return n},c2=(e,...t)=>{let n,r,s,a;const i=c=>{const d=t.reduce((f,p)=>p(f),e());return n=s2(d),r=n.cache.get,s=n.cache.set,a=l,l(c)},l=c=>{const d=r(c);if(d)return d;const f=i2(c,n);return s(c,f),f};return a=i,(...c)=>a(l2(...c))},d2=[],Ge=e=>{const t=n=>n[e]||d2;return t.isThemeGetter=!0,t},Wh=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,Yh=/^\((?:(\w[\w-]*):)?(.+)\)$/i,u2=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,p2=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,f2=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,h2=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,m2=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,g2=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,bn=e=>u2.test(e),Ie=e=>!!e&&!Number.isNaN(Number(e)),xn=e=>!!e&&Number.isInteger(Number(e)),ci=e=>e.endsWith("%")&&Ie(e.slice(0,-1)),en=e=>p2.test(e),Zh=()=>!0,b2=e=>f2.test(e)&&!h2.test(e),uc=()=>!1,x2=e=>m2.test(e),y2=e=>g2.test(e),v2=e=>!xe(e)&&!ye(e),w2=e=>An(e,em,uc),xe=e=>Wh.test(e),Rn=e=>An(e,tm,b2),yu=e=>An(e,A2,Ie),N2=e=>An(e,rm,Zh),k2=e=>An(e,nm,uc),vu=e=>An(e,Xh,uc),S2=e=>An(e,Jh,y2),ns=e=>An(e,om,x2),ye=e=>Yh.test(e),Wr=e=>nr(e,tm),C2=e=>nr(e,nm),wu=e=>nr(e,Xh),M2=e=>nr(e,em),E2=e=>nr(e,Jh),rs=e=>nr(e,om,!0),I2=e=>nr(e,rm,!0),An=(e,t,n)=>{const r=Wh.exec(e);return r?r[1]?t(r[1]):n(r[2]):!1},nr=(e,t,n=!1)=>{const r=Yh.exec(e);return r?r[1]?t(r[1]):n:!1},Xh=e=>e==="position"||e==="percentage",Jh=e=>e==="image"||e==="url",em=e=>e==="length"||e==="size"||e==="bg-size",tm=e=>e==="length",A2=e=>e==="number",nm=e=>e==="family-name",rm=e=>e==="number"||e==="weight",om=e=>e==="shadow",P2=()=>{const e=Ge("color"),t=Ge("font"),n=Ge("text"),r=Ge("font-weight"),s=Ge("tracking"),a=Ge("leading"),i=Ge("breakpoint"),l=Ge("container"),c=Ge("spacing"),d=Ge("radius"),f=Ge("shadow"),p=Ge("inset-shadow"),h=Ge("text-shadow"),m=Ge("drop-shadow"),g=Ge("blur"),b=Ge("perspective"),x=Ge("aspect"),y=Ge("ease"),w=Ge("animate"),v=()=>["auto","avoid","all","avoid-page","page","left","right","column"],N=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],k=()=>[...N(),ye,xe],C=()=>["auto","hidden","clip","visible","scroll"],E=()=>["auto","contain","none"],A=()=>[ye,xe,c],I=()=>[bn,"full","auto",...A()],z=()=>[xn,"none","subgrid",ye,xe],$=()=>["auto",{span:["full",xn,ye,xe]},xn,ye,xe],B=()=>[xn,"auto",ye,xe],R=()=>["auto","min","max","fr",ye,xe],M=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],T=()=>["start","end","center","stretch","center-safe","end-safe"],_=()=>["auto",...A()],L=()=>[bn,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...A()],O=()=>[bn,"screen","full","dvw","lvw","svw","min","max","fit",...A()],j=()=>[bn,"screen","full","lh","dvh","lvh","svh","min","max","fit",...A()],F=()=>[e,ye,xe],H=()=>[...N(),wu,vu,{position:[ye,xe]}],D=()=>["no-repeat",{repeat:["","x","y","space","round"]}],Q=()=>["auto","cover","contain",M2,w2,{size:[ye,xe]}],G=()=>[ci,Wr,Rn],ee=()=>["","none","full",d,ye,xe],se=()=>["",Ie,Wr,Rn],te=()=>["solid","dashed","dotted","double"],Z=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],re=()=>[Ie,ci,wu,vu],be=()=>["","none",g,ye,xe],X=()=>["none",Ie,ye,xe],K=()=>["none",Ie,ye,xe],J=()=>[Ie,ye,xe],ae=()=>[bn,"full",...A()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[en],breakpoint:[en],color:[Zh],container:[en],"drop-shadow":[en],ease:["in","out","in-out"],font:[v2],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[en],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[en],shadow:[en],spacing:["px",Ie],text:[en],"text-shadow":[en],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",bn,xe,ye,x]}],container:["container"],columns:[{columns:[Ie,xe,ye,l]}],"break-after":[{"break-after":v()}],"break-before":[{"break-before":v()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],sr:["sr-only","not-sr-only"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:k()}],overflow:[{overflow:C()}],"overflow-x":[{"overflow-x":C()}],"overflow-y":[{"overflow-y":C()}],overscroll:[{overscroll:E()}],"overscroll-x":[{"overscroll-x":E()}],"overscroll-y":[{"overscroll-y":E()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:I()}],"inset-x":[{"inset-x":I()}],"inset-y":[{"inset-y":I()}],start:[{"inset-s":I(),start:I()}],end:[{"inset-e":I(),end:I()}],"inset-bs":[{"inset-bs":I()}],"inset-be":[{"inset-be":I()}],top:[{top:I()}],right:[{right:I()}],bottom:[{bottom:I()}],left:[{left:I()}],visibility:["visible","invisible","collapse"],z:[{z:[xn,"auto",ye,xe]}],basis:[{basis:[bn,"full","auto",l,...A()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[Ie,bn,"auto","initial","none",xe]}],grow:[{grow:["",Ie,ye,xe]}],shrink:[{shrink:["",Ie,ye,xe]}],order:[{order:[xn,"first","last","none",ye,xe]}],"grid-cols":[{"grid-cols":z()}],"col-start-end":[{col:$()}],"col-start":[{"col-start":B()}],"col-end":[{"col-end":B()}],"grid-rows":[{"grid-rows":z()}],"row-start-end":[{row:$()}],"row-start":[{"row-start":B()}],"row-end":[{"row-end":B()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":R()}],"auto-rows":[{"auto-rows":R()}],gap:[{gap:A()}],"gap-x":[{"gap-x":A()}],"gap-y":[{"gap-y":A()}],"justify-content":[{justify:[...M(),"normal"]}],"justify-items":[{"justify-items":[...T(),"normal"]}],"justify-self":[{"justify-self":["auto",...T()]}],"align-content":[{content:["normal",...M()]}],"align-items":[{items:[...T(),{baseline:["","last"]}]}],"align-self":[{self:["auto",...T(),{baseline:["","last"]}]}],"place-content":[{"place-content":M()}],"place-items":[{"place-items":[...T(),"baseline"]}],"place-self":[{"place-self":["auto",...T()]}],p:[{p:A()}],px:[{px:A()}],py:[{py:A()}],ps:[{ps:A()}],pe:[{pe:A()}],pbs:[{pbs:A()}],pbe:[{pbe:A()}],pt:[{pt:A()}],pr:[{pr:A()}],pb:[{pb:A()}],pl:[{pl:A()}],m:[{m:_()}],mx:[{mx:_()}],my:[{my:_()}],ms:[{ms:_()}],me:[{me:_()}],mbs:[{mbs:_()}],mbe:[{mbe:_()}],mt:[{mt:_()}],mr:[{mr:_()}],mb:[{mb:_()}],ml:[{ml:_()}],"space-x":[{"space-x":A()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":A()}],"space-y-reverse":["space-y-reverse"],size:[{size:L()}],"inline-size":[{inline:["auto",...O()]}],"min-inline-size":[{"min-inline":["auto",...O()]}],"max-inline-size":[{"max-inline":["none",...O()]}],"block-size":[{block:["auto",...j()]}],"min-block-size":[{"min-block":["auto",...j()]}],"max-block-size":[{"max-block":["none",...j()]}],w:[{w:[l,"screen",...L()]}],"min-w":[{"min-w":[l,"screen","none",...L()]}],"max-w":[{"max-w":[l,"screen","none","prose",{screen:[i]},...L()]}],h:[{h:["screen","lh",...L()]}],"min-h":[{"min-h":["screen","lh","none",...L()]}],"max-h":[{"max-h":["screen","lh",...L()]}],"font-size":[{text:["base",n,Wr,Rn]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[r,I2,N2]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",ci,xe]}],"font-family":[{font:[C2,k2,t]}],"font-features":[{"font-features":[xe]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:[s,ye,xe]}],"line-clamp":[{"line-clamp":[Ie,"none",ye,yu]}],leading:[{leading:[a,...A()]}],"list-image":[{"list-image":["none",ye,xe]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",ye,xe]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:F()}],"text-color":[{text:F()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...te(),"wavy"]}],"text-decoration-thickness":[{decoration:[Ie,"from-font","auto",ye,Rn]}],"text-decoration-color":[{decoration:F()}],"underline-offset":[{"underline-offset":[Ie,"auto",ye,xe]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:A()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",ye,xe]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],wrap:[{wrap:["break-word","anywhere","normal"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",ye,xe]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:H()}],"bg-repeat":[{bg:D()}],"bg-size":[{bg:Q()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},xn,ye,xe],radial:["",ye,xe],conic:[xn,ye,xe]},E2,S2]}],"bg-color":[{bg:F()}],"gradient-from-pos":[{from:G()}],"gradient-via-pos":[{via:G()}],"gradient-to-pos":[{to:G()}],"gradient-from":[{from:F()}],"gradient-via":[{via:F()}],"gradient-to":[{to:F()}],rounded:[{rounded:ee()}],"rounded-s":[{"rounded-s":ee()}],"rounded-e":[{"rounded-e":ee()}],"rounded-t":[{"rounded-t":ee()}],"rounded-r":[{"rounded-r":ee()}],"rounded-b":[{"rounded-b":ee()}],"rounded-l":[{"rounded-l":ee()}],"rounded-ss":[{"rounded-ss":ee()}],"rounded-se":[{"rounded-se":ee()}],"rounded-ee":[{"rounded-ee":ee()}],"rounded-es":[{"rounded-es":ee()}],"rounded-tl":[{"rounded-tl":ee()}],"rounded-tr":[{"rounded-tr":ee()}],"rounded-br":[{"rounded-br":ee()}],"rounded-bl":[{"rounded-bl":ee()}],"border-w":[{border:se()}],"border-w-x":[{"border-x":se()}],"border-w-y":[{"border-y":se()}],"border-w-s":[{"border-s":se()}],"border-w-e":[{"border-e":se()}],"border-w-bs":[{"border-bs":se()}],"border-w-be":[{"border-be":se()}],"border-w-t":[{"border-t":se()}],"border-w-r":[{"border-r":se()}],"border-w-b":[{"border-b":se()}],"border-w-l":[{"border-l":se()}],"divide-x":[{"divide-x":se()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":se()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...te(),"hidden","none"]}],"divide-style":[{divide:[...te(),"hidden","none"]}],"border-color":[{border:F()}],"border-color-x":[{"border-x":F()}],"border-color-y":[{"border-y":F()}],"border-color-s":[{"border-s":F()}],"border-color-e":[{"border-e":F()}],"border-color-bs":[{"border-bs":F()}],"border-color-be":[{"border-be":F()}],"border-color-t":[{"border-t":F()}],"border-color-r":[{"border-r":F()}],"border-color-b":[{"border-b":F()}],"border-color-l":[{"border-l":F()}],"divide-color":[{divide:F()}],"outline-style":[{outline:[...te(),"none","hidden"]}],"outline-offset":[{"outline-offset":[Ie,ye,xe]}],"outline-w":[{outline:["",Ie,Wr,Rn]}],"outline-color":[{outline:F()}],shadow:[{shadow:["","none",f,rs,ns]}],"shadow-color":[{shadow:F()}],"inset-shadow":[{"inset-shadow":["none",p,rs,ns]}],"inset-shadow-color":[{"inset-shadow":F()}],"ring-w":[{ring:se()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:F()}],"ring-offset-w":[{"ring-offset":[Ie,Rn]}],"ring-offset-color":[{"ring-offset":F()}],"inset-ring-w":[{"inset-ring":se()}],"inset-ring-color":[{"inset-ring":F()}],"text-shadow":[{"text-shadow":["none",h,rs,ns]}],"text-shadow-color":[{"text-shadow":F()}],opacity:[{opacity:[Ie,ye,xe]}],"mix-blend":[{"mix-blend":[...Z(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":Z()}],"mask-clip":[{"mask-clip":["border","padding","content","fill","stroke","view"]},"mask-no-clip"],"mask-composite":[{mask:["add","subtract","intersect","exclude"]}],"mask-image-linear-pos":[{"mask-linear":[Ie]}],"mask-image-linear-from-pos":[{"mask-linear-from":re()}],"mask-image-linear-to-pos":[{"mask-linear-to":re()}],"mask-image-linear-from-color":[{"mask-linear-from":F()}],"mask-image-linear-to-color":[{"mask-linear-to":F()}],"mask-image-t-from-pos":[{"mask-t-from":re()}],"mask-image-t-to-pos":[{"mask-t-to":re()}],"mask-image-t-from-color":[{"mask-t-from":F()}],"mask-image-t-to-color":[{"mask-t-to":F()}],"mask-image-r-from-pos":[{"mask-r-from":re()}],"mask-image-r-to-pos":[{"mask-r-to":re()}],"mask-image-r-from-color":[{"mask-r-from":F()}],"mask-image-r-to-color":[{"mask-r-to":F()}],"mask-image-b-from-pos":[{"mask-b-from":re()}],"mask-image-b-to-pos":[{"mask-b-to":re()}],"mask-image-b-from-color":[{"mask-b-from":F()}],"mask-image-b-to-color":[{"mask-b-to":F()}],"mask-image-l-from-pos":[{"mask-l-from":re()}],"mask-image-l-to-pos":[{"mask-l-to":re()}],"mask-image-l-from-color":[{"mask-l-from":F()}],"mask-image-l-to-color":[{"mask-l-to":F()}],"mask-image-x-from-pos":[{"mask-x-from":re()}],"mask-image-x-to-pos":[{"mask-x-to":re()}],"mask-image-x-from-color":[{"mask-x-from":F()}],"mask-image-x-to-color":[{"mask-x-to":F()}],"mask-image-y-from-pos":[{"mask-y-from":re()}],"mask-image-y-to-pos":[{"mask-y-to":re()}],"mask-image-y-from-color":[{"mask-y-from":F()}],"mask-image-y-to-color":[{"mask-y-to":F()}],"mask-image-radial":[{"mask-radial":[ye,xe]}],"mask-image-radial-from-pos":[{"mask-radial-from":re()}],"mask-image-radial-to-pos":[{"mask-radial-to":re()}],"mask-image-radial-from-color":[{"mask-radial-from":F()}],"mask-image-radial-to-color":[{"mask-radial-to":F()}],"mask-image-radial-shape":[{"mask-radial":["circle","ellipse"]}],"mask-image-radial-size":[{"mask-radial":[{closest:["side","corner"],farthest:["side","corner"]}]}],"mask-image-radial-pos":[{"mask-radial-at":N()}],"mask-image-conic-pos":[{"mask-conic":[Ie]}],"mask-image-conic-from-pos":[{"mask-conic-from":re()}],"mask-image-conic-to-pos":[{"mask-conic-to":re()}],"mask-image-conic-from-color":[{"mask-conic-from":F()}],"mask-image-conic-to-color":[{"mask-conic-to":F()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:H()}],"mask-repeat":[{mask:D()}],"mask-size":[{mask:Q()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",ye,xe]}],filter:[{filter:["","none",ye,xe]}],blur:[{blur:be()}],brightness:[{brightness:[Ie,ye,xe]}],contrast:[{contrast:[Ie,ye,xe]}],"drop-shadow":[{"drop-shadow":["","none",m,rs,ns]}],"drop-shadow-color":[{"drop-shadow":F()}],grayscale:[{grayscale:["",Ie,ye,xe]}],"hue-rotate":[{"hue-rotate":[Ie,ye,xe]}],invert:[{invert:["",Ie,ye,xe]}],saturate:[{saturate:[Ie,ye,xe]}],sepia:[{sepia:["",Ie,ye,xe]}],"backdrop-filter":[{"backdrop-filter":["","none",ye,xe]}],"backdrop-blur":[{"backdrop-blur":be()}],"backdrop-brightness":[{"backdrop-brightness":[Ie,ye,xe]}],"backdrop-contrast":[{"backdrop-contrast":[Ie,ye,xe]}],"backdrop-grayscale":[{"backdrop-grayscale":["",Ie,ye,xe]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[Ie,ye,xe]}],"backdrop-invert":[{"backdrop-invert":["",Ie,ye,xe]}],"backdrop-opacity":[{"backdrop-opacity":[Ie,ye,xe]}],"backdrop-saturate":[{"backdrop-saturate":[Ie,ye,xe]}],"backdrop-sepia":[{"backdrop-sepia":["",Ie,ye,xe]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":A()}],"border-spacing-x":[{"border-spacing-x":A()}],"border-spacing-y":[{"border-spacing-y":A()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",ye,xe]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[Ie,"initial",ye,xe]}],ease:[{ease:["linear","initial",y,ye,xe]}],delay:[{delay:[Ie,ye,xe]}],animate:[{animate:["none",w,ye,xe]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[b,ye,xe]}],"perspective-origin":[{"perspective-origin":k()}],rotate:[{rotate:X()}],"rotate-x":[{"rotate-x":X()}],"rotate-y":[{"rotate-y":X()}],"rotate-z":[{"rotate-z":X()}],scale:[{scale:K()}],"scale-x":[{"scale-x":K()}],"scale-y":[{"scale-y":K()}],"scale-z":[{"scale-z":K()}],"scale-3d":["scale-3d"],skew:[{skew:J()}],"skew-x":[{"skew-x":J()}],"skew-y":[{"skew-y":J()}],transform:[{transform:[ye,xe,"","none","gpu","cpu"]}],"transform-origin":[{origin:k()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:ae()}],"translate-x":[{"translate-x":ae()}],"translate-y":[{"translate-y":ae()}],"translate-z":[{"translate-z":ae()}],"translate-none":["translate-none"],accent:[{accent:F()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:F()}],"color-scheme":[{scheme:["normal","dark","light","light-dark","only-dark","only-light"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",ye,xe]}],"field-sizing":[{"field-sizing":["fixed","content"]}],"pointer-events":[{"pointer-events":["auto","none"]}],resize:[{resize:["none","","y","x"]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":A()}],"scroll-mx":[{"scroll-mx":A()}],"scroll-my":[{"scroll-my":A()}],"scroll-ms":[{"scroll-ms":A()}],"scroll-me":[{"scroll-me":A()}],"scroll-mbs":[{"scroll-mbs":A()}],"scroll-mbe":[{"scroll-mbe":A()}],"scroll-mt":[{"scroll-mt":A()}],"scroll-mr":[{"scroll-mr":A()}],"scroll-mb":[{"scroll-mb":A()}],"scroll-ml":[{"scroll-ml":A()}],"scroll-p":[{"scroll-p":A()}],"scroll-px":[{"scroll-px":A()}],"scroll-py":[{"scroll-py":A()}],"scroll-ps":[{"scroll-ps":A()}],"scroll-pe":[{"scroll-pe":A()}],"scroll-pbs":[{"scroll-pbs":A()}],"scroll-pbe":[{"scroll-pbe":A()}],"scroll-pt":[{"scroll-pt":A()}],"scroll-pr":[{"scroll-pr":A()}],"scroll-pb":[{"scroll-pb":A()}],"scroll-pl":[{"scroll-pl":A()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",ye,xe]}],fill:[{fill:["none",...F()]}],"stroke-w":[{stroke:[Ie,Wr,Rn,yu]}],stroke:[{stroke:["none",...F()]}],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","inset-bs","inset-be","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-x","border-w-y","border-w-s","border-w-e","border-w-bs","border-w-be","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-x","border-color-y","border-color-s","border-color-e","border-color-bs","border-color-be","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],translate:["translate-x","translate-y","translate-none"],"translate-none":["translate","translate-x","translate-y","translate-z"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mbs","scroll-mbe","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pbs","scroll-pbe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]},orderSensitiveModifiers:["*","**","after","backdrop","before","details-content","file","first-letter","first-line","marker","placeholder","selection"]}},_2=c2(P2);function W(...e){return _2(qh(e))}const $2="rounded-lg border border-border bg-surface overflow-hidden",D2="border-b border-border px-3 sm:px-4 py-1.5 sm:py-2",T2="p-2 sm:p-3 lg:p-4",sm="space-y-3 sm:space-y-4",am="gap-2 sm:gap-3",im="px-3 sm:px-4 py-1.5 sm:py-2",L2="grid grid-cols-2 sm:grid-cols-2 lg:grid-cols-4",R2="grid grid-cols-1 lg:grid-cols-2",O2="flex flex-col-reverse md:flex-row",B2="w-full md:w-44 lg:w-52 md:flex-shrink-0 border-b md:border-b-0 md:border-l border-border",z2="text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider",F2="text-[11px] sm:text-xs text-foreground",Us="text-[10px] text-foreground-subtle",j2="text-[11px] sm:text-xs font-medium text-foreground",fl="text-base sm:text-lg font-semibold leading-tight text-foreground",H2="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",V2="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",q2="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",U2="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",Q2="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",G2="inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors",K2="border-primary/50 bg-primary/15 text-primary",W2="border-border bg-surface text-foreground-subtle hover:bg-surface-hover";function Y2(e,t){for(const n of e.slots)for(const r of n.addons)if(r.id===t)return r;return null}function Z2(e,t){return e.models.find(n=>n.id===t)??null}function X2(e,t){return e.models.find(n=>!!n.formats[t])??null}function J2(e,t){const n=new Set((t.configSchema??[]).map(s=>s.key)),r={};for(const[s,a]of Object.entries(e))n.has(s)&&(r[s]=a);return r}function lm(e){const{source:t,target:n,catalog:r,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=Y2(r,i);if(!c){a.push({addonId:i,outcome:"skip",modelId:null,reason:"addon not in target catalog",patch:null});continue}const d=Z2(c,l.modelId),f=d!==null&&!!d.formats[n.engine.format];let p,h;if(f)p=l.modelId,h="exact";else{const g=X2(c,n.engine.format);if(!g){a.push({addonId:i,outcome:"skip",modelId:null,reason:"no compatible model for target format",patch:null});continue}p=g.id,h="mapped"}const m={enabled:l.enabled,modelId:p,settings:J2(l.settings,c)};a.push({addonId:i,outcome:h,modelId:p,patch:m})}return a}const hl={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 rr(e){return hl[e]??hl.watching}function fn(e,t){if(typeof globalThis>"u")return Be(t);const n=globalThis.__camstackSharedContexts,r=n??new Map;n||(globalThis.__camstackSharedContexts=r);const s=r.get(e);if(s)return s;const a=Be(t);return r.set(e,a),a}function xr(e){const n=(typeof globalThis<"u"?globalThis:void 0)?.[e];return n&&typeof n=="object"?n:{}}const ek={singleton:!0,requiredVersion:!1,eager:!0},jt=e=>({version:"0.0.0",scope:"default",lib:e,shareConfig:ek}),Nu="__mf_module_cache__";function tk(){const e=globalThis,t=e[Nu];if(t&&typeof t=="object"){const r=t;return r.share??={},r.remote??={},r}const n={share:{},remote:{}};return e[Nu]=n,n}function nk(){const e=tk();e.share.react??=kh,e.share["react-dom"]??=Sh,e.share["react-dom/client"]??=Ch,e.share["react/jsx-runtime"]??=Nh,e.share["@tanstack/react-query"]??=Eh,e.share["@trpc/client"]??=Ph,e.share["@trpc/react-query"]??=Dh,e.share["@camstack/ui-library"]??=xr("__camstackUiLibrary"),e.share["@camstack/sdk"]??=xr("__camstackSdk"),e.share["@camstack/types"]??=xr("__camstackTypes")}function pc(){nk(),kr.getInstance()===null&&kr.init({name:"admin_ui_host",remotes:[],shared:{react:jt(()=>kh),"react-dom":jt(()=>Sh),"react-dom/client":jt(()=>Ch),"react/jsx-runtime":jt(()=>Nh),"@tanstack/react-query":jt(()=>Eh),"@trpc/client":jt(()=>Ph),"@trpc/react-query":jt(()=>Dh),"@camstack/ui-library":jt(()=>xr("__camstackUiLibrary")),"@camstack/sdk":jt(()=>xr("__camstackSdk")),"@camstack/types":jt(()=>xr("__camstackTypes"))}})}/**
31
- * @license lucide-react v0.576.0 - ISC
32
- *
33
- * This source code is licensed under the ISC license.
34
- * See the LICENSE file in the root directory of this source tree.
35
- */const cm=(...e)=>e.filter((t,n,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===n).join(" ").trim();/**
36
- * @license lucide-react v0.576.0 - ISC
37
- *
38
- * This source code is licensed under the ISC license.
39
- * See the LICENSE file in the root directory of this source tree.
40
- */const rk=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();/**
41
- * @license lucide-react v0.576.0 - ISC
42
- *
43
- * This source code is licensed under the ISC license.
44
- * See the LICENSE file in the root directory of this source tree.
45
- */const ok=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,r)=>r?r.toUpperCase():n.toLowerCase());/**
46
- * @license lucide-react v0.576.0 - ISC
47
- *
48
- * This source code is licensed under the ISC license.
49
- * See the LICENSE file in the root directory of this source tree.
50
- */const ku=e=>{const t=ok(e);return t.charAt(0).toUpperCase()+t.slice(1)};/**
51
- * @license lucide-react v0.576.0 - ISC
52
- *
53
- * This source code is licensed under the ISC license.
54
- * See the LICENSE file in the root directory of this source tree.
55
- */var sk={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
56
- * @license lucide-react v0.576.0 - ISC
57
- *
58
- * This source code is licensed under the ISC license.
59
- * See the LICENSE file in the root directory of this source tree.
60
- */const ak=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1};/**
61
- * @license lucide-react v0.576.0 - ISC
62
- *
63
- * This source code is licensed under the ISC license.
64
- * See the LICENSE file in the root directory of this source tree.
65
- */const ik=qe(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:s="",children:a,iconNode:i,...l},c)=>Me("svg",{ref:c,...sk,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:cm("lucide",s),...!a&&!ak(l)&&{"aria-hidden":"true"},...l},[...i.map(([d,f])=>Me(d,f)),...Array.isArray(a)?a:[a]]));/**
66
- * @license lucide-react v0.576.0 - ISC
67
- *
68
- * This source code is licensed under the ISC license.
69
- * See the LICENSE file in the root directory of this source tree.
70
- */const le=(e,t)=>{const n=qe(({className:r,...s},a)=>Me(ik,{ref:a,iconNode:t,className:cm(`lucide-${rk(ku(e))}`,`lucide-${e}`,r),...s}));return n.displayName=ku(e),n};/**
71
- * @license lucide-react v0.576.0 - ISC
72
- *
73
- * This source code is licensed under the ISC license.
74
- * See the LICENSE file in the root directory of this source tree.
75
- */const lk=[["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"}]],Nn=le("activity",lk);/**
76
- * @license lucide-react v0.576.0 - ISC
77
- *
78
- * This source code is licensed under the ISC license.
79
- * See the LICENSE file in the root directory of this source tree.
80
- */const ck=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],dk=le("arrow-down",ck);/**
81
- * @license lucide-react v0.576.0 - ISC
82
- *
83
- * This source code is licensed under the ISC license.
84
- * See the LICENSE file in the root directory of this source tree.
85
- */const uk=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],pk=le("arrow-left",uk);/**
86
- * @license lucide-react v0.576.0 - ISC
87
- *
88
- * This source code is licensed under the ISC license.
89
- * See the LICENSE file in the root directory of this source tree.
90
- */const fk=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],hk=le("arrow-right",fk);/**
91
- * @license lucide-react v0.576.0 - ISC
92
- *
93
- * This source code is licensed under the ISC license.
94
- * See the LICENSE file in the root directory of this source tree.
95
- */const mk=[["path",{d:"M5 3h14",key:"7usisc"}],["path",{d:"m18 13-6-6-6 6",key:"1kf1n9"}],["path",{d:"M12 7v14",key:"1akyts"}]],fc=le("arrow-up-to-line",mk);/**
96
- * @license lucide-react v0.576.0 - ISC
97
- *
98
- * This source code is licensed under the ISC license.
99
- * See the LICENSE file in the root directory of this source tree.
100
- */const gk=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],bk=le("arrow-up",gk);/**
101
- * @license lucide-react v0.576.0 - ISC
102
- *
103
- * This source code is licensed under the ISC license.
104
- * See the LICENSE file in the root directory of this source tree.
105
- */const xk=[["path",{d:"M10 10v4",key:"1mb2ec"}],["path",{d:"M14 10v4",key:"1nt88p"}],["path",{d:"M22 14v-4",key:"14q9d5"}],["path",{d:"M6 10v4",key:"1n77qd"}],["rect",{x:"2",y:"6",width:"16",height:"12",rx:"2",key:"13zb55"}]],yk=le("battery-full",xk);/**
106
- * @license lucide-react v0.576.0 - ISC
107
- *
108
- * This source code is licensed under the ISC license.
109
- * See the LICENSE file in the root directory of this source tree.
110
- */const vk=[["path",{d:"M22 14v-4",key:"14q9d5"}],["path",{d:"M6 14v-4",key:"14a6bd"}],["rect",{x:"2",y:"6",width:"16",height:"12",rx:"2",key:"13zb55"}]],wk=le("battery-low",vk);/**
111
- * @license lucide-react v0.576.0 - ISC
112
- *
113
- * This source code is licensed under the ISC license.
114
- * See the LICENSE file in the root directory of this source tree.
115
- */const Nk=[["path",{d:"M10 17h.01",key:"nbq80n"}],["path",{d:"M10 7v6",key:"nne03l"}],["path",{d:"M14 6h2a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2",key:"1m83kb"}],["path",{d:"M22 14v-4",key:"14q9d5"}],["path",{d:"M6 18H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2",key:"h8lgfh"}]],kk=le("battery-warning",Nk);/**
116
- * @license lucide-react v0.576.0 - ISC
117
- *
118
- * This source code is licensed under the ISC license.
119
- * See the LICENSE file in the root directory of this source tree.
120
- */const Sk=[["path",{d:"M 22 14 L 22 10",key:"nqc4tb"}],["rect",{x:"2",y:"6",width:"16",height:"12",rx:"2",key:"13zb55"}]],dm=le("battery",Sk);/**
121
- * @license lucide-react v0.576.0 - ISC
122
- *
123
- * This source code is licensed under the ISC license.
124
- * See the LICENSE file in the root directory of this source tree.
125
- */const Ck=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M22 8c0-2.3-.8-4.3-2-6",key:"5bb3ad"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}],["path",{d:"M4 2C2.8 3.7 2 5.7 2 8",key:"tap9e0"}]],Mk=le("bell-ring",Ck);/**
126
- * @license lucide-react v0.576.0 - ISC
127
- *
128
- * This source code is licensed under the ISC license.
129
- * See the LICENSE file in the root directory of this source tree.
130
- */const Ek=[["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"}]],ya=le("bell",Ek);/**
131
- * @license lucide-react v0.576.0 - ISC
132
- *
133
- * This source code is licensed under the ISC license.
134
- * See the LICENSE file in the root directory of this source tree.
135
- */const Ik=[["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z",key:"uouzyp"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M21 21a4 4 0 0 0-3.81-4",key:"1b0z45"}],["path",{d:"M21 5a4 4 0 0 1-3.55 3.97",key:"5cxbf6"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M3 21a4 4 0 0 1 3.81-4",key:"1fjd4g"}],["path",{d:"M3 5a4 4 0 0 0 3.55 3.97",key:"1d7oge"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M9 7.13V6a3 3 0 1 1 6 0v1.13",key:"1vgav8"}]],Ak=le("bug",Ik);/**
136
- * @license lucide-react v0.576.0 - ISC
137
- *
138
- * This source code is licensed under the ISC license.
139
- * See the LICENSE file in the root directory of this source tree.
140
- */const Pk=[["path",{d:"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z",key:"18u6gg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]],hc=le("camera",Pk);/**
141
- * @license lucide-react v0.576.0 - ISC
142
- *
143
- * This source code is licensed under the ISC license.
144
- * See the LICENSE file in the root directory of this source tree.
145
- */const _k=[["path",{d:"M2 8V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-6",key:"3zrzxg"}],["path",{d:"M2 12a9 9 0 0 1 8 8",key:"g6cvee"}],["path",{d:"M2 16a5 5 0 0 1 4 4",key:"1y1dii"}],["line",{x1:"2",x2:"2.01",y1:"20",y2:"20",key:"xu2jvo"}]],$k=le("cast",_k);/**
146
- * @license lucide-react v0.576.0 - ISC
147
- *
148
- * This source code is licensed under the ISC license.
149
- * See the LICENSE file in the root directory of this source tree.
150
- */const Dk=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Ro=le("check",Dk);/**
151
- * @license lucide-react v0.576.0 - ISC
152
- *
153
- * This source code is licensed under the ISC license.
154
- * See the LICENSE file in the root directory of this source tree.
155
- */const Tk=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],or=le("chevron-down",Tk);/**
156
- * @license lucide-react v0.576.0 - ISC
157
- *
158
- * This source code is licensed under the ISC license.
159
- * See the LICENSE file in the root directory of this source tree.
160
- */const Lk=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Rk=le("chevron-left",Lk);/**
161
- * @license lucide-react v0.576.0 - ISC
162
- *
163
- * This source code is licensed under the ISC license.
164
- * See the LICENSE file in the root directory of this source tree.
165
- */const Ok=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Pn=le("chevron-right",Ok);/**
166
- * @license lucide-react v0.576.0 - ISC
167
- *
168
- * This source code is licensed under the ISC license.
169
- * See the LICENSE file in the root directory of this source tree.
170
- */const Bk=[["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"}]],va=le("circle-alert",Bk);/**
171
- * @license lucide-react v0.576.0 - ISC
172
- *
173
- * This source code is licensed under the ISC license.
174
- * See the LICENSE file in the root directory of this source tree.
175
- */const zk=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],Fk=le("circle-check-big",zk);/**
176
- * @license lucide-react v0.576.0 - ISC
177
- *
178
- * This source code is licensed under the ISC license.
179
- * See the LICENSE file in the root directory of this source tree.
180
- */const jk=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],Hk=le("circle-check",jk);/**
181
- * @license lucide-react v0.576.0 - ISC
182
- *
183
- * This source code is licensed under the ISC license.
184
- * See the LICENSE file in the root directory of this source tree.
185
- */const Vk=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]],qk=le("circle-dot",Vk);/**
186
- * @license lucide-react v0.576.0 - ISC
187
- *
188
- * This source code is licensed under the ISC license.
189
- * See the LICENSE file in the root directory of this source tree.
190
- */const Uk=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"10",x2:"10",y1:"15",y2:"9",key:"c1nkhi"}],["line",{x1:"14",x2:"14",y1:"15",y2:"9",key:"h65svq"}]],Qk=le("circle-pause",Uk);/**
191
- * @license lucide-react v0.576.0 - ISC
192
- *
193
- * This source code is licensed under the ISC license.
194
- * See the LICENSE file in the root directory of this source tree.
195
- */const Gk=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M12 8v8",key:"napkw2"}]],Kk=le("circle-plus",Gk);/**
196
- * @license lucide-react v0.576.0 - ISC
197
- *
198
- * This source code is licensed under the ISC license.
199
- * See the LICENSE file in the root directory of this source tree.
200
- */const Wk=[["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"}]],um=le("circle-question-mark",Wk);/**
201
- * @license lucide-react v0.576.0 - ISC
202
- *
203
- * This source code is licensed under the ISC license.
204
- * See the LICENSE file in the root directory of this source tree.
205
- */const Yk=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],Zk=le("circle-x",Yk);/**
206
- * @license lucide-react v0.576.0 - ISC
207
- *
208
- * This source code is licensed under the ISC license.
209
- * See the LICENSE file in the root directory of this source tree.
210
- */const Xk=[["line",{x1:"15",x2:"15",y1:"12",y2:"18",key:"1p7wdc"}],["line",{x1:"12",x2:"18",y1:"15",y2:"15",key:"1nscbv"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],Jk=le("copy-plus",Xk);/**
211
- * @license lucide-react v0.576.0 - ISC
212
- *
213
- * This source code is licensed under the ISC license.
214
- * See the LICENSE file in the root directory of this source tree.
215
- */const e5=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],_n=le("copy",e5);/**
216
- * @license lucide-react v0.576.0 - ISC
217
- *
218
- * This source code is licensed under the ISC license.
219
- * See the LICENSE file in the root directory of this source tree.
220
- */const t5=[["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"}]],n5=le("cpu",t5);/**
221
- * @license lucide-react v0.576.0 - ISC
222
- *
223
- * This source code is licensed under the ISC license.
224
- * See the LICENSE file in the root directory of this source tree.
225
- */const r5=[["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"}]],pm=le("crosshair",r5);/**
226
- * @license lucide-react v0.576.0 - ISC
227
- *
228
- * This source code is licensed under the ISC license.
229
- * See the LICENSE file in the root directory of this source tree.
230
- */const o5=[["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"}]],s5=le("database",o5);/**
231
- * @license lucide-react v0.576.0 - ISC
232
- *
233
- * This source code is licensed under the ISC license.
234
- * See the LICENSE file in the root directory of this source tree.
235
- */const a5=[["path",{d:"M11 20H2",key:"nlcfvz"}],["path",{d:"M11 4.562v16.157a1 1 0 0 0 1.242.97L19 20V5.562a2 2 0 0 0-1.515-1.94l-4-1A2 2 0 0 0 11 4.561z",key:"au4z13"}],["path",{d:"M11 4H8a2 2 0 0 0-2 2v14",key:"74r1mk"}],["path",{d:"M14 12h.01",key:"1jfl7z"}],["path",{d:"M22 20h-3",key:"vhrsz"}]],fm=le("door-open",a5);/**
236
- * @license lucide-react v0.576.0 - ISC
237
- *
238
- * This source code is licensed under the ISC license.
239
- * See the LICENSE file in the root directory of this source tree.
240
- */const i5=[["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"}]],ml=le("download",i5);/**
241
- * @license lucide-react v0.576.0 - ISC
242
- *
243
- * This source code is licensed under the ISC license.
244
- * See the LICENSE file in the root directory of this source tree.
245
- */const l5=[["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"}]],hm=le("ellipsis-vertical",l5);/**
246
- * @license lucide-react v0.576.0 - ISC
247
- *
248
- * This source code is licensed under the ISC license.
249
- * See the LICENSE file in the root directory of this source tree.
250
- */const c5=[["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"}]],mm=le("external-link",c5);/**
251
- * @license lucide-react v0.576.0 - ISC
252
- *
253
- * This source code is licensed under the ISC license.
254
- * See the LICENSE file in the root directory of this source tree.
255
- */const d5=[["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"}]],gm=le("eye-off",d5);/**
256
- * @license lucide-react v0.576.0 - ISC
257
- *
258
- * This source code is licensed under the ISC license.
259
- * See the LICENSE file in the root directory of this source tree.
260
- */const u5=[["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"}]],Oo=le("eye",u5);/**
261
- * @license lucide-react v0.576.0 - ISC
262
- *
263
- * This source code is licensed under the ISC license.
264
- * See the LICENSE file in the root directory of this source tree.
265
- */const p5=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],bm=le("funnel",p5);/**
266
- * @license lucide-react v0.576.0 - ISC
267
- *
268
- * This source code is licensed under the ISC license.
269
- * See the LICENSE file in the root directory of this source tree.
270
- */const f5=[["circle",{cx:"12",cy:"9",r:"1",key:"124mty"}],["circle",{cx:"19",cy:"9",r:"1",key:"1ruzo2"}],["circle",{cx:"5",cy:"9",r:"1",key:"1a8b28"}],["circle",{cx:"12",cy:"15",r:"1",key:"1e56xg"}],["circle",{cx:"19",cy:"15",r:"1",key:"1a92ep"}],["circle",{cx:"5",cy:"15",r:"1",key:"5r1jwy"}]],h5=le("grip-horizontal",f5);/**
271
- * @license lucide-react v0.576.0 - ISC
272
- *
273
- * This source code is licensed under the ISC license.
274
- * See the LICENSE file in the root directory of this source tree.
275
- */const m5=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],xm=le("house",m5);/**
276
- * @license lucide-react v0.576.0 - ISC
277
- *
278
- * This source code is licensed under the ISC license.
279
- * See the LICENSE file in the root directory of this source tree.
280
- */const g5=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],b5=le("image",g5);/**
281
- * @license lucide-react v0.576.0 - ISC
282
- *
283
- * This source code is licensed under the ISC license.
284
- * See the LICENSE file in the root directory of this source tree.
285
- */const x5=[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]],y5=le("inbox",x5);/**
286
- * @license lucide-react v0.576.0 - ISC
287
- *
288
- * This source code is licensed under the ISC license.
289
- * See the LICENSE file in the root directory of this source tree.
290
- */const v5=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],w5=le("info",v5);/**
291
- * @license lucide-react v0.576.0 - ISC
292
- *
293
- * This source code is licensed under the ISC license.
294
- * See the LICENSE file in the root directory of this source tree.
295
- */const N5=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]],k5=le("layout-grid",N5);/**
296
- * @license lucide-react v0.576.0 - ISC
297
- *
298
- * This source code is licensed under the ISC license.
299
- * See the LICENSE file in the root directory of this source tree.
300
- */const S5=[["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"}]],ym=le("lightbulb",S5);/**
301
- * @license lucide-react v0.576.0 - ISC
302
- *
303
- * This source code is licensed under the ISC license.
304
- * See the LICENSE file in the root directory of this source tree.
305
- */const C5=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],Ot=le("loader-circle",C5);/**
306
- * @license lucide-react v0.576.0 - ISC
307
- *
308
- * This source code is licensed under the ISC license.
309
- * See the LICENSE file in the root directory of this source tree.
310
- */const M5=[["line",{x1:"2",x2:"5",y1:"12",y2:"12",key:"bvdh0s"}],["line",{x1:"19",x2:"22",y1:"12",y2:"12",key:"1tbv5k"}],["line",{x1:"12",x2:"12",y1:"2",y2:"5",key:"11lu5j"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}],["circle",{cx:"12",cy:"12",r:"7",key:"fim9np"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],E5=le("locate-fixed",M5);/**
311
- * @license lucide-react v0.576.0 - ISC
312
- *
313
- * This source code is licensed under the ISC license.
314
- * See the LICENSE file in the root directory of this source tree.
315
- */const I5=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],Su=le("maximize-2",I5);/**
316
- * @license lucide-react v0.576.0 - ISC
317
- *
318
- * This source code is licensed under the ISC license.
319
- * See the LICENSE file in the root directory of this source tree.
320
- */const A5=[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]],P5=le("menu",A5);/**
321
- * @license lucide-react v0.576.0 - ISC
322
- *
323
- * This source code is licensed under the ISC license.
324
- * See the LICENSE file in the root directory of this source tree.
325
- */const _5=[["path",{d:"M12 19v3",key:"npa21l"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["rect",{x:"9",y:"2",width:"6",height:"13",rx:"3",key:"s6n7sd"}]],vm=le("mic",_5);/**
326
- * @license lucide-react v0.576.0 - ISC
327
- *
328
- * This source code is licensed under the ISC license.
329
- * See the LICENSE file in the root directory of this source tree.
330
- */const $5=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],Cu=le("minimize-2",$5);/**
331
- * @license lucide-react v0.576.0 - ISC
332
- *
333
- * This source code is licensed under the ISC license.
334
- * See the LICENSE file in the root directory of this source tree.
335
- */const D5=[["path",{d:"M5 12h14",key:"1ays0h"}]],wm=le("minus",D5);/**
336
- * @license lucide-react v0.576.0 - ISC
337
- *
338
- * This source code is licensed under the ISC license.
339
- * See the LICENSE file in the root directory of this source tree.
340
- */const T5=[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]],mc=le("moon",T5);/**
341
- * @license lucide-react v0.576.0 - ISC
342
- *
343
- * This source code is licensed under the ISC license.
344
- * See the LICENSE file in the root directory of this source tree.
345
- */const L5=[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]],R5=le("music",L5);/**
346
- * @license lucide-react v0.576.0 - ISC
347
- *
348
- * This source code is licensed under the ISC license.
349
- * See the LICENSE file in the root directory of this source tree.
350
- */const O5=[["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"}]],gl=le("network",O5);/**
351
- * @license lucide-react v0.576.0 - ISC
352
- *
353
- * This source code is licensed under the ISC license.
354
- * See the LICENSE file in the root directory of this source tree.
355
- */const B5=[["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"}]],z5=le("pencil",B5);/**
356
- * @license lucide-react v0.576.0 - ISC
357
- *
358
- * This source code is licensed under the ISC license.
359
- * See the LICENSE file in the root directory of this source tree.
360
- */const F5=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],bl=le("play",F5);/**
361
- * @license lucide-react v0.576.0 - ISC
362
- *
363
- * This source code is licensed under the ISC license.
364
- * See the LICENSE file in the root directory of this source tree.
365
- */const j5=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],Bo=le("plus",j5);/**
366
- * @license lucide-react v0.576.0 - ISC
367
- *
368
- * This source code is licensed under the ISC license.
369
- * See the LICENSE file in the root directory of this source tree.
370
- */const H5=[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]],V5=le("plug",H5);/**
371
- * @license lucide-react v0.576.0 - ISC
372
- *
373
- * This source code is licensed under the ISC license.
374
- * See the LICENSE file in the root directory of this source tree.
375
- */const q5=[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],U5=le("power-off",q5);/**
376
- * @license lucide-react v0.576.0 - ISC
377
- *
378
- * This source code is licensed under the ISC license.
379
- * See the LICENSE file in the root directory of this source tree.
380
- */const Q5=[["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"}]],Nm=le("radar",Q5);/**
381
- * @license lucide-react v0.576.0 - ISC
382
- *
383
- * This source code is licensed under the ISC license.
384
- * See the LICENSE file in the root directory of this source tree.
385
- */const G5=[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]],K5=le("radio",G5);/**
386
- * @license lucide-react v0.576.0 - ISC
387
- *
388
- * This source code is licensed under the ISC license.
389
- * See the LICENSE file in the root directory of this source tree.
390
- */const W5=[["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"}]],gc=le("refresh-cw",W5);/**
391
- * @license lucide-react v0.576.0 - ISC
392
- *
393
- * This source code is licensed under the ISC license.
394
- * See the LICENSE file in the root directory of this source tree.
395
- */const Y5=[["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"}]],km=le("rotate-ccw",Y5);/**
396
- * @license lucide-react v0.576.0 - ISC
397
- *
398
- * This source code is licensed under the ISC license.
399
- * See the LICENSE file in the root directory of this source tree.
400
- */const Z5=[["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"}]],Sm=le("rotate-cw",Z5);/**
401
- * @license lucide-react v0.576.0 - ISC
402
- *
403
- * This source code is licensed under the ISC license.
404
- * See the LICENSE file in the root directory of this source tree.
405
- */const X5=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],J5=le("save",X5);/**
406
- * @license lucide-react v0.576.0 - ISC
407
- *
408
- * This source code is licensed under the ISC license.
409
- * See the LICENSE file in the root directory of this source tree.
410
- */const eS=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}]],tS=le("scan",eS);/**
411
- * @license lucide-react v0.576.0 - ISC
412
- *
413
- * This source code is licensed under the ISC license.
414
- * See the LICENSE file in the root directory of this source tree.
415
- */const nS=[["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"}]],rS=le("scroll-text",nS);/**
416
- * @license lucide-react v0.576.0 - ISC
417
- *
418
- * This source code is licensed under the ISC license.
419
- * See the LICENSE file in the root directory of this source tree.
420
- */const oS=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],go=le("search",oS);/**
421
- * @license lucide-react v0.576.0 - ISC
422
- *
423
- * This source code is licensed under the ISC license.
424
- * See the LICENSE file in the root directory of this source tree.
425
- */const sS=[["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"}]],aS=le("server",sS);/**
426
- * @license lucide-react v0.576.0 - ISC
427
- *
428
- * This source code is licensed under the ISC license.
429
- * See the LICENSE file in the root directory of this source tree.
430
- */const iS=[["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"}]],lS=le("shield",iS);/**
431
- * @license lucide-react v0.576.0 - ISC
432
- *
433
- * This source code is licensed under the ISC license.
434
- * See the LICENSE file in the root directory of this source tree.
435
- */const cS=[["path",{d:"M12 10.189V14",key:"1p8cqu"}],["path",{d:"M12 2v3",key:"qbqxhf"}],["path",{d:"M19 13V7a2 2 0 0 0-2-2H7a2 2 0 0 0-2 2v6",key:"qpkstq"}],["path",{d:"M19.38 20A11.6 11.6 0 0 0 21 14l-8.188-3.639a2 2 0 0 0-1.624 0L3 14a11.6 11.6 0 0 0 2.81 7.76",key:"7tigtc"}],["path",{d:"M2 21c.6.5 1.2 1 2.5 1 2.5 0 2.5-2 5-2 1.3 0 1.9.5 2.5 1s1.2 1 2.5 1c2.5 0 2.5-2 5-2 1.3 0 1.9.5 2.5 1",key:"1924j5"}]],dS=le("ship",cS);/**
436
- * @license lucide-react v0.576.0 - ISC
437
- *
438
- * This source code is licensed under the ISC license.
439
- * See the LICENSE file in the root directory of this source tree.
440
- */const uS=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],pS=le("sliders-horizontal",uS);/**
441
- * @license lucide-react v0.576.0 - ISC
442
- *
443
- * This source code is licensed under the ISC license.
444
- * See the LICENSE file in the root directory of this source tree.
445
- */const fS=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Mu=le("square",fS);/**
446
- * @license lucide-react v0.576.0 - ISC
447
- *
448
- * This source code is licensed under the ISC license.
449
- * See the LICENSE file in the root directory of this source tree.
450
- */const hS=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]],mS=le("star",hS);/**
451
- * @license lucide-react v0.576.0 - ISC
452
- *
453
- * This source code is licensed under the ISC license.
454
- * See the LICENSE file in the root directory of this source tree.
455
- */const gS=[["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"}]],Cm=le("sun",gS);/**
456
- * @license lucide-react v0.576.0 - ISC
457
- *
458
- * This source code is licensed under the ISC license.
459
- * See the LICENSE file in the root directory of this source tree.
460
- */const bS=[["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"}]],xS=le("table-2",bS);/**
461
- * @license lucide-react v0.576.0 - ISC
462
- *
463
- * This source code is licensed under the ISC license.
464
- * See the LICENSE file in the root directory of this source tree.
465
- */const yS=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]],Eu=le("target",yS);/**
466
- * @license lucide-react v0.576.0 - ISC
467
- *
468
- * This source code is licensed under the ISC license.
469
- * See the LICENSE file in the root directory of this source tree.
470
- */const vS=[["path",{d:"M14 4v10.54a4 4 0 1 1-4 0V4a2 2 0 0 1 4 0Z",key:"17jzev"}]],wS=le("thermometer",vS);/**
471
- * @license lucide-react v0.576.0 - ISC
472
- *
473
- * This source code is licensed under the ISC license.
474
- * See the LICENSE file in the root directory of this source tree.
475
- */const NS=[["circle",{cx:"9",cy:"12",r:"3",key:"u3jwor"}],["rect",{width:"20",height:"14",x:"2",y:"5",rx:"7",key:"g7kal2"}]],kS=le("toggle-left",NS);/**
476
- * @license lucide-react v0.576.0 - ISC
477
- *
478
- * This source code is licensed under the ISC license.
479
- * See the LICENSE file in the root directory of this source tree.
480
- */const SS=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],Kt=le("trash-2",SS);/**
481
- * @license lucide-react v0.576.0 - ISC
482
- *
483
- * This source code is licensed under the ISC license.
484
- * See the LICENSE file in the root directory of this source tree.
485
- */const CS=[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]],MS=le("trending-up",CS);/**
486
- * @license lucide-react v0.576.0 - ISC
487
- *
488
- * This source code is licensed under the ISC license.
489
- * See the LICENSE file in the root directory of this source tree.
490
- */const ES=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],IS=le("trending-down",ES);/**
491
- * @license lucide-react v0.576.0 - ISC
492
- *
493
- * This source code is licensed under the ISC license.
494
- * See the LICENSE file in the root directory of this source tree.
495
- */const AS=[["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"}]],zo=le("triangle-alert",AS);/**
496
- * @license lucide-react v0.576.0 - ISC
497
- *
498
- * This source code is licensed under the ISC license.
499
- * See the LICENSE file in the root directory of this source tree.
500
- */const PS=[["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"}]],Mm=le("upload",PS);/**
501
- * @license lucide-react v0.576.0 - ISC
502
- *
503
- * This source code is licensed under the ISC license.
504
- * See the LICENSE file in the root directory of this source tree.
505
- */const _S=[["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"}]],$S=le("wifi-off",_S);/**
506
- * @license lucide-react v0.576.0 - ISC
507
- *
508
- * This source code is licensed under the ISC license.
509
- * See the LICENSE file in the root directory of this source tree.
510
- */const DS=[["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"}]],Em=le("wifi",DS);/**
511
- * @license lucide-react v0.576.0 - ISC
512
- *
513
- * This source code is licensed under the ISC license.
514
- * See the LICENSE file in the root directory of this source tree.
515
- */const TS=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],bc=le("wrench",TS);/**
516
- * @license lucide-react v0.576.0 - ISC
517
- *
518
- * This source code is licensed under the ISC license.
519
- * See the LICENSE file in the root directory of this source tree.
520
- */const LS=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Ye=le("x",LS);/**
521
- * @license lucide-react v0.576.0 - ISC
522
- *
523
- * This source code is licensed under the ISC license.
524
- * See the LICENSE file in the root directory of this source tree.
525
- */const RS=[["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"}]],Iu=le("zap",RS);/**
526
- * @license lucide-react v0.576.0 - ISC
527
- *
528
- * This source code is licensed under the ISC license.
529
- * See the LICENSE file in the root directory of this source tree.
530
- */const OS=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],BS=le("zoom-in",OS);/**
531
- * @license lucide-react v0.576.0 - ISC
532
- *
533
- * This source code is licensed under the ISC license.
534
- * See the LICENSE file in the root directory of this source tree.
535
- */const zS=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],FS=le("zoom-out",zS),jS={frigate:dS,scrypted:lS,reolink:K5,homeAssistant:xm,rtsp:$k},HS={online:Hk,offline:Zk,degraded:va,unknown:um},Au=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,Pu=qh,sr=(e,t)=>n=>{var r;if(t?.variants==null)return Pu(e,n?.class,n?.className);const{variants:s,defaultVariants:a}=t,i=Object.keys(s).map(d=>{const f=n?.[d],p=a?.[d];if(f===null)return null;const h=Au(f)||Au(p);return s[d][h]}),l=n&&Object.entries(n).reduce((d,f)=>{let[p,h]=f;return h===void 0||(d[p]=h),d},{}),c=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,f)=>{let{class:p,className:h,...m}=f;return Object.entries(m).every(g=>{let[b,x]=g;return Array.isArray(x)?x.includes({...a,...l}[b]):{...a,...l}[b]===x})?[...d,p,h]:d},[]);return Pu(e,i,c,n?.class,n?.className)},VS=sr("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"}}),Oe=qe(({className:e,variant:t,size:n,...r},s)=>o("button",{ref:s,className:W(VS({variant:t,size:n}),e),...r}));Oe.displayName="Button";const qS=sr("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"}}),xc=qe(({className:e,variant:t,size:n,icon:r,...s},a)=>o("button",{ref:a,className:W(qS({variant:t,size:n}),e),...s,children:o(r,{className:"h-4 w-4"})}));xc.displayName="IconButton";const US=sr("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"}}),yr=qe(({className:e,variant:t,style:n,...r},s)=>o("span",{ref:s,className:W(US({variant:t,styleVariant:n}),e),...r}));yr.displayName="Badge";const QS=sr("rounded-lg p-3",{variants:{variant:{flat:"bg-surface",bordered:"bg-surface border border-border"}},defaultVariants:{variant:"bordered"}}),Lt=qe(({className:e,variant:t,...n},r)=>o("div",{ref:r,className:W(QS({variant:t}),e),...n}));Lt.displayName="Card";function Im({expanded:e,onExpandedChange:t,header:n,children:r,dimmed:s=!1,hideChevron:a=!1,className:i}){return u("div",{className:W("rounded-lg border border-border bg-surface overflow-hidden",s&&"opacity-[0.45]",i),children:[u("div",{role:"button",tabIndex:0,className:"flex items-center gap-2.5 px-3 py-2.5 cursor-pointer select-none",onClick:()=>t(!e),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),t(!e))},children:[!a&&o("span",{className:"text-foreground-subtle shrink-0",children:e?o(or,{className:"h-4 w-4"}):o(Pn,{className:"h-4 w-4"})}),n]}),e&&r&&o("div",{className:"border-t border-border px-3 py-3",children:r})]})}const yc=qe(({className:e,...t},n)=>o("label",{ref:n,className:W("text-[10px] uppercase tracking-wider text-foreground-muted font-medium",e),...t}));yc.displayName="Label";const GS=sr("",{variants:{orientation:{horizontal:"h-px w-full bg-border-subtle",vertical:"w-px h-full bg-border-subtle"}},defaultVariants:{orientation:"horizontal"}}),vc=qe(({className:e,orientation:t,...n},r)=>o("div",{ref:r,role:"separator",className:W(GS({orientation:t}),e),...n}));vc.displayName="Separator";const Am=qe(({className:e,...t},n)=>o("div",{ref:n,className:W("animate-pulse bg-surface-hover rounded-md h-4 w-full",e),...t}));Am.displayName="Skeleton";const _u=sr("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"}}),Qs=qe(({className:e,state:t,leftSlot:n,rightSlot:r,...s},a)=>n||r?u("div",{className:"relative flex items-center w-full",children:[n&&o("div",{className:"absolute left-2.5 flex items-center pointer-events-none",children:n}),o("input",{ref:a,className:W(_u({state:t}),n?"pl-7":"",r?"pr-7":"",e),...s}),r&&o("div",{className:"absolute right-2.5 flex items-center pointer-events-none",children:r})]}):o("input",{ref:a,className:W(_u({state:t}),e),...s}));Qs.displayName="Input";const bo=qe(({className:e,options:t,...n},r)=>u("div",{className:"relative w-full",children:[o("select",{ref:r,className:W("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=>o("option",{value:s.value,children:s.label},s.value))}),o("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none text-foreground-muted",children:o(or,{className:"h-3.5 w-3.5"})})]}));bo.displayName="Select";const Pm=qe(({className:e,...t},n)=>o("input",{ref:n,type:"checkbox",className:W("w-3.5 h-3.5 rounded-sm border border-border accent-primary",e),...t}));Pm.displayName="Checkbox";const wc=qe(({className:e,checked:t,onCheckedChange:n,label:r,...s},a)=>u("button",{ref:a,role:"switch","aria-checked":t,type:"button",onClick:()=>n(!t),className:W("inline-flex items-center gap-2",e),...s,children:[o("span",{className:W("w-8 h-4 rounded-full transition-colors",t?"bg-primary":"bg-surface-hover"),children:o("span",{className:W("block w-3.5 h-3.5 rounded-full bg-white transition-transform",t?"translate-x-4":"translate-x-0.5")})}),r&&o("span",{className:"text-xs text-foreground",children:r})]}));wc.displayName="Switch";const _m=Be(null);function $m(){const e=ve(_m);if(!e)throw new Error("Dialog compound components must be used within <Dialog>");return e}function Dm({children:e,open:t,onOpenChange:n}){const[r,s]=P(!1),a=t??r,i=Qn(),l=U(c=>{n?.(c),t===void 0&&s(c)},[t,n]);return o(_m.Provider,{value:{open:a,setOpen:l,contentId:i},children:e})}function KS({children:e,...t}){const{setOpen:n}=$m();return o("button",{type:"button",onClick:()=>n(!0),...t,children:e})}const WS=sr("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"}}),Nc=qe(({className:e,width:t,children:n,...r},s)=>{const{open:a,setOpen:i,contentId:l}=$m(),c=ne(null),d=s??c;Y(()=>{const p=d.current;p&&(a&&!p.open&&p.showModal(),!a&&p.open&&p.close())},[a,d]);const f=p=>{p.target===p.currentTarget&&i(!1)};return o("dialog",{ref:d,id:l,className:W(WS({width:t}),"w-full",e),onClick:f,onClose:()=>i(!1),...r,children:n})});Nc.displayName="DialogContent";function Tm({className:e,...t}){return o("div",{className:W("flex flex-col gap-1 mb-3",e),...t})}function Lm({className:e,...t}){return o("div",{className:W("flex justify-end gap-2 mt-4",e),...t})}function Rm({className:e,...t}){return o("h2",{className:W("text-sm font-semibold text-foreground",e),...t})}function Om({className:e,...t}){return o("p",{className:W("text-xs text-foreground-muted",e),...t})}const Bm=Be(null);function kc(){const e=ve(Bm);if(!e)throw new Error("Dropdown compound components must be used within <Dropdown>");return e}function zm({children:e}){const[t,n]=P(!1),r=Qn(),s=Qn(),a=ne(null);return o(Bm.Provider,{value:{open:t,setOpen:n,triggerId:r,contentId:s,triggerRef:a},children:o("div",{className:"relative inline-block",children:e})})}function Fm({children:e,...t}){const{open:n,setOpen:r,triggerId:s,contentId:a,triggerRef:i}=kc();return o("button",{type:"button",ref:i,id:s,"aria-haspopup":"menu","aria-expanded":n,"aria-controls":n?a:void 0,onClick:()=>r(!n),...t,children:e})}function jm({className:e,children:t,align:n="start",offset:r=4,...s}){const{open:a,setOpen:i,contentId:l,triggerId:c,triggerRef:d}=kc(),f=ne(null),[p,h]=P(null);if(ba(()=>{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+r,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,r,d]),Y(()=>{if(!a)return;const g=x=>{const y=f.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||!p||typeof document>"u")return null;const m={position:"fixed",top:p.top,...n==="end"?{right:window.innerWidth-p.left}:{left:p.left},minWidth:p.minWidth};return Lo(o("div",{ref:f,id:l,role:"menu","aria-labelledby":c,style:m,className:W("z-50 bg-background-elevated border border-border rounded-md shadow-lg py-1 min-w-[160px]",e),...s,children:t}),document.body)}function Hm({className:e,icon:t,variant:n="default",children:r,onClick:s,...a}){const{setOpen:i}=kc(),l=U(c=>{s?.(c),i(!1)},[s,i]);return u("button",{type:"button",role:"menuitem",className:W("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&&o(t,{size:14}),r]})}const Vm=Be(null);function qm(){const e=ve(Vm);if(!e)throw new Error("Tooltip compound components must be used within <Tooltip>");return e}function YS({children:e}){const[t,n]=P(!1),r=ne(null),s=Qn(),a=()=>{r.current=setTimeout(()=>n(!0),300)},i=()=>{r.current&&clearTimeout(r.current),n(!1)};return o(Vm.Provider,{value:{open:t,show:a,hide:i,tooltipId:s},children:o("div",{className:"relative inline-block",children:e})})}function ZS({children:e,...t}){const{show:n,hide:r,tooltipId:s,open:a}=qm();return o("div",{onMouseEnter:n,onMouseLeave:r,onFocus:n,onBlur:r,"aria-describedby":a?s:void 0,...t,children:e})}function XS({className:e,children:t,...n}){const{open:r,tooltipId:s}=qm();return o("div",{id:s,role:"tooltip",className:W("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",r?"opacity-100":"opacity-0",e),...n,children:t})}const $u="(max-width: 767px)",Du="(min-width: 768px) and (max-width: 1023px)";function Um(e){return t=>{const n=window.matchMedia(e);return n.addEventListener("change",t),()=>n.removeEventListener("change",t)}}function Qm(e){return()=>window.matchMedia(e).matches}function Gm(){return!1}function ar(){return xa(Um($u),Qm($u),Gm)}function Km(){return xa(Um(Du),Qm(Du),Gm)}function Sc({open:e,onClose:t,title:n,children:r,className:s}){return Y(()=>{if(!e)return;const a=i=>{i.key==="Escape"&&t()};return document.addEventListener("keydown",a),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",a),document.body.style.overflow=""}},[e,t]),u(me,{children:[o("div",{className:W("fixed inset-0 z-40 bg-black/50 transition-opacity duration-200",e?"opacity-100":"pointer-events-none opacity-0"),onClick:t,"aria-hidden":"true"}),u("div",{role:"dialog","aria-modal":"true",className:W("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:[o("div",{className:"flex justify-center pt-2 pb-1",children:o("div",{className:"h-1 w-8 rounded-full bg-foreground-subtle/30"})}),n&&u("div",{className:"flex items-center justify-between px-4 pb-2",children:[o("span",{className:"text-sm font-medium text-foreground",children:n}),o("button",{onClick:t,className:"p-1 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors",children:o(Ye,{className:"h-4 w-4"})})]}),o("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:r})]})]})}const Wm=Be(null);function Ym(){const e=ve(Wm);if(!e)throw new Error("Popover compound components must be used within <Popover>");return e}function Zm({children:e,open:t,onOpenChange:n}){const[r,s]=P(!1),a=t??r,i=Qn(),l=Qn(),c=U(d=>{n?.(d),t===void 0&&s(d)},[t,n]);return o(Wm.Provider,{value:{open:a,setOpen:c,triggerId:i,contentId:l},children:o("div",{className:"relative inline-block",children:e})})}function Xm({children:e,...t}){const{open:n,setOpen:r,triggerId:s,contentId:a}=Ym();return o("button",{type:"button",id:s,"aria-haspopup":"dialog","aria-expanded":n,"aria-controls":n?a:void 0,onClick:()=>r(!n),...t,children:e})}function Jm({className:e,children:t,...n}){const{open:r,setOpen:s,contentId:a,triggerId:i}=Ym(),l=ar(),c=ne(null);return Y(()=>{if(!r||l)return;const d=p=>{const h=c.current,m=document.getElementById(i);h&&!h.contains(p.target)&&!m?.contains(p.target)&&s(!1)},f=p=>{p.key==="Escape"&&s(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",f)}},[r,s,i,l]),r?l?o(Sc,{open:r,onClose:()=>s(!1),children:t}):o("div",{ref:c,id:a,role:"dialog","aria-labelledby":i,className:W("absolute left-0 top-full z-50 mt-1 bg-background-elevated border border-border rounded-lg shadow-lg p-3",e),...n,children:t}):null}const eg=Be(null);function tg(){const e=ve(eg);if(!e)throw new Error("Tabs compound components must be used within <Tabs>");return e}function JS({value:e,onValueChange:t,defaultValue:n="",className:r,...s}){const[a,i]=P(n),l=e??a,c=U(d=>{t?.(d),e===void 0&&i(d)},[e,t]);return o(eg.Provider,{value:{value:l,setValue:c},children:o("div",{className:r,...s})})}function eC({className:e,...t}){return o("div",{role:"tablist",className:W("flex flex-row border-b border-border-subtle",e),...t})}function tC({value:e,className:t,...n}){const{value:r,setValue:s}=tg(),a=e===r,i=`tabpanel-${e}`;return o("button",{type:"button",role:"tab","aria-selected":a,"aria-controls":i,tabIndex:a?0:-1,className:W("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 nC({value:e,className:t,...n}){const{value:r}=tg();return e!==r?null:o("div",{role:"tabpanel",id:`tabpanel-${e}`,className:W("pt-3",t),...n})}const Cc=qe(({className:e,...t},n)=>o("div",{ref:n,className:W("overflow-auto [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-surface-hover [&::-webkit-scrollbar-thumb]:rounded-full",e),...t}));Cc.displayName="ScrollArea";function rC({title:e,onClose:t,children:n,defaultWidth:r=360,defaultHeight:s=280,minWidth:a=280,minHeight:i=160,offsetIndex:l=0,className:c}){const[d,f]=P({x:80+l*30,y:80+l*30}),[p,h]=P({w:r,h:s}),[m,g]=P(!1),b=ne(!1),x=ne(!1),y=ne({x:0,y:0}),w=ar(),v=U(k=>{k.preventDefault(),b.current=!0,y.current={x:k.clientX-d.x,y:k.clientY-d.y}},[d]),N=U(k=>{k.preventDefault(),k.stopPropagation(),x.current=!0,y.current={x:k.clientX,y:k.clientY}},[]);return Y(()=>{const k=E=>{if(b.current&&f({x:E.clientX-y.current.x,y:E.clientY-y.current.y}),x.current){const A=E.clientX-y.current.x,I=E.clientY-y.current.y;y.current={x:E.clientX,y:E.clientY},h(z=>({w:Math.max(a,z.w+A),h:Math.max(i,z.h+I)}))}},C=()=>{b.current=!1,x.current=!1};return window.addEventListener("mousemove",k),window.addEventListener("mouseup",C),()=>{window.removeEventListener("mousemove",k),window.removeEventListener("mouseup",C)}},[a,i]),w?u("div",{className:W("fixed inset-x-0 bottom-0 z-50 rounded-t-xl border-t border-border bg-background-elevated shadow-2xl flex flex-col overflow-hidden",c),style:{maxHeight:"60dvh"},children:[u("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b border-border shrink-0 bg-surface",children:[o("span",{className:"text-[11px] font-medium truncate",children:e}),u("div",{className:"flex items-center gap-1 shrink-0",children:[o("button",{onClick:()=>g(!m),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",children:m?o(Su,{size:12}):o(Cu,{size:12})}),o("button",{onClick:t,className:"p-0.5 rounded hover:bg-danger/20 text-foreground-muted hover:text-danger transition-colors",children:o(Ye,{size:12})})]})]}),!m&&o("div",{className:"flex-1 min-h-0 overflow-y-auto",children:n})]}):u("div",{className:W("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:p.w,height:m?"auto":p.h},children:[u("div",{onMouseDown:v,className:"flex items-center justify-between gap-2 px-3 py-2 border-b border-border cursor-move select-none shrink-0 bg-surface",children:[u("div",{className:"flex items-center gap-2 min-w-0",children:[o(h5,{size:12,className:"text-foreground-subtle shrink-0"}),o("span",{className:"text-[11px] font-medium truncate",children:e})]}),u("div",{className:"flex items-center gap-1 shrink-0",children:[o("button",{onClick:()=>g(!m),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",title:m?"Restore":"Minimize",children:m?o(Su,{size:12}):o(Cu,{size:12})}),o("button",{onClick:t,className:"p-0.5 rounded hover:bg-danger/20 text-foreground-muted hover:text-danger transition-colors",title:"Close",children:o(Ye,{size:12})})]})]}),!m&&u("div",{className:"flex-1 min-h-0 overflow-y-auto relative",children:[n,o("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 Mc({open:e,onClose:t,children:n,className:r,width:s="w-64"}){const a=ne(null);return Y(()=>{if(!e)return;const i=l=>{l.key==="Escape"&&t()};return document.addEventListener("keydown",i),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",i),document.body.style.overflow=""}},[e,t]),u(me,{children:[o("div",{className:W("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"}),o("div",{ref:a,role:"dialog","aria-modal":"true",className:W("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",r),children:n})]})}function Ec({items:e,className:t}){return o("nav",{className:`flex items-center gap-1 text-[11px] text-foreground-subtle ${t??""}`,children:e.map((n,r)=>{const s=r===e.length-1,a=!s&&(n.onClick||n.href);return u(ic.Fragment,{children:[r>0&&o(Pn,{className:"h-3 w-3 flex-shrink-0"}),a?n.onClick?o("button",{type:"button",onClick:n.onClick,className:"hover:text-foreground transition-colors",children:n.label}):o("a",{href:n.href,className:"hover:text-foreground transition-colors",children:n.label}):o("span",{className:s?"text-foreground font-medium":"",children:n.label})]},r)})})}const Tu={left:"text-left",right:"text-right",center:"text-center"};function ng({columns:e,rows:t,rowKey:n,onRowClick:r,minWidthPx:s=480,emptyMessage:a,className:i,bordered:l=!0,rowClassName:c}){if(t.length===0&&a)return o("div",{className:`rounded-lg ${l?"border border-border":""} bg-surface px-3 py-4 text-xs text-foreground-subtle text-center ${i??""}`,children:a});if(t.length===0)return null;const d=`rounded-lg ${l?"border border-border":""} bg-surface overflow-x-auto ${i??""}`;return o("div",{className:d,children:u("table",{className:"w-full text-xs",style:{minWidth:`${s}px`},children:[o("thead",{className:"bg-surface",children:o("tr",{children:e.map(f=>{const p=f.align??"left",h=f.nowrap??!0;return o("th",{className:["px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border",Tu[p],h?"whitespace-nowrap":"",f.width??""].filter(Boolean).join(" "),children:f.headerRender?f.headerRender():f.header},f.key)})})}),o("tbody",{children:t.map((f,p)=>{const h=n?n(f,p):p,m=c?.(f,p)??"",g=r!==void 0;return o("tr",{onClick:g?()=>r(f,p):void 0,className:[g?"cursor-pointer hover:bg-primary/5":"hover:bg-primary/5",m].filter(Boolean).join(" "),children:e.map(b=>{const x=b.align??"left",y=b.nowrap??!1;return o("td",{className:["px-3 py-2 text-foreground border-b border-border",Tu[x],y?"whitespace-nowrap":""].filter(Boolean).join(" "),children:b.render(f,p)},b.key)})},h)})})]})})}function Ic({open:e,onClose:t,title:n,subtitle:r,footer:s,children:a,widthClass:i="w-[360px]"}){return Y(()=>{if(!e)return;const l=c=>{c.key==="Escape"&&t()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e,t]),e?u("aside",{className:W("absolute top-0 right-0 bottom-0 z-20 flex flex-col","bg-surface border-l border-border shadow-xl",i),role:"dialog","aria-modal":"false",children:[u("header",{className:"flex items-start justify-between gap-2 px-4 py-3 border-b border-border",children:[u("div",{className:"min-w-0",children:[o("div",{className:"text-sm font-semibold text-foreground truncate",children:n}),r!==void 0&&o("div",{className:"text-[11px] text-foreground-subtle mt-0.5 truncate",children:r})]}),o("button",{type:"button",onClick:t,className:"p-1 rounded hover:bg-muted text-foreground-subtle hover:text-foreground","aria-label":"Close panel",children:o(Ye,{className:"w-4 h-4"})})]}),o("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3",children:a}),s!==void 0&&o("footer",{className:"flex items-center gap-2 justify-end px-4 py-3 border-t border-border",children:s})]}):null}const oC={inherit:"bg-muted",on:"bg-emerald-500",off:"bg-orange-500",na:"bg-gray-300 opacity-50"};function rg({node:e,depth:t,selectedAddonId:n,onSelect:r,agentDots:s}){const a=e.addonId===n,i=s?.[e.addonId]??[];return u("div",{children:[u("button",{type:"button",onClick:()=>r(e.addonId),className:W("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:[o("span",{className:"truncate",children:e.addonName}),i.length>0&&o("span",{className:"flex items-center gap-1 shrink-0",children:i.map(l=>o("span",{title:`${l.agentNodeId}: ${l.state}`,className:W("w-2 h-2 rounded-full",oC[l.state])},l.agentNodeId))})]}),e.children.map(l=>o(rg,{node:l,depth:t+1,selectedAddonId:n,onSelect:r,agentDots:s},l.addonId))]})}function og({tree:e,selectedAddonId:t,onSelect:n,agentDots:r,className:s}){return o("div",{className:W("flex flex-col py-2",s),children:e.map(a=>o(rg,{node:a,depth:0,selectedAddonId:t,onSelect:n,agentDots:r},a.addonId))})}function wa(e){const t=[],n=[],r=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),r.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 sC(e){return e?e.models.map(t=>({id:t.id,name:t.name})):[]}function $s({step:e,schema:t,allSchemas:n,depth:r=0,onChange:s,onDelete:a,readOnly:i=!1,toggleMode:l="simple",overrideState:c=null,onOverrideChange:d,inheritedEnabled:f,hideModelAndSettings:p=!1}){const[h,m]=P(!1),g=sC(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=u(me,{children:[u("div",{className:"flex-1 min-w-0",children:[o("span",{className:"text-[10px] uppercase tracking-wider font-medium text-foreground-subtle/60 block leading-none",children:e.slot}),o("span",{className:"text-sm font-semibold text-foreground truncate block leading-tight",children:e.addonName}),u("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(x=>o("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&&o("span",{className:"text-foreground-subtle/40 text-[10px]",children:"→"}),e.outputClasses.map(x=>o("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"&&o("button",{onClick:x=>{x.stopPropagation(),s({...e,enabled:!e.enabled})},className:W("relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors",e.enabled?"bg-success":"bg-foreground-subtle/30"),children:o("span",{className:W("inline-block h-4 w-4 rounded-full bg-white shadow transition-transform",e.enabled?"translate-x-6":"translate-x-1")})}),!i&&l==="threeState"&&d&&u("div",{className:"flex items-center gap-0.5 rounded-md border border-border p-0.5",onClick:x=>x.stopPropagation(),children:[o(di,{label:"Inherit",active:c===null,variant:"inherit",subtext:f===void 0?void 0:f?"on":"off",onClick:()=>d(null)}),o(di,{label:"On",active:c===!0,variant:"on",onClick:()=>d(!0)}),o(di,{label:"Off",active:c===!1,variant:"off",onClick:()=>d(!1)})]})]});return o(Im,{expanded:h,onExpandedChange:m,dimmed:!e.enabled,header:b,children:p?o("p",{className:"text-[11px] text-foreground-subtle",children:"Model and detection settings are managed per agent — open the Pipeline page for this camera's agent to edit them."}):u("div",{className:"space-y-3",children:[o(xl,{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&&o(xl,{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=>o(Na,{field:x,allFields:t.configSchema??[],step:e,disabled:i,onChange:s},x.key))]})})}function xl({label:e,value:t,options:n,disabled:r,onChange:s}){return u("div",{children:[o("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e}),u("select",{value:t,onChange:a=>s(a.target.value),disabled:r,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&&o("option",{value:t,children:t||"default"}),n.map(a=>o("option",{value:a.value,disabled:a.disabled,children:a.label},a.value))]})]})}function aC({label:e,description:t,value:n,options:r,disabled:s,onChange:a}){function i(l){if(s)return;const c=n.includes(l)?n.filter(d=>d!==l):[...n,l];a(c)}return u("div",{children:[o("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1",children:e}),t&&o("p",{className:"text-[10px] text-foreground-subtle/60 mb-1.5",children:t}),o("div",{className:"flex flex-wrap gap-1.5",children:r.map(l=>{const c=n.includes(l.value);return o("button",{type:"button",disabled:s,onClick:()=>i(l.value),className:W("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 iC(e,t,n){const r=t.settings?.[e];if(r!==void 0)return r;const s=n.find(a=>"key"in a&&a.key===e);return s&&"default"in s?s.default:void 0}function Na({field:e,allFields:t,step:n,disabled:r,onChange:s}){const a=e.type!=="separator"&&e.type!=="info"?e.showWhen:void 0;if(a){const{field:l,equals:c,notEquals:d,in:f,notIn:p}=a,h=iC(l,n,t);if(c!==void 0&&h!==c||d!==void 0&&h===d||f!==void 0&&!f.includes(h)||p!==void 0&&p.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 o(xl,{label:e.label,value:c,disabled:r||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 o(aC,{label:e.label,description:e.description,value:c,options:e.options,disabled:r||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,f=e.min??0,p=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 u("div",{children:[u("div",{className:"flex items-center justify-between mb-1",children:[o("span",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide",children:e.label}),m&&u("span",{className:"text-xs font-medium text-foreground tabular-nums",children:[typeof x=="number"?x.toFixed(2).replace(/\.?0+$/,""):x,g?` ${g}`:""]})]}),e.description&&o("p",{className:"text-[10px] text-foreground-subtle/60 mb-1.5",children:e.description}),o("input",{type:"range",min:f,max:p,step:h,value:d,disabled:r||e.disabled,onChange:y=>i(Number(y.target.value)),className:"w-full accent-primary h-1.5"})]})}if(e.type==="boolean"){const l=n.settings?.[e.key],c=typeof l=="boolean"?l:e.default===!0;return u("label",{className:"flex items-center gap-2",children:[o("input",{type:"checkbox",checked:c,disabled:r||e.disabled,onChange:d=>i(d.target.checked),className:"h-3.5 w-3.5 accent-primary"}),o("span",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide",children:e.label})]})}if(e.type==="text"||e.type==="password"||e.type==="textarea"){const l=n.settings?.[e.key],c=typeof l=="string"?l:e.default??"",d=e.type==="password"?"password":"text";return u("div",{children:[o("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e.label}),e.type==="textarea"?o("textarea",{value:c,disabled:r||e.disabled,placeholder:e.placeholder,onChange:f=>i(f.target.value),rows:3,className:"w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground focus:outline-none focus:border-primary/50 resize-y"}):o("input",{type:d,value:c,disabled:r||e.disabled,placeholder:e.placeholder,onChange:f=>i(f.target.value),className:"w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground focus:outline-none focus:border-primary/50"})]})}return e.type==="separator"?o("div",{className:"border-t border-border my-2"}):e.type==="info"?o("div",{className:"rounded-md border border-border bg-surface px-2 py-1.5 text-[10px] text-foreground-subtle",children:e.content}):null}function di({label:e,active:t,variant:n,subtext:r,onClick:s}){return u("button",{type:"button",onClick:s,className:W("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,r&&t&&u("span",{className:"ml-1 opacity-60",children:["(",r,")"]})]})}function sg(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 lC(e,t,n){return n?{enabled:n.enabled??t.enabled,modelId:n.modelId??t.modelId,settings:n.settings??t.settings}:t}function cC({addon:e,agentDefault:t,modelsForFormat:n,onChangeAgentConfig:r}){const s=a=>{r?.({...t,...a})};return u("div",{className:"space-y-4 text-xs",children:[u("label",{className:"flex items-center gap-2",children:[o("input",{type:"checkbox",checked:t.enabled,onChange:a=>s({enabled:a.target.checked})}),u("span",{children:["Enabled on this agent (",e.name,")"]})]}),u("div",{children:[o("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle mb-1",children:"Model"}),o("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=>o("option",{value:a.id,children:a.name},a.id))})]}),(e.configSchema?.length??0)>0&&u("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[o("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),e.configSchema?.map(a=>o(Na,{field:a,allFields:e.configSchema??[],step:sg(e,t),disabled:!1,onChange:i=>s({settings:{...i.settings}})},a.key))]})]})}function dC({addon:e,agentDefault:t,agentNodeId:n,currentPatch:r,modelsForFormat:s,onChangePatch:a}){const i=lC("device",t,r),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}=r??{},x=m==="inherit"?b:{...b,enabled:m==="on"};l(x)},d=m=>{const{modelId:g,...b}=r??{},x=m===void 0?b:{...b,modelId:m};l(x)},f=m=>{const{settings:g,...b}=r??{},x=m===void 0?b:{...b,settings:m};l(x)},p=r?.enabled===void 0?"inherit":r.enabled?"on":"off",h=r?.modelId!==void 0;return u("div",{className:"space-y-4 text-xs",children:[u("div",{className:"flex items-center gap-1",children:[["inherit","on","off"].map(m=>o("button",{type:"button",onClick:()=>c(m),className:W("px-3 py-1 border border-border rounded text-xs capitalize",p===m?"bg-primary text-primary-foreground border-primary":"bg-surface text-foreground hover:bg-muted"),children:m},m)),u("span",{className:"ml-2 text-[10px] text-foreground-subtle",children:["agent default: ",o("span",{className:"font-semibold",children:t.enabled?"on":"off"})]})]}),u("div",{children:[u("div",{className:"flex items-center justify-between mb-1",children:[o("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Model"}),h?o("button",{type:"button",className:"text-[10px] text-foreground-subtle hover:text-foreground",onClick:()=>d(void 0),children:"Clear"}):o("button",{type:"button",className:"text-[10px] text-primary hover:underline",onClick:()=>d(t.modelId),children:"Override"})]}),o("select",{disabled:!h,className:"w-full bg-surface border border-border rounded px-2 py-1 text-xs disabled:opacity-50",value:h?r?.modelId??t.modelId:t.modelId,onChange:m=>d(m.target.value),children:s.map(m=>o("option",{value:m.id,children:m.name},m.id))}),!h&&u("div",{className:"text-[10px] text-foreground-subtle mt-1",children:["inherits from ",n]})]}),(e.configSchema?.length??0)>0&&(()=>{const m=r?.settings!==void 0;return u("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[u("div",{className:"flex items-center justify-between",children:[o("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),m?o("button",{type:"button",className:"text-[10px] text-foreground-subtle hover:text-foreground",onClick:()=>f(void 0),children:"Clear"}):o("button",{type:"button",className:"text-[10px] text-primary hover:underline",onClick:()=>f({...t.settings}),children:"Override"})]}),e.configSchema?.map(g=>o(Na,{field:g,allFields:e.configSchema??[],step:sg(e,i),disabled:!m,onChange:b=>f({...b.settings})},g.key)),!m&&u("div",{className:"text-[10px] text-foreground-subtle",children:["inherits from ",n]})]})})(),u("div",{className:"rounded bg-muted/40 px-3 py-2 text-[11px] text-foreground-subtle",children:[o("div",{className:"font-semibold text-foreground mb-0.5",children:"Effective config preview"}),u("div",{className:"font-mono truncate",children:[e.id," · model: ",i.modelId," · ",i.enabled?"on":"off"]})]})]})}function ka(e){const{mode:t,addon:n,agentDefault:r,agentNodeId:s,currentPatch:a,onChangeAgentConfig:i,onChangePatch:l,engineFormat:c}=e,d=q(()=>n.models.filter(f=>!!f.formats[c]),[n.models,c]);return t==="agent"?o(cC,{addon:n,agentDefault:r,modelsForFormat:d,onChangeAgentConfig:i}):o(dC,{addon:n,agentDefault:r,agentNodeId:s,currentPatch:a,modelsForFormat:d,onChangePatch:l})}function uC(e){const t=[],n=(r,s)=>{for(const a of r)t.push({node:a,depth:s}),n(a.children,s+1)};return n(e,0),t}const Lu={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 pC({slot:e}){const t=Lu[e]??Lu.classifier;return o("span",{className:W("text-[9px] font-semibold uppercase tracking-widest leading-none",t.className),children:t.label})}const Ru="inline-flex items-center rounded bg-muted px-1.5 py-px text-[9px] font-medium text-foreground-subtle";function fC({inputs:e,outputs:t}){return e.length===0&&t.length===0?null:u("span",{className:"inline-flex items-center gap-1 flex-wrap",children:[e.map(n=>o("span",{className:W(Ru,"bg-blue-500/10 text-blue-500"),children:n},`in-${n}`)),e.length>0&&t.length>0&&o("span",{className:"text-foreground-subtle/60 text-[9px]",children:"→"}),t.map(n=>o("span",{className:W(Ru,"bg-emerald-500/10 text-emerald-500"),children:n},`out-${n}`))]})}function hC({enabled:e,onChange:t,disabled:n}){return o("button",{type:"button",role:"switch","aria-checked":e,disabled:n,onClick:r=>{r.stopPropagation(),t(!e)},className:W("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:o("span",{className:W("inline-block h-3 w-3 rounded-full bg-white shadow transition-transform",e?"translate-x-3.5":"translate-x-0.5")})})}function mC(e){return e.kind==="enabled"?u("span",{className:"inline-flex items-center gap-1",children:[o("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500 shrink-0"}),o("span",{className:"font-mono text-foreground",children:e.modelId})]}):e.kind==="disabled"?u("span",{className:"inline-flex items-center gap-1 text-foreground-subtle",children:[o("span",{className:"h-1.5 w-1.5 rounded-full border border-foreground-subtle/60 shrink-0"}),"off"]}):u("span",{className:"inline-flex items-center gap-1 text-foreground-subtle/70",children:[o("span",{className:"h-1.5 w-1.5 rounded-full bg-muted shrink-0"}),"n/a"]})}function gC({node:e,depth:t,agents:n,getCellState:r,onCellClick:s,selectedCell:a,toggleProps:i}){return u(me,{children:[u("div",{className:"sticky left-0 z-10 bg-surface px-3 py-2 border-b border-border text-xs flex items-start gap-2",style:{paddingLeft:`${12+t*14}px`},children:[u("div",{className:"flex flex-col gap-1 min-w-0 flex-1",children:[o(pC,{slot:e.slot}),u("div",{className:"flex items-center gap-2 flex-wrap",children:[o("span",{className:"font-semibold truncate",children:e.addonName}),o(fC,{inputs:e.inputClasses,outputs:e.outputClasses})]})]}),i&&o("span",{className:"pl-2 pt-0.5 shrink-0",children:o(hC,{enabled:i.enabled,onChange:i.onChange,disabled:i.disabled})})]}),n.map(l=>{const c=r(e.addonId,l.agentNodeId),d=a?.addonId===e.addonId&&a.agentNodeId===l.agentNodeId;return o("button",{type:"button",onClick:()=>s(e.addonId,l.agentNodeId),className:W("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:mC(c)},l.agentNodeId)})]})}function Ac({tree:e,agents:t,getCellState:n,onCellClick:r,selectedCell:s,onToggleEnabled:a}){const i=q(()=>uC(e),[e]),l=`minmax(320px, 1fr) repeat(${t.length}, minmax(160px, 220px))`,c=a!==void 0&&t.length===1,d=t[0]?.agentNodeId;return o("div",{className:"overflow-auto border border-border rounded",children:u("div",{className:"grid",style:{gridTemplateColumns:l},children:[o("div",{className:"sticky top-0 left-0 z-20 bg-muted/60 px-3 py-2 text-[10px] uppercase tracking-widest text-foreground-subtle border-b border-border",children:"Step"}),t.map(f=>u("div",{className:"sticky top-0 z-10 bg-muted/60 px-3 py-2 border-b border-l border-border",children:[o("div",{className:"text-xs font-semibold text-foreground",children:f.agentNodeId}),o("div",{className:"text-[10px] text-foreground-subtle truncate",children:f.engineLabel})]},f.agentNodeId)),i.map(({node:f,depth:p})=>{const h=c&&d!==void 0?n(f.addonId,d):null,m=c&&h!==null?{enabled:h.kind==="enabled",onChange:g=>a?.(f.addonId,g),disabled:h.kind==="na"}:void 0;return o(gC,{node:f,depth:p,agents:t,getCellState:n,onCellClick:r,selectedCell:s,toggleProps:m},f.addonId)})]})})}const ag=typeof globalThis<"u"?globalThis.__camstackTrpcReact:void 0,S=ag??CN();typeof globalThis<"u"&&!ag&&(globalThis.__camstackTrpcReact=S);const Pc=fn("camstack:system",null);function _c({system:e,children:t}){return o(Pc.Provider,{value:e,children:t})}function Le(){const e=ve(Pc);if(!e)throw new Error("useSystem(): no <SystemProvider> in tree");return e}function bC(){return ve(Pc)}function pt(e,t){const n=Le(),r=ne(t);r.current=t;const[s,a]=P(n.connectionVersion);Y(()=>n.subscribeConnectionEvents((i,l)=>{i==="connected"&&a(l)}),[n]),Y(()=>n.subscribeEvent(e,l=>{r.current(l)}),[n,e,s])}function yl(e){const t=ne(e);return t.current=e,t}function Br(e,t){const[n,r]=P(null),s=yl(t);return pt(e,a=>{const i=a.data,l=s.current;l&&!l(i)||r(i)}),n}function $c(e,t,n){const[r,s]=P(()=>new Map),a=yl(t),i=yl(n);pt(e,c=>{const d=c.data,f=i.current;if(f&&!f(d))return;const p=a.current(d);s(h=>{const m=new Map(h);return m.set(p,d),m})});const l=q(()=>Array.from(r.values()),[r]);return{map:r,values:l}}function zr(){const{data:e,isLoading:t}=S.nodes.topology.useQuery(void 0,{staleTime:6e4}),r=Br("cluster.topology-snapshot")?.nodes??e;return{nodes:q(()=>{const a=[];for(const i of r??[])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},[r]),isLoading:t}}function ig({selectedNodeId:e,onSelect:t,label:n="Node",hideIcon:r=!1,alwaysShow:s=!1}){const{nodes:a}=zr();return!s&&a.length<=1?null:u("div",{className:"flex items-center gap-1.5",children:[!r&&o(aS,{className:"h-3.5 w-3.5 text-foreground-subtle"}),n&&o("span",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:n}),o("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 o("button",{type:"button",onClick:()=>t(i.id),disabled:!i.isOnline,title:i.isOnline?i.name:`${i.name} (offline)`,className:W("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 xC={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 yC({status:e,showDot:t=!0,showLabel:n=!0,size:r="sm",className:s}){const a=xC[e];return u("span",{className:W("inline-flex items-center gap-1.5",r==="sm"?"text-xs":"text-sm",s),children:[t&&o("span",{className:W("h-1.5 w-1.5 shrink-0 rounded-full",a.colorClass),"aria-hidden":"true"}),n&&o("span",{className:"text-foreground",children:a.label})]})}const vC={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 wC({provider:e,showLabel:t=!0,className:n}){const r=vC[e];return u("span",{className:W("inline-flex items-center gap-1.5 text-xs",n),children:[o("span",{className:W("h-1.5 w-1.5 shrink-0 rounded-sm",r.colorClass),"aria-hidden":"true"}),t&&o("span",{className:"text-foreground",children:r.label})]})}const NC={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 lg({children:e,variant:t="neutral",mono:n,className:r}){return o("span",{className:W("inline-flex items-center rounded-md px-2 py-0.5 text-[11px] font-bold leading-tight",n&&"font-mono",NC[t],r),children:e})}function kC({version:e,preRelease:t,className:n}){const r=t??/-(alpha|beta|rc|dev|canary|next)/i.test(e);return o(lg,{variant:r?"warning":"success",mono:!0,className:n,children:e})}function SC({label:e,description:t,error:n,required:r,children:s,orientation:a="vertical",className:i}){const l=a==="horizontal";return u("div",{className:W("flex gap-2",l?"flex-row items-center justify-between":"flex-col",i),children:[u("div",{className:W(l?"flex-1":""),children:[u(yc,{children:[e,r&&o("span",{className:"text-danger ml-0.5",children:"*"})]}),t&&o("p",{className:"text-foreground-subtle text-xs mt-0.5",children:t})]}),o("div",{className:W(l?"shrink-0":""),children:s}),n&&o("p",{className:"text-danger text-xs",children:n})]})}function CC({title:e,subtitle:t,actions:n,className:r}){return u("div",{className:W("flex flex-col gap-2 mb-3 sm:flex-row sm:items-center sm:justify-between",r),children:[u("div",{children:[o("h1",{className:"text-sm font-semibold text-foreground",children:e}),t&&o("p",{className:"text-foreground-subtle text-xs",children:t})]}),n&&o("div",{className:"flex items-center gap-2 flex-wrap",children:n})]})}function Dc({icon:e,title:t,description:n,action:r,className:s}){return u("div",{className:W("flex flex-col items-center justify-center gap-3 py-12",s),children:[e&&o(e,{className:"h-12 w-12 text-foreground-subtle","aria-hidden":"true"}),u("div",{className:"flex flex-col items-center gap-1 text-center",children:[o("p",{className:"text-foreground-muted text-sm font-medium",children:t}),n&&o("p",{className:"text-foreground-subtle text-xs max-w-xs",children:n})]}),r&&o("div",{className:"mt-1",children:r})]})}const cg=fn("camstack:confirm-dialog",null);function Je(){const e=ve(cg);if(!e)throw new Error("useConfirm must be used within ConfirmDialogProvider");return e.confirm}function dg({children:e}){const[t,n]=P(null),r=U(c=>new Promise(d=>{n({...c,resolve:d})}),[]),s=()=>{t?.resolve(!0),n(null)},a=()=>{t?.resolve(!1),n(null)},i={danger:{icon:"text-red-400",button:"bg-red-500 hover:bg-red-600 text-white"},warning:{icon:"text-orange-400",button:"bg-orange-500 hover:bg-orange-600 text-white"},default:{icon:"text-primary",button:"bg-primary hover:bg-primary/90 text-white"}},l=t?i[t.variant??"default"]:i.default;return u(cg.Provider,{value:{confirm:r},children:[e,t&&u("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[o("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:a}),u("div",{className:"relative z-10 w-full max-w-sm mx-4 rounded-xl border border-border bg-surface shadow-2xl overflow-hidden animate-in fade-in zoom-in-95 duration-150",onClick:c=>c.stopPropagation(),children:[u("div",{className:"px-5 pt-5 pb-4",children:[o("h3",{className:"text-sm font-semibold text-foreground",children:t.title}),o("p",{className:"mt-2 text-xs text-foreground-subtle leading-relaxed",children:t.message})]}),u("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border bg-surface-hover/30",children:[o("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"}),o("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 MC({value:e,label:t,trend:n,className:r}){return u(Lt,{className:W("flex flex-col gap-1",r),children:[u("div",{className:"flex items-baseline gap-2",children:[o("span",{className:"text-2xl font-semibold text-foreground",children:e}),n&&u("span",{className:W("inline-flex items-center gap-0.5 text-xs font-medium",n.direction==="up"?"text-success":"text-danger"),children:[n.direction==="up"?o(MS,{className:"h-3 w-3"}):o(IS,{className:"h-3 w-3"}),n.value,"%"]})]}),o("span",{className:"text-xs text-foreground-muted",children:t})]})}function EC({items:e,className:t}){return o("dl",{className:W("flex flex-col",t),children:e.map(n=>u("div",{className:"flex items-center h-7",children:[o("dt",{className:"text-foreground-subtle text-xs w-1/3 shrink-0",children:n.key}),o("dd",{className:"text-foreground text-xs",children:n.value})]},n.key))})}function IC({children:e,maxHeight:t=300,className:n}){const[r,s]=P(!1),a=U(()=>{navigator.clipboard.writeText(e).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)})},[e]);return u("div",{className:W("relative group",n),children:[o(Cc,{style:{maxHeight:t},children:o("pre",{className:"font-mono text-xs bg-surface p-3 rounded-md border border-border-subtle",children:o("code",{children:e})})}),o("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity",children:o(xc,{icon:r?Ro:_n,"aria-label":"Copy code",variant:"ghost",size:"sm",onClick:a})})]})}function AC({filters:e,values:t,onChange:n,className:r}){const s=ar(),[a,i]=P(!1),l=(d,f)=>{n({...t,[d]:f})},c=Object.values(t).filter(d=>d!==void 0&&d!=="").length;if(s){const d=e.find(p=>p.type==="search"),f=e.some(p=>p.type!=="search");return u("div",{className:W("flex items-center gap-2",r),children:[d&&o(Qs,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:p=>l(d.key,p.target.value),leftSlot:o(go,{className:"h-3 w-3 text-foreground-subtle"}),className:"flex-1"}),f&&u(me,{children:[u("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-foreground-muted hover:bg-surface-hover transition-colors shrink-0",children:[o(pS,{className:"h-3.5 w-3.5"}),"Filters",c>0&&o(yr,{variant:"info",className:"ml-1 text-[10px] px-1 py-0",children:c})]}),o(Sc,{open:a,onClose:()=>i(!1),title:"Filters",children:o("div",{className:"flex flex-col gap-3",children:e.filter(p=>p.type!=="search").map(p=>{switch(p.type){case"select":return u("div",{children:[o("label",{className:"text-xs text-foreground-muted mb-1 block",children:p.label}),o(bo,{options:p.options,value:t[p.key]??"",onChange:h=>l(p.key,h.target.value),className:"w-full"})]},p.key);case"badge-toggle":return o("div",{className:"flex items-center gap-1 flex-wrap",children:p.options.map(h=>{const g=t[p.key]===h.value;return o("button",{type:"button",onClick:()=>l(p.key,g?void 0:h.value),children:o(yr,{variant:g?"info":"default",className:"cursor-pointer",children:h.label})},h.value)})},p.key);default:return null}})})})]})]})}return o("div",{className:W("flex items-center gap-2 flex-wrap",r),children:e.map(d=>{switch(d.type){case"search":return o(Qs,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:f=>l(d.key,f.target.value),leftSlot:o(go,{className:"h-3 w-3 text-foreground-subtle"}),className:"w-48"},d.key);case"select":return o(bo,{options:d.options,value:t[d.key]??"",onChange:f=>l(d.key,f.target.value),className:"w-36"},d.key);case"badge-toggle":return o("div",{className:"flex items-center gap-1",children:d.options.map(f=>{const h=t[d.key]===f.value;return o("button",{type:"button",onClick:()=>l(d.key,h?void 0:f.value),children:o(yr,{variant:h?"info":"default",className:"cursor-pointer",children:f.label})},f.value)})},d.key);default:return null}})})}function vl({label:e,icon:t,href:n,badge:r,active:s=!1,className:a}){return u("a",{href:n,className:W("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:[o(t,{className:"h-3.5 w-3.5 shrink-0"}),o("span",{className:"truncate flex-1",children:e}),r!==void 0&&o(yr,{className:"ml-auto text-[10px] px-1.5 py-0",children:r})]})}function wl({logo:e,sections:t,footer:n,onNavigate:r,className:s}){return u("nav",{className:W("bg-surface border-r border-border h-full flex flex-col",s),children:[e&&o("div",{className:"px-3 py-2 shrink-0",children:e}),o("div",{className:"flex-1 overflow-auto px-1 py-1",children:t.map((a,i)=>u("div",{className:W(i>0?"mt-3":""),children:[a.label&&o("span",{className:"text-[10px] text-foreground-disabled uppercase tracking-wider px-2 mb-1 block",children:a.label}),o("div",{className:"flex flex-col gap-0.5",onClick:r,children:a.items.map(l=>o(vl,{...l},l.href))})]},i))}),n&&n.length>0&&u("div",{className:"shrink-0 px-1 pb-1",children:[o(vc,{className:"mb-1"}),o("div",{className:"flex flex-col gap-0.5",onClick:r,children:n.map(a=>o(vl,{...a},a.href))})]})]})}function PC({sidebar:e,header:t,mobileLogo:n,mobileActions:r,children:s,className:a}){const i=ar(),[l,c]=P(!1);return u("div",{className:W("flex h-screen",a),children:[!i&&o(wl,{...e,className:W("w-44",e.className)}),i&&o(Mc,{open:l,onClose:()=>c(!1),width:"w-64",children:o(wl,{...e,onNavigate:()=>c(!1),className:"w-full border-r-0"})}),u("div",{className:"flex flex-1 flex-col min-w-0",children:[i&&u("header",{className:"flex items-center h-12 border-b border-border px-3 shrink-0 bg-surface/80 backdrop-blur-sm",children:[o("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:o(P5,{className:"h-5 w-5"})}),n&&o("div",{className:"flex-1 flex justify-center",children:n}),r&&o("div",{className:"shrink-0",children:r})]}),!i&&t&&u("header",{className:"flex items-center h-10 border-b border-border px-4 shrink-0",children:[t.breadcrumbs&&t.breadcrumbs.length>0&&o("nav",{className:"flex items-center gap-1 text-xs flex-1 min-w-0",children:t.breadcrumbs.map((d,f)=>{const p=f===t.breadcrumbs.length-1;return u("span",{className:"flex items-center gap-1",children:[f>0&&o(Pn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),d.href&&!p?o("a",{href:d.href,className:"text-foreground-subtle hover:text-foreground transition-colors truncate",children:d.label}):o("span",{className:"text-foreground truncate",children:d.label})]},f)})}),t.actions&&o("div",{className:"flex items-center gap-2 ml-auto shrink-0",children:t.actions})]}),o("main",{className:"flex-1 overflow-auto p-4",children:s})]})]})}const _C={online:"bg-success",offline:"bg-danger",warning:"bg-warning",unknown:"bg-foreground-subtle"};function $C({title:e,subtitle:t,status:n,selected:r,onClick:s,badges:a,actions:i,offlineAction:l,className:c}){const d=n==="offline";return u("div",{onClick:s,className:W("w-full rounded-lg border p-3 text-left transition-colors",s&&"cursor-pointer",r?"border-primary bg-primary/10":"border-border bg-surface hover:bg-surface-hover",d&&!r&&"opacity-50",c),children:[u("div",{className:"flex items-center justify-between mb-2",children:[o("span",{className:"text-sm font-medium truncate",children:e}),n&&o("span",{className:W("h-2 w-2 rounded-full shrink-0",_C[n])})]}),t&&o("div",{className:"text-[11px] text-foreground-muted",children:t}),a&&a.length>0&&o("div",{className:"flex flex-wrap gap-1 mt-2",children:a.map((f,p)=>{const h=W("rounded px-1.5 py-0.5 text-[10px] flex items-center gap-0.5",r?"bg-primary/20":"bg-surface-hover",f.onClick&&"hover:opacity-80 transition-opacity cursor-pointer");return f.onClick?u("button",{onClick:m=>{m.stopPropagation(),f.onClick()},className:h,children:[f.icon,f.label]},p):u("span",{className:h,children:[f.icon,f.label]},p)})}),!d&&i&&i.length>0&&o("div",{className:"flex items-center gap-0.5 mt-2 -mb-1",children:i.map((f,p)=>o("button",{onClick:h=>{h.stopPropagation(),f.onClick()},className:"p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors",title:f.label,"aria-label":f.label,children:f.icon},p))}),d&&l&&o("div",{className:"mt-2",onClick:f=>f.stopPropagation(),children:l})]})}function DC({children:e,minCardWidth:t=220,gap:n=3,className:r}){return o("div",{className:W("p-4 overflow-y-auto flex-1 content-start",r),style:{display:"grid",gridTemplateColumns:`repeat(auto-fill, minmax(${t}px, 1fr))`,gap:`${n*4}px`},children:e})}const TC="capability.binding-changed";function St(e,t){const[n,r]=P(null);return Y(()=>{if(t===null){r(null);return}let s=!1;const a=async()=>{try{const l=await e.deviceManager.getBindings.query({deviceId:t});s||r(l)}catch{s||r(l=>l)}};a();const i=e.live?.onEvent.subscribe({category:TC},{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?MN(e,n):null,[e,n])}function an(e){const t=U(r=>e?e.subscribe(()=>r()):()=>{},[e]),n=U(()=>e?.value,[e]);return xa(t,n,n)}function ug(e,t,n){const r=St(e,t),s=r?n(r.state):void 0;return an(s)}function Fr(e){const t=St(e.trpc,e.deviceId),n=t!==null?e.slice(t):void 0,r=an(n),s=t!==null?e.cap(t):void 0,c=(e.requireFeature===void 0||(e.deviceFeatures??[]).includes(e.requireFeature))&&s!==void 0&&r!==void 0;return{dev:t,cap:s,slice:r,available:c}}function LC(e){return e.parentDeviceId===null?"top-level":e.role?"accessory":"adopted"}const RC={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 OC(e){const t=RC[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 BC={siren:ya,floodlight:ym,spotlight:Cm,"pir-sensor":Nm,chime:R5,autotrack:pm,nightvision:mc,"privacy-mask":gm,doorbell:fm},zC={camera:hc,hub:gl,nvr:gl,light:ym,siren:ya,switch:kS,sensor:Nm,thermostat:wS,button:qk,generic:bc};function pg(e){return e.role?BC[e.role]??bc:zC[e.type.toLowerCase()]??hc}const fg={"native-snapshot":b5,"two-way-audio":vm,"pan-tilt-zoom":pm,"ptz-autotrack":E5,"doorbell-button":fm,"motion-trigger":Nn,"battery-operated":dm,rebootable:Sm},hg={"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"},FC={"native-snapshot":"snapshot",rebootable:"reboot","pan-tilt-zoom":"ptz","ptz-autotrack":"ptz-autotrack","two-way-audio":"intercom","motion-trigger":"motion-trigger"},mg=new Set(["camera","hub","nvr"]);function gg(e){return!mg.has(e.type.toLowerCase())}function Ou(e){return e.role?!0:!mg.has(e.type.toLowerCase())}function bg(e){return(e.features??[]).includes("motion-trigger")}function jC(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 r=n.slice(-2).join("-");if(r.length>=6)return r}return`…${e.slice(-18)}`}function HC({trpc:e,accessoryChildren:t,adoptedChildren:n,onNavigate:r}){return u("div",{className:"border-t border-border-subtle/50",children:[n.length>0&&o(Bu,{trpc:e,label:"Adopted devices",rows:n,onNavigate:r}),t.length>0&&o(Bu,{trpc:e,label:"Accessories",rows:t,onNavigate:r})]})}function Bu({trpc:e,label:t,rows:n,onNavigate:r}){return u("div",{children:[o("div",{className:"px-3 pt-1.5 pb-1 text-[9px] font-semibold uppercase tracking-wide text-foreground-subtle",children:t}),o("ul",{children:n.map(s=>o(VC,{trpc:e,child:s,onNavigate:r},s.id))})]})}function VC({trpc:e,child:t,onNavigate:n}){const r=!t.disabled,s=r&&gg(t),a=r&&bg(t),i=pg(t);return o("li",{children:u("div",{onClick:l=>{l.stopPropagation(),n(t.id)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-surface-hover transition-colors cursor-pointer",children:[o(i,{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),o("span",{className:"text-[10.5px] text-foreground flex-1 truncate",children:t.name}),a&&o(UC,{trpc:e,deviceId:t.id,features:t.features}),s&&o(qC,{trpc:e,deviceId:t.id}),o("span",{className:W("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 qC({trpc:e,deviceId:t}){const{dev:n,cap:r,slice:s,available:a}=Fr({trpc:e,deviceId:t,cap:p=>p.switch,slice:p=>p.state.switch}),[i,l]=P(!1);if(n!==null&&!r)return null;const c=s?.on===!0,d={transform:c?"translateX(14px)":"translateX(2px)"},f=async p=>{if(p.stopPropagation(),!(i||!a||!r)){l(!0);try{await r.setState({on:!c})}finally{l(!1)}}};return o("button",{type:"button",onClick:p=>{f(p)},disabled:i||!a,className:W("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:o("span",{className:W("absolute h-3 w-3 rounded-full transition-all",c?"bg-success":"bg-foreground-subtle"),style:d})})}function UC({trpc:e,deviceId:t,features:n}){const{dev:r,cap:s,slice:a,available:i}=Fr({trpc:e,deviceId:t,cap:p=>p.motionTrigger,slice:p=>p.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:n}),[l,c]=P(!1);if(r!==null&&!s)return null;const d=a?.enabled===!0,f=async p=>{if(p.stopPropagation(),!(l||!i||!s)){c(!0);try{await s.setMotionTrigger({enabled:!d})}finally{c(!1)}}};return o("button",{type:"button",onClick:p=>{f(p)},disabled:l||!i,className:W("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:o(Nn,{className:"h-2.5 w-2.5"})})}function xg({trpc:e,device:t,flags:n}){if(!!t.disabled)return null;const s=t.type.toLowerCase(),a=n.showSwitchToggle&&gg(t),i=bg(t),l=s==="hub"||s==="nvr",c=(t.features??[]).includes("rebootable"),d=l&&c;return u(me,{children:[i&&o(GC,{trpc:e,deviceId:t.id,features:t.features}),a&&o(QC,{trpc:e,deviceId:t.id}),d&&o(WC,{trpc:e,deviceId:t.id})]})}function QC({trpc:e,deviceId:t}){const{dev:n,cap:r,slice:s,available:a}=Fr({trpc:e,deviceId:t,cap:p=>p.switch,slice:p=>p.state.switch}),[i,l]=P(!1);if(n!==null&&!r)return null;const c=s?.on===!0,d={transform:c?"translateX(14px)":"translateX(2px)"},f=async p=>{if(p.stopPropagation(),!(i||!a||!r)){l(!0);try{await r.setState({on:!c})}finally{l(!1)}}};return o("button",{type:"button",onClick:p=>{f(p)},disabled:i||!a,className:W("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:o("span",{className:W("absolute h-3 w-3 rounded-full transition-all",c?"bg-success":"bg-foreground-subtle"),style:d})})}function GC({trpc:e,deviceId:t,features:n}){const{dev:r,cap:s,slice:a,available:i}=Fr({trpc:e,deviceId:t,cap:p=>p.motionTrigger,slice:p=>p.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:n}),[l,c]=P(!1);if(r!==null&&!s)return null;const d=a?.enabled===!0,f=async p=>{if(p.stopPropagation(),!(l||!i||!s)){c(!0);try{await s.setMotionTrigger({enabled:!d})}finally{c(!1)}}};return o("button",{type:"button",onClick:p=>{f(p)},disabled:l||!i,className:W("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:o(Nn,{className:"h-2.5 w-2.5"})})}const ui=168,KC=4;function WC({trpc:e,deviceId:t}){const{dev:n,cap:r}=Fr({trpc:e,deviceId:t,cap:x=>x.reboot,slice:()=>{}}),s=ne(null),a=ne(null),[i,l]=P(null),[c,d]=P(!1),f=n!==null&&r!==void 0&&r!==null,p=i!==null,h=()=>l(null),m=()=>{const x=s.current;if(!x)return;const y=x.getBoundingClientRect(),w=y.right-ui,v=Math.max(8,Math.min(w,window.innerWidth-ui-8)),N=y.bottom+KC;l({top:N,left:v})};if(Y(()=>{if(!p)return;const x=w=>{const v=s.current,N=a.current,k=w.target;k!==null&&(v&&v.contains(k)||N&&N.contains(k)||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)}},[p]),n!==null&&!r)return null;const g=x=>{x.stopPropagation(),p?h():m()},b=async()=>{if(!(c||!f||!r)){d(!0),h();try{await r.reboot({})}finally{d(!1)}}};return u(me,{children:[o("button",{ref:s,type:"button",onClick:g,disabled:c||!f,className:W("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||!f)&&"opacity-50",p&&"bg-surface-hover text-foreground"),title:"More actions","aria-label":"More actions","aria-haspopup":"menu","aria-expanded":p,children:o(hm,{className:"h-3 w-3"})}),i&&Lo(o("div",{ref:a,role:"menu",style:{position:"fixed",top:i.top,left:i.left,width:ui},className:"z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-1",onClick:x=>x.stopPropagation(),children:u("button",{type:"button",role:"menuitem",onClick:()=>{b()},disabled:c||!f,className:W("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:[o(Sm,{className:"h-3 w-3 shrink-0 text-foreground-subtle"}),o("span",{children:"Reboot device"})]})}),document.body)]})}const YC=Object.freeze([]);function ZC(e){return e==="native"?"native":"enhanced"}function XC(e){return e.map(t=>({kind:"marker",feature:t}))}function JC(e,t){const n=new Map,r=t.entries??[];for(const a of r)n.set(a.capName,a);const s=[];for(const a of e){const i=FC[a];if(i===void 0){s.push({kind:"marker",feature:a});continue}const l=n.get(i);l&&s.push({kind:ZC(l.kind),feature:a,capName:i})}return s}function e3(e,t,n){const[r,s]=P(null),[a,i]=P(!1),[l,c]=P(!0);return Y(()=>{if(t===null){s(null),i(!1),c(!1);return}let d=!1;c(!0),i(!1);const f=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)}};f();const p=e.live?.onEvent.subscribe({category:"capability.binding-changed"},{onData:h=>{const m=h.data?.source;if(!m){f();return}m.type==="device"&&m.id===t&&f()}});return()=>{d=!0,p?.unsubscribe()}},[e,t]),n.length===0?{loading:l,resolved:YC}:l||a||!r?{loading:l,resolved:XC(n)}:{loading:!1,resolved:JC(n,r)}}const t3=[];function yg({trpc:e,device:t,flags:n,accessoryCount:r,adoptedCount:s,showFeatureRow:a=!1}){const i=r+s,l=n.showChildrenAccordion&&i>0,c=t.features??t3,d=a&&c.length>0,{resolved:f}=e3(e,d?t.id:null,c),p=d&&f.length>0;return!l&&!p?null:u("div",{className:"flex items-center gap-1.5 flex-nowrap whitespace-nowrap min-w-0",children:[l&&o(n3,{accessoryCount:r,adoptedCount:s}),p&&o(r3,{resolved:f})]})}function n3({accessoryCount:e,adoptedCount:t}){const n=e+t;if(n===0)return null;const r=t>0&&e>0?`${String(t)} adopted · ${String(e)} accessor${e===1?"y":"ies"}`:t>0?`${String(t)} adopted`:`${String(e)} accessor${e===1?"y":"ies"}`;return u("span",{className:"text-[9px] font-medium text-foreground-subtle bg-surface-elevated/60 rounded px-1.5 py-0.5 flex-shrink-0",title:r,children:["+",n]})}const vg=240,zu=200;function r3({resolved:e}){const t=ne(null),[n,r]=P(null);return u("span",{ref:t,className:"relative inline-flex items-center gap-1 cursor-help",onMouseEnter:()=>{const i=t.current;if(!i)return;const l=i.getBoundingClientRect(),f=window.innerHeight-l.bottom>=zu?l.bottom+4:l.top-zu-4,p=Math.max(8,Math.min(l.left,window.innerWidth-vg-8));r({top:f,left:p})},onMouseLeave:()=>r(null),children:[e.map(i=>{const l=fg[i.feature];return l?o("span",{className:"inline-flex items-center justify-center h-4 w-4 rounded bg-surface-elevated/60 text-foreground-subtle",title:hg[i.feature]??i.feature,children:o(l,{className:"h-2.5 w-2.5"})},i.feature):null}),n&&Lo(o(o3,{resolved:e,position:n}),document.body)]})}function o3({resolved:e,position:t}){return u("div",{style:{position:"fixed",top:t.top,left:t.left,width:vg,pointerEvents:"none"},className:"z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-2",children:[o("h5",{className:"text-[9px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5",children:"Features"}),o("ul",{className:"space-y-0.5",children:e.map(n=>o(s3,{entry:n},n.feature))})]})}function s3({entry:e}){const t=fg[e.feature],n=hg[e.feature]??e.feature;return u("li",{className:"flex items-center justify-between gap-2 text-[10px]",children:[u("span",{className:"flex items-center gap-1.5 text-foreground",children:[t&&o(t,{className:"h-3 w-3 text-foreground-subtle"}),o("span",{children:n})]}),o(a3,{kind:e.kind})]})}function a3({kind:e}){return e==="marker"?o("span",{className:"text-[8.5px] px-1 rounded text-foreground-subtle",title:"Informational marker (no cap registered)",children:"marker"}):o("span",{className:W("text-[8.5px] px-1 rounded",e==="native"?"bg-success/15 text-success":"bg-primary/15 text-primary"),children:e})}function wg({device:e,variant:t,flags:n,parent:r,integrationIcon:s,hasChildren:a,expanded:i,onToggleExpand:l,onNavigateToParent:c}){const d=pg(e);return u("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[n.showChildrenAccordion&&a?o("button",{type:"button",onClick:f=>{f.stopPropagation(),l()},className:"flex h-3.5 w-3.5 items-center justify-center text-foreground-subtle hover:text-foreground transition-colors flex-shrink-0","aria-label":i?"Collapse children":"Expand children","aria-expanded":i,children:i?o(or,{className:"h-3 w-3"}):o(Pn,{className:"h-3 w-3"})}):n.showChildrenAccordion?o("span",{className:"h-3.5 w-3.5 flex-shrink-0"}):null,o(d,{className:W("text-foreground-subtle flex-shrink-0",t==="minimal"?"h-3 w-3":"h-3.5 w-3.5")}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-1.5 min-w-0",children:[n.showIntegrationIcon&&s&&o("span",{className:"flex-shrink-0",children:s}),o("span",{className:W("font-semibold text-foreground truncate",t==="minimal"?"text-[10.5px]":"text-[11px]"),title:e.name,children:e.name})]}),(n.showId||n.showStableId)&&u("div",{className:"mt-0.5 flex items-center gap-1 text-[9px] text-foreground-subtle font-mono truncate",title:n.showStableId?`stableId: ${e.stableId}`:void 0,children:[n.showId&&u("span",{className:"flex-shrink-0 tabular-nums",children:["#",String(e.id)]}),n.showId&&n.showStableId&&o("span",{className:"flex-shrink-0 opacity-50",children:"·"}),n.showStableId&&o("span",{className:"truncate",children:jC(e.stableId)})]}),n.showParentBadge&&r&&u("button",{type:"button",onClick:f=>{f.stopPropagation(),c(r.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: ${r.name} (#${String(r.id)})`,children:[o(gl,{className:"h-2.5 w-2.5 shrink-0"}),u("span",{className:"truncate",children:["Under: ",r.name]})]})]})]})}function Tc(e,t){return ug(e,t,r=>r.battery)??null}function Lc(e,t){const n=St(e,t),r=ne(!1),{data:s,isLoading:a,isFetching:i,refetch:l}=tr({queryKey:["device",t,"snapshot"],queryFn:()=>{if(!n)throw new Error("useDeviceSnapshotImage: device proxy not ready");const f=r.current;return r.current=!1,n.snapshot?.getSnapshot({force:f})??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(){r.current=!0,l()}return{src:c,loading:a||i,refresh:d}}function i3(e){return e<=10?kk:e<=30?wk:e>=95?yk:dm}function l3(e,t){return t!=="none"?"text-emerald-400":e<=10?"text-rose-400":e<=30?"text-amber-400":"text-foreground-subtle"}function Rc({status:e,variant:t="compact",className:n}){if(!e)return null;const r=i3(e.percentage),s=l3(e.percentage,e.charging),a=e.charging==="solar"?Cm:e.charging==="dc"?V5:null,i=e.sleeping;return u("span",{className:W("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:[o(r,{className:"h-3.5 w-3.5"}),u("span",{children:[Math.round(e.percentage),"%"]}),a&&o(a,{className:"h-3 w-3"}),i&&o(mc,{className:"h-3 w-3 text-blue-300"}),t==="full"&&e.charging!=="none"&&o("span",{className:"text-foreground-subtle",children:e.charging})]})}function Ng({trpc:e,device:t,status:n,enabled:r,showStatusPills:s=!1}){const a=r&&t.online,i=Lc(e,a?t.id:null),l=(t.features??[]).includes("battery-operated"),c=s&&l&&!t.disabled,d=Tc(e,c?t.id:null);return!r&&!c?null:u("span",{className:"inline-flex items-center gap-1.5 flex-nowrap whitespace-nowrap",children:[c&&d&&o(Rc,{status:d}),r&&o(c3,{deviceName:t.name,snapshotUrl:i.src,status:n})]})}const pi=288,Fu=196,fi=8;function c3({deviceName:e,snapshotUrl:t,status:n}){const r=ne(null),[s,a]=P(null),i=n==="offline"||n==="disabled",l=()=>{const d=r.current;if(!d)return;const f=d.getBoundingClientRect(),p=f.top,h=window.innerHeight-f.bottom,m=p<Fu+fi&&h>p,g=m?f.bottom+fi:f.top-Fu-fi,b=f.right-pi,x=Math.max(8,Math.min(b,window.innerWidth-pi-8));a({top:g,left:x,placeBelow:m})},c=()=>a(null);return u(me,{children:[o("button",{ref:r,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:o(Oo,{className:"h-3.5 w-3.5"})}),s&&Lo(u("div",{style:{position:"fixed",top:s.top,left:s.left,width:pi,pointerEvents:"none"},className:"rounded-lg border border-border bg-surface shadow-lg shadow-black/30 z-[9999] overflow-hidden",children:[o("div",{className:"h-40 bg-background flex items-center justify-center",children:t&&!i?o("img",{src:t,alt:e,className:"h-full w-full object-cover"}):o("span",{className:"text-xs text-foreground-subtle",children:n==="offline"?"Offline — no snapshot":n==="disabled"?"Disabled":"No snapshot yet"})}),o("div",{className:"px-3 py-2",children:o("p",{className:"text-xs font-semibold text-foreground truncate",children:e})})]}),document.body)]})}function kg({status:e}){const t=e==="disabled"?"bg-warning":e==="online"?"bg-success":"bg-danger",n=e==="disabled"?"Disabled":e==="online"?"Online":"Offline";return o("span",{className:W("h-1.5 w-1.5 rounded-full flex-shrink-0",t),title:n})}function xo(e){const{trpc:t,device:n,parent:r,integrationIcon:s,onNavigate:a,className:i}=e,l=OC(e),c=e.variant??"compact",d=e.view??"card",f=!n.disabled,p=n.isCamera??n.type.toLowerCase()==="camera",h=e.children??[],m=h.filter(Ou),g=h.filter(E=>!Ou(E)),b=h.length>0,[x,y]=P(!1),w=e.expanded??x,v=e.onToggleExpand??(()=>y(E=>!E)),N=E=>{a?.(E)},k=e.indentLevel??(e.isAccessoryRow?2:0),C=f?n.online?"online":"offline":"disabled";return d==="table"?o(u3,{trpc:t,device:n,variant:c,flags:l,parent:r??null,integrationIcon:s??null,accessoryCount:m.length,adoptedCount:g.length,hasChildren:b,expanded:w,onToggleExpand:v,onNavigate:N,displayStatus:C,isCamera:p,showSnapshot:l.showSnapshot&&p,isAccessoryRow:e.isAccessoryRow??!1,indentLevel:k,className:i}):u("div",{className:W("rounded-lg border border-border bg-surface transition-colors",!f&&"opacity-60",i),children:[u("div",{onClick:()=>N(n.id),className:W("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:[o(wg,{device:n,variant:c,flags:l,parent:r??null,integrationIcon:s??null,hasChildren:b,expanded:w,onToggleExpand:v,onNavigateToParent:N}),o(yg,{trpc:t,device:n,flags:l,accessoryCount:m.length,adoptedCount:g.length,showFeatureRow:!1}),o(Ng,{trpc:t,device:n,status:C,enabled:l.showSnapshot&&p,showStatusPills:!0}),o(xg,{trpc:t,device:n,flags:l}),o(kg,{status:C})]}),w&&b&&o(HC,{trpc:t,accessoryChildren:m,adoptedChildren:g,onNavigate:N})]})}const d3={0:"pl-2",1:"pl-6",2:"pl-8"};function u3(e){const{trpc:t,device:n,variant:r,flags:s,parent:a,integrationIcon:i,accessoryCount:l,adoptedCount:c,hasChildren:d,expanded:f,onToggleExpand:p,onNavigate:h,displayStatus:m,isCamera:g,showSnapshot:b,isAccessoryRow:x,indentLevel:y,className:w}=e;return u("tr",{onClick:()=>h(n.id),className:W("cursor-pointer hover:bg-surface-hover transition-colors",!s.showChildrenAccordion&&"border-b border-border-subtle/40",x&&"bg-foreground-subtle/[0.03]",w),children:[o("td",{className:W("py-2 align-middle pr-2",d3[y]),children:o(wg,{device:n,variant:r,flags:s,parent:a,integrationIcon:i,hasChildren:d,expanded:f,onToggleExpand:p,onNavigateToParent:h})}),o("td",{className:"px-2 py-2 align-middle text-[10px] text-foreground-subtle whitespace-nowrap",children:n.type}),o("td",{className:"px-2 py-2 align-middle",children:o(yg,{trpc:t,device:n,flags:s,accessoryCount:l,adoptedCount:c,showFeatureRow:!0})}),o("td",{className:"px-2 py-2 align-middle",children:o(Ng,{trpc:t,device:n,status:m,enabled:b&&g,showStatusPills:!0})}),o("td",{className:"px-2 py-2 align-middle text-right whitespace-nowrap",children:u("span",{className:"inline-flex items-center gap-1.5",children:[o(xg,{trpc:t,device:n,flags:s}),o(kg,{status:m})]})})]})}function Sg(e,t){const[n,r]=P(e);return Y(()=>{const s=setTimeout(()=>r(e),t);return()=>clearTimeout(s)},[e,t]),n}const p3=new Set(["hub","nvr"]);function f3(e){const t=new Map;for(const s of e)t.set(s.id,s);const n=[],r=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(p3.has(i.type)&&!l){n.push(s);continue}const d=r.get(a);d?d.push(s):r.set(a,[s])}return{topLevel:n,accessoriesByParent:r}}const ju=2;function h3(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=[],r=Math.max(2,e-ju),s=Math.min(t-1,e+ju);n.push({kind:"page",n:1}),r>2&&n.push({kind:"ellipsis",side:"left"});for(let a=r;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 m3({currentPage:e,totalItems:t,pageSize:n,onPageChange:r,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=h3(e,a);return u("div",{className:"flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle",children:[u("span",{children:["Showing ",i,"–",l," of ",t," ",s]}),u("span",{className:"inline-flex items-center gap-1",children:[o("button",{type:"button","aria-label":"Previous page",disabled:e===1,onClick:()=>r(e-1),className:W("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:o(Rk,{className:"h-3 w-3"})}),c.map((d,f)=>{if(d.kind==="ellipsis")return o("span",{className:"px-1 text-foreground-subtle/60 select-none",children:"…"},`e-${f}`);const p=d.n===e;return o("button",{type:"button",onClick:()=>r(d.n),className:W("inline-flex items-center justify-center h-7 min-w-7 px-1.5 rounded border text-[10.5px] font-medium transition-colors",p?"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}`)}),o("button",{type:"button","aria-label":"Next page",disabled:e===a,onClick:()=>r(e+1),className:W("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:o(Pn,{className:"h-3 w-3"})})]})]})}function g3({view:e,onViewChange:t,types:n,currentType:r,onTypeChange:s,addons:a,currentAddon:i,onAddonChange:l,hideAddons:c=!1}){return u("div",{className:"flex items-center gap-2 flex-wrap",children:[u("span",{className:"inline-flex border border-border rounded-md overflow-hidden",children:[o("button",{type:"button",onClick:()=>t("cards"),className:W("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:o(k5,{className:"h-3.5 w-3.5"})}),o("button",{type:"button",onClick:()=>t("table"),className:W("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:o(xS,{className:"h-3.5 w-3.5"})})]}),n&&n.length>0&&u(me,{children:[o(Hu,{children:"Type"}),o(hi,{active:r===null,onClick:()=>s(null),children:"All"}),n.map(d=>o(hi,{active:r===d,onClick:()=>s(r===d?null:d),children:b3(d)},d))]}),!c&&a&&a.length>0&&u(me,{children:[o(Hu,{children:"Integration"}),a.map(d=>o(hi,{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 Hu({children:e}){return o("span",{className:"text-[10px] font-medium uppercase tracking-wider text-foreground-subtle ml-1",children:e})}function hi({active:e,icon:t,onClick:n,showClearIcon:r,children:s}){return u("button",{type:"button",onClick:n,className:W("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&&o("span",{className:"inline-flex items-center",children:t}),o("span",{children:s}),e&&r&&o(Ye,{className:"h-2.5 w-2.5 opacity-70"})]})}function b3(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function x3({variant:e,onClearFilters:t}){return u("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[o(y5,{className:"h-8 w-8 text-foreground-subtle/40 mb-3"}),o("p",{className:"text-sm font-medium text-foreground-subtle",children:e==="filtered"?"No devices match the current filters":"No devices yet"}),e==="filtered"&&t&&o("button",{type:"button",onClick:t,className:"mt-2 text-[11px] text-primary hover:underline",children:"Clear filters"})]})}function qt(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 Vu(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 y3(e,t){try{localStorage.setItem(`camstack:${e}:lastFilters`,JSON.stringify(t))}catch{}}function qu(e,t,n){const r=new URLSearchParams(window.location.search),s=r.get(qt(e,"view")),a=s==="cards"||s==="table"?s:n.view??t,i=r.get(qt(e,"page")),l=i?parseInt(i,10):1,c=Number.isFinite(l)&&l>=1?l:1,d=r.get(qt(e,"addon"))??n.addon??null,f=r.get(qt(e,"type"))??n.type??null,p=r.get(qt(e,"q"))??n.q??"";return{view:a,page:c,addon:d,type:f,q:p}}function v3(e,t,n){const r=new URLSearchParams(window.location.search),s=(l,c)=>{c===null||c===""?r.delete(l):r.set(l,c)};s(qt(e,"view"),t.view===n?null:t.view),s(qt(e,"page"),t.page===1?null:String(t.page)),s(qt(e,"addon"),t.addon),s(qt(e,"type"),t.type),s(qt(e,"q"),t.q||null);const a=r.toString(),i=a?`${window.location.pathname}?${a}`:window.location.pathname;window.history.replaceState(null,"",i)}function w3(e){const{scope:t,defaultView:n,lsKey:r}=e,[s,a]=P(()=>{const g=Vu(r);return qu(t,n,g)}),i=ne(s);i.current=s,Y(()=>{const g=()=>{const b=Vu(r),x=qu(t,n,b);i.current=x,a(x)};return window.addEventListener("popstate",g),()=>window.removeEventListener("popstate",g)},[t,n,r]);const l=U(g=>{const b=g(i.current);i.current=b,a(b),v3(t,b,n),y3(r,{view:b.view,addon:b.addon,type:b.type,q:b.q})},[t,n,r]),c=U(g=>l(b=>({...b,view:g})),[l]),d=U(g=>l(b=>({...b,page:g})),[l]),f=U(g=>l(b=>({...b,addon:g,page:1})),[l]),p=U(g=>l(b=>({...b,type:g,page:1})),[l]),h=U(g=>l(b=>({...b,q:g,page:1})),[l]),m=U(()=>l(g=>({...g,addon:null,type:null,q:"",page:1})),[l]);return{state:s,setView:c,setPage:d,setAddon:f,setType:p,setQ:h,clearFilters:m}}const N3={cards:24,table:50};function yo(e){const{devices:t,trpc:n,defaultView:r="table",filters:s,forceAddon:a,resolveIntegrationIcon:i,resolveParent:l,onNavigate:c,pageSize:d=N3,urlScope:f="root",lsKey:p=f==="root"?"devices":"integrations:nested"}=e,h=w3({scope:f,defaultView:r,lsKey:p}),m=h.state.view,g=m==="cards"?d.cards:d.table,[b,x]=P(h.state.q),y=Sg(b,300);Y(()=>{y!==h.state.q&&h.setQ(y)},[y]);const w=a??h.state.addon,v=q(()=>{const R=h.state.q.toLowerCase().trim();return t.filter(M=>!(w&&M.addonId!==w||h.state.type&&M.type!==h.state.type||R&&!M.name.toLowerCase().includes(R)&&!M.stableId.toLowerCase().includes(R)))},[t,w,h.state.type,h.state.q]),N=q(()=>f3(v),[v]),k=q(()=>{if(h.state.q.trim()==="")return new Set;const R=h.state.q.toLowerCase().trim(),M=new Set;for(const[T,_]of N.accessoriesByParent.entries())_.some(L=>L.name.toLowerCase().includes(R)||L.stableId.toLowerCase().includes(R))&&M.add(T);return M},[N.accessoriesByParent,h.state.q]),C=N.topLevel.length,E=Math.max(1,Math.ceil(C/g)),A=Math.min(h.state.page,E),I=(A-1)*g,z=N.topLevel.slice(I,I+g);Y(()=>{A!==h.state.page&&h.setPage(A)},[A]),I3();const $=w!=null||h.state.type!==null||h.state.q!=="",B=C===0;return u("div",{className:"flex flex-col gap-3",children:[u("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[o(g3,{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}),u("div",{className:"relative",children:[o(go,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle pointer-events-none"}),o("input",{type:"text",value:b,onChange:R=>x(R.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"})]})]}),B?o(x3,{variant:$?"filtered":"nofilter",onClearFilters:$?h.clearFilters:void 0}):m==="cards"?o(k3,{rows:z,accessoriesByParent:N.accessoriesByParent,trpc:n,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:c??null}):o(M3,{rows:z,accessoriesByParent:N.accessoriesByParent,autoExpandedParents:k,devices:v,trpc:n,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:c??null}),o(m3,{currentPage:A,totalItems:C,pageSize:g,onPageChange:h.setPage}),a===void 0&&$&&C>0&&u("p",{className:"text-[11px] text-foreground-subtle",children:["Showing ",C," of ",t.length," devices",w&&u(me,{children:[" ","· filtered by"," ",o("strong",{className:"text-primary",children:s?.addons?.find(R=>R.id===w)?.name??w})]})]})]})}function k3({rows:e,accessoriesByParent:t,trpc:n,resolveIntegrationIcon:r,resolveParent:s,onNavigate:a}){return o("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 o(xo,{trpc:n,device:i,view:"card",integrationIcon:r?.(i.addonId)??null,parent:i.parentDeviceId!==null?s?.(i.parentDeviceId)??null:null,children:l,onNavigate:a??void 0},i.id)})})}const S3=new Set(["hub","nvr"]);function C3(e,t){return e.parentDeviceId===null||t===null?0:S3.has(t.toLowerCase())?1:0}function M3({rows:e,accessoriesByParent:t,autoExpandedParents:n,devices:r,trpc:s,resolveIntegrationIcon:a,resolveParent:i,onNavigate:l}){const c=q(()=>{const d=new Map;for(const f of r)d.set(f.id,f.type);return d},[r]);return o("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:u("table",{className:"w-full border-collapse",children:[o("thead",{children:u("tr",{className:"border-b border-border",children:[o("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle",children:"Name"}),o("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-24",children:"Type"}),o("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Features"}),o("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-20",children:"Preview"}),o("th",{className:"text-right px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Actions"})]})}),o("tbody",{children:e.map(d=>{const f=t.get(d.id)??[],p=f.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 o(E3,{parent:d,accessories:f,hasAccessories:p,forceExpanded:h,trpc:s,integrationIcon:a?.(d.addonId)??null,parentRowParent:m,indentLevel:C3(d,g),onNavigate:l??null},d.id)})})]})})}function E3({parent:e,accessories:t,hasAccessories:n,forceExpanded:r,trpc:s,integrationIcon:a,parentRowParent:i,indentLevel:l,onNavigate:c}){const[d,f]=P(r),p=ne(r);return Y(()=>{p.current!==r&&(f(r),p.current=r)},[r]),u(me,{children:[o(xo,{trpc:s,device:e,view:"table",integrationIcon:a,parent:i,children:t,onNavigate:c??void 0,showChildrenAccordion:n,expanded:d,onToggleExpand:()=>f(g=>!g),indentLevel:l}),n&&d&&t.map(g=>o(xo,{trpc:s,device:g,view:"table",integrationIcon:null,parent:null,isAccessoryRow:!0,showChildrenAccordion:!1,onNavigate:c??void 0},g.id))]})}function I3(){ke()}function A3({options:e,value:t,onChange:n}){return o("div",{className:"flex flex-wrap gap-2",children:e.map(r=>{const s=r.id===t;return u("button",{onClick:()=>r.available&&n(r.id),disabled:!r.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":r.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:[o(n5,{className:"h-3.5 w-3.5 shrink-0"}),r.label,r.isBest&&u("span",{className:"inline-flex items-center gap-0.5 rounded-full bg-amber-500/15 px-1.5 py-0.5 text-[10px] font-semibold text-amber-400",children:[o(mS,{className:"h-2.5 w-2.5"}),"Best"]}),r.platformScore!=null&&u("span",{className:"text-[10px] text-foreground-subtle/60",children:["(",r.platformScore,")"]}),o("span",{className:`h-1.5 w-1.5 rounded-full ${r.available?"bg-success":"bg-danger"}`})]},r.id)})})}function P3(e,t){const n=new Set(t.slots.flatMap(i=>i.addons.map(l=>l.id))),r=[];function s(i){if(!n.has(i.addonId))return r.push(`Addon "${i.addonId}" is no longer available — step removed`),null;const l=t.slots.flatMap(f=>f.addons).find(f=>f.id===i.addonId);let c=i.modelId;if(l&&!l.models.some(f=>f.id===c)){const f=l.defaultModelId;r.push(`Model "${c}" not available for ${i.addonId} — using "${f}"`),c=f}const d=i.children.map(f=>s(f)).filter(f=>f!==null);return{...i,modelId:c,children:d}}const a=e.map(i=>s(i)).filter(i=>i!==null);return{valid:r.length===0,steps:a,warnings:r}}function _3(e){const t=new Map;for(const n of e.slots)for(const r of n.addons)t.set(r.id,r);return t}function mi(e){return{addonId:e.id,addonName:e.name,slot:e.slot,inputClasses:[...e.inputClasses],outputClasses:[...e.outputClasses],enabled:!0,modelId:e.defaultModelId,children:[]}}function gi({addon:e,onClick:t}){return o("button",{type:"button",onClick:t,className:"w-full rounded-lg border border-dashed border-border/60 px-3 py-2.5 text-left transition-all hover:border-primary/30 hover:bg-surface/60 group",children:u("div",{className:"flex items-center gap-3",children:[o(Kk,{className:"h-[18px] w-[18px] text-foreground-subtle/30 group-hover:text-primary/60 shrink-0"}),u("div",{className:"flex-1 min-w-0",children:[o("span",{className:"text-[13px] font-medium text-foreground-subtle/50 group-hover:text-foreground-subtle block truncate",children:e.name}),u("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(n=>o("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&&o("span",{className:"text-foreground-subtle/25 text-[10px]",children:"→"}),e.outputClasses.map(n=>o("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 Oc({schema:e,steps:t,onChange:n,templates:r,selectedTemplateId:s,onSelectTemplate:a,onSaveTemplate:i,onUpdateTemplate:l,onDeleteTemplate:c,readOnly:d=!1,excludeAddons:f=[],hideTemplates:p=!1,showOnlyEnabled:h=!1,showSlotLabels:m=!1,toggleMode:g="simple",overrides:b={},onOverrideChange:x,inheritedEnabledByAddon:y={},hideModelAndSettings:w=!1}){const v=H=>({toggleMode:g,hideModelAndSettings:w,...g==="threeState"?{overrideState:b[H]!==void 0?b[H]:null,onOverrideChange:x?D=>x(H,D):void 0,inheritedEnabled:y[H]}:{}}),N=q(()=>new Set(f),[f]),k=q(()=>_3(e),[e]),[C,E]=P([]),A=s?JSON.stringify(t)!==JSON.stringify(r.find(H=>H.id===s)?.steps):!1;function I(H){const D=H.target.value||null;if(D){const Q=r.find(G=>G.id===D);if(Q){const G=P3(Q.steps,e);E([...G.warnings])}}else E([]);a(D)}function z(){s&&l(s,t)}function $(){const H=window.prompt("Template name:");H?.trim()&&i(H.trim(),t)}function B(){if(!s)return;const H=r.find(D=>D.id===s);H&&window.confirm(`Delete template "${H.name}"?`)&&c(s)}function R(H){n(t.map(D=>D.addonId!==H.addonId?D:M(H)))}function M(H){const D=H.children.some(Q=>Q.enabled||Q.children.some(G=>G.enabled));return{...H,enabled:H.enabled||D,children:H.children.map(Q=>{const G=Q.children.some(ee=>ee.enabled);return{...Q,enabled:Q.enabled||G}})}}function T(H,D){const Q=mi(D);n(t.map(G=>G.addonId!==H?G:{...G,children:[...G.children,Q]}))}function _(H){const D=new Set;for(const Q of H){D.add(Q.addonId);for(const ee of Q.children)D.add(ee.addonId);const G=_(Q.children);for(const ee of G)D.add(ee)}return D}const L=_(t);function O(H){const D=k.get(H.addonId);if(!D)return[];const G=e.slots.find(Z=>Z.id===D.slot)?.parentSlot==null,ee=D.childSlots,se=new Set(H.children.map(Z=>Z.addonId)),te=[];for(const Z of e.slots)if(ee.includes(Z.id))for(const re of Z.addons){if(se.has(re.id)||N.has(re.id))continue;const be=re.inputClasses.length===0;if(be&&!G)continue;(be||re.inputClasses.some(K=>H.outputClasses.includes(K)))&&te.push(re)}return te}function j(H){const D=h?{...H,children:H.children.filter(G=>G.enabled).map(G=>({...G,children:G.children.filter(ee=>ee.enabled)}))}:H,Q=h?[]:O(D);return u("div",{className:"space-y-1.5",children:[o($s,{step:D,schema:k.get(D.addonId)??null,allSchemas:k,onChange:R,onDelete:d?void 0:G=>n(t.filter(ee=>ee.addonId!==G)),readOnly:d,...v(D.addonId)}),(D.children.length>0||Q.length>0)&&u("div",{className:"ml-4 pl-3 border-l border-border/60 space-y-1.5",children:[m&&o("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/40",children:"Slot: Cropper / Classifier"}),D.children.map(G=>{const ee=O(G);return u("div",{className:"space-y-1.5",children:[o($s,{step:G,schema:k.get(G.addonId)??null,allSchemas:k,depth:1,onChange:se=>{R({...D,children:D.children.map(te=>te.addonId===se.addonId?se:te)})},onDelete:d?void 0:se=>{R({...D,children:D.children.filter(te=>te.addonId!==se)})},readOnly:d,...v(G.addonId)}),(G.children.length>0||ee.length>0)&&u("div",{className:"ml-4 pl-3 border-l border-border/40 space-y-1.5",children:[m&&o("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/30",children:"Slot: Recognizer"}),G.children.map(se=>o($s,{step:se,schema:k.get(se.addonId)??null,allSchemas:k,depth:2,onChange:te=>{R({...D,children:D.children.map(Z=>Z.addonId===G.addonId?{...Z,children:Z.children.map(re=>re.addonId===te.addonId?te:re)}:Z)})},onDelete:d?void 0:te=>{R({...D,children:D.children.map(Z=>Z.addonId===G.addonId?{...Z,children:Z.children.filter(re=>re.addonId!==te)}:Z)})},readOnly:d,...v(se.addonId)},se.addonId)),!d&&ee.map(se=>o(gi,{addon:se,onClick:()=>{const te=mi(se);R({...D,children:D.children.map(Z=>Z.addonId===G.addonId?{...Z,children:[...Z.children,te]}:Z)})}},se.id))]})]},G.addonId)}),!d&&Q.map(G=>o(gi,{addon:G,onClick:()=>T(D.addonId,G)},G.id))]})]},D.addonId)}const F=e.slots.filter(H=>H.parentSlot===null).sort((H,D)=>H.priority-D.priority);return u("div",{className:"space-y-4",children:[!p&&o("div",{className:"rounded-lg border border-border bg-surface p-3",children:u("div",{className:"flex items-center gap-2",children:[o("div",{className:"relative flex-1 min-w-0",children:u("select",{value:s??"",onChange:I,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:[o("option",{value:"",children:"No template"}),r.map(H=>o("option",{value:H.id,children:H.name},H.id))]})}),A&&o("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500 shrink-0"}),o("button",{onClick:z,disabled:!s||d,title:"Save",className:W("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:o(J5,{className:"h-4 w-4"})}),o("button",{onClick:$,disabled:d,title:"Save As",className:W("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:o(Jk,{className:"h-4 w-4"})}),o("button",{onClick:B,disabled:!s||d,title:"Delete",className:W("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:o(Kt,{className:"h-4 w-4"})})]})}),C.length>0&&u("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 text-xs text-amber-400 space-y-1",children:[u("div",{className:"flex items-center justify-between",children:[o("span",{className:"font-medium",children:"Template loaded with warnings:"}),o("button",{onClick:()=>E([]),className:"text-amber-400/60 hover:text-amber-400",children:o(Ye,{className:"h-3.5 w-3.5"})})]}),C.map((H,D)=>u("div",{children:["• ",H]},D))]}),F.map(H=>{const D=t.filter(te=>te.slot===H.id&&!N.has(te.addonId)),Q=h?D.filter(te=>te.enabled):D,G=h?[]:H.addons.filter(te=>!L.has(te.id)&&!N.has(te.id)),ee=new Map,se=[];for(const te of Q)te.group?(ee.has(te.group)||ee.set(te.group,[]),ee.get(te.group).push(te)):se.push(te);return u("div",{className:"space-y-2",children:[m&&u("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50",children:["Slot: ",H.label]}),se.map(te=>j(te)),[...ee.entries()].map(([te,Z])=>u("div",{className:"space-y-2 rounded-lg border border-border/40 p-2",children:[o("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50 px-1",children:te}),Z.map(re=>j(re))]},te)),!d&&G.map(te=>o(gi,{addon:te,onClick:()=>{n([...t,mi(te)])}},te.id))]},H.id)})]})}const no={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"},Uu=["#ef4444","#8b5cf6","#06b6d4","#f97316","#10b981","#6366f1","#e11d48","#0891b2","#7c3aed","#059669"],Cg="#f59e42";function dt(e,t){if(t?.[e])return t[e];if(t?.[e.toLowerCase()])return t[e.toLowerCase()];if(no[e])return no[e];if(no[e.toLowerCase()])return no[e.toLowerCase()];let n=0;for(let r=0;r<e.length;r++)n=n*31+(e.codePointAt(r)??0)>>>0;return Uu[n%Uu.length]??Cg}function $3({src:e,imageWidth:t,imageHeight:n,detections:r=[],classColors:s,aspectRatio:a,className:i,placeholder:l,showConfidence:c=!0,minConfidence:d=0,borderWidth:f=2}){function p(y){return dt(y,s)}const h=a??(t&&n?`${t}/${n}`:"16/9"),m=r.filter(y=>y.score>=d),g=m.filter(y=>y.kind==="first-level"),b=m.filter(y=>y.kind==="detail"),x=L3(b,y=>y.parentId??"");return o("div",{className:W("rounded-lg border border-border bg-surface overflow-hidden relative",i),style:{aspectRatio:h},children:e?u(me,{children:[o("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?o(D3,{mask:y.debug.mask,maskWidth:y.debug.maskWidth,maskHeight:y.debug.maskHeight,bbox:y.bbox,imageWidth:t,imageHeight:n,color:p(y.macroClass)},`mask-${w}`):null),g.map(y=>{const w=x.get(y.id)??[];return o(Qu,{detection:y,imageWidth:t,imageHeight:n,color:p(y.macroClass),showConfidence:c,borderWidth:y.debug?.mask?1:f,children:w.map(v=>o(T3,{child:v,parentBbox:y.bbox,color:p(v.macroClass),showConfidence:c},`child-${v.id}`))},`det-${y.id}`)}),b.filter(y=>!y.parentId||!g.some(w=>w.id===y.parentId)).map(y=>o(Qu,{detection:y,imageWidth:t,imageHeight:n,color:p(y.macroClass),showConfidence:c,borderWidth:f},`orphan-${y.id}`))]}):o("div",{className:"w-full h-full flex items-center justify-center text-foreground-subtle text-sm",children:l??"No image loaded"})})}function Qu({detection:e,imageWidth:t,imageHeight:n,color:r,showConfidence:s,borderWidth:a,children:i}){const{x:l,y:c,width:d,height:f}=e.bbox,p=u("div",{className:"absolute left-0 flex flex-col items-start gap-px",style:{bottom:"100%",marginBottom:"2px"},children:[u("span",{className:"text-[10px] px-1 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:r},children:[e.macroClass,s&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((h,m)=>u("span",{className:"text-[9px] font-semibold px-1 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:dt(h.label)},children:[h.label," ",(h.score*100).toFixed(0),"%"]},`${e.id}-lbl-${m}`))]});return u("div",{className:"absolute rounded-sm",style:{left:`${l/t*100}%`,top:`${c/n*100}%`,width:`${d/t*100}%`,height:`${f/n*100}%`,borderWidth:`${a}px`,borderStyle:"solid",borderColor:r},children:[p,i]})}function D3({mask:e,maskWidth:t,maskHeight:n,bbox:r,imageWidth:s,imageHeight:a,color:i}){const l=ne(null);return Y(()=>{const c=l.current;if(!c)return;const d=c.getContext("2d");if(!d)return;const f=atob(e),p=new Uint8Array(f.length);for(let y=0;y<f.length;y++)p[y]=f.charCodeAt(y);const 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<p.length?p[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]),o("canvas",{ref:l,className:"absolute pointer-events-none",style:{left:`${r.x/s*100}%`,top:`${r.y/a*100}%`,width:`${r.width/s*100}%`,height:`${r.height/a*100}%`,imageRendering:"pixelated"}})}function T3({child:e,parentBbox:t,color:n,showConfidence:r}){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 o("div",{className:"absolute rounded-sm",style:{left:`${Math.max(0,s)}%`,top:`${Math.max(0,a)}%`,width:`${Math.min(100,i)}%`,height:`${Math.min(100,l)}%`,borderWidth:"1px",borderStyle:"solid",borderColor:n},children:u("div",{className:"absolute left-0 flex flex-col items-start gap-px",style:{bottom:"100%",marginBottom:"1px"},children:[u("span",{className:"text-[9px] px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:n},children:[e.macroClass,r&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((c,d)=>u("span",{className:"text-[8px] font-semibold px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:dt(c.label)},children:[c.label," ",(c.score*100).toFixed(0),"%"]},`${e.id}-lbl-${d}`))]})})}function L3(e,t){const n=new Map;for(const r of e){const s=t(r),a=n.get(s)??[];a.push(r),n.set(s,a)}return n}function R3({detections:e,classColors:t,className:n,hiddenKeys:r,onToggleVisibility:s}){const a=t;if(e.length===0)return o("div",{className:"text-sm text-foreground-subtle italic text-center py-4",children:"No detections"});const i=e.filter(f=>f.kind==="first-level"),l=e.filter(f=>f.kind==="detail"),c=new Map;for(const f of l){if(!f.parentId)continue;const p=c.get(f.parentId)??[];p.push(f),c.set(f.parentId,p)}const d=l.filter(f=>!f.parentId||!i.some(p=>p.id===f.parentId));return u("div",{className:n,children:[u("div",{className:"text-xs font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:["Detections (",e.length,")"]}),u("div",{className:"space-y-2",children:[i.map(f=>o(Gu,{detection:f,children_:c.get(f.id)??[],colors:a,hiddenKeys:r,onToggleVisibility:s},f.id)),d.map(f=>o(Gu,{detection:f,children_:[],colors:a,hiddenKeys:r,onToggleVisibility:s},f.id))]})]})}function Gu({detection:e,children_:t,colors:n,hiddenKeys:r,onToggleVisibility:s}){const a=dt(e.macroClass,n),i=!r?.has(e.id),l=e.debug?.mask,c=e.debug?.maskWidth,d=e.debug?.maskHeight,f=e.debug?.alternateLabels;return u("div",{className:`rounded-md border border-border bg-surface p-3 space-y-1 ${i?"":"opacity-40"}`,children:[u("div",{className:"flex justify-between items-center",children:[u("div",{className:"flex items-center gap-2",children:[s&&o("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"}),o("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{backgroundColor:a}}),o("span",{className:"text-sm font-medium text-foreground",children:e.macroClass}),e.kind==="detail"&&o("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:"detail"}),l&&c&&d&&u("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",c,"x",d]})]}),o(z3,{confidence:e.score})]}),u("div",{className:"text-[10px] text-foreground-subtle font-mono",children:["bbox: [",Math.round(e.bbox.x),", ",Math.round(e.bbox.y),","," ",Math.round(e.bbox.x+e.bbox.width),","," ",Math.round(e.bbox.y+e.bbox.height),"]"]}),e.labels.length>0&&o("div",{className:"flex flex-wrap gap-1 mt-1",children:e.labels.map((p,h)=>u("span",{className:"inline-flex items-center gap-1 text-[10px] font-medium px-1.5 py-0.5 rounded-full",style:{backgroundColor:dt(p.label,n)+"20",color:dt(p.label,n)},children:[p.label,u("span",{className:"opacity-60",children:[(p.score*100).toFixed(0),"%"]}),p.detectionId&&u("span",{className:"opacity-40 text-[8px]",children:["→ ",p.detectionId]})]},h))}),f&&Object.keys(f).length>0&&o(B3,{alternateLabels:f,colors:n}),t.length>0&&o(O3,{items:t,colors:n,hiddenKeys:r,onToggleVisibility:s})]})}function O3({items:e,colors:t,hiddenKeys:n,onToggleVisibility:r}){return o("div",{className:"ml-4 mt-1.5 space-y-1.5 border-l-2 border-border pl-3",children:e.map(s=>{const a=dt(s.macroClass,t),i=!n?.has(s.id),l=s.debug?.mask,c=s.debug?.maskWidth,d=s.debug?.maskHeight;return u("div",{className:`text-xs space-y-0.5 ${i?"":"opacity-40"}`,children:[u("div",{className:"flex items-center gap-1.5",children:[r&&o("input",{type:"checkbox",checked:i,onChange:()=>r(s.id,!i),className:"h-3 w-3 rounded border-border accent-primary cursor-pointer shrink-0"}),o("span",{className:"h-1.5 w-1.5 rounded-full shrink-0",style:{backgroundColor:a}}),o("span",{className:"font-medium",style:{color:a},children:s.macroClass}),u("span",{className:"text-foreground-subtle",children:[(s.score*100).toFixed(0),"%"]}),l&&c&&d&&u("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",c,"x",d]})]}),s.labels.length>0&&o("div",{className:"flex flex-wrap gap-1 ml-5 mt-0.5",children:s.labels.map((f,p)=>u("span",{className:"inline-flex items-center gap-0.5 text-[9px] font-medium px-1 py-0.5 rounded-full",style:{backgroundColor:dt(f.label,t)+"20",color:dt(f.label,t)},children:[f.label," ",u("span",{className:"opacity-60",children:[(f.score*100).toFixed(0),"%"]})]},p))})]},s.id)})})}function B3({alternateLabels:e,colors:t}){const[n,r]=P(!1),s=Object.keys(e);return u("div",{className:"mt-1",children:[u("button",{onClick:()=>r(a=>!a),className:"text-[9px] text-foreground-subtle hover:text-foreground transition-colors flex items-center gap-1",children:[o("span",{className:`transition-transform ${n?"rotate-90":""}`,children:"▶"}),"Alternates (",s.length," source",s.length!==1?"s":"",")"]}),n&&o("div",{className:"mt-1 ml-3 space-y-1.5",children:s.map(a=>{const i=e[a];return!i||i.length===0?null:u("div",{children:[o("div",{className:"text-[9px] font-medium text-foreground-subtle mb-0.5",children:a}),o("div",{className:"flex flex-wrap gap-1",children:i.map((l,c)=>u("span",{className:"inline-flex items-center gap-0.5 text-[9px] px-1 py-0.5 rounded-full",style:{backgroundColor:dt(a,t)+"10",color:dt(a,t),opacity:Math.max(.4,l.score)},children:[l.label,u("span",{className:"opacity-60",children:[(l.score*100).toFixed(1),"%"]})]},c))})]},a)})})]})}function z3({confidence:e}){const t=e>=.8?"bg-success/10 text-success":e>=.5?"bg-warning/10 text-warning":"bg-danger/10 text-danger";return u("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${t}`,children:[(e*100).toFixed(1),"%"]})}function F3({timings:e,totalMs:t,className:n}){const r=Object.entries(e);return r.length===0&&t===void 0?null:u("div",{className:`rounded-lg border border-border bg-surface p-3 space-y-2 ${n??""}`,children:[o("div",{className:"text-xs font-medium text-foreground-subtle uppercase tracking-wide",children:"Timings"}),u("div",{className:"space-y-1 text-xs",children:[r.map(([s,a])=>u("div",{className:"flex justify-between",children:[o("span",{className:"text-foreground-subtle",children:s}),u("span",{className:"font-mono text-foreground",children:[a.toFixed(1),"ms"]})]},s)),t!==void 0&&u("div",{className:"flex justify-between pt-1 border-t border-border font-medium text-foreground",children:[o("span",{children:"Total"}),u("span",{className:"font-mono",children:[t.toFixed(1),"ms"]})]})]})]})}function j3({images:e,selectedFilename:t,uploadedName:n,onSelect:r,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 f=d.files?.[0];if(!f)return;const p=new FileReader;p.onload=()=>{const h=p.result,m=h.split(",")[1];m&&s(m,f.name,h)},p.readAsDataURL(f)},d.click()};return u("div",{className:`flex flex-wrap items-center gap-2 ${a??""}`,children:[e.map(d=>o("button",{onClick:()=>r(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)),o("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&&o("span",{className:"text-xs text-foreground-subtle",children:n})]})}const os="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 H3({runtime:e,backend:t,modelId:n,agentId:r="hub",runtimes:s,backends:a,models:i,agents:l=[],onRuntimeChange:c,onBackendChange:d,onModelChange:f,onAgentChange:p,layout:h="grid",className:m,showAgent:g=!1}){return u("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&&u("label",{className:"space-y-1",children:[o("span",{className:"text-xs font-medium text-foreground-subtle",children:"Agent"}),o("select",{value:r,onChange:x=>p?.(x.target.value),className:os,children:l.map(x=>u("option",{value:x.id,children:[x.name," (",x.status,")"]},x.id))})]}),u("label",{className:"space-y-1",children:[o("span",{className:"text-xs font-medium text-foreground-subtle",children:"Runtime"}),o("select",{value:e,onChange:x=>c(x.target.value),className:os,children:s.map(x=>u("option",{value:x.value,disabled:!x.available,children:[x.label,x.available?"":" (unavailable)"]},x.value))})]}),u("label",{className:"space-y-1",children:[o("span",{className:"text-xs font-medium text-foreground-subtle",children:"Backend"}),o("select",{value:t,onChange:x=>d(x.target.value),className:os,children:a.map(x=>u("option",{value:x.id,disabled:!x.available,children:[x.label,x.available?"":" (unavailable)"]},x.id))})]}),u("label",{className:"space-y-1",children:[o("span",{className:"text-xs font-medium text-foreground-subtle",children:"Model"}),o("select",{value:n,onChange:x=>f(x.target.value),className:os,children:i.length===0?o("option",{value:"",children:"No compatible models"}):i.map(x=>u("option",{value:x.id,children:[x.name,x.downloaded?" ✓":""]},x.id))})]})]})}function V3({className:e}){return u("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[o("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"}),o("circle",{cx:"12",cy:"12",r:"3"})]})}function q3({className:e}){return u("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[o("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"}),o("path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}),o("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"}),o("path",{d:"m2 2 20 20"})]})}function U3({className:e}){return o("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:o("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function Mg({onLogin:e,serverUrl:t,logoSrc:n,error:r,className:s}){const[a,i]=P(""),[l,c]=P(""),[d,f]=P(!1),[p,h]=P(!1),[m,g]=P(null),b=r??m,x=async y=>{if(y.preventDefault(),!p){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 o("div",{className:W("flex min-h-screen items-center justify-center bg-background p-4",s),children:u("div",{className:"w-full max-w-sm",children:[n&&o("div",{className:"flex justify-center mb-8",children:o("img",{src:n,alt:"Logo",className:"h-12"})}),t&&o("p",{className:"mb-4 text-center text-xs text-foreground-subtle truncate",children:t}),u("form",{onSubmit:x,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[b&&o("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:b}),u("div",{className:"space-y-1.5",children:[o("label",{className:"text-xs font-medium text-foreground-subtle",children:"Username"}),o("input",{type:"text",value:a,onChange:y=>i(y.target.value),autoComplete:"username",required:!0,className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary"})]}),u("div",{className:"space-y-1.5",children:[o("label",{className:"text-xs font-medium text-foreground-subtle",children:"Password"}),u("div",{className:"relative",children:[o("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"}),o("button",{type:"button",onClick:()=>f(y=>!y),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",tabIndex:-1,children:d?o(q3,{className:"h-4 w-4"}):o(V3,{className:"h-4 w-4"})})]})]}),u("button",{type:"submit",disabled:p,className:"w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center justify-center gap-2",children:[p&&o(U3,{className:"h-4 w-4 animate-spin"}),p?"Logging in...":"Log in"]})]})]})})}const Nl="camstack_dev_token",Eg=Be(null);function Q3(){const e=ve(Eg);if(!e)throw new Error("useDevShell must be used within a DevShell");return e}function G3(){return typeof window>"u"?null:localStorage.getItem(Nl)}function K3({className:e}){return u("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[o("circle",{cx:"12",cy:"12",r:"4"}),o("path",{d:"M12 2v2"}),o("path",{d:"M12 20v2"}),o("path",{d:"m4.93 4.93 1.41 1.41"}),o("path",{d:"m17.66 17.66 1.41 1.41"}),o("path",{d:"M2 12h2"}),o("path",{d:"M20 12h2"}),o("path",{d:"m6.34 17.66-1.41 1.41"}),o("path",{d:"m19.07 4.93-1.41 1.41"})]})}function W3({className:e}){return o("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:o("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})})}function Y3({children:e,serverUrl:t,title:n,token:r,onLogout:s}){const a=Or(),i=q(()=>{const h=t.replace(/^http/,"ws")+"/trpc",m=NN({url:h,connectionParams:()=>({token:r})});return[kN({condition:g=>g.type==="subscription",true:SN({client:m,transformer:dl}),false:$h({url:`${t}/trpc`,transformer:dl,headers:()=>({authorization:`Bearer ${r}`})})})]},[t,r]),l=q(()=>_h({links:i}),[i]),c=q(()=>S.createClient({links:i}),[i]),d=q(()=>Th({serverUrl:t,token:r}),[t,r]);Y(()=>(d.init().catch(()=>{}),()=>{d.close()}),[d]);const f=q(()=>new Ih,[]),p=q(()=>({trpc:l,token:r,logout:s}),[l,r,s]);return o(_c,{system:d,children:o(S.Provider,{client:c,queryClient:f,children:o(Ah,{client:f,children:o(Eg.Provider,{value:p,children:u("div",{className:"min-h-screen bg-background text-foreground",children:[u("div",{className:"flex items-center justify-between border-b border-border bg-surface px-4 py-2",children:[u("div",{className:"flex items-center gap-2",children:[o("span",{className:"rounded bg-warning/20 px-2 py-0.5 text-xs font-bold text-warning",children:"DEV MODE"}),n&&o("span",{className:"text-sm font-medium text-foreground",children:n}),o("span",{className:"text-xs text-foreground-subtle",children:t})]}),u("div",{className:"flex items-center gap-2",children:[u("button",{type:"button",onClick:a.toggleMode,className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",title:`Theme: ${a.mode}`,children:[a.resolvedMode==="dark"?o(K3,{className:"h-3.5 w-3.5"}):o(W3,{className:"h-3.5 w-3.5"}),a.mode==="dark"?"Dark":a.mode==="light"?"Light":"System"]}),o("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"})]})]}),o("div",{className:"p-4",children:e({trpc:l,theme:a})})]})})})})})}function Ig({children:e,serverUrl:t="https://localhost:4443",title:n}){const[r,s]=P(G3),a=U(async(l,c)=>{const p=await _h({links:[$h({url:`${t}/trpc`,transformer:dl})]}).auth.login.mutate({username:l,password:c});if(!p.token)throw new Error("No token returned");localStorage.setItem(Nl,p.token),s(p.token)},[t]),i=U(()=>{localStorage.removeItem(Nl),s(null)},[]);return r?o(Vs,{children:o(Y3,{serverUrl:t,title:n,token:r,onLogout:i,children:e})}):o(Vs,{children:o(Mg,{onLogin:a,serverUrl:t})})}function Z3(e,t={}){const{serverUrl:n="https://localhost:4443",title:r,rootId:s="root"}=t,a=document.getElementById(s);if(!a){console.error(`[mountAddonPage] Element #${s} not found`);return}Mh(a).render(Me(Ig,{serverUrl:n,title:r,children:({trpc:i,theme:l})=>Me(e,{trpc:i,theme:{isDark:l.resolvedMode==="dark"},navigate:c=>{console.log("[dev] navigate:",c)}})}))}const Ag=fn("camstack:custom-field-renderers",{});function Pg({renderers:e,children:t}){return o(Ag.Provider,{value:e,children:t})}function _g(e){return ve(Ag)[e]??null}const Bc=fn("camstack:device-context",null);function $g({deviceId:e,device:t,children:n}){const r={deviceId:e,device:t??null};return o(Bc.Provider,{value:r,children:n})}function hn(){return ve(Bc)?.deviceId??null}function zc(){return ve(Bc)?.device??null}const X3=S.accessories.getStatus.useQuery,Sa=S.addonPages.listPages.useQuery,Fo=S.addons.list.useQuery,J3=S.addons.getLogs.useQuery,eM=S.addons.listPackages.useQuery,Fc=S.addons.installPackage.useMutation,tM=S.addons.installFromWorkspace.useMutation,nM=S.addons.isWorkspaceAvailable.useQuery,rM=S.addons.listWorkspacePackages.useQuery,Dg=S.addons.uninstallPackage.useMutation,Tg=S.addons.reloadPackages.useMutation,Lg=S.addons.searchAvailable.useQuery,jc=S.addons.listUpdates.useQuery,kl=S.addons.updatePackage.useMutation,oM=S.addons.rollbackPackage.useMutation,Rg=S.addons.forceRefresh.useMutation,Og=S.addons.restartServer.useMutation,Bg=S.addons.getVersions.useQuery,Ca=S.addons.restartAddon.useMutation,zg=S.addons.retryLoad.useMutation,Fg=S.addons.getAutoUpdateSettings.useQuery,sM=S.addons.setAutoUpdateSettings.useMutation,jg=S.addons.getAddonAutoUpdate.useQuery,Hg=S.addons.setAddonAutoUpdate.useMutation,Vg=S.addons.applyAutoUpdateToAll.useMutation,aM=S.addons.custom.useMutation,iM=S.addons.onAddonLogs.useSubscription,Hc=S.addonSettings.getGlobalSettings.useQuery,qg=S.addonSettings.updateGlobalSettings.useMutation,lM=S.addonSettings.getDeviceSettings.useQuery,Ug=S.addonSettings.updateDeviceSettings.useMutation,Qg=S.addonWidgets.listWidgets.useQuery,cM=S.alerts.emit.useMutation,dM=S.alerts.update.useMutation,Gg=S.alerts.list.useQuery,Kg=S.alerts.getUnreadCount.useQuery,Wg=S.alerts.markRead.useMutation,Yg=S.alerts.markAllRead.useMutation,Zg=S.alerts.dismiss.useMutation,uM=S.audioAnalysis.resolveDeviceSettings.useQuery,pM=S.audioAnalysis.getDeviceSettingsContribution.useQuery,fM=S.audioAnalysis.getDeviceLiveContribution.useQuery,hM=S.audioAnalysis.applyDeviceSettingsPatch.useMutation,mM=S.audioAnalyzer.analyseChunk.useMutation,gM=S.audioAnalyzer.classify.useQuery,bM=S.audioAnalyzer.isReady.useQuery,xM=S.audioAnalyzer.dispose.useMutation,Xg=S.audioAnalyzer.reprobeAudioEngine.useMutation,yM=S.audioCodec.listSupportedCodecs.useQuery,vM=S.audioCodec.canHandle.useQuery,wM=S.audioCodec.createDecodeSession.useMutation,NM=S.audioCodec.createEncodeSession.useMutation,kM=S.audioCodec.closeSession.useMutation,SM=S.audioCodec.pushEncodedFrame.useMutation,CM=S.audioCodec.pullPcm.useQuery,MM=S.audioCodec.pushPcm.useMutation,EM=S.audioCodec.pullEncoded.useQuery,IM=S.audioCodec.flushEncode.useMutation,AM=S.audioCodec.listActiveSessions.useQuery,PM=S.audioMetrics.getCurrentSnapshot.useQuery,_M=S.audioMetrics.getHistory.useQuery,Vc=S.authentication.listProviders.useQuery,$M=S.authentication.setProviderEnabled.useMutation,qc=S.backup.listDestinations.useQuery,Jg=S.backup.trigger.useMutation,DM=S.backup.list.useQuery,eb=S.backup.listLocations.useQuery,tb=S.backup.getEntries.useQuery,nb=S.backup.restore.useMutation,rb=S.backup.delete.useMutation,Uc=S.backup.listArchives.useQuery,ob=S.backup.upsertDestinationPolicy.useMutation,sb=S.backup.previewSchedule.useQuery,TM=S.battery.getStatus.useQuery,LM=S.brightness.setBrightness.useMutation,RM=S.brightness.getStatus.useQuery,OM=S.cameraCredentials.getCredentials.useQuery,BM=S.cameraCredentials.getStatus.useQuery,zM=S.cameraStreams.getCameraStreams.useQuery,FM=S.cameraStreams.getBrokerStreams.useQuery,ab=S.cameraStreams.getRtspEntries.useQuery,jM=S.decoder.supportsCodec.useQuery,HM=S.decoder.getInfo.useQuery,VM=S.decoder.createSession.useQuery,qM=S.decoder.destroySession.useQuery,UM=S.decoder.pushPacket.useQuery,QM=S.decoder.openStream.useQuery,GM=S.decoder.pullFrames.useQuery,KM=S.decoder.updateConfig.useQuery,WM=S.decoder.getStats.useQuery,YM=S.decoder.listActiveSessions.useQuery,ib=S.decoder.reprobeHwaccel.useMutation,ZM=S.detectionPipeline.getDeviceSettingsContribution.useQuery,XM=S.detectionPipeline.getDeviceLiveContribution.useQuery,JM=S.detectionPipeline.applyDeviceSettingsPatch.useMutation,lb=S.deviceDiscovery.listDiscovered.useQuery,cb=S.deviceDiscovery.refreshDiscovery.useMutation,e4=S.deviceDiscovery.adoptDevice.useMutation,t4=S.deviceDiscovery.releaseDevice.useMutation,n4=S.deviceDiscovery.getStatus.useQuery,db=S.deviceExport.getStatus.useQuery,r4=S.deviceExport.listSupportedDeviceKinds.useQuery,o4=S.deviceExport.listExposedDevices.useQuery,s4=S.deviceExport.exposeDevice.useMutation,a4=S.deviceExport.unexposeDevice.useMutation,i4=S.deviceExport.getDeviceSettingsContribution.useQuery,l4=S.deviceExport.getDeviceLiveContribution.useQuery,c4=S.deviceExport.applyDeviceSettingsPatch.useMutation,d4=S.deviceManager.allocateDeviceId.useMutation,u4=S.deviceManager.registerDevice.useMutation,p4=S.deviceManager.removeDevice.useMutation,f4=S.deviceManager.persistConfig.useMutation,h4=S.deviceManager.loadConfig.useQuery,m4=S.deviceManager.loadRuntimeState.useQuery,g4=S.deviceManager.loadMeta.useQuery,ub=S.deviceManager.setName.useMutation,pb=S.deviceManager.setLocation.useMutation,b4=S.deviceManager.setMetadata.useMutation,fb=S.deviceManager.listLocations.useQuery,x4=S.deviceManager.addLocation.useMutation,y4=S.deviceManager.removeLocation.useMutation,v4=S.deviceManager.setDisabled.useMutation,w4=S.deviceManager.listPersistedByAddon.useQuery,$n=S.deviceManager.listAll.useQuery,Gn=S.deviceManager.getDevice.useQuery,hb=S.deviceManager.getChildren.useQuery,N4=S.deviceManager.getStreamSources.useQuery,k4=S.deviceManager.getConfigSchema.useQuery,S4=S.deviceManager.getSettingsSchema.useQuery,C4=S.deviceManager.updateConfig.useMutation,mb=S.deviceManager.enable.useMutation,gb=S.deviceManager.disable.useMutation,bb=S.deviceManager.remove.useMutation,M4=S.deviceManager.getStreamProfileMap.useQuery,E4=S.deviceManager.setStreamProfileMap.useMutation,I4=S.deviceManager.probeStreams.useMutation,xb=S.deviceManager.getBindings.useQuery,A4=S.deviceManager.getAllBindings.useQuery,yb=S.deviceManager.setWrapperActive.useMutation,P4=S.deviceManager.listWrappersForCap.useQuery,vb=S.deviceManager.listBindableCapsForDeviceType.useQuery,_4=S.deviceManager.getDeviceSettingsAggregate.useQuery,$4=S.deviceManager.getDeviceLiveInfoAggregate.useQuery,Qc=S.deviceManager.getDeviceAggregate.useQuery,D4=S.deviceManager.updateDeviceField.useMutation,wb=S.deviceManager.updateDeviceFieldsBatch.useMutation,Gc=S.deviceManager.discoverDevices.useMutation,Nb=S.deviceManager.adoptDevice.useMutation,kb=S.deviceManager.getCreationSchema.useQuery,Sb=S.deviceManager.createDevice.useMutation,Kc=S.deviceManager.testCreationField.useMutation,T4=S.deviceManager.testField.useMutation,L4=S.deviceManager.getDeviceStatusAggregate.useQuery,R4=S.deviceOps.getStreamSources.useQuery,O4=S.deviceOps.getConfigEntries.useQuery,B4=S.deviceOps.setConfig.useMutation,z4=S.deviceOps.removeDevice.useMutation,F4=S.deviceOps.getSettingsSchema.useQuery,j4=S.deviceProvider.start.useMutation,H4=S.deviceProvider.stop.useMutation,V4=S.deviceProvider.getStatus.useQuery,q4=S.deviceProvider.getDevices.useQuery,U4=S.deviceProvider.supportsDiscovery.useQuery,Q4=S.deviceProvider.discoverDevices.useMutation,G4=S.deviceProvider.adoptDiscoveredDevice.useMutation,K4=S.deviceProvider.supportsManualCreation.useQuery,W4=S.deviceProvider.getChildCreationSchema.useQuery,Y4=S.deviceProvider.createDevice.useMutation,Z4=S.deviceProvider.testCreationField.useMutation,X4=S.deviceState.getSnapshot.useQuery,J4=S.deviceState.getCapSlice.useQuery,eE=S.deviceState.getAllSnapshots.useQuery,tE=S.deviceState.setCapSlice.useMutation,nE=S.deviceStatus.getStatus.useQuery,rE=S.doorbell.getStatus.useQuery,oE=S.events.getEvents.useQuery,sE=S.events.getEventThumbnail.useQuery,aE=S.events.getEventClipUrl.useQuery,iE=S.featureProbe.getStatus.useQuery,Wc=S.integrations.list.useQuery,Cb=S.integrations.get.useQuery,Mb=S.integrations.getByAddonId.useQuery,Eb=S.integrations.create.useMutation,Ib=S.integrations.update.useMutation,Ab=S.integrations.delete.useMutation,lE=S.integrations.getSettings.useQuery,cE=S.integrations.setSettings.useMutation,Pb=S.integrations.getAvailableTypes.useQuery,_b=S.integrations.testConnection.useMutation,$b=S.intercom.startSession.useMutation,Db=S.intercom.handleAnswer.useMutation,Tb=S.intercom.stopSession.useMutation,dE=S.intercom.startTalkSession.useMutation,uE=S.intercom.pushTalkPcm.useMutation,pE=S.intercom.endTalkSession.useMutation,fE=S.intercom.getStatus.useQuery,Lb=S.localNetwork.list.useQuery,hE=S.localNetwork.getPreferred.useQuery,Rb=S.localNetwork.getConnectionEndpoints.useQuery,Ob=S.localNetwork.getAllowedAddresses.useQuery,Bb=S.localNetwork.setAllowedAddresses.useMutation,zb=S.localNetwork.resetAllowlistToBestMatch.useMutation,mE=S.meshNetwork.getStatus.useQuery,gE=S.meshNetwork.join.useMutation,bE=S.meshNetwork.startLogin.useMutation,xE=S.meshNetwork.leave.useMutation,yE=S.meshNetwork.listPeers.useQuery,vE=S.meshNetwork.testConnection.useMutation,Fb=S.meshOrchestrator.listProviders.useQuery,jb=S.meshOrchestrator.joinProvider.useMutation,Hb=S.meshOrchestrator.leaveProvider.useMutation,wE=S.metricsProvider.collectSnapshot.useQuery,NE=S.metricsProvider.getCached.useQuery,kE=S.metricsProvider.getCurrent.useQuery,SE=S.metricsProvider.getDiskSpace.useQuery,CE=S.metricsProvider.getGpuInfo.useQuery,ME=S.metricsProvider.getCpuTemperature.useQuery,EE=S.metricsProvider.getProcessStats.useQuery,IE=S.metricsProvider.listAddonInstances.useQuery,AE=S.metricsProvider.getAddonStats.useQuery,Vb=S.metricsProvider.listNodeProcesses.useQuery,qb=S.metricsProvider.killProcess.useMutation,PE=S.motion.isDetected.useQuery,_E=S.motion.getStatus.useQuery,$E=S.motionDetection.analyze.useMutation,DE=S.motionDetection.removeCamera.useMutation,TE=S.motionDetection.reset.useMutation,LE=S.motionDetection.getDeviceSettingsContribution.useQuery,RE=S.motionDetection.getDeviceLiveContribution.useQuery,OE=S.motionDetection.applyDeviceSettingsPatch.useMutation,BE=S.motionTrigger.setMotionTrigger.useMutation,zE=S.motionTrigger.getStatus.useQuery,FE=S.mqttBroker.listBrokers.useQuery,jE=S.mqttBroker.getBrokerConfig.useQuery,HE=S.mqttBroker.addBroker.useMutation,VE=S.mqttBroker.removeBroker.useMutation,qE=S.mqttBroker.testConnection.useMutation,UE=S.mqttBroker.startEmbeddedBroker.useMutation,QE=S.mqttBroker.stopEmbeddedBroker.useMutation,Ub=S.mqttBroker.getStatus.useQuery,GE=S.nativeObjectDetection.getStatus.useQuery,Yc=S.networkQuality.getDeviceStats.useQuery,KE=S.networkQuality.getAllStats.useQuery,WE=S.networkQuality.reportClientStats.useMutation,Dn=S.nodes.topology.useQuery,YE=S.nodes.deployAddon.useMutation,Qb=S.nodes.undeployAddon.useMutation,Ma=S.nodes.restartAddon.useMutation,Gb=S.nodes.restartProcess.useMutation,Kb=S.nodes.restartNode.useMutation,ZE=S.nodes.shutdownNode.useMutation,Wb=S.nodes.renameNode.useMutation,Yb=S.nodes.clusterAddonStatus.useQuery,Zb=S.nodes.setProcessLogLevel.useMutation,XE=S.nodes.executeQuery.useMutation,JE=S.notificationOutput.send.useMutation,eI=S.notificationOutput.sendTest.useMutation,tI=S.osd.setOverlay.useMutation,nI=S.osd.getStatus.useQuery,rI=S.pipelineAnalytics.getActiveTracks.useQuery,oI=S.pipelineAnalytics.getTrack.useQuery,sI=S.pipelineAnalytics.listTracks.useQuery,aI=S.pipelineAnalytics.clearTracks.useMutation,iI=S.pipelineAnalytics.getMotionEvents.useQuery,lI=S.pipelineAnalytics.getObjectEvents.useQuery,cI=S.pipelineAnalytics.getAudioEvents.useQuery,dI=S.pipelineAnalytics.getEventMedia.useQuery,uI=S.pipelineAnalytics.getTrackMedia.useQuery,pI=S.pipelineAnalytics.getDeviceSettingsContribution.useQuery,fI=S.pipelineAnalytics.getDeviceLiveContribution.useQuery,hI=S.pipelineAnalytics.applyDeviceSettingsPatch.useMutation,Xb=S.pipelineExecutor.getAvailableEngines.useQuery,Jb=S.pipelineExecutor.getSelectedEngine.useQuery,mI=S.pipelineExecutor.getDefaultSteps.useQuery,ex=S.pipelineExecutor.reprobeEngine.useMutation,gI=S.pipelineExecutor.getVideoPipelineSteps.useQuery,bI=S.pipelineExecutor.setVideoPipelineSteps.useMutation,jo=S.pipelineExecutor.getSchema.useQuery,xI=S.pipelineExecutor.getGlobalSteps.useQuery,yI=S.pipelineExecutor.getGlobalPipelineConfig.useQuery,vI=S.pipelineExecutor.getOrchestratorConfigSchema.useQuery,wI=S.pipelineExecutor.listTemplates.useQuery,NI=S.pipelineExecutor.saveTemplate.useMutation,kI=S.pipelineExecutor.updateTemplate.useMutation,SI=S.pipelineExecutor.deleteTemplate.useMutation,CI=S.pipelineExecutor.getCapabilities.useQuery,MI=S.pipelineExecutor.getAddonModels.useQuery,tx=S.pipelineExecutor.downloadModel.useMutation,nx=S.pipelineExecutor.deleteModel.useMutation,EI=S.pipelineExecutor.detect.useQuery,II=S.pipelineExecutor.runPipeline.useMutation,AI=S.pipelineExecutor.runPipelineBatch.useMutation,PI=S.pipelineExecutor.cacheFrameInPool.useMutation,_I=S.pipelineExecutor.inferCached.useMutation,$I=S.pipelineExecutor.uncacheFrame.useMutation,DI=S.pipelineExecutor.getEffectiveTuning.useQuery,rx=S.pipelineExecutor.listLoadedEngines.useQuery,TI=S.pipelineExecutor.spinEngine.useMutation,ox=S.pipelineExecutor.killEngine.useMutation,LI=S.pipelineExecutor.listReferenceImages.useQuery,RI=S.pipelineExecutor.getReferenceImage.useQuery,OI=S.pipelineExecutor.getReferenceAudioFiles.useQuery,BI=S.pipelineExecutor.getReferenceAudio.useQuery,zI=S.pipelineExecutor.getAudioCapabilities.useQuery,FI=S.pipelineExecutor.runAudioTest.useMutation,jI=S.pipelineExecutor.getDetectionConfigSchema.useQuery,sx=S.pipelineOrchestrator.assignPipeline.useMutation,ax=S.pipelineOrchestrator.unassignPipeline.useMutation,ix=S.pipelineOrchestrator.rebalance.useMutation,Ea=S.pipelineOrchestrator.getPipelineAssignments.useQuery,Ia=S.pipelineOrchestrator.getPipelineAssignment.useQuery,lx=S.pipelineOrchestrator.getAgentLoad.useQuery,HI=S.pipelineOrchestrator.getGlobalMetrics.useQuery,VI=S.pipelineOrchestrator.getCameraMetrics.useQuery,cx=S.pipelineOrchestrator.getCapabilityBindings.useQuery,dx=S.pipelineOrchestrator.setCapabilityBinding.useMutation,ux=S.pipelineOrchestrator.assignDecoder.useMutation,px=S.pipelineOrchestrator.unassignDecoder.useMutation,fx=S.pipelineOrchestrator.getDecoderAssignments.useQuery,hx=S.pipelineOrchestrator.assignAudio.useMutation,mx=S.pipelineOrchestrator.unassignAudio.useMutation,qI=S.pipelineOrchestrator.getAudioAssignment.useQuery,gx=S.pipelineOrchestrator.getAudioNodeLoad.useQuery,bx=S.pipelineOrchestrator.getAudioAssignments.useQuery,UI=S.pipelineOrchestrator.getDecoderAssignment.useQuery,Zc=S.pipelineOrchestrator.getAgentSettings.useQuery,jr=S.pipelineOrchestrator.listAgentSettings.useQuery,Xc=S.pipelineOrchestrator.setAgentAddonDefaults.useMutation,xx=S.pipelineOrchestrator.removeAgentSettings.useMutation,Jc=S.pipelineOrchestrator.getCameraSettings.useQuery,yx=S.pipelineOrchestrator.setCameraStepToggle.useMutation,QI=S.pipelineOrchestrator.getCameraStepOverrides.useQuery,vx=S.pipelineOrchestrator.setCameraStepOverride.useMutation,wx=S.pipelineOrchestrator.setCameraPipelineForAgent.useMutation,Nx=S.pipelineOrchestrator.resolvePipeline.useQuery,kx=S.pipelineOrchestrator.listTemplates.useQuery,GI=S.pipelineOrchestrator.saveTemplate.useMutation,Sx=S.pipelineOrchestrator.updateTemplate.useMutation,Cx=S.pipelineOrchestrator.deleteTemplate.useMutation,KI=S.pipelineOrchestrator.getDeviceSettingsContribution.useQuery,WI=S.pipelineOrchestrator.getDeviceLiveContribution.useQuery,YI=S.pipelineOrchestrator.applyDeviceSettingsPatch.useMutation,ZI=S.pipelineRunner.attachCamera.useMutation,XI=S.pipelineRunner.detachCamera.useMutation,JI=S.pipelineRunner.reportMotion.useMutation,eA=S.pipelineRunner.getLocalLoad.useQuery,tA=S.pipelineRunner.getLocalMetrics.useQuery,ed=S.pipelineRunner.getCameraMetrics.useQuery,nA=S.pipelineRunner.getAllCameraMetrics.useQuery,Mx=S.pipelineRunner.getLocalCameras.useQuery,rA=S.platformProbe.getCapabilities.useQuery,oA=S.platformProbe.getHardware.useQuery,sA=S.platformProbe.resolveInferenceConfig.useQuery,aA=S.platformProbe.resolveHwAccel.useQuery,iA=S.platformProbe.getHardwareEncoders.useQuery,lA=S.platformProbe.refreshHardwareEncoders.useMutation,cA=S.ptz.move.useMutation,dA=S.ptz.continuousMove.useMutation,uA=S.ptz.stop.useMutation,pA=S.ptz.getPresets.useQuery,fA=S.ptz.goToPreset.useMutation,hA=S.ptz.goHome.useMutation,mA=S.ptz.getPosition.useQuery,gA=S.ptz.getStatus.useQuery,Ex=S.ptzAutotrack.getStatus.useQuery,Ix=S.ptzAutotrack.setEnabled.useMutation,bA=S.ptzAutotrack.getSettings.useQuery,Ax=S.ptzAutotrack.setSettings.useMutation,Px=S.reboot.reboot.useMutation,xA=S.recording.getSegments.useQuery,yA=S.recording.getPlaybackUrl.useQuery,vA=S.recording.getThumbnailAt.useQuery,wA=S.recordingEngine.getStatus.useQuery,_x=S.recordingEngine.enable.useMutation,$x=S.recordingEngine.disable.useMutation,Dx=S.recordingEngine.getConfig.useQuery,NA=S.recordingEngine.updateConfig.useMutation,kA=S.recordingEngine.getPlaylist.useQuery,SA=S.recordingEngine.getThumbnail.useQuery,Tx=S.recordingEngine.getSegments.useQuery,CA=S.recordingEngine.getAvailability.useQuery,MA=S.recordingEngine.estimateStorage.useQuery,EA=S.recordingEngine.estimateGlobalStorage.useQuery,Lx=S.recordingEngine.getStorageUsage.useQuery,IA=S.recordingEngine.setPolicy.useMutation,AA=S.recordingEngine.getPolicy.useQuery,Rx=S.recordingEngine.getPolicyStatus.useQuery,Ox=S.recordingEngine.getRetentionConfig.useQuery,PA=S.recordingEngine.updateRetentionConfig.useMutation,_A=S.recordingEngine.getMotionStats.useQuery,Bx=S.remoteAccess.listProviders.useQuery,zx=S.remoteAccess.startProvider.useMutation,Fx=S.remoteAccess.stopProvider.useMutation,$A=S.settingsStore.get.useQuery,DA=S.settingsStore.set.useMutation,TA=S.settingsStore.query.useQuery,LA=S.settingsStore.insert.useMutation,RA=S.settingsStore.update.useMutation,OA=S.settingsStore.delete.useMutation,BA=S.settingsStore.count.useQuery,zA=S.settingsStore.isEmpty.useQuery,FA=S.settingsStore.declareCollection.useMutation,jA=S.snapshot.getSnapshot.useQuery,HA=S.snapshot.invalidateCache.useMutation,VA=S.snapshot.getStatus.useQuery,qA=S.snapshot.getDeviceSettingsContribution.useQuery,UA=S.snapshot.getDeviceLiveContribution.useQuery,QA=S.snapshot.applyDeviceSettingsPatch.useMutation,GA=S.snapshotProvider.supportsDevice.useQuery,KA=S.snapshotProvider.getSnapshot.useQuery,WA=S.storage.resolve.useQuery,YA=S.storage.write.useMutation,ZA=S.storage.read.useQuery,XA=S.storage.exists.useQuery,JA=S.storage.list.useQuery,eP=S.storage.delete.useMutation,tP=S.storage.getAvailableSpace.useQuery,nP=S.storage.beginUpload.useMutation,rP=S.storage.writeChunk.useMutation,oP=S.storage.finalizeUpload.useMutation,sP=S.storage.abortUpload.useMutation,aP=S.storage.beginDownload.useMutation,iP=S.storage.readChunk.useQuery,lP=S.storage.endDownload.useMutation,jx=S.storage.listLocations.useQuery,cP=S.storage.getDefaultLocation.useQuery,Aa=S.storage.upsertLocation.useMutation,Hx=S.storage.deleteLocation.useMutation,dP=S.storage.testLocation.useQuery,td=S.storage.listProviders.useQuery,uP=S.storage.testConfig.useQuery,pP=S.streamBroker.publishCameraStream.useMutation,fP=S.streamBroker.retractCameraStream.useMutation,hP=S.streamBroker.assignProfile.useMutation,mP=S.streamBroker.unassignProfile.useMutation,gP=S.streamBroker.listAllCameraStreams.useQuery,bP=S.streamBroker.listAllProfileSlots.useQuery,xP=S.streamBroker.getBrokerStats.useQuery,yP=S.streamBroker.listClients.useQuery,vP=S.streamBroker.killClient.useMutation,wP=S.streamBroker.restartProfile.useMutation,NP=S.streamBroker.getStreamUrl.useQuery,kP=S.streamBroker.getStreamWithCodec.useMutation,SP=S.streamBroker.releaseStreamWithCodec.useMutation,CP=S.streamBroker.getBroker.useQuery,MP=S.streamBroker.setPreBufferDuration.useMutation,EP=S.streamBroker.getPreBufferInfo.useQuery,IP=S.streamBroker.getRtspPort.useQuery,AP=S.streamBroker.getAllRtspEntries.useQuery,PP=S.streamBroker.getRtspEntry.useQuery,Vx=S.streamBroker.regenerateRtspToken.useMutation,_P=S.streamBroker.setRtspEnabled.useMutation,$P=S.streamBroker.isRtspEnabled.useQuery,DP=S.streamBroker.getDeviceSettingsContribution.useQuery,TP=S.streamBroker.getDeviceLiveContribution.useQuery,LP=S.streamBroker.applyDeviceSettingsPatch.useMutation,RP=S.switch.setState.useMutation,OP=S.switch.getStatus.useQuery,BP=S.system.info.useQuery,zP=S.system.health.useQuery,FP=S.system.featureFlags.useQuery,jP=S.system.networkAddresses.useQuery,HP=S.system.getRetentionConfig.useQuery,VP=S.system.setRetentionConfig.useMutation,qP=S.system.forceRetentionCleanup.useMutation,qx=S.toast.onToast.useSubscription,Ux=S.turnOrchestrator.listProviders.useQuery,Qx=S.turnOrchestrator.getAllServers.useQuery,Gx=S.turnOrchestrator.setProviderEnabled.useMutation,UP=S.turnProvider.getTurnServers.useQuery,nd=S.userManagement.listUsers.useQuery,Kx=S.userManagement.createUser.useMutation,Wx=S.userManagement.updateUser.useMutation,Yx=S.userManagement.deleteUser.useMutation,rd=S.userManagement.resetPassword.useMutation,Zx=S.userManagement.setUserScopes.useMutation,QP=S.userManagement.validateCredentials.useMutation,Xx=S.userManagement.listApiKeys.useQuery,GP=S.userManagement.createApiKey.useMutation,Jx=S.userManagement.revokeApiKey.useMutation,KP=S.userManagement.validateApiKey.useMutation,ey=S.userManagement.createScopedToken.useMutation,ty=S.userManagement.revokeScopedToken.useMutation,WP=S.userManagement.validateScopedToken.useQuery,ny=S.userManagement.listScopedTokens.useQuery,ry=S.userManagement.setupTotp.useMutation,oy=S.userManagement.confirmTotp.useMutation,sy=S.userManagement.disableTotp.useMutation,ay=S.userManagement.getTotpStatus.useQuery,YP=S.userManagement.verifyTotp.useMutation,ZP=S.webrtcSession.listStreams.useQuery,XP=S.webrtcSession.createSession.useMutation,JP=S.webrtcSession.handleOffer.useMutation,e_=S.webrtcSession.handleAnswer.useMutation,t_=S.webrtcSession.closeSession.useMutation,n_=S.webrtcSession.hasAdaptiveBitrate.useQuery,r_=S.zoneAnalytics.getCurrentSnapshot.useQuery,o_=S.zoneAnalytics.getZoneHistory.useQuery,s_=S.zoneAnalytics.getCameraHistory.useQuery,a_=S.zoneAnalytics.getUnzonedHistory.useQuery,i_=S.zoneRules.listRules.useQuery,l_=S.zoneRules.setRules.useMutation,c_=S.zones.listZones.useQuery,d_=S.zones.addZone.useMutation,u_=S.zones.removeZone.useMutation,p_=S.zones.updateZone.useMutation,iy=fn("camstack:widget-registry",null),Gs=new Map,ss=new Map,Ku=new Set;function f_(e){if(!e||typeof e!="object")return!1;const t=e.default;return t!==null&&typeof t=="object"}function h_(e){if(!e||typeof e!="object")return typeof e;const t=e,n=Object.getPrototypeOf(t),r=n&&typeof n=="object"?n.constructor?.name:void 0;return{ownKeys:Object.keys(t),allKeys:Object.getOwnPropertyNames(t),proto:typeof r=="string"?r:void 0}}async function m_(e,t){const n=Gs.get(e);if(n)return n;const r=ss.get(e);if(r)return r;Ku.has(e)||(pc(),kr.registerRemotes([{name:e,entry:t,type:"module"}],{force:!1}),Ku.add(e));const s=kr.loadRemote(`${e}/widgets`).then(a=>{if(!f_(a)){const l=h_(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 Gs.set(e,i),ss.delete(e),i}).catch(a=>{throw ss.delete(e),a});return ss.set(e,s),s}const g_=3e4,b_=2e3;function ly({children:e}){const t=ke(),n=ne(Date.now()),{data:r}=Qg(void 0,{staleTime:0,refetchOnMount:"always",refetchInterval:l=>{const c=l.state.data;return c&&c.length>0||Date.now()-n.current>=g_?!1:b_}});pt("addon.widget-ready",()=>{t.invalidateQueries({queryKey:[["addonWidgets","listWidgets"]]})});const[s,a]=P(0);Y(()=>{if(!r)return;let l=!1;const c=new Set;for(const d of r){if(c.has(d.remoteName)||(c.add(d.remoteName),Gs.has(d.remoteName)))continue;const f=d.bundleUrl;m_(d.remoteName,f).then(()=>{l||a(p=>p+1)}).catch(p=>{const h=p instanceof Error?p.message:String(p);(typeof globalThis<"u"?globalThis.console:void 0)?.error?.("[WidgetRegistry] Failed to load widget remote",{remoteName:d.remoteName,entryUrl:f,reason:h})})}return()=>{l=!0}},[r]);const i=q(()=>{const l=r??[],c=new Map;for(const f of l)c.set(`${f.addonId}/${f.stableId}`,f);const d=(f,p)=>({widgetId:f,addonId:p.addonId,stableId:p.stableId,label:p.label,description:p.description,icon:p.icon,remoteName:p.remoteName,bundleUrl:p.bundleUrl,hosts:p.hosts,requires:p.requires,defaultSize:p.defaultSize,allowedSizes:p.allowedSizes,defaultColumns:p.defaultColumns,defaultRows:p.defaultRows});return{resolve:f=>{const p=c.get(f);if(!p)return;const h=Gs.get(p.remoteName);if(!h)return null;const m=h[p.stableId];if(m)return m},metadata:f=>{const p=c.get(f);if(p)return d(f,p)},listAll:()=>{const f=[];for(const[p,h]of c)f.push(d(p,h));return f}}},[r,s]);return o(iy.Provider,{value:i,children:e})}function cy(e){return Pa().resolve(e)}function dy(e){return Pa().metadata(e)}function uy(){return Pa().listAll()}function Pa(){const e=py();if(!e)throw new Error("useWidgetRegistry(): no <WidgetRegistryProvider> in tree");return e}function py(){return x_(iy)}function x_(e){return ve(e)}function lt(e){const{widgetId:t,host:n="device-tab",config:r,deviceId:s,integrationId:a,instanceId:i,size:l,columns:c,rows:d}=e,f=cy(t),p=dy(t),h=q(()=>i??t,[i,t]);if(f===void 0&&p===void 0)return o(as,{widgetId:t,reason:"unknown"});if(f===void 0)return o(as,{widgetId:t,reason:"missing-export"});if(f===null)return o(y_,{});if(p){if(p.requires.deviceContext&&s===void 0)return o(as,{widgetId:t,reason:"missing-device-context"});if(p.requires.integrationContext&&a===void 0)return o(as,{widgetId:t,reason:"missing-integration-context"})}return o(f,{instanceId:h,host:n,config:r,deviceId:s,integrationId:a,size:l,columns:c,rows:d})}function y_(){return u("div",{className:"rounded-lg border border-border bg-surface/40 p-4 animate-pulse",children:[o("div",{className:"h-3 w-24 bg-foreground-subtle/20 rounded mb-2"}),o("div",{className:"h-2 w-full bg-foreground-subtle/10 rounded mb-1"}),o("div",{className:"h-2 w-3/4 bg-foreground-subtle/10 rounded"})]})}function as({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 o("div",{className:"rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning",children:n})}const ir="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",_a="block text-[11px] font-medium text-foreground mb-1",v_="text-[10px] text-foreground-subtle mt-0.5";function Ue({label:e,description:t,required:n,span:r,children:s,translationFn:a}){const i=r===2?"col-span-2":r===3?"col-span-3":r===4?"col-span-4":"col-span-1",l=Bt(e,a),c=Bt(t,a);return u("div",{className:i,children:[l!==void 0&&l!==""&&u("label",{className:_a,children:[l,n&&o("span",{className:"text-danger ml-0.5",children:"*"})]}),s,c&&o("p",{className:v_,children:c})]})}function w_({field:e,value:t,onChange:n,disabled:r,translationFn:s}){return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:o("input",{type:e.inputType??"text",className:ir,value:t==null?"":String(t),placeholder:e.placeholder,maxLength:e.maxLength,pattern:e.pattern,disabled:r||e.disabled,onChange:a=>n(a.target.value)})})}function N_({field:e,value:t,onChange:n,disabled:r,translationFn:s}){const[a,i]=P(t==null?"":String(t)),l=ne(!1);Y(()=>{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 f=Number(d);Number.isNaN(f)||n(f)};return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"flex items-center gap-1",children:[o("input",{type:"number",className:ir,value:a,placeholder:e.placeholder,min:e.min,max:e.max,step:e.step,disabled:r||e.disabled,onFocus:()=>{l.current=!0},onBlur:()=>{l.current=!1},onChange:d=>c(d.target.value)}),e.unit&&o("span",{className:"text-xs text-foreground-subtle whitespace-nowrap",children:e.unit})]})})}function k_({field:e,value:t,onChange:n,disabled:r,translationFn:s}){const a=!!t,i=r||e.disabled;return e.style==="checkbox"?o(Ue,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[o("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)}),o("span",{className:"text-xs font-medium text-foreground",children:Bt(e.label,s)}),e.required&&o("span",{className:"text-danger",children:"*"})]})}):o(Ue,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"flex items-center justify-between",children:[u("span",{className:_a+" mb-0",children:[Bt(e.label,s),e.required&&o("span",{className:"text-danger ml-0.5",children:"*"})]}),o("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:o("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 S_({field:e,value:t,onChange:n,disabled:r,translationFn:s}){const a=e.options.some(i=>i.value==="");return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("select",{className:ir,value:t==null?"":String(t),disabled:r||e.disabled,onChange:i=>n(i.target.value),children:[!e.required&&!a&&o("option",{value:"",children:"— Select —"}),e.options.map(i=>o("option",{value:i.value,children:i.label},i.value))]})})}function C_({field:e,value:t,onChange:n,disabled:r,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 o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:o("div",{className:"flex flex-wrap gap-2",children:e.options.map(l=>{const c=a.includes(l.value);return u("label",{className:["flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs cursor-pointer select-none transition-colors",c?"border-primary bg-primary/10 text-primary":"border-border bg-background text-foreground hover:bg-surface",r||e.disabled?"opacity-50 cursor-not-allowed":""].join(" "),children:[o("input",{type:"checkbox",className:"sr-only",checked:c,disabled:r||e.disabled,onChange:()=>i(l.value)}),l.label]},l.value)})})})}function M_({field:e,value:t,onChange:n,disabled:r,translationFn:s}){const[a,i]=P(!1),l=e.showToggle!==!1;return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"relative",children:[o("input",{type:a?"text":"password",className:ir+(l?" pr-9":""),value:t==null?"":String(t),placeholder:e.placeholder,disabled:r||e.disabled,onChange:c=>n(c.target.value)}),l&&o("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?o(gm,{className:"h-3.5 w-3.5"}):o(Oo,{className:"h-3.5 w-3.5"})})]})})}function E_({field:e,value:t,onChange:n,disabled:r,translationFn:s}){return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:o("textarea",{className:ir+" resize-y min-h-[60px]",value:t==null?"":String(t),placeholder:e.placeholder,rows:e.rows??3,maxLength:e.maxLength,disabled:r||e.disabled,onChange:a=>n(a.target.value)})})}function I_({field:e,value:t,onChange:n,disabled:r,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",f=r||e.disabled,p=e.displayScale??1,h=e.min/p,m=e.max/p,g=l/p,b=(e.step??1)/p;if(i&&a)return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("button",{className:"w-full rounded-lg border border-dashed border-border px-3 py-2 text-xs text-foreground-subtle hover:border-primary/40 hover:text-primary transition-colors text-left",disabled:f,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),k=Math.min(e.max,Math.max(e.min,N));k!==l&&n(k)},w="flex h-6 w-6 shrink-0 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:cursor-not-allowed disabled:opacity-40";return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[u("div",{className:"flex min-w-0 flex-1 basis-[160px] items-center gap-2",children:[o("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:h}),o("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:f,onChange:v=>n(Number(v.target.value)*p)}),o("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:m})]}),(c||i||e.unit)&&u("div",{className:"flex shrink-0 items-center gap-2",children:[x&&o("button",{type:"button",className:w,disabled:f||l<=e.min,onClick:()=>y(-1),title:`Decrease by ${e.step??1}`,"aria-label":"Decrement",children:o(wm,{className:"h-3 w-3"})}),c&&o("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:f,onChange:v=>{if(v.target.value===""){n(i?null:e.min);return}const N=Number(v.target.value)*p,k=e.step??1,C=N-e.min,E=e.min+Math.round(C/k)*k;n(Math.min(e.max,Math.max(e.min,E)))}}),x&&o("button",{type:"button",className:w,disabled:f||l>=e.max,onClick:()=>y(1),title:`Increase by ${e.step??1}`,"aria-label":"Increment",children:o(Bo,{className:"h-3 w-3"})}),e.unit&&o("span",{className:"text-[10px] text-foreground-subtle",children:e.unit}),i&&o("button",{className:"text-[10px] text-foreground-subtle hover:text-primary transition-colors",title:`Reset to ${d}`,disabled:f,onClick:()=>n(null),children:d})]})]})})}function A_({field:e,value:t,onChange:n,disabled:r,translationFn:s}){const a=Array.isArray(t)?t:[],[i,l]=P(""),c=ne(null),d=U(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]),f=m=>n(a.filter(g=>g!==m)),p=m=>{m.key==="Enter"||m.key===","?(m.preventDefault(),d(i)):m.key==="Backspace"&&i===""&&a.length>0&&f(a[a.length-1])},h=r||e.disabled;return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:["flex flex-wrap gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 min-h-[38px] cursor-text","focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30",h?"opacity-50 cursor-not-allowed":""].join(" "),onClick:()=>!h&&c.current?.focus(),children:[a.map(m=>u("span",{className:"inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[m,!h&&o("button",{type:"button",onClick:()=>f(m),className:"hover:text-danger",children:o(Ye,{className:"h-2.5 w-2.5"})})]},m)),o("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:p,onBlur:()=>{i.trim()&&d(i)}}),e.suggestions&&o("datalist",{id:`tags-suggestions-${e.key}`,children:e.suggestions.map(m=>o("option",{value:m},m))})]})})}function fy({field:e,value:t,onChange:n,disabled:r,translationFn:s}){const{nodes:a}=zr(),i=typeof t=="string"?t:"",l=e.showOffline?a:a.filter(c=>c.isOnline);return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("select",{className:"w-full px-3 py-2 text-sm bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-primary/50 disabled:opacity-50",value:i,onChange:c=>n(c.target.value),disabled:r,children:[o("option",{value:"",children:"Select node…"}),l.map(c=>u("option",{value:c.id,disabled:!c.isOnline,children:[c.shortName,c.isOnline?"":" (offline)"]},c.id))]})})}function hy({field:e,value:t,onChange:n,disabled:r,translationFn:s}){const{nodes:a}=zr(),i=new Set(Array.isArray(t)?t.map(String):[]),l=e.showOffline?a:a.filter(d=>d.isOnline),c=d=>{const f=new Set(i);f.has(d)?f.delete(d):f.add(d),n([...f])};return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:o("div",{className:"flex flex-wrap gap-1.5",children:l.map(d=>{const f=i.has(d.id);return o("button",{type:"button",onClick:()=>c(d.id),disabled:r||!d.isOnline,className:`px-2.5 py-1 text-xs font-medium rounded-md border transition-colors ${f?"border-primary bg-primary/10 text-primary":"border-border bg-surface text-foreground-subtle hover:bg-surface-hover"} ${d.isOnline?"":"opacity-50 cursor-not-allowed"}`,children:d.shortName},d.id)})})})}function P_({field:e,value:t,onChange:n,disabled:r,translationFn:s}){const a=t==null?"#000000":String(t);return u(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:[u("div",{className:"flex items-center gap-2",children:[o("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:r||e.disabled,onChange:i=>n(i.target.value)}),o("input",{type:"text",className:ir+" flex-1 font-mono",value:a,placeholder:"#000000",disabled:r||e.disabled,onChange:i=>n(i.target.value)})]}),e.presets&&e.presets.length>0&&o("div",{className:"flex gap-1.5 mt-1.5",children:e.presets.map(i=>o("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:r||e.disabled,title:i,onClick:()=>n(i)},i))})]})}function __({field:e,value:t,onChange:n,disabled:r,translationFn:s,onTestField:a,onAction:i,externalProbe:l}){const[c,d]=P("idle"),[f,p]=P(null),h=l?.status??c,m=l?.result??f,g=!!a||!!i,b=U(async()=>{if(g){d("probing"),p(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"};p(v),d(v.status==="ok"?"ok":"error")}catch(w){p({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"?o(Ot,{className:"h-3 w-3 animate-spin"}):h==="ok"?o(Fk,{className:"h-3 w-3"}):h==="error"?o(va,{className:"h-3 w-3"}):o(Em,{className:"h-3 w-3"});return u(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:[u("div",{className:"@container flex items-center gap-2",style:{containerType:"inline-size"},children:[u("button",{type:"button",onClick: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,o("span",{className:"hidden @[280px]:inline",children:"Test"})]}),o("input",{type:e.inputType??"url",className:ir+" flex-1 min-w-0",value:t==null?"":String(t),placeholder:e.placeholder,disabled:r||e.disabled,onChange:w=>{n(w.target.value),c!=="idle"&&(d("idle"),p(null))}})]}),h==="ok"&&m?.labels&&m.labels.length>0&&o("div",{className:"flex flex-wrap gap-1 mt-1.5",children:m.labels.map((w,v)=>o("span",{className:"text-xs bg-success/10 text-success rounded px-2 py-0.5 font-mono",children:w},v))}),h==="error"&&m?.error&&o("p",{className:"text-xs text-danger mt-1 truncate",title:m.error,children:m.error})]})}function $_({field:e,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a}){const[i,l]=P(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 o("div",{className:d,children:u("div",{className:"rounded-lg border border-border bg-surface/50 overflow-hidden",children:[u("div",{className:["px-3 py-2 flex items-center justify-between",c?"cursor-pointer hover:bg-surface":""].join(" "),onClick:c?()=>l(f=>!f):void 0,children:[o("span",{className:"text-xs font-semibold text-foreground",children:Bt(e.label,s)}),c&&o("span",{className:"text-foreground-subtle text-xs",children:i?"▸":"▾"})]}),!i&&o("div",{className:"px-3 pb-3 grid grid-cols-2 gap-x-4 gap-y-3",children:e.fields.map(f=>o(lr,{field:f,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a},f.key))})]})})}function D_({field:e,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a,onAction:i}){const l=e.tabs[0]?.id??"",[c,d]=P(l),f=e.span===2?"col-span-2":e.span===3?"col-span-3":e.span===4?"col-span-4":"col-span-1";return e.tabs.length===0?null:u("div",{className:f,children:[e.label&&o("div",{className:_a,children:Bt(e.label,s)}),u("div",{className:"rounded-lg border border-border-subtle bg-surface-hover/40 overflow-hidden",children:[o("div",{className:"flex flex-wrap gap-1 p-1.5 border-b border-border-subtle bg-surface/40",role:"tablist",children:e.tabs.map(p=>{const h=p.id===c;return u("button",{type:"button",role:"tab","aria-selected":h,onClick:()=>d(p.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:[o("span",{children:Bt(p.label,s)}),p.badge&&o("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:p.badge})]},p.id)})}),e.tabs.map(p=>p.id!==c?null:o("div",{role:"tabpanel",className:"px-3 pb-3 pt-2 grid grid-cols-2 gap-x-4 gap-y-3",children:p.fields.map((h,m)=>{const g="key"in h&&typeof h.key=="string"?h.key:`__${p.id}__${m}`;return o(lr,{field:h,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a,onAction:i},g)})},p.id))]})]})}function T_({span:e}){return o("div",{className:e===2?"col-span-2":e===3?"col-span-3":e===4?"col-span-4":"col-span-full",children:o("hr",{className:"border-border"})})}const Wu={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 L_(e){if(typeof window>"u"||typeof DOMParser>"u")return"";const t=new Set(["A","UL","OL","LI","STRONG","EM","CODE","BR","P","SPAN"]),n=new DOMParser().parseFromString(`<div>${e}</div>`,"text/html"),r=n.body.firstElementChild;if(!r)return"";const s=a=>{const i=Array.from(a.children);for(const l of i){if(!t.has(l.tagName)){const d=n.createTextNode(l.textContent??"");l.replaceWith(d);continue}const c=l.tagName==="A"?new Set(["href"]):new Set;for(const d of Array.from(l.attributes))c.has(d.name)||l.removeAttribute(d.name);if(l.tagName==="A"){const d=l.getAttribute("href")??"";!/^https?:\/\//i.test(d)&&!d.startsWith("mailto:")?l.removeAttribute("href"):(l.setAttribute("target","_blank"),l.setAttribute("rel","noopener noreferrer"))}s(l)}};return s(r),r.innerHTML}function R_({field:e}){const t=e.variant??"info",n=Wu[t]??Wu.info,r=e.format==="html";return o("div",{className:"col-span-full",children:u("div",{className:`rounded-md border-l-4 px-3 py-2.5 ${n.border} ${n.bg}`,children:[e.label&&o("p",{className:`text-xs font-semibold mb-0.5 ${n.text}`,children:e.label}),r?o("div",{className:"text-xs text-foreground-subtle leading-relaxed info-html-content",dangerouslySetInnerHTML:{__html:L_(e.content)}}):o("p",{className:"text-xs text-foreground-subtle leading-relaxed whitespace-pre-line",children:e.content})]})})}const Yu={ok:"bg-success",warn:"bg-amber-500",danger:"bg-danger",idle:"bg-foreground-subtle/40",unknown:"bg-foreground-subtle/40"};function O_(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),r=t%60;return r===0?`${n}m`:`${n}m ${r}s`}function B_(e){return!Number.isFinite(e)||e<=0?"—":new Date(e).toLocaleTimeString()}function z_({kind:e,value:t}){if(t==null||t==="")return o("span",{className:"text-foreground-subtle/60",children:"—"});if(e==="monospace")return o("span",{className:"font-mono text-[11px]",children:String(t)});if(e==="status"){const n=String(t).toLowerCase(),r=Yu[n]??Yu.unknown;return u("span",{className:"inline-flex items-center gap-1.5",children:[o("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${r}`}),o("span",{children:String(t)})]})}return e==="duration"&&typeof t=="number"?o("span",{className:"font-mono text-[11px]",children:O_(t)}):e==="timestamp"&&typeof t=="number"?o("span",{className:"font-mono text-[11px]",children:B_(t)}):o("span",{children:String(t)})}function F_({field:e}){const t=e.value??[],n=e.description;return u("div",{className:"col-span-full",children:[e.label&&o("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1",children:e.label}),n&&o("p",{className:"text-xs text-foreground-subtle mb-2",children:n}),t.length===0?o("div",{className:"rounded-md border border-border bg-surface-subtle px-3 py-2 text-xs text-foreground-subtle",children:e.emptyMessage??"No entries"}):o("div",{className:"rounded-md border border-border overflow-hidden",children:u("table",{className:"w-full text-xs",children:[o("thead",{className:"bg-surface-subtle border-b border-border",children:o("tr",{children:e.columns.map(r=>o("th",{className:"px-3 py-1.5 text-left font-medium text-foreground-subtle",style:r.width?{width:r.width}:void 0,children:r.label},r.key))})}),o("tbody",{className:"divide-y divide-border",children:t.map((r,s)=>o("tr",{className:"hover:bg-surface-hover/40",children:e.columns.map(a=>o("td",{className:"px-3 py-1.5 align-top text-foreground",children:o(z_,{kind:a.kind,value:r[a.key]})},a.key))},s))})]})})]})}function j_({field:e,value:t,onChange:n,disabled:r,translationFn:s,onTestField:a,onAction:i}){const l=Array.isArray(t)?t:[],c=e.minRows??0,d=e.maxRows??Number.POSITIVE_INFINITY,f=(x,y,w)=>{const v=l.slice(),N=v[x]??{};v[x]={...N,[y]:w},n(v)},p=x=>{l.length<=c||n(l.filter((y,w)=>w!==x))},h=()=>{if(l.length>=d)return;const x=e.defaultItem??{};n([...l,{...x}])},m=(x,y)=>e.rowTitleTemplate?e.rowTitleTemplate.replace(/\{(\w+)\}/g,(w,v)=>{const N=x[v];return N==null||N===""?"—":String(N)}):`Row ${y+1}`,g=l.length>c,b=l.length<d;return u("div",{className:"col-span-full space-y-2",children:[u("div",{className:"space-y-0.5",children:[e.label&&o("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle",children:Bt(e.label,s)}),e.description&&o("p",{className:"text-[11px] text-foreground-subtle",children:Bt(e.description,s)})]}),l.length===0?o("div",{className:"rounded-md border border-dashed border-border bg-background px-3 py-3 text-center text-[11px] text-foreground-subtle",children:e.emptyMessage??"No entries"}):o("div",{className:"space-y-2",children:l.map((x,y)=>u("div",{className:"rounded-md border border-border bg-background",children:[u("div",{className:"flex items-center justify-between border-b border-border px-3 py-1.5",children:[o("span",{className:"text-xs font-medium text-foreground",children:m(x,y)}),u("button",{type:"button",onClick:()=>p(y),disabled:r||!g,className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-30 disabled:cursor-not-allowed",title:g?"Remove this row":`At least ${c} row(s) required`,children:[o(wm,{className:"h-3 w-3"}),"Remove"]})]}),o("div",{className:"grid grid-cols-1 @[420px]:grid-cols-2 gap-x-3 gap-y-2 p-3",children:e.itemFields.map(w=>o(lr,{field:w,values:x,onChange:(v,N)=>f(y,v,N),disabled:r,translationFn:s,onTestField:a,allFields:e.itemFields,onAction:i},w.key))})]},y))}),u("div",{children:[u("button",{type:"button",onClick:h,disabled:r||!b,className:"inline-flex items-center gap-1 rounded border border-border bg-surface px-3 py-1 text-[11px] font-medium text-foreground hover:border-primary/40 hover:bg-primary/5 disabled:opacity-30 disabled:cursor-not-allowed",children:[o(Bo,{className:"h-3 w-3"}),e.addLabel??"Add"]}),!b&&Number.isFinite(d)&&u("span",{className:"ml-2 text-[10px] text-foreground-subtle",children:["(limit: ",d,")"]})]})]})}function H_({field:e,disabled:t,onAction:n}){const[r,s]=P(!1),a=Je(),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 o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,children:o("button",{onClick:i,disabled:t||r,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:r?"Processing...":e.buttonLabel})})}function my(e,t){const n={...e.paramsStatic??{}};if(e.paramsFromForm)for(const[r,s]of Object.entries(e.paramsFromForm)){const a=t[s];a!=null&&a!==""&&(n[r]=a)}return n}function V_({field:e,value:t,values:n,onChange:r,disabled:s,onAction:a}){const[i,l]=P(!1),[c,d]=P(null),[f,p]=P(null),h=my(e,n),m=Object.keys(e.paramsFromForm??{}).some(w=>h[w]===void 0),g=(e.refreshOn??Object.values(e.paramsFromForm??{})).map(w=>`${w}=${JSON.stringify(n[w])}`).join("|");Y(()=>{if(!a||m){p(null),d(null);return}let w=!1;return l(!0),d(null),a(e.action,e.key,h).then(v=>{if(w)return;const N=v;let k=[];if(Array.isArray(N))k=N;else if(N&&typeof N=="object")for(const C of Object.keys(N)){const E=N[C];if(Array.isArray(E)){k=E;break}}p(k)}).catch(v=>{w||(d(v instanceof Error?v.message:String(v)),p([]))}).finally(()=>{w||l(!1)}),()=>{w=!0}},[g,a,e.action,e.key]);const b=e.mapOption.value,x=e.mapOption.label,y=e.mapOption.description;return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,children:m?o("div",{className:"text-[11px] text-foreground-subtle italic",children:e.emptyParamsMessage??"Fill the prerequisite fields above first."}):i?u("div",{className:"flex items-center gap-2 text-[11px] text-foreground-subtle",children:[o(Ot,{className:"h-3 w-3 animate-spin"})," Loading options…"]}):c?o("div",{className:"text-[11px] text-danger",children:c}):f&&f.length===0?o("div",{className:"text-[11px] text-foreground-subtle italic",children:e.emptyResultsMessage??"No options returned."}):(()=>{const w=(f??[]).some(v=>{const N=v[b];return N===""||N===void 0});return u("select",{className:"w-full rounded-md border border-border bg-surface px-2 py-1.5 text-xs text-foreground",value:typeof t=="string"?t:"",disabled:s,onChange:v=>r(v.target.value),children:[!w&&o("option",{value:"",children:"— Select —"}),(f??[]).map((v,N)=>{const k=v[b],C=v[x],E=y?v[y]:void 0,A=typeof k=="string"&&k!==""?k:`row-${N}`;return u("option",{value:typeof k=="string"?k:String(k??""),children:[typeof C=="string"?C:String(C??A),E!==void 0?` (${String(E)})`:""]},A)})]})})()})}function q_({field:e,values:t,disabled:n,onAction:r}){const[s,a]=P(!1),[i,l]=P(null),c=Je(),d=async()=>{if(e.confirmMessage&&!await c({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant==="danger"?"danger":"default"})||!r)return;const p=my(e,t);a(!0),l(null);try{const h=await r(e.action,e.key,p),m=typeof h=="object"&&h!==null?h:null,g=e.successMessage?e.successMessage.replace(/\{(\w+)\}/g,(b,x)=>{const y=m?.[x];return y===void 0?"":String(y)}):"Done.";l({kind:"ok",text:g})}catch(h){l({kind:"error",text:h instanceof Error?h.message:String(h)})}finally{a(!1)}},f={default:"border border-border text-foreground hover:bg-surface-hover",primary:"bg-primary text-primary-foreground hover:bg-primary/90",danger:"bg-danger text-white hover:bg-danger/90"};return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,children:u("div",{className:"flex flex-col gap-1.5",children:[o("button",{onClick:d,disabled:n||s,className:`inline-flex w-fit items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${f[e.variant??"default"]??f.default}`,children:s?"Working…":e.buttonLabel}),i&&o("div",{className:`text-[11px] ${i.kind==="ok"?"text-emerald-700 dark:text-emerald-300":"text-danger"}`,children:i.text})]})})}function U_({field:e}){const t=hn();return o(Ue,{label:e.label,description:e.description,required:e.required,span:e.span,children:o(lt,{widgetId:e.widgetId,host:"device-tab",config:e.widgetConfig,deviceId:t??void 0,instanceId:e.key})})}function Q_(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 G_({field:e,values:t,onAction:n,translationFn:r}){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=Q_(i,l),d="label"in e?e.label:void 0,f="description"in e?e.description:void 0,p="span"in e?e.span:void 0,h="actions"in e?e.actions??[]:[];return o(Ue,{label:d,description:f,span:p,translationFn:r,children:u("div",{className:"flex items-stretch gap-1",children:[o("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&&o("div",{className:"flex items-center gap-1",children:h.map(m=>o(W_,{action:m,fieldKey:s,value:i,onAction:n},m.action))})]})})}function K_({name:e}){const t="h-3.5 w-3.5";switch(e){case"copy":return o(_n,{className:t});case"refresh-cw":return o(gc,{className:t});case"external-link":return o(mm,{className:t});case"trash-2":return o(Kt,{className:t});case"download":return o(ml,{className:t});case"upload":return o(Mm,{className:t});default:return o(bc,{className:t})}}function W_({action:e,fieldKey:t,value:n,onAction:r}){const s=Je(),[a,i]=P(!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 o("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(r){i(!0);try{await r(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:o(K_,{name:e.icon})})}function Y_(e){return"multiple"in e&&e.multiple!=null}function Z_({field:e,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c}){const d=e.multiple,f=d.min,p=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<f;)g.push(b);const x=k=>n(e.key,[...k]),y=(k,C)=>{const E=[...g];E[k]=C,x(E)},w=()=>{g.length>=p||x([...g,b])},v=k=>{g.length<=f||x(g.filter((C,E)=>E!==k))},N=()=>{const{multiple:k,...C}=e;return{...C,...{label:void 0,description:void 0,required:!1}}};return o(Ue,{label:e.label,description:e.description,required:f>0?e.required:!1,span:e.span,translationFn:s,children:u("div",{className:"space-y-2",children:[g.map((k,C)=>{const E=d.itemLabel?.replace("${n}",String(C+1));return u("div",{className:"space-y-1",children:[E&&o("div",{className:_a,children:E}),u("div",{className:"flex items-center gap-2",children:[o("div",{className:"flex-1 min-w-0",children:o(lr,{field:N(),values:{...t,[e.key]:k},onChange:(A,I)=>y(C,I),disabled:r,translationFn:s,onTestField:a,onAction:c,allFields:l})}),g.length>f&&o("button",{type:"button",onClick:()=>v(C),disabled:r,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:o(Kt,{className:"h-3.5 w-3.5"})})]})]},C)}),u("div",{className:"flex items-center justify-between pt-1",children:[g.length<p?u("button",{type:"button",onClick:w,disabled:r,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:[o(Bo,{className:"h-3 w-3"}),d.addLabel??"Add"]}):o("span",{}),u("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:[g.length,"/",p]})]})]})})}function od(e,t,n){if(!("showWhen"in e)||!e.showWhen)return!0;const r=e.showWhen,s=t[r.field],a=n?.find(c=>"key"in c&&c.key===r.field),i=a&&"default"in a?a.default:void 0,l=s!==void 0?s:i;return r.equals!==void 0?l===r.equals:r.notEquals!==void 0?l!==r.notEquals:r.in!==void 0?r.in.includes(l):r.notIn!==void 0?!r.notIn.includes(l):r.includes!==void 0?Array.isArray(l)&&l.includes(r.includes):r.notIncludes!==void 0?!Array.isArray(l)||!l.includes(r.notIncludes):!0}function lr({field:e,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c}){if(Y_(e))return o(Z_,{field:e,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c});if("readonlyField"in e&&e.readonlyField===!0)return o(G_,{field:e,values:t,onAction:c,translationFn:s});if(!od(e,t,l))return null;const d=t[e.key],f=d!==void 0?d:"default"in e?e.default:void 0,p=m=>n(e.key,m),h=_g(e.type);switch(e.type){case"text":return o(w_,{field:e,value:f,onChange:p,disabled:r,translationFn:s});case"number":return o(N_,{field:e,value:f,onChange:p,disabled:r,translationFn:s});case"boolean":return o(k_,{field:e,value:f,onChange:p,disabled:r,translationFn:s});case"select":return o(S_,{field:e,value:f,onChange:p,disabled:r,translationFn:s});case"multiselect":return o(C_,{field:e,value:f,onChange:p,disabled:r,translationFn:s});case"password":return o(M_,{field:e,value:f,onChange:p,disabled:r,translationFn:s});case"textarea":return o(E_,{field:e,value:f,onChange:p,disabled:r,translationFn:s});case"slider":return o(I_,{field:e,value:f,onChange:p,disabled:r,translationFn:s});case"tags":return o(A_,{field:e,value:f,onChange:p,disabled:r,translationFn:s});case"color":return o(P_,{field:e,value:f,onChange:p,disabled:r,translationFn:s});case"node-select":return o(fy,{field:e,value:f,onChange:p,disabled:r,translationFn:s});case"node-multiselect":return o(hy,{field:e,value:f,onChange:p,disabled:r,translationFn:s});case"probe":return o(__,{field:e,value:f,onChange:p,disabled:r,translationFn:s,onTestField:a,onAction:c,externalProbe:i});case"group":return o($_,{field:e,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a});case"sub-tabs":return o(D_,{field:e,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a,onAction:c});case"separator":return o(T_,{});case"info":return o(R_,{field:e});case"object-array":return o(F_,{field:e});case"editable-array":return o(j_,{field:e,value:f,onChange:p,disabled:r,translationFn:s,onTestField:a,onAction:c});case"button":return o(H_,{field:e,disabled:r,onAction:c});case"addon-action-select":return o(V_,{field:e,value:f,values:t,onChange:p,disabled:r,onAction:c});case"addon-action-button":return o(q_,{field:e,values:t,disabled:r,onAction:c});case"widget":return o(U_,{field:e});default:return h?o(h,{field:e,value:f,onChange:p,disabled:r}):null}}function X_(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function Bt(e,t){if(e!==void 0)return t&&X_(e)?t(e):e}function J_({section:e,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a,probeResults:i}){const[l,c]=P(e.defaultCollapsed??!1),d=e.style==="accordion",f=e.columns??2,p=f===1?"grid-cols-1":f===3?"grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3":f===4?"grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4":"grid-cols-1 @[640px]:grid-cols-2";return u("div",{className:"@container rounded-lg border border-border bg-surface p-3",style:{containerType:"inline-size"},children:[u("div",{className:["flex items-center justify-between mb-2",d?"cursor-pointer":""].join(" "),onClick:d?()=>c(h=>!h):void 0,children:[u("div",{children:[o("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:Bt(e.title,s)}),e.description&&o("p",{className:"text-[10px] text-foreground-subtle mt-0.5",children:Bt(e.description,s)})]}),d&&o("span",{className:"text-foreground-subtle text-xs ml-2",children:l?"▸":"▾"})]}),!l&&o("div",{className:`grid ${p} gap-x-3 gap-y-2.5`,children:e.fields.map(h=>o(lr,{field:h,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a,externalProbe:i?.[h.key]},h.key))})]})}function gy({schema:e,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a,probeResults:i,onClearProbe:l}){const c=(d,f)=>{n({...t,[d]:f}),l?.(d)};return o("div",{className:"space-y-4",children:e.sections.map(d=>o(J_,{section:d,values:t,onChange:c,disabled:r,translationFn:s,onTestField:a,probeResults:i},d.id))})}const e$=({open:e})=>o("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:o("polyline",{points:"9 18 15 12 9 6"})});function Zu(e){const t={};if(!e)return t;for(const n of e.sections)for(const r of n.fields){if(r.type==="separator"||r.type==="info"||r.type==="button"||r.type==="group")continue;const s=r.key;t[s]=r.value}return t}function t$(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:r,...s}=n;return s})}))}}function n$({trpc:e,addonId:t,nodeId:n,title:r,disabled:s,onAfterChange:a,refreshToken:i,collapsible:l,defaultOpen:c,mode:d,onOverrideChange:f}){const p=d??"persist",[h,m]=P(null),[g,b]=P(!0),[x,y]=P(null),[w,v]=P(!1),[N,k]=P(c??!1),[C,E]=P({}),[A,I]=P(null);Y(()=>{I(null),E({})},[e,t,n,i,p]);const z=JSON.stringify(C);Y(()=>{let _=!1;b(!0),y(null);const L=p==="override"&&Object.keys(C).length>0?C:void 0;return e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n,...L?{overlay:L}:{}}).then(O=>{_||(m(O),L||I(Zu(O)),b(!1))}).catch(O=>{_||(y(O instanceof Error?O.message:String(O)),b(!1))}),()=>{_=!0}},[e,t,n,i,p,z]);const $=q(()=>Zu(h),[h]),B=q(()=>h?t$(h):null,[h]),R=async _=>{if(p==="override"){const O=A??$,j={};for(const H of Object.keys(_))_[H]!==O[H]&&(j[H]=_[H]);const F={...O,...j};E(j),f?.(j,F);return}const L={};for(const O of Object.keys(_))_[O]!==$[O]&&(L[O]=_[O]);if(Object.keys(L).length!==0){v(!0);try{await e.addonSettings.updateGlobalSettings.mutate({addonId:t,nodeId:n,patch:L});const O=await e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n});m(O),a?.()}catch(O){y(O instanceof Error?O.message:String(O))}finally{v(!1)}}};if(g)return u("div",{className:"text-xs text-foreground-subtle animate-pulse",children:["Loading ",r??t,"…"]});if(x)return u("div",{className:"text-xs text-red-400",children:[r??t,": ",x]});if(!h||!B)return u("div",{className:"text-xs text-foreground-subtle",children:[r??t," not available on ",n,"."]});const M=p==="override"?{...$,...C}:$,T=u(me,{children:[p==="override"?o("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,o(gy,{schema:B,values:M,onChange:R,disabled:s===!0||w})]});return l===!0?u("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("button",{type:"button",onClick:()=>k(_=>!_),className:"w-full px-4 py-2 flex items-center gap-2 hover:bg-surface-hover text-left","aria-expanded":N,children:[o(e$,{open:N}),o("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide flex-1",children:r??t}),o("span",{className:"text-[10px] text-foreground-subtle",children:N?"hide":"edit"})]}),N?o("div",{className:"border-t border-border px-4 py-3",children:T}):null]}):r?u("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[o("div",{className:"border-b border-border px-4 py-2",children:o("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide",children:r})}),o("div",{className:"px-4 py-3",children:T})]}):o("div",{children:T})}function by({detections:{motion:e,motionRaw:t,detection:n,phase:r},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,f=i&&n&&n.detections.length>0;return!c&&!d&&!f&&!l?null:u("div",{className:"absolute inset-0 pointer-events-none z-10",children:[l&&o(r$,{phase:r}),d&&o(o$,{raw:t}),c&&o(s$,{motion:e}),f&&o(a$,{detections:n.detections,frameWidth:n.frameWidth,frameHeight:n.frameHeight})]})}function r$({phase:e}){const t=rr(e);return u("div",{className:"absolute top-2 left-2 flex items-center gap-1.5 px-2 py-1 rounded-md bg-black/60 backdrop-blur-sm",children:[o("span",{className:`w-2 h-2 rounded-full ${t.dotClass}`}),o("span",{className:"text-[10px] font-semibold text-white uppercase tracking-wider",children:t.label})]})}function o$({raw:e}){return e.frameWidth===0||e.frameHeight===0?null:o(me,{children:e.boxes.map((t,n)=>{const[r,s,a,i]=t.bbox,l=r/e.frameWidth*100,c=s/e.frameHeight*100,d=(a-r)/e.frameWidth*100,f=(i-s)/e.frameHeight*100,p=Math.max(.05,Math.min(.25,t.changeScore*.3));return o("div",{className:"absolute rounded-sm",style:{left:`${l}%`,top:`${c}%`,width:`${d}%`,height:`${f}%`,backgroundColor:`rgba(239, 68, 68, ${p})`}},`mr-${n}`)})})}function s$({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 o(me,{children:t.map((n,r)=>{const s=Math.max(.15,Math.min(.5,n.intensity/255));return o("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-${r}`)})})}function a$({detections:e,frameWidth:t,frameHeight:n}){return t===0||n===0?null:o(me,{children:e.map(r=>{const{x:s,y:a,width:i,height:l}=r.bbox,c=s/t*100,d=a/n*100,f=i/t*100,p=l/n*100,h=dt(r.macroClass),m=[`${r.macroClass} ${(r.score*100).toFixed(0)}%`];for(const g of r.labels)m.push(g.label);return o("div",{className:"absolute border-2 rounded-sm",style:{left:`${c}%`,top:`${d}%`,width:`${f}%`,height:`${p}%`,borderColor:h},children:o("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-${r.id}`)})})}function i$(e){const t={};if(typeof window<"u"){if(e){const r=e.getBoundingClientRect();r.width>0&&r.height>0&&(t.viewportWidth=Math.round(r.width),t.viewportHeight=Math.round(r.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 l$=3e3,c$=5;function xy({serverUrl:e,streamKey:t,label:n,autoPlay:r=!0,muted:s=!0,showControls:a=!0,className:i="",onStateChange:l,onError:c,overlay:d,createSession:f,sendAnswer:p,closeSession:h,hintsOverride:m}){const g=ne(null),b=ne(null),x=ne(null),y=ne(new Set),w=ne(null),v=ne(null),N=ne(0),k=ne(!0),[C,E]=P("idle"),[A,I]=P(""),[z,$]=P(s),[B,R]=P(!1),[M,T]=P(!1),_=ne(null),L=ne(!1);(p||f)&&(L.current=!0);const O=L.current,j=U(K=>{E(K),l?.(K)},[l]),F=U(()=>{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 K of y.current)h(K).catch(()=>{});y.current.clear()}g.current&&(g.current.srcObject=null)},[h]),H=U(async()=>{if(!k.current||!f||!p)return;F(),j("connecting");const K=new AbortController;w.current=K;try{const ae={...i$(b.current),...m},{sessionId:fe,sdpOffer:ge}=await f(ae);if(y.current.add(fe),!k.current||K.signal.aborted){h?.(fe).catch(()=>{}),y.current.delete(fe);return}const V=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]});x.current=V;const ie=new MediaStream;V.ontrack=pe=>{console.debug("[WebRTC] ontrack",pe.track.kind,pe.track.readyState),ie.addTrack(pe.track),g.current&&(g.current.srcObject=ie,g.current.play().catch(()=>{}))},V.oniceconnectionstatechange=()=>{if(!k.current)return;const pe=V.iceConnectionState;console.debug("[WebRTC] ICE state:",pe),pe==="connected"||pe==="completed"?(N.current=0,j("playing"),g.current?.paused&&(console.debug("[WebRTC] video was paused at ICE connected — calling play()"),g.current.play().catch(()=>{}))):(pe==="failed"||pe==="disconnected"||pe==="closed")&&(j("disconnected"),ee())},V.onicecandidateerror=pe=>{console.debug("[WebRTC] ICE candidate error:",pe)},console.debug("[WebRTC] Setting remote description (server offer)..."),await V.setRemoteDescription({type:"offer",sdp:ge});const ue=await V.createAnswer();if(await V.setLocalDescription(ue),console.debug("[WebRTC] Local description set, waiting for ICE gathering..."),await Xu(V),!k.current)return;const de=(V.localDescription?.sdp??"").split(`
536
- `).filter(pe=>pe.startsWith("a=candidate:")).length;console.debug("[WebRTC] Sending answer to server",{localCandidates:de,sessionId:fe.slice(0,8)}),await p(fe,V.localDescription?.sdp??""),console.debug("[WebRTC] Answer sent successfully");const ce=V,Se=()=>{const pe=ce.connectionState;if(pe==="closed"||pe==="failed")return;const _e=g.current;_e&&_e.readyState===0&&console.log(`[WebRTC] no video data yet (ice=${ce.iceConnectionState})`)};setTimeout(Se,3e3),setTimeout(Se,8e3)}catch(J){if(!k.current)return;const ae=J instanceof Error?J.message:String(J);I(ae),j("error"),c?.(ae),ee()}},[e,t,f,p,F,j,c,m]),D=U(async()=>{if(k.current){F(),j("connecting");try{const K=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]});x.current=K,K.addTransceiver("video",{direction:"recvonly"}),K.addTransceiver("audio",{direction:"recvonly"});const J=new MediaStream;K.ontrack=ie=>{J.addTrack(ie.track),g.current&&(g.current.srcObject=J,g.current.play().catch(()=>{}))},K.oniceconnectionstatechange=()=>{if(!k.current)return;const ie=K.iceConnectionState;ie==="connected"||ie==="completed"?(N.current=0,j("playing"),g.current?.paused&&g.current.play().catch(()=>{})):(ie==="failed"||ie==="disconnected"||ie==="closed")&&(j("disconnected"),ee())};const ae=await K.createOffer();if(await K.setLocalDescription(ae),await Xu(K),!k.current)return;const fe=`${e}/api/webrtc?src=${encodeURIComponent(t)}`,ge=await fetch(fe,{method:"POST",headers:{"Content-Type":"application/sdp"},body:K.localDescription?.sdp??""});if(!ge.ok)throw new Error(`WHEP ${ge.status}: ${ge.statusText}`);const V=await ge.text();await K.setRemoteDescription({type:"answer",sdp:V})}catch(K){if(!k.current)return;const J=K instanceof Error?K.message:String(K);I(J),j("error"),c?.(J),ee()}}},[e,t,F,j,c]),Q=O?H:D,G=ne(()=>{});G.current=Q;const ee=U(()=>{k.current&&(N.current>=c$||(N.current+=1,v.current=setTimeout(()=>{k.current&&G.current()},l$)))},[]);Y(()=>(k.current=!0,N.current=0,r&&Q(),()=>{k.current=!1,F()}),[e,t]);const se=ne(!1);Y(()=>{!r||!O||!f||!p||se.current||x.current||(se.current=!0,Q())},[r,O,f,p,Q]);const te=()=>{N.current=0,Q()},Z=()=>{g.current&&(g.current.muted=!g.current.muted,$(g.current.muted))},re=async()=>{if(b.current)try{document.fullscreenElement?await document.exitFullscreen():await b.current.requestFullscreen()}catch(K){console.warn(`Fullscreen toggle failed: ${K instanceof Error?K.message:K}`)}},be=()=>{if(!g.current)return;const K=document.createElement("canvas");K.width=g.current.videoWidth||1280,K.height=g.current.videoHeight||720;const J=K.getContext("2d");if(!J)return;J.drawImage(g.current,0,0);const ae=document.createElement("a");ae.download=`${t.replace(/[/:]/g,"-")}-${Date.now()}.jpg`,ae.href=K.toDataURL("image/jpeg",.92),ae.click()};Y(()=>{const K=()=>R(!!document.fullscreenElement);return document.addEventListener("fullscreenchange",K),()=>document.removeEventListener("fullscreenchange",K)},[]);const X=()=>{T(!0),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>T(!1),3e3)};return u("div",{ref:b,className:`relative bg-black overflow-hidden group ${i}`,onMouseMove:X,onMouseEnter:X,children:[o("video",{ref:g,autoPlay:r,muted:z,playsInline:!0,className:"w-full h-full object-contain"}),n&&C==="playing"&&o("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,C==="connecting"&&u("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-black/70 gap-2",children:[o("svg",{className:"h-6 w-6 text-white/60 animate-spin",viewBox:"0 0 24 24",fill:"none",children:o("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]"})}),o("span",{className:"text-xs text-white/60",children:"Connecting…"})]}),(C==="error"||C==="disconnected")&&u("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-black/70 gap-2",children:[o("svg",{className:"h-6 w-6 text-red-400",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:o("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"})}),o("span",{className:"text-xs text-red-400 text-center px-4",children:C==="error"?A||"Connection failed":"Disconnected"}),o("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&&C==="playing"&&u("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 ${M?"opacity-100":"opacity-0"}`,children:[o("div",{className:"flex items-center gap-1",children:o(bi,{onClick:Z,title:z?"Unmute":"Mute",children:z?u("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),o("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),o("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]}):u("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),o("path",{d:"M19.07 4.93a10 10 0 010 14.14M15.54 8.46a5 5 0 010 7.07"})]})})}),u("div",{className:"flex items-center gap-1",children:[o(bi,{onClick:be,title:"Take snapshot",children:u("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o("path",{d:"M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z"}),o("circle",{cx:"12",cy:"13",r:"4"})]})}),o(bi,{onClick:re,title:B?"Exit fullscreen":"Fullscreen",children:B?o("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:o("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"})}):o("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:o("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 bi({onClick:e,title:t,children:n}){return o("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 Xu(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 sd=fn("camstack:player-overlays-state",null),ad=fn("camstack:player-overlays-actions",null);function yy({children:e}){const[t,n]=P(()=>new Map),[r,s]=P(()=>new Map),a=U(p=>{n(h=>{const m=new Map(h);return m.set(p.id,p),m})},[]),i=U(p=>{n(h=>{if(!h.has(p))return h;const m=new Map(h);return m.delete(p),m})},[]),l=U(p=>{s(h=>{const m=new Map(h);return m.set(p.id,p),m})},[]),c=U(p=>{s(h=>{if(!h.has(p))return h;const m=new Map(h);return m.delete(p),m})},[]),d=q(()=>({layers:t,buttons:r}),[t,r]),f=q(()=>({setLayer:a,removeLayer:i,setButton:l,removeButton:c}),[a,i,l,c]);return o(sd.Provider,{value:d,children:o(ad.Provider,{value:f,children:e})})}function vy(){const e=ve(sd);return q(()=>e?[...e.layers.values()].sort((t,n)=>t.order-n.order):[],[e])}function wy(){const e=ve(sd);return q(()=>e?[...e.buttons.values()].sort((t,n)=>t.order-n.order):[],[e])}function d$(e){const t=ve(ad);Y(()=>{if(!(!t||!e))return t.setLayer(e),()=>t.removeLayer(e.id)},[t,e])}function u$(e){const t=ve(ad);Y(()=>{if(!(!t||!e))return t.setButton(e),()=>t.removeButton(e.id)},[t,e])}function p$(e){return e==="streaming"?"bg-emerald-500":e==="connecting"?"bg-amber-500":e==="error"?"bg-rose-500":"bg-zinc-500"}function f$(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 Sl({className:e}){return o("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:o("polygon",{points:"5 3 19 12 5 21 5 3"})})}function h$({className:e}){return o("svg",{className:e,viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:o("rect",{x:"6",y:"6",width:"12",height:"12",rx:"1"})})}function m$({className:e}){return u("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[o("path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z"}),o("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),o("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),o("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}function g$({className:e}){return u("svg",{className:e,viewBox:"0 0 24 24",fill:"currentColor",children:[o("circle",{cx:"5",cy:"12",r:"2"}),o("circle",{cx:"12",cy:"12",r:"2"}),o("circle",{cx:"19",cy:"12",r:"2"})]})}function xi({label:e,active:t,onClick:n}){return u("button",{type:"button",onClick:n,className:"w-full flex items-center justify-between gap-3 px-3 py-1.5 text-[11px] text-foreground hover:bg-surface-hover transition-colors",children:[o("span",{children:e}),o("span",{className:`inline-block h-3 w-5 rounded-full transition-colors ${t?"bg-primary":"bg-foreground-subtle/30"} relative`,children:o("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-white transition-all ${t?"left-2.5":"left-0.5"}`})})]})}function Ny({className:e}){return u("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[o("polyline",{points:"23 4 23 10 17 10"}),o("polyline",{points:"1 20 1 14 7 14"}),o("path",{d:"M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15"})]})}function b$({className:e}){return u("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[o("line",{x1:"2",y1:"2",x2:"22",y2:"22"}),o("path",{d:"M10.41 10.41a2 2 0 11-2.83-2.83"}),o("line",{x1:"13.5",y1:"13.5",x2:"6",y2:"21"}),o("path",{d:"M18 12l-1.5-1.5"}),o("path",{d:"M21 15V5a2 2 0 00-2-2H5"}),o("path",{d:"M21 21H5a2 2 0 01-2-2V11"})]})}function id({serverUrl:e,createSession:t,sendAnswer:n,closeSession:r,streams:s,activeStreamId:a,onStreamChange:i,deviceName:l,phase:c,pipelineMetrics:d,detections:f,defaultShowDetections:p=!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:k,ptzAvailable:C=!1,ptzShown:E=!1,ptzOverlay:A,onPtzToggle:I,intercomAvailable:z=!1,intercomShown:$=!1,onIntercomToggle:B,chromeless:R=!1,className:M}){const T=wy(),[_,L]=P(g),[O,j]=P(p),[F,H]=P(h),[D,Q]=P(null),[G,ee]=P(!1),se=ne(null);Y(()=>{if(!G)return;function ce(Se){se.current&&!se.current.contains(Se.target)&&ee(!1)}return document.addEventListener("mousedown",ce),()=>document.removeEventListener("mousedown",ce)},[G]);const te=a??D??s?.[0]?.id??"",Z=s?.find(ce=>ce.id===te)??s?.[0],re=Z?.inputFps!=null?{status:Z.status??"unknown",inputFps:Z.inputFps,bitrateKbps:Z.bitrateKbps??0}:null,be=ce=>{Q(ce),i?.(ce),_&&b&&(L(!1),setTimeout(()=>L(!0),50))},X=q(()=>{const ce=Z?.target;if(ce)return Se=>t(ce,Se)},[t,Z]),K=s,J=()=>L(!0),ae=()=>L(!1),fe=d?.phase??c,ge=fe==="active",V=!!f,ie=V&&(O||F),ue=C&&E&&!!A,de=b?_:!0;return u("div",{className:`overflow-hidden ${R?"":"rounded-xl border border-border bg-surface"} ${M??""}`,children:[u("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border",children:[u("div",{className:"flex items-center gap-2",children:[(m??re)&&o("span",{className:`w-2 h-2 rounded-full ${p$((m??re).status)}`}),l&&o("span",{className:"text-xs font-medium text-foreground",children:l}),K&&K.length>1&&u("div",{className:"relative",children:[o("select",{"data-testid":"stream-profile-select",value:te,onChange:ce=>be(ce.target.value),className:"appearance-none cursor-pointer rounded-md border border-border bg-surface-hover hover:bg-surface text-foreground text-[11px] font-medium pl-2 pr-6 py-1 focus:outline-none focus:ring-1 focus:ring-primary transition-colors",children:K.map(ce=>o("option",{value:ce.id,children:ce.label},ce.id))}),o("span",{className:"pointer-events-none absolute right-1.5 top-1/2 -translate-y-1/2 text-foreground-subtle",children:o("svg",{className:"h-2.5 w-2.5",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:o("polyline",{points:"3 4.5 6 7.5 9 4.5"})})})]})]}),u("div",{className:"flex items-center gap-1.5",children:[z&&u("button",{"data-testid":"stream-intercom-toggle","data-intercom-shown":$?"true":"false",onClick:B,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors ${$?"bg-primary/15 text-primary":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,title:$?"Close intercom":"Open intercom",children:[o(m$,{className:"h-3 w-3"}),o("span",{className:"hidden xl:inline",children:"Intercom"})]}),T.map(ce=>{const pe=ce.tone==="primary"?"bg-primary text-primary-foreground":"bg-primary/15 text-primary";return u("button",{type:"button","data-toolbar-button-id":ce.id,"data-toolbar-button-active":ce.active?"true":"false",onClick:ce.onClick,disabled:ce.disabled,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors disabled:opacity-50 ${ce.active?pe:"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,title:ce.title??ce.label,children:[ce.icon,o("span",{className:"hidden xl:inline",children:ce.label})]},ce.id)}),b&&u("button",{"data-testid":"stream-play-toggle","data-stream-playing":de?"true":"false",onClick:de?ae:J,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors ${de?"bg-danger/10 text-danger hover:bg-danger/20":"bg-primary/10 text-primary hover:bg-primary/20"}`,title:de?"Stop stream":"Start stream",children:[de?o(h$,{className:"h-3 w-3"}):o(Sl,{className:"h-3 w-3"}),o("span",{className:"hidden xl:inline",children:de?"Stop":"Play"})]}),w&&u("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:[o(Ny,{className:`h-3 w-3 ${y?"animate-spin":""}`}),o("span",{className:"hidden xl:inline",children:"Snapshot"})]}),(V||C||d||fe||m||re&&re.inputFps>0)&&u("div",{ref:se,className:"relative",children:[o("button",{onClick:()=>ee(ce=>!ce),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:o(g$,{className:"h-3.5 w-3.5"})}),G&&u("div",{className:"absolute right-0 top-full mt-1 z-30 min-w-[200px] rounded-lg border border-border bg-surface shadow-xl py-1.5",children:[v&&m&&u("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[u("div",{className:"flex justify-between gap-3",children:[o("span",{children:"Input"}),u("span",{className:"tabular-nums text-foreground",children:[m.inputFps.toFixed(1)," fps"]})]}),u("div",{className:"flex justify-between gap-3",children:[o("span",{children:"Decode"}),u("span",{className:"tabular-nums text-foreground",children:[m.decodeFps.toFixed(1)," fps"]})]}),u("div",{className:"flex justify-between gap-3",children:[o("span",{children:"Uptime"}),o("span",{className:"tabular-nums text-foreground",children:f$(m.uptimeMs)})]})]}),!v&&re&&re.inputFps>0&&u("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[u("div",{className:"flex justify-between gap-3",children:[o("span",{children:"Input"}),u("span",{className:"tabular-nums text-foreground",children:[re.inputFps.toFixed(1)," fps"]})]}),re.bitrateKbps>0&&u("div",{className:"flex justify-between gap-3",children:[o("span",{children:"Bitrate"}),u("span",{className:"tabular-nums text-foreground",children:[re.bitrateKbps," kbps"]})]})]}),(d||V&&fe)&&u("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[u("div",{className:"flex justify-between gap-3 items-center",children:[o("span",{children:"Phase"}),u("span",{className:`flex items-center gap-1 font-semibold uppercase tracking-wider ${ge?"text-red-400":"text-emerald-400"}`,children:[o("span",{className:`w-1.5 h-1.5 rounded-full ${ge?"bg-red-500 animate-pulse":"bg-emerald-500"}`}),ge?"Active":"Watching"]})]}),d&&d.detectionFps>0&&u("div",{className:"flex justify-between gap-3",children:[o("span",{children:"Detection"}),u("span",{className:"tabular-nums text-foreground",children:[d.detectionFps.toFixed(1)," det/s"]})]}),d&&d.avgInferenceMs>0&&u("div",{className:"flex justify-between gap-3",children:[o("span",{children:"Inference"}),u("span",{className:"tabular-nums text-foreground",children:[d.avgInferenceMs.toFixed(0)," ms"]})]})]}),V&&u(me,{children:[o(xi,{label:"Show detections",active:O,onClick:()=>j(ce=>!ce)}),o(xi,{label:"Show motion",active:F,onClick:()=>H(ce=>!ce)})]}),C&&o(xi,{label:"PTZ controls",active:E,onClick:()=>{I?.(),ee(!1)}})]})]})]})]}),de?o("div",{className:"aspect-video relative",children:o(xy,{serverUrl:e,streamKey:te,autoPlay:!0,className:"w-full h-full",createSession:X,sendAnswer:n,closeSession:r,overlay:ie||k||ue?u(me,{children:[ie&&o(by,{detections:f,showPhaseIndicator:!1,showMotionZones:F,showMotionRaw:F,showDetections:O}),k,ue&&A]}):void 0},te)}):o(x$,{src:x??null,isLoading:y,onPlay:J,onRetry:w,extraOverlay:k||ue?u(me,{children:[k,ue&&A]}):null,suppressPlayHover:!!k||ue}),N]})}function x$({src:e,isLoading:t,onPlay:n,onRetry:r,extraOverlay:s,suppressPlayHover:a=!1}){return e?u("div",{className:"relative w-full aspect-video bg-black/90 flex items-center justify-center",children:[o("img",{src:e,alt:"Camera snapshot",className:"w-full h-full object-contain"}),!a&&o("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:o("div",{className:"h-14 w-14 rounded-full bg-white/20 backdrop-blur-sm flex items-center justify-center",children:o(Sl,{className:"h-7 w-7 text-white ml-0.5"})})}),s]}):t?o("div",{className:"relative w-full aspect-video bg-black/90 flex items-center justify-center",children:o("div",{className:"h-8 w-8 border-2 border-white/20 border-t-white/60 rounded-full animate-spin"})}):o("div",{className:"relative w-full aspect-video bg-black/90 flex items-center justify-center",children:u("div",{className:"flex flex-col items-center gap-2 text-white/40",children:[o(b$,{className:"h-8 w-8"}),o("span",{className:"text-xs",children:"No snapshot available"}),u("div",{className:"flex items-center gap-2 mt-1",children:[r&&u("button",{onClick:r,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:[o(Ny,{className:"h-3 w-3"}),"Retry"]}),u("button",{onClick:n,className:"inline-flex items-center gap-1.5 rounded-md bg-primary/80 px-3 py-1.5 text-xs font-medium text-white hover:bg-primary transition-colors",children:[o(Sl,{className:"h-3 w-3"}),"Play Live"]})]})]})})}const Ju={value:"auto",label:"Auto (best available)"};function y$(e){return e.charAt(0).toUpperCase()+e.slice(1)}function v$({deviceId:e,value:t,onChange:n,disabled:r,label:s,className:a}){const i=Qn(),l=ab({deviceId:e},{refetchOnWindowFocus:!1}),[c,d]=P([Ju]);Y(()=>{if(!l.data)return;const h=`${e}/`,m=[Ju];for(const g of l.data){if(!g.enabled)continue;const b=g.brokerId.startsWith(h)?g.brokerId.slice(h.length):g.brokerId;m.push({value:b,label:y$(b)})}d(m)},[l.data,e]);const f=s??"Preferred stream",p=l.isLoading?"Loading available streams…":l.isError?"Could not load streams — only Auto available.":c.length===1?"No enabled streams found — only Auto available.":null;return u("div",{className:a,children:[o("label",{id:i,className:"text-xs font-medium text-foreground-muted block mb-1",children:f}),o(bo,{"aria-labelledby":i,options:c,value:t,disabled:r,onChange:h=>n(h.target.value)}),p!==null&&o("p",{className:"text-foreground-subtle text-[10px] mt-1",children:p})]})}function w$({samples:e,sampleRate:t=16e3,height:n=96,className:r="",color:s="#3b82f6",bgColor:a="transparent"}){const i=ne(null),l=ne(null),c=U(()=>{const p=i.current,h=l.current;if(!p||!h||!e||e.length===0)return;const m=h.clientWidth;if(m===0)return;const g=window.devicePixelRatio||1;p.width=m*g,p.height=n*g,p.style.width=`${m}px`,p.style.height=`${n}px`;const b=p.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 k=0,C=0;for(let z=v;z<N;z++){const $=e[z];$<k&&(k=$),$>C&&(C=$)}const E=y-C*y,A=y-k*y,I=Math.max(1,A-E);b.fillRect(w,E,1,I)}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]);Y(()=>{c()},[c]),Y(()=>{const p=new ResizeObserver(()=>c()),h=l.current;return h&&p.observe(h),()=>p.disconnect()},[c]);const f=((e&&t?Math.round(e.length/t*1e3):0)/1e3).toFixed(1);return u("div",{ref:l,className:`relative ${r}`,children:[o("canvas",{ref:i,className:"w-full rounded-md"}),e&&e.length>0&&u("div",{className:"absolute bottom-1 right-2 text-[10px] text-foreground-subtle/60 font-mono",children:[f,"s · ",t/1e3,"kHz · ",e.length.toLocaleString()," samples"]})]})}function N$({currentDbfs:e,durationSec:t=30,maxSamples:n=120,height:r=64,className:s="",color:a="#10b981",clipColor:i="#ef4444",clipThreshold:l=-6,minDbfs:c=-96}){const d=ne(null),f=ne(null),[p,h]=P([]);Y(()=>{e!==null&&h(b=>{const x=[...b,{dbfs:e,timestamp:Date.now()}];return x.length>n?x.slice(-n):x})},[e,n]);const m=U(()=>{const b=d.current,x=f.current;if(!b||!x)return;const y=x.clientWidth;if(y===0)return;const w=window.devicePixelRatio||1;b.width=y*w,b.height=r*w,b.style.width=`${y}px`,b.style.height=`${r}px`;const v=b.getContext("2d");if(!v||(v.scale(w,w),v.clearRect(0,0,y,r),p.length===0))return;const N=p[p.length-1].timestamp,k=t*1e3,C=N-k,E=p.filter($=>$.timestamp>=C);if(E.length===0)return;const A=Math.max(1,Math.floor(y/(t*2))),I=Math.abs(c);for(const $ of E){const B=$.timestamp-C,R=Math.floor(B/k*y),T=(Math.max(c,Math.min(0,$.dbfs))-c)/I,_=Math.max(1,T*r),L=$.dbfs>=l;v.fillStyle=L?i:a,v.globalAlpha=.8,v.fillRect(R,r-_,A,_)}v.globalAlpha=1;const z=r-(l-c)/I*r;v.strokeStyle=i,v.globalAlpha=.25,v.lineWidth=1,v.setLineDash([4,4]),v.beginPath(),v.moveTo(0,z),v.lineTo(y,z),v.stroke(),v.setLineDash([]),v.globalAlpha=1},[p,t,r,a,i,l,c]);Y(()=>{m()},[m]),Y(()=>{const b=new ResizeObserver(()=>m()),x=f.current;return x&&b.observe(x),()=>b.disconnect()},[m]);const g=p.length>0?p[p.length-1].dbfs:null;return u("div",{ref:f,className:`relative ${s}`,children:[o("canvas",{ref:d,className:"w-full rounded-md"}),u("div",{className:"absolute top-1 left-2 text-[9px] text-foreground-subtle/50 font-mono",children:[t,"s"]}),g!==null&&u("div",{className:"absolute bottom-1 right-2 text-[9px] text-foreground-subtle/50 font-mono",children:[g.toFixed(1)," dBFS · ",p.length," samples"]})]})}function k$(e){return e>=.8?"bg-emerald-500":e>=.5?"bg-amber-500":e>=.3?"bg-orange-500":"bg-zinc-500"}function S$(e){return e>=.8?"text-emerald-400":e>=.5?"text-amber-400":e>=.3?"text-orange-400":"text-zinc-400"}function C$({classifications:e,processing:t=!1,inferenceMs:n,maxItems:r=10,className:s=""}){const a=e.slice(0,r),i=a.length>0?a[0].score:1;return t?o("div",{className:`rounded-xl border border-border bg-surface p-4 text-center ${s}`,children:o("div",{className:"text-sm text-foreground-subtle animate-pulse",children:"Classifying audio..."})}):a.length===0?o("div",{className:`rounded-xl border border-border bg-surface p-4 text-center ${s}`,children:o("div",{className:"text-xs text-foreground-subtle",children:"No classifications yet"})}):u("div",{className:`rounded-xl border border-border bg-surface overflow-hidden ${s}`,children:[u("div",{className:"px-3 py-2 border-b border-border flex items-center justify-between",children:[o("h3",{className:"text-xs font-medium text-foreground",children:"Audio Classifications"}),u("div",{className:"flex items-center gap-3 text-[10px] text-foreground-subtle",children:[a.length<e.length&&u("span",{children:["showing ",a.length," of ",e.length]}),n!==void 0&&u("span",{className:"font-mono",children:[n.toFixed(1),"ms"]})]})]}),o("div",{className:"divide-y divide-border/50",children:a.map((l,c)=>{const d=i>0?l.score/i*100:0;return u("div",{className:"px-3 py-1.5 flex items-center gap-3 hover:bg-surface-hover/30",children:[o("span",{className:"text-[10px] text-foreground-subtle w-5 text-right font-mono",children:c+1}),o("span",{className:"text-xs font-medium text-foreground min-w-[120px]",children:l.className}),o("div",{className:"flex-1 h-2 rounded-full bg-zinc-800 overflow-hidden",children:o("div",{className:`h-full rounded-full transition-all duration-300 ${k$(l.score)}`,style:{width:`${d}%`}})}),u("span",{className:`text-xs font-mono font-semibold w-14 text-right ${S$(l.score)}`,children:[(l.score*100).toFixed(1),"%"]})]},`${l.className}-${c}`)})})]})}function M$({data:e,label:t="Response",className:n=""}){const[r,s]=P(!1);if(!e)return null;const a=JSON.stringify(e,null,2);return u("div",{className:`rounded-xl border border-border bg-surface overflow-hidden ${n}`,children:[u("div",{className:"px-3 py-2 border-b border-border flex items-center justify-between cursor-pointer select-none hover:bg-surface-hover/30",onClick:()=>s(i=>!i),children:[u("div",{className:"flex items-center gap-2",children:[o("span",{className:"text-[10px] text-foreground-subtle",children:r?"▼":"▶"}),o("h3",{className:"text-xs font-medium text-foreground",children:t})]}),o("span",{className:"text-[10px] text-foreground-subtle font-mono",children:a.length>1e3?`${(a.length/1024).toFixed(1)} KB`:`${a.length} bytes`})]}),r&&o("div",{className:"max-h-80 overflow-y-auto overflow-x-auto",children:o("pre",{className:"p-3 text-[10px] leading-4 font-mono text-foreground-subtle whitespace-pre",children:a})})]})}const E$={Activity:Nn,Eye:Oo,AlertTriangle:zo,PauseCircle:Qk,PowerOff:U5};function ld({phase:e,...t}){const n=rr(e),r=E$[n.icon];return o(r,{...t})}function Vn(e){const[t,n]=P([]),r=U(a=>{n(i=>{const l=[...i,a];return l.length>e?l.slice(-e):l})},[e]),s=U(()=>{n([])},[]);return q(()=>({entries:t,append:r,reset:s}),[t,r,s])}function ep(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 tp={error:{icon:va,color:"text-red-400"},warn:{icon:zo,color:"text-amber-400"},info:{icon:w5,color:"text-blue-400"},debug:{icon:Ak,color:"text-gray-500"}},np={debug:0,info:1,warn:2,error:3},I$=["all","debug","info","warn","error"],A$=500;function P$(e,t){return t?(np[e]??0)>=(np[t]??0):!0}function Xt({agentId:e,addonId:t,deviceId:n,integrationId:r,requestId:s,level:a,maxHeight:i="max-h-96",showScope:l=!1,showFilters:c=!0,limit:d=100,liveBuffer:f,onClose:p,className:h}){const[m,g]=P(""),[b,x]=P(""),[y,w]=P(a),v=e,N=t??(m||void 0),k=n??(b?Number(b):void 0),C=r,E=s,A=q(()=>{const V={};return v&&(V.agentId=v),N&&(V.addonId=N),k!==void 0&&Number.isFinite(k)&&(V.deviceId=k),C&&(V.integrationId=C),E&&(V.requestId=E),Object.keys(V).length>0?V:void 0},[v,N,k,C,E]),I=Vn(A$),z=f??I,$=z.entries,[B,R]=P(0),[M,T]=P(!1),[_,L]=P(!1),[O,j]=P(new Set),[F,H]=P(""),D=ne(null),Q=`${v??""}:${N??""}:${String(k??"")}:${C??""}:${E??""}`,G=ne(Q);Y(()=>{G.current!==Q&&(G.current=Q,z.reset(),R(0),j(new Set))},[Q,z]);const{data:ee,isLoading:se}=S.logs.query.useQuery({...A?{tags:A}:{},limit:d},{staleTime:3e4});S.logs.subscribe.useSubscription({...A?{tags:A}:{}},{onData:V=>{z.append(V)}});const te=ne($.length);Y(()=>{const V=D.current;if(!V){te.current=$.length;return}const ie=te.current;if(te.current=$.length,!($.length<=ie)){if(M&&V.scrollTop<=8)V.scrollTo({top:0});else if(!M&&V.scrollTop>0){const ue=V.querySelector("tbody tr"),de=ue instanceof HTMLElement?ue.offsetHeight:24;V.scrollTop+=de*($.length-ie)}}},[$.length,M]);const Z=q(()=>{const V=(ee??[]).map(pe=>({timestamp:pe.timestamp,level:pe.level,message:pe.message,scope:pe.scope,tags:pe.tags,meta:pe.meta})),ie=new Set,ue=[];for(const pe of[...$].reverse()){const _e=`${pe.timestamp}|${pe.level}|${pe.scope??""}|${pe.message}`;ie.has(_e)||(ie.add(_e),ue.push(pe))}for(const pe of V){const _e=`${pe.timestamp}|${pe.level}|${pe.scope??""}|${pe.message}`;ie.has(_e)||(ie.add(_e),ue.push(pe))}const ce=(B>0?ue.filter(pe=>new Date(pe.timestamp).getTime()>B):ue).filter(pe=>P$(pe.level,y)),Se=F.trim().toLowerCase();return Se?ce.filter(pe=>{if(pe.message.toLowerCase().includes(Se)||pe.scope&&pe.scope.toLowerCase().includes(Se))return!0;if(pe.tags){for(const _e of Object.values(pe.tags))if(_e!==void 0&&String(_e).toLowerCase().includes(Se))return!0}if(pe.meta){for(const _e of Object.values(pe.meta))if(_e!=null&&ep(_e).toLowerCase().includes(Se))return!0}return!1}):ce},[ee,$,y,B,F]),re=U(()=>{const V=Z.map(ie=>{const ue=new Date(ie.timestamp).toLocaleTimeString(),de=ie.tags?" "+Object.entries(ie.tags).filter(([,ce])=>ce).map(([ce,Se])=>`${ce}=${Se}`).join(" "):"";return`${ue} [${ie.level.toUpperCase()}]${ie.scope?` [${ie.scope}]`:""}${de} ${ie.message}`});navigator.clipboard.writeText(V.join(`
537
- `)).then(()=>{L(!0),setTimeout(()=>L(!1),1500)})},[Z]),be=S.logs.clear.useMutation(),X=U(()=>{R(Date.now()),z.reset(),be.mutate({...A?{tags:A}:{}})},[z,be,A]),K=U(V=>{j(ie=>{const ue=new Set(ie);return ue.has(V)?ue.delete(V):ue.add(V),ue})},[]),[J,ae]=P(null),fe=U((V,ie)=>{const ue=new Date(V.timestamp).toISOString(),de=V.tags?" "+Object.entries(V.tags).filter(([,pe])=>pe).map(([pe,_e])=>`${pe}=${_e}`).join(" "):"",ce=V.meta&&Object.keys(V.meta).length>0?` meta=${JSON.stringify(V.meta)}`:"",Se=`${ue} [${V.level.toUpperCase()}]${V.scope?` [${V.scope}]`:""}${de} ${V.message}${ce}`;navigator.clipboard.writeText(Se).then(()=>{ae(ie),setTimeout(()=>ae(pe=>pe===ie?null:pe),1200)})},[]),ge=U(V=>`${V.timestamp}|${V.level}|${V.scope??""}|${V.message}`,[]);return u("div",{className:W("h-full min-h-0 flex flex-col",h),onClick:V=>V.stopPropagation(),children:[u("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[o("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle font-medium",children:"Logs"}),v&&o(yi,{label:"agent",value:v}),N&&o(yi,{label:"addon",value:N}),k!==void 0&&o(yi,{label:"device",value:`#${k}`}),o("div",{className:"flex rounded border border-border overflow-hidden text-[9px]",children:I$.map(V=>u("button",{type:"button",onClick:()=>w(V==="all"?void 0:V),className:W("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))}),o(vi,{icon:fc,label:M?"Auto":"Paused",active:!M,onClick:()=>{T(V=>!V),!M&&D.current&&D.current.scrollTo({top:0,behavior:"smooth"})}}),o(vi,{icon:_n,label:_?"Copied!":"Copy",onClick:re,disabled:Z.length===0}),o(vi,{icon:Kt,label:"Clear",onClick:X}),u("div",{className:"relative",children:[o("input",{type:"text",value:F,onChange:V=>H(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"}),F&&o("button",{type:"button",onClick:()=>H(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",title:"Clear search",children:o(Ye,{className:"h-2.5 w-2.5"})})]}),$.length>0&&u("span",{className:"text-[9px] text-emerald-400 font-medium",children:["+",$.length," live"]})]}),p&&o("button",{type:"button",onClick:p,className:"text-foreground-subtle hover:text-foreground",children:o(Ye,{className:"h-3.5 w-3.5"})})]}),c&&(!t||!n)&&u("div",{className:"flex items-center gap-2 px-3 py-1 border-b border-border/50 bg-surface/50 text-[10px]",children:[!t&&u("label",{className:"flex items-center gap-1",children:[o("span",{className:"text-foreground-subtle",children:"Addon:"}),o("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&&u("label",{className:"flex items-center gap-1",children:[o("span",{className:"text-foreground-subtle",children:"Device:"}),o("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"})]})]}),u("div",{ref:D,className:W("flex-1 min-h-0 overflow-auto font-mono text-[10px]",i),children:[se&&u("div",{className:"flex items-center justify-center gap-2 py-6 text-foreground-subtle",children:[o(Ot,{className:"h-3.5 w-3.5 animate-spin"}),"Loading logs..."]}),!se&&Z.length===0&&o("div",{className:"py-4 text-center text-foreground-subtle",children:"No logs found"}),Z.length>0&&o("table",{className:"w-full",children:o("tbody",{children:Z.map(V=>{const ie=tp[V.level]??tp.info,ue=ie.icon,de=ge(V),ce=O.has(de),Se=V.tags&&Object.keys(V.tags).length>0,pe=V.meta&&Object.keys(V.meta).length>0,_e=Se||pe;return u("tr",{className:W("hover:bg-surface-hover/30 border-b border-border/30",_e&&"cursor-pointer"),onClick:_e?()=>K(de):void 0,children:[o("td",{className:"px-2 py-1 text-foreground-subtle whitespace-nowrap align-top w-[70px]",children:new Date(V.timestamp).toLocaleTimeString()}),o("td",{className:W("px-1 py-1 align-top w-5",ie.color),children:o(ue,{className:"h-3 w-3"})}),l&&o("td",{className:"px-2 py-1 text-foreground-subtle align-top truncate max-w-[120px]",title:V.scope,children:V.scope?.replace(/^addon:/,"")??""}),o("td",{className:"px-2 py-1 text-foreground break-all",children:u("div",{className:"flex items-start gap-1",children:[_e&&(ce?o(or,{className:"h-3 w-3 text-foreground-subtle shrink-0 mt-0.5"}):o(Pn,{className:"h-3 w-3 text-foreground-subtle shrink-0 mt-0.5"})),u("div",{className:"flex-1 min-w-0",children:[V.message,ce&&_e&&u("div",{className:"mt-1 text-[9px] text-foreground-subtle bg-surface rounded px-2 py-1 space-y-0.5",children:[pe&&Object.entries(V.meta).filter(([,Ae])=>Ae!==void 0&&Ae!=="").map(([Ae,We])=>u("div",{children:[o("span",{className:"text-amber-400/80 font-medium",children:Ae}),o("span",{className:"text-foreground-subtle",children:": "}),o("span",{className:"text-foreground break-all",children:ep(We)})]},`m-${Ae}`)),Se&&Object.entries(V.tags).filter(([,Ae])=>Ae!==void 0).map(([Ae,We])=>u("div",{children:[o("span",{className:"text-primary/70 font-medium",children:Ae}),o("span",{className:"text-foreground-subtle",children:": "}),o("span",{className:"text-foreground",children:We})]},`t-${Ae}`))]})]})]})}),o("td",{className:"px-1 py-1 align-top w-5",children:o(_$,{copied:J===de,onCopy:()=>fe(V,de)})})]},de)})})})]})]})}function ky({position:e="bottom",className:t,...n}){return o("div",{className:W(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:o(Xt,{maxHeight:"max-h-48",...n})})}function yi({label:e,value:t}){return u("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium",children:[e,": ",t]})}function _$({copied:e,onCopy:t}){return o("button",{type:"button",title:"Copy this row",onClick:n=>{n.stopPropagation(),t()},className:W("rounded p-0.5 transition-colors",e?"text-emerald-400":"text-foreground-subtle/60 hover:text-foreground hover:bg-surface-hover"),children:e?o(Ro,{className:"h-3 w-3"}):o(_n,{className:"h-3 w-3"})})}function vi({icon:e,label:t,onClick:n,disabled:r,active:s}){return u("button",{type:"button",onClick:n,disabled:r,className:W("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",r&&"opacity-40 cursor-not-allowed"),children:[o(e,{className:"h-2.5 w-2.5"}),t]})}function $$(e,t,n,r){if(r!==void 0&&(e.source.deviceId??(e.source.type==="device"&&typeof e.source.id=="number"?e.source.id:void 0))!==r||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 D$={[Ne.AddonStarted]:{icon:bl,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Started"},[Ne.AddonInstalled]:{icon:ml,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Installed"},[Ne.AddonRestarted]:{icon:gc,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Restarted"},[Ne.AddonUpdated]:{icon:Mm,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Updated"},[Ne.AddonStopped]:{icon:Mu,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"Stopped"},[Ne.AddonUninstalled]:{icon:Kt,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"Uninstalled"},[Ne.AddonCrashed]:{icon:va,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Crashed"},[Ne.AddonError]:{icon:zo,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Error"},[Ne.DetectionPhaseTransition]:{icon:Nn,color:"bg-violet-500/15 text-violet-400 border-violet-500/30",label:"Phase"},[Ne.DetectionResult]:{icon:tS,color:"bg-purple-500/15 text-purple-400 border-purple-500/30",label:"Detection"},[Ne.DetectionEvent]:{icon:Oo,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Event"},[Ne.DetectionCameraNative]:{icon:Eu,color:"bg-cyan-500/15 text-cyan-400 border-cyan-500/30",label:"Camera AI"},[Ne.ProviderMotion]:{icon:Iu,color:"bg-orange-500/15 text-orange-400 border-orange-500/30",label:"Motion"},[Ne.MotionOnMotionChanged]:{icon:Iu,color:"bg-orange-500/15 text-orange-400 border-orange-500/30",label:"Motion"},[Ne.MotionAnalysis]:{icon:Nn,color:"bg-orange-500/10 text-orange-300 border-orange-500/20",label:"Motion analysis"},[Ne.MotionZonesRaw]:{icon:Nn,color:"bg-orange-500/10 text-orange-300 border-orange-500/20",label:"Motion zones"},[Ne.ProviderDetection]:{icon:Eu,color:"bg-cyan-500/15 text-cyan-400 border-cyan-500/30",label:"Provider Det"},[Ne.PipelineAudioInferenceResult]:{icon:vm,color:"bg-pink-500/15 text-pink-400 border-pink-500/30",label:"Audio"},[Ne.AgentOnline]:{icon:bl,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Agent Online"},[Ne.AgentOffline]:{icon:Mu,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Agent Offline"},[Ne.DeviceRegistered]:{icon:ml,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Registered"},[Ne.DeviceUnregistered]:{icon:Kt,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Unregistered"},[Ne.DeviceStateChanged]:{icon:Nn,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"State"}};function Cl(e,t){const n=D$[e]??{icon:bl,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:e.split(".").pop()??e};if(e===Ne.DeviceStateChanged&&t&&typeof t.capName=="string"){const r=t.capName;return{...n,label:r}}return n}const hr=Object.freeze([...new Set(Object.values(Ne))].sort()),T$=Object.freeze([Ne.PipelineCameraMetricsSnapshot,Ne.PipelineRunnerLoadSnapshot,Ne.PipelineEngineMetricsSnapshot,Ne.PipelineInferenceResult,Ne.PipelineTrace,Ne.PipelineProgress,Ne.StreamBrokerMetricsSnapshot,Ne.MetricsNodeResourcesSnapshot,Ne.MetricsNodeProcessesSnapshot,Ne.ClusterTopologySnapshot,Ne.MotionAnalysis,Ne.MotionZonesRaw,Ne.DetectionResult,Ne.PipelineAudioInferenceResult,Ne.PlatformProbePhase,Ne.BenchmarkProgress,Ne.ModelDownloadProgress]),L$=new Set(T$),R$=Object.freeze(hr.filter(e=>!L$.has(e)));function Ds(e,t){if(e===Ne.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===Ne.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,f=typeof d=="string"?d:"";f&&i.set(f,(i.get(f)??0)+1)}return[...i.entries()].map(([l,c])=>c>1?`${l} ×${c}`:l).join(", ")}if(e===Ne.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:"",f=l.score;return f?`${d} (${Math.round(f*100)}%)`:d}).filter(Boolean).join(", ")}if(e===Ne.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===Ne.ProviderMotion)return t.active===!0?"motion start":"motion stop";if(e===Ne.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===Ne.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===Ne.ProviderDetection||e===Ne.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,r=t.error;return r||(n?`addon: ${n}`:null)}function O$(e){const t=e.category;return t===Ne.DetectionResult||t===Ne.PipelineAudioInferenceResult?Ds(t,e.data)!==null:!0}const B$=300;function cr({agentId:e,addonId:t,deviceId:n,defaultCategories:r,categories:s,category:a,maxHeight:i="max-h-96",limit:l=50,showCategoryFilter:c=!0,showFilters:d=!1,liveBuffer:f,onClose:p,className:h}){const m=q(()=>r??s??R$,[r,s]),g=q(()=>[...m].sort().join(","),[m]),[b,x]=P(()=>new Set(m)),y=ne(g);Y(()=>{y.current!==g&&(y.current=g,x(new Set(m)))},[g,m]);const w=Vn(B$),v=f??w,N=v.entries,[k,C]=P(!0),[E,A]=P(new Set),[I,z]=P(""),[$,B]=P(!1),[R,M]=P(""),[T,_]=P(0),L=ne(null),O=ne(null),j=`${e??""}:${t??""}:${String(n??"")}:${a??""}`,F=ne(j);Y(()=>{F.current!==j&&(F.current=j,v.reset(),A(new Set),_(0))},[j,v]),Y(()=>{if(!$)return;const he=Pe=>{const Te=O.current;Te&&Pe.target instanceof Node&&!Te.contains(Pe.target)&&B(!1)};return document.addEventListener("mousedown",he),()=>{document.removeEventListener("mousedown",he)}},[$]);const H=q(()=>{const he={};return e&&(he.agentId=e),t&&(he.addonId=t),n!==void 0&&(he.deviceId=n),a&&(he.category=a),he},[e,t,n,a]),D=q(()=>[...b].sort(),[b]),Q=q(()=>D.join(","),[D]),G=q(()=>{const he={...H,limit:l};return D.length>0&&D.length<hr.length&&(he.category=D),he},[H,l,Q,D]),{data:ee,isLoading:se}=S.systemEvents.getRecent.useQuery(G,{staleTime:3e4}),te=ne(b);Y(()=>{te.current=b},[b]);const Z=H;S.systemEvents.subscribe.useSubscription(Z,{onData:he=>{const Pe=he;Pe?.id&&$$(Pe,e,t,n)&&te.current.has(Pe.category)&&v.append(Pe)}});const re=ne(N.length);Y(()=>{const he=L.current;if(!he){re.current=N.length;return}const Pe=re.current;if(re.current=N.length,!(N.length<=Pe)){if(k&&he.scrollTop<=8)he.scrollTo({top:0});else if(!k&&he.scrollTop>0){const Te=he.firstElementChild?.firstElementChild,Re=Te instanceof HTMLElement?Te.offsetHeight:28;he.scrollTop+=Re*(N.length-Pe)}}},[N.length,k]);const be=q(()=>{const he=new Map;for(const Re of ee??[])he.set(Re.id,Re);for(const Re of N)he.set(Re.id,Re);let Pe=[...he.values()].filter(Re=>b.has(Re.category)).filter(O$);T>0&&(Pe=Pe.filter(Re=>new Date(Re.timestamp).getTime()>T));const Te=I.trim().toLowerCase();return Te&&(Pe=Pe.filter(Re=>{if(Re.category.toLowerCase().includes(Te)||Cl(Re.category,Re.data).label.toLowerCase().includes(Te))return!0;const Ln=Ds(Re.category,Re.data);if(Ln&&Ln.toLowerCase().includes(Te))return!0;try{if(new Date(Re.timestamp).toLocaleTimeString().toLowerCase().includes(Te))return!0}catch{}try{if(JSON.stringify(Re.data).toLowerCase().includes(Te)||JSON.stringify(Re.source).toLowerCase().includes(Te))return!0}catch{}return!1})),Pe.sort((Re,Tn)=>new Date(Tn.timestamp).getTime()-new Date(Re.timestamp).getTime())},[ee,N,b,I,T]),X=U(he=>{A(Pe=>{const Te=new Set(Pe);return Te.has(he)?Te.delete(he):Te.add(he),Te})},[]),K=U(he=>{x(Pe=>{const Te=new Set(Pe);return Te.has(he)?Te.delete(he):Te.add(he),Te})},[]),J=U(()=>{x(new Set(m)),z(""),_(0)},[m]),ae=U(()=>{_(Date.now()),v.reset()},[v]),[fe,ge]=P(!1),[V,ie]=P(null),ue=U(he=>{const Pe=new Date(he.timestamp).toISOString(),Te=Ds(he.category,he.data)??"",Re=Te?` ${Te}`:"";return`${Pe} [${he.category}]${Re} data=${JSON.stringify(he.data)}`},[]),de=U(()=>{const he=be.map(ue);navigator.clipboard.writeText(he.join(`
538
- `)).then(()=>{ge(!0),setTimeout(()=>ge(!1),1500)})},[be,ue]),ce=U(he=>{navigator.clipboard.writeText(ue(he)).then(()=>{ie(he.id),setTimeout(()=>ie(Pe=>Pe===he.id?null:Pe),1200)})},[ue]),Se=U(()=>{x(new Set(hr))},[]),pe=U(()=>{x(new Set)},[]),_e=q(()=>{const he=R.trim().toLowerCase();return he?hr.filter(Pe=>Pe.toLowerCase().includes(he)):hr},[R]),Ae=hr.length,We=b.size,st=We===Ae,ur=st?"All":`${We}/${Ae}`;return u("div",{className:W("h-full min-h-0 flex flex-col",h),onClick:he=>he.stopPropagation(),children:[u("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[o("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle font-medium",children:"Events"}),e&&o(is,{label:"agent",value:e}),t&&o(is,{label:"addon",value:t}),n!==void 0&&o(is,{label:"device",value:`#${n}`}),a&&o(is,{label:"category",value:a}),u("button",{type:"button",onClick:()=>{C(he=>!he),!k&&L.current&&L.current.scrollTo({top:0,behavior:"smooth"})},className:W("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",k?"border-border text-foreground-subtle hover:text-foreground":"border-amber-500/30 bg-amber-500/10 text-amber-400"),children:[o(fc,{className:"h-2.5 w-2.5"}),k?"Auto":"Paused"]}),c&&u("div",{className:"relative",ref:O,children:[u("button",{type:"button",onClick:()=>B(he=>!he),className:W("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",st?"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:[o(bm,{className:"h-2.5 w-2.5"}),"Filter (",ur,")"]}),$&&o(z$,{search:R,onSearchChange:M,categories:_e,active:b,onToggle:K,onSelectAll:Se,onSelectNone:pe,onResetDefaults:J})]}),u("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:"Reset filters to defaults",children:[o(km,{className:"h-2.5 w-2.5"}),"Reset"]}),u("button",{type:"button",onClick:ae,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:[o(Kt,{className:"h-2.5 w-2.5"}),"Clear"]}),u("button",{type:"button",onClick:de,disabled:be.length===0,className:W("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",fe?"border-emerald-500/30 bg-emerald-500/10 text-emerald-400":"border-border text-foreground-subtle hover:text-foreground",be.length===0&&"opacity-40 cursor-not-allowed"),title:"Copy all visible events",children:[o(_n,{className:"h-2.5 w-2.5"}),fe?"Copied!":"Copy"]}),u("div",{className:"relative",children:[o("input",{type:"text",value:I,onChange:he=>z(he.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"}),I&&o("button",{type:"button",onClick:()=>z(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",title:"Clear search",children:o(Ye,{className:"h-2.5 w-2.5"})})]}),N.length>0&&u("span",{className:"text-[9px] text-emerald-400 font-medium",children:["+",N.length," live"]})]}),p&&o("button",{type:"button",onClick:p,className:"text-foreground-subtle hover:text-foreground",children:o(Ye,{className:"h-3.5 w-3.5"})})]}),u("div",{ref:L,className:W("flex-1 min-h-0 overflow-auto text-[10px]",i),children:[se&&u("div",{className:"flex items-center justify-center gap-2 py-6 text-foreground-subtle",children:[o(Ot,{className:"h-3.5 w-3.5 animate-spin"}),"Loading events..."]}),!se&&be.length===0&&o("div",{className:"py-4 text-center text-foreground-subtle",children:"No events found"}),be.length>0&&o("div",{className:"divide-y divide-border/30",children:be.map(he=>{const Pe=Cl(he.category,he.data),Te=Pe.icon,Re=Ds(he.category,he.data),Tn=E.has(he.id);return u("div",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-surface-hover/30 cursor-pointer",onClick:()=>X(he.id),children:[o("span",{className:"text-foreground-subtle whitespace-nowrap w-[70px] shrink-0 pt-0.5",children:new Date(he.timestamp).toLocaleTimeString()}),o(j$,{copied:V===he.id,onCopy:()=>ce(he)}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-1.5",children:[Tn?o(or,{className:"h-3 w-3 text-foreground-subtle shrink-0"}):o(Pn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),u("span",{className:W("inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[9px] font-medium",Pe.color),children:[o(Te,{className:"h-2.5 w-2.5"}),Pe.label]}),he.source.nodeId&&he.source.nodeId!=="hub"&&o("span",{className:"text-[9px] px-1 py-0.5 rounded bg-foreground-subtle/10 text-foreground-subtle font-mono",children:he.source.nodeId})]}),Re&&o("p",{className:"text-foreground-subtle text-[10px] mt-0.5 ml-5",children:Re}),Tn&&u("div",{className:"mt-1 ml-5 text-[9px] bg-surface rounded px-2 py-1.5 space-y-0.5 font-mono overflow-x-auto",children:[u("div",{children:[o("span",{className:"text-primary/70",children:"source"}),o("span",{className:"text-foreground-subtle",children:": "}),o("span",{className:"text-foreground",children:JSON.stringify(he.source)})]}),u("div",{children:[o("span",{className:"text-primary/70",children:"category"}),o("span",{className:"text-foreground-subtle",children:": "}),o("span",{className:"text-foreground",children:he.category})]}),Object.entries(he.data).map(([Ln,Kr])=>u("div",{children:[o("span",{className:"text-primary/70",children:Ln}),o("span",{className:"text-foreground-subtle",children:": "}),o("span",{className:"text-foreground break-all",children:typeof Kr=="object"?JSON.stringify(Kr):String(Kr)})]},Ln))]})]})]},he.id)})})]})]})}function z$({search:e,onSearchChange:t,categories:n,active:r,onToggle:s,onSelectAll:a,onSelectNone:i,onResetDefaults:l}){return u("div",{className:"absolute z-20 top-full mt-1 left-0 w-72 max-h-80 rounded-md border border-border bg-surface shadow-lg flex flex-col",onClick:c=>c.stopPropagation(),children:[u("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border/50",children:[o(go,{className:"h-3 w-3 text-foreground-subtle"}),o("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&&o("button",{type:"button",onClick:()=>t(""),className:"text-foreground-subtle hover:text-foreground",children:o(Ye,{className:"h-2.5 w-2.5"})})]}),u("div",{className:"flex items-center gap-1 px-2 py-1 border-b border-border/50 text-[9px]",children:[o("button",{type:"button",onClick:a,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"All"}),o("button",{type:"button",onClick:i,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"None"}),o("button",{type:"button",onClick:l,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"Defaults"})]}),u("div",{className:"overflow-y-auto flex-1",children:[n.length===0&&o("div",{className:"text-[10px] text-foreground-subtle italic px-2 py-3 text-center",children:"No matches"}),n.map(c=>{const d=r.has(c),f=Cl(c),p=f.icon;return u("button",{type:"button",onClick:()=>s(c),className:"w-full flex items-center gap-2 px-2 py-1 text-left hover:bg-surface-hover/40 text-[10px]",children:[o("input",{type:"checkbox",readOnly:!0,checked:d,className:"accent-violet-500"}),u("span",{className:W("inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[9px] font-medium shrink-0",f.color),children:[o(p,{className:"h-2.5 w-2.5"}),f.label]}),o("span",{className:"text-foreground-subtle font-mono truncate",children:c})]},c)})]})]})}function F$({position:e="bottom",className:t,...n}){return o("div",{className:W(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:o(cr,{maxHeight:"max-h-48",...n})})}function is({label:e,value:t}){return u("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium",children:[e,": ",t]})}function j$({copied:e,onCopy:t}){return o("button",{type:"button",title:"Copy this event",onClick:n=>{n.stopPropagation(),t()},className:W("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?o(Ro,{className:"h-3 w-3"}):o(_n,{className:"h-3 w-3"})})}function Sy({deviceId:e,className:t="",onOpenChild:n}){const r=S.useUtils(),s=S.deviceDiscovery.listDiscovered.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),a=S.deviceDiscovery.getStatus.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),i=S.deviceDiscovery.refreshDiscovery.useMutation({onSuccess:()=>{r.deviceDiscovery.listDiscovered.invalidate({deviceId:e}),r.deviceDiscovery.getStatus.invalidate({deviceId:e})}}),l=S.deviceDiscovery.adoptDevice.useMutation({onSuccess:()=>{r.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),c=S.deviceDiscovery.releaseDevice.useMutation({onSuccess:()=>{r.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),[d,f]=P(null),{available:p,adopted:h}=q(()=>{const v=s.data??[],N=C=>typeof C.metadata.rtspChannel=="number"?C.metadata.rtspChannel:Number.POSITIVE_INFINITY,k=(C,E)=>{const A=N(C),I=N(E);return A!==I?A-I:C.name.localeCompare(E.name)};return{available:v.filter(C=>!C.alreadyAdopted).sort(k),adopted:v.filter(C=>C.alreadyAdopted).sort(k)}},[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){f(v.childNativeId);try{await l.mutateAsync({deviceId:e,childNativeId:v.childNativeId})}finally{f(null)}}async function w(v){if(v.adoptedDeviceId!=null){f(v.childNativeId);try{await c.mutateAsync({deviceId:e,childDeviceId:v.adoptedDeviceId})}finally{f(null)}}}return u("div",{className:`rounded-xl border border-border bg-surface ${t}`,children:[u("div",{className:"flex items-start justify-between gap-2 border-b border-border px-3 py-2 sm:px-5 sm:py-3",children:[u("div",{className:"min-w-0",children:[o("h3",{className:"text-sm font-semibold text-foreground",children:"Discovered devices"}),u("p",{className:"text-[11px] text-foreground-subtle",children:["Channels behind this hub. Click ",o("span",{className:"font-medium",children:"Add"})," to promote a channel to a managed device, or ",o("span",{className:"font-medium",children:"Remove"})," to detach."]})]}),u("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?o(Ot,{className:"h-3.5 w-3.5 animate-spin"}):o(gc,{className:"h-3.5 w-3.5"}),o("span",{className:"hidden sm:inline",children:"Refresh"})]})]}),g?u("div",{className:"flex items-start gap-2 border-b border-border bg-destructive/10 px-5 py-2 text-[11px] text-destructive",children:[o(zo,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),u("span",{children:["Last refresh failed: ",g]})]}):null,s.isLoading?o("div",{className:"flex items-center justify-center py-8 text-foreground-subtle",children:o(Ot,{className:"h-5 w-5 animate-spin"})}):p.length===0&&h.length===0?o("div",{className:"px-5 py-8 text-center text-xs text-foreground-subtle",children:"No channels reported by the hub yet. Click Refresh to enumerate."}):u(me,{children:[p.length>0?o(rp,{title:"Available to add",count:p.length,tone:"primary",children:p.map(v=>o(op,{child:v,busy:d===v.childNativeId,onAdopt:y,onRelease:w,onOpenChild:n},v.childNativeId))}):null,h.length>0?o(rp,{title:"Already adopted",count:h.length,tone:"muted",children:h.map(v=>o(op,{child:v,busy:d===v.childNativeId,onAdopt:y,onRelease:w,onOpenChild:n},v.childNativeId))}):null]}),b!=null?u("div",{className:"border-t border-border px-5 py-2 text-[10px] text-foreground-subtle",children:["Last refreshed ",new Date(b).toLocaleString()]}):null]})}function rp({title:e,count:t,tone:n,children:r}){return u("div",{className:"border-t border-border",children:[u("div",{className:`flex items-center justify-between border-b px-3 sm:px-5 py-1.5 text-[10px] uppercase tracking-wider ${n==="primary"?"bg-primary/5 text-primary border-primary/30":"bg-surface text-foreground-subtle border-border"}`,children:[o("span",{className:"font-semibold",children:e}),o("span",{className:"font-mono",children:t})]}),o("div",{className:"divide-y divide-border",children:r})]})}function op({child:e,busy:t,onAdopt:n,onRelease:r,onOpenChild:s}){return u("div",{className:"flex flex-wrap items-center justify-between gap-2 px-3 py-2 sm:px-5 sm:py-3 sm:flex-nowrap sm:gap-3",children:[u("div",{className:"min-w-0 flex-1",children:[u("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[o(H$,{status:e.status}),o("span",{className:"truncate text-sm font-medium text-foreground",children:e.name}),e.metadata.isDoorbell?o("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?o("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?o("span",{className:"rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle",children:"Multifocal"}):null]}),u("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle",children:[typeof e.metadata.rtspChannel=="number"?u("span",{children:["ch ",o("span",{className:"font-mono",children:e.metadata.rtspChannel})]}):null,e.metadata.model?o("span",{className:"truncate max-w-[160px]",children:e.metadata.model}):null,e.metadata.uid?u("span",{className:"font-mono truncate max-w-[140px]",children:[e.metadata.uid.slice(0,12),"…"]}):null]})]}),e.alreadyAdopted?u("div",{className:"flex items-center gap-2",children:[s&&e.adoptedDeviceId!==null?u("button",{type:"button",onClick:()=>s(e.adoptedDeviceId),className:"inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",title:"Open device detail",children:[o(mm,{className:"h-3.5 w-3.5"}),"Open"]}):null,u("button",{type:"button",onClick:()=>{r(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?o(Ot,{className:"h-3.5 w-3.5 animate-spin"}):o(Kt,{className:"h-3.5 w-3.5"}),"Remove"]})]}):u("button",{type:"button",onClick:()=>{n(e)},disabled:t,className:"inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50",children:[t?o(Ot,{className:"h-3.5 w-3.5 animate-spin"}):o(Bo,{className:"h-3.5 w-3.5"}),"Add"]})]})}function H$({status:e}){switch(e){case"online":return u("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/40 bg-emerald-500/10 px-2 py-0.5 text-[10px] font-medium text-emerald-500",children:[o(Em,{className:"h-2.5 w-2.5"})," online"]});case"sleeping":return u("span",{className:"inline-flex items-center gap-1 rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] font-medium text-amber-500",children:[o(mc,{className:"h-2.5 w-2.5"})," sleeping"]});case"offline":return u("span",{className:"inline-flex items-center gap-1 rounded-full border border-destructive/40 bg-destructive/10 px-2 py-0.5 text-[10px] font-medium text-destructive",children:[o($S,{className:"h-2.5 w-2.5"})," offline"]});case"unknown":default:return u("span",{className:"inline-flex items-center gap-1 rounded-full border border-border bg-surface px-2 py-0.5 text-[10px] font-medium text-foreground-subtle",children:[o(um,{className:"h-2.5 w-2.5"})," unknown"]})}}function V$(e,t){if(!e||typeof e!="object")return!1;const n=e;if(n.category!==Ne.DeviceStateChanged)return!1;const r=n.data;return!(!r||typeof r!="object"||r.deviceId!==t||typeof r.capName!="string"||!r.slice||typeof r.slice!="object")}function wi(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.id=="string"?t.id:null,r=typeof t.timestamp=="string"?t.timestamp:null,s=t.data;return!n||!r||!s||typeof s!="object"||typeof s.capName!="string"||!s.slice||typeof s.slice!="object"?null:{id:n,timestamp:r,capName:s.capName,slice:s.slice}}const q$=300,U$=Object.freeze([...new Set(PN.filter(e=>e.scope==="device").map(e=>e.name))].sort());function cd({deviceId:e,defaultCaps:t,maxHeight:n="max-h-96",limit:r=50,liveBuffer:s,onClose:a,className:i}){const l=q(()=>new Set(t??[]),[t]),[c,d]=P(l),[f,p]=P(""),[h,m]=P(!0),[g,b]=P(new Set),[x,y]=P(0),[w,v]=P(!1),[N,k]=P(""),C=ne(null),E=Vn(q$),A=s??E,I=A.entries,z=ne(null),$=ne(e);Y(()=>{$.current!==e&&($.current=e,A.reset(),b(new Set),y(0))},[e,A]);const B=q(()=>({deviceId:e,category:Ne.DeviceStateChanged,limit:r}),[e,r]),{data:R,isLoading:M}=S.systemEvents.getRecent.useQuery(B,{staleTime:3e4}),T=ne(c);Y(()=>{T.current=c},[c]),S.systemEvents.subscribe.useSubscription({deviceId:e,category:Ne.DeviceStateChanged},{onData:V=>{if(!V$(V,e))return;const ie=wi(V);if(!ie)return;const ue=T.current;ue.size>0&&!ue.has(ie.capName)||A.append(ie)}});const _=ne(I.length);Y(()=>{const V=z.current;if(!V){_.current=I.length;return}const ie=_.current;if(_.current=I.length,!(I.length<=ie)){if(h&&V.scrollTop<=8)V.scrollTo({top:0});else if(!h&&V.scrollTop>0){const ue=V.firstElementChild?.firstElementChild,de=ue instanceof HTMLElement?ue.offsetHeight:28,ce=I.length-ie;V.scrollTop+=de*ce}}},[I.length,h]);const L=q(()=>{const V=new Map;for(const de of R??[]){const ce=wi(de);ce&&V.set(ce.id,ce)}for(const de of I)V.set(de.id,de);let ie=[...V.values()];x>0&&(ie=ie.filter(de=>new Date(de.timestamp).getTime()>x)),c.size>0&&(ie=ie.filter(de=>c.has(de.capName)));const ue=f.trim().toLowerCase();return ue&&(ie=ie.filter(de=>{if(de.capName.toLowerCase().includes(ue))return!0;try{if(new Date(de.timestamp).toLocaleTimeString().toLowerCase().includes(ue))return!0}catch{}try{if(Object.entries(de.slice).map(([Se,pe])=>`${Se}=${Ni(pe)}`).join(" · ").toLowerCase().includes(ue))return!0}catch{}try{if(JSON.stringify(de.slice).toLowerCase().includes(ue))return!0}catch{}return!1})),ie.sort((de,ce)=>new Date(ce.timestamp).getTime()-new Date(de.timestamp).getTime())},[R,I,c,f,x]),O=q(()=>{const V=new Set(U$);for(const ie of R??[]){const ue=wi(ie);ue&&V.add(ue.capName)}for(const ie of I)V.add(ie.capName);return[...V].sort()},[R,I]),j=U(V=>{b(ie=>{const ue=new Set(ie);return ue.has(V)?ue.delete(V):ue.add(V),ue})},[]),F=U(V=>{d(ie=>{const ue=new Set(ie);return ue.has(V)?ue.delete(V):ue.add(V),ue})},[]),H=U(()=>{d(new Set(t??[])),p("")},[t]),D=U(()=>{y(Date.now()),A.reset()},[A]),[Q,G]=P(!1),[ee,se]=P(null),te=U(V=>`${new Date(V.timestamp).toISOString()} [${V.capName}] slice=${JSON.stringify(V.slice)}`,[]),Z=U(()=>{const V=L.map(te);navigator.clipboard.writeText(V.join(`
539
- `)).then(()=>{G(!0),setTimeout(()=>G(!1),1500)})},[L,te]),re=U(V=>{navigator.clipboard.writeText(te(V)).then(()=>{se(V.id),setTimeout(()=>se(ie=>ie===V.id?null:ie),1200)})},[te]),be=U(()=>{d(new Set(O))},[O]),X=U(()=>{d(new Set)},[]),K=q(()=>{const V=N.trim().toLowerCase();return V?O.filter(ie=>ie.toLowerCase().includes(V)):O},[N,O]),J=O.length,ae=c.size,fe=ae===0||ae===J,ge=fe?"All":`${ae}/${J}`;return Y(()=>{if(!w)return;const V=ie=>{const ue=C.current;ue&&!ue.contains(ie.target)&&v(!1)};return document.addEventListener("mousedown",V),()=>document.removeEventListener("mousedown",V)},[w]),u("div",{className:W("h-full min-h-0 flex flex-col",i),onClick:V=>V.stopPropagation(),children:[u("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[o("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle font-medium",children:"State"}),o(Q$,{label:"device",value:`#${e}`}),u("button",{type:"button",onClick:()=>{m(V=>!V),!h&&z.current&&z.current.scrollTo({top:0,behavior:"smooth"})},className:W("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:[o(fc,{className:"h-2.5 w-2.5"}),h?"Auto":"Paused"]}),u("div",{className:"relative",ref:C,children:[u("button",{type:"button",onClick:()=>v(V=>!V),className:W("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",fe?"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:[o(bm,{className:"h-2.5 w-2.5"}),"Filter (",ge,")"]}),w&&o(G$,{search:N,onSearchChange:k,caps:K,active:c,onToggle:F,onSelectAll:be,onSelectNone:X,onResetDefaults:H})]}),u("button",{type:"button",onClick:H,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:[o(km,{className:"h-2.5 w-2.5"}),"Reset"]}),u("button",{type:"button",onClick:D,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:[o(Kt,{className:"h-2.5 w-2.5"}),"Clear"]}),u("button",{type:"button",onClick:Z,disabled:L.length===0,className:W("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",Q?"border-emerald-500/30 bg-emerald-500/10 text-emerald-400":"border-border text-foreground-subtle hover:text-foreground",L.length===0&&"opacity-40 cursor-not-allowed"),title:"Copy all visible state changes",children:[o(_n,{className:"h-2.5 w-2.5"}),Q?"Copied!":"Copy"]}),u("div",{className:"relative",children:[o("input",{type:"text",value:f,onChange:V=>p(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"}),f&&o("button",{type:"button",onClick:()=>p(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",title:"Clear search",children:o(Ye,{className:"h-2.5 w-2.5"})})]}),I.length>0&&u("span",{className:"text-[9px] text-emerald-400 font-medium",children:["+",I.length," live"]})]}),a&&o("button",{type:"button",onClick:a,className:"text-foreground-subtle hover:text-foreground",children:o(Ye,{className:"h-3.5 w-3.5"})})]}),u("div",{ref:z,className:W("flex-1 min-h-0 overflow-auto text-[10px]",n),children:[M&&u("div",{className:"flex items-center justify-center gap-2 py-6 text-foreground-subtle",children:[o(Ot,{className:"h-3.5 w-3.5 animate-spin"}),"Loading state changes..."]}),!M&&L.length===0&&o("div",{className:"py-4 text-center text-foreground-subtle",children:"No state changes"}),L.length>0&&o("div",{className:"divide-y divide-border/30",children:L.map(V=>{const ie=g.has(V.id),ue=Object.entries(V.slice),de=ue.slice(0,3).map(([ce,Se])=>`${ce}=${Ni(Se)}`).join(" · ");return u("div",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-surface-hover/30 cursor-pointer",onClick:()=>j(V.id),children:[o("span",{className:"text-foreground-subtle whitespace-nowrap w-[70px] shrink-0 pt-0.5",children:new Date(V.timestamp).toLocaleTimeString()}),o(K$,{copied:ee===V.id,onCopy:()=>re(V)}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-1.5",children:[ie?o(or,{className:"h-3 w-3 text-foreground-subtle shrink-0"}):o(Pn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),o("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}),ue.length>3&&u("span",{className:"text-[9px] text-foreground-subtle",children:["+",ue.length-3," more"]})]}),de&&o("p",{className:"text-foreground-subtle text-[10px] mt-0.5 ml-5 truncate",children:de}),ie&&o("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:ue.length===0?o("div",{className:"text-foreground-subtle italic",children:"empty slice"}):ue.map(([ce,Se])=>u("div",{children:[o("span",{className:"text-primary/70",children:ce}),o("span",{className:"text-foreground-subtle",children:": "}),o("span",{className:"text-foreground break-all",children:Ni(Se)})]},ce))})]})]},V.id)})})]})]})}function Ni(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 Q$({label:e,value:t}){return u("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium",children:[e,": ",t]})}function G$({search:e,onSearchChange:t,caps:n,active:r,onToggle:s,onSelectAll:a,onSelectNone:i,onResetDefaults:l}){return u("div",{className:"absolute z-20 top-full mt-1 left-0 w-72 max-h-80 rounded-md border border-border bg-surface shadow-lg flex flex-col",onClick:c=>c.stopPropagation(),children:[u("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border/50",children:[o(go,{className:"h-3 w-3 text-foreground-subtle"}),o("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&&o("button",{type:"button",onClick:()=>t(""),className:"text-foreground-subtle hover:text-foreground",children:o(Ye,{className:"h-2.5 w-2.5"})})]}),u("div",{className:"flex items-center gap-1 px-2 py-1 border-b border-border/50 text-[9px]",children:[o("button",{type:"button",onClick:a,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"All"}),o("button",{type:"button",onClick:i,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"None"}),o("button",{type:"button",onClick:l,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"Defaults"})]}),u("div",{className:"overflow-y-auto flex-1",children:[n.length===0&&o("div",{className:"text-[10px] text-foreground-subtle italic px-2 py-3 text-center",children:"No matches"}),n.map(c=>{const d=r.has(c);return u("button",{type:"button",onClick:()=>s(c),className:"w-full flex items-center gap-2 px-2 py-1 text-left hover:bg-surface-hover/40 text-[10px]",children:[o("input",{type:"checkbox",readOnly:!0,checked:d,className:"accent-violet-500"}),o("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 K$({copied:e,onCopy:t}){return o("button",{type:"button",title:"Copy this state change",onClick:n=>{n.stopPropagation(),t()},className:W("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?o(Ro,{className:"h-3 w-3"}):o(_n,{className:"h-3 w-3"})})}const ki=500,W$=[{id:"logs",label:"Logs",icon:rS},{id:"events",label:"Events",icon:ya},{id:"state",label:"State",icon:s5}];function Y$({deviceId:e,defaultEventCategories:t,defaultStateCaps:n,initialTab:r="events",className:s,maxHeight:a="max-h-96"}){const[i,l]=P(r),c=Vn(ki),d=Vn(ki),f=Vn(ki),p=c.reset,h=d.reset,m=f.reset;return Y(()=>{p(),h(),m()},[e,p,h,m]),u("div",{className:W("flex flex-col h-full min-h-0",s),children:[o("div",{className:"flex items-center gap-1 mb-2 shrink-0",children:W$.map(({id:g,label:b,icon:x})=>u("button",{type:"button",onClick:()=>l(g),className:W("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:[o(x,{className:"h-3.5 w-3.5"}),b]},g))}),u("div",{className:"flex-1 min-h-0 overflow-hidden",children:[i==="logs"&&o(Xt,{deviceId:e,maxHeight:a,showFilters:!1,liveBuffer:c}),i==="events"&&o(cr,{deviceId:e,defaultCategories:t,maxHeight:a,showCategoryFilter:!0,liveBuffer:d}),i==="state"&&o(cd,{deviceId:e,defaultCaps:n,maxHeight:a,liveBuffer:f})]})]})}function Cy({label:e,icon:t,title:n="Confirm action",description:r,confirmLabel:s,triggerVariant:a="outline",confirmVariant:i="danger",size:l="sm",disabled:c,className:d,action:f,onSuccess:p}){const[h,m]=P(!1),[g,b]=P(!1),[x,y]=P(null),w=async()=>{y(null),b(!0);try{const v=await f();p?.(v),m(!1)}catch(v){y(v instanceof Error?v.message:String(v))}finally{b(!1)}};return u(me,{children:[u(Oe,{type:"button",variant:a,size:l,disabled:c,onClick:()=>{y(null),m(!0)},className:d,children:[t&&o(t,{className:"h-3.5 w-3.5"}),e]}),o(Dm,{open:h,onOpenChange:v=>!g&&m(v),children:u(Nc,{children:[u(Tm,{children:[u(Rm,{className:"flex items-center gap-2",children:[o(zo,{className:"h-4 w-4 text-amber-400"}),n]}),typeof r=="string"?o(Om,{children:r}):r]}),x&&o("div",{className:W("mt-2 px-3 py-2 rounded border border-danger/40 bg-danger/10","text-xs text-danger"),children:x}),u(Lm,{children:[o(Oe,{type:"button",variant:"ghost",size:l,disabled:g,onClick:()=>m(!1),children:"Cancel"}),u(Oe,{type:"button",variant:i,size:l,disabled:g,onClick:()=>{w()},children:[g&&o(Ot,{className:"h-3.5 w-3.5 animate-spin"}),s??e]})]})]})})]})}function ls({direction:e,icon:t,disabled:n,className:r,variant:s,onMove:a,onStart:i,onStop:l}){const[c,d]=P(null),[f,p]=P(!1),h=U(w=>{if(n)return;w.currentTarget.setPointerCapture(w.pointerId),d(Date.now()),p(!1);const v=setTimeout(()=>{p(!0),i(e)},250);w.currentTarget.dataset.timer=String(v)},[e,n,i]),m=U(w=>{const v=Number(w.currentTarget.dataset.timer);v&&clearTimeout(v),w.currentTarget.dataset.timer="",f?l():c!==null&&a(e),d(null),p(!1)},[f,e,a,l,c]),g=U(w=>{const v=Number(w.currentTarget.dataset.timer);v&&clearTimeout(v),w.currentTarget.dataset.timer="",f&&l(),d(null),p(!1)},[f,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 o("button",{type:"button",disabled:n,onPointerDown:h,onPointerUp:m,onPointerCancel:g,className:W("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,r),title:e,children:o(t,{className:x})})}function dd({controls:e,mode:t="overlay",showPresets:n,showZoom:r=!0,showHome:s=!0,className:a}){const{move:i,startContinuous:l,stopContinuous:c,zoom:d,goHome:f,goToPreset:p,presets:h,busy:m,error:g}=e,[b,x]=P(!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=W(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"),k=w?"h-9 w-9":"h-7 w-7",C=w?"h-4 w-4":"h-3.5 w-3.5",E=w?"text-foreground hover:bg-surface-hover":"text-white hover:bg-white/15",A=w?"h-12 w-px bg-border mx-1":"h-12 w-px bg-white/15 mx-1";return u("div",{className:W(v,a),children:[g&&u("div",{className:"rounded bg-danger/90 px-2 py-1 text-[10px] font-medium text-white shadow-lg max-w-[200px] self-center",children:["PTZ: ",g]}),u("div",{className:W(N,w&&"justify-center"),children:[u("div",{className:"grid grid-cols-3 gap-0.5",children:[o("span",{"aria-hidden":!0,className:w?"h-9 w-9":"h-7 w-7"}),o(ls,{direction:"up",icon:bk,variant:t,onMove:i,onStart:l,onStop:c}),o("span",{"aria-hidden":!0,className:w?"h-9 w-9":"h-7 w-7"}),o(ls,{direction:"left",icon:pk,variant:t,onMove:i,onStart:l,onStop:c}),o("span",{"aria-hidden":!0,className:w?"h-9 w-9":"h-7 w-7"}),o(ls,{direction:"right",icon:hk,variant:t,onMove:i,onStart:l,onStop:c}),o("span",{"aria-hidden":!0,className:w?"h-9 w-9":"h-7 w-7"}),o(ls,{direction:"down",icon:dk,variant:t,onMove:i,onStart:l,onStop:c}),o("span",{"aria-hidden":!0,className:w?"h-9 w-9":"h-7 w-7"})]}),(r||s)&&o("div",{className:A}),u("div",{className:"flex flex-col gap-0.5",children:[r&&u(me,{children:[o("button",{type:"button",onClick:()=>d("in"),disabled:m,title:"Zoom in",className:W("flex items-center justify-center rounded disabled:opacity-40",k,E),children:o(BS,{className:C})}),o("button",{type:"button",onClick:()=>d("out"),disabled:m,title:"Zoom out",className:W("flex items-center justify-center rounded disabled:opacity-40",k,E),children:o(FS,{className:C})})]}),s&&o("button",{type:"button",onClick:()=>f(),disabled:m,title:"Go home",className:W("flex items-center justify-center rounded disabled:opacity-40",k,E),children:o(xm,{className:C})})]}),y&&u("div",{className:"relative",children:[u("button",{type:"button",onClick:()=>x(I=>!I),disabled:m,className:W("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",o(or,{className:W("h-3 w-3 transition-transform",b&&"rotate-180")})]}),b&&o("div",{className:W("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(I=>o("button",{type:"button",onClick:()=>{p(I.id),x(!1)},disabled:m,className:W("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:I.name||I.id},I.id))})]})]})]})}function Z$(e,t){const n=document.createElement("a");n.href=t,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n)}function X$({trpc:e,deviceId:t,deviceName:n,size:r="sm",className:s}){const[a,i]=P(!1),[l,c]=P(!1),[d,f]=P(null),p=n.replace(/[^a-zA-Z0-9_.-]+/g,"_"),h=U(async k=>{i(!0),f(null),c(!1);try{const C=await e.snapshot.getSnapshot.query({deviceId:t,force:!0});if(!C)throw new Error("No snapshot available");const E=`data:${C.contentType};base64,${C.base64}`;if(k==="copy")try{await navigator.clipboard.writeText(E)}catch{throw new Error("Clipboard unavailable")}else{const A=C.contentType.includes("png")?"png":"jpg",I=new Date().toISOString().replace(/[:.]/g,"-");Z$(`${p}-${I}.${A}`,E)}c(!0),setTimeout(()=>c(!1),1500)}catch(C){f(C instanceof Error?C.message:String(C))}finally{i(!1)}},[e,t,p]),m=r==="md"?"h-9 px-3 text-sm gap-2":"h-7 px-2.5 text-[11px] gap-1.5",[g,b]=P(null),[x,y]=P(!1),w=()=>{y(!1);const k=setTimeout(()=>{y(!0),h("copy")},600);b(k)},v=()=>{g&&(clearTimeout(g),b(null)),x||h("download")},N=()=>{g&&(clearTimeout(g),b(null))};return u("button",{type:"button",title:"Click to download · long-press to copy",disabled:a,onPointerDown:w,onPointerUp:v,onPointerLeave:N,onPointerCancel:N,className:W("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?o(Ot,{className:"h-3.5 w-3.5 animate-spin"}):l?o(Ro,{className:"h-3.5 w-3.5 text-success"}):o(hc,{className:"h-3.5 w-3.5"}),"Snapshot"]})}function J$(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 ud({history:e,limit:t=5,latestIsFresh:n,className:r}){if(e.length===0)return null;const s=n?Mk:ya,a=e.slice(0,t);return u("div",{className:W("rounded-lg border border-border bg-surface px-3 py-2",r),children:[u("div",{className:"flex items-center gap-2 mb-2",children:[o(s,{className:W("h-4 w-4 text-amber-400",n&&"animate-pulse")}),o("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle",children:"Recent presses"}),o("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})]}),o("ul",{className:"space-y-1",children:a.map(i=>u("li",{className:"flex items-center justify-between text-[11px]",title:new Date(i.timestamp).toLocaleString(),children:[o("span",{className:"text-foreground",children:J$(i.timestamp)}),o("span",{className:"text-foreground-subtle font-mono text-[10px]",children:new Date(i.timestamp).toLocaleTimeString()})]},`${i.deviceId}-${i.timestamp}`))})]})}function My({items:e,header:t,triggerClassName:n,title:r="More actions"}){const[s,a]=P(!1),i=e.filter(l=>!l.hidden);return i.length===0?null:u(Zm,{open:s,onOpenChange:a,children:[o(Xm,{title:r,className:W("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:o(hm,{className:"h-4 w-4"})}),u(Jm,{className:"left-auto right-0 mt-1 min-w-[200px] p-1",children:[t&&o("div",{className:"px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle",children:t}),o("ul",{className:"space-y-0.5",children:i.map((l,c)=>u("li",{children:[l.separatorBefore&&c>0&&o("div",{className:"my-1 h-px bg-border"}),u("button",{type:"button",disabled:l.disabled,onClick:()=>{l.disabled||(l.onClick(),a(!1))},className:W("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&&o(l.icon,{className:W("h-3.5 w-3.5 shrink-0 mt-0.5",l.danger&&"text-danger/80")}),u("span",{className:"flex-1 min-w-0",children:[o("span",{className:"block leading-tight",children:l.label}),l.description&&o("span",{className:"block mt-0.5 text-[10px] text-foreground-subtle leading-tight",children:l.description})]})]})]},l.id))})]})]})}const eD=[{value:"view",label:"View",icon:Oo,hint:"Read-only — queries + subscriptions"},{value:"create",label:"Create",icon:z5,hint:"Mutations that create or update"},{value:"delete",label:"Delete",icon:Kt,hint:"Destructive ops (delete/revoke/reset/…)"}],tD=["device","system"];function nD(){return{type:"capability",target:"",access:["view"]}}function rD(e){if(e==null)return[];const t=new Set;for(const n of e)if(n.type==="device")for(const r of n.targets)t.add(r);return[...t]}function oD(e,t,n,r){let s;switch(e){case"addon":s=n;break;case"capability":s=r;break;case"category":s=tD.map(i=>({value:i,label:i}));break}if(t==null)return s;const a=new Set(t.filter(i=>i.type!=="device"&&i.type===e).map(i=>i.target));return s.filter(i=>a.has(i.value))}function sD(e,t){if(t==null)return["view","create","delete"];const n=t.filter(s=>s.type!==e.type?!1:s.type==="device"&&e.type==="device"?s.targets.some(a=>e.targets.includes(a)):s.type!=="device"&&e.type!=="device"?s.target===e.target:!1);if(n.length===0)return[];const r=new Set;for(const s of n)for(const a of s.access)r.add(a);return[...r]}function pd({value:e,onChange:t,clampToParent:n,emptyHint:r}){const{data:s}=Fo(),{data:a}=$n({}),i=q(()=>(s??[]).map(g=>({value:g.manifest.id,label:g.manifest.id})).sort((g,b)=>g.label.localeCompare(b.label)),[s]),l=q(()=>[..._N].sort().map(g=>({value:g,label:g})),[]),c=q(()=>(a??[]).map(g=>({value:String(g.id),label:`${g.name} (#${g.id} · ${g.addonId})`})).sort((g,b)=>g.label.localeCompare(b.label)),[a]),d=q(()=>n==null?null:rD(n),[n]),f=(g,b)=>{const x=[...b];switch(g){case"category":return{type:"category",target:"device",access:x};case"capability":return{type:"capability",target:"",access:x};case"addon":return{type:"addon",target:"",access:x};case"device":return{type:"device",targets:[],access:x}}},p=(g,b)=>{t(e.map((x,y)=>{if(y!==g)return x;if(b.type!==void 0&&b.type!==x.type)return f(b.type,b.access??x.access);const w=[...b.access??x.access];return x.type==="device"?{type:"device",targets:[...b.targets??x.targets],access:w}:x.type==="category"?{type:"category",target:b.target??x.target,access:w}:x.type==="capability"?{type:"capability",target:b.target??x.target,access:w}:{type:"addon",target:b.target??x.target,access:w}}))},h=g=>{t(e.filter((b,x)=>x!==g))},m=()=>{t([...e,nD()])};return u("div",{className:"space-y-2",children:[e.length===0&&r&&o("div",{className:"text-[10px] text-foreground-subtle italic px-2 py-2",children:r}),e.map((g,b)=>{const x=sD(g,n);return u("div",{className:"flex flex-wrap items-start gap-1.5 rounded border border-border bg-surface px-2 py-1.5",children:[u("select",{value:g.type,onChange:y=>p(b,{type:y.target.value}),className:"rounded border border-border bg-background px-2 py-1 text-[11px] focus:outline-none focus:ring-1 focus:ring-primary",children:[o("option",{value:"category",children:"category"}),o("option",{value:"capability",children:"capability"}),o("option",{value:"addon",children:"addon"}),o("option",{value:"device",children:"device"})]}),g.type==="device"?o(aD,{value:g.targets,choices:c,clampToParent:d,onChange:y=>p(b,{targets:y})}):u("select",{value:g.target,onChange:y=>p(b,{target:y.target.value}),className:"flex-1 min-w-[160px] rounded border border-border bg-background px-2 py-1 text-[11px] font-mono focus:outline-none focus:ring-1 focus:ring-primary",children:[u("option",{value:"",children:["— pick ",g.type," —"]}),oD(g.type,n,i,l).map(y=>o("option",{value:y.value,children:y.label},y.value))]}),o("div",{className:"flex items-center gap-1",children:eD.map(({value:y,label:w,icon:v,hint:N})=>{const k=g.access.includes(y),C=n!=null&&!x.includes(y)&&!k;return u("label",{title:C?`${N} — not granted by your scope`:N,className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] cursor-pointer transition-colors ${k?"bg-primary/15 text-primary font-medium":"text-foreground-subtle hover:bg-foreground-subtle/10"} ${C?"opacity-40 cursor-not-allowed":""}`,children:[o("input",{type:"checkbox",checked:k,disabled:C,onChange:E=>{const A=new Set(g.access);E.target.checked?A.add(y):A.delete(y),p(b,{access:[...A]})},className:"sr-only"}),o(v,{className:"h-3 w-3"}),w]},y)})}),o("button",{type:"button",onClick:()=>h(b),className:"rounded p-1 text-foreground-subtle hover:bg-danger/10 hover:text-danger transition-colors",title:"Remove scope",children:o(Ye,{className:"h-3 w-3"})})]},b)}),u("button",{type:"button",onClick:m,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-foreground-subtle/10 transition-colors",children:[o(Bo,{className:"h-3 w-3"}),"Add scope"]})]})}function aD({value:e,choices:t,clampToParent:n,onChange:r}){const[s,a]=P(""),i=q(()=>{const f=n==null?t:t.filter(h=>n.includes(h.value)),p=new Set(e);return f.filter(h=>!p.has(h.value))},[t,n,e]),l=f=>t.find(p=>p.value===f)?.label??`#${f}`,c=f=>{f&&(r([...e,f]),a(""))},d=f=>{r(e.filter(p=>p!==f))};return u("div",{className:"flex-1 min-w-[160px] flex flex-wrap items-center gap-1",children:[e.length===0&&o("span",{className:"text-[10px] text-foreground-subtle italic px-1",children:"no devices selected"}),e.map(f=>u("span",{className:"inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-mono text-primary",children:[l(f),o("button",{type:"button",onClick:()=>d(f),className:"hover:text-danger transition-colors",title:"Remove device",children:o(Ye,{className:"h-2.5 w-2.5"})})]},f)),i.length>0&&u("select",{value:s,onChange:f=>c(f.target.value),className:"rounded border border-border bg-background px-1.5 py-0.5 text-[10px] focus:outline-none focus:ring-1 focus:ring-primary",children:[o("option",{value:"",children:"+ add device…"}),i.map(f=>o("option",{value:f.value,children:f.label},f.value))]})]})}function fd(e){for(const t of e){if(t.type==="device"){if(t.targets.length===0)return"Scope device: pick at least one device"}else if(t.target.trim().length===0)return`Scope ${t.type}: pick a target`;if(t.access.length===0){const n=t.type==="device"?`[${t.targets.join(",")}]`:t.target;return`Scope ${t.type}:${n}: pick at least one access`}}return null}const Ey=fn("camstack:zone-editing",null);function Iy({children:e}){const[t,n]=P(!1),[r,s]=P(null),[a,i]=P(null),[l,c]=P(null),d=U(w=>{n(w),w||(s(null),i(null),c(null))},[]),f=U(w=>{s(w)},[]),p=U(w=>{i(w)},[]),h=U(w=>{n(!0),i(null),s(w),c(null)},[]),m=U(()=>{n(!1),s(null),i(null),c(null)},[]),g=U(w=>{i(w.id),c(w)},[]),b=U(w=>{c(v=>v===null?v:{...v,...w})},[]),x=U(()=>{c(null)},[]),y=q(()=>({editing:t,drawingKind:r,selectedZoneId:a,editingDraft:l,setEditing:d,setDrawingKind:f,setSelectedZoneId:p,startDrawing:h,exitEditing:m,enterDraft:g,updateDraft:b,discardDraft:x}),[t,r,a,l,d,f,p,h,m,g,b,x]);return o(Ey.Provider,{value:y,children:e})}function iD(){return ve(Ey)}const sp=500,lD=800;function cs(e,t,n){try{const r=e.live;if(!r)return null;const s=r.onEvent;return!s||typeof s.subscribe!="function"?null:s.subscribe({category:t},{onData:n})}catch{return null}}function ds(e,t){return e?.id===t}function Ay(e,t){const[n,r]=P(null),[s,a]=P(null),[i,l]=P(null),[c,d]=P("watching"),f=ne(void 0),p=ne(void 0),h=ne(void 0);return Y(()=>{if(t===null)return;const m=cs(e,"detection.motion-analysis",g=>{const b=g;if(!ds(b?.source,t))return;const x=b.data;!x?.regions||x.regions.length===0||(r({zones:x.regions.map(y=>({...y.bbox,intensity:y.intensity})),frameWidth:x.frameWidth,frameHeight:x.frameHeight}),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>r(null),sp))});return()=>{m?.unsubscribe(),f.current&&clearTimeout(f.current)}},[e,t]),Y(()=>{if(t===null)return;const m=cs(e,"detection.motion-zones-raw",g=>{const b=g;if(!ds(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}),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>a(null),sp))});return()=>{m?.unsubscribe(),p.current&&clearTimeout(p.current)}},[e,t]),Y(()=>{if(t===null)return;const m=cs(e,"detection.result",g=>{const b=g;if(!ds(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),lD))});return()=>{m?.unsubscribe(),h.current&&clearTimeout(h.current)}},[e,t]),Y(()=>{if(t===null)return;const m=cs(e,"detection.phase-transition",g=>{const b=g;ds(b?.source,t)&&b.data?.to&&d(b.data.to)});return()=>{m?.unsubscribe()}},[e,t]),{motion:n,motionRaw:s,detection:i,phase:c}}function hd(e,t,n=5e3){const[r,s]=P([]);Y(()=>{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]=P(null);Y(()=>{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]),pt("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||r.length===0?{streams:[],hasWebrtc:!1}:{streams:r.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,r]),d=U(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]),f=U(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]),p=U(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:f,closeSession:p}}const ap={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 md(e,t,n){const r=n?.defaultSpeed??.5,s=n?.pulseMs??250,a=n?.enabled??!0,l=St(e,a?t:null)?.ptz,[c,d]=P([]),[f,p]=P(!1),[h,m]=P(null),g=U(async()=>{if(!(!a||!l))try{const C=await l.getPresets({});d(C)}catch(C){const E=C instanceof Error?C.message:String(C);if(E.includes("provider not available")||E.includes("no 'ptz' binding"))return;m(E)}},[l,a]);Y(()=>{g()},[g]);const b=U(async C=>{if(!(!a||!l)){m(null),p(!0);try{return await C()}catch(E){m(E instanceof Error?E.message:String(E));return}finally{p(!1)}}},[a,l]),x=U(async(C,E)=>{if(!l)return;const A=ap[C],I=E??r;await b(async()=>{await l.move({pan:A.pan,tilt:A.tilt,speed:I}),await new Promise(z=>setTimeout(z,s)),await l.stop({})})},[l,r,s,b]),y=U(async(C,E)=>{if(!l)return;const A=ap[C],I=E??r;await b(()=>l.continuousMove({pan:A.pan,tilt:A.tilt,speed:I}))},[l,r,b]),w=U(async()=>{l&&await b(()=>l.stop({}))},[l,b]),v=U(async(C,E)=>{if(!l)return;const A=C==="in"?1:-1,I=E??r;await b(async()=>{await l.move({zoom:A,speed:I}),await new Promise(z=>setTimeout(z,s)),await l.stop({})})},[l,r,s,b]),N=U(async()=>{l&&await b(()=>l.goHome({}))},[l,b]),k=U(async C=>{l&&await b(()=>l.goToPreset({presetId:C}))},[l,b]);return{move:x,startContinuous:y,stopContinuous:w,zoom:v,goHome:N,goToPreset:k,presets:c,refreshPresets:g,busy:f,error:h}}function gd(e){const t=e?.deviceId??null,n=e?.historyLimit??20,r=Br("doorbell.onPressed",t!==null?i=>i.deviceId===t:void 0),[s,a]=P([]);return Y(()=>{r&&a(i=>{if(i.length>0&&i[0].deviceId===r.deviceId&&i[0].timestamp===r.timestamp)return i;const l=[r,...i];return l.length>n?l.slice(0,n):l})},[r,n]),{latest:r??null,history:s}}function cD(e){const t=Le(),n=q(()=>e?JSON.stringify(e):"",[e]),[r,s]=P(()=>t.listDevices(e));return Y(()=>{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]),r}function dD(e){const t=Le(),[n,r]=P(()=>e===null?null:t.getDevice(e));return Y(()=>{if(e===null){r(null);return}const s=()=>{r(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 uD(e,t,n){const r=Le();return tr({queryKey:e,queryFn:()=>t(r)(),...n})}function pD(e,t){const n=Le();return cc({mutationFn:r=>e(n)(r),...t})}function fD(e,t){const n=Le(),r=ke(),[s,a]=P(n.connectionVersion);Y(()=>n.subscribeConnectionEvents((c,d)=>{c==="connected"&&a(d)}),[n]);const i=t.join("|"),l=JSON.stringify(e);Y(()=>{const c=[],d=()=>{const f=JSON.parse(l),h=f.length===1&&Array.isArray(f[0])?f:[f];r.invalidateQueries({queryKey:h})};d();for(const f of i.split("|"))if(f)try{c.push(n.subscribeEvent(f,d))}catch{}return()=>{for(const f of c)f()}},[n,r,i,l,s])}const hD=Object.freeze(Object.defineProperty({__proto__:null,AddonGlobalSettingsForm:n$,AgentStepEditor:ka,AppShell:PC,AudioClassificationList:C$,AudioLevelWaveform:N$,AudioWaveform:w$,BTN_COMPACT:H2,BTN_COMPACT_DANGER:q2,BTN_COMPACT_PRIMARY:V2,BTN_COMPACT_WARNING:U2,Badge:yr,BatteryBadge:Rc,BottomSheet:Sc,Breadcrumb:Ec,Button:Oe,CHIP_ACTIVE:K2,CHIP_BASE:G2,CHIP_INACTIVE:W2,CLASS_COLORS:no,CameraStreamPlayer:xy,Card:Lt,Checkbox:Pm,CodeBlock:IC,CollapsibleCard:Im,ConfigFormBuilder:gy,ConfigFormField:lr,ConfigSchemaField:Na,ConfirmActionButton:Cy,ConfirmDialogProvider:dg,CustomFieldRenderersProvider:Pg,DEFAULT_COLOR:Cg,DataTable:ng,DetectionCanvas:$3,DetectionOverlay:by,DetectionResultTree:R3,DevShell:Ig,DeviceActivityPanel:Y$,DeviceCard:$C,DeviceContextProvider:$g,DeviceGrid:DC,DeviceItem:xo,DeviceList:yo,Dialog:Dm,DialogContent:Nc,DialogDescription:Om,DialogFooter:Lm,DialogHeader:Tm,DialogTitle:Rm,DialogTrigger:KS,DiscoveryPanel:Sy,DoorbellRecentPanel:ud,Dropdown:zm,DropdownContent:jm,DropdownItem:Hm,DropdownTrigger:Fm,EmptyState:Dc,EventStream:cr,FilterBar:AC,FloatingEventStream:F$,FloatingLogStream:ky,FloatingPanel:rC,FormField:SC,GRID_GAP:am,GRID_PAIRED:R2,GRID_QUICK_STATS:L2,INPUT_COMPACT:Q2,IconButton:xc,ImageSelector:j3,InferenceConfigSelector:H3,Input:Qs,KebabMenu:My,KeyValueList:EC,LIST_ROW:im,Label:yc,LogStream:Xt,LoginForm:Mg,MobileDrawer:Mc,NodeMultiSelectField:hy,NodePicker:ig,NodeSelectField:fy,PHASE_CONFIG:hl,PTZOverlay:dd,PageHeader:CC,PhaseIcon:ld,PipelineBuilder:Oc,PipelineRuntimeSelector:A3,PipelineStep:$s,PipelineTreeMatrix:Ac,PlayerOverlaysProvider:yy,Popover:Zm,PopoverContent:Jm,PopoverTrigger:Xm,ProviderBadge:wC,ResponseLog:M$,SECTION_BODY:T2,SECTION_CARD:$2,SECTION_HEADER:D2,SPLIT_PANEL_OUTER:O2,SPLIT_PANEL_SIDE:B2,STACK_GAP:sm,ScopePicker:pd,ScrollArea:Cc,Select:bo,SemanticBadge:lg,Separator:vc,Sidebar:wl,SidebarItem:vl,Skeleton:Am,SlideOverPanel:Ic,SnapshotButton:X$,StatCard:MC,StateValuesStream:cd,StatusBadge:yC,StepTimings:F3,StepTreeMaster:og,StreamBrokerSelector:v$,StreamPanel:id,Switch:wc,SystemProvider:_c,TEXT_FIELD_LABEL:F2,TEXT_HINT:Us,TEXT_METRIC:fl,TEXT_SECTION_LABEL:z2,TEXT_VALUE:j2,Tabs:JS,TabsContent:nC,TabsList:eC,TabsTrigger:tC,ThemeProvider:Vs,Tooltip:YS,TooltipContent:XS,TooltipTrigger:ZS,VersionBadge:kC,WidgetRegistryProvider:ly,WidgetSlot:lt,ZoneEditingProvider:Iy,buildStepTreeFromSchema:wa,cn:W,createSharedContext:fn,createTheme:RN,darkColors:Oh,defaultTheme:ul,deriveDeviceKind:LC,ensureMfHostInit:pc,getClassColor:dt,getPhaseVisual:rr,isFieldVisible:od,lightColors:Bh,mirror:lm,mountAddonPage:Z3,providerIcons:jS,statusIcons:HS,themeToCss:jN,trpc:S,useAccessoriesGetStatus:X3,useAddonPagesListPages:Sa,useAddonSettingsGetDeviceSettings:lM,useAddonSettingsGetGlobalSettings:Hc,useAddonSettingsUpdateDeviceSettings:Ug,useAddonSettingsUpdateGlobalSettings:qg,useAddonWidgetsListWidgets:Qg,useAddonsApplyAutoUpdateToAll:Vg,useAddonsCustom:aM,useAddonsForceRefresh:Rg,useAddonsGetAddonAutoUpdate:jg,useAddonsGetAutoUpdateSettings:Fg,useAddonsGetLogs:J3,useAddonsGetVersions:Bg,useAddonsInstallFromWorkspace:tM,useAddonsInstallPackage:Fc,useAddonsIsWorkspaceAvailable:nM,useAddonsList:Fo,useAddonsListPackages:eM,useAddonsListUpdates:jc,useAddonsListWorkspacePackages:rM,useAddonsOnAddonLogs:iM,useAddonsReloadPackages:Tg,useAddonsRestartAddon:Ca,useAddonsRestartServer:Og,useAddonsRetryLoad:zg,useAddonsRollbackPackage:oM,useAddonsSearchAvailable:Lg,useAddonsSetAddonAutoUpdate:Hg,useAddonsSetAutoUpdateSettings:sM,useAddonsUninstallPackage:Dg,useAddonsUpdatePackage:kl,useAlertsDismiss:Zg,useAlertsEmit:cM,useAlertsGetUnreadCount:Kg,useAlertsList:Gg,useAlertsMarkAllRead:Yg,useAlertsMarkRead:Wg,useAlertsUpdate:dM,useAllWidgets:uy,useAudioAnalysisApplyDeviceSettingsPatch:hM,useAudioAnalysisGetDeviceLiveContribution:fM,useAudioAnalysisGetDeviceSettingsContribution:pM,useAudioAnalysisResolveDeviceSettings:uM,useAudioAnalyzerAnalyseChunk:mM,useAudioAnalyzerClassify:gM,useAudioAnalyzerDispose:xM,useAudioAnalyzerIsReady:bM,useAudioAnalyzerReprobeAudioEngine:Xg,useAudioCodecCanHandle:vM,useAudioCodecCloseSession:kM,useAudioCodecCreateDecodeSession:wM,useAudioCodecCreateEncodeSession:NM,useAudioCodecFlushEncode:IM,useAudioCodecListActiveSessions:AM,useAudioCodecListSupportedCodecs:yM,useAudioCodecPullEncoded:EM,useAudioCodecPullPcm:CM,useAudioCodecPushEncodedFrame:SM,useAudioCodecPushPcm:MM,useAudioMetricsGetCurrentSnapshot:PM,useAudioMetricsGetHistory:_M,useAuthenticationListProviders:Vc,useAuthenticationSetProviderEnabled:$M,useBackupDelete:rb,useBackupGetEntries:tb,useBackupList:DM,useBackupListArchives:Uc,useBackupListDestinations:qc,useBackupListLocations:eb,useBackupPreviewSchedule:sb,useBackupRestore:nb,useBackupTrigger:Jg,useBackupUpsertDestinationPolicy:ob,useBatteryGetStatus:TM,useBrightnessGetStatus:RM,useBrightnessSetBrightness:LM,useCameraCredentialsGetCredentials:OM,useCameraCredentialsGetStatus:BM,useCameraStreamsGetBrokerStreams:FM,useCameraStreamsGetCameraStreams:zM,useCameraStreamsGetRtspEntries:ab,useClusterNodes:zr,useConfirm:Je,useCustomFieldRenderer:_g,useDebouncedString:Sg,useDecoderCreateSession:VM,useDecoderDestroySession:qM,useDecoderGetInfo:HM,useDecoderGetStats:WM,useDecoderListActiveSessions:YM,useDecoderOpenStream:QM,useDecoderPullFrames:GM,useDecoderPushPacket:UM,useDecoderReprobeHwaccel:ib,useDecoderSupportsCodec:jM,useDecoderUpdateConfig:KM,useDetectionPipelineApplyDeviceSettingsPatch:JM,useDetectionPipelineGetDeviceLiveContribution:XM,useDetectionPipelineGetDeviceSettingsContribution:ZM,useDevShell:Q3,useDevice:dD,useDeviceBattery:Tc,useDeviceCapability:Fr,useDeviceDetections:Ay,useDeviceDiscoveryAdoptDevice:e4,useDeviceDiscoveryGetStatus:n4,useDeviceDiscoveryListDiscovered:lb,useDeviceDiscoveryRefreshDiscovery:cb,useDeviceDiscoveryReleaseDevice:t4,useDeviceExportApplyDeviceSettingsPatch:c4,useDeviceExportExposeDevice:s4,useDeviceExportGetDeviceLiveContribution:l4,useDeviceExportGetDeviceSettingsContribution:i4,useDeviceExportGetStatus:db,useDeviceExportListExposedDevices:o4,useDeviceExportListSupportedDeviceKinds:r4,useDeviceExportUnexposeDevice:a4,useDeviceId:hn,useDeviceManagerAddLocation:x4,useDeviceManagerAdoptDevice:Nb,useDeviceManagerAllocateDeviceId:d4,useDeviceManagerCreateDevice:Sb,useDeviceManagerDisable:gb,useDeviceManagerDiscoverDevices:Gc,useDeviceManagerEnable:mb,useDeviceManagerGetAllBindings:A4,useDeviceManagerGetBindings:xb,useDeviceManagerGetChildren:hb,useDeviceManagerGetConfigSchema:k4,useDeviceManagerGetCreationSchema:kb,useDeviceManagerGetDevice:Gn,useDeviceManagerGetDeviceAggregate:Qc,useDeviceManagerGetDeviceLiveInfoAggregate:$4,useDeviceManagerGetDeviceSettingsAggregate:_4,useDeviceManagerGetDeviceStatusAggregate:L4,useDeviceManagerGetSettingsSchema:S4,useDeviceManagerGetStreamProfileMap:M4,useDeviceManagerGetStreamSources:N4,useDeviceManagerListAll:$n,useDeviceManagerListBindableCapsForDeviceType:vb,useDeviceManagerListLocations:fb,useDeviceManagerListPersistedByAddon:w4,useDeviceManagerListWrappersForCap:P4,useDeviceManagerLoadConfig:h4,useDeviceManagerLoadMeta:g4,useDeviceManagerLoadRuntimeState:m4,useDeviceManagerPersistConfig:f4,useDeviceManagerProbeStreams:I4,useDeviceManagerRegisterDevice:u4,useDeviceManagerRemove:bb,useDeviceManagerRemoveDevice:p4,useDeviceManagerRemoveLocation:y4,useDeviceManagerSetDisabled:v4,useDeviceManagerSetLocation:pb,useDeviceManagerSetMetadata:b4,useDeviceManagerSetName:ub,useDeviceManagerSetStreamProfileMap:E4,useDeviceManagerSetWrapperActive:yb,useDeviceManagerTestCreationField:Kc,useDeviceManagerTestField:T4,useDeviceManagerUpdateConfig:C4,useDeviceManagerUpdateDeviceField:D4,useDeviceManagerUpdateDeviceFieldsBatch:wb,useDeviceOpsGetConfigEntries:O4,useDeviceOpsGetSettingsSchema:F4,useDeviceOpsGetStreamSources:R4,useDeviceOpsRemoveDevice:z4,useDeviceOpsSetConfig:B4,useDeviceProviderAdoptDiscoveredDevice:G4,useDeviceProviderCreateDevice:Y4,useDeviceProviderDiscoverDevices:Q4,useDeviceProviderGetChildCreationSchema:W4,useDeviceProviderGetDevices:q4,useDeviceProviderGetStatus:V4,useDeviceProviderStart:j4,useDeviceProviderStop:H4,useDeviceProviderSupportsDiscovery:U4,useDeviceProviderSupportsManualCreation:K4,useDeviceProviderTestCreationField:Z4,useDeviceProxy:St,useDeviceSnapshot:zc,useDeviceSnapshotImage:Lc,useDeviceState:ug,useDeviceStateGetAllSnapshots:eE,useDeviceStateGetCapSlice:J4,useDeviceStateGetSnapshot:X4,useDeviceStateSetCapSlice:tE,useDeviceStateSlice:an,useDeviceStatusGetStatus:nE,useDeviceWebrtc:hd,useDevices:cD,useDoorbellEvents:gd,useDoorbellGetStatus:rE,useEventInvalidation:fD,useEventStreamLatest:Br,useEventStreamMap:$c,useEventsGetEventClipUrl:aE,useEventsGetEventThumbnail:sE,useEventsGetEvents:oE,useFeatureProbeGetStatus:iE,useIntegrationsCreate:Eb,useIntegrationsDelete:Ab,useIntegrationsGet:Cb,useIntegrationsGetAvailableTypes:Pb,useIntegrationsGetByAddonId:Mb,useIntegrationsGetSettings:lE,useIntegrationsList:Wc,useIntegrationsSetSettings:cE,useIntegrationsTestConnection:_b,useIntegrationsUpdate:Ib,useIntercomEndTalkSession:pE,useIntercomGetStatus:fE,useIntercomHandleAnswer:Db,useIntercomPushTalkPcm:uE,useIntercomStartSession:$b,useIntercomStartTalkSession:dE,useIntercomStopSession:Tb,useIsMidWidth:Km,useIsMobile:ar,useLiveBuffer:Vn,useLiveEvent:pt,useLocalNetworkGetAllowedAddresses:Ob,useLocalNetworkGetConnectionEndpoints:Rb,useLocalNetworkGetPreferred:hE,useLocalNetworkList:Lb,useLocalNetworkResetAllowlistToBestMatch:zb,useLocalNetworkSetAllowedAddresses:Bb,useMeshNetworkGetStatus:mE,useMeshNetworkJoin:gE,useMeshNetworkLeave:xE,useMeshNetworkListPeers:yE,useMeshNetworkStartLogin:bE,useMeshNetworkTestConnection:vE,useMeshOrchestratorJoinProvider:jb,useMeshOrchestratorLeaveProvider:Hb,useMeshOrchestratorListProviders:Fb,useMetricsProviderCollectSnapshot:wE,useMetricsProviderGetAddonStats:AE,useMetricsProviderGetCached:NE,useMetricsProviderGetCpuTemperature:ME,useMetricsProviderGetCurrent:kE,useMetricsProviderGetDiskSpace:SE,useMetricsProviderGetGpuInfo:CE,useMetricsProviderGetProcessStats:EE,useMetricsProviderKillProcess:qb,useMetricsProviderListAddonInstances:IE,useMetricsProviderListNodeProcesses:Vb,useMotionDetectionAnalyze:$E,useMotionDetectionApplyDeviceSettingsPatch:OE,useMotionDetectionGetDeviceLiveContribution:RE,useMotionDetectionGetDeviceSettingsContribution:LE,useMotionDetectionRemoveCamera:DE,useMotionDetectionReset:TE,useMotionGetStatus:_E,useMotionIsDetected:PE,useMotionTriggerGetStatus:zE,useMotionTriggerSetMotionTrigger:BE,useMqttBrokerAddBroker:HE,useMqttBrokerGetBrokerConfig:jE,useMqttBrokerGetStatus:Ub,useMqttBrokerListBrokers:FE,useMqttBrokerRemoveBroker:VE,useMqttBrokerStartEmbeddedBroker:UE,useMqttBrokerStopEmbeddedBroker:QE,useMqttBrokerTestConnection:qE,useNativeObjectDetectionGetStatus:GE,useNetworkQualityGetAllStats:KE,useNetworkQualityGetDeviceStats:Yc,useNetworkQualityReportClientStats:WE,useNodesClusterAddonStatus:Yb,useNodesDeployAddon:YE,useNodesExecuteQuery:XE,useNodesRenameNode:Wb,useNodesRestartAddon:Ma,useNodesRestartNode:Kb,useNodesRestartProcess:Gb,useNodesSetProcessLogLevel:Zb,useNodesShutdownNode:ZE,useNodesTopology:Dn,useNodesUndeployAddon:Qb,useNotificationOutputSend:JE,useNotificationOutputSendTest:eI,useOptionalSystem:bC,useOptionalWidgetRegistry:py,useOsdGetStatus:nI,useOsdSetOverlay:tI,usePTZ:md,usePipelineAnalyticsApplyDeviceSettingsPatch:hI,usePipelineAnalyticsClearTracks:aI,usePipelineAnalyticsGetActiveTracks:rI,usePipelineAnalyticsGetAudioEvents:cI,usePipelineAnalyticsGetDeviceLiveContribution:fI,usePipelineAnalyticsGetDeviceSettingsContribution:pI,usePipelineAnalyticsGetEventMedia:dI,usePipelineAnalyticsGetMotionEvents:iI,usePipelineAnalyticsGetObjectEvents:lI,usePipelineAnalyticsGetTrack:oI,usePipelineAnalyticsGetTrackMedia:uI,usePipelineAnalyticsListTracks:sI,usePipelineExecutorCacheFrameInPool:PI,usePipelineExecutorDeleteModel:nx,usePipelineExecutorDeleteTemplate:SI,usePipelineExecutorDetect:EI,usePipelineExecutorDownloadModel:tx,usePipelineExecutorGetAddonModels:MI,usePipelineExecutorGetAudioCapabilities:zI,usePipelineExecutorGetAvailableEngines:Xb,usePipelineExecutorGetCapabilities:CI,usePipelineExecutorGetDefaultSteps:mI,usePipelineExecutorGetDetectionConfigSchema:jI,usePipelineExecutorGetEffectiveTuning:DI,usePipelineExecutorGetGlobalPipelineConfig:yI,usePipelineExecutorGetGlobalSteps:xI,usePipelineExecutorGetOrchestratorConfigSchema:vI,usePipelineExecutorGetReferenceAudio:BI,usePipelineExecutorGetReferenceAudioFiles:OI,usePipelineExecutorGetReferenceImage:RI,usePipelineExecutorGetSchema:jo,usePipelineExecutorGetSelectedEngine:Jb,usePipelineExecutorGetVideoPipelineSteps:gI,usePipelineExecutorInferCached:_I,usePipelineExecutorKillEngine:ox,usePipelineExecutorListLoadedEngines:rx,usePipelineExecutorListReferenceImages:LI,usePipelineExecutorListTemplates:wI,usePipelineExecutorReprobeEngine:ex,usePipelineExecutorRunAudioTest:FI,usePipelineExecutorRunPipeline:II,usePipelineExecutorRunPipelineBatch:AI,usePipelineExecutorSaveTemplate:NI,usePipelineExecutorSetVideoPipelineSteps:bI,usePipelineExecutorSpinEngine:TI,usePipelineExecutorUncacheFrame:$I,usePipelineExecutorUpdateTemplate:kI,usePipelineOrchestratorApplyDeviceSettingsPatch:YI,usePipelineOrchestratorAssignAudio:hx,usePipelineOrchestratorAssignDecoder:ux,usePipelineOrchestratorAssignPipeline:sx,usePipelineOrchestratorDeleteTemplate:Cx,usePipelineOrchestratorGetAgentLoad:lx,usePipelineOrchestratorGetAgentSettings:Zc,usePipelineOrchestratorGetAudioAssignment:qI,usePipelineOrchestratorGetAudioAssignments:bx,usePipelineOrchestratorGetAudioNodeLoad:gx,usePipelineOrchestratorGetCameraMetrics:VI,usePipelineOrchestratorGetCameraSettings:Jc,usePipelineOrchestratorGetCameraStepOverrides:QI,usePipelineOrchestratorGetCapabilityBindings:cx,usePipelineOrchestratorGetDecoderAssignment:UI,usePipelineOrchestratorGetDecoderAssignments:fx,usePipelineOrchestratorGetDeviceLiveContribution:WI,usePipelineOrchestratorGetDeviceSettingsContribution:KI,usePipelineOrchestratorGetGlobalMetrics:HI,usePipelineOrchestratorGetPipelineAssignment:Ia,usePipelineOrchestratorGetPipelineAssignments:Ea,usePipelineOrchestratorListAgentSettings:jr,usePipelineOrchestratorListTemplates:kx,usePipelineOrchestratorRebalance:ix,usePipelineOrchestratorRemoveAgentSettings:xx,usePipelineOrchestratorResolvePipeline:Nx,usePipelineOrchestratorSaveTemplate:GI,usePipelineOrchestratorSetAgentAddonDefaults:Xc,usePipelineOrchestratorSetCameraPipelineForAgent:wx,usePipelineOrchestratorSetCameraStepOverride:vx,usePipelineOrchestratorSetCameraStepToggle:yx,usePipelineOrchestratorSetCapabilityBinding:dx,usePipelineOrchestratorUnassignAudio:mx,usePipelineOrchestratorUnassignDecoder:px,usePipelineOrchestratorUnassignPipeline:ax,usePipelineOrchestratorUpdateTemplate:Sx,usePipelineRunnerAttachCamera:ZI,usePipelineRunnerDetachCamera:XI,usePipelineRunnerGetAllCameraMetrics:nA,usePipelineRunnerGetCameraMetrics:ed,usePipelineRunnerGetLocalCameras:Mx,usePipelineRunnerGetLocalLoad:eA,usePipelineRunnerGetLocalMetrics:tA,usePipelineRunnerReportMotion:JI,usePlatformProbeGetCapabilities:rA,usePlatformProbeGetHardware:oA,usePlatformProbeGetHardwareEncoders:iA,usePlatformProbeRefreshHardwareEncoders:lA,usePlatformProbeResolveHwAccel:aA,usePlatformProbeResolveInferenceConfig:sA,usePlayerOverlayLayer:d$,usePlayerOverlayLayers:vy,usePlayerToolbarButton:u$,usePlayerToolbarButtons:wy,usePtzAutotrackGetSettings:bA,usePtzAutotrackGetStatus:Ex,usePtzAutotrackSetEnabled:Ix,usePtzAutotrackSetSettings:Ax,usePtzContinuousMove:dA,usePtzGetPosition:mA,usePtzGetPresets:pA,usePtzGetStatus:gA,usePtzGoHome:hA,usePtzGoToPreset:fA,usePtzMove:cA,usePtzStop:uA,useRebootReboot:Px,useRecordingEngineDisable:$x,useRecordingEngineEnable:_x,useRecordingEngineEstimateGlobalStorage:EA,useRecordingEngineEstimateStorage:MA,useRecordingEngineGetAvailability:CA,useRecordingEngineGetConfig:Dx,useRecordingEngineGetMotionStats:_A,useRecordingEngineGetPlaylist:kA,useRecordingEngineGetPolicy:AA,useRecordingEngineGetPolicyStatus:Rx,useRecordingEngineGetRetentionConfig:Ox,useRecordingEngineGetSegments:Tx,useRecordingEngineGetStatus:wA,useRecordingEngineGetStorageUsage:Lx,useRecordingEngineGetThumbnail:SA,useRecordingEngineSetPolicy:IA,useRecordingEngineUpdateConfig:NA,useRecordingEngineUpdateRetentionConfig:PA,useRecordingGetPlaybackUrl:yA,useRecordingGetSegments:xA,useRecordingGetThumbnailAt:vA,useRemoteAccessListProviders:Bx,useRemoteAccessStartProvider:zx,useRemoteAccessStopProvider:Fx,useSettingsStoreCount:BA,useSettingsStoreDeclareCollection:FA,useSettingsStoreDelete:OA,useSettingsStoreGet:$A,useSettingsStoreInsert:LA,useSettingsStoreIsEmpty:zA,useSettingsStoreQuery:TA,useSettingsStoreSet:DA,useSettingsStoreUpdate:RA,useSnapshotApplyDeviceSettingsPatch:QA,useSnapshotGetDeviceLiveContribution:UA,useSnapshotGetDeviceSettingsContribution:qA,useSnapshotGetSnapshot:jA,useSnapshotGetStatus:VA,useSnapshotInvalidateCache:HA,useSnapshotProviderGetSnapshot:KA,useSnapshotProviderSupportsDevice:GA,useStorageAbortUpload:sP,useStorageBeginDownload:aP,useStorageBeginUpload:nP,useStorageDelete:eP,useStorageDeleteLocation:Hx,useStorageEndDownload:lP,useStorageExists:XA,useStorageFinalizeUpload:oP,useStorageGetAvailableSpace:tP,useStorageGetDefaultLocation:cP,useStorageList:JA,useStorageListLocations:jx,useStorageListProviders:td,useStorageRead:ZA,useStorageReadChunk:iP,useStorageResolve:WA,useStorageTestConfig:uP,useStorageTestLocation:dP,useStorageUpsertLocation:Aa,useStorageWrite:YA,useStorageWriteChunk:rP,useStreamBrokerApplyDeviceSettingsPatch:LP,useStreamBrokerAssignProfile:hP,useStreamBrokerGetAllRtspEntries:AP,useStreamBrokerGetBroker:CP,useStreamBrokerGetBrokerStats:xP,useStreamBrokerGetDeviceLiveContribution:TP,useStreamBrokerGetDeviceSettingsContribution:DP,useStreamBrokerGetPreBufferInfo:EP,useStreamBrokerGetRtspEntry:PP,useStreamBrokerGetRtspPort:IP,useStreamBrokerGetStreamUrl:NP,useStreamBrokerGetStreamWithCodec:kP,useStreamBrokerIsRtspEnabled:$P,useStreamBrokerKillClient:vP,useStreamBrokerListAllCameraStreams:gP,useStreamBrokerListAllProfileSlots:bP,useStreamBrokerListClients:yP,useStreamBrokerPublishCameraStream:pP,useStreamBrokerRegenerateRtspToken:Vx,useStreamBrokerReleaseStreamWithCodec:SP,useStreamBrokerRestartProfile:wP,useStreamBrokerRetractCameraStream:fP,useStreamBrokerSetPreBufferDuration:MP,useStreamBrokerSetRtspEnabled:_P,useStreamBrokerUnassignProfile:mP,useSwitchGetStatus:OP,useSwitchSetState:RP,useSystem:Le,useSystemFeatureFlags:FP,useSystemForceRetentionCleanup:qP,useSystemGetRetentionConfig:HP,useSystemHealth:zP,useSystemInfo:BP,useSystemMutation:pD,useSystemNetworkAddresses:jP,useSystemQuery:uD,useSystemSetRetentionConfig:VP,useThemeMode:Or,useToastOnToast:qx,useTurnOrchestratorGetAllServers:Qx,useTurnOrchestratorListProviders:Ux,useTurnOrchestratorSetProviderEnabled:Gx,useTurnProviderGetTurnServers:UP,useUserManagementConfirmTotp:oy,useUserManagementCreateApiKey:GP,useUserManagementCreateScopedToken:ey,useUserManagementCreateUser:Kx,useUserManagementDeleteUser:Yx,useUserManagementDisableTotp:sy,useUserManagementGetTotpStatus:ay,useUserManagementListApiKeys:Xx,useUserManagementListScopedTokens:ny,useUserManagementListUsers:nd,useUserManagementResetPassword:rd,useUserManagementRevokeApiKey:Jx,useUserManagementRevokeScopedToken:ty,useUserManagementSetUserScopes:Zx,useUserManagementSetupTotp:ry,useUserManagementUpdateUser:Wx,useUserManagementValidateApiKey:KP,useUserManagementValidateCredentials:QP,useUserManagementValidateScopedToken:WP,useUserManagementVerifyTotp:YP,useWebrtcSessionCloseSession:t_,useWebrtcSessionCreateSession:XP,useWebrtcSessionHandleAnswer:e_,useWebrtcSessionHandleOffer:JP,useWebrtcSessionHasAdaptiveBitrate:n_,useWebrtcSessionListStreams:ZP,useWidget:cy,useWidgetMetadata:dy,useWidgetRegistry:Pa,useZoneAnalyticsGetCameraHistory:s_,useZoneAnalyticsGetCurrentSnapshot:r_,useZoneAnalyticsGetUnzonedHistory:a_,useZoneAnalyticsGetZoneHistory:o_,useZoneEditing:iD,useZoneRulesListRules:i_,useZoneRulesSetRules:l_,useZonesAddZone:d_,useZonesListZones:c_,useZonesRemoveZone:u_,useZonesUpdateZone:p_,validateScopes:fd},Symbol.toStringTag,{value:"Module"}));/**
540
- * react-router v7.15.0
541
- *
542
- * Copyright (c) Remix Software Inc.
543
- *
544
- * This source code is licensed under the MIT license found in the
545
- * LICENSE.md file in the root directory of this source tree.
546
- *
547
- * @license MIT
548
- */var ip="popstate";function lp(e){return typeof e=="object"&&e!=null&&"pathname"in e&&"search"in e&&"hash"in e&&"state"in e&&"key"in e}function mD(e={}){function t(r,s){let a=s.state?.masked,{pathname:i,search:l,hash:c}=a||r.location;return Ml("",{pathname:i,search:l,hash:c},s.state&&s.state.usr||null,s.state&&s.state.key||"default",a?{pathname:r.location.pathname,search:r.location.search,hash:r.location.hash}:void 0)}function n(r,s){return typeof s=="string"?s:vo(s)}return bD(t,n,null,e)}function ze(e,t){if(e===!1||e===null||typeof e>"u")throw new Error(t)}function wt(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}function gD(){return Math.random().toString(36).substring(2,10)}function cp(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 Ml(e,t,n=null,r,s){return{pathname:typeof e=="string"?e:e.pathname,search:"",hash:"",...typeof t=="string"?Hr(t):t,state:n,key:t&&t.key||r||gD(),mask:s}}function vo({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 Hr(e){let t={};if(e){let n=e.indexOf("#");n>=0&&(t.hash=e.substring(n),e=e.substring(0,n));let r=e.indexOf("?");r>=0&&(t.search=e.substring(r),e=e.substring(0,r)),e&&(t.pathname=e)}return t}function bD(e,t,n,r={}){let{window:s=document.defaultView,v5Compat:a=!1}=r,i=s.history,l="POP",c=null,d=f();d==null&&(d=0,i.replaceState({...i.state,idx:d},""));function f(){return(i.state||{idx:null}).idx}function p(){l="POP";let x=f(),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=lp(x)?x:Ml(b.location,x,y);d=f()+1;let v=cp(w,d),N=b.createHref(w.mask||w);try{i.pushState(v,"",N)}catch(k){if(k instanceof DOMException&&k.name==="DataCloneError")throw k;s.location.assign(N)}a&&c&&c({action:l,location:b.location,delta:1})}function m(x,y){l="REPLACE";let w=lp(x)?x:Ml(b.location,x,y);d=f();let v=cp(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 xD(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(ip,p),c=x,()=>{s.removeEventListener(ip,p),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 xD(e,t=!1){let n="http://localhost";typeof window<"u"&&(n=window.location.origin!=="null"?window.location.origin:window.location.href),ze(n,"No window.location.(origin|href) available to create URL");let r=typeof e=="string"?e:vo(e);return r=r.replace(/ $/,"%20"),!t&&r.startsWith("//")&&(r=n+r),new URL(r,n)}function Py(e,t,n="/"){return yD(e,t,n,!1)}function yD(e,t,n,r,s){let a=typeof t=="string"?Hr(t):t,i=ln(a.pathname||"/",n);if(i==null)return null;let l=vD(e),c=null,d=$D(i);for(let f=0;c==null&&f<l.length;++f)c=PD(l[f],d,r);return c}function vD(e){let t=_y(e);return wD(t),t}function _y(e,t=[],n=[],r="",s=!1){let a=(i,l,c=s,d)=>{let f={relativePath:d===void 0?i.path||"":d,caseSensitive:i.caseSensitive===!0,childrenIndex:l,route:i};if(f.relativePath.startsWith("/")){if(!f.relativePath.startsWith(r)&&c)return;ze(f.relativePath.startsWith(r),`Absolute route path "${f.relativePath}" nested under path "${r}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),f.relativePath=f.relativePath.slice(r.length)}let p=Rt([r,f.relativePath]),h=n.concat(f);i.children&&i.children.length>0&&(ze(i.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${p}".`),_y(i.children,t,h,p,c)),!(i.path==null&&!i.index)&&t.push({path:p,score:ID(p,i.index),routesMeta:h})};return e.forEach((i,l)=>{if(i.path===""||!i.path?.includes("?"))a(i,l);else for(let c of $y(i.path))a(i,l,!0,c)}),t}function $y(e){let t=e.split("/");if(t.length===0)return[];let[n,...r]=t,s=n.endsWith("?"),a=n.replace(/\?$/,"");if(r.length===0)return s?[a,""]:[a];let i=$y(r.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 wD(e){e.sort((t,n)=>t.score!==n.score?n.score-t.score:AD(t.routesMeta.map(r=>r.childrenIndex),n.routesMeta.map(r=>r.childrenIndex)))}var ND=/^:[\w-]+$/,kD=3,SD=2,CD=1,MD=10,ED=-2,dp=e=>e==="*";function ID(e,t){let n=e.split("/"),r=n.length;return n.some(dp)&&(r+=ED),t&&(r+=SD),n.filter(s=>!dp(s)).reduce((s,a)=>s+(ND.test(a)?kD:a===""?CD:MD),r)}function AD(e,t){return e.length===t.length&&e.slice(0,-1).every((r,s)=>r===t[s])?e[e.length-1]-t[t.length-1]:0}function PD(e,t,n=!1){let{routesMeta:r}=e,s={},a="/",i=[];for(let l=0;l<r.length;++l){let c=r[l],d=l===r.length-1,f=a==="/"?t:t.slice(a.length)||"/",p=Ks({path:c.relativePath,caseSensitive:c.caseSensitive,end:d},f),h=c.route;if(!p&&d&&n&&!r[r.length-1].route.index&&(p=Ks({path:c.relativePath,caseSensitive:c.caseSensitive,end:!1},f)),!p)return null;Object.assign(s,p.params),i.push({params:s,pathname:Rt([a,p.pathname]),pathnameBase:RD(Rt([a,p.pathnameBase])),route:h}),p.pathnameBase!=="/"&&(a=Rt([a,p.pathnameBase]))}return i}function Ks(e,t){typeof e=="string"&&(e={path:e,caseSensitive:!1,end:!0});let[n,r]=_D(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:r.reduce((d,{paramName:f,isOptional:p},h)=>{if(f==="*"){let g=l[h]||"";i=a.slice(0,a.length-g.length).replace(/(.)\/+$/,"$1")}const m=l[h];return p&&!m?d[f]=void 0:d[f]=(m||"").replace(/%2F/g,"/"),d},{}),pathname:a,pathnameBase:i,pattern:e}}function _D(e,t=!1,n=!0){wt(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 r=[],s="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(i,l,c,d,f)=>{if(r.push({paramName:l,isOptional:c!=null}),c){let p=f.charAt(d+i.length);return p&&p!=="/"?"/([^\\/]*)":"(?:/([^\\/]*))?"}return"/([^\\/]+)"}).replace(/\/([\w-]+)\?(\/|$)/g,"(/$1)?$2");return e.endsWith("*")?(r.push({paramName:"*"}),s+=e==="*"||e==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):n?s+="\\/*$":e!==""&&e!=="/"&&(s+="(?:(?=\\/|$))"),[new RegExp(s,t?void 0:"i"),r]}function $D(e){try{return e.split("/").map(t=>decodeURIComponent(t).replace(/\//g,"%2F")).join("/")}catch(t){return wt(!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 ln(e,t){if(t==="/")return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith("/")?t.length-1:t.length,r=e.charAt(n);return r&&r!=="/"?null:e.slice(n)||"/"}var DD=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;function TD(e,t="/"){let{pathname:n,search:r="",hash:s=""}=typeof e=="string"?Hr(e):e,a;return n?(n=Dy(n),n.startsWith("/")?a=up(n.substring(1),"/"):a=up(n,t)):a=t,{pathname:a,search:OD(r),hash:BD(s)}}function up(e,t){let n=Ws(t).split("/");return e.split("/").forEach(s=>{s===".."?n.length>1&&n.pop():s!=="."&&n.push(s)}),n.length>1?n.join("/"):"/"}function Si(e,t,n,r){return`Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(r)}]. 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 LD(e){return e.filter((t,n)=>n===0||t.route.path&&t.route.path.length>0)}function bd(e){let t=LD(e);return t.map((n,r)=>r===t.length-1?n.pathname:n.pathnameBase)}function $a(e,t,n,r=!1){let s;typeof e=="string"?s=Hr(e):(s={...e},ze(!s.pathname||!s.pathname.includes("?"),Si("?","pathname","search",s)),ze(!s.pathname||!s.pathname.includes("#"),Si("#","pathname","hash",s)),ze(!s.search||!s.search.includes("#"),Si("#","search","hash",s)));let a=e===""||s.pathname==="",i=a?"/":s.pathname,l;if(i==null)l=n;else{let p=t.length-1;if(!r&&i.startsWith("..")){let h=i.split("/");for(;h[0]==="..";)h.shift(),p-=1;s.pathname=h.join("/")}l=p>=0?t[p]:"/"}let c=TD(s,l),d=i&&i!=="/"&&i.endsWith("/"),f=(a||i===".")&&n.endsWith("/");return!c.pathname.endsWith("/")&&(d||f)&&(c.pathname+="/"),c}var Dy=e=>e.replace(/\/\/+/g,"/"),Rt=e=>Dy(e.join("/")),Ws=e=>e.replace(/\/+$/,""),RD=e=>Ws(e).replace(/^\/*/,"/"),OD=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,BD=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e,zD=class{constructor(e,t,n,r=!1){this.status=e,this.statusText=t||"",this.internal=r,n instanceof Error?(this.data=n.toString(),this.error=n):this.data=n}};function FD(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}function jD(e){let t=e.map(n=>n.route.path).filter(Boolean);return Rt(t)||"/"}var Ty=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Ly(e,t){let n=e;if(typeof n!="string"||!DD.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let r=n,s=!1;if(Ty)try{let a=new URL(window.location.href),i=n.startsWith("//")?new URL(a.protocol+n):new URL(n),l=ln(i.pathname,t);i.origin===a.origin&&l!=null?n=l+i.search+i.hash:s=!0}catch{wt(!1,`<Link to="${n}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:r,isExternal:s,to:n}}Object.getOwnPropertyNames(Object.prototype).sort().join("\0");var Ry=["POST","PUT","PATCH","DELETE"];new Set(Ry);var HD=["GET",...Ry];new Set(HD);var Vr=Be(null);Vr.displayName="DataRouter";var Da=Be(null);Da.displayName="DataRouterState";var Oy=Be(!1);function VD(){return ve(Oy)}var By=Be({isTransitioning:!1});By.displayName="ViewTransition";var qD=Be(new Map);qD.displayName="Fetchers";var UD=Be(null);UD.displayName="Await";var gt=Be(null);gt.displayName="Navigation";var Ho=Be(null);Ho.displayName="Location";var Ct=Be({outlet:null,matches:[],isDataRoute:!1});Ct.displayName="Route";var xd=Be(null);xd.displayName="RouteError";var zy="REACT_ROUTER_ERROR",QD="REDIRECT",GD="ROUTE_ERROR_RESPONSE";function KD(e){if(e.startsWith(`${zy}:${QD}:{`))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 WD(e){if(e.startsWith(`${zy}:${GD}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t=="object"&&t&&typeof t.status=="number"&&typeof t.statusText=="string")return new zD(t.status,t.statusText,t.data)}catch{}}function YD(e,{relative:t}={}){ze(qr(),"useHref() may be used only in the context of a <Router> component.");let{basename:n,navigator:r}=ve(gt),{hash:s,pathname:a,search:i}=Vo(e,{relative:t}),l=a;return n!=="/"&&(l=a==="/"?n:Rt([n,a])),r.createHref({pathname:l,search:i,hash:s})}function qr(){return ve(Ho)!=null}function bt(){return ze(qr(),"useLocation() may be used only in the context of a <Router> component."),ve(Ho).location}var Fy="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function jy(e){ve(gt).static||ba(e)}function et(){let{isDataRoute:e}=ve(Ct);return e?uT():ZD()}function ZD(){ze(qr(),"useNavigate() may be used only in the context of a <Router> component.");let e=ve(Vr),{basename:t,navigator:n}=ve(gt),{matches:r}=ve(Ct),{pathname:s}=bt(),a=JSON.stringify(bd(r)),i=ne(!1);return jy(()=>{i.current=!0}),U((c,d={})=>{if(wt(i.current,Fy),!i.current)return;if(typeof c=="number"){n.go(c);return}let f=$a(c,JSON.parse(a),s,d.relative==="path");e==null&&t!=="/"&&(f.pathname=f.pathname==="/"?t:Rt([t,f.pathname])),(d.replace?n.replace:n.push)(f,d.state,d)},[t,n,a,s,e])}var XD=Be(null);function JD(e){let t=ve(Ct).outlet;return q(()=>t&&Me(XD.Provider,{value:e},t),[t,e])}function yd(){let{matches:e}=ve(Ct);return e[e.length-1]?.params??{}}function Vo(e,{relative:t}={}){let{matches:n}=ve(Ct),{pathname:r}=bt(),s=JSON.stringify(bd(n));return q(()=>$a(e,JSON.parse(s),r,t==="path"),[e,s,r,t])}function eT(e,t){return Hy(e,t)}function Hy(e,t,n){ze(qr(),"useRoutes() may be used only in the context of a <Router> component.");let{navigator:r}=ve(gt),{matches:s}=ve(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||"";qy(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.
549
-
550
- Please change the parent <Route path="${x}"> to <Route path="${x==="/"?"*":`${x}/*`}">.`)}let f=bt(),p;if(t){let x=typeof t=="string"?Hr(t):t;ze(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.`),p=x}else p=f;let h=p.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})):Py(e,{pathname:m});wt(d||g!=null,`No routes matched location "${p.pathname}${p.search}${p.hash}" `),wt(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 "${p.pathname}${p.search}${p.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=sT(g&&g.map(x=>Object.assign({},x,{params:Object.assign({},i,x.params),pathname:Rt([c,r.encodeLocation?r.encodeLocation(x.pathname.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:x.pathname]),pathnameBase:x.pathnameBase==="/"?c:Rt([c,r.encodeLocation?r.encodeLocation(x.pathnameBase.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:x.pathnameBase])})),s,n);return t&&b?Me(Ho.Provider,{value:{location:{pathname:"/",search:"",hash:"",state:null,key:"default",mask:void 0,...p},navigationType:"POP"}},b):b}function tT(){let e=dT(),t=FD(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,r="rgba(200,200,200, 0.5)",s={padding:"0.5rem",backgroundColor:r},a={padding:"2px 4px",backgroundColor:r},i=null;return console.error("Error handled by React Router default ErrorBoundary:",e),i=Me(Sr,null,Me("p",null,"💿 Hey developer 👋"),Me("p",null,"You can provide a way better UX than this when your app throws errors by providing your own ",Me("code",{style:a},"ErrorBoundary")," or"," ",Me("code",{style:a},"errorElement")," prop on your route.")),Me(Sr,null,Me("h2",null,"Unexpected Application Error!"),Me("h3",{style:{fontStyle:"italic"}},t),n?Me("pre",{style:s},n):null,i)}var nT=Me(tT,null),Vy=class extends bN{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=WD(e.digest);n&&(e=n)}let t=e!==void 0?Me(Ct.Provider,{value:this.props.routeContext},Me(xd.Provider,{value:e,children:this.props.component})):this.props.children;return this.context?Me(rT,{error:e},t):t}};Vy.contextType=Oy;var Ci=new WeakMap;function rT({children:e,error:t}){let{basename:n}=ve(gt);if(typeof t=="object"&&t&&"digest"in t&&typeof t.digest=="string"){let r=KD(t.digest);if(r){let s=Ci.get(t);if(s)throw s;let a=Ly(r.location,n);if(Ty&&!Ci.get(t))if(a.isExternal||r.reloadDocument)window.location.href=a.absoluteURL||a.to;else{const i=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(a.to,{replace:r.replace}));throw Ci.set(t,i),i}return Me("meta",{httpEquiv:"refresh",content:`0;url=${a.absoluteURL||a.to}`})}}return e}function oT({routeContext:e,match:t,children:n}){let r=ve(Vr);return r&&r.static&&r.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(r.staticContext._deepestRenderedBoundaryId=t.route.id),Me(Ct.Provider,{value:e},n)}function sT(e,t=[],n){let r=n?.state;if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let s=e,a=r?.errors;if(a!=null){let f=s.findIndex(p=>p.route.id&&a?.[p.route.id]!==void 0);ze(f>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(",")}`),s=s.slice(0,Math.min(s.length,f+1))}let i=!1,l=-1;if(n&&r){i=r.renderFallback;for(let f=0;f<s.length;f++){let p=s[f];if((p.route.HydrateFallback||p.route.hydrateFallbackElement)&&(l=f),p.route.id){let{loaderData:h,errors:m}=r,g=p.route.loader&&!h.hasOwnProperty(p.route.id)&&(!m||m[p.route.id]===void 0);if(p.route.lazy||g){n.isStatic&&(i=!0),l>=0?s=s.slice(0,l+1):s=[s[0]];break}}}}let c=n?.onError,d=r&&c?(f,p)=>{c(f,{location:r.location,params:r.matches?.[0]?.params??{},pattern:jD(r.matches),errorInfo:p})}:void 0;return s.reduceRight((f,p,h)=>{let m,g=!1,b=null,x=null;r&&(m=a&&p.route.id?a[p.route.id]:void 0,b=p.route.errorElement||nT,i&&(l<0&&h===0?(qy("route-fallback",!1,"No `HydrateFallback` element provided to render during initial hydration"),g=!0,x=null):l===h&&(g=!0,x=p.route.hydrateFallbackElement||null)));let y=t.concat(s.slice(0,h+1)),w=()=>{let v;return m?v=b:g?v=x:p.route.Component?v=Me(p.route.Component,null):p.route.element?v=p.route.element:v=f,Me(oT,{match:p,routeContext:{outlet:f,matches:y,isDataRoute:r!=null},children:v})};return r&&(p.route.ErrorBoundary||p.route.errorElement||h===0)?Me(Vy,{location:r.location,revalidation:r.revalidation,component:b,error:m,children:w(),routeContext:{outlet:null,matches:y,isDataRoute:!0},onError:d}):w()},null)}function vd(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function aT(e){let t=ve(Vr);return ze(t,vd(e)),t}function iT(e){let t=ve(Da);return ze(t,vd(e)),t}function lT(e){let t=ve(Ct);return ze(t,vd(e)),t}function wd(e){let t=lT(e),n=t.matches[t.matches.length-1];return ze(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function cT(){return wd("useRouteId")}function dT(){let e=ve(xd),t=iT("useRouteError"),n=wd("useRouteError");return e!==void 0?e:t.errors?.[n]}function uT(){let{router:e}=aT("useNavigate"),t=wd("useNavigate"),n=ne(!1);return jy(()=>{n.current=!0}),U(async(s,a={})=>{wt(n.current,Fy),n.current&&(typeof s=="number"?await e.navigate(s):await e.navigate(s,{fromRouteId:t,...a}))},[e,t])}var pp={};function qy(e,t,n){!t&&!pp[e]&&(pp[e]=!0,wt(!1,n))}He(pT);function pT({routes:e,manifest:t,future:n,state:r,isStatic:s,onError:a}){return Hy(e,void 0,{manifest:t,state:r,isStatic:s,onError:a})}function xt({to:e,replace:t,state:n,relative:r}){ze(qr(),"<Navigate> may be used only in the context of a <Router> component.");let{static:s}=ve(gt);wt(!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}=ve(Ct),{pathname:i}=bt(),l=et(),c=$a(e,bd(a),i,r==="path"),d=JSON.stringify(c);return Y(()=>{l(JSON.parse(d),{replace:t,state:n,relative:r})},[l,d,r,t,n]),null}function fT(e){return JD(e.context)}function De(e){ze(!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 hT({basename:e="/",children:t=null,location:n,navigationType:r="POP",navigator:s,static:a=!1,useTransitions:i}){ze(!qr(),"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=Hr(n));let{pathname:d="/",search:f="",hash:p="",state:h=null,key:m="default",mask:g}=n,b=q(()=>{let x=ln(d,l);return x==null?null:{location:{pathname:x,search:f,hash:p,state:h,key:m,mask:g},navigationType:r}},[l,d,f,p,h,m,r,g]);return wt(b!=null,`<Router basename="${l}"> is not able to match the URL "${d}${f}${p}" because it does not start with the basename, so the <Router> won't render anything.`),b==null?null:Me(gt.Provider,{value:c},Me(Ho.Provider,{children:t,value:b}))}function mT({children:e,location:t}){return eT(El(e),t)}function El(e,t=[]){let n=[];return mN.forEach(e,(r,s)=>{if(!gN(r))return;let a=[...t,s];if(r.type===Sr){n.push.apply(n,El(r.props.children,a));return}ze(r.type===De,`[${typeof r.type=="string"?r.type:r.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`),ze(!r.props.index||!r.props.children,"An index route cannot have child routes.");let i={id:r.props.id||a.join("-"),caseSensitive:r.props.caseSensitive,element:r.props.element,Component:r.props.Component,index:r.props.index,path:r.props.path,middleware:r.props.middleware,loader:r.props.loader,action:r.props.action,hydrateFallbackElement:r.props.hydrateFallbackElement,HydrateFallback:r.props.HydrateFallback,errorElement:r.props.errorElement,ErrorBoundary:r.props.ErrorBoundary,hasErrorBoundary:r.props.hasErrorBoundary===!0||r.props.ErrorBoundary!=null||r.props.errorElement!=null,shouldRevalidate:r.props.shouldRevalidate,handle:r.props.handle,lazy:r.props.lazy};r.props.children&&(i.children=El(r.props.children,a)),n.push(i)}),n}var Ts="get",Ls="application/x-www-form-urlencoded";function Ta(e){return typeof HTMLElement<"u"&&e instanceof HTMLElement}function gT(e){return Ta(e)&&e.tagName.toLowerCase()==="button"}function bT(e){return Ta(e)&&e.tagName.toLowerCase()==="form"}function xT(e){return Ta(e)&&e.tagName.toLowerCase()==="input"}function yT(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function vT(e,t){return e.button===0&&(!t||t==="_self")&&!yT(e)}function Il(e=""){return new URLSearchParams(typeof e=="string"||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(s=>[n,s]):[[n,r]])},[]))}function wT(e,t){let n=Il(e);return t&&t.forEach((r,s)=>{n.has(s)||t.getAll(s).forEach(a=>{n.append(s,a)})}),n}var us=null;function NT(){if(us===null)try{new FormData(document.createElement("form"),0),us=!1}catch{us=!0}return us}var kT=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function Mi(e){return e!=null&&!kT.has(e)?(wt(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Ls}"`),null):e}function ST(e,t){let n,r,s,a,i;if(bT(e)){let l=e.getAttribute("action");r=l?ln(l,t):null,n=e.getAttribute("method")||Ts,s=Mi(e.getAttribute("enctype"))||Ls,a=new FormData(e)}else if(gT(e)||xT(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(r=c?ln(c,t):null,n=e.getAttribute("formmethod")||l.getAttribute("method")||Ts,s=Mi(e.getAttribute("formenctype"))||Mi(l.getAttribute("enctype"))||Ls,a=new FormData(l,e),!NT()){let{name:d,type:f,value:p}=e;if(f==="image"){let h=d?`${d}.`:"";a.append(`${h}x`,"0"),a.append(`${h}y`,"0")}else d&&a.append(d,p)}}else{if(Ta(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');n=Ts,r=null,s=Ls,i=e}return a&&s==="text/plain"&&(i=a,a=void 0),{action:r,method:n.toLowerCase(),encType:s,formData:a,body:i}}Object.getOwnPropertyNames(Object.prototype).sort().join("\0");function Nd(e,t){if(e===!1||e===null||typeof e>"u")throw new Error(t)}function Uy(e,t,n,r){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}_.${r}`:s.pathname=`${s.pathname}.${r}`:s.pathname==="/"?s.pathname=`_root.${r}`:t&&ln(s.pathname,t)==="/"?s.pathname=`${Ws(t)}/_root.${r}`:s.pathname=`${Ws(s.pathname)}.${r}`,s}async function CT(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 MT(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 ET(e,t,n){let r=await Promise.all(e.map(async s=>{let a=t.routes[s.route.id];if(a){let i=await CT(a,n);return i.links?i.links():[]}return[]}));return _T(r.flat(1).filter(MT).filter(s=>s.rel==="stylesheet"||s.rel==="preload").map(s=>s.rel==="stylesheet"?{...s,rel:"prefetch",as:"style"}:{...s,rel:"prefetch"}))}function fp(e,t,n,r,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 f=r.routes[c.route.id];if(!f||!f.hasLoader)return!1;if(i(c,d)||l(c,d))return!0;if(c.route.shouldRevalidate){let p=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 p=="boolean")return p}return!0}):[]}function IT(e,t,{includeHydrateFallback:n}={}){return AT(e.map(r=>{let s=t.routes[r.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 AT(e){return[...new Set(e)]}function PT(e){let t={},n=Object.keys(e).sort();for(let r of n)t[r]=e[r];return t}function _T(e,t){let n=new Set;return new Set(t),e.reduce((r,s)=>{let a=JSON.stringify(PT(s));return n.has(a)||(n.add(a),r.push({key:a,link:s})),r},[])}function kd(){let e=ve(Vr);return Nd(e,"You must render this element inside a <DataRouterContext.Provider> element"),e}function $T(){let e=ve(Da);return Nd(e,"You must render this element inside a <DataRouterStateContext.Provider> element"),e}var Sd=Be(void 0);Sd.displayName="FrameworkContext";function Cd(){let e=ve(Sd);return Nd(e,"You must render this element inside a <HydratedRouter> element"),e}function DT(e,t){let n=ve(Sd),[r,s]=P(!1),[a,i]=P(!1),{onFocus:l,onBlur:c,onMouseEnter:d,onMouseLeave:f,onTouchStart:p}=t,h=ne(null);Y(()=>{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]),Y(()=>{if(r){let b=setTimeout(()=>{i(!0)},100);return()=>{clearTimeout(b)}}},[r]);let m=()=>{s(!0)},g=()=>{s(!1),i(!1)};return n?e!=="intent"?[a,h,{}]:[a,h,{onFocus:Yr(l,m),onBlur:Yr(c,g),onMouseEnter:Yr(d,m),onMouseLeave:Yr(f,g),onTouchStart:Yr(p,m)}]:[!1,h,{}]}function Yr(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function TT({page:e,...t}){let n=VD(),{router:r}=kd(),s=q(()=>Py(r.routes,e,r.basename),[r.routes,e,r.basename]);return s?n?Me(RT,{page:e,matches:s,...t}):Me(OT,{page:e,matches:s,...t}):null}function LT(e){let{manifest:t,routeModules:n}=Cd(),[r,s]=P([]);return Y(()=>{let a=!1;return ET(e,t,n).then(i=>{a||s(i)}),()=>{a=!0}},[e,t,n]),r}function RT({page:e,matches:t,...n}){let r=bt(),{future:s}=Cd(),{basename:a}=kd(),i=q(()=>{if(e===r.pathname+r.search+r.hash)return[];let l=Uy(e,a,s.unstable_trailingSlashAwareDataRequests,"rsc"),c=!1,d=[];for(let f of t)typeof f.route.shouldRevalidate=="function"?c=!0:d.push(f.route.id);return c&&d.length>0&&l.searchParams.set("_routes",d.join(",")),[l.pathname+l.search]},[a,s.unstable_trailingSlashAwareDataRequests,e,r,t]);return Me(Sr,null,i.map(l=>Me("link",{key:l,rel:"prefetch",as:"fetch",href:l,...n})))}function OT({page:e,matches:t,...n}){let r=bt(),{future:s,manifest:a,routeModules:i}=Cd(),{basename:l}=kd(),{loaderData:c,matches:d}=$T(),f=q(()=>fp(e,t,d,a,r,"data"),[e,t,d,a,r]),p=q(()=>fp(e,t,d,a,r,"assets"),[e,t,d,a,r]),h=q(()=>{if(e===r.pathname+r.search+r.hash)return[];let b=new Set,x=!1;if(t.forEach(w=>{let v=a.routes[w.route.id];!v||!v.hasLoader||(!f.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=Uy(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,r,a,f,t,e,i]),m=q(()=>IT(p,a),[p,a]),g=LT(p);return Me(Sr,null,h.map(b=>Me("link",{key:b,rel:"prefetch",as:"fetch",href:b,...n})),m.map(b=>Me("link",{key:b,rel:"modulepreload",href:b,...n})),g.map(({key:b,link:x})=>Me("link",{key:b,nonce:n.nonce,...x,crossOrigin:x.crossOrigin??n.crossOrigin})))}function BT(...e){return t=>{e.forEach(n=>{typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var zT=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";try{zT&&(window.__reactRouterVersion="7.15.0")}catch{}function FT({basename:e,children:t,useTransitions:n,window:r}){let s=ne();s.current==null&&(s.current=mD({window:r,v5Compat:!0}));let a=s.current,[i,l]=P({action:a.action,location:a.location}),c=U(d=>{n===!1?l(d):lc(()=>l(d))},[n]);return ba(()=>a.listen(c),[a,c]),Me(hT,{basename:e,children:t,location:i.location,navigationType:i.action,navigator:a,useTransitions:n})}var Qy=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Kn=qe(function({onClick:t,discover:n="render",prefetch:r="none",relative:s,reloadDocument:a,replace:i,mask:l,state:c,target:d,to:f,preventScrollReset:p,viewTransition:h,defaultShouldRevalidate:m,...g},b){let{basename:x,navigator:y,useTransitions:w}=ve(gt),v=typeof f=="string"&&Qy.test(f),N=Ly(f,x);f=N.to;let k=YD(f,{relative:s}),C=bt(),E=null;if(l){let T=$a(l,[],C.mask?C.mask.pathname:"/",!0);x!=="/"&&(T.pathname=T.pathname==="/"?x:Rt([x,T.pathname])),E=y.createHref(T)}let[A,I,z]=DT(r,g),$=qT(f,{replace:i,mask:l,state:c,target:d,preventScrollReset:p,relative:s,viewTransition:h,defaultShouldRevalidate:m,useTransitions:w});function B(T){t&&t(T),T.defaultPrevented||$(T)}let R=!(N.isExternal||a),M=Me("a",{...g,...z,href:(R?E:void 0)||N.absoluteURL||k,onClick:R?B:t,ref:BT(b,I),target:d,"data-discover":!v&&n==="render"?"true":void 0});return A&&!v?Me(Sr,null,M,Me(TT,{page:k})):M});Kn.displayName="Link";var jT=qe(function({"aria-current":t="page",caseSensitive:n=!1,className:r="",end:s=!1,style:a,to:i,viewTransition:l,children:c,...d},f){let p=Vo(i,{relative:d.relative}),h=bt(),m=ve(Da),{navigator:g,basename:b}=ve(gt),x=m!=null&&WT(p)&&l===!0,y=g.encodeLocation?g.encodeLocation(p).pathname:p.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=ln(v,b)||v);const N=y!=="/"&&y.endsWith("/")?y.length-1:y.length;let k=w===y||!s&&w.startsWith(y)&&w.charAt(N)==="/",C=v!=null&&(v===y||!s&&v.startsWith(y)&&v.charAt(y.length)==="/"),E={isActive:k,isPending:C,isTransitioning:x},A=k?t:void 0,I;typeof r=="function"?I=r(E):I=[r,k?"active":null,C?"pending":null,x?"transitioning":null].filter(Boolean).join(" ");let z=typeof a=="function"?a(E):a;return Me(Kn,{...d,"aria-current":A,className:I,ref:f,style:z,to:i,viewTransition:l},typeof c=="function"?c(E):c)});jT.displayName="NavLink";var HT=qe(({discover:e="render",fetcherKey:t,navigate:n,reloadDocument:r,replace:s,state:a,method:i=Ts,action:l,onSubmit:c,relative:d,preventScrollReset:f,viewTransition:p,defaultShouldRevalidate:h,...m},g)=>{let{useTransitions:b}=ve(gt),x=GT(),y=KT(l,{relative:d}),w=i.toLowerCase()==="get"?"get":"post",v=typeof l=="string"&&Qy.test(l);return Me("form",{ref:g,method:w,action:y,onSubmit:r?c:k=>{if(c&&c(k),k.defaultPrevented)return;k.preventDefault();let C=k.nativeEvent.submitter,E=C?.getAttribute("formmethod")||i,A=()=>x(C||k.currentTarget,{fetcherKey:t,method:E,navigate:n,replace:s,state:a,relative:d,preventScrollReset:f,viewTransition:p,defaultShouldRevalidate:h});b&&n!==!1?lc(()=>A()):A()},...m,"data-discover":!v&&e==="render"?"true":void 0})});HT.displayName="Form";function VT(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Gy(e){let t=ve(Vr);return ze(t,VT(e)),t}function qT(e,{target:t,replace:n,mask:r,state:s,preventScrollReset:a,relative:i,viewTransition:l,defaultShouldRevalidate:c,useTransitions:d}={}){let f=et(),p=bt(),h=Vo(e,{relative:i});return U(m=>{if(vT(m,t)){m.preventDefault();let g=n!==void 0?n:vo(p)===vo(h),b=()=>f(e,{replace:g,mask:r,state:s,preventScrollReset:a,relative:i,viewTransition:l,defaultShouldRevalidate:c});d?lc(()=>b()):b()}},[p,f,h,n,r,s,t,e,a,i,l,c,d])}function La(e){wt(typeof URLSearchParams<"u","You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let t=ne(Il(e)),n=ne(!1),r=bt(),s=q(()=>wT(r.search,n.current?null:t.current),[r.search]),a=et(),i=U((l,c)=>{const d=Il(typeof l=="function"?l(new URLSearchParams(s)):l);n.current=!0,a("?"+d,c)},[a,s]);return[s,i]}var UT=0,QT=()=>`__${String(++UT)}__`;function GT(){let{router:e}=Gy("useSubmit"),{basename:t}=ve(gt),n=cT(),r=e.fetch,s=e.navigate;return U(async(a,i={})=>{let{action:l,method:c,encType:d,formData:f,body:p}=ST(a,t);if(i.navigate===!1){let h=i.fetcherKey||QT();await r(h,n,i.action||l,{defaultShouldRevalidate:i.defaultShouldRevalidate,preventScrollReset:i.preventScrollReset,formData:f,body:p,formMethod:i.method||c,formEncType:i.encType||d,flushSync:i.flushSync})}else await s(i.action||l,{defaultShouldRevalidate:i.defaultShouldRevalidate,preventScrollReset:i.preventScrollReset,formData:f,body:p,formMethod:i.method||c,formEncType:i.encType||d,replace:i.replace,state:i.state,fromRouteId:n,flushSync:i.flushSync,viewTransition:i.viewTransition})},[r,s,t,n])}function KT(e,{relative:t}={}){let{basename:n}=ve(gt),r=ve(Ct);ze(r,"useFormAction must be used inside a RouteContext");let[s]=r.matches.slice(-1),a={...Vo(e||".",{relative:t})},i=bt();if(e==null){a.search=i.search;let l=new URLSearchParams(a.search),c=l.getAll("index");if(c.some(f=>f==="")){l.delete("index"),c.filter(p=>p).forEach(p=>l.append("index",p));let f=l.toString();a.search=f?`?${f}`:""}}return(!e||e===".")&&s.route.index&&(a.search=a.search?a.search.replace(/^\?/,"?index&"):"?index"),n!=="/"&&(a.pathname=a.pathname==="/"?n:Rt([n,a.pathname])),vo(a)}function WT(e,{relative:t}={}){let n=ve(By);ze(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:r}=Gy("useViewTransitionState"),s=Vo(e,{relative:t});if(!n.isTransitioning)return!1;let a=ln(n.currentLocation.pathname,r)||n.currentLocation.pathname,i=ln(n.nextLocation.pathname,r)||n.nextLocation.pathname;return Ks(s.pathname,i)!=null||Ks(s.pathname,a)!=null}const YT=3e4;function ZT(e){const t=ne(e);t.current=e,Y(()=>{let n=null;const r=()=>{if(document.visibilityState==="hidden"){n=Date.now();return}if(document.visibilityState==="visible"&&n!==null){const i=Date.now()-n;n=null,i>=YT&&t.current()}},s=()=>{t.current()},a=i=>{i.persisted&&t.current()};return document.addEventListener("visibilitychange",r),window.addEventListener("online",s),window.addEventListener("pageshow",a),()=>{document.removeEventListener("visibilitychange",r),window.removeEventListener("online",s),window.removeEventListener("pageshow",a)}},[])}let Al="disconnected";const Pl=new Set;function XT(){for(const e of Pl)e()}function JT(e){Al!==e&&(Al=e,XT())}function eL(e){return Pl.add(e),()=>{Pl.delete(e)}}function hp(){return Al}function tL(){return xa(eL,hp,hp)}let io=null;function Rs(){if(!io){const e=window.location.origin,t=localStorage.getItem("camstack_admin_token")??void 0;io=Th({serverUrl:e,token:t,onConnectionChange:n=>JT(n)})}return io}function mr(){io?.close(),io=null}function nL(e){const t=hn();return t===null?o("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."}):o(lt,{widgetId:"pipeline-orchestrator/zone-editor",host:"device-tab",deviceId:t})}function rL({deviceId:e}){return u("div",{className:sm,children:[u("div",{className:`grid ${am}`,style:{gridTemplateColumns:"repeat(auto-fit, minmax(min(100%, 340px), 1fr))"},children:[o(lt,{widgetId:"pipeline-analytics/live-occupancy-panel",host:"device-tab",deviceId:e}),o(lt,{widgetId:"pipeline-analytics/audio-metrics-panel",host:"device-tab",deviceId:e})]}),o(lt,{widgetId:"pipeline-analytics/audio-history-chart",host:"device-tab",deviceId:e}),o(lt,{widgetId:"pipeline-analytics/occupancy-history-chart",host:"device-tab",deviceId:e}),o(lt,{widgetId:"pipeline-analytics/motion-history-chart",host:"device-tab",deviceId:e}),o(lt,{widgetId:"pipeline-analytics/detection-history-chart",host:"device-tab",deviceId:e})]})}function oL(e){const t=hn();return t===null?o("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."}):o(rL,{deviceId:t})}/**
551
- * @license lucide-react v0.511.0 - ISC
552
- *
553
- * This source code is licensed under the ISC license.
554
- * See the LICENSE file in the root directory of this source tree.
555
- */const sL=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),aL=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,r)=>r?r.toUpperCase():n.toLowerCase()),mp=e=>{const t=aL(e);return t.charAt(0).toUpperCase()+t.slice(1)},Ky=(...e)=>e.filter((t,n,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===n).join(" ").trim(),iL=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};/**
556
- * @license lucide-react v0.511.0 - ISC
557
- *
558
- * This source code is licensed under the ISC license.
559
- * See the LICENSE file in the root directory of this source tree.
560
- */var lL={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"};/**
561
- * @license lucide-react v0.511.0 - ISC
562
- *
563
- * This source code is licensed under the ISC license.
564
- * See the LICENSE file in the root directory of this source tree.
565
- */const cL=qe(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:s="",children:a,iconNode:i,...l},c)=>Me("svg",{ref:c,...lL,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:Ky("lucide",s),...!a&&!iL(l)&&{"aria-hidden":"true"},...l},[...i.map(([d,f])=>Me(d,f)),...Array.isArray(a)?a:[a]]));/**
566
- * @license lucide-react v0.511.0 - ISC
567
- *
568
- * This source code is licensed under the ISC license.
569
- * See the LICENSE file in the root directory of this source tree.
570
- */const oe=(e,t)=>{const n=qe(({className:r,...s},a)=>Me(cL,{ref:a,iconNode:t,className:Ky(`lucide-${sL(mp(e))}`,`lucide-${e}`,r),...s}));return n.displayName=mp(e),n};/**
571
- * @license lucide-react v0.511.0 - ISC
572
- *
573
- * This source code is licensed under the ISC license.
574
- * See the LICENSE file in the root directory of this source tree.
575
- */const dL=[["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"}]],qo=oe("activity",dL);/**
576
- * @license lucide-react v0.511.0 - ISC
577
- *
578
- * This source code is licensed under the ISC license.
579
- * See the LICENSE file in the root directory of this source tree.
580
- */const uL=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],Wy=oe("archive",uL);/**
581
- * @license lucide-react v0.511.0 - ISC
582
- *
583
- * This source code is licensed under the ISC license.
584
- * See the LICENSE file in the root directory of this source tree.
585
- */const pL=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],Md=oe("arrow-left",pL);/**
586
- * @license lucide-react v0.511.0 - ISC
587
- *
588
- * This source code is licensed under the ISC license.
589
- * See the LICENSE file in the root directory of this source tree.
590
- */const fL=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],hL=oe("arrow-right",fL);/**
591
- * @license lucide-react v0.511.0 - ISC
592
- *
593
- * This source code is licensed under the ISC license.
594
- * See the LICENSE file in the root directory of this source tree.
595
- */const mL=[["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"}]],gL=oe("battery-full",mL);/**
596
- * @license lucide-react v0.511.0 - ISC
597
- *
598
- * This source code is licensed under the ISC license.
599
- * See the LICENSE file in the root directory of this source tree.
600
- */const bL=[["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"}]],Uo=oe("bell",bL);/**
601
- * @license lucide-react v0.511.0 - ISC
602
- *
603
- * This source code is licensed under the ISC license.
604
- * See the LICENSE file in the root directory of this source tree.
605
- */const xL=[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}]],yL=oe("book-open",xL);/**
606
- * @license lucide-react v0.511.0 - ISC
607
- *
608
- * This source code is licensed under the ISC license.
609
- * See the LICENSE file in the root directory of this source tree.
610
- */const vL=[["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"}]],wL=oe("bot",vL);/**
611
- * @license lucide-react v0.511.0 - ISC
612
- *
613
- * This source code is licensed under the ISC license.
614
- * See the LICENSE file in the root directory of this source tree.
615
- */const NL=[["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"}]],Ra=oe("box",NL);/**
616
- * @license lucide-react v0.511.0 - ISC
617
- *
618
- * This source code is licensed under the ISC license.
619
- * See the LICENSE file in the root directory of this source tree.
620
- */const kL=[["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"}]],Qo=oe("boxes",kL);/**
621
- * @license lucide-react v0.511.0 - ISC
622
- *
623
- * This source code is licensed under the ISC license.
624
- * See the LICENSE file in the root directory of this source tree.
625
- */const SL=[["path",{d:"M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5",key:"1osxxc"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M3 10h5",key:"r794hk"}],["path",{d:"M17.5 17.5 16 16.3V14",key:"akvzfd"}],["circle",{cx:"16",cy:"16",r:"6",key:"qoo3c4"}]],CL=oe("calendar-clock",SL);/**
626
- * @license lucide-react v0.511.0 - ISC
627
- *
628
- * This source code is licensed under the ISC license.
629
- * See the LICENSE file in the root directory of this source tree.
630
- */const ML=[["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"}]],Yy=oe("calendar",ML);/**
631
- * @license lucide-react v0.511.0 - ISC
632
- *
633
- * This source code is licensed under the ISC license.
634
- * See the LICENSE file in the root directory of this source tree.
635
- */const EL=[["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"}]],Cr=oe("camera",EL);/**
636
- * @license lucide-react v0.511.0 - ISC
637
- *
638
- * This source code is licensed under the ISC license.
639
- * See the LICENSE file in the root directory of this source tree.
640
- */const IL=[["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"}]],Zy=oe("cctv",IL);/**
641
- * @license lucide-react v0.511.0 - ISC
642
- *
643
- * This source code is licensed under the ISC license.
644
- * See the LICENSE file in the root directory of this source tree.
645
- */const AL=[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]],PL=oe("check-check",AL);/**
646
- * @license lucide-react v0.511.0 - ISC
647
- *
648
- * This source code is licensed under the ISC license.
649
- * See the LICENSE file in the root directory of this source tree.
650
- */const _L=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Mt=oe("check",_L);/**
651
- * @license lucide-react v0.511.0 - ISC
652
- *
653
- * This source code is licensed under the ISC license.
654
- * See the LICENSE file in the root directory of this source tree.
655
- */const $L=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],Nt=oe("chevron-down",$L);/**
656
- * @license lucide-react v0.511.0 - ISC
657
- *
658
- * This source code is licensed under the ISC license.
659
- * See the LICENSE file in the root directory of this source tree.
660
- */const DL=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Ed=oe("chevron-left",DL);/**
661
- * @license lucide-react v0.511.0 - ISC
662
- *
663
- * This source code is licensed under the ISC license.
664
- * See the LICENSE file in the root directory of this source tree.
665
- */const TL=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Et=oe("chevron-right",TL);/**
666
- * @license lucide-react v0.511.0 - ISC
667
- *
668
- * This source code is licensed under the ISC license.
669
- * See the LICENSE file in the root directory of this source tree.
670
- */const LL=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],RL=oe("chevron-up",LL);/**
671
- * @license lucide-react v0.511.0 - ISC
672
- *
673
- * This source code is licensed under the ISC license.
674
- * See the LICENSE file in the root directory of this source tree.
675
- */const OL=[["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"}]],Mr=oe("circle-alert",OL);/**
676
- * @license lucide-react v0.511.0 - ISC
677
- *
678
- * This source code is licensed under the ISC license.
679
- * See the LICENSE file in the root directory of this source tree.
680
- */const BL=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],Ei=oe("circle-check-big",BL);/**
681
- * @license lucide-react v0.511.0 - ISC
682
- *
683
- * This source code is licensed under the ISC license.
684
- * See the LICENSE file in the root directory of this source tree.
685
- */const zL=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],Xy=oe("circle-check",zL);/**
686
- * @license lucide-react v0.511.0 - ISC
687
- *
688
- * This source code is licensed under the ISC license.
689
- * See the LICENSE file in the root directory of this source tree.
690
- */const FL=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]],Jy=oe("circle-dot",FL);/**
691
- * @license lucide-react v0.511.0 - ISC
692
- *
693
- * This source code is licensed under the ISC license.
694
- * See the LICENSE file in the root directory of this source tree.
695
- */const jL=[["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"}]],HL=oe("circle-help",jL);/**
696
- * @license lucide-react v0.511.0 - ISC
697
- *
698
- * This source code is licensed under the ISC license.
699
- * See the LICENSE file in the root directory of this source tree.
700
- */const VL=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]],qL=oe("clock",VL);/**
701
- * @license lucide-react v0.511.0 - ISC
702
- *
703
- * This source code is licensed under the ISC license.
704
- * See the LICENSE file in the root directory of this source tree.
705
- */const UL=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],e0=oe("copy",UL);/**
706
- * @license lucide-react v0.511.0 - ISC
707
- *
708
- * This source code is licensed under the ISC license.
709
- * See the LICENSE file in the root directory of this source tree.
710
- */const QL=[["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"}]],ft=oe("cpu",QL);/**
711
- * @license lucide-react v0.511.0 - ISC
712
- *
713
- * This source code is licensed under the ISC license.
714
- * See the LICENSE file in the root directory of this source tree.
715
- */const GL=[["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"}]],KL=oe("crosshair",GL);/**
716
- * @license lucide-react v0.511.0 - ISC
717
- *
718
- * This source code is licensed under the ISC license.
719
- * See the LICENSE file in the root directory of this source tree.
720
- */const WL=[["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"}]],t0=oe("database",WL);/**
721
- * @license lucide-react v0.511.0 - ISC
722
- *
723
- * This source code is licensed under the ISC license.
724
- * See the LICENSE file in the root directory of this source tree.
725
- */const YL=[["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"}]],Cn=oe("download",YL);/**
726
- * @license lucide-react v0.511.0 - ISC
727
- *
728
- * This source code is licensed under the ISC license.
729
- * See the LICENSE file in the root directory of this source tree.
730
- */const ZL=[["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"}]],XL=oe("ellipsis-vertical",ZL);/**
731
- * @license lucide-react v0.511.0 - ISC
732
- *
733
- * This source code is licensed under the ISC license.
734
- * See the LICENSE file in the root directory of this source tree.
735
- */const JL=[["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"}]],Id=oe("external-link",JL);/**
736
- * @license lucide-react v0.511.0 - ISC
737
- *
738
- * This source code is licensed under the ISC license.
739
- * See the LICENSE file in the root directory of this source tree.
740
- */const eR=[["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"}]],n0=oe("eye-off",eR);/**
741
- * @license lucide-react v0.511.0 - ISC
742
- *
743
- * This source code is licensed under the ISC license.
744
- * See the LICENSE file in the root directory of this source tree.
745
- */const tR=[["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"}]],Go=oe("eye",tR);/**
746
- * @license lucide-react v0.511.0 - ISC
747
- *
748
- * This source code is licensed under the ISC license.
749
- * See the LICENSE file in the root directory of this source tree.
750
- */const nR=[["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"}]],lo=oe("film",nR);/**
751
- * @license lucide-react v0.511.0 - ISC
752
- *
753
- * This source code is licensed under the ISC license.
754
- * See the LICENSE file in the root directory of this source tree.
755
- */const rR=[["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"}]],oR=oe("flame",rR);/**
756
- * @license lucide-react v0.511.0 - ISC
757
- *
758
- * This source code is licensed under the ISC license.
759
- * See the LICENSE file in the root directory of this source tree.
760
- */const sR=[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]],r0=oe("gauge",sR);/**
761
- * @license lucide-react v0.511.0 - ISC
762
- *
763
- * This source code is licensed under the ISC license.
764
- * See the LICENSE file in the root directory of this source tree.
765
- */const aR=[["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"}]],_l=oe("ghost",aR);/**
766
- * @license lucide-react v0.511.0 - ISC
767
- *
768
- * This source code is licensed under the ISC license.
769
- * See the LICENSE file in the root directory of this source tree.
770
- */const iR=[["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"}]],lR=oe("git-branch",iR);/**
771
- * @license lucide-react v0.511.0 - ISC
772
- *
773
- * This source code is licensed under the ISC license.
774
- * See the LICENSE file in the root directory of this source tree.
775
- */const cR=[["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"}]],Wt=oe("globe",cR);/**
776
- * @license lucide-react v0.511.0 - ISC
777
- *
778
- * This source code is licensed under the ISC license.
779
- * See the LICENSE file in the root directory of this source tree.
780
- */const dR=[["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"}]],Ys=oe("hard-drive",dR);/**
781
- * @license lucide-react v0.511.0 - ISC
782
- *
783
- * This source code is licensed under the ISC license.
784
- * See the LICENSE file in the root directory of this source tree.
785
- */const uR=[["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"}]],pR=oe("house",uR);/**
786
- * @license lucide-react v0.511.0 - ISC
787
- *
788
- * This source code is licensed under the ISC license.
789
- * See the LICENSE file in the root directory of this source tree.
790
- */const fR=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],kn=oe("info",fR);/**
791
- * @license lucide-react v0.511.0 - ISC
792
- *
793
- * This source code is licensed under the ISC license.
794
- * See the LICENSE file in the root directory of this source tree.
795
- */const hR=[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]],mR=oe("key-round",hR);/**
796
- * @license lucide-react v0.511.0 - ISC
797
- *
798
- * This source code is licensed under the ISC license.
799
- * See the LICENSE file in the root directory of this source tree.
800
- */const gR=[["path",{d:"M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z",key:"165ttr"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814",key:"1ubxi2"}]],o0=oe("key-square",gR);/**
801
- * @license lucide-react v0.511.0 - ISC
802
- *
803
- * This source code is licensed under the ISC license.
804
- * See the LICENSE file in the root directory of this source tree.
805
- */const bR=[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]],xR=oe("key",bR);/**
806
- * @license lucide-react v0.511.0 - ISC
807
- *
808
- * This source code is licensed under the ISC license.
809
- * See the LICENSE file in the root directory of this source tree.
810
- */const yR=[["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"}]],vR=oe("layers",yR);/**
811
- * @license lucide-react v0.511.0 - ISC
812
- *
813
- * This source code is licensed under the ISC license.
814
- * See the LICENSE file in the root directory of this source tree.
815
- */const wR=[["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"}]],s0=oe("layout-dashboard",wR);/**
816
- * @license lucide-react v0.511.0 - ISC
817
- *
818
- * This source code is licensed under the ISC license.
819
- * See the LICENSE file in the root directory of this source tree.
820
- */const NR=[["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"}]],kR=oe("lightbulb",NR);/**
821
- * @license lucide-react v0.511.0 - ISC
822
- *
823
- * This source code is licensed under the ISC license.
824
- * See the LICENSE file in the root directory of this source tree.
825
- */const SR=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],Ee=oe("loader-circle",SR);/**
826
- * @license lucide-react v0.511.0 - ISC
827
- *
828
- * This source code is licensed under the ISC license.
829
- * See the LICENSE file in the root directory of this source tree.
830
- */const CR=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]],a0=oe("lock",CR);/**
831
- * @license lucide-react v0.511.0 - ISC
832
- *
833
- * This source code is licensed under the ISC license.
834
- * See the LICENSE file in the root directory of this source tree.
835
- */const MR=[["path",{d:"m10 17 5-5-5-5",key:"1bsop3"}],["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}]],ER=oe("log-in",MR);/**
836
- * @license lucide-react v0.511.0 - ISC
837
- *
838
- * This source code is licensed under the ISC license.
839
- * See the LICENSE file in the root directory of this source tree.
840
- */const IR=[["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"}]],Ad=oe("log-out",IR);/**
841
- * @license lucide-react v0.511.0 - ISC
842
- *
843
- * This source code is licensed under the ISC license.
844
- * See the LICENSE file in the root directory of this source tree.
845
- */const AR=[["path",{d:"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7",key:"132q7q"}],["rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",key:"izxlao"}]],PR=oe("mail",AR);/**
846
- * @license lucide-react v0.511.0 - ISC
847
- *
848
- * This source code is licensed under the ISC license.
849
- * See the LICENSE file in the root directory of this source tree.
850
- */const _R=[["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"}]],$R=oe("map-pin",_R);/**
851
- * @license lucide-react v0.511.0 - ISC
852
- *
853
- * This source code is licensed under the ISC license.
854
- * See the LICENSE file in the root directory of this source tree.
855
- */const DR=[["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"}]],Pd=oe("memory-stick",DR);/**
856
- * @license lucide-react v0.511.0 - ISC
857
- *
858
- * This source code is licensed under the ISC license.
859
- * See the LICENSE file in the root directory of this source tree.
860
- */const TR=[["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 18h16",key:"19g7jn"}],["path",{d:"M4 6h16",key:"1o0s65"}]],LR=oe("menu",TR);/**
861
- * @license lucide-react v0.511.0 - ISC
862
- *
863
- * This source code is licensed under the ISC license.
864
- * See the LICENSE file in the root directory of this source tree.
865
- */const RR=[["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"}]],$l=oe("mic",RR);/**
866
- * @license lucide-react v0.511.0 - ISC
867
- *
868
- * This source code is licensed under the ISC license.
869
- * See the LICENSE file in the root directory of this source tree.
870
- */const OR=[["path",{d:"M5 12h14",key:"1ays0h"}]],BR=oe("minus",OR);/**
871
- * @license lucide-react v0.511.0 - ISC
872
- *
873
- * This source code is licensed under the ISC license.
874
- * See the LICENSE file in the root directory of this source tree.
875
- */const zR=[["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"}]],FR=oe("monitor",zR);/**
876
- * @license lucide-react v0.511.0 - ISC
877
- *
878
- * This source code is licensed under the ISC license.
879
- * See the LICENSE file in the root directory of this source tree.
880
- */const jR=[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]],i0=oe("moon",jR);/**
881
- * @license lucide-react v0.511.0 - ISC
882
- *
883
- * This source code is licensed under the ISC license.
884
- * See the LICENSE file in the root directory of this source tree.
885
- */const HR=[["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"}]],VR=oe("move",HR);/**
886
- * @license lucide-react v0.511.0 - ISC
887
- *
888
- * This source code is licensed under the ISC license.
889
- * See the LICENSE file in the root directory of this source tree.
890
- */const qR=[["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"}]],Mn=oe("network",qR);/**
891
- * @license lucide-react v0.511.0 - ISC
892
- *
893
- * This source code is licensed under the ISC license.
894
- * See the LICENSE file in the root directory of this source tree.
895
- */const UR=[["path",{d:"M12 16h.01",key:"1drbdi"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z",key:"1fd625"}]],QR=oe("octagon-alert",UR);/**
896
- * @license lucide-react v0.511.0 - ISC
897
- *
898
- * This source code is licensed under the ISC license.
899
- * See the LICENSE file in the root directory of this source tree.
900
- */const GR=[["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"}]],l0=oe("package",GR);/**
901
- * @license lucide-react v0.511.0 - ISC
902
- *
903
- * This source code is licensed under the ISC license.
904
- * See the LICENSE file in the root directory of this source tree.
905
- */const KR=[["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"}]],Ur=oe("pencil",KR);/**
906
- * @license lucide-react v0.511.0 - ISC
907
- *
908
- * This source code is licensed under the ISC license.
909
- * See the LICENSE file in the root directory of this source tree.
910
- */const WR=[["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"}]],c0=oe("pin",WR);/**
911
- * @license lucide-react v0.511.0 - ISC
912
- *
913
- * This source code is licensed under the ISC license.
914
- * See the LICENSE file in the root directory of this source tree.
915
- */const YR=[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]],Oa=oe("play",YR);/**
916
- * @license lucide-react v0.511.0 - ISC
917
- *
918
- * This source code is licensed under the ISC license.
919
- * See the LICENSE file in the root directory of this source tree.
920
- */const ZR=[["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"}]],wo=oe("plug",ZR);/**
921
- * @license lucide-react v0.511.0 - ISC
922
- *
923
- * This source code is licensed under the ISC license.
924
- * See the LICENSE file in the root directory of this source tree.
925
- */const XR=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],ot=oe("plus",XR);/**
926
- * @license lucide-react v0.511.0 - ISC
927
- *
928
- * This source code is licensed under the ISC license.
929
- * See the LICENSE file in the root directory of this source tree.
930
- */const JR=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],d0=oe("power",JR);/**
931
- * @license lucide-react v0.511.0 - ISC
932
- *
933
- * This source code is licensed under the ISC license.
934
- * See the LICENSE file in the root directory of this source tree.
935
- */const e6=[["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"}]],No=oe("puzzle",e6);/**
936
- * @license lucide-react v0.511.0 - ISC
937
- *
938
- * This source code is licensed under the ISC license.
939
- * See the LICENSE file in the root directory of this source tree.
940
- */const t6=[["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"}]],n6=oe("radar",t6);/**
941
- * @license lucide-react v0.511.0 - ISC
942
- *
943
- * This source code is licensed under the ISC license.
944
- * See the LICENSE file in the root directory of this source tree.
945
- */const r6=[["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"}]],Ba=oe("radio",r6);/**
946
- * @license lucide-react v0.511.0 - ISC
947
- *
948
- * This source code is licensed under the ISC license.
949
- * See the LICENSE file in the root directory of this source tree.
950
- */const o6=[["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"}]],ht=oe("refresh-cw",o6);/**
951
- * @license lucide-react v0.511.0 - ISC
952
- *
953
- * This source code is licensed under the ISC license.
954
- * See the LICENSE file in the root directory of this source tree.
955
- */const s6=[["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"}]],u0=oe("rotate-ccw",s6);/**
956
- * @license lucide-react v0.511.0 - ISC
957
- *
958
- * This source code is licensed under the ISC license.
959
- * See the LICENSE file in the root directory of this source tree.
960
- */const a6=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],yt=oe("rotate-cw",a6);/**
961
- * @license lucide-react v0.511.0 - ISC
962
- *
963
- * This source code is licensed under the ISC license.
964
- * See the LICENSE file in the root directory of this source tree.
965
- */const i6=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],l6=oe("save",i6);/**
966
- * @license lucide-react v0.511.0 - ISC
967
- *
968
- * This source code is licensed under the ISC license.
969
- * See the LICENSE file in the root directory of this source tree.
970
- */const c6=[["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"}]],rt=oe("scroll-text",c6);/**
971
- * @license lucide-react v0.511.0 - ISC
972
- *
973
- * This source code is licensed under the ISC license.
974
- * See the LICENSE file in the root directory of this source tree.
975
- */const d6=[["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"}]],u6=oe("search-x",d6);/**
976
- * @license lucide-react v0.511.0 - ISC
977
- *
978
- * This source code is licensed under the ISC license.
979
- * See the LICENSE file in the root directory of this source tree.
980
- */const p6=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],p0=oe("search",p6);/**
981
- * @license lucide-react v0.511.0 - ISC
982
- *
983
- * This source code is licensed under the ISC license.
984
- * See the LICENSE file in the root directory of this source tree.
985
- */const f6=[["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"}]],cn=oe("server",f6);/**
986
- * @license lucide-react v0.511.0 - ISC
987
- *
988
- * This source code is licensed under the ISC license.
989
- * See the LICENSE file in the root directory of this source tree.
990
- */const h6=[["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"}]],Yt=oe("settings",h6);/**
991
- * @license lucide-react v0.511.0 - ISC
992
- *
993
- * This source code is licensed under the ISC license.
994
- * See the LICENSE file in the root directory of this source tree.
995
- */const m6=[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]],g6=oe("share-2",m6);/**
996
- * @license lucide-react v0.511.0 - ISC
997
- *
998
- * This source code is licensed under the ISC license.
999
- * See the LICENSE file in the root directory of this source tree.
1000
- */const b6=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],dn=oe("shield-check",b6);/**
1001
- * @license lucide-react v0.511.0 - ISC
1002
- *
1003
- * This source code is licensed under the ISC license.
1004
- * See the LICENSE file in the root directory of this source tree.
1005
- */const x6=[["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"}]],y6=oe("shield-x",x6);/**
1006
- * @license lucide-react v0.511.0 - ISC
1007
- *
1008
- * This source code is licensed under the ISC license.
1009
- * See the LICENSE file in the root directory of this source tree.
1010
- */const v6=[["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"}]],w6=oe("shield",v6);/**
1011
- * @license lucide-react v0.511.0 - ISC
1012
- *
1013
- * This source code is licensed under the ISC license.
1014
- * See the LICENSE file in the root directory of this source tree.
1015
- */const N6=[["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"}]],ps=oe("skull",N6);/**
1016
- * @license lucide-react v0.511.0 - ISC
1017
- *
1018
- * This source code is licensed under the ISC license.
1019
- * See the LICENSE file in the root directory of this source tree.
1020
- */const k6=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],Er=oe("smartphone",k6);/**
1021
- * @license lucide-react v0.511.0 - ISC
1022
- *
1023
- * This source code is licensed under the ISC license.
1024
- * See the LICENSE file in the root directory of this source tree.
1025
- */const S6=[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]],C6=oe("sparkles",S6);/**
1026
- * @license lucide-react v0.511.0 - ISC
1027
- *
1028
- * This source code is licensed under the ISC license.
1029
- * See the LICENSE file in the root directory of this source tree.
1030
- */const M6=[["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"}]],f0=oe("square-check-big",M6);/**
1031
- * @license lucide-react v0.511.0 - ISC
1032
- *
1033
- * This source code is licensed under the ISC license.
1034
- * See the LICENSE file in the root directory of this source tree.
1035
- */const E6=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Ko=oe("square",E6);/**
1036
- * @license lucide-react v0.511.0 - ISC
1037
- *
1038
- * This source code is licensed under the ISC license.
1039
- * See the LICENSE file in the root directory of this source tree.
1040
- */const I6=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]],Ii=oe("star",I6);/**
1041
- * @license lucide-react v0.511.0 - ISC
1042
- *
1043
- * This source code is licensed under the ISC license.
1044
- * See the LICENSE file in the root directory of this source tree.
1045
- */const A6=[["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"}]],P6=oe("sun",A6);/**
1046
- * @license lucide-react v0.511.0 - ISC
1047
- *
1048
- * This source code is licensed under the ISC license.
1049
- * See the LICENSE file in the root directory of this source tree.
1050
- */const _6=[["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"}]],$6=oe("table-2",_6);/**
1051
- * @license lucide-react v0.511.0 - ISC
1052
- *
1053
- * This source code is licensed under the ISC license.
1054
- * See the LICENSE file in the root directory of this source tree.
1055
- */const D6=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],h0=oe("terminal",D6);/**
1056
- * @license lucide-react v0.511.0 - ISC
1057
- *
1058
- * This source code is licensed under the ISC license.
1059
- * See the LICENSE file in the root directory of this source tree.
1060
- */const T6=[["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"}]],Ke=oe("trash-2",T6);/**
1061
- * @license lucide-react v0.511.0 - ISC
1062
- *
1063
- * This source code is licensed under the ISC license.
1064
- * See the LICENSE file in the root directory of this source tree.
1065
- */const L6=[["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"}]],ut=oe("triangle-alert",L6);/**
1066
- * @license lucide-react v0.511.0 - ISC
1067
- *
1068
- * This source code is licensed under the ISC license.
1069
- * See the LICENSE file in the root directory of this source tree.
1070
- */const R6=[["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"}]],za=oe("upload",R6);/**
1071
- * @license lucide-react v0.511.0 - ISC
1072
- *
1073
- * This source code is licensed under the ISC license.
1074
- * See the LICENSE file in the root directory of this source tree.
1075
- */const O6=[["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"}]],B6=oe("users",O6);/**
1076
- * @license lucide-react v0.511.0 - ISC
1077
- *
1078
- * This source code is licensed under the ISC license.
1079
- * See the LICENSE file in the root directory of this source tree.
1080
- */const z6=[["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"}]],m0=oe("video",z6);/**
1081
- * @license lucide-react v0.511.0 - ISC
1082
- *
1083
- * This source code is licensed under the ISC license.
1084
- * See the LICENSE file in the root directory of this source tree.
1085
- */const F6=[["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"}]],g0=oe("wifi-off",F6);/**
1086
- * @license lucide-react v0.511.0 - ISC
1087
- *
1088
- * This source code is licensed under the ISC license.
1089
- * See the LICENSE file in the root directory of this source tree.
1090
- */const j6=[["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=oe("wifi",j6);/**
1091
- * @license lucide-react v0.511.0 - ISC
1092
- *
1093
- * This source code is licensed under the ISC license.
1094
- * See the LICENSE file in the root directory of this source tree.
1095
- */const H6=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Fe=oe("x",H6);/**
1096
- * @license lucide-react v0.511.0 - ISC
1097
- *
1098
- * This source code is licensed under the ISC license.
1099
- * See the LICENSE file in the root directory of this source tree.
1100
- */const V6=[["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"}]],q6=oe("wrench",V6);/**
1101
- * @license lucide-react v0.511.0 - ISC
1102
- *
1103
- * This source code is licensed under the ISC license.
1104
- * See the LICENSE file in the root directory of this source tree.
1105
- */const U6=[["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"}]],_d=oe("zap",U6);function Q6(e){const t=Le();return tr({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"),r=Reflect.get(t.trpcClient,e.capName);if(!n(r))throw new Error(`useFieldResolver: no cap namespace '${e.capName}' on the tRPC client`);const s=Reflect.get(r,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 G6(e){return typeof e=="string"&&e.length>0&&e!=="undefined"&&e!=="null"}function K6(e={}){const t=ke(),n=jr(void 0,{staleTime:1e4,enabled:e.enabled??!0}),r=q(()=>(n.data??[]).filter(i=>G6(i.nodeId)),[n.data]),s=U(()=>{t.invalidateQueries({queryKey:["pipelineOrchestrator","listAgentSettings"]})},[t]);return{agents:r,isLoading:n.isLoading,isError:n.isError,error:n.error,refetch:()=>{n.refetch()},invalidate:s}}function W6({field:e,disabled:t}){const n=ke(),r=e.deviceId,s=Q6(e.catalogResolver),a=Zc({agentNodeId:e.nodeId}),i=Jc({deviceId:r}),c=yx({onSuccess:()=>{n.invalidateQueries({queryKey:[["pipelineOrchestrator","getCameraSettings"]]}),n.invalidateQueries({queryKey:[["deviceManager"]]})}}),d=s.data,f=a.data??null,p=i.data??null,h=q(()=>d?Z6(d,f,p):[],[d,f,p]),m=q(()=>{if(!f)return{};const g={};for(const[b,x]of Object.entries(f.addonDefaults))g[b]=x.enabled;return g},[f]);return s.error?u("div",{className:"text-xs text-red-400",children:["Failed to load pipeline catalog for ",o("code",{children:e.nodeId}),": ",String(s.error.message??s.error)]}):s.isLoading||!d||a.isLoading?u("div",{className:"text-xs text-foreground-subtle animate-pulse",children:["Loading pipeline for ",e.nodeId,"…"]}):u("div",{className:"col-span-full space-y-4",children:[u("div",{className:"flex items-center gap-2 text-[11px] text-foreground-subtle",children:["Agent: ",o("span",{className:"text-foreground",children:e.nodeId}),u("span",{className:"ml-2",children:["Engine: ",o("span",{className:"text-foreground font-mono",children:`${d.selectedEngine.runtime}/${d.selectedEngine.backend}`})]}),u("span",{className:"ml-auto text-[10px]",children:["Model + settings edited on Pipeline → ",e.nodeId,"."]})]}),o(Oc,{schema:d,steps:h,onChange:()=>{},templates:[],selectedTemplateId:null,onSelectTemplate:()=>{},onSaveTemplate:()=>{},onUpdateTemplate:()=>{},onDeleteTemplate:()=>{},readOnly:t===!0,hideTemplates:!0,toggleMode:"threeState",hideModelAndSettings:!0,overrides:p?.stepToggles??{},onOverrideChange:(g,b)=>c.mutate({deviceId:r,addonId:g,enabled:b}),inheritedEnabledByAddon:m}),o(Y6,{deviceId:r,currentAgentNodeId:e.nodeId,catalog:d,pipelineByAgent:p?.pipelineByAgent??{},disabled:t===!0})]})}function Y6({deviceId:e,currentAgentNodeId:t,catalog:n,pipelineByAgent:r,disabled:s}){const a=ke(),[i,l]=P(!1),[c,d]=P(t),{agents:f}=K6({enabled:i}),p=Nx({deviceId:e,agentNodeId:c},{enabled:i}),m=wx({onSuccess:()=>{a.invalidateQueries({queryKey:[["pipelineOrchestrator","getCameraSettings"]]}),a.invalidateQueries({queryKey:[["pipelineOrchestrator","resolvePipeline"]]})}}),g=r[c]??null,b=f,x=q(()=>g?X6(g.steps,n):[],[g,n]),y=w=>{const v=g?.audio??null;m.mutate({deviceId:e,agentNodeId:c,pipeline:{steps:J6(w),audio:v?{modelId:v.modelId,enabled:v.enabled}:null}})};return u("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("button",{type:"button",onClick:()=>l(w=>!w),className:"w-full px-4 py-2 flex items-center gap-2 hover:bg-surface-hover",children:[i?o(Nt,{className:"h-3 w-3"}):o(Et,{className:"h-3 w-3"}),o("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide",children:"Advanced — custom pipeline per agent"}),o("span",{className:"ml-auto text-[10px] text-foreground-subtle",children:Object.keys(r).length>0?`${Object.keys(r).length} override(s) active`:"None configured"})]}),i&&u("div",{className:"border-t border-border px-4 py-3 space-y-3",children:[u("div",{className:"flex items-center gap-2 text-xs",children:[o("span",{className:"text-foreground-subtle",children:"Agent:"}),u("select",{value:c,disabled:s,onChange:w=>d(w.target.value),className:"rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary",children:[typeof t=="string"&&t.length>0&&t!=="undefined"&&u("option",{value:t,children:[t," (current)"]}),b.filter(w=>w.nodeId!==t).map(w=>o("option",{value:w.nodeId,children:w.nodeId},w.nodeId))]}),r[c]&&u("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:[o(Ke,{className:"h-3 w-3"}),"Remove override"]})]}),g?o(Oc,{schema:n,steps:x,onChange:y,templates:[],selectedTemplateId:null,onSelectTemplate:()=>{},onSaveTemplate:()=>{},onUpdateTemplate:()=>{},onDeleteTemplate:()=>{},readOnly:s,hideTemplates:!0}):u("div",{className:"text-xs text-foreground-subtle space-y-2",children:[u("p",{children:["No custom pipeline for ",o("code",{children:c}),". The camera uses the agent's default + step toggles."]}),o("button",{type:"button",onClick:()=>{const w=p.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||!p.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 Z6(e,t,n){const r=d=>{for(const f of e.slots)for(const p of f.addons)if(p.id===d)return p;return null},s=d=>{const f=t?.addonDefaults[d.id],p=f?.enabled??d.enabledByDefault??!0,h=n?.stepToggles?.[d.id],m=h!==void 0?h:p;return{addonId:d.id,addonName:d.name,slot:d.slot,inputClasses:[...d.inputClasses],outputClasses:[...d.outputClasses],enabled:m,modelId:f?.modelId??d.defaultModelId,children:[],...f?.settings&&Object.keys(f.settings).length>0?{settings:f.settings}:{}}},a=new Map;for(const d of e.slots)for(const f of d.addons)a.set(f.id,s(f));const i=[],l=new Set;for(const[d,f]of a){const p=r(d);p&&p.inputClasses.length===0&&(i.push(f),l.add(d))}let c=!0;for(;c;){c=!1;for(const[d,f]of a){if(l.has(d))continue;const p=r(d);if(p)for(const[h,m]of a){if(h===d)continue;const g=r(h);if(g&&l.has(h)&&g.outputClasses.some(b=>p.inputClasses.includes(b))){m.children.push(f),l.add(d),c=!0;break}}}}return i}function X6(e,t){const n=new Map;for(const s of t.slots)for(const a of s.addons)n.set(a.id,a);const r=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(r),...s.settings?{settings:{...s.settings}}:{}}};return[...e].map(r)}function J6(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 eO({tabs:e,active:t,onChange:n}){return o("div",{className:"flex rounded-lg border border-border bg-surface p-0.5 gap-0.5",children:e.map(r=>o("button",{type:"button",onClick:()=>n(r.id),className:["flex-1 rounded-md px-3 py-1.5 text-xs font-medium transition-colors",t===r.id?"bg-primary/12 text-primary":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"].join(" "),children:r.label},r.id))})}function tO(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 r=Math.min(...n),s=Math.max(...n);return r===s?`${r} MB`:`${r}-${s} MB`}function nO(e){return`${e.inputSize.width}x${e.inputSize.height}`}function rO(e){return e.formats?Object.keys(e.formats).filter(t=>e.formats[t]!==void 0):[]}function oO({entry:e,selected:t,onSelect:n,disabled:r}){const s=tO(e),a=nO(e),i=rO(e);return u("button",{type:"button",onClick:n,disabled:r,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",r?"opacity-50 cursor-not-allowed":"cursor-pointer"].join(" "),children:[o("div",{className:"flex items-start justify-between gap-2",children:u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2",children:[o("span",{className:"text-xs font-semibold text-foreground truncate",children:e.name}),t&&o(Mt,{className:"h-3.5 w-3.5 text-primary shrink-0"})]}),o("p",{className:"text-[10px] text-foreground-subtle mt-0.5 line-clamp-2",children:e.description})]})}),u("div",{className:"flex items-center gap-3 mt-2 flex-wrap",children:[u("span",{className:"inline-flex items-center gap-1 text-[10px] text-foreground-subtle",children:[o(ft,{className:"h-3 w-3"}),a]}),s&&o("span",{className:"text-[10px] text-foreground-subtle",children:s}),i.length>0&&o("div",{className:"flex gap-1",children:i.map(l=>o("span",{className:"text-[9px] uppercase rounded bg-surface border border-border px-1 py-0.5 text-foreground-subtle font-mono",children:l},l))}),e.labels.length>0&&u("span",{className:"text-[10px] text-foreground-subtle",children:[e.labels.length," label",e.labels.length!==1?"s":""]})]})]})}function sO({field:e,value:t,onChange:n,disabled:r}){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]=P(a?"catalog":"custom"),f=t==null?"":String(t);return u("div",{className:"space-y-3",children:[l.length>1&&o(eO,{tabs:l,active:c,onChange:d}),c==="catalog"&&a&&o("div",{className:"space-y-1.5 max-h-[320px] overflow-y-auto pr-1",children:s.map(p=>o(oO,{entry:p,selected:f===p.id,onSelect:()=>n(p.id),disabled:r||e.disabled},p.id))}),c==="catalog"&&!a&&u("div",{className:"rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2",children:[o(kn,{className:"h-3.5 w-3.5 text-info shrink-0 mt-0.5"}),o("p",{className:"text-[11px] text-foreground-subtle leading-relaxed",children:"No predefined models available. Use the Custom Path tab to specify a model file path or URL."})]}),c==="custom"&&i&&u("div",{className:"space-y-2",children:[o("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:f,disabled:r||e.disabled,onChange:p=>n(p.target.value)}),e.acceptFormats&&e.acceptFormats.length>0&&u("p",{className:"text-[10px] text-foreground-subtle",children:["Accepted formats: ",e.acceptFormats.join(", ")]})]}),(e.compatibilityNote||e.conversionGuideUrl)&&u("div",{className:"flex items-start justify-between gap-3 pt-1",children:[e.compatibilityNote&&u("p",{className:"flex items-start gap-1 text-[10px] text-foreground-subtle",children:[o(kn,{className:"h-3 w-3 mt-0.5 shrink-0"}),e.compatibilityNote]}),e.conversionGuideUrl&&u("a",{href:e.conversionGuideUrl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-[11px] text-primary hover:underline shrink-0",children:["How to convert your model",o(Id,{className:"h-3 w-3"})]})]})]})}function b0(e){const t=Le();return Ay(t.trpcClient,e)}function aO({deviceId:e,deviceName:t,hasPTZ:n=!1,className:r}){const s=Le(),a=typeof window<"u"?window.location.origin:"",i=Number.isFinite(e),[l,c]=P(!1),d=i&&n&&l,f=St(s.trpcClient,i?e:null),p=ne(!1),{data:h,isLoading:m,isFetching:g,refetch:b}=tr({queryKey:["device",e,"snapshot.getSnapshot"],queryFn:()=>{const I=p.current;return p.current=!1,f?.snapshot?.getSnapshot({force:I})??null},enabled:!!f&&i,staleTime:5e3,retry:!1}),x=()=>{p.current=!0,b()},{streams:y,pipelineMetrics:w,createSession:v,sendAnswer:N,closeSession:k}=hd(s.trpcClient,i?e:null),C=b0(i?e:null),E=md(s.trpcClient,i?e:0,{enabled:d}),A=h?`data:${h.contentType};base64,${h.base64}`:null;return o(id,{serverUrl:a,createSession:v,sendAnswer:N,closeSession:k,streams:y,pipelineMetrics:w,deviceName:t,phase:C.phase,detections:C,defaultShowDetections:!1,defaultShowMotion:!1,autoPlay:!1,showPlayStop:!0,snapshotSrc:A,snapshotLoading:m||g,onRefreshSnapshot:x,ptzAvailable:i&&n,ptzShown:d,onPtzToggle:()=>c(I=>!I),ptzOverlay:d?o(dd,{controls:E}):void 0,className:r})}function iO(){const e=hn(),t=zc();if(e===null)return null;const n=typeof t?.name=="string"?t.name:"",s=(t?.features??[]).includes(Hn.PanTiltZoom);return o(aO,{deviceId:e,deviceName:n,hasPTZ:s})}function vt(e,t){const n=Le(),r=ke(),[s,a]=P(n.connectionVersion);Y(()=>n.subscribeConnectionEvents((c,d)=>{c==="connected"&&a(d)}),[n]);const i=t.join("|"),l=JSON.stringify(e);Y(()=>{const c=[],d=()=>{const f=JSON.parse(l),h=f.length===1&&Array.isArray(f[0])?f:[f];r.invalidateQueries({queryKey:h})};d();for(const f of i.split("|"))if(f)try{c.push(n.subscribeEvent(f,d))}catch{}return()=>{for(const f of c)f()}},[n,r,i,l,s])}function fs({icon:e,label:t,value:n,subtext:r,color:s}){return u("div",{className:"rounded-lg border border-border bg-surface p-2 sm:p-2.5 min-w-0",children:[u("div",{className:"flex items-center gap-1.5 mb-0.5 min-w-0",children:[o(e,{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),o("span",{className:`${Us} uppercase tracking-wider whitespace-nowrap overflow-hidden text-ellipsis min-w-0`,children:t})]}),o("p",{className:`${s?`${fl.replace("text-foreground","")} ${s}`:fl} whitespace-nowrap overflow-hidden text-ellipsis`,children:n}),r&&o("p",{className:`${Us} mt-0.5 truncate`,children:r})]})}function hs({label:e,value:t,warning:n}){return u("div",{className:"min-w-0",children:[o("p",{className:`${Us} truncate`,children:e}),o("p",{className:`text-[11px] font-medium truncate ${n?"text-warning":"text-foreground"}`,children:t})]})}function on({label:e,value:t}){return u("div",{className:`${im} flex items-start gap-2 sm:gap-3`,children:[o("span",{className:"w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle",children:e}),o("div",{className:"flex-1 min-w-0 text-[11px] text-foreground",children:t})]})}function lO(){const e=hn();vt(["pipelineOrchestrator","getPipelineAssignment"],["pipeline.camera-assigned","pipeline.camera-unassigned","pipeline.camera-updated"]),vt(["pipelineRunner","getCameraMetrics"],["pipeline.camera-metrics-snapshot"]);const{data:t}=Ia({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}=ed({deviceId:e??0,...s?{nodeId:s}:{}},{enabled:e!==null,staleTime:2e3,retry:!1}),i=Le(),l=St(i.trpcClient,e),{data:c}=tr({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,f=a?.detectionMode??null,p=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=rr(d??"watching"),y=c?.length??0;return u("div",{className:"grid grid-cols-2 sm:grid-cols-2 lg:grid-cols-4 gap-2 sm:gap-3",children:[o(fs,{icon:qo,label:"Phase",value:x.label,color:x.textColor,subtext:f??void 0}),o(fs,{icon:r0,label:"Detection FPS",value:`${p.toFixed(1)}`,subtext:h>0?`target: ${h}`:void 0}),o(fs,{icon:ft,label:"Inference",value:`${m.toFixed(1)} ms`,subtext:g>0?`queue: ${g}`:void 0}),o(fs,{icon:Go,label:"Active Tracks",value:String(y),subtext:b>0?`dropped: ${b}`:void 0})]})}function Ai(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function cO(){const e=hn(),{data:t}=Yc({deviceId:e??0},{enabled:e!==null,refetchInterval:5e3});if(e===null)return null;const n=t?.streams??{},r=Object.entries(n);return r.length===0?null:u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[o("div",{className:"border-b border-border px-3 sm:px-4 py-2",children:o("h2",{className:"text-[11px] font-semibold text-foreground uppercase tracking-wider",children:"Stream Network"})}),o("div",{className:"divide-y divide-border",children:r.map(([s,a])=>u("div",{className:"px-3 sm:px-4 py-2",children:[u("div",{className:"flex items-center gap-1.5 mb-1.5",children:[o(Wn,{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),o("span",{className:"text-[11px] font-medium text-foreground truncate",children:s})]}),u("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-2",children:[o(hs,{label:"Nominal",value:Ai(a.nominalBitrateKbps??0)}),o(hs,{label:"Observed",value:Ai(a.observedBitrateKbps??0)}),o(hs,{label:"Peak",value:Ai(a.peakBitrateKbps??0)}),o(hs,{label:"Packet Loss",value:`${(a.packetLossPercent??0).toFixed(2)}%`,warning:(a.packetLossPercent??0)>1})]})]},s))})]})}const dO=3e4;function uO({field:e}){const t=hn(),n=e.type==="doorbell-recent"&&typeof e.historyLimit=="number"?e.historyLimit:10,r=gd({deviceId:t??void 0,historyLimit:n});if(t===null)return null;const s=r.latest?Date.now()-r.latest.timestamp<dO:!1;return o(ud,{history:r.history,latestIsFresh:s})}const pO={streaming:{icon:m0,label:"Streaming"},detection:{icon:Go,label:"Detection"},recording:{icon:Jy,label:"Recording"},audio:{icon:$l,label:"Audio"},snapshot:{icon:Cr,label:"Snapshot"},motion:{icon:_d,label:"Motion"},ptz:{icon:Yt,label:"PTZ"},webrtc:{icon:Ba,label:"WebRTC"},onvif:{icon:w6,label:"ONVIF"},analytics:{icon:ft,label:"Analytics"},"battery-operated":{icon:gL,label:"Battery"},"native-snapshot":{icon:Cr,label:"Native Snapshot"},"pan-tilt-zoom":{icon:Yt,label:"PTZ"},"two-way-audio":{icon:$l,label:"Two-way Audio"},"doorbell-button":{icon:Uo,label:"Doorbell"},rebootable:{icon:ht,label:"Rebootable"}},fO=Ra;function Fa({capabilities:e,showLabels:t=!1}){return o("div",{className:"flex items-center gap-1 flex-wrap",children:e.map(n=>{const r=pO[n],s=r?.icon??fO,a=r?.label??n;return u("span",{className:"inline-flex items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-foreground-subtle",title:a,children:[o(s,{className:"h-3 w-3"}),t&&o("span",{children:a})]},n)})})}const hO={frigate:{icon:Zy,color:"#3b82f6",label:"Frigate"},scrypted:{icon:cn,color:"#a855f7",label:"Scrypted"},reolink:{icon:Ba,color:"#06b6d4",label:"Reolink"},homeassistant:{icon:pR,color:"#22d3ee",label:"Home Assistant"},rtsp:{icon:Wn,color:"#78716c",label:"RTSP"},onvif:{icon:Wn,color:"#78716c",label:"ONVIF"}},gp={sm:"h-4 w-4",md:"h-5 w-5",lg:"h-6 w-6"},mO={sm:"h-7 w-7",md:"h-8 w-8",lg:"h-10 w-10"};function x0(e){const t=e.toLowerCase();return t.startsWith("provider-")?t.slice(9):t}function gO(e){const t=x0(e);return hO[t]??{icon:Zy,color:"#78716c",label:e}}function bO(e){const t=x0(e);return`/api/addon-assets/${e.toLowerCase().startsWith("provider-")?e:`provider-${t}`}/assets/icon.svg`}function un({type:e,size:t="md",showLabel:n}){const r=gO(e),s=r.icon,[a,i]=P(!1),l=bO(e);return u("div",{className:"flex items-center gap-2",children:[o("div",{className:`flex items-center justify-center rounded-lg ${mO[t]}`,style:{backgroundColor:`${r.color}15`},children:a?o(s,{className:gp[t],style:{color:r.color}}):o("img",{src:l,alt:r.label,className:gp[t],onError:()=>i(!0)})}),n&&o("span",{className:"text-xs font-medium text-foreground-subtle",children:r.label})]})}function xO({deviceId:e,initialName:t}){const n=ke(),[r,s]=P(!1),[a,i]=P(t),[l,c]=P(!1),d=ne(null);Y(()=>{r||i(t)},[t,r]),Y(()=>{r&&d.current?.focus()},[r]);const f=ub({onSuccess:()=>{n.invalidateQueries({queryKey:[["deviceManager","getDevice"]]}),n.invalidateQueries({queryKey:[["deviceManager","listAll"]]}),n.invalidateQueries({queryKey:[["deviceManager","getDeviceAggregate"]]})}}),p=async()=>{const m=a.trim();if(m.length===0||m===t){s(!1),i(t);return}c(!0);try{await f.mutateAsync({deviceId:e,name:m}),s(!1)}catch{}finally{c(!1)}},h=()=>{i(t),s(!1)};return r?o(on,{label:"Name",value:u("div",{className:"flex items-center gap-1",children:[o("input",{ref:d,type:"text",value:a,onChange:m=>i(m.target.value),onKeyDown:m=>{m.key==="Enter"?p():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"}),o("button",{type:"button",onClick:()=>void p(),disabled:l,className:"p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50","aria-label":"Save",children:o(Mt,{className:"h-3 w-3"})}),o("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:o(Fe,{className:"h-3 w-3"})})]})}):o(on,{label:"Name",value:u("div",{className:"flex items-center gap-2 group",children:[o("span",{className:"truncate",children:t}),o("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:o(Ur,{className:"h-3 w-3 text-foreground-subtle"})})]})})}function yO({deviceId:e,initialLocation:t}){const n=ke(),[r,s]=P(!1),[a,i]=P(t??""),[l,c]=P(!1),d=ne(null),{data:f}=fb(void 0,{staleTime:3e4,enabled:r}),p=f??[];Y(()=>{r||i(t??"")},[t,r]),Y(()=>{r&&d.current?.focus()},[r]);const h=pb({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?p:p.filter(w=>w.toLowerCase()!==y&&w.toLowerCase().includes(y))},[p,a]),g=a.trim().length>0&&!p.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 r?o(on,{label:"Location",value:u("div",{className:"relative",children:[u("div",{className:"flex items-center gap-1",children:[o("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"}),o("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:o(Mt,{className:"h-3 w-3"})}),o("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:o(Fe,{className:"h-3 w-3"})})]}),(m.length>0||g)&&u("div",{className:"absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md",children:[m.map(y=>u("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:[o($R,{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),o("span",{className:"truncate",children:y})]},y)),g&&u("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:[o("span",{className:"text-foreground-subtle",children:"Create"}),u("span",{className:"font-medium truncate",children:['"',a.trim(),'"']})]})]})]})}):o(on,{label:"Location",value:u("div",{className:"flex items-center gap-2 group",children:[t?o("span",{className:"truncate",children:t}):o("span",{className:"italic text-foreground-subtle",children:"unset"}),o("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:o(Ur,{className:"h-3 w-3 text-foreground-subtle"})})]})})}const bp=["manufacturer","model","hardware","firmware","serialNumber","uid","mac","itemNo"];function vO(e){return e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/^./,t=>t.toUpperCase())}function wO(e){return e==null?"—":typeof e=="string"||typeof e=="number"||typeof e=="boolean"?String(e):JSON.stringify(e)}function y0(){const e=hn(),t=zc(),{data:n}=Gn({deviceId:e??0},{enabled:e!==null,staleTime:3e4}),r=n??t??null,[s,a]=P("identity");if(e===null||!r)return null;const i=String(r.stableId??""),l=String(r.name??""),c=String(r.type??""),d=String(r.addonId??""),f=r.features??[],p=r.location??null,h=r.metadata??null,m=h!==null&&Object.keys(h).length>0;return u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3",children:[o("h2",{className:"text-[11px] font-semibold text-foreground uppercase tracking-wider",children:"Device Info"}),m&&u("div",{className:"flex items-center gap-1 rounded-md bg-surface-hover p-0.5",children:[o(xp,{active:s==="identity",onClick:()=>a("identity"),label:"Identity"}),o(xp,{active:s==="hardware",onClick:()=>a("hardware"),label:"Hardware"})]})]}),(!m||s==="identity")&&u("div",{className:"divide-y divide-border",children:[o(on,{label:"ID",value:u("span",{className:"font-mono text-[11px] text-foreground",children:[`#${e}`,u("span",{className:"ml-1.5 text-foreground-subtle",children:["(",i,")"]})]})}),o(xO,{deviceId:e,initialName:l}),o(yO,{deviceId:e,initialLocation:p}),o(on,{label:"Type",value:c}),o(on,{label:"Provider",value:o(un,{type:d,size:"sm",showLabel:!0})}),o(on,{label:"Capabilities",value:f.length>0?o(Fa,{capabilities:f,showLabels:!0}):o("span",{className:"text-[11px] text-foreground-subtle",children:"None"})})]}),m&&s==="hardware"&&o(NO,{metadata:h})]})}function xp({active:e,onClick:t,label:n}){return o("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 NO({metadata:e}){const t=bp.filter(s=>s in e),n=Object.keys(e).filter(s=>!bp.includes(s)).sort(),r=[...t,...n];return u("div",{children:[o("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."}),o("div",{className:"divide-y divide-border",children:r.map(s=>o(on,{label:vO(s),value:o("span",{className:"font-mono text-[11px] text-foreground break-all",children:wO(e[s])})},s))})]})}function Os(e){try{const t=e.split(".");if(t.length<2||!t[1])return null;const n=JSON.parse(atob(t[1]));return{id:String(n.userId??""),username:String(n.username??"unknown"),isAdmin:!!n.isAdmin,exp:Number(n.exp??0),scopes:CO(n.scopes)}}catch{return null}}const kO=new Set(["view","create","delete"]),SO=new Set(["category","capability","addon","device"]);function CO(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){if(typeof n!="object"||n===null)continue;const r=n,{type:s,access:a}=r;if(typeof s!="string"||!SO.has(s)||!Array.isArray(a))continue;const i=a.filter(c=>typeof c=="string"&&kO.has(c));if(i.length===0)continue;if(s==="device"){const c=r.targets;if(!Array.isArray(c))continue;const d=c.filter(f=>typeof f=="string"&&f.length>0);if(d.length===0)continue;t.push({type:"device",targets:d,access:i});continue}const l=r.target;if(typeof l=="string")if(s==="category"){if(l!=="device"&&l!=="system")continue;t.push({type:s,target:l,access:i})}else s==="capability"?t.push({type:s,target:l,access:i}):t.push({type:"addon",target:l,access:i})}return t}function MO(e){const t=Os(e);return t?t.exp*1e3<Date.now():!0}const EO="changeme",v0=Be(null);function IO({children:e}){const[t,n]=P(null),[r,s]=P(!0),[a,i]=P(!1);Y(()=>{if(typeof window<"u"&&window.location.hash.startsWith("#token=")){const x=new URLSearchParams(window.location.hash.slice(1)).get("token");x&&(localStorage.setItem("camstack_admin_token",x),window.history.replaceState({},"","/admin"))}const p=localStorage.getItem("camstack_admin_token");if(!p){s(!1);return}if(MO(p)){localStorage.removeItem("camstack_admin_token"),s(!1);return}const h=Os(p);if(!h){localStorage.removeItem("camstack_admin_token"),s(!1);return}Rs().trpcClient.system.info.query().then(()=>n(h)).catch(b=>{const x=b?.data?.code;x==="UNAUTHORIZED"||x==="FORBIDDEN"?(localStorage.removeItem("camstack_admin_token"),mr()):n(h)}).finally(()=>s(!1))},[]);const l=U(async(p,h)=>{const g=await Rs().login(p,h);if(g.requiresTotp===!0)return{kind:"totp-required",challengeToken:g.token};const b=g.token;return localStorage.setItem("camstack_admin_token",b),mr(),n(Os(b)),i(h===EO),{kind:"ok"}},[]),c=U(async(p,h)=>{const b=(await Rs().loginVerifyTotp(p,h)).token;localStorage.setItem("camstack_admin_token",b),mr(),n(Os(b)),i(!1)},[]),d=U(()=>{localStorage.removeItem("camstack_admin_token"),mr(),n(null),i(!1)},[]),f=U(()=>{i(!1)},[]);return o(v0.Provider,{value:{user:t,loading:r,mustChangePassword:a,login:l,verifyTotp:c,logout:d,clearMustChangePassword:f},children:e})}function mn(){const e=ve(v0);if(!e)throw new Error("useAuth must be used within AuthProvider");return e}function At({children:e,requireAdmin:t}){const{user:n,loading:r,mustChangePassword:s}=mn(),a=bt();return r?o("div",{className:"flex h-screen items-center justify-center bg-background text-foreground-subtle",children:"Loading..."}):n?s&&a.pathname!=="/change-password"?o(xt,{to:"/change-password",replace:!0}):t&&!n.isAdmin?o(xt,{to:"/access-denied",replace:!0}):o(me,{children:e}):o(xt,{to:"/login",replace:!0})}var Pi={};const Ce=e=>typeof e=="string",Zr=()=>{let e,t;const n=new Promise((r,s)=>{e=r,t=s});return n.resolve=e,n.reject=t,n},yp=e=>e==null?"":""+e,AO=(e,t,n)=>{e.forEach(r=>{t[r]&&(n[r]=t[r])})},PO=/###/g,vp=e=>e&&e.indexOf("###")>-1?e.replace(PO,"."):e,wp=e=>!e||Ce(e),co=(e,t,n)=>{const r=Ce(t)?t.split("."):t;let s=0;for(;s<r.length-1;){if(wp(e))return{};const a=vp(r[s]);!e[a]&&n&&(e[a]=new n),Object.prototype.hasOwnProperty.call(e,a)?e=e[a]:e={},++s}return wp(e)?{}:{obj:e,k:vp(r[s])}},Np=(e,t,n)=>{const{obj:r,k:s}=co(e,t,Object);if(r!==void 0||t.length===1){r[s]=n;return}let a=t[t.length-1],i=t.slice(0,t.length-1),l=co(e,i,Object);for(;l.obj===void 0&&i.length;)a=`${i[i.length-1]}.${a}`,i=i.slice(0,i.length-1),l=co(e,i,Object),l?.obj&&typeof l.obj[`${l.k}.${a}`]<"u"&&(l.obj=void 0);l.obj[`${l.k}.${a}`]=n},_O=(e,t,n,r)=>{const{obj:s,k:a}=co(e,t,Object);s[a]=s[a]||[],s[a].push(n)},Zs=(e,t)=>{const{obj:n,k:r}=co(e,t);if(n&&Object.prototype.hasOwnProperty.call(n,r))return n[r]},$O=(e,t,n)=>{const r=Zs(e,n);return r!==void 0?r:Zs(t,n)},w0=(e,t,n)=>{for(const r in t)r!=="__proto__"&&r!=="constructor"&&(r in e?Ce(e[r])||e[r]instanceof String||Ce(t[r])||t[r]instanceof String?n&&(e[r]=t[r]):w0(e[r],t[r],n):e[r]=t[r]);return e},On=e=>e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var DO={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};const TO=e=>Ce(e)?e.replace(/[&<>"'\/]/g,t=>DO[t]):e;class LO{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 r=new RegExp(t);return this.regExpQueue.length===this.capacity&&this.regExpMap.delete(this.regExpQueue.shift()),this.regExpMap.set(t,r),this.regExpQueue.push(t),r}}const RO=[" ",",","?","!",";"],OO=new LO(20),BO=(e,t,n)=>{t=t||"",n=n||"";const r=RO.filter(i=>t.indexOf(i)<0&&n.indexOf(i)<0);if(r.length===0)return!0;const s=OO.getRegExp(`(${r.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},Dl=(e,t,n=".")=>{if(!e)return;if(e[t])return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;const r=t.split(n);let s=e;for(let a=0;a<r.length;){if(!s||typeof s!="object")return;let i,l="";for(let c=a;c<r.length;++c)if(c!==a&&(l+=n),l+=r[c],i=s[l],i!==void 0){if(["string","number","boolean"].indexOf(typeof i)>-1&&c<r.length-1)continue;a+=c-a+1;break}s=i}return s},ko=e=>e?.replace(/_/g,"-"),zO={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 Xs{constructor(t,n={}){this.init(t,n)}init(t,n={}){this.prefix=n.prefix||"i18next:",this.logger=t||zO,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,r,s){return s&&!this.debug?null:(Ce(t[0])&&(t[0]=`${r}${this.prefix} ${t[0]}`),this.logger[n](t))}create(t){return new Xs(this.logger,{prefix:`${this.prefix}:${t}:`,...this.options})}clone(t){return t=t||this.options,t.prefix=t.prefix||this.prefix,new Xs(this.logger,t)}}var Ut=new Xs;class ja{constructor(){this.observers={}}on(t,n){return t.split(" ").forEach(r=>{this.observers[r]||(this.observers[r]=new Map);const s=this.observers[r].get(n)||0;this.observers[r].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 kp extends ja{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,r,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],r&&(Array.isArray(r)?l.push(...r):Ce(r)&&a?l.push(...r.split(a)):l.push(r)));const c=Zs(this.data,l);return!c&&!n&&!r&&t.indexOf(".")>-1&&(t=l[0],n=l[1],r=l.slice(2).join(".")),c||!i||!Ce(r)?c:Dl(this.data?.[t]?.[n],r,a)}addResource(t,n,r,s,a={silent:!1}){const i=a.keySeparator!==void 0?a.keySeparator:this.options.keySeparator;let l=[t,n];r&&(l=l.concat(i?r.split(i):r)),t.indexOf(".")>-1&&(l=t.split("."),s=n,n=l[1]),this.addNamespaces(n),Np(this.data,l,s),a.silent||this.emit("added",t,n,r,s)}addResources(t,n,r,s={silent:!1}){for(const a in r)(Ce(r[a])||Array.isArray(r[a]))&&this.addResource(t,n,a,r[a],{silent:!0});s.silent||this.emit("added",t,n,r)}addResourceBundle(t,n,r,s,a,i={silent:!1,skipCopy:!1}){let l=[t,n];t.indexOf(".")>-1&&(l=t.split("."),s=r,r=n,n=l[1]),this.addNamespaces(n);let c=Zs(this.data,l)||{};i.skipCopy||(r=JSON.parse(JSON.stringify(r))),s?w0(c,r,a):c={...c,...r},Np(this.data,l,c),i.silent||this.emit("added",t,n,r)}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 N0={processors:{},addPostProcessor(e){this.processors[e.name]=e},handle(e,t,n,r,s){return e.forEach(a=>{t=this.processors[a]?.process(t,n,r,s)??t}),t}};const k0=Symbol("i18next/PATH_KEY");function FO(){const e=[],t=Object.create(null);let n;return t.get=(r,s)=>(n?.revoke?.(),s===k0?e:(e.push(s),n=Proxy.revocable(r,t),n.proxy)),Proxy.revocable(Object.create(null),t).proxy}function vr(e,t){const{[k0]:n}=e(FO()),r=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(r)}`}return n.join(r)}const Sp={},_i=e=>!Ce(e)&&typeof e!="boolean"&&typeof e!="number";class Js extends ja{constructor(t,n={}){super(),AO(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],t,this),this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.logger=Ut.create("translator")}changeLanguage(t){t&&(this.language=t)}exists(t,n={interpolation:{}}){const r={...n};if(t==null)return!1;const s=this.resolve(t,r);if(s?.res===void 0)return!1;const a=_i(s.res);return!(r.returnObjects===!1&&a)}extractFromKey(t,n){let r=n.nsSeparator!==void 0?n.nsSeparator:this.options.nsSeparator;r===void 0&&(r=":");const s=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator;let a=n.ns||this.options.defaultNS||[];const i=r&&t.indexOf(r)>-1,l=!this.options.userDefinedKeySeparator&&!n.keySeparator&&!this.options.userDefinedNsSeparator&&!n.nsSeparator&&!BO(t,r,s);if(i&&!l){const c=t.match(this.interpolator.nestingRegexp);if(c&&c.length>0)return{key:t,namespaces:Ce(a)?[a]:a};const d=t.split(r);(r!==s||r===s&&this.options.ns.indexOf(d[0])>-1)&&(a=d.shift()),t=d.join(s)}return{key:t,namespaces:Ce(a)?[a]:a}}translate(t,n,r){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=vr(t,{...this.options,...s})),Array.isArray(t)||(t=[String(t)]),t=t.map(R=>typeof R=="function"?vr(R,{...this.options,...s}):String(R));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 f=s.nsSeparator!==void 0?s.nsSeparator:this.options.nsSeparator;f===void 0&&(f=":");const p=s.lng||this.language,h=s.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if(p?.toLowerCase()==="cimode")return h?a?{res:`${d}${f}${l}`,usedKey:l,exactUsedKey:l,usedLng:p,usedNS:d,usedParams:this.getUsedParamsDetails(s)}:`${d}${f}${l}`:a?{res:l,usedKey:l,exactUsedKey:l,usedLng:p,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&&!Ce(s.count),k=Js.hasDefaultValue(s),C=N?this.pluralResolver.getSuffix(p,s.count,s):"",E=s.ordinal&&N?this.pluralResolver.getSuffix(p,s.count,{ordinal:!1}):"",A=N&&!s.ordinal&&s.count===0,I=A&&s[`defaultValue${this.options.pluralSeparator}zero`]||s[`defaultValue${C}`]||s[`defaultValue${E}`]||s.defaultValue;let z=g;v&&!g&&k&&(z=I);const $=_i(z),B=Object.prototype.toString.apply(z);if(v&&z&&$&&y.indexOf(B)<0&&!(Ce(w)&&Array.isArray(z))){if(!s.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn("accessing an object - but returnObjects options is not enabled!");const R=this.options.returnedObjectHandler?this.options.returnedObjectHandler(b,z,{...s,ns:c}):`key '${l} (${this.language})' returned an object instead of string.`;return a?(m.res=R,m.usedParams=this.getUsedParamsDetails(s),m):R}if(i){const R=Array.isArray(z),M=R?[]:{},T=R?x:b;for(const _ in z)if(Object.prototype.hasOwnProperty.call(z,_)){const L=`${T}${i}${_}`;k&&!g?M[_]=this.translate(L,{...s,defaultValue:_i(I)?I[_]:void 0,joinArrays:!1,ns:c}):M[_]=this.translate(L,{...s,joinArrays:!1,ns:c}),M[_]===L&&(M[_]=z[_])}g=M}}else if(v&&Ce(w)&&Array.isArray(g))g=g.join(w),g&&(g=this.extendTranslation(g,t,s,r));else{let R=!1,M=!1;!this.isValidLookup(g)&&k&&(R=!0,g=I),this.isValidLookup(g)||(M=!0,g=l);const _=(s.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey)&&M?void 0:g,L=k&&I!==g&&this.options.updateMissing;if(M||R||L){if(this.logger.log(L?"updateKey":"missingKey",p,d,l,L?I:g),i){const H=this.resolve(l,{...s,keySeparator:!1});H&&H.res&&this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.")}let O=[];const j=this.languageUtils.getFallbackCodes(this.options.fallbackLng,s.lng||this.language);if(this.options.saveMissingTo==="fallback"&&j&&j[0])for(let H=0;H<j.length;H++)O.push(j[H]);else this.options.saveMissingTo==="all"?O=this.languageUtils.toResolveHierarchy(s.lng||this.language):O.push(s.lng||this.language);const F=(H,D,Q)=>{const G=k&&Q!==g?Q:_;this.options.missingKeyHandler?this.options.missingKeyHandler(H,d,D,G,L,s):this.backendConnector?.saveMissing&&this.backendConnector.saveMissing(H,d,D,G,L,s),this.emit("missingKey",H,d,D,g)};this.options.saveMissing&&(this.options.saveMissingPlurals&&N?O.forEach(H=>{const D=this.pluralResolver.getSuffixes(H,s);A&&s[`defaultValue${this.options.pluralSeparator}zero`]&&D.indexOf(`${this.options.pluralSeparator}zero`)<0&&D.push(`${this.options.pluralSeparator}zero`),D.forEach(Q=>{F([H],l+Q,s[`defaultValue${Q}`]||I)})}):F(O,l,I))}g=this.extendTranslation(g,t,s,m,r),M&&g===l&&this.options.appendNamespaceToMissingKey&&(g=`${d}${f}${l}`),(M||R)&&this.options.parseMissingKeyHandler&&(g=this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey?`${d}${f}${l}`:l,R?g:void 0,s))}return a?(m.res=g,m.usedParams=this.getUsedParamsDetails(s),m):g}extendTranslation(t,n,r,s,a){if(this.i18nFormat?.parse)t=this.i18nFormat.parse(t,{...this.options.interpolation.defaultVariables,...r},r.lng||this.language||s.usedLng,s.usedNS,s.usedKey,{resolved:s});else if(!r.skipInterpolation){r.interpolation&&this.interpolator.init({...r,interpolation:{...this.options.interpolation,...r.interpolation}});const c=Ce(t)&&(r?.interpolation?.skipOnVariables!==void 0?r.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables);let d;if(c){const p=t.match(this.interpolator.nestingRegexp);d=p&&p.length}let f=r.replace&&!Ce(r.replace)?r.replace:r;if(this.options.interpolation.defaultVariables&&(f={...this.options.interpolation.defaultVariables,...f}),t=this.interpolator.interpolate(t,f,r.lng||this.language||s.usedLng,r),c){const p=t.match(this.interpolator.nestingRegexp),h=p&&p.length;d<h&&(r.nest=!1)}!r.lng&&s&&s.res&&(r.lng=this.language||s.usedLng),r.nest!==!1&&(t=this.interpolator.nest(t,(...p)=>a?.[0]===p[0]&&!r.context?(this.logger.warn(`It seems you are nesting recursively key: ${p[0]} in key: ${n[0]}`),null):this.translate(...p,n),r)),r.interpolation&&this.interpolator.reset()}const i=r.postProcess||this.options.postProcess,l=Ce(i)?[i]:i;return t!=null&&l?.length&&r.applyPostProcessor!==!1&&(t=N0.handle(l,t,n,this.options&&this.options.postProcessPassResolved?{i18nResolved:{...s,usedParams:this.getUsedParamsDetails(r)},...r}:r,this)),t}resolve(t,n={}){let r,s,a,i,l;return Ce(t)&&(t=[t]),Array.isArray(t)&&(t=t.map(c=>typeof c=="function"?vr(c,{...this.options,...n}):c)),t.forEach(c=>{if(this.isValidLookup(r))return;const d=this.extractFromKey(c,n),f=d.key;s=f;let p=d.namespaces;this.options.fallbackNS&&(p=p.concat(this.options.fallbackNS));const h=n.count!==void 0&&!Ce(n.count),m=h&&!n.ordinal&&n.count===0,g=n.context!==void 0&&(Ce(n.context)||typeof n.context=="number")&&n.context!=="",b=n.lngs?n.lngs:this.languageUtils.toResolveHierarchy(n.lng||this.language,n.fallbackLng);p.forEach(x=>{this.isValidLookup(r)||(l=x,!Sp[`${b[0]}-${x}`]&&this.utils?.hasLoadedNamespace&&!this.utils?.hasLoadedNamespace(l)&&(Sp[`${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(r))return;i=y;const w=[f];if(this.i18nFormat?.addLookupKeys)this.i18nFormat.addLookupKeys(w,f,y,x,n);else{let N;h&&(N=this.pluralResolver.getSuffix(y,n.count,n));const k=`${this.options.pluralSeparator}zero`,C=`${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;if(h&&(n.ordinal&&N.indexOf(C)===0&&w.push(f+N.replace(C,this.options.pluralSeparator)),w.push(f+N),m&&w.push(f+k)),g){const E=`${f}${this.options.contextSeparator||"_"}${n.context}`;w.push(E),h&&(n.ordinal&&N.indexOf(C)===0&&w.push(E+N.replace(C,this.options.pluralSeparator)),w.push(E+N),m&&w.push(E+k))}}let v;for(;v=w.pop();)this.isValidLookup(r)||(a=v,r=this.getResource(y,x,v,n))}))})}),{res:r,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,r,s={}){return this.i18nFormat?.getResource?this.i18nFormat.getResource(t,n,r,s):this.resourceStore.getResource(t,n,r,s)}getUsedParamsDetails(t={}){const n=["defaultValue","ordinal","context","replace","lng","lngs","fallbackLng","ns","keySeparator","nsSeparator","returnObjects","returnDetails","joinArrays","postProcess","interpolation"],r=t.replace&&!Ce(t.replace);let s=r?t.replace:t;if(r&&typeof t.count<"u"&&(s.count=t.count),this.options.interpolation.defaultVariables&&(s={...this.options.interpolation.defaultVariables,...s}),!r){s={...s};for(const a of n)delete s[a]}return s}static hasDefaultValue(t){const n="defaultValue";for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&n===r.substring(0,n.length)&&t[r]!==void 0)return!0;return!1}}class Cp{constructor(t){this.options=t,this.supportedLngs=this.options.supportedLngs||!1,this.logger=Ut.create("languageUtils")}getScriptPartFromCode(t){if(t=ko(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=ko(t),!t||t.indexOf("-")<0)return t;const n=t.split("-");return this.formatLanguageCode(n[0])}formatLanguageCode(t){if(Ce(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(r=>{if(n)return;const s=this.formatLanguageCode(r);(!this.options.supportedLngs||this.isSupportedCode(s))&&(n=s)}),!n&&this.options.supportedLngs&&t.forEach(r=>{if(n)return;const s=this.getScriptPartFromCode(r);if(this.isSupportedCode(s))return n=s;const a=this.getLanguagePartFromCode(r);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)),Ce(t)&&(t=[t]),Array.isArray(t))return t;if(!n)return t.default||[];let r=t[n];return r||(r=t[this.getScriptPartFromCode(n)]),r||(r=t[this.formatLanguageCode(n)]),r||(r=t[this.getLanguagePartFromCode(n)]),r||(r=t.default),r||[]}toResolveHierarchy(t,n){const r=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 Ce(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))):Ce(t)&&a(this.formatLanguageCode(t)),r.forEach(i=>{s.indexOf(i)<0&&a(this.formatLanguageCode(i))}),s}}const Mp={zero:0,one:1,two:2,few:3,many:4,other:5},Ep={select:e=>e===1?"one":"other",resolvedOptions:()=>({pluralCategories:["one","other"]})};class jO{constructor(t,n={}){this.languageUtils=t,this.options=n,this.logger=Ut.create("pluralResolver"),this.pluralRulesCache={}}clearCache(){this.pluralRulesCache={}}getRule(t,n={}){const r=ko(t==="dev"?"en":t),s=n.ordinal?"ordinal":"cardinal",a=JSON.stringify({cleanedCode:r,type:s});if(a in this.pluralRulesCache)return this.pluralRulesCache[a];let i;try{i=new Intl.PluralRules(r,{type:s})}catch{if(typeof Intl>"u")return this.logger.error("No Intl support, please use an Intl polyfill!"),Ep;if(!t.match(/-|_/))return Ep;const c=this.languageUtils.getLanguagePartFromCode(t);i=this.getRule(c,n)}return this.pluralRulesCache[a]=i,i}needsPlural(t,n={}){let r=this.getRule(t,n);return r||(r=this.getRule("dev",n)),r?.resolvedOptions().pluralCategories.length>1}getPluralFormsOfKey(t,n,r={}){return this.getSuffixes(t,r).map(s=>`${n}${s}`)}getSuffixes(t,n={}){let r=this.getRule(t,n);return r||(r=this.getRule("dev",n)),r?r.resolvedOptions().pluralCategories.sort((s,a)=>Mp[s]-Mp[a]).map(s=>`${this.options.prepend}${n.ordinal?`ordinal${this.options.prepend}`:""}${s}`):[]}getSuffix(t,n,r={}){const s=this.getRule(t,r);return s?`${this.options.prepend}${r.ordinal?`ordinal${this.options.prepend}`:""}${s.select(n)}`:(this.logger.warn(`no plural rule found for: ${t}`),this.getSuffix("dev",n,r))}}const Ip=(e,t,n,r=".",s=!0)=>{let a=$O(e,t,n);return!a&&s&&Ce(n)&&(a=Dl(e,n,r),a===void 0&&(a=Dl(t,n,r))),a},$i=e=>e.replace(/\$/g,"$$$$");class Ap{constructor(t={}){this.logger=Ut.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:r,useRawValueToEscape:s,prefix:a,prefixEscaped:i,suffix:l,suffixEscaped:c,formatSeparator:d,unescapeSuffix:f,unescapePrefix:p,nestingPrefix:h,nestingPrefixEscaped:m,nestingSuffix:g,nestingSuffixEscaped:b,nestingOptionsSeparator:x,maxReplaces:y,alwaysFormat:w}=t.interpolation;this.escape=n!==void 0?n:TO,this.escapeValue=r!==void 0?r:!0,this.useRawValueToEscape=s!==void 0?s:!1,this.prefix=a?On(a):i||"{{",this.suffix=l?On(l):c||"}}",this.formatSeparator=d||",",this.unescapePrefix=f?"":p||"-",this.unescapeSuffix=this.unescapePrefix?"":f||"",this.nestingPrefix=h?On(h):m||On("$t("),this.nestingSuffix=g?On(g):b||On(")"),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,r)=>n?.source===r?(n.lastIndex=0,n):new RegExp(r,"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,r,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=Ip(n,c,m,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(y,void 0,r,{...s,...n,interpolationkey:m}):y}const g=m.split(this.formatSeparator),b=g.shift().trim(),x=g.join(this.formatSeparator).trim();return this.format(Ip(n,c,b,this.options.keySeparator,this.options.ignoreJSONStructure),x,r,{...s,...n,interpolationkey:b})};this.resetRegExp();const f=s?.missingInterpolationHandler||this.options.missingInterpolationHandler,p=s?.interpolation?.skipOnVariables!==void 0?s.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:m=>$i(m)},{regex:this.regexp,safeValue:m=>this.escapeValue?$i(this.escape(m)):$i(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 f=="function"){const x=f(t,a,s);i=Ce(x)?x:""}else if(s&&Object.prototype.hasOwnProperty.call(s,g))i="";else if(p){i=a[0];continue}else this.logger.warn(`missed to pass in variable ${g} for interpolating ${t}`),i="";else!Ce(i)&&!this.useRawValueToEscape&&(i=yp(i));const b=m.safeValue(i);if(t=t.replace(a[0],b),p?(m.regex.lastIndex+=i.length,m.regex.lastIndex-=a[0].length):m.regex.lastIndex=0,l++,l>=this.maxReplaces)break}}),t}nest(t,n,r={}){let s,a,i;const l=(c,d)=>{const f=this.nestingOptionsSeparator;if(c.indexOf(f)<0)return c;const p=c.split(new RegExp(`${On(f)}[ ]*{`));let h=`{${p[1]}`;c=p[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}${f}${h}`}return i.defaultValue&&i.defaultValue.indexOf(this.prefix)>-1&&delete i.defaultValue,c};for(;s=this.nestingRegexp.exec(t);){let c=[];i={...r},i=i.replace&&!Ce(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(f=>f.trim()).filter(Boolean),s[1]=s[1].slice(0,d)),a=n(l.call(this,s[1].trim(),i),i),a&&s[0]===t&&!Ce(a))return a;Ce(a)||(a=yp(a)),a||(this.logger.warn(`missed to resolve ${s[1]} for nesting ${t}`),a=""),c.length&&(a=c.reduce((f,p)=>this.format(f,p,r.lng,{...r,interpolationkey:s[1].trim()}),a.trim())),t=t.replace(s[0],a),this.regexp.lastIndex=0}return t}}const HO=e=>{let t=e.toLowerCase().trim();const n={};if(e.indexOf("(")>-1){const r=e.split("(");t=r[0].toLowerCase().trim();const s=r[1].substring(0,r[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,""),f=l.trim();n[f]||(n[f]=d),d==="false"&&(n[f]=!1),d==="true"&&(n[f]=!0),isNaN(d)||(n[f]=parseInt(d,10))}})}return{formatName:t,formatOptions:n}},Pp=e=>{const t={};return(n,r,s)=>{let a=s;s&&s.interpolationkey&&s.formatParams&&s.formatParams[s.interpolationkey]&&s[s.interpolationkey]&&(a={...a,[s.interpolationkey]:void 0});const i=r+JSON.stringify(a);let l=t[i];return l||(l=e(ko(r),s),t[i]=l),l(n)}},VO=e=>(t,n,r)=>e(ko(n),r)(t);class qO{constructor(t={}){this.logger=Ut.create("formatter"),this.options=t,this.init(t)}init(t,n={interpolation:{}}){this.formatSeparator=n.interpolation.formatSeparator||",";const r=n.cacheInBuiltFormats?Pp:VO;this.formats={number:r((s,a)=>{const i=new Intl.NumberFormat(s,{...a});return l=>i.format(l)}),currency:r((s,a)=>{const i=new Intl.NumberFormat(s,{...a,style:"currency"});return l=>i.format(l)}),datetime:r((s,a)=>{const i=new Intl.DateTimeFormat(s,{...a});return l=>i.format(l)}),relativetime:r((s,a)=>{const i=new Intl.RelativeTimeFormat(s,{...a});return l=>i.format(l,a.range||"day")}),list:r((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()]=Pp(n)}format(t,n,r,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:f}=HO(c);if(this.formats[d]){let p=l;try{const h=s?.formatParams?.[s.interpolationkey]||{},m=h.locale||h.lng||s.locale||s.lng||r;p=this.formats[d](l,m,{...f,...s,...h})}catch(h){this.logger.warn(h)}return p}else this.logger.warn(`there was no format function for ${d}`);return l},t)}}const UO=(e,t)=>{e.pending[t]!==void 0&&(delete e.pending[t],e.pendingCount--)};class QO extends ja{constructor(t,n,r,s={}){super(),this.backend=t,this.store=n,this.services=r,this.languageUtils=r.languageUtils,this.options=s,this.logger=Ut.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?.(r,s.backend,s)}queueLoad(t,n,r,s){const a={},i={},l={},c={};return t.forEach(d=>{let f=!0;n.forEach(p=>{const h=`${d}|${p}`;!r.reload&&this.store.hasResourceBundle(d,p)?this.state[h]=2:this.state[h]<0||(this.state[h]===1?i[h]===void 0&&(i[h]=!0):(this.state[h]=1,f=!1,i[h]===void 0&&(i[h]=!0),a[h]===void 0&&(a[h]=!0),c[p]===void 0&&(c[p]=!0)))}),f||(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,r){const s=t.split("|"),a=s[0],i=s[1];n&&this.emit("failedLoading",a,i,n),!n&&r&&this.store.addResourceBundle(a,i,r,void 0,void 0,{skipCopy:!0}),this.state[t]=n?-1:2,n&&r&&(this.state[t]=0);const l={};this.queue.forEach(c=>{_O(c.loaded,[a],i),UO(c,t),n&&c.errors.push(n),c.pendingCount===0&&!c.done&&(Object.keys(c.loaded).forEach(d=>{l[d]||(l[d]={});const f=c.loaded[d];f.length&&f.forEach(p=>{l[d][p]===void 0&&(l[d][p]=!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,r,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:r,tried:s,wait:a,callback:i});return}this.readingCalls++;const l=(d,f)=>{if(this.readingCalls--,this.waitingReads.length>0){const p=this.waitingReads.shift();this.read(p.lng,p.ns,p.fcName,p.tried,p.wait,p.callback)}if(d&&f&&s<this.maxRetries){setTimeout(()=>{this.read.call(this,t,n,r,s+1,a*2,i)},a);return}i(d,f)},c=this.backend[r].bind(this.backend);if(c.length===2){try{const d=c(t,n);d&&typeof d.then=="function"?d.then(f=>l(null,f)).catch(l):l(null,d)}catch(d){l(d)}return}return c(t,n,l)}prepareLoading(t,n,r={},s){if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),s&&s();Ce(t)&&(t=this.languageUtils.toResolveHierarchy(t)),Ce(n)&&(n=[n]);const a=this.queueLoad(t,n,r,s);if(!a.toLoad.length)return a.pending.length||s(),null;a.toLoad.forEach(i=>{this.loadOne(i)})}load(t,n,r){this.prepareLoading(t,n,{},r)}reload(t,n,r){this.prepareLoading(t,n,{reload:!0},r)}loadOne(t,n=""){const r=t.split("|"),s=r[0],a=r[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,r,s,a,i={},l=()=>{}){if(this.services?.utils?.hasLoadedNamespace&&!this.services?.utils?.hasLoadedNamespace(n)){this.logger.warn(`did not save key "${r}" 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(!(r==null||r==="")){if(this.backend?.create){const c={...i,isUpdate:a},d=this.backend.create.bind(this.backend);if(d.length<6)try{let f;d.length===5?f=d(t,n,r,s,c):f=d(t,n,r,s),f&&typeof f.then=="function"?f.then(p=>l(null,p)).catch(l):l(null,f)}catch(f){l(f)}else d(t,n,r,s,l,c)}!t||!t[0]||this.store.addResource(t[0],n,r,s)}}}const Di=()=>({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]),Ce(e[1])&&(t.defaultValue=e[1]),Ce(e[2])&&(t.tDescription=e[2]),typeof e[2]=="object"||typeof e[3]=="object"){const n=e[3]||e[2];Object.keys(n).forEach(r=>{t[r]=n[r]})}return t},interpolation:{escapeValue:!0,format:e=>e,prefix:"{{",suffix:"}}",formatSeparator:",",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",nestingOptionsSeparator:",",maxReplaces:1e3,skipOnVariables:!0},cacheInBuiltFormats:!0}),_p=e=>(Ce(e.ns)&&(e.ns=[e.ns]),Ce(e.fallbackLng)&&(e.fallbackLng=[e.fallbackLng]),Ce(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),ms=()=>{},GO=e=>{Object.getOwnPropertyNames(Object.getPrototypeOf(e)).forEach(n=>{typeof e[n]=="function"&&(e[n]=e[n].bind(e))})},S0="__i18next_supportNoticeShown",KO=()=>!!(typeof globalThis<"u"&&globalThis[S0]||typeof process<"u"&&Pi&&Pi.I18NEXT_NO_SUPPORT_NOTICE||typeof process<"u"&&Pi),WO=()=>{typeof globalThis<"u"&&(globalThis[S0]=!0)},YO=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 uo extends ja{constructor(t={},n){if(super(),this.options=_p(t),this.services={},this.logger=Ut,this.modules={external:[]},GO(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&&(Ce(t.ns)?t.defaultNS=t.ns:t.ns.indexOf("translation")<0&&(t.defaultNS=t.ns[0]));const r=Di();this.options={...r,...this.options,..._p(t)},this.options.interpolation={...r.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=r.overloadTranslationOptionHandler),this.options.showSupportNotice!==!1&&!YO(this)&&!KO()&&(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 💙"),WO());const s=d=>d?typeof d=="function"?new d:d:null;if(!this.options.isClone){this.modules.logger?Ut.init(s(this.modules.logger),this.options):Ut.init(null,this.options);let d;this.modules.formatter?d=this.modules.formatter:d=qO;const f=new Cp(this.options);this.store=new kp(this.options.resources,this.options);const p=this.services;p.logger=Ut,p.resourceStore=this.store,p.languageUtils=f,p.pluralResolver=new jO(f,{prepend:this.options.pluralSeparator,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),this.options.interpolation.format&&this.options.interpolation.format!==r.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===r.interpolation.format)&&(p.formatter=s(d),p.formatter.init&&p.formatter.init(p,this.options),this.options.interpolation.format=p.formatter.format.bind(p.formatter)),p.interpolator=new Ap(this.options),p.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},p.backendConnector=new QO(s(this.modules.backend),p.resourceStore,p,this.options),p.backendConnector.on("*",(m,...g)=>{this.emit(m,...g)}),this.modules.languageDetector&&(p.languageDetector=s(this.modules.languageDetector),p.languageDetector.init&&p.languageDetector.init(p,this.options.detection,this.options)),this.modules.i18nFormat&&(p.i18nFormat=s(this.modules.i18nFormat),p.i18nFormat.init&&p.i18nFormat.init(this)),this.translator=new Js(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=ms),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]=(...f)=>this.store[d](...f)}),["addResource","addResources","addResourceBundle","removeResourceBundle"].forEach(d=>{this[d]=(...f)=>(this.store[d](...f),this)});const l=Zr(),c=()=>{const d=(f,p)=>{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(p),n(f,p)};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=ms){let r=n;const s=Ce(t)?t:this.language;if(typeof t=="function"&&(r=t),!this.options.resources||this.options.partialBundledLanguages){if(s?.toLowerCase()==="cimode"&&(!this.options.preload||this.options.preload.length===0))return r();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),r(l)})}else r(null)}reloadResources(t,n,r){const s=Zr();return typeof t=="function"&&(r=t,t=void 0),typeof n=="function"&&(r=n,n=void 0),t||(t=this.languages),n||(n=this.options.ns),r||(r=ms),this.services.backendConnector.reload(t,n,a=>{s.resolve(),r(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"&&N0.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 r=this.languages[n];if(!(["cimode","dev"].indexOf(r)>-1)&&this.store.hasLanguageSomeTranslations(r)){this.resolvedLanguage=r;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 r=Zr();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,r.resolve((...d)=>this.t(...d)),n&&n(l,(...d)=>this.t(...d))},i=l=>{!t&&!l&&this.services.languageDetector&&(l=[]);const c=Ce(l)?l:l&&l[0],d=this.store.hasLanguageSomeTranslations(c)?c:this.services.languageUtils.getBestMatchFromCodes(Ce(l)?[l]:l);d&&(this.language||s(d),this.translator.language||this.translator.changeLanguage(d),this.services.languageDetector?.cacheUserLanguage?.(d)),this.loadResources(d,f=>{a(f,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),r}getFixedT(t,n,r){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||r||s.keyPrefix);const d={...this.options,...c};typeof c.keyPrefix=="function"&&(c.keyPrefix=vr(c.keyPrefix,d));const f=this.options.keySeparator||".";let p;return c.keyPrefix&&Array.isArray(a)?p=a.map(h=>(typeof h=="function"&&(h=vr(h,d)),`${c.keyPrefix}${f}${h}`)):(typeof a=="function"&&(a=vr(a,d)),p=c.keyPrefix?`${c.keyPrefix}${f}${a}`:a),this.t(p,c)};return Ce(t)?s.lng=t:s.lngs=t,s.ns=n,s.keyPrefix=r,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 r=n.lng||this.resolvedLanguage||this.languages[0],s=this.options?this.options.fallbackLng:!1,a=this.languages[this.languages.length-1];if(r.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(r,t)||!this.services.backendConnector.backend||this.options.resources&&!this.options.partialBundledLanguages||i(r,t)&&(!s||i(a,t)))}loadNamespaces(t,n){const r=Zr();return this.options.ns?(Ce(t)&&(t=[t]),t.forEach(s=>{this.options.ns.indexOf(s)<0&&this.options.ns.push(s)}),this.loadResources(s=>{r.resolve(),n&&n(s)}),r):(n&&n(),Promise.resolve())}loadLanguages(t,n){const r=Zr();Ce(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=>{r.resolve(),n&&n(i)}),r):(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"],r=this.services?.languageUtils||new Cp(Di());return t.toLowerCase().indexOf("-latn")>1?"ltr":n.indexOf(r.getLanguagePartFromCode(t))>-1||t.toLowerCase().indexOf("-arab")>1?"rtl":"ltr"}static createInstance(t={},n){const r=new uo(t,n);return r.createInstance=uo.createInstance,r}cloneInstance(t={},n=ms){const r=t.forkResourceStore;r&&delete t.forkResourceStore;const s={...this.options,...t,isClone:!0},a=new uo(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)},r){const l=Object.keys(this.store.data).reduce((c,d)=>(c[d]={...this.store.data[d]},c[d]=Object.keys(c[d]).reduce((f,p)=>(f[p]={...c[d][p]},f),c[d]),c),{});a.store=new kp(l,s),a.services.resourceStore=a.store}if(t.interpolation){const c={...Di().interpolation,...this.options.interpolation,...t.interpolation},d={...s,interpolation:c};a.services.interpolator=new Ap(d)}return a.translator=new Js(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 Ze=uo.createInstance();Ze.createInstance;Ze.dir;Ze.init;Ze.loadResources;Ze.reloadResources;Ze.use;Ze.changeLanguage;Ze.getFixedT;Ze.t;Ze.exists;Ze.setDefaultNamespace;Ze.hasLoadedNamespace;Ze.loadNamespaces;Ze.loadLanguages;const ZO=(e,t,n,r)=>{const s=[n,{code:t,...r||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(s,"warn","react-i18next::",!0);Yn(s[0])&&(s[0]=`react-i18next:: ${s[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...s):console?.warn&&console.warn(...s)},$p={},Tl=(e,t,n,r)=>{Yn(n)&&$p[n]||(Yn(n)&&($p[n]=new Date),ZO(e,t,n,r))},C0=(e,t)=>()=>{if(e.isInitialized)t();else{const n=()=>{setTimeout(()=>{e.off("initialized",n)},0),t()};e.on("initialized",n)}},Ll=(e,t,n)=>{e.loadNamespaces(t,C0(e,n))},Dp=(e,t,n,r)=>{if(Yn(n)&&(n=[n]),e.options.preload&&e.options.preload.indexOf(t)>-1)return Ll(e,n,r);n.forEach(s=>{e.options.ns.indexOf(s)<0&&e.options.ns.push(s)}),e.loadLanguages(t,C0(e,r))},XO=(e,t,n={})=>!t.languages||!t.languages.length?(Tl(t,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:t.languages}),!0):t.hasLoadedNamespace(e,{lng:n.lng,precheck:(r,s)=>{if(n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&r.services.backendConnector.backend&&r.isLanguageChangingTo&&!s(r.isLanguageChangingTo,e))return!1}}),Yn=e=>typeof e=="string",JO=e=>typeof e=="object"&&e!==null,e8=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,t8={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},n8=e=>t8[e],r8=e=>e.replace(e8,n8);let Rl={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:r8,transDefaultProps:void 0};const o8=(e={})=>{Rl={...Rl,...e}},s8=()=>Rl;let M0;const a8=e=>{M0=e},i8=()=>M0,l8={type:"3rdParty",init(e){o8(e.options.react),a8(e)}},c8=Be();class d8{constructor(){this.usedNamespaces={}}addUsedNamespaces(t){t.forEach(n=>{this.usedNamespaces[n]||(this.usedNamespaces[n]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}var E0={exports:{}},I0={};/**
1106
- * @license React
1107
- * use-sync-external-store-shim.production.js
1108
- *
1109
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1110
- *
1111
- * This source code is licensed under the MIT license found in the
1112
- * LICENSE file in the root directory of this source tree.
1113
- */var Ir=Lh;function u8(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var p8=typeof Object.is=="function"?Object.is:u8,f8=Ir.useState,h8=Ir.useEffect,m8=Ir.useLayoutEffect,g8=Ir.useDebugValue;function b8(e,t){var n=t(),r=f8({inst:{value:n,getSnapshot:t}}),s=r[0].inst,a=r[1];return m8(function(){s.value=n,s.getSnapshot=t,Ti(s)&&a({inst:s})},[e,n,t]),h8(function(){return Ti(s)&&a({inst:s}),e(function(){Ti(s)&&a({inst:s})})},[e]),g8(n),n}function Ti(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!p8(e,n)}catch{return!0}}function x8(e,t){return t()}var y8=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?x8:b8;I0.useSyncExternalStore=Ir.useSyncExternalStore!==void 0?Ir.useSyncExternalStore:y8;E0.exports=I0;var A0=E0.exports;const v8=(e,t)=>{if(Yn(t))return t;if(JO(t)&&Yn(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},w8={t:v8,ready:!1},N8=()=>()=>{},zt=(e,t={})=>{const{i18n:n}=t,{i18n:r,defaultNS:s}=ve(c8)||{},a=n||r||i8();a&&!a.reportNamespaces&&(a.reportNamespaces=new d8),a||Tl(a,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const i=q(()=>({...s8(),...a?.options?.react,...t}),[a,t]),{useSuspense:l,keyPrefix:c}=i,d=s||a?.options?.defaultNS,f=Yn(d)?[d]:d||["translation"],p=q(()=>f,f);a?.reportNamespaces?.addUsedNamespaces?.(p);const h=ne(0),m=U(I=>{if(!a)return N8;const{bindI18n:z,bindI18nStore:$}=i,B=()=>{h.current+=1,I()};return z&&a.on(z,B),$&&a.store.on($,B),()=>{z&&z.split(" ").forEach(R=>a.off(R,B)),$&&$.split(" ").forEach(R=>a.store.off(R,B))}},[a,i]),g=ne(),b=U(()=>{if(!a)return w8;const I=!!(a.isInitialized||a.initializedStoreOnce)&&p.every(T=>XO(T,a,i)),z=t.lng||a.language,$=h.current,B=g.current;if(B&&B.ready===I&&B.lng===z&&B.keyPrefix===c&&B.revision===$)return B;const M={t:a.getFixedT(z,i.nsMode==="fallback"?p:p[0],c),ready:I,lng:z,keyPrefix:c,revision:$};return g.current=M,M},[a,p,c,i,t.lng]),[x,y]=P(0),{t:w,ready:v}=A0.useSyncExternalStore(m,b,b);Y(()=>{if(a&&!v&&!l){const I=()=>y(z=>z+1);t.lng?Dp(a,t.lng,p,I):Ll(a,p,I)}},[a,t.lng,p,v,l,x]);const N=a||{},k=ne(null),C=ne(),E=I=>{const z=Object.getOwnPropertyDescriptors(I);z.__original&&delete z.__original;const $=Object.create(Object.getPrototypeOf(I),z);if(!Object.prototype.hasOwnProperty.call($,"__original"))try{Object.defineProperty($,"__original",{value:I,writable:!1,enumerable:!1,configurable:!1})}catch{}return $},A=q(()=>{const I=N,z=I?.language;let $=I;I&&(k.current&&k.current.__original===I?C.current!==z?($=E(I),k.current=$,C.current=z):$=k.current:($=E(I),k.current=$,C.current=z));const B=!v&&!l?(...M)=>(Tl(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(...M)):w,R=[B,$,v];return R.t=B,R.i18n=$,R.ready=v,R},[w,N,v,N.resolvedLanguage,N.language,N.languages]);if(a&&l&&!v)throw new Promise(I=>{const z=()=>I();t.lng?Dp(a,t.lng,p,z):Ll(a,p,z)});return A},Tp={info:kn,success:Xy,warning:ut,error:Mr},k8={info:"text-blue-400",success:"text-green-400",warning:"text-amber-400",error:"text-red-400"},Lp={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 S8(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 r=Math.floor(n/60);if(r<24)return`${String(r)}h ago`;const s=Math.floor(r/24);return`${String(s)}d ago`}function Rp({alert:e,onMarkRead:t,onDismiss:n}){const r=e.severity in Tp?e.severity:"info",s=e.status in Lp?e.status:"active",a=Tp[r],i=k8[r],l=Lp[s];return u("div",{className:`flex items-start gap-2.5 px-3 py-2.5 border-l-2 ${l} ${e.read?"opacity-60":""} hover:bg-surface-hover transition-colors`,children:[o(a,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 ${i}`}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-1.5",children:[o("span",{className:`text-[11px] font-semibold ${e.read?"text-foreground-subtle":"text-foreground"}`,children:e.title}),!e.read&&o("span",{className:"h-1.5 w-1.5 rounded-full bg-primary shrink-0"})]}),o("div",{className:"text-[10px] text-foreground-subtle mt-0.5 line-clamp-2",children:e.message}),e.status==="in-progress"&&e.progress!==void 0&&u("div",{className:"mt-1.5 flex items-center gap-2",children:[o("div",{className:"flex-1 h-1 bg-surface-hover rounded-full overflow-hidden",children:o("div",{className:"h-full bg-primary rounded-full transition-all duration-300",style:{width:`${String(Math.min(100,Math.max(0,e.progress)))}%`}})}),u("span",{className:"text-[9px] text-foreground-subtle font-mono shrink-0",children:[String(Math.round(e.progress)),"%"]})]}),o("div",{className:"text-[9px] text-foreground-subtle/60 mt-1",children:S8(e.updatedAt)})]}),u("div",{className:"flex items-center gap-0.5 shrink-0",children:[!e.read&&o("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:o(Mt,{className:"h-3 w-3 text-foreground-subtle"})}),e.status!=="in-progress"&&o("button",{type:"button",onClick:c=>{c.stopPropagation(),n(e.id)},className:"p-1 rounded hover:bg-surface-hover transition-colors",title:"Dismiss",children:o(Fe,{className:"h-3 w-3 text-foreground-subtle"})})]})]})}function Op({variant:e="icon",compact:t=!1}={}){const[n,r]=P(!1),[s,a]=P(!1),i=ne(null),l=ne(null),c=ke(),{data:d=0}=Kg(void 0,{staleTime:1e4,refetchInterval:3e4}),{data:f=[],isLoading:p}=Gg({limit:50},{enabled:n,staleTime:5e3}),h=s?f:f.filter(I=>!I.read),m=f.filter(I=>I.read).length,g=()=>{c.invalidateQueries({queryKey:[["alerts"]]})},b=Wg({onSuccess:g}),x=Yg({onSuccess:g}),y=Zg({onSuccess:g});pt("alert.created",()=>{c.invalidateQueries({queryKey:[["alerts"]]})}),pt("alert.updated",()=>{c.invalidateQueries({queryKey:[["alerts"]]})}),Y(()=>{if(!n)return;const I=z=>{const $=z.target;i.current&&!i.current.contains($)&&l.current&&!l.current.contains($)&&r(!1)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[n]);const w=U(I=>{b.mutate({alertId:I})},[b]),v=U(I=>{I&&y.mutate({alertId:I})},[y]),N=U(()=>{x.mutate(void 0),r(!1)},[x]),k=h.filter(I=>I.status==="in-progress"),C=h.filter(I=>I.status!=="in-progress"),[E,A]=P({});return Y(()=>{if(n&&l.current){const I=l.current.getBoundingClientRect();A({position:"fixed",left:I.left,bottom:window.innerHeight-I.top+4,zIndex:9999})}},[n]),u("div",{children:[e==="sidebar"?u("button",{ref:l,type:"button",onClick:()=>r(!n),className:`flex w-full items-center gap-2.5 rounded-md ${t?"justify-center px-0 py-2":"px-2.5 py-1.5"} text-[12px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,title:t?`Alerts${d>0?` (${d})`:""}`:void 0,children:[u("span",{className:"relative inline-flex shrink-0",children:[o(rt,{className:"h-3.5 w-3.5"}),t&&d>0&&o("span",{className:"absolute -top-1 -right-1 h-2 w-2 rounded-full bg-primary"})]}),!t&&o("span",{className:"flex-1 text-left",children:"Alerts"}),!t&&d>0&&o("span",{className:"flex items-center justify-center h-4 min-w-4 px-1 rounded-full bg-primary text-primary-foreground text-[9px] font-bold leading-none",children:d>99?"99+":String(d)})]}):u("button",{ref:l,type:"button",onClick:()=>r(!n),className:"relative p-1.5 rounded-md hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors","aria-label":"Alerts",children:[o(rt,{className:"h-4.5 w-4.5"}),d>0&&o("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&&Lo(u("div",{ref:i,style:E,className:"w-80 max-h-[28rem] bg-surface border border-border rounded-lg shadow-xl flex flex-col overflow-hidden",children:[u("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border shrink-0",children:[o("span",{className:"text-[12px] font-semibold text-foreground",children:"Alerts"}),u("div",{className:"flex items-center gap-2",children:[m>0&&u("label",{className:"flex items-center gap-1 text-[10px] text-foreground-subtle cursor-pointer select-none",children:[o("input",{type:"checkbox",checked:s,onChange:I=>a(I.target.checked),className:"h-3 w-3 rounded border-border accent-primary cursor-pointer"}),"Show read"]}),d>0&&u("button",{type:"button",onClick:N,className:"flex items-center gap-1 text-[10px] text-primary hover:text-primary/80 transition-colors",children:[o(PL,{className:"h-3 w-3"}),"Mark all read"]})]})]}),u("div",{className:"flex-1 overflow-y-auto",children:[p&&o("div",{className:"flex items-center justify-center py-8",children:o(Ee,{className:"h-4 w-4 animate-spin text-foreground-subtle"})}),!p&&h.length===0&&u("div",{className:"flex flex-col items-center justify-center py-8 text-foreground-subtle",children:[o(rt,{className:"h-6 w-6 mb-2 opacity-40"}),o("span",{className:"text-[11px]",children:f.length>0?"No unread alerts":"No alerts"}),f.length>0&&!s&&u("button",{type:"button",onClick:()=>a(!0),className:"text-[10px] text-primary mt-1 hover:underline",children:["Show ",m," read alert",m!==1?"s":""]})]}),k.length>0&&u("div",{className:"border-b border-border",children:[o("div",{className:"px-3 py-1.5 bg-surface-hover/50",children:o("span",{className:"text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60",children:"In Progress"})}),k.map(I=>o(Rp,{alert:I,onMarkRead:w,onDismiss:v},I.id))]}),C.map(I=>o(Rp,{alert:I,onMarkRead:w,onDismiss:v},I.id))]})]}),document.body)]})}function P0(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 Bp=new Map,gs=new Map,zp=new Set;function C8(e){return!e||typeof e!="object"?!1:typeof e.default=="function"}async function M8(e,t){const n=Bp.get(e);if(n)return n;const r=gs.get(e);if(r)return r;zp.has(e)||(pc(),kr.registerRemotes([{name:e,entry:t,type:"module"}],{force:!1}),zp.add(e));const s=kr.loadRemote(`${e}/page`).then(a=>{if(!C8(a))throw new Error(`Addon page remote ${e} (${t}) does not expose a default React component on './page'`);return Bp.set(e,a.default),gs.delete(e),a.default}).catch(a=>{throw gs.delete(e),a});return gs.set(e,s),s}function E8(){const{pagePath:e}=yd(),t=Le(),{data:n}=Sa(void 0,{staleTime:6e4}),r=q(()=>n?P0(n):void 0,[n]),s=r?.find(d=>d.path===`/addon/${e}`),[a,i]=P(null),[l,c]=P(null);return Y(()=>{if(!s)return;c(null),i(null);let d=!1;return M8(s.remoteName,s.bundleUrl).then(f=>{d||i(()=>f)}).catch(f=>{if(d)return;const p=f instanceof Error?f.message:String(f);c(`Failed to load addon page: ${p}`)}),()=>{d=!0}},[s]),r?s?l?o("div",{className:"flex items-center justify-center h-full text-red-400 text-sm",children:l}):a?o(a,{trpc:t.trpcClient,theme:{isDark:document.documentElement.classList.contains("dark")},navigate:d=>{window.location.href=d}}):o("div",{className:"flex items-center justify-center h-full",children:o("div",{className:"animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full"})}):o("div",{className:"flex items-center justify-center h-full text-foreground-subtle",children:"Addon page not found"}):o("div",{className:"flex items-center justify-center h-full",children:o("div",{className:"animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full"})})}const I8={dark:i0,light:P6,system:FR},A8={gauge:r0,puzzle:No,bot:wL,cpu:ft,terminal:h0,box:Ra,wrench:q6,activity:qo,plug:wo};function P8(){const e=bt(),t=et(),{user:n,logout:r}=mn(),s=Or(),{t:a}=zt(),i=ar(),l=Km(),c=tL(),d=c!=="connected",f=c==="connecting",[p,h]=P(!1),[m,g]=P(()=>typeof window>"u"?!1:window.localStorage.getItem("camstack:sidebar-collapsed")==="1");Y(()=>{typeof window>"u"||window.localStorage.setItem("camstack:sidebar-collapsed",m?"1":"0")},[m]);const[b,x]=P(()=>{if(typeof window>"u")return new Set;try{const F=window.localStorage.getItem("camstack:sidebar-collapsed-groups");if(!F)return new Set;const H=JSON.parse(F);return Array.isArray(H)?new Set(H.filter(D=>typeof D=="string")):new Set}catch{return new Set}});Y(()=>{typeof window>"u"||window.localStorage.setItem("camstack:sidebar-collapsed-groups",JSON.stringify([...b]))},[b]),Y(()=>{l&&window.localStorage.getItem("camstack:sidebar-collapsed")===null&&g(!0)},[l]);const{data:y=[]}=jc(void 0,{staleTime:3e4,refetchInterval:3e4}),w=y.length,v=ke(),N=ne(Date.now()),k=3e4,C=2e3,{data:E}=Sa(void 0,{staleTime:0,refetchOnMount:"always",refetchInterval:F=>{const H=F.state.data;return H&&H.length>0||Date.now()-N.current>=k?!1:C}}),A=q(()=>E?P0(E):[],[E]);pt("addon.page-ready",()=>{v.invalidateQueries({queryKey:[["addonPages","listPages"]]})});const I=()=>{r(),t("/login")},z=F=>!!(e.pathname===F||e.pathname.startsWith(F+"/")),B=["/pipeline","/timeline"].some(F=>e.pathname===F||e.pathname.startsWith(F+"/")),R=[{label:a("nav.devices","Devices"),icon:Cr,path:"/devices"},{label:a("nav.integrations"),icon:wo,path:"/integrations"},{label:a("nav.timeline","Timeline"),icon:qL,path:"/timeline"},{label:a("nav.pipeline","Pipeline"),icon:lR,path:"/pipeline"}],M=[{label:a("system.identity","Identity & Access"),icon:a0,path:"/system/identity"},{label:a("system.network","Network"),icon:Wt,path:"/system/network"},{label:a("system.integrations","Integrations"),icon:wo,path:"/system/integrations"},{label:a("system.data","Data"),icon:t0,path:"/system/data"},{label:a("system.cluster","Cluster"),icon:Mn,path:"/system/cluster"},{label:a("system.addons"),icon:No,path:"/system/addons"},{label:a("system.addonSettings","Addon Settings"),icon:Yt,path:"/system/settings"},{label:a("system.logs","Logs"),icon:rt,path:"/system/logs"}],T=s?.mode??"system",_={dark:a("theme.dark"),light:a("theme.light"),system:a("theme.system")},L=m&&!i,O=(F,H="md")=>`flex w-full items-center gap-2.5 rounded-md ${L?"justify-center px-0 py-2":"px-2.5 py-1.5"} ${H==="lg"?"text-[13px] font-medium":"text-[12px]"} transition-all ${F?H==="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"}`,j=u(me,{children:[u("div",{className:`flex h-14 items-center border-b border-border ${L?"justify-center px-1":"pl-3 pr-4 gap-2"}`,children:[!L&&o("img",{src:s?.resolvedMode==="light"?"/brand/logo-horizontal-light.svg":"/brand/logo-horizontal-dark.svg",alt:"CamStack Admin",className:"h-9 flex-1 min-w-0"}),!i&&o("button",{onClick:()=>g(F=>!F),className:`p-1.5 rounded-md hover:bg-surface-hover text-foreground-subtle transition-colors flex-shrink-0 ${L?"":"mr-2"}`,"aria-label":m?"Expand sidebar":"Collapse sidebar",title:m?"Expand sidebar":"Collapse sidebar",children:m?o(Et,{className:"h-4 w-4"}):o(Ed,{className:"h-4 w-4"})})]}),u("nav",{className:`flex-1 overflow-y-auto py-3 ${L?"px-1.5":"px-2"} space-y-0.5`,children:[(()=>{const F=z("/dashboard");return u("button",{"data-testid":"nav-dashboard",onClick:()=>{t("/dashboard"),h(!1)},className:O(F,"lg"),title:L?a("nav.dashboard"):void 0,children:[o(s0,{className:`h-4 w-4 shrink-0 ${F?"text-primary":""}`}),!L&&a("nav.dashboard")]})})(),!L&&o("div",{className:"pt-4 pb-1.5 px-2.5",children:o("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60",children:a("nav.camerasSection","Cameras")})}),L&&o("div",{className:"pt-3 mb-1 mx-2 border-t border-border/60"}),R.map(F=>{const H=F.icon,D=z(F.path),Q=`nav-${F.path.replace(/^\//,"").replace(/\//g,"-")}`;return u("button",{"data-testid":Q,onClick:()=>{t(F.path),h(!1)},className:O(D),title:L?F.label:void 0,children:[o(H,{className:`h-3.5 w-3.5 shrink-0 ${D?"text-primary":""}`}),!L&&F.label]},F.path)}),!L&&o("div",{className:"pt-4 pb-1.5 px-2.5",children:o("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60",children:a("system.title")})}),L&&o("div",{className:"pt-3 mb-1 mx-2 border-t border-border/60"}),M.map(F=>{const H=F.icon,D=z(F.path),Q=F.path==="/system/addons",G=`nav-${F.path.replace(/^\//,"").replace(/\//g,"-")}`;return u("button",{"data-testid":G,onClick:()=>{t(F.path),h(!1)},className:O(D),title:L?F.label:void 0,children:[o(H,{className:`h-3.5 w-3.5 shrink-0 ${D?"text-primary":""}`}),!L&&u(me,{children:[o("span",{className:"flex-1 text-left",children:F.label}),Q&&w>0&&o("span",{className:"ml-auto rounded-full bg-primary px-1.5 py-0.5 text-[9px] font-bold text-primary-foreground leading-none",children:w})]}),L&&Q&&w>0&&o("span",{className:"absolute mt-[-14px] ml-3 h-2 w-2 rounded-full bg-primary"})]},F.path)}),A&&A.length>0&&!L&&o("div",{className:"pt-4 pb-1.5 px-2.5",children:o("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60",children:a("nav.addonPages","Addon Pages")})}),L&&A&&A.length>0&&o("div",{className:"pt-3 mb-1 mx-2 border-t border-border/60"}),A?.map(F=>{const H=z(F.path),D=A8[F.icon]??No;return u("button",{onClick:()=>{t(F.path),h(!1)},className:O(H),title:L?F.label:void 0,children:[o(D,{className:`h-3.5 w-3.5 shrink-0 ${H?"text-primary":""}`}),!L&&F.label]},F.id)})]}),u("div",{className:`border-t border-border ${L?"p-1.5":"p-2"} space-y-0.5`,children:[u("button",{onClick:()=>s?.toggleMode(),className:O(!1),title:L?_[T]:void 0,children:[(()=>{const F=I8[T];return o(F,{className:"h-3.5 w-3.5 shrink-0"})})(),!L&&o("span",{children:_[T]})]}),o(Op,{variant:"sidebar",compact:L}),u("button",{type:"button",onClick:()=>t("/system/my-access"),className:O(z("/system/my-access")),title:L?a("system.myAccess","My access"):void 0,children:[o(dn,{className:"h-3.5 w-3.5 shrink-0"}),!L&&o("span",{className:"truncate",children:a("system.myAccess","My access")})]}),u("button",{onClick:I,className:O(!1).replace("hover:text-foreground","hover:text-danger"),title:L?n?.username??"Logout":void 0,children:[o(Ad,{className:"h-3.5 w-3.5 shrink-0"}),!L&&o("span",{className:"truncate",children:n?.username??"User"})]})]})]});return u("div",{className:"flex h-screen bg-background text-foreground",children:[!i&&o("aside",{className:`flex flex-col border-r border-border bg-surface/80 backdrop-blur-sm shrink-0 transition-[width] duration-150 ease-out ${L?"w-12":"w-48"}`,children:j}),i&&o(Mc,{open:p,onClose:()=>h(!1),width:"w-64",children:j}),u("div",{className:"flex flex-1 flex-col min-w-0",children:[d&&u("div",{className:"flex items-center justify-center gap-2 bg-danger/90 px-3 py-2 text-[12px] font-medium text-white shrink-0",children:[o(g0,{className:"h-3.5 w-3.5"}),o("span",{children:f?a("connection.reconnecting","Reconnecting…"):a("connection.disconnected","Server unreachable — reconnecting…")}),o(Ee,{className:"h-3.5 w-3.5 animate-spin"})]}),i&&u("header",{className:"flex items-center h-12 border-b border-border px-3 shrink-0 bg-surface/80 backdrop-blur-sm",children:[o("button",{onClick:()=>h(!0),className:"p-1.5 -ml-1.5 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors","aria-label":"Open menu",children:o(LR,{className:"h-5 w-5"})}),o("div",{className:"flex-1 flex justify-center",children:o("img",{src:s?.resolvedMode==="light"?"/brand/logo-horizontal-light.svg":"/brand/logo-horizontal-dark.svg",alt:"CamStack",className:"h-7"})}),o(Op,{})]}),u("main",{className:`relative flex-1 min-h-0 bg-background ${B?"overflow-hidden":"overflow-auto"}`,children:[d&&o("div",{className:"absolute inset-0 z-40 bg-background/60 backdrop-blur-[2px]"}),o(fT,{})]})]})]})}function _8(){const{login:e,verifyTotp:t}=mn(),n=Or(),r=et(),[s,a]=P(""),[i,l]=P(""),[c,d]=P(!1),[f,p]=P(""),[h,m]=P(!1),[g,b]=P("credentials"),[x,y]=P(""),[w,v]=P(""),N=async E=>{E.preventDefault(),p(""),m(!0);try{const A=await e(s,i);if(A.kind==="totp-required"){y(A.challengeToken),b("totp");return}r(i==="changeme"?"/change-password":"/dashboard",{replace:!0})}catch(A){p(A instanceof Error?A.message:"Login failed")}finally{m(!1)}},k=async E=>{E.preventDefault(),p(""),m(!0);try{await t(x,w.trim()),r("/dashboard",{replace:!0})}catch(A){p(A instanceof Error?A.message:"TOTP verification failed"),v("")}finally{m(!1)}},C=()=>{b("credentials"),y(""),v(""),p("")};return o("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:u("div",{className:"w-full max-w-sm",children:[o("div",{className:"flex justify-center mb-8",children:o("img",{src:n?.resolvedMode==="light"?"/brand/logo-horizontal-light.svg":"/brand/logo-horizontal-dark.svg",alt:"CamStack Admin",className:"h-12"})}),g==="credentials"?u("form",{onSubmit:N,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[f&&o("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:f}),u("div",{className:"space-y-1.5",children:[o("label",{className:"text-xs font-medium text-foreground-subtle",children:"Username"}),o("input",{"data-testid":"login-username",type:"text",placeholder:"Username",value:s,onChange:E=>a(E.target.value),className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all",autoFocus:!0})]}),u("div",{className:"space-y-1.5",children:[o("label",{className:"text-xs font-medium text-foreground-subtle",children:"Password"}),u("div",{className:"relative",children:[o("input",{"data-testid":"login-password",type:c?"text":"password",placeholder:"Password",value:i,onChange:E=>l(E.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"}),o("button",{type:"button",onClick:()=>d(!c),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground transition-colors",tabIndex:-1,children:c?o(n0,{className:"h-4 w-4"}):o(Go,{className:"h-4 w-4"})})]})]}),o("button",{"data-testid":"login-submit",type:"submit",disabled:h||!s||!i,className:"w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all",children:h?u("span",{className:"flex items-center justify-center gap-2",children:[o("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary-foreground/30 border-t-primary-foreground"}),"Logging in..."]}):"Log in"})]}):u("form",{onSubmit:k,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[u("div",{className:"flex items-center gap-2 pb-1 border-b border-border",children:[o(Er,{className:"h-4 w-4 text-primary"}),o("div",{className:"text-sm font-medium text-foreground",children:"Two-factor authentication"})]}),u("p",{className:"text-xs text-foreground-subtle",children:["Enter the 6-digit code from your authenticator app to finish signing in as"," ",o("span",{className:"font-mono text-foreground",children:s}),"."]}),f&&o("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:f}),u("div",{className:"space-y-1.5",children:[o("label",{className:"text-xs font-medium text-foreground-subtle",children:"Authentication code"}),o("input",{"data-testid":"login-totp",type:"text",inputMode:"numeric",autoComplete:"one-time-code",placeholder:"123456",value:w,onChange:E=>v(E.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full rounded-lg border border-border bg-background px-3 py-3 text-center text-2xl font-mono tracking-widest text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all",autoFocus:!0})]}),o("button",{"data-testid":"login-totp-submit",type:"submit",disabled:h||w.length!==6,className:"w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all",children:h?u("span",{className:"flex items-center justify-center gap-2",children:[o("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary-foreground/30 border-t-primary-foreground"}),"Verifying..."]}):"Verify and sign in"}),u("button",{type:"button",onClick:C,className:"w-full flex items-center justify-center gap-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors",children:[o(Md,{className:"h-3 w-3"}),"Back to username + password"]})]}),g==="credentials"&&o($8,{}),o("p",{className:"mt-6 text-center text-[10px] text-foreground-subtle/50",children:"CamStack v0.1.0"})]})})}function $8(){const t=(Vc().data??[]).filter(n=>n.enabled&&n.hasRedirectFlow);return t.length===0?null:u("div",{className:"mt-6 space-y-3",children:[u("div",{className:"flex items-center gap-3",children:[o("div",{className:"h-px flex-1 bg-border"}),o("span",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:"Or continue with"}),o("div",{className:"h-px flex-1 bg-border"})]}),o("div",{className:"space-y-2",children:t.map(n=>{const r=n.instanceId?`/addon/${encodeURIComponent(n.addonId)}/${encodeURIComponent(n.instanceId)}/start`:`/addon/${encodeURIComponent(n.addonId)}/start`,s=n.instanceId?`${n.addonId}#${n.instanceId}`:n.addonId;return u("a",{href:r,className:"flex items-center justify-center gap-2 w-full rounded-lg border border-border bg-surface px-4 py-2.5 text-sm font-medium text-foreground hover:bg-surface-hover transition-colors",children:[o(dn,{className:"h-4 w-4 text-primary"}),n.displayName]},s)})})]})}const Fp=8;function D8(){const{user:e,mustChangePassword:t,clearMustChangePassword:n,logout:r}=mn(),s=Or(),a=et(),[i,l]=P(""),[c,d]=P(""),[f,p]=P(!1),[h,m]=P(""),g=rd({onSuccess:()=>{n(),a("/dashboard",{replace:!0})},onError:x=>{m(x instanceof Error?x.message:"Could not change password")}}),b=async x=>{if(x.preventDefault(),m(""),!e){m("Not signed in");return}if(i.length<Fp){m(`Password must be at least ${Fp} characters`);return}if(i!==c){m("The two passwords do not match");return}if(i==="changeme"){m("Choose a password different from the seed default");return}g.mutate({id:e.id,newPassword:i})};return o("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:u("div",{className:"w-full max-w-sm",children:[o("div",{className:"flex justify-center mb-8",children:o("img",{src:s?.resolvedMode==="light"?"/brand/logo-horizontal-light.svg":"/brand/logo-horizontal-dark.svg",alt:"CamStack Admin",className:"h-12"})}),u("form",{onSubmit:b,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[u("div",{className:"space-y-1",children:[o("h1",{className:"text-sm font-semibold text-foreground",children:"Set a new password"}),o("p",{className:"text-xs text-foreground-subtle",children:t?"You must rotate the seed password before continuing.":"Choose a new password for your account."})]}),h&&o("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:h}),u("div",{className:"space-y-1.5",children:[o("label",{className:"text-xs font-medium text-foreground-subtle",children:"New password"}),u("div",{className:"relative",children:[o("input",{"data-testid":"change-password-new",type:f?"text":"password",value:i,onChange:x=>l(x.target.value),className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all",autoFocus:!0}),o("button",{type:"button",onClick:()=>p(!f),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground transition-colors",tabIndex:-1,children:f?o(n0,{className:"h-4 w-4"}):o(Go,{className:"h-4 w-4"})})]})]}),u("div",{className:"space-y-1.5",children:[o("label",{className:"text-xs font-medium text-foreground-subtle",children:"Confirm new password"}),o("input",{"data-testid":"change-password-confirm",type:f?"text":"password",value:c,onChange:x=>d(x.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"})]}),o("button",{"data-testid":"change-password-submit",type:"submit",disabled:g.isPending||!i||!c,className:"w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all",children:g.isPending?"Saving…":"Save and continue"}),t&&o("button",{type:"button",onClick:()=>{r(),a("/login",{replace:!0})},className:"w-full text-xs text-foreground-subtle hover:text-foreground transition-colors",children:"Sign out instead"})]})]})})}function T8(){const e=et();return u("div",{className:"flex min-h-screen flex-col items-center justify-center bg-background text-foreground p-4",children:[o("div",{className:"flex h-16 w-16 items-center justify-center rounded-2xl bg-danger/10 mb-4",children:o(y6,{className:"h-8 w-8 text-danger"})}),o("h1",{className:"text-xl font-bold",children:"Access Denied"}),o("p",{className:"mt-2 text-sm text-foreground-subtle",children:"You don't have permission to access this page."}),o("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 _0="camstack:dashboard-layout",Li={version:1,widgets:[]};function L8(){try{const e=localStorage.getItem(_0);if(!e)return Li;const t=JSON.parse(e);return t&&t.version===1&&Array.isArray(t.widgets)?{version:1,widgets:t.widgets}:Li}catch{return Li}}function R8(e){try{localStorage.setItem(_0,JSON.stringify(e))}catch{}}function O8(){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 B8(){const[e,t]=P(L8),[n,r]=P(!1),s=uy(),a=q(()=>s.filter(d=>d.hosts.includes("dashboard")),[s]),i=U(d=>{t(d),R8(d)},[]),l=U(d=>{i({version:1,widgets:[...e.widgets,d]})},[e,i]),c=U(d=>{i({version:1,widgets:e.widgets.filter(f=>f.instanceId!==d)})},[e,i]);return u("div",{className:"p-4",children:[u("div",{className:"flex items-center justify-between mb-4",children:[o("h1",{className:"text-lg font-semibold text-foreground",children:"Dashboard"}),u("button",{onClick:()=>r(!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:[o(ot,{className:"h-3.5 w-3.5"}),"Add widget"]})]}),e.widgets.length===0?o(z8,{onAdd:()=>r(!0)}):o("div",{className:"grid grid-cols-12 gap-3 auto-rows-[minmax(80px,_auto)]",children:e.widgets.map(d=>o(F8,{entry:d,onRemove:()=>c(d.instanceId)},d.instanceId))}),n&&o(H8,{widgets:a,onClose:()=>r(!1),onAdd:d=>{l(d),r(!1)}})]})}function z8({onAdd:e}){return u("div",{className:"flex flex-col items-center justify-center py-24 text-foreground-subtle",children:[o("div",{className:"flex h-16 w-16 items-center justify-center rounded-2xl bg-surface border border-border mb-4",children:o(s0,{className:"h-8 w-8 text-foreground-subtle/40"})}),o("p",{className:"text-sm font-medium text-foreground/70",children:"Your dashboard is empty"}),o("p",{className:"text-xs text-foreground-subtle mt-1 mb-4",children:"Add widgets to monitor your cameras and system"}),u("button",{onClick:e,className:"flex items-center gap-1.5 rounded-lg bg-primary px-4 py-2 text-xs font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg transition-all",children:[o(ot,{className:"h-3.5 w-3.5"}),"Add your first widget"]})]})}function F8({entry:e,onRemove:t}){const n=j8(e.columns),r=Math.max(1,Math.min(12,e.rows));return u("div",{className:"relative group rounded-lg border border-border bg-surface overflow-hidden flex flex-col",style:{gridColumn:`span ${n} / span ${n}`,gridRow:`span ${r} / span ${r}`},children:[o("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:o(Fe,{className:"h-3 w-3"})}),o("div",{className:"flex-1 min-h-0 overflow-auto p-2",children:o(lt,{widgetId:e.widgetId,host:"dashboard",instanceId:e.instanceId,config:e.config,deviceId:e.deviceId,size:e.size,columns:e.columns,rows:e.rows})})]})}function j8(e){return!Number.isFinite(e)||e<1?6:Math.min(12,Math.floor(e))}function H8({widgets:e,onClose:t,onAdd:n}){const[r,s]=P(null);return o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:t,children:u("div",{className:"w-full max-w-2xl rounded-xl border border-border bg-surface p-5 shadow-2xl shadow-black/20",onClick:a=>a.stopPropagation(),children:[u("div",{className:"flex items-center justify-between mb-4",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:r?`Configure: ${r.label}`:"Add widget"}),o("button",{onClick:t,className:"p-1 rounded-md hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors",children:o(Fe,{className:"h-4 w-4"})})]}),r===null?o(V8,{widgets:e,onSelect:s}):o(q8,{widget:r,onCancel:()=>s(null),onAdd:n})]})})}function V8({widgets:e,onSelect:t}){return e.length===0?o("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."}):o("div",{className:"grid grid-cols-2 gap-2 max-h-96 overflow-auto",children:e.map(n=>u("button",{onClick:()=>t(n),className:"flex flex-col rounded-lg border border-border p-3 text-left hover:bg-surface-hover hover:border-primary/30 transition-all group",children:[o("span",{className:"text-xs font-medium text-foreground block",children:n.label}),o("span",{className:"text-[10px] text-foreground-subtle truncate",title:n.widgetId,children:n.widgetId}),n.description&&o("span",{className:"text-[10px] text-foreground-subtle mt-1 line-clamp-2",children:n.description})]},n.widgetId))})}function q8({widget:e,onCancel:t,onAdd:n}){const[r,s]=P(e.defaultSize),[a,i]=P(e.defaultColumns),[l,c]=P(e.defaultRows),[d,f]=P(null),{data:p}=$n({},{enabled:e.requires.deviceContext,staleTime:3e4}),h=!e.requires.deviceContext||d!==null&&d>0,m=()=>{if(!h)return;const g={instanceId:O8(),widgetId:e.widgetId,size:r,columns:a,rows:l,...e.requires.deviceContext&&d!==null?{deviceId:d}:{}};n(g)};return u("div",{className:"space-y-3",children:[u("div",{children:[o("label",{className:"block text-[11px] font-medium text-foreground-subtle mb-1",children:"Size"}),o("div",{className:"flex items-center gap-1",children:e.allowedSizes.map(g=>o("button",{onClick:()=>s(g),className:`px-3 py-1 rounded-md text-[11px] font-medium border transition-colors ${r===g?"bg-primary/10 text-primary border-primary/30":"border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground"}`,children:g.toUpperCase()},g))})]}),u("div",{className:"grid grid-cols-2 gap-3",children:[o(jp,{label:"Columns (1-12)",value:a,min:1,max:12,onChange:i}),o(jp,{label:"Rows (1-12)",value:l,min:1,max:12,onChange:c})]}),e.requires.deviceContext&&u("div",{children:[o("label",{className:"block text-[11px] font-medium text-foreground-subtle mb-1",children:"Device"}),u("select",{value:d??"",onChange:g=>f(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:[o("option",{value:"",children:"— select a device —"}),(p??[]).map(g=>u("option",{value:g.id,children:[g.name??g.stableId," (#",g.id,")"]},g.id))]})]}),u("div",{className:"flex items-center justify-end gap-2 pt-2 border-t border-border",children:[o("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"}),o("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 jp({label:e,value:t,min:n,max:r,onChange:s}){return u("div",{children:[o("label",{className:"block text-[11px] font-medium text-foreground-subtle mb-1",children:e}),o("input",{type:"number",min:n,max:r,value:t,onChange:a=>{const i=Number(a.target.value);Number.isFinite(i)&&s(Math.max(n,Math.min(r,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 U8(){return o(B8,{})}function Xe({icon:e,title:t,subtitle:n,actions:r,children:s}){const a=!!t||n!=null||r!=null;return u("div",{className:"p-4 space-y-4",children:[a&&u("div",{className:"flex items-center justify-between gap-4",children:[u("div",{className:"min-w-0",children:[t&&u("h1",{className:"text-lg font-semibold text-foreground flex items-center gap-2",children:[e&&o(e,{className:"h-4 w-4 text-foreground-subtle"}),t]}),n&&o("p",{className:"text-xs text-foreground-subtle mt-0.5",children:n})]}),r&&o("div",{className:"shrink-0 flex items-center gap-2",children:r})]}),s]})}const Hp=["camera","hub","nvr","light","siren","switch","sensor","thermostat","button","generic"];function Q8(){const{t:e}=zt(),t=et(),n=Le();vt(["deviceManager"],["device.registered","device.unregistered","device.online","device.offline","device.disabled","device.enabled"]),vt(["integrations"],["integration.enabled","integration.disabled","integration.deleted","provider.started","provider.stopped","addon.installed","addon.uninstalled","addon.started","addon.stopped"]);const{data:r}=$n({},{staleTime:3e4}),{data:s}=Wc(void 0,{staleTime:3e4}),a=q(()=>r??[],[r]),{activeDevices:i,orphanDevices:l}=q(()=>{const m=new Set((s??[]).map(k=>k.addonId)),g=k=>typeof k.addonId=="string"&&k.addonId.length>0&&!m.has(k.addonId),b=new Set;for(const k of a)g(k)&&b.add(k.id);const x=new Set(b),y=new Map;for(const k of a)y.set(k.id,k);const w=(k,C=0)=>{if(C>32)return!1;if(b.has(k.id))return!0;if(k.parentDeviceId==null)return!1;const E=y.get(k.parentDeviceId);return E?w(E,C+1):!1};for(const k of a)w(k)&&x.add(k.id);const v=[],N=[];for(const k of a)x.has(k.id)?N.push(k):v.push(k);return{activeDevices:v,orphanDevices:N}},[a,s]),c=q(()=>{const m=new Map;for(const g of a)m.set(g.id,{id:g.id,name:g.name??g.stableId??`#${String(g.id)}`});return m},[a]),d=U(m=>c.get(m)??null,[c]),f=q(()=>(s??[]).map(m=>({id:m.addonId,name:m.name??m.addonId,icon:o(un,{type:m.addonId,size:"sm"})})),[s]),p=U(m=>o(un,{type:m,size:"sm"}),[]),h=U(m=>t(`/devices/${String(m)}`),[t]);return u(Xe,{icon:Cr,title:e("nav.devices","Devices"),children:[o(yo,{devices:i,trpc:n.trpcClient,filters:{types:Hp,addons:f},resolveIntegrationIcon:p,resolveParent:d,onNavigate:h}),l.length>0&&u("div",{className:"mt-6 space-y-2",children:[u("div",{className:"flex items-baseline gap-2",children:[o(ut,{className:"h-3.5 w-3.5 text-warning shrink-0"}),o("h2",{className:"text-sm font-semibold text-foreground",children:"Orphan devices"}),u("span",{className:"text-[10px] text-foreground-subtle",children:[l.length," device",l.length===1?"":"s"," pointing at integrations no longer registered"]})]}),u("div",{className:"rounded-lg border border-warning/30 bg-warning/5 p-2",children:[o("p",{className:"text-[11px] text-foreground-subtle px-2 pb-2",children:"These devices reference an addonId that has no matching integration. Delete them, or re-install the missing integration to bring them back online. The provider scope (`addonId`) shown beside each row is what's failing to resolve."}),o(yo,{devices:l,trpc:n.trpcClient,filters:{types:Hp,addons:f},urlScope:"nested",lsKey:"devices:orphan",resolveIntegrationIcon:p,resolveParent:d,onNavigate:h})]})]})]})}function G8({onSelect:e,onClose:t,pendingAddonId:n=null}){const{t:r}=zt(),s=et(),{data:a,isLoading:i}=Pb();if(i)return o("div",{className:"space-y-2 p-2",children:[1,2,3].map(c=>o("div",{className:"h-14 rounded-lg bg-surface animate-pulse"},c))});const l=n!==null;return u("div",{className:"space-y-2",children:[(a??[]).map(c=>{const d=c.instanceMode==="unique"&&c.existingInstances.length>0,f=n===c.addonId,p=l;return u("button",{disabled:p,onClick:()=>{if(!p)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?o("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0",style:{backgroundColor:`${c.color}15`},children:o("img",{src:c.iconUrl,alt:"",className:"h-5 w-5"})}):o("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0",style:{backgroundColor:`${c.color}15`},children:o("span",{className:"text-sm",style:{color:c.color},children:"◉"})}),u("div",{className:"flex-1 min-w-0",children:[o("p",{className:"text-xs font-semibold text-foreground",children:c.name}),c.description&&o("p",{className:"text-[10px] text-foreground-subtle mt-0.5 truncate",children:c.description})]}),f?o(Ee,{className:"h-4 w-4 animate-spin text-primary flex-shrink-0"}):d?u("span",{className:"flex items-center gap-1 text-[10px] font-medium text-foreground-subtle",children:[o(Yt,{className:"h-3 w-3"}),r("integrations.manage")]}):o(Et,{className:"h-4 w-4 text-foreground-subtle flex-shrink-0"})]},c.addonId)}),(a??[]).length===0&&o("div",{className:"py-8 text-center text-xs text-foreground-subtle",children:r("integrations.noProviders")})]})}function K8(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function Vp(e,t){if(e!==void 0)return t&&K8(e)?t(e):e}function W8({section:e,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a,probeResults:i,onAction:l}){const[c,d]=P(e.defaultCollapsed??!1),f=e.style==="accordion";if(e.fields.reduce((b,x)=>b+(od(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 u("div",{className:"@container rounded-lg border border-border bg-surface p-3",style:{containerType:"inline-size"},children:[!g&&u("div",{className:["flex items-center justify-between mb-2",f?"cursor-pointer":""].join(" "),onClick:f?()=>d(b=>!b):void 0,children:[u("div",{children:[e.title&&o("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:Vp(e.title,s)}),e.description&&o("p",{className:"text-[10px] text-foreground-subtle mt-0.5",children:Vp(e.description,s)})]}),f&&o("span",{className:"text-foreground-subtle text-xs ml-2",children:c?"▸":"▾"})]}),!c&&o("div",{className:`grid ${m} gap-x-3 gap-y-2.5`,children:e.fields.map(b=>o(lr,{field:b,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a,externalProbe:i?.[b.key],allFields:e.fields,onAction:l},b.key))})]})}function En({schema:e,values:t,onChange:n,disabled:r,translationFn:s,onTestField:a,probeResults:i,onClearProbe:l,onAction:c}){const d=(f,p)=>{n({...t,[f]:p}),l?.(f)};return o("div",{className:"space-y-4",children:e.sections.map((f,p)=>o(W8,{section:f,values:t,onChange:d,disabled:r,translationFn:s,onTestField:a,probeResults:i,onAction:c},`${f.id}-${p}`))})}function Y8({addonId:e,configSchema:t,onSave:n,onBack:r}){const{t:s}=zt(),[a,i]=P(""),[l,c]=P({}),[d,f]=P(null),p=_b({onSuccess:h=>f(h),onError:h=>f({success:!1,error:String(h)})});return u("div",{className:"space-y-4",children:[u("div",{children:[o("label",{className:"block text-[11px] font-medium text-foreground mb-1",children:s("integrations.integrationName")}),o("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&&o(En,{schema:t,values:l,onChange:c}),d&&o("div",{className:`rounded-lg border px-3 py-2 text-xs ${d.success?"border-success/30 bg-success/5 text-success":"border-danger/30 bg-danger/5 text-danger"}`,children:d.success?s("integrations.connectionSuccess"):`${s("integrations.errorPrefix")} ${d.error}`}),u("div",{className:"flex items-center justify-between pt-2",children:[o("button",{onClick:r,className:"rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors",children:s("integrations.back")}),u("div",{className:"flex items-center gap-2",children:[o("button",{onClick:()=>p.mutate({addonId:e,settings:l}),disabled:p.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:p.isPending?s("integrations.testing"):s("integrations.testConnection")}),o("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 Z8({providerId:e,onImport:t,onSkip:n}){const{t:r}=zt(),[s,a]=P(new Set),i=Gc(),l=i.data,c=i.isPending||!i.data&&!i.isError;Y(()=>{e&&(i.isPending||i.data||i.mutate({addonId:e}))},[e,i]);function d(p){a(h=>{const m=new Set(h);return m.has(p)?m.delete(p):m.add(p),m})}if(c)return u("div",{className:"flex flex-col items-center py-12",children:[o("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent"}),o("p",{className:"mt-3 text-xs text-foreground-subtle",children:r("integrations.searchingDevices")})]});const f=l??[];return u("div",{className:"space-y-4",children:[o("p",{className:"text-xs text-foreground-subtle",children:f.length>0?r("integrations.foundDevices",{count:f.length}):r("integrations.noDevicesFound")}),f.length>0&&o("div",{className:"space-y-1.5 max-h-64 overflow-y-auto",children:f.map(p=>{const h=p.stableId,m=p.suggestedName??h,g=s.has(h);return u("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:[o("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&&o(Mt,{className:"h-3 w-3 text-primary-foreground"})}),o(Cr,{className:"h-3.5 w-3.5 text-foreground-subtle flex-shrink-0"}),o("span",{className:"text-xs font-medium text-foreground truncate",children:m})]},h)})}),u("div",{className:"flex items-center justify-between pt-2",children:[o("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:r("integrations.skip")}),f.length>0&&u("button",{onClick:()=>t(Array.from(s)),disabled:s.size===0,className:"rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50",children:[r("integrations.importSelected")," (",s.size,")"]})]})]})}function X8(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 r=n,{value:s,...a}=r;return a};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(n=>({...n,fields:n.fields.map(t)}))}}function J8({open:e,onClose:t}){const{t:n}=zt(),r=et(),s=ke(),[a,i]=P("picker"),[l,c]=P(null),[d,f]=P(null),[p,h]=P("manual"),{data:m}=Hc({addonId:l??"",nodeId:"hub"},{enabled:l!=null}),g=q(()=>m?X8(m):null,[m]),b=Eb({onSuccess:()=>s.invalidateQueries({queryKey:[["integrations"]]})}),x=Gc(),y=x.data;Y(()=>{a!=="discovery"||!d||!l||x.isPending||x.data||x.mutate({addonId:l})},[a,d,l,x]);const w=Nb({onSuccess:()=>s.invalidateQueries({queryKey:[["deviceManager"]]})});async function v(R,M,T,_){if(!b.isPending){if(c(R),h(T),M==="unique"){try{const L=await b.mutateAsync({addonId:R,name:_,settings:{}});t(),E(),r(`/integrations/${L.id}`)}catch{}return}i("config")}}async function N(R){if(l)try{const M=await b.mutateAsync({addonId:l,name:R.name,settings:R.config});f(M.id),p==="auto"||p==="both"?i("discovery"):C(M.id)}catch{}}async function k(R){if(l){for(const M of R){const T=y?.find(_=>_.stableId===M);T&&await w.mutateAsync({addonId:l,candidate:T})}C()}}function C(R){const M=R??d??l;t(),E(),M&&r(`/integrations/${M}`)}function E(){i("picker"),c(null),f(null),h("manual")}function A(){t(),E()}if(!e)return null;const I={picker:n("integrations.newIntegration"),config:n("integrations.configureIntegration"),discovery:n("integrations.importDevices")},z=b.isPending,$=z?l:null,B=b.error;return u("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[o("div",{className:"absolute inset-0 bg-black/60",onClick:z?void 0:A}),u("div",{className:"relative z-10 w-full max-w-lg rounded-xl border border-border bg-background shadow-2xl",children:[u("div",{className:"flex items-center justify-between border-b border-border px-5 py-4",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:I[a]}),o("button",{onClick:A,disabled:z,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:o(Fe,{className:"h-4 w-4"})})]}),u("div",{className:"relative px-5 py-4",children:[B&&!z&&o("div",{className:"mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:B instanceof Error?B.message:String(B)}),a==="picker"&&o(G8,{onSelect:v,onClose:A,pendingAddonId:$}),a==="config"&&l&&o(Y8,{addonId:l,configSchema:g??null,onSave:N,onBack:()=>i("picker")}),a==="discovery"&&d&&o(Z8,{providerId:d,onImport:k,onSkip:C}),z&&u("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background/85 backdrop-blur-sm",children:[o(Ee,{className:"h-6 w-6 animate-spin text-primary"}),o("p",{className:"text-xs font-medium text-foreground",children:n("integrations.creating",{defaultValue:"Creating integration…"})}),o("p",{className:"text-[10px] text-foreground-subtle",children:n("integrations.creatingHint",{defaultValue:"Waiting for the addon to restart and register"})})]})]})]})]})}const qp={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 Ha({status:e}){const t=qp[e]??qp.stopped;return u("span",{className:`inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-[10px] font-medium ${t.bg} ${t.text}`,children:[o("span",{className:`h-1.5 w-1.5 rounded-full ${t.dot}`}),t.label]})}const Ri="px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle";function e9({integrations:e,expandedAddonId:t,onToggleExpand:n,onOpenSettings:r,renderExpanded:s}){const a=U(i=>n(i),[n]);return o("div",{className:"overflow-hidden rounded-lg border border-border bg-surface",children:u("table",{className:"w-full table-fixed text-xs",children:[o("thead",{className:"bg-surface-hover/40",children:u("tr",{children:[o("th",{className:W(Ri,"w-[60%]"),children:"Integration"}),o("th",{className:W(Ri,"w-[15%]"),children:"Devices"}),o("th",{className:W(Ri,"w-[25%]"),children:"Status"})]})}),o("tbody",{children:e.map(i=>{const l=t===i.addonId;return o(t9,{integration:i,isExpanded:l,onClick:a,onOpenSettings:r,renderExpanded:s},i.id)})})]})})}function t9({integration:e,isExpanded:t,onClick:n,onOpenSettings:r,renderExpanded:s}){const a=U(c=>{c.stopPropagation(),r(e.id)},[e.id,r]),i=U(()=>{n(e.addonId)},[e.addonId,n]),l=U(c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),i())},[i]);return u(me,{children:[u("tr",{role:"button",tabIndex:0,"aria-expanded":t,className:W("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:[o("td",{className:"px-3 py-2.5",children:u("div",{className:"flex items-center gap-2.5",children:[t?o(Nt,{className:"h-3.5 w-3.5 flex-shrink-0 text-foreground-subtle"}):o(Et,{className:"h-3.5 w-3.5 flex-shrink-0 text-foreground-subtle"}),o(un,{type:e.addonId,size:"sm"}),u("div",{className:"flex min-w-0 flex-col",children:[o("span",{className:"truncate text-xs font-semibold text-foreground",children:e.name}),o("span",{className:"truncate text-[10px] text-foreground-subtle",children:e.addonId})]})]})}),u("td",{className:"px-3 py-2.5 text-[11px] text-foreground-subtle",children:[e.deviceCount," device",e.deviceCount!==1?"s":""]}),o("td",{className:"px-3 py-2.5",children:u("div",{className:"flex items-center justify-between gap-2",children:[o(Ha,{status:e.status}),u("button",{type:"button",onClick:a,className:"flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary",title:"Open integration settings",children:[o(Yt,{className:"h-3 w-3"}),"Settings"]})]})})]}),t&&o("tr",{className:"border-t border-border bg-surface",children:o("td",{colSpan:3,className:"px-3 py-3",children:s(e.addonId)})})]})}function n9(e){if(!e.enabled)return"disabled";switch(e.processState){case"running":return"running";case"stopped":case"crashed":case"unknown":default:return"stopped"}}const bs="expand";function r9(){const{t:e}=zt(),t=et(),n=Le(),[r]=La(),[s,a]=P(!1),i=U(()=>a(!0),[]),l=U(()=>a(!1),[]);vt(["integrations"],["integration.enabled","integration.disabled","integration.deleted","provider.started","provider.stopped","addon.installed","addon.uninstalled","addon.started","addon.stopped","addon.updated"]),vt(["deviceManager"],["device.registered","device.unregistered","device.online","device.offline","device.disabled","device.enabled"]);const{data:c,isLoading:d,refetch:f}=Wc(void 0,{staleTime:3e4}),{data:p,isLoading:h,refetch:m}=$n({},{staleTime:3e4}),g=q(()=>p??[],[p]),b=q(()=>c??[],[c]),x=q(()=>{const R=new Map;for(const M of g)R.set(M.id,{id:M.id,name:M.name??M.stableId??`#${String(M.id)}`});return R},[g]),y=q(()=>{const R=new Map;for(const M of g){if(M.parentDeviceId!==null&&M.parentDeviceId!==void 0&&!!M.role)continue;const _=M.addonId??"";_&&R.set(_,(R.get(_)??0)+1)}return R},[g]),w=q(()=>b.map(R=>({id:R.id,addonId:R.addonId,name:R.name,enabled:R.enabled,status:n9(R),deviceCount:y.get(R.addonId)??0})),[b,y]),v=r.get(bs),N=U(R=>{const M=new URLSearchParams(window.location.search);M.get(bs)===R?M.delete(bs):M.set(bs,R);const _=M.toString(),L=`${window.location.pathname}${_?`?${_}`:""}${window.location.hash}`;window.history.replaceState(window.history.state,"",L),window.dispatchEvent(new PopStateEvent("popstate"))},[]),k=U(R=>t(`/integrations/${R}`),[t]),C=U(R=>x.get(R)??null,[x]),E=U(R=>o(un,{type:R,size:"sm"}),[]),A=U(R=>t(`/devices/${String(R)}`),[t]),I=U(R=>o(yo,{devices:g,trpc:n.trpcClient,forceAddon:R,urlScope:"nested",lsKey:`integrations:nested:${R}`,resolveIntegrationIcon:E,resolveParent:C,onNavigate:A}),[g,n.trpcClient,E,C,A]),z=U(()=>{f(),m()},[f,m]),$=d||h,B=b.length>0;return u(Xe,{icon:wo,title:e("nav.integrations","Integrations"),actions:u(me,{children:[o("button",{onClick:z,disabled:$,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:o(ht,{className:W("h-3.5 w-3.5",$&&"animate-spin")})}),u("button",{onClick:i,className:"flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm",children:[o(ot,{className:"h-3.5 w-3.5"}),"New Integration"]})]}),children:[$&&o("div",{className:"space-y-2",children:[1,2,3].map(R=>o("div",{className:"h-12 rounded-lg border border-border bg-surface animate-pulse"},R))}),!$&&!B&&u("div",{className:"flex flex-col items-center py-20 text-foreground-subtle",children:[o("p",{className:"text-sm",children:"No integrations configured."}),o("p",{className:"text-xs mt-1",children:'Click "New Integration" to connect cameras and devices.'})]}),!$&&B&&o(e9,{integrations:w,expandedAddonId:v,onToggleExpand:N,onOpenSettings:k,renderExpanded:I}),o(J8,{open:s,onClose:l})]})}function $0(e){const t=[];for(const n of e)n.type==="probe"&&t.push(n.key),n.type==="group"&&"fields"in n&&t.push(...$0(n.fields));return t}function o9(e,t,n){const[r,s]=P("idle"),[a,i]=P({}),l=q(()=>{const p=[];for(const h of e.sections)p.push(...$0(h.fields));return p},[e]),c=l.length>0&&n!==void 0,d=U(p=>{i(h=>{if(!h[p])return h;const m={...h};return delete m[p],m})},[]),f=U(async()=>{if(!n)return;const p=l.filter(b=>{const x=t[b];return x!=null&&String(x).trim()!==""});if(p.length===0)return;s("testing");const h={};for(const b of p)h[b]={status:"probing"};i(h);const m=await Promise.allSettled(p.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:r,hasProbeFields:c,probeResults:a,handleTestAll:f,clearProbeResult:d}}function D0(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(...D0(n.fields));return t}function Oi(e){return e==null?!0:typeof e=="string"?e.trim()==="":!1}function Ol(e,t={}){for(const n of e){if(n.type==="group"&&"fields"in n){Ol(n.fields,t);continue}"key"in n&&n.key&&"default"in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Up(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function s9({open:e,integrationId:t,addonId:n,onClose:r}){const{t:s}=zt(),a=ke(),[i,l]=P({}),[c,d]=P(!1),[f,p]=P(null),[h,m]=P(Up),g=kb({addonId:n,type:it.Camera},{enabled:e}),b=g.data??null;Y(()=>{if(e){const M=b?Ol(b.sections.flatMap(T=>T.fields)):{};l(M),m(Up()),d(!1),p(null)}},[e,t,b]);const x=q(()=>({...i,_probeRequestId:h}),[i,h]),y=Sb({onSuccess:()=>{a.invalidateQueries({queryKey:[["deviceManager"]]})}}),w=Kc(),v=U(async(M,T)=>{d(!0);const _=await w.mutateAsync({addonId:n,type:it.Camera,key:M,value:T,formValues:x});return _.status==="ok"&&_.suggestedValues&&l(L=>{let O=!1;const j={...L};for(const[F,H]of Object.entries(_.suggestedValues??{}))Oi(L[F])&&!Oi(H)&&(j[F]=H,O=!0);return O?j:L}),_},[w,n,x]),{testAllStatus:N,hasProbeFields:k,probeResults:C,handleTestAll:E,clearProbeResult:A}=o9(b??{sections:[]},i,v);async function I(M){p(null);try{if(await y.mutateAsync({addonId:n,type:it.Camera,config:i}),M){const T=b?Ol(b.sections.flatMap(_=>_.fields)):{};l(T)}else r()}catch(T){p(T instanceof Error?T.message:String(T))}}if(!e)return null;const $=D0((b?.sections??[]).flatMap(M=>M.fields)).filter(M=>Oi(i[M])),B=$.length===0,R=!g.isLoading&&(g.isError||b===null);return u("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[o("div",{className:"absolute inset-0 bg-black/60",onClick:r}),u("div",{className:"relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl",children:[u("div",{className:"flex items-center justify-between border-b border-border px-5 py-4 shrink-0",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:s("integrations.addDevice")}),o("button",{onClick:r,className:"rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:o(Fe,{className:"h-4 w-4"})})]}),o("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3",children:g.isLoading?o("div",{className:"flex items-center justify-center py-8",children:o(Ee,{className:"h-5 w-5 animate-spin text-primary"})}):R?u("div",{className:"flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3",children:[o(ut,{className:"h-4 w-4 text-destructive mt-0.5 shrink-0"}),u("div",{className:"space-y-1",children:[o("p",{className:"text-xs font-medium text-destructive",children:"Provider unavailable"}),u("p",{className:"text-xs text-foreground-subtle",children:["The addon ",o("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."]})]})]}):o(En,{schema:b,values:i,onChange:l,onTestField:v,probeResults:C,onClearProbe:A})}),!R&&!g.isLoading&&u("div",{className:"border-t border-border bg-surface/50 shrink-0",children:[u("button",{type:"button",onClick:()=>d(M=>!M),className:"flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:[u("span",{className:"flex items-center gap-2",children:[o(rt,{className:"h-3.5 w-3.5"}),"Test logs",o("span",{className:"font-mono text-[9px] opacity-60",children:h.slice(0,14)})]}),o(Nt,{className:`h-3.5 w-3.5 transition-transform ${c?"rotate-180":""}`})]}),c&&o("div",{className:"border-t border-border max-h-64 overflow-hidden",children:o(Xt,{addonId:n,requestId:h,limit:50,maxHeight:"max-h-64",showFilters:!1,showScope:!1,className:"border-0 rounded-none"})})]}),!R&&!g.isLoading&&(f||$.length>0)&&o("div",{className:"border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0",children:u("div",{className:"flex items-start gap-2",children:[o(ut,{className:"h-3.5 w-3.5 text-destructive mt-0.5 shrink-0"}),o("p",{className:"text-[11px] text-destructive",children:f||`Required: ${$.join(", ")}`})]})}),u("div",{className:"flex items-center justify-between border-t border-border px-5 py-3 shrink-0",children:[u("div",{className:"flex items-center gap-2",children:[o("button",{onClick:r,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")}),!R&&k&&u("button",{type:"button",onClick:E,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"?o(Ee,{className:"h-3.5 w-3.5 animate-spin"}):o(Wn,{className:"h-3.5 w-3.5"}),"Test All"]})]}),u("div",{className:"flex items-center gap-2",children:[o("button",{onClick:()=>I(!0),disabled:R||!B||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")}),o("button",{onClick:()=>I(!1),disabled:R||!B||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 a9(){const{t:e}=zt(),{integrationId:t}=yd(),n=ke(),r=et(),s=Le(),[a,i]=P(!1),[l,c]=P(!1),[d,f]=P(!1),[p,h]=P(!1),{data:m,isLoading:g}=Cb({id:t??""},{enabled:!!t}),{data:b}=Hc({addonId:m?.addonId??"",nodeId:"hub"},{enabled:!!m?.addonId}),x=b!=null&&Array.isArray(b.sections)&&b.sections.some(B=>B.fields.length>0),{data:y}=$n({},{refetchInterval:5e3}),w=[["integrations","get"],{input:{id:t??""},type:"query"}],v=Ib({onMutate:async B=>{await n.cancelQueries({queryKey:w});const R=n.getQueryData(w);return R!=null&&n.setQueryData(w,{...R,enabled:B.enabled}),{previous:R}},onError:(B,R,M)=>{const T=M;T?.previous!=null&&n.setQueryData(w,T.previous)},onSettled:()=>{n.invalidateQueries({queryKey:[["integrations"]]}),n.invalidateQueries({queryKey:[["deviceManager"]]})}}),N=Ab({onSuccess:()=>{n.invalidateQueries({queryKey:[["integrations"]]}),n.invalidateQueries({queryKey:[["deviceManager"]]}),f(!1),r("/integrations")}}),k=Ca({onSuccess:()=>{n.invalidateQueries({queryKey:[["integrations"]]}),n.invalidateQueries({queryKey:[["deviceManager"]]})}}),C=q(()=>y??[],[y]),E=q(()=>{const B=new Map;for(const R of C)B.set(R.id,{id:R.id,name:R.name??R.stableId??`#${String(R.id)}`});return B},[C]),A=U(B=>E.get(B)??null,[E]),I=U(B=>o(un,{type:B,size:"sm"}),[]),z=U(B=>r(`/devices/${String(B)}`),[r]),$=q(()=>{const B=m?.addonId;if(!B)return 0;let R=0;for(const M of C)M.addonId!==B||M.parentDeviceId!==null&&M.parentDeviceId!==void 0&&M.role||(R+=1);return R},[C,m?.addonId]);return g?u("div",{className:"p-4",children:[o("div",{className:"h-16 rounded-lg bg-surface animate-pulse mb-4"}),o("div",{className:"h-40 rounded-lg bg-surface animate-pulse"})]}):m?u("div",{className:"p-4 space-y-4",children:[o(Ec,{items:[{label:"Integrations",onClick:()=>r("/integrations")},{label:m.name}]}),u("div",{className:"flex items-center justify-between",children:[u("div",{className:"flex items-center gap-3",children:[o("img",{src:`/api/addon-assets/${m.addonId}/assets/icon.svg`,alt:"",className:"h-8 w-8 rounded-lg",onError:B=>{B.target.style.display="none"}}),u("div",{children:[o("h1",{className:"text-lg font-semibold text-foreground",children:m.name}),u("p",{className:"text-[11px] text-foreground-subtle mt-0.5",children:[m.addonId," · ",$," ",e("integrations.devices")]})]})]}),u("div",{className:"flex items-center gap-3",children:[u("div",{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${v.isPending?"opacity-60":""} ${m.enabled?"border-success/30 bg-success/5":"border-border bg-surface"}`,title:e("integrations.toggleHint",{defaultValue:"Click to toggle"}),children:[o(wc,{checked:m.enabled,onCheckedChange:B=>v.mutate({id:t,enabled:B}),disabled:v.isPending,"aria-label":m.enabled?"Disable integration":"Enable integration"}),o("span",{className:`text-[11px] font-medium ${m.enabled?"text-success":"text-foreground-subtle"}`,children:m.enabled?"Enabled":"Disabled"}),v.isPending&&o(Ee,{className:"h-3 w-3 animate-spin text-foreground-subtle"})]}),x&&u("button",{onClick:()=>c(!0),className:"flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:[o(Yt,{className:"h-3 w-3"}),e("integrations.config")]}),u("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:[o(rt,{className:"h-3 w-3"}),e("integrations.logs",{defaultValue:"Logs"})]}),o(Cy,{label:"Restart",icon:ht,title:`Restart "${m.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${$} active). Streams will reconnect automatically.`,confirmLabel:"Restart",triggerVariant:"outline",confirmVariant:"danger",disabled:k.isPending,action:()=>k.mutateAsync({addonId:m.addonId})}),u("button",{onClick:()=>f(!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:[o(Ke,{className:"h-3 w-3"}),e("integrations.delete",{defaultValue:"Delete"})]})]})]}),o(yo,{devices:C,trpc:s.trpcClient,defaultView:"cards",forceAddon:m.addonId,urlScope:"root",lsKey:`integration-detail:${m.addonId}`,resolveIntegrationIcon:I,resolveParent:A,onNavigate:z}),o("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:o(ot,{className:"h-5 w-5 text-primary-foreground"})}),a&&t&&o(s9,{open:a,integrationId:t,addonId:m.addonId,onClose:()=>i(!1)}),l&&o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>c(!1),children:u("div",{className:"rounded-xl border border-border bg-surface p-6 shadow-xl w-80",onClick:B=>B.stopPropagation(),children:[o("h2",{className:"text-sm font-semibold text-foreground mb-2",children:e("integrations.providerConfig")}),o("p",{className:"text-[11px] text-foreground-subtle",children:e("integrations.configComingSoon")}),o("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"})]})}),p&&o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6",onClick:()=>h(!1),children:u("div",{className:"flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]",onClick:B=>B.stopPropagation(),children:[u("div",{className:"flex items-center justify-between border-b border-border px-4 py-2.5",children:[u("div",{className:"flex items-center gap-2 min-w-0",children:[o(rt,{className:"h-4 w-4 text-primary shrink-0"}),o("h2",{className:"text-sm font-semibold text-foreground truncate",children:m.name}),u("span",{className:"text-[10px] text-foreground-subtle font-mono truncate",children:[m.addonId,t?` · ${t}`:""]})]}),o("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:o(Fe,{className:"h-4 w-4"})})]}),o("div",{className:"flex-1 min-h-0 overflow-hidden",children:o(Xt,{addonId:m.addonId,limit:200,maxHeight:"max-h-full",showScope:!1,className:"h-full border-0 rounded-none"})})]})}),d&&o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>!N.isPending&&f(!1),children:u("div",{className:"rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3",onClick:B=>B.stopPropagation(),children:[u("div",{className:"flex items-start gap-3",children:[o("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0",children:o(ut,{className:"h-4 w-4 text-danger"})}),u("div",{className:"min-w-0",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:e("integrations.deleteTitle",{defaultValue:"Delete integration?"})}),o("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:$})})]})]}),N.error&&o("div",{className:"rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger",children:N.error instanceof Error?N.error.message:String(N.error)}),u("div",{className:"flex items-center justify-end gap-2 pt-1",children:[o("button",{onClick:()=>f(!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"})}),o("button",{onClick:()=>N.mutate({id:t}),disabled:N.isPending,className:"inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed",children:N.isPending?u(me,{children:[o(Ee,{className:"h-3 w-3 animate-spin"}),e("integrations.deleting",{defaultValue:"Deleting…"})]}):u(me,{children:[o(Ke,{className:"h-3 w-3"}),e("integrations.confirmDelete",{defaultValue:"Delete integration"})]})})]})]})})]}):u("div",{className:"flex flex-col items-center justify-center py-20 px-6 text-center gap-4",children:[o("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10",children:o(u6,{className:"h-6 w-6 text-foreground-subtle"})}),u("div",{className:"space-y-1 max-w-sm",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:e("integrations.integrationNotFound",{defaultValue:"Integration not found"})}),o("p",{className:"text-[11px] text-foreground-subtle",children:e("integrations.integrationNotFoundHint",{defaultValue:'The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.',id:t??""})})]}),u("button",{onClick:()=>r("/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:[o(Md,{className:"h-3 w-3"}),e("integrations.backToList",{defaultValue:"Back to integrations"})]})]})}function i9({label:e,color:t,title:n,style:r}){return u("div",{className:"absolute top-1/2 -translate-y-1/2 -translate-x-1/2 z-10 group cursor-pointer",style:r,title:n,children:[o("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&&o("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-1.5 hidden group-hover:block z-20 pointer-events-none",children:u("div",{className:"bg-surface border border-border rounded px-2 py-1 text-[10px] text-foreground whitespace-nowrap shadow-lg",children:[o("span",{className:"inline-block h-1.5 w-1.5 rounded-full mr-1 align-middle",style:{backgroundColor:t}}),e]})})]})}const Bi=36e5;function l9(e){return String(e).padStart(2,"0")}function c9(e){const t=new Date(e);return`${l9(t.getHours())}:00`}function d9({startMs:e,endMs:t,segments:n,events:r,playheadMs:s,onSeek:a}){const i=ne(null),l=t-e,c=U(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 f=[],p=Math.floor(e/Bi),h=Math.ceil(t/Bi);for(let m=p;m<=h;m++){const g=m*Bi;g<e||g>t||f.push({percent:c(g),label:c9(g)})}return u("div",{className:"select-none",children:[o("div",{className:"relative h-5 mb-1",children:f.map(({percent:m,label:g})=>o("span",{className:"absolute -translate-x-1/2 text-[10px] text-foreground-subtle",style:{left:`${m}%`},children:g},g))}),u("div",{ref:i,className:"relative h-8 rounded bg-surface-hover cursor-pointer overflow-hidden border border-border",onClick:d,onPointerMove:m=>{m.buttons===1&&d(m)},children:[n.map((m,g)=>{const b=c(m.startMs),x=c(m.endMs)-b;return o("div",{className:"absolute top-1 bottom-1 rounded-sm bg-success/60",style:{left:`${b}%`,width:`${Math.max(x,.1)}%`}},g)}),r.map(m=>o(i9,{label:m.label,color:m.color,title:`${m.label} — ${new Date(m.timestampMs).toLocaleTimeString()}`,style:{left:`${c(m.timestampMs)}%`}},m.id)),o("div",{className:"absolute top-0 bottom-0 w-0.5 bg-danger z-20 pointer-events-none",style:{left:`${c(s)}%`},children:o("div",{className:"absolute -top-0.5 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-danger rotate-45"})})]})]})}const Qp={person:"#f59e0b",vehicle:"#3b82f6",car:"#3b82f6",face:"#a855f7",plate:"#ec4899",animal:"#10b981",motion:"#ef4444",unknown:"#6b7280"};function Bl(e){return Qp[e.toLowerCase()]??Qp.unknown}function u9(e){const t=new Date(e);return t.setHours(0,0,0,0),t.getTime()}function p9(e){return new Date(e).toISOString().slice(0,10)}function f9(e){return new Date(e+"T00:00:00").getTime()}function h9(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 m9(e){const t=["person","vehicle","face","motion"];return Array.from({length:24},(n,r)=>({id:`placeholder-${r}`,timestampMs:e+Math.floor(Math.random()*24*36e5),label:t[r%t.length],color:Bl(t[r%t.length])})).sort((n,r)=>n.timestampMs-r.timestampMs)}function g9(){const{t:e}=zt(),t=u9(new Date),[n,r]=P(t),[s,a]=P(null),[i,l]=P(t+12*36e5),c=n,d=n+24*36e5,{data:f,isLoading:p}=$n({},{staleTime:3e4}),h=f??[],m=q(()=>h.filter(N=>{const k=N.type.toLowerCase();return k==="camera"||k.includes("camera")||N.features.some(C=>C.toLowerCase().includes("video")||C.toLowerCase().includes("stream"))}).map(N=>({id:N.id,name:N.name??N.stableId})),[h]),g=s??m[0]?.id??null,{data:b}=tr({queryKey:["events",g,c],queryFn:()=>Promise.resolve(null),enabled:!!g,staleTime:6e4}),x=q(()=>{const v=Array.isArray(b)?b:(()=>{const k=pu(b)?.events;return Array.isArray(k)?k:[]})();return v.length===0?g?m9(c):[]:v.flatMap((N,k)=>{const C=pu(N);if(!C)return[];const E=String(C.class??C.type??C.label??"unknown").toLowerCase(),A=typeof C.timestamp=="number"?C.timestamp:c;return[{id:String(C.id??k),timestampMs:A,label:E,color:Bl(E)}]})},[b,g,c]),y=q(()=>g?h9(c):[],[g,c]);function w(v){r(N=>N+v*24*36e5),l(N=>N+v*24*36e5)}return u("div",{className:"flex flex-col h-full p-4 gap-4 overflow-hidden",children:[u("div",{className:"flex items-center justify-between gap-4 shrink-0",children:[o("h1",{className:"text-lg font-semibold text-foreground",children:e("nav.timeline","Timeline")}),u("div",{className:"flex items-center gap-2",children:[o("button",{onClick:()=>w(-1),className:"p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors",children:o(Ed,{className:"h-4 w-4"})}),u("div",{className:"relative flex items-center",children:[o(Yy,{className:"absolute left-2 h-3.5 w-3.5 text-foreground-subtle pointer-events-none"}),o("input",{type:"date",value:p9(n),onChange:v=>{if(v.target.value){const N=f9(v.target.value);r(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"})]}),o("button",{onClick:()=>w(1),className:"p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors",disabled:n>=t,children:o(Et,{className:"h-4 w-4"})})]})]}),u("div",{className:"flex gap-1.5 shrink-0 overflow-x-auto pb-1",children:[p&&o("div",{className:"h-8 w-48 rounded-lg bg-surface animate-pulse"}),!p&&m.length===0&&o("span",{className:"text-xs text-foreground-subtle",children:"No cameras found"}),m.map(v=>{const N=v.id===g;return o("button",{onClick:()=>a(v.id),className:`shrink-0 rounded-lg px-3 py-1.5 text-[12px] font-medium transition-all border ${N?"bg-primary/12 text-primary border-primary/30":"bg-surface text-foreground-subtle border-border hover:bg-surface-hover hover:text-foreground"}`,children:v.name},v.id)})]}),u("div",{className:"relative w-full aspect-video rounded-xl border border-border bg-black shrink-0 overflow-hidden max-h-[45vh]",children:[u("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 text-foreground-subtle",children:[o(lo,{className:"h-12 w-12 opacity-20"}),o("p",{className:"text-sm opacity-50",children:g?`${m.find(v=>v.id===g)?.name??g} — seek to play`:"Select a camera"})]}),o("div",{className:"absolute top-3 left-3 rounded bg-black/60 px-2 py-1 text-[11px] text-white font-mono",children:new Date(i).toLocaleTimeString()})]}),u("div",{className:"rounded-xl border border-border bg-surface px-4 pt-3 pb-4 shrink-0",children:[u("div",{className:"flex flex-wrap items-center gap-4 mb-3",children:[o("span",{className:"text-[10px] font-semibold text-foreground-subtle uppercase tracking-wider",children:"Timeline"}),u("div",{className:"flex items-center gap-1.5",children:[o("span",{className:"inline-block h-2 w-4 rounded-sm bg-success/60"}),o("span",{className:"text-[10px] text-foreground-subtle",children:"Recording"})]}),Array.from(new Set(x.map(v=>v.label))).slice(0,5).map(v=>u("div",{className:"flex items-center gap-1.5",children:[o("span",{className:"inline-block h-2.5 w-2.5 rounded-full",style:{backgroundColor:Bl(v)}}),o("span",{className:"text-[10px] text-foreground-subtle capitalize",children:v})]},v))]}),g?o(d9,{startMs:c,endMs:d,segments:y,events:x,playheadMs:i,onSeek:l}):o("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 b9({selectedNodeId:e,onSelect:t,refreshToken:n}){const{data:r}=Dn(void 0,{staleTime:3e4}),{data:s}=Ea(void 0,{staleTime:3e4}),a=new Map;for(const d of s??[])a.set(d.agentNodeId,(a.get(d.agentNodeId)??0)+1);const i=r??[],l=i.filter(d=>d.isOnline).length,c=i.filter(d=>!d.isOnline).length;return u("div",{className:"flex flex-col h-full",children:[u("button",{type:"button",onClick:()=>t(po),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===po?"bg-primary/10 text-primary":"text-foreground hover:bg-surface-hover"}`,children:[o(Wt,{className:"h-4 w-4 flex-shrink-0"}),u("div",{className:"min-w-0 flex-1",children:[o("div",{className:"text-xs font-semibold truncate",children:"Cluster"}),o("div",{className:"text-[10px] text-foreground-subtle",children:"Balancer + failover + assignments"})]})]}),o("div",{className:"flex-1 overflow-y-auto",children:i.map(d=>{const f=e===d.id,p=a.get(d.id)??0,h=d.isHub?cn:ft;return u("button",{type:"button",onClick:()=>t(d.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${f?"bg-primary/10 text-primary":"text-foreground hover:bg-surface-hover"}`,children:[o(h,{className:"h-4 w-4 flex-shrink-0"}),u("div",{className:"min-w-0 flex-1",children:[u("div",{className:"flex items-center gap-2",children:[o("span",{className:"text-xs font-semibold truncate",children:d.name}),d.isHub&&o("span",{className:"text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5",children:"hub"}),!d.isOnline&&o("span",{className:"h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0"}),d.isOnline&&o("span",{className:"h-1.5 w-1.5 rounded-full bg-success flex-shrink-0"})]}),u("div",{className:"text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5",children:[u("span",{children:[d.cpuCores," cores"]}),o("span",{children:"•"}),u("span",{children:[Math.round(d.memoryMB/1024)," GB"]}),p>0&&u(me,{children:[o("span",{children:"•"}),u("span",{className:"inline-flex items-center gap-0.5 text-foreground",children:[o(m0,{className:"h-2.5 w-2.5"}),p]})]})]})]})]},d.id)})}),u("div",{className:"px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between",children:[u("span",{children:[l," online"]}),c>0&&u("span",{className:"text-destructive",children:[c," offline"]})]})]})}function x9({nodeId:e,refreshToken:t}){const{data:n}=Dn(void 0,{staleTime:3e4}),r=n?.find(i=>i.id===e),a=Br("pipeline.runner-load-snapshot",i=>i.nodeId===e)?.load??null;return r?u("div",{className:"px-6 py-4 border-b border-border",children:[u("div",{className:"flex items-center gap-2 mb-1",children:[o("h2",{className:"text-base font-semibold text-foreground",children:r.name}),r.isOnline?o("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success",children:"online"}):o("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive",children:"offline"}),r.isHub&&o("span",{className:"text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5",children:"hub"})]}),u("div",{className:"text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap",children:[o("span",{children:r.cpuModel??"CPU"}),o("span",{children:"•"}),u("span",{children:[r.cpuCores," cores"]}),o("span",{children:"•"}),u("span",{children:[Math.round(r.memoryMB/1024)," GB"]}),a&&u(me,{children:[o("span",{children:"•"}),u("span",{children:[a.attachedCameras," cameras (",a.activeCameras," active)"]}),o("span",{children:"•"}),u("span",{children:[a.avgInferenceTimeMs.toFixed(0),"ms avg inference"]}),o("span",{children:"•"}),u("span",{children:["queue ",a.queueDepthTotal]}),a.hardware.hasGpu&&u(me,{children:[o("span",{children:"•"}),o("span",{className:"text-success",children:"GPU"})]})]})]})]}):o("div",{className:"px-6 py-4 border-b border-border",children:u("div",{className:"text-xs text-foreground-subtle",children:["Node not found: ",e]})})}function T0({refreshToken:e,nodeId:t}){const[n,r]=P(new Map),{nodes:s}=zr();pt("pipeline.camera-metrics-snapshot",p=>{const h=p.data;typeof h?.deviceId=="number"&&r(m=>{const g=new Map(m);return g.set(h.deviceId,h),g})});const{data:a}=gx(void 0,{staleTime:5e3}),i=q(()=>{const p=new Map;for(const h of a??[])p.set(h.nodeId,h.deviceCount);return p},[a]),l=q(()=>{const p=new Map,h=Date.now()-3e4;for(const m of n.values()){if(m.timestamp<h)continue;const g=m.nodeId??"hub",b=p.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,p.set(g,b)}return p},[n]),c=q(()=>{const p=new Map;for(const h of s)p.set(h.id,h.shortName);return p},[s]),d=q(()=>{let p=0,h=0,m=0,g=0,b=0;for(const y of l.values())p+=y.attachedCameras,h+=y.activeCameras,m+=y.totalFps,g+=y.totalInferenceWeighted,b+=y.queueDepth;const x=p>0?g/p:0;return{totalAgents:s.length,onlineAgents:s.filter(y=>y.isOnline).length,attachedCameras:p,activeCameras:h,avgInferenceTimeMs:x,queueDepth:b,totalFps:m}},[l,s]);if(t){const p=l.get(t);return u("div",{className:"@container/liveload",children:[o("h3",{className:"text-sm font-semibold text-foreground mb-2",children:"Live load"}),u("div",{className:"grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3",children:[o(Ht,{label:"FPS",value:p?p.totalFps.toFixed(1):"—"}),o(Ht,{label:"Cameras",value:p?`${p.activeCameras}/${p.attachedCameras}`:"—"}),o(Ht,{label:"Avg infer ms",value:p&&p.attachedCameras>0?(p.totalInferenceWeighted/p.attachedCameras).toFixed(0):"—"}),o(Ht,{label:"Queue",value:p?String(p.queueDepth):"—"}),o(Ht,{label:"Audio",value:String(i.get(t)??"—")})]})]})}const f=[...l.entries()].sort(([p],[h])=>p==="hub"?-1:h==="hub"?1:p.localeCompare(h));return u("div",{className:"@container/liveload",children:[o("h3",{className:"text-sm font-semibold text-foreground mb-2",children:"Live load"}),u("div",{className:"grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3",children:[o(Ht,{label:"Total agents",value:`${d.onlineAgents}/${d.totalAgents}`}),o(Ht,{label:"Cameras",value:`${d.activeCameras}/${d.attachedCameras}`}),o(Ht,{label:"Total FPS",value:d.totalFps.toFixed(1)}),o(Ht,{label:"Avg inference ms",value:d.avgInferenceTimeMs.toFixed(0)}),o(Ht,{label:"Queue depth",value:String(d.queueDepth)})]}),o("div",{className:"rounded-lg border border-border overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[480px]",children:[o("thead",{className:"bg-surface",children:u("tr",{className:"text-foreground-subtle text-[10px] uppercase tracking-wider",children:[o("th",{className:"text-left px-3 py-2",children:"Agent"}),o("th",{className:"text-right px-3 py-2",children:"FPS"}),o("th",{className:"text-right px-3 py-2",children:"Cameras"}),o("th",{className:"text-right px-3 py-2",children:"Inference ms"}),o("th",{className:"text-right px-3 py-2",children:"Queue"}),o("th",{className:"text-right px-3 py-2",children:"Audio"})]})}),u("tbody",{children:[f.map(([p,h])=>u("tr",{className:"border-t border-border",children:[o("td",{className:"px-3 py-2 text-foreground font-medium",children:c.get(p)??p}),o("td",{className:"px-3 py-2 text-right text-foreground",children:h.totalFps.toFixed(1)}),o("td",{className:"px-3 py-2 text-right text-foreground",children:h.attachedCameras}),o("td",{className:"px-3 py-2 text-right text-foreground",children:h.attachedCameras>0?(h.totalInferenceWeighted/h.attachedCameras).toFixed(0):"—"}),o("td",{className:"px-3 py-2 text-right text-foreground",children:h.queueDepth}),o("td",{className:"px-3 py-2 text-right text-foreground",children:i.get(p)??"—"})]},p)),f.length===0&&o("tr",{children:o("td",{colSpan:6,className:"px-3 py-4 text-center text-foreground-subtle text-[11px]",children:"No camera metrics received yet"})})]})]})})]})}function Ht({label:e,value:t}){return u("div",{className:"rounded-lg border border-border bg-surface/60 p-3",children:[o("div",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle mb-1",children:e}),o("div",{className:"text-lg font-semibold text-foreground",children:t})]})}function L0(e){return $n({addonId:e})}function y9(e){return Gn({deviceId:e},{enabled:Number.isFinite(e)})}const v9=3e4,w9=2e3;function R0(e){const t=ne(0);return t.current===0&&(t.current=Date.now()),hb({parentDeviceId:e},{enabled:Number.isFinite(e),staleTime:0,refetchOnMount:"always",refetchInterval:n=>{const r=n.state.data;return r&&r.length>0||Date.now()-t.current>=v9?!1:w9}})}const zi={active:!1,pinned:!1,nodeId:null,reason:""},Fi=["pipeline.camera-assigned","pipeline.camera-unassigned","pipeline.camera-updated","agent.online","agent.offline"],N9={pipeline:ft,decoder:lo,audio:$l},Gp={pipeline:"Pipeline",decoder:"Decoder",audio:"Audio"};function O0({mode:e,nodeId:t,compact:n=!1}){if(e==="agent"&&!t)throw new Error('CameraAssignmentsTable: nodeId is required when mode === "agent"');const r=ke(),[s,a]=P(null),[i,l]=P(null),[c,d]=P(new Map);vt(["pipelineOrchestrator","getPipelineAssignments"],Fi),vt(["pipelineOrchestrator","getDecoderAssignments"],Fi),vt(["pipelineOrchestrator","getAudioAssignments"],Fi);const{data:f}=Ea(void 0,{staleTime:3e4}),{data:p}=fx(void 0,{staleTime:3e4}),{data:h}=bx(void 0,{staleTime:3e4}),{nodes:m}=zr(),{data:g}=L0();pt("pipeline.camera-metrics-snapshot",$=>{const B=$.data;typeof B.deviceId=="number"&&d(R=>{const M=new Map(R);return M.set(B.deviceId,B),M})}),Y(()=>{if(c.size===0)return;const $=setInterval(()=>{d(B=>{const R=Date.now()-1e4;let M=!1;const T=new Map(B);for(const[_,L]of B)L.timestamp<R&&(T.delete(_),M=!0);return M?T:B})},5e3);return()=>clearInterval($)},[c.size]);const b=q(()=>{const $=new Map;for(const B of g??[])$.set(B.id,B.name);return $},[g]),x=q(()=>{const $=new Map,B=M=>{const T=$.get(M);if(T)return T;const _={deviceId:M,deviceName:b.get(M)??`Device ${M}`,pipeline:zi,decoder:zi,audio:zi};return $.set(M,_),_};for(const M of f??[]){const T=B(M.deviceId);$.set(M.deviceId,{...T,pipeline:{active:e==="cluster"?!0:M.agentNodeId===t,pinned:M.pinned,nodeId:M.agentNodeId,reason:M.reason??""}})}for(const M of p??[]){const T=B(M.deviceId);$.set(M.deviceId,{...T,decoder:{active:e==="cluster"?!0:M.decoderNodeId===t,pinned:M.pinned,nodeId:M.decoderNodeId,reason:M.reason??""}})}for(const M of h??[]){const T=B(M.deviceId);$.set(M.deviceId,{...T,audio:{active:e==="cluster"?!0:M.nodeId===t,pinned:M.pinned,nodeId:M.nodeId,reason:"capacity"}})}let R=[...$.values()];return e==="agent"&&(R=R.filter(M=>M.pipeline.active||M.decoder.active||M.audio.active)),R.sort((M,T)=>M.deviceId-T.deviceId),R},[f,p,h,b,e,t]),y=q(()=>(m??[]).filter($=>$.isOnline).map($=>({id:$.id,name:$.name})),[m]),w=()=>{r.invalidateQueries({queryKey:[["pipelineOrchestrator","getPipelineAssignments"]]}),r.invalidateQueries({queryKey:[["pipelineOrchestrator","getDecoderAssignments"]]}),r.invalidateQueries({queryKey:[["pipelineOrchestrator","getAudioAssignments"]]})},v=sx({onSuccess:w}),N=ax({onSuccess:w}),k=ux({onSuccess:w}),C=px({onSuccess:w}),E=hx({onSuccess:w}),A=mx({onSuccess:w}),I=($,B,R)=>{B==="pipeline"?v.mutate({deviceId:$,agentNodeId:R}):B==="decoder"?k.mutate({deviceId:$,nodeId:R}):E.mutate({deviceId:$,nodeId:R}),a(null)},z=($,B)=>{B==="pipeline"?N.mutate({deviceId:$}):B==="decoder"?C.mutate({deviceId:$}):A.mutate({deviceId:$}),a(null)};return o("div",{className:"rounded-lg border border-border overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[640px]",children:[o("thead",{className:"bg-surface",children:u("tr",{className:"text-foreground-subtle text-[10px] uppercase tracking-wider",children:[!n&&o("th",{className:"w-6"}),o("th",{className:"text-left px-3 py-2 align-middle",children:"Camera"}),o("th",{className:"text-left px-3 py-2 align-middle",children:"Pipeline"}),o("th",{className:"text-left px-3 py-2 align-middle",children:"Decoder"}),o("th",{className:"text-left px-3 py-2 align-middle",children:"Audio"}),o("th",{className:"text-left px-3 py-2 align-middle",children:"Status"})]})}),u("tbody",{children:[x.map($=>{const B=c.get($.deviceId),R=i===$.deviceId;return u(ic.Fragment,{children:[u("tr",{className:"border-t border-border align-middle relative",children:[!n&&o("td",{className:"px-2 py-2 align-middle",children:o("button",{type:"button",onClick:()=>l(R?null:$.deviceId),className:"p-1 rounded hover:bg-surface-hover text-foreground-subtle","aria-label":R?"Collapse broker details":"Expand broker details",children:R?o(Nt,{className:"h-3.5 w-3.5"}):o(Et,{className:"h-3.5 w-3.5"})})}),u("td",{className:"px-3 py-2 align-middle",children:[o("div",{className:"text-foreground font-medium leading-tight",children:$.deviceName}),u("div",{className:"text-[10px] text-foreground-subtle leading-tight",children:["#",$.deviceId]})]}),o(ji,{role:"pipeline",state:$.pipeline,mode:e,deviceId:$.deviceId,onlineNodes:y,isMenuOpen:s?.deviceId===$.deviceId&&s.role==="pipeline",onToggleMenu:()=>a(s?.deviceId===$.deviceId&&s.role==="pipeline"?null:{deviceId:$.deviceId,role:"pipeline"}),onCloseMenu:()=>a(null),onMove:M=>I($.deviceId,"pipeline",M),onUnpin:()=>z($.deviceId,"pipeline")}),o(ji,{role:"decoder",state:$.decoder,mode:e,deviceId:$.deviceId,onlineNodes:y,isMenuOpen:s?.deviceId===$.deviceId&&s.role==="decoder",onToggleMenu:()=>a(s?.deviceId===$.deviceId&&s.role==="decoder"?null:{deviceId:$.deviceId,role:"decoder"}),onCloseMenu:()=>a(null),onMove:M=>I($.deviceId,"decoder",M),onUnpin:()=>z($.deviceId,"decoder")}),o(ji,{role:"audio",state:$.audio,mode:e,deviceId:$.deviceId,onlineNodes:y,isMenuOpen:s?.deviceId===$.deviceId&&s.role==="audio",onToggleMenu:()=>a(s?.deviceId===$.deviceId&&s.role==="audio"?null:{deviceId:$.deviceId,role:"audio"}),onCloseMenu:()=>a(null),onMove:M=>I($.deviceId,"audio",M),onUnpin:()=>z($.deviceId,"audio")}),o("td",{className:"px-3 py-2 align-middle",children:o(C9,{snap:B})})]}),R&&!n&&u("tr",{className:"bg-surface/50",children:[o("td",{}),o("td",{colSpan:5,className:"px-3 py-2",children:o(lt,{widgetId:"stream-broker/stream-broker-panel",host:"device-tab",deviceId:$.deviceId,instanceId:`pipeline-row/${$.deviceId}`,config:{variant:"compact",title:"Stream brokers & clients"}})})]})]},$.deviceId)}),x.length===0&&o("tr",{children:o("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 ji({role:e,state:t,mode:n,onlineNodes:r,isMenuOpen:s,onToggleMenu:a,onCloseMenu:i,onMove:l,onUnpin:c}){const d=N9[e],f=r.filter(m=>m.id!==(t.nodeId??"")),h=(t.active||n==="cluster")&&(f.length>0||t.pinned);return u("td",{className:"px-3 py-2 align-middle relative",children:[u("div",{className:"flex items-center gap-2",children:[n==="agent"?o(k9,{state:t,Icon:d}):o(S9,{state:t,Icon:d}),o("div",{className:"ml-auto",children:h&&o("button",{type:"button",onClick:a,className:"p-1 rounded hover:bg-surface-hover","aria-label":`${Gp[e]} actions`,children:o(XL,{className:"h-3 w-3 text-foreground-subtle"})})})]}),s&&h&&o(M9,{title:Gp[e],targets:f,pinned:t.pinned,onMove:l,onUnpin:c,onClose:i})]})}function k9({state:e,Icon:t}){const n=e.active?f0:Ko;return u("div",{className:"flex items-center gap-1.5",children:[o(n,{className:`h-3.5 w-3.5 ${e.active?"text-success":"text-foreground-subtle/50"}`}),o(t,{className:`h-3 w-3 ${e.active?"text-foreground-subtle":"text-foreground-subtle/40"}`}),e.pinned&&o(c0,{className:"h-2.5 w-2.5 text-amber-400"})]})}function S9({state:e,Icon:t}){return!e.active||!e.nodeId?u("div",{className:"flex items-center gap-1.5 text-foreground-subtle/60",children:[o(t,{className:"h-3 w-3"}),o("span",{className:"text-[10px] italic",children:"—"})]}):u("div",{className:"flex items-center gap-1.5 min-w-0",children:[o(t,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),u("div",{className:"flex flex-col leading-tight min-w-0",children:[o("span",{className:"font-mono text-[11px] text-foreground truncate",children:e.nodeId}),o("span",{className:"flex items-center gap-1 text-[10px]",children:e.pinned?u("span",{className:"inline-flex items-center gap-0.5 text-amber-400",children:[o(c0,{className:"h-2.5 w-2.5"})," manual"]}):u("span",{className:"text-foreground-subtle truncate",children:["auto · ",e.reason||"capacity"]})})]})]})}function C9({snap:e}){if(!e)return o("span",{className:"text-[10px] text-foreground-subtle italic",children:"—"});const{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:s,configuredFps:a}=e.metrics,i=rr(t);return u("div",{className:"flex flex-col gap-0.5 font-mono text-[10px] tabular-nums leading-tight",children:[u("span",{className:`inline-flex items-center gap-1 ${i.textColor}`,children:[o(ld,{phase:t,className:"h-2.5 w-2.5"}),o("span",{className:"font-semibold uppercase tracking-wider",children:i.label})]}),u("span",{className:"text-foreground-subtle",children:[o("span",{className:"text-foreground",children:n.toFixed(1)}),u("span",{children:["/",a.toFixed(0)," fps"]})]}),u("span",{className:"text-foreground-subtle",children:[o("span",{className:"text-foreground",children:r.toFixed(0)}),o("span",{children:" ms"}),s>0&&u("span",{className:"text-warning ml-1",children:["q",s]})]})]})}function M9({title:e,targets:t,pinned:n,onMove:r,onUnpin:s,onClose:a}){const i=ne(null);return Y(()=>{const l=c=>{i.current?.contains(c.target)||a()};return window.addEventListener("mousedown",l),()=>window.removeEventListener("mousedown",l)},[a]),u("div",{ref:i,className:"absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left",children:[o("div",{className:"px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border",children:e}),t.length>0&&o("div",{className:"py-1",children:t.map(l=>u("button",{type:"button",onClick:()=>r(l.id),className:"block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover",children:["Move to ",l.name]},l.id))}),n&&u("button",{type:"button",onClick:s,className:"block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border",children:["Unpin ",e.toLowerCase()]}),t.length===0&&!n&&o("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle italic",children:"Already auto · no other nodes online"})]})}function E9({nodeId:e,refreshToken:t}){return u("div",{className:"space-y-6",children:[o(T0,{refreshToken:t,nodeId:e}),u("div",{children:[o("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Cameras on this node"}),u("p",{className:"text-[11px] text-foreground-subtle",children:["Checkboxes mark the roles currently running on ",e,". Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream."]})]}),o(O0,{mode:"agent",nodeId:e,compact:!0})]})}function I9(e,t){const n=Math.max(0,t-e),r=Math.floor(e/1e3),s=Math.floor(n/1e3);return`${r}s idle · ${s}s left`}function A9({nodeId:e,refreshToken:t}){const n=ke(),r=ox({onSettled:()=>{n.invalidateQueries({queryKey:["pipelineExecutor","listLoadedEngines"]})}}),{data:s}=rx({nodeId:e},{staleTime:5e3}),i=Br("pipeline.engine-metrics-snapshot",h=>h.nodeId===e)?.engines??s??null,l=i===null;vt(["pipelineRunner","getLocalCameras"],["pipeline.camera-assigned","pipeline.camera-unassigned"]);const{data:c}=Mx({nodeId:e},{staleTime:3e4}),{values:d}=$c("pipeline.camera-metrics-snapshot",h=>h.deviceId,h=>h.nodeId===e),f=q(()=>d.filter(h=>h.metrics.phase==="active").length,[d]),p=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?`)||r.mutate({nodeId:e,engine:h,force:m.length>0})};return u("div",{className:"space-y-6",children:[u("div",{children:[o("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Inference engines on this node"}),u("p",{className:"text-[11px] text-foreground-subtle",children:[(i??[]).length," engine(s) resident in RAM. ",(c??[]).length," camera(s) attached, ",f," actively dispatching frames. Refreshes every 5s."]})]}),o("div",{className:"rounded-lg border border-border overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[640px]",children:[o("thead",{className:"bg-surface",children:u("tr",{className:"text-foreground-subtle text-[10px] uppercase tracking-wider",children:[o("th",{className:"text-left px-3 py-2 whitespace-nowrap",children:"Kind"}),o("th",{className:"text-left px-3 py-2 whitespace-nowrap",children:"Runtime / Backend / Device"}),o("th",{className:"text-left px-3 py-2",children:"Models"}),o("th",{className:"text-right px-3 py-2 whitespace-nowrap",children:"Pool PID"}),o("th",{className:"text-right px-3 py-2 whitespace-nowrap",children:"Auto-kill"}),o("th",{className:"text-right px-3 py-2 whitespace-nowrap",children:"In use"}),o("th",{className:"w-20"})]})}),u("tbody",{children:[l&&o("tr",{children:o("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 u("tr",{className:`border-t border-border ${m?"bg-amber-500/5":""}`,children:[o("td",{className:"px-3 py-2",children:u("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${m?"bg-amber-500/15 text-amber-400":"bg-success/15 text-success"}`,children:[m?o(oR,{className:"h-3 w-3"}):o(ft,{className:"h-3 w-3"}),m?"warm":"runtime"]})}),o("td",{className:"px-3 py-2",children:u("span",{className:"inline-flex items-center gap-1 text-[11px] text-sky-400",children:[o(_d,{className:"h-3 w-3"}),h.engine.runtime,"/",h.engine.backend,h.engine.device?`/${h.engine.device}`:"",h.engine.format?` · ${h.engine.format}`:""]})}),o("td",{className:"px-3 py-2",children:h.modelsLoaded.length===0?o("span",{className:"text-foreground-subtle text-[11px]",children:"—"}):o("div",{className:"flex flex-wrap gap-1",children:h.modelsLoaded.map(g=>o("span",{className:"inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle",children:g},g))})}),o("td",{className:"px-3 py-2 text-right font-mono text-foreground",children:h.poolPid??"—"}),o("td",{className:"px-3 py-2 text-right text-[11px]",children:h.idleMs!==null&&h.idleTtlMs!==null?o("span",{className:"text-foreground-subtle",children:I9(h.idleMs,h.idleTtlMs)}):o("span",{className:"text-foreground-subtle/50",children:"never"})}),o("td",{className:"px-3 py-2 text-right text-foreground",children:m?"—":(c??[]).length}),o("td",{className:"px-3 py-2 text-right",children:u("button",{type:"button",disabled:r.isPending,onClick:()=>p(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:[o(Ke,{className:"h-3 w-3"}),"Kill"]})})]},h.engineKey)}),!l&&(i??[]).length===0&&o("tr",{children:o("td",{colSpan:7,className:"px-3 py-4 text-center text-foreground-subtle text-[11px]",children:"No engines resident — the factory spins up on the first pipeline run."})})]})]})}),u("div",{className:"text-[10px] text-foreground-subtle leading-relaxed",children:[o("strong",{className:"text-foreground",children:"runtime"}),": main camera-serving engine; never auto-killed while cameras attached. ",o("strong",{className:"text-foreground",children:"warm"}),": benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL."]}),r.isError&&u("div",{className:"rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive",children:["Kill failed: ",r.error instanceof Error?r.error.message:"unknown"]})]})}function kt(e){if(!Number.isFinite(e)||e<0)return"—";if(e<1024)return`${Math.round(e)} B`;const t=["KB","MB","GB","TB","PB"];let n=e/1024,r="KB";for(const a of t){if(r=a,n<1024)break;n/=1024}return`${n>=100?Math.round(n).toString():n.toFixed(1)} ${r}`}function B0(e){return kt(e*1024*1024)}const P9=new Set(EN);function Kp(e){return P9.has(e)}function Hi(e,t,n){return`${e}/${t}/${n}`}function zl(e){return{coreml:"CoreML",openvino:"OpenVINO",onnx:"ONNX"}[e.format]??e.format.toUpperCase()}function Wp(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 Bn(e){return e.format}function _9(e,t){let n=0,r=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&&(r++,s+=c.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:s}}function $9({addonId:e,model:t,format:n,isActive:r,progress:s,errorMsg:a,onDownload:i,onDelete:l}){const c=t.formats[n];return c?u("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors",children:[o("div",{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?"bg-success":"bg-foreground-subtle/30"}`}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2",children:[o("span",{className:"text-sm font-medium text-foreground",children:t.name}),u("span",{className:"text-[10px] text-foreground-subtle font-mono",children:["(",t.id,")"]})]}),s&&s.progress>=0&&s.progress<100&&u("div",{className:"mt-1.5 flex items-center gap-2 max-w-xs",children:[o("div",{className:"flex-1 h-1 bg-surface-hover rounded-full overflow-hidden",children:o("div",{className:"bg-primary h-full rounded-full transition-all duration-300",style:{width:`${s.progress}%`}})}),u("span",{className:"text-[9px] text-primary font-mono tabular-nums shrink-0",children:[Math.round(s.progress),"%"]})]})]}),o("span",{className:"text-xs text-foreground-subtle tabular-nums shrink-0",children:B0(c.sizeMB)}),a&&u("span",{className:"flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0",title:a,children:[o(Mr,{className:"h-3 w-3 shrink-0"}),a]}),c.downloaded?u("button",{onClick:l,disabled:r,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:[r?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Ke,{className:"h-3 w-3"}),r?"Deleting...":"Delete"]}):u("button",{onClick:i,disabled:r,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:[r?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Cn,{className:"h-3 w-3"}),r?"Downloading...":"Download"]})]}):null}function D9({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){const[s,a]=P(!1);return u("div",{className:"relative",children:[u("button",{type:"button",onClick:()=>a(!s),className:"flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors",children:[o(ft,{className:"h-4 w-4 text-primary shrink-0"}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2",children:[o("span",{className:"text-sm font-medium text-foreground",children:zl(n)}),Bn(n)===Bn(t)&&o("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium",children:"Active"})]}),o("div",{className:"text-[10px] text-foreground-subtle",children:Wp(n)})]}),o(Nt,{className:`h-4 w-4 text-foreground-subtle transition-transform ${s?"rotate-180":""}`})]}),s&&o("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=Bn(i)===Bn(n),c=Bn(i)===Bn(t);return u("button",{type:"button",onClick:()=>{r(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:[o(ft,{className:`h-4 w-4 shrink-0 ${l?"text-primary":"text-foreground-subtle"}`}),u("div",{className:"flex-1",children:[u("div",{className:"flex items-center gap-2",children:[o("span",{className:`text-sm font-medium ${l?"text-primary":"text-foreground"}`,children:zl(i)}),c&&o("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium",children:"Active"})]}),o("div",{className:"text-[10px] text-foreground-subtle",children:Wp(i)})]}),l&&o(Xy,{className:"h-4 w-4 text-primary shrink-0"})]},Bn(i))})})]})}function T9({embedded:e=!1,nodeId:t}={}){const n=ke(),r=t??"hub",[s,a]=P(null),[i,l]=P(new Set),[c,d]=P(new Map),[f,p]=P(new Map),[h,m]=P(""),{data:g=[]}=Xb({nodeId:r},{staleTime:6e4}),x=g.filter((O,j,F)=>F.findIndex(H=>H.format===O.format)===j),{data:y}=Jb({nodeId:r},{staleTime:3e4}),w=y,{data:v,isLoading:N}=jo({nodeId:r},{staleTime:1e4}),k=tx(),C=nx();pt("model.download.progress",O=>{const j=O.data,F=typeof j.modelId=="string"?j.modelId:void 0,H=typeof j.progress=="number"?j.progress:void 0,D=typeof j.totalMB=="number"?j.totalMB:0;F===void 0||H===void 0||(d(Q=>{const G=new Map(Q);return H===100||H===-1?G.delete(F):G.set(F,{modelId:F,progress:H,totalMB:D}),G}),H===100&&n.invalidateQueries({queryKey:[["pipelineExecutor","getSchema"]]}))});const E=w??{runtime:"node",backend:"cpu",format:"onnx"},A=x.find(O=>O.format===s)??E,I=A.format,z=v?.slots??[],$=z.map(O=>({...O,addons:O.addons.map(j=>({...j,models:j.models.filter(F=>F.formats[I]!==void 0)})).filter(j=>j.models.length>0)})).filter(O=>O.addons.length>0),B=_9($,I),R=U(async(O,j,F)=>{if(!Kp(F))return;const H=Hi(O,j,F);l(D=>new Set([...D,H])),p(D=>{const Q=new Map(D);return Q.delete(H),Q});try{await k.mutateAsync({addonId:O,modelId:j,format:F,nodeId:r}),n.invalidateQueries({queryKey:[["pipelineExecutor","getSchema"]]})}catch(D){p(Q=>new Map([...Q,[H,D instanceof Error?D.message:"Download failed"]]))}finally{l(D=>{const Q=new Set(D);return Q.delete(H),Q})}},[k,n,r]),M=U(async(O,j,F)=>{if(!Kp(F))return;const H=Hi(O,j,F);l(D=>new Set([...D,H])),p(D=>{const Q=new Map(D);return Q.delete(H),Q});try{await C.mutateAsync({addonId:O,modelId:j,format:F,nodeId:r}),n.invalidateQueries({queryKey:[["pipelineExecutor","getSchema"]]})}catch(D){p(Q=>new Map([...Q,[H,D instanceof Error?D.message:"Delete failed"]]))}finally{l(D=>{const Q=new Set(D);return Q.delete(H),Q})}},[C,n,r]),T=U(O=>{a(O.format)},[]),_=h.trim()?$.map(O=>({...O,addons:O.addons.map(j=>({...j,models:j.models.filter(F=>F.name.toLowerCase().includes(h.toLowerCase())||F.id.toLowerCase().includes(h.toLowerCase())||j.name.toLowerCase().includes(h.toLowerCase()))})).filter(j=>j.models.length>0)})).filter(O=>O.addons.length>0):$,L=u(me,{children:[N&&o("div",{className:"flex items-center justify-center py-16",children:o(Ee,{className:"h-5 w-5 animate-spin text-foreground-subtle"})}),!N&&z.length===0&&u("div",{className:"flex flex-col items-center justify-center py-16 text-foreground-subtle",children:[o(Ys,{className:"h-8 w-8 mb-3 opacity-30"}),o("span",{className:"text-sm",children:"No pipeline steps available"}),o("span",{className:"text-xs mt-1",children:"Configure the detection pipeline to see available models."})]}),!N&&z.length>0&&u(me,{children:[o(D9,{engines:x,activeEngine:E,viewEngine:A,onSelect:T}),u("div",{className:"flex items-center gap-4 text-xs text-foreground-subtle",children:[u("span",{children:[o("span",{className:"font-semibold text-foreground tabular-nums",children:B.total}),o("span",{className:"ml-1",children:"compatible models"})]}),o("span",{className:"text-border",children:"|"}),u("span",{children:[o("span",{className:"font-semibold text-success tabular-nums",children:B.downloaded}),o("span",{className:"ml-1",children:"downloaded"})]}),o("span",{className:"text-border",children:"|"}),u("span",{className:"tabular-nums",children:[B0(B.downloadedSizeMB),o("span",{className:"ml-1",children:"on disk"})]})]}),B.total>5&&u("div",{className:"relative",children:[o(p0,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle"}),o("input",{type:"text",value:h,onChange:O=>m(O.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"})]}),_.map(O=>{const j=O.addons.reduce((H,D)=>H+D.models.length,0),F=O.addons.reduce((H,D)=>H+D.models.filter(Q=>Q.formats[I]?.downloaded).length,0);return u("div",{children:[u("div",{className:"flex items-center gap-2 mb-2",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:O.label}),o("div",{className:"flex-1 h-px bg-border"}),u("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:[F,"/",j]})]}),o("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:O.addons.map(H=>H.models.map(D=>{const Q=Hi(H.id,D.id,I);return o($9,{addonId:H.id,model:D,format:I,isActive:i.has(Q),progress:c.get(D.id),errorMsg:f.get(Q),onDownload:()=>R(H.id,D.id,I),onDelete:()=>M(H.id,D.id,I)},`${H.id}/${D.id}`)}))})]},O.id)}),_.length===0&&o("div",{className:"text-center py-8 text-sm text-foreground-subtle",children:h.trim()?u(me,{children:["No models matching “",h,"”"]}):u(me,{children:["No models available for ",zl(A)," format"]})})]})]});return e?o("div",{className:"space-y-4",children:L}):o(Xe,{children:L})}function L9({nodeId:e,refreshToken:t}){return o(T9,{embedded:!0,nodeId:e})}function z0({nodeId:e,title:t}){const{data:n}=L0(),{data:r}=Ea(void 0,{staleTime:3e4}),s=q(()=>{const d=new Map;for(const f of n??[])d.set(f.id,f.name);return d},[n]),a=q(()=>{if(!e)return null;const d=new Set;for(const f of r??[])f.agentNodeId===e&&d.add(f.deviceId);return d},[e,r]),[i,l]=P(new Map);pt("pipeline.camera-metrics-snapshot",d=>{const f=d.data;typeof f.deviceId=="number"&&(e&&f.nodeId!==e||l(p=>{const h=new Map(p);return h.set(f.deviceId,f),h}))}),Y(()=>{if(i.size===0)return;const d=setInterval(()=>{l(f=>{const p=Date.now()-1e4;let h=!1;const m=new Map(f);for(const[g,b]of f)b.timestamp<p&&(m.delete(g),h=!0);return h?m:f})},5e3);return()=>clearInterval(d)},[i.size]);const c=q(()=>{const d=[];for(const f of i.values())a&&!a.has(f.deviceId)||d.push(f);return d.sort((f,p)=>f.deviceId-p.deviceId),d},[i,a]);return c.length===0?u("div",{className:"rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic",children:[t??"Cameras",": no live snapshots yet"]}):u("div",{className:"rounded-md border border-border bg-surface px-3 py-2",children:[u("div",{className:"flex items-center gap-2 mb-1.5",children:[o("span",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:t??"Cameras"}),o("span",{className:"text-[10px] text-foreground-subtle",children:c.length})]}),o("div",{className:"flex flex-wrap gap-1.5",children:c.map(d=>{const f=s.get(d.deviceId)??`#${d.deviceId}`,p=rr(d.metrics.phase);return u("div",{title:`${f} · ${p.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] ${p.badgeClass}`,children:[o(ld,{phase:d.metrics.phase,className:"h-2.5 w-2.5"}),o("span",{className:"font-medium text-foreground/90 max-w-[120px] truncate",children:f}),o("span",{className:"font-mono tabular-nums",children:d.metrics.actualFps.toFixed(1)}),o("span",{className:"opacity-60",children:"fps"})]},d.deviceId)})})]})}function Vi(e,t){if(!e)return null;for(const n of e.slots)for(const r of n.addons)if(r.id===t)return r;return null}function R9({nodeId:e,refreshToken:t}){const n=ke(),[r,s]=P(null),[a,i]=P(null),l=jo({nodeId:e},{refetchOnMount:"always"}),c=Zc({agentNodeId:e},{refetchOnMount:"always"}),d=Xc({onSuccess:()=>{n.invalidateQueries({queryKey:[["addonSettings"]]}),n.invalidateQueries({queryKey:[["pipelineOrchestrator"]]}),n.invalidateQueries({queryKey:[["pipelineExecutor"]]})}}),f=l.data??null,p=c.data,h=f?.selectedEngine.format??"coreml",m=q(()=>f?wa(f):[],[f]),g=q(()=>[{agentNodeId:e,engineLabel:h}],[e,h]),b=(C,E)=>{const A=p?.addonDefaults[C];return Vi(f,C)?.models.some($=>!!$.formats[h])?A?A.enabled?{kind:"enabled",modelId:A.modelId}:{kind:"disabled"}:{kind:"na"}:{kind:"na"}},x=r&&f?Vi(f,r.addonId):null,y=C=>{const E=p?.addonDefaults[C]??null;s({addonId:C,agentNodeId:e}),i(E)},w=(C,E)=>{if(!p)return;const A=p.addonDefaults[C],I=Vi(f,C);if(!A&&!I)return;const z={enabled:E,modelId:A?.modelId??I?.defaultModelId??"",settings:A?.settings??{}};d.mutate({agentNodeId:e,defaults:{...p.addonDefaults,[C]:z}})},v=()=>{s(null),i(null)},N=()=>{!a||!r||!p||d.mutate({agentNodeId:e,defaults:{...p.addonDefaults,[r.addonId]:a}},{onSuccess:v})};if(l.isLoading||c.isLoading)return o("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading pipeline…"});if(l.error)return u("div",{className:"text-xs text-red-400",children:["Failed to load catalog: ",String(l.error)]});if(!f)return o("div",{className:"text-xs text-foreground-subtle",children:"Catalog unavailable for this node (runner offline?)."});const k=r!==null&&x!==null&&a!==null;return u("div",{className:"relative h-full w-full space-y-3",children:[o(z0,{nodeId:e}),o("div",{className:k?"pr-[360px]":"",children:m.length>0?o(Ac,{tree:m,agents:g,getCellState:b,onCellClick:y,selectedCell:r,onToggleEnabled:w}):o("div",{className:"text-xs text-foreground-subtle",children:"Catalog empty."})}),o(Ic,{open:k,onClose:v,title:x?.name??"",subtitle:r?`${r.agentNodeId} · ${h}`:"",footer:u(me,{children:[o("button",{type:"button",className:"px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted",onClick:v,children:"Cancel"}),o("button",{type:"button",disabled:!a||!r||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&&r&&o(ka,{mode:"agent",addon:x,agentDefault:a,agentNodeId:r.agentNodeId,engineFormat:h,onChangeAgentConfig:C=>i(C)})})]})}function F0({pendingCount:e,onSave:t,onDiscard:n,saving:r=!1,saveLabel:s="Save",discardLabel:a="Discard"}){return e<=0?null:u("div",{className:"sticky bottom-0 -mb-3 flex items-center justify-between gap-3 rounded-lg border border-primary/40 bg-primary/5 px-3 py-2 shadow-sm z-10",children:[u("span",{className:"text-xs text-foreground",children:[e," unsaved change",e===1?"":"s"]}),u("div",{className:"flex items-center gap-2",children:[o("button",{type:"button",onClick:n,disabled:r,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}),o("button",{type:"button",onClick:t,disabled:r,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:r?"Saving…":s})]})]})}function j0({tabs:e,activeId:t,onChange:n,countByTab:r,pendingByTab:s}){return e.length===0?null:o("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=r?.get(a.id)??0,c=s?.get(a.id)??0;return u("button",{type:"button",onClick:()=>n(a.id),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?"text-primary border-primary bg-primary/5":"text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover"}`,children:[a.label,l>0&&u("span",{className:"ml-1.5 text-[10px] opacity-60",children:["(",l,")"]}),c>0&&o("span",{className:"ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-primary"})]},a.id)})})}function O9(e,t){for(const n of e)for(const r of n.fields){if(!("key"in r)||r.key!==t)continue;if(r.type==="button"||r.type==="separator"||r.type==="info")return!0;const s=r.immediate;return s===!0?!0:s===!1?!1:n.immediate===!0}return!1}function H0({schema:e,serverValues:t,onImmediateSave:n,onDeferredSave:r}){const[s,a]=P({}),[i,l]=P(!1),c=ne(null),d=e?.sections??[],f=Object.keys(s).length>0,p=q(()=>({...t,...s}),[t,s]);Y(()=>{if(f){l(!0);return}c.current&&clearTimeout(c.current),c.current=setTimeout(()=>l(!1),500)},[f]);const h=U(()=>{l(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>l(!1),2e3)},[]),m=U(y=>{h();const w={},v={},N={...t,...s};for(const[k,C]of Object.entries(y))N[k]!==C&&(O9(d,k)?w[k]=C:v[k]=C);Object.keys(w).length>0&&n(w),a(k=>{const C={...k};for(const E of Object.keys(w))delete C[E];for(const[E,A]of Object.entries(v))C[E]=A;return C})},[h,t,s,d,n]),g=U(y=>{const w={},v={};for(const[N,k]of Object.entries(s))y.includes(N)?w[N]=k:v[N]=k;a(v),Object.keys(w).length>0&&r(w)},[s,r]),b=U(y=>{a(w=>{const v={...w};for(const N of y)delete v[N];return v})},[]),x=U(()=>{a({})},[]);return{values:p,pendingKeys:Object.keys(s),hasPendingEdits:f,editingPaused:i,handleChange:m,handleSave:g,handleDiscard:b,resetAll:x}}const B9=qe(function({addonId:t,schema:n,serverValues:r,onImmediateSave:s,onStateChange:a,onAction:i,disabled:l},c){const d=H0({schema:n,serverValues:r,onImmediateSave:U(b=>s(t,b),[t,s]),onDeferredSave:U(()=>{},[])});xN(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 f=d.pendingKeys,p=f.join("|"),h=q(()=>f.map(b=>`${b}=${JSON.stringify(d.values[b])}`).join(","),[f,d.values]),m=ne(a);Y(()=>{m.current=a},[a]),Y(()=>{const b={};for(const x of f)b[x]=d.values[x];m.current({addonId:t,pendingKeys:f,pendingValues:b})},[t,p,h]);const g=q(()=>{if(i)return(b,x,y)=>i(t,b,x,y)},[t,i]);return o(En,{schema:n,values:d.values,onChange:d.handleChange,disabled:l,onAction:g})});function V0(e,t){if(e.type==="separator"||e.type==="info"||e.type==="button")return e;if(e.type==="group"){const a=e.fields.map(i=>V0(i,t));return{...e,fields:a}}const n=e;t[e.key]=n.value;const{value:r,...s}=n;return s}function z9(e,t){return{...e,fields:e.fields.map(n=>V0(n,t))}}function F9(e){const t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(r=>z9(r,t))},values:t}}function Qr({nodeId:e,addonIds:t,level:n,deviceId:r,sectionIds:s,sectionTab:a,extraTabs:i,title:l,description:c}){const d=ke(),f=Le().trpcClient,p=qg(),h=Ug(),m=ex(),g=ib(),b=Xg(),x=!!(i&&i.length>0),[y,w]=P(null);if(n==="device"&&!r)throw new Error('NodeAddonsSettingsPanel: deviceId is required when level === "device"');const v=e??"hub",N=wN({queries:t.map(X=>({queryKey:[["addonSettings",n==="global"?"getGlobalSettings":"getDeviceSettings"],{addonId:X,nodeId:v,deviceId:r??null}],queryFn:async()=>{if(n==="global"){const J=await f.addonSettings.getGlobalSettings.query({addonId:X,nodeId:v});return{addonId:X,result:J}}const K=await f.addonSettings.getDeviceSettings.query({addonId:X,deviceId:r,nodeId:v});return{addonId:X,result:K}},staleTime:3e4}))}),k=N.some(X=>X.isLoading),C=N.map(X=>{if(!X.data)return"-";if(X.data.result===null)return`${X.data.addonId}:n`;const K=[];for(const J of X.data.result.sections){K.push(`s:${J.id}:${J.tab??"general"}`);for(const ae of J.fields){if(!("key"in ae))continue;const fe="options"in ae&&Array.isArray(ae.options)?ae.options.map(ie=>ie.value).join(","):"",ge=ae.value,V=ge===void 0?"":typeof ge=="string"?ge:JSON.stringify(ge);K.push(`f:${ae.key}:${fe}:${V}`)}}return`${X.data.addonId}:${K.join("|")}`}).join("||"),E=q(()=>{const X=new Set;for(const K of N){const J=K.data?.result?.sections;if(J)for(const ae of J)X.add(ae.tab??"general")}return[...X]},[C+"::"+N.map(X=>(X.data?.result?.sections??[]).map(K=>K.tab??"general").join(",")).join("::")]),A=q(()=>new Map((i??[]).map(X=>[X.id,X])),[i]),I=q(()=>{if(!x)return[];const X=[...new Set([...E,...(i??[]).map(J=>J.id)])],K=J=>{const ae=A.get(J);if(ae?.order!==void 0)return ae.order;const fe=cl[J];return fe?fe.order:50};return X.sort((J,ae)=>{const fe=K(J),ge=K(ae);return fe!==ge?fe-ge:J.localeCompare(ae)})},[x,E,i,A]),z=q(()=>{const X=new Map;for(const K of E){const J=cl[K];X.set(K,J?.label??K.charAt(0).toUpperCase()+K.slice(1))}for(const K of i??[])X.set(K.id,K.label);return X},[E,i]),$=x?y&&I.includes(y)?y:I[0]??null:null,B=$!==null&&A.has($),R=x?$&&!B?$:void 0:a,{data:M}=Fo(void 0,{staleTime:6e4}),T=q(()=>{const X=new Map;for(const K of M??[]){const J=K.manifest?.id;if(!J)continue;const ae=K.manifest?.name??K.manifest?.packageDisplayName??J;X.set(J,ae)}return X},[M]),_=q(()=>{const X=s?new Set(s):null,K=[];for(const J of N){if(!J.data||J.data.result===null)continue;const{schema:ae,values:fe}=F9(J.data.result),ge=ae.sections.filter(ue=>X?X.has(ue.id):!0);if(ge.length===0)continue;const V={...J.data.result,sections:J.data.result.sections.filter(ue=>X?X.has(ue.id):!0)},ie={...ae,sections:ge};K.push({addonId:J.data.addonId,schemaWithValues:V,schema:ie,serverValues:fe})}return K},[C,s]),[L,O]=P(new Map),j=U(X=>{O(K=>{const J=new Map(K);return J.set(X.addonId,X),J})},[]),F=ne(new Map),H=U(X=>K=>{K?F.current.set(X,K):F.current.delete(X)},[]),D=U(async(X,K)=>{n==="global"?await p.mutateAsync({addonId:X,nodeId:v,patch:K}):await h.mutateAsync({addonId:X,deviceId:r,nodeId:v,patch:K}),d.invalidateQueries({queryKey:[["addonSettings"]]})},[p,h,v,n,r,d]),Q=U(async(X,K,J,ae)=>{const fe=v;try{switch(K){case"reprobe-engine":await m.mutateAsync({nodeId:fe}),d.invalidateQueries({queryKey:[["addonSettings"]]});return;case"reprobe-hwaccel":await g.mutateAsync({nodeId:fe}),d.invalidateQueries({queryKey:[["addonSettings"]]});return;case"reprobe-audio-engine":await b.mutateAsync({nodeId:fe}),d.invalidateQueries({queryKey:[["addonSettings"]]});return;default:{const ge=await f.addons.custom.mutate({addonId:X,action:K,input:ae});return d.invalidateQueries({queryKey:[["addonSettings"]]}),ge}}}catch(ge){throw console.error("[NodeAddonsSettingsPanel] action failed",{addonId:X,action:K,err:ge}),ge}},[m,g,b,v,d,f]),G=U((X,K)=>{D(X,K)},[D]),ee=cc({mutationFn:async()=>{const X=[];for(const J of _){const ae=L.get(J.addonId);!ae||ae.pendingKeys.length===0||X.push({addonId:J.addonId,patch:ae.pendingValues})}return X.length===0?{saved:[]}:{saved:await Promise.all(X.map(async({addonId:J,patch:ae})=>(n==="global"?await p.mutateAsync({addonId:J,nodeId:v,patch:ae}):await h.mutateAsync({addonId:J,deviceId:r,nodeId:v,patch:ae}),J)))}},onSuccess:({saved:X})=>{for(const K of X)F.current.get(K)?.discard();d.invalidateQueries({queryKey:[["addonSettings"]]})}}),se=U(()=>{for(const X of F.current.values())X.discard()},[]),te=q(()=>{let X=0;for(const K of _){const J=L.get(K.addonId);J&&(X+=J.pendingKeys.length)}return X},[_,L]),Z=q(()=>{const X=new Map;for(const K of _){const J=L.get(K.addonId);if(!J||J.pendingKeys.length===0)continue;const ae=new Set(J.pendingKeys);for(const fe of K.schema.sections){const ge=fe.tab??"general";for(const V of fe.fields)"key"in V&&ae.has(V.key)&&X.set(ge,(X.get(ge)??0)+1)}}return X},[_,L]);if(k)return o("div",{className:"h-24 rounded-lg border border-border bg-surface animate-pulse"});const re=$&&B?A.get($):void 0;if(!x&&_.length===0)return u("div",{className:"text-[11px] text-foreground-subtle italic",children:["No addons in ",t.length>0?`[${t.join(", ")}]`:"the current selection"," ","expose ",n,"-level settings on this node."]});const be=ee.isPending;return u("div",{className:"space-y-4",children:[(l||c)&&u("div",{className:"border-b border-border pb-2",children:[l&&o("h2",{className:"text-sm font-semibold text-foreground",children:l}),c&&o("p",{className:"text-[11px] text-foreground-subtle mt-0.5",children:c})]}),x&&o(j0,{tabs:I.map(X=>({id:X,label:z.get(X)??X})),activeId:$,onChange:w,pendingByTab:Z}),ee.isError&&u("div",{className:"rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400",children:["Save failed: ",String(ee.error?.message??ee.error)]}),re?re.content:(()=>{const X=R?_.reduce((ae,fe)=>ae+fe.schemaWithValues.sections.filter(ge=>(ge.tab??"general")===R).length,0):0,K=R!==null&&X<=1,J=_.map(ae=>({...ae,renderedWithValues:{...ae.schemaWithValues,sections:ae.schemaWithValues.sections.filter(fe=>R?(fe.tab??"general")===R:!0).map(fe=>K?{...fe,title:"",description:void 0}:fe)}})).filter(ae=>ae.renderedWithValues.sections.length>0).sort((ae,fe)=>{const ge=ue=>{let de=Number.POSITIVE_INFINITY;for(const ce of ue)typeof ce.order=="number"&&ce.order<de&&(de=ce.order);return de},V=ge(ae.renderedWithValues.sections),ie=ge(fe.renderedWithValues.sections);return V!==ie?V-ie:0});return J.length===0?o("div",{className:"text-[11px] text-foreground-subtle italic",children:"Nothing to configure here for this node."}):o(j9,{entries:J,paneStates:L,displayNames:T,disabled:be,setPaneRef:H,onPaneStateChange:j,onImmediateSave:G,onAction:Q,inline:x||!!a})})(),!k&&o(F0,{pendingCount:te,onSave:()=>ee.mutate(),onDiscard:se,saving:be})]})}function j9({entries:e,paneStates:t,displayNames:n,disabled:r,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]),f=d[0]?.addonId??"",[p,h]=P(f);Y(()=>{d.length!==0&&(d.find(x=>x.addonId===p)||h(d[0].addonId))},[d,p]);const m=d.find(x=>x.addonId===p)??d[0];if(!m)return null;const g=q(()=>l?(x,y,w,v)=>l(x,y,w,v):void 0,[l]),b=x=>o(B9,{ref:s(x.addonId),addonId:x.addonId,schema:x.renderedWithValues,serverValues:x.serverValues,onImmediateSave:i,onStateChange:a,onAction:g,disabled:r},x.addonId);return d.length===1||c?o("div",{className:"flex flex-col gap-4",children:d.map(b)}):u("div",{className:"flex flex-col gap-3",children:[o("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 u("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&&o("span",{className:"ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400"})]},x.addonId)})}),o("div",{className:"space-y-2",children:d.map(x=>o("div",{style:x.addonId===m.addonId?void 0:{display:"none"},children:b(x)},x.addonId))})]})}const H9=["detection-pipeline","decoder-nodeav","audio-analyzer","pipeline-runner"];function V9({nodeId:e,refreshToken:t}){return u("div",{className:"flex flex-col h-full",children:[o(x9,{nodeId:e,refreshToken:t}),o("div",{className:"flex-1 min-h-0 overflow-y-auto p-6",children:o(Qr,{nodeId:e,addonIds:H9,level:"global",extraTabs:[{id:"assignments",label:"Assignments",order:-10,content:o(E9,{nodeId:e,refreshToken:t})},{id:"tree",label:"Pipeline",order:39,content:o(R9,{nodeId:e,refreshToken:t})},{id:"engines",label:"Warm instances",order:180,content:o(A9,{nodeId:e,refreshToken:t})},{id:"models",label:"Models",order:200,content:o(L9,{nodeId:e,refreshToken:t})}]})})]})}function q9({refreshToken:e}){const t=ke(),n=ix({onSuccess:()=>{t.invalidateQueries({queryKey:[["pipelineOrchestrator","getPipelineAssignments"]]}),t.invalidateQueries({queryKey:[["pipelineOrchestrator","getDecoderAssignments"]]}),t.invalidateQueries({queryKey:[["pipelineOrchestrator","getAudioAssignments"]]})}});return u("div",{className:"space-y-6",children:[o(T0,{refreshToken:e}),u("div",{className:"flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between",children:[u("div",{className:"min-w-0",children:[o("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Placement matrix"}),o("p",{className:"text-[11px] text-foreground-subtle",children:"Pipeline · decoder · audio assignments per camera. Click the kebab to pin / unpin / move any role; expand the chevron for the per-camera broker drill-down."})]}),u("button",{type:"button",onClick:()=>n.mutate(void 0),disabled:n.isPending,className:"inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap",children:[o(_d,{className:"h-3.5 w-3.5"}),n.isPending?"Rebalancing…":"Rebalance pipelines"]})]}),o(O0,{mode:"cluster"})]})}const U9=["pipeline-orchestrator"];function Q9({refreshToken:e}){return o("div",{className:"space-y-4 max-w-3xl",children:o(Qr,{nodeId:"hub",addonIds:U9,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 G9({refreshToken:e}){const t=ke(),{data:n,isLoading:r}=kx(),[s,a]=P(null),[i,l]=P(""),[c,d]=P(""),f=()=>{t.invalidateQueries({queryKey:[["pipelineOrchestrator","listTemplates"]]})},p=Sx({onSuccess:()=>{a(null),f()}}),h=Cx({onSuccess:f}),m=y=>{a(y.id),l(y.name),d(y.description??"")},g=()=>{a(null),l(""),d("")},b=()=>{if(!s)return;const y=c.trim();p.mutate({id:s,name:i.trim()||"Untitled",...y?{description:y}:{}})};if(r)return o("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading templates…"});const x=[...n??[]].sort((y,w)=>y.name.localeCompare(w.name));return o("div",{className:"space-y-6 max-w-4xl",children:u("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"border-b border-border px-4 py-3 flex items-center justify-between",children:[u("div",{children:[o("h3",{className:"text-sm font-semibold text-foreground",children:"Templates"}),o("p",{className:"text-[11px] text-foreground-subtle mt-0.5",children:"Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab."})]}),u("div",{className:"text-[11px] text-foreground-subtle",children:[x.length," template",x.length===1?"":"s"]})]}),x.length===0?u("div",{className:"px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2",children:[o(ot,{className:"h-6 w-6 opacity-40"}),o("div",{children:'No templates yet. Create one from a device Pipeline tab ("Save as template").'})]}):o("ul",{className:"divide-y divide-border",children:x.map(y=>{const w=s===y.id;return o("li",{className:"px-4 py-3 text-xs",children:u("div",{className:"flex items-start gap-3",children:[o("div",{className:"flex-1 min-w-0",children:w?u("div",{className:"space-y-2",children:[o("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}),o("input",{className:"w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary",value:c,onChange:v=>d(v.target.value),placeholder:"Description (optional)"})]}):u(me,{children:[o("div",{className:"font-medium text-foreground",children:y.name}),y.description&&o("div",{className:"text-foreground-subtle mt-0.5",children:y.description}),u("div",{className:"mt-1 font-mono text-[10px] text-foreground-subtle",children:["engine ",y.config.engine.runtime,"/",y.config.engine.backend," · ",y.config.steps.length," step(s)",y.config.audio?.enabled?" · audio":"",u("span",{className:"ml-2",children:["updated ",new Date(y.updatedAt).toLocaleString()]})]})]})}),o("div",{className:"flex items-center gap-1 shrink-0",children:w?u(me,{children:[u("button",{type:"button",onClick:b,disabled:p.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:[o(Mt,{className:"h-3 w-3"}),"Save"]}),u("button",{type:"button",onClick:g,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover",children:[o(Fe,{className:"h-3 w-3"}),"Cancel"]})]}):u(me,{children:[o("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:o(Ur,{className:"h-3 w-3"})}),o("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:o(Ke,{className:"h-3 w-3"})})]})})]})},y.id)})})]})})}function Yp(e,t){if(!e)return null;for(const n of e.slots)for(const r of n.addons)if(r.id===t)return r;return null}function K9({nodeId:e,refreshToken:t}){const n=ke(),r=Le().trpcClient,[s,a]=P(null),[i,l]=P(null),c=jr(void 0,{refetchOnMount:"always"});vt(["nodes","topology"],["agent.online","agent.offline","agent.unregistered","addon.installed","addon.uninstalled","addon.updated"]);const d=Dn(void 0,{staleTime:3e4,refetchOnMount:"always"}),f=q(()=>{const I=new Set;for(const z of d.data??[])z.isOnline&&I.add(z.id);return I},[d.data]),p=jo({nodeId:e},{refetchOnMount:"always"}),h=q(()=>(c.data??[]).filter(I=>f.has(I.nodeId)).map(I=>I.nodeId),[c.data,f]),m=tr({enabled:h.length>0,queryKey:[["pipelineExecutor","getSchema"],"schema-by-agent",h.join(","),t],queryFn:async()=>{const I={};for(const z of h)try{const $=await r.pipelineExecutor.getSchema.query({nodeId:z});I[z]=$.selectedEngine.format}catch{I[z]="coreml"}return I}}),g=Xc({onSuccess:()=>{n.invalidateQueries({queryKey:[["pipelineOrchestrator"]]}),n.invalidateQueries({queryKey:[["pipelineExecutor"]]}),n.invalidateQueries({queryKey:[["addonSettings"]]})}}),b=q(()=>p.data?wa(p.data):[],[p.data]),x=q(()=>{const I=c.data??[],z=f;return(z.size===0?[]:I.filter(B=>z.has(B.nodeId))).map(B=>{const R=m.data?.[B.nodeId];return{agentNodeId:B.nodeId,engineLabel:R??"(engine unknown)"}})},[c.data,m.data,f]),y=(I,z)=>{const B=c.data?.find(_=>_.nodeId===z)?.settings.addonDefaults[I],R=m.data?.[z];return Yp(p.data??null,I)?.models.some(_=>R!==void 0&&!!_.formats[R])?B?B.enabled?{kind:"enabled",modelId:B.modelId}:{kind:"disabled"}:{kind:"na"}:{kind:"na"}},w=s?c.data?.find(I=>I.nodeId===s.agentNodeId)??null:null,v=s&&p.data?Yp(p.data,s.addonId):null,N=s?m.data?.[s.agentNodeId]??"coreml":"coreml",k=()=>{a(null),l(null)},C=(I,z)=>{const B=c.data?.find(R=>R.nodeId===z)?.settings.addonDefaults[I]??null;a({addonId:I,agentNodeId:z}),l(B)},E=()=>{!i||!s||!w||g.mutate({agentNodeId:s.agentNodeId,defaults:{...w.settings.addonDefaults,[s.addonId]:i}},{onSuccess:k})};if(c.isLoading||p.isLoading)return o("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading agents…"});if(!p.data)return u("div",{className:"text-xs text-foreground-subtle",children:["Catalog unavailable for ",e,"."]});const A=s!==null&&v!==null&&i!==null;return u("div",{className:"relative h-full w-full space-y-3",children:[o(z0,{title:"Cluster cameras"}),o("div",{className:A?"pr-[360px]":"",children:b.length>0&&x.length>0?o(Ac,{tree:b,agents:x,getCellState:y,onCellClick:C,selectedCell:s}):o("div",{className:"text-xs text-foreground-subtle",children:"No agents or catalog empty."})}),o(Ic,{open:A,onClose:k,title:v?.name??"",subtitle:s?`${s.agentNodeId} · ${N}`:"",footer:u(me,{children:[o("button",{type:"button",className:"px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted",onClick:k,children:"Cancel"}),o("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:E,children:g.isPending?"Saving…":"Save"})]}),children:v&&i&&s&&o(ka,{mode:"agent",addon:v,agentDefault:i,agentNodeId:s.agentNodeId,engineFormat:N,onChangeAgentConfig:I=>l(I)})})]})}const W9=[{id:"assignments",label:"Assignments"},{id:"pipeline",label:"Pipeline"},{id:"settings",label:"Settings"},{id:"templates",label:"Templates"}];function Y9({refreshToken:e}){const[t,n]=P("assignments"),{data:r}=Dn(void 0,{staleTime:3e4}),s=r?.find(a=>a.isHub&&a.isOnline)?.id??r?.find(a=>a.isOnline)?.id??null;return u("div",{className:"flex flex-col h-full",children:[u("div",{className:"px-6 py-4 border-b border-border",children:[o("h2",{className:"text-base font-semibold text-foreground",children:"Cluster Orchestration"}),o("div",{className:"text-[11px] text-foreground-subtle mt-1",children:"Assignments with live load, cluster-wide settings, pipeline template library, per-camera pipeline overrides."})]}),o("div",{className:"flex items-center gap-1 px-6 border-b border-border",children:W9.map(a=>o("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))}),u("div",{className:"flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab",children:[t==="assignments"&&o(q9,{refreshToken:e}),t==="pipeline"&&(s?o(K9,{nodeId:s,refreshToken:e}):o("div",{className:"text-xs text-foreground-subtle",children:"No online node available — schema unreachable."})),t==="settings"&&o(Q9,{refreshToken:e}),t==="templates"&&o(G9,{refreshToken:e})]})]})}const po="__cluster__";function Z9(){const[e,t]=La(),n=e.get("node")??po,[r,s]=P(0);return Y(()=>{e.get("node")||t({node:po},{replace:!0})},[e,t]),u("div",{className:"flex flex-col h-full overflow-hidden",children:[o("div",{className:"flex items-center justify-end gap-4 px-4 py-3 border-b border-border shrink-0",children:u("button",{type:"button",onClick:()=>s(i=>i+1),title:"Refresh",className:"inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:[o(ht,{className:"h-3.5 w-3.5"}),"Refresh"]})}),u("div",{className:"flex-1 flex flex-col md:flex-row overflow-hidden min-h-0",children:[o("aside",{className:"w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border overflow-y-auto",children:o(b9,{selectedNodeId:n,onSelect:i=>{t({node:i},{replace:!0})},refreshToken:r})}),o("section",{className:"flex-1 min-h-0 overflow-hidden",children:n===po?o(Y9,{refreshToken:r}):o(V9,{nodeId:n,refreshToken:r})})]})]})}const X9="device-export",qi="export",J9="Export";function Fl(e){return e.type==="separator"||e.type==="info"||e.type==="object-array"||e.type==="widget"||e.type==="addon-action-button"?!1:e.type==="group"?e.fields.some(Fl):e.type==="sub-tabs"?e.tabs.some(t=>t.fields.some(Fl)):e.writerCapName===X9}function So(e){return e.fields.some(Fl)}function e7(e){const[t,n]=P("idle"),[r,s]=P(null),a=ne(null),i=ne(null),l=ne(null),c=ne(!0),d=$b(),f=Db(),p=Tb(),h=U(()=>{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=U(async()=>{if(t==="idle")return;n("stopping");const b=l.current;if(b&&e!==null)try{await Promise.race([p.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,p,h]),g=U(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 k=x.iceConnectionState;k==="connected"||k==="completed"?n("talking"):(k==="failed"||k==="closed"||k==="disconnected")&&c.current&&(s(k==="failed"?"WebRTC connection failed":null),m())};for(const k of b.getAudioTracks())x.addTrack(k,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 f.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 p.mutateAsync({deviceId:e,sessionId:y})}catch{}l.current=null,c.current&&(s(v),n("error"))}},[e,t,d,f,p,m]);return Y(()=>(c.current=!0,()=>{c.current=!1;const b=l.current;if(b!==null&&e!==null&&p.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:r,start:g,stop:m,isTalking:t==="talking"}}let t7=0;function at(){return++t7}function Ui(e){switch(e.type){case"system":return"system";case"device":return`#${e.deviceId}`;case"provider":return e.providerId;case"addon":return e.addonId}}function n7(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 r7(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 o7(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 s7({scope:e,greeting:t,className:n}){const r=Le(),[s,a]=P(()=>{const v=[];return t&&v.push({id:at(),kind:"info",text:t}),v.push({id:at(),kind:"info",text:`scope: ${Ui(e)} — type help or context for available commands`}),v}),[i,l]=P(""),[c,d]=P([]),[f,p]=P(-1),h=ne(null),m=ne(null);Y(()=>{const v=m.current;v&&(v.scrollTop=v.scrollHeight)},[s]);const g=U(()=>{h.current?.focus()},[]),b=cc({mutationFn:v=>r.trpcClient.repl.execute.mutate({code:v,scope:e}),onSuccess:v=>{const N=v??{},k=typeof N.output=="string"?N.output:v==null?"undefined":typeof v=="string"?v:JSON.stringify(v,null,2),C=N.type==="error";a(E=>[...E,{id:at(),kind:C?"error":"result",text:k}])},onError:v=>{const N=v instanceof Error?v.message:String(v);a(k=>[...k,{id:at(),kind:"error",text:N}])}});function x(v){const N=v.trim();if(N){if(N==="clear"){a([{id:at(),kind:"info",text:`scope: ${Ui(e)}`}]),l("");return}if(N==="help"){a(k=>[...k,{id:at(),kind:"input",text:`> ${N}`},...n7(e).map(C=>({id:at(),kind:"info",text:C}))]),l("");return}if(N==="context"){a(k=>[...k,{id:at(),kind:"input",text:`> ${N}`},...o7(e).map(C=>({id:at(),kind:"info",text:C}))]),l("");return}if(N==="examples"){a(k=>[...k,{id:at(),kind:"input",text:`> ${N}`},...r7(e).map(C=>({id:at(),kind:"info",text:C}))]),l("");return}d(k=>[...k,N]),p(-1),a(k=>[...k,{id:at(),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=f===-1?c.length-1:Math.max(0,f-1);p(N),l(c[N]??"");return}if(v.key==="ArrowDown"){if(v.preventDefault(),f===-1)return;const N=f+1;N>=c.length?(p(-1),l("")):(p(N),l(c[N]??""));return}v.ctrlKey&&v.key==="l"&&(v.preventDefault(),a([{id:at(),kind:"info",text:`scope: ${Ui(e)}`}]))}const w={input:"text-zinc-300",result:"text-emerald-300",error:"text-red-300",info:"text-zinc-400"};return u("div",{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??""}`,onClick:g,children:[u("div",{ref:m,className:"flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]",children:[s.map(v=>o("pre",{className:`whitespace-pre-wrap break-words leading-relaxed ${w[v.kind]}`,children:v.text},v.id)),b.isPending&&o("span",{className:"text-zinc-500 animate-pulse",children:"…thinking"})]}),u("div",{className:"flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]",children:[o("span",{className:"text-emerald-400 flex-shrink-0 select-none font-bold",children:">"}),o("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 a7(e){const t=ke(),n=e!==null&&Number.isFinite(e),r=Ex({deviceId:e??0},{enabled:n,refetchInterval:5e3,retry:1}),s=Ix({onSuccess:()=>{t.invalidateQueries({queryKey:[["ptzAutotrack"]]})}}),a=Ax({onSuccess:()=>{t.invalidateQueries({queryKey:[["ptzAutotrack"]]})}}),i=U(async d=>{e!==null&&await s.mutateAsync({deviceId:e,enabled:d})},[e,s]),l=U(async d=>{e!==null&&await a.mutateAsync({deviceId:e,settings:d})},[e,a]),c=r.error?r.error.message:s.error?s.error.message:a.error?a.error.message:null;return{status:r.data??null,isLoading:r.isLoading,isPending:s.isPending||a.isPending,error:c,setEnabled:i,setSettings:l}}function i7({deviceId:e}){const{status:t,isLoading:n,isPending:r,error:s,setEnabled:a,setSettings:i}=a7(Number.isFinite(e)?e:null),[l,c]=P({targetType:"",stopDelaySeconds:30,disappearDelaySeconds:15}),[d,f]=P(!1);return Y(()=>{if(d)return;const p=t?.currentSettings;p&&c({targetType:p.targetType,stopDelaySeconds:p.stopDelaySeconds,disappearDelaySeconds:p.disappearDelaySeconds})},[t,d]),n&&!t?u("div",{className:"flex items-center gap-2 px-3 py-2 text-[10.5px] text-foreground-subtle",children:[o(Ee,{className:"h-3 w-3 animate-spin"}),"Loading autotrack…"]}):u("div",{className:"border-t border-border/40 mt-2 pt-2 px-1 space-y-2",children:[u("div",{className:"flex items-center justify-between px-2",children:[u("div",{className:"flex items-center gap-1.5 text-[10.5px] font-semibold text-foreground",children:[o(KL,{className:"h-3 w-3 text-primary"}),"Autotracking"]}),u("button",{type:"button",onClick:()=>{a(!(t?.enabled??!1))},disabled:r,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:[o("span",{className:`h-1.5 w-1.5 rounded-full ${t?.enabled?"bg-success":"bg-foreground-subtle/40"}`}),t?.enabled?"Enabled":"Disabled"]})]}),s&&u("div",{className:"flex items-start gap-1.5 rounded-md border border-danger/30 bg-danger/5 px-2 py-1.5 text-[10px] text-danger",children:[o(Mr,{className:"h-3 w-3 flex-shrink-0 mt-0.5"}),o("span",{className:"leading-snug break-words",children:s})]}),u("div",{className:"grid grid-cols-2 gap-2 px-2",children:[(t?.supportedTargetTypes?.length??0)>0&&u("label",{className:"col-span-2 flex flex-col gap-1",children:[o("span",{className:"text-[10px] font-medium text-foreground-subtle",children:"Target type"}),o("select",{value:l.targetType,onFocus:()=>f(!0),onChange:p=>c(h=>({...h,targetType:p.target.value})),onBlur:()=>{f(!1);const p=t?.currentSettings?.targetType??"";l.targetType!==p&&i({targetType:l.targetType})},disabled:r,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(p=>o("option",{value:p.value,children:p.label},p.value))})]}),u("label",{className:"flex flex-col gap-1",children:[o("span",{className:"text-[10px] font-medium text-foreground-subtle",children:"Stop delay (s)"}),o("input",{type:"number",min:0,max:300,value:l.stopDelaySeconds,onFocus:()=>f(!0),onChange:p=>c(h=>({...h,stopDelaySeconds:Number(p.target.value)||0})),onBlur:()=>{f(!1);const p=t?.currentSettings?.stopDelaySeconds??30;l.stopDelaySeconds!==p&&i({stopDelaySeconds:l.stopDelaySeconds})},disabled:r,className:"rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50"})]}),u("label",{className:"flex flex-col gap-1",children:[o("span",{className:"text-[10px] font-medium text-foreground-subtle",children:"Disappear delay (s)"}),o("input",{type:"number",min:0,max:300,value:l.disappearDelaySeconds,onFocus:()=>f(!0),onChange:p=>c(h=>({...h,disappearDelaySeconds:Number(p.target.value)||0})),onBlur:()=>{f(!1);const p=t?.currentSettings?.disappearDelaySeconds??15;l.disappearDelaySeconds!==p&&i({disappearDelaySeconds:l.disappearDelaySeconds})},disabled:r,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"})]})]}),o("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 l7({deviceId:e,intercomAvailable:t=!1}){const n=Le(),r=typeof window<"u"?window.location.origin:"",s=Number.isFinite(e),a=b0(s?e:null),{streams:i,pipelineMetrics:l,createSession:c,sendAnswer:d,closeSession:f}=hd(n.trpcClient,s?e:null),p=Lc(n.trpcClient,s?e:null),h=e7(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=vy(),y=x.length>0?o(me,{children:x.map(w=>o("div",{className:"absolute inset-0",children:w.node},w.id))}):null;return o(id,{serverUrl:r,createSession:c,sendAnswer:d,closeSession:f,streams:i,pipelineMetrics:l,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:p.src,snapshotLoading:p.loading,onRefreshSnapshot:p.refresh,intercomAvailable:t,intercomShown:g,onIntercomToggle:b,extraOverlay:y,chromeless:!0,className:"h-full"})}function c7({deviceId:e}){return Number.isFinite(e)?o("div",{className:"flex flex-col h-full",children:o(Xt,{deviceId:e,limit:50,maxHeight:"max-h-full",showScope:!1,showFilters:!1})}):u("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]})}function d7({deviceId:e}){if(!Number.isFinite(e))return u("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]});const t=[`CamStack REPL — device #${e}`,""," device.state.battery.value sync state read"," await device.snapshot.getSnapshot({}) cap action",""," type 'examples' for more, 'context' for the full API"].join(`
1114
- `);return o(s7,{scope:{type:"device",deviceId:e},greeting:t,className:"h-full border-0 rounded-none"})}function u7({deviceId:e}){const t=Le(),n=Number.isFinite(e),r=md(t.trpcClient,n?e:0,{enabled:n}),{data:s}=y9(n?e:0);if(!n)return u("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]});const a=(s?.features??[]).includes(Hn.PtzAutotrack);return u("div",{className:"flex flex-col h-full overflow-y-auto",children:[o(dd,{controls:r,mode:"panel"}),a&&o(i7,{deviceId:e})]})}function p7({deviceId:e}){return Number.isFinite(e)?o("div",{className:"flex flex-col h-full overflow-y-auto",children:o(cr,{deviceId:e,limit:50,maxHeight:"max-h-full"})}):u("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]})}function f7({deviceId:e}){return Number.isFinite(e)?o("div",{className:"flex flex-col h-full overflow-y-auto",children:o(cd,{deviceId:e,limit:50,maxHeight:"max-h-full"})}):u("div",{className:"flex items-center justify-center h-full text-[11px] text-foreground-subtle italic",children:["Device #",e," not loaded."]})}function h7({parentDeviceId:e}){const{t}=zt(),n=et(),r=Le(),{data:s,isLoading:a,isError:i}=R0(e);if(a)return o("div",{className:"rounded-lg border border-border bg-surface p-3",children:o("p",{className:"text-[10px] text-foreground-subtle",children:t("common.loading",{defaultValue:"Loading…"})})});if(i)return o("div",{className:"rounded-lg border border-border bg-surface p-3",children:o("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(p=>!!p.role),d=l.some(p=>!p.role),f=c&&!d?t("device.accessories",{defaultValue:"Accessories"}):!c&&d?t("device.adoptedDevices",{defaultValue:"Adopted devices"}):t("device.children",{defaultValue:"Children"});return u("div",{className:"rounded-lg border border-border bg-surface p-3",children:[o("div",{className:"text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5",children:f}),o("div",{className:"space-y-1",children:l.map(p=>o(xo,{trpc:r.trpcClient,device:p,variant:"minimal",onNavigate:h=>n(`/devices/${String(h)}`)},p.id))})]})}function Qi(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function m7({device:e}){const t=et(),n=typeof e.id=="number"?e.id:null,r=String(e.type??""),s=r===it.Camera,a=r===it.Hub,i=e.features??[],{data:l}=Yc({deviceId:n??0},{enabled:n!==null&&s,refetchInterval:5e3}),c=l?.streams??{},d=Object.entries(c),f=i.includes(Hn.DoorbellButton),p=gd(f?{deviceId:n??void 0,historyLimit:10}:void 0),h=p.latest?Date.now()-p.latest.timestamp<3e4:!1;return u("div",{className:"space-y-5",children:[a&&n!==null&&o(Sy,{deviceId:n,onOpenChild:m=>t(`/devices/${m}`)}),s&&n!==null&&o(lt,{widgetId:"pipeline-orchestrator/pipeline-quick-stats",host:"device-tab",deviceId:n}),f&&o(ud,{history:p.history,latestIsFresh:h}),s&&n!==null&&o(lt,{widgetId:"stream-broker/stream-broker-panel",host:"device-tab",deviceId:n}),s&&d.length>0&&u("div",{className:"@container rounded-lg border border-border bg-surface overflow-hidden",style:{containerType:"inline-size"},children:[o("div",{className:"border-b border-border px-4 py-2",children:o("h2",{className:"text-xs font-semibold text-foreground uppercase tracking-wider",children:"Stream Network"})}),o("div",{className:"divide-y divide-border",children:d.map(([m,g])=>u("div",{className:"px-4 py-2.5",children:[u("div",{className:"flex items-center gap-2 mb-2",children:[o(Wn,{className:"h-3 w-3 text-foreground-subtle"}),o("span",{className:"text-[11px] font-medium text-foreground",children:m})]}),u("div",{className:"grid grid-cols-2 @[640px]:grid-cols-4 gap-2",children:[o(xs,{label:"Nominal",value:Qi(g.nominalBitrateKbps??0)}),o(xs,{label:"Observed",value:Qi(g.observedBitrateKbps??0)}),o(xs,{label:"Peak",value:Qi(g.peakBitrateKbps??0)}),o(xs,{label:"Packet Loss",value:`${(g.packetLossPercent??0).toFixed(2)}%`,warning:(g.packetLossPercent??0)>1})]})]},m))})]}),o(y0,{})]})}function xs({label:e,value:t,warning:n}){return u("div",{children:[o("p",{className:"text-[10px] text-foreground-subtle",children:e}),o("p",{className:`text-xs font-medium ${n?"text-warning":"text-foreground"}`,children:t})]})}function g7({schema:e,values:t,pendingKeys:n,onChange:r,onAction:s,onSave:a,onDiscard:i,disabled:l}){const c=e.tabs??[],d=q(()=>{const k=new Map;for(const C of e.sections){const E=C.tab??"general",A=k.get(E)??[];A.push(C),k.set(E,A)}return k},[e.sections]),f=new Set(c.map(k=>k.id)),p=[...c,...[...d.keys()].filter(k=>!f.has(k)).map(k=>({id:k,label:k,icon:"wrench",order:100}))],h=p[0]?.id??"general",[m,g]=P(h),b=d.get(m)??[],y={sections:b.length<=1?b.length===1?[{...b[0],title:""}]:b:b.every(C=>!C.title)?[{...b[0],title:"",fields:b.flatMap(C=>C.fields)}]:b},w=o(F0,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>i(n),saving:l});if(p.length<=1)return u("div",{className:"flex flex-col gap-3",children:[o(En,{schema:e,values:t,onChange:r,onAction:s,disabled:l}),w]});const v=new Map,N=new Map;for(const[k,C]of d){v.set(k,C.length);const E=new Set,A=z=>{for(const $ of z)if("key"in $&&typeof $.key=="string"&&E.add($.key),$.type==="group")A($.fields);else if($.type==="sub-tabs")for(const B of $.tabs)A(B.fields)};for(const z of C)A(z.fields);const I=n.filter(z=>E.has(z)).length;I>0&&N.set(k,I)}return u("div",{className:"flex flex-col gap-3",children:[o(j0,{tabs:p.map(k=>({id:k.id,label:k.label})),activeId:m,onChange:g,countByTab:v,pendingByTab:N}),o(En,{schema:y,values:t,onChange:r,onAction:s,disabled:l}),w]})}function b7(e,t){return t&&t==="admin"?e:!0}function x7(e){if(!e)return null;const n={sections:[...e.sections].sort((r,s)=>{const a=r.tab??"general",i=s.tab??"general";return a!==i?a.localeCompare(i):So(r)&&So(s)?r.id.localeCompare(s.id):(r.order??0)-(s.order??0)})};return e.tabs?{...n,tabs:e.tabs}:n}function q0(e){return e.type==="separator"||e.type==="info"||e.type==="button"||e.type==="widget"||e.type==="addon-action-button"}function U0(e){return e.key}function y7(e){if(!q0(e))return e.value}function Q0(e){return q0(e)?null:e}function ea(e,t){for(const n of e)if(t(n),n.type==="group")ea(n.fields,t);else if(n.type==="sub-tabs")for(const r of n.tabs)ea(r.fields,t)}function v7(e){if(!e)return{};const t={};for(const n of e.sections)ea(n.fields,r=>{const s=U0(r);s!==null&&(t[s]=y7(r))});return t}function Zp(e,t){if(!e)return null;let n=null;for(const r of e.sections)if(ea(r.fields,s=>{if(n!==null||U0(s)!==t)return;const a=Q0(s);a&&a.writerCapName&&a.writerAddonId&&(n={capName:a.writerCapName,addonId:a.writerAddonId})}),n!==null)break;return n}function w7(e){return{...e,fields:e.fields.map(G0)}}function G0(e){return e.type==="separator"||e.type==="info"||e.type==="button"||e.type==="object-array"?e:{...e,readonlyField:!0}}function N7(e,t){return e&&{...e,sections:e.sections.map(n=>({...n,fields:n.fields.map(r=>{const s=Q0(r);return s?b7(t,s.minRole)?r:G0(r):r})}))}}function jl({deviceId:e,sectionFilter:t}){const n=ke(),{user:r}=mn(),s=r?.isAdmin===!0,a=ne(!1),{data:i,isLoading:l}=Qc({deviceId:e},{refetchInterval:()=>a.current?!1:2500,staleTime:6e4,enabled:Number.isFinite(e)}),{data:c}=Gn({deviceId:e},{staleTime:6e4,enabled:Number.isFinite(e)}),d=i?.settings??null,f=i?.live??null,p=q(()=>{if(!d&&!f)return null;const B=d?.sections??[],R=(f?.sections??[]).map(w7),M=[...B,...R],T=t?M.filter(t):M.filter(j=>j.location!=="top-tab"&&!So(j));if(T.length===0)return null;const _=new Set;for(const j of T)_.add(j.tab??"general");const O=[...d?.tabs??[],...(f?.tabs??[]).filter(j=>!(d?.tabs??[]).some(F=>F.id===j.id))].filter(j=>_.has(j.id));return O.length>0?{tabs:O,sections:T}:{sections:T}},[d,f,t]),h=q(()=>x7(p),[p]),m=q(()=>N7(h,s),[h,s]),g=q(()=>v7(m),[m]),b=Vx(),x=Kc(),y=wb({onSuccess:()=>{n.invalidateQueries({queryKey:[["deviceManager","getDeviceAggregate"]]})}}),w={isPending:y.isPending,mutate:B=>{y.mutate({deviceId:e,changes:[...B]})}},v=U(B=>{const R=Object.entries(B).map(([M,T])=>{const _=Zp(m,M);return _?{writerCapName:_.capName,writerAddonId:_.addonId,key:M,value:T}:null}).filter(M=>M!==null);R.length>0&&w.mutate(R)},[m,w]),N=U(B=>{const R=Object.entries(B).map(([M,T])=>{const _=Zp(m,M);return _?{writerCapName:_.capName,writerAddonId:_.addonId,key:M,value:T}:null}).filter(M=>M!==null);R.length>0&&w.mutate(R)},[m,w]),k=H0({schema:m,serverValues:g,onImmediateSave:v,onDeferredSave:N}),{values:C,pendingKeys:E,handleChange:A,handleSave:I,handleDiscard:z}=k;if(a.current=k.editingPaused,l)return u("div",{className:"flex items-center justify-center py-12 text-foreground-subtle",children:[o(Ee,{className:"h-4 w-4 animate-spin mr-2"}),o("span",{className:"text-xs",children:"Loading device aggregate…"})]});if(!m||m.sections.length===0)return o("div",{className:"text-xs text-foreground-subtle italic py-4 text-center",children:"No aggregate contributions for this device."});async function $(B,R,M){if(B==="regenerate-rtsp-token"){const T=["rtspUrl:","regenerateToken:"].find(O=>R.startsWith(O));if(!T)throw new Error(`regenerate-rtsp-token: unrecognised key "${R}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);const _=R.slice(T.length);if(!_)throw new Error(`regenerate-rtsp-token: key "${R}" has no streamId after prefix`);const L=`${e}/${_}`;await b.mutateAsync({brokerId:L}),n.invalidateQueries({queryKey:[["deviceManager","getDeviceAggregate"]]});return}if(B==="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:R,value:M})}catch(T){return{status:"error",error:T instanceof Error?T.message:String(T)}}}if(B==="refresh-driver-data"){await y.mutateAsync({deviceId:e,changes:[{writerCapName:"device-manager",writerAddonId:"device-manager",key:R,value:Date.now()}]});return}throw new Error(`[device-aggregate] unknown action "${B}"`)}return o(g7,{schema:m,values:C,pendingKeys:E,onChange:A,onAction:$,onSave:I,onDiscard:z,disabled:w.isPending})}function k7({deviceId:e}){return o(jl,{deviceId:e})}const K0=6e4,Hl=60*K0,Xp=24*Hl;function Va(e){if(e==null||e<=0)return"—";const t=Date.now()-e;return t<0||t<3e4?"just now":t<Hl?`${String(Math.floor(t/K0))}m ago`:t<Xp?`${String(Math.floor(t/Hl))}h ago`:`${String(Math.floor(t/Xp))}d ago`}function S7(e,t=new Date){const n=new Date(e);return n.getFullYear()===t.getFullYear()&&n.getMonth()===t.getMonth()&&n.getDate()===t.getDate()}function W0({dev:e,busy:t,setBusy:n}){const r=e?.motionTrigger,s=an(e?.state.motionTrigger),[a,i]=P(!1);if(!r)return null;const l=s?.enabled===!0,c=s!==void 0,d=async()=>{if(t||!c)return;const p=!l;n(!0),i(!0);try{await r.setMotionTrigger({enabled:p})}finally{n(!1),i(!1)}};return u("button",{type:"button",onClick:()=>{d()},disabled:t||!c,title:c?l?"Disable trigger on motion":"Enable trigger on motion":"Awaiting state…","aria-pressed":l,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${l?"border-primary/50 bg-primary/15 text-primary":"border-border bg-surface text-foreground-subtle hover:text-foreground"}`,children:[o(qo,{className:"h-3 w-3"}),o("span",{children:a?l?"Disabling…":"Enabling…":c?l?"On motion: on":"On motion: off":"On motion: …"})]})}function Y0({deviceId:e,deviceName:t,useSiren:n=!1}){const r=Le(),s=St(r.trpcClient,e),a=an(s?.state.switch),[i,l]=P(!1),c=a?.on??!1,d=a?.lastChangedAt??null,f=a!==void 0,p=n?Uo:d0,h=async()=>{if(!(i||!f||!s?.switch)){l(!0);try{await s.switch.setState({on:!c})}finally{l(!1)}}};return u("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 p-4",children:[o("button",{type:"button",onClick:()=>{h()},disabled:i||!f||!s?.switch,title:f?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:o(p,{className:"h-10 w-10"})}),o(W0,{dev:s,busy:i,setBusy:l}),u("div",{className:"text-center",children:[o("div",{className:`text-sm font-semibold ${c?"text-success":"text-foreground-subtle"}`,children:f?c?"On":"Off":"Unknown"}),o("div",{className:"text-[10px] text-foreground-subtle mt-0.5",children:f?`Changed ${Va(d)}`:"Awaiting state…"})]})]})}function C7({deviceId:e,deviceName:t}){const n=Le(),r=St(n.trpcClient,e),s=an(r?.state.switch),a=an(r?.state.brightness),i=s?.on??!1,l=s?.lastChangedAt??null,c=s!==void 0,d=a!==void 0,f=r?.brightness!==void 0,[p,h]=P(!1),[m,g]=P(a?.percentage??0);Y(()=>{a?.percentage!==void 0&&g(a.percentage)},[a?.percentage]);const b=async()=>{if(!(p||!c||!r?.switch)){h(!0);try{await r.switch.setState({on:!i})}finally{h(!1)}}},x=async()=>{if(!(p||!d||!r?.brightness)){h(!0);try{await r.brightness.setBrightness({percentage:m})}finally{h(!1)}}};return u("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 p-4",children:[o("button",{type:"button",onClick:()=>{b()},disabled:p||!c||!r?.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:o(kR,{className:"h-9 w-9"})}),f?u("div",{className:"flex w-full max-w-xs flex-col items-center gap-1",children:[o("input",{type:"range",min:0,max:100,step:1,value:m,disabled:p||!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"}),o("div",{className:"text-[10px] text-foreground-subtle tabular-nums",children:d?`${String(m)}%`:"Brightness unavailable"})]}):null,o(W0,{dev:r,busy:p,setBusy:h}),u("div",{className:"text-center",children:[o("div",{className:`text-sm font-semibold ${i?"text-warning":"text-foreground-subtle"}`,children:c?i?"On":"Off":"Unknown"}),o("div",{className:"text-[10px] text-foreground-subtle mt-0.5",children:c?`Changed ${Va(l)}`:"Awaiting state…"})]})]})}function M7({deviceId:e}){const t=Le(),n=St(t.trpcClient,e),r=an(n?.state.motion),s=r?.detected??!1,a=r?.lastDetectedAt??null,i=r!==void 0;return u("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 p-4",children:[o("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?o(n6,{className:"h-10 w-10"}):o(qo,{className:"h-10 w-10"})}),u("div",{className:"text-center",children:[o("div",{className:`text-sm font-semibold ${s?"text-danger":"text-foreground-subtle"}`,children:i?s?"Triggered":"Idle":"Unknown"}),o("div",{className:"text-[10px] text-foreground-subtle mt-0.5",children:i?`Last trip ${Va(a)}`:"Awaiting state…"})]})]})}function E7({deviceId:e}){const t=Le(),n=St(t.trpcClient,e),r=an(n?.state.doorbell),s=r?.lastPressedAt??null,a=r!==void 0,i=s!==null&&Date.now()-s<6e4,[l,c]=P(0),[d,f]=P(null);return Y(()=>{s===null||s===d||(f(s),S7(s)&&c(p=>p+1))},[s,d]),u("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 p-4",children:[o("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:o(Uo,{className:"h-10 w-10"})}),u("div",{className:"text-center",children:[o("div",{className:`text-sm font-semibold ${i?"text-primary":"text-foreground-subtle"}`,children:a?`Last press ${Va(s)}`:"Unknown"}),o("div",{className:"text-[10px] text-foreground-subtle mt-0.5 tabular-nums",children:a?`${String(l)} ring${l===1?"":"s"} today`:"Awaiting state…"})]})]})}function I7({deviceName:e,deviceType:t,provider:n,isOnline:r,features:s}){return u("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center",children:[o(un,{type:n,size:"lg"}),u("div",{children:[o("div",{className:"text-sm font-semibold text-foreground",children:e}),o("div",{className:"text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5",children:t})]}),u("div",{className:"flex items-center gap-2 flex-wrap justify-center",children:[o(Ha,{status:r?"online":"offline"}),s.length>0&&o(Fa,{capabilities:s})]}),o("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 A7({deviceId:e}){const t=ke(),n=lb({deviceId:e},{refetchInterval:1e4,retry:!1}),r=cb({onSuccess:()=>{t.invalidateQueries({queryKey:[["deviceDiscovery","listDiscovered"]]}),t.invalidateQueries({queryKey:[["deviceDiscovery","getStatus"]]})}}),s=q(()=>P7(n.data??[]),[n.data]);return u("div",{className:"flex h-full w-full flex-col gap-3 p-3 sm:p-4",children:[u("div",{className:"flex flex-wrap items-stretch gap-2 sm:gap-3",children:[o(Gi,{label:"Discovered",value:s.total,icon:o(Mn,{className:"h-3.5 w-3.5"})}),o(Gi,{label:"Adopted",value:s.adopted,accent:"success"}),o(Gi,{label:"Available",value:s.available,accent:s.available>0?"primary":void 0}),u("button",{type:"button",onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.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:[r.isPending?o(Ee,{className:"h-3.5 w-3.5 animate-spin"}):o(ht,{className:"h-3.5 w-3.5"}),o("span",{className:"hidden sm:inline",children:"Discover"})]})]}),u("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2",children:[o(ys,{icon:o(Wn,{className:"h-3 w-3 text-emerald-500"}),label:`${s.online} online`}),o(ys,{icon:o(i0,{className:"h-3 w-3 text-amber-500"}),label:`${s.sleeping} sleeping`}),o(ys,{icon:o(g0,{className:"h-3 w-3 text-destructive"}),label:`${s.offline} offline`}),s.unknown>0?o(ys,{icon:o(HL,{className:"h-3 w-3 text-foreground-subtle"}),label:`${s.unknown} unknown`}):null]})]})}function P7(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 Gi({label:e,value:t,icon:n,accent:r}){return u("div",{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r==="success"?"bg-emerald-500/10 border-emerald-500/30 text-emerald-500":r==="primary"?"bg-primary/10 border-primary/30 text-primary":"bg-surface-hover border-border text-foreground"}`,children:[u("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate",children:[n,o("span",{className:"truncate",children:e})]}),o("div",{className:"text-xl sm:text-2xl font-semibold tabular-nums leading-none",children:t})]})}function ys({icon:e,label:t}){return u("span",{className:"inline-flex items-center gap-1",children:[e,o("span",{children:t})]})}const _7=e=>o(Y0,{...e,useSiren:!0}),$7={[it.Switch]:Y0,[it.Siren]:_7,[it.Light]:C7,[it.Sensor]:M7,[it.Button]:E7,[it.Hub]:A7};function D7(e){const t=$7[e.deviceType]??I7;return o(t,{...e})}function $d(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 r=Math.floor(t/60),s=t%60;return s>0?`${r}h ${s}m`:`${r}h`}function ta(e){return new Date(e).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function na(e){return e.toISOString().slice(0,10)}function T7(e,t){return na(e)===na(t)}function ro(e){const t=new Date(e);return t.setHours(0,0,0,0),t}function L7(e){const t=new Date(e);return t.setHours(23,59,59,999),t}function Pt({className:e=""}){return o("div",{className:`animate-pulse rounded bg-foreground-subtle/10 ${e}`})}function zn(){return u("div",{className:"flex items-center gap-3 px-4 py-3",children:[o(Pt,{className:"h-4 w-4"}),o(Pt,{className:"h-3 w-24"}),o(Pt,{className:"h-3 w-16 ml-auto"})]})}function Xr({children:e,actions:t}){return u("div",{className:"border-b border-border px-4 py-2.5 flex items-center justify-between",children:[o("h2",{className:"text-xs font-semibold text-foreground uppercase tracking-wider",children:e}),t]})}function Jp({icon:e,label:t,value:n}){return u("div",{className:"flex items-center gap-2",children:[o(e,{className:"h-3.5 w-3.5 text-foreground-subtle flex-shrink-0"}),u("div",{className:"min-w-0",children:[o("p",{className:"text-[10px] text-foreground-subtle leading-tight",children:t}),o("p",{className:"text-xs font-medium text-foreground leading-tight",children:n})]})]})}function R7({segments:e,selectedDate:t}){const n=ro(t).getTime(),r=1440*60*1e3,s=Array.from({length:25},(a,i)=>i);return u("div",{className:"space-y-1",children:[o("div",{className:"flex justify-between px-0.5",children:s.filter(a=>a%3===0).map(a=>o("span",{className:"text-[9px] text-foreground-subtle font-mono",children:String(a).padStart(2,"0")},a))}),u("div",{className:"relative h-6 rounded bg-background border border-border overflow-hidden",children:[e.map(a=>{const i=new Date(a.startTime).getTime()-n,l=new Date(a.endTime).getTime()-n,c=Math.max(0,i/r*100),d=Math.min(100-c,(l-i)/r*100);return d<=0?null:o("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:`${ta(a.startTime)} - ${ta(a.endTime)} (${$d(a.duration)})`},a.id)}),s.slice(1,-1).map(a=>o("div",{className:"absolute top-0 bottom-0 w-px bg-border/50",style:{left:`${a/24*100}%`}},a))]})]})}function O7({segment:e,selected:t,onToggle:n,onPlay:r,onDownload:s,onDelete:a}){return u("div",{className:`flex items-center gap-3 px-4 py-2 border-b border-border last:border-b-0 hover:bg-background/50 transition-colors ${t?"bg-primary/5":""}`,children:[o("button",{onClick:n,className:"flex-shrink-0 text-foreground-subtle hover:text-foreground",children:t?o(f0,{className:"h-4 w-4 text-primary"}):o(Ko,{className:"h-4 w-4"})}),u("div",{className:"flex-1 min-w-0",children:[u("p",{className:"text-xs font-mono text-foreground",children:[ta(e.startTime)," - ",ta(e.endTime)]}),u("p",{className:"text-[10px] text-foreground-subtle",children:[$d(e.duration),e.sizeBytes!=null&&` · ${kt(e.sizeBytes)}`]})]}),u("div",{className:"flex items-center gap-1 flex-shrink-0",children:[o("button",{onClick:r,title:"Play",className:"p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle hover:text-foreground transition-colors",children:o(Oa,{className:"h-3.5 w-3.5"})}),o("button",{onClick:s,title:"Download",className:"p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle hover:text-foreground transition-colors",children:o(Cn,{className:"h-3.5 w-3.5"})}),o("button",{onClick:a,title:"Delete",className:"p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger transition-colors",children:o(Ke,{className:"h-3.5 w-3.5"})})]})]})}function B7({deviceId:e}){const t=ke(),[n,r]=P(()=>ro(new Date)),[s,a]=P(new Set),i=Rx({deviceId:e},{refetchInterval:5e3}),l=Dx({deviceId:e}),c=l.data?.streams[0]?.streamId??"stream0",d=Tx({deviceId:e,streamId:c,startTime:ro(n).getTime(),endTime:L7(n).getTime()}),f=Lx({deviceId:e,streamId:c},{refetchInterval:3e4}),p=Ox({deviceId:e,dataCategory:"recording:main"}),h=U(()=>{t.invalidateQueries({queryKey:["recordingEngine","getPolicyStatus"]}),t.invalidateQueries({queryKey:["recordingEngine","getSegments"]}),t.invalidateQueries({queryKey:["recordingEngine","getStorageUsage"]})},[t]),m=_x({onSuccess:h}),g={isPending:m.isPending,error:m.error,mutate:()=>{const _=l.data,L=_?{mode:_.mode,streams:_.streams,enabled:!0,preBufferSec:_.preBufferSec,postBufferSec:_.postBufferSec,scheduleRules:_.scheduleRules}:{mode:"continuous",streams:[{streamId:c,mode:"always"}],enabled:!0,preBufferSec:10,postBufferSec:5};m.mutate({deviceId:e,policy:L})}},b=$x({onSuccess:h}),x=i.data??void 0,y=l.data??void 0,w=d.data??[],v=f.data,N=p.data??void 0,k=(x?.enabled??!1)&&(x?.activeStreams??0)>0,C=g.isPending||b.isPending,E=T7(n,new Date),A=q(()=>[...w].sort((_,L)=>new Date(L.startTime).getTime()-new Date(_.startTime).getTime()),[w]),I=q(()=>w.reduce((_,L)=>_+(L.duration??0),0),[w]),z=q(()=>w.reduce((_,L)=>_+(L.sizeBytes??0),0),[w]);function $(){k?b.mutate({deviceId:e}):g.mutate()}function B(){r(_=>{const L=new Date(_);return L.setDate(L.getDate()-1),ro(L)}),a(new Set)}function R(){E||(r(_=>{const L=new Date(_);return L.setDate(L.getDate()+1),ro(L)}),a(new Set))}function M(_){a(L=>{const O=new Set(L);return O.has(_)?O.delete(_):O.add(_),O})}function T(){s.size===A.length?a(new Set):a(new Set(A.map(_=>_.id)))}return i.isLoading&&l.isLoading?u("div",{className:"space-y-4",children:[u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[o(Xr,{children:"Recording Status"}),u("div",{className:"px-4 py-4 space-y-3",children:[o(Pt,{className:"h-10 w-full"}),o(Pt,{className:"h-4 w-48"})]})]}),u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[o(Xr,{children:"Segments"}),u("div",{className:"divide-y divide-border",children:[o(zn,{}),o(zn,{}),o(zn,{})]})]})]}):u("div",{className:"space-y-4",children:[u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[o(Xr,{children:"Recording Status"}),u("div",{className:"px-4 py-4 flex items-center justify-between gap-4",children:[u("div",{className:"flex items-center gap-3 min-w-0",children:[o("div",{className:`flex items-center justify-center rounded-full p-2 flex-shrink-0 ${k?"bg-danger/10":"bg-foreground-subtle/10"}`,children:o(Jy,{className:`h-5 w-5 ${k?"text-danger animate-pulse":"text-foreground-subtle"}`})}),u("div",{className:"min-w-0",children:[o("p",{className:`text-sm font-medium ${k?"text-danger":"text-foreground-subtle"}`,children:k?"Recording":"Not Recording"}),o("p",{className:"text-[11px] text-foreground-subtle mt-0.5 truncate",children:k&&x?`${x.mode} – ${x.activeStreams} stream(s)`:"No active recording session"})]})]}),o("button",{onClick:$,disabled:C,className:`inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors flex-shrink-0 disabled:opacity-50 ${k?"bg-danger/10 text-danger hover:bg-danger/20":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:k?u(me,{children:[o(Ko,{className:"h-3.5 w-3.5"}),C?"Stopping...":"Stop Recording"]}):u(me,{children:[o(Oa,{className:"h-3.5 w-3.5"}),C?"Starting...":"Start Recording"]})})]}),k&&x&&u("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-[11px] text-foreground-subtle",children:[o(lo,{className:"h-3.5 w-3.5 text-primary flex-shrink-0"}),u("span",{children:[x.activeStreams," active stream",x.activeStreams!==1?"s":""," · mode: ",x.mode]})]})]}),u("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[o(Xr,{children:u("span",{className:"flex items-center gap-1.5",children:[o(Yt,{className:"h-3.5 w-3.5"}),"Settings"]})}),l.isLoading?u("div",{className:"px-4 py-3 space-y-2",children:[o(Pt,{className:"h-3 w-32"}),o(Pt,{className:"h-3 w-40"}),o(Pt,{className:"h-3 w-28"})]}):u("div",{className:"divide-y divide-border",children:[o(Jr,{label:"Stream",value:c}),o(Jr,{label:"Pre-buffer",value:y?`${y.preBufferSec}s`:"N/A"}),o(Jr,{label:"Mode",value:y?.mode??"continuous"}),o(Jr,{label:"Retention",value:N?.retentionDays!=null?`${N.retentionDays} days`:"N/A"}),N?.retentionGb!=null&&o(Jr,{label:"Max Storage",value:`${N.retentionGb} GB`})]})]}),u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[o(Xr,{children:u("span",{className:"flex items-center gap-1.5",children:[o(Ys,{className:"h-3.5 w-3.5"}),"Storage"]})}),f.isLoading?u("div",{className:"px-4 py-3 space-y-2",children:[o(Pt,{className:"h-3 w-28"}),o(Pt,{className:"h-3 w-36"}),o(Pt,{className:"h-3 w-24"})]}):f.error?u("div",{className:"px-4 py-4 flex items-center gap-2 text-xs text-danger",children:[o(ut,{className:"h-4 w-4"}),"Failed to load storage info"]}):u("div",{className:"px-4 py-3 grid grid-cols-2 gap-3",children:[o(Jp,{icon:Ys,label:"Total",value:v?.totalBytes!=null?kt(v.totalBytes):"N/A"}),o(Jp,{icon:lo,label:"Segments",value:v?.segmentCount!=null?String(v.segmentCount):"N/A"})]})]})]}),u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"border-b border-border px-4 py-2.5 flex items-center justify-between",children:[o("h2",{className:"text-xs font-semibold text-foreground uppercase tracking-wider",children:"Segment Browser"}),u("div",{className:"flex items-center gap-2",children:[o("button",{onClick:B,className:"p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle hover:text-foreground transition-colors",children:o(Ed,{className:"h-4 w-4"})}),u("div",{className:"flex items-center gap-1.5 text-xs text-foreground font-medium",children:[o(Yy,{className:"h-3.5 w-3.5 text-foreground-subtle"}),E?"Today":na(n)]}),o("button",{onClick:R,disabled:E,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:o(Et,{className:"h-4 w-4"})})]})]}),u("div",{className:"px-4 py-3 border-b border-border",children:[o(R7,{segments:w,selectedDate:n}),u("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-foreground-subtle",children:[u("span",{children:[w.length," segment",w.length!==1?"s":""]}),I>0&&u("span",{children:[$d(I)," recorded"]}),z>0&&o("span",{children:kt(z)})]})]}),A.length>0&&u("div",{className:"border-b border-border px-4 py-2 flex items-center justify-between",children:[o("button",{onClick:T,className:"text-[11px] text-foreground-subtle hover:text-foreground transition-colors",children:s.size===A.length?"Deselect All":"Select All"}),s.size>0&&u("div",{className:"flex items-center gap-2",children:[u("span",{className:"text-[10px] text-foreground-subtle",children:[s.size," selected"]}),u("button",{className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-[10px] font-medium bg-foreground-subtle/10 text-foreground-subtle hover:text-foreground transition-colors",title:"Download selected",children:[o(Cn,{className:"h-3 w-3"}),"Download"]}),u("button",{className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-[10px] font-medium bg-danger/10 text-danger hover:bg-danger/20 transition-colors",title:"Delete selected",children:[o(Ke,{className:"h-3 w-3"}),"Delete"]})]})]}),d.isLoading?u("div",{className:"divide-y divide-border",children:[o(zn,{}),o(zn,{}),o(zn,{}),o(zn,{})]}):A.length===0?u("div",{className:"flex flex-col items-center justify-center py-12 text-foreground-subtle",children:[o(lo,{className:"h-8 w-8 mb-3 opacity-30"}),o("p",{className:"text-sm",children:"No recorded segments"}),o("p",{className:"text-xs mt-1 opacity-70",children:E?"Recorded clips will appear here as they are created":`No recordings found for ${na(n)}`})]}):o("div",{className:"max-h-[400px] overflow-y-auto",children:A.map(_=>o(O7,{segment:_,selected:s.has(_.id),onToggle:()=>M(_.id),onPlay:()=>{},onDownload:()=>{},onDelete:()=>{}},_.id))})]}),i.error&&u("div",{className:"rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 flex items-center gap-2 text-xs text-danger",children:[o(ut,{className:"h-4 w-4 flex-shrink-0"}),"Failed to load recording status. Will retry automatically."]}),(g.error||b.error)&&u("div",{className:"rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 flex items-center gap-2 text-xs text-danger",children:[o(ut,{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 Jr({label:e,value:t}){return u("div",{className:"flex items-center justify-between px-4 py-2.5",children:[o("span",{className:"text-xs text-foreground-subtle",children:e}),o("span",{className:"text-xs font-medium text-foreground",children:t})]})}function z7({deviceId:e}){const t=ke(),n=Number.isFinite(e),{data:r}=Gn({deviceId:e},{enabled:n}),s=typeof r?.type=="string"?r.type:"camera";vt(["deviceManager","getBindings"],["capability.binding-changed"]);const{data:a,isLoading:i,isError:l,error:c}=xb({deviceId:e},{staleTime:3e4,enabled:n}),{data:d}=vb({deviceType:s},{staleTime:3e4,enabled:!!s}),f=yb({onSuccess:()=>{t.invalidateQueries({queryKey:[["deviceManager","getBindings"]]})}});if(i)return o("div",{className:"p-4",children:o("div",{className:"h-20 rounded-lg border border-border bg-surface animate-pulse"})});if(l)return u("div",{className:"p-4 text-xs text-red-400",children:["Failed to load bindings: ",c instanceof Error?c.message:String(c)]});const p=new Map,h={};for(const b of d??[])h[b.capName]=b.wrappers;for(const b of a?.entries??[])p.set(b.capName,{...b,wrappers:h[b.capName]??[]});for(const b of d??[])p.has(b.capName)||p.set(b.capName,{capName:b.capName,kind:"unbound",providerAddonId:"",providerNodeId:"",nativeAddonId:"",wrappers:b.wrappers});const m=[...p.values()].sort((b,x)=>b.capName.localeCompare(x.capName));if(m.length===0)return u("div",{className:"flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle",children:[o(Qo,{className:"h-8 w-8 opacity-40"}),o("p",{className:"text-xs",children:"No capability providers applicable to this device yet."}),o("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 u("div",{className:"flex flex-col gap-3 p-1",children:[u("div",{className:"text-[11px] text-foreground-subtle",children:[o("span",{className:"font-medium text-foreground",children:g})," ","of ",m.length," capabilit",m.length===1?"y":"ies"," bound — rows marked ",o("em",{children:"unbound"})," have a wrapper available you can activate."]}),o("div",{className:"overflow-hidden rounded-lg border border-border bg-surface",children:u("table",{className:"w-full border-collapse text-[11px]",children:[o("thead",{children:u("tr",{className:"bg-surface-hover/50 text-left text-[10px] uppercase tracking-wide text-foreground-subtle",children:[o("th",{className:"px-3 py-2 font-medium",children:"Capability"}),o("th",{className:"px-3 py-2 font-medium",children:"Kind"}),o("th",{className:"px-3 py-2 font-medium",children:"Active Provider"}),o("th",{className:"px-3 py-2 font-medium",children:"Node"}),o("th",{className:"px-3 py-2 font-medium",children:"Native"}),o("th",{className:"px-3 py-2 font-medium",children:"Wrapper"})]})}),o("tbody",{children:m.map(b=>{const x=b.kind==="wrapped"?b.providerAddonId:null;return u("tr",{className:"border-t border-border align-middle",children:[o("td",{className:"px-3 py-2 font-mono text-foreground",children:b.capName}),o("td",{className:"px-3 py-2",children:o(F7,{kind:b.kind})}),o("td",{className:"px-3 py-2 font-mono text-foreground-subtle",children:b.providerAddonId||o("span",{className:"opacity-40",children:"—"})}),o("td",{className:"px-3 py-2",children:b.providerNodeId?o(j7,{nodeId:b.providerNodeId}):o("span",{className:"text-[10px] opacity-40",children:"—"})}),o("td",{className:"px-3 py-2 font-mono text-foreground-subtle",children:b.nativeAddonId||o("span",{className:"opacity-40",children:"—"})}),o("td",{className:"px-3 py-2",children:o(H7,{wrappers:b.wrappers,activeWrapperId:x,disabled:f.isPending,onPick:y=>{const w=x===y;f.mutate({deviceId:e,capName:b.capName,wrapperAddonId:y,active:!w})}})})]},b.capName)})})]})})]})}function F7({kind:e}){return e==="native"?u("span",{className:"inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium",children:[o(cn,{className:"h-3 w-3"}),"native"]}):e==="wrapped"?u("span",{className:"inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium",children:[o(vR,{className:"h-3 w-3"}),"wrapped"]}):u("span",{className:"inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium",children:[o(BR,{className:"h-3 w-3"}),"unbound"]})}function j7({nodeId:e}){return o("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 H7({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?o("span",{className:"text-[10px] opacity-40",children:"none available"}):o("div",{className:"flex flex-wrap gap-1",children:e.map(s=>{const a=s===t;return u("button",{disabled:n,onClick:()=>r(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?o(Mt,{className:"h-3 w-3"}):o(u0,{className:"h-3 w-3"}),s]},s)})})}function V7(e,t){if(!e)return null;for(const n of e.slots)for(const r of n.addons)if(r.id===t)return r;return null}function q7(e,t,n){const r=e?.stepOverridesByAgent?.[t]?.[n];if(r)return r.enabled===!1?"off":(r.enabled===!0,"on");const s=e?.stepToggles?.[n];return s===!1?"off":s===!0?"on":"inherit"}function U7({agents:e,currentAgent:t,onPick:n}){const[r,s]=P(!1);return u("div",{className:"relative",children:[o("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 ▾"}),r&&o("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=>o("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 Q7({deviceId:e,refreshToken:t}){const n=ke(),[r,s]=P(null),[a,i]=P(null),[l,c]=P(null),[d,f]=P(null),p=Jc({deviceId:e}),h=jr(),m=Ia({deviceId:e}),g=lx(),b=q(()=>{const T=m.data?.agentNodeId;if(T)return T;const _=g.data?.find(L=>L.online)?.nodeId;return _||"hub"},[m.data?.agentNodeId,g.data]),x=a??b,y=jo({nodeId:x??""},{enabled:!!x}),w=vx({onSuccess:()=>{n.invalidateQueries({queryKey:[["pipelineOrchestrator","getCameraSettings"]]}),c(null)}}),v=q(()=>y.data?wa(y.data):[],[y.data]),N=q(()=>{const T=p.data??null,_={};for(const L of h.data??[])for(const O of Object.keys(L.settings.addonDefaults)){const j=_[O]??[];j.push({agentNodeId:L.nodeId,state:q7(T,L.nodeId,O)}),_[O]=j}return _},[p.data,h.data]),k=r?V7(y.data??null,r):null,C=x?h.data?.find(T=>T.nodeId===x)??null:null,E=r&&C?C.settings.addonDefaults[r]??null:null,A=r&&x?p.data?.stepOverridesByAgent?.[x]?.[r]??null:null,I=y.data?.selectedEngine.format??"coreml",z=T=>{i(T),c(null),f(null)},$=T=>{s(T),c(null),f(null)},B=T=>{if(!x||!r||!y.data||!h.data)return;const _=h.data.find(j=>j.nodeId===T),L=h.data.find(j=>j.nodeId===x);if(!_||!L)return;const[O]=lm({source:{nodeId:_.nodeId,engine:{format:I},defaults:_.settings.addonDefaults},target:{nodeId:L.nodeId,engine:{format:I},defaults:L.settings.addonDefaults},catalog:y.data,addonIds:[r]});if(!O){f("no mirror result");return}if(O.outcome==="skip"){f(`skipped: ${O.reason??"no candidate"}`);return}c(O.patch),f(`${O.outcome} from ${T}`)},R=()=>{!x||!r||w.mutate({deviceId:e,agentNodeId:x,addonId:r,patch:l})},M=()=>{!x||!r||w.mutate({deviceId:e,agentNodeId:x,addonId:r,patch:null})};return h.isLoading||y.isLoading?o("div",{className:"text-xs text-foreground-subtle animate-pulse p-4",children:"Loading pipeline…"}):y.data?o("div",{className:"@container h-full",style:{containerType:"inline-size"},children:u("div",{className:"flex flex-col @[720px]:flex-row h-full",children:[o("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:o(og,{tree:v,selectedAddonId:r,onSelect:$,agentDots:N})}),o("section",{className:"flex-1 min-w-0 p-4 overflow-y-auto",children:!r||!k?o("div",{className:"text-sm text-foreground-subtle",children:"Select a step on the left to configure it for this camera."}):u("div",{className:"space-y-4",children:[u("div",{children:[o("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Selected step"}),o("div",{className:"text-base font-semibold",children:k.name})]}),u("div",{className:"flex items-end gap-3 flex-wrap",children:[u("div",{children:[o("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle mb-1",children:"Agent"}),o("div",{className:"flex rounded border border-border overflow-hidden",children:(h.data??[]).map(T=>o("button",{type:"button",onClick:()=>z(T.nodeId),className:`px-3 py-1 text-xs ${x===T.nodeId?"bg-primary text-primary-foreground":"bg-surface hover:bg-muted"}`,children:T.nodeId},T.nodeId))})]}),o(U7,{agents:(h.data??[]).map(T=>T.nodeId),currentAgent:x,onPick:B}),d&&o("div",{className:"text-[10px] text-foreground-subtle",children:d})]}),E&&o(ka,{mode:"device",addon:k,agentDefault:E,agentNodeId:x??"",currentPatch:l??A,engineFormat:I,onChangePatch:c}),u("div",{className:"flex items-center justify-between gap-2 pt-4 border-t border-border",children:[o("button",{type:"button",className:"px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle",disabled:!A||w.isPending,onClick:M,children:"Clear override"}),u("div",{className:"flex items-center gap-2",children:[o("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"}),o("button",{type:"button",className:"px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50",disabled:!x||!r||w.isPending,onClick:R,children:w.isPending?"Saving…":"Save"})]})]})]})})]})}):o("div",{className:"text-xs text-foreground-subtle p-4",children:"Catalog unavailable."})}const G7=[{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 K7(e){const t=e===it.Camera;return G7.filter(n=>t||!n.cameraOnly).map(({id:n,label:r})=>({id:n,label:r}))}const W7=[{id:"logs",icon:rt,label:"Logs"},{id:"repl",icon:h0,label:"REPL"},{id:"events",icon:Uo,label:"Events"},{id:"state",icon:t0,label:"State"},{id:"ptz",icon:VR,label:"PTZ",featureGate:Hn.PanTiltZoom}];function Y7(){const e=yd(),t=Number(e.deviceId),n=Number.isFinite(t),r=et(),s=ke(),a=Je(),i=Le(),[l,c]=P("overview"),[d,f]=P("logs"),p="device-detail.left-col-width-px",[h,m]=P(()=>{if(typeof window>"u")return null;const de=window.localStorage.getItem(p),ce=de?Number(de):NaN;return Number.isFinite(ce)&&ce>0?ce:null}),g=ne(h);g.current=h;function b(de){de.preventDefault();const ce=de.clientX,Se=de.currentTarget.previousElementSibling?.getBoundingClientRect().width??h??0,pe=280,_e=Math.max(pe+50,Math.floor(window.innerWidth*.7)),Ae=st=>{const ur=Math.max(pe,Math.min(_e,Se+(st.clientX-ce)));m(ur)},We=()=>{document.removeEventListener("mousemove",Ae),document.removeEventListener("mouseup",We);const st=g.current;if(st!==null)try{window.localStorage.setItem(p,String(Math.round(st)))}catch{}document.body.style.userSelect="",document.body.style.cursor=""};document.body.style.userSelect="none",document.body.style.cursor="col-resize",document.addEventListener("mousemove",Ae),document.addEventListener("mouseup",We)}const{data:x,isLoading:y,isError:w}=Gn({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:v}=Qc({deviceId:t},{enabled:n,staleTime:3e4}),N=q(()=>{const de=v?.settings?.sections??[],ce=v?.live?.sections??[],Se=[...de,...ce],pe=new Set;for(const Ae of Se)Ae.location==="top-tab"&&Ae.tab&&pe.add(Ae.tab);return Se.some(So)&&pe.add(qi),[...pe].map(Ae=>{if(Ae===qi)return{id:Ae,label:J9,isAddonContrib:!0};const We=cl[Ae];return{id:Ae,label:We?.label??Ae,isAddonContrib:!0}})},[v]),k=x,C=String(k?.name??e.deviceId??"Device"),E=k?.online===!0,A=E?"online":"offline",I=String(k?.addonId??"rtsp"),z=k?.features??[],$=k?.type,B=$===it.Camera,R=typeof k?.parentDeviceId=="number"?k.parentDeviceId:null,{data:M}=Gn({deviceId:R??0},{enabled:R!==null,staleTime:3e4}),T=ar(),_=q(()=>[...K7($),...N],[$,N]),{data:L}=R0(n?t:0),O=(L??[]).length>0,j=q(()=>W7.filter(({featureGate:de})=>!de||z.includes(de)),[z]),{data:F}=Mb({addonId:I},{enabled:!!I&&I!=="rtsp"}),H=bb({onSuccess:()=>{s.invalidateQueries({queryKey:[["deviceManager"]]}),r(F?.id?`/integrations/${F.id}`:"/integrations")}}),D=mb({onSuccess:()=>{s.invalidateQueries({queryKey:[["deviceManager"]]})}}),Q=gb({onSuccess:()=>{s.invalidateQueries({queryKey:[["deviceManager"]]})}}),G=Px(),ee=Ca({onSuccess:()=>{s.invalidateQueries({queryKey:[["deviceManager"]]})}}),se=z.includes(Hn.Rebootable),te=z.includes(Hn.BatteryOperated),Z=Tc(i.trpcClient,te&&n?t:null),[re,be]=P(!1),X=St(i.trpcClient,n?t:null),K=async()=>{if(!(re||!X)){be(!0);try{await X.snapshot?.invalidateCache({});const de=await X.snapshot?.getSnapshot({});if(!de)return;const ce=`data:${de.contentType};base64,${de.base64}`,Se=de.contentType.includes("png")?"png":"jpg",pe=C.replace(/[^a-zA-Z0-9_.-]+/g,"_"),_e=new Date().toISOString().replace(/[:.]/g,"-"),Ae=document.createElement("a");Ae.href=ce,Ae.download=`${pe}-${_e}.${Se}`,document.body.appendChild(Ae),Ae.click(),document.body.removeChild(Ae)}finally{be(!1)}}},J=D.isPending||Q.isPending,{data:ae}=Ia({deviceId:t},{enabled:n,refetchInterval:1e4}),fe=ae?.agentNodeId??null,V=typeof fe=="string"&&fe.length>0&&!fe.startsWith("addon:")?fe:void 0,{data:ie}=ed({deviceId:t,...V?{nodeId:V}:{}},{enabled:n,refetchInterval:3e3,retry:!1});function ue(){if(!n)return null;switch(l){case"overview":return o(m7,{device:k??{}});case"config":return o(k7,{deviceId:t});case"pipeline":return o(Q7,{deviceId:t,refreshToken:0});case"bindings":return o(z7,{deviceId:t});case"recording":return o(B7,{deviceId:t});default:{const de=l;return N.some(Se=>Se.id===de)?de===qi?o(jl,{deviceId:t,sectionFilter:So}):o(jl,{deviceId:t,sectionFilter:Se=>Se.location==="top-tab"&&Se.tab===de}):null}}}return n?y?u("div",{className:"flex flex-col h-full",children:[u("div",{className:"border-b border-border bg-surface px-6 py-4",children:[o("div",{className:"h-4 w-48 rounded bg-surface-hover animate-pulse mb-3"}),o("div",{className:"h-8 w-64 rounded bg-surface-hover animate-pulse"})]}),o("div",{className:"flex-1 p-6",children:o("div",{className:"h-40 rounded-lg border border-border bg-surface animate-pulse"})})]}):w||!x?u("div",{className:"flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle",children:[o("p",{className:"text-lg font-semibold text-foreground",children:"Device not found"}),u("p",{className:"text-xs",children:["No device with ID ",u("code",{className:"font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]",children:["#",t]})]}),o("button",{onClick:()=>r("/integrations"),className:"mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors",children:"Back to Integrations"})]}):u("div",{className:"absolute inset-0 flex flex-col overflow-hidden",children:[u("div",{className:"border-b border-border bg-surface px-6 py-3 flex-shrink-0",children:[o("div",{className:"mb-2",children:o(Ec,{items:[{label:"Integrations",onClick:()=>r("/integrations")},{label:F?.name??I,onClick:()=>F?.id&&r(`/integrations/${F.id}`)},{label:C}]})}),u("div",{className:"flex items-center gap-2 sm:gap-3",children:[o(un,{type:I,size:"lg"}),u("div",{className:"min-w-0 flex-1",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[o("h1",{className:"text-sm sm:text-base font-semibold text-foreground truncate",children:C}),o(Ha,{status:A}),te&&o(Rc,{status:Z,variant:"full"})]}),R!==null&&M&&u("button",{type:"button",onClick:()=>r(`/devices/${R}`),className:"text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1",title:`Open parent device ${M.name}`,children:[o("span",{children:"↑"}),o("span",{className:"truncate",children:String(M.name??`Device #${R}`)})]}),o("div",{className:"hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle",children:z.length>0&&o(Fa,{capabilities:z})})]}),ie&&o("div",{className:"hidden lg:flex",children:o(Z7,{metrics:ie})}),u("div",{className:"flex items-center gap-1 shrink-0",children:[u("button",{onClick:async()=>{await a({title:`Disable "${C}"?`,message:"The device will stop processing streams and events. You can re-enable it later.",confirmLabel:"Disable",variant:"danger"})&&Q.mutate({deviceId:t})},disabled:J,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:[o(d0,{className:"h-3.5 w-3.5"}),o("span",{className:"hidden sm:inline",children:J?"Updating…":"Enabled"})]}),o("div",{className:"hidden sm:block h-5 w-px bg-border mx-1"}),o(My,{triggerClassName:"ml-1",items:[{id:"snapshot",label:"Take snapshot",description:"Fetch a fresh frame and download it.",icon:Cr,disabled:re,onClick:()=>{K()}},{id:"reboot",label:"Reboot device",description:"Camera goes offline for ~30 seconds.",icon:yt,hidden:!se,disabled:G.isPending,danger:!0,onClick:async()=>{await a({title:`Reboot "${C}"?`,message:"The camera will go offline for around 30 seconds while the firmware reboots.",confirmLabel:"Reboot",variant:"danger"})&&G.mutate({deviceId:t})}},{id:"restart-addon",label:"Restart addon",description:`Bounces every device served by ${F?.name??I}.`,icon:ht,disabled:ee.isPending,danger:!0,onClick:async()=>{await a({title:`Restart "${F?.name??I}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${C}"). Streams will reconnect automatically.`,confirmLabel:"Restart",variant:"danger"})&&ee.mutate({addonId:I})}},{id:"delete",label:"Delete device",description:"Remove the device and all its settings.",icon:Ke,separatorBefore:!0,disabled:H.isPending,danger:!0,onClick:async()=>{await a({title:`Delete "${C}"?`,message:"This will remove the device and all its settings. This action cannot be undone.",confirmLabel:"Delete",variant:"danger"})&&H.mutate({deviceId:t})}}]})]})]})]}),o($g,{deviceId:t,device:k??void 0,children:o(yy,{children:o(Iy,{children:u("main",{className:T?"flex-1 overflow-y-auto flex flex-col":"flex-1 min-h-0 overflow-hidden flex flex-row",children:[u("div",{className:T?"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:!T&&h!==null?{width:`${String(h)}px`}:void 0,children:[o("div",{className:`flex-shrink-0 border-b border-border-subtle ${B?"aspect-video bg-black":"bg-surface"}`,children:B?o(l7,{deviceId:t,intercomAvailable:z.includes(Hn.TwoWayAudio)}):o(D7,{deviceId:t,deviceName:C,deviceType:$??"unknown",provider:I,isOnline:E,features:z})}),u("div",{className:T?"flex flex-col border-b border-border":"flex-1 min-h-0 flex flex-col overflow-hidden",children:[o("div",{className:"flex-shrink-0 border-b border-border-subtle px-2 py-1.5",children:o("div",{className:"flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5",children:j.map(({id:de,label:ce,icon:Se})=>u("button",{onClick:()=>f(de),title:ce,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${d===de?"bg-primary/15 text-primary":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,children:[o(Se,{className:"h-3 w-3"}),ce]},de))})}),u("div",{className:T?"h-72 overflow-hidden":"flex-1 min-h-0 overflow-hidden",children:[d==="logs"&&o(c7,{deviceId:t}),d==="repl"&&o(d7,{deviceId:t}),d==="events"&&o(p7,{deviceId:t}),d==="state"&&o(f7,{deviceId:t}),d==="ptz"&&o(u7,{deviceId:t})]})]})]}),!T&&o("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:o("span",{className:"absolute inset-y-0 -left-1 -right-1"})}),u("div",{className:T?"flex flex-col":"flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden",children:[o("div",{className:"flex-shrink-0 border-b border-border bg-surface px-4",children:o("div",{className:"flex flex-wrap items-center gap-0",children:_.map(de=>{const ce=l===de.id;return u("button",{onClick:()=>c(de.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${ce?"text-primary":"text-foreground-subtle hover:text-foreground"}`,children:[de.label,ce&&o("span",{className:"absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary"})]},de.id)})})}),u("div",{className:T?"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"&&O&&o(h7,{parentDeviceId:t}),ue()]})]})]})})})})]}):u("div",{className:"flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle",children:[o("p",{className:"text-lg font-semibold text-foreground",children:"Invalid device id"}),u("p",{className:"text-xs",children:["The URL segment ",o("code",{className:"font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]",children:e.deviceId})," is not a number."]}),o("button",{onClick:()=>r("/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 Z7({metrics:e}){const t=e.phase??"idle",n=rr(t);return u("div",{className:"flex items-center gap-3 flex-shrink-0",children:[u("div",{className:"flex items-center gap-1.5",children:[o("span",{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),o("span",{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),o("div",{className:"h-3 w-px bg-border"}),u("div",{className:"flex items-center gap-1 text-[10px] text-foreground-subtle",children:[o(qo,{className:"h-3 w-3"}),o("span",{className:"text-foreground tabular-nums",children:(e.actualFps??0).toFixed(1)}),o("span",{children:"fps"})]}),u("div",{className:"flex items-center gap-1 text-[10px] text-foreground-subtle",children:[o(ft,{className:"h-3 w-3"}),o("span",{className:"text-foreground tabular-nums",children:(e.avgInferenceTimeMs??0).toFixed(0)}),o("span",{children:"ms"})]}),(e.queueDepth??0)>0&&u("span",{className:"text-[10px] text-warning tabular-nums",children:["q:",e.queueDepth]})]})}function X7({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:s}){const a=n==="upload"||n==="local",{data:i,isLoading:l}=Bg({name:e},{staleTime:5*6e4});return u("div",{className:"fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden",style:{top:"auto",bottom:"auto"},ref:c=>{if(!c)return;const d=c.parentElement?.getBoundingClientRect();if(!d)return;const f=window.innerHeight-d.bottom,p=d.top;f<280&&p>f?(c.style.bottom=`${window.innerHeight-d.top+4}px`,c.style.top="auto"):(c.style.top=`${d.bottom+4}px`,c.style.bottom="auto"),c.style.right=`${window.innerWidth-d.right}px`},onClick:c=>c.stopPropagation(),children:[u("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border",children:[o("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle font-medium",children:"Versions"}),o("button",{type:"button",onClick:s,className:"text-foreground-subtle hover:text-foreground",children:o(Fe,{className:"h-3 w-3"})})]}),a&&u("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]",children:[o(za,{className:"h-3 w-3 mt-0.5 text-cyan-500 shrink-0"}),u("div",{className:"text-cyan-700 dark:text-cyan-200",children:[u("span",{className:"font-semibold",children:[n==="upload"?"Uploaded copy":"Local copy"," in place."]})," ","Re-install ",o("span",{className:"font-mono",children:t})," from npm to track upstream releases again."]})]}),l&&u("div",{className:"flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle",children:[o(Ee,{className:"h-3.5 w-3.5 animate-spin"}),"Loading versions..."]}),i&&o("div",{className:"max-h-64 overflow-auto divide-y divide-border",children:i.map(c=>{const d=c.version===t,f=/-(alpha|beta|rc|dev|canary|next)/i.test(c.version);return u("div",{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${d?"bg-primary/5":"hover:bg-surface-hover"} transition-colors`,children:[o("span",{className:`font-mono flex-1 ${d?"text-primary font-semibold":f?"text-amber-400":"text-foreground"}`,children:c.version}),c.distTags.map(p=>o("span",{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${p==="latest"?"bg-emerald-500/15 text-emerald-400":p==="beta"?"bg-amber-500/15 text-amber-400":"bg-gray-500/15 text-gray-400"}`,children:p},p)),c.deprecated&&o("span",{className:"text-[9px] text-red-400 line-through",children:"deprecated"}),o("span",{className:"text-[9px] text-foreground-subtle shrink-0",children:new Date(c.publishedAt).toLocaleDateString()}),d&&!a?o(Mt,{className:"h-3 w-3 text-primary shrink-0"}):o("button",{type:"button",onClick:()=>r(c.version),className:"shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors",title:d?`Re-install ${c.version} from npm`:`Install ${c.version}`,children:o(Cn,{className:"h-3 w-3"})})]},c.version)})}),i&&i.length===0&&o("div",{className:"py-4 text-center text-[10px] text-foreground-subtle",children:"No versions found"})]})}function J7({isBundle:e,installSource:t}){return u("div",{className:"relative flex-shrink-0",children:[o("div",{className:`h-9 w-9 rounded-lg flex items-center justify-center ${e?"bg-indigo-500/20 text-indigo-700 dark:text-indigo-300":"bg-purple-500/20 text-purple-700 dark:text-purple-300"}`,children:e?o(l0,{className:"h-4 w-4"}):o(No,{className:"h-4 w-4"})}),t==="local"&&o("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"&&o("span",{className:"absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm",children:o("svg",{viewBox:"0 0 780 250",className:"w-[11px] h-[11px]",children:o("path",{fill:"#fff",d:"M240 250h100V50h100v200h340V0H0v250z"})})}),t==="upload"&&o("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:o(za,{className:"h-2.5 w-2.5 text-white"})})]})}function eB({addonId:e}){const t=ke(),{data:n="inherit"}=jg({addonId:e},{staleTime:3e4}),r=Hg({onSuccess:()=>{t.invalidateQueries({queryKey:[["addons","getAddonAutoUpdate"]]})}});return o("div",{className:"flex rounded-lg border border-border overflow-hidden text-[10px] font-medium",children:["inherit","off","latest","beta"].map(s=>o("button",{type:"button",onClick:a=>{a.stopPropagation(),r.mutate({addonId:e,channel:s})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===s?s==="inherit"?"bg-gray-700/50 text-gray-700 dark:text-gray-300":s==="off"?"bg-gray-700 text-gray-700 dark:text-gray-300":s==="latest"?"bg-blue-500/20 text-blue-400":"bg-amber-500/20 text-amber-400":"bg-transparent text-foreground-subtle hover:bg-surface-hover"} ${s!=="inherit"?"border-l border-border":""}`,children:s},s))})}function Vl({addon:e,agents:t=[],clusterStatus:n,hideVersion:r,availableUpdate:s,onUpdate:a,isUpdating:i,bundle:l}){const[c,d]=P(!1),[f,p]=P(!1),[h,m]=P(!1),[g,b]=P(!1),[x,y]=P(!1),[w,v]=P("logs"),N=ke(),k=Je(),{manifest:C}=e,E=e.installedOn??[],A=!l&&!C.protected&&C.removable!==!1,I=!!l,z=l?.displayName??C.name,$=l?.packageName??C.packageName,B=l?.version??C.packageVersion??C.version,R=l?.installSource??e.installSource,M=l?l.bundle?.description??l.addons[0]?.manifest.description:C.description;!l&&(C.components&&C.components.length>0||t.length>=2);const T=Dg({onSuccess:()=>{N.invalidateQueries({queryKey:[["addons"]]}),N.invalidateQueries({queryKey:[["addonPages"]]}),N.invalidateQueries({queryKey:[["capabilities"]]})}}),_=Ca({onSuccess:()=>{N.invalidateQueries({queryKey:[["addons"]]})}}),L=Fc({onSuccess:()=>{N.invalidateQueries({queryKey:[["addons"]]}),N.invalidateQueries({queryKey:[["addonPages"]]}),N.invalidateQueries({queryKey:[["capabilities"]]}),N.invalidateQueries({queryKey:[["integrations"]]})}}),O=zg({onSuccess:()=>{N.invalidateQueries({queryKey:[["addons"]]}),N.invalidateQueries({queryKey:[["alerts"]]})}}),j=e.health,F=j?.phase==="failed"&&!j.inGracePeriod,H=F&&j?.nextRetryAt&&!j.retrying;return u("div",{className:`rounded-lg border bg-surface overflow-hidden ${F?"border-red-500/50":"border-border"}`,children:[F&&j&&u("div",{className:"bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5",children:[o(QR,{className:"h-4 w-4 text-danger shrink-0 mt-0.5"}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"text-xs font-semibold text-danger",children:["Failed to load (attempt #",j.retryCount,")"]}),o("div",{className:"text-[11px] text-foreground mt-0.5 break-words font-mono",children:j.lastError?.message??"Unknown error"}),H&&j.nextRetryAt&&u("div",{className:"text-[10px] text-foreground-subtle mt-1",children:["Auto-retry at ",new Date(j.nextRetryAt).toLocaleTimeString()]})]}),u("button",{type:"button",disabled:O.isPending||j.retrying,onClick:D=>{D.stopPropagation(),O.mutate({packageName:$})},className:"inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0",title:"Reset retry counter and force immediate reload",children:[o(ht,{className:`h-3 w-3 ${O.isPending||j.retrying?"animate-spin":""}`}),"Retry now"]})]}),u("div",{className:"flex items-start gap-3 px-4 py-3",children:[o(J7,{isBundle:I||!!C.components&&C.components.length>1,installSource:R}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2",children:[o("span",{className:"text-sm font-semibold text-foreground truncate",children:z}),u("span",{className:"text-[10px] text-foreground-subtle font-mono shrink-0",children:["(",$,")"]}),I&&u("span",{className:"text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1",children:[o(l0,{className:"h-3 w-3"}),l.addons.length]})]}),M&&o("p",{className:"text-[10px] text-foreground-subtle mt-0.5 line-clamp-1",children:M}),!I&&e.process&&u("div",{className:"flex items-center gap-1.5 mt-1",children:[o("span",{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode==="forked"?"bg-blue-500/15 text-blue-400":"bg-gray-500/15 text-gray-400"}`,children:e.process.mode==="forked"?"forked":"in-process"}),e.process.pid!=null&&u("span",{className:"text-[9px] font-mono text-foreground-subtle",children:["PID ",e.process.pid]}),o("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})]})]}),!r&&u("div",{className:"relative inline-flex items-center gap-1.5 shrink-0 pt-0.5",children:[i?u("span",{className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400",children:[o(Ee,{className:"h-3 w-3 animate-spin"}),"Updating to ",s,"…"]}):s&&a?u("button",{type:"button",onClick:D=>{D.stopPropagation(),a()},className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-semibold border border-primary/40 bg-primary/10 text-primary hover:bg-primary/20 transition-colors animate-pulse",title:`Update to ${s}`,children:[o(Cn,{className:"h-3 w-3"}),s]}):null,u("button",{type:"button",onClick:D=>{D.stopPropagation(),m(Q=>!Q)},className:["inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors",R==="local"?"border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20":s?"border-amber-500/30 bg-amber-500/10 text-amber-400 hover:bg-amber-500/20":"border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20"].join(" "),title:s?`Current ${B} — newer ${s} available`:"View all versions",children:[B,o(Nt,{className:"h-3 w-3 opacity-50"})]}),h&&o(X7,{packageName:$,currentVersion:B,...R?{installSource:R}:{},onInstall:D=>{m(!1),L.mutate({packageName:$,version:D})},onClose:()=>m(!1)})]})]}),!I&&u("div",{className:"flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20",children:[u("button",{type:"button",onClick:D=>{D.stopPropagation(),_.mutate({addonId:C.id})},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-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors",children:[o(ht,{className:`h-3 w-3 ${_.isPending?"animate-spin":""}`}),"Restart"]}),u("button",{type:"button",onClick:D=>{D.stopPropagation(),b(Q=>!Q)},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:[o(rt,{className:"h-3 w-3"}),"Logs"]}),!I&&u("button",{type:"button",onClick:D=>{D.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:[o(Yt,{className:"h-3 w-3"}),"Settings"]}),o("div",{className:"flex-1"}),A&&u("button",{type:"button",onClick:async D=>{D.stopPropagation(),await k({title:`Uninstall ${C.name}?`,message:"This will remove the addon package and all its data. This action cannot be undone.",confirmLabel:"Uninstall",variant:"danger"})&&T.mutate({packageName:C.packageName})},disabled:T.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:[o(Ke,{className:"h-3 w-3"}),T.isPending?"Removing...":"Uninstall"]})]}),n&&n.nodes.length>1&&!I&&u("div",{className:"border-t border-border px-4 py-2 bg-muted/10",children:[o("div",{className:"text-[10px] font-medium text-foreground-subtle mb-1.5",children:"Cluster Deployment"}),o("div",{className:"space-y-1",children:n.nodes.map(D=>u("div",{className:"flex items-center gap-2 text-[10px]",children:[o("div",{className:`h-1.5 w-1.5 rounded-full shrink-0 ${D.status==="offline"?"bg-muted-foreground/30":D.synced?"bg-success":"bg-amber-500"}`}),o("span",{className:"font-medium text-foreground min-w-[60px]",children:D.name}),o("span",{className:"font-mono text-foreground-subtle",children:D.version}),!D.synced&&D.status!=="offline"&&o("span",{className:"text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20",children:"outdated"}),D.status==="offline"&&o("span",{className:"text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground",children:"offline"}),D.synced&&D.status!=="offline"&&o("span",{className:"text-[9px] text-success",children:"synced"})]},D.nodeId))})]}),g&&!I&&u("div",{className:"border-t border-border",children:[u("div",{className:"flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50",children:[u("div",{className:"flex rounded border border-border overflow-hidden text-[9px]",children:[o("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"}),o("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"})]}),o("div",{className:"flex-1"}),o("button",{type:"button",onClick:D=>{D.stopPropagation(),b(!1)},className:"text-foreground-subtle hover:text-foreground",children:o(Fe,{className:"h-3.5 w-3.5"})})]}),w==="logs"&&o(Xt,{addonId:C.id,maxHeight:"max-h-64",showFilters:!1}),w==="events"&&o(cr,{addonId:C.id,category:"addon.*",maxHeight:"max-h-64"})]}),I&&u(me,{children:[o("button",{type:"button",onClick:()=>d(D=>!D),className:"w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors",children:c?o(RL,{className:"h-3.5 w-3.5 text-foreground-subtle"}):o(Nt,{className:"h-3.5 w-3.5 text-foreground-subtle"})}),c&&o("div",{className:"border-t border-border px-3 py-2 space-y-2",children:l.addons.map(D=>o(Vl,{addon:D,agents:t,hideVersion:!0},D.manifest.id))})]}),x&&!I&&o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",onClick:()=>y(!1),children:u("div",{className:"w-full max-w-lg max-h-[80vh] rounded-xl border border-border bg-surface shadow-2xl flex flex-col overflow-hidden",onClick:D=>D.stopPropagation(),children:[u("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0",children:[u("div",{className:"flex items-center gap-2",children:[o(Yt,{className:"h-4 w-4 text-primary"}),u("h2",{className:"text-sm font-semibold text-foreground",children:[z," Settings"]})]}),o("button",{onClick:()=>y(!1),className:"text-foreground-subtle hover:text-foreground transition-colors p-1 rounded",children:o(Fe,{className:"h-4 w-4"})})]}),u("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-4",children:[o(Qr,{nodeId:"hub",addonIds:[C.id],level:"global"}),R==="npm"&&u("div",{children:[o("div",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:"Auto-Update"}),o(eB,{addonId:C.id})]}),C.components&&C.components.length>0&&u("div",{children:[u("div",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:["Components (",C.components.length,")"]}),o("div",{className:"flex flex-wrap gap-1",children:C.components.map(D=>o("span",{className:"text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono",children:D},D))})]}),t.length>=2&&u("div",{children:[o("div",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2",children:"Installed on"}),u("div",{className:"flex items-center gap-1.5 flex-wrap",children:[E.length===0&&o("span",{className:"text-[10px] text-foreground-subtle",children:"Hub (local)"}),E.map(D=>o("span",{className:"rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle",children:D},D)),u("div",{className:"relative",children:[u("button",{type:"button",onClick:D=>{D.stopPropagation(),p(Q=>!Q)},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:[o(ot,{className:"h-3 w-3"}),"Add agent"]}),f&&u("div",{className:"absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden",children:[t.filter(D=>!D.isHub&&!E.includes(D.name)).map(D=>o("button",{type:"button",onClick:Q=>{Q.stopPropagation(),p(!1)},className:"w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors",children:D.name},D.id)),t.filter(D=>!D.isHub&&!E.includes(D.name)).length===0&&o("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle",children:"No available agents"})]})]})]})]})]}),o("div",{className:"flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0",children:o("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 tB=".tgz,.tar.gz,.zip";function nB({onUploadSuccess:e}){const[t,n]=P(!1),r=ne(null),s=U(async i=>{n(!0);const l=new FormData;l.append("file",i);const c=localStorage.getItem("camstack_admin_token")??"";try{(await(await fetch("/api/addons/upload",{method:"POST",headers:{Authorization:`Bearer ${c}`},body:l})).json()).success&&e()}finally{n(!1)}},[e]),a=U(i=>{const l=i.target.files?.[0];l&&s(l),i.target.value=""},[s]);return u(me,{children:[o("input",{ref:r,type:"file",accept:tB,onChange:a,className:"hidden"}),u("button",{type:"button",onClick:()=>r.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?o(Ee,{className:"w-3.5 h-3.5 animate-spin"}):o(za,{className:"w-3.5 h-3.5"}),t?"Uploading...":"Upload"]})]})}function rB(e,t){const n=e??"hub-only";return n==="any-node"?!0:n==="hub-only"?t:!t}function oB(e){const t=e;if(!t?.manifest)return null;const n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??"0.0.0",capabilities:t.manifest.capabilities??[]},r=t.process,s=r?{pid:r.pid,mode:r.mode==="forked"?"forked":"in-process",state:r.state??"unknown"}:void 0,a=t.health;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...s?{process:s}:{},hasBackup:t.hasBackup,...a?{health:a}:{}}}function sB(e){const t=new Map,n=[];for(const s of e){const a=s.manifest.packageName;if(!a){n.push(s);continue}const i=t.get(a);if(i)i.addons.push(s);else{const l=s.manifest.bundle,c={packageName:a,displayName:l?.displayName??s.manifest.packageDisplayName??s.manifest.name,version:s.manifest.packageVersion,addons:[s],...s.installSource!==void 0?{installSource:s.installSource}:{},...l!==void 0?{bundle:l}:{}};t.set(a,c)}}const r=[];for(const s of t.values())s.bundle!==void 0||s.addons.length>=2?r.push({bundle:s,representative:s.addons[0]}):r.push(s.addons[0]);return r.push(...n),r}function tn(e){return"bundle"in e}function aB({addons:e,clusterStatus:t,selectedNode:n,onRefresh:r,isRefreshing:s}){const a=ke(),[i,l]=P(""),c=yN(i),[d,f]=P(!1),p=ne(null);Y(()=>{if(!d)return;const D=Q=>{p.current&&!p.current.contains(Q.target)&&f(!1)};return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[d]);const{data:h}=jc(void 0,{staleTime:5*6e4}),m=q(()=>{const D=new Map;for(const Q of h??[])D.set(Q.name,Q.latestVersion);return D},[h]),[g,b]=P(null),[x,y]=P(null),w=kl({onMutate:D=>{b(D.name),y(null)},onSuccess:(D,Q)=>{b(null);const G=D;if(G&&G.success===!1){y({name:Q.name,message:G.error??"Update failed (no error message returned by server)"});return}a.invalidateQueries({queryKey:[["addons"]]}),a.invalidateQueries({queryKey:[["addons","listUpdates"]]})},onError:(D,Q)=>{b(null),y({name:Q.name,message:D instanceof Error?D.message:String(D)})}}),{data:v}=Fg(void 0,{staleTime:3e4}),N=Vg({onSuccess:()=>{a.invalidateQueries({queryKey:[["addons","getAutoUpdateSettings"]]})}}),{data:k,isFetching:C}=Lg({query:c||void 0},{enabled:d,staleTime:6e4}),E=kl(),A=async()=>{const D=h??[];for(const Q of D)await E.mutateAsync({name:Q.name,version:Q.latestVersion});a.invalidateQueries({queryKey:[["addons"]]})},I=Fc({onSuccess:()=>{a.invalidateQueries({queryKey:[["addons"]]}),a.invalidateQueries({queryKey:[["addonPages"]]}),a.invalidateQueries({queryKey:[["capabilities"]]}),a.invalidateQueries({queryKey:[["integrations"]]})}}),[z,$]=P("type"),[B,R]=P(()=>typeof window>"u"?"grouped":window.localStorage.getItem("camstack.addons.viewMode")==="flat"?"flat":"grouped"),M=D=>{R(D),typeof window<"u"&&window.localStorage.setItem("camstack.addons.viewMode",D)},[T,_]=La(),L=T.get("capability"),O=q(()=>{let D=n.isHub?e:e.filter(Q=>{const G=Q.manifest.execution;return rB(G?.placement,n.isHub)});return L&&(D=D.filter(Q=>(Q.manifest.capabilities??[]).some(ee=>(typeof ee=="string"?ee:ee.name)===L))),D},[e,n.isHub,L]),j=()=>{const D=new URLSearchParams(T);D.delete("capability"),_(D,{replace:!0})},F=B==="flat"?O:sB(O),H=q(()=>{const D=[...F];switch(z){case"type":D.sort((Q,G)=>{const ee=tn(Q)?0:1,se=tn(G)?0:1;if(ee!==se)return ee-se;const te=tn(Q)?Q.bundle.displayName:Q.manifest.name,Z=tn(G)?G.bundle.displayName:G.manifest.name;return te.localeCompare(Z)});break;case"name":D.sort((Q,G)=>{const ee=tn(Q)?Q.bundle.displayName:Q.manifest.name,se=tn(G)?G.bundle.displayName:G.manifest.name;return ee.localeCompare(se)});break;case"source":D.sort((Q,G)=>{const ee=tn(Q)?Q.bundle.installSource??"":Q.installSource??"",se=tn(G)?G.bundle.installSource??"":G.installSource??"";return ee.localeCompare(se)});break}return D},[F,z]);return u("div",{className:"space-y-4",children:[x&&o("div",{className:"rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]",children:u("div",{className:"flex items-start justify-between gap-3",children:[u("div",{className:"space-y-0.5",children:[u("div",{className:"font-medium text-danger",children:["Failed to update ",x.name]}),o("div",{className:"text-foreground-subtle font-mono",children:x.message})]}),o("button",{type:"button",onClick:()=>y(null),className:"text-foreground-subtle hover:text-foreground text-[10px]",children:"dismiss"})]})}),u("div",{className:"flex items-center gap-2 flex-wrap",children:[u("div",{className:"flex items-center gap-1.5",children:[o("span",{className:"text-[10px] text-foreground-subtle",children:"Sort:"}),u("select",{value:z,onChange:D=>$(D.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:[o("option",{value:"type",children:"Bundles first"}),o("option",{value:"name",children:"Name"}),o("option",{value:"source",children:"Install source"})]})]}),u("div",{className:"flex items-center gap-1.5",children:[o("span",{className:"text-[10px] text-foreground-subtle",children:"View:"}),o("div",{className:"flex rounded-md border border-border overflow-hidden text-[10px] font-medium",children:["grouped","flat"].map(D=>o("button",{type:"button",onClick:()=>M(D),className:`px-2.5 py-1.5 transition-colors capitalize ${B===D?"bg-primary/10 text-primary":"bg-transparent text-foreground-subtle hover:bg-surface-hover"}`,title:D==="grouped"?"Group multi-addon packages into a bundle card":"Show every addon as its own card",children:D},D))})]}),u("div",{className:"flex items-center gap-1.5",children:[o(ht,{className:"h-3 w-3 text-foreground-subtle"}),o("span",{className:"text-[10px] text-foreground-subtle",children:"Auto-Update:"}),o("div",{className:"flex rounded-md border border-border overflow-hidden text-[10px] font-medium",children:["off","latest","beta"].map(D=>o("button",{type:"button",onClick:()=>N.mutate({channel:D}),disabled:N.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${v?.channel===D?D==="off"?"bg-gray-700 text-gray-200":D==="latest"?"bg-blue-500/20 text-blue-400":"bg-amber-500/20 text-amber-400":"bg-transparent text-foreground-subtle hover:bg-surface-hover"} ${D!=="off"?"border-l border-border":""}`,children:D},D))})]}),(h?.length??0)>0&&u("button",{type:"button",onClick:()=>void A(),disabled:E.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:[o(Cn,{className:`w-3 h-3 ${E.isPending?"animate-bounce":""}`}),"Update All (",h.length,")"]}),u("button",{type:"button",onClick:r,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:[o(ht,{className:`w-3 h-3 ${s?"animate-spin":""}`}),"Refresh"]})]}),u("div",{className:"flex items-center gap-3",children:[u("div",{className:"relative flex-1 min-w-[200px]",ref:p,children:[o(p0,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle"}),o("input",{type:"text",value:i,onChange:D=>{l(D.target.value),f(!0)},onFocus:()=>f(!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"}),C&&o(Ee,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin"}),d&&k&&k.length>0&&u("div",{className:"absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden",children:[k.length>0&&u("div",{className:"px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border",children:["npm results (",k.length,")"]}),k&&k.length>0&&o("div",{className:"max-h-72 overflow-auto divide-y divide-border",children:k.map(D=>u("div",{className:"flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors",children:[o("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:D.name.replace("@camstack/addon-","").charAt(0).toUpperCase()}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2",children:[o("span",{className:"text-[11px] font-semibold truncate",children:D.name}),u("span",{className:"text-[10px] text-foreground-subtle",children:["v",D.version]})]}),D.description&&o("div",{className:"text-[10px] text-foreground-subtle truncate",children:D.description})]}),D.installed?u("span",{className:"inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md border border-emerald-500/30 bg-emerald-500/10 text-emerald-400 shrink-0",children:[o(Mt,{className:"h-3 w-3"}),D.installedVersion??"Installed"]}):u("button",{type:"button",onClick:()=>I.mutate({packageName:D.name}),disabled:I.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:[I.isPending?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Cn,{className:"h-3 w-3"}),"Install"]})]},D.name))})]})]}),o(nB,{onUploadSuccess:()=>{a.invalidateQueries({queryKey:[["addons"]]}),r()}})]}),L&&u("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm",children:[o("span",{className:"text-foreground-subtle",children:"Filtering by capability:"}),o("span",{className:"font-mono text-primary font-semibold",children:L}),o("button",{type:"button",onClick:j,className:"ml-auto text-xs text-foreground-subtle hover:text-foreground underline",children:"Clear"})]}),O.length===0&&o("div",{className:"text-xs text-foreground-subtle",children:e.length===0?"No addons installed":L?`No installed addons declare the "${L}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${n.name} (placement filter active)`}),o("div",{className:"space-y-2",children:H.map(D=>{if(tn(D)){const ee=D.bundle.packageName,se=m.get(ee);return o(Vl,{addon:D.representative,clusterStatus:t?.[D.representative.manifest.id],bundle:D.bundle,availableUpdate:se,isUpdating:g===ee,onUpdate:se?()=>w.mutate({name:ee,version:se}):void 0},ee)}const Q=D.manifest.packageName,G=m.get(Q);return o(Vl,{addon:D,clusterStatus:t?.[D.manifest.id],availableUpdate:G,isUpdating:g===Q,onUpdate:G?()=>w.mutate({name:D.manifest.packageName,version:G}):void 0},D.manifest.id)})})]})}function iB(){const e=ke(),{data:t,isLoading:n,isError:r}=Fo(),{data:s}=Yb(void 0,{staleTime:15e3}),{data:a}=Dn(void 0,{staleTime:3e4,refetchInterval:1e4}),i=q(()=>{const x=new Map;x.set("hub",{id:"hub",name:"Hub",isHub:!0});for(const y of a??[]){const w=String(y.id??"");w&&x.set(w,{id:w,name:String(y.name??w),isHub:!!y.isHub})}return[...x.values()]},[a]),[l,c]=P("hub"),d=i.find(x=>x.id===l)??i[0],f=Rg(),p=Tg(),h=f.isPending||p.isPending,m=async()=>{await f.mutateAsync(),await p.mutateAsync(),e.invalidateQueries({queryKey:[["addons"]]})},g=ne(f);g.current=f,Y(()=>{g.current.mutate()},[]);const b=(t??[]).map(oB).filter(x=>x!==null);return u(Xe,{children:[u("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[o(ig,{selectedNodeId:l,onSelect:c}),u("div",{className:"flex items-center gap-3 flex-wrap",children:[!n&&!r&&u("span",{className:"text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium",children:[b.length," installed"]}),u("button",{type:"button",onClick:()=>void m(),disabled:h,className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors",title:"Re-fetch addons + check npm for new versions",children:[o(ht,{className:`w-3 h-3 ${h?"animate-spin":""}`}),"Check for updates"]})]})]}),!d.isHub&&u("div",{className:"rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle",children:["Showing only addons compatible with"," ",o("span",{className:"font-medium text-foreground",children:d.name})," ","— agents only run ",o("code",{className:"font-mono",children:"agent-only"})," and"," ",o("code",{className:"font-mono",children:"any-node"})," addons. Install / uninstall is hub-driven; agents auto-sync from the hub."]}),n&&o("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading…"}),r&&o("div",{className:"text-xs text-danger",children:"Failed to load addons"}),!n&&!r&&o(aB,{addons:b,clusterStatus:s,selectedNode:d,onRefresh:()=>void m(),isRefreshing:h})]})}const lB={view:{icon:Go,cls:"bg-foreground-subtle/15 text-foreground-subtle"},create:{icon:Ur,cls:"bg-primary/15 text-primary"},delete:{icon:Ke,cls:"bg-danger/15 text-danger"}};function cB(){const{user:e,logout:t}=mn();if(!e)return o(Xe,{children:o("div",{className:"text-xs text-foreground-subtle",children:"Not signed in."})});const n=e.isAdmin,r=e.scopes??[];return u(Xe,{children:[u("div",{className:"text-xs text-foreground-subtle",children:["Signed in as ",o("span",{className:"font-medium text-foreground",children:e.username}),n?" (admin)":""]}),n&&u("div",{className:"rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5",children:[o(kn,{className:"h-4 w-4 text-primary mt-0.5 shrink-0"}),u("div",{children:[o("div",{className:"font-semibold text-foreground",children:"Unrestricted access"}),o("p",{className:"text-foreground-subtle mt-0.5",children:"Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below."})]})]}),r.length===0&&!n&&u("div",{className:"rounded-lg border border-warning/30 bg-warning/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5",children:[o(kn,{className:"h-4 w-4 text-warning mt-0.5 shrink-0"}),u("div",{children:[o("div",{className:"font-semibold text-foreground",children:"No scopes granted"}),u("p",{className:"text-foreground-subtle mt-0.5",children:["Your account doesn't have any capability or addon grants yet. Every protected endpoint will return 403 until an admin assigns you scopes from ",o("span",{className:"font-mono",children:"/system/users"}),"."]})]})]}),r.length>0&&u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border",children:[o("div",{children:"Type"}),o("div",{children:"Target"}),o("div",{children:"Access"})]}),o("ul",{className:"divide-y divide-border",children:r.map((s,a)=>u("li",{className:"grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs",children:[o("span",{className:"font-mono text-foreground-subtle",children:s.type}),o("span",{className:"font-mono text-foreground",children:s.type==="device"?s.targets.join(", "):s.target}),o("div",{className:"flex items-center gap-1",children:["view","create","delete"].map(i=>{const l=s.access.includes(i),{icon:c,cls:d}=lB[i];return u("span",{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${l?d:"bg-transparent text-foreground-subtle/40 line-through"}`,title:l?`Can ${i}`:`Cannot ${i}`,children:[o(c,{className:"h-3 w-3"}),i]},i)})})]},a))})]}),u("div",{className:"rounded-lg border border-border bg-surface px-4 py-3 text-xs text-foreground-subtle flex items-start gap-2.5",children:[o(kn,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),u("div",{className:"flex-1",children:[o("div",{className:"font-semibold text-foreground",children:"Updating access"}),u("p",{className:"mt-0.5",children:["Scopes are baked into your session token at login. Changes an admin makes via ",o("span",{className:"font-mono",children:"setUserScopes"})," take effect on your"," ",o("span",{className:"font-medium text-foreground",children:"next login"}),". Sign out and back in to refresh."]})]}),u("button",{onClick:t,className:"inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors shrink-0",children:[o(Ad,{className:"h-3 w-3"}),"Sign out"]})]})]})}function dB(){return o(Xe,{children:o("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:o(Xt,{limit:500,maxHeight:"max-h-[calc(100vh-250px)]",showScope:!0,showFilters:!0})})})}function Dd({tabs:e,defaultTab:t}){const[n,r]=La(),s=n.get("tab"),a=t??e[0]?.id??"",i=e.some(d=>d.id===s)?s:a,l=e.find(d=>d.id===i)??e[0],c=d=>{const f=new URLSearchParams(n);f.set("tab",d),r(f,{replace:!0})};return u("div",{className:"space-y-3",children:[o("div",{className:"flex border-b border-border",children:e.map(d=>{const f=d.icon,p=d.id===i;return u("button",{onClick:()=>c(d.id),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium border-b-2 transition-colors ${p?"border-primary text-primary":"border-transparent text-foreground-subtle hover:text-foreground"}`,children:[f&&o(f,{className:"h-3.5 w-3.5"}),d.label]},d.id)})}),o("div",{children:l?.content})]})}function uB({value:e,size:t=192}){const[n,r]=P(null),[s,a]=P(null);if(Y(()=>{let d=!1;return LN(()=>import("./browser-BXdiCFWD.js").then(f=>f.b),[]).then(async f=>{if(d)return;const p=f.create;if(typeof p!="function"){a("qrcode.create() unavailable in installed version");return}try{const h=p(e,{errorCorrectionLevel:"M"});d||r(h)}catch(h){d||a(h instanceof Error?h.message:"QR generation failed")}}).catch(()=>{d||a("qrcode library not installed")}),()=>{d=!0}},[e]),s)return o("div",{className:"flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4",style:{width:t,height:t},children:"QR rendering unavailable — use the secret below."});if(!n)return o("div",{className:"flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse",style:{width:t,height:t},children:"Generating…"});const i=n.modules.size,l=t/i,c=[];for(let d=0;d<i;d++)for(let f=0;f<i;f++)n.modules.data[d*i+f]&&c.push(o("rect",{x:f*l,y:d*l,width:l,height:l,fill:"currentColor"},`${f}-${d}`));return u("svg",{width:t,height:t,viewBox:`0 0 ${t} ${t}`,className:"text-black",children:[o("rect",{x:0,y:0,width:t,height:t,fill:"white"}),c]})}function pB({userId:e,username:t,onClose:n}){const r=ke(),s=Je(),a=ay({userId:e}),i=a.data,[l,c]=P(null),[d,f]=P(""),[p,h]=P(null),[m,g]=P(!1),b=()=>r.invalidateQueries({queryKey:[["userManagement","getTotpStatus"]]}),x=ry({onSuccess:A=>{c({secret:A.secret,otpauthUrl:A.otpauthUrl}),h(null),f(""),b()}}),y=oy({onSuccess:()=>{c(null),f(""),h(null),b()},onError:A=>{h(A instanceof Error?A.message:"Confirmation failed — code did not match")}}),w=sy({onSuccess:b}),v=q(()=>a.isLoading?"loading":l?"setup_in_progress":i?.enabled?"enrolled":i&&i.confirmedAt===null&&x.isSuccess?"setup_in_progress":"not_enrolled",[a.isLoading,i,l,x.isSuccess]);Y(()=>{if(!m)return;const A=setTimeout(()=>g(!1),1500);return()=>clearTimeout(A)},[m]);const N=()=>{c(null),x.mutate({userId:e})},k=()=>{h(null),y.mutate({userId:e,code:d.trim()})},C=async()=>{await s({title:"Disable TOTP",message:`Disable two-factor authentication for "${t}"? They'll be able to log in with just their password until a new TOTP enrollment is completed.`,confirmLabel:"Disable",variant:"danger"})&&w.mutate({userId:e})},E=()=>{l&&navigator.clipboard.writeText(l.secret).then(()=>g(!0))};return o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4",children:u("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden",children:[u("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[u("div",{className:"flex items-center gap-2",children:[o(Er,{className:"h-4 w-4 text-primary"}),u("div",{children:[o("div",{className:"text-sm font-medium text-foreground",children:"Two-factor authentication"}),u("div",{className:"text-[11px] text-foreground-subtle",children:["User: ",o("span",{className:"font-mono",children:t})]})]})]}),o("button",{onClick:n,className:"p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle",children:o(Fe,{className:"h-4 w-4"})})]}),u("div",{className:"p-4 space-y-4",children:[v==="loading"&&u("div",{className:"flex items-center gap-2 text-xs text-foreground-subtle",children:[o(Ee,{className:"h-3.5 w-3.5 animate-spin"}),"Checking status…"]}),v==="not_enrolled"&&u(me,{children:[u("div",{className:"space-y-2",children:[o("div",{className:"text-xs text-foreground",children:"TOTP is not enrolled for this user. Click below to generate a fresh secret + QR code."}),u("ul",{className:"text-[11px] text-foreground-subtle pl-4 list-disc space-y-1",children:[o("li",{children:"Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc."}),o("li",{children:"The secret is shown ONCE — copy it to a secure place if you can't scan the QR."}),o("li",{children:"Enrollment isn't active until the user submits a valid 6-digit code below."})]})]}),x.isError&&u("div",{className:"rounded border border-danger/40 bg-danger/5 px-3 py-2 flex items-start gap-2 text-[11px] text-danger",children:[o(Mr,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),x.error instanceof Error?x.error.message:"Setup failed"]}),o("div",{className:"flex justify-end",children:u(Oe,{onClick:N,disabled:x.isPending,children:[x.isPending?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Er,{className:"h-3 w-3"}),"Enable TOTP"]})})]}),v==="setup_in_progress"&&l&&u(me,{children:[u("div",{className:"flex flex-col items-center gap-3",children:[o("div",{className:"rounded-lg border border-border bg-white p-3",children:o(uB,{value:l.otpauthUrl,size:180})}),u("div",{className:"w-full",children:[o("div",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle mb-1",children:"Secret (manual entry)"}),u("div",{className:"flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5",children:[o("code",{className:"text-[11px] font-mono text-foreground break-all flex-1",children:l.secret}),u("button",{onClick:E,className:"inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground",children:[m?o(Ei,{className:"h-3 w-3 text-emerald-500"}):o(e0,{className:"h-3 w-3"}),m?"Copied":"Copy"]})]})]})]}),u("div",{className:"space-y-1.5",children:[o("label",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:"Enter the 6-digit code from the authenticator app"}),o("input",{type:"text",inputMode:"numeric",autoComplete:"one-time-code",placeholder:"123456",value:d,onChange:A=>f(A.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary"}),p&&u("div",{className:"rounded border border-danger/40 bg-danger/5 px-2 py-1.5 flex items-start gap-1.5 text-[11px] text-danger",children:[o(Mr,{className:"h-3 w-3 mt-0.5 shrink-0"}),p]})]}),u("div",{className:"flex justify-end gap-2",children:[o("button",{onClick:()=>c(null),className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),u(Oe,{onClick:k,disabled:y.isPending||d.length!==6,variant:"primary",children:[y.isPending?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Ei,{className:"h-3 w-3"}),"Confirm"]})]})]}),v==="enrolled"&&i&&u(me,{children:[u("div",{className:"rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5",children:[o(Ei,{className:"h-4 w-4 mt-0.5 text-emerald-500 shrink-0"}),u("div",{className:"text-xs text-foreground space-y-0.5",children:[o("div",{className:"font-medium",children:"TOTP is active"}),u("div",{className:"text-foreground-subtle",children:["Enrolled on ",i.confirmedAt?new Date(i.confirmedAt).toLocaleString():"—"]})]})]}),o("div",{className:"text-[11px] text-foreground-subtle",children:"The user must enter a code from their authenticator app at every login. Disabling here removes the secret from the server; the user keeps their app entry until they remove it manually."}),u("div",{className:"flex justify-end gap-2",children:[o(Oe,{onClick:n,variant:"secondary",children:"Close"}),u("button",{onClick:C,disabled:w.isPending,className:"rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1",children:[w.isPending?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Fe,{className:"h-3 w-3"}),"Disable TOTP"]})]})]})]})]})})}function fB(){const e=ke(),[t,n]=P(!1),[r,s]=P(""),[a,i]=P(""),[l,c]=P(!1),[d,f]=P(null),{data:p,isLoading:h,isError:m}=nd(),g=Je(),b=()=>e.invalidateQueries({queryKey:[["userManagement","listUsers"]]}),x=Kx({onSuccess:()=>{b(),n(!1),s(""),i(""),c(!1),f(null)},onError:M=>{f(M instanceof Error?M.message:"Failed to create user")}}),y=Yx({onSuccess:b}),w=Wx({onSuccess:b}),v=rd({onSuccess:b}),N=Zx({onSuccess:()=>{b(),C(null)}}),[k,C]=P(null),[E,A]=P(null),I=p??[];async function z(M){await g({title:"Delete user",message:`Permanently delete user "${M.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:"Delete",variant:"danger"})&&y.mutate({id:M.id})}async function $(M){const T=window.prompt(`New password for "${M.username}":`);if(!T)return;if(T.length<8){window.alert("Password must be at least 8 characters.");return}await g({title:"Reset password",message:`Reset the password for "${M.username}"? They will need to use the new password on their next login.`,confirmLabel:"Reset"})&&v.mutate({id:M.id,newPassword:T})}function B(M,T){T!==M.isAdmin&&w.mutate({id:M.id,isAdmin:T})}function R(M){return M?new Date(typeof M=="number"?M:String(M)).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"}):"—"}return u(Xe,{children:[o("div",{className:"flex items-center justify-end",children:u("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:[o(ot,{className:"h-3.5 w-3.5"}),"Create User"]})}),t&&u("div",{className:"rounded-lg border border-border bg-surface p-4 space-y-3",children:[u("div",{className:"flex items-center justify-between",children:[o("span",{className:"text-xs font-medium text-foreground",children:"New User"}),o("button",{onClick:()=>n(!1),className:"text-foreground-subtle hover:text-foreground",children:o(Fe,{className:"h-4 w-4"})})]}),u("div",{className:"grid grid-cols-3 gap-3",children:[u("div",{className:"space-y-1",children:[o("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Username"}),o("input",{type:"text",value:r,onChange:M=>s(M.target.value),placeholder:"john",className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary"})]}),u("div",{className:"space-y-1",children:[o("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Password"}),o("input",{type:"password",value:a,onChange:M=>i(M.target.value),placeholder:"••••••••",className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary"})]}),u("div",{className:"space-y-1",children:[o("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Admin"}),u("label",{className:"flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer",children:[o("input",{type:"checkbox",checked:l,onChange:M=>c(M.target.checked),className:"rounded border-border focus:ring-primary"}),o("span",{className:"text-foreground-subtle",children:"Unrestricted access"})]})]})]}),d&&o("p",{className:"text-[10px] text-danger",children:d}),u("div",{className:"flex justify-end gap-2",children:[o("button",{onClick:()=>n(!1),className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),o("button",{onClick:()=>x.mutate({username:r,password:a,isAdmin:l}),disabled:x.isPending||!r||!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:x.isPending?"Creating...":"Create"})]})]}),h&&o("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading..."}),m&&o("div",{className:"text-xs text-danger",children:"Failed to load"}),!h&&!m&&I.length===0&&o("div",{className:"text-xs text-foreground-subtle",children:"No data"}),(()=>{const M=_=>y.isPending&&y.variables?.id===_.id||w.isPending&&w.variables?.id===_.id||v.isPending&&v.variables?.id===_.id;return o(ng,{columns:[{key:"username",header:"Username",render:_=>_.username},{key:"isAdmin",header:"Admin",render:_=>u("label",{className:"inline-flex items-center gap-1.5 text-xs cursor-pointer",children:[o("input",{type:"checkbox",checked:_.isAdmin,onChange:L=>B(_,L.target.checked),disabled:M(_),className:"rounded border-border focus:ring-primary disabled:opacity-50"}),o("span",{className:_.isAdmin?"text-primary font-medium":"text-foreground-subtle",children:_.isAdmin?"Admin":"Regular"})]})},{key:"scopes",header:"Scopes",render:_=>{if(_.isAdmin)return o("span",{className:"text-[10px] text-foreground-subtle italic",children:"unscoped"});const L=_.scopes??[];return u("button",{onClick:()=>C(_),className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground",title:"Edit scope grants",children:[o(dn,{className:"h-3 w-3"}),L.length===0?"no access":`${L.length} grant${L.length===1?"":"s"}`]})}},{key:"createdAt",header:"Created",render:_=>o("span",{className:"text-foreground-subtle",children:R(_.createdAt)})},{key:"actions",header:"Actions",align:"right",render:_=>{const L=M(_);return u("div",{className:"flex items-center justify-end gap-1",children:[u("button",{onClick:()=>A(_),disabled:L,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50",title:"Two-factor authentication",children:[o(Er,{className:"h-3 w-3"}),"2FA"]}),u("button",{onClick:()=>$(_),disabled:L,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50",title:"Reset password",children:[o(xR,{className:"h-3 w-3"}),"Reset password"]}),u("button",{onClick:()=>z(_),disabled:L,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50",title:"Delete user",children:[L?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Ke,{className:"h-3 w-3"}),"Delete"]})]})}}],rows:I,rowKey:_=>_.id,minWidthPx:560})})(),E&&o(pB,{userId:E.id,username:E.username,onClose:()=>A(null)}),k&&o(hB,{user:k,onClose:()=>C(null),onSubmit:M=>N.mutate({userId:k.id,scopes:M}),submitting:N.isPending})]})}function hB(e){const{user:t}=mn(),n=t?.isAdmin===!0;return o(mB,{...e,callerScopes:n?null:t?.scopes??[]})}function mB({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:s}){const a=q(()=>(e.scopes??[]).map(d=>({...d,access:[...d.access]})),[e.scopes]),[i,l]=P(a),c=fd(i);return o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",children:u("div",{className:"w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl",children:[u("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[u("div",{children:[u("div",{className:"text-sm font-semibold text-foreground",children:["Edit scopes — ",e.username]}),o("div",{className:"text-[10px] text-foreground-subtle",children:e.isAdmin?"Admin users bypass the scope check; this list is ignored.":"Pick which capabilities this user can call, and which access flavours within each."})]}),o("button",{onClick:t,className:"text-foreground-subtle hover:text-foreground",children:o(Fe,{className:"h-4 w-4"})})]}),u("div",{className:"px-4 py-4",children:[o(pd,{value:i,onChange:l,clampToParent:s,emptyHint:u(me,{children:["No scopes granted. ",o("span",{className:"font-medium text-foreground",children:e.username})," cannot call any protected endpoint until a scope is added."]})}),c&&o("p",{className:"mt-2 text-[10px] text-danger",children:c})]}),u("div",{className:"flex items-center justify-end gap-2 border-t border-border px-4 py-3",children:[o("button",{onClick:t,className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),o("button",{onClick:()=>n(i),disabled:r||c!==null,className:"rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:r?o(Ee,{className:"h-3 w-3 animate-spin"}):"Save scopes"})]})]})})}const gB="bg-primary/10 text-primary",bB="bg-foreground-subtle/10 text-foreground-subtle";function fo(e){if(!e)return"—";const t=new Date(e);return Number.isNaN(t.getTime())?"—":t.toLocaleString()}function xB(e){return e?e==="*"?"*":e.join(", "):""}function yB(){const e=ke(),t=Je(),{data:n,isLoading:r}=Xx(),{data:s}=nd(),a=q(()=>n??[],[n]),i=q(()=>s??[],[s]),l=()=>e.invalidateQueries({queryKey:[["userManagement","listApiKeys"]]}),c=()=>e.invalidateQueries({queryKey:[["userManagement","listScopedTokens"]]}),[d,f]=P(!1),[p,h]=P(null),m=Jx({onSuccess:l}),g=ey({onSuccess:({token:w,record:v})=>{c(),f(!1),h({token:w,label:v.name})}}),b=ty({onSuccess:c}),x=async(w,v)=>{await t({title:`Revoke "${v}"?`,message:"Any client using this token will lose access immediately. This cannot be undone.",confirmLabel:"Revoke",variant:"danger"})&&m.mutate({id:w})},y=async(w,v)=>{await t({title:`Revoke "${v}"?`,message:"The scoped token will be invalid on its next use.",confirmLabel:"Revoke",variant:"danger"})&&b.mutate({id:w})};return u(Xe,{children:[u("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[o("p",{className:"text-xs text-foreground-subtle max-w-2xl",children:"Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius."}),u("button",{onClick:()=>f(!0),className:"inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",disabled:i.length===0,title:i.length===0?"Create a user first":"Issue a scoped token",children:[o(dn,{className:"h-3.5 w-3.5"}),"New token"]})]}),u(ef,{title:"Scoped tokens",subtitle:"Grouped per user",children:[i.length===0&&o(wB,{text:"No users yet — scoped tokens are issued on behalf of an existing user."}),i.map(w=>o(NB,{userId:w.id,username:w.username,onRevoke:(v,N)=>{y(v,N)},revokePending:b.isPending,revokeId:b.variables?.id},w.id))]}),a.length>0&&o(ef,{title:"Legacy API keys",subtitle:`${a.length} pre-existing — revoke only`,children:o(Z0,{headers:["Label","Admin","Prefix","Allowed providers","Created","Last used",""],rows:a.map(w=>{const v=!!w.isAdmin,N=m.isPending&&m.variables?.id===w.id;return u("tr",{className:"hover:bg-primary/5",children:[o("td",{className:"px-3 py-2 text-foreground border-b border-border font-medium",children:w.label}),o("td",{className:"px-3 py-2 text-foreground border-b border-border",children:o("span",{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${v?gB:bB}`,children:v?"admin":"regular"})}),u("td",{className:"px-3 py-2 text-foreground border-b border-border font-mono text-[11px]",children:[w.tokenPrefix,"…"]}),o("td",{className:"px-3 py-2 text-foreground border-b border-border text-foreground-subtle",children:xB(w.allowedProviders)||"all"}),o("td",{className:"px-3 py-2 text-foreground-subtle border-b border-border",children:fo(w.createdAt)}),o("td",{className:"px-3 py-2 text-foreground-subtle border-b border-border",children:fo(w.lastUsedAt)}),o("td",{className:"px-3 py-2 border-b border-border text-right",children:u("button",{onClick:()=>{x(w.id,w.label)},disabled:N,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50",title:"Revoke",children:[N?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Ke,{className:"h-3 w-3"}),"Revoke"]})})]},w.id)})})}),r&&o(vB,{}),d&&o(kB,{users:i.map(w=>({id:w.id,username:w.username})),onClose:()=>f(!1),onSubmit:w=>g.mutate({userId:w.userId,name:w.name,scopes:w.scopes,...w.expiresAt!==void 0?{expiresAt:w.expiresAt}:{}}),submitting:g.isPending}),p&&o(SB,{token:p.token,label:p.label,onClose:()=>h(null)})]})}function ef({title:e,subtitle:t,children:n}){return u("div",{className:"space-y-2",children:[u("div",{className:"flex items-baseline justify-between",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:e}),t&&o("span",{className:"text-[10px] text-foreground-subtle",children:t})]}),n]})}function vB(){return o("div",{className:"space-y-2",children:[1,2].map(e=>o("div",{className:"h-10 rounded border border-border bg-surface animate-pulse"},e))})}function wB({text:e}){return o("div",{className:"rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center",children:e})}function Z0({headers:e,rows:t}){return o("div",{className:"rounded-lg border border-border bg-surface overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[640px]",children:[o("thead",{children:o("tr",{children:e.map((n,r)=>o("th",{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${r===e.length-1?"text-right":"text-left"}`,children:n},r))})}),o("tbody",{children:t})]})})}function NB({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:s}){const{data:a,isLoading:i}=ny({userId:e}),l=a??[];return i||l.length===0?null:u("div",{className:"space-y-1.5",children:[o("div",{className:"text-[11px] font-medium text-foreground",children:t}),o(Z0,{headers:["Name","Prefix","Scopes","Expires","Last used","Created",""],rows:l.map(c=>{const d=r&&s===c.id;return u("tr",{className:"hover:bg-primary/5",children:[o("td",{className:"px-3 py-2 text-foreground border-b border-border font-medium",children:c.name}),u("td",{className:"px-3 py-2 text-foreground border-b border-border font-mono text-[11px]",children:[c.tokenPrefix,"…"]}),o("td",{className:"px-3 py-2 text-foreground border-b border-border",children:o("div",{className:"flex flex-wrap gap-1",children:c.scopes.map((f,p)=>u("span",{className:"inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono",children:[f.type,":",f.type==="device"?`[${f.targets.join(",")}]`:f.target]},p))})}),o("td",{className:"px-3 py-2 text-foreground-subtle border-b border-border",children:fo(c.expiresAt)}),o("td",{className:"px-3 py-2 text-foreground-subtle border-b border-border",children:fo(c.lastUsedAt)}),o("td",{className:"px-3 py-2 text-foreground-subtle border-b border-border",children:fo(c.createdAt)}),o("td",{className:"px-3 py-2 border-b border-border text-right",children:u("button",{onClick:()=>n(c.id,c.name),disabled:d,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50",children:[d?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Ke,{className:"h-3 w-3"}),"Revoke"]})})]},c.id)})})]})}function kB({users:e,onClose:t,onSubmit:n,submitting:r}){const{user:s}=mn(),i=s?.isAdmin===!0?null:s?.scopes??[],[l,c]=P(e[0]?.id??""),[d,f]=P(""),[p,h]=P([{type:"capability",target:"",access:["view","create"]}]),[m,g]=P(""),b=fd(p),x=l!==""&&d.trim().length>0&&p.length>0&&b===null&&!r,y=()=>{const w=parseInt(m,10),v=Number.isFinite(w)&&w>0?Date.now()+w*864e5:void 0;n({userId:l,name:d.trim(),scopes:p,expiresAt:v})};return u(X0,{title:"Create scoped token",onClose:t,children:[u("div",{className:"space-y-3",children:[o(vs,{label:"On behalf of user",children:o("select",{value:l,onChange:w=>c(w.target.value),className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary",children:e.map(w=>o("option",{value:w.id,children:w.username},w.id))})}),o(vs,{label:"Name",children:o("input",{value:d,onChange:w=>f(w.target.value),placeholder:"cloudflare-tunnel-route",className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary"})}),u(vs,{label:"Scopes",hint:"Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.",children:[o(pd,{value:p,onChange:h,clampToParent:i}),b&&o("p",{className:"mt-1 text-[10px] text-danger",children:b})]}),o(vs,{label:"Expires in (days)",hint:"Leave blank for non-expiring.",children:o("input",{type:"number",min:1,value:m,onChange:w=>g(w.target.value),placeholder:"30",className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary"})})]}),u(J0,{children:[o("button",{onClick:t,className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),u("button",{onClick:y,disabled:!x,className:"inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[r?o(Ee,{className:"h-3.5 w-3.5 animate-spin"}):o(dn,{className:"h-3.5 w-3.5"}),"Issue token"]})]})]})}function SB({token:e,label:t,onClose:n}){const[r,s]=P(!1),a=async()=>{try{await navigator.clipboard.writeText(e),s(!0)}catch{}};return u(X0,{title:`Token: ${t}`,onClose:n,children:[u("div",{className:"space-y-3",children:[o("div",{className:"rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning",children:"Copy this token now. Once you close this dialog the secret cannot be displayed again."}),o("div",{className:"rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all",children:e})]}),u(J0,{children:[u("button",{onClick:()=>{a()},className:"inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30",children:[r?o(Mt,{className:"h-3.5 w-3.5 text-primary"}):o(e0,{className:"h-3.5 w-3.5"}),r?"Copied":"Copy"]}),o("button",{onClick:n,className:"rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:"Done"})]})]})}function X0({title:e,onClose:t,children:n}){return o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:t,children:u("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl",onClick:r=>r.stopPropagation(),children:[u("div",{className:"flex items-start justify-between border-b border-border px-4 py-3",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:e}),o("button",{onClick:t,className:"text-foreground-subtle hover:text-foreground",children:o(Fe,{className:"h-4 w-4"})})]}),o("div",{className:"p-4",children:n})]})})}function J0({children:e}){return o("div",{className:"flex justify-end gap-2 border-t border-border px-4 py-3",children:e})}function vs({label:e,hint:t,children:n}){return u("div",{className:"space-y-1",children:[o("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:e}),n,t&&o("p",{className:"text-[10px] text-foreground-subtle",children:t})]})}function qa(e){const{title:t,subtitle:n,pageIcon:r,itemIcon:s,capability:a,installButtonLabel:i="Add addon",items:l,isLoading:c,emptyTitle:d="No addons installed for this capability",emptyDescription:f,itemIconColor:p,renderStatusBadges:h,renderActionButtons:m,renderExpandedBody:g,trailing:b,showChrome:x=!1}=e,y=l.length>1,[w,v]=P(()=>l[0]?.addonId??null);Y(()=>{w&&(l.some(C=>C.addonId===w)||v(l[0]?.addonId??null))},[l,w]);const N=C=>v(E=>E===C?null:C),k=a?`/system/addons?capability=${encodeURIComponent(a)}`:null;return o(Xe,{icon:x?r:void 0,title:x?t:void 0,subtitle:x?n:void 0,actions:x&&k?o(Kn,{to:k,children:u(Oe,{variant:"primary",size:"sm",children:[o(ot,{className:"h-3.5 w-3.5 mr-1"}),i]})}):void 0,children:c?o(Lt,{children:o("div",{className:"p-6 text-sm text-foreground-subtle",children:"Loading…"})}):l.length===0?o(Lt,{children:o(Dc,{title:d,description:f??(k?`Install an addon that declares the "${a}" capability to get started.`:void 0),action:x&&k?o(Kn,{to:k,children:u(Oe,{variant:"primary",size:"sm",children:[o(ot,{className:"h-3.5 w-3.5 mr-1"}),i]})}):void 0})}):u("div",{className:"flex flex-col gap-4",children:[l.map(C=>{const E=!y||w===C.addonId,A=p?.(C)??"bg-primary/15 text-primary";return u(Lt,{children:[u("div",{className:`flex items-center gap-4 p-4 ${E?"border-b border-border":""}`,children:[u("button",{type:"button",onClick:()=>y&&N(C.addonId),className:`flex items-center gap-4 flex-1 min-w-0 text-left ${y?"hover:opacity-80 transition-opacity":""}`,disabled:!y,children:[o("div",{className:`h-10 w-10 rounded-lg flex items-center justify-center shrink-0 ${A}`,children:o(s,{className:"h-5 w-5"})}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[o("span",{className:"font-semibold text-foreground",children:C.displayName}),h?.(C)]}),u("div",{className:"text-xs text-foreground-subtle mt-1 font-mono",children:["@camstack/addon-",C.addonId]})]}),y&&o(Nt,{className:`h-4 w-4 text-foreground-subtle shrink-0 transition-transform ${E?"rotate-180":""}`})]}),m&&o("div",{className:"flex items-center gap-1 shrink-0",children:m(C)})]}),E&&g?.(C)]},C.addonId)}),b]})})}function Ua({addonId:e,defaultActivity:t,showActivity:n=!0,maxHeight:r="max-h-64",defaultTab:s}){const a=t??(s==="events"?"events":"logs"),[i,l]=P(a);return u("div",{className:"flex flex-col gap-4",children:[o(Qr,{nodeId:"hub",addonIds:[e],level:"global"}),n&&u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border bg-surface-hover/20",children:[o("span",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide",children:"Activity"}),u("div",{className:"flex items-center gap-1",children:[o(tf,{kind:"logs",active:i==="logs",onClick:()=>l("logs")}),o(tf,{kind:"events",active:i==="events",onClick:()=>l("events")})]})]}),i==="logs"?o(Xt,{addonId:e,maxHeight:r,showFilters:!1}):o(cr,{addonId:e,category:"addon.*",maxHeight:r})]})]})}function tf({kind:e,active:t,onClick:n}){return u("button",{onClick:n,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t?"bg-primary/10 text-primary":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,children:[o(e==="logs"?rt:Uo,{className:"h-3 w-3"}),e==="logs"?"Logs":"Events"]})}function CB(e){const t=e.kind??"";return t==="local"||e.addonId==="local-auth"?{headline:"Username + password (local).",icon:o0,bullets:["Users live in the hub’s SQLite database — no IdP roundtrip.","TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).","API keys + scoped tokens are managed from the API Keys page."],setupSteps:["Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).","Hand out either passwords or scoped tokens — both validate through this provider."]}:t==="oidc"||e.addonId.startsWith("auth-oidc")?{headline:"OpenID Connect (Google, Microsoft, Okta, Keycloak, …).",icon:Wt,bullets:["Three-leg redirect flow with PKCE S256 + nonce.","id_token is signature-verified against the IdP’s JWKS — no implicit trust.","First-time sign-ins are auto-provisioned with the configured Default Role."],setupSteps:["Register a web app at your IdP and copy the client_id + client_secret.","Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.","Paste issuer + credentials in the Settings panel below — saves on every change."]}:t==="saml"?{headline:"SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).",icon:Wt,bullets:["Heavier handshake than OIDC — exchange metadata XML with your IdP.","Group → role mapping via SAML assertions."]}:t==="webauthn"||t==="passkey"?{headline:"Passkeys / WebAuthn — passwordless second factor.",icon:Er,bullets:["Enroll a YubiKey, Touch ID, or platform passkey per user.","Resistant to phishing — the browser binds the credential to your hub origin."]}:t==="totp"?{headline:"TOTP — six-digit codes from any authenticator app.",icon:Er,bullets:["Second factor on top of password (RFC 6238, ±30 s clock skew).","Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc."]}:{headline:e.displayName,icon:dn,bullets:["Generic authentication provider. No additional hints registered."]}}function MB(){const e=Vc(),t=e.data??[];return o(qa,{title:"Authentication",subtitle:"Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Each provider’s settings + live logs are inline below; no redirect to /system/addons.",pageIcon:dn,itemIcon:dn,capability:"auth-provider",installButtonLabel:"Add provider",items:t,isLoading:e.isLoading,emptyTitle:"No authentication providers registered",emptyDescription:"Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.",itemIconColor:n=>n.enabled?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-foreground-subtle/15 text-foreground-subtle",renderStatusBadges:n=>u(me,{children:[!n.enabled&&o("span",{className:"text-[10px] rounded-full px-2 py-0.5 font-medium bg-red-500/15 text-red-700 dark:text-red-300",children:"Disabled"}),n.hasCredentialFlow&&u("span",{className:"text-[10px] rounded-full px-2 py-0.5 font-medium bg-blue-500/15 text-blue-700 dark:text-blue-300",children:[o(o0,{className:"inline h-2.5 w-2.5 mr-0.5"}),"Credential"]}),n.hasRedirectFlow&&u("span",{className:"text-[10px] rounded-full px-2 py-0.5 font-medium bg-violet-500/15 text-violet-700 dark:text-violet-300",children:[o(Wt,{className:"inline h-2.5 w-2.5 mr-0.5"}),"Redirect SSO"]}),n.status&&u("span",{className:"text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300",children:[o(ut,{className:"inline h-2.5 w-2.5 mr-0.5"}),n.status]})]}),renderExpandedBody:n=>{const r=CB(n),s=r.icon;return u(me,{children:[u("div",{className:"p-4 space-y-3 border-b border-border",children:[u("div",{className:"flex items-start gap-2.5",children:[o(s,{className:"h-4 w-4 mt-0.5 text-primary shrink-0"}),o("div",{className:"text-xs text-foreground font-medium",children:r.headline})]}),o("ul",{className:"text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc",children:r.bullets.map((a,i)=>o("li",{children:a},i))}),r.setupSteps&&r.setupSteps.length>0&&u("div",{className:"rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5",children:[u("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide",children:[o(yL,{className:"h-3 w-3"}),"Setup steps"]}),o("ol",{className:"text-xs text-foreground space-y-0.5 pl-4 list-decimal",children:r.setupSteps.map((a,i)=>o("li",{children:a},i))})]}),n.addonId==="local-auth"&&u("div",{className:"rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground",children:[o(kn,{className:"h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0"}),u("span",{children:["TOTP / 2FA settings are exposed per-user from the"," ",o("a",{href:"/system/users",className:"underline text-primary",children:"Users"})," page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”."]})]})]}),o("div",{className:"p-4",children:o(Ua,{addonId:n.addonId,maxHeight:"max-h-64"})})]})}})}function EB(){return o("div",{className:"flex flex-col p-4",children:o(Dd,{tabs:[{id:"users",label:"Users",icon:B6,content:o(fB,{})},{id:"api-keys",label:"Tokens",icon:mR,content:o(yB,{})},{id:"authentication",label:"Authentication",icon:dn,content:o(MB,{})}]})})}function ev(){const e=ke(),t=Bx(void 0,{refetchInterval:5e3}),n=t.data??[],[r,s]=P(null),a=()=>{e.invalidateQueries({queryKey:[["remoteAccess"]]}),s(null)},i=zx({onSuccess:a,onError:()=>s(null)}),l=Fx({onSuccess:a,onError:()=>s(null)});return o(qa,{title:"Remote Access",subtitle:"Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.",pageIcon:Wt,itemIcon:Wt,capability:"network-access",installButtonLabel:"Add tunnel",items:n,isLoading:t.isLoading,emptyTitle:"No remote-access providers installed",emptyDescription:"Install a tunnel addon (e.g. @camstack/addon-cloudflare-tunnel) to expose this hub publicly.",itemIconColor:c=>c.connected?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-foreground-subtle/15 text-foreground-subtle",renderStatusBadges:c=>u(me,{children:[o("span",{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${c.connected?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-foreground-subtle/15 text-foreground-subtle"}`,children:c.connected?"Connected":"Disconnected"}),c.endpoint&&u("a",{href:c.endpoint.url,target:"_blank",rel:"noopener noreferrer",onClick:d=>d.stopPropagation(),className:"text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1",children:[o(Id,{className:"h-3 w-3"}),c.endpoint.url]}),c.error&&o("span",{className:"text-[10px] text-danger",children:c.error})]}),renderActionButtons:c=>{const d=r===c.addonId;return c.connected?u(Oe,{size:"sm",variant:"secondary",disabled:d,onClick:()=>{s(c.addonId),l.mutate({addonId:c.addonId})},children:[d?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Ko,{className:"h-3 w-3"}),"Stop"]}):u(Oe,{size:"sm",variant:"primary",disabled:d,onClick:()=>{s(c.addonId),i.mutate({addonId:c.addonId})},children:[d?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Oa,{className:"h-3 w-3"}),"Start"]})},renderExpandedBody:c=>o("div",{className:"p-4",children:o(Ua,{addonId:c.addonId,maxHeight:"max-h-72"})})})}function IB(){const e=ke(),t=Ux(void 0,{refetchInterval:3e4}),n=Qx(),r=t.data??[],s=n.data??[],[a,i]=P(null),l=Gx({onSuccess:()=>{e.invalidateQueries({queryKey:[["turnOrchestrator"]]}),i(null)},onError:()=>i(null)});return o(qa,{title:"TURN Servers",subtitle:"ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.",pageIcon:Mn,itemIcon:Mn,capability:"turn-provider",installButtonLabel:"Add provider",items:r,isLoading:t.isLoading,emptyTitle:"No TURN providers installed",emptyDescription:"Install a TURN addon (e.g. @camstack/addon-cloudflare-turn) to enable WebRTC behind restrictive NATs.",itemIconColor:c=>c.error?"bg-danger/15 text-danger":c.enabled?"bg-violet-500/15 text-violet-700 dark:text-violet-300":"bg-foreground-subtle/15 text-foreground-subtle",renderStatusBadges:c=>u(me,{children:[o("span",{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${c.enabled?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-foreground-subtle/15 text-foreground-subtle"}`,children:c.enabled?"Enabled":"Disabled"}),u("span",{className:"text-[10px] text-foreground-subtle",children:["· ",c.serverCount," server",c.serverCount===1?"":"s"]}),c.error&&o("span",{className:"text-[10px] text-danger",children:c.error})]}),renderActionButtons:c=>{const d=a===c.addonId;return c.enabled?u(Oe,{size:"sm",variant:"secondary",disabled:d,onClick:()=>{i(c.addonId),l.mutate({addonId:c.addonId,enabled:!1})},children:[d?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Ko,{className:"h-3 w-3"}),"Disable"]}):u(Oe,{size:"sm",variant:"primary",disabled:d,onClick:()=>{i(c.addonId),l.mutate({addonId:c.addonId,enabled:!0})},children:[d?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Oa,{className:"h-3 w-3"}),"Enable"]})},renderExpandedBody:c=>u(me,{children:[c.urls.length>0&&u("div",{className:"px-4 py-3 border-b border-border",children:[u("div",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2",children:["Discovered ICE servers (",c.urls.length,")"]}),o("div",{className:"flex flex-wrap gap-1",children:c.urls.map(d=>o("span",{className:"inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground",children:d},d))})]}),o("div",{className:"p-4",children:o(Ua,{addonId:c.addonId,maxHeight:"max-h-72"})})]}),trailing:u(Lt,{children:[u("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between",children:[u("div",{children:[o("div",{className:"text-sm font-semibold",children:"Combined ICE server list"}),o("div",{className:"text-xs text-foreground-subtle",children:"What the WebRTC layer fetches per-session."})]}),o(Oe,{size:"sm",variant:"secondary",onClick:()=>n.refetch(),disabled:n.isFetching,children:"Refresh"})]}),o("div",{className:"p-4",children:s.length===0?o("div",{className:"text-xs text-foreground-subtle",children:"No servers from enabled providers."}):o("div",{className:"flex flex-col gap-3",children:s.map((c,d)=>{const f=Array.isArray(c.urls)?c.urls:[c.urls];return u("div",{className:"rounded border border-border bg-surface",children:[(c.username||c.credential)&&u("div",{className:"px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3",children:[c.username&&u("span",{children:[o("span",{className:"text-foreground-subtle",children:"user:"})," ",o("span",{className:"text-foreground",children:c.username})]}),c.credential&&u("span",{title:c.credential,children:[o("span",{className:"text-foreground-subtle",children:"credential:"})," ",o("span",{className:"text-foreground",children:`${c.credential.slice(0,8)}…${c.credential.slice(-4)}`})]})]}),o("ul",{className:"divide-y divide-border",children:f.map(p=>o("li",{className:"px-3 py-1.5 font-mono text-xs text-foreground break-all",children:p},p))})]},d)})})})]})})}const AB={lan:Mn,wifi:Wn,docker:Qo,vpn:a0,loopback:cn,other:cn},PB={lan:"LAN",wifi:"Wi-Fi",docker:"Docker",vpn:"VPN",loopback:"Loopback",other:"Other"},_B=["lan","wifi","vpn","docker","other","loopback"];function $B(e){const{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:s,emptyMessage:a}=e,i=q(()=>t.filter(f=>!(r&&f.kind==="loopback"||s&&f.family!=="IPv4")),[t,r,s]),l=q(()=>{const f=new Map;for(const p of i){const h=f.get(p.kind)??[];h.push(p),f.set(p.kind,h)}return _B.filter(p=>f.has(p)).map(p=>({kind:p,items:f.get(p)}))},[i]),c=f=>e.mode==="single"?e.value===f:e.value.includes(f),d=f=>{if(n||f.kind==="loopback")return;if(e.mode==="single"){e.onChange(e.value===f.address?null:f.address);return}const p=new Set(e.value);p.has(f.address)?p.delete(f.address):p.add(f.address),e.onChange([...p])};return i.length===0?o("div",{className:"text-xs text-foreground-subtle italic",children:a??"No addresses available."}):o("div",{className:"flex flex-col gap-3",children:l.map(({kind:f,items:p})=>{const h=AB[f]??cn;return u("div",{className:"rounded-md border border-border overflow-hidden",children:[u("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border",children:[o(h,{className:"h-3.5 w-3.5 text-foreground-subtle"}),o("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle",children:PB[f]??f}),u("span",{className:"text-[10px] text-foreground-subtle",children:["· ",p.length]})]}),o("ul",{className:"divide-y divide-border",children:p.map(m=>{const g=c(m.address),b=m.kind==="loopback",x=!m.plausible&&!b;return u("li",{className:`flex items-center gap-3 px-3 py-2 ${b?"opacity-60 cursor-not-allowed":n?"opacity-60":x?"cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]":"cursor-pointer hover:bg-surface-hover/30"}`,onClick:()=>d(m),children:[o("span",{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode==="single"?"rounded-full":"rounded"} border ${g?"border-primary bg-primary text-primary-foreground":"border-border bg-surface"}`,children:g&&o(Mt,{className:"h-3 w-3"})}),u("div",{className:`flex-1 min-w-0 ${x?"text-foreground-subtle":""}`,children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[o("span",{className:`font-mono text-xs font-semibold ${x?"text-foreground-subtle":"text-foreground"}`,children:m.name}),o("span",{className:"text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono",children:m.family}),m.preferred&&o("span",{className:"text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary",children:"Auto-preferred"}),b&&o("span",{className:"text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle",children:"Always included"}),x&&u("span",{className:"inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300",title:m.plausibleReason||void 0,children:[o(ut,{className:"h-2.5 w-2.5"}),"Unlikely usable"]})]}),u("div",{className:"text-xs text-foreground-subtle mt-0.5 font-mono break-all",children:[m.address,m.cidr&&m.cidr!==m.address?` (${m.cidr})`:""]})]})]},`${m.name}-${m.family}-${m.address}`)})})]},f)})})}const nf={"lan-ipv4":"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300","lan-ipv6":"bg-violet-500/15 text-violet-700 dark:text-violet-300",public:"bg-blue-500/15 text-blue-700 dark:text-blue-300",loopback:"bg-foreground-subtle/15 text-foreground-subtle"};function DB(){const e=ke(),t=Le(),n=Lb(void 0,{refetchInterval:3e4}),r=Ob(void 0),s=Bb({onSuccess:()=>{e.invalidateQueries({queryKey:[["localNetwork"]]})}}),a=zb({onSuccess:C=>{p(C.addresses),e.invalidateQueries({queryKey:[["localNetwork"]]})}}),i=q(()=>n.data?.interfaces??[],[n.data]),l=typeof window<"u"?Number(window.location.port)||(window.location.protocol==="https:"?443:80):4e3,c=typeof window<"u"&&window.location.protocol==="https:"?"https":"http",d=Rb({port:l,scheme:c},{refetchInterval:3e4}),[f,p]=P([]),[h,m]=P(!1);Y(()=>{!h&&r.data&&(p(r.data.addresses),m(!0))},[r.data,h]);const g=r.data?.addresses??[],b=q(()=>{if(f.length!==g.length)return!0;const C=[...f].sort(),E=[...g].sort();return C.some((A,I)=>A!==E[I])},[f,g]),x=()=>{s.mutate({addresses:[...f]})},y=()=>{p(g)},w=()=>{p([])},v=()=>{n.refetch(),d.refetch(),r.refetch()},N=async()=>{try{const C=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info("[network-addresses] race result",C)}catch(C){console.warn("[network-addresses] race failed",C)}},k=d.data?.endpoints??[];return u(Xe,{children:[u("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[o("p",{className:"text-xs text-foreground-subtle max-w-2xl",children:"Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate."}),u("div",{className:"flex items-center gap-2 shrink-0",children:[u(Oe,{size:"sm",variant:"secondary",onClick:v,disabled:n.isLoading,children:[o(ht,{className:`h-3 w-3 ${n.isLoading?"animate-spin":""}`}),"Refresh"]}),o(Oe,{size:"sm",variant:"secondary",onClick:N,children:"Probe race"})]})]}),u("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[u(Lt,{children:[u("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between",children:[u("div",{children:[o("div",{className:"text-sm font-semibold",children:"Allowed addresses"}),o("div",{className:"text-xs text-foreground-subtle",children:f.length===0?"Auto — every non-loopback / non-link-local interface participates.":`${f.length} pinned`})]}),u("div",{className:"flex items-center gap-1",children:[u(Oe,{size:"sm",variant:"secondary",onClick:()=>a.mutate(void 0),disabled:a.isPending||s.isPending,title:"Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.",children:[o(C6,{className:"h-3 w-3"}),a.isPending?"Detecting…":"Best match"]}),u(Oe,{size:"sm",variant:"secondary",onClick:w,disabled:f.length===0||s.isPending,children:[o(u0,{className:"h-3 w-3"}),"Clear"]}),b&&o(Oe,{size:"sm",variant:"secondary",onClick:y,disabled:s.isPending,children:"Discard"}),u(Oe,{size:"sm",variant:"primary",onClick:x,disabled:!b||s.isPending,children:[o(l6,{className:"h-3 w-3"}),s.isPending?"Saving…":"Save"]})]})]}),o("div",{className:"p-4",children:o($B,{mode:"multiple",interfaces:i,value:f,onChange:p,disabled:s.isPending,emptyMessage:n.isLoading?"Loading interfaces…":"No interfaces detected."})})]}),u(Lt,{children:[u("div",{className:"px-4 py-3 border-b border-border",children:[o("div",{className:"text-sm font-semibold",children:"Connection endpoints — priority order"}),o("div",{className:"text-xs text-foreground-subtle",children:"Live preview of the ranked candidate list the SDK would race against. Updates with each Save."})]}),o("div",{className:"p-4",children:k.length===0?o("div",{className:"text-xs text-foreground-subtle italic",children:d.isLoading?"Loading…":"No endpoints available."}):o("ul",{className:"space-y-1 text-xs",children:k.map(C=>u("li",{className:`flex items-center gap-2 flex-wrap ${C.plausible?"":"opacity-80"}`,children:[o("span",{className:"font-mono text-[10px] w-10 text-foreground-subtle",children:String(C.priority).padStart(4,"0")}),o("span",{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${nf[C.kind]??nf.loopback}`,children:C.kind}),C.interfaceKind!=="lan"&&C.interfaceKind!=="public"&&o("span",{className:"text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase",children:C.interfaceKind}),!C.plausible&&C.interfaceKind!=="loopback"&&u("span",{className:"inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300",title:C.plausibleReason||void 0,children:[o(ut,{className:"h-2.5 w-2.5"}),"Unlikely usable"]}),o("span",{className:`font-mono break-all ${C.plausible?"text-foreground":"text-foreground-subtle"}`,children:C.baseUrl}),u("span",{className:"text-foreground-subtle",children:["— ",C.label]})]},`${C.priority}-${C.baseUrl}`))})})]})]})]})}const TB={mesh:"bg-violet-500/15 text-violet-700 dark:text-violet-300",public:"bg-blue-500/15 text-blue-700 dark:text-blue-300"};function tv(){const e=ke(),t=Fb(void 0,{refetchInterval:5e3}),n=t.data??[],[r,s]=P(null),[a,i]=P({}),[l,c]=P({}),d=()=>{e.invalidateQueries({queryKey:[["meshOrchestrator"]]}),s(null)},f=jb({onSuccess:d,onError:()=>s(null)}),p=Hb({onSuccess:d,onError:()=>s(null)});return o(qa,{title:"Mesh Networks",subtitle:"Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).",pageIcon:Qo,itemIcon:Mn,capability:"mesh-network",installButtonLabel:"Add mesh",items:n,isLoading:t.isLoading,emptyTitle:"No mesh-network providers installed",emptyDescription:"Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.",itemIconColor:h=>h.joined?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-foreground-subtle/15 text-foreground-subtle",renderStatusBadges:h=>u(me,{children:[o("span",{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${h.joined?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-foreground-subtle/15 text-foreground-subtle"}`,children:h.joined?"Joined":"Not joined"}),h.joined&&u("span",{className:"text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle",children:[h.peerCount," peer",h.peerCount===1?"":"s"]})]}),renderActionButtons:h=>{const m=r===h.addonId;return h.joined?u(Oe,{size:"sm",variant:"secondary",disabled:m,onClick:()=>{s(h.addonId),p.mutate({addonId:h.addonId})},children:[m?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Ad,{className:"h-3 w-3"}),"Leave"]}):null},renderExpandedBody:h=>{const m=r===h.addonId,g=a[h.addonId]??"",b=l[h.addonId]??"",x=g.trim().length>=8;return u(me,{children:[h.joined?u("div",{className:"p-4 space-y-3",children:[u("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-1 text-xs",children:[h.meshIp&&u("div",{className:"flex items-center gap-1.5",children:[o("span",{className:"text-foreground-subtle",children:"Mesh IP:"}),o("span",{className:"font-mono text-foreground",children:h.meshIp})]}),h.magicDnsHostname&&u("div",{className:"flex items-center gap-1.5",children:[o("span",{className:"text-foreground-subtle",children:"MagicDNS:"}),o("span",{className:"font-mono text-foreground break-all",children:h.magicDnsHostname})]})]}),h.endpoints.length>0&&u("div",{className:"flex flex-col gap-1",children:[o("div",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide",children:"Endpoints"}),h.endpoints.map(y=>u("div",{className:"flex items-center gap-2 text-xs",children:[u("span",{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${TB[y.scope]??"bg-foreground-subtle/15 text-foreground-subtle"}`,children:[y.scope==="public"?o(Wt,{className:"inline h-2.5 w-2.5 mr-0.5"}):null,y.label]}),u("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),className:"text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1",children:[o(Id,{className:"h-3 w-3 shrink-0"}),y.url]})]},y.id))]}),h.error&&o("div",{className:"text-xs text-danger",children:h.error})]}):u("div",{className:"p-4 space-y-3",children:[o("div",{className:"text-xs text-foreground-subtle",children:"Provide an auth key to join this hub into the mesh. The key is forwarded to the daemon and never persisted in clear."}),u("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:[o("input",{type:"password",autoComplete:"off",placeholder:"Auth key (tskey-auth-…)",value:g,onChange:y=>i(w=>({...w,[h.addonId]:y.target.value})),className:"rounded-md border border-border bg-surface px-2 py-1 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary"}),o("input",{type:"text",placeholder:"Hostname (optional)",value:b,onChange:y=>c(w=>({...w,[h.addonId]:y.target.value})),className:"rounded-md border border-border bg-surface px-2 py-1 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary"})]}),o("div",{className:"flex justify-end",children:u(Oe,{size:"sm",variant:"primary",disabled:m||!x,onClick:()=>{s(h.addonId),f.mutate({addonId:h.addonId,authKey:g.trim(),hostname:b.trim()?b.trim():void 0})},children:[m?o(Ee,{className:"h-3 w-3 animate-spin"}):o(ER,{className:"h-3 w-3"}),"Join"]})}),h.error&&o("div",{className:"text-xs text-danger",children:h.error})]}),o("div",{className:"p-4 border-t border-border",children:o(Ua,{addonId:h.addonId,maxHeight:"max-h-72"})})]})}})}function LB(){return o("div",{className:"flex flex-col p-4",children:o(Dd,{tabs:[{id:"addresses",label:"Network Addresses",icon:cn,content:o(DB,{})},{id:"remote-access",label:"Remote Access",icon:Wt,content:o(ev,{})},{id:"mesh",label:"Mesh Networks",icon:Qo,content:o(tv,{})},{id:"turn",label:"TURN Servers",icon:Mn,content:o(IB,{})}]})})}const RB=[{kind:"mesh",title:"Mesh networks",subtitle:"Private VPN meshes connecting this hub to your other devices (Tailscale, Headscale, …).",icon:Qo,emptyHint:"Install a mesh-network addon (e.g. @camstack/addon-tailscale-client) to join this hub into a private mesh.",addLabel:"Add mesh"},{kind:"ingress",title:"Public ingress",subtitle:"Public tunnels that expose this hub to the internet (Cloudflare Tunnel, Tailscale Funnel, …).",icon:Wt,emptyHint:"Install a tunnel addon (e.g. @camstack/addon-cloudflare-tunnel) to expose this hub publicly.",addLabel:"Add tunnel"},{kind:"broker",title:"Brokers",subtitle:"Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).",icon:Ba,emptyHint:"Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.",addLabel:"Add broker"},{kind:"email",title:"Email providers",subtitle:"Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).",icon:PR,emptyHint:"Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.",addLabel:"Add email provider"},{kind:"device-export",title:"Device export",subtitle:"Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).",icon:g6,emptyHint:"Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …",addLabel:"Add export"}];function OB(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){const t=e.name;if(typeof t=="string")return t}return null}function BB(e){const t=e,n=t?.manifest;if(!n?.id)return null;const r=[];for(const a of n.capabilities??[]){const i=OB(a);i!==null&&r.push(i)}const s=n.packageDisplayName??n.name??n.id;return{addonId:n.id,displayName:s,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:t?.process?.state??null}}function zB(e,t){const n=new Set(t);return e.filter(r=>r.capNames.some(s=>n.has(s)))}function FB(e){const t=e[0];return t?`/system/addons?capability=${encodeURIComponent(t)}`:null}function jB({kind:e,title:t,subtitle:n,icon:r,installHref:s,addLabel:a}){return u("div",{className:"flex items-center justify-between gap-3",children:[u("div",{className:"flex items-start gap-3 min-w-0",children:[o("div",{className:"h-9 w-9 rounded-lg bg-primary/10 text-primary flex items-center justify-center shrink-0",children:o(r,{className:"h-4 w-4"})}),u("div",{className:"min-w-0",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:t}),o(UB,{kind:e})]}),o("p",{className:"text-xs text-foreground-subtle mt-0.5",children:n})]})]}),s&&o(Kn,{to:s,className:"shrink-0",children:u(Oe,{size:"sm",variant:"primary",children:[o(ot,{className:"h-3.5 w-3.5 mr-1"}),a]})})]})}function HB(e){return e==="running"?{label:"Running",className:"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300"}:e==="crashed"||e==="failed"?{label:e==="failed"?"Failed":"Crashed",className:"bg-danger/15 text-danger"}:e==="stopped"||e==="disabled"?{label:"Stopped",className:"bg-foreground-subtle/15 text-foreground-subtle"}:{label:e??"Unknown",className:"bg-foreground-subtle/15 text-foreground-subtle"}}function Td({label:e,className:t}){return o("span",{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function VB(){const{data:e,isLoading:t}=Ub(void 0,{refetchInterval:1e4,retry:!1});if(t||!e)return null;const n=IN.safeParse(e);if(!n.success)return null;const r=n.data,s=`${r.brokerCount} broker${r.brokerCount===1?"":"s"}${r.embeddedRunning?" • embedded up":""}`;return o(Td,{label:s,className:"bg-primary/10 text-primary"})}function qB(){const{data:e,isLoading:t}=db(void 0,{refetchInterval:1e4,retry:!1});if(t||!e)return null;const n=AN.safeParse(e);if(!n.success)return null;const r=n.data,s=r.linkState==="linked"?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":r.linkState==="error"?"bg-danger/15 text-danger":"bg-foreground-subtle/15 text-foreground-subtle",a=`${r.linkState} • ${r.exposedDeviceCount} exposed`;return o(Td,{label:a,className:s})}function UB({kind:e}){return e==="broker"?o(VB,{}):e==="device-export"?o(qB,{}):null}function QB(e,t){const n=t.get(e);return n||`/system/addons?addonId=${encodeURIComponent(e)}`}function GB({rows:e,emptyHint:t,emptyTitle:n,installHref:r,addLabel:s,addonPagePaths:a}){return e.length===0?o(Lt,{children:o(Dc,{title:n,description:t,action:r?o(Kn,{to:r,children:u(Oe,{size:"sm",variant:"primary",children:[o(ot,{className:"h-3.5 w-3.5 mr-1"}),s]})}):void 0})}):o("div",{className:"flex flex-col gap-3",children:e.map(i=>{const l=HB(i.processState);return o(Lt,{children:u("div",{className:"flex items-center gap-4 p-4",children:[o("div",{className:"h-10 w-10 rounded-lg bg-primary/15 text-primary flex items-center justify-center shrink-0",children:o(No,{className:"h-5 w-5"})}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[o("span",{className:"font-semibold text-foreground",children:i.displayName}),o(Td,{label:l.label,className:l.className})]}),o("div",{className:"text-xs text-foreground-subtle mt-1 font-mono truncate",children:i.packageName})]}),o(Kn,{to:QB(i.addonId,a),className:"shrink-0",children:o(Oe,{size:"sm",variant:"secondary",children:"Configure"})})]})},i.addonId)})})}function KB(e){const t=new Map;for(const n of e??[])t.has(n.addonId)||t.set(n.addonId,n.page.path);return t}function WB(){const t=(Fo(void 0,{refetchInterval:1e4}).data??[]).map(BB).filter(s=>s!==null),n=Sa(void 0,{refetchInterval:3e4}),r=KB(n.data);return o(Xe,{icon:wo,title:"Integrations",subtitle:"External systems this hub talks to — mesh VPNs, public tunnels, brokers, email, and device exporters. Per-provider settings live on each addon's own page; this page is the directory.",children:o("div",{className:"flex flex-col gap-6",children:RB.map(s=>{const a=Object.entries(DN).filter(([,l])=>l===s.kind).map(([l])=>l),i=FB(a);return u("section",{className:"space-y-3",children:[o(jB,{kind:s.kind,title:s.title,subtitle:s.subtitle,icon:s.icon,installHref:i,addLabel:s.addLabel}),s.kind==="mesh"?o(tv,{}):s.kind==="ingress"?o(ev,{}):o(GB,{rows:zB(t,a),emptyHint:s.emptyHint,emptyTitle:`No ${s.title.toLowerCase()} installed`,installHref:i,addLabel:s.addLabel,addonPagePaths:r})]},s.kind)})})})}function YB(e){const t=e.basePath;if(typeof t=="string"&&t.length>0)return t;const n=Object.keys(e);return n.length===0?"":n.join(", ")}function ZB({location:e,onEdit:t,onDelete:n,onSetDefault:r}){const s=YB(e.config);return u("div",{className:"flex items-center gap-3 px-3 py-2 border-t border-border first:border-t-0 hover:bg-primary/5",children:[u("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[o("div",{className:"w-[88px] shrink-0",children:e.isDefault?u("span",{className:"inline-flex items-center gap-0.5 rounded bg-primary/10 border border-primary/20 px-1.5 py-0.5 text-[10px] font-semibold text-primary uppercase tracking-wide",title:"Default location for this type",children:[o(Ii,{className:"h-2.5 w-2.5 fill-primary"}),"Default"]}):u("button",{onClick:()=>r(e),className:"inline-flex items-center gap-0.5 rounded border border-border px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 hover:border-primary/30 uppercase tracking-wide",title:"Promote to default for this type",children:[o(Ii,{className:"h-2.5 w-2.5"}),"Set default"]})}),o("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono",children:e.providerId}),e.isSystem&&o("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5",title:"System-managed location — cannot be deleted; edit config to relocate",children:"system"}),u("div",{className:"min-w-0",children:[o("div",{className:"text-xs font-medium text-foreground truncate",children:e.displayName}),s&&o("div",{className:"text-[10px] text-foreground-subtle truncate font-mono",children:s})]})]}),u("div",{className:"flex items-center gap-1 shrink-0",children:[!e.isDefault&&u("button",{onClick:()=>r(e),className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10",title:"Set as default for this type",children:[o(Ii,{className:"h-3 w-3"}),"Set default"]}),u("button",{onClick:()=>t(e),className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10",children:[o(Ur,{className:"h-3 w-3"}),"Edit"]}),!e.isSystem&&_s[e.type]!=="singleton"&&o("button",{onClick:()=>n(e),className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10",title:"Delete location",children:o(Ke,{className:"h-3 w-3"})})]})]})}function XB({type:e,displayName:t,description:n,locations:r,onAdd:s,onEdit:a,onDelete:i,onSetDefault:l}){const c=q(()=>{const d=[...r];return d.sort((f,p)=>f.isDefault!==p.isDefault?f.isDefault?-1:1:f.displayName.localeCompare(p.displayName)),d},[r]);return u("div",{className:"rounded-lg border border-border bg-surface",children:[u("div",{className:"flex items-start justify-between border-b border-border px-3 py-2",children:[u("div",{className:"space-y-0.5",children:[u("div",{className:"flex items-center gap-2",children:[o("span",{className:"text-sm font-semibold text-foreground capitalize",children:t}),o("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono",children:e})]}),n&&o("p",{className:"text-[11px] text-foreground-subtle",children:n}),_s[e]==="singleton"&&o("p",{className:"text-[10px] text-foreground-subtle italic",children:"Singleton — one location per type. Edit the existing entry; it can't be split."})]}),_s[e]==="multi"&&u("button",{onClick:()=>s(e),className:"inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90",children:[o(ot,{className:"h-3 w-3"}),"Add"]})]}),c.length===0?o("div",{className:"px-3 py-4 text-center text-[11px] text-foreground-subtle italic",children:_s[e]==="multi"?'No location registered. Click "Add" to register one.':"No location registered yet — should be auto-seeded at next boot."}):o("div",{children:c.map(d=>o(ZB,{location:d,onEdit:a,onDelete:i,onSetDefault:l},d.id))})]})}function JB(e){const t=e.trim().toLowerCase();return t.length===0?"":t.replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function rf(e,t){const n=JB(t),r=n.length>0?n:"default";return`${e}:${r}`}function nv({initialType:e,onClose:t,onCreated:n}){const r=ke(),s=Le().trpcClient,[a,i]=P("picker"),[l,c]=P(e),[d,f]=P(null),[p,h]=P({}),[m,g]=P(""),[b,x]=P(null),[y,w]=P(!1),[v,N]=P(null),[k,C]=P(!1),E=td(),A=q(()=>{const T=E.data;return Array.isArray(T)?T.filter(L=>L.supportedLocationTypes.includes(l)):[]},[E.data,l]),I=E.isLoading,z=Aa({onSuccess:()=>{r.invalidateQueries({queryKey:[["storage","listLocations"]]}),n()}}),$=q(()=>b!==null&&b.length>0?b:rf(l,m),[l,m,b]),B=async()=>{if(d){C(!0),N(null);try{const L=await(O=>s.storage.testConfig.query(O))({providerId:d.providerId,config:p});N(L)}catch(T){N({ok:!1,error:T instanceof Error?T.message:String(T)})}finally{C(!1)}}},R=()=>{d&&z.mutate({id:$,type:l,displayName:m.trim(),providerId:d.providerId,config:p,isDefault:y})},M={picker:"Add Location — Pick provider",config:`Add Location — ${d?.displayName??""}`,naming:"Add Location — Name & defaults"};return o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:t,children:u("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl",onClick:T=>T.stopPropagation(),children:[u("div",{className:"flex items-start justify-between border-b border-border px-4 py-3",children:[u("div",{className:"space-y-0.5",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:M[a]}),u("p",{className:"text-xs text-foreground-subtle",children:["Type: ",o("span",{className:"font-mono",children:l})]})]}),o("button",{onClick:t,className:"text-foreground-subtle hover:text-foreground",children:o(Fe,{className:"h-4 w-4"})})]}),a==="picker"&&u("div",{className:"p-4 space-y-2",children:[I&&o("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading providers…"}),!I&&A.length===0&&u("div",{className:"rounded border border-border bg-background px-3 py-4 text-center text-xs text-foreground-subtle",children:['No storage-provider supports type "',l,'". Install a compatible addon (e.g. ',o("code",{className:"font-mono",children:"remote-storage"}),") to enable it."]}),A.map(T=>u("button",{onClick:()=>{f(T),i("config")},className:"flex w-full items-center gap-3 rounded-lg border border-border bg-background p-3 text-left hover:border-primary/40 hover:bg-primary/5 transition-colors",children:[u("div",{className:"flex-1 min-w-0",children:[o("p",{className:"text-xs font-semibold text-foreground",children:T.displayName}),o("p",{className:"text-[10px] text-foreground-subtle font-mono mt-0.5 truncate",children:T.providerId})]}),o(Et,{className:"h-4 w-4 text-foreground-subtle flex-shrink-0"})]},T.providerId))]}),a==="config"&&d&&u("div",{className:"p-4 space-y-3 max-h-[60vh] overflow-y-auto",children:[o(En,{schema:d.configSchema,values:p,onChange:h}),v&&o("div",{className:`rounded border px-3 py-2 text-[11px] ${v.ok?"border-success/30 bg-success/5 text-success":"border-danger/30 bg-danger/5 text-danger"}`,children:v.ok?"Connection OK.":`Test failed: ${v.error??"unknown error"}`}),u("div",{className:"flex items-center justify-between pt-1",children:[o("button",{onClick:()=>i("picker"),className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Back"}),u("div",{className:"flex items-center gap-2",children:[o("button",{onClick:()=>{B()},disabled:k,className:"rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50",children:k?"Testing…":"Test connection"}),o("button",{onClick:()=>i("naming"),className:"rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:"Next"})]})]})]}),a==="naming"&&d&&u("div",{className:"p-4 space-y-3",children:[u("div",{className:"space-y-1",children:[o("label",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:"Display name"}),o("input",{type:"text",value:m,onChange:T=>g(T.target.value),placeholder:`${l} on ${d.displayName}`,className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary"})]}),u("div",{className:"space-y-1",children:[u("label",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:["Id ",o("span",{className:"lowercase tracking-normal text-foreground-subtle",children:"— auto-derived; override if needed"})]}),o("input",{type:"text",value:$,onChange:T=>x(T.target.value),placeholder:rf(l,m),className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground font-mono focus:outline-none focus:ring-1 focus:ring-primary"}),u("p",{className:"text-[10px] text-foreground-subtle",children:["Format: ",o("code",{className:"font-mono",children:"<type>:<slug>"}),". Lowercase letters, digits, and hyphens only."]})]}),u("label",{className:"flex items-start gap-2 rounded border border-border bg-background px-3 py-2 cursor-pointer hover:bg-primary/5",children:[o("input",{type:"checkbox",checked:y,onChange:T=>w(T.target.checked),className:"accent-primary mt-0.5"}),u("div",{className:"space-y-0.5",children:[u("div",{className:"text-xs font-medium text-foreground",children:['Mark as default for type "',l,'"']}),u("div",{className:"text-[10px] text-foreground-subtle",children:["Setting this as default will demote the current default for this type. References like"," ",u("code",{className:"font-mono",children:['"',l,'"']})," resolve to whichever location is the default."]})]})]}),z.isError&&o("div",{className:"rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]",children:z.error instanceof Error?z.error.message:String(z.error)}),u("div",{className:"flex items-center justify-between pt-1",children:[o("button",{onClick:()=>i("config"),className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Back"}),u("div",{className:"flex items-center gap-2",children:[o("button",{onClick:()=>{c(e),f(null),h({}),g(""),x(null),w(!1),N(null),i("picker")},className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Reset"}),u("button",{onClick:R,disabled:z.isPending||m.trim().length===0,className:"inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[z.isPending?o(Ee,{className:"h-3.5 w-3.5 animate-spin"}):null,z.isPending?"Saving…":"Save"]})]})]})]})]})})}function ez({location:e,onClose:t,onSaved:n}){const r=ke(),s=Le().trpcClient,[a,i]=P({...e.config}),[l,c]=P(e.displayName),[d,f]=P(null),[p,h]=P(!1),m=td(),g=q(()=>{const w=m.data;return Array.isArray(w)?w.find(N=>N.providerId===e.providerId)??null:null},[m.data,e.providerId]),b=Aa({onSuccess:()=>{r.invalidateQueries({queryKey:[["storage","listLocations"]]}),n()}}),x=async()=>{h(!0),f(null);try{const v=await(N=>s.storage.testConfig.query(N))({providerId:e.providerId,config:a});f(v)}catch(w){f({ok:!1,error:w instanceof Error?w.message:String(w)})}finally{h(!1)}},y=()=>{b.mutate({id:e.id,type:e.type,providerId:e.providerId,isDefault:e.isDefault,displayName:l.trim(),config:a})};return o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:t,children:u("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl",onClick:w=>w.stopPropagation(),children:[u("div",{className:"flex items-start justify-between border-b border-border px-4 py-3",children:[u("div",{className:"space-y-0.5",children:[u("h2",{className:"text-sm font-semibold text-foreground",children:["Edit ",e.displayName]}),u("p",{className:"text-xs text-foreground-subtle",children:[o("span",{className:"font-mono",children:e.id})," · ",g?.displayName??e.providerId]})]}),o("button",{onClick:t,className:"text-foreground-subtle hover:text-foreground",children:o(Fe,{className:"h-4 w-4"})})]}),u("div",{className:"p-4 space-y-3 max-h-[60vh] overflow-y-auto",children:[u("div",{className:"space-y-1",children:[o("label",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:"Display name"}),o("input",{type:"text",value:l,onChange:w=>c(w.target.value),className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary"})]}),g&&o(En,{schema:g.configSchema,values:a,onChange:i}),!g&&!m.isLoading&&u("div",{className:"rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300",children:["Provider ",o("code",{className:"font-mono",children:e.providerId})," is no longer registered. Field schema unavailable; raw config is preserved on save."]}),d&&o("div",{className:`rounded border px-3 py-2 text-[11px] ${d.ok?"border-success/30 bg-success/5 text-success":"border-danger/30 bg-danger/5 text-danger"}`,children:d.ok?"Connection OK.":`Test failed: ${d.error??"unknown error"}`}),b.isError&&o("div",{className:"rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]",children:b.error instanceof Error?b.error.message:String(b.error)})]}),u("div",{className:"flex items-center justify-between gap-2 border-t border-border px-4 py-3",children:[o("button",{onClick:t,className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),u("div",{className:"flex items-center gap-2",children:[o("button",{onClick:()=>{x()},disabled:p||!g,className:"rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50",children:p?"Testing…":"Test connection"}),u("button",{onClick:y,disabled:b.isPending||l.trim().length===0,className:"inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[b.isPending?o(Ee,{className:"h-3.5 w-3.5 animate-spin"}):null,b.isPending?"Saving…":"Save"]})]})]})]})})}const tz={data:"Data",media:"Media",recordings:"Recordings","recordings-high":"Recordings (High)","recordings-low":"Recordings (Low)","recordings-clips":"Recordings (Clips)","event-images":"Event Images",models:"Models","addons-data":"Addons Data",cache:"Cache",logs:"Logs",backups:"Backups"},nz={backups:"Snapshot archives. Default landing for `backup-orchestrator`.",recordings:"Continuous recordings (combined high + low + clips when no slot is specified).","recordings-high":"High-quality continuous recordings.","recordings-low":"Low-quality continuous recordings.","recordings-clips":"Event clips (motion / detection triggers).","event-images":"Detection snapshots, thumbnails, and crops.",models:"ML model files. Read by inference-engine addons.",logs:"Long-term log archives."};function rz(){const e=ke(),t=Je(),{data:n,isLoading:r,isError:s}=jx({}),[a,i]=P(null),[l,c]=P(null),d=Hx({onSuccess:()=>{e.invalidateQueries({queryKey:[["storage","listLocations"]]})}}),f=Aa({onSuccess:()=>{e.invalidateQueries({queryKey:[["storage","listLocations"]]})}}),p=g=>{g.isDefault||f.mutate({id:g.id,type:g.type,providerId:g.providerId,displayName:g.displayName,config:g.config,isDefault:!0})},h=async g=>{if(g.isDefault){await t({title:"Cannot delete default location",message:`"${g.displayName}" is the default for type "${g.type}". Mark another location as default first, then delete this one.`,confirmLabel:"OK",variant:"warning"});return}await t({title:`Delete location "${g.displayName}"?`,message:"This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.",confirmLabel:"Delete",variant:"danger"})&&d.mutate({id:g.id})},m=q(()=>{const g=new Map;for(const b of fu)g.set(b,[]);for(const b of n??[]){const x=g.get(b.type);x?x.push(b):g.set(b.type,[b])}return g},[n]);return u(Xe,{children:[r&&o("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading locations…"}),s&&o("div",{className:"text-xs text-danger",children:"Failed to load storage locations."}),!r&&!s&&o("div",{className:"space-y-3",children:fu.map(g=>o(XB,{type:g,displayName:tz[g],description:nz[g],locations:m.get(g)??[],onAdd:b=>i(b),onEdit:b=>c(b),onDelete:b=>{h(b)},onSetDefault:b=>p(b)},g))}),a!==null&&o(nv,{initialType:a,onClose:()=>i(null),onCreated:()=>{e.invalidateQueries({queryKey:[["storage","listLocations"]]}),i(null)}}),l!==null&&o(ez,{location:l,onClose:()=>c(null),onSaved:()=>{e.invalidateQueries({queryKey:[["storage","listLocations"]]}),c(null)}})]})}const oz=[["backup","listDestinations"]],sz=["backup","listArchives"];function az({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){const r=ke(),s=Je(),{data:a,isLoading:i,isError:l}=Uc({destinationId:e}),c=a??[],d=rb({onSuccess:()=>{r.invalidateQueries({queryKey:[[...sz]]}),r.invalidateQueries({queryKey:oz})}}),f=U(async b=>{await s({title:"Delete this archive?",message:`Permanently deletes "${b.label??b.id}" and frees ${kt(b.sizeBytes)}.`,confirmLabel:"Delete",variant:"danger"})&&d.mutate({destinationId:e,backupId:b.id})},[s,e,d]),[p,h]=P(null),m=U(async b=>{h(b.id);try{const x=localStorage.getItem("camstack_admin_token"),y={};x&&(y.Authorization=`Bearer ${x}`);const w=await fetch(iz(e,b.id),{headers:y});if(!w.ok)throw new Error(`download failed: ${w.status} ${w.statusText}`);const v=await w.blob(),N=URL.createObjectURL(v),k=document.createElement("a");k.href=N,k.download=`${b.label??b.id}.tar.gz`,document.body.appendChild(k),k.click(),k.remove(),URL.revokeObjectURL(N)}finally{h(null)}},[e]),g=q(()=>[...c].sort((b,x)=>x.createdAt-b.createdAt),[c]);return i?o("div",{className:"text-xs text-foreground-subtle animate-pulse py-2",children:"Loading archives…"}):l?o("div",{className:"text-xs text-danger py-2",children:"Failed to read manifest for this destination"}):g.length===0?o("div",{className:"text-xs text-foreground-subtle italic py-2",children:"No archives at this destination yet."}):o("div",{className:"rounded border border-border bg-surface overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[640px]",children:[o("thead",{children:u("tr",{className:"text-foreground-subtle bg-background/30",children:[o("th",{className:"text-left px-3 py-1.5 font-medium",children:"When"}),o("th",{className:"text-left px-3 py-1.5 font-medium",children:"Label"}),o("th",{className:"text-left px-3 py-1.5 font-medium",children:"Includes"}),o("th",{className:"text-right px-3 py-1.5 font-medium",children:"Size"}),o("th",{className:"text-right px-3 py-1.5 font-medium w-52",children:"Actions"})]})}),o("tbody",{children:g.map(b=>u("tr",{className:"border-t border-border hover:bg-primary/5",children:[o("td",{className:"px-3 py-1.5 text-foreground tabular-nums",children:lz(b.createdAt)}),o("td",{className:"px-3 py-1.5 text-foreground",children:b.label??o("span",{className:"text-foreground-subtle italic",children:"—"})}),o("td",{className:"px-3 py-1.5 text-foreground-subtle",children:b.locations.join(", ")}),o("td",{className:"px-3 py-1.5 text-foreground text-right tabular-nums",children:kt(b.sizeBytes)}),o("td",{className:"px-3 py-1.5",children:u("div",{className:"flex items-center justify-end gap-1",children:[u("button",{onClick:()=>{m(b)},disabled:p===b.id,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50",title:"Download archive",children:[p===b.id?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Cn,{className:"h-3 w-3"}),"Download"]}),t&&n&&u("button",{onClick:()=>n({destinationId:e,archiveId:b.id}),className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10",title:"Restore from this archive",children:[o(yt,{className:"h-3 w-3"}),"Restore"]}),o("button",{onClick:()=>{f(b)},disabled:d.isPending,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50",title:"Delete archive",children:d.isPending?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Ke,{className:"h-3 w-3"})})]})})]},b.id))})]})})}function iz(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function lz(e){return new Date(e).toLocaleString(void 0,{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})}const rv=[{id:"manual",label:"Manual only",cron:""},{id:"hourly",label:"Every hour",cron:"0 * * * *",description:"On the hour"},{id:"every-3h",label:"Every 3 hours",cron:"0 */3 * * *",description:"00:00, 03:00, 06:00, 09:00 …"},{id:"every-6h",label:"Every 6 hours",cron:"0 */6 * * *",description:"00:00, 06:00, 12:00, 18:00"},{id:"daily-3am",label:"Daily at 03:00",cron:"0 3 * * *",description:"Every night at 3 AM"},{id:"weekly-sun",label:"Weekly Sunday 03:00",cron:"0 3 * * 0",description:"Sunday morning at 3 AM"}];function cz(e){const t=e.trim();for(const n of rv)if(n.cron===t)return n.id;return"custom"}function dz({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){const s=cz(e),[a,i]=P(s==="custom");Y(()=>{s!=="custom"&&i(!1)},[s]);const l=fz(e,250),c=sb({cron:l,count:n},{enabled:l.trim().length>0}),d=c.data??null,f=h=>{i(!1),t(h.cron)},p=a||s==="custom";return u("div",{className:"space-y-3",children:[u("div",{className:"space-y-1",children:[o("div",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:"Schedule preset"}),u("div",{className:"flex flex-wrap gap-1.5",children:[rv.map(h=>{const m=!a&&s===h.id;return o("button",{type:"button",onClick:()=>f(h),disabled:r,className:"rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 "+(m?"border-primary bg-primary/10 text-primary":"border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground"),title:h.description??h.label,children:h.label},h.id)}),o("button",{type:"button",onClick:()=>{i(!0),e.trim().length===0&&t("0 3 * * *")},disabled:r,className:"rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 "+(p?"border-primary bg-primary/10 text-primary":"border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground"),children:"Custom…"})]})]}),p&&u("div",{className:"space-y-1",children:[o("div",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:"Cron expression (5-field POSIX)"}),o("input",{type:"text",value:e,onChange:h=>t(h.target.value),disabled:r,placeholder:"0 3 * * *",spellCheck:!1,className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary"}),u("p",{className:"text-[10px] text-foreground-subtle",children:["Format: ",o("span",{className:"font-mono",children:"minute hour day-of-month month day-of-week"})," · all times server-local"]})]}),o(uz,{cron:l,preview:d,loading:c.isFetching})]})}function uz({cron:e,preview:t,loading:n}){return n&&t===null?u("div",{className:"flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle",children:[o(Ee,{className:"h-3 w-3 animate-spin"}),"Validating…"]}):t===null?null:t.ok?t.nextRuns.length===0?o("div",{className:"rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle",children:"No future runs match this expression."}):u("div",{className:"space-y-1",children:[o("div",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle",children:"Next runs"}),o("ul",{className:"rounded border border-border bg-background/40 divide-y divide-border",children:t.nextRuns.map((r,s)=>u("li",{className:"flex items-center justify-between px-3 py-1.5 text-[11px]",children:[o("span",{className:"text-foreground tabular-nums",children:new Date(r).toLocaleString()}),o("span",{className:"text-foreground-subtle text-[10px] tabular-nums",children:pz(r)})]},`${r}-${s}`))})]}):o("div",{className:"rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger",children:t.error??"Invalid cron expression"})}function pz(e){const t=e-Date.now();if(t<=0)return"now";const n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;const r=Math.floor(n/60);if(r<60)return`in ${r}m`;const s=Math.floor(r/60);return s<24?`in ${s}h`:`in ${Math.floor(s/24)}d`}function fz(e,t){const[n,r]=P(e),s=q(()=>e,[e]);return Y(()=>{const a=setTimeout(()=>r(s),t);return()=>clearTimeout(a)},[s,t]),n}const hz=[["backup","listDestinations"]];function mz({onCreateAt:e,onOpenRestoreWizard:t}){const{data:n,isLoading:r,isError:s}=qc(),a=n??[],[i,l]=P(null),c=f=>{l(p=>p===f?null:f)},d=vz();return r?o("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Loading destinations…"}):s?o("div",{className:"text-xs text-danger",children:"Failed to load destinations"}):a.length===0?o("div",{className:"rounded-lg border border-border bg-surface px-4 py-8 text-center",children:o("p",{className:"text-xs text-foreground-subtle",children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):o("div",{className:"rounded-lg border border-border bg-surface overflow-x-auto",children:u("table",{className:"w-full text-xs min-w-[720px]",children:[o("thead",{children:u("tr",{className:"text-foreground-subtle border-b border-border bg-background/40",children:[o("th",{className:"text-left px-3 py-2 font-medium w-6"}),o("th",{className:"text-left px-3 py-2 font-medium",children:"Destination"}),o("th",{className:"text-left px-3 py-2 font-medium w-20",children:"Enabled"}),o("th",{className:"text-left px-3 py-2 font-medium w-28",children:"Retention"}),o("th",{className:"text-left px-3 py-2 font-medium w-56",children:"Schedule"}),o("th",{className:"text-left px-3 py-2 font-medium w-44",children:"Last success"}),o("th",{className:"text-right px-3 py-2 font-medium w-44",children:"Actions"})]})}),o("tbody",{children:a.map(f=>{const p=d.get(f.id);return o(gz,{row:f,isOpen:i===f.id,onToggle:()=>c(f.id),onCreateAt:e,liveLastSuccessAt:p?.at,liveLastSuccessSizeBytes:p?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},f.id)})})]})})}function gz({row:e,isOpen:t,onToggle:n,onCreateAt:r,onOpenRestoreWizard:s,liveLastSuccessAt:a,liveLastSuccessSizeBytes:i}){const l=ke(),c=ob({onSuccess:()=>{l.invalidateQueries({queryKey:hz})}}),[d,f]=P(String(e.retentionCount));Y(()=>{f(String(e.retentionCount))},[e.retentionCount]);const[p,h]=P(!1),m=U(x=>{c.mutate({locationId:e.id,enabled:x,retentionCount:e.retentionCount,...e.label!==void 0?{label:e.label}:{},...e.cron!==void 0?{cron:e.cron}:{}})},[c,e.id,e.retentionCount,e.label,e.cron]),g=U(()=>{const x=Number.parseInt(d,10);if(Number.isNaN(x)||x<1){f(String(e.retentionCount));return}x!==e.retentionCount&&c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:x,...e.label!==void 0?{label:e.label}:{},...e.cron!==void 0?{cron:e.cron}:{}})},[c,d,e.id,e.enabled,e.retentionCount,e.label,e.cron]),b=U(x=>{c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label!==void 0?{label:e.label}:{},cron:x},{onSuccess:()=>{h(!1)}})},[c,e.id,e.enabled,e.retentionCount,e.label]);return u(me,{children:[u("tr",{className:"border-t border-border first:border-t-0 hover:bg-primary/5",children:[o("td",{className:"px-2 py-2",children:o("button",{onClick:n,className:"inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground",title:t?"Hide archives":"Show archives",children:t?o(Nt,{className:"h-3.5 w-3.5"}):o(Et,{className:"h-3.5 w-3.5"})})}),o("td",{className:"px-3 py-2",children:u("button",{onClick:n,className:"text-left hover:underline focus:outline-none",title:"View archives",children:[o("div",{className:"text-foreground font-medium",children:e.displayName}),u("div",{className:"flex items-center gap-1.5 mt-0.5",children:[o("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5",children:e.kind}),o("span",{className:"text-[10px] text-foreground-subtle font-mono",children:e.id})]})]})}),o("td",{className:"px-3 py-2",children:o("label",{className:"inline-flex items-center cursor-pointer",children:o("input",{type:"checkbox",className:"accent-primary",checked:e.enabled,disabled:c.isPending,onChange:x=>m(x.target.checked)})})}),o("td",{className:"px-3 py-2",children:o("input",{type:"number",min:1,max:1e3,value:d,disabled:c.isPending,onChange:x=>f(x.target.value),onBlur:g,onKeyDown:x=>{x.key==="Enter"&&x.target.blur(),x.key==="Escape"&&f(String(e.retentionCount))},className:"w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary"})}),o("td",{className:"px-3 py-2",children:o(bz,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>h(!0),disabled:c.isPending})}),o("td",{className:"px-3 py-2 text-foreground-subtle",children:(()=>{const x=wz(a,e.lastSuccessAt),y=x===a?i:e.lastSuccessSizeBytes;return x!==void 0?o(Nz,{at:x,sizeBytes:y}):o("span",{className:"italic",children:"Never"})})()}),o("td",{className:"px-3 py-2",children:o("div",{className:"flex items-center justify-end gap-1.5",children:e.triggerSupported&&u("button",{onClick:()=>r(e),className:"inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90",children:[o(ot,{className:"h-3 w-3"}),"Create here"]})})})]}),t&&o("tr",{className:"border-t border-border bg-background/30",children:o("td",{colSpan:7,className:"px-4 py-3",children:o(az,{destinationId:e.id,restoreSupported:e.restoreSupported,...s?{onOpenRestoreWizard:s}:{}})})}),p&&o(yz,{destinationName:e.displayName,currentCron:e.cron??"",onSave:b,onClose:()=>h(!1),saving:c.isPending,saveError:c.error instanceof Error?c.error.message:null})]})}function bz({cron:e,nextRunAt:t,onEdit:n,disabled:r}){const s=typeof e=="string"&&e.trim().length>0;return u("button",{type:"button",onClick:n,disabled:r,className:"group flex flex-col items-start gap-0.5 text-left rounded px-1.5 py-1 -mx-1.5 hover:bg-primary/5 disabled:opacity-50",title:"Edit schedule",children:[u("div",{className:"flex items-center gap-1.5",children:[o(CL,{className:"h-3 w-3 text-foreground-subtle group-hover:text-foreground"}),o("span",{className:s?"font-mono text-foreground":"italic text-foreground-subtle",children:s?e:"Manual"})]}),s&&t!==void 0&&u("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:["next ",xz(t)]})]})}function xz(e){const t=e-Date.now();if(t<=0)return"imminent";const n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;const r=Math.floor(n/60);if(r<60)return`in ${r}m`;const s=Math.floor(r/60);return s<24?`in ${s}h`:`in ${Math.floor(s/24)}d`}function yz({destinationName:e,currentCron:t,onSave:n,onClose:r,saving:s,saveError:a}){const[i,l]=P(t);return o("tr",{children:o("td",{colSpan:7,className:"p-0",children:o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:r,children:u("div",{className:"w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl",onClick:c=>c.stopPropagation(),children:[u("div",{className:"flex items-start justify-between border-b border-border px-4 py-3",children:[u("div",{className:"space-y-0.5",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:"Schedule"}),u("p",{className:"text-xs text-foreground-subtle",children:["→ ",e]})]}),o("button",{onClick:r,className:"text-foreground-subtle hover:text-foreground",title:"Close",children:o(Fe,{className:"h-4 w-4"})})]}),u("div",{className:"p-4",children:[o(dz,{value:i,onChange:l,disabled:s}),a!==null&&o("div",{className:"mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger",children:a})]}),u("div",{className:"flex justify-end gap-2 border-t border-border px-4 py-3",children:[o("button",{onClick:r,disabled:s,className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground disabled:opacity-50",children:"Cancel"}),o("button",{onClick:()=>n(i.trim()),disabled:s||i.trim()===t.trim(),className:"inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:s?"Saving…":"Save"})]})]})})})})}function vz(){const{map:e}=$c(Ne.BackupCompleted,t=>t.destinationId);return q(()=>{const t=new Map;for(const[n,r]of e)t.set(n,{at:Date.now(),sizeBytes:r.sizeMB*1024*1024});return t},[e])}function wz(e,t){return e===void 0?t:t===void 0||e>t?e:t}function Nz({at:e,sizeBytes:t}){const n=kz(e),r=q(()=>new Date(e).toLocaleString(),[e]);return u("span",{title:r,className:"text-foreground tabular-nums",children:[n,t!==void 0&&u("span",{className:"ml-1 text-foreground-subtle",children:["· ",kt(t)]})]})}function kz(e){const[,t]=P(0);return Y(()=>{const n=setInterval(()=>t(r=>r+1),3e4);return()=>clearInterval(n)},[]),Sz(e)}function Sz(e){const t=Math.max(0,Date.now()-e),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const s=Math.floor(r/60);if(s<24)return`${s}h ago`;const a=Math.floor(s/24);if(a<30)return`${a}d ago`;const i=Math.floor(a/30);return i<12?`${i}mo ago`:`${Math.floor(a/365)}y ago`}const Cz=[["backup","list"]];function Mz({initialDestinationId:e,initialArchiveId:t,onClose:n,onScheduled:r}){const s=ke(),[a,i]=P(e&&t?2:1),[l,c]=P(e),[d,f]=P(t),[p,h]=P(new Set),{data:m}=qc(),g=m??[],{data:b,isLoading:x}=Uc({destinationId:l??""},{enabled:!!l}),y=b??[];Y(()=>{if(l!==void 0)return;const z=g.filter($=>$.restoreSupported);z.length===1&&c(z[0].id)},[l,g]);const{data:w}=tb({destinationId:l??"",backupId:d??""},{enabled:!!l&&!!d}),v=q(()=>w?.locations??[],[w]);Y(()=>{v.length!==0&&h(z=>z.size===0?new Set(v):z)},[v]);const N=nb({onSuccess:()=>{s.invalidateQueries({queryKey:Cz}),r(),n()}}),k=z=>{h($=>{const B=new Set($);return B.has(z)?B.delete(z):B.add(z),B})},C=!!l&&!!d,E=p.size>0,A=C&&E&&!N.isPending,I=()=>{!l||!d||N.mutate({destinationId:l,backupId:d,locations:[...p]})};return o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:n,children:u("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl",onClick:z=>z.stopPropagation(),children:[u("div",{className:"flex items-start justify-between border-b border-border px-4 py-3",children:[u("div",{className:"space-y-0.5",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:"Restore Backup"}),u("p",{className:"text-xs text-foreground-subtle",children:["Step ",a," of 3 — ",a===1?"pick source":a===2?"pick locations":"confirm"]})]}),o("button",{onClick:n,className:"text-foreground-subtle hover:text-foreground",children:o(Fe,{className:"h-4 w-4"})})]}),a===1&&o(Ez,{destinations:g,destinationId:l,onPickDestination:z=>{c(z),f(void 0),h(new Set)},archives:y,archivesLoading:x,archiveId:d,onPickArchive:f}),a===2&&o(Iz,{locations:v,picked:p,onToggle:k}),a===3&&o(Az,{destinationName:g.find(z=>z.id===l)?.displayName??l??"",archive:y.find(z=>z.id===d),picked:[...p]}),u("div",{className:"flex justify-between gap-2 border-t border-border px-4 py-3",children:[o("div",{children:a>1&&u("button",{onClick:()=>i(z=>z===3?2:1),className:"inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:[o(Md,{className:"h-3 w-3"}),"Back"]})}),u("div",{className:"flex items-center gap-2",children:[o("button",{onClick:n,className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),a<3?u("button",{disabled:a===1&&!C||a===2&&!E,onClick:()=>i(z=>z===1?2:3),className:"inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:["Next",o(hL,{className:"h-3 w-3"})]}):u("button",{onClick:I,disabled:!A,className:"inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[N.isPending?o(Ee,{className:"h-3.5 w-3.5 animate-spin"}):o(yt,{className:"h-3.5 w-3.5"}),"Schedule Restore"]})]})]})]})})}function Ez({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:s,archiveId:a,onPickArchive:i}){const l=e.filter(c=>c.restoreSupported);return u("div",{className:"p-4 space-y-3",children:[u("div",{className:"space-y-1.5",children:[o("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Destination"}),u("select",{value:t??"",onChange:c=>n(c.target.value),className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary",children:[o("option",{value:"",disabled:!0,children:"Select destination…"}),l.map(c=>u("option",{value:c.id,children:[c.displayName," (",c.kind,")"]},c.id))]})]}),u("div",{className:"space-y-1.5",children:[o("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Archive"}),!t&&o("div",{className:"text-xs text-foreground-subtle italic",children:"Pick a destination first."}),t&&s&&o("div",{className:"text-xs text-foreground-subtle animate-pulse",children:"Reading archives…"}),t&&!s&&r.length===0&&o("div",{className:"text-xs text-foreground-subtle italic",children:"No archives available at this destination."}),t&&r.length>0&&o("div",{className:"rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto",children:r.map(c=>{const d=a===c.id;return u("label",{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${d?"bg-primary/10":"hover:bg-primary/5"}`,children:[u("div",{className:"flex items-center gap-2",children:[o("input",{type:"radio",name:"archive",checked:d,onChange:()=>i(c.id),className:"accent-primary"}),u("div",{children:[o("div",{className:"font-medium text-foreground",children:c.label??c.id}),o("div",{className:"text-[10px] text-foreground-subtle",children:new Date(c.createdAt).toLocaleString()})]})]}),o("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:kt(c.sizeBytes)})]},c.id)})})]})]})}function Iz({locations:e,picked:t,onToggle:n}){return e.length===0?o("div",{className:"p-4",children:o("div",{className:"text-xs text-foreground-subtle",children:"Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball."})}):u("div",{className:"p-4 space-y-3",children:[o("div",{className:"rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300",children:"Selected entries will overwrite live data on the next server restart. Unchecked entries stay current."}),u("div",{className:"space-y-1.5",children:[o("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Apply"}),o("div",{className:"rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto",children:e.map(r=>u("label",{className:"flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer",children:[o("input",{type:"checkbox",checked:t.has(r),onChange:()=>n(r),className:"accent-primary"}),o("span",{className:"font-mono text-foreground",children:r}),o("span",{className:"ml-auto text-[10px] text-foreground-subtle",children:_z(r)})]},r))})]})]})}function Az({destinationName:e,archive:t,picked:n}){return u("div",{className:"p-4 space-y-3 text-xs",children:[o("div",{className:"rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300",children:"Restore is applied at next server boot. Active connections will drop when you restart."}),u("dl",{className:"space-y-1.5",children:[o(ws,{term:"Destination",value:e}),o(ws,{term:"Archive",value:t?.label??t?.id??"—"}),t&&o(ws,{term:"Created",value:`${new Date(t.createdAt).toLocaleString()} · ${kt(t.sizeBytes)}`}),o(ws,{term:"Locations",value:n.length>0?n.join(", "):"— (full archive)"})]})]})}function ws({term:e,value:t}){return u("div",{className:"flex justify-between gap-3",children:[o("dt",{className:"text-foreground-subtle",children:e}),o("dd",{className:"text-foreground font-mono text-right truncate",children:t})]})}const Pz={db:"Database",addons:"Addon configs","addons-data":"Addon data",tls:"TLS certificates",cache:"Cache",data:"Top-level data"};function _z(e){return Pz[e]??""}const $z=[["backup","list"]],Dz=[["backup","listLocations"]];function Tz(){const e=ke(),t=Je(),{data:n}=eb(),r=Jg({onSuccess:()=>{e.invalidateQueries({queryKey:$z}),e.invalidateQueries({queryKey:[["backup","listDestinations"]]}),e.invalidateQueries({queryKey:[["backup","listArchives"]]})}}),s=Og(),[a,i]=P(null),[l,c]=P(null),[d,f]=P(!1),[p,h]=P(!1),[m,g]=P(!1),b=async()=>{await t({title:"Restart server now?",message:"Active connections will drop and the apply-backup hook will run before boot.",confirmLabel:"Restart",variant:"warning"})&&s.mutate({confirm:!0})};return u(Xe,{children:[u("div",{className:"flex items-center justify-end gap-2 flex-wrap",children:[u("button",{onClick:()=>f(!0),className:"inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30",children:[o(yt,{className:"h-3.5 w-3.5"}),"Restore…"]}),u("button",{onClick:()=>g(!0),className:"inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:[o(ot,{className:"h-3.5 w-3.5"}),"Add destination"]})]}),p&&o("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300",children:u("div",{className:"flex items-center justify-between gap-3",children:[u("div",{className:"flex items-center gap-2",children:[o(yt,{className:"h-3.5 w-3.5"}),o("span",{children:"Restore scheduled. Restart the server to apply."})]}),u("button",{onClick:()=>{b()},disabled:s.isPending,className:"inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50",children:[s.isPending?o(Ee,{className:"h-3.5 w-3.5 animate-spin"}):o(yt,{className:"h-3.5 w-3.5"}),"Restart Now"]})]})}),o(mz,{onCreateAt:x=>i(x),onOpenRestoreWizard:x=>c(x)}),a&&o(Lz,{destination:a,locations:n??[],onClose:()=>i(null),onSubmit:(x,y)=>{r.mutate({destinations:[a.id],locations:x,label:y||void 0},{onSuccess:()=>{i(null),e.invalidateQueries({queryKey:Dz})}})},submitting:r.isPending}),(l||d)&&o(Mz,{...l?{initialDestinationId:l.destinationId,initialArchiveId:l.archiveId}:{},onClose:()=>{c(null),f(!1)},onScheduled:()=>h(!0)}),m&&o(nv,{initialType:"backups",onClose:()=>g(!1),onCreated:()=>{g(!1),e.invalidateQueries({queryKey:[["backup","listDestinations"]]})}})]})}function Lz({destination:e,locations:t,onClose:n,onSubmit:r,submitting:s}){const a=t.filter(p=>p.present),[i,l]=P(""),[c,d]=P(()=>new Set(a.map(p=>p.name))),f=p=>{d(h=>{const m=new Set(h);return m.has(p)?m.delete(p):m.add(p),m})};return o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:n,children:u("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl",onClick:p=>p.stopPropagation(),children:[u("div",{className:"flex items-start justify-between border-b border-border px-4 py-3",children:[u("div",{className:"space-y-0.5",children:[o("h2",{className:"text-sm font-semibold text-foreground",children:"Create Backup"}),u("p",{className:"text-xs text-foreground-subtle",children:["→ ",e.displayName]})]}),o("button",{onClick:n,className:"text-foreground-subtle hover:text-foreground",children:o(Fe,{className:"h-4 w-4"})})]}),u("div",{className:"p-4 space-y-3",children:[u("div",{className:"space-y-1",children:[o("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Label (optional)"}),o("input",{type:"text",value:i,onChange:p=>l(p.target.value),placeholder:"pre-upgrade",className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary"})]}),u("div",{className:"space-y-1.5",children:[o("label",{className:"text-[10px] text-foreground-subtle uppercase tracking-wide",children:"Include"}),u("div",{className:"rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto",children:[a.length===0&&o("div",{className:"px-3 py-2 text-xs text-foreground-subtle italic",children:"Nothing to back up."}),a.map(p=>u("label",{className:"flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer",children:[u("div",{className:"flex items-center gap-2",children:[o("input",{type:"checkbox",checked:c.has(p.name),onChange:()=>f(p.name),className:"accent-primary"}),o("span",{className:"font-mono text-foreground",children:p.name})]}),u("div",{className:"text-[10px] text-foreground-subtle tabular-nums",children:[kt(p.sizeBytes)," · ",p.fileCount," files"]})]},p.name))]})]})]}),u("div",{className:"flex justify-end gap-2 border-t border-border px-4 py-3",children:[o("button",{onClick:n,className:"rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground",children:"Cancel"}),u("button",{onClick:()=>r(Array.from(c),i.trim()),disabled:s||c.size===0,className:"inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[s?o(Ee,{className:"h-3.5 w-3.5 animate-spin"}):o(Wy,{className:"h-3.5 w-3.5"}),s?"Creating…":"Create"]})]})]})})}function Rz(){return o("div",{className:"flex flex-col p-4",children:o(Dd,{tabs:[{id:"storage",label:"Storage",icon:Ys,content:o(rz,{})},{id:"backup",label:"Backup",icon:Wy,content:o(Tz,{})}]})})}function Oz(){const{data:e,isLoading:t}=Dn(void 0,{staleTime:3e4}),n=(e??[]).find(s=>s.isHub&&s.isOnline),r=n?.addons.map(s=>s.id)??[];return o(Xe,{children:t?o("div",{className:"text-muted-foreground text-sm py-12 text-center",children:"Loading hub topology…"}):n?r.length===0?o("div",{className:"text-muted-foreground text-sm py-12 text-center",children:"No addons installed on the hub yet."}):o(Qr,{nodeId:n.id,addonIds:r,level:"global"}):u("div",{className:"flex flex-col items-center justify-center text-muted-foreground text-sm gap-2 py-12",children:[o(Yt,{className:"h-8 w-8 opacity-30"}),o("p",{children:"No online hub node found."}),o("p",{className:"text-xs",children:"Settings will appear once the hub is reachable."})]})})}function Bz(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,r)=>{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{r(new Error(`HTTP ${s.status}`));return}s.status>=200&&s.status<300?n(a):r(new Error(a.error??`HTTP ${s.status}`))}),s.addEventListener("error",()=>r(new Error("Network error during upload"))),s.addEventListener("abort",()=>r(new Error("Upload aborted"))),s.send(t)})}function zz({nodeId:e,addons:t,isHub:n}){const r=ke(),s=Je(),[a,i]=P(null),[l,c]=P(null),[d,f]=P(!1),[p,h]=P(null),[m,g]=P(0),b=ne(null),x=Ma(),y=Qb(),w=()=>{r.invalidateQueries({queryKey:[["nodes","topology"]]})},v=async E=>{i(E);try{await x.mutateAsync({nodeId:e,addonId:E}),w()}catch(A){console.error("Failed to restart addon:",A)}finally{i(null)}},N=async E=>{if(await s({title:"Uninstall addon",message:`Remove "${E}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:"Uninstall",variant:"danger"})){c(E);try{await y.mutateAsync({nodeId:e,addonId:E}),w()}catch(I){console.error("Failed to uninstall addon:",I)}finally{c(null)}}},C=u("div",{className:"flex items-center gap-2 mb-2",children:[o("input",{ref:b,type:"file",accept:".tgz,.tar.gz",className:"hidden",onChange:async E=>{const A=E.target.files?.[0];if(A){E.target.value="",h(null),f(!0),g(0);try{const I=localStorage.getItem("camstack_admin_token");await Bz({file:A,nodeId:e,token:I,onProgress:g}),w()}catch(I){h(I instanceof Error?I.message:String(I))}finally{f(!1),g(0)}}}}),u("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?o(Ee,{className:"h-3 w-3 animate-spin"}):o(za,{className:"h-3 w-3"}),d?`Uploading… ${m}%`:"Upload addon (.tgz)"]}),d&&o("div",{className:"flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]",children:o("div",{className:"h-full bg-primary transition-all",style:{width:`${m}%`}})}),p&&o("span",{className:"text-[10px] text-destructive",children:p})]});return t.length===0?u("div",{children:[C,o("div",{className:"py-4 text-xs text-muted-foreground text-center",children:"No addons on this node"})]}):u("div",{children:[C,u("table",{className:"w-full text-xs",children:[o("thead",{children:u("tr",{className:"text-muted-foreground text-left",children:[o("th",{className:"py-2 font-medium",children:"Addon"}),o("th",{className:"py-2 font-medium",children:"Capabilities"}),o("th",{className:"py-2 font-medium",children:"Status"}),o("th",{className:"py-2 font-medium w-16"})]})}),o("tbody",{children:t.map(E=>u("tr",{className:"border-t border-border/50",children:[o("td",{className:"py-2 font-medium",children:E.id}),o("td",{className:"py-2",children:o("div",{className:"flex flex-wrap gap-1",children:E.capabilities.length>0?E.capabilities.map(A=>o("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400",children:A},A)):o("span",{className:"text-muted-foreground",children:"—"})})}),o("td",{className:"py-2",children:o("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full ${E.status==="running"?"bg-success/10 text-success":E.status==="error"?"bg-destructive/10 text-destructive":"bg-muted text-muted-foreground"}`,children:E.status})}),o("td",{className:"py-2",children:u("div",{className:"flex items-center gap-1 justify-end",children:[o("button",{onClick:()=>v(E.id),disabled:a===E.id||l===E.id,className:"p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",title:`Restart ${E.id}`,children:o(yt,{className:`h-3 w-3 ${a===E.id?"animate-spin":""}`})}),o("button",{onClick:()=>N(E.id),disabled:a===E.id||l===E.id,className:"p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50",title:`Uninstall ${E.id}`,children:l===E.id?o(Ee,{className:"h-3 w-3 animate-spin"}):o(Ke,{className:"h-3 w-3"})})]})})]},E.id))})]})]})}function Fz(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 jz({state:e}){return o("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 Hz=["trace","debug","info","warn","error"];function Vz({proc:e,nodeId:t,defaultExpanded:n,activePanel:r,onTogglePanel:s}){const a=e.services??[],i=a.length===1,[l,c]=P(i||n),[d,f]=P(null),[p,h]=P("info"),m=e.name.includes("(core)"),g=Ma(),b=Gb(),x=Zb(),y=async N=>{f(N);try{await g.mutateAsync({nodeId:t,addonId:N})}catch(k){console.error("Failed to restart addon:",k)}finally{f(null)}},w=async()=>{f(e.name);try{await b.mutateAsync({nodeId:t,processName:e.name})}catch(N){console.error("Failed to restart process:",N)}finally{f(null)}},v=async N=>{const k=`${t}/${e.name}`;try{await x.mutateAsync({nodeId:k,level:N}),h(N)}catch(C){console.error("Failed to set log level:",C)}};return u("div",{className:"border border-border/50 rounded-lg overflow-hidden",children:[u("div",{role:i?void 0:"button",tabIndex:i?void 0:0,onClick:i?void 0:()=>c(!l),onKeyDown:i?void 0:N=>{(N.key==="Enter"||N.key===" ")&&c(!l)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${i?"":"hover:bg-muted/40 cursor-pointer"}`,children:[i?o("span",{className:"h-3 w-3 shrink-0"}):l?o(Nt,{className:"h-3 w-3 text-muted-foreground shrink-0"}):o(Et,{className:"h-3 w-3 text-muted-foreground shrink-0"}),m?o(cn,{className:"h-3.5 w-3.5 text-primary shrink-0"}):o(Ra,{className:"h-3.5 w-3.5 text-amber-500 shrink-0"}),o("span",{className:"text-xs font-semibold flex-1",children:e.name}),u("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:["PID ",e.pid]}),o(jz,{state:e.state}),u("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:[e.cpuPercent,"% CPU"]}),o("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:kt(e.memoryRss)}),o("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:Fz(e.uptimeSeconds)}),!m&&u("div",{className:"flex items-center gap-1",onClick:N=>N.stopPropagation(),children:[u(zm,{children:[o(Fm,{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:p}),o(jm,{align:"end",className:"min-w-[70px] py-0.5",children:Hz.map(N=>o(Hm,{onClick:()=>v(N),className:`h-auto px-2 py-1 text-[10px] font-mono ${N===p?"text-primary font-semibold":""}`,children:N},N))})]}),o("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:o(yt,{className:`h-3 w-3 ${d===e.name?"animate-spin":""}`})})]})]}),l&&a.length>0&&o("div",{className:"divide-y divide-border/30",children:a.map(N=>u("div",{children:[u("div",{className:"flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors",children:[o("div",{className:`h-1.5 w-1.5 rounded-full shrink-0 ${N.status==="running"?"bg-success":"bg-muted-foreground/30"}`}),o("span",{className:"text-xs font-medium flex-1 min-w-0 truncate",children:N.addonId}),N.capabilities.length>0&&u("div",{className:"flex gap-1 flex-shrink-0",children:[N.capabilities.slice(0,3).map(k=>o("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]",children:k},k)),N.capabilities.length>3&&u("span",{className:"text-[9px] text-muted-foreground",children:["+",N.capabilities.length-3]})]}),u("div",{className:"flex items-center gap-1 shrink-0",children:[o("button",{onClick:()=>s(N.addonId,"logs"),className:`p-0.5 rounded transition-colors ${r?.addonId===N.addonId&&r.type==="logs"?"bg-primary/10 text-primary":"hover:bg-muted text-muted-foreground hover:text-foreground"}`,title:`Show logs for ${N.addonId}`,children:o(rt,{className:"h-3 w-3"})}),o("button",{onClick:()=>s(N.addonId,"events"),className:`p-0.5 rounded transition-colors ${r?.addonId===N.addonId&&r.type==="events"?"bg-primary/10 text-primary":"hover:bg-muted text-muted-foreground hover:text-foreground"}`,title:`Show events for ${N.addonId}`,children:o(Ba,{className:"h-3 w-3"})}),o("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:o(yt,{className:`h-3 w-3 ${d===N.addonId?"animate-spin":""}`})})]})]}),r?.addonId===N.addonId&&r.type==="logs"&&o("div",{className:"border-t border-border/40 bg-muted/5",children:o(Xt,{addonId:N.addonId,agentId:t,maxHeight:"max-h-48",showFilters:!1,onClose:()=>s(N.addonId,"logs")})}),r?.addonId===N.addonId&&r.type==="events"&&o("div",{className:"border-t border-border/40 bg-muted/5",children:o(cr,{addonId:N.addonId,category:"addon.*",maxHeight:"max-h-48",onClose:()=>s(N.addonId,"events")})})]},N.addonId))}),l&&a.length===0&&o("div",{className:"px-3 py-2 pl-9 text-[10px] text-muted-foreground",children:"No services"})]})}function qz({nodeId:e,processes:t}){const[n,r]=P(null),s=(a,i)=>{r(l=>l?.addonId===a&&l.type===i?null:{addonId:a,type:i})};return t.length===0?o("div",{className:"py-4 text-xs text-muted-foreground text-center",children:"No processes on this node"}):o("div",{className:"space-y-2 py-1",children:t.map((a,i)=>o(Vz,{proc:a,nodeId:e,defaultExpanded:i===0,activePanel:n,onTogglePanel:s},a.name))})}function Uz(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 Qz(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Gz({nodeId:e}){const t=ke(),n=Je(),[r,s]=P("all"),a=Br("metrics.node-processes-snapshot",k=>k.nodeId===e),{data:i}=Vb({nodeId:e},{staleTime:6e4}),l=a?.processes??i,c=q(()=>l?[...l]:[],[l]),d=q(()=>r==="ghost"?c.filter(k=>k.classification==="ghost"):c,[c,r]),f=q(()=>{const k=c.filter(E=>E.classification==="ghost"),C=new Map;for(const E of k)C.has(E.ppid)||C.set(E.ppid,[]),C.get(E.ppid).push(E);return[...C.entries()].filter(([,E])=>E.length>1).map(([E,A])=>({ppid:E,children:A})).sort((E,A)=>A.children.length-E.children.length)},[c]),p=qb({onSettled:()=>{t.invalidateQueries({queryKey:[["metricsProvider","listNodeProcesses"]]})}}),h=q(()=>{const k=new Map;for(const C of c)k.set(C.pid,C.classification);return k},[c]),m=async(k,C)=>{if(k.classification==="root"||k.classification==="system")return;const E=k.classification==="ghost"?"ghost":k.addonId??"process",A=C?"SIGKILL":"SIGTERM";await n({title:`Send ${A}?`,message:`Target pid ${k.pid} (${E}) on node ${e}.`,confirmLabel:`Send ${A}`,variant:"danger"})&&p.mutate({nodeId:e,pid:k.pid,force:C})},g=async(k,C)=>{try{await p.mutateAsync({nodeId:e,pid:k,force:C})}catch{}},b=async k=>{const C=h.get(k.ppid);if(C==="root"||C==="system"){await n({title:"Cannot kill protected ancestor",message:C==="root"?`pid ${k.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${k.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:"OK",cancelLabel:"Close",variant:"warning"});return}await n({title:`Kill ghost parent + ${k.children.length} child(ren)?`,message:`SIGKILL parent pid ${k.ppid} and SIGTERM ${k.children.length} ghost child(ren) on node ${e}.`,confirmLabel:"Kill all",variant:"danger"})&&(await Promise.all([g(k.ppid,!0),...k.children.map(A=>g(A.pid,!1))]),t.invalidateQueries({queryKey:[["metricsProvider","listNodeProcesses"]]}))},x=async()=>{const k=c.filter(E=>E.classification==="ghost");k.length===0||!await n({title:`Kill all ${k.length} ghost process(es)?`,message:`SIGKILL ${k.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:"Kill all",variant:"danger"})||(await Promise.all(k.map(E=>g(E.pid,!0))),t.invalidateQueries({queryKey:[["metricsProvider","listNodeProcesses"]]}))},y=c.filter(k=>k.classification==="ghost").length,w=c.filter(k=>k.classification==="managed").length,v=c.filter(k=>k.classification==="root").length,N=c.filter(k=>k.classification==="system").length;return u("div",{className:"space-y-4",children:[u("div",{className:"flex items-start justify-between gap-4",children:[u("p",{className:"text-[11px] text-foreground-subtle",children:["ps"," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),u("button",{type:"button",onClick:()=>t.invalidateQueries({queryKey:[["metricsProvider","listNodeProcesses"]]}),className:"inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover",children:[o(ht,{className:"h-3 w-3"})," Refresh"]})]}),u("div",{className:"grid grid-cols-4 gap-3",children:[u("div",{className:"rounded-lg border border-border p-3",children:[o("div",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:"Root"}),o("div",{className:"text-xl font-semibold text-foreground",children:v})]}),u("div",{className:"rounded-lg border border-border p-3",children:[o("div",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:"Managed"}),o("div",{className:"text-xl font-semibold text-foreground",children:w})]}),u("div",{className:"rounded-lg border border-border p-3",children:[o("div",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:"System"}),o("div",{className:"text-xl font-semibold text-foreground",children:N})]}),u("div",{className:`rounded-lg border p-3 ${y>0?"border-destructive/40 bg-destructive/5":"border-border"}`,children:[u("div",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1",children:[y>0&&o(ps,{className:"h-3 w-3 text-destructive"})," Ghosts"]}),o("div",{className:`text-xl font-semibold ${y>0?"text-destructive":"text-foreground"}`,children:y})]})]}),f.length>0&&u("div",{className:"rounded-lg border border-amber-500/40 bg-amber-500/5 p-3",children:[u("div",{className:"flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2",children:[o(ut,{className:"h-3 w-3"})," Recurring ghost parents (",f.length,")"]}),o("div",{className:"space-y-1.5",children:f.map(k=>u("div",{className:"text-[11px] text-foreground flex items-center justify-between gap-2",children:[u("div",{className:"flex items-center gap-2",children:[u("span",{className:"font-mono text-foreground-subtle",children:["ppid ",k.ppid]}),u("span",{children:["→ ",k.children.length," ghost(s)"]})]}),u("button",{type:"button",disabled:p.isPending,onClick:()=>{b(k)},className:"inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30",children:[o(ps,{className:"h-3 w-3"})," Kill parent + ",k.children.length]})]},k.ppid))})]}),u("div",{className:"flex items-center justify-between gap-2 text-[11px]",children:[u("div",{className:"flex items-center gap-2",children:[o("span",{className:"text-foreground-subtle",children:"Filter:"}),u("button",{type:"button",className:`px-2 py-0.5 rounded ${r==="all"?"bg-primary text-primary-foreground":"border border-border text-foreground hover:bg-surface-hover"}`,onClick:()=>s("all"),children:["All (",c.length,")"]}),u("button",{type:"button",className:`px-2 py-0.5 rounded ${r==="ghost"?"bg-destructive text-destructive-foreground":"border border-border text-foreground hover:bg-surface-hover"}`,onClick:()=>s("ghost"),children:["Ghost only (",y,")"]})]}),y>0&&u("button",{type:"button",disabled:p.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:[o(ps,{className:"h-3 w-3"})," Kill all ",y," ghost(s)"]})]}),o("div",{className:"rounded-lg border border-border overflow-hidden",children:u("table",{className:"w-full text-xs",children:[o("thead",{className:"bg-surface",children:u("tr",{className:"text-foreground-subtle text-[10px] uppercase tracking-wider",children:[o("th",{className:"text-left px-3 py-2",children:"Class"}),o("th",{className:"text-right px-3 py-2",children:"PID"}),o("th",{className:"text-right px-3 py-2",children:"PPID"}),o("th",{className:"text-left px-3 py-2",children:"Addon"}),o("th",{className:"text-left px-3 py-2",children:"Command"}),o("th",{className:"text-right px-3 py-2",children:"CPU%"}),o("th",{className:"text-right px-3 py-2",children:"RSS"}),o("th",{className:"text-right px-3 py-2",children:"Uptime"}),o("th",{className:"w-44"})]})}),u("tbody",{children:[d.length===0&&o("tr",{children:o("td",{colSpan:9,className:"px-3 py-4 text-center text-foreground-subtle text-[11px]",children:r==="ghost"?"No ghost processes detected.":"Scanning…"})}),d.map(k=>u("tr",{className:`border-t border-border ${k.classification==="ghost"?"bg-destructive/5":""}`,children:[o("td",{className:"px-3 py-2",children:o("span",{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${k.classification==="ghost"?"bg-destructive/20 text-destructive":k.classification==="root"?"bg-sky-500/20 text-sky-400":k.classification==="system"?"bg-foreground-subtle/20 text-foreground-subtle":"bg-success/20 text-success"}`,children:k.classification})}),o("td",{className:"px-3 py-2 text-right font-mono text-foreground",children:k.pid}),u("td",{className:"px-3 py-2 text-right font-mono text-foreground-subtle",children:[k.ppid,k.orphaned?" ⚠":""]}),o("td",{className:"px-3 py-2 text-foreground-subtle text-[11px]",children:k.addonId??"—"}),o("td",{className:"px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all",children:Qz(k.command)}),o("td",{className:"px-3 py-2 text-right text-foreground",children:k.cpuPercent.toFixed(1)}),o("td",{className:"px-3 py-2 text-right text-foreground",children:kt(k.memoryRssBytes)}),o("td",{className:"px-3 py-2 text-right text-foreground-subtle",children:Uz(k.uptimeSec)}),o("td",{className:"px-3 py-2 text-right",children:u("div",{className:"inline-flex gap-1",children:[u("button",{type:"button",disabled:p.isPending||k.classification==="root"||k.classification==="system",onClick:()=>{m(k,!1)},title:"SIGTERM",className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30",children:[o(Ke,{className:"h-3 w-3"})," Term"]}),u("button",{type:"button",disabled:p.isPending||k.classification==="root"||k.classification==="system",onClick:()=>{m(k,!0)},title:"SIGKILL",className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30",children:[o(ps,{className:"h-3 w-3"})," Kill"]})]})})]},k.pid))]})]})}),p.isError&&u("div",{className:"rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive",children:["Kill failed: ",p.error instanceof Error?p.error.message:"unknown"]})]})}function Kz({nodeId:e,addonIds:t}){return t.length===0?o("div",{className:"py-4 text-xs text-muted-foreground text-center",children:"No addons on this node"}):o("div",{className:"w-full py-2",children:o(Qr,{nodeId:e,addonIds:t,level:"global"})})}function Wz({nodeId:e,addons:t}){const n=ke(),{data:r,isLoading:s}=cx({nodeId:e}),a=q(()=>{const l=new Map;for(const c of t)for(const d of c.capabilities){const f=l.get(d)??[];f.push(c.id),l.set(d,f)}return[...l.entries()].sort(([c],[d])=>c.localeCompare(d)).map(([c,d])=>({capName:c,providers:d}))},[t]),i=dx({onSuccess:()=>{n.invalidateQueries({queryKey:[["pipelineOrchestrator","getCapabilityBindings"]]})}});return a.length===0?o("div",{className:"py-4 text-xs text-muted-foreground text-center",children:"No capabilities on this node"}):u("table",{className:"w-full text-xs",children:[o("thead",{children:u("tr",{className:"text-muted-foreground text-left",children:[o("th",{className:"py-2 font-medium w-1/2",children:"Capability"}),o("th",{className:"py-2 font-medium",children:"Bound provider"})]})}),o("tbody",{children:a.map(({capName:l,providers:c})=>{const f=r?.[l]??c[0]??"",p=c.length===1;return u("tr",{className:"border-t border-border/50",children:[o("td",{className:"py-2 font-medium",children:l}),o("td",{className:"py-2",children:o("select",{value:f,onChange:h=>i.mutate({nodeId:e,capName:l,addonId:h.target.value}),disabled:p||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:p?"Only one provider installed — choice becomes available once a second addon registers this capability":void 0,children:c.map(h=>o("option",{value:h,children:h},h))})})]},l)})})]})}function Yz(e){if(e==null)return"—";const t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),s=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${s}m`:r>0?`${r}h ${s}m`:`${s}m`}function Zz(e){const[t,n]=P(!1),[r,s]=P(e.name),a=ke(),i=Wb({onSuccess:()=>{a.invalidateQueries({queryKey:[["nodes","topology"]]})}}),l=(e.localIps??[]).filter(p=>!p.includes(":")),c=(e.localIps??[]).filter(p=>p.includes(":")),d=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await i.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(p){console.error("Rename failed:",p)}},f=[["Node ID",o("span",{className:"font-mono text-xs",children:e.nodeId})],["Display Name",t?u("div",{className:"flex items-center gap-1.5",children:[o("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:r,onChange:p=>s(p.target.value),onKeyDown:p=>{p.key==="Enter"&&d(),p.key==="Escape"&&n(!1)},disabled:i.isPending,autoFocus:!0}),o("button",{onClick:()=>void d(),disabled:i.isPending,className:"p-0.5 text-success hover:bg-success/10 rounded",title:"Save",children:o(Mt,{className:"h-3.5 w-3.5"})}),o("button",{onClick:()=>n(!1),className:"p-0.5 text-muted-foreground hover:bg-muted rounded",title:"Cancel",children:o(Fe,{className:"h-3.5 w-3.5"})})]}):u("div",{className:"flex items-center gap-1.5",children:[o("span",{className:"text-xs",children:e.name}),!e.isHub&&o("button",{onClick:()=>{s(e.name),n(!0)},className:"p-0.5 text-muted-foreground hover:text-primary rounded",title:"Rename",children:o(Ur,{className:"h-3 w-3"})})]})],["Hostname",o("span",{className:"text-xs",children:e.hostname})],["Role",e.isHub?o("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium",children:"Hub"}):o("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium",children:"Agent"})],["Platform",u("span",{className:"text-xs",children:[e.platform," / ",e.arch]})],["CPU",u("span",{className:"text-xs",children:[e.cpuModel??"—"," (",e.cpuCores," cores)"]})],["Memory",o("span",{className:"text-xs",children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:"—"})],["Uptime",o("span",{className:"text-xs",children:Yz(e.uptime)})],["Engines",e.engines.length>0?o("div",{className:"flex flex-wrap gap-1",children:e.engines.map(p=>o("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium",children:p},p))}):o("span",{className:"text-xs text-muted-foreground",children:"—"})]];return l.length>0&&f.push(["IPv4",o("div",{className:"flex flex-wrap gap-1.5",children:l.map((p,h)=>o("span",{className:"font-mono text-xs px-1.5 py-0.5 rounded bg-muted",children:p},`${p}-${h}`))})]),c.length>0&&f.push(["IPv6",o("div",{className:"flex flex-wrap gap-1.5",children:c.map((p,h)=>o("span",{className:"font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]",title:p,children:p},`${p}-${h}`))})]),o("div",{className:"py-2",children:o("table",{className:"w-full text-sm",children:o("tbody",{children:f.map(([p,h],m)=>u("tr",{className:m%2===0?"bg-muted/20":"",children:[o("td",{className:"py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap",children:p}),o("td",{className:"py-1.5 px-2",children:h})]},p))})})})}function Xz({node:e}){const[t,n]=P("info"),r=e.processes??[],s=e.addons.map(a=>a.id);return e.isOnline?u("div",{className:"border border-border rounded-xl overflow-hidden",children:[u("div",{className:"flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border",children:[o("div",{className:"w-2.5 h-2.5 rounded-full bg-success"}),o("span",{className:"text-sm font-semibold",children:e.name}),u("span",{className:"text-xs text-muted-foreground",children:[e.cpuModel??e.platform," · ",e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:""," · ",e.arch]}),e.engines.map(a=>o("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium",children:a},a)),u("div",{className:"ml-auto flex gap-3 text-xs text-muted-foreground",children:[u("span",{className:"flex items-center gap-1",children:[o(ft,{className:"h-3 w-3"})," ",e.cpuPercent,"%"]}),u("span",{className:"flex items-center gap-1",children:[o(Pd,{className:"h-3 w-3"})," ",e.memoryPercent,"%"]})]})]}),o("div",{className:"flex border-b border-border px-4",children:["info","addons","forks","processes","settings","capabilities"].map(a=>o("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 (${r.length})`:a==="processes"?"Processes":a==="settings"?"Settings":"Capabilities"},a))}),u("div",{className:"px-4 py-2",children:[t==="info"&&o(Zz,{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"&&o(zz,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),t==="forks"&&o(qz,{nodeId:e.id,processes:r}),t==="processes"&&o(Gz,{nodeId:e.id}),t==="settings"&&o(Kz,{nodeId:e.id,addonIds:s}),t==="capabilities"&&o(Wz,{nodeId:e.id,addons:e.addons})]})]}):u("div",{className:"border border-border rounded-xl overflow-hidden opacity-60",children:[u("div",{className:"flex items-center gap-3 px-4 py-3 bg-muted/30",children:[o("div",{className:"w-2.5 h-2.5 rounded-full bg-destructive"}),o("span",{className:"text-sm font-semibold",children:e.name}),u("span",{className:"text-xs text-muted-foreground",children:[e.cpuModel??e.platform," · ",e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:""," · ",e.arch]}),e.engines.map(a=>o("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium",children:a},a)),o("span",{className:"ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive",children:"offline"})]}),u("div",{className:"px-4 py-3 text-xs text-muted-foreground",children:[e.addons.length," addon",e.addons.length!==1?"s":""," assigned — will resume when node reconnects"]})]})}function Jz({nodes:e}){const t=[...e].sort((n,r)=>n.isHub?-1:r.isHub?1:n.isOnline&&!r.isOnline?-1:!n.isOnline&&r.isOnline?1:n.name.localeCompare(r.name));return o("div",{className:"flex flex-col gap-4",children:t.map(n=>o(Xz,{node:n},n.id))})}function Qe(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=Qe(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var eF={value:()=>{}};function Qa(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new Bs(n)}function Bs(e){this._=e}function tF(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",s=n.indexOf(".");if(s>=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}Bs.prototype=Qa.prototype={constructor:Bs,on:function(e,t){var n=this._,r=tF(e+"",n),s,a=-1,i=r.length;if(arguments.length<2){for(;++a<i;)if((s=(e=r[a]).type)&&(s=nF(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=r[a]).type)n[s]=of(n[s],e.name,t);else if(t==null)for(s in n)n[s]=of(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 Bs(e)},call:function(e,t){if((s=arguments.length-2)>0)for(var n=new Array(s),r=0,s,a;r<s;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(a=this._[e],r=0,s=a.length;r<s;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],s=0,a=r.length;s<a;++s)r[s].value.apply(t,n)}};function nF(e,t){for(var n=0,r=e.length,s;n<r;++n)if((s=e[n]).name===t)return s.value}function of(e,t,n){for(var r=0,s=e.length;r<s;++r)if(e[r].name===t){e[r]=eF,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var ql="http://www.w3.org/1999/xhtml";const sf={svg:"http://www.w3.org/2000/svg",xhtml:ql,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Ga(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),sf.hasOwnProperty(t)?{space:sf[t],local:e}:e}function rF(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===ql&&t.documentElement.namespaceURI===ql?t.createElement(e):t.createElementNS(n,e)}}function oF(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ov(e){var t=Ga(e);return(t.local?oF:rF)(t)}function sF(){}function Ld(e){return e==null?sF:function(){return this.querySelector(e)}}function aF(e){typeof e!="function"&&(e=Ld(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var a=t[s],i=a.length,l=r[s]=new Array(i),c,d,f=0;f<i;++f)(c=a[f])&&(d=e.call(c,c.__data__,f,a))&&("__data__"in c&&(d.__data__=c.__data__),l[f]=d);return new mt(r,this._parents)}function iF(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function lF(){return[]}function sv(e){return e==null?lF:function(){return this.querySelectorAll(e)}}function cF(e){return function(){return iF(e.apply(this,arguments))}}function dF(e){typeof e=="function"?e=cF(e):e=sv(e);for(var t=this._groups,n=t.length,r=[],s=[],a=0;a<n;++a)for(var i=t[a],l=i.length,c,d=0;d<l;++d)(c=i[d])&&(r.push(e.call(c,c.__data__,d,i)),s.push(c));return new mt(r,s)}function av(e){return function(){return this.matches(e)}}function iv(e){return function(t){return t.matches(e)}}var uF=Array.prototype.find;function pF(e){return function(){return uF.call(this.children,e)}}function fF(){return this.firstElementChild}function hF(e){return this.select(e==null?fF:pF(typeof e=="function"?e:iv(e)))}var mF=Array.prototype.filter;function gF(){return Array.from(this.children)}function bF(e){return function(){return mF.call(this.children,e)}}function xF(e){return this.selectAll(e==null?gF:bF(typeof e=="function"?e:iv(e)))}function yF(e){typeof e!="function"&&(e=av(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var a=t[s],i=a.length,l=r[s]=[],c,d=0;d<i;++d)(c=a[d])&&e.call(c,c.__data__,d,a)&&l.push(c);return new mt(r,this._parents)}function lv(e){return new Array(e.length)}function vF(){return new mt(this._enter||this._groups.map(lv),this._parents)}function ra(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}ra.prototype={constructor:ra,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 wF(e){return function(){return e}}function NF(e,t,n,r,s,a){for(var i=0,l,c=t.length,d=a.length;i<d;++i)(l=t[i])?(l.__data__=a[i],r[i]=l):n[i]=new ra(e,a[i]);for(;i<c;++i)(l=t[i])&&(s[i]=l)}function kF(e,t,n,r,s,a,i){var l,c,d=new Map,f=t.length,p=a.length,h=new Array(f),m;for(l=0;l<f;++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<p;++l)m=i.call(e,a[l],l,a)+"",(c=d.get(m))?(r[l]=c,c.__data__=a[l],d.delete(m)):n[l]=new ra(e,a[l]);for(l=0;l<f;++l)(c=t[l])&&d.get(h[l])===c&&(s[l]=c)}function SF(e){return e.__data__}function CF(e,t){if(!arguments.length)return Array.from(this,SF);var n=t?kF:NF,r=this._parents,s=this._groups;typeof e!="function"&&(e=wF(e));for(var a=s.length,i=new Array(a),l=new Array(a),c=new Array(a),d=0;d<a;++d){var f=r[d],p=s[d],h=p.length,m=MF(e.call(f,f&&f.__data__,d,r)),g=m.length,b=l[d]=new Array(g),x=i[d]=new Array(g),y=c[d]=new Array(h);n(f,p,b,x,y,m,t);for(var w=0,v=0,N,k;w<g;++w)if(N=b[w]){for(w>=v&&(v=w+1);!(k=x[v])&&++v<g;);N._next=k||null}}return i=new mt(i,r),i._enter=l,i._exit=c,i}function MF(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function EF(){return new mt(this._exit||this._groups.map(lv),this._parents)}function IF(e,t,n){var r=this.enter(),s=this,a=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(s=t(s),s&&(s=s.selection())),n==null?a.remove():n(a),r&&s?r.merge(s).order():s}function AF(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,s=n.length,a=r.length,i=Math.min(s,a),l=new Array(s),c=0;c<i;++c)for(var d=n[c],f=r[c],p=d.length,h=l[c]=new Array(p),m,g=0;g<p;++g)(m=d[g]||f[g])&&(h[g]=m);for(;c<s;++c)l[c]=n[c];return new mt(l,this._parents)}function PF(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],s=r.length-1,a=r[s],i;--s>=0;)(i=r[s])&&(a&&i.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(i,a),a=i);return this}function _F(e){e||(e=$F);function t(p,h){return p&&h?e(p.__data__,h.__data__):!p-!h}for(var n=this._groups,r=n.length,s=new Array(r),a=0;a<r;++a){for(var i=n[a],l=i.length,c=s[a]=new Array(l),d,f=0;f<l;++f)(d=i[f])&&(c[f]=d);c.sort(t)}return new mt(s,this._parents).order()}function $F(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function DF(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function TF(){return Array.from(this)}function LF(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,a=r.length;s<a;++s){var i=r[s];if(i)return i}return null}function RF(){let e=0;for(const t of this)++e;return e}function OF(){return!this.node()}function BF(e){for(var t=this._groups,n=0,r=t.length;n<r;++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 zF(e){return function(){this.removeAttribute(e)}}function FF(e){return function(){this.removeAttributeNS(e.space,e.local)}}function jF(e,t){return function(){this.setAttribute(e,t)}}function HF(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function VF(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function qF(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 UF(e,t){var n=Ga(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?FF:zF:typeof t=="function"?n.local?qF:VF:n.local?HF:jF)(n,t))}function cv(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function QF(e){return function(){this.style.removeProperty(e)}}function GF(e,t,n){return function(){this.style.setProperty(e,t,n)}}function KF(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function WF(e,t,n){return arguments.length>1?this.each((t==null?QF:typeof t=="function"?KF:GF)(e,t,n??"")):Ar(this.node(),e)}function Ar(e,t){return e.style.getPropertyValue(t)||cv(e).getComputedStyle(e,null).getPropertyValue(t)}function YF(e){return function(){delete this[e]}}function ZF(e,t){return function(){this[e]=t}}function XF(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function JF(e,t){return arguments.length>1?this.each((t==null?YF:typeof t=="function"?XF:ZF)(e,t)):this.node()[e]}function dv(e){return e.trim().split(/^|\s+/)}function Rd(e){return e.classList||new uv(e)}function uv(e){this._node=e,this._names=dv(e.getAttribute("class")||"")}uv.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 pv(e,t){for(var n=Rd(e),r=-1,s=t.length;++r<s;)n.add(t[r])}function fv(e,t){for(var n=Rd(e),r=-1,s=t.length;++r<s;)n.remove(t[r])}function ej(e){return function(){pv(this,e)}}function tj(e){return function(){fv(this,e)}}function nj(e,t){return function(){(t.apply(this,arguments)?pv:fv)(this,e)}}function rj(e,t){var n=dv(e+"");if(arguments.length<2){for(var r=Rd(this.node()),s=-1,a=n.length;++s<a;)if(!r.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?nj:t?ej:tj)(n,t))}function oj(){this.textContent=""}function sj(e){return function(){this.textContent=e}}function aj(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function ij(e){return arguments.length?this.each(e==null?oj:(typeof e=="function"?aj:sj)(e)):this.node().textContent}function lj(){this.innerHTML=""}function cj(e){return function(){this.innerHTML=e}}function dj(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function uj(e){return arguments.length?this.each(e==null?lj:(typeof e=="function"?dj:cj)(e)):this.node().innerHTML}function pj(){this.nextSibling&&this.parentNode.appendChild(this)}function fj(){return this.each(pj)}function hj(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function mj(){return this.each(hj)}function gj(e){var t=typeof e=="function"?e:ov(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function bj(){return null}function xj(e,t){var n=typeof e=="function"?e:ov(e),r=t==null?bj:typeof t=="function"?t:Ld(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function yj(){var e=this.parentNode;e&&e.removeChild(this)}function vj(){return this.each(yj)}function wj(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Nj(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function kj(e){return this.select(e?Nj:wj)}function Sj(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Cj(e){return function(t){e.call(this,t,this.__data__)}}function Mj(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function Ej(e){return function(){var t=this.__on;if(t){for(var n=0,r=-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[++r]=a;++r?t.length=r:delete this.__on}}}function Ij(e,t,n){return function(){var r=this.__on,s,a=Cj(t);if(r){for(var i=0,l=r.length;i<l;++i)if((s=r[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},r?r.push(s):this.__on=[s]}}function Aj(e,t,n){var r=Mj(e+""),s,a=r.length,i;if(arguments.length<2){var l=this.node().__on;if(l){for(var c=0,d=l.length,f;c<d;++c)for(s=0,f=l[c];s<a;++s)if((i=r[s]).type===f.type&&i.name===f.name)return f.value}return}for(l=t?Ij:Ej,s=0;s<a;++s)this.each(l(r[s],t,n));return this}function hv(e,t,n){var r=cv(e),s=r.CustomEvent;typeof s=="function"?s=new s(t,n):(s=r.document.createEvent("Event"),n?(s.initEvent(t,n.bubbles,n.cancelable),s.detail=n.detail):s.initEvent(t,!1,!1)),e.dispatchEvent(s)}function Pj(e,t){return function(){return hv(this,e,t)}}function _j(e,t){return function(){return hv(this,e,t.apply(this,arguments))}}function $j(e,t){return this.each((typeof t=="function"?_j:Pj)(e,t))}function*Dj(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,a=r.length,i;s<a;++s)(i=r[s])&&(yield i)}var mv=[null];function mt(e,t){this._groups=e,this._parents=t}function Wo(){return new mt([[document.documentElement]],mv)}function Tj(){return this}mt.prototype=Wo.prototype={constructor:mt,select:aF,selectAll:dF,selectChild:hF,selectChildren:xF,filter:yF,data:CF,enter:vF,exit:EF,join:IF,merge:AF,selection:Tj,order:PF,sort:_F,call:DF,nodes:TF,node:LF,size:RF,empty:OF,each:BF,attr:UF,style:WF,property:JF,classed:rj,text:ij,html:uj,raise:fj,lower:mj,append:gj,insert:xj,remove:vj,clone:kj,datum:Sj,on:Aj,dispatch:$j,[Symbol.iterator]:Dj};function ct(e){return typeof e=="string"?new mt([[document.querySelector(e)]],[document.documentElement]):new mt([[e]],mv)}function Lj(e){let t;for(;t=e.sourceEvent;)e=t;return e}function _t(e,t){if(e=Lj(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.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 Rj={passive:!1},Co={capture:!0,passive:!1};function Ki(e){e.stopImmediatePropagation()}function wr(e){e.preventDefault(),e.stopImmediatePropagation()}function gv(e){var t=e.document.documentElement,n=ct(e).on("dragstart.drag",wr,Co);"onselectstart"in t?n.on("selectstart.drag",wr,Co):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function bv(e,t){var n=e.document.documentElement,r=ct(e).on("dragstart.drag",null);t&&(r.on("click.drag",wr,Co),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const Ns=e=>()=>e;function Ul(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:a,x:i,y:l,dx:c,dy:d,dispatch:f}){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:r,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:f}})}Ul.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Oj(e){return!e.ctrlKey&&!e.button}function Bj(){return this.parentNode}function zj(e,t){return t??{x:e.x,y:e.y}}function Fj(){return navigator.maxTouchPoints||"ontouchstart"in this}function xv(){var e=Oj,t=Bj,n=zj,r=Fj,s={},a=Qa("start","drag","end"),i=0,l,c,d,f,p=0;function h(N){N.on("mousedown.drag",m).filter(r).on("touchstart.drag",x).on("touchmove.drag",y,Rj).on("touchend.drag touchcancel.drag",w).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function m(N,k){if(!(f||!e.call(this,N,k))){var C=v(this,t.call(this,N,k),N,k,"mouse");C&&(ct(N.view).on("mousemove.drag",g,Co).on("mouseup.drag",b,Co),gv(N.view),Ki(N),d=!1,l=N.clientX,c=N.clientY,C("start",N))}}function g(N){if(wr(N),!d){var k=N.clientX-l,C=N.clientY-c;d=k*k+C*C>p}s.mouse("drag",N)}function b(N){ct(N.view).on("mousemove.drag mouseup.drag",null),bv(N.view,d),wr(N),s.mouse("end",N)}function x(N,k){if(e.call(this,N,k)){var C=N.changedTouches,E=t.call(this,N,k),A=C.length,I,z;for(I=0;I<A;++I)(z=v(this,E,N,k,C[I].identifier,C[I]))&&(Ki(N),z("start",N,C[I]))}}function y(N){var k=N.changedTouches,C=k.length,E,A;for(E=0;E<C;++E)(A=s[k[E].identifier])&&(wr(N),A("drag",N,k[E]))}function w(N){var k=N.changedTouches,C=k.length,E,A;for(f&&clearTimeout(f),f=setTimeout(function(){f=null},500),E=0;E<C;++E)(A=s[k[E].identifier])&&(Ki(N),A("end",N,k[E]))}function v(N,k,C,E,A,I){var z=a.copy(),$=_t(I||C,k),B,R,M;if((M=n.call(N,new Ul("beforestart",{sourceEvent:C,target:h,identifier:A,active:i,x:$[0],y:$[1],dx:0,dy:0,dispatch:z}),E))!=null)return B=M.x-$[0]||0,R=M.y-$[1]||0,function T(_,L,O){var j=$,F;switch(_){case"start":s[A]=T,F=i++;break;case"end":delete s[A],--i;case"drag":$=_t(O||L,k),F=i;break}z.call(_,N,new Ul(_,{sourceEvent:L,subject:M,target:h,identifier:A,active:F,x:$[0]+B,y:$[1]+R,dx:$[0]-j[0],dy:$[1]-j[1],dispatch:z}),E)}}return h.filter=function(N){return arguments.length?(e=typeof N=="function"?N:Ns(!!N),h):e},h.container=function(N){return arguments.length?(t=typeof N=="function"?N:Ns(N),h):t},h.subject=function(N){return arguments.length?(n=typeof N=="function"?N:Ns(N),h):n},h.touchable=function(N){return arguments.length?(r=typeof N=="function"?N:Ns(!!N),h):r},h.on=function(){var N=a.on.apply(a,arguments);return N===a?h:N},h.clickDistance=function(N){return arguments.length?(p=(N=+N)*N,h):Math.sqrt(p)},h}function Od(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function yv(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function Yo(){}var Mo=.7,oa=1/Mo,Nr="\\s*([+-]?\\d+)\\s*",Eo="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Gt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",jj=/^#([0-9a-f]{3,8})$/,Hj=new RegExp(`^rgb\\(${Nr},${Nr},${Nr}\\)$`),Vj=new RegExp(`^rgb\\(${Gt},${Gt},${Gt}\\)$`),qj=new RegExp(`^rgba\\(${Nr},${Nr},${Nr},${Eo}\\)$`),Uj=new RegExp(`^rgba\\(${Gt},${Gt},${Gt},${Eo}\\)$`),Qj=new RegExp(`^hsl\\(${Eo},${Gt},${Gt}\\)$`),Gj=new RegExp(`^hsla\\(${Eo},${Gt},${Gt},${Eo}\\)$`),af={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};Od(Yo,Zn,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:lf,formatHex:lf,formatHex8:Kj,formatHsl:Wj,formatRgb:cf,toString:cf});function lf(){return this.rgb().formatHex()}function Kj(){return this.rgb().formatHex8()}function Wj(){return vv(this).formatHsl()}function cf(){return this.rgb().formatRgb()}function Zn(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=jj.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?df(t):n===3?new nt(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?ks(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?ks(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=Hj.exec(e))?new nt(t[1],t[2],t[3],1):(t=Vj.exec(e))?new nt(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=qj.exec(e))?ks(t[1],t[2],t[3],t[4]):(t=Uj.exec(e))?ks(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=Qj.exec(e))?ff(t[1],t[2]/100,t[3]/100,1):(t=Gj.exec(e))?ff(t[1],t[2]/100,t[3]/100,t[4]):af.hasOwnProperty(e)?df(af[e]):e==="transparent"?new nt(NaN,NaN,NaN,0):null}function df(e){return new nt(e>>16&255,e>>8&255,e&255,1)}function ks(e,t,n,r){return r<=0&&(e=t=n=NaN),new nt(e,t,n,r)}function Yj(e){return e instanceof Yo||(e=Zn(e)),e?(e=e.rgb(),new nt(e.r,e.g,e.b,e.opacity)):new nt}function Ql(e,t,n,r){return arguments.length===1?Yj(e):new nt(e,t,n,r??1)}function nt(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Od(nt,Ql,yv(Yo,{brighter(e){return e=e==null?oa:Math.pow(oa,e),new nt(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Mo:Math.pow(Mo,e),new nt(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new nt(qn(this.r),qn(this.g),qn(this.b),sa(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:uf,formatHex:uf,formatHex8:Zj,formatRgb:pf,toString:pf}));function uf(){return`#${jn(this.r)}${jn(this.g)}${jn(this.b)}`}function Zj(){return`#${jn(this.r)}${jn(this.g)}${jn(this.b)}${jn((isNaN(this.opacity)?1:this.opacity)*255)}`}function pf(){const e=sa(this.opacity);return`${e===1?"rgb(":"rgba("}${qn(this.r)}, ${qn(this.g)}, ${qn(this.b)}${e===1?")":`, ${e})`}`}function sa(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function qn(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function jn(e){return e=qn(e),(e<16?"0":"")+e.toString(16)}function ff(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new $t(e,t,n,r)}function vv(e){if(e instanceof $t)return new $t(e.h,e.s,e.l,e.opacity);if(e instanceof Yo||(e=Zn(e)),!e)return new $t;if(e instanceof $t)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),a=Math.max(t,n,r),i=NaN,l=a-s,c=(a+s)/2;return l?(t===a?i=(n-r)/l+(n<r)*6:n===a?i=(r-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 $t(i,l,c,e.opacity)}function Xj(e,t,n,r){return arguments.length===1?vv(e):new $t(e,t,n,r??1)}function $t(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Od($t,Xj,yv(Yo,{brighter(e){return e=e==null?oa:Math.pow(oa,e),new $t(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Mo:Math.pow(Mo,e),new $t(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,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new nt(Wi(e>=240?e-240:e+120,s,r),Wi(e,s,r),Wi(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new $t(hf(this.h),Ss(this.s),Ss(this.l),sa(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=sa(this.opacity);return`${e===1?"hsl(":"hsla("}${hf(this.h)}, ${Ss(this.s)*100}%, ${Ss(this.l)*100}%${e===1?")":`, ${e})`}`}}));function hf(e){return e=(e||0)%360,e<0?e+360:e}function Ss(e){return Math.max(0,Math.min(1,e||0))}function Wi(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 Bd=e=>()=>e;function Jj(e,t){return function(n){return e+n*t}}function eH(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function tH(e){return(e=+e)==1?wv:function(t,n){return n-t?eH(t,n,e):Bd(isNaN(t)?n:t)}}function wv(e,t){var n=t-e;return n?Jj(e,n):Bd(isNaN(e)?t:e)}const aa=(function e(t){var n=tH(t);function r(s,a){var i=n((s=Ql(s)).r,(a=Ql(a)).r),l=n(s.g,a.g),c=n(s.b,a.b),d=wv(s.opacity,a.opacity);return function(f){return s.r=i(f),s.g=l(f),s.b=c(f),s.opacity=d(f),s+""}}return r.gamma=e,r})(1);function nH(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,r=t.slice(),s;return function(a){for(s=0;s<n;++s)r[s]=e[s]*(1-a)+t[s]*a;return r}}function rH(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function oH(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,s=new Array(r),a=new Array(n),i;for(i=0;i<r;++i)s[i]=ho(e[i],t[i]);for(;i<n;++i)a[i]=t[i];return function(l){for(i=0;i<r;++i)a[i]=s[i](l);return a}}function sH(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function Vt(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function aH(e,t){var n={},r={},s;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(s in t)s in e?n[s]=ho(e[s],t[s]):r[s]=t[s];return function(a){for(s in n)r[s]=n[s](a);return r}}var Gl=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Yi=new RegExp(Gl.source,"g");function iH(e){return function(){return e}}function lH(e){return function(t){return e(t)+""}}function Nv(e,t){var n=Gl.lastIndex=Yi.lastIndex=0,r,s,a,i=-1,l=[],c=[];for(e=e+"",t=t+"";(r=Gl.exec(e))&&(s=Yi.exec(t));)(a=s.index)>n&&(a=t.slice(n,a),l[i]?l[i]+=a:l[++i]=a),(r=r[0])===(s=s[0])?l[i]?l[i]+=s:l[++i]=s:(l[++i]=null,c.push({i,x:Vt(r,s)})),n=Yi.lastIndex;return n<t.length&&(a=t.slice(n),l[i]?l[i]+=a:l[++i]=a),l.length<2?c[0]?lH(c[0].x):iH(t):(t=c.length,function(d){for(var f=0,p;f<t;++f)l[(p=c[f]).i]=p.x(d);return l.join("")})}function ho(e,t){var n=typeof t,r;return t==null||n==="boolean"?Bd(t):(n==="number"?Vt:n==="string"?(r=Zn(t))?(t=r,aa):Nv:t instanceof Zn?aa:t instanceof Date?sH:rH(t)?nH:Array.isArray(t)?oH:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?aH:Vt)(e,t)}var mf=180/Math.PI,Kl={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function kv(e,t,n,r,s,a){var i,l,c;return(i=Math.sqrt(e*e+t*t))&&(e/=i,t/=i),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(l=Math.sqrt(n*n+r*r))&&(n/=l,r/=l,c/=l),e*r<t*n&&(e=-e,t=-t,c=-c,i=-i),{translateX:s,translateY:a,rotate:Math.atan2(t,e)*mf,skewX:Math.atan(c)*mf,scaleX:i,scaleY:l}}var Cs;function cH(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Kl:kv(t.a,t.b,t.c,t.d,t.e,t.f)}function dH(e){return e==null||(Cs||(Cs=document.createElementNS("http://www.w3.org/2000/svg","g")),Cs.setAttribute("transform",e),!(e=Cs.transform.baseVal.consolidate()))?Kl:(e=e.matrix,kv(e.a,e.b,e.c,e.d,e.e,e.f))}function Sv(e,t,n,r){function s(d){return d.length?d.pop()+" ":""}function a(d,f,p,h,m,g){if(d!==p||f!==h){var b=m.push("translate(",null,t,null,n);g.push({i:b-4,x:Vt(d,p)},{i:b-2,x:Vt(f,h)})}else(p||h)&&m.push("translate("+p+t+h+n)}function i(d,f,p,h){d!==f?(d-f>180?f+=360:f-d>180&&(d+=360),h.push({i:p.push(s(p)+"rotate(",null,r)-2,x:Vt(d,f)})):f&&p.push(s(p)+"rotate("+f+r)}function l(d,f,p,h){d!==f?h.push({i:p.push(s(p)+"skewX(",null,r)-2,x:Vt(d,f)}):f&&p.push(s(p)+"skewX("+f+r)}function c(d,f,p,h,m,g){if(d!==p||f!==h){var b=m.push(s(m)+"scale(",null,",",null,")");g.push({i:b-4,x:Vt(d,p)},{i:b-2,x:Vt(f,h)})}else(p!==1||h!==1)&&m.push(s(m)+"scale("+p+","+h+")")}return function(d,f){var p=[],h=[];return d=e(d),f=e(f),a(d.translateX,d.translateY,f.translateX,f.translateY,p,h),i(d.rotate,f.rotate,p,h),l(d.skewX,f.skewX,p,h),c(d.scaleX,d.scaleY,f.scaleX,f.scaleY,p,h),d=f=null,function(m){for(var g=-1,b=h.length,x;++g<b;)p[(x=h[g]).i]=x.x(m);return p.join("")}}}var uH=Sv(cH,"px, ","px)","deg)"),pH=Sv(dH,", ",")",")"),fH=1e-12;function gf(e){return((e=Math.exp(e))+1/e)/2}function hH(e){return((e=Math.exp(e))-1/e)/2}function mH(e){return((e=Math.exp(2*e))-1)/(e+1)}const zs=(function e(t,n,r){function s(a,i){var l=a[0],c=a[1],d=a[2],f=i[0],p=i[1],h=i[2],m=f-l,g=p-c,b=m*m+g*g,x,y;if(b<fH)y=Math.log(h/d)/t,x=function(E){return[l+E*m,c+E*g,d*Math.exp(t*E*y)]};else{var w=Math.sqrt(b),v=(h*h-d*d+r*b)/(2*d*n*w),N=(h*h-d*d-r*b)/(2*h*n*w),k=Math.log(Math.sqrt(v*v+1)-v),C=Math.log(Math.sqrt(N*N+1)-N);y=(C-k)/t,x=function(E){var A=E*y,I=gf(k),z=d/(n*w)*(I*mH(t*A+k)-hH(k));return[l+z*m,c+z*g,d*I/gf(t*A+k)]}}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 Pr=0,oo=0,eo=0,Cv=1e3,ia,so,la=0,Xn=0,Ka=0,Io=typeof performance=="object"&&performance.now?performance:Date,Mv=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function zd(){return Xn||(Mv(gH),Xn=Io.now()+Ka)}function gH(){Xn=0}function ca(){this._call=this._time=this._next=null}ca.prototype=Ev.prototype={constructor:ca,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?zd():+n)+(t==null?0:+t),!this._next&&so!==this&&(so?so._next=this:ia=this,so=this),this._call=e,this._time=n,Wl()},stop:function(){this._call&&(this._call=null,this._time=1/0,Wl())}};function Ev(e,t,n){var r=new ca;return r.restart(e,t,n),r}function bH(){zd(),++Pr;for(var e=ia,t;e;)(t=Xn-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Pr}function bf(){Xn=(la=Io.now())+Ka,Pr=oo=0;try{bH()}finally{Pr=0,yH(),Xn=0}}function xH(){var e=Io.now(),t=e-la;t>Cv&&(Ka-=t,la=e)}function yH(){for(var e,t=ia,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:ia=n);so=e,Wl(r)}function Wl(e){if(!Pr){oo&&(oo=clearTimeout(oo));var t=e-Xn;t>24?(e<1/0&&(oo=setTimeout(bf,e-Io.now()-Ka)),eo&&(eo=clearInterval(eo))):(eo||(la=Io.now(),eo=setInterval(xH,Cv)),Pr=1,Mv(bf))}}function xf(e,t,n){var r=new ca;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var vH=Qa("start","end","cancel","interrupt"),wH=[],Iv=0,yf=1,Yl=2,Fs=3,vf=4,Zl=5,js=6;function Wa(e,t,n,r,s,a){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;NH(e,n,{name:t,index:r,group:s,on:vH,tween:wH,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:Iv})}function Fd(e,t){var n=Ft(e,t);if(n.state>Iv)throw new Error("too late; already scheduled");return n}function Jt(e,t){var n=Ft(e,t);if(n.state>Fs)throw new Error("too late; already running");return n}function Ft(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function NH(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=Ev(a,0,n.time);function a(d){n.state=yf,n.timer.restart(i,n.delay,n.time),n.delay<=d&&i(d-n.delay)}function i(d){var f,p,h,m;if(n.state!==yf)return c();for(f in r)if(m=r[f],m.name===n.name){if(m.state===Fs)return xf(i);m.state===vf?(m.state=js,m.timer.stop(),m.on.call("interrupt",e,e.__data__,m.index,m.group),delete r[f]):+f<t&&(m.state=js,m.timer.stop(),m.on.call("cancel",e,e.__data__,m.index,m.group),delete r[f])}if(xf(function(){n.state===Fs&&(n.state=vf,n.timer.restart(l,n.delay,n.time),l(d))}),n.state=Yl,n.on.call("start",e,e.__data__,n.index,n.group),n.state===Yl){for(n.state=Fs,s=new Array(h=n.tween.length),f=0,p=-1;f<h;++f)(m=n.tween[f].value.call(e,e.__data__,n.index,n.group))&&(s[++p]=m);s.length=p+1}}function l(d){for(var f=d<n.duration?n.ease.call(null,d/n.duration):(n.timer.restart(c),n.state=Zl,1),p=-1,h=s.length;++p<h;)s[p].call(e,f);n.state===Zl&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=js,n.timer.stop(),delete r[t];for(var d in r)return;delete e.__transition}}function Hs(e,t){var n=e.__transition,r,s,a=!0,i;if(n){t=t==null?null:t+"";for(i in n){if((r=n[i]).name!==t){a=!1;continue}s=r.state>Yl&&r.state<Zl,r.state=js,r.timer.stop(),r.on.call(s?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[i]}a&&delete e.__transition}}function kH(e){return this.each(function(){Hs(this,e)})}function SH(e,t){var n,r;return function(){var s=Jt(this,e),a=s.tween;if(a!==n){r=n=a;for(var i=0,l=r.length;i<l;++i)if(r[i].name===t){r=r.slice(),r.splice(i,1);break}}s.tween=r}}function CH(e,t,n){var r,s;if(typeof n!="function")throw new Error;return function(){var a=Jt(this,e),i=a.tween;if(i!==r){s=(r=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 MH(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=Ft(this.node(),n).tween,s=0,a=r.length,i;s<a;++s)if((i=r[s]).name===e)return i.value;return null}return this.each((t==null?SH:CH)(n,e,t))}function jd(e,t,n){var r=e._id;return e.each(function(){var s=Jt(this,r);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return Ft(s,r).value[t]}}function Av(e,t){var n;return(typeof t=="number"?Vt:t instanceof Zn?aa:(n=Zn(t))?(t=n,aa):Nv)(e,t)}function EH(e){return function(){this.removeAttribute(e)}}function IH(e){return function(){this.removeAttributeNS(e.space,e.local)}}function AH(e,t,n){var r,s=n+"",a;return function(){var i=this.getAttribute(e);return i===s?null:i===r?a:a=t(r=i,n)}}function PH(e,t,n){var r,s=n+"",a;return function(){var i=this.getAttributeNS(e.space,e.local);return i===s?null:i===r?a:a=t(r=i,n)}}function _H(e,t,n){var r,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===r&&c===s?a:(s=c,a=t(r=i,l)))}}function $H(e,t,n){var r,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===r&&c===s?a:(s=c,a=t(r=i,l)))}}function DH(e,t){var n=Ga(e),r=n==="transform"?pH:Av;return this.attrTween(e,typeof t=="function"?(n.local?$H:_H)(n,r,jd(this,"attr."+e,t)):t==null?(n.local?IH:EH)(n):(n.local?PH:AH)(n,r,t))}function TH(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function LH(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function RH(e,t){var n,r;function s(){var a=t.apply(this,arguments);return a!==r&&(n=(r=a)&&LH(e,a)),n}return s._value=t,s}function OH(e,t){var n,r;function s(){var a=t.apply(this,arguments);return a!==r&&(n=(r=a)&&TH(e,a)),n}return s._value=t,s}function BH(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 r=Ga(e);return this.tween(n,(r.local?RH:OH)(r,t))}function zH(e,t){return function(){Fd(this,e).delay=+t.apply(this,arguments)}}function FH(e,t){return t=+t,function(){Fd(this,e).delay=t}}function jH(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?zH:FH)(t,e)):Ft(this.node(),t).delay}function HH(e,t){return function(){Jt(this,e).duration=+t.apply(this,arguments)}}function VH(e,t){return t=+t,function(){Jt(this,e).duration=t}}function qH(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?HH:VH)(t,e)):Ft(this.node(),t).duration}function UH(e,t){if(typeof t!="function")throw new Error;return function(){Jt(this,e).ease=t}}function QH(e){var t=this._id;return arguments.length?this.each(UH(t,e)):Ft(this.node(),t).ease}function GH(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Jt(this,e).ease=n}}function KH(e){if(typeof e!="function")throw new Error;return this.each(GH(this._id,e))}function WH(e){typeof e!="function"&&(e=av(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var a=t[s],i=a.length,l=r[s]=[],c,d=0;d<i;++d)(c=a[d])&&e.call(c,c.__data__,d,a)&&l.push(c);return new pn(r,this._parents,this._name,this._id)}function YH(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,s=n.length,a=Math.min(r,s),i=new Array(r),l=0;l<a;++l)for(var c=t[l],d=n[l],f=c.length,p=i[l]=new Array(f),h,m=0;m<f;++m)(h=c[m]||d[m])&&(p[m]=h);for(;l<r;++l)i[l]=t[l];return new pn(i,this._parents,this._name,this._id)}function ZH(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 XH(e,t,n){var r,s,a=ZH(t)?Fd:Jt;return function(){var i=a(this,e),l=i.on;l!==r&&(s=(r=l).copy()).on(t,n),i.on=s}}function JH(e,t){var n=this._id;return arguments.length<2?Ft(this.node(),n).on.on(e):this.each(XH(n,e,t))}function eV(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function tV(){return this.on("end.remove",eV(this._id))}function nV(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Ld(e));for(var r=this._groups,s=r.length,a=new Array(s),i=0;i<s;++i)for(var l=r[i],c=l.length,d=a[i]=new Array(c),f,p,h=0;h<c;++h)(f=l[h])&&(p=e.call(f,f.__data__,h,l))&&("__data__"in f&&(p.__data__=f.__data__),d[h]=p,Wa(d[h],t,n,h,d,Ft(f,n)));return new pn(a,this._parents,t,n)}function rV(e){var t=this._name,n=this._id;typeof e!="function"&&(e=sv(e));for(var r=this._groups,s=r.length,a=[],i=[],l=0;l<s;++l)for(var c=r[l],d=c.length,f,p=0;p<d;++p)if(f=c[p]){for(var h=e.call(f,f.__data__,p,c),m,g=Ft(f,n),b=0,x=h.length;b<x;++b)(m=h[b])&&Wa(m,t,n,b,h,g);a.push(h),i.push(f)}return new pn(a,i,t,n)}var oV=Wo.prototype.constructor;function sV(){return new oV(this._groups,this._parents)}function aV(e,t){var n,r,s;return function(){var a=Ar(this,e),i=(this.style.removeProperty(e),Ar(this,e));return a===i?null:a===n&&i===r?s:s=t(n=a,r=i)}}function Pv(e){return function(){this.style.removeProperty(e)}}function iV(e,t,n){var r,s=n+"",a;return function(){var i=Ar(this,e);return i===s?null:i===r?a:a=t(r=i,n)}}function lV(e,t,n){var r,s,a;return function(){var i=Ar(this,e),l=n(this),c=l+"";return l==null&&(c=l=(this.style.removeProperty(e),Ar(this,e))),i===c?null:i===r&&c===s?a:(s=c,a=t(r=i,l))}}function cV(e,t){var n,r,s,a="style."+t,i="end."+a,l;return function(){var c=Jt(this,e),d=c.on,f=c.value[a]==null?l||(l=Pv(t)):void 0;(d!==n||s!==f)&&(r=(n=d).copy()).on(i,s=f),c.on=r}}function dV(e,t,n){var r=(e+="")=="transform"?uH:Av;return t==null?this.styleTween(e,aV(e,r)).on("end.style."+e,Pv(e)):typeof t=="function"?this.styleTween(e,lV(e,r,jd(this,"style."+e,t))).each(cV(this._id,e)):this.styleTween(e,iV(e,r,t),n).on("end.style."+e,null)}function uV(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function pV(e,t,n){var r,s;function a(){var i=t.apply(this,arguments);return i!==s&&(r=(s=i)&&uV(e,i,n)),r}return a._value=t,a}function fV(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,pV(e,t,n??""))}function hV(e){return function(){this.textContent=e}}function mV(e){return function(){var t=e(this);this.textContent=t??""}}function gV(e){return this.tween("text",typeof e=="function"?mV(jd(this,"text",e)):hV(e==null?"":e+""))}function bV(e){return function(t){this.textContent=e.call(this,t)}}function xV(e){var t,n;function r(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&bV(s)),t}return r._value=e,r}function yV(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,xV(e))}function vV(){for(var e=this._name,t=this._id,n=_v(),r=this._groups,s=r.length,a=0;a<s;++a)for(var i=r[a],l=i.length,c,d=0;d<l;++d)if(c=i[d]){var f=Ft(c,t);Wa(c,e,n,d,i,{time:f.time+f.delay+f.duration,delay:0,duration:f.duration,ease:f.ease})}return new pn(r,this._parents,e,n)}function wV(){var e,t,n=this,r=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=Jt(this,r),f=d.on;f!==e&&(t=(e=f).copy(),t._.cancel.push(l),t._.interrupt.push(l),t._.end.push(c)),d.on=t}),s===0&&a()})}var NV=0;function pn(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function _v(){return++NV}var nn=Wo.prototype;pn.prototype={constructor:pn,select:nV,selectAll:rV,selectChild:nn.selectChild,selectChildren:nn.selectChildren,filter:WH,merge:YH,selection:sV,transition:vV,call:nn.call,nodes:nn.nodes,node:nn.node,size:nn.size,empty:nn.empty,each:nn.each,on:JH,attr:DH,attrTween:BH,style:dV,styleTween:fV,text:gV,textTween:yV,remove:tV,tween:MH,delay:jH,duration:qH,ease:QH,easeVarying:KH,end:wV,[Symbol.iterator]:nn[Symbol.iterator]};function kV(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var SV={time:null,delay:0,duration:250,ease:kV};function CV(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 MV(e){var t,n;e instanceof pn?(t=e._id,e=e._name):(t=_v(),(n=SV).time=zd(),e=e==null?null:e+"");for(var r=this._groups,s=r.length,a=0;a<s;++a)for(var i=r[a],l=i.length,c,d=0;d<l;++d)(c=i[d])&&Wa(c,e,t,d,i,n||CV(c,t));return new pn(r,this._parents,e,t)}Wo.prototype.interrupt=kH;Wo.prototype.transition=MV;const Ms=e=>()=>e;function EV(e,{sourceEvent:t,target:n,transform:r,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:r,enumerable:!0,configurable:!0},_:{value:s}})}function sn(e,t,n){this.k=e,this.x=t,this.y=n}sn.prototype={constructor:sn,scale:function(e){return e===1?this:new sn(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new sn(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 Ya=new sn(1,0,0);$v.prototype=sn.prototype;function $v(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Ya;return e.__zoom}function Zi(e){e.stopImmediatePropagation()}function to(e){e.preventDefault(),e.stopImmediatePropagation()}function IV(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function AV(){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 wf(){return this.__zoom||Ya}function PV(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function _V(){return navigator.maxTouchPoints||"ontouchstart"in this}function $V(e,t,n){var r=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>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),i>a?(a+i)/2:Math.min(0,a)||Math.max(0,i))}function Dv(){var e=IV,t=AV,n=$V,r=PV,s=_V,a=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],l=250,c=zs,d=Qa("start","zoom","end"),f,p,h,m=500,g=150,b=0,x=10;function y(M){M.property("__zoom",wf).on("wheel.zoom",A,{passive:!1}).on("mousedown.zoom",I).on("dblclick.zoom",z).filter(s).on("touchstart.zoom",$).on("touchmove.zoom",B).on("touchend.zoom touchcancel.zoom",R).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}y.transform=function(M,T,_,L){var O=M.selection?M.selection():M;O.property("__zoom",wf),M!==O?k(M,T,_,L):O.interrupt().each(function(){C(this,arguments).event(L).start().zoom(null,typeof T=="function"?T.apply(this,arguments):T).end()})},y.scaleBy=function(M,T,_,L){y.scaleTo(M,function(){var O=this.__zoom.k,j=typeof T=="function"?T.apply(this,arguments):T;return O*j},_,L)},y.scaleTo=function(M,T,_,L){y.transform(M,function(){var O=t.apply(this,arguments),j=this.__zoom,F=_==null?N(O):typeof _=="function"?_.apply(this,arguments):_,H=j.invert(F),D=typeof T=="function"?T.apply(this,arguments):T;return n(v(w(j,D),F,H),O,i)},_,L)},y.translateBy=function(M,T,_,L){y.transform(M,function(){return n(this.__zoom.translate(typeof T=="function"?T.apply(this,arguments):T,typeof _=="function"?_.apply(this,arguments):_),t.apply(this,arguments),i)},null,L)},y.translateTo=function(M,T,_,L,O){y.transform(M,function(){var j=t.apply(this,arguments),F=this.__zoom,H=L==null?N(j):typeof L=="function"?L.apply(this,arguments):L;return n(Ya.translate(H[0],H[1]).scale(F.k).translate(typeof T=="function"?-T.apply(this,arguments):-T,typeof _=="function"?-_.apply(this,arguments):-_),j,i)},L,O)};function w(M,T){return T=Math.max(a[0],Math.min(a[1],T)),T===M.k?M:new sn(T,M.x,M.y)}function v(M,T,_){var L=T[0]-_[0]*M.k,O=T[1]-_[1]*M.k;return L===M.x&&O===M.y?M:new sn(M.k,L,O)}function N(M){return[(+M[0][0]+ +M[1][0])/2,(+M[0][1]+ +M[1][1])/2]}function k(M,T,_,L){M.on("start.zoom",function(){C(this,arguments).event(L).start()}).on("interrupt.zoom end.zoom",function(){C(this,arguments).event(L).end()}).tween("zoom",function(){var O=this,j=arguments,F=C(O,j).event(L),H=t.apply(O,j),D=_==null?N(H):typeof _=="function"?_.apply(O,j):_,Q=Math.max(H[1][0]-H[0][0],H[1][1]-H[0][1]),G=O.__zoom,ee=typeof T=="function"?T.apply(O,j):T,se=c(G.invert(D).concat(Q/G.k),ee.invert(D).concat(Q/ee.k));return function(te){if(te===1)te=ee;else{var Z=se(te),re=Q/Z[2];te=new sn(re,D[0]-Z[0]*re,D[1]-Z[1]*re)}F.zoom(null,te)}})}function C(M,T,_){return!_&&M.__zooming||new E(M,T)}function E(M,T){this.that=M,this.args=T,this.active=0,this.sourceEvent=null,this.extent=t.apply(M,T),this.taps=0}E.prototype={event:function(M){return M&&(this.sourceEvent=M),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(M,T){return this.mouse&&M!=="mouse"&&(this.mouse[1]=T.invert(this.mouse[0])),this.touch0&&M!=="touch"&&(this.touch0[1]=T.invert(this.touch0[0])),this.touch1&&M!=="touch"&&(this.touch1[1]=T.invert(this.touch1[0])),this.that.__zoom=T,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(M){var T=ct(this.that).datum();d.call(M,this.that,new EV(M,{sourceEvent:this.sourceEvent,target:y,transform:this.that.__zoom,dispatch:d}),T)}};function A(M,...T){if(!e.apply(this,arguments))return;var _=C(this,T).event(M),L=this.__zoom,O=Math.max(a[0],Math.min(a[1],L.k*Math.pow(2,r.apply(this,arguments)))),j=_t(M);if(_.wheel)(_.mouse[0][0]!==j[0]||_.mouse[0][1]!==j[1])&&(_.mouse[1]=L.invert(_.mouse[0]=j)),clearTimeout(_.wheel);else{if(L.k===O)return;_.mouse=[j,L.invert(j)],Hs(this),_.start()}to(M),_.wheel=setTimeout(F,g),_.zoom("mouse",n(v(w(L,O),_.mouse[0],_.mouse[1]),_.extent,i));function F(){_.wheel=null,_.end()}}function I(M,...T){if(h||!e.apply(this,arguments))return;var _=M.currentTarget,L=C(this,T,!0).event(M),O=ct(M.view).on("mousemove.zoom",D,!0).on("mouseup.zoom",Q,!0),j=_t(M,_),F=M.clientX,H=M.clientY;gv(M.view),Zi(M),L.mouse=[j,this.__zoom.invert(j)],Hs(this),L.start();function D(G){if(to(G),!L.moved){var ee=G.clientX-F,se=G.clientY-H;L.moved=ee*ee+se*se>b}L.event(G).zoom("mouse",n(v(L.that.__zoom,L.mouse[0]=_t(G,_),L.mouse[1]),L.extent,i))}function Q(G){O.on("mousemove.zoom mouseup.zoom",null),bv(G.view,L.moved),to(G),L.event(G).end()}}function z(M,...T){if(e.apply(this,arguments)){var _=this.__zoom,L=_t(M.changedTouches?M.changedTouches[0]:M,this),O=_.invert(L),j=_.k*(M.shiftKey?.5:2),F=n(v(w(_,j),L,O),t.apply(this,T),i);to(M),l>0?ct(this).transition().duration(l).call(k,F,L,M):ct(this).call(y.transform,F,L,M)}}function $(M,...T){if(e.apply(this,arguments)){var _=M.touches,L=_.length,O=C(this,T,M.changedTouches.length===L).event(M),j,F,H,D;for(Zi(M),F=0;F<L;++F)H=_[F],D=_t(H,this),D=[D,this.__zoom.invert(D),H.identifier],O.touch0?!O.touch1&&O.touch0[2]!==D[2]&&(O.touch1=D,O.taps=0):(O.touch0=D,j=!0,O.taps=1+!!f);f&&(f=clearTimeout(f)),j&&(O.taps<2&&(p=D[0],f=setTimeout(function(){f=null},m)),Hs(this),O.start())}}function B(M,...T){if(this.__zooming){var _=C(this,T).event(M),L=M.changedTouches,O=L.length,j,F,H,D;for(to(M),j=0;j<O;++j)F=L[j],H=_t(F,this),_.touch0&&_.touch0[2]===F.identifier?_.touch0[0]=H:_.touch1&&_.touch1[2]===F.identifier&&(_.touch1[0]=H);if(F=_.that.__zoom,_.touch1){var Q=_.touch0[0],G=_.touch0[1],ee=_.touch1[0],se=_.touch1[1],te=(te=ee[0]-Q[0])*te+(te=ee[1]-Q[1])*te,Z=(Z=se[0]-G[0])*Z+(Z=se[1]-G[1])*Z;F=w(F,Math.sqrt(te/Z)),H=[(Q[0]+ee[0])/2,(Q[1]+ee[1])/2],D=[(G[0]+se[0])/2,(G[1]+se[1])/2]}else if(_.touch0)H=_.touch0[0],D=_.touch0[1];else return;_.zoom("touch",n(v(F,H,D),_.extent,i))}}function R(M,...T){if(this.__zooming){var _=C(this,T).event(M),L=M.changedTouches,O=L.length,j,F;for(Zi(M),h&&clearTimeout(h),h=setTimeout(function(){h=null},m),j=0;j<O;++j)F=L[j],_.touch0&&_.touch0[2]===F.identifier?delete _.touch0:_.touch1&&_.touch1[2]===F.identifier&&delete _.touch1;if(_.touch1&&!_.touch0&&(_.touch0=_.touch1,delete _.touch1),_.touch0)_.touch0[1]=this.__zoom.invert(_.touch0[0]);else if(_.end(),_.taps===2&&(F=_t(F,this),Math.hypot(p[0]-F[0],p[1]-F[1])<x)){var H=ct(this).on("dblclick.zoom");H&&H.apply(this,arguments)}}}return y.wheelDelta=function(M){return arguments.length?(r=typeof M=="function"?M:Ms(+M),y):r},y.filter=function(M){return arguments.length?(e=typeof M=="function"?M:Ms(!!M),y):e},y.touchable=function(M){return arguments.length?(s=typeof M=="function"?M:Ms(!!M),y):s},y.extent=function(M){return arguments.length?(t=typeof M=="function"?M:Ms([[+M[0][0],+M[0][1]],[+M[1][0],+M[1][1]]]),y):t},y.scaleExtent=function(M){return arguments.length?(a[0]=+M[0],a[1]=+M[1],y):[a[0],a[1]]},y.translateExtent=function(M){return arguments.length?(i[0][0]=+M[0][0],i[1][0]=+M[1][0],i[0][1]=+M[0][1],i[1][1]=+M[1][1],y):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},y.constrain=function(M){return arguments.length?(n=M,y):n},y.duration=function(M){return arguments.length?(l=+M,y):l},y.interpolate=function(M){return arguments.length?(c=M,y):c},y.on=function(){var M=d.on.apply(d,arguments);return M===d?y:M},y.clickDistance=function(M){return arguments.length?(b=(M=+M)*M,y):Math.sqrt(b)},y.tapDistance=function(M){return arguments.length?(x=+M,y):x},y}const Zt={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:r})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:r}", 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."},Ao=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Tv=["Enter"," ","Escape"],Lv={"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 _r;(function(e){e.Strict="strict",e.Loose="loose"})(_r||(_r={}));var Un;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Un||(Un={}));var Po;(function(e){e.Partial="partial",e.Full="full"})(Po||(Po={}));const Rv={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var wn;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(wn||(wn={}));var da;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(da||(da={}));var we;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(we||(we={}));const Nf={[we.Left]:we.Right,[we.Right]:we.Left,[we.Top]:we.Bottom,[we.Bottom]:we.Top};function Ov(e){return e===null?null:e?"valid":"invalid"}const Bv=e=>"id"in e&&"source"in e&&"target"in e,DV=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Hd=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),Zo=(e,t=[0,0])=>{const{width:n,height:r}=gn(e),s=e.origin??t,a=n*s[0],i=r*s[1];return{x:e.position.x-a,y:e.position.y-i}},TV=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const a=typeof s=="string";let i=!t.nodeLookup&&!a?s:void 0;t.nodeLookup&&(i=a?t.nodeLookup.get(s):Hd(s)?s:t.nodeLookup.get(s.id));const l=i?ua(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Za(r,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Xa(n)},Xo=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(s=>{(t.filter===void 0||t.filter(s))&&(n=Za(n,ua(s)),r=!0)}),r?Xa(n):{x:0,y:0,width:0,height:0}},Vd=(e,t,[n,r,s]=[0,0,1],a=!1,i=!1)=>{const l={...es(t,[n,r,s]),width:t.width/s,height:t.height/s},c=[];for(const d of e.values()){const{measured:f,selectable:p=!0,hidden:h=!1}=d;if(i&&!p||h)continue;const m=f.width??d.width??d.initialWidth??null,g=f.height??d.height??d.initialHeight??null,b=_o(l,Dr(d)),x=(m??0)*(g??0),y=a&&b>0;(!d.internals.handleBounds||y||b>=x||d.dragging)&&c.push(d)}return c},LV=(e,t)=>{const n=new Set;return e.forEach(r=>{n.add(r.id)}),t.filter(r=>n.has(r.source)||n.has(r.target))};function RV(e,t){const n=new Map,r=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)&&(!r||r.has(s.id))&&n.set(s.id,s)}),n}async function OV({nodes:e,width:t,height:n,panZoom:r,minZoom:s,maxZoom:a},i){if(e.size===0)return Promise.resolve(!0);const l=RV(e,i),c=Xo(l),d=qd(c,t,n,i?.minZoom??s,i?.maxZoom??a,i?.padding??.1);return await r.setViewport(d,{duration:i?.duration,ease:i?.ease,interpolate:i?.interpolate}),Promise.resolve(!0)}function zv({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[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},f=i.origin??r;let p=i.extent||s;if(i.extent==="parent"&&!i.expandParent)if(!l)a?.("005",Zt.error005());else{const m=l.measured.width,g=l.measured.height;m&&g&&(p=[[c,d],[c+m,d+g]])}else l&&Tr(i.extent)&&(p=[[i.extent[0][0]+c,i.extent[0][1]+d],[i.extent[1][0]+c,i.extent[1][1]+d]]);const h=Tr(p)?Jn(t,p,i.measured):t;return(i.measured.width===void 0||i.measured.height===void 0)&&a?.("015",Zt.error015()),{position:{x:h.x-c+(i.measured.width??0)*f[0],y:h.y-d+(i.measured.height??0)*f[1]},positionAbsolute:h}}async function BV({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,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=r.filter(h=>h.deletable!==!1),f=LV(i,c);for(const h of c)l.has(h.id)&&!f.find(g=>g.id===h.id)&&f.push(h);if(!s)return{edges:f,nodes:i};const p=await s({nodes:i,edges:f});return typeof p=="boolean"?p?{edges:f,nodes:i}:{edges:[],nodes:[]}:p}const $r=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Jn=(e={x:0,y:0},t,n)=>({x:$r(e.x,t[0][0],t[1][0]-(n?.width??0)),y:$r(e.y,t[0][1],t[1][1]-(n?.height??0))});function Fv(e,t,n){const{width:r,height:s}=gn(n),{x:a,y:i}=n.internals.positionAbsolute;return Jn(e,[[a,i],[a+r,i+s]],t)}const kf=(e,t,n)=>e<t?$r(Math.abs(e-t),1,t)/t:e>n?-$r(Math.abs(e-n),1,t)/t:0,jv=(e,t,n=15,r=40)=>{const s=kf(e.x,r,t.width-r)*n,a=kf(e.y,r,t.height-r)*n;return[s,a]},Za=(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)}),Xl=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),Xa=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),Dr=(e,t=[0,0])=>{const{x:n,y:r}=Hd(e)?e.internals.positionAbsolute:Zo(e,t);return{x:n,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},ua=(e,t=[0,0])=>{const{x:n,y:r}=Hd(e)?e.internals.positionAbsolute:Zo(e,t);return{x:n,y:r,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},Hv=(e,t)=>Xa(Za(Xl(e),Xl(t))),_o=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},Sf=e=>Dt(e.width)&&Dt(e.height)&&Dt(e.x)&&Dt(e.y),Dt=e=>!isNaN(e)&&isFinite(e),zV=(e,t)=>{},Jo=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),es=({x:e,y:t},[n,r,s],a=!1,i=[1,1])=>{const l={x:(e-n)/s,y:(t-r)/s};return a?Jo(l,i):l},pa=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r});function pr(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 FV(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=pr(e,n),s=pr(e,t);return{top:r,right:s,bottom:r,left:s,x:s*2,y:r*2}}if(typeof e=="object"){const r=pr(e.top??e.y??0,n),s=pr(e.bottom??e.y??0,n),a=pr(e.left??e.x??0,t),i=pr(e.right??e.x??0,t);return{top:r,right:i,bottom:s,left:a,x:a+i,y:r+s}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function jV(e,t,n,r,s,a){const{x:i,y:l}=pa(e,[t,n,r]),{x:c,y:d}=pa({x:e.x+e.width,y:e.y+e.height},[t,n,r]),f=s-c,p=a-d;return{left:Math.floor(i),top:Math.floor(l),right:Math.floor(f),bottom:Math.floor(p)}}const qd=(e,t,n,r,s,a)=>{const i=FV(a,t,n),l=(t-i.x)/e.width,c=(n-i.y)/e.height,d=Math.min(l,c),f=$r(d,r,s),p=e.x+e.width/2,h=e.y+e.height/2,m=t/2-p*f,g=n/2-h*f,b=jV(e,m,g,f,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:f}},$o=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Tr(e){return e!=null&&e!=="parent"}function gn(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function Vv(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function qv(e,t={width:0,height:0},n,r,s){const a={...e},i=r.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 Cf(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function HV(){let e,t;return{promise:new Promise((r,s)=>{e=r,t=s}),resolve:e,reject:t}}function VV(e){return{...Lv,...e||{}}}function mo(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:s}){const{x:a,y:i}=Tt(e),l=es({x:a-(s?.left??0),y:i-(s?.top??0)},r),{x:c,y:d}=n?Jo(l,t):l;return{xSnapped:c,ySnapped:d,...l}}const Ud=e=>({width:e.offsetWidth,height:e.offsetHeight}),Uv=e=>e?.getRootNode?.()||window?.document,qV=["INPUT","SELECT","TEXTAREA"];function Qv(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:qV.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const Gv=e=>"clientX"in e,Tt=(e,t)=>{const n=Gv(e),r=n?e.clientX:e.touches?.[0].clientX,s=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:s-(t?.top??0)}},Mf=(e,t,n,r,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)/r,y:(l.top-n.top)/r,...Ud(i)}})};function Kv({sourceX:e,sourceY:t,targetX:n,targetY:r,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+r*.125,f=Math.abs(c-e),p=Math.abs(d-t);return[c,d,f,p]}function Es(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Ef({pos:e,x1:t,y1:n,x2:r,y2:s,c:a}){switch(e){case we.Left:return[t-Es(t-r,a),n];case we.Right:return[t+Es(r-t,a),n];case we.Top:return[t,n-Es(n-s,a)];case we.Bottom:return[t,n+Es(s-n,a)]}}function Wv({sourceX:e,sourceY:t,sourcePosition:n=we.Bottom,targetX:r,targetY:s,targetPosition:a=we.Top,curvature:i=.25}){const[l,c]=Ef({pos:n,x1:e,y1:t,x2:r,y2:s,c:i}),[d,f]=Ef({pos:a,x1:r,y1:s,x2:e,y2:t,c:i}),[p,h,m,g]=Kv({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:l,sourceControlY:c,targetControlX:d,targetControlY:f});return[`M${e},${t} C${l},${c} ${d},${f} ${r},${s}`,p,h,m,g]}function Yv({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,a=n<e?n+s:n-s,i=Math.abs(r-t)/2,l=r<t?r+i:r-i;return[a,l,s,i]}function UV({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:s=!1,zIndexMode:a="basic"}){if(a==="manual")return r;const i=s&&n?r+1e3:r,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 QV({sourceNode:e,targetNode:t,width:n,height:r,transform:s}){const a=Za(ua(e),ua(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:r/s[2]};return _o(i,Xa(a))>0}const GV=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,KV=(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)),WV=(e,t,n={})=>{if(!e.source||!e.target)return t;const r=n.getEdgeId||GV;let s;return Bv(e)?s={...e}:s={...e,id:r(e)},KV(s,t)?t:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,t.concat(s))};function Zv({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,a,i,l]=Yv({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,a,i,l]}const If={[we.Left]:{x:-1,y:0},[we.Right]:{x:1,y:0},[we.Top]:{x:0,y:-1},[we.Bottom]:{x:0,y:1}},YV=({source:e,sourcePosition:t=we.Bottom,target:n})=>t===we.Left||t===we.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},Af=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function ZV({source:e,sourcePosition:t=we.Bottom,target:n,targetPosition:r=we.Top,center:s,offset:a,stepPosition:i}){const l=If[t],c=If[r],d={x:e.x+l.x*a,y:e.y+l.y*a},f={x:n.x+c.x*a,y:n.y+c.y*a},p=YV({source:d,sourcePosition:t,target:f}),h=p.x!==0?"x":"y",m=p[h];let g=[],b,x;const y={x:0,y:0},w={x:0,y:0},[,,v,N]=Yv({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+(f.x-d.x)*i,x=s.y??(d.y+f.y)/2):(b=s.x??(d.x+f.x)/2,x=s.y??d.y+(f.y-d.y)*i);const A=[{x:b,y:d.y},{x:b,y:f.y}],I=[{x:d.x,y:x},{x:f.x,y:x}];l[h]===m?g=h==="x"?A:I:g=h==="x"?I:A}else{const A=[{x:d.x,y:f.y}],I=[{x:f.x,y:d.y}];if(h==="x"?g=l.x===m?I:A:g=l.y===m?A:I,t===r){const M=Math.abs(e[h]-n[h]);if(M<=a){const T=Math.min(a-1,a-M);l[h]===m?y[h]=(d[h]>e[h]?-1:1)*T:w[h]=(f[h]>n[h]?-1:1)*T}}if(t!==r){const M=h==="x"?"y":"x",T=l[h]===c[M],_=d[M]>f[M],L=d[M]<f[M];(l[h]===1&&(!T&&_||T&&L)||l[h]!==1&&(!T&&L||T&&_))&&(g=h==="x"?A:I)}const z={x:d.x+y.x,y:d.y+y.y},$={x:f.x+w.x,y:f.y+w.y},B=Math.max(Math.abs(z.x-g[0].x),Math.abs($.x-g[0].x)),R=Math.max(Math.abs(z.y-g[0].y),Math.abs($.y-g[0].y));B>=R?(b=(z.x+$.x)/2,x=g[0].y):(b=g[0].x,x=(z.y+$.y)/2)}const k={x:d.x+y.x,y:d.y+y.y},C={x:f.x+w.x,y:f.y+w.y};return[[e,...k.x!==g[0].x||k.y!==g[0].y?[k]:[],...g,...C.x!==g[g.length-1].x||C.y!==g[g.length-1].y?[C]:[],n],b,x,v,N]}function XV(e,t,n,r){const s=Math.min(Af(e,t)/2,Af(t,n)/2,r),{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,f=e.y<n.y?1:-1;return`L ${a+s*d},${i}Q ${a},${i} ${a},${i+s*f}`}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 Jl({sourceX:e,sourceY:t,sourcePosition:n=we.Bottom,targetX:r,targetY:s,targetPosition:a=we.Top,borderRadius:i=5,centerX:l,centerY:c,offset:d=20,stepPosition:f=.5}){const[p,h,m,g,b]=ZV({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:s},targetPosition:a,center:{x:l,y:c},offset:d,stepPosition:f});let x=`M${p[0].x} ${p[0].y}`;for(let y=1;y<p.length-1;y++)x+=XV(p[y-1],p[y],p[y+1],i);return x+=`L${p[p.length-1].x} ${p[p.length-1].y}`,[x,h,m,g,b]}function Pf(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function JV(e){const{sourceNode:t,targetNode:n}=e;if(!Pf(t)||!Pf(n))return null;const r=t.internals.handleBounds||_f(t.handles),s=n.internals.handleBounds||_f(n.handles),a=$f(r?.source??[],e.sourceHandle),i=$f(e.connectionMode===_r.Strict?s?.target??[]:(s?.target??[]).concat(s?.source??[]),e.targetHandle);if(!a||!i)return e.onError?.("008",Zt.error008(a?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=a?.position||we.Bottom,c=i?.position||we.Top,d=er(t,a,l),f=er(n,i,c);return{sourceX:d.x,sourceY:d.y,targetX:f.x,targetY:f.y,sourcePosition:l,targetPosition:c}}function _f(e){if(!e)return null;const t=[],n=[];for(const r of e)r.width=r.width??1,r.height=r.height??1,r.type==="source"?t.push(r):r.type==="target"&&n.push(r);return{source:t,target:n}}function er(e,t,n=we.Left,r=!1){const s=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:i,height:l}=t??gn(e);if(r)return{x:s+i/2,y:a+l/2};switch(t?.position??n){case we.Top:return{x:s+i/2,y:a};case we.Right:return{x:s+i,y:a+l/2};case we.Bottom:return{x:s+i/2,y:a+l};case we.Left:return{x:s,y:a+l/2}}}function $f(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function ec(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function eq(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:s}){const a=new Set;return e.reduce((i,l)=>([l.markerStart||r,l.markerEnd||s].forEach(c=>{if(c&&typeof c=="object"){const d=ec(c,t);a.has(d)||(i.push({id:d,color:c.color||n,...c}),a.add(d))}}),i),[]).sort((i,l)=>i.id.localeCompare(l.id))}const Xv=1e3,tq=10,Qd={nodeOrigin:[0,0],nodeExtent:Ao,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},nq={...Qd,checkEquality:!0};function Gd(e,t){const n={...e};for(const r in t)t[r]!==void 0&&(n[r]=t[r]);return n}function rq(e,t,n){const r=Gd(Qd,n);for(const s of e.values())if(s.parentId)Wd(s,e,t,r);else{const a=Zo(s,r.nodeOrigin),i=Tr(s.extent)?s.extent:r.nodeExtent,l=Jn(a,i,gn(s));s.internals.positionAbsolute=l}}function oq(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;const n=[],r=[];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"&&r.push(a)}return{source:n,target:r}}function Kd(e){return e==="manual"}function tc(e,t,n,r={}){const s=Gd(nq,r),a={i:0},i=new Map(t),l=s?.elevateNodesOnSelect&&!Kd(s.zIndexMode)?Xv:0;let c=e.length>0,d=!1;t.clear(),n.clear();for(const f of e){let p=i.get(f.id);if(s.checkEquality&&f===p?.internals.userNode)t.set(f.id,p);else{const h=Zo(f,s.nodeOrigin),m=Tr(f.extent)?f.extent:s.nodeExtent,g=Jn(h,m,gn(f));p={...s.defaults,...f,measured:{width:f.measured?.width,height:f.measured?.height},internals:{positionAbsolute:g,handleBounds:oq(f,p),z:Jv(f,l,s.zIndexMode),userNode:f}},t.set(f.id,p)}(p.measured===void 0||p.measured.width===void 0||p.measured.height===void 0)&&!p.hidden&&(c=!1),f.parentId&&Wd(p,t,n,r,a),d||=f.selected??!1}return{nodesInitialized:c,hasSelectedNodes:d}}function sq(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 Wd(e,t,n,r,s){const{elevateNodesOnSelect:a,nodeOrigin:i,nodeExtent:l,zIndexMode:c}=Gd(Qd,r),d=e.parentId,f=t.get(d);if(!f){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}sq(e,n),s&&!f.parentId&&f.internals.rootParentIndex===void 0&&c==="auto"&&(f.internals.rootParentIndex=++s.i,f.internals.z=f.internals.z+s.i*tq),s&&f.internals.rootParentIndex!==void 0&&(s.i=f.internals.rootParentIndex);const p=a&&!Kd(c)?Xv:0,{x:h,y:m,z:g}=aq(e,f,i,l,p,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 Jv(e,t,n){const r=Dt(e.zIndex)?e.zIndex:0;return Kd(n)?r:r+(e.selected?t:0)}function aq(e,t,n,r,s,a){const{x:i,y:l}=t.internals.positionAbsolute,c=gn(e),d=Zo(e,n),f=Tr(e.extent)?Jn(d,e.extent,c):d;let p=Jn({x:i+f.x,y:l+f.y},r,c);e.extent==="parent"&&(p=Fv(p,c,t));const h=Jv(e,s,a),m=t.internals.z??0;return{x:p.x,y:p.y,z:m>=h?m+1:h}}function Yd(e,t,n,r=[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??Dr(l),d=Hv(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,f=gn(l),p=l.origin??r,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(f.width,Math.round(i.width)),b=Math.max(f.height,Math.round(i.height)),x=(g-f.width)*p[0],y=(b-f.height)*p[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}})})),(f.width<i.width||f.height<i.height||h||m)&&s.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:g+(h?p[0]*h-x:0),height:b+(m?p[1]*m-y:0)}})}),s}function iq(e,t,n,r,s,a,i){const l=r?.querySelector(".xyflow__viewport");let c=!1;if(!l)return{changes:[],updatedInternals:c};const d=[],f=window.getComputedStyle(l),{m22:p}=new window.DOMMatrixReadOnly(f.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=Ud(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=Tr(g.extent)?g.extent:a;let{positionAbsolute:N}=g.internals;g.parentId&&g.extent==="parent"?N=Fv(N,b,t.get(g.parentId)):v&&(N=Jn(N,v,b));const k={...g,measured:b,internals:{...g.internals,positionAbsolute:N,handleBounds:{source:Mf("source",m.nodeElement,w,p,g.id),target:Mf("target",m.nodeElement,w,p,g.id)}}};t.set(g.id,k),g.parentId&&Wd(k,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:Dr(k,s)}))}}if(h.length>0){const m=Yd(h,t,n,s);d.push(...m)}return{changes:d,updatedInternals:c}}async function lq({delta:e,panZoom:t,transform:n,translateExtent:r,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]],r),l=!!i&&(i.x!==n[0]||i.y!==n[1]||i.k!==n[2]);return Promise.resolve(l)}function Df(e,t,n,r,s,a){let i=s;const l=r.get(i)||new Map;r.set(i,l.set(n,t)),i=`${s}-${e}`;const c=r.get(i)||new Map;if(r.set(i,c.set(n,t)),a){i=`${s}-${e}-${a}`;const d=r.get(i)||new Map;r.set(i,d.set(n,t))}}function e1(e,t,n){e.clear(),t.clear();for(const r of n){const{source:s,target:a,sourceHandle:i=null,targetHandle:l=null}=r,c={edgeId:r.id,source:s,target:a,sourceHandle:i,targetHandle:l},d=`${s}-${i}--${a}-${l}`,f=`${a}-${l}--${s}-${i}`;Df("source",c,f,e,s,i),Df("target",c,d,e,a,l),t.set(r.id,r)}}function t1(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:t1(n,t):!1}function Tf(e,t,n){let r=e;do{if(r?.matches?.(t))return!0;if(r===n)return!1;r=r?.parentElement}while(r);return!1}function cq(e,t,n,r){const s=new Map;for(const[a,i]of e)if((i.selected||i.id===r)&&(!i.parentId||!t1(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 Xi({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){const s=[];for(const[i,l]of t){const c=n.get(i)?.internals.userNode;c&&s.push({...c,position:l.position,dragging:r})}if(!e)return[s[0],s];const a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:r}:s[0],s]}function dq({dragItems:e,snapGrid:t,x:n,y:r}){const s=e.values().next().value;if(!s)return null;const a={x:n-s.distance.x,y:r-s.distance.y},i=Jo(a,t);return{x:i.x-a.x,y:i.y-a.y}}function uq({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:s}){let a={x:null,y:null},i=0,l=new Map,c=!1,d={x:0,y:0},f=null,p=!1,h=null,m=!1,g=!1,b=null;function x({noDragClassName:w,handleSelector:v,domNode:N,isSelectable:k,nodeId:C,nodeClickDistance:E=0}){h=ct(N);function A({x:B,y:R}){const{nodeLookup:M,nodeExtent:T,snapGrid:_,snapToGrid:L,nodeOrigin:O,onNodeDrag:j,onSelectionDrag:F,onError:H,updateNodePositions:D}=t();a={x:B,y:R};let Q=!1;const G=l.size>1,ee=G&&T?Xl(Xo(l)):null,se=G&&L?dq({dragItems:l,snapGrid:_,x:B,y:R}):null;for(const[te,Z]of l){if(!M.has(te))continue;let re={x:B-Z.distance.x,y:R-Z.distance.y};L&&(re=se?{x:Math.round(re.x+se.x),y:Math.round(re.y+se.y)}:Jo(re,_));let be=null;if(G&&T&&!Z.extent&&ee){const{positionAbsolute:J}=Z.internals,ae=J.x-ee.x+T[0][0],fe=J.x+Z.measured.width-ee.x2+T[1][0],ge=J.y-ee.y+T[0][1],V=J.y+Z.measured.height-ee.y2+T[1][1];be=[[ae,ge],[fe,V]]}const{position:X,positionAbsolute:K}=zv({nodeId:te,nextPosition:re,nodeLookup:M,nodeExtent:be||T,nodeOrigin:O,onError:H});Q=Q||Z.position.x!==X.x||Z.position.y!==X.y,Z.position=X,Z.internals.positionAbsolute=K}if(g=g||Q,!!Q&&(D(l,!0),b&&(r||j||!C&&F))){const[te,Z]=Xi({nodeId:C,dragItems:l,nodeLookup:M});r?.(b,l,te,Z),j?.(b,te,Z),C||F?.(b,Z)}}async function I(){if(!f)return;const{transform:B,panBy:R,autoPanSpeed:M,autoPanOnNodeDrag:T}=t();if(!T){c=!1,cancelAnimationFrame(i);return}const[_,L]=jv(d,f,M);(_!==0||L!==0)&&(a.x=(a.x??0)-_/B[2],a.y=(a.y??0)-L/B[2],await R({x:_,y:L})&&A(a)),i=requestAnimationFrame(I)}function z(B){const{nodeLookup:R,multiSelectionActive:M,nodesDraggable:T,transform:_,snapGrid:L,snapToGrid:O,selectNodesOnDrag:j,onNodeDragStart:F,onSelectionDragStart:H,unselectNodesAndEdges:D}=t();p=!0,(!j||!k)&&!M&&C&&(R.get(C)?.selected||D()),k&&j&&C&&e?.(C);const Q=mo(B.sourceEvent,{transform:_,snapGrid:L,snapToGrid:O,containerBounds:f});if(a=Q,l=cq(R,T,Q,C),l.size>0&&(n||F||!C&&H)){const[G,ee]=Xi({nodeId:C,dragItems:l,nodeLookup:R});n?.(B.sourceEvent,l,G,ee),F?.(B.sourceEvent,G,ee),C||H?.(B.sourceEvent,ee)}}const $=xv().clickDistance(E).on("start",B=>{const{domNode:R,nodeDragThreshold:M,transform:T,snapGrid:_,snapToGrid:L}=t();f=R?.getBoundingClientRect()||null,m=!1,g=!1,b=B.sourceEvent,M===0&&z(B),a=mo(B.sourceEvent,{transform:T,snapGrid:_,snapToGrid:L,containerBounds:f}),d=Tt(B.sourceEvent,f)}).on("drag",B=>{const{autoPanOnNodeDrag:R,transform:M,snapGrid:T,snapToGrid:_,nodeDragThreshold:L,nodeLookup:O}=t(),j=mo(B.sourceEvent,{transform:M,snapGrid:T,snapToGrid:_,containerBounds:f});if(b=B.sourceEvent,(B.sourceEvent.type==="touchmove"&&B.sourceEvent.touches.length>1||C&&!O.has(C))&&(m=!0),!m){if(!c&&R&&p&&(c=!0,I()),!p){const F=Tt(B.sourceEvent,f),H=F.x-d.x,D=F.y-d.y;Math.sqrt(H*H+D*D)>L&&z(B)}(a.x!==j.xSnapped||a.y!==j.ySnapped)&&l&&p&&(d=Tt(B.sourceEvent,f),A(j))}}).on("end",B=>{if(!(!p||m)&&(c=!1,p=!1,cancelAnimationFrame(i),l.size>0)){const{nodeLookup:R,updateNodePositions:M,onNodeDragStop:T,onSelectionDragStop:_}=t();if(g&&(M(l,!1),g=!1),s||T||!C&&_){const[L,O]=Xi({nodeId:C,dragItems:l,nodeLookup:R,dragging:!1});s?.(B.sourceEvent,l,L,O),T?.(B.sourceEvent,L,O),C||_?.(B.sourceEvent,O)}}}).filter(B=>{const R=B.target;return!B.button&&(!w||!Tf(R,`.${w}`,N))&&(!v||Tf(R,v,N))});h.call($)}function y(){h?.on(".drag",null)}return{update:x,destroy:y}}function pq(e,t,n){const r=[],s={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const a of t.values())_o(s,Dr(a))>0&&r.push(a);return r}const fq=250;function hq(e,t,n,r){let s=[],a=1/0;const i=pq(e,n,t+fq);for(const l of i){const c=[...l.internals.handleBounds?.source??[],...l.internals.handleBounds?.target??[]];for(const d of c){if(r.nodeId===d.nodeId&&r.type===d.type&&r.id===d.id)continue;const{x:f,y:p}=er(l,d,d.position,!0),h=Math.sqrt(Math.pow(f-e.x,2)+Math.pow(p-e.y,2));h>t||(h<a?(s=[{...d,x:f,y:p}],a=h):h===a&&s.push({...d,x:f,y:p}))}}if(!s.length)return null;if(s.length>1){const l=r.type==="source"?"target":"source";return s.find(c=>c.type===l)??s[0]}return s[0]}function n1(e,t,n,r,s,a=!1){const i=r.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,...er(i,c,c.position,!0)}:c}function r1(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function mq(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const o1=()=>!0;function gq(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:s,edgeUpdaterType:a,isTarget:i,domNode:l,nodeLookup:c,lib:d,autoPanOnConnect:f,flowId:p,panBy:h,cancelConnection:m,onConnectStart:g,onConnect:b,onConnectEnd:x,isValidConnection:y=o1,onReconnectEnd:w,updateConnection:v,getTransform:N,getFromHandle:k,autoPanSpeed:C,dragThreshold:E=1,handleDomNode:A}){const I=Uv(e.target);let z=0,$;const{x:B,y:R}=Tt(e),M=r1(a,A),T=l?.getBoundingClientRect();let _=!1;if(!T||!M)return;const L=n1(s,M,r,c,t);if(!L)return;let O=Tt(e,T),j=!1,F=null,H=!1,D=null;function Q(){if(!f||!T)return;const[X,K]=jv(O,T,C);h({x:X,y:K}),z=requestAnimationFrame(Q)}const G={...L,nodeId:s,type:M,position:L.position},ee=c.get(s);let te={inProgress:!0,isValid:null,from:er(ee,G,we.Left,!0),fromHandle:G,fromPosition:G.position,fromNode:ee,to:O,toHandle:null,toPosition:Nf[G.position],toNode:null,pointer:O};function Z(){_=!0,v(te),g?.(e,{nodeId:s,handleId:r,handleType:M})}E===0&&Z();function re(X){if(!_){const{x:V,y:ie}=Tt(X),ue=V-B,de=ie-R;if(!(ue*ue+de*de>E*E))return;Z()}if(!k()||!G){be(X);return}const K=N();O=Tt(X,T),$=hq(es(O,K,!1,[1,1]),n,c,G),j||(Q(),j=!0);const J=s1(X,{handle:$,connectionMode:t,fromNodeId:s,fromHandleId:r,fromType:i?"target":"source",isValidConnection:y,doc:I,lib:d,flowId:p,nodeLookup:c});D=J.handleDomNode,F=J.connection,H=mq(!!$,J.isValid);const ae=c.get(s),fe=ae?er(ae,G,we.Left,!0):te.from,ge={...te,from:fe,isValid:H,to:J.toHandle&&H?pa({x:J.toHandle.x,y:J.toHandle.y},K):O,toHandle:J.toHandle,toPosition:H&&J.toHandle?J.toHandle.position:Nf[G.position],toNode:J.toHandle?c.get(J.toHandle.nodeId):null,pointer:O};v(ge),te=ge}function be(X){if(!("touches"in X&&X.touches.length>0)){if(_){($||D)&&F&&H&&b?.(F);const{inProgress:K,...J}=te,ae={...J,toPosition:te.toHandle?te.toPosition:null};x?.(X,ae),a&&w?.(X,ae)}m(),cancelAnimationFrame(z),j=!1,H=!1,F=null,D=null,I.removeEventListener("mousemove",re),I.removeEventListener("mouseup",be),I.removeEventListener("touchmove",re),I.removeEventListener("touchend",be)}}I.addEventListener("mousemove",re),I.addEventListener("mouseup",be),I.addEventListener("touchmove",re),I.addEventListener("touchend",be)}function s1(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:s,fromType:a,doc:i,lib:l,flowId:c,isValidConnection:d=o1,nodeLookup:f}){const p=a==="target",h=t?i.querySelector(`.${l}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:m,y:g}=Tt(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=r1(void 0,x),v=x.getAttribute("data-nodeid"),N=x.getAttribute("data-handleid"),k=x.classList.contains("connectable"),C=x.classList.contains("connectableend");if(!v||!w)return y;const E={source:p?v:r,sourceHandle:p?N:s,target:p?r:v,targetHandle:p?s:N};y.connection=E;const I=k&&C&&(n===_r.Strict?p&&w==="source"||!p&&w==="target":v!==r||N!==s);y.isValid=I&&d(E),y.toHandle=n1(v,w,N,f,n,!0)}return y}const nc={onPointerDown:gq,isValid:s1};function bq({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){const s=ct(e);function a({translateExtent:l,width:c,height:d,zoomStep:f=1,pannable:p=!0,zoomable:h=!0,inversePan:m=!1}){const g=v=>{if(v.sourceEvent.type!=="wheel"||!t)return;const N=n(),k=v.sourceEvent.ctrlKey&&$o()?10:1,C=-v.sourceEvent.deltaY*(v.sourceEvent.deltaMode===1?.05:v.sourceEvent.deltaMode?1:.002)*f,E=N[2]*Math.pow(2,C*k);t.scaleTo(E)};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 k=[v.sourceEvent.clientX??v.sourceEvent.touches[0].clientX,v.sourceEvent.clientY??v.sourceEvent.touches[0].clientY],C=[k[0]-b[0],k[1]-b[1]];b=k;const E=r()*Math.max(N[2],Math.log(N[2]))*(m?-1:1),A={x:N[0]-C[0]*E,y:N[1]-C[1]*E},I=[[0,0],[c,d]];t.setViewportConstrained({x:A.x,y:A.y,zoom:N[2]},I,l)},w=Dv().on("start",x).on("zoom",p?y:null).on("zoom.wheel",h?g:null);s.call(w,{})}function i(){s.on("zoom",null)}return{update:a,destroy:i,pointer:_t}}const Ja=e=>({x:e.x,y:e.y,zoom:e.k}),Ji=({x:e,y:t,zoom:n})=>Ya.translate(e,t).scale(n),gr=(e,t)=>e.target.closest(`.${t}`),a1=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),xq=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,el=(e,t=0,n=xq,r=()=>{})=>{const s=typeof t=="number"&&t>0;return s||r(),s?e.transition().duration(t).ease(n).on("end",r):e},i1=e=>{const t=e.ctrlKey&&$o()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function yq({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:s,panOnScrollSpeed:a,zoomOnPinch:i,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:d}){return f=>{if(gr(f,t))return f.ctrlKey&&f.preventDefault(),!1;f.preventDefault(),f.stopImmediatePropagation();const p=n.property("__zoom").k||1;if(f.ctrlKey&&i){const x=_t(f),y=i1(f),w=p*Math.pow(2,y);r.scaleTo(n,w,x,f);return}const h=f.deltaMode===1?20:1;let m=s===Un.Vertical?0:f.deltaX*h,g=s===Un.Horizontal?0:f.deltaY*h;!$o()&&f.shiftKey&&s!==Un.Vertical&&(m=f.deltaY*h,g=0),r.translateBy(n,-(m/p)*a,-(g/p)*a,{internal:!0});const b=Ja(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(f,b),e.panScrollTimeout=setTimeout(()=>{d?.(f,b),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(f,b))}}function vq({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,s){const a=r.type==="wheel",i=!t&&a&&!r.ctrlKey,l=gr(r,e);if(r.ctrlKey&&a&&l&&r.preventDefault(),i||l)return null;r.preventDefault(),n.call(this,r,s)}}function wq({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;const s=Ja(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=s,r.sourceEvent?.type==="mousedown"&&t(!0),n&&n?.(r.sourceEvent,s)}}function Nq({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:s}){return a=>{e.usedRightMouseButton=!!(n&&a1(t,e.mouseButton??0)),a.sourceEvent?.sync||r([a.transform.x,a.transform.y,a.transform.k]),s&&!a.sourceEvent?.internal&&s?.(a.sourceEvent,Ja(a.transform))}}function kq({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:s,onPaneContextMenu:a}){return i=>{if(!i.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&a1(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&a(i.sourceEvent),e.usedRightMouseButton=!1,r(!1),s)){const l=Ja(i.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s?.(i.sourceEvent,l)},n?150:0)}}}function Sq({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:s,zoomOnDoubleClick:a,userSelectionActive:i,noWheelClassName:l,noPanClassName:c,lib:d,connectionInProgress:f}){return p=>{const h=e||t,m=n&&p.ctrlKey,g=p.type==="wheel";if(p.button===1&&p.type==="mousedown"&&(gr(p,`${d}-flow__node`)||gr(p,`${d}-flow__edge`)))return!0;if(!r&&!h&&!s&&!a&&!n||i||f&&!g||gr(p,l)&&g||gr(p,c)&&(!g||s&&g&&!e)||!n&&p.ctrlKey&&g)return!1;if(!n&&p.type==="touchstart"&&p.touches?.length>1)return p.preventDefault(),!1;if(!h&&!s&&!m&&g||!r&&(p.type==="mousedown"||p.type==="touchstart")||Array.isArray(r)&&!r.includes(p.button)&&p.type==="mousedown")return!1;const b=Array.isArray(r)&&r.includes(p.button)||!p.button||p.button<=1;return(!p.ctrlKey||g)&&b}}function Cq({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,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},f=e.getBoundingClientRect(),p=Dv().scaleExtent([t,n]).translateExtent(r),h=ct(e).call(p);w({x:s.x,y:s.y,zoom:$r(s.zoom,t,n)},[[0,0],[f.width,f.height]],r);const m=h.on("wheel.zoom"),g=h.on("dblclick.zoom");p.wheelDelta(i1);function b($,B){return h?new Promise(R=>{p?.interpolate(B?.interpolate==="linear"?ho:zs).transform(el(h,B?.duration,B?.ease,()=>R(!0)),$)}):Promise.resolve(!1)}function x({noWheelClassName:$,noPanClassName:B,onPaneContextMenu:R,userSelectionActive:M,panOnScroll:T,panOnDrag:_,panOnScrollMode:L,panOnScrollSpeed:O,preventScrolling:j,zoomOnPinch:F,zoomOnScroll:H,zoomOnDoubleClick:D,zoomActivationKeyPressed:Q,lib:G,onTransformChange:ee,connectionInProgress:se,paneClickDistance:te,selectionOnDrag:Z}){M&&!d.isZoomingOrPanning&&y();const re=T&&!Q&&!M;p.clickDistance(Z?1/0:!Dt(te)||te<0?0:te);const be=re?yq({zoomPanValues:d,noWheelClassName:$,d3Selection:h,d3Zoom:p,panOnScrollMode:L,panOnScrollSpeed:O,zoomOnPinch:F,onPanZoomStart:i,onPanZoom:a,onPanZoomEnd:l}):vq({noWheelClassName:$,preventScrolling:j,d3ZoomHandler:m});if(h.on("wheel.zoom",be,{passive:!1}),!M){const K=wq({zoomPanValues:d,onDraggingChange:c,onPanZoomStart:i});p.on("start",K);const J=Nq({zoomPanValues:d,panOnDrag:_,onPaneContextMenu:!!R,onPanZoom:a,onTransformChange:ee});p.on("zoom",J);const ae=kq({zoomPanValues:d,panOnDrag:_,panOnScroll:T,onPaneContextMenu:R,onPanZoomEnd:l,onDraggingChange:c});p.on("end",ae)}const X=Sq({zoomActivationKeyPressed:Q,panOnDrag:_,zoomOnScroll:H,panOnScroll:T,zoomOnDoubleClick:D,zoomOnPinch:F,userSelectionActive:M,noPanClassName:B,noWheelClassName:$,lib:G,connectionInProgress:se});p.filter(X),D?h.on("dblclick.zoom",g):h.on("dblclick.zoom",null)}function y(){p.on("zoom",null)}async function w($,B,R){const M=Ji($),T=p?.constrain()(M,B,R);return T&&await b(T),new Promise(_=>_(T))}async function v($,B){const R=Ji($);return await b(R,B),new Promise(M=>M(R))}function N($){if(h){const B=Ji($),R=h.property("__zoom");(R.k!==$.zoom||R.x!==$.x||R.y!==$.y)&&p?.transform(h,B,null,{sync:!0})}}function k(){const $=h?$v(h.node()):{x:0,y:0,k:1};return{x:$.x,y:$.y,zoom:$.k}}function C($,B){return h?new Promise(R=>{p?.interpolate(B?.interpolate==="linear"?ho:zs).scaleTo(el(h,B?.duration,B?.ease,()=>R(!0)),$)}):Promise.resolve(!1)}function E($,B){return h?new Promise(R=>{p?.interpolate(B?.interpolate==="linear"?ho:zs).scaleBy(el(h,B?.duration,B?.ease,()=>R(!0)),$)}):Promise.resolve(!1)}function A($){p?.scaleExtent($)}function I($){p?.translateExtent($)}function z($){const B=!Dt($)||$<0?0:$;p?.clickDistance(B)}return{update:x,destroy:y,setViewport:v,setViewportConstrained:w,getViewport:k,scaleTo:C,scaleBy:E,setScaleExtent:A,setTranslateExtent:I,syncViewport:N,setClickDistance:z}}var Lr;(function(e){e.Line="line",e.Handle="handle"})(Lr||(Lr={}));function Mq({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:s,affectsY:a}){const i=e-t,l=n-r,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 Lf(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),r=e.includes("left"),s=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:r,affectsY:s}}function yn(e,t){return Math.max(0,t-e)}function vn(e,t){return Math.max(0,e-t)}function Is(e,t,n){return Math.max(0,t-e,e-n)}function Rf(e,t){return e?!t:t}function Eq(e,t,n,r,s,a,i,l){let{affectsX:c,affectsY:d}=t;const{isHorizontal:f,isVertical:p}=t,h=f&&p,{xSnapped:m,ySnapped:g}=n,{minWidth:b,maxWidth:x,minHeight:y,maxHeight:w}=r,{x:v,y:N,width:k,height:C,aspectRatio:E}=e;let A=Math.floor(f?m-e.pointerX:0),I=Math.floor(p?g-e.pointerY:0);const z=k+(c?-A:A),$=C+(d?-I:I),B=-a[0]*k,R=-a[1]*C;let M=Is(z,b,x),T=Is($,y,w);if(i){let O=0,j=0;c&&A<0?O=yn(v+A+B,i[0][0]):!c&&A>0&&(O=vn(v+z+B,i[1][0])),d&&I<0?j=yn(N+I+R,i[0][1]):!d&&I>0&&(j=vn(N+$+R,i[1][1])),M=Math.max(M,O),T=Math.max(T,j)}if(l){let O=0,j=0;c&&A>0?O=vn(v+A,l[0][0]):!c&&A<0&&(O=yn(v+z,l[1][0])),d&&I>0?j=vn(N+I,l[0][1]):!d&&I<0&&(j=yn(N+$,l[1][1])),M=Math.max(M,O),T=Math.max(T,j)}if(s){if(f){const O=Is(z/E,y,w)*E;if(M=Math.max(M,O),i){let j=0;!c&&!d||c&&!d&&h?j=vn(N+R+z/E,i[1][1])*E:j=yn(N+R+(c?A:-A)/E,i[0][1])*E,M=Math.max(M,j)}if(l){let j=0;!c&&!d||c&&!d&&h?j=yn(N+z/E,l[1][1])*E:j=vn(N+(c?A:-A)/E,l[0][1])*E,M=Math.max(M,j)}}if(p){const O=Is($*E,b,x)/E;if(T=Math.max(T,O),i){let j=0;!c&&!d||d&&!c&&h?j=vn(v+$*E+B,i[1][0])/E:j=yn(v+(d?I:-I)*E+B,i[0][0])/E,T=Math.max(T,j)}if(l){let j=0;!c&&!d||d&&!c&&h?j=yn(v+$*E,l[1][0])/E:j=vn(v+(d?I:-I)*E,l[0][0])/E,T=Math.max(T,j)}}}I=I+(I<0?T:-T),A=A+(A<0?M:-M),s&&(h?z>$*E?I=(Rf(c,d)?-A:A)/E:A=(Rf(c,d)?-I:I)*E:f?(I=A/E,d=c):(A=I*E,c=d));const _=c?v+A:v,L=d?N+I:N;return{width:k+(c?-A:A),height:C+(d?-I:I),x:a[0]*A*(c?-1:1)+_,y:a[1]*I*(d?-1:1)+L}}const l1={width:0,height:0,x:0,y:0},Iq={...l1,pointerX:0,pointerY:0,aspectRatio:1};function Aq(e){return[[0,0],[e.measured.width,e.measured.height]]}function Pq(e,t,n){const r=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[[r-l,s-c],[r+a-l,s+i-c]]}function _q({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:s}){const a=ct(e);let i={controlDirection:Lf("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:f,keepAspectRatio:p,resizeDirection:h,onResizeStart:m,onResize:g,onResizeEnd:b,shouldResize:x}){let y={...l1},w={...Iq};i={boundaries:f,resizeDirection:h,keepAspectRatio:p,controlDirection:Lf(d)};let v,N=null,k=[],C,E,A,I=!1;const z=xv().on("start",$=>{const{nodeLookup:B,transform:R,snapGrid:M,snapToGrid:T,nodeOrigin:_,paneDomNode:L}=n();if(v=B.get(t),!v)return;N=L?.getBoundingClientRect()??null;const{xSnapped:O,ySnapped:j}=mo($.sourceEvent,{transform:R,snapGrid:M,snapToGrid:T,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:O,pointerY:j,aspectRatio:y.width/y.height},C=void 0,v.parentId&&(v.extent==="parent"||v.expandParent)&&(C=B.get(v.parentId),E=C&&v.extent==="parent"?Aq(C):void 0),k=[],A=void 0;for(const[F,H]of B)if(H.parentId===t&&(k.push({id:F,position:{...H.position},extent:H.extent}),H.extent==="parent"||H.expandParent)){const D=Pq(H,v,H.origin??_);A?A=[[Math.min(D[0][0],A[0][0]),Math.min(D[0][1],A[0][1])],[Math.max(D[1][0],A[1][0]),Math.max(D[1][1],A[1][1])]]:A=D}m?.($,{...y})}).on("drag",$=>{const{transform:B,snapGrid:R,snapToGrid:M,nodeOrigin:T}=n(),_=mo($.sourceEvent,{transform:B,snapGrid:R,snapToGrid:M,containerBounds:N}),L=[];if(!v)return;const{x:O,y:j,width:F,height:H}=y,D={},Q=v.origin??T,{width:G,height:ee,x:se,y:te}=Eq(w,i.controlDirection,_,i.boundaries,i.keepAspectRatio,Q,E,A),Z=G!==F,re=ee!==H,be=se!==O&&Z,X=te!==j&&re;if(!be&&!X&&!Z&&!re)return;if((be||X||Q[0]===1||Q[1]===1)&&(D.x=be?se:y.x,D.y=X?te:y.y,y.x=D.x,y.y=D.y,k.length>0)){const fe=se-O,ge=te-j;for(const V of k)V.position={x:V.position.x-fe+Q[0]*(G-F),y:V.position.y-ge+Q[1]*(ee-H)},L.push(V)}if((Z||re)&&(D.width=Z&&(!i.resizeDirection||i.resizeDirection==="horizontal")?G:y.width,D.height=re&&(!i.resizeDirection||i.resizeDirection==="vertical")?ee:y.height,y.width=D.width,y.height=D.height),C&&v.expandParent){const fe=Q[0]*(D.width??0);D.x&&D.x<fe&&(y.x=fe,w.x=w.x-(D.x-fe));const ge=Q[1]*(D.height??0);D.y&&D.y<ge&&(y.y=ge,w.y=w.y-(D.y-ge))}const K=Mq({width:y.width,prevWidth:F,height:y.height,prevHeight:H,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),J={...y,direction:K};x?.($,J)!==!1&&(I=!0,g?.($,J),r(D,L))}).on("end",$=>{I&&(b?.($,{...y}),s?.({...y}),I=!1)});a.call(z)}function c(){a.on(".drag",null)}return{update:l,destroy:c}}var c1={exports:{}},d1={};/**
1115
- * @license React
1116
- * use-sync-external-store-shim/with-selector.production.js
1117
- *
1118
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1119
- *
1120
- * This source code is licensed under the MIT license found in the
1121
- * LICENSE file in the root directory of this source tree.
1122
- */var ei=Lh,$q=A0;function Dq(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var Tq=typeof Object.is=="function"?Object.is:Dq,Lq=$q.useSyncExternalStore,Rq=ei.useRef,Oq=ei.useEffect,Bq=ei.useMemo,zq=ei.useDebugValue;d1.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var a=Rq(null);if(a.current===null){var i={hasValue:!1,value:null};a.current=i}else i=a.current;a=Bq(function(){function c(m){if(!d){if(d=!0,f=m,m=r(m),s!==void 0&&i.hasValue){var g=i.value;if(s(g,m))return p=g}return p=m}if(g=p,Tq(f,m))return g;var b=r(m);return s!==void 0&&s(g,b)?(f=m,g):(f=m,p=b)}var d=!1,f,p,h=n===void 0?null:n;return[function(){return c(t())},h===null?void 0:function(){return c(h())}]},[t,n,r,s]);var l=Lq(e,a[0],a[1]);return Oq(function(){i.hasValue=!0,i.value=l},[l]),zq(l),l};c1.exports=d1;var Fq=c1.exports;const jq=hN(Fq),Hq={},Of=e=>{let t;const n=new Set,r=(f,p)=>{const h=typeof f=="function"?f(t):f;if(!Object.is(h,t)){const m=t;t=p??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(g=>g(t,m))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>d,subscribe:f=>(n.add(f),()=>n.delete(f)),destroy:()=>{(Hq?"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(r,s,c);return c},Vq=e=>e?Of(e):Of,{useDebugValue:qq}=ic,{useSyncExternalStoreWithSelector:Uq}=jq,Qq=e=>e;function u1(e,t=Qq,n){const r=Uq(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return qq(r),r}const Bf=(e,t)=>{const n=Vq(e),r=(s,a=t)=>u1(n,s,a);return Object.assign(r,n),r},Gq=(e,t)=>e?Bf(e,t):Bf;function je(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[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}const ti=Be(null),Kq=ti.Provider,p1=Zt.error001();function $e(e,t){const n=ve(ti);if(n===null)throw new Error(p1);return u1(n,e,t)}function Ve(){const e=ve(ti);if(e===null)throw new Error(p1);return q(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const zf={display:"none"},Wq={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},f1="react-flow__node-desc",h1="react-flow__edge-desc",Yq="react-flow__aria-live",Zq=e=>e.ariaLiveMessage,Xq=e=>e.ariaLabelConfig;function Jq({rfId:e}){const t=$e(Zq);return o("div",{id:`${Yq}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Wq,children:t})}function eU({rfId:e,disableKeyboardA11y:t}){const n=$e(Xq);return u(me,{children:[o("div",{id:`${f1}-${e}`,style:zf,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),o("div",{id:`${h1}-${e}`,style:zf,children:n["edge.a11yDescription.default"]}),!t&&o(Jq,{rfId:e})]})}const ni=qe(({position:e="top-left",children:t,className:n,style:r,...s},a)=>{const i=`${e}`.split("-");return o("div",{className:Qe(["react-flow__panel",n,...i]),style:r,ref:a,...s,children:t})});ni.displayName="Panel";function tU({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:o(ni,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:o("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const nU=e=>{const t=[],n=[];for(const[,r]of e.nodeLookup)r.selected&&t.push(r.internals.userNode);for(const[,r]of e.edgeLookup)r.selected&&n.push(r);return{selectedNodes:t,selectedEdges:n}},As=e=>e.id;function rU(e,t){return je(e.selectedNodes.map(As),t.selectedNodes.map(As))&&je(e.selectedEdges.map(As),t.selectedEdges.map(As))}function oU({onSelectionChange:e}){const t=Ve(),{selectedNodes:n,selectedEdges:r}=$e(nU,rU);return Y(()=>{const s={nodes:n,edges:r};e?.(s),t.getState().onSelectionChangeHandlers.forEach(a=>a(s))},[n,r,e]),null}const sU=e=>!!e.onSelectionChangeHandlers;function aU({onSelectionChange:e}){const t=$e(sU);return e||t?o(oU,{onSelectionChange:e}):null}const rc=typeof window<"u"?ba:Y,m1=[0,0],iU={x:0,y:0,zoom:1},lU=["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"],Ff=[...lU,"rfId"],cU=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}),jf={translateExtent:Ao,nodeOrigin:m1,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function dU(e){const{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:s,setTranslateExtent:a,setNodeExtent:i,reset:l,setDefaultNodesAndEdges:c}=$e(cU,je),d=Ve();rc(()=>(c(e.defaultNodes,e.defaultEdges),()=>{f.current=jf,l()}),[]);const f=ne(jf);return rc(()=>{for(const p of Ff){const h=e[p],m=f.current[p];h!==m&&(typeof e[p]>"u"||(p==="nodes"?t(h):p==="edges"?n(h):p==="minZoom"?r(h):p==="maxZoom"?s(h):p==="translateExtent"?a(h):p==="nodeExtent"?i(h):p==="ariaLabelConfig"?d.setState({ariaLabelConfig:VV(h)}):p==="fitView"?d.setState({fitViewQueued:h}):p==="fitViewOptions"?d.setState({fitViewOptions:h}):d.setState({[p]:h})))}f.current=e},Ff.map(p=>e[p])),null}function Hf(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function uU(e){const[t,n]=P(e==="system"?null:e);return Y(()=>{if(e!=="system"){n(e);return}const r=Hf(),s=()=>n(r?.matches?"dark":"light");return s(),r?.addEventListener("change",s),()=>{r?.removeEventListener("change",s)}},[e]),t!==null?t:Hf()?.matches?"dark":"light"}const Vf=typeof document<"u"?document:null;function Do(e=null,t={target:Vf,actInsideInputWithModifier:!0}){const[n,r]=P(!1),s=ne(!1),a=ne(new Set([])),[i,l]=q(()=>{if(e!==null){const d=(Array.isArray(e)?e:[e]).filter(p=>typeof p=="string").map(p=>p.replace("+",`
1123
- `).replace(`
1124
-
1125
- `,`
1126
- +`).split(`
1127
- `)),f=d.reduce((p,h)=>p.concat(...h),[]);return[d,f]}return[[],[]]},[e]);return Y(()=>{const c=t?.target??Vf,d=t?.actInsideInputWithModifier??!0;if(e!==null){const f=m=>{if(s.current=m.ctrlKey||m.metaKey||m.shiftKey||m.altKey,(!s.current||s.current&&!d)&&Qv(m))return!1;const b=Uf(m.code,l);if(a.current.add(m[b]),qf(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(),r(!0)}},p=m=>{const g=Uf(m.code,l);qf(i,a.current,!0)?(r(!1),a.current.clear()):a.current.delete(m[g]),m.key==="Meta"&&a.current.clear(),s.current=!1},h=()=>{a.current.clear(),r(!1)};return c?.addEventListener("keydown",f),c?.addEventListener("keyup",p),window.addEventListener("blur",h),window.addEventListener("contextmenu",h),()=>{c?.removeEventListener("keydown",f),c?.removeEventListener("keyup",p),window.removeEventListener("blur",h),window.removeEventListener("contextmenu",h)}}},[e,r]),n}function qf(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Uf(e,t){return t.includes(e)?"code":"key"}const pU=()=>{const e=Ve();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:r}=e.getState();return r?r.scaleTo(t,n):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[r,s,a],panZoom:i}=e.getState();return i?(await i.setViewport({x:t.x??r,y:t.y??s,zoom:t.zoom??a},n),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[t,n,r]=e.getState().transform;return{x:t,y:n,zoom:r}},setCenter:async(t,n,r)=>e.getState().setCenter(t,n,r),fitBounds:async(t,n)=>{const{width:r,height:s,minZoom:a,maxZoom:i,panZoom:l}=e.getState(),c=qd(t,r,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:r,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},f=n.snapGrid??s,p=n.snapToGrid??a;return es(d,r,p,f)},flowToScreenPosition:t=>{const{transform:n,domNode:r}=e.getState();if(!r)return t;const{x:s,y:a}=r.getBoundingClientRect(),i=pa(t,n);return{x:i.x+s,y:i.y+a}}}),[])};function g1(e,t){const n=[],r=new Map,s=[];for(const a of e)if(a.type==="add"){s.push(a);continue}else if(a.type==="remove"||a.type==="replace")r.set(a.id,[a]);else{const i=r.get(a.id);i?i.push(a):r.set(a.id,[a])}for(const a of t){const i=r.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)fU(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 fU(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 hU(e,t){return g1(e,t)}function mU(e,t){return g1(e,t)}function Fn(e,t){return{id:e,type:"select",selected:t}}function br(e,t=new Set,n=!1){const r=[];for(const[s,a]of e){const i=t.has(s);!(a.selected===void 0&&!i)&&a.selected!==i&&(n&&(a.selected=i),r.push(Fn(a.id,i)))}return r}function Qf({items:e=[],lookup:t}){const n=[],r=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)r.get(s)===void 0&&n.push({id:s,type:"remove"});return n}function Gf(e){return{id:e.id,type:"remove"}}const Kf=e=>DV(e),gU=e=>Bv(e);function b1(e){return qe(e)}function Wf(e){const[t,n]=P(BigInt(0)),[r]=P(()=>bU(()=>n(s=>s+BigInt(1))));return rc(()=>{const s=r.get();s.length&&(e(s),r.reset())},[t]),r}function bU(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const x1=Be(null);function xU({children:e}){const t=Ve(),n=U(l=>{const{nodes:c=[],setNodes:d,hasDefaultNodes:f,onNodesChange:p,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=Qf({items:b,lookup:h});for(const y of g.values())x=y(x);f&&d(b),x.length>0?p?.(x):m&&window.requestAnimationFrame(()=>{const{fitViewQueued:y,nodes:w,setNodes:v}=t.getState();y&&v(w)})},[]),r=Wf(n),s=U(l=>{const{edges:c=[],setEdges:d,hasDefaultEdges:f,onEdgesChange:p,edgeLookup:h}=t.getState();let m=c;for(const g of l)m=typeof g=="function"?g(m):g;f?d(m):p&&p(Qf({items:m,lookup:h}))},[]),a=Wf(s),i=q(()=>({nodeQueue:r,edgeQueue:a}),[]);return o(x1.Provider,{value:i,children:e})}function yU(){const e=ve(x1);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const vU=e=>!!e.panZoom;function Zd(){const e=pU(),t=Ve(),n=yU(),r=$e(vU),s=q(()=>{const a=p=>t.getState().nodeLookup.get(p),i=p=>{n.nodeQueue.push(p)},l=p=>{n.edgeQueue.push(p)},c=p=>{const{nodeLookup:h,nodeOrigin:m}=t.getState(),g=Kf(p)?p:h.get(p.id),b=g.parentId?qv(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 Dr(x)},d=(p,h,m={replace:!1})=>{i(g=>g.map(b=>{if(b.id===p){const x=typeof h=="function"?h(b):h;return m.replace&&Kf(x)?x:{...b,...x}}return b}))},f=(p,h,m={replace:!1})=>{l(g=>g.map(b=>{if(b.id===p){const x=typeof h=="function"?h(b):h;return m.replace&&gU(x)?x:{...b,...x}}return b}))};return{getNodes:()=>t.getState().nodes.map(p=>({...p})),getNode:p=>a(p)?.internals.userNode,getInternalNode:a,getEdges:()=>{const{edges:p=[]}=t.getState();return p.map(h=>({...h}))},getEdge:p=>t.getState().edgeLookup.get(p),setNodes:i,setEdges:l,addNodes:p=>{const h=Array.isArray(p)?p:[p];n.nodeQueue.push(m=>[...m,...h])},addEdges:p=>{const h=Array.isArray(p)?p:[p];n.edgeQueue.push(m=>[...m,...h])},toObject:()=>{const{nodes:p=[],edges:h=[],transform:m}=t.getState(),[g,b,x]=m;return{nodes:p.map(y=>({...y})),edges:h.map(y=>({...y})),viewport:{x:g,y:b,zoom:x}}},deleteElements:async({nodes:p=[],edges:h=[]})=>{const{nodes:m,edges:g,onNodesDelete:b,onEdgesDelete:x,triggerNodeChanges:y,triggerEdgeChanges:w,onDelete:v,onBeforeDelete:N}=t.getState(),{nodes:k,edges:C}=await BV({nodesToRemove:p,edgesToRemove:h,nodes:m,edges:g,onBeforeDelete:N}),E=C.length>0,A=k.length>0;if(E){const I=C.map(Gf);x?.(C),w(I)}if(A){const I=k.map(Gf);b?.(k),y(I)}return(A||E)&&v?.({nodes:k,edges:C}),{deletedNodes:k,deletedEdges:C}},getIntersectingNodes:(p,h=!0,m)=>{const g=Sf(p),b=g?p:c(p),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===p.id||!w.internals.positionAbsolute))return!1;const v=Dr(x?y:w),N=_o(v,b);return h&&N>0||N>=v.width*v.height||N>=b.width*b.height}):[]},isNodeIntersecting:(p,h,m=!0)=>{const b=Sf(p)?p:c(p);if(!b)return!1;const x=_o(b,h);return m&&x>0||x>=h.width*h.height||x>=b.width*b.height},updateNode:d,updateNodeData:(p,h,m={replace:!1})=>{d(p,g=>{const b=typeof h=="function"?h(g):h;return m.replace?{...g,data:b}:{...g,data:{...g.data,...b}}},m)},updateEdge:f,updateEdgeData:(p,h,m={replace:!1})=>{f(p,g=>{const b=typeof h=="function"?h(g):h;return m.replace?{...g,data:b}:{...g,data:{...g.data,...b}}},m)},getNodesBounds:p=>{const{nodeLookup:h,nodeOrigin:m}=t.getState();return TV(p,{nodeLookup:h,nodeOrigin:m})},getHandleConnections:({type:p,id:h,nodeId:m})=>Array.from(t.getState().connectionLookup.get(`${m}-${p}${h?`-${h}`:""}`)?.values()??[]),getNodeConnections:({type:p,handleId:h,nodeId:m})=>Array.from(t.getState().connectionLookup.get(`${m}${p?h?`-${p}-${h}`:`-${p}`:""}`)?.values()??[]),fitView:async p=>{const h=t.getState().fitViewResolver??HV();return t.setState({fitViewQueued:!0,fitViewOptions:p,fitViewResolver:h}),n.nodeQueue.push(m=>[...m]),h.promise}}},[]);return q(()=>({...s,...e,viewportInitialized:r}),[r])}const Yf=e=>e.selected,wU=typeof window<"u"?window:void 0;function NU({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=Ve(),{deleteElements:r}=Zd(),s=Do(e,{actInsideInputWithModifier:!1}),a=Do(t,{target:wU});Y(()=>{if(s){const{edges:i,nodes:l}=n.getState();r({nodes:l.filter(Yf),edges:i.filter(Yf)}),n.setState({nodesSelectionActive:!1})}},[s]),Y(()=>{n.setState({multiSelectionActive:a})},[a])}function kU(e){const t=Ve();Y(()=>{const n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const r=Ud(e.current);(r.height===0||r.width===0)&&t.getState().onError?.("004",Zt.error004()),t.setState({width:r.width||500,height:r.height||500})};if(e.current){n(),window.addEventListener("resize",n);const r=new ResizeObserver(()=>n());return r.observe(e.current),()=>{window.removeEventListener("resize",n),r&&e.current&&r.unobserve(e.current)}}},[])}const ri={position:"absolute",width:"100%",height:"100%",top:0,left:0},SU=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function CU({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:r=!1,panOnScrollSpeed:s=.5,panOnScrollMode:a=Un.Free,zoomOnDoubleClick:i=!0,panOnDrag:l=!0,defaultViewport:c,translateExtent:d,minZoom:f,maxZoom:p,zoomActivationKeyCode:h,preventScrolling:m=!0,children:g,noWheelClassName:b,noPanClassName:x,onViewportChange:y,isControlledViewport:w,paneClickDistance:v,selectionOnDrag:N}){const k=Ve(),C=ne(null),{userSelectionActive:E,lib:A,connectionInProgress:I}=$e(SU,je),z=Do(h),$=ne();kU(C);const B=U(R=>{y?.({x:R[0],y:R[1],zoom:R[2]}),w||k.setState({transform:R})},[y,w]);return Y(()=>{if(C.current){$.current=Cq({domNode:C.current,minZoom:f,maxZoom:p,translateExtent:d,viewport:c,onDraggingChange:_=>k.setState(L=>L.paneDragging===_?L:{paneDragging:_}),onPanZoomStart:(_,L)=>{const{onViewportChangeStart:O,onMoveStart:j}=k.getState();j?.(_,L),O?.(L)},onPanZoom:(_,L)=>{const{onViewportChange:O,onMove:j}=k.getState();j?.(_,L),O?.(L)},onPanZoomEnd:(_,L)=>{const{onViewportChangeEnd:O,onMoveEnd:j}=k.getState();j?.(_,L),O?.(L)}});const{x:R,y:M,zoom:T}=$.current.getViewport();return k.setState({panZoom:$.current,transform:[R,M,T],domNode:C.current.closest(".react-flow")}),()=>{$.current?.destroy()}}},[]),Y(()=>{$.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:r,panOnScrollSpeed:s,panOnScrollMode:a,zoomOnDoubleClick:i,panOnDrag:l,zoomActivationKeyPressed:z,preventScrolling:m,noPanClassName:x,userSelectionActive:E,noWheelClassName:b,lib:A,onTransformChange:B,connectionInProgress:I,selectionOnDrag:N,paneClickDistance:v})},[e,t,n,r,s,a,i,l,z,m,x,E,b,A,B,I,N,v]),o("div",{className:"react-flow__renderer",ref:C,style:ri,children:g})}const MU=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function EU(){const{userSelectionActive:e,userSelectionRect:t}=$e(MU,je);return e&&t?o("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 tl=(e,t)=>n=>{n.target===t.current&&e?.(n)},IU=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function AU({isSelecting:e,selectionKeyPressed:t,selectionMode:n=Po.Full,panOnDrag:r,paneClickDistance:s,selectionOnDrag:a,onSelectionStart:i,onSelectionEnd:l,onPaneClick:c,onPaneContextMenu:d,onPaneScroll:f,onPaneMouseEnter:p,onPaneMouseMove:h,onPaneMouseLeave:m,children:g}){const b=Ve(),{userSelectionActive:x,elementsSelectable:y,dragging:w,connectionInProgress:v}=$e(IU,je),N=y&&(e||x),k=ne(null),C=ne(),E=ne(new Set),A=ne(new Set),I=ne(!1),z=O=>{if(I.current||v){I.current=!1;return}c?.(O),b.getState().resetSelectedElements(),b.setState({nodesSelectionActive:!1})},$=O=>{if(Array.isArray(r)&&r?.includes(2)){O.preventDefault();return}d?.(O)},B=f?O=>f(O):void 0,R=O=>{I.current&&(O.stopPropagation(),I.current=!1)},M=O=>{const{domNode:j}=b.getState();if(C.current=j?.getBoundingClientRect(),!C.current)return;const F=O.target===k.current;if(!F&&!!O.target.closest(".nokey")||!e||!(a&&F||t)||O.button!==0||!O.isPrimary)return;O.target?.setPointerCapture?.(O.pointerId),I.current=!1;const{x:Q,y:G}=Tt(O.nativeEvent,C.current);b.setState({userSelectionRect:{width:0,height:0,startX:Q,startY:G,x:Q,y:G}}),F||(O.stopPropagation(),O.preventDefault())},T=O=>{const{userSelectionRect:j,transform:F,nodeLookup:H,edgeLookup:D,connectionLookup:Q,triggerNodeChanges:G,triggerEdgeChanges:ee,defaultEdgeOptions:se,resetSelectedElements:te}=b.getState();if(!C.current||!j)return;const{x:Z,y:re}=Tt(O.nativeEvent,C.current),{startX:be,startY:X}=j;if(!I.current){const ge=t?0:s;if(Math.hypot(Z-be,re-X)<=ge)return;te(),i?.(O)}I.current=!0;const K={startX:be,startY:X,x:Z<be?Z:be,y:re<X?re:X,width:Math.abs(Z-be),height:Math.abs(re-X)},J=E.current,ae=A.current;E.current=new Set(Vd(H,K,F,n===Po.Partial,!0).map(ge=>ge.id)),A.current=new Set;const fe=se?.selectable??!0;for(const ge of E.current){const V=Q.get(ge);if(V)for(const{edgeId:ie}of V.values()){const ue=D.get(ie);ue&&(ue.selectable??fe)&&A.current.add(ie)}}if(!Cf(J,E.current)){const ge=br(H,E.current,!0);G(ge)}if(!Cf(ae,A.current)){const ge=br(D,A.current);ee(ge)}b.setState({userSelectionRect:K,userSelectionActive:!0,nodesSelectionActive:!1})},_=O=>{O.button===0&&(O.target?.releasePointerCapture?.(O.pointerId),!x&&O.target===k.current&&b.getState().userSelectionRect&&z?.(O),b.setState({userSelectionActive:!1,userSelectionRect:null}),I.current&&(l?.(O),b.setState({nodesSelectionActive:E.current.size>0})))},L=r===!0||Array.isArray(r)&&r.includes(0);return u("div",{className:Qe(["react-flow__pane",{draggable:L,dragging:w,selection:e}]),onClick:N?void 0:tl(z,k),onContextMenu:tl($,k),onWheel:tl(B,k),onPointerEnter:N?void 0:p,onPointerMove:N?T:h,onPointerUp:N?_:void 0,onPointerDownCapture:N?M:void 0,onClickCapture:N?R:void 0,onPointerLeave:m,ref:k,style:ri,children:[g,o(EU,{})]})}function oc({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:a,multiSelectionActive:i,nodeLookup:l,onError:c}=t.getState(),d=l.get(e);if(!d){c?.("012",Zt.error012(e));return}t.setState({nodesSelectionActive:!1}),d.selected?(n||d.selected&&i)&&(a({nodes:[d],edges:[]}),requestAnimationFrame(()=>r?.current?.blur())):s([e])}function y1({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:a,nodeClickDistance:i}){const l=Ve(),[c,d]=P(!1),f=ne();return Y(()=>{f.current=uq({getStoreItems:()=>l.getState(),onNodeMouseDown:p=>{oc({id:p,store:l,nodeRef:e})},onDragStart:()=>{d(!0)},onDragStop:()=>{d(!1)}})},[]),Y(()=>{if(!(t||!e.current||!f.current))return f.current.update({noDragClassName:n,handleSelector:r,domNode:e.current,isSelectable:a,nodeId:s,nodeClickDistance:i}),()=>{f.current?.destroy()}},[n,r,t,a,e,s,i]),c}const PU=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function v1(){const e=Ve();return U(n=>{const{nodeExtent:r,snapToGrid:s,snapGrid:a,nodesDraggable:i,onError:l,updateNodePositions:c,nodeLookup:d,nodeOrigin:f}=e.getState(),p=new Map,h=PU(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=Jo(w,a));const{position:v,positionAbsolute:N}=zv({nodeId:y.id,nextPosition:w,nodeLookup:d,nodeExtent:r,nodeOrigin:f,onError:l});y.position=v,y.internals.positionAbsolute=N,p.set(y.id,y)}c(p)},[])}const Xd=Be(null),_U=Xd.Provider;Xd.Consumer;const w1=()=>ve(Xd),$U=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),DU=(e,t,n)=>r=>{const{connectionClickStartHandle:s,connectionMode:a,connection:i}=r,{fromHandle:l,toHandle:c,isValid:d}=i,f=c?.nodeId===e&&c?.id===t&&c?.type===n;return{connectingFrom:l?.nodeId===e&&l?.id===t&&l?.type===n,connectingTo:f,clickConnecting:s?.nodeId===e&&s?.id===t&&s?.type===n,isPossibleEndHandle:a===_r.Strict?l?.type!==n:e!==l?.nodeId||t!==l?.id,connectionInProcess:!!l,clickConnectionInProcess:!!s,valid:f&&d}};function TU({type:e="source",position:t=we.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:a=!0,id:i,onConnect:l,children:c,className:d,onMouseDown:f,onTouchStart:p,...h},m){const g=i||null,b=e==="target",x=Ve(),y=w1(),{connectOnClick:w,noPanClassName:v,rfId:N}=$e($U,je),{connectingFrom:k,connectingTo:C,clickConnecting:E,isPossibleEndHandle:A,connectionInProcess:I,clickConnectionInProcess:z,valid:$}=$e(DU(y,g,e),je);y||x.getState().onError?.("010",Zt.error010());const B=T=>{const{defaultEdgeOptions:_,onConnect:L,hasDefaultEdges:O}=x.getState(),j={..._,...T};if(O){const{edges:F,setEdges:H}=x.getState();H(WV(j,F))}L?.(j),l?.(j)},R=T=>{if(!y)return;const _=Gv(T.nativeEvent);if(s&&(_&&T.button===0||!_)){const L=x.getState();nc.onPointerDown(T.nativeEvent,{handleDomNode:T.currentTarget,autoPanOnConnect:L.autoPanOnConnect,connectionMode:L.connectionMode,connectionRadius:L.connectionRadius,domNode:L.domNode,nodeLookup:L.nodeLookup,lib:L.lib,isTarget:b,handleId:g,nodeId:y,flowId:L.rfId,panBy:L.panBy,cancelConnection:L.cancelConnection,onConnectStart:L.onConnectStart,onConnectEnd:(...O)=>x.getState().onConnectEnd?.(...O),updateConnection:L.updateConnection,onConnect:B,isValidConnection:n||((...O)=>x.getState().isValidConnection?.(...O)??!0),getTransform:()=>x.getState().transform,getFromHandle:()=>x.getState().connection.fromHandle,autoPanSpeed:L.autoPanSpeed,dragThreshold:L.connectionDragThreshold})}_?f?.(T):p?.(T)},M=T=>{const{onClickConnectStart:_,onClickConnectEnd:L,connectionClickStartHandle:O,connectionMode:j,isValidConnection:F,lib:H,rfId:D,nodeLookup:Q,connection:G}=x.getState();if(!y||!O&&!s)return;if(!O){_?.(T.nativeEvent,{nodeId:y,handleId:g,handleType:e}),x.setState({connectionClickStartHandle:{nodeId:y,type:e,id:g}});return}const ee=Uv(T.target),se=n||F,{connection:te,isValid:Z}=nc.isValid(T.nativeEvent,{handle:{nodeId:y,id:g,type:e},connectionMode:j,fromNodeId:O.nodeId,fromHandleId:O.id||null,fromType:O.type,isValidConnection:se,flowId:D,doc:ee,lib:H,nodeLookup:Q});Z&&te&&B(te);const re=structuredClone(G);delete re.inProgress,re.toPosition=re.toHandle?re.toHandle.position:null,L?.(T,re),x.setState({connectionClickStartHandle:null})};return o("div",{"data-handleid":g,"data-nodeid":y,"data-handlepos":t,"data-id":`${N}-${y}-${g}-${e}`,className:Qe(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",v,d,{source:!b,target:b,connectable:r,connectablestart:s,connectableend:a,clickconnecting:E,connectingfrom:k,connectingto:C,valid:$,connectionindicator:r&&(!I||A)&&(I||z?a:s)}]),onMouseDown:R,onTouchStart:R,onClick:w?M:void 0,ref:m,...h,children:c})}const In=He(b1(TU));function LU({data:e,isConnectable:t,sourcePosition:n=we.Bottom}){return u(me,{children:[e?.label,o(In,{type:"source",position:n,isConnectable:t})]})}function RU({data:e,isConnectable:t,targetPosition:n=we.Top,sourcePosition:r=we.Bottom}){return u(me,{children:[o(In,{type:"target",position:n,isConnectable:t}),e?.label,o(In,{type:"source",position:r,isConnectable:t})]})}function OU(){return null}function BU({data:e,isConnectable:t,targetPosition:n=we.Top}){return u(me,{children:[o(In,{type:"target",position:n,isConnectable:t}),e?.label]})}const fa={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Zf={input:LU,default:RU,output:BU,group:OU};function zU(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 FU=e=>{const{width:t,height:n,x:r,y:s}=Xo(e.nodeLookup,{filter:a=>!!a.selected});return{width:Dt(t)?t:null,height:Dt(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${r}px,${s}px)`}};function jU({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ve(),{width:s,height:a,transformString:i,userSelectionActive:l}=$e(FU,je),c=v1(),d=ne(null);Y(()=>{n||d.current?.focus({preventScroll:!0})},[n]);const f=!l&&s!==null&&a!==null;if(y1({nodeRef:d,disabled:!f}),!f)return null;const p=e?m=>{const g=r.getState().nodes.filter(b=>b.selected);e(m,g)}:void 0,h=m=>{Object.prototype.hasOwnProperty.call(fa,m.key)&&(m.preventDefault(),c({direction:fa[m.key],factor:m.shiftKey?4:1}))};return o("div",{className:Qe(["react-flow__nodesselection","react-flow__container",t]),style:{transform:i},children:o("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:p,tabIndex:n?void 0:-1,onKeyDown:n?void 0:h,style:{width:s,height:a}})})}const Xf=typeof window<"u"?window:void 0,HU=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function N1({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:a,onPaneScroll:i,paneClickDistance:l,deleteKeyCode:c,selectionKeyCode:d,selectionOnDrag:f,selectionMode:p,onSelectionStart:h,onSelectionEnd:m,multiSelectionKeyCode:g,panActivationKeyCode:b,zoomActivationKeyCode:x,elementsSelectable:y,zoomOnScroll:w,zoomOnPinch:v,panOnScroll:N,panOnScrollSpeed:k,panOnScrollMode:C,zoomOnDoubleClick:E,panOnDrag:A,defaultViewport:I,translateExtent:z,minZoom:$,maxZoom:B,preventScrolling:R,onSelectionContextMenu:M,noWheelClassName:T,noPanClassName:_,disableKeyboardA11y:L,onViewportChange:O,isControlledViewport:j}){const{nodesSelectionActive:F,userSelectionActive:H}=$e(HU,je),D=Do(d,{target:Xf}),Q=Do(b,{target:Xf}),G=Q||A,ee=Q||N,se=f&&G!==!0,te=D||H||se;return NU({deleteKeyCode:c,multiSelectionKeyCode:g}),o(CU,{onPaneContextMenu:a,elementsSelectable:y,zoomOnScroll:w,zoomOnPinch:v,panOnScroll:ee,panOnScrollSpeed:k,panOnScrollMode:C,zoomOnDoubleClick:E,panOnDrag:!D&&G,defaultViewport:I,translateExtent:z,minZoom:$,maxZoom:B,zoomActivationKeyCode:x,preventScrolling:R,noWheelClassName:T,noPanClassName:_,onViewportChange:O,isControlledViewport:j,paneClickDistance:l,selectionOnDrag:se,children:u(AU,{onSelectionStart:h,onSelectionEnd:m,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:a,onPaneScroll:i,panOnDrag:G,isSelecting:!!te,selectionMode:p,selectionKeyPressed:D,paneClickDistance:l,selectionOnDrag:se,children:[e,F&&o(jU,{onSelectionContextMenu:M,noPanClassName:_,disableKeyboardA11y:L})]})})}N1.displayName="FlowRenderer";const VU=He(N1),qU=e=>t=>e?Vd(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 UU(e){return $e(U(qU(e),[e]),je)}const QU=e=>e.updateNodeInternals;function GU(){const e=$e(QU),[t]=P(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const r=new Map;n.forEach(s=>{const a=s.target.getAttribute("data-id");r.set(a,{id:a,nodeElement:s.target,force:!0})}),e(r)}));return Y(()=>()=>{t?.disconnect()},[t]),t}function KU({node:e,nodeType:t,hasDimensions:n,resizeObserver:r}){const s=Ve(),a=ne(null),i=ne(null),l=ne(e.sourcePosition),c=ne(e.targetPosition),d=ne(t),f=n&&!!e.internals.handleBounds;return Y(()=>{a.current&&!e.hidden&&(!f||i.current!==a.current)&&(i.current&&r?.unobserve(i.current),r?.observe(a.current),i.current=a.current)},[f,e.hidden]),Y(()=>()=>{i.current&&(r?.unobserve(i.current),i.current=null)},[]),Y(()=>{if(a.current){const p=d.current!==t,h=l.current!==e.sourcePosition,m=c.current!==e.targetPosition;(p||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 WU({id:e,onClick:t,onMouseEnter:n,onMouseMove:r,onMouseLeave:s,onContextMenu:a,onDoubleClick:i,nodesDraggable:l,elementsSelectable:c,nodesConnectable:d,nodesFocusable:f,resizeObserver:p,noDragClassName:h,noPanClassName:m,disableKeyboardA11y:g,rfId:b,nodeTypes:x,nodeClickDistance:y,onError:w}){const{node:v,internals:N,isParent:k}=$e(Z=>{const re=Z.nodeLookup.get(e),be=Z.parentLookup.has(e);return{node:re,internals:re.internals,isParent:be}},je);let C=v.type||"default",E=x?.[C]||Zf[C];E===void 0&&(w?.("003",Zt.error003(C)),C="default",E=x?.default||Zf.default);const A=!!(v.draggable||l&&typeof v.draggable>"u"),I=!!(v.selectable||c&&typeof v.selectable>"u"),z=!!(v.connectable||d&&typeof v.connectable>"u"),$=!!(v.focusable||f&&typeof v.focusable>"u"),B=Ve(),R=Vv(v),M=KU({node:v,nodeType:C,hasDimensions:R,resizeObserver:p}),T=y1({nodeRef:M,disabled:v.hidden||!A,noDragClassName:h,handleSelector:v.dragHandle,nodeId:e,isSelectable:I,nodeClickDistance:y}),_=v1();if(v.hidden)return null;const L=gn(v),O=zU(v),j=I||A||t||n||r||s,F=n?Z=>n(Z,{...N.userNode}):void 0,H=r?Z=>r(Z,{...N.userNode}):void 0,D=s?Z=>s(Z,{...N.userNode}):void 0,Q=a?Z=>a(Z,{...N.userNode}):void 0,G=i?Z=>i(Z,{...N.userNode}):void 0,ee=Z=>{const{selectNodesOnDrag:re,nodeDragThreshold:be}=B.getState();I&&(!re||!A||be>0)&&oc({id:e,store:B,nodeRef:M}),t&&t(Z,{...N.userNode})},se=Z=>{if(!(Qv(Z.nativeEvent)||g)){if(Tv.includes(Z.key)&&I){const re=Z.key==="Escape";oc({id:e,store:B,unselect:re,nodeRef:M})}else if(A&&v.selected&&Object.prototype.hasOwnProperty.call(fa,Z.key)){Z.preventDefault();const{ariaLabelConfig:re}=B.getState();B.setState({ariaLiveMessage:re["node.a11yDescription.ariaLiveMessage"]({direction:Z.key.replace("Arrow","").toLowerCase(),x:~~N.positionAbsolute.x,y:~~N.positionAbsolute.y})}),_({direction:fa[Z.key],factor:Z.shiftKey?4:1})}}},te=()=>{if(g||!M.current?.matches(":focus-visible"))return;const{transform:Z,width:re,height:be,autoPanOnNodeFocus:X,setCenter:K}=B.getState();if(!X)return;Vd(new Map([[e,v]]),{x:0,y:0,width:re,height:be},Z,!0).length>0||K(v.position.x+L.width/2,v.position.y+L.height/2,{zoom:Z[2]})};return o("div",{className:Qe(["react-flow__node",`react-flow__node-${C}`,{[m]:A},v.className,{selected:v.selected,selectable:I,parent:k,draggable:A,dragging:T}]),ref:M,style:{zIndex:N.z,transform:`translate(${N.positionAbsolute.x}px,${N.positionAbsolute.y}px)`,pointerEvents:j?"all":"none",visibility:R?"visible":"hidden",...v.style,...O},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:F,onMouseMove:H,onMouseLeave:D,onContextMenu:Q,onClick:ee,onDoubleClick:G,onKeyDown:$?se:void 0,tabIndex:$?0:void 0,onFocus:$?te:void 0,role:v.ariaRole??($?"group":void 0),"aria-roledescription":"node","aria-describedby":g?void 0:`${f1}-${b}`,"aria-label":v.ariaLabel,...v.domAttributes,children:o(_U,{value:e,children:o(E,{id:e,data:v.data,type:C,positionAbsoluteX:N.positionAbsolute.x,positionAbsoluteY:N.positionAbsolute.y,selected:v.selected??!1,selectable:I,draggable:A,deletable:v.deletable??!0,isConnectable:z,sourcePosition:v.sourcePosition,targetPosition:v.targetPosition,dragging:T,dragHandle:v.dragHandle,zIndex:N.z,parentId:v.parentId,...L})})})}var YU=He(WU);const ZU=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function k1(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,onError:a}=$e(ZU,je),i=UU(e.onlyRenderVisibleElements),l=GU();return o("div",{className:"react-flow__nodes",style:ri,children:i.map(c=>o(YU,{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:r,elementsSelectable:s,nodeClickDistance:e.nodeClickDistance,onError:a},c))})}k1.displayName="NodeRenderer";const XU=He(k1);function JU(e){return $e(U(n=>{if(!e)return n.edges.map(s=>s.id);const r=[];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&&QV({sourceNode:a,targetNode:i,width:n.width,height:n.height,transform:n.transform})&&r.push(s.id)}return r},[e]),je)}const eQ=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return o("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},tQ=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return o("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},Jf={[da.Arrow]:eQ,[da.ArrowClosed]:tQ};function nQ(e){const t=Ve();return q(()=>Object.prototype.hasOwnProperty.call(Jf,e)?Jf[e]:(t.getState().onError?.("009",Zt.error009(e)),null),[e])}const rQ=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:a="strokeWidth",strokeWidth:i,orient:l="auto-start-reverse"})=>{const c=nQ(t);return c?o("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:a,orient:l,refX:"0",refY:"0",children:o(c,{color:n,strokeWidth:i})}):null},S1=({defaultColor:e,rfId:t})=>{const n=$e(a=>a.edges),r=$e(a=>a.defaultEdgeOptions),s=q(()=>eq(n,{id:t,defaultColor:e,defaultMarkerStart:r?.markerStart,defaultMarkerEnd:r?.markerEnd}),[n,r,t,e]);return s.length?o("svg",{className:"react-flow__marker","aria-hidden":"true",children:o("defs",{children:s.map(a=>o(rQ,{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};S1.displayName="MarkerDefinitions";var oQ=He(S1);function C1({x:e,y:t,label:n,labelStyle:r,labelShowBg:s=!0,labelBgStyle:a,labelBgPadding:i=[2,4],labelBgBorderRadius:l=2,children:c,className:d,...f}){const[p,h]=P({x:1,y:0,width:0,height:0}),m=Qe(["react-flow__edge-textwrapper",d]),g=ne(null);return Y(()=>{if(g.current){const b=g.current.getBBox();h({x:b.x,y:b.y,width:b.width,height:b.height})}},[n]),n?u("g",{transform:`translate(${e-p.width/2} ${t-p.height/2})`,className:m,visibility:p.width?"visible":"hidden",...f,children:[s&&o("rect",{width:p.width+2*i[0],x:-i[0],y:-i[1],height:p.height+2*i[1],className:"react-flow__edge-textbg",style:a,rx:l,ry:l}),o("text",{className:"react-flow__edge-text",y:p.height/2,dy:"0.3em",ref:g,style:r,children:n}),c]}):null}C1.displayName="EdgeText";const sQ=He(C1);function oi({path:e,labelX:t,labelY:n,label:r,labelStyle:s,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c,interactionWidth:d=20,...f}){return u(me,{children:[o("path",{...f,d:e,fill:"none",className:Qe(["react-flow__edge-path",f.className])}),d?o("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:d,className:"react-flow__edge-interaction"}):null,r&&Dt(t)&&Dt(n)?o(sQ,{x:t,y:n,label:r,labelStyle:s,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c}):null]})}function eh({pos:e,x1:t,y1:n,x2:r,y2:s}){return e===we.Left||e===we.Right?[.5*(t+r),n]:[t,.5*(n+s)]}function M1({sourceX:e,sourceY:t,sourcePosition:n=we.Bottom,targetX:r,targetY:s,targetPosition:a=we.Top}){const[i,l]=eh({pos:n,x1:e,y1:t,x2:r,y2:s}),[c,d]=eh({pos:a,x1:r,y1:s,x2:e,y2:t}),[f,p,h,m]=Kv({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:i,sourceControlY:l,targetControlX:c,targetControlY:d});return[`M${e},${t} C${i},${l} ${c},${d} ${r},${s}`,f,p,h,m]}function E1(e){return He(({id:t,sourceX:n,sourceY:r,targetX:s,targetY:a,sourcePosition:i,targetPosition:l,label:c,labelStyle:d,labelShowBg:f,labelBgStyle:p,labelBgPadding:h,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:x,interactionWidth:y})=>{const[w,v,N]=M1({sourceX:n,sourceY:r,sourcePosition:i,targetX:s,targetY:a,targetPosition:l}),k=e.isInternal?void 0:t;return o(oi,{id:k,path:w,labelX:v,labelY:N,label:c,labelStyle:d,labelShowBg:f,labelBgStyle:p,labelBgPadding:h,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:x,interactionWidth:y})})}const aQ=E1({isInternal:!1}),I1=E1({isInternal:!0});aQ.displayName="SimpleBezierEdge";I1.displayName="SimpleBezierEdgeInternal";function A1(e){return He(({id:t,sourceX:n,sourceY:r,targetX:s,targetY:a,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:h,sourcePosition:m=we.Bottom,targetPosition:g=we.Top,markerEnd:b,markerStart:x,pathOptions:y,interactionWidth:w})=>{const[v,N,k]=Jl({sourceX:n,sourceY:r,sourcePosition:m,targetX:s,targetY:a,targetPosition:g,borderRadius:y?.borderRadius,offset:y?.offset,stepPosition:y?.stepPosition}),C=e.isInternal?void 0:t;return o(oi,{id:C,path:v,labelX:N,labelY:k,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:h,markerEnd:b,markerStart:x,interactionWidth:w})})}const P1=A1({isInternal:!1}),_1=A1({isInternal:!0});P1.displayName="SmoothStepEdge";_1.displayName="SmoothStepEdgeInternal";function $1(e){return He(({id:t,...n})=>{const r=e.isInternal?void 0:t;return o(P1,{...n,id:r,pathOptions:q(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}const iQ=$1({isInternal:!1}),D1=$1({isInternal:!0});iQ.displayName="StepEdge";D1.displayName="StepEdgeInternal";function T1(e){return He(({id:t,sourceX:n,sourceY:r,targetX:s,targetY:a,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:h,markerEnd:m,markerStart:g,interactionWidth:b})=>{const[x,y,w]=Zv({sourceX:n,sourceY:r,targetX:s,targetY:a}),v=e.isInternal?void 0:t;return o(oi,{id:v,path:x,labelX:y,labelY:w,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:h,markerEnd:m,markerStart:g,interactionWidth:b})})}const lQ=T1({isInternal:!1}),L1=T1({isInternal:!0});lQ.displayName="StraightEdge";L1.displayName="StraightEdgeInternal";function R1(e){return He(({id:t,sourceX:n,sourceY:r,targetX:s,targetY:a,sourcePosition:i=we.Bottom,targetPosition:l=we.Top,label:c,labelStyle:d,labelShowBg:f,labelBgStyle:p,labelBgPadding:h,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:x,pathOptions:y,interactionWidth:w})=>{const[v,N,k]=Wv({sourceX:n,sourceY:r,sourcePosition:i,targetX:s,targetY:a,targetPosition:l,curvature:y?.curvature}),C=e.isInternal?void 0:t;return o(oi,{id:C,path:v,labelX:N,labelY:k,label:c,labelStyle:d,labelShowBg:f,labelBgStyle:p,labelBgPadding:h,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:x,interactionWidth:w})})}const cQ=R1({isInternal:!1}),O1=R1({isInternal:!0});cQ.displayName="BezierEdge";O1.displayName="BezierEdgeInternal";const th={default:O1,straight:L1,step:D1,smoothstep:_1,simplebezier:I1},nh={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},dQ=(e,t,n)=>n===we.Left?e-t:n===we.Right?e+t:e,uQ=(e,t,n)=>n===we.Top?e-t:n===we.Bottom?e+t:e,rh="react-flow__edgeupdater";function oh({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:a,onMouseOut:i,type:l}){return o("circle",{onMouseDown:s,onMouseEnter:a,onMouseOut:i,className:Qe([rh,`${rh}-${l}`]),cx:dQ(t,r,e),cy:uQ(n,r,e),r,stroke:"transparent",fill:"transparent"})}function pQ({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:r,sourceY:s,targetX:a,targetY:i,sourcePosition:l,targetPosition:c,onReconnect:d,onReconnectStart:f,onReconnectEnd:p,setReconnecting:h,setUpdateHover:m}){const g=Ve(),b=(N,k)=>{if(N.button!==0)return;const{autoPanOnConnect:C,domNode:E,connectionMode:A,connectionRadius:I,lib:z,onConnectStart:$,cancelConnection:B,nodeLookup:R,rfId:M,panBy:T,updateConnection:_}=g.getState(),L=k.type==="target",O=(H,D)=>{h(!1),p?.(H,n,k.type,D)},j=H=>d?.(n,H),F=(H,D)=>{h(!0),f?.(N,n,k.type),$?.(H,D)};nc.onPointerDown(N.nativeEvent,{autoPanOnConnect:C,connectionMode:A,connectionRadius:I,domNode:E,handleId:k.id,nodeId:k.nodeId,nodeLookup:R,isTarget:L,edgeUpdaterType:k.type,lib:z,flowId:M,cancelConnection:B,panBy:T,isValidConnection:(...H)=>g.getState().isValidConnection?.(...H)??!0,onConnect:j,onConnectStart:F,onConnectEnd:(...H)=>g.getState().onConnectEnd?.(...H),onReconnectEnd:O,updateConnection:_,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 u(me,{children:[(e===!0||e==="source")&&o(oh,{position:l,centerX:r,centerY:s,radius:t,onMouseDown:x,onMouseEnter:w,onMouseOut:v,type:"source"}),(e===!0||e==="target")&&o(oh,{position:c,centerX:a,centerY:i,radius:t,onMouseDown:y,onMouseEnter:w,onMouseOut:v,type:"target"})]})}function fQ({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:r,onClick:s,onDoubleClick:a,onContextMenu:i,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,reconnectRadius:f,onReconnect:p,onReconnectStart:h,onReconnectEnd:m,rfId:g,edgeTypes:b,noPanClassName:x,onError:y,disableKeyboardA11y:w}){let v=$e(K=>K.edgeLookup.get(e));const N=$e(K=>K.defaultEdgeOptions);v=N?{...N,...v}:v;let k=v.type||"default",C=b?.[k]||th[k];C===void 0&&(y?.("011",Zt.error011(k)),k="default",C=b?.default||th.default);const E=!!(v.focusable||t&&typeof v.focusable>"u"),A=typeof p<"u"&&(v.reconnectable||n&&typeof v.reconnectable>"u"),I=!!(v.selectable||r&&typeof v.selectable>"u"),z=ne(null),[$,B]=P(!1),[R,M]=P(!1),T=Ve(),{zIndex:_,sourceX:L,sourceY:O,targetX:j,targetY:F,sourcePosition:H,targetPosition:D}=$e(U(K=>{const J=K.nodeLookup.get(v.source),ae=K.nodeLookup.get(v.target);if(!J||!ae)return{zIndex:v.zIndex,...nh};const fe=JV({id:e,sourceNode:J,targetNode:ae,sourceHandle:v.sourceHandle||null,targetHandle:v.targetHandle||null,connectionMode:K.connectionMode,onError:y});return{zIndex:UV({selected:v.selected,zIndex:v.zIndex,sourceNode:J,targetNode:ae,elevateOnSelect:K.elevateEdgesOnSelect,zIndexMode:K.zIndexMode}),...fe||nh}},[v.source,v.target,v.sourceHandle,v.targetHandle,v.selected,v.zIndex]),je),Q=q(()=>v.markerStart?`url('#${ec(v.markerStart,g)}')`:void 0,[v.markerStart,g]),G=q(()=>v.markerEnd?`url('#${ec(v.markerEnd,g)}')`:void 0,[v.markerEnd,g]);if(v.hidden||L===null||O===null||j===null||F===null)return null;const ee=K=>{const{addSelectedEdges:J,unselectNodesAndEdges:ae,multiSelectionActive:fe}=T.getState();I&&(T.setState({nodesSelectionActive:!1}),v.selected&&fe?(ae({nodes:[],edges:[v]}),z.current?.blur()):J([e])),s&&s(K,v)},se=a?K=>{a(K,{...v})}:void 0,te=i?K=>{i(K,{...v})}:void 0,Z=l?K=>{l(K,{...v})}:void 0,re=c?K=>{c(K,{...v})}:void 0,be=d?K=>{d(K,{...v})}:void 0,X=K=>{if(!w&&Tv.includes(K.key)&&I){const{unselectNodesAndEdges:J,addSelectedEdges:ae}=T.getState();K.key==="Escape"?(z.current?.blur(),J({edges:[v]})):ae([e])}};return o("svg",{style:{zIndex:_},children:u("g",{className:Qe(["react-flow__edge",`react-flow__edge-${k}`,v.className,x,{selected:v.selected,animated:v.animated,inactive:!I&&!s,updating:$,selectable:I}]),onClick:ee,onDoubleClick:se,onContextMenu:te,onMouseEnter:Z,onMouseMove:re,onMouseLeave:be,onKeyDown:E?X:void 0,tabIndex:E?0:void 0,role:v.ariaRole??(E?"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":E?`${h1}-${g}`:void 0,ref:z,...v.domAttributes,children:[!R&&o(C,{id:e,source:v.source,target:v.target,type:v.type,selected:v.selected,animated:v.animated,selectable:I,deletable:v.deletable??!0,label:v.label,labelStyle:v.labelStyle,labelShowBg:v.labelShowBg,labelBgStyle:v.labelBgStyle,labelBgPadding:v.labelBgPadding,labelBgBorderRadius:v.labelBgBorderRadius,sourceX:L,sourceY:O,targetX:j,targetY:F,sourcePosition:H,targetPosition:D,data:v.data,style:v.style,sourceHandleId:v.sourceHandle,targetHandleId:v.targetHandle,markerStart:Q,markerEnd:G,pathOptions:"pathOptions"in v?v.pathOptions:void 0,interactionWidth:v.interactionWidth}),A&&o(pQ,{edge:v,isReconnectable:A,reconnectRadius:f,onReconnect:p,onReconnectStart:h,onReconnectEnd:m,sourceX:L,sourceY:O,targetX:j,targetY:F,sourcePosition:H,targetPosition:D,setUpdateHover:B,setReconnecting:M})]})})}var hQ=He(fQ);const mQ=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function B1({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:r,noPanClassName:s,onReconnect:a,onEdgeContextMenu:i,onEdgeMouseEnter:l,onEdgeMouseMove:c,onEdgeMouseLeave:d,onEdgeClick:f,reconnectRadius:p,onEdgeDoubleClick:h,onReconnectStart:m,onReconnectEnd:g,disableKeyboardA11y:b}){const{edgesFocusable:x,edgesReconnectable:y,elementsSelectable:w,onError:v}=$e(mQ,je),N=JU(t);return u("div",{className:"react-flow__edges",children:[o(oQ,{defaultColor:e,rfId:n}),N.map(k=>o(hQ,{id:k,edgesFocusable:x,edgesReconnectable:y,elementsSelectable:w,noPanClassName:s,onReconnect:a,onContextMenu:i,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,onClick:f,reconnectRadius:p,onDoubleClick:h,onReconnectStart:m,onReconnectEnd:g,rfId:n,onError:v,edgeTypes:r,disableKeyboardA11y:b},k))]})}B1.displayName="EdgeRenderer";const gQ=He(B1),bQ=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function xQ({children:e}){const t=$e(bQ);return o("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function yQ(e){const t=Zd(),n=ne(!1);Y(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const vQ=e=>e.panZoom?.syncViewport;function wQ(e){const t=$e(vQ),n=Ve();return Y(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function NQ(e){return e.connection.inProgress?{...e.connection,to:es(e.connection.to,e.transform)}:{...e.connection}}function kQ(e){return NQ}function SQ(e){const t=kQ();return $e(t,je)}const CQ=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function MQ({containerStyle:e,style:t,type:n,component:r}){const{nodesConnectable:s,width:a,height:i,isValid:l,inProgress:c}=$e(CQ,je);return!(a&&s&&c)?null:o("svg",{style:e,width:a,height:i,className:"react-flow__connectionline react-flow__container",children:o("g",{className:Qe(["react-flow__connection",Ov(l)]),children:o(z1,{style:t,type:n,CustomComponent:r,isValid:l})})})}const z1=({style:e,type:t=wn.Bezier,CustomComponent:n,isValid:r})=>{const{inProgress:s,from:a,fromNode:i,fromHandle:l,fromPosition:c,to:d,toNode:f,toHandle:p,toPosition:h,pointer:m}=SQ();if(!s)return;if(n)return o(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:Ov(r),toNode:f,toHandle:p,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 wn.Bezier:[g]=Wv(b);break;case wn.SimpleBezier:[g]=M1(b);break;case wn.Step:[g]=Jl({...b,borderRadius:0});break;case wn.SmoothStep:[g]=Jl(b);break;default:[g]=Zv(b)}return o("path",{d:g,fill:"none",className:"react-flow__connection-path",style:e})};z1.displayName="ConnectionLine";const EQ={};function sh(e=EQ){ne(e),Ve(),Y(()=>{},[e])}function IQ(){Ve(),ne(!1),Y(()=>{},[])}function F1({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:r,onEdgeClick:s,onNodeDoubleClick:a,onEdgeDoubleClick:i,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:f,onSelectionContextMenu:p,onSelectionStart:h,onSelectionEnd:m,connectionLineType:g,connectionLineStyle:b,connectionLineComponent:x,connectionLineContainerStyle:y,selectionKeyCode:w,selectionOnDrag:v,selectionMode:N,multiSelectionKeyCode:k,panActivationKeyCode:C,zoomActivationKeyCode:E,deleteKeyCode:A,onlyRenderVisibleElements:I,elementsSelectable:z,defaultViewport:$,translateExtent:B,minZoom:R,maxZoom:M,preventScrolling:T,defaultMarkerColor:_,zoomOnScroll:L,zoomOnPinch:O,panOnScroll:j,panOnScrollSpeed:F,panOnScrollMode:H,zoomOnDoubleClick:D,panOnDrag:Q,onPaneClick:G,onPaneMouseEnter:ee,onPaneMouseMove:se,onPaneMouseLeave:te,onPaneScroll:Z,onPaneContextMenu:re,paneClickDistance:be,nodeClickDistance:X,onEdgeContextMenu:K,onEdgeMouseEnter:J,onEdgeMouseMove:ae,onEdgeMouseLeave:fe,reconnectRadius:ge,onReconnect:V,onReconnectStart:ie,onReconnectEnd:ue,noDragClassName:de,noWheelClassName:ce,noPanClassName:Se,disableKeyboardA11y:pe,nodeExtent:_e,rfId:Ae,viewport:We,onViewportChange:st}){return sh(e),sh(t),IQ(),yQ(n),wQ(We),o(VU,{onPaneClick:G,onPaneMouseEnter:ee,onPaneMouseMove:se,onPaneMouseLeave:te,onPaneContextMenu:re,onPaneScroll:Z,paneClickDistance:be,deleteKeyCode:A,selectionKeyCode:w,selectionOnDrag:v,selectionMode:N,onSelectionStart:h,onSelectionEnd:m,multiSelectionKeyCode:k,panActivationKeyCode:C,zoomActivationKeyCode:E,elementsSelectable:z,zoomOnScroll:L,zoomOnPinch:O,zoomOnDoubleClick:D,panOnScroll:j,panOnScrollSpeed:F,panOnScrollMode:H,panOnDrag:Q,defaultViewport:$,translateExtent:B,minZoom:R,maxZoom:M,onSelectionContextMenu:p,preventScrolling:T,noDragClassName:de,noWheelClassName:ce,noPanClassName:Se,disableKeyboardA11y:pe,onViewportChange:st,isControlledViewport:!!We,children:u(xQ,{children:[o(gQ,{edgeTypes:t,onEdgeClick:s,onEdgeDoubleClick:i,onReconnect:V,onReconnectStart:ie,onReconnectEnd:ue,onlyRenderVisibleElements:I,onEdgeContextMenu:K,onEdgeMouseEnter:J,onEdgeMouseMove:ae,onEdgeMouseLeave:fe,reconnectRadius:ge,defaultMarkerColor:_,noPanClassName:Se,disableKeyboardA11y:pe,rfId:Ae}),o(MQ,{style:b,type:g,component:x,containerStyle:y}),o("div",{className:"react-flow__edgelabel-renderer"}),o(XU,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:f,nodeClickDistance:X,onlyRenderVisibleElements:I,noPanClassName:Se,noDragClassName:de,disableKeyboardA11y:pe,nodeExtent:_e,rfId:Ae}),o("div",{className:"react-flow__viewport-portal"})]})})}F1.displayName="GraphView";const AQ=He(F1),ah=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:s,height:a,fitView:i,fitViewOptions:l,minZoom:c=.5,maxZoom:d=2,nodeOrigin:f,nodeExtent:p,zIndexMode:h="basic"}={})=>{const m=new Map,g=new Map,b=new Map,x=new Map,y=r??t??[],w=n??e??[],v=f??[0,0],N=p??Ao;e1(b,x,y);const{nodesInitialized:k}=tc(w,m,g,{nodeOrigin:v,nodeExtent:N,zIndexMode:h});let C=[0,0,1];if(i&&s&&a){const E=Xo(m,{filter:$=>!!(($.width||$.initialWidth)&&($.height||$.initialHeight))}),{x:A,y:I,zoom:z}=qd(E,s,a,c,d,l?.padding??.1);C=[A,I,z]}return{rfId:"1",width:s??0,height:a??0,transform:C,nodes:w,nodesInitialized:k,nodeLookup:m,parentLookup:g,edges:y,edgeLookup:x,connectionLookup:b,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:c,maxZoom:d,translateExtent:Ao,nodeExtent:N,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:_r.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:{...Rv},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:zV,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:Lv,zIndexMode:h,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},PQ=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:s,height:a,fitView:i,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:f,nodeExtent:p,zIndexMode:h})=>Gq((m,g)=>{async function b(){const{nodeLookup:x,panZoom:y,fitViewOptions:w,fitViewResolver:v,width:N,height:k,minZoom:C,maxZoom:E}=g();y&&(await OV({nodes:x,width:N,height:k,panZoom:y,minZoom:C,maxZoom:E},w),v?.resolve(!0),m({fitViewResolver:null}))}return{...ah({nodes:e,edges:t,width:s,height:a,fitView:i,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:f,nodeExtent:p,defaultNodes:n,defaultEdges:r,zIndexMode:h}),setNodes:x=>{const{nodeLookup:y,parentLookup:w,nodeOrigin:v,elevateNodesOnSelect:N,fitViewQueued:k,zIndexMode:C,nodesSelectionActive:E}=g(),{nodesInitialized:A,hasSelectedNodes:I}=tc(x,y,w,{nodeOrigin:v,nodeExtent:p,elevateNodesOnSelect:N,checkEquality:!0,zIndexMode:C}),z=E&&I;k&&A?(b(),m({nodes:x,nodesInitialized:A,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:z})):m({nodes:x,nodesInitialized:A,nodesSelectionActive:z})},setEdges:x=>{const{connectionLookup:y,edgeLookup:w}=g();e1(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:k,nodeExtent:C,debug:E,fitViewQueued:A,zIndexMode:I}=g(),{changes:z,updatedInternals:$}=iq(x,w,v,N,k,C,I);$&&(rq(w,v,{nodeOrigin:k,nodeExtent:C,zIndexMode:I}),A?(b(),m({fitViewQueued:!1,fitViewOptions:void 0})):m({}),z?.length>0&&(E&&console.log("React Flow: trigger node changes",z),y?.(z)))},updateNodePositions:(x,y=!1)=>{const w=[];let v=[];const{nodeLookup:N,triggerNodeChanges:k,connection:C,updateConnection:E,onNodesChangeMiddlewareMap:A}=g();for(const[I,z]of x){const $=N.get(I),B=!!($?.expandParent&&$?.parentId&&z?.position),R={id:I,type:"position",position:B?{x:Math.max(0,z.position.x),y:Math.max(0,z.position.y)}:z.position,dragging:y};if($&&C.inProgress&&C.fromNode.id===$.id){const M=er($,C.fromHandle,we.Left,!0);E({...C,from:M})}B&&$.parentId&&w.push({id:I,parentId:$.parentId,rect:{...z.internals.positionAbsolute,width:z.measured.width??0,height:z.measured.height??0}}),v.push(R)}if(w.length>0){const{parentLookup:I,nodeOrigin:z}=g(),$=Yd(w,N,I,z);v.push(...$)}for(const I of A.values())v=I(v);k(v)},triggerNodeChanges:x=>{const{onNodesChange:y,setNodes:w,nodes:v,hasDefaultNodes:N,debug:k}=g();if(x?.length){if(N){const C=hU(x,v);w(C)}k&&console.log("React Flow: trigger node changes",x),y?.(x)}},triggerEdgeChanges:x=>{const{onEdgesChange:y,setEdges:w,edges:v,hasDefaultEdges:N,debug:k}=g();if(x?.length){if(N){const C=mU(x,v);w(C)}k&&console.log("React Flow: trigger edge changes",x),y?.(x)}},addSelectedNodes:x=>{const{multiSelectionActive:y,edgeLookup:w,nodeLookup:v,triggerNodeChanges:N,triggerEdgeChanges:k}=g();if(y){const C=x.map(E=>Fn(E,!0));N(C);return}N(br(v,new Set([...x]),!0)),k(br(w))},addSelectedEdges:x=>{const{multiSelectionActive:y,edgeLookup:w,nodeLookup:v,triggerNodeChanges:N,triggerEdgeChanges:k}=g();if(y){const C=x.map(E=>Fn(E,!0));k(C);return}k(br(w,new Set([...x]))),N(br(v,new Set,!0))},unselectNodesAndEdges:({nodes:x,edges:y}={})=>{const{edges:w,nodes:v,nodeLookup:N,triggerNodeChanges:k,triggerEdgeChanges:C}=g(),E=x||v,A=y||w,I=[];for(const $ of E){if(!$.selected)continue;const B=N.get($.id);B&&(B.selected=!1),I.push(Fn($.id,!1))}const z=[];for(const $ of A)$.selected&&z.push(Fn($.id,!1));k(I),C(z)},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 k=y.reduce((E,A)=>A.selected?[...E,Fn(A.id,!1)]:E,[]),C=x.reduce((E,A)=>A.selected?[...E,Fn(A.id,!1)]:E,[]);w(k),v(C)},setNodeExtent:x=>{const{nodes:y,nodeLookup:w,parentLookup:v,nodeOrigin:N,elevateNodesOnSelect:k,nodeExtent:C,zIndexMode:E}=g();x[0][0]===C[0][0]&&x[0][1]===C[0][1]&&x[1][0]===C[1][0]&&x[1][1]===C[1][1]||(tc(y,w,v,{nodeOrigin:N,nodeExtent:x,elevateNodesOnSelect:k,checkEquality:!1,zIndexMode:E}),m({nodeExtent:x}))},panBy:x=>{const{transform:y,width:w,height:v,panZoom:N,translateExtent:k}=g();return lq({delta:x,panZoom:N,transform:y,translateExtent:k,width:w,height:v})},setCenter:async(x,y,w)=>{const{width:v,height:N,maxZoom:k,panZoom:C}=g();if(!C)return Promise.resolve(!1);const E=typeof w?.zoom<"u"?w.zoom:k;return await C.setViewport({x:v/2-x*E,y:N/2-y*E,zoom:E},{duration:w?.duration,ease:w?.ease,interpolate:w?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{m({connection:{...Rv}})},updateConnection:x=>{m({connection:x})},reset:()=>m({...ah()})}},Object.is);function _Q({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:r,initialWidth:s,initialHeight:a,initialMinZoom:i,initialMaxZoom:l,initialFitViewOptions:c,fitView:d,nodeOrigin:f,nodeExtent:p,zIndexMode:h,children:m}){const[g]=P(()=>PQ({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:s,height:a,fitView:d,minZoom:i,maxZoom:l,fitViewOptions:c,nodeOrigin:f,nodeExtent:p,zIndexMode:h}));return o(Kq,{value:g,children:o(xU,{children:m})})}function $Q({children:e,nodes:t,edges:n,defaultNodes:r,defaultEdges:s,width:a,height:i,fitView:l,fitViewOptions:c,minZoom:d,maxZoom:f,nodeOrigin:p,nodeExtent:h,zIndexMode:m}){return ve(ti)?o(me,{children:e}):o(_Q,{initialNodes:t,initialEdges:n,defaultNodes:r,defaultEdges:s,initialWidth:a,initialHeight:i,fitView:l,initialFitViewOptions:c,initialMinZoom:d,initialMaxZoom:f,nodeOrigin:p,nodeExtent:h,zIndexMode:m,children:e})}const DQ={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function TQ({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:a,edgeTypes:i,onNodeClick:l,onEdgeClick:c,onInit:d,onMove:f,onMoveStart:p,onMoveEnd:h,onConnect:m,onConnectStart:g,onConnectEnd:b,onClickConnectStart:x,onClickConnectEnd:y,onNodeMouseEnter:w,onNodeMouseMove:v,onNodeMouseLeave:N,onNodeContextMenu:k,onNodeDoubleClick:C,onNodeDragStart:E,onNodeDrag:A,onNodeDragStop:I,onNodesDelete:z,onEdgesDelete:$,onDelete:B,onSelectionChange:R,onSelectionDragStart:M,onSelectionDrag:T,onSelectionDragStop:_,onSelectionContextMenu:L,onSelectionStart:O,onSelectionEnd:j,onBeforeDelete:F,connectionMode:H,connectionLineType:D=wn.Bezier,connectionLineStyle:Q,connectionLineComponent:G,connectionLineContainerStyle:ee,deleteKeyCode:se="Backspace",selectionKeyCode:te="Shift",selectionOnDrag:Z=!1,selectionMode:re=Po.Full,panActivationKeyCode:be="Space",multiSelectionKeyCode:X=$o()?"Meta":"Control",zoomActivationKeyCode:K=$o()?"Meta":"Control",snapToGrid:J,snapGrid:ae,onlyRenderVisibleElements:fe=!1,selectNodesOnDrag:ge,nodesDraggable:V,autoPanOnNodeFocus:ie,nodesConnectable:ue,nodesFocusable:de,nodeOrigin:ce=m1,edgesFocusable:Se,edgesReconnectable:pe,elementsSelectable:_e=!0,defaultViewport:Ae=iU,minZoom:We=.5,maxZoom:st=2,translateExtent:ur=Ao,preventScrolling:he=!0,nodeExtent:Pe,defaultMarkerColor:Te="#b1b1b7",zoomOnScroll:Re=!0,zoomOnPinch:Tn=!0,panOnScroll:Ln=!1,panOnScrollSpeed:Kr=.5,panOnScrollMode:bw=Un.Free,zoomOnDoubleClick:xw=!0,panOnDrag:yw=!0,onPaneClick:vw,onPaneMouseEnter:ww,onPaneMouseMove:Nw,onPaneMouseLeave:kw,onPaneScroll:Sw,onPaneContextMenu:Cw,paneClickDistance:Mw=1,nodeClickDistance:Ew=0,children:Iw,onReconnect:Aw,onReconnectStart:Pw,onReconnectEnd:_w,onEdgeContextMenu:$w,onEdgeDoubleClick:Dw,onEdgeMouseEnter:Tw,onEdgeMouseMove:Lw,onEdgeMouseLeave:Rw,reconnectRadius:Ow=10,onNodesChange:Bw,onEdgesChange:zw,noDragClassName:Fw="nodrag",noWheelClassName:jw="nowheel",noPanClassName:ou="nopan",fitView:su,fitViewOptions:au,connectOnClick:Hw,attributionPosition:Vw,proOptions:qw,defaultEdgeOptions:Uw,elevateNodesOnSelect:Qw=!0,elevateEdgesOnSelect:Gw=!1,disableKeyboardA11y:iu=!1,autoPanOnConnect:Kw,autoPanOnNodeDrag:Ww,autoPanSpeed:Yw,connectionRadius:Zw,isValidConnection:Xw,onError:Jw,style:eN,id:lu,nodeDragThreshold:tN,connectionDragThreshold:nN,viewport:rN,onViewportChange:oN,width:sN,height:aN,colorMode:iN="light",debug:lN,onScroll:cu,ariaLabelConfig:cN,zIndexMode:du="basic",...dN},uN){const ii=lu||"1",pN=uU(iN),fN=U(uu=>{uu.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),cu?.(uu)},[cu]);return o("div",{"data-testid":"rf__wrapper",...dN,onScroll:fN,style:{...eN,...DQ},ref:uN,className:Qe(["react-flow",s,pN]),id:lu,role:"application",children:u($Q,{nodes:e,edges:t,width:sN,height:aN,fitView:su,fitViewOptions:au,minZoom:We,maxZoom:st,nodeOrigin:ce,nodeExtent:Pe,zIndexMode:du,children:[o(dU,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:m,onConnectStart:g,onConnectEnd:b,onClickConnectStart:x,onClickConnectEnd:y,nodesDraggable:V,autoPanOnNodeFocus:ie,nodesConnectable:ue,nodesFocusable:de,edgesFocusable:Se,edgesReconnectable:pe,elementsSelectable:_e,elevateNodesOnSelect:Qw,elevateEdgesOnSelect:Gw,minZoom:We,maxZoom:st,nodeExtent:Pe,onNodesChange:Bw,onEdgesChange:zw,snapToGrid:J,snapGrid:ae,connectionMode:H,translateExtent:ur,connectOnClick:Hw,defaultEdgeOptions:Uw,fitView:su,fitViewOptions:au,onNodesDelete:z,onEdgesDelete:$,onDelete:B,onNodeDragStart:E,onNodeDrag:A,onNodeDragStop:I,onSelectionDrag:T,onSelectionDragStart:M,onSelectionDragStop:_,onMove:f,onMoveStart:p,onMoveEnd:h,noPanClassName:ou,nodeOrigin:ce,rfId:ii,autoPanOnConnect:Kw,autoPanOnNodeDrag:Ww,autoPanSpeed:Yw,onError:Jw,connectionRadius:Zw,isValidConnection:Xw,selectNodesOnDrag:ge,nodeDragThreshold:tN,connectionDragThreshold:nN,onBeforeDelete:F,debug:lN,ariaLabelConfig:cN,zIndexMode:du}),o(AQ,{onInit:d,onNodeClick:l,onEdgeClick:c,onNodeMouseEnter:w,onNodeMouseMove:v,onNodeMouseLeave:N,onNodeContextMenu:k,onNodeDoubleClick:C,nodeTypes:a,edgeTypes:i,connectionLineType:D,connectionLineStyle:Q,connectionLineComponent:G,connectionLineContainerStyle:ee,selectionKeyCode:te,selectionOnDrag:Z,selectionMode:re,deleteKeyCode:se,multiSelectionKeyCode:X,panActivationKeyCode:be,zoomActivationKeyCode:K,onlyRenderVisibleElements:fe,defaultViewport:Ae,translateExtent:ur,minZoom:We,maxZoom:st,preventScrolling:he,zoomOnScroll:Re,zoomOnPinch:Tn,zoomOnDoubleClick:xw,panOnScroll:Ln,panOnScrollSpeed:Kr,panOnScrollMode:bw,panOnDrag:yw,onPaneClick:vw,onPaneMouseEnter:ww,onPaneMouseMove:Nw,onPaneMouseLeave:kw,onPaneScroll:Sw,onPaneContextMenu:Cw,paneClickDistance:Mw,nodeClickDistance:Ew,onSelectionContextMenu:L,onSelectionStart:O,onSelectionEnd:j,onReconnect:Aw,onReconnectStart:Pw,onReconnectEnd:_w,onEdgeContextMenu:$w,onEdgeDoubleClick:Dw,onEdgeMouseEnter:Tw,onEdgeMouseMove:Lw,onEdgeMouseLeave:Rw,reconnectRadius:Ow,defaultMarkerColor:Te,noDragClassName:Fw,noWheelClassName:jw,noPanClassName:ou,rfId:ii,disableKeyboardA11y:iu,nodeExtent:Pe,viewport:rN,onViewportChange:oN}),o(aU,{onSelectionChange:R}),Iw,o(tU,{proOptions:qw,position:Vw}),o(eU,{rfId:ii,disableKeyboardA11y:iu})]})})}var LQ=b1(TQ);function RQ({dimensions:e,lineWidth:t,variant:n,className:r}){return o("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Qe(["react-flow__background-pattern",n,r])})}function OQ({radius:e,className:t}){return o("circle",{cx:e,cy:e,r:e,className:Qe(["react-flow__background-pattern","dots",t])})}var Sn;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Sn||(Sn={}));const BQ={[Sn.Dots]:1,[Sn.Lines]:1,[Sn.Cross]:6},zQ=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function j1({id:e,variant:t=Sn.Dots,gap:n=20,size:r,lineWidth:s=1,offset:a=0,color:i,bgColor:l,style:c,className:d,patternClassName:f}){const p=ne(null),{transform:h,patternId:m}=$e(zQ,je),g=r||BQ[t],b=t===Sn.Dots,x=t===Sn.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],k=x?[v,v]:w,C=[N[0]*h[2]||1+k[0]/2,N[1]*h[2]||1+k[1]/2],E=`${m}${e||""}`;return u("svg",{className:Qe(["react-flow__background",d]),style:{...c,...ri,"--xy-background-color-props":l,"--xy-background-pattern-color-props":i},ref:p,"data-testid":"rf__background",children:[o("pattern",{id:E,x:h[0]%w[0],y:h[1]%w[1],width:w[0],height:w[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${C[0]},-${C[1]})`,children:b?o(OQ,{radius:v/2,className:f}):o(RQ,{dimensions:k,lineWidth:s,variant:t,className:f})}),o("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${E})`})]})}j1.displayName="Background";const FQ=He(j1);function jQ(){return o("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:o("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function HQ(){return o("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:o("path",{d:"M0 0h32v4.2H0z"})})}function VQ(){return o("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:o("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 qQ(){return o("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:o("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 UQ(){return o("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:o("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 Ps({children:e,className:t,...n}){return o("button",{type:"button",className:Qe(["react-flow__controls-button",t]),...n,children:e})}const QQ=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function H1({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:a,onZoomOut:i,onFitView:l,onInteractiveChange:c,className:d,children:f,position:p="bottom-left",orientation:h="vertical","aria-label":m}){const g=Ve(),{isInteractive:b,minZoomReached:x,maxZoomReached:y,ariaLabelConfig:w}=$e(QQ,je),{zoomIn:v,zoomOut:N,fitView:k}=Zd(),C=()=>{v(),a?.()},E=()=>{N(),i?.()},A=()=>{k(s),l?.()},I=()=>{g.setState({nodesDraggable:!b,nodesConnectable:!b,elementsSelectable:!b}),c?.(!b)};return u(ni,{className:Qe(["react-flow__controls",h==="horizontal"?"horizontal":"vertical",d]),position:p,style:e,"data-testid":"rf__controls","aria-label":m??w["controls.ariaLabel"],children:[t&&u(me,{children:[o(Ps,{onClick:C,className:"react-flow__controls-zoomin",title:w["controls.zoomIn.ariaLabel"],"aria-label":w["controls.zoomIn.ariaLabel"],disabled:y,children:o(jQ,{})}),o(Ps,{onClick:E,className:"react-flow__controls-zoomout",title:w["controls.zoomOut.ariaLabel"],"aria-label":w["controls.zoomOut.ariaLabel"],disabled:x,children:o(HQ,{})})]}),n&&o(Ps,{className:"react-flow__controls-fitview",onClick:A,title:w["controls.fitView.ariaLabel"],"aria-label":w["controls.fitView.ariaLabel"],children:o(VQ,{})}),r&&o(Ps,{className:"react-flow__controls-interactive",onClick:I,title:w["controls.interactive.ariaLabel"],"aria-label":w["controls.interactive.ariaLabel"],children:b?o(UQ,{}):o(qQ,{})}),f]})}H1.displayName="Controls";const GQ=He(H1);function KQ({id:e,x:t,y:n,width:r,height:s,style:a,color:i,strokeColor:l,strokeWidth:c,className:d,borderRadius:f,shapeRendering:p,selected:h,onClick:m}){const{background:g,backgroundColor:b}=a||{},x=i||g||b;return o("rect",{className:Qe(["react-flow__minimap-node",{selected:h},d]),x:t,y:n,rx:f,ry:f,width:r,height:s,style:{fill:x,stroke:l,strokeWidth:c},shapeRendering:p,onClick:m?y=>m(y,e):void 0})}const WQ=He(KQ),YQ=e=>e.nodes.map(t=>t.id),nl=e=>e instanceof Function?e:()=>e;function ZQ({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s,nodeComponent:a=WQ,onClick:i}){const l=$e(YQ,je),c=nl(t),d=nl(e),f=nl(n),p=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return o(me,{children:l.map(h=>o(JQ,{id:h,nodeColorFunc:c,nodeStrokeColorFunc:d,nodeClassNameFunc:f,nodeBorderRadius:r,nodeStrokeWidth:s,NodeComponent:a,onClick:i,shapeRendering:p},h))})}function XQ({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:r,nodeBorderRadius:s,nodeStrokeWidth:a,shapeRendering:i,NodeComponent:l,onClick:c}){const{node:d,x:f,y:p,width:h,height:m}=$e(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}=gn(x);return{node:x,x:y,y:w,width:v,height:N}},je);return!d||d.hidden||!Vv(d)?null:o(l,{x:f,y:p,width:h,height:m,style:d.style,selected:!!d.selected,className:r(d),color:t(d),borderRadius:s,strokeColor:n(d),strokeWidth:a,shapeRendering:i,onClick:c,id:d.id})}const JQ=He(XQ);var eG=He(ZQ);const tG=200,nG=150,rG=e=>!e.hidden,oG=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?Hv(Xo(e.nodeLookup,{filter:rG}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},sG="react-flow__minimap-desc";function V1({style:e,className:t,nodeStrokeColor:n,nodeColor:r,nodeClassName:s="",nodeBorderRadius:a=5,nodeStrokeWidth:i,nodeComponent:l,bgColor:c,maskColor:d,maskStrokeColor:f,maskStrokeWidth:p,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 k=Ve(),C=ne(null),{boundingRect:E,viewBB:A,rfId:I,panZoom:z,translateExtent:$,flowWidth:B,flowHeight:R,ariaLabelConfig:M}=$e(oG,je),T=e?.width??tG,_=e?.height??nG,L=E.width/T,O=E.height/_,j=Math.max(L,O),F=j*T,H=j*_,D=N*j,Q=E.x-(F-E.width)/2-D,G=E.y-(H-E.height)/2-D,ee=F+D*2,se=H+D*2,te=`${sG}-${I}`,Z=ne(0),re=ne();Z.current=j,Y(()=>{if(C.current&&z)return re.current=bq({domNode:C.current,panZoom:z,getTransform:()=>k.getState().transform,getViewScale:()=>Z.current}),()=>{re.current?.destroy()}},[z]),Y(()=>{re.current?.update({translateExtent:$,width:B,height:R,inversePan:w,pannable:b,zoomStep:v,zoomable:x})},[b,x,w,v,$,B,R]);const be=m?J=>{const[ae,fe]=re.current?.pointer(J)||[0,0];m(J,{x:ae,y:fe})}:void 0,X=g?U((J,ae)=>{const fe=k.getState().nodeLookup.get(ae).internals.userNode;g(J,fe)},[]):void 0,K=y??M["minimap.ariaLabel"];return o(ni,{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 f=="string"?f:void 0,"--xy-minimap-mask-stroke-width-props":typeof p=="number"?p*j:void 0,"--xy-minimap-node-background-color-props":typeof r=="string"?r: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:Qe(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:u("svg",{width:T,height:_,viewBox:`${Q} ${G} ${ee} ${se}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":te,ref:C,onClick:be,children:[K&&o("title",{id:te,children:K}),o(eG,{onClick:X,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:a,nodeClassName:s,nodeStrokeWidth:i,nodeComponent:l}),o("path",{className:"react-flow__minimap-mask",d:`M${Q-D},${G-D}h${ee+D*2}v${se+D*2}h${-ee-D*2}z
1128
- M${A.x},${A.y}h${A.width}v${A.height}h${-A.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}V1.displayName="MiniMap";He(V1);const aG=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,iG={[Lr.Line]:"right",[Lr.Handle]:"bottom-right"};function lG({nodeId:e,position:t,variant:n=Lr.Handle,className:r,style:s=void 0,children:a,color:i,minWidth:l=10,minHeight:c=10,maxWidth:d=Number.MAX_VALUE,maxHeight:f=Number.MAX_VALUE,keepAspectRatio:p=!1,resizeDirection:h,autoScale:m=!0,shouldResize:g,onResizeStart:b,onResize:x,onResizeEnd:y}){const w=w1(),v=typeof e=="string"?e:w,N=Ve(),k=ne(null),C=n===Lr.Handle,E=$e(U(aG(C&&m),[C,m]),je),A=ne(null),I=t??iG[n];Y(()=>{if(!(!k.current||!v))return A.current||(A.current=_q({domNode:k.current,nodeId:v,getStoreItems:()=>{const{nodeLookup:$,transform:B,snapGrid:R,snapToGrid:M,nodeOrigin:T,domNode:_}=N.getState();return{nodeLookup:$,transform:B,snapGrid:R,snapToGrid:M,nodeOrigin:T,paneDomNode:_}},onChange:($,B)=>{const{triggerNodeChanges:R,nodeLookup:M,parentLookup:T,nodeOrigin:_}=N.getState(),L=[],O={x:$.x,y:$.y},j=M.get(v);if(j&&j.expandParent&&j.parentId){const F=j.origin??_,H=$.width??j.measured.width??0,D=$.height??j.measured.height??0,Q={id:j.id,parentId:j.parentId,rect:{width:H,height:D,...qv({x:$.x??j.position.x,y:$.y??j.position.y},{width:H,height:D},j.parentId,M,F)}},G=Yd([Q],M,T,_);L.push(...G),O.x=$.x?Math.max(F[0]*H,$.x):void 0,O.y=$.y?Math.max(F[1]*D,$.y):void 0}if(O.x!==void 0&&O.y!==void 0){const F={id:v,type:"position",position:{...O}};L.push(F)}if($.width!==void 0&&$.height!==void 0){const H={id:v,type:"dimensions",resizing:!0,setAttributes:h?h==="horizontal"?"width":"height":!0,dimensions:{width:$.width,height:$.height}};L.push(H)}for(const F of B){const H={...F,type:"position"};L.push(H)}R(L)},onEnd:({width:$,height:B})=>{const R={id:v,type:"dimensions",resizing:!1,dimensions:{width:$,height:B}};N.getState().triggerNodeChanges([R])}})),A.current.update({controlPosition:I,boundaries:{minWidth:l,minHeight:c,maxWidth:d,maxHeight:f},keepAspectRatio:p,resizeDirection:h,onResizeStart:b,onResize:x,onResizeEnd:y,shouldResize:g}),()=>{A.current?.destroy()}},[I,l,c,d,f,p,b,x,y,g]);const z=I.split("-");return o("div",{className:Qe(["react-flow__resize-control","nodrag",...z,n,r]),ref:k,style:{...s,scale:E,...i&&{[C?"backgroundColor":"borderColor"]:i}},children:a})}He(lG);var q1=Object.defineProperty,cG=(e,t,n)=>t in e?q1(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dG=(e,t)=>{for(var n in t)q1(e,n,{get:t[n],enumerable:!0})},uG=(e,t,n)=>cG(e,t+"",n),U1={};dG(U1,{Graph:()=>It,alg:()=>Jd,json:()=>G1,version:()=>hG});var pG=Object.defineProperty,Q1=(e,t)=>{for(var n in t)pG(e,n,{get:t[n],enumerable:!0})},It=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected="directed"in e?e.directed:!0,this._isMultigraph="multigraph"in e?e.multigraph:!1,this._isCompound="compound"in e?e.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children["\0"]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return typeof e!="function"?this._defaultNodeLabelFn=()=>e:this._defaultNodeLabelFn=e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,t){return e.forEach(n=>{t!==void 0?this.setNode(n,t):this.setNode(n)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]="\0",this._children[e]={},this._children["\0"][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let t=n=>this.removeEdge(this._edgeObjs[n]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(n=>{this.setParent(n)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(t===void 0)t="\0";else{t+="";for(let n=t;n!==void 0;n=this.parent(n))if(n===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}parent(e){if(this._isCompound){let t=this._parent[e];if(t!=="\0")return t}}children(e="\0"){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if(e==="\0")return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t);for(let r of this.successors(e))n.add(r);return Array.from(n.values())}}isLeaf(e){let t;return this.isDirected()?t=this.successors(e):t=this.neighbors(e),t.length===0}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([s,a])=>{e(s)&&t.setNode(s,a)}),Object.values(this._edgeObjs).forEach(s=>{t.hasNode(s.v)&&t.hasNode(s.w)&&t.setEdge(s,this.edge(s))});let n={},r=s=>{let a=this.parent(s);return!a||t.hasNode(a)?(n[s]=a??void 0,a??void 0):a in n?n[a]:r(a)};return this._isCompound&&t.nodes().forEach(s=>t.setParent(s,r(s))),t}setDefaultEdgeLabel(e){return typeof e!="function"?this._defaultEdgeLabelFn=()=>e:this._defaultEdgeLabelFn=e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((n,r)=>(t!==void 0?this.setEdge(n,r,t):this.setEdge(n,r),r)),this}setEdge(e,t,n,r){let s,a,i,l,c=!1;typeof e=="object"&&e!==null&&"v"in e?(s=e.v,a=e.w,i=e.name,arguments.length===2&&(l=t,c=!0)):(s=e,a=t,i=r,arguments.length>2&&(l=n,c=!0)),s=""+s,a=""+a,i!==void 0&&(i=""+i);let d=ao(this._isDirected,s,a,i);if(d in this._edgeLabels)return c&&(this._edgeLabels[d]=l),this;if(i!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(s),this.setNode(a),this._edgeLabels[d]=c?l:this._defaultEdgeLabelFn(s,a,i);let f=fG(this._isDirected,s,a,i);return s=f.v,a=f.w,Object.freeze(f),this._edgeObjs[d]=f,ih(this._preds[a],s),ih(this._sucs[s],a),this._in[a][d]=f,this._out[s][d]=f,this._edgeCount++,this}edge(e,t,n){let r=arguments.length===1?rl(this._isDirected,e):ao(this._isDirected,e,t,n);return this._edgeLabels[r]}edgeAsObj(e,t,n){let r=arguments.length===1?this.edge(e):this.edge(e,t,n);return typeof r!="object"?{label:r}:r}hasEdge(e,t,n){return(arguments.length===1?rl(this._isDirected,e):ao(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=arguments.length===1?rl(this._isDirected,e):ao(this._isDirected,e,t,n),s=this._edgeObjs[r];if(s){let a=s.v,i=s.w;delete this._edgeLabels[r],delete this._edgeObjs[r],lh(this._preds[i],a),lh(this._sucs[a],i),delete this._in[i][r],delete this._out[a][r],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let r=Object.values(e);return n?r.filter(s=>s.v===t&&s.w===n||s.v===n&&s.w===t):r}};function ih(e,t){e[t]?e[t]++:e[t]=1}function lh(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function ao(e,t,n,r){let s=""+t,a=""+n;if(!e&&s>a){let i=s;s=a,a=i}return s+""+a+""+(r===void 0?"\0":r)}function fG(e,t,n,r){let s=""+t,a=""+n;if(!e&&s>a){let l=s;s=a,a=l}let i={v:s,w:a};return r&&(i.name=r),i}function rl(e,t){return ao(e,t.v,t.w,t.name)}var hG="4.0.1",G1={};Q1(G1,{read:()=>xG,write:()=>mG});function mG(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:gG(e),edges:bG(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function gG(e){return e.nodes().map(t=>{let n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function bG(e){return e.edges().map(t=>{let n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function xG(e){let t=new It(e.options);return e.value!==void 0&&t.setGraph(e.value),e.nodes.forEach(n=>{t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(n=>{t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var Jd={};Q1(Jd,{CycleException:()=>ma,bellmanFord:()=>K1,components:()=>wG,dijkstra:()=>ha,dijkstraAll:()=>SG,findCycles:()=>CG,floydWarshall:()=>EG,isAcyclic:()=>AG,postorder:()=>_G,preorder:()=>$G,prim:()=>DG,shortestPaths:()=>TG,tarjan:()=>Y1,topsort:()=>Z1});var yG=()=>1;function K1(e,t,n,r){return vG(e,String(t),n||yG,r||function(s){return e.outEdges(s)})}function vG(e,t,n,r){let s={},a,i=0,l=e.nodes(),c=function(p){let h=n(p);s[p.v].distance+h<s[p.w].distance&&(s[p.w]={distance:s[p.v].distance+h,predecessor:p.v},a=!0)},d=function(){l.forEach(function(p){r(p).forEach(function(h){let m=h.v===p?h.v:h.w,g=m===h.v?h.w:h.v;c({v:m,w:g})})})};l.forEach(function(p){let h=p===t?0:Number.POSITIVE_INFINITY;s[p]={distance:h,predecessor:""}});let f=l.length;for(let p=1;p<f&&(a=!1,i++,d(),!!a);p++);if(i===f-1&&(a=!1,d(),a))throw new Error("The graph contains a negative weight cycle");return s}function wG(e){let t={},n=[],r;function s(a){a in t||(t[a]=!0,r.push(a),e.successors(a).forEach(s),e.predecessors(a).forEach(s))}return e.nodes().forEach(function(a){r=[],s(a),r.length&&n.push(r)}),n}var W1=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(e,t){let n=this._keyIndices,r=String(e);if(!(r in n)){let s=this._arr,a=s.length;return n[r]=a,s.push({key:r,priority:t}),this._decrease(a),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let n=this._keyIndices[e];if(n===void 0)throw new Error(`Key not found: ${e}`);let r=this._arr[n].priority;if(t>r)throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,r=n+1,s=e;n<t.length&&(s=t[n].priority<t[s].priority?n:s,r<t.length&&(s=t[r].priority<t[s].priority?r:s),s!==e&&(this._swap(e,s),this._heapify(s)))}_decrease(e){let t=this._arr,n=t[e].priority,r;for(;e!==0&&(r=e>>1,!(t[r].priority<n));)this._swap(e,r),e=r}_swap(e,t){let n=this._arr,r=this._keyIndices,s=n[e],a=n[t];n[e]=a,n[t]=s,r[a.key]=e,r[s.key]=t}},NG=()=>1;function ha(e,t,n,r){let s=function(a){return e.outEdges(a)};return kG(e,String(t),n||NG,r||s)}function kG(e,t,n,r){let s={},a=new W1,i,l,c=function(d){let f=d.v!==i?d.v:d.w,p=s[f],h=n(d),m=l.distance+h;if(h<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+d+" Weight: "+h);m<p.distance&&(p.distance=m,p.predecessor=i,a.decrease(f,m))};for(e.nodes().forEach(function(d){let f=d===t?0:Number.POSITIVE_INFINITY;s[d]={distance:f,predecessor:""},a.add(d,f)});a.size()>0&&(i=a.removeMin(),l=s[i],l.distance!==Number.POSITIVE_INFINITY);)r(i).forEach(c);return s}function SG(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=ha(e,s,t,n),r},{})}function Y1(e){let t=0,n=[],r={},s=[];function a(i){let l=r[i]={onStack:!0,lowlink:t,index:t++};if(n.push(i),e.successors(i).forEach(function(c){c in r?r[c].onStack&&(l.lowlink=Math.min(l.lowlink,r[c].index)):(a(c),l.lowlink=Math.min(l.lowlink,r[c].lowlink))}),l.lowlink===l.index){let c=[],d;do d=n.pop(),r[d].onStack=!1,c.push(d);while(i!==d);s.push(c)}}return e.nodes().forEach(function(i){i in r||a(i)}),s}function CG(e){return Y1(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var MG=()=>1;function EG(e,t,n){return IG(e,t||MG,n||function(r){return e.outEdges(r)})}function IG(e,t,n){let r={},s=e.nodes();return s.forEach(function(a){r[a]={},r[a][a]={distance:0,predecessor:""},s.forEach(function(i){a!==i&&(r[a][i]={distance:Number.POSITIVE_INFINITY,predecessor:""})}),n(a).forEach(function(i){let l=i.v===a?i.w:i.v,c=t(i);r[a][l]={distance:c,predecessor:a}})}),s.forEach(function(a){let i=r[a];s.forEach(function(l){let c=r[l];s.forEach(function(d){let f=c[a],p=i[d],h=c[d],m=f.distance+p.distance;m<h.distance&&(h.distance=m,h.predecessor=p.predecessor)})})}),r}var ma=class extends Error{constructor(...e){super(...e)}};function Z1(e){let t={},n={},r=[];function s(a){if(a in n)throw new ma;a in t||(n[a]=!0,t[a]=!0,e.predecessors(a).forEach(s),delete n[a],r.push(a))}if(e.sinks().forEach(s),Object.keys(t).length!==e.nodeCount())throw new ma;return r}function AG(e){try{Z1(e)}catch(t){if(t instanceof ma)return!1;throw t}return!0}function PG(e,t,n,r,s){Array.isArray(t)||(t=[t]);let a=(l=>{var c;return(c=e.isDirected()?e.successors(l):e.neighbors(l))!=null?c:[]}),i={};return t.forEach(function(l){if(!e.hasNode(l))throw new Error("Graph does not have node: "+l);s=X1(e,l,n==="post",i,a,r,s)}),s}function X1(e,t,n,r,s,a,i){return t in r||(r[t]=!0,n||(i=a(i,t)),s(t).forEach(function(l){i=X1(e,l,n,r,s,a,i)}),n&&(i=a(i,t))),i}function J1(e,t,n){return PG(e,t,n,function(r,s){return r.push(s),r},[])}function _G(e,t){return J1(e,t,"post")}function $G(e,t){return J1(e,t,"pre")}function DG(e,t){let n=new It,r={},s=new W1,a;function i(c){let d=c.v===a?c.w:c.v,f=s.priority(d);if(f!==void 0){let p=t(c);p<f&&(r[d]=a,s.decrease(d,p))}}if(e.nodeCount()===0)return n;e.nodes().forEach(function(c){s.add(c,Number.POSITIVE_INFINITY),n.setNode(c)}),s.decrease(e.nodes()[0],0);let l=!1;for(;s.size()>0;){if(a=s.removeMin(),a in r)n.setEdge(a,r[a]);else{if(l)throw new Error("Input graph is not connected: "+e);l=!0}e.nodeEdges(a).forEach(i)}return n}function TG(e,t,n,r){return LG(e,t,n,r??(s=>{let a=e.outEdges(s);return a??[]}))}function LG(e,t,n,r){if(n===void 0)return ha(e,t,n,r);let s=!1,a=e.nodes();for(let i=0;i<a.length;i++){let l=r(a[i]);for(let c=0;c<l.length;c++){let d=l[c],f=d.v===a[i]?d.v:d.w,p=f===d.v?d.w:d.v;n({v:f,w:p})<0&&(s=!0)}if(s)return K1(e,t,n,r)}return ha(e,t,n,r)}function Gr(e,t,n,r){let s=r;for(;e.hasNode(s);)s=eu(r);return n.dummy=t,e.setNode(s,n),s}function RG(e){let t=new It().setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function ew(e){let t=new It({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function ch(e,t){let n=e.x,r=e.y,s=t.x-n,a=t.y-r,i=e.width/2,l=e.height/2;if(!s&&!a)throw new Error("Not possible to find intersection inside of the rectangle");let c,d;return Math.abs(a)*i>Math.abs(s)*l?(a<0&&(l=-l),c=l*s/a,d=l):(s<0&&(i=-i),c=i,d=i*a/s),{x:n+c,y:r+d}}function ts(e){let t=To(nw(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s]||(t[s]=[]),t[s][r.order]=n)}),t}function OG(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Qt(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function BG(e){let t=e.nodes().map(i=>e.node(i).rank).filter(i=>i!==void 0),n=Qt(Math.min,t),r=[];e.nodes().forEach(i=>{let l=e.node(i).rank-n;r[l]||(r[l]=[]),r[l].push(i)});let s=0,a=e.graph().nodeRankFactor;Array.from(r).forEach((i,l)=>{i===void 0&&l%a!==0?--s:i!==void 0&&s&&i.forEach(c=>e.node(c).rank+=s)})}function dh(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),Gr(e,"border",s,t)}function zG(e,t=tw){let n=[];for(let r=0;r<e.length;r+=t){let s=e.slice(r,r+t);n.push(s)}return n}var tw=65535;function Qt(e,t){if(t.length>tw){let n=zG(t);return e(...n.map(r=>e(...r)))}else return e(...t)}function nw(e){let t=e.nodes().map(n=>{let r=e.node(n).rank;return r===void 0?Number.MIN_VALUE:r});return Qt(Math.max,t)}function FG(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function rw(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function ow(e,t){return t()}var jG=0;function eu(e){let t=++jG;return e+(""+t)}function To(e,t,n=1){t==null&&(t=e,e=0);let r=a=>a<t;n<0&&(r=a=>t<a);let s=[];for(let a=e;r(a);a+=n)s.push(a);return s}function ga(e,t){let n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function si(e,t){let n;return typeof t=="string"?n=r=>r[t]:n=t,Object.entries(e).reduce((r,[s,a])=>(r[s]=n(a,s),r),{})}function HG(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}var ai="\0",VG="3.0.0",qG=class{constructor(){uG(this,"_sentinel");let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return uh(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&uh(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,UG)),n=n._prev;return"["+e.join(", ")+"]"}};function uh(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function UG(e,t){if(e!=="_next"&&e!=="_prev")return t}var QG=qG,GG=()=>1;function KG(e,t){if(e.nodeCount()<=1)return[];let n=YG(e,t||GG);return WG(n.graph,n.buckets,n.zeroIdx).flatMap(r=>e.outEdges(r.v,r.w)||[])}function WG(e,t,n){var r;let s=[],a=t[t.length-1],i=t[0],l;for(;e.nodeCount();){for(;l=i.dequeue();)ol(e,t,n,l);for(;l=a.dequeue();)ol(e,t,n,l);if(e.nodeCount()){for(let c=t.length-2;c>0;--c)if(l=(r=t[c])==null?void 0:r.dequeue(),l){s=s.concat(ol(e,t,n,l,!0)||[]);break}}}return s}function ol(e,t,n,r,s){let a=[],i=s?a:void 0;return(e.inEdges(r.v)||[]).forEach(l=>{let c=e.edge(l),d=e.node(l.v);s&&a.push({v:l.v,w:l.w}),d.out-=c,sc(t,n,d)}),(e.outEdges(r.v)||[]).forEach(l=>{let c=e.edge(l),d=l.w,f=e.node(d);f.in-=c,sc(t,n,f)}),e.removeNode(r.v),i}function YG(e,t){let n=new It,r=0,s=0;e.nodes().forEach(l=>{n.setNode(l,{v:l,in:0,out:0})}),e.edges().forEach(l=>{let c=n.edge(l.v,l.w)||0,d=t(l),f=c+d;n.setEdge(l.v,l.w,f);let p=n.node(l.v),h=n.node(l.w);s=Math.max(s,p.out+=d),r=Math.max(r,h.in+=d)});let a=ZG(s+r+3).map(()=>new QG),i=r+1;return n.nodes().forEach(l=>{sc(a,i,n.node(l))}),{graph:n,buckets:a,zeroIdx:i}}function sc(e,t,n){var r,s,a;n.out?n.in?(a=e[n.out-n.in+t])==null||a.enqueue(n):(s=e[e.length-1])==null||s.enqueue(n):(r=e[0])==null||r.enqueue(n)}function ZG(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function XG(e){(e.graph().acyclicer==="greedy"?KG(e,t(e)):JG(e)).forEach(n=>{let r=e.edge(n);e.removeEdge(n),r.forwardName=n.name,r.reversed=!0,e.setEdge(n.w,n.v,r,eu("rev"))});function t(n){return r=>n.edge(r).weight}}function JG(e){let t=[],n={},r={};function s(a){Object.hasOwn(r,a)||(r[a]=!0,n[a]=!0,e.outEdges(a).forEach(i=>{Object.hasOwn(n,i.w)?t.push(i):s(i.w)}),delete n[a])}return e.nodes().forEach(s),t}function eK(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}function tK(e){e.graph().dummyChains=[],e.edges().forEach(t=>nK(e,t))}function nK(e,t){let n=t.v,r=e.node(n).rank,s=t.w,a=e.node(s).rank,i=t.name,l=e.edge(t),c=l.labelRank;if(a===r+1)return;e.removeEdge(t);let d,f,p;for(p=0,++r;r<a;++p,++r)l.points=[],f={width:0,height:0,edgeLabel:l,edgeObj:t,rank:r},d=Gr(e,"edge",f,"_d"),r===c&&(f.width=l.width,f.height=l.height,f.dummy="edge-label",f.labelpos=l.labelpos),e.setEdge(n,d,{weight:l.weight},i),p===0&&e.graph().dummyChains.push(d),n=d;e.setEdge(n,s,{weight:l.weight},i)}function rK(e){e.graph().dummyChains.forEach(t=>{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}function tu(e){let t={};function n(r){let s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let a=e.outEdges(r),i=a?a.map(c=>c==null?Number.POSITIVE_INFINITY:n(c.w)-e.edge(c).minlen):[],l=Qt(Math.min,i);return l===Number.POSITIVE_INFINITY&&(l=0),s.rank=l}e.sources().forEach(n)}function Rr(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var sw=oK;function oK(e){let t=new It({directed:!1}),n=e.nodes();if(n.length===0)throw new Error("Graph must have at least one node");let r=n[0],s=e.nodeCount();t.setNode(r,{});let a,i;for(;sK(t,e)<s&&(a=aK(t,e),!!a);)i=t.hasNode(a.v)?Rr(e,a):-Rr(e,a),iK(t,e,i);return t}function sK(e,t){function n(r){let s=t.nodeEdges(r);s&&s.forEach(a=>{let i=a.v,l=r===i?a.w:i;!e.hasNode(l)&&!Rr(t,a)&&(e.setNode(l,{}),e.setEdge(r,l,{}),n(l))})}return e.nodes().forEach(n),e.nodeCount()}function aK(e,t){return t.edges().reduce((n,r)=>{let s=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(s=Rr(t,r)),s<n[0]?[s,r]:n},[Number.POSITIVE_INFINITY,null])[1]}function iK(e,t,n){e.nodes().forEach(r=>t.node(r).rank+=n)}var{preorder:lK,postorder:cK}=Jd,dK=dr;dr.initLowLimValues=ru;dr.initCutValues=nu;dr.calcCutValue=aw;dr.leaveEdge=lw;dr.enterEdge=cw;dr.exchangeEdges=dw;function dr(e){e=RG(e),tu(e);let t=sw(e);ru(t),nu(t,e);let n,r;for(;n=lw(t);)r=cw(t,e,n),dw(t,e,n,r)}function nu(e,t){let n=cK(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>uK(e,t,r))}function uK(e,t,n){let r=e.node(n).parent,s=e.edge(n,r);s.cutvalue=aw(e,t,n)}function aw(e,t,n){let r=e.node(n).parent,s=!0,a=t.edge(n,r),i=0;a||(s=!1,a=t.edge(r,n)),i=a.weight;let l=t.nodeEdges(n);return l&&l.forEach(c=>{let d=c.v===n,f=d?c.w:c.v;if(f!==r){let p=d===s,h=t.edge(c).weight;if(i+=p?h:-h,fK(e,n,f)){let m=e.edge(n,f).cutvalue;i+=p?-m:m}}}),i}function ru(e,t){arguments.length<2&&(t=e.nodes()[0]),iw(e,{},1,t)}function iw(e,t,n,r,s){let a=n,i=e.node(r);t[r]=!0;let l=e.neighbors(r);return l&&l.forEach(c=>{Object.hasOwn(t,c)||(n=iw(e,t,n,c,r))}),i.low=a,i.lim=n++,s?i.parent=s:delete i.parent,n}function lw(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function cw(e,t,n){let r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);let a=e.node(r),i=e.node(s),l=a,c=!1;return a.lim>i.lim&&(l=i,c=!0),t.edges().filter(d=>c===ph(e,e.node(d.v),l)&&c!==ph(e,e.node(d.w),l)).reduce((d,f)=>Rr(t,f)<Rr(t,d)?f:d)}function dw(e,t,n,r){let s=n.v,a=n.w;e.removeEdge(s,a),e.setEdge(r.v,r.w,{}),ru(e),nu(e,t),pK(e,t)}function pK(e,t){let n=e.nodes().find(s=>!e.node(s).parent);if(!n)return;let r=lK(e,[n]);r=r.slice(1),r.forEach(s=>{let a=e.node(s).parent,i=t.edge(s,a),l=!1;i||(i=t.edge(a,s),l=!0),t.node(s).rank=t.node(a).rank+(l?i.minlen:-i.minlen)})}function fK(e,t,n){return e.hasEdge(t,n)}function ph(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var hK=mK;function mK(e){let t=e.graph().ranker;if(typeof t=="function")return t(e);switch(t){case"network-simplex":fh(e);break;case"tight-tree":bK(e);break;case"longest-path":gK(e);break;case"none":break;default:fh(e)}}var gK=tu;function bK(e){tu(e),sw(e)}function fh(e){dK(e)}var xK=yK;function yK(e){let t=wK(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,a=vK(e,t,s.v,s.w),i=a.path,l=a.lca,c=0,d=i[c],f=!0;for(;n!==s.w;){if(r=e.node(n),f){for(;(d=i[c])!==l&&e.node(d).maxRank<r.rank;)c++;d===l&&(f=!1)}if(!f){for(;c<i.length-1&&e.node(i[c+1]).minRank<=r.rank;)c++;d=i[c]}d!==void 0&&e.setParent(n,d),n=e.successors(n)[0]}})}function vK(e,t,n,r){let s=[],a=[],i=Math.min(t[n].low,t[r].low),l=Math.max(t[n].lim,t[r].lim),c;c=n;do c=e.parent(c),s.push(c);while(c&&(t[c].low>i||l>t[c].lim));let d=c,f=r;for(;(f=e.parent(f))!==d;)a.push(f);return{path:s.concat(a.reverse()),lca:d}}function wK(e){let t={},n=0;function r(s){let a=n;e.children(s).forEach(r),t[s]={low:a,lim:n++}}return e.children(ai).forEach(r),t}function NK(e){let t=Gr(e,"root",{},"_root"),n=kK(e),r=Object.values(n),s=Qt(Math.max,r)-1,a=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(l=>e.edge(l).minlen*=a);let i=SK(e)+1;e.children(ai).forEach(l=>uw(e,t,a,i,s,n,l)),e.graph().nodeRankFactor=a}function uw(e,t,n,r,s,a,i){var l;let c=e.children(i);if(!c.length){i!==t&&e.setEdge(t,i,{weight:0,minlen:n});return}let d=dh(e,"_bt"),f=dh(e,"_bb"),p=e.node(i);e.setParent(d,i),p.borderTop=d,e.setParent(f,i),p.borderBottom=f,c.forEach(h=>{var m;uw(e,t,n,r,s,a,h);let g=e.node(h),b=g.borderTop?g.borderTop:h,x=g.borderBottom?g.borderBottom:h,y=g.borderTop?r:2*r,w=b!==x?1:s-((m=a[i])!=null?m:0)+1;e.setEdge(d,b,{weight:y,minlen:w,nestingEdge:!0}),e.setEdge(x,f,{weight:y,minlen:w,nestingEdge:!0})}),e.parent(i)||e.setEdge(t,d,{weight:0,minlen:s+((l=a[i])!=null?l:0)})}function kK(e){let t={};function n(r,s){let a=e.children(r);a&&a.length&&a.forEach(i=>n(i,s+1)),t[r]=s}return e.children(ai).forEach(r=>n(r,1)),t}function SK(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function CK(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{e.edge(n).nestingEdge&&e.removeEdge(n)})}var MK=EK;function EK(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let a=s.minRank,i=s.maxRank+1;a<i;++a)hh(e,"borderLeft","_bl",n,s,a),hh(e,"borderRight","_br",n,s,a)}}e.children(ai).forEach(t)}function hh(e,t,n,r,s,a){let i={width:0,height:0,rank:a,borderType:t},l=s[t][a-1],c=Gr(e,"border",i,n);s[t][a]=c,e.setParent(c,r),l&&e.setEdge(l,c,{weight:1})}function IK(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="lr"||n==="rl")&&pw(e)}function AK(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="bt"||n==="rl")&&PK(e),(n==="lr"||n==="rl")&&(_K(e),pw(e))}function pw(e){e.nodes().forEach(t=>mh(e.node(t))),e.edges().forEach(t=>mh(e.edge(t)))}function mh(e){let t=e.width;e.width=e.height,e.height=t}function PK(e){e.nodes().forEach(t=>sl(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(sl),Object.hasOwn(r,"y")&&sl(r)})}function sl(e){e.y=-e.y}function _K(e){e.nodes().forEach(t=>al(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(al),Object.hasOwn(r,"x")&&al(r)})}function al(e){let t=e.x;e.x=e.y,e.y=t}function $K(e){let t={},n=e.nodes().filter(l=>!e.children(l).length),r=n.map(l=>e.node(l).rank),s=Qt(Math.max,r),a=To(s+1).map(()=>[]);function i(l){if(t[l])return;t[l]=!0;let c=e.node(l);a[c.rank].push(l);let d=e.successors(l);d&&d.forEach(i)}return n.sort((l,c)=>e.node(l).rank-e.node(c).rank).forEach(i),a}function DK(e,t){let n=0;for(let r=1;r<t.length;++r)n+=TK(e,t[r-1],t[r]);return n}function TK(e,t,n){let r=HG(n,n.map((d,f)=>f)),s=t.flatMap(d=>{let f=e.outEdges(d);return f?f.map(p=>({pos:r[p.w],weight:e.edge(p).weight})).sort((p,h)=>p.pos-h.pos):[]}),a=1;for(;a<n.length;)a<<=1;let i=2*a-1;a-=1;let l=new Array(i).fill(0),c=0;return s.forEach(d=>{let f=d.pos+a;l[f]+=d.weight;let p=0;for(;f>0;)f%2&&(p+=l[f+1]),f=f-1>>1,l[f]+=d.weight;c+=d.weight*p}),c}function LK(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(!r||!r.length)return{v:n};{let s=r.reduce((a,i)=>{let l=e.edge(i),c=e.node(i.v);return{sum:a.sum+l.weight*c.order,weight:a.weight+l.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}})}function RK(e,t){let n={};e.forEach((s,a)=>{let i={indegree:0,in:[],out:[],vs:[s.v],i:a};s.barycenter!==void 0&&(i.barycenter=s.barycenter,i.weight=s.weight),n[s.v]=i}),t.edges().forEach(s=>{let a=n[s.v],i=n[s.w];a!==void 0&&i!==void 0&&(i.indegree++,a.out.push(i))});let r=Object.values(n).filter(s=>!s.indegree);return OK(r)}function OK(e){let t=[];function n(s){return a=>{a.merged||(a.barycenter===void 0||s.barycenter===void 0||a.barycenter>=s.barycenter)&&BK(s,a)}}function r(s){return a=>{a.in.push(s),--a.indegree===0&&e.push(a)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>ga(s,["vs","i","barycenter","weight"]))}function BK(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}function zK(e,t){let n=FG(e,f=>Object.hasOwn(f,"barycenter")),r=n.lhs,s=n.rhs.sort((f,p)=>p.i-f.i),a=[],i=0,l=0,c=0;r.sort(FK(!!t)),c=gh(a,s,c),r.forEach(f=>{c+=f.vs.length,a.push(f.vs),i+=f.barycenter*f.weight,l+=f.weight,c=gh(a,s,c)});let d={vs:a.flat(1)};return l&&(d.barycenter=i/l,d.weight=l),d}function gh(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function FK(e){return(t,n)=>t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}function fw(e,t,n,r){let s=e.children(t),a=e.node(t),i=a?a.borderLeft:void 0,l=a?a.borderRight:void 0,c={};i&&(s=s.filter(h=>h!==i&&h!==l));let d=LK(e,s);d.forEach(h=>{if(e.children(h.v).length){let m=fw(e,h.v,n,r);c[h.v]=m,Object.hasOwn(m,"barycenter")&&HK(h,m)}});let f=RK(d,n);jK(f,c);let p=zK(f,r);if(i&&l){p.vs=[i,p.vs,l].flat(1);let h=e.predecessors(i);if(h&&h.length){let m=e.node(h[0]),g=e.predecessors(l),b=e.node(g[0]);Object.hasOwn(p,"barycenter")||(p.barycenter=0,p.weight=0),p.barycenter=(p.barycenter*p.weight+m.order+b.order)/(p.weight+2),p.weight+=2}}return p}function jK(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function HK(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}function VK(e,t,n,r){r||(r=e.nodes());let s=qK(e),a=new It({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(i=>e.node(i));return r.forEach(i=>{let l=e.node(i),c=e.parent(i);if(l.rank===t||l.minRank<=t&&t<=l.maxRank){a.setNode(i),a.setParent(i,c||s);let d=e[n](i);d&&d.forEach(f=>{let p=f.v===i?f.w:f.v,h=a.edge(p,i),m=h!==void 0?h.weight:0;a.setEdge(p,i,{weight:e.edge(f).weight+m})}),Object.hasOwn(l,"minRank")&&a.setNode(i,{borderLeft:l.borderLeft[t],borderRight:l.borderRight[t]})}}),a}function qK(e){let t;for(;e.hasNode(t=eu("_root")););return t}function UK(e,t,n){let r={},s;n.forEach(a=>{let i=e.parent(a),l,c;for(;i;){if(l=e.parent(i),l?(c=r[l],r[l]=i):(c=s,s=i),c&&c!==i){t.setEdge(c,i);return}i=l}})}function hw(e,t={}){if(typeof t.customOrder=="function"){t.customOrder(e,hw);return}let n=nw(e),r=bh(e,To(1,n+1),"inEdges"),s=bh(e,To(n-1,-1,-1),"outEdges"),a=$K(e);if(xh(e,a),t.disableOptimalOrderHeuristic)return;let i=Number.POSITIVE_INFINITY,l,c=t.constraints||[];for(let d=0,f=0;f<4;++d,++f){QK(d%2?r:s,d%4>=2,c),a=ts(e);let p=DK(e,a);p<i?(f=0,l=Object.assign({},a),i=p):p===i&&(l=structuredClone(a))}xh(e,l)}function bh(e,t,n){let r=new Map,s=(a,i)=>{r.has(a)||r.set(a,[]),r.get(a).push(i)};for(let a of e.nodes()){let i=e.node(a);if(typeof i.rank=="number"&&s(i.rank,a),typeof i.minRank=="number"&&typeof i.maxRank=="number")for(let l=i.minRank;l<=i.maxRank;l++)l!==i.rank&&s(l,a)}return t.map(function(a){return VK(e,a,n,r.get(a)||[])})}function QK(e,t,n){let r=new It;e.forEach(function(s){n.forEach(l=>r.setEdge(l.left,l.right));let a=s.graph().root,i=fw(s,a,r,t);i.vs.forEach((l,c)=>s.node(l).order=c),UK(s,r,i.vs)})}function xh(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}function GK(e,t){let n={};function r(s,a){let i=0,l=0,c=s.length,d=a[a.length-1];return a.forEach((f,p)=>{let h=WK(e,f),m=h?e.node(h).order:c;(h||f===d)&&(a.slice(l,p+1).forEach(g=>{let b=e.predecessors(g);b&&b.forEach(x=>{let y=e.node(x),w=y.order;(w<i||m<w)&&!(y.dummy&&e.node(g).dummy)&&mw(n,x,g)})}),l=p+1,i=m)}),a}return t.length&&t.reduce(r),n}function KK(e,t){let n={};function r(a,i,l,c,d){To(i,l).forEach(f=>{let p=a[f];if(p!==void 0&&e.node(p).dummy){let h=e.predecessors(p);h&&h.forEach(m=>{if(m===void 0)return;let g=e.node(m);g.dummy&&(g.order<c||g.order>d)&&mw(n,m,p)})}})}function s(a,i){let l=-1,c=-1,d=0;return i.forEach((f,p)=>{if(e.node(f).dummy==="border"){let h=e.predecessors(f);if(h&&h.length){let m=h[0];if(m===void 0)return;c=e.node(m).order,r(i,d,p,l,c),d=p,l=c}}r(i,d,i.length,c,a.length)}),i}return t.length&&t.reduce(s),n}function WK(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(r=>e.node(r).dummy)}}function mw(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function YK(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];return r!==void 0&&Object.hasOwn(r,n)}function ZK(e,t,n,r){let s={},a={},i={};return t.forEach(l=>{l.forEach((c,d)=>{s[c]=c,a[c]=c,i[c]=d})}),t.forEach(l=>{let c=-1;l.forEach(d=>{let f=r(d);if(f&&f.length){let p=f.sort((m,g)=>{let b=i[m],x=i[g];return(b!==void 0?b:0)-(x!==void 0?x:0)}),h=(p.length-1)/2;for(let m=Math.floor(h),g=Math.ceil(h);m<=g;++m){let b=p[m];if(b===void 0)continue;let x=i[b];if(x!==void 0&&a[d]===d&&c<x&&!YK(n,d,b)){let y=s[b];y!==void 0&&(a[b]=d,a[d]=s[d]=y,c=x)}}}})}),{root:s,align:a}}function XK(e,t,n,r,s=!1){let a={},i=JK(e,t,n,s),l=s?"borderLeft":"borderRight";function c(m,g){let b=i.nodes().slice(),x={},y=b.pop();for(;y;){if(x[y])m(y);else{x[y]=!0,b.push(y);for(let w of g(y))b.push(w)}y=b.pop()}}function d(m){let g=i.inEdges(m);g?a[m]=g.reduce((b,x)=>{var y;let w=(y=a[x.v])!=null?y:0,v=i.edge(x);return Math.max(b,w+(v!==void 0?v:0))},0):a[m]=0}function f(m){let g=i.outEdges(m),b=Number.POSITIVE_INFINITY;g&&(b=g.reduce((y,w)=>{let v=a[w.w],N=i.edge(w);return Math.min(y,(v!==void 0?v:0)-(N!==void 0?N:0))},Number.POSITIVE_INFINITY));let x=e.node(m);b!==Number.POSITIVE_INFINITY&&x.borderType!==l&&(a[m]=Math.max(a[m]!==void 0?a[m]:0,b))}function p(m){return i.predecessors(m)||[]}function h(m){return i.successors(m)||[]}return c(d,p),c(f,h),Object.keys(r).forEach(m=>{var g;let b=n[m];b!==void 0&&(a[m]=(g=a[b])!=null?g:0)}),a}function JK(e,t,n,r){let s=new It,a=e.graph(),i=oW(a.nodesep,a.edgesep,r);return t.forEach(l=>{let c;l.forEach(d=>{let f=n[d];if(f!==void 0){if(s.setNode(f),c!==void 0){let p=n[c];if(p!==void 0){let h=s.edge(p,f);s.setEdge(p,f,Math.max(i(e,d,c),h||0))}}c=d}})}),s}function eW(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,a=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([l,c])=>{let d=sW(e,l)/2;s=Math.max(c+d,s),a=Math.min(c-d,a)});let i=s-a;return i<n[0]&&(n=[i,r]),n},[Number.POSITIVE_INFINITY,null])[1]}function tW(e,t){let n=Object.values(t),r=Qt(Math.min,n),s=Qt(Math.max,n);["u","d"].forEach(a=>{["l","r"].forEach(i=>{let l=a+i,c=e[l];if(!c||c===t)return;let d=Object.values(c),f=r-Qt(Math.min,d);i!=="l"&&(f=s-Qt(Math.max,d)),f&&(e[l]=si(c,p=>p+f))})})}function nW(e,t=void 0){let n=e.ul;return n?si(n,(r,s)=>{var a,i;if(t){let c=t.toLowerCase(),d=e[c];if(d&&d[s]!==void 0)return d[s]}let l=Object.values(e).map(c=>{let d=c[s];return d!==void 0?d:0}).sort((c,d)=>c-d);return(((a=l[1])!=null?a:0)+((i=l[2])!=null?i:0))/2}):{}}function rW(e){let t=ts(e),n=Object.assign(GK(e,t),KK(e,t)),r={},s;["u","d"].forEach(i=>{s=i==="u"?t:Object.values(t).reverse(),["l","r"].forEach(l=>{l==="r"&&(s=s.map(f=>Object.values(f).reverse()));let c=ZK(e,s,n,f=>(i==="u"?e.predecessors(f):e.successors(f))||[]),d=XK(e,s,c.root,c.align,l==="r");l==="r"&&(d=si(d,f=>-f)),r[i+l]=d})});let a=eW(e,r);return tW(r,a),nW(r,e.graph().align)}function oW(e,t,n){return(r,s,a)=>{let i=r.node(s),l=r.node(a),c=0,d;if(c+=i.width/2,Object.hasOwn(i,"labelpos"))switch(i.labelpos.toLowerCase()){case"l":d=-i.width/2;break;case"r":d=i.width/2;break}if(d&&(c+=n?d:-d),d=void 0,c+=(i.dummy?t:e)/2,c+=(l.dummy?t:e)/2,c+=l.width/2,Object.hasOwn(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":d=l.width/2;break;case"r":d=-l.width/2;break}return d&&(c+=n?d:-d),c}}function sW(e,t){return e.node(t).width}function aW(e){e=ew(e),iW(e),Object.entries(rW(e)).forEach(([t,n])=>e.node(t).x=n)}function iW(e){let t=ts(e),n=e.graph(),r=n.ranksep,s=n.rankalign,a=0;t.forEach(i=>{let l=i.reduce((c,d)=>{var f;let p=(f=e.node(d).height)!=null?f:0;return c>p?c:p},0);i.forEach(c=>{let d=e.node(c);s==="top"?d.y=a+d.height/2:s==="bottom"?d.y=a+l-d.height/2:d.y=a+l/2}),a+=l+r})}function lW(e,t={}){let n=t.debugTiming?rw:ow;return n("layout",()=>{let r=n(" buildLayoutGraph",()=>xW(e));return n(" runLayout",()=>cW(r,n,t)),n(" updateInputGraph",()=>dW(e,r)),r})}function cW(e,t,n){t(" makeSpaceForEdgeLabels",()=>yW(e)),t(" removeSelfEdges",()=>IW(e)),t(" acyclic",()=>XG(e)),t(" nestingGraph.run",()=>NK(e)),t(" rank",()=>hK(ew(e))),t(" injectEdgeLabelProxies",()=>vW(e)),t(" removeEmptyRanks",()=>BG(e)),t(" nestingGraph.cleanup",()=>CK(e)),t(" normalizeRanks",()=>OG(e)),t(" assignRankMinMax",()=>wW(e)),t(" removeEdgeLabelProxies",()=>NW(e)),t(" normalize.run",()=>tK(e)),t(" parentDummyChains",()=>xK(e)),t(" addBorderSegments",()=>MK(e)),t(" order",()=>hw(e,n)),t(" insertSelfEdges",()=>AW(e)),t(" adjustCoordinateSystem",()=>IK(e)),t(" position",()=>aW(e)),t(" positionSelfEdges",()=>PW(e)),t(" removeBorderNodes",()=>EW(e)),t(" normalize.undo",()=>rK(e)),t(" fixupEdgeLabelCoords",()=>CW(e)),t(" undoCoordinateSystem",()=>AK(e)),t(" translateGraph",()=>kW(e)),t(" assignNodeIntersects",()=>SW(e)),t(" reversePoints",()=>MW(e)),t(" acyclic.undo",()=>eK(e))}function dW(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.order=s.order,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var uW=["nodesep","edgesep","ranksep","marginx","marginy"],pW={ranksep:50,edgesep:20,nodesep:50,rankdir:"TB",rankalign:"center"},fW=["acyclicer","ranker","rankdir","align","rankalign"],hW=["width","height","rank"],yh={width:0,height:0},mW=["minlen","weight","width","height","labeloffset"],gW={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},bW=["labelpos"];function xW(e){let t=new It({multigraph:!0,compound:!0}),n=ll(e.graph());return t.setGraph(Object.assign({},pW,il(n,uW),ga(n,fW))),e.nodes().forEach(r=>{let s=ll(e.node(r)),a=il(s,hW);Object.keys(yh).forEach(l=>{a[l]===void 0&&(a[l]=yh[l])}),t.setNode(r,a);let i=e.parent(r);i!==void 0&&t.setParent(r,i)}),e.edges().forEach(r=>{let s=ll(e.edge(r));t.setEdge(r,Object.assign({},gW,il(s,mW),ga(s,bW)))}),t}function yW(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function vW(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),s={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};Gr(e,"edge-proxy",s,"_ep")}})}function wW(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function NW(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy==="edge-proxy"){let r=n;e.edge(r.e).labelRank=n.rank,e.removeNode(t)}})}function kW(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,a=e.graph(),i=a.marginx||0,l=a.marginy||0;function c(d){let f=d.x,p=d.y,h=d.width,m=d.height;t=Math.min(t,f-h/2),n=Math.max(n,f+h/2),r=Math.min(r,p-m/2),s=Math.max(s,p+m/2)}e.nodes().forEach(d=>c(e.node(d))),e.edges().forEach(d=>{let f=e.edge(d);Object.hasOwn(f,"x")&&c(f)}),t-=i,r-=l,e.nodes().forEach(d=>{let f=e.node(d);f.x-=t,f.y-=r}),e.edges().forEach(d=>{let f=e.edge(d);f.points.forEach(p=>{p.x-=t,p.y-=r}),Object.hasOwn(f,"x")&&(f.x-=t),Object.hasOwn(f,"y")&&(f.y-=r)}),a.width=n-t+i,a.height=s-r+l}function SW(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),a,i;n.points?(a=n.points[0],i=n.points[n.points.length-1]):(n.points=[],a=s,i=r),n.points.unshift(ch(r,a)),n.points.push(ch(s,i))})}function CW(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function MW(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function EW(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),a=e.node(n.borderLeft[n.borderLeft.length-1]),i=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(i.x-a.x),n.height=Math.abs(s.y-r.y),n.x=a.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function IW(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function AW(e){ts(e).forEach(t=>{let n=0;t.forEach((r,s)=>{let a=e.node(r);a.order=s+n,(a.selfEdges||[]).forEach(i=>{Gr(e,"selfedge",{width:i.label.width,height:i.label.height,rank:a.rank,order:s+ ++n,e:i.e,label:i.label},"_se")}),delete a.selfEdges})})}function PW(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy==="selfedge"){let r=n,s=e.node(r.e.v),a=s.x+s.width/2,i=s.y,l=n.x-a,c=s.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:a+2*l/3,y:i-c},{x:a+5*l/6,y:i-c},{x:a+l,y:i},{x:a+5*l/6,y:i+c},{x:a+2*l/3,y:i+c}],r.label.x=n.x,r.label.y=n.y}})}function il(e,t){return si(ga(e,t),Number)}function ll(e){let t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}function _W(e){let t=ts(e),n=new It({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let a="layer"+s;n.setNode(a,{rank:"same"}),r.reduce((i,l)=>(n.setEdge(i,l,{style:"invis"}),l))}),n}var $W={graphlib:U1,version:VG,layout:lW,debug:_W,util:{time:rw,notime:ow}},vh=$W;/*! For license information please see dagre.esm.js.LEGAL.txt */function DW({data:e,selected:t}){const n=e.isOnline,r=e.isHub,s=e.engines??[],a=e.addons??[],i=e.processes??[],l=e.name,c=e.hostname,d=e.localIps??[],f=e.cpuPercent,p=e.memoryPercent,h=e.isExpanded,m=e.onToggleExpand,g=e.onShowNodeLogs,b=e.onRestartNode,x=e.id,y=i.length,w=U(E=>{E.stopPropagation(),m?.()},[m]),v=U(E=>{E.stopPropagation(),g?.()},[g]),N=U(E=>{E.stopPropagation(),b?.()},[b]);return u("div",{className:`rounded-xl bg-surface px-3 py-2.5 min-w-[180px] max-w-[260px] transition-all duration-200 ${n?r?"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:[o(In,{type:"target",position:we.Top,className:"!bg-border !w-2 !h-2"}),u("div",{className:"flex items-center gap-1.5 mb-1.5",children:[o("div",{className:`w-2 h-2 rounded-full ${n?"bg-success":"bg-destructive"}`}),o("span",{className:"text-xs font-semibold truncate flex-1",children:l}),r?o("span",{className:"text-[8px] px-1 py-0.5 rounded bg-primary/10 text-primary font-medium",children:"HUB"}):o("span",{className:"text-[8px] px-1 py-0.5 rounded bg-muted text-muted-foreground font-medium",children:"AGENT"})]}),(c||d.length>0)&&(()=>{const E=d.filter(A=>!A.includes(":"));return u("div",{className:"text-[9px] text-muted-foreground mb-1 space-y-0.5",title:[c,...d].filter(Boolean).join(", "),children:[c&&o("div",{className:"truncate",children:c}),E.length>0&&o("div",{className:"truncate font-mono opacity-70",children:E.join(", ")})]})})(),s.length>0&&o("div",{className:"flex flex-wrap gap-1 mb-1.5",children:s.map(E=>o("span",{className:"text-[8px] px-1 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium",children:E},E))}),a.length>0&&u("div",{className:"text-[9px] text-muted-foreground mb-1",children:[a.length," addon",a.length!==1?"s":""," in-process"]}),n&&u("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground",children:[u("span",{className:"flex items-center gap-0.5",children:[o(ft,{className:"h-2.5 w-2.5"}),f,"%"]}),u("span",{className:"flex items-center gap-0.5",children:[o(Pd,{className:"h-2.5 w-2.5"}),p,"%"]}),u("div",{className:"flex items-center gap-1 ml-auto",children:[y>0&&u("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?o(Nt,{className:"h-3 w-3"}):o(Et,{className:"h-3 w-3"}),o("span",{className:"text-[9px] font-medium",children:y})]}),o("button",{onClick:v,className:"p-0.5 rounded hover:bg-primary/10 text-muted-foreground hover:text-primary transition-colors",title:`Logs: ${x}`,children:o(rt,{className:"h-3 w-3"})}),o("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:o(yt,{className:"h-3 w-3"})})]})]}),!n&&o("div",{className:"text-[10px] text-muted-foreground",children:"offline"}),o(In,{type:"source",position:we.Bottom,className:"!bg-border !w-2 !h-2"})]})}const TW=He(DW);function LW(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 RW({data:e}){const t=e.name,n=e.state,r=e.pid,s=e.cpuPercent,a=e.memoryRss,i=e.addonId,l=e.services??[],c=e.isExpanded,d=e.onToggleServices,f=e.parentNodeId,p=e.onShowLogs,h=e.onRestartAddon,m=n==="running",g=t.includes("(core)"),b=!g&&l.length===1,x=b?l[0]:null,y=f??"hub",w=`${y}/${t}`,v=U(E=>{E.stopPropagation(),d?.()},[d]),N=g?cn:Ra,k=g?"border-primary/50":m?"border-amber-500/50":"border-destructive/50",C=g?"text-primary":"text-amber-500";return u("div",{className:`rounded-lg bg-surface min-w-[150px] border ${k} ${c?"max-w-[240px]":"max-w-[210px]"}`,children:[o(In,{type:"target",position:we.Top,className:`!w-1.5 !h-1.5 ${g?"!bg-primary":"!bg-amber-500"}`}),u("div",{className:"px-2.5 pt-2 pb-1.5",children:[u("div",{className:"flex items-start gap-1.5 mb-1.5",children:[o(N,{className:`h-3 w-3 ${C} shrink-0 mt-0.5`}),o("span",{className:"text-[10px] font-semibold truncate flex-1",children:g?"core":i??t}),o("span",{className:"text-[8px] text-muted-foreground/60 tabular-nums shrink-0",children:r})]}),u("div",{className:"flex items-center gap-2 text-[9px] text-muted-foreground",children:[o("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${m?"bg-success":"bg-destructive"}`}),u("span",{className:"flex items-center gap-0.5",children:[o(ft,{className:"h-2 w-2"}),s,"%"]}),u("span",{className:"flex items-center gap-0.5",children:[o(Pd,{className:"h-2 w-2"}),LW(a)]}),b&&x?u("div",{className:"flex items-center gap-0.5 ml-auto",children:[o("button",{onClick:E=>{E.stopPropagation(),p?.(x.addonId,y)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors",title:`Logs: ${x.addonId}`,children:o(rt,{className:"h-2.5 w-2.5"})}),o("button",{onClick:E=>{E.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:o(yt,{className:"h-2.5 w-2.5"})})]}):l.length>0?u("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?o(Nt,{className:"h-2.5 w-2.5"}):o(Et,{className:"h-2.5 w-2.5"}),o("span",{className:"text-[8px] font-medium",children:l.length})]}):null]})]}),c&&l.length>0&&!b&&o("div",{className:"border-t border-border/40 px-2 py-1 space-y-0.5 max-h-[200px] overflow-y-auto",children:l.map(E=>{const A=g?y:`${y}/${t}`;return u("div",{className:"flex items-center gap-1 py-0.5",children:[o("div",{className:`w-1 h-1 rounded-full shrink-0 ${E.status==="running"?"bg-success":"bg-muted-foreground/30"}`}),o("span",{className:"text-[9px] truncate flex-1",children:E.addonId}),o("button",{onClick:I=>{I.stopPropagation(),p?.(E.addonId,y)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors",title:`Logs: ${E.addonId}`,children:o(rt,{className:"h-2.5 w-2.5"})}),o("button",{onClick:I=>{I.stopPropagation(),h?.(E.addonId,A)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors",title:`Restart: ${E.addonId}`,children:o(yt,{className:"h-2.5 w-2.5"})})]},E.addonId)})}),o(In,{type:"source",position:we.Bottom,className:`!w-1.5 !h-1.5 ${g?"!bg-primary":"!bg-amber-500"}`})]})}const OW=He(RW),BW={clusterNode:TW,processNode:OW},fr={cluster:{width:320,height:170},process:{width:240,height:100},processExpanded:{width:240,height:240}};function zW(e){return typeof e=="object"&&e!==null&&typeof e.x=="number"&&typeof e.y=="number"}function FW(e,t){const n=new vh.graphlib.Graph;n.setGraph({rankdir:"TB",nodesep:40,ranksep:80,marginx:30,marginy:30}),n.setDefaultEdgeLabel(()=>({}));for(const s of e){const a=s.type==="processNode"&&!!s.data?.isExpanded,i=s.type==="clusterNode"?fr.cluster:a?fr.processExpanded:fr.process;n.setNode(s.id,{width:i.width,height:i.height})}for(const s of t)n.setEdge(s.source,s.target);vh.layout(n);const r=new Map;for(const s of e){const a=n.node(s.id);if(!zW(a))continue;const i=s.type==="processNode"&&!!s.data?.isExpanded,l=s.type==="clusterNode"?fr.cluster:i?fr.processExpanded:fr.process;r.set(s.id,{x:a.x-l.width/2,y:a.y-l.height/2})}return r}function jW({topology:e}){const{resolvedMode:t}=Or(),n=Kb(),r=Ma(),[,s]=P(null),[a,i]=P(()=>e.length<=1?new Set(e.map(E=>E.id)):new Set),[l,c]=P(null),[d,f]=P(null),p=U((E,A)=>{f(I=>I?.addonId===E&&I?.agentId===A?null:{addonId:E,agentId:A})},[]),h=U(E=>{f(A=>A?.agentId===E&&!A?.addonId?null:{agentId:E})},[]),m=U(async E=>{try{await n.mutateAsync({nodeId:E})}catch(A){console.error("Failed to restart node:",A)}},[n]),g=U(async(E,A)=>{try{await r.mutateAsync({nodeId:A,addonId:E})}catch(I){console.error("Failed to restart addon:",I)}},[r]),b=U(E=>{i(A=>{const I=new Set(A);return I.has(E)?I.delete(E):I.add(E),I})},[]),x=U(E=>{c(A=>A===E?null:E)},[]),y=U(E=>{s(E)},[]),w=q(()=>{const E=e.filter(M=>M.isHub),A=e.filter(M=>!M.isHub),I=[],z=[],$=E[0]?.id;function B(M,T){const _=[...T];if(_.length!==0)for(const L of _){const O=`proc:${M}/${L.name}`,j=L.services??[],F=l===O;I.push({id:O,type:"processNode",position:{x:0,y:0},data:{...L,addonId:L.name.includes("(core)")?void 0:j.length>1?L.name:j[0]?.addonId??L.name,parentNodeId:M,services:j,isExpanded:F,onToggleServices:()=>x(O),onShowLogs:p,onRestartAddon:g}}),z.push({id:`edge:${M}-${O}`,source:M,target:O,animated:!0,style:{stroke:"var(--amber-500, #f59e0b)",strokeWidth:1,strokeDasharray:"4 4"}})}}for(const M of E)I.push({id:M.id,type:"clusterNode",position:{x:0,y:0},data:{...M,label:M.name,isExpanded:a.has(M.id),onToggleExpand:()=>b(M.id),onShowDetail:()=>y(M.id),onShowNodeLogs:()=>h(M.id),onRestartNode:()=>m(M.id)}}),a.has(M.id)&&B(M.id,M.processes??[]);for(const M of A)I.push({id:M.id,type:"clusterNode",position:{x:0,y:0},data:{...M,label:M.name,isExpanded:a.has(M.id),onToggleExpand:()=>b(M.id),onShowDetail:()=>y(M.id),onShowNodeLogs:()=>h(M.id),onRestartNode:()=>m(M.id)}}),$&&M.isOnline&&z.push({id:`${$}-${M.id}`,source:$,target:M.id,animated:!0,style:{stroke:"var(--border)",strokeWidth:1.5}}),a.has(M.id)&&B(M.id,M.processes??[]);const R=FW(I,z);for(const M of I){const T=R.get(M.id);T&&(M.position=T)}return{nodes:I,edges:z}},[e,a,l,b,x,y,p,h,m,g]),v=ne(new Map),N=q(()=>{const E=v.current;return w.nodes.map(I=>({...I,position:E.get(I.id)??I.position}))},[w.nodes]),k=U(E=>{for(const A of E)A.type==="position"&&A.position&&v.current.set(A.id,A.position)},[]),C=U(()=>s(null),[]);return o("div",{className:"flex flex-col gap-4 flex-1",children:u("div",{className:"relative flex-1 min-h-[350px] border border-border rounded-xl overflow-hidden",children:[u(LQ,{nodes:N,edges:w.edges,onNodesChange:k,onPaneClick:C,nodeTypes:BW,nodesConnectable:!1,fitView:!0,fitViewOptions:{padding:.2,maxZoom:1.2},proOptions:{hideAttribution:!0},className:"bg-background",colorMode:t,children:[o(FQ,{gap:20,size:1}),o(GQ,{showInteractive:!1})]}),d&&o(ky,{addonId:d.addonId,agentId:d.agentId,showScope:!0,onClose:()=>f(null)})]})})}function HW({onlineNodeIds:e}){const t=ke(),n=Je(),{data:r,isLoading:s}=jr(),a=xx({onSuccess:()=>{t.invalidateQueries({queryKey:[["pipelineOrchestrator","listAgentSettings"]]})}}),i=q(()=>{if(!r)return[];const c=new Set(e);return c.add("hub"),r.filter(d=>!c.has(d.nodeId))},[r,e]);if(s)return o("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?o("section",{className:"rounded-lg border border-border bg-surface p-6",children:u("div",{className:"flex flex-col items-center gap-2 text-center text-muted-foreground",children:[o(_l,{className:"h-6 w-6 opacity-40"}),o("p",{className:"text-xs",children:"No stale agent entries."}),o("p",{className:"text-[11px] opacity-60",children:"Every persisted nodeId matches a node currently online in the cluster."})]})}):u("section",{className:"rounded-lg border border-border bg-surface",children:[u("header",{className:"flex items-center gap-2 px-4 py-3 border-b border-border",children:[o(_l,{className:"h-4 w-4 text-muted-foreground"}),o("h2",{className:"text-sm font-semibold",children:"Offline agents"}),u("span",{className:"ml-auto text-[11px] text-muted-foreground",children:[i.length," stale ",i.length===1?"entry":"entries"]})]}),o("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."}),o("ul",{className:"divide-y divide-border",children:i.map(c=>{const d=Object.keys(c.settings.addonDefaults??{}).length,f=Object.values(c.settings.addonDefaults??{}).filter(p=>p?.enabled).length;return u("li",{className:"flex items-center gap-3 px-4 py-2 text-xs",children:[o("span",{className:"font-mono text-foreground",children:c.nodeId}),u("span",{className:"text-muted-foreground",children:[d," addons configured",d>0&&u(me,{children:[" · ",f," enabled"]})]}),u("button",{type:"button",onClick:()=>{l(c.nodeId)},disabled:a.isPending,className:"ml-auto flex items-center gap-1 px-2 py-1 rounded text-destructive hover:bg-destructive/10 disabled:opacity-50",children:[o(Ke,{className:"h-3 w-3"}),"Remove"]})]},c.nodeId)})})]})}function VW(e){const[t,n]=P(()=>typeof window<"u"?window.matchMedia(e).matches:!1);return Y(()=>{const r=window.matchMedia(e),s=a=>n(a.matches);return r.addEventListener("change",s),()=>r.removeEventListener("change",s)},[e]),t}function qW(){const{data:e,isLoading:t}=Dn(void 0,{staleTime:1/0}),[n,r]=P(null);return pt("cluster.topology-snapshot",a=>{const i=a.data?.nodes;Array.isArray(i)&&r(i)}),{nodes:q(()=>n??e??[],[n,e]),isLoading:t&&!n}}function UW(){const[e,t]=P("diagram"),n=VW("(max-width: 767px)"),r=n&&e==="diagram"?"table":e,{nodes:s,isLoading:a}=qW(),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}=jr(),f=q(()=>{if(!d)return 0;const h=new Set(c);return h.add("hub"),d.filter(m=>!h.has(m.nodeId)).length},[d,c]),p=(h,m,g,b)=>u("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:[o(g,{className:"h-3.5 w-3.5"}),m,b!==void 0&&b>0&&o("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 u("div",{className:"flex flex-col h-full gap-4 p-4",children:[u("div",{className:"flex items-center justify-between",children:[u("div",{className:"flex items-center gap-2",children:[i>0&&u("span",{className:"text-xs px-2 py-0.5 rounded-full bg-success/10 text-success",children:[i," online"]}),l>0&&u("span",{className:"text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive",children:[l," offline"]})]}),u("div",{className:"flex gap-0.5 p-1 rounded-lg bg-muted",children:[!n&&p("diagram","Diagram",Mn),p("table","Table",$6),p("offline-agents","Offline agents",_l,f)]})]}),a?o("div",{className:"flex items-center justify-center flex-1 text-muted-foreground",children:"Loading cluster topology..."}):r==="diagram"?o(jW,{topology:s}):r==="table"?o("div",{className:"flex-1 overflow-auto",children:o(Jz,{nodes:s})}):o("div",{className:"flex-1 overflow-auto",children:o(HW,{onlineNodeIds:c})})]})}function rn({title:e,children:t}){return u("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[o("div",{className:"border-b border-border px-4 py-2.5",children:o("h2",{className:"text-xs font-semibold text-foreground uppercase tracking-wider",children:e})}),o("div",{className:"p-4",children:t})]})}function tt({name:e,cssVar:t,hex:n}){const r=t?`var(${t})`:n;return u("div",{className:"flex flex-col items-center gap-1.5",children:[o("div",{className:"h-10 w-10 rounded-lg border border-border shadow-inner",style:{backgroundColor:r}}),o("span",{className:"text-[10px] text-foreground-subtle text-center leading-tight",children:e})]})}const QW={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 GW(){const[e,t]=P({name:"Example",count:10,enabled:!0,mode:"a",tags:["camera"],confidence:60});return u("div",{className:"p-6 space-y-6 max-w-5xl mx-auto",children:[u("div",{className:"mb-6",children:[o("h1",{className:"text-xl font-bold text-foreground",children:"Component Showroom"}),o("p",{className:"text-sm text-foreground-subtle mt-1",children:"All UI components at a glance"})]}),o(rn,{title:"Typography",children:u("div",{className:"space-y-3",children:[o("h1",{className:"text-2xl font-bold text-foreground",children:"Heading 1 — Display title"}),o("h2",{className:"text-xl font-semibold text-foreground",children:"Heading 2 — Section title"}),o("h3",{className:"text-base font-semibold text-foreground",children:"Heading 3 — Card title"}),o("h4",{className:"text-sm font-semibold text-foreground",children:"Heading 4 — Sub-section"}),o("p",{className:"text-sm text-foreground",children:"Body text — Regular paragraph content goes here. It uses the foreground color."}),o("p",{className:"text-sm text-foreground-subtle",children:"Subtle text — Secondary/descriptive text with reduced emphasis."}),o("p",{className:"text-xs text-foreground-subtle uppercase tracking-wider font-semibold",children:"Label / Caption"}),o("p",{className:"text-xs text-foreground-disabled",children:"Disabled / placeholder text"})]})}),o(rn,{title:"Colors",children:u("div",{className:"flex flex-wrap gap-4",children:[o(tt,{name:"primary",cssVar:"--color-primary"}),o(tt,{name:"background",cssVar:"--color-background"}),o(tt,{name:"surface",cssVar:"--color-surface"}),o(tt,{name:"foreground",cssVar:"--color-foreground"}),o(tt,{name:"success",cssVar:"--color-success"}),o(tt,{name:"warning",cssVar:"--color-warning"}),o(tt,{name:"danger",cssVar:"--color-danger"}),o(tt,{name:"info",cssVar:"--color-info"}),o(tt,{name:"border",cssVar:"--color-border"}),o("div",{className:"w-px"}),o(tt,{name:"frigate",hex:"#3b82f6"}),o(tt,{name:"scrypted",hex:"#a855f7"}),o(tt,{name:"reolink",hex:"#06b6d4"}),o(tt,{name:"ha",hex:"#22d3ee"}),o(tt,{name:"rtsp",hex:"#78716c"})]})}),o(rn,{title:"Buttons",children:u("div",{className:"flex flex-wrap gap-3",children:[o("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"}),o("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"}),o("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"}),o("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"}),o("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"}),o("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"})]})}),o(rn,{title:"Inputs",children:u("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u("div",{children:[o("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Text input"}),o("input",{type:"text",className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30",placeholder:"Type something..."})]}),u("div",{children:[o("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Number input"}),o("input",{type:"number",className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30",placeholder:"0"})]}),u("div",{children:[o("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Password input"}),o("input",{type:"password",className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30",placeholder:"••••••••"})]}),u("div",{children:[o("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Select"}),u("select",{className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30",children:[o("option",{children:"Option A"}),o("option",{children:"Option B"}),o("option",{children:"Option C"})]})]}),u("div",{className:"md:col-span-2",children:[o("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Textarea"}),o("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})]}),o("div",{children:u("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[o("input",{type:"checkbox",className:"h-3.5 w-3.5 rounded border-border accent-primary",defaultChecked:!0}),o("span",{className:"text-xs font-medium text-foreground",children:"Checkbox (checked)"})]})}),o("div",{children:u("div",{className:"flex items-center justify-between",children:[o("span",{className:"text-xs font-medium text-foreground",children:"Toggle switch"}),o(KW,{})]})}),u("div",{children:[o("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Slider"}),o("input",{type:"range",className:"w-full h-1 accent-primary cursor-pointer",min:0,max:100,defaultValue:60})]}),u("div",{children:[o("label",{className:"block text-xs font-medium text-foreground mb-1",children:"Tags example"}),o("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=>o("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))})]})]})}),o(rn,{title:"Badges",children:u("div",{className:"space-y-3",children:[u("div",{children:[o("p",{className:"text-xs text-foreground-subtle mb-2",children:"StatusBadge"}),o("div",{className:"flex flex-wrap gap-2",children:["running","stopped","error","online","offline","idle"].map(n=>o(Ha,{status:n},n))})]}),u("div",{children:[o("p",{className:"text-xs text-foreground-subtle mb-2",children:"CapabilityBadges"}),o(Fa,{capabilities:["streaming","detection","recording","audio"]})]})]})}),o(rn,{title:"Cards",children:u("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[u("div",{className:"rounded-lg bg-surface p-4",children:[o("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Surface card"}),o("p",{className:"text-xs text-foreground-subtle",children:"Uses `bg-surface`. Default card background."})]}),u("div",{className:"rounded-lg border border-border bg-surface p-4",children:[o("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Bordered card"}),o("p",{className:"text-xs text-foreground-subtle",children:"Uses `border border-border bg-surface`."})]}),u("div",{className:"rounded-lg border border-primary/30 bg-primary/5 p-4",children:[o("h3",{className:"text-sm font-semibold text-primary mb-1",children:"Accent card"}),o("p",{className:"text-xs text-foreground-subtle",children:"Highlighted with primary color."})]}),u("div",{className:"rounded-lg bg-background p-4",children:[o("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Background card"}),o("p",{className:"text-xs text-foreground-subtle",children:"Uses `bg-background`. Inset card."})]})]})}),o(rn,{title:"Provider Icons",children:o("div",{className:"flex flex-wrap gap-4",children:["frigate","scrypted","reolink","homeassistant","rtsp","onvif"].map(n=>o(un,{type:n,size:"lg",showLabel:!0},n))})}),u(rn,{title:"Form Builder Demo",children:[o(En,{schema:QW,values:e,onChange:t}),u("details",{className:"mt-3",children:[o("summary",{className:"text-[10px] text-foreground-subtle cursor-pointer hover:text-foreground",children:"View current values"}),o("pre",{className:"mt-2 rounded-md bg-background p-3 text-[10px] text-foreground-subtle overflow-auto",children:JSON.stringify(e,null,2)})]})]}),o(rn,{title:"Info Boxes",children:o("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:r,content:s})=>{const i={info:{border:"border-info",bg:"bg-info/5",text:"text-info"},warning:{border:"border-warning",bg:"bg-warning/5",text:"text-warning"},success:{border:"border-success",bg:"bg-success/5",text:"text-success"},danger:{border:"border-danger",bg:"bg-danger/5",text:"text-danger"}}[n];return u("div",{className:`rounded-md border-l-4 px-3 py-2.5 ${i.border} ${i.bg}`,children:[o("p",{className:`text-xs font-semibold mb-0.5 ${i.text}`,children:r}),o("p",{className:"text-xs text-foreground-subtle leading-relaxed",children:s})]},n)})})})]})}function KW(){const[e,t]=P(!0);return o("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:o("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 wh={info:{bg:"bg-blue-500/10",border:"border-blue-500/30",icon:kn},warning:{bg:"bg-orange-500/10",border:"border-orange-500/30",icon:ut},critical:{bg:"bg-red-500/10",border:"border-red-500/30",icon:Mr}};function WW({toast:e,onDismiss:t}){const n=wh[e.severity]??wh.info,r=n.icon;return Y(()=>{const s=e.duration??5e3;if(s<=0)return;const a=setTimeout(()=>t(e.id),s);return()=>clearTimeout(a)},[e.id,e.duration,t]),u("div",{className:`flex items-start gap-3 px-4 py-3 rounded-lg border ${n.border} ${n.bg} shadow-lg backdrop-blur-sm animate-in slide-in-from-right-5 fade-in duration-200`,children:[o(r,{className:"h-4 w-4 shrink-0 mt-0.5 text-foreground-subtle"}),u("div",{className:"flex-1 min-w-0",children:[o("div",{className:"text-xs font-semibold text-foreground",children:e.title}),o("div",{className:"text-[11px] text-foreground-subtle mt-0.5",children:e.message})]}),o("button",{type:"button",onClick:()=>t(e.id),className:"shrink-0 p-0.5 rounded hover:bg-surface-hover transition-colors",children:o(Fe,{className:"h-3.5 w-3.5 text-foreground-subtle"})})]})}function YW(){const[e,t]=P([]),n=U(r=>{t(s=>s.filter(a=>a.id!==r))},[]);return qx(void 0,{onData:r=>{const s=r,a=`toast-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;t(i=>[...i,{...s,id:a,timestamp:Date.now()}])}}),e.length===0?null:o("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(r=>o("div",{className:"pointer-events-auto",children:o(WW,{toast:r,onDismiss:n})},r.id))})}const ac=new Ih({defaultOptions:{queries:{staleTime:3e4,retry:!1,refetchOnWindowFocus:!1}}});function ZW({field:e,value:t,onChange:n,disabled:r}){return o(W6,{field:e,value:t,onChange:n,disabled:r})}function XW({field:e,value:t,onChange:n,disabled:r}){return o(sO,{field:e,value:t,onChange:n,disabled:r})}const JW={"zone-editor":nL,"live-stats":oL,"pipeline-editor":ZW,"model-selector":XW,"live-stream-viewer":iO,"pipeline-stats":lO,"stream-network-stats":cO,"doorbell-recent":uO,"device-info":y0};function eY({children:e}){const{user:t}=mn(),[n,r]=P(0),s=ne(t?.username??null);Y(()=>{const p=t?.username??null;p!==s.current&&(s.current=p,mr(),r(h=>h+1))},[t]);const a=q(()=>Rs(),[n]),[i,l]=P(!1),[c,d]=P(null);Y(()=>{if(l(!1),d(null),!t){l(!0);return}let p=!1;return a.init().then(()=>{p||l(!0)},h=>{if(p)return;const m=h instanceof Error?h.message:String(h);d(m),l(!0)}),()=>{p=!0}},[a,t]);const f=U(()=>{mr(),r(p=>p+1),ac.invalidateQueries()},[]);return ZT(f),o(_c,{system:a,children:o(S.Provider,{client:a.trpcClient,queryClient:ac,children:u(ly,{children:[i?e:o(tY,{}),c!==null&&i&&u("div",{className:"fixed bottom-4 right-4 z-50 max-w-sm rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning shadow-lg",children:["Boot probe failed: ",c,". Retrying in background."]})]})})})}function tY(){return o("div",{className:"flex min-h-screen items-center justify-center bg-background",children:u("div",{className:"flex items-center gap-3 text-sm text-foreground-subtle",children:[o("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary/30 border-t-primary"}),"Connecting…"]})})}function nY(){return o(Vs,{defaultMode:"dark",children:o(Ah,{client:ac,children:o(IO,{children:o(eY,{children:o(dg,{children:u(Pg,{renderers:JW,children:[o(FT,{children:u(mT,{children:[o(De,{path:"/login",element:o(_8,{})}),o(De,{path:"/change-password",element:o(At,{children:o(D8,{})})}),o(De,{path:"/access-denied",element:o(T8,{})}),o(De,{path:"/showroom",element:o(GW,{})}),u(De,{element:o(At,{children:o(P8,{})}),children:[o(De,{index:!0,element:o(xt,{to:"/dashboard",replace:!0})}),o(De,{path:"/dashboard",element:o(U8,{})}),o(De,{path:"/devices",element:o(Q8,{})}),o(De,{path:"/cameras",element:o(xt,{to:"/devices",replace:!0})}),o(De,{path:"/integrations",element:o(r9,{})}),o(De,{path:"/integrations/:integrationId",element:o(a9,{})}),o(De,{path:"/timeline",element:o(g9,{})}),o(De,{path:"/pipeline",element:o(Z9,{})}),o(De,{path:"/devices/:deviceId",element:o(Y7,{})}),o(De,{path:"/system/logs",element:o(At,{requireAdmin:!0,children:o(dB,{})})}),o(De,{path:"/system/addons",element:o(At,{requireAdmin:!0,children:o(iB,{})})}),o(De,{path:"/system/settings",element:o(At,{requireAdmin:!0,children:o(Oz,{})})}),o(De,{path:"/system/cluster",element:o(At,{requireAdmin:!0,children:o(UW,{})})}),o(De,{path:"/system/identity",element:o(At,{requireAdmin:!0,children:o(EB,{})})}),o(De,{path:"/system/my-access",element:o(cB,{})}),o(De,{path:"/system/network",element:o(At,{requireAdmin:!0,children:o(LB,{})})}),o(De,{path:"/system/integrations",element:o(At,{requireAdmin:!0,children:o(WB,{})})}),o(De,{path:"/system/data",element:o(At,{requireAdmin:!0,children:o(Rz,{})})}),o(De,{path:"/system/users",element:o(xt,{to:"/system/identity?tab=users",replace:!0})}),o(De,{path:"/system/api-keys",element:o(xt,{to:"/system/identity?tab=api-keys",replace:!0})}),o(De,{path:"/system/authentication",element:o(xt,{to:"/system/identity?tab=authentication",replace:!0})}),o(De,{path:"/system/remote-access",element:o(xt,{to:"/system/network?tab=remote-access",replace:!0})}),o(De,{path:"/system/turn",element:o(xt,{to:"/system/network?tab=turn",replace:!0})}),o(De,{path:"/system/storage",element:o(xt,{to:"/system/data?tab=storage",replace:!0})}),o(De,{path:"/system/backup",element:o(xt,{to:"/system/data?tab=backup",replace:!0})}),o(De,{path:"/addon/:pagePath",element:o(At,{requireAdmin:!0,children:o(E8,{})})})]})]})}),o(YW,{})]})})})})})})}const rY={dashboard:"Dashboard",integrations:"Integrations",metrics:"Metrics"},oY={title:"System",addons:"Addons",agents:"Agents",processes:"Processes",logs:"Logs",users:"Users",settings:"Settings",repl:"REPL",models:"Models",integrations:"Integrations"},sY={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"},aY={disconnected:"Server unreachable — reconnecting…",connected:"Connected"},iY={online:"Online",offline:"Offline",connecting:"Connecting",error:"Error",disabled:"Disabled",enabled:"Enabled",active:"Active",inactive:"Inactive",running:"Running",stopped:"Stopped",pending:"Pending",unknown:"Unknown"},lY={login:"Login",logout:"Logout",username:"Username",password:"Password",signIn:"Sign In",invalidCredentials:"Invalid username or password"},cY={dark:"Dark",light:"Light",system:"System"},dY={select:"Language",en:"English",it:"Italian"},uY={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"}},pY={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"},fY={nav:rY,system:oY,common:sY,connection:aY,status:iY,auth:lY,theme:cY,language:dY,pages:uY,integrations:pY},hY={dashboard:"Dashboard",integrations:"Integrazioni",metrics:"Metriche"},mY={title:"Sistema",addons:"Addon",agents:"Agenti",processes:"Processi",logs:"Log",users:"Utenti",settings:"Impostazioni",repl:"REPL",models:"Modelli",integrations:"Integrazioni"},gY={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"},bY={disconnected:"Server non raggiungibile — riconnessione in corso…",connected:"Connesso"},xY={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"},yY={login:"Accesso",logout:"Esci",username:"Nome utente",password:"Password",signIn:"Accedi",invalidCredentials:"Nome utente o password non validi"},vY={dark:"Scuro",light:"Chiaro",system:"Sistema"},wY={select:"Lingua",en:"Inglese",it:"Italiano"},NY={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"}},kY={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"},SY={nav:hY,system:mY,common:gY,connection:bY,status:xY,auth:yY,theme:vY,language:wY,pages:NY,integrations:kY},gw="camstack_language",CY=localStorage.getItem(gw)??"en";Ze.use(l8).init({resources:{en:{translation:fY},it:{translation:SY}},lng:CY,fallbackLng:"en",interpolation:{escapeValue:!1}});Ze.on("languageChanged",e=>{localStorage.setItem(gw,e)});window.__camstackUiLibrary=hD;window.__camstackSdk=$N;window.__camstackTypes=TN;Mh(document.getElementById("root")).render(o(vN,{children:o(nY,{})}));