@camstack/addon-admin-ui 0.1.16 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DlquBRmD.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CziSE-Do.js} +1 -1
- package/dist/assets/{devices-CVfa8e_5.js → devices-BfsgGvwu.js} +1 -1
- package/dist/assets/{hostInit-Bq0J4U4L.js → hostInit-7yPTCcmg.js} +1 -1
- package/dist/assets/{index-C5--Sp9A.js → index-BlKJSHE9.js} +2 -2
- package/dist/assets/index-C-M4yvxf.js +1 -0
- package/dist/assets/{index-BqEwAQt-.js → index-DculG9Gi.js} +2 -2
- package/dist/assets/index-DfH297U6.js +1 -0
- package/dist/assets/{index-CJH_U_aT.js → index-Dvmk3HcY.js} +1 -1
- package/dist/assets/index-K1-f6oQr.js +1 -0
- package/dist/assets/{index-Bftw8yZ0.js → index-X-IEwb-L.js} +2 -2
- package/dist/assets/index-cfq-Npln.js +1 -0
- package/dist/assets/{index-CLnkxPD7.js → index-iCcWZGKs.js} +1 -1
- package/dist/assets/index-ptcmLXsE.js +1 -0
- package/dist/assets/{remoteEntry-qFyESaJr.js → remoteEntry-Da_G1gka.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-cGbq1Btt.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-kSAHDLPS.js} +2 -2
- package/dist/index.html +3 -3
- package/dist/mf-entry-bootstrap-0.js +2 -2
- package/dist/sw.js +1 -1
- package/package.json +1 -1
- package/dist/assets/index-B3BmQjhl.js +0 -1
- package/dist/assets/index-BYRl5bfb.js +0 -1
- package/dist/assets/index-gZlh9vZc.js +0 -1
- package/dist/assets/index-o6URf7uT.js +0 -1
- package/dist/assets/index-otlbS_ZJ.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"./virtualExposes-_ivNhQLP.js";import{d as fr}from"./virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-
|
|
1
|
+
import"./virtualExposes-_ivNhQLP.js";import{d as fr}from"./virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-kSAHDLPS.js";import{c as r,a as $f,d as u,e as ve,g as q1}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_1_jsx_mf_2_runtime__loadShare__.mjs-C_6K4VBY.js";import{b as Oe,e as $,h as q,c as Y,f as Q,d as ye,a as _f,j as Ve,k as Me,i as ne,l as mr,m as Gs,g as Ws,R as Al,n as Pl,o as Q1,p as U1,q as hr,r as Fe,s as K1,t as G1,u as W1,v as Y1}from"./__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs-Dl4u0xYE.js";import{a as Df,b as vo}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs-CzO_Esxm.js";import{a as Lf,b as Tf}from"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.mjs-DNpf5SLz.js";import{_ as Rf,m as Kn,n as ke,o as Of,p as zf,h as El,j as Z1}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.mjs-CeLhKMin.js";import{_ as Bf,c as Ff,s as jf,n as X1,B as J1,F as ew}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_client__loadShare__.mjs-DIkg6-MH.js";import{_ as Hf,a as tw}from"./__mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.mjs-OcRSBqRe.js";import{c as nw,D as Rn,a as at,M as rw,W as $i,S as us}from"./auth-records-BEfan3dC.js";import{S as _i,c as Vf}from"./devices-BfsgGvwu.js";import{E as Ne,A as ow,C as sw}from"./capability-router-map-B3jHfbHt.js";import{s as aw}from"./index-Dvmk3HcY.js";import{a as Pd,S as Ed,s as iw}from"./index-DfH297U6.js";import{r as qf}from"./__mfe_internal__admin_ui_host__loadShare__react__loadShare__.mjs_commonjs-proxy-CSyOECfO.js";import"./preload-helper-BlTxHScW.js";import"./__mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-xw6c6JeS.js";import"./schemas-XgIEoUz3.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))o(s);new MutationObserver(s=>{for(const a of s)if(a.type==="childList")for(const i of a.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&o(i)}).observe(document,{childList:!0,subtree:!0});function n(s){const a={};return s.integrity&&(a.integrity=s.integrity),s.referrerPolicy&&(a.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?a.credentials="include":s.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function o(s){if(s.ep)return;s.ep=!0;const a=n(s);fetch(s.href,a)}})();const Qf={frigate:"#3b82f6",scrypted:"#a855f7",reolink:"#06b6d4",homeAssistant:"#22d3ee",rtsp:"#78716c"},Uf={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:Qf},Kf={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:Qf},Di={colors:{dark:Uf,light:Kf},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 Gf(e,t){const n={...e};for(const o in t){const s=t[o],a=e[o];s!==void 0&&typeof s=="object"&&s!==null&&!Array.isArray(s)&&typeof a=="object"&&a!==null?n[o]=Gf(a,s):s!==void 0&&(n[o]=s)}return n}function lw(e){return e?Gf(structuredClone(Di),e):structuredClone(Di)}function Wf(e){return e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function cw(e){return`--color-${Wf(e)}`}function $d(e){const t=[];for(const[n,o]of Object.entries(e))n!=="provider"&&t.push(` ${cw(n)}: ${o};`);return t.join(`
|
|
2
2
|
`)}function dw(e){const t=[];for(const[n,o]of Object.entries(e))t.push(` --color-provider-${Wf(n)}: ${o};`);return t.join(`
|
|
3
3
|
`)}function uw(e){const t=[];for(const[n,o]of Object.entries(e))t.push(` --spacing-${n}: ${o}px;`);return t.join(`
|
|
4
4
|
`)}function pw(e){const t=[];for(const[n,o]of Object.entries(e))t.push(` --radius-${n}: ${o}px;`);return t.join(`
|
|
@@ -527,7 +527,7 @@ ${n.replace(/^ {2}/gm," ")}
|
|
|
527
527
|
*
|
|
528
528
|
* This source code is licensed under the ISC license.
|
|
529
529
|
* See the LICENSE file in the root directory of this source tree.
|
|
530
|
-
*/const c5=[["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"}]],d5=ce("zoom-out",c5),u5={frigate:Lk,scrypted:_k,reolink:xk,homeAssistant:Im,rtsp:o2},p5={online:m2,offline:k2,degraded:Zs,unknown:vm},Ud=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,Kd=Jf,Zn=(e,t)=>n=>{var o;if(t?.variants==null)return Kd(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 m=Ud(f)||Ud(p);return s[d][m]}),l=n&&Object.entries(n).reduce((d,f)=>{let[p,m]=f;return m===void 0||(d[p]=m),d},{}),c=t==null||(o=t.compoundVariants)===null||o===void 0?void 0:o.reduce((d,f)=>{let{class:p,className:m,...h}=f;return Object.entries(h).every(g=>{let[b,x]=g;return Array.isArray(x)?x.includes({...a,...l}[b]):{...a,...l}[b]===x})?[...d,p,m]:d},[]);return Kd(e,i,c,n?.class,n?.className)},f5=Zn("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"}}),He=Ve(({className:e,variant:t,size:n,...o},s)=>r("button",{ref:s,className:K(f5({variant:t,size:n}),e),...o}));He.displayName="Button";const m5=Zn("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"}}),Bl=Ve(({className:e,variant:t,size:n,icon:o,...s},a)=>r("button",{ref:a,className:K(m5({variant:t,size:n}),e),...s,children:r(o,{className:"h-4 w-4"})}));Bl.displayName="IconButton";const h5=Zn("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"}}),cr=Ve(({className:e,variant:t,style:n,...o},s)=>r("span",{ref:s,className:K(h5({variant:t,styleVariant:n}),e),...o}));cr.displayName="Badge";const g5=Zn("rounded-lg p-3",{variants:{variant:{flat:"bg-surface",bordered:"bg-surface border border-border"}},defaultVariants:{variant:"bordered"}}),Ge=Ve(({className:e,variant:t,...n},o)=>r("div",{ref:o,className:K(g5({variant:t}),e),...n}));Ge.displayName="Card";function Om({expanded:e,onExpandedChange:t,header:n,children:o,dimmed:s=!1,hideChevron:a=!1,className:i}){return u("div",{className:K("rounded-lg border border-border bg-surface overflow-hidden",s&&"opacity-[0.45]",i),children:[u("div",{role:"button",tabIndex:0,className:"flex items-center gap-2.5 px-3 py-2.5 cursor-pointer select-none",onClick:()=>t(!e),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),t(!e))},children:[!a&&r("span",{className:"text-foreground-subtle shrink-0",children:e?r(Yn,{className:"h-4 w-4"}):r(Cn,{className:"h-4 w-4"})}),n]}),e&&o&&r("div",{className:"border-t border-border px-3 py-3",children:o})]})}const Fl=Ve(({className:e,...t},n)=>r("label",{ref:n,className:K("text-[10px] uppercase tracking-wider text-foreground-muted font-medium",e),...t}));Fl.displayName="Label";const b5=Zn("",{variants:{orientation:{horizontal:"h-px w-full bg-border-subtle",vertical:"w-px h-full bg-border-subtle"}},defaultVariants:{orientation:"horizontal"}}),jl=Ve(({className:e,orientation:t,...n},o)=>r("div",{ref:o,role:"separator",className:K(b5({orientation:t}),e),...n}));jl.displayName="Separator";const zm=Ve(({className:e,...t},n)=>r("div",{ref:n,className:K("animate-pulse bg-surface-hover rounded-md h-4 w-full",e),...t}));zm.displayName="Skeleton";const Gd=Zn("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"}}),Ss=Ve(({className:e,state:t,leftSlot:n,rightSlot:o,...s},a)=>n||o?u("div",{className:"relative flex items-center w-full",children:[n&&r("div",{className:"absolute left-2.5 flex items-center pointer-events-none",children:n}),r("input",{ref:a,className:K(Gd({state:t}),n?"pl-7":"",o?"pr-7":"",e),...s}),o&&r("div",{className:"absolute right-2.5 flex items-center pointer-events-none",children:o})]}):r("input",{ref:a,className:K(Gd({state:t}),e),...s}));Ss.displayName="Input";const Cs=Ve(({className:e,options:t,...n},o)=>u("div",{className:"relative w-full",children:[r("select",{ref:o,className:K("h-7 w-full px-2.5 text-xs bg-surface border border-border rounded-md text-foreground appearance-none pr-7 focus:outline-none focus:ring-1 focus:ring-primary",e),...n,children:t.map(s=>r("option",{value:s.value,children:s.label},s.value))}),r("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none text-foreground-muted",children:r(Yn,{className:"h-3.5 w-3.5"})})]}));Cs.displayName="Select";const Bm=Ve(({className:e,...t},n)=>r("input",{ref:n,type:"checkbox",className:K("w-3.5 h-3.5 rounded-sm border border-border accent-primary",e),...t}));Bm.displayName="Checkbox";const Hl=Ve(({className:e,checked:t,onCheckedChange:n,label:o,...s},a)=>u("button",{ref:a,role:"switch","aria-checked":t,type:"button",onClick:()=>n(!t),className:K("inline-flex items-center gap-2",e),...s,children:[r("span",{className:K("w-8 h-4 rounded-full transition-colors",t?"bg-primary":"bg-surface-hover"),children:r("span",{className:K("block w-3.5 h-3.5 rounded-full bg-white transition-transform",t?"translate-x-4":"translate-x-0.5")})}),o&&r("span",{className:"text-xs text-foreground",children:o})]}));Hl.displayName="Switch";const Fm=Oe(null);function jm(){const e=ye(Fm);if(!e)throw new Error("Dialog compound components must be used within <Dialog>");return e}function Hm({children:e,open:t,onOpenChange:n}){const[o,s]=$(!1),a=t??o,i=mr(),l=q(c=>{n?.(c),t===void 0&&s(c)},[t,n]);return r(Fm.Provider,{value:{open:a,setOpen:l,contentId:i},children:e})}function x5({children:e,...t}){const{setOpen:n}=jm();return r("button",{type:"button",onClick:()=>n(!0),...t,children:e})}const y5=Zn("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"}}),Vl=Ve(({className:e,width:t,children:n,...o},s)=>{const{open:a,setOpen:i,contentId:l}=jm(),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 r("dialog",{ref:d,id:l,className:K(y5({width:t}),"w-full",e),onClick:f,onClose:()=>i(!1),...o,children:n})});Vl.displayName="DialogContent";function Vm({className:e,...t}){return r("div",{className:K("flex flex-col gap-1 mb-3",e),...t})}function qm({className:e,...t}){return r("div",{className:K("flex justify-end gap-2 mt-4",e),...t})}function Qm({className:e,...t}){return r("h2",{className:K("text-sm font-semibold text-foreground",e),...t})}function Um({className:e,...t}){return r("p",{className:K("text-xs text-foreground-muted",e),...t})}const Km=Oe(null);function ql(){const e=ye(Km);if(!e)throw new Error("Dropdown compound components must be used within <Dropdown>");return e}function Gm({children:e}){const[t,n]=$(!1),o=mr(),s=mr(),a=ne(null);return r(Km.Provider,{value:{open:t,setOpen:n,triggerId:o,contentId:s,triggerRef:a},children:r("div",{className:"relative inline-block",children:e})})}function Wm({children:e,...t}){const{open:n,setOpen:o,triggerId:s,contentId:a,triggerRef:i}=ql();return r("button",{type:"button",ref:i,id:s,"aria-haspopup":"menu","aria-expanded":n,"aria-controls":n?a:void 0,onClick:()=>o(!n),...t,children:e})}function Ym({className:e,children:t,align:n="start",offset:o=4,...s}){const{open:a,setOpen:i,contentId:l,triggerId:c,triggerRef:d}=ql(),f=ne(null),[p,m]=$(null);if(Gs(()=>{if(!a){m(null);return}const g=()=>{const b=d.current;if(!b)return;const x=b.getBoundingClientRect(),v=n==="end"?x.right:x.left;m({top:x.bottom+o,left:v,minWidth:x.width})};return g(),window.addEventListener("resize",g),window.addEventListener("scroll",g,!0),()=>{window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0)}},[a,n,o,d]),Y(()=>{if(!a)return;const g=x=>{const v=f.current,w=d.current;v&&!v.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 h={position:"fixed",top:p.top,...n==="end"?{right:window.innerWidth-p.left}:{left:p.left},minWidth:p.minWidth};return vo(r("div",{ref:f,id:l,role:"menu","aria-labelledby":c,style:h,className:K("z-50 bg-background-elevated border border-border rounded-md shadow-lg py-1 min-w-[160px]",e),...s,children:t}),document.body)}function Zm({className:e,icon:t,variant:n="default",children:o,onClick:s,...a}){const{setOpen:i}=ql(),l=q(c=>{s?.(c),i(!1)},[s,i]);return u("button",{type:"button",role:"menuitem",className:K("h-7 text-xs px-2 w-full text-left flex items-center gap-2",n==="danger"?"text-danger hover:bg-danger/10":"text-foreground hover:bg-surface-hover",e),onClick:l,...a,children:[t&&r(t,{size:14}),o]})}const Xm=Oe(null);function Jm(){const e=ye(Xm);if(!e)throw new Error("Tooltip compound components must be used within <Tooltip>");return e}function v5({children:e}){const[t,n]=$(!1),o=ne(null),s=mr(),a=()=>{o.current=setTimeout(()=>n(!0),300)},i=()=>{o.current&&clearTimeout(o.current),n(!1)};return r(Xm.Provider,{value:{open:t,show:a,hide:i,tooltipId:s},children:r("div",{className:"relative inline-block",children:e})})}function w5({children:e,...t}){const{show:n,hide:o,tooltipId:s,open:a}=Jm();return r("div",{onMouseEnter:n,onMouseLeave:o,onFocus:n,onBlur:o,"aria-describedby":a?s:void 0,...t,children:e})}function N5({className:e,children:t,...n}){const{open:o,tooltipId:s}=Jm();return r("div",{id:s,role:"tooltip",className:K("absolute bottom-full left-1/2 -translate-x-1/2 mb-2 bg-foreground text-background text-xs px-2 py-1 rounded-md shadow-md whitespace-nowrap pointer-events-none transition-opacity duration-150",o?"opacity-100":"opacity-0",e),...n,children:t})}const Wd="(max-width: 767px)",Yd="(min-width: 768px) and (max-width: 1023px)";function eh(e){return t=>{const n=window.matchMedia(e);return n.addEventListener("change",t),()=>n.removeEventListener("change",t)}}function th(e){return()=>window.matchMedia(e).matches}function nh(){return!1}function Xn(){return Ws(eh(Wd),th(Wd),nh)}function rh(){return Ws(eh(Yd),th(Yd),nh)}function Ql({open:e,onClose:t,title:n,children:o,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(ve,{children:[r("div",{className:K("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:K("fixed inset-x-0 bottom-0 z-50 flex flex-col bg-background-elevated border-t border-border rounded-t-xl shadow-2xl transition-transform duration-200 ease-out","max-h-[80dvh]",e?"translate-y-0":"translate-y-full",s),children:[r("div",{className:"flex justify-center pt-2 pb-1",children:r("div",{className:"h-1 w-8 rounded-full bg-foreground-subtle/30"})}),n&&u("div",{className:"flex items-center justify-between px-4 pb-2",children:[r("span",{className:"text-sm font-medium text-foreground",children:n}),r("button",{onClick:t,className:"p-1 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors",children:r(Je,{className:"h-4 w-4"})})]}),r("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:o})]})]})}const oh=Oe(null);function sh(){const e=ye(oh);if(!e)throw new Error("Popover compound components must be used within <Popover>");return e}function ah({children:e,open:t,onOpenChange:n}){const[o,s]=$(!1),a=t??o,i=mr(),l=mr(),c=q(d=>{n?.(d),t===void 0&&s(d)},[t,n]);return r(oh.Provider,{value:{open:a,setOpen:c,triggerId:i,contentId:l},children:r("div",{className:"relative inline-block",children:e})})}function ih({children:e,...t}){const{open:n,setOpen:o,triggerId:s,contentId:a}=sh();return r("button",{type:"button",id:s,"aria-haspopup":"dialog","aria-expanded":n,"aria-controls":n?a:void 0,onClick:()=>o(!n),...t,children:e})}function lh({className:e,children:t,...n}){const{open:o,setOpen:s,contentId:a,triggerId:i}=sh(),l=Xn(),c=ne(null);return Y(()=>{if(!o||l)return;const d=p=>{const m=c.current,h=document.getElementById(i);m&&!m.contains(p.target)&&!h?.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)}},[o,s,i,l]),o?l?r(Ql,{open:o,onClose:()=>s(!1),children:t}):r("div",{ref:c,id:a,role:"dialog","aria-labelledby":i,className:K("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 ch=Oe(null);function dh(){const e=ye(ch);if(!e)throw new Error("Tabs compound components must be used within <Tabs>");return e}function k5({value:e,onValueChange:t,defaultValue:n="",className:o,...s}){const[a,i]=$(n),l=e??a,c=q(d=>{t?.(d),e===void 0&&i(d)},[e,t]);return r(ch.Provider,{value:{value:l,setValue:c},children:r("div",{className:o,...s})})}function S5({className:e,...t}){return r("div",{role:"tablist",className:K("flex flex-row border-b border-border-subtle",e),...t})}function C5({value:e,className:t,...n}){const{value:o,setValue:s}=dh(),a=e===o,i=`tabpanel-${e}`;return r("button",{type:"button",role:"tab","aria-selected":a,"aria-controls":i,tabIndex:a?0:-1,className:K("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 M5({value:e,className:t,...n}){const{value:o}=dh();return e!==o?null:r("div",{role:"tabpanel",id:`tabpanel-${e}`,className:K("pt-3",t),...n})}const Ul=Ve(({className:e,...t},n)=>r("div",{ref:n,className:K("overflow-auto [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-surface-hover [&::-webkit-scrollbar-thumb]:rounded-full",e),...t}));Ul.displayName="ScrollArea";function I5({title:e,onClose:t,children:n,defaultWidth:o=360,defaultHeight:s=280,minWidth:a=280,minHeight:i=160,offsetIndex:l=0,className:c}){const[d,f]=$({x:80+l*30,y:80+l*30}),[p,m]=$({w:o,h:s}),[h,g]=$(!1),b=ne(!1),x=ne(!1),v=ne({x:0,y:0}),w=Xn(),y=q(k=>{k.preventDefault(),b.current=!0,v.current={x:k.clientX-d.x,y:k.clientY-d.y}},[d]),N=q(k=>{k.preventDefault(),k.stopPropagation(),x.current=!0,v.current={x:k.clientX,y:k.clientY}},[]);return Y(()=>{const k=M=>{if(b.current&&f({x:M.clientX-v.current.x,y:M.clientY-v.current.y}),x.current){const P=M.clientX-v.current.x,I=M.clientY-v.current.y;v.current={x:M.clientX,y:M.clientY},m(F=>({w:Math.max(a,F.w+P),h:Math.max(i,F.h+I)}))}},S=()=>{b.current=!1,x.current=!1};return window.addEventListener("mousemove",k),window.addEventListener("mouseup",S),()=>{window.removeEventListener("mousemove",k),window.removeEventListener("mouseup",S)}},[a,i]),w?u("div",{className:K("fixed inset-x-0 bottom-0 z-50 rounded-t-xl border-t border-border bg-background-elevated shadow-2xl flex flex-col overflow-hidden",c),style:{maxHeight:"60dvh"},children:[u("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b border-border shrink-0 bg-surface",children:[r("span",{className:"text-[11px] font-medium truncate",children:e}),u("div",{className:"flex items-center gap-1 shrink-0",children:[r("button",{onClick:()=>g(!h),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",children:h?r(jd,{size:12}):r(Hd,{size:12})}),r("button",{onClick:t,className:"p-0.5 rounded hover:bg-danger/20 text-foreground-muted hover:text-danger transition-colors",children:r(Je,{size:12})})]})]}),!h&&r("div",{className:"flex-1 min-h-0 overflow-y-auto",children:n})]}):u("div",{className:K("fixed z-50 rounded-lg border border-border bg-background-elevated shadow-2xl flex flex-col overflow-hidden",c),style:{left:d.x,top:d.y,width:h?280:p.w,height:h?"auto":p.h},children:[u("div",{onMouseDown:y,className:"flex items-center justify-between gap-2 px-3 py-2 border-b border-border cursor-move select-none shrink-0 bg-surface",children:[u("div",{className:"flex items-center gap-2 min-w-0",children:[r(F2,{size:12,className:"text-foreground-subtle shrink-0"}),r("span",{className:"text-[11px] font-medium truncate",children:e})]}),u("div",{className:"flex items-center gap-1 shrink-0",children:[r("button",{onClick:()=>g(!h),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",title:h?"Restore":"Minimize",children:h?r(jd,{size:12}):r(Hd,{size:12})}),r("button",{onClick:t,className:"p-0.5 rounded hover:bg-danger/20 text-foreground-muted hover:text-danger transition-colors",title:"Close",children:r(Je,{size:12})})]})]}),!h&&u("div",{className:"flex-1 min-h-0 overflow-y-auto relative",children:[n,r("div",{onMouseDown:N,className:"absolute bottom-0 right-0 w-4 h-4 cursor-nwse-resize",style:{background:"linear-gradient(135deg, transparent 50%, var(--color-foreground-subtle) 50%)",opacity:.4}})]})]})}function Kl({open:e,onClose:t,children:n,className:o,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(ve,{children:[r("div",{className:K("fixed inset-0 z-40 bg-black/50 backdrop-blur-sm transition-opacity duration-200",e?"opacity-100":"pointer-events-none opacity-0"),onClick:t,"aria-hidden":"true"}),r("div",{ref:a,role:"dialog","aria-modal":"true",className:K("fixed inset-y-0 left-0 z-50 flex flex-col bg-surface border-r border-border shadow-2xl transition-transform duration-200 ease-out",s,e?"translate-x-0":"-translate-x-full",o),children:n})]})}function Gl({items:e,className:t}){return r("nav",{className:`flex items-center gap-1 text-[11px] text-foreground-subtle ${t??""}`,children:e.map((n,o)=>{const s=o===e.length-1,a=!s&&(n.onClick||n.href);return u(Al.Fragment,{children:[o>0&&r(Cn,{className:"h-3 w-3 flex-shrink-0"}),a?n.onClick?r("button",{type:"button",onClick:n.onClick,className:"hover:text-foreground transition-colors",children:n.label}):r("a",{href:n.href,className:"hover:text-foreground transition-colors",children:n.label}):r("span",{className:s?"text-foreground font-medium":"",children:n.label})]},o)})})}const Zd={left:"text-left",right:"text-right",center:"text-center"};function uh({columns:e,rows:t,rowKey:n,onRowClick:o,minWidthPx:s=480,emptyMessage:a,className:i,bordered:l=!0,rowClassName:c}){if(t.length===0&&a)return r("div",{className:`rounded-lg ${l?"border border-border":""} bg-surface px-3 py-4 text-xs text-foreground-subtle text-center ${i??""}`,children:a});if(t.length===0)return null;const d=`rounded-lg ${l?"border border-border":""} bg-surface overflow-x-auto ${i??""}`;return r("div",{className:d,children:u("table",{className:"w-full text-xs",style:{minWidth:`${s}px`},children:[r("thead",{className:"bg-surface",children:r("tr",{children:e.map(f=>{const p=f.align??"left",m=f.nowrap??!0;return r("th",{className:["px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border",Zd[p],m?"whitespace-nowrap":"",f.width??""].filter(Boolean).join(" "),children:f.headerRender?f.headerRender():f.header},f.key)})})}),r("tbody",{children:t.map((f,p)=>{const m=n?n(f,p):p,h=c?.(f,p)??"",g=o!==void 0;return r("tr",{onClick:g?()=>o(f,p):void 0,className:[g?"cursor-pointer hover:bg-primary/5":"hover:bg-primary/5",h].filter(Boolean).join(" "),children:e.map(b=>{const x=b.align??"left",v=b.nowrap??!1;return r("td",{className:["px-3 py-2 text-foreground border-b border-border",Zd[x],v?"whitespace-nowrap":""].filter(Boolean).join(" "),children:b.render(f,p)},b.key)})},m)})})]})})}function Wl({open:e,onClose:t,title:n,subtitle:o,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:K("absolute top-0 right-0 bottom-0 z-20 flex flex-col","bg-surface border-l border-border shadow-xl",i),role:"dialog","aria-modal":"false",children:[u("header",{className:"flex items-start justify-between gap-2 px-4 py-3 border-b border-border",children:[u("div",{className:"min-w-0",children:[r("div",{className:"text-sm font-semibold text-foreground truncate",children:n}),o!==void 0&&r("div",{className:"text-[11px] text-foreground-subtle mt-0.5 truncate",children:o})]}),r("button",{type:"button",onClick:t,className:"p-1 rounded hover:bg-muted text-foreground-subtle hover:text-foreground","aria-label":"Close panel",children:r(Je,{className:"w-4 h-4"})})]}),r("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3",children:a}),s!==void 0&&r("footer",{className:"flex items-center gap-2 justify-end px-4 py-3 border-t border-border",children:s})]}):null}const A5={inherit:"bg-muted",on:"bg-emerald-500",off:"bg-orange-500",na:"bg-gray-300 opacity-50"};function ph({node:e,depth:t,selectedAddonId:n,onSelect:o,agentDots:s}){const a=e.addonId===n,i=s?.[e.addonId]??[];return u("div",{children:[u("button",{type:"button",onClick:()=>o(e.addonId),className:K("w-full flex items-center justify-between gap-2 text-left px-3 py-1.5 text-xs","border-l-2",a?"bg-accent border-primary text-foreground font-medium":"border-transparent hover:bg-muted/40 text-foreground"),style:{paddingLeft:`${12+t*14}px`},children:[r("span",{className:"truncate",children:e.addonName}),i.length>0&&r("span",{className:"flex items-center gap-1 shrink-0",children:i.map(l=>r("span",{title:`${l.agentNodeId}: ${l.state}`,className:K("w-2 h-2 rounded-full",A5[l.state])},l.agentNodeId))})]}),e.children.map(l=>r(ph,{node:l,depth:t+1,selectedAddonId:n,onSelect:o,agentDots:s},l.addonId))]})}function fh({tree:e,selectedAddonId:t,onSelect:n,agentDots:o,className:s}){return r("div",{className:K("flex flex-col py-2",s),children:e.map(a=>r(ph,{node:a,depth:0,selectedAddonId:t,onSelect:n,agentDots:o},a.addonId))})}function ea(e){const t=[],n=[],o=new Map;for(const a of e.slots)for(const i of a.addons){const l={addonId:i.id,addonName:i.name,slot:i.slot,inputClasses:i.inputClasses,outputClasses:i.outputClasses,children:[]};i.slot==="audio-classifier"?t.push(l):(n.push(l),o.set(i.id,l))}const s=[];for(const a of n){if(a.inputClasses.length===0){s.push(a);continue}const i=n.find(l=>l.addonId!==a.addonId&&l.outputClasses.some(c=>a.inputClasses.includes(c)));i&&i.children.push(a)}return[...s,...t]}function P5(e){return e?e.models.map(t=>({id:t.id,name:t.name})):[]}function ps({step:e,schema:t,allSchemas:n,depth:o=0,onChange:s,onDelete:a,readOnly:i=!1,toggleMode:l="simple",overrideState:c=null,onOverrideChange:d,inheritedEnabled:f,hideModelAndSettings:p=!1}){const[m,h]=$(!1),g=P5(t);if(g.length>0&&!g.some(x=>x.id===e.modelId)&&!i){const v=(t?.defaultModelId?g.find(w=>w.id===t.defaultModelId):null)??g[0];v&&v.id!==e.modelId&&queueMicrotask(()=>s({...e,modelId:v.id}))}const b=u(ve,{children:[u("div",{className:"flex-1 min-w-0",children:[r("span",{className:"text-[10px] uppercase tracking-wider font-medium text-foreground-subtle/60 block leading-none",children:e.slot}),r("span",{className:"text-sm font-semibold text-foreground truncate block leading-tight",children:e.addonName}),u("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(x=>r("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-blue-500/12 text-blue-400",children:x},x)),e.inputClasses.length>0&&e.outputClasses.length>0&&r("span",{className:"text-foreground-subtle/40 text-[10px]",children:"→"}),e.outputClasses.map(x=>r("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-green-500/12 text-green-400",children:x},x))]})]}),!i&&l==="simple"&&r("button",{onClick:x=>{x.stopPropagation(),s({...e,enabled:!e.enabled})},className:K("relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors",e.enabled?"bg-success":"bg-foreground-subtle/30"),children:r("span",{className:K("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:[r(Fa,{label:"Inherit",active:c===null,variant:"inherit",subtext:f===void 0?void 0:f?"on":"off",onClick:()=>d(null)}),r(Fa,{label:"On",active:c===!0,variant:"on",onClick:()=>d(!0)}),r(Fa,{label:"Off",active:c===!1,variant:"off",onClick:()=>d(!1)})]})]});return r(Om,{expanded:m,onExpandedChange:h,dimmed:!e.enabled,header:b,children:p?r("p",{className:"text-[11px] text-foreground-subtle",children:"Model and detection settings are managed per agent — open the Pipeline page for this camera's agent to edit them."}):u("div",{className:"space-y-3",children:[r(Fi,{label:"Model",value:e.modelId,disabled:i,options:g.map(x=>({value:x.id,label:x.name})),onChange:x=>s({...e,modelId:x})}),e.slot==="audio-classifier"&&e.engine&&r(Fi,{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[v,w]=x.split("/");s({...e,engine:{runtime:v,backend:w,format:w==="coreml"?"coreml":"onnx"}})}}),t?.configSchema?.map(x=>r(ta,{field:x,allFields:t.configSchema??[],step:e,disabled:i,onChange:s},x.key))]})})}function Fi({label:e,value:t,options:n,disabled:o,onChange:s}){return u("div",{children:[r("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e}),u("select",{value:t,onChange:a=>s(a.target.value),disabled:o,className:"w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground focus:outline-none focus:border-primary/50",children:[n.length===0&&r("option",{value:t,children:t||"default"}),n.map(a=>r("option",{value:a.value,disabled:a.disabled,children:a.label},a.value))]})]})}function E5({label:e,description:t,value:n,options:o,disabled:s,onChange:a}){function i(l){if(s)return;const c=n.includes(l)?n.filter(d=>d!==l):[...n,l];a(c)}return u("div",{children:[r("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1",children:e}),t&&r("p",{className:"text-[10px] text-foreground-subtle/60 mb-1.5",children:t}),r("div",{className:"flex flex-wrap gap-1.5",children:o.map(l=>{const c=n.includes(l.value);return r("button",{type:"button",disabled:s,onClick:()=>i(l.value),className:K("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 $5(e,t,n){const o=t.settings?.[e];if(o!==void 0)return o;const s=n.find(a=>"key"in a&&a.key===e);return s&&"default"in s?s.default:void 0}function ta({field:e,allFields:t,step:n,disabled:o,onChange:s}){const a=e.type!=="separator"&&e.type!=="info"?e.showWhen:void 0;if(a){const{field:l,equals:c,notEquals:d,in:f,notIn:p}=a,m=$5(l,n,t);if(c!==void 0&&m!==c||d!==void 0&&m===d||f!==void 0&&!f.includes(m)||p!==void 0&&p.includes(m))return null}function i(l){s({...n,settings:{...n.settings,[e.key]:l}})}if(e.type==="select"){const l=n.settings?.[e.key],c=typeof l=="string"?l:e.default??"";return r(Fi,{label:e.label,value:c,disabled:o||e.disabled,options:e.options,onChange:i})}if(e.type==="multiselect"){const l=n.settings?.[e.key],c=Array.isArray(l)?l:Array.isArray(e.default)?e.default:[];return r(E5,{label:e.label,description:e.description,value:c,options:e.options,disabled:o||e.disabled,onChange:i})}if(e.type==="slider"||e.type==="number"){const l=n.settings?.[e.key],c=typeof e.default=="number"?e.default:e.min??0,d=typeof l=="number"?l:c,f=e.min??0,p=e.max??1,m=e.step??.01,h=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:[r("span",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide",children:e.label}),h&&u("span",{className:"text-xs font-medium text-foreground tabular-nums",children:[typeof x=="number"?x.toFixed(2).replace(/\.?0+$/,""):x,g?` ${g}`:""]})]}),e.description&&r("p",{className:"text-[10px] text-foreground-subtle/60 mb-1.5",children:e.description}),r("input",{type:"range",min:f,max:p,step:m,value:d,disabled:o||e.disabled,onChange:v=>i(Number(v.target.value)),className:"w-full accent-primary h-1.5"})]})}if(e.type==="boolean"){const l=n.settings?.[e.key],c=typeof l=="boolean"?l:e.default===!0;return u("label",{className:"flex items-center gap-2",children:[r("input",{type:"checkbox",checked:c,disabled:o||e.disabled,onChange:d=>i(d.target.checked),className:"h-3.5 w-3.5 accent-primary"}),r("span",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide",children:e.label})]})}if(e.type==="text"||e.type==="password"||e.type==="textarea"){const l=n.settings?.[e.key],c=typeof l=="string"?l:e.default??"",d=e.type==="password"?"password":"text";return u("div",{children:[r("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e.label}),e.type==="textarea"?r("textarea",{value:c,disabled:o||e.disabled,placeholder:e.placeholder,onChange: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"}):r("input",{type:d,value:c,disabled:o||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"?r("div",{className:"border-t border-border my-2"}):e.type==="info"?r("div",{className:"rounded-md border border-border bg-surface px-2 py-1.5 text-[10px] text-foreground-subtle",children:e.content}):null}function Fa({label:e,active:t,variant:n,subtext:o,onClick:s}){return u("button",{type:"button",onClick:s,className:K("px-2 py-1 text-[10px] font-medium rounded transition-colors",t?n==="on"?"bg-green-500/20 text-green-400":n==="off"?"bg-red-500/20 text-red-400":"bg-primary/20 text-primary":"text-foreground-subtle hover:bg-surface-hover"),children:[e,o&&t&&u("span",{className:"ml-1 opacity-60",children:["(",o,")"]})]})}function mh(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 _5(e,t,n){return n?{enabled:n.enabled??t.enabled,modelId:n.modelId??t.modelId,settings:n.settings??t.settings}:t}function D5({addon:e,agentDefault:t,modelsForFormat:n,onChangeAgentConfig:o}){const s=a=>{o?.({...t,...a})};return u("div",{className:"space-y-4 text-xs",children:[u("label",{className:"flex items-center gap-2",children:[r("input",{type:"checkbox",checked:t.enabled,onChange:a=>s({enabled:a.target.checked})}),u("span",{children:["Enabled on this agent (",e.name,")"]})]}),u("div",{children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle mb-1",children:"Model"}),r("select",{className:"w-full bg-surface border border-border rounded px-2 py-1 text-xs",value:t.modelId,onChange:a=>s({modelId:a.target.value}),children:n.map(a=>r("option",{value:a.id,children:a.name},a.id))})]}),(e.configSchema?.length??0)>0&&u("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),e.configSchema?.map(a=>r(ta,{field:a,allFields:e.configSchema??[],step:mh(e,t),disabled:!1,onChange:i=>s({settings:{...i.settings}})},a.key))]})]})}function L5({addon:e,agentDefault:t,agentNodeId:n,currentPatch:o,modelsForFormat:s,onChangePatch:a}){const i=_5("device",t,o),l=h=>{const g=h.enabled!==void 0||h.modelId!==void 0||h.settings!==void 0;a?.(g?h:null)},c=h=>{const{enabled:g,...b}=o??{},x=h==="inherit"?b:{...b,enabled:h==="on"};l(x)},d=h=>{const{modelId:g,...b}=o??{},x=h===void 0?b:{...b,modelId:h};l(x)},f=h=>{const{settings:g,...b}=o??{},x=h===void 0?b:{...b,settings:h};l(x)},p=o?.enabled===void 0?"inherit":o.enabled?"on":"off",m=o?.modelId!==void 0;return u("div",{className:"space-y-4 text-xs",children:[u("div",{className:"flex items-center gap-1",children:[["inherit","on","off"].map(h=>r("button",{type:"button",onClick:()=>c(h),className:K("px-3 py-1 border border-border rounded text-xs capitalize",p===h?"bg-primary text-primary-foreground border-primary":"bg-surface text-foreground hover:bg-muted"),children:h},h)),u("span",{className:"ml-2 text-[10px] text-foreground-subtle",children:["agent default: ",r("span",{className:"font-semibold",children:t.enabled?"on":"off"})]})]}),u("div",{children:[u("div",{className:"flex items-center justify-between mb-1",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Model"}),m?r("button",{type:"button",className:"text-[10px] text-foreground-subtle hover:text-foreground",onClick:()=>d(void 0),children:"Clear"}):r("button",{type:"button",className:"text-[10px] text-primary hover:underline",onClick:()=>d(t.modelId),children:"Override"})]}),r("select",{disabled:!m,className:"w-full bg-surface border border-border rounded px-2 py-1 text-xs disabled:opacity-50",value:m?o?.modelId??t.modelId:t.modelId,onChange:h=>d(h.target.value),children:s.map(h=>r("option",{value:h.id,children:h.name},h.id))}),!m&&u("div",{className:"text-[10px] text-foreground-subtle mt-1",children:["inherits from ",n]})]}),(e.configSchema?.length??0)>0&&(()=>{const h=o?.settings!==void 0;return u("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[u("div",{className:"flex items-center justify-between",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),h?r("button",{type:"button",className:"text-[10px] text-foreground-subtle hover:text-foreground",onClick:()=>f(void 0),children:"Clear"}):r("button",{type:"button",className:"text-[10px] text-primary hover:underline",onClick:()=>f({...t.settings}),children:"Override"})]}),e.configSchema?.map(g=>r(ta,{field:g,allFields:e.configSchema??[],step:mh(e,i),disabled:!h,onChange:b=>f({...b.settings})},g.key)),!h&&u("div",{className:"text-[10px] text-foreground-subtle",children:["inherits from ",n]})]})})(),u("div",{className:"rounded bg-muted/40 px-3 py-2 text-[11px] text-foreground-subtle",children:[r("div",{className:"font-semibold text-foreground mb-0.5",children:"Effective config preview"}),u("div",{className:"font-mono truncate",children:[e.id," · model: ",i.modelId," · ",i.enabled?"on":"off"]})]})]})}function na(e){const{mode:t,addon:n,agentDefault:o,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"?r(D5,{addon:n,agentDefault:o,modelsForFormat:d,onChangeAgentConfig:i}):r(L5,{addon:n,agentDefault:o,agentNodeId:s,currentPatch:a,modelsForFormat:d,onChangePatch:l})}function T5(e){const t=[],n=(o,s)=>{for(const a of o)t.push({node:a,depth:s}),n(a.children,s+1)};return n(e,0),t}const Xd={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 R5({slot:e}){const t=Xd[e]??Xd.classifier;return r("span",{className:K("text-[9px] font-semibold uppercase tracking-widest leading-none",t.className),children:t.label})}const Jd="inline-flex items-center rounded bg-muted px-1.5 py-px text-[9px] font-medium text-foreground-subtle";function O5({inputs:e,outputs:t}){return e.length===0&&t.length===0?null:u("span",{className:"inline-flex items-center gap-1 flex-wrap",children:[e.map(n=>r("span",{className:K(Jd,"bg-blue-500/10 text-blue-500"),children:n},`in-${n}`)),e.length>0&&t.length>0&&r("span",{className:"text-foreground-subtle/60 text-[9px]",children:"→"}),t.map(n=>r("span",{className:K(Jd,"bg-emerald-500/10 text-emerald-500"),children:n},`out-${n}`))]})}function z5({enabled:e,onChange:t,disabled:n}){return r("button",{type:"button",role:"switch","aria-checked":e,disabled:n,onClick:o=>{o.stopPropagation(),t(!e)},className:K("relative inline-flex h-3.5 w-7 shrink-0 items-center rounded-full transition-colors",e?"bg-emerald-500":"bg-foreground-subtle/30",n?"opacity-50 cursor-not-allowed":"cursor-pointer"),title:e?"Click to disable":"Click to enable",children:r("span",{className:K("inline-block h-3 w-3 rounded-full bg-white shadow transition-transform",e?"translate-x-3.5":"translate-x-0.5")})})}function B5(e){return e.kind==="enabled"?u("span",{className:"inline-flex items-center gap-1",children:[r("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500 shrink-0"}),r("span",{className:"font-mono text-foreground",children:e.modelId})]}):e.kind==="disabled"?u("span",{className:"inline-flex items-center gap-1 text-foreground-subtle",children:[r("span",{className:"h-1.5 w-1.5 rounded-full border border-foreground-subtle/60 shrink-0"}),"off"]}):u("span",{className:"inline-flex items-center gap-1 text-foreground-subtle/70",children:[r("span",{className:"h-1.5 w-1.5 rounded-full bg-muted shrink-0"}),"n/a"]})}function F5({node:e,depth:t,agents:n,getCellState:o,onCellClick:s,selectedCell:a,toggleProps:i}){return u(ve,{children:[u("div",{className:"sticky left-0 z-10 bg-surface px-3 py-2 border-b border-border text-xs flex items-start gap-2",style:{paddingLeft:`${12+t*14}px`},children:[u("div",{className:"flex flex-col gap-1 min-w-0 flex-1",children:[r(R5,{slot:e.slot}),u("div",{className:"flex items-center gap-2 flex-wrap",children:[r("span",{className:"font-semibold truncate",children:e.addonName}),r(O5,{inputs:e.inputClasses,outputs:e.outputClasses})]})]}),i&&r("span",{className:"pl-2 pt-0.5 shrink-0",children:r(z5,{enabled:i.enabled,onChange:i.onChange,disabled:i.disabled})})]}),n.map(l=>{const c=o(e.addonId,l.agentNodeId),d=a?.addonId===e.addonId&&a.agentNodeId===l.agentNodeId;return r("button",{type:"button",onClick:()=>s(e.addonId,l.agentNodeId),className:K("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:B5(c)},l.agentNodeId)})]})}function Yl({tree:e,agents:t,getCellState:n,onCellClick:o,selectedCell:s,onToggleEnabled:a}){const i=Q(()=>T5(e),[e]),l=`minmax(320px, 1fr) repeat(${t.length}, minmax(160px, 220px))`,c=a!==void 0&&t.length===1,d=t[0]?.agentNodeId;return r("div",{className:"overflow-auto border border-border rounded",children:u("div",{className:"grid",style:{gridTemplateColumns:l},children:[r("div",{className:"sticky top-0 left-0 z-20 bg-muted/60 px-3 py-2 text-[10px] uppercase tracking-widest text-foreground-subtle border-b border-border",children:"Step"}),t.map(f=>u("div",{className:"sticky top-0 z-10 bg-muted/60 px-3 py-2 border-b border-l border-border",children:[r("div",{className:"text-xs font-semibold text-foreground",children:f.agentNodeId}),r("div",{className:"text-[10px] text-foreground-subtle truncate",children:f.engineLabel})]},f.agentNodeId)),i.map(({node:f,depth:p})=>{const m=c&&d!==void 0?n(f.addonId,d):null,h=c&&m!==null?{enabled:m.kind==="enabled",onChange:g=>a?.(f.addonId,g),disabled:m.kind==="na"}:void 0;return r(F5,{node:f,depth:p,agents:t,getCellState:n,onCellClick:o,selectedCell:s,toggleProps:h},f.addonId)})]})})}const hh=typeof globalThis<"u"?globalThis.__camstackTrpcReact:void 0,C=hh??tw();typeof globalThis<"u"&&!hh&&(globalThis.__camstackTrpcReact=C);const Zl=un("camstack:system",null);function Xl({system:e,children:t}){return r(Zl.Provider,{value:e,children:t})}function Le(){const e=ye(Zl);if(!e)throw new Error("useSystem(): no <SystemProvider> in tree");return e}function j5(){return ye(Zl)}function dt(e,t){const n=Le(),o=ne(t);o.current=t;const[s,a]=$(n.connectionVersion);Y(()=>n.subscribeConnectionEvents((i,l)=>{i==="connected"&&a(l)}),[n]),Y(()=>n.subscribeEvent(e,l=>{o.current(l)}),[n,e,s])}function ji(e){const t=ne(e);return t.current=e,t}function Ar(e,t){const[n,o]=$(null),s=ji(t);return dt(e,a=>{const i=a.data,l=s.current;l&&!l(i)||o(i)}),n}function Jl(e,t,n){const[o,s]=$(()=>new Map),a=ji(t),i=ji(n);dt(e,c=>{const d=c.data,f=i.current;if(f&&!f(d))return;const p=a.current(d);s(m=>{const h=new Map(m);return h.set(p,d),h})});const l=Q(()=>Array.from(o.values()),[o]);return{map:o,values:l}}function Pr(){const{data:e,isLoading:t}=C.nodes.topology.useQuery(void 0,{staleTime:6e4}),o=Ar("cluster.topology-snapshot")?.nodes??e;return{nodes:Q(()=>{const a=[];for(const i of o??[])a.push({id:String(i.id??""),name:String(i.name??i.id??""),shortName:i.isHub?"HUB":String(i.name??i.id??""),isHub:!!i.isHub,isOnline:!!i.isOnline,localIps:i.localIps??[],addons:(i.addons??[]).map(l=>({addonId:l.id,capabilities:l.capabilities}))});return a.sort((i,l)=>i.isHub!==l.isHub?i.isHub?-1:1:i.name.localeCompare(l.name)),a},[o]),isLoading:t}}function gh({selectedNodeId:e,onSelect:t,label:n="Node",hideIcon:o=!1,alwaysShow:s=!1}){const{nodes:a}=Pr();return!s&&a.length<=1?null:u("div",{className:"flex items-center gap-1.5",children:[!o&&r(Ek,{className:"h-3.5 w-3.5 text-foreground-subtle"}),n&&r("span",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:n}),r("div",{className:"flex rounded-md border border-border overflow-hidden text-[11px] font-medium",children:a.map((i,l)=>{const c=e===i.id;return r("button",{type:"button",onClick:()=>t(i.id),disabled:!i.isOnline,title:i.isOnline?i.name:`${i.name} (offline)`,className:K("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 H5={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 V5({status:e,showDot:t=!0,showLabel:n=!0,size:o="sm",className:s}){const a=H5[e];return u("span",{className:K("inline-flex items-center gap-1.5",o==="sm"?"text-xs":"text-sm",s),children:[t&&r("span",{className:K("h-1.5 w-1.5 shrink-0 rounded-full",a.colorClass),"aria-hidden":"true"}),n&&r("span",{className:"text-foreground",children:a.label})]})}const q5={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 Q5({provider:e,showLabel:t=!0,className:n}){const o=q5[e];return u("span",{className:K("inline-flex items-center gap-1.5 text-xs",n),children:[r("span",{className:K("h-1.5 w-1.5 shrink-0 rounded-sm",o.colorClass),"aria-hidden":"true"}),t&&r("span",{className:"text-foreground",children:o.label})]})}const U5={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 bh({children:e,variant:t="neutral",mono:n,className:o}){return r("span",{className:K("inline-flex items-center rounded-md px-2 py-0.5 text-[11px] font-bold leading-tight",n&&"font-mono",U5[t],o),children:e})}function K5({version:e,preRelease:t,className:n}){const o=t??/-(alpha|beta|rc|dev|canary|next)/i.test(e);return r(bh,{variant:o?"warning":"success",mono:!0,className:n,children:e})}function G5({label:e,description:t,error:n,required:o,children:s,orientation:a="vertical",className:i}){const l=a==="horizontal";return u("div",{className:K("flex gap-2",l?"flex-row items-center justify-between":"flex-col",i),children:[u("div",{className:K(l?"flex-1":""),children:[u(Fl,{children:[e,o&&r("span",{className:"text-danger ml-0.5",children:"*"})]}),t&&r("p",{className:"text-foreground-subtle text-xs mt-0.5",children:t})]}),r("div",{className:K(l?"shrink-0":""),children:s}),n&&r("p",{className:"text-danger text-xs",children:n})]})}function W5({title:e,subtitle:t,actions:n,className:o}){return u("div",{className:K("flex flex-col gap-2 mb-3 sm:flex-row sm:items-center sm:justify-between",o),children:[u("div",{children:[r("h1",{className:"text-sm font-semibold text-foreground",children:e}),t&&r("p",{className:"text-foreground-subtle text-xs",children:t})]}),n&&r("div",{className:"flex items-center gap-2 flex-wrap",children:n})]})}function ko({icon:e,title:t,description:n,action:o,className:s}){return u("div",{className:K("flex flex-col items-center justify-center gap-3 py-12",s),children:[e&&r(e,{className:"h-12 w-12 text-foreground-subtle","aria-hidden":"true"}),u("div",{className:"flex flex-col items-center gap-1 text-center",children:[r("p",{className:"text-foreground-muted text-sm font-medium",children:t}),n&&r("p",{className:"text-foreground-subtle text-xs max-w-xs",children:n})]}),o&&r("div",{className:"mt-1",children:o})]})}const xh=un("camstack:confirm-dialog",null);function rt(){const e=ye(xh);if(!e)throw new Error("useConfirm must be used within ConfirmDialogProvider");return e.confirm}function yh({children:e}){const[t,n]=$(null),o=q(c=>new Promise(d=>{n({...c,resolve:d})}),[]),s=()=>{t?.resolve(!0),n(null)},a=()=>{t?.resolve(!1),n(null)},i={danger:{icon:"text-red-400",button:"bg-red-500 hover:bg-red-600 text-white"},warning:{icon:"text-orange-400",button:"bg-orange-500 hover:bg-orange-600 text-white"},default:{icon:"text-primary",button:"bg-primary hover:bg-primary/90 text-white"}},l=t?i[t.variant??"default"]:i.default;return u(xh.Provider,{value:{confirm:o},children:[e,t&&u("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[r("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:a}),u("div",{className:"relative z-10 w-full max-w-sm mx-4 rounded-xl border border-border bg-surface shadow-2xl overflow-hidden animate-in fade-in zoom-in-95 duration-150",onClick:c=>c.stopPropagation(),children:[u("div",{className:"px-5 pt-5 pb-4",children:[r("h3",{className:"text-sm font-semibold text-foreground",children:t.title}),r("p",{className:"mt-2 text-xs text-foreground-subtle leading-relaxed",children:t.message})]}),u("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border bg-surface-hover/30",children:[r("button",{type:"button",onClick:a,className:"px-3 py-1.5 text-xs font-medium rounded-md border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:t.cancelLabel??"Cancel"}),r("button",{type:"button",onClick:s,className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${l.button}`,children:t.confirmLabel??"Confirm"})]})]})]})]})}function Y5({value:e,label:t,trend:n,className:o}){return u(Ge,{className:K("flex flex-col gap-1",o),children:[u("div",{className:"flex items-baseline gap-2",children:[r("span",{className:"text-2xl font-semibold text-foreground",children:e}),n&&u("span",{className:K("inline-flex items-center gap-0.5 text-xs font-medium",n.direction==="up"?"text-success":"text-danger"),children:[n.direction==="up"?r(Yk,{className:"h-3 w-3"}):r(Xk,{className:"h-3 w-3"}),n.value,"%"]})]}),r("span",{className:"text-xs text-foreground-muted",children:t})]})}function Z5({items:e,className:t}){return r("dl",{className:K("flex flex-col",t),children:e.map(n=>u("div",{className:"flex items-center h-7",children:[r("dt",{className:"text-foreground-subtle text-xs w-1/3 shrink-0",children:n.key}),r("dd",{className:"text-foreground text-xs",children:n.value})]},n.key))})}function X5({children:e,maxHeight:t=300,className:n}){const[o,s]=$(!1),a=q(()=>{navigator.clipboard.writeText(e).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)})},[e]);return u("div",{className:K("relative group",n),children:[r(Ul,{style:{maxHeight:t},children:r("pre",{className:"font-mono text-xs bg-surface p-3 rounded-md border border-border-subtle",children:r("code",{children:e})})}),r("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity",children:r(Bl,{icon:o?wo:Mn,"aria-label":"Copy code",variant:"ghost",size:"sm",onClick:a})})]})}function J5({filters:e,values:t,onChange:n,className:o}){const s=Xn(),[a,i]=$(!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:K("flex items-center gap-2",o),children:[d&&r(Ss,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:p=>l(d.key,p.target.value),leftSlot:r(oo,{className:"h-3 w-3 text-foreground-subtle"}),className:"flex-1"}),f&&u(ve,{children:[u("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-foreground-muted hover:bg-surface-hover transition-colors shrink-0",children:[r(Rk,{className:"h-3.5 w-3.5"}),"Filters",c>0&&r(cr,{variant:"info",className:"ml-1 text-[10px] px-1 py-0",children:c})]}),r(Ql,{open:a,onClose:()=>i(!1),title:"Filters",children:r("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:[r("label",{className:"text-xs text-foreground-muted mb-1 block",children:p.label}),r(Cs,{options:p.options,value:t[p.key]??"",onChange:m=>l(p.key,m.target.value),className:"w-full"})]},p.key);case"badge-toggle":return r("div",{className:"flex items-center gap-1 flex-wrap",children:p.options.map(m=>{const g=t[p.key]===m.value;return r("button",{type:"button",onClick:()=>l(p.key,g?void 0:m.value),children:r(cr,{variant:g?"info":"default",className:"cursor-pointer",children:m.label})},m.value)})},p.key);default:return null}})})})]})]})}return r("div",{className:K("flex items-center gap-2 flex-wrap",o),children:e.map(d=>{switch(d.type){case"search":return r(Ss,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:f=>l(d.key,f.target.value),leftSlot:r(oo,{className:"h-3 w-3 text-foreground-subtle"}),className:"w-48"},d.key);case"select":return r(Cs,{options:d.options,value:t[d.key]??"",onChange:f=>l(d.key,f.target.value),className:"w-36"},d.key);case"badge-toggle":return r("div",{className:"flex items-center gap-1",children:d.options.map(f=>{const m=t[d.key]===f.value;return r("button",{type:"button",onClick:()=>l(d.key,m?void 0:f.value),children:r(cr,{variant:m?"info":"default",className:"cursor-pointer",children:f.label})},f.value)})},d.key);default:return null}})})}function Hi({label:e,icon:t,href:n,badge:o,active:s=!1,className:a}){return u("a",{href:n,className:K("flex items-center gap-2 h-7 px-2 text-[11px] transition-colors",s?"border-l-2 border-primary bg-primary/[0.08] text-foreground rounded-r-md":"text-foreground-subtle hover:bg-surface-hover rounded-md",a),children:[r(t,{className:"h-3.5 w-3.5 shrink-0"}),r("span",{className:"truncate flex-1",children:e}),o!==void 0&&r(cr,{className:"ml-auto text-[10px] px-1.5 py-0",children:o})]})}function Vi({logo:e,sections:t,footer:n,onNavigate:o,className:s}){return u("nav",{className:K("bg-surface border-r border-border h-full flex flex-col",s),children:[e&&r("div",{className:"px-3 py-2 shrink-0",children:e}),r("div",{className:"flex-1 overflow-auto px-1 py-1",children:t.map((a,i)=>u("div",{className:K(i>0?"mt-3":""),children:[a.label&&r("span",{className:"text-[10px] text-foreground-disabled uppercase tracking-wider px-2 mb-1 block",children:a.label}),r("div",{className:"flex flex-col gap-0.5",onClick:o,children:a.items.map(l=>r(Hi,{...l},l.href))})]},i))}),n&&n.length>0&&u("div",{className:"shrink-0 px-1 pb-1",children:[r(jl,{className:"mb-1"}),r("div",{className:"flex flex-col gap-0.5",onClick:o,children:n.map(a=>r(Hi,{...a},a.href))})]})]})}function eS({sidebar:e,header:t,mobileLogo:n,mobileActions:o,children:s,className:a}){const i=Xn(),[l,c]=$(!1);return u("div",{className:K("flex h-screen",a),children:[!i&&r(Vi,{...e,className:K("w-44",e.className)}),i&&r(Kl,{open:l,onClose:()=>c(!1),width:"w-64",children:r(Vi,{...e,onNavigate:()=>c(!1),className:"w-full border-r-0"})}),u("div",{className:"flex flex-1 flex-col min-w-0",children:[i&&u("header",{className:"flex items-center h-12 border-b border-border px-3 shrink-0 bg-surface/80 backdrop-blur-sm",children:[r("button",{onClick:()=>c(!0),className:"p-1.5 -ml-1.5 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors","aria-label":"Open menu",children:r(nk,{className:"h-5 w-5"})}),n&&r("div",{className:"flex-1 flex justify-center",children:n}),o&&r("div",{className:"shrink-0",children:o})]}),!i&&t&&u("header",{className:"flex items-center h-10 border-b border-border px-4 shrink-0",children:[t.breadcrumbs&&t.breadcrumbs.length>0&&r("nav",{className:"flex items-center gap-1 text-xs flex-1 min-w-0",children:t.breadcrumbs.map((d,f)=>{const p=f===t.breadcrumbs.length-1;return u("span",{className:"flex items-center gap-1",children:[f>0&&r(Cn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),d.href&&!p?r("a",{href:d.href,className:"text-foreground-subtle hover:text-foreground transition-colors truncate",children:d.label}):r("span",{className:"text-foreground truncate",children:d.label})]},f)})}),t.actions&&r("div",{className:"flex items-center gap-2 ml-auto shrink-0",children:t.actions})]}),r("main",{className:"flex-1 overflow-auto p-4",children:s})]})]})}const tS={online:"bg-success",offline:"bg-danger",warning:"bg-warning",unknown:"bg-foreground-subtle"};function nS({title:e,subtitle:t,status:n,selected:o,onClick:s,badges:a,actions:i,offlineAction:l,className:c}){const d=n==="offline";return u("div",{onClick:s,className:K("w-full rounded-lg border p-3 text-left transition-colors",s&&"cursor-pointer",o?"border-primary bg-primary/10":"border-border bg-surface hover:bg-surface-hover",d&&!o&&"opacity-50",c),children:[u("div",{className:"flex items-center justify-between mb-2",children:[r("span",{className:"text-sm font-medium truncate",children:e}),n&&r("span",{className:K("h-2 w-2 rounded-full shrink-0",tS[n])})]}),t&&r("div",{className:"text-[11px] text-foreground-muted",children:t}),a&&a.length>0&&r("div",{className:"flex flex-wrap gap-1 mt-2",children:a.map((f,p)=>{const m=K("rounded px-1.5 py-0.5 text-[10px] flex items-center gap-0.5",o?"bg-primary/20":"bg-surface-hover",f.onClick&&"hover:opacity-80 transition-opacity cursor-pointer");return f.onClick?u("button",{onClick:h=>{h.stopPropagation(),f.onClick()},className:m,children:[f.icon,f.label]},p):u("span",{className:m,children:[f.icon,f.label]},p)})}),!d&&i&&i.length>0&&r("div",{className:"flex items-center gap-0.5 mt-2 -mb-1",children:i.map((f,p)=>r("button",{onClick:m=>{m.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&&r("div",{className:"mt-2",onClick:f=>f.stopPropagation(),children:l})]})}function rS({children:e,minCardWidth:t=220,gap:n=3,className:o}){return r("div",{className:K("p-4 overflow-y-auto flex-1 content-start",o),style:{display:"grid",gridTemplateColumns:`repeat(auto-fill, minmax(${t}px, 1fr))`,gap:`${n*4}px`},children:e})}const oS="capability.binding-changed";function kt(e,t){const[n,o]=$(null);return Y(()=>{if(t===null){o(null);return}let s=!1;const a=async()=>{try{const l=await e.deviceManager.getBindings.query({deviceId:t});s||o(l)}catch{s||o(l=>l)}};a();const i=e.live?.onEvent.subscribe({category:oS},{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?nw(e,n):null,[e,n])}function on(e){const t=q(o=>e?e.subscribe(()=>o()):()=>{},[e]),n=q(()=>e?.value,[e]);return Ws(t,n,n)}function vh(e,t,n){const o=kt(e,t),s=o?n(o.state):void 0;return on(s)}function Er(e){const t=kt(e.trpc,e.deviceId),n=t!==null?e.slice(t):void 0,o=on(n),s=t!==null?e.cap(t):void 0,c=(e.requireFeature===void 0||(e.deviceFeatures??[]).includes(e.requireFeature))&&s!==void 0&&o!==void 0;return{dev:t,cap:s,slice:o,available:c}}function sS(e){return e.parentDeviceId===null?"top-level":e.role?"accessory":"adopted"}const aS={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 iS(e){const t=aS[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 lS={siren:Ys,floodlight:Am,spotlight:Lm,"pir-sensor":$m,chime:lk,autotrack:wm,nightvision:Rl,"privacy-mask":Cm,doorbell:Nm},cS={camera:Tl,hub:zi,nvr:zi,light:Am,siren:Ys,switch:Kk,sensor:$m,thermostat:Qk,button:g2,generic:zl};function wh(e){return e.role?lS[e.role]??zl:cS[e.type.toLowerCase()]??Tl}const Nh={"native-snapshot":V2,"two-way-audio":Pm,"pan-tilt-zoom":wm,"ptz-autotrack":J2,"doorbell-button":Nm,"motion-trigger":yn,"battery-operated":ym,rebootable:Dm},kh={"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"},dS={"native-snapshot":"snapshot",rebootable:"reboot","pan-tilt-zoom":"ptz","ptz-autotrack":"ptz-autotrack","two-way-audio":"intercom","motion-trigger":"motion-trigger"},Sh=new Set(["camera","hub","nvr"]);function Ch(e){return!Sh.has(e.type.toLowerCase())}function eu(e){return e.role?!0:!Sh.has(e.type.toLowerCase())}function Mh(e){return(e.features??[]).includes("motion-trigger")}function uS(e){if(e.length<=24)return e;const t=e.lastIndexOf(":");if(t>=0&&t<e.length-4)return e.slice(t+1);const n=e.split("-");if(n.length>2){const o=n.slice(-2).join("-");if(o.length>=6)return o}return`…${e.slice(-18)}`}function pS({trpc:e,accessoryChildren:t,adoptedChildren:n,onNavigate:o}){return u("div",{className:"border-t border-border-subtle/50",children:[n.length>0&&r(tu,{trpc:e,label:"Adopted devices",rows:n,onNavigate:o}),t.length>0&&r(tu,{trpc:e,label:"Accessories",rows:t,onNavigate:o})]})}function tu({trpc:e,label:t,rows:n,onNavigate:o}){return u("div",{children:[r("div",{className:"px-3 pt-1.5 pb-1 text-[9px] font-semibold uppercase tracking-wide text-foreground-subtle",children:t}),r("ul",{children:n.map(s=>r(fS,{trpc:e,child:s,onNavigate:o},s.id))})]})}function fS({trpc:e,child:t,onNavigate:n}){const o=!t.disabled,s=o&&Ch(t),a=o&&Mh(t),i=wh(t);return r("li",{children:u("div",{onClick:l=>{l.stopPropagation(),n(t.id)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-surface-hover transition-colors cursor-pointer",children:[r(i,{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),r("span",{className:"text-[10.5px] text-foreground flex-1 truncate",children:t.name}),a&&r(hS,{trpc:e,deviceId:t.id,features:t.features}),s&&r(mS,{trpc:e,deviceId:t.id}),r("span",{className:K("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 mS({trpc:e,deviceId:t}){const{dev:n,cap:o,slice:s,available:a}=Er({trpc:e,deviceId:t,cap:p=>p.switch,slice:p=>p.state.switch}),[i,l]=$(!1);if(n!==null&&!o)return null;const c=s?.on===!0,d={transform:c?"translateX(14px)":"translateX(2px)"},f=async p=>{if(p.stopPropagation(),!(i||!a||!o)){l(!0);try{await o.setState({on:!c})}finally{l(!1)}}};return r("button",{type:"button",onClick:p=>{f(p)},disabled:i||!a,className:K("relative inline-flex h-4 w-7 items-center rounded-full border transition-colors flex-shrink-0",c?"bg-success/30 border-success/50":"bg-surface-hover border-border",i&&"opacity-60",!a&&"opacity-40 cursor-not-allowed"),title:a?c?"Turn off":"Turn on":"Awaiting state…","aria-pressed":c,children:r("span",{className:K("absolute h-3 w-3 rounded-full transition-all",c?"bg-success":"bg-foreground-subtle"),style:d})})}function hS({trpc:e,deviceId:t,features:n}){const{dev:o,cap:s,slice:a,available:i}=Er({trpc:e,deviceId:t,cap:p=>p.motionTrigger,slice:p=>p.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:n}),[l,c]=$(!1);if(o!==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 r("button",{type:"button",onClick:p=>{f(p)},disabled:l||!i,className:K("inline-flex h-4 w-4 items-center justify-center rounded transition-colors flex-shrink-0",d?"text-primary bg-primary/10":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover",(l||!i)&&"opacity-50"),title:i?d?"Motion-trigger: on (click to disable)":"Motion-trigger: off (click to enable)":"Awaiting state…","aria-pressed":d,children:r(yn,{className:"h-2.5 w-2.5"})})}function Ih({trpc:e,device:t,flags:n}){if(!!t.disabled)return null;const s=t.type.toLowerCase(),a=n.showSwitchToggle&&Ch(t),i=Mh(t),l=s==="hub"||s==="nvr",c=(t.features??[]).includes("rebootable"),d=l&&c;return u(ve,{children:[i&&r(bS,{trpc:e,deviceId:t.id,features:t.features}),a&&r(gS,{trpc:e,deviceId:t.id}),d&&r(yS,{trpc:e,deviceId:t.id})]})}function gS({trpc:e,deviceId:t}){const{dev:n,cap:o,slice:s,available:a}=Er({trpc:e,deviceId:t,cap:p=>p.switch,slice:p=>p.state.switch}),[i,l]=$(!1);if(n!==null&&!o)return null;const c=s?.on===!0,d={transform:c?"translateX(14px)":"translateX(2px)"},f=async p=>{if(p.stopPropagation(),!(i||!a||!o)){l(!0);try{await o.setState({on:!c})}finally{l(!1)}}};return r("button",{type:"button",onClick:p=>{f(p)},disabled:i||!a,className:K("relative inline-flex h-4 w-7 items-center rounded-full border transition-colors flex-shrink-0",c?"bg-success/30 border-success/50":"bg-surface-hover border-border",i&&"opacity-60",!a&&"opacity-40 cursor-not-allowed"),title:a?c?"Turn off":"Turn on":"Awaiting state…","aria-pressed":c,children:r("span",{className:K("absolute h-3 w-3 rounded-full transition-all",c?"bg-success":"bg-foreground-subtle"),style:d})})}function bS({trpc:e,deviceId:t,features:n}){const{dev:o,cap:s,slice:a,available:i}=Er({trpc:e,deviceId:t,cap:p=>p.motionTrigger,slice:p=>p.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:n}),[l,c]=$(!1);if(o!==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 r("button",{type:"button",onClick:p=>{f(p)},disabled:l||!i,className:K("inline-flex h-4 w-4 items-center justify-center rounded transition-colors flex-shrink-0",d?"text-primary bg-primary/10":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover",(l||!i)&&"opacity-50"),title:i?d?"Motion-trigger: on (click to disable)":"Motion-trigger: off (click to enable)":"Awaiting state…","aria-pressed":d,children:r(yn,{className:"h-2.5 w-2.5"})})}const ja=168,xS=4;function yS({trpc:e,deviceId:t}){const{dev:n,cap:o}=Er({trpc:e,deviceId:t,cap:x=>x.reboot,slice:()=>{}}),s=ne(null),a=ne(null),[i,l]=$(null),[c,d]=$(!1),f=n!==null&&o!==void 0&&o!==null,p=i!==null,m=()=>l(null),h=()=>{const x=s.current;if(!x)return;const v=x.getBoundingClientRect(),w=v.right-ja,y=Math.max(8,Math.min(w,window.innerWidth-ja-8)),N=v.bottom+xS;l({top:N,left:y})};if(Y(()=>{if(!p)return;const x=w=>{const y=s.current,N=a.current,k=w.target;k!==null&&(y&&y.contains(k)||N&&N.contains(k)||m())},v=w=>{w.key==="Escape"&&(w.stopPropagation(),m())};return document.addEventListener("mousedown",x),document.addEventListener("keydown",v),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",v)}},[p]),n!==null&&!o)return null;const g=x=>{x.stopPropagation(),p?m():h()},b=async()=>{if(!(c||!f||!o)){d(!0),m();try{await o.reboot({})}finally{d(!1)}}};return u(ve,{children:[r("button",{ref:s,type:"button",onClick:g,disabled:c||!f,className:K("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:r(km,{className:"h-3 w-3"})}),i&&vo(r("div",{ref:a,role:"menu",style:{position:"fixed",top:i.top,left:i.left,width:ja},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:K("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-[11px] text-foreground","hover:bg-surface-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed"),children:[r(Dm,{className:"h-3 w-3 shrink-0 text-foreground-subtle"}),r("span",{children:"Reboot device"})]})}),document.body)]})}const vS=Object.freeze([]);function wS(e){return e==="native"?"native":"enhanced"}function NS(e){return e.map(t=>({kind:"marker",feature:t}))}function kS(e,t){const n=new Map,o=t.entries??[];for(const a of o)n.set(a.capName,a);const s=[];for(const a of e){const i=dS[a];if(i===void 0){s.push({kind:"marker",feature:a});continue}const l=n.get(i);l&&s.push({kind:wS(l.kind),feature:a,capName:i})}return s}function SS(e,t,n){const[o,s]=$(null),[a,i]=$(!1),[l,c]=$(!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 m=await e.deviceManager.getBindings.query({deviceId:t});if(d)return;s(m),c(!1)}catch{if(d)return;i(!0),c(!1)}};f();const p=e.live?.onEvent.subscribe({category:"capability.binding-changed"},{onData:m=>{const h=m.data?.source;if(!h){f();return}h.type==="device"&&h.id===t&&f()}});return()=>{d=!0,p?.unsubscribe()}},[e,t]),n.length===0?{loading:l,resolved:vS}:l||a||!o?{loading:l,resolved:NS(n)}:{loading:!1,resolved:kS(n,o)}}const CS=[];function Ah({trpc:e,device:t,flags:n,accessoryCount:o,adoptedCount:s,showFeatureRow:a=!1}){const i=o+s,l=n.showChildrenAccordion&&i>0,c=t.features??CS,d=a&&c.length>0,{resolved:f}=SS(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&&r(MS,{accessoryCount:o,adoptedCount:s}),p&&r(IS,{resolved:f})]})}function MS({accessoryCount:e,adoptedCount:t}){const n=e+t;if(n===0)return null;const o=t>0&&e>0?`${String(t)} adopted · ${String(e)} accessor${e===1?"y":"ies"}`:t>0?`${String(t)} adopted`:`${String(e)} accessor${e===1?"y":"ies"}`;return u("span",{className:"text-[9px] font-medium text-foreground-subtle bg-surface-elevated/60 rounded px-1.5 py-0.5 flex-shrink-0",title:o,children:["+",n]})}const Ph=240,nu=200;function IS({resolved:e}){const t=ne(null),[n,o]=$(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>=nu?l.bottom+4:l.top-nu-4,p=Math.max(8,Math.min(l.left,window.innerWidth-Ph-8));o({top:f,left:p})},onMouseLeave:()=>o(null),children:[e.map(i=>{const l=Nh[i.feature];return l?r("span",{className:"inline-flex items-center justify-center h-4 w-4 rounded bg-surface-elevated/60 text-foreground-subtle",title:kh[i.feature]??i.feature,children:r(l,{className:"h-2.5 w-2.5"})},i.feature):null}),n&&vo(r(AS,{resolved:e,position:n}),document.body)]})}function AS({resolved:e,position:t}){return u("div",{style:{position:"fixed",top:t.top,left:t.left,width:Ph,pointerEvents:"none"},className:"z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-2",children:[r("h5",{className:"text-[9px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5",children:"Features"}),r("ul",{className:"space-y-0.5",children:e.map(n=>r(PS,{entry:n},n.feature))})]})}function PS({entry:e}){const t=Nh[e.feature],n=kh[e.feature]??e.feature;return u("li",{className:"flex items-center justify-between gap-2 text-[10px]",children:[u("span",{className:"flex items-center gap-1.5 text-foreground",children:[t&&r(t,{className:"h-3 w-3 text-foreground-subtle"}),r("span",{children:n})]}),r(ES,{kind:e.kind})]})}function ES({kind:e}){return e==="marker"?r("span",{className:"text-[8.5px] px-1 rounded text-foreground-subtle",title:"Informational marker (no cap registered)",children:"marker"}):r("span",{className:K("text-[8.5px] px-1 rounded",e==="native"?"bg-success/15 text-success":"bg-primary/15 text-primary"),children:e})}function Eh({device:e,variant:t,flags:n,parent:o,integrationIcon:s,hasChildren:a,expanded:i,onToggleExpand:l,onNavigateToParent:c}){const d=wh(e);return u("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[n.showChildrenAccordion&&a?r("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?r(Yn,{className:"h-3 w-3"}):r(Cn,{className:"h-3 w-3"})}):n.showChildrenAccordion?r("span",{className:"h-3.5 w-3.5 flex-shrink-0"}):null,r(d,{className:K("text-foreground-subtle flex-shrink-0",t==="minimal"?"h-3 w-3":"h-3.5 w-3.5")}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-1.5 min-w-0",children:[n.showIntegrationIcon&&s&&r("span",{className:"flex-shrink-0",children:s}),r("span",{className:K("font-semibold text-foreground truncate",t==="minimal"?"text-[10.5px]":"text-[11px]"),title:e.name,children:e.name})]}),(n.showId||n.showStableId)&&u("div",{className:"mt-0.5 flex items-center gap-1 text-[9px] text-foreground-subtle font-mono truncate",title:n.showStableId?`stableId: ${e.stableId}`:void 0,children:[n.showId&&u("span",{className:"flex-shrink-0 tabular-nums",children:["#",String(e.id)]}),n.showId&&n.showStableId&&r("span",{className:"flex-shrink-0 opacity-50",children:"·"}),n.showStableId&&r("span",{className:"truncate",children:uS(e.stableId)})]}),n.showParentBadge&&o&&u("button",{type:"button",onClick:f=>{f.stopPropagation(),c(o.id)},className:"mt-0.5 inline-flex max-w-full items-center gap-1 text-[9px] text-foreground-subtle hover:text-primary transition-colors",title:`Open parent: ${o.name} (#${String(o.id)})`,children:[r(zi,{className:"h-2.5 w-2.5 shrink-0"}),u("span",{className:"truncate",children:["Under: ",o.name]})]})]})]})}function ec(e,t){return vh(e,t,o=>o.battery)??null}function tc(e,t){const n=kt(e,t),o=ne(!1),{data:s,isLoading:a,isFetching:i,refetch:l}=Kn({queryKey:["device",t,"snapshot"],queryFn:()=>{if(!n)throw new Error("useDeviceSnapshotImage: device proxy not ready");const f=o.current;return o.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(){o.current=!0,l()}return{src:c,loading:a||i,refresh:d}}function $S(e){return e<=10?WN:e<=30?KN:e>=95?QN:ym}function _S(e,t){return t!=="none"?"text-emerald-400":e<=10?"text-rose-400":e<=30?"text-amber-400":"text-foreground-subtle"}function nc({status:e,variant:t="compact",className:n}){if(!e)return null;const o=$S(e.percentage),s=_S(e.percentage,e.charging),a=e.charging==="solar"?Lm:e.charging==="dc"?fk:null,i=e.sleeping;return u("span",{className:K("inline-flex items-center gap-1 text-[10px] font-medium",s,n),title:`Battery: ${Math.round(e.percentage)}%`+(e.charging!=="none"?` · charging (${e.charging})`:"")+(e.sleeping?" · sleeping":""),children:[r(o,{className:"h-3.5 w-3.5"}),u("span",{children:[Math.round(e.percentage),"%"]}),a&&r(a,{className:"h-3 w-3"}),i&&r(Rl,{className:"h-3 w-3 text-blue-300"}),t==="full"&&e.charging!=="none"&&r("span",{className:"text-foreground-subtle",children:e.charging})]})}function $h({trpc:e,device:t,status:n,enabled:o,showStatusPills:s=!1}){const a=o&&t.online,i=tc(e,a?t.id:null),l=(t.features??[]).includes("battery-operated"),c=s&&l&&!t.disabled,d=ec(e,c?t.id:null);return!o&&!c?null:u("span",{className:"inline-flex items-center gap-1.5 flex-nowrap whitespace-nowrap",children:[c&&d&&r(nc,{status:d}),o&&r(DS,{deviceName:t.name,snapshotUrl:i.src,status:n})]})}const Ha=288,ru=196,Va=8;function DS({deviceName:e,snapshotUrl:t,status:n}){const o=ne(null),[s,a]=$(null),i=n==="offline"||n==="disabled",l=()=>{const d=o.current;if(!d)return;const f=d.getBoundingClientRect(),p=f.top,m=window.innerHeight-f.bottom,h=p<ru+Va&&m>p,g=h?f.bottom+Va:f.top-ru-Va,b=f.right-Ha,x=Math.max(8,Math.min(b,window.innerWidth-Ha-8));a({top:g,left:x,placeBelow:h})},c=()=>a(null);return u(ve,{children:[r("button",{ref:o,type:"button",onClick:d=>d.stopPropagation(),onMouseEnter:l,onMouseLeave:c,onFocus:l,onBlur:c,className:"flex h-6 w-6 items-center justify-center rounded text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors flex-shrink-0",title:"Preview","aria-label":"Preview snapshot",children:r(Xs,{className:"h-3.5 w-3.5"})}),s&&vo(u("div",{style:{position:"fixed",top:s.top,left:s.left,width:Ha,pointerEvents:"none"},className:"rounded-lg border border-border bg-surface shadow-lg shadow-black/30 z-[9999] overflow-hidden",children:[r("div",{className:"h-40 bg-background flex items-center justify-center",children:t&&!i?r("img",{src:t,alt:e,className:"h-full w-full object-cover"}):r("span",{className:"text-xs text-foreground-subtle",children:n==="offline"?"Offline — no snapshot":n==="disabled"?"Disabled":"No snapshot yet"})}),r("div",{className:"px-3 py-2",children:r("p",{className:"text-xs font-semibold text-foreground truncate",children:e})})]}),document.body)]})}function _h({status:e}){const t=e==="disabled"?"bg-warning":e==="online"?"bg-success":"bg-danger",n=e==="disabled"?"Disabled":e==="online"?"Online":"Offline";return r("span",{className:K("h-1.5 w-1.5 rounded-full flex-shrink-0",t),title:n})}function so(e){const{trpc:t,device:n,parent:o,integrationIcon:s,onNavigate:a,className:i}=e,l=iS(e),c=e.variant??"compact",d=e.view??"card",f=!n.disabled,p=n.isCamera??n.type.toLowerCase()==="camera",m=e.children??[],h=m.filter(eu),g=m.filter(M=>!eu(M)),b=m.length>0,[x,v]=$(!1),w=e.expanded??x,y=e.onToggleExpand??(()=>v(M=>!M)),N=M=>{a?.(M)},k=e.indentLevel??(e.isAccessoryRow?2:0),S=f?n.online?"online":"offline":"disabled";return d==="table"?r(TS,{trpc:t,device:n,variant:c,flags:l,parent:o??null,integrationIcon:s??null,accessoryCount:h.length,adoptedCount:g.length,hasChildren:b,expanded:w,onToggleExpand:y,onNavigate:N,displayStatus:S,isCamera:p,showSnapshot:l.showSnapshot&&p,isAccessoryRow:e.isAccessoryRow??!1,indentLevel:k,className:i}):u("div",{className:K("rounded-lg border border-border bg-surface transition-colors",!f&&"opacity-60",i),children:[u("div",{onClick:()=>N(n.id),className:K("flex items-center gap-2 cursor-pointer hover:border-foreground-subtle/30 w-full",c==="minimal"?"px-2.5 py-1.5":"px-3 py-2.5"),children:[r(Eh,{device:n,variant:c,flags:l,parent:o??null,integrationIcon:s??null,hasChildren:b,expanded:w,onToggleExpand:y,onNavigateToParent:N}),r(Ah,{trpc:t,device:n,flags:l,accessoryCount:h.length,adoptedCount:g.length,showFeatureRow:!1}),r($h,{trpc:t,device:n,status:S,enabled:l.showSnapshot&&p,showStatusPills:!0}),r(Ih,{trpc:t,device:n,flags:l}),r(_h,{status:S})]}),w&&b&&r(pS,{trpc:t,accessoryChildren:h,adoptedChildren:g,onNavigate:N})]})}const LS={0:"pl-2",1:"pl-6",2:"pl-8"};function TS(e){const{trpc:t,device:n,variant:o,flags:s,parent:a,integrationIcon:i,accessoryCount:l,adoptedCount:c,hasChildren:d,expanded:f,onToggleExpand:p,onNavigate:m,displayStatus:h,isCamera:g,showSnapshot:b,isAccessoryRow:x,indentLevel:v,className:w}=e;return u("tr",{onClick:()=>m(n.id),className:K("cursor-pointer hover:bg-surface-hover transition-colors",!s.showChildrenAccordion&&"border-b border-border-subtle/40",x&&"bg-foreground-subtle/[0.03]",w),children:[r("td",{className:K("py-2 align-middle pr-2",LS[v]),children:r(Eh,{device:n,variant:o,flags:s,parent:a,integrationIcon:i,hasChildren:d,expanded:f,onToggleExpand:p,onNavigateToParent:m})}),r("td",{className:"px-2 py-2 align-middle text-[10px] text-foreground-subtle whitespace-nowrap",children:n.type}),r("td",{className:"px-2 py-2 align-middle",children:r(Ah,{trpc:t,device:n,flags:s,accessoryCount:l,adoptedCount:c,showFeatureRow:!0})}),r("td",{className:"px-2 py-2 align-middle",children:r($h,{trpc:t,device:n,status:h,enabled:b&&g,showStatusPills:!0})}),r("td",{className:"px-2 py-2 align-middle text-right whitespace-nowrap",children:u("span",{className:"inline-flex items-center gap-1.5",children:[r(Ih,{trpc:t,device:n,flags:s}),r(_h,{status:h})]})})]})}function Dh(e,t){const[n,o]=$(e);return Y(()=>{const s=setTimeout(()=>o(e),t);return()=>clearTimeout(s)},[e,t]),n}const RS=new Set(["hub","nvr"]);function OS(e){const t=new Map;for(const s of e)t.set(s.id,s);const n=[],o=new Map;for(const s of e){const a=s.parentDeviceId;if(a==null){n.push(s);continue}const i=t.get(a);if(!i){n.push(s);continue}const l=s.role!==null&&s.role!==void 0;if(RS.has(i.type)&&!l){n.push(s);continue}const d=o.get(a);d?d.push(s):o.set(a,[s])}return{topLevel:n,accessoriesByParent:o}}const ou=2;function zS(e,t){if(t<=1)return[{kind:"page",n:1}];if(t<=7){const a=[];for(let i=1;i<=t;i++)a.push({kind:"page",n:i});return a}const n=[],o=Math.max(2,e-ou),s=Math.min(t-1,e+ou);n.push({kind:"page",n:1}),o>2&&n.push({kind:"ellipsis",side:"left"});for(let a=o;a<=s;a++)n.push({kind:"page",n:a});return s<t-1&&n.push({kind:"ellipsis",side:"right"}),n.push({kind:"page",n:t}),n}function BS({currentPage:e,totalItems:t,pageSize:n,onPageChange:o,itemNoun:s="devices"}){if(t<=n)return null;const a=Math.ceil(t/n),i=(e-1)*n+1,l=Math.min(e*n,t),c=zS(e,a);return u("div",{className:"flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle",children:[u("span",{children:["Showing ",i,"–",l," of ",t," ",s]}),u("span",{className:"inline-flex items-center gap-1",children:[r("button",{type:"button","aria-label":"Previous page",disabled:e===1,onClick:()=>o(e-1),className:K("inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle","hover:text-foreground hover:bg-surface-hover transition-colors","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface"),children:r(l2,{className:"h-3 w-3"})}),c.map((d,f)=>{if(d.kind==="ellipsis")return r("span",{className:"px-1 text-foreground-subtle/60 select-none",children:"…"},`e-${f}`);const p=d.n===e;return r("button",{type:"button",onClick:()=>o(d.n),className:K("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}`)}),r("button",{type:"button","aria-label":"Next page",disabled:e===a,onClick:()=>o(e+1),className:K("inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle","hover:text-foreground hover:bg-surface-hover transition-colors","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface"),children:r(Cn,{className:"h-3 w-3"})})]})]})}function FS({view:e,onViewChange:t,types:n,currentType:o,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:[r("button",{type:"button",onClick:()=>t("cards"),className:K("inline-flex items-center justify-center h-7 w-8 transition-colors",e==="cards"?"bg-primary/10 text-primary":"bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),"aria-label":"Cards view",children:r(W2,{className:"h-3.5 w-3.5"})}),r("button",{type:"button",onClick:()=>t("table"),className:K("inline-flex items-center justify-center h-7 w-8 border-l border-border transition-colors",e==="table"?"bg-primary/10 text-primary":"bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),"aria-label":"Table view",children:r(Hk,{className:"h-3.5 w-3.5"})})]}),n&&n.length>0&&u(ve,{children:[r(su,{children:"Type"}),r(qa,{active:o===null,onClick:()=>s(null),children:"All"}),n.map(d=>r(qa,{active:o===d,onClick:()=>s(o===d?null:d),children:jS(d)},d))]}),!c&&a&&a.length>0&&u(ve,{children:[r(su,{children:"Integration"}),a.map(d=>r(qa,{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 su({children:e}){return r("span",{className:"text-[10px] font-medium uppercase tracking-wider text-foreground-subtle ml-1",children:e})}function qa({active:e,icon:t,onClick:n,showClearIcon:o,children:s}){return u("button",{type:"button",onClick:n,className:K("inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border text-[10.5px] font-medium transition-colors",e?"border-primary/40 bg-primary/15 text-primary":"border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),children:[t&&r("span",{className:"inline-flex items-center",children:t}),r("span",{children:s}),e&&o&&r(Je,{className:"h-2.5 w-2.5 opacity-70"})]})}function jS(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function HS({variant:e,onClearFilters:t}){return u("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[r(Q2,{className:"h-8 w-8 text-foreground-subtle/40 mb-3"}),r("p",{className:"text-sm font-medium text-foreground-subtle",children:e==="filtered"?"No devices match the current filters":"No devices yet"}),e==="filtered"&&t&&r("button",{type:"button",onClick:t,className:"mt-2 text-[11px] text-primary hover:underline",children:"Clear filters"})]})}function 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 au(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 VS(e,t){try{localStorage.setItem(`camstack:${e}:lastFilters`,JSON.stringify(t))}catch{}}function iu(e,t,n){const o=new URLSearchParams(window.location.search),s=o.get(qt(e,"view")),a=s==="cards"||s==="table"?s:n.view??t,i=o.get(qt(e,"page")),l=i?parseInt(i,10):1,c=Number.isFinite(l)&&l>=1?l:1,d=o.get(qt(e,"addon"))??n.addon??null,f=o.get(qt(e,"type"))??n.type??null,p=o.get(qt(e,"q"))??n.q??"";return{view:a,page:c,addon:d,type:f,q:p}}function qS(e,t,n){const o=new URLSearchParams(window.location.search),s=(l,c)=>{c===null||c===""?o.delete(l):o.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=o.toString(),i=a?`${window.location.pathname}?${a}`:window.location.pathname;window.history.replaceState(null,"",i)}function QS(e){const{scope:t,defaultView:n,lsKey:o}=e,[s,a]=$(()=>{const g=au(o);return iu(t,n,g)}),i=ne(s);i.current=s,Y(()=>{const g=()=>{const b=au(o),x=iu(t,n,b);i.current=x,a(x)};return window.addEventListener("popstate",g),()=>window.removeEventListener("popstate",g)},[t,n,o]);const l=q(g=>{const b=g(i.current);i.current=b,a(b),qS(t,b,n),VS(o,{view:b.view,addon:b.addon,type:b.type,q:b.q})},[t,n,o]),c=q(g=>l(b=>({...b,view:g})),[l]),d=q(g=>l(b=>({...b,page:g})),[l]),f=q(g=>l(b=>({...b,addon:g,page:1})),[l]),p=q(g=>l(b=>({...b,type:g,page:1})),[l]),m=q(g=>l(b=>({...b,q:g,page:1})),[l]),h=q(()=>l(g=>({...g,addon:null,type:null,q:"",page:1})),[l]);return{state:s,setView:c,setPage:d,setAddon:f,setType:p,setQ:m,clearFilters:h}}const US={cards:24,table:50};function ao(e){const{devices:t,trpc:n,defaultView:o="table",filters:s,forceAddon:a,resolveIntegrationIcon:i,resolveParent:l,onNavigate:c,pageSize:d=US,urlScope:f="root",lsKey:p=f==="root"?"devices":"integrations:nested"}=e,m=QS({scope:f,defaultView:o,lsKey:p}),h=m.state.view,g=h==="cards"?d.cards:d.table,[b,x]=$(m.state.q),v=Dh(b,300);Y(()=>{v!==m.state.q&&m.setQ(v)},[v]);const w=a??m.state.addon,y=Q(()=>{const O=m.state.q.toLowerCase().trim();return t.filter(A=>!(w&&A.addonId!==w||m.state.type&&A.type!==m.state.type||O&&!A.name.toLowerCase().includes(O)&&!A.stableId.toLowerCase().includes(O)))},[t,w,m.state.type,m.state.q]),N=Q(()=>OS(y),[y]),k=Q(()=>{if(m.state.q.trim()==="")return new Set;const O=m.state.q.toLowerCase().trim(),A=new Set;for(const[D,_]of N.accessoriesByParent.entries())_.some(R=>R.name.toLowerCase().includes(O)||R.stableId.toLowerCase().includes(O))&&A.add(D);return A},[N.accessoriesByParent,m.state.q]),S=N.topLevel.length,M=Math.max(1,Math.ceil(S/g)),P=Math.min(m.state.page,M),I=(P-1)*g,F=N.topLevel.slice(I,I+g);Y(()=>{P!==m.state.page&&m.setPage(P)},[P]),XS();const E=w!=null||m.state.type!==null||m.state.q!=="",B=S===0;return u("div",{className:"flex flex-col gap-3",children:[u("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[r(FS,{view:h,onViewChange:m.setView,types:s?.types,currentType:m.state.type,onTypeChange:m.setType,addons:s?.addons,currentAddon:m.state.addon,onAddonChange:m.setAddon,hideAddons:a!==void 0}),u("div",{className:"relative",children:[r(oo,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle pointer-events-none"}),r("input",{type:"text",value:b,onChange:O=>x(O.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?r(HS,{variant:E?"filtered":"nofilter",onClearFilters:E?m.clearFilters:void 0}):h==="cards"?r(KS,{rows:F,accessoriesByParent:N.accessoriesByParent,trpc:n,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:c??null}):r(YS,{rows:F,accessoriesByParent:N.accessoriesByParent,autoExpandedParents:k,devices:y,trpc:n,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:c??null}),r(BS,{currentPage:P,totalItems:S,pageSize:g,onPageChange:m.setPage}),a===void 0&&E&&S>0&&u("p",{className:"text-[11px] text-foreground-subtle",children:["Showing ",S," of ",t.length," devices",w&&u(ve,{children:[" ","· filtered by"," ",r("strong",{className:"text-primary",children:s?.addons?.find(O=>O.id===w)?.name??w})]})]})]})}function KS({rows:e,accessoriesByParent:t,trpc:n,resolveIntegrationIcon:o,resolveParent:s,onNavigate:a}){return r("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:e.map(i=>{const l=t.get(i.id)??[];return r(so,{trpc:n,device:i,view:"card",integrationIcon:o?.(i.addonId)??null,parent:i.parentDeviceId!==null?s?.(i.parentDeviceId)??null:null,children:l,onNavigate:a??void 0},i.id)})})}const GS=new Set(["hub","nvr"]);function WS(e,t){return e.parentDeviceId===null||t===null?0:GS.has(t.toLowerCase())?1:0}function YS({rows:e,accessoriesByParent:t,autoExpandedParents:n,devices:o,trpc:s,resolveIntegrationIcon:a,resolveParent:i,onNavigate:l}){const c=Q(()=>{const d=new Map;for(const f of o)d.set(f.id,f.type);return d},[o]);return r("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:u("table",{className:"w-full border-collapse",children:[r("thead",{children:u("tr",{className:"border-b border-border",children:[r("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle",children:"Name"}),r("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-24",children:"Type"}),r("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Features"}),r("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-20",children:"Preview"}),r("th",{className:"text-right px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Actions"})]})}),r("tbody",{children:e.map(d=>{const f=t.get(d.id)??[],p=f.length>0,m=n.has(d.id),h=d.parentDeviceId!==null?i?.(d.parentDeviceId)??null:null,g=d.parentDeviceId!==null?c.get(d.parentDeviceId)??null:null;return r(ZS,{parent:d,accessories:f,hasAccessories:p,forceExpanded:m,trpc:s,integrationIcon:a?.(d.addonId)??null,parentRowParent:h,indentLevel:WS(d,g),onNavigate:l??null},d.id)})})]})})}function ZS({parent:e,accessories:t,hasAccessories:n,forceExpanded:o,trpc:s,integrationIcon:a,parentRowParent:i,indentLevel:l,onNavigate:c}){const[d,f]=$(o),p=ne(o);return Y(()=>{p.current!==o&&(f(o),p.current=o)},[o]),u(ve,{children:[r(so,{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=>r(so,{trpc:s,device:g,view:"table",integrationIcon:null,parent:null,isAccessoryRow:!0,showChildrenAccordion:!1,onNavigate:c??void 0},g.id))]})}function XS(){ke()}function JS({options:e,value:t,onChange:n}){return r("div",{className:"flex flex-wrap gap-2",children:e.map(o=>{const s=o.id===t;return u("button",{onClick:()=>o.available&&n(o.id),disabled:!o.available,className:`flex items-center gap-2 rounded-lg border px-3 py-2 text-xs font-medium transition-all ${s?"border-primary/40 bg-primary/10 text-primary":o.available?"border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground":"border-border/40 bg-surface/40 text-foreground-subtle/40 cursor-not-allowed"}`,children:[r(A2,{className:"h-3.5 w-3.5 shrink-0"}),o.label,o.isBest&&u("span",{className:"inline-flex items-center gap-0.5 rounded-full bg-amber-500/15 px-1.5 py-0.5 text-[10px] font-semibold text-amber-400",children:[r(Bk,{className:"h-2.5 w-2.5"}),"Best"]}),o.platformScore!=null&&u("span",{className:"text-[10px] text-foreground-subtle/60",children:["(",o.platformScore,")"]}),r("span",{className:`h-1.5 w-1.5 rounded-full ${o.available?"bg-success":"bg-danger"}`})]},o.id)})})}function eC(e,t){const n=new Set(t.slots.flatMap(i=>i.addons.map(l=>l.id))),o=[];function s(i){if(!n.has(i.addonId))return o.push(`Addon "${i.addonId}" is no longer available — step removed`),null;const l=t.slots.flatMap(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;o.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:o.length===0,steps:a,warnings:o}}function tC(e){const t=new Map;for(const n of e.slots)for(const o of n.addons)t.set(o.id,o);return t}function Qa(e){return{addonId:e.id,addonName:e.name,slot:e.slot,inputClasses:[...e.inputClasses],outputClasses:[...e.outputClasses],enabled:!0,modelId:e.defaultModelId,children:[]}}function Ua({addon:e,onClick:t}){return r("button",{type:"button",onClick:t,className:"w-full rounded-lg border border-dashed border-border/60 px-3 py-2.5 text-left transition-all hover:border-primary/30 hover:bg-surface/60 group",children:u("div",{className:"flex items-center gap-3",children:[r(v2,{className:"h-[18px] w-[18px] text-foreground-subtle/30 group-hover:text-primary/60 shrink-0"}),u("div",{className:"flex-1 min-w-0",children:[r("span",{className:"text-[13px] font-medium text-foreground-subtle/50 group-hover:text-foreground-subtle block truncate",children:e.name}),u("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(n=>r("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-blue-500/8 text-blue-400/50",children:n},n)),e.inputClasses.length>0&&e.outputClasses.length>0&&r("span",{className:"text-foreground-subtle/25 text-[10px]",children:"→"}),e.outputClasses.map(n=>r("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-green-500/8 text-green-400/50",children:n},n))]})]})]})})}function rc({schema:e,steps:t,onChange:n,templates:o,selectedTemplateId:s,onSelectTemplate:a,onSaveTemplate:i,onUpdateTemplate:l,onDeleteTemplate:c,readOnly:d=!1,excludeAddons:f=[],hideTemplates:p=!1,showOnlyEnabled:m=!1,showSlotLabels:h=!1,toggleMode:g="simple",overrides:b={},onOverrideChange:x,inheritedEnabledByAddon:v={},hideModelAndSettings:w=!1}){const y=H=>({toggleMode:g,hideModelAndSettings:w,...g==="threeState"?{overrideState:b[H]!==void 0?b[H]:null,onOverrideChange:x?T=>x(H,T):void 0,inheritedEnabled:v[H]}:{}}),N=Q(()=>new Set(f),[f]),k=Q(()=>tC(e),[e]),[S,M]=$([]),P=s?JSON.stringify(t)!==JSON.stringify(o.find(H=>H.id===s)?.steps):!1;function I(H){const T=H.target.value||null;if(T){const W=o.find(G=>G.id===T);if(W){const G=eC(W.steps,e);M([...G.warnings])}}else M([]);a(T)}function F(){s&&l(s,t)}function E(){const H=window.prompt("Template name:");H?.trim()&&i(H.trim(),t)}function B(){if(!s)return;const H=o.find(T=>T.id===s);H&&window.confirm(`Delete template "${H.name}"?`)&&c(s)}function O(H){n(t.map(T=>T.addonId!==H.addonId?T:A(H)))}function A(H){const T=H.children.some(W=>W.enabled||W.children.some(G=>G.enabled));return{...H,enabled:H.enabled||T,children:H.children.map(W=>{const G=W.children.some(ee=>ee.enabled);return{...W,enabled:W.enabled||G}})}}function D(H,T){const W=Qa(T);n(t.map(G=>G.addonId!==H?G:{...G,children:[...G.children,W]}))}function _(H){const T=new Set;for(const W of H){T.add(W.addonId);for(const ee of W.children)T.add(ee.addonId);const G=_(W.children);for(const ee of G)T.add(ee)}return T}const R=_(t);function L(H){const T=k.get(H.addonId);if(!T)return[];const G=e.slots.find(X=>X.id===T.slot)?.parentSlot==null,ee=T.childSlots,se=new Set(H.children.map(X=>X.addonId)),te=[];for(const X of e.slots)if(ee.includes(X.id))for(const re of X.addons){if(se.has(re.id)||N.has(re.id))continue;const ge=re.inputClasses.length===0;if(ge&&!G)continue;(ge||re.inputClasses.some(U=>H.outputClasses.includes(U)))&&te.push(re)}return te}function z(H){const T=m?{...H,children:H.children.filter(G=>G.enabled).map(G=>({...G,children:G.children.filter(ee=>ee.enabled)}))}:H,W=m?[]:L(T);return u("div",{className:"space-y-1.5",children:[r(ps,{step:T,schema:k.get(T.addonId)??null,allSchemas:k,onChange:O,onDelete:d?void 0:G=>n(t.filter(ee=>ee.addonId!==G)),readOnly:d,...y(T.addonId)}),(T.children.length>0||W.length>0)&&u("div",{className:"ml-4 pl-3 border-l border-border/60 space-y-1.5",children:[h&&r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/40",children:"Slot: Cropper / Classifier"}),T.children.map(G=>{const ee=L(G);return u("div",{className:"space-y-1.5",children:[r(ps,{step:G,schema:k.get(G.addonId)??null,allSchemas:k,depth:1,onChange:se=>{O({...T,children:T.children.map(te=>te.addonId===se.addonId?se:te)})},onDelete:d?void 0:se=>{O({...T,children:T.children.filter(te=>te.addonId!==se)})},readOnly:d,...y(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:[h&&r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/30",children:"Slot: Recognizer"}),G.children.map(se=>r(ps,{step:se,schema:k.get(se.addonId)??null,allSchemas:k,depth:2,onChange:te=>{O({...T,children:T.children.map(X=>X.addonId===G.addonId?{...X,children:X.children.map(re=>re.addonId===te.addonId?te:re)}:X)})},onDelete:d?void 0:te=>{O({...T,children:T.children.map(X=>X.addonId===G.addonId?{...X,children:X.children.filter(re=>re.addonId!==te)}:X)})},readOnly:d,...y(se.addonId)},se.addonId)),!d&&ee.map(se=>r(Ua,{addon:se,onClick:()=>{const te=Qa(se);O({...T,children:T.children.map(X=>X.addonId===G.addonId?{...X,children:[...X.children,te]}:X)})}},se.id))]})]},G.addonId)}),!d&&W.map(G=>r(Ua,{addon:G,onClick:()=>D(T.addonId,G)},G.id))]})]},T.addonId)}const j=e.slots.filter(H=>H.parentSlot===null).sort((H,T)=>H.priority-T.priority);return u("div",{className:"space-y-4",children:[!p&&r("div",{className:"rounded-lg border border-border bg-surface p-3",children:u("div",{className:"flex items-center gap-2",children:[r("div",{className:"relative flex-1 min-w-0",children:u("select",{value:s??"",onChange: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:[r("option",{value:"",children:"No template"}),o.map(H=>r("option",{value:H.id,children:H.name},H.id))]})}),P&&r("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500 shrink-0"}),r("button",{onClick:F,disabled:!s||d,title:"Save",className:K("p-2 rounded-lg border border-border transition-colors",s&&!d?"text-foreground-subtle hover:bg-surface-hover":"text-foreground-subtle/30 cursor-not-allowed"),children:r(kk,{className:"h-4 w-4"})}),r("button",{onClick:E,disabled:d,title:"Save As",className:K("p-2 rounded-lg border border-border transition-colors",d?"text-foreground-subtle/30 cursor-not-allowed":"text-foreground-subtle hover:bg-surface-hover"),children:r(C2,{className:"h-4 w-4"})}),r("button",{onClick:B,disabled:!s||d,title:"Delete",className:K("p-2 rounded-lg border border-border transition-colors",s&&!d?"text-foreground-subtle hover:text-danger":"text-foreground-subtle/30 cursor-not-allowed"),children:r(rn,{className:"h-4 w-4"})})]})}),S.length>0&&u("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 text-xs text-amber-400 space-y-1",children:[u("div",{className:"flex items-center justify-between",children:[r("span",{className:"font-medium",children:"Template loaded with warnings:"}),r("button",{onClick:()=>M([]),className:"text-amber-400/60 hover:text-amber-400",children:r(Je,{className:"h-3.5 w-3.5"})})]}),S.map((H,T)=>u("div",{children:["• ",H]},T))]}),j.map(H=>{const T=t.filter(te=>te.slot===H.id&&!N.has(te.addonId)),W=m?T.filter(te=>te.enabled):T,G=m?[]:H.addons.filter(te=>!R.has(te.id)&&!N.has(te.id)),ee=new Map,se=[];for(const te of W)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:[h&&u("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50",children:["Slot: ",H.label]}),se.map(te=>z(te)),[...ee.entries()].map(([te,X])=>u("div",{className:"space-y-2 rounded-lg border border-border/40 p-2",children:[r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50 px-1",children:te}),X.map(re=>z(re))]},te)),!d&&G.map(te=>r(Ua,{addon:te,onClick:()=>{n([...t,Qa(te)])}},te.id))]},H.id)})]})}const Qr={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"},lu=["#ef4444","#8b5cf6","#06b6d4","#f97316","#10b981","#6366f1","#e11d48","#0891b2","#7c3aed","#059669"],Lh="#f59e42";function ct(e,t){if(t?.[e])return t[e];if(t?.[e.toLowerCase()])return t[e.toLowerCase()];if(Qr[e])return Qr[e];if(Qr[e.toLowerCase()])return Qr[e.toLowerCase()];let n=0;for(let o=0;o<e.length;o++)n=n*31+(e.codePointAt(o)??0)>>>0;return lu[n%lu.length]??Lh}function nC({src:e,imageWidth:t,imageHeight:n,detections:o=[],classColors:s,aspectRatio:a,className:i,placeholder:l,showConfidence:c=!0,minConfidence:d=0,borderWidth:f=2}){function p(v){return ct(v,s)}const m=a??(t&&n?`${t}/${n}`:"16/9"),h=o.filter(v=>v.score>=d),g=h.filter(v=>v.kind==="first-level"),b=h.filter(v=>v.kind==="detail"),x=sC(b,v=>v.parentId??"");return r("div",{className:K("rounded-lg border border-border bg-surface overflow-hidden relative",i),style:{aspectRatio:m},children:e?u(ve,{children:[r("img",{src:e,className:"absolute inset-0 w-full h-full object-fill",alt:""}),h.map((v,w)=>v.debug?.mask&&v.debug.maskWidth&&v.debug.maskHeight?r(rC,{mask:v.debug.mask,maskWidth:v.debug.maskWidth,maskHeight:v.debug.maskHeight,bbox:v.bbox,imageWidth:t,imageHeight:n,color:p(v.macroClass)},`mask-${w}`):null),g.map(v=>{const w=x.get(v.id)??[];return r(cu,{detection:v,imageWidth:t,imageHeight:n,color:p(v.macroClass),showConfidence:c,borderWidth:v.debug?.mask?1:f,children:w.map(y=>r(oC,{child:y,parentBbox:v.bbox,color:p(y.macroClass),showConfidence:c},`child-${y.id}`))},`det-${v.id}`)}),b.filter(v=>!v.parentId||!g.some(w=>w.id===v.parentId)).map(v=>r(cu,{detection:v,imageWidth:t,imageHeight:n,color:p(v.macroClass),showConfidence:c,borderWidth:f},`orphan-${v.id}`))]}):r("div",{className:"w-full h-full flex items-center justify-center text-foreground-subtle text-sm",children:l??"No image loaded"})})}function cu({detection:e,imageWidth:t,imageHeight:n,color:o,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:o},children:[e.macroClass,s&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((m,h)=>u("span",{className:"text-[9px] font-semibold px-1 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:ct(m.label)},children:[m.label," ",(m.score*100).toFixed(0),"%"]},`${e.id}-lbl-${h}`))]});return u("div",{className:"absolute rounded-sm",style:{left:`${l/t*100}%`,top:`${c/n*100}%`,width:`${d/t*100}%`,height:`${f/n*100}%`,borderWidth:`${a}px`,borderStyle:"solid",borderColor:o},children:[p,i]})}function rC({mask:e,maskWidth:t,maskHeight:n,bbox:o,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 v=0;v<f.length;v++)p[v]=f.charCodeAt(v);const m=parseInt(i.slice(1,3),16),h=parseInt(i.slice(3,5),16),g=parseInt(i.slice(5,7),16);c.width=t,c.height=n;const b=d.createImageData(t,n),x=t*n;for(let v=0;v<x;v++){const w=v<p.length?p[v]:0,y=v*4;w>0&&(b.data[y]=m,b.data[y+1]=h,b.data[y+2]=g,b.data[y+3]=120)}d.putImageData(b,0,0)},[e,t,n,i]),r("canvas",{ref:l,className:"absolute pointer-events-none",style:{left:`${o.x/s*100}%`,top:`${o.y/a*100}%`,width:`${o.width/s*100}%`,height:`${o.height/a*100}%`,imageRendering:"pixelated"}})}function oC({child:e,parentBbox:t,color:n,showConfidence:o}){if(t.width<=0||t.height<=0)return null;const s=(e.bbox.x-t.x)/t.width*100,a=(e.bbox.y-t.y)/t.height*100,i=e.bbox.width/t.width*100,l=e.bbox.height/t.height*100;return r("div",{className:"absolute rounded-sm",style:{left:`${Math.max(0,s)}%`,top:`${Math.max(0,a)}%`,width:`${Math.min(100,i)}%`,height:`${Math.min(100,l)}%`,borderWidth:"1px",borderStyle:"solid",borderColor:n},children:u("div",{className:"absolute left-0 flex flex-col items-start gap-px",style:{bottom:"100%",marginBottom:"1px"},children:[u("span",{className:"text-[9px] px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:n},children:[e.macroClass,o&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((c,d)=>u("span",{className:"text-[8px] font-semibold px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:ct(c.label)},children:[c.label," ",(c.score*100).toFixed(0),"%"]},`${e.id}-lbl-${d}`))]})})}function sC(e,t){const n=new Map;for(const o of e){const s=t(o),a=n.get(s)??[];a.push(o),n.set(s,a)}return n}function aC({detections:e,classColors:t,className:n,hiddenKeys:o,onToggleVisibility:s}){const a=t;if(e.length===0)return r("div",{className:"text-sm text-foreground-subtle italic text-center py-4",children:"No detections"});const i=e.filter(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=>r(du,{detection:f,children_:c.get(f.id)??[],colors:a,hiddenKeys:o,onToggleVisibility:s},f.id)),d.map(f=>r(du,{detection:f,children_:[],colors:a,hiddenKeys:o,onToggleVisibility:s},f.id))]})]})}function du({detection:e,children_:t,colors:n,hiddenKeys:o,onToggleVisibility:s}){const a=ct(e.macroClass,n),i=!o?.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&&r("input",{type:"checkbox",checked:i,onChange:()=>s(e.id,!i),className:"h-3.5 w-3.5 rounded border-border accent-primary cursor-pointer shrink-0"}),r("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{backgroundColor:a}}),r("span",{className:"text-sm font-medium text-foreground",children:e.macroClass}),e.kind==="detail"&&r("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:"detail"}),l&&c&&d&&u("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",c,"x",d]})]}),r(cC,{confidence:e.score})]}),u("div",{className:"text-[10px] text-foreground-subtle font-mono",children:["bbox: [",Math.round(e.bbox.x),", ",Math.round(e.bbox.y),","," ",Math.round(e.bbox.x+e.bbox.width),","," ",Math.round(e.bbox.y+e.bbox.height),"]"]}),e.labels.length>0&&r("div",{className:"flex flex-wrap gap-1 mt-1",children:e.labels.map((p,m)=>u("span",{className:"inline-flex items-center gap-1 text-[10px] font-medium px-1.5 py-0.5 rounded-full",style:{backgroundColor:ct(p.label,n)+"20",color:ct(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]})]},m))}),f&&Object.keys(f).length>0&&r(lC,{alternateLabels:f,colors:n}),t.length>0&&r(iC,{items:t,colors:n,hiddenKeys:o,onToggleVisibility:s})]})}function iC({items:e,colors:t,hiddenKeys:n,onToggleVisibility:o}){return r("div",{className:"ml-4 mt-1.5 space-y-1.5 border-l-2 border-border pl-3",children:e.map(s=>{const a=ct(s.macroClass,t),i=!n?.has(s.id),l=s.debug?.mask,c=s.debug?.maskWidth,d=s.debug?.maskHeight;return u("div",{className:`text-xs space-y-0.5 ${i?"":"opacity-40"}`,children:[u("div",{className:"flex items-center gap-1.5",children:[o&&r("input",{type:"checkbox",checked:i,onChange:()=>o(s.id,!i),className:"h-3 w-3 rounded border-border accent-primary cursor-pointer shrink-0"}),r("span",{className:"h-1.5 w-1.5 rounded-full shrink-0",style:{backgroundColor:a}}),r("span",{className:"font-medium",style:{color:a},children:s.macroClass}),u("span",{className:"text-foreground-subtle",children:[(s.score*100).toFixed(0),"%"]}),l&&c&&d&&u("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",c,"x",d]})]}),s.labels.length>0&&r("div",{className:"flex flex-wrap gap-1 ml-5 mt-0.5",children:s.labels.map((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:ct(f.label,t)+"20",color:ct(f.label,t)},children:[f.label," ",u("span",{className:"opacity-60",children:[(f.score*100).toFixed(0),"%"]})]},p))})]},s.id)})})}function lC({alternateLabels:e,colors:t}){const[n,o]=$(!1),s=Object.keys(e);return u("div",{className:"mt-1",children:[u("button",{onClick:()=>o(a=>!a),className:"text-[9px] text-foreground-subtle hover:text-foreground transition-colors flex items-center gap-1",children:[r("span",{className:`transition-transform ${n?"rotate-90":""}`,children:"▶"}),"Alternates (",s.length," source",s.length!==1?"s":"",")"]}),n&&r("div",{className:"mt-1 ml-3 space-y-1.5",children:s.map(a=>{const i=e[a];return!i||i.length===0?null:u("div",{children:[r("div",{className:"text-[9px] font-medium text-foreground-subtle mb-0.5",children:a}),r("div",{className:"flex flex-wrap gap-1",children:i.map((l,c)=>u("span",{className:"inline-flex items-center gap-0.5 text-[9px] px-1 py-0.5 rounded-full",style:{backgroundColor:ct(a,t)+"10",color:ct(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 cC({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 dC({timings:e,totalMs:t,className:n}){const o=Object.entries(e);return o.length===0&&t===void 0?null:u("div",{className:`rounded-lg border border-border bg-surface p-3 space-y-2 ${n??""}`,children:[r("div",{className:"text-xs font-medium text-foreground-subtle uppercase tracking-wide",children:"Timings"}),u("div",{className:"space-y-1 text-xs",children:[o.map(([s,a])=>u("div",{className:"flex justify-between",children:[r("span",{className:"text-foreground-subtle",children:s}),u("span",{className:"font-mono text-foreground",children:[a.toFixed(1),"ms"]})]},s)),t!==void 0&&u("div",{className:"flex justify-between pt-1 border-t border-border font-medium text-foreground",children:[r("span",{children:"Total"}),u("span",{className:"font-mono",children:[t.toFixed(1),"ms"]})]})]})]})}function uC({images:e,selectedFilename:t,uploadedName:n,onSelect:o,onUpload:s,className:a,accept:i="image/*",uploadLabel:l="Upload..."}){const c=()=>{const d=document.createElement("input");d.type="file",d.accept=i,d.onchange=()=>{const f=d.files?.[0];if(!f)return;const p=new FileReader;p.onload=()=>{const m=p.result,h=m.split(",")[1];h&&s(h,f.name,m)},p.readAsDataURL(f)},d.click()};return u("div",{className:`flex flex-wrap items-center gap-2 ${a??""}`,children:[e.map(d=>r("button",{onClick:()=>o(d.filename),className:`px-3 py-1.5 text-xs rounded-md border transition-colors ${t===d.filename?"bg-primary text-primary-foreground border-primary":"bg-surface border-border text-foreground hover:border-primary/50"}`,children:d.id??d.filename.replace(/\.[^.]+$/,"")},d.filename)),r("button",{onClick:c,className:"px-3 py-1.5 text-xs rounded-md border border-border bg-surface text-foreground hover:bg-surface-hover transition-colors",children:l}),n&&r("span",{className:"text-xs text-foreground-subtle",children:n})]})}const zo="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 pC({runtime:e,backend:t,modelId:n,agentId:o="hub",runtimes:s,backends:a,models:i,agents:l=[],onRuntimeChange:c,onBackendChange:d,onModelChange:f,onAgentChange:p,layout:m="grid",className:h,showAgent:g=!1}){return u("div",{className:`${m==="grid"?"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4":m==="horizontal"?"flex flex-wrap items-end gap-4":"space-y-3"} ${h??""}`,children:[g&&l.length>0&&u("label",{className:"space-y-1",children:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Agent"}),r("select",{value:o,onChange:x=>p?.(x.target.value),className:zo,children:l.map(x=>u("option",{value:x.id,children:[x.name," (",x.status,")"]},x.id))})]}),u("label",{className:"space-y-1",children:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Runtime"}),r("select",{value:e,onChange:x=>c(x.target.value),className:zo,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:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Backend"}),r("select",{value:t,onChange:x=>d(x.target.value),className:zo,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:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Model"}),r("select",{value:n,onChange:x=>f(x.target.value),className:zo,children:i.length===0?r("option",{value:"",children:"No compatible models"}):i.map(x=>u("option",{value:x.id,children:[x.name,x.downloaded?" ✓":""]},x.id))})]})]})}function fC({className:e}){return u("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[r("path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}),r("circle",{cx:"12",cy:"12",r:"3"})]})}function mC({className:e}){return u("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[r("path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"}),r("path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}),r("path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"}),r("path",{d:"m2 2 20 20"})]})}function hC({className:e}){return r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:r("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function Th({onLogin:e,serverUrl:t,logoSrc:n,error:o,className:s}){const[a,i]=$(""),[l,c]=$(""),[d,f]=$(!1),[p,m]=$(!1),[h,g]=$(null),b=o??h,x=async v=>{if(v.preventDefault(),!p){g(null),m(!0);try{await e(a,l)}catch(w){const y=w instanceof Error?w.message:"Login failed. Please try again.";g(y)}finally{m(!1)}}};return r("div",{className:K("flex min-h-screen items-center justify-center bg-background p-4",s),children:u("div",{className:"w-full max-w-sm",children:[n&&r("div",{className:"flex justify-center mb-8",children:r("img",{src:n,alt:"Logo",className:"h-12"})}),t&&r("p",{className:"mb-4 text-center text-xs text-foreground-subtle truncate",children:t}),u("form",{onSubmit:x,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[b&&r("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:b}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"Username"}),r("input",{type:"text",value:a,onChange:v=>i(v.target.value),autoComplete:"username",required:!0,className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary"})]}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"Password"}),u("div",{className:"relative",children:[r("input",{type:d?"text":"password",value:l,onChange:v=>c(v.target.value),autoComplete:"current-password",required:!0,className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary"}),r("button",{type:"button",onClick:()=>f(v=>!v),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",tabIndex:-1,children:d?r(mC,{className:"h-4 w-4"}):r(fC,{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&&r(hC,{className:"h-4 w-4 animate-spin"}),p?"Logging in...":"Log in"]})]})]})})}const qi="camstack_dev_token",Rh=Oe(null);function gC(){const e=ye(Rh);if(!e)throw new Error("useDevShell must be used within a DevShell");return e}function bC(){return typeof window>"u"?null:localStorage.getItem(qi)}function xC({className:e}){return u("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[r("circle",{cx:"12",cy:"12",r:"4"}),r("path",{d:"M12 2v2"}),r("path",{d:"M12 20v2"}),r("path",{d:"m4.93 4.93 1.41 1.41"}),r("path",{d:"m17.66 17.66 1.41 1.41"}),r("path",{d:"M2 12h2"}),r("path",{d:"M20 12h2"}),r("path",{d:"m6.34 17.66-1.41 1.41"}),r("path",{d:"m19.07 4.93-1.41 1.41"})]})}function yC({className:e}){return r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:r("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})})}function vC({children:e,serverUrl:t,title:n,token:o,onLogout:s}){const a=Ir(),i=Q(()=>{const m=t.replace(/^http/,"ws")+"/trpc",h=X1({url:m,connectionParams:()=>({token:o})});return[J1({condition:g=>g.type==="subscription",true:ew({client:h,transformer:_i}),false:jf({url:`${t}/trpc`,transformer:_i,headers:()=>({authorization:`Bearer ${o}`})})})]},[t,o]),l=Q(()=>Ff({links:i}),[i]),c=Q(()=>C.createClient({links:i}),[i]),d=Q(()=>Vf({serverUrl:t,token:o}),[t,o]);Y(()=>(d.init().catch(()=>{}),()=>{d.close()}),[d]);const f=Q(()=>new Of,[]),p=Q(()=>({trpc:l,token:o,logout:s}),[l,o,s]);return r(Xl,{system:d,children:r(C.Provider,{client:c,queryClient:f,children:r(zf,{client:f,children:r(Rh.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:[r("span",{className:"rounded bg-warning/20 px-2 py-0.5 text-xs font-bold text-warning",children:"DEV MODE"}),n&&r("span",{className:"text-sm font-medium text-foreground",children:n}),r("span",{className:"text-xs text-foreground-subtle",children:t})]}),u("div",{className:"flex items-center gap-2",children:[u("button",{type:"button",onClick:a.toggleMode,className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",title:`Theme: ${a.mode}`,children:[a.resolvedMode==="dark"?r(xC,{className:"h-3.5 w-3.5"}):r(yC,{className:"h-3.5 w-3.5"}),a.mode==="dark"?"Dark":a.mode==="light"?"Light":"System"]}),r("button",{type:"button",onClick:s,className:"rounded-md px-2.5 py-1 text-xs font-medium text-danger hover:bg-danger/10 transition-colors",children:"Logout"})]})]}),r("div",{className:"p-4",children:e({trpc:l,theme:a})})]})})})})})}function Oh({children:e,serverUrl:t="https://localhost:4443",title:n}){const[o,s]=$(bC),a=q(async(l,c)=>{const p=await Ff({links:[jf({url:`${t}/trpc`,transformer:_i})]}).auth.login.mutate({username:l,password:c});if(!p.token)throw new Error("No token returned");localStorage.setItem(qi,p.token),s(p.token)},[t]),i=q(()=>{localStorage.removeItem(qi),s(null)},[]);return o?r(ws,{children:r(vC,{serverUrl:t,title:n,token:o,onLogout:i,children:e})}):r(ws,{children:r(Th,{onLogin:a,serverUrl:t})})}function wC(e,t={}){const{serverUrl:n="https://localhost:4443",title:o,rootId:s="root"}=t,a=document.getElementById(s);if(!a){console.error(`[mountAddonPage] Element #${s} not found`);return}Tf(a).render(Me(Oh,{serverUrl:n,title:o,children:({trpc:i,theme:l})=>Me(e,{trpc:i,theme:{isDark:l.resolvedMode==="dark"},navigate:c=>{console.log("[dev] navigate:",c)}})}))}const zh=un("camstack:custom-field-renderers",{});function Bh({renderers:e,children:t}){return r(zh.Provider,{value:e,children:t})}function Fh(e){return ye(zh)[e]??null}const oc=un("camstack:device-context",null);function jh({deviceId:e,device:t,children:n}){const o={deviceId:e,device:t??null};return r(oc.Provider,{value:o,children:n})}function pn(){return ye(oc)?.deviceId??null}function sc(){return ye(oc)?.device??null}const NC=C.accessories.getStatus.useQuery,ac=C.addonPages.listPages.useQuery,ra=C.addons.list.useQuery,kC=C.addons.getLogs.useQuery,SC=C.addons.listPackages.useQuery,ic=C.addons.installPackage.useMutation,CC=C.addons.installFromWorkspace.useMutation,MC=C.addons.isWorkspaceAvailable.useQuery,IC=C.addons.listWorkspacePackages.useQuery,Hh=C.addons.uninstallPackage.useMutation,Vh=C.addons.reloadPackages.useMutation,qh=C.addons.searchAvailable.useQuery,lc=C.addons.listUpdates.useQuery,Qi=C.addons.updatePackage.useMutation,AC=C.addons.rollbackPackage.useMutation,Qh=C.addons.forceRefresh.useMutation,Uh=C.addons.restartServer.useMutation,Kh=C.addons.getVersions.useQuery,oa=C.addons.restartAddon.useMutation,Gh=C.addons.retryLoad.useMutation,Wh=C.addons.getAutoUpdateSettings.useQuery,PC=C.addons.setAutoUpdateSettings.useMutation,Yh=C.addons.getAddonAutoUpdate.useQuery,Zh=C.addons.setAddonAutoUpdate.useMutation,Xh=C.addons.applyAutoUpdateToAll.useMutation,EC=C.addons.custom.useMutation,$C=C.addons.onAddonLogs.useSubscription,cc=C.addonSettings.getGlobalSettings.useQuery,Jh=C.addonSettings.updateGlobalSettings.useMutation,_C=C.addonSettings.getDeviceSettings.useQuery,eg=C.addonSettings.updateDeviceSettings.useMutation,tg=C.addonWidgets.listWidgets.useQuery,DC=C.alerts.emit.useMutation,LC=C.alerts.update.useMutation,ng=C.alerts.list.useQuery,rg=C.alerts.getUnreadCount.useQuery,og=C.alerts.markRead.useMutation,sg=C.alerts.markAllRead.useMutation,ag=C.alerts.dismiss.useMutation,TC=C.audioAnalysis.resolveDeviceSettings.useQuery,RC=C.audioAnalysis.getDeviceSettingsContribution.useQuery,OC=C.audioAnalysis.getDeviceLiveContribution.useQuery,zC=C.audioAnalysis.applyDeviceSettingsPatch.useMutation,BC=C.audioAnalyzer.analyseChunk.useMutation,FC=C.audioAnalyzer.classify.useQuery,jC=C.audioAnalyzer.isReady.useQuery,HC=C.audioAnalyzer.dispose.useMutation,ig=C.audioAnalyzer.reprobeAudioEngine.useMutation,VC=C.audioCodec.listSupportedCodecs.useQuery,qC=C.audioCodec.canHandle.useQuery,QC=C.audioCodec.createDecodeSession.useMutation,UC=C.audioCodec.createEncodeSession.useMutation,KC=C.audioCodec.closeSession.useMutation,GC=C.audioCodec.pushEncodedFrame.useMutation,WC=C.audioCodec.pullPcm.useQuery,YC=C.audioCodec.pushPcm.useMutation,ZC=C.audioCodec.pullEncoded.useQuery,XC=C.audioCodec.flushEncode.useMutation,JC=C.audioCodec.listActiveSessions.useQuery,e3=C.audioMetrics.getCurrentSnapshot.useQuery,t3=C.audioMetrics.getHistory.useQuery,dc=C.authentication.listProviders.useQuery,n3=C.authentication.setProviderEnabled.useMutation,uc=C.backup.listDestinations.useQuery,lg=C.backup.trigger.useMutation,r3=C.backup.list.useQuery,cg=C.backup.listLocations.useQuery,dg=C.backup.getEntries.useQuery,ug=C.backup.restore.useMutation,pg=C.backup.delete.useMutation,pc=C.backup.listArchives.useQuery,fg=C.backup.upsertDestinationPolicy.useMutation,mg=C.backup.previewSchedule.useQuery,o3=C.battery.getStatus.useQuery,s3=C.brightness.setBrightness.useMutation,a3=C.brightness.getStatus.useQuery,i3=C.cameraStreams.getCameraStreams.useQuery,l3=C.cameraStreams.getBrokerStreams.useQuery,c3=C.cameraStreams.getRtspEntries.useQuery,d3=C.decoder.supportsCodec.useQuery,u3=C.decoder.getInfo.useQuery,p3=C.decoder.createSession.useQuery,f3=C.decoder.destroySession.useQuery,m3=C.decoder.pushPacket.useQuery,h3=C.decoder.openStream.useQuery,g3=C.decoder.pullFrames.useQuery,b3=C.decoder.updateConfig.useQuery,x3=C.decoder.getStats.useQuery,y3=C.decoder.listActiveSessions.useQuery,hg=C.decoder.reprobeHwaccel.useMutation,v3=C.detectionPipeline.getDeviceSettingsContribution.useQuery,w3=C.detectionPipeline.getDeviceLiveContribution.useQuery,N3=C.detectionPipeline.applyDeviceSettingsPatch.useMutation,gg=C.deviceDiscovery.listDiscovered.useQuery,bg=C.deviceDiscovery.refreshDiscovery.useMutation,k3=C.deviceDiscovery.adoptDevice.useMutation,S3=C.deviceDiscovery.releaseDevice.useMutation,C3=C.deviceDiscovery.getStatus.useQuery,M3=C.deviceManager.allocateDeviceId.useMutation,I3=C.deviceManager.registerDevice.useMutation,A3=C.deviceManager.removeDevice.useMutation,P3=C.deviceManager.persistConfig.useMutation,E3=C.deviceManager.loadConfig.useQuery,$3=C.deviceManager.loadRuntimeState.useQuery,_3=C.deviceManager.loadMeta.useQuery,xg=C.deviceManager.setName.useMutation,yg=C.deviceManager.setLocation.useMutation,D3=C.deviceManager.setMetadata.useMutation,vg=C.deviceManager.listLocations.useQuery,L3=C.deviceManager.addLocation.useMutation,T3=C.deviceManager.removeLocation.useMutation,R3=C.deviceManager.setDisabled.useMutation,O3=C.deviceManager.listPersistedByAddon.useQuery,Jn=C.deviceManager.listAll.useQuery,Fn=C.deviceManager.getDevice.useQuery,wg=C.deviceManager.getChildren.useQuery,z3=C.deviceManager.getStreamSources.useQuery,B3=C.deviceManager.getConfigSchema.useQuery,F3=C.deviceManager.getSettingsSchema.useQuery,j3=C.deviceManager.updateConfig.useMutation,Ng=C.deviceManager.enable.useMutation,kg=C.deviceManager.disable.useMutation,Sg=C.deviceManager.remove.useMutation,H3=C.deviceManager.getStreamProfileMap.useQuery,V3=C.deviceManager.setStreamProfileMap.useMutation,q3=C.deviceManager.probeStreams.useMutation,Cg=C.deviceManager.getBindings.useQuery,Q3=C.deviceManager.getAllBindings.useQuery,Mg=C.deviceManager.setWrapperActive.useMutation,U3=C.deviceManager.listWrappersForCap.useQuery,Ig=C.deviceManager.listBindableCapsForDeviceType.useQuery,K3=C.deviceManager.getDeviceSettingsAggregate.useQuery,G3=C.deviceManager.getDeviceLiveInfoAggregate.useQuery,fc=C.deviceManager.getDeviceAggregate.useQuery,W3=C.deviceManager.updateDeviceField.useMutation,Ag=C.deviceManager.updateDeviceFieldsBatch.useMutation,mc=C.deviceManager.discoverDevices.useMutation,Pg=C.deviceManager.adoptDevice.useMutation,Eg=C.deviceManager.getCreationSchema.useQuery,$g=C.deviceManager.createDevice.useMutation,hc=C.deviceManager.testCreationField.useMutation,Y3=C.deviceManager.testField.useMutation,Z3=C.deviceManager.getDeviceStatusAggregate.useQuery,X3=C.deviceOps.getStreamSources.useQuery,J3=C.deviceOps.getConfigEntries.useQuery,eM=C.deviceOps.setConfig.useMutation,tM=C.deviceOps.removeDevice.useMutation,nM=C.deviceOps.getSettingsSchema.useQuery,rM=C.deviceProvider.start.useMutation,oM=C.deviceProvider.stop.useMutation,sM=C.deviceProvider.getStatus.useQuery,aM=C.deviceProvider.getDevices.useQuery,iM=C.deviceProvider.supportsDiscovery.useQuery,lM=C.deviceProvider.discoverDevices.useMutation,cM=C.deviceProvider.adoptDiscoveredDevice.useMutation,dM=C.deviceProvider.supportsManualCreation.useQuery,uM=C.deviceProvider.getChildCreationSchema.useQuery,pM=C.deviceProvider.createDevice.useMutation,fM=C.deviceProvider.testCreationField.useMutation,mM=C.deviceState.getSnapshot.useQuery,hM=C.deviceState.getCapSlice.useQuery,gM=C.deviceState.getAllSnapshots.useQuery,bM=C.deviceState.setCapSlice.useMutation,xM=C.doorbell.getStatus.useQuery,yM=C.events.getEvents.useQuery,vM=C.events.getEventThumbnail.useQuery,wM=C.events.getEventClipUrl.useQuery,sa=C.integrations.list.useQuery,_g=C.integrations.get.useQuery,Dg=C.integrations.getByAddonId.useQuery,Lg=C.integrations.create.useMutation,Tg=C.integrations.update.useMutation,Rg=C.integrations.delete.useMutation,NM=C.integrations.getSettings.useQuery,kM=C.integrations.setSettings.useMutation,Og=C.integrations.getAvailableTypes.useQuery,zg=C.integrations.testConnection.useMutation,Bg=C.intercom.startSession.useMutation,Fg=C.intercom.handleAnswer.useMutation,jg=C.intercom.stopSession.useMutation,SM=C.intercom.getStatus.useQuery,Hg=C.localNetwork.list.useQuery,CM=C.localNetwork.getPreferred.useQuery,Vg=C.localNetwork.getConnectionEndpoints.useQuery,qg=C.localNetwork.getAllowedAddresses.useQuery,Qg=C.localNetwork.setAllowedAddresses.useMutation,Ug=C.localNetwork.resetAllowlistToBestMatch.useMutation,Kg=C.meshOrchestrator.listProviders.useQuery,Gg=C.meshOrchestrator.joinProvider.useMutation,Wg=C.meshOrchestrator.leaveProvider.useMutation,MM=C.metricsProvider.collectSnapshot.useQuery,IM=C.metricsProvider.getCached.useQuery,AM=C.metricsProvider.getCurrent.useQuery,PM=C.metricsProvider.getDiskSpace.useQuery,EM=C.metricsProvider.getGpuInfo.useQuery,$M=C.metricsProvider.getCpuTemperature.useQuery,_M=C.metricsProvider.getProcessStats.useQuery,DM=C.metricsProvider.listAddonInstances.useQuery,LM=C.metricsProvider.getAddonStats.useQuery,Yg=C.metricsProvider.listNodeProcesses.useQuery,Zg=C.metricsProvider.killProcess.useMutation,TM=C.motion.isDetected.useQuery,RM=C.motion.getStatus.useQuery,OM=C.motionDetection.analyze.useMutation,zM=C.motionDetection.removeCamera.useMutation,BM=C.motionDetection.reset.useMutation,FM=C.motionDetection.getDeviceSettingsContribution.useQuery,jM=C.motionDetection.getDeviceLiveContribution.useQuery,HM=C.motionDetection.applyDeviceSettingsPatch.useMutation,VM=C.motionTrigger.setMotionTrigger.useMutation,qM=C.motionTrigger.getStatus.useQuery,QM=C.nativeObjectDetection.getStatus.useQuery,gc=C.networkQuality.getDeviceStats.useQuery,UM=C.networkQuality.getAllStats.useQuery,KM=C.networkQuality.reportClientStats.useMutation,In=C.nodes.topology.useQuery,GM=C.nodes.deployAddon.useMutation,Xg=C.nodes.undeployAddon.useMutation,aa=C.nodes.restartAddon.useMutation,Jg=C.nodes.restartProcess.useMutation,eb=C.nodes.restartNode.useMutation,WM=C.nodes.shutdownNode.useMutation,tb=C.nodes.renameNode.useMutation,nb=C.nodes.clusterAddonStatus.useQuery,rb=C.nodes.setProcessLogLevel.useMutation,YM=C.nodes.executeQuery.useMutation,ZM=C.notificationOutput.send.useMutation,XM=C.notificationOutput.sendTest.useMutation,JM=C.osd.setOverlay.useMutation,e4=C.osd.getStatus.useQuery,t4=C.pipelineAnalytics.getActiveTracks.useQuery,n4=C.pipelineAnalytics.getTrack.useQuery,r4=C.pipelineAnalytics.listTracks.useQuery,o4=C.pipelineAnalytics.clearTracks.useMutation,s4=C.pipelineAnalytics.getMotionEvents.useQuery,a4=C.pipelineAnalytics.getObjectEvents.useQuery,i4=C.pipelineAnalytics.getAudioEvents.useQuery,l4=C.pipelineAnalytics.getEventMedia.useQuery,c4=C.pipelineAnalytics.getTrackMedia.useQuery,d4=C.pipelineAnalytics.getDeviceSettingsContribution.useQuery,u4=C.pipelineAnalytics.getDeviceLiveContribution.useQuery,p4=C.pipelineAnalytics.applyDeviceSettingsPatch.useMutation,ob=C.pipelineExecutor.getAvailableEngines.useQuery,sb=C.pipelineExecutor.getSelectedEngine.useQuery,f4=C.pipelineExecutor.getDefaultSteps.useQuery,ab=C.pipelineExecutor.reprobeEngine.useMutation,m4=C.pipelineExecutor.getVideoPipelineSteps.useQuery,h4=C.pipelineExecutor.setVideoPipelineSteps.useMutation,So=C.pipelineExecutor.getSchema.useQuery,g4=C.pipelineExecutor.getGlobalSteps.useQuery,b4=C.pipelineExecutor.getGlobalPipelineConfig.useQuery,x4=C.pipelineExecutor.getOrchestratorConfigSchema.useQuery,y4=C.pipelineExecutor.listTemplates.useQuery,v4=C.pipelineExecutor.saveTemplate.useMutation,w4=C.pipelineExecutor.updateTemplate.useMutation,N4=C.pipelineExecutor.deleteTemplate.useMutation,k4=C.pipelineExecutor.getCapabilities.useQuery,S4=C.pipelineExecutor.getAddonModels.useQuery,ib=C.pipelineExecutor.downloadModel.useMutation,lb=C.pipelineExecutor.deleteModel.useMutation,C4=C.pipelineExecutor.detect.useQuery,M4=C.pipelineExecutor.runPipeline.useMutation,I4=C.pipelineExecutor.runPipelineBatch.useMutation,A4=C.pipelineExecutor.cacheFrameInPool.useMutation,P4=C.pipelineExecutor.inferCached.useMutation,E4=C.pipelineExecutor.uncacheFrame.useMutation,$4=C.pipelineExecutor.getEffectiveTuning.useQuery,cb=C.pipelineExecutor.listLoadedEngines.useQuery,_4=C.pipelineExecutor.spinEngine.useMutation,db=C.pipelineExecutor.killEngine.useMutation,D4=C.pipelineExecutor.listReferenceImages.useQuery,L4=C.pipelineExecutor.getReferenceImage.useQuery,T4=C.pipelineExecutor.getReferenceAudioFiles.useQuery,R4=C.pipelineExecutor.getReferenceAudio.useQuery,O4=C.pipelineExecutor.getAudioCapabilities.useQuery,z4=C.pipelineExecutor.runAudioTest.useMutation,B4=C.pipelineExecutor.getDetectionConfigSchema.useQuery,ub=C.pipelineOrchestrator.assignPipeline.useMutation,pb=C.pipelineOrchestrator.unassignPipeline.useMutation,fb=C.pipelineOrchestrator.rebalance.useMutation,ia=C.pipelineOrchestrator.getPipelineAssignments.useQuery,la=C.pipelineOrchestrator.getPipelineAssignment.useQuery,mb=C.pipelineOrchestrator.getAgentLoad.useQuery,F4=C.pipelineOrchestrator.getGlobalMetrics.useQuery,j4=C.pipelineOrchestrator.getCameraMetrics.useQuery,hb=C.pipelineOrchestrator.getCapabilityBindings.useQuery,gb=C.pipelineOrchestrator.setCapabilityBinding.useMutation,bb=C.pipelineOrchestrator.assignDecoder.useMutation,xb=C.pipelineOrchestrator.unassignDecoder.useMutation,yb=C.pipelineOrchestrator.getDecoderAssignments.useQuery,vb=C.pipelineOrchestrator.assignAudio.useMutation,wb=C.pipelineOrchestrator.unassignAudio.useMutation,H4=C.pipelineOrchestrator.getAudioAssignment.useQuery,Nb=C.pipelineOrchestrator.getAudioNodeLoad.useQuery,kb=C.pipelineOrchestrator.getAudioAssignments.useQuery,V4=C.pipelineOrchestrator.getDecoderAssignment.useQuery,bc=C.pipelineOrchestrator.getAgentSettings.useQuery,$r=C.pipelineOrchestrator.listAgentSettings.useQuery,xc=C.pipelineOrchestrator.setAgentAddonDefaults.useMutation,Sb=C.pipelineOrchestrator.removeAgentSettings.useMutation,yc=C.pipelineOrchestrator.getCameraSettings.useQuery,Cb=C.pipelineOrchestrator.setCameraStepToggle.useMutation,q4=C.pipelineOrchestrator.getCameraStepOverrides.useQuery,Mb=C.pipelineOrchestrator.setCameraStepOverride.useMutation,Ib=C.pipelineOrchestrator.setCameraPipelineForAgent.useMutation,Ab=C.pipelineOrchestrator.resolvePipeline.useQuery,Pb=C.pipelineOrchestrator.listTemplates.useQuery,Q4=C.pipelineOrchestrator.saveTemplate.useMutation,Eb=C.pipelineOrchestrator.updateTemplate.useMutation,$b=C.pipelineOrchestrator.deleteTemplate.useMutation,U4=C.pipelineOrchestrator.getDeviceSettingsContribution.useQuery,K4=C.pipelineOrchestrator.getDeviceLiveContribution.useQuery,G4=C.pipelineOrchestrator.applyDeviceSettingsPatch.useMutation,W4=C.pipelineRunner.attachCamera.useMutation,Y4=C.pipelineRunner.detachCamera.useMutation,Z4=C.pipelineRunner.reportMotion.useMutation,X4=C.pipelineRunner.getLocalLoad.useQuery,J4=C.pipelineRunner.getLocalMetrics.useQuery,vc=C.pipelineRunner.getCameraMetrics.useQuery,eI=C.pipelineRunner.getAllCameraMetrics.useQuery,_b=C.pipelineRunner.getLocalCameras.useQuery,tI=C.platformProbe.getCapabilities.useQuery,nI=C.platformProbe.getHardware.useQuery,rI=C.platformProbe.resolveInferenceConfig.useQuery,oI=C.platformProbe.resolveHwAccel.useQuery,sI=C.ptz.move.useMutation,aI=C.ptz.continuousMove.useMutation,iI=C.ptz.stop.useMutation,lI=C.ptz.getPresets.useQuery,cI=C.ptz.goToPreset.useMutation,dI=C.ptz.goHome.useMutation,uI=C.ptz.getPosition.useQuery,pI=C.ptz.getStatus.useQuery,Db=C.ptzAutotrack.getStatus.useQuery,Lb=C.ptzAutotrack.setEnabled.useMutation,fI=C.ptzAutotrack.getSettings.useQuery,Tb=C.ptzAutotrack.setSettings.useMutation,Rb=C.reboot.reboot.useMutation,mI=C.recording.getSegments.useQuery,hI=C.recording.getPlaybackUrl.useQuery,gI=C.recording.getThumbnailAt.useQuery,bI=C.recordingEngine.getStatus.useQuery,Ob=C.recordingEngine.enable.useMutation,zb=C.recordingEngine.disable.useMutation,Bb=C.recordingEngine.getConfig.useQuery,xI=C.recordingEngine.updateConfig.useMutation,yI=C.recordingEngine.getPlaylist.useQuery,vI=C.recordingEngine.getThumbnail.useQuery,Fb=C.recordingEngine.getSegments.useQuery,wI=C.recordingEngine.getAvailability.useQuery,NI=C.recordingEngine.estimateStorage.useQuery,kI=C.recordingEngine.estimateGlobalStorage.useQuery,jb=C.recordingEngine.getStorageUsage.useQuery,SI=C.recordingEngine.setPolicy.useMutation,CI=C.recordingEngine.getPolicy.useQuery,Hb=C.recordingEngine.getPolicyStatus.useQuery,Vb=C.recordingEngine.getRetentionConfig.useQuery,MI=C.recordingEngine.updateRetentionConfig.useMutation,II=C.recordingEngine.getMotionStats.useQuery,qb=C.remoteAccess.listProviders.useQuery,Qb=C.remoteAccess.startProvider.useMutation,Ub=C.remoteAccess.stopProvider.useMutation,AI=C.settingsStore.get.useQuery,PI=C.settingsStore.set.useMutation,EI=C.settingsStore.query.useQuery,$I=C.settingsStore.insert.useMutation,_I=C.settingsStore.update.useMutation,DI=C.settingsStore.delete.useMutation,LI=C.settingsStore.count.useQuery,TI=C.settingsStore.isEmpty.useQuery,RI=C.settingsStore.declareCollection.useMutation,OI=C.snapshot.getSnapshot.useQuery,zI=C.snapshot.invalidateCache.useMutation,BI=C.snapshot.getStatus.useQuery,FI=C.snapshot.getDeviceSettingsContribution.useQuery,jI=C.snapshot.getDeviceLiveContribution.useQuery,HI=C.snapshot.applyDeviceSettingsPatch.useMutation,VI=C.snapshotProvider.supportsDevice.useQuery,qI=C.snapshotProvider.getSnapshot.useQuery,QI=C.storage.resolve.useQuery,UI=C.storage.write.useMutation,KI=C.storage.read.useQuery,GI=C.storage.exists.useQuery,WI=C.storage.list.useQuery,YI=C.storage.delete.useMutation,ZI=C.storage.getAvailableSpace.useQuery,XI=C.storage.beginUpload.useMutation,JI=C.storage.writeChunk.useMutation,eA=C.storage.finalizeUpload.useMutation,tA=C.storage.abortUpload.useMutation,nA=C.storage.beginDownload.useMutation,rA=C.storage.readChunk.useQuery,oA=C.storage.endDownload.useMutation,Kb=C.storage.listLocations.useQuery,sA=C.storage.getDefaultLocation.useQuery,ca=C.storage.upsertLocation.useMutation,Gb=C.storage.deleteLocation.useMutation,aA=C.storage.testLocation.useQuery,wc=C.storage.listProviders.useQuery,iA=C.storage.testConfig.useQuery,lA=C.streamBroker.publishCameraStream.useMutation,cA=C.streamBroker.retractCameraStream.useMutation,dA=C.streamBroker.assignProfile.useMutation,uA=C.streamBroker.unassignProfile.useMutation,pA=C.streamBroker.listAllCameraStreams.useQuery,fA=C.streamBroker.listAllProfileSlots.useQuery,mA=C.streamBroker.getBrokerStats.useQuery,hA=C.streamBroker.listClients.useQuery,gA=C.streamBroker.killClient.useMutation,bA=C.streamBroker.restartProfile.useMutation,xA=C.streamBroker.getStreamUrl.useQuery,yA=C.streamBroker.getBroker.useQuery,vA=C.streamBroker.setPreBufferDuration.useMutation,wA=C.streamBroker.getPreBufferInfo.useQuery,NA=C.streamBroker.getRtspPort.useQuery,kA=C.streamBroker.getAllRtspEntries.useQuery,SA=C.streamBroker.getRtspEntry.useQuery,Wb=C.streamBroker.regenerateRtspToken.useMutation,CA=C.streamBroker.setRtspEnabled.useMutation,MA=C.streamBroker.isRtspEnabled.useQuery,IA=C.streamBroker.getDeviceSettingsContribution.useQuery,AA=C.streamBroker.getDeviceLiveContribution.useQuery,PA=C.streamBroker.applyDeviceSettingsPatch.useMutation,EA=C.switch.setState.useMutation,$A=C.switch.getStatus.useQuery,_A=C.system.info.useQuery,DA=C.system.health.useQuery,LA=C.system.featureFlags.useQuery,TA=C.system.networkAddresses.useQuery,RA=C.system.getRetentionConfig.useQuery,OA=C.system.setRetentionConfig.useMutation,zA=C.system.forceRetentionCleanup.useMutation,Yb=C.toast.onToast.useSubscription,Zb=C.turnOrchestrator.listProviders.useQuery,Xb=C.turnOrchestrator.getAllServers.useQuery,BA=C.turnOrchestrator.setProviderEnabled.useMutation,FA=C.turnProvider.getTurnServers.useQuery,Nc=C.userManagement.listUsers.useQuery,Jb=C.userManagement.createUser.useMutation,ex=C.userManagement.updateUser.useMutation,tx=C.userManagement.deleteUser.useMutation,kc=C.userManagement.resetPassword.useMutation,jA=C.userManagement.validateCredentials.useMutation,nx=C.userManagement.listApiKeys.useQuery,HA=C.userManagement.createApiKey.useMutation,rx=C.userManagement.revokeApiKey.useMutation,VA=C.userManagement.validateApiKey.useMutation,ox=C.userManagement.createScopedToken.useMutation,sx=C.userManagement.revokeScopedToken.useMutation,qA=C.userManagement.validateScopedToken.useQuery,ax=C.userManagement.listScopedTokens.useQuery,QA=C.webrtcSession.listStreams.useQuery,UA=C.webrtcSession.createSession.useMutation,KA=C.webrtcSession.handleAnswer.useMutation,GA=C.webrtcSession.closeSession.useMutation,WA=C.webrtcSession.hasAdaptiveBitrate.useQuery,YA=C.zoneAnalytics.getCurrentSnapshot.useQuery,ZA=C.zoneAnalytics.getZoneHistory.useQuery,XA=C.zoneAnalytics.getCameraHistory.useQuery,JA=C.zoneAnalytics.getUnzonedHistory.useQuery,eP=C.zoneRules.listRules.useQuery,tP=C.zoneRules.setRules.useMutation,nP=C.zones.listZones.useQuery,rP=C.zones.addZone.useMutation,oP=C.zones.removeZone.useMutation,sP=C.zones.updateZone.useMutation,ix=un("camstack:widget-registry",null),Ms=new Map,Bo=new Map,uu=new Set;function aP(e){if(!e||typeof e!="object")return!1;const t=e.default;return t!==null&&typeof t=="object"}function iP(e){if(!e||typeof e!="object")return typeof e;const t=e,n=Object.getPrototypeOf(t),o=n&&typeof n=="object"?n.constructor?.name:void 0;return{ownKeys:Object.keys(t),allKeys:Object.getOwnPropertyNames(t),proto:typeof o=="string"?o:void 0}}async function lP(e,t){const n=Ms.get(e);if(n)return n;const o=Bo.get(e);if(o)return o;uu.has(e)||(Dl(),fr.registerRemotes([{name:e,entry:t,type:"module"}],{force:!1}),uu.add(e));const s=fr.loadRemote(`${e}/widgets`).then(a=>{if(!aP(a)){const l=iP(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 Ms.set(e,i),Bo.delete(e),i}).catch(a=>{throw Bo.delete(e),a});return Bo.set(e,s),s}const cP=3e4,dP=2e3;function lx({children:e}){const t=ke(),n=ne(Date.now()),{data:o}=tg(void 0,{staleTime:0,refetchOnMount:"always",refetchInterval:l=>{const c=l.state.data;return c&&c.length>0||Date.now()-n.current>=cP?!1:dP}});dt("addon.widget-ready",()=>{t.invalidateQueries({queryKey:[["addonWidgets","listWidgets"]]})});const[s,a]=$(0);Y(()=>{if(!o)return;let l=!1;const c=new Set;for(const d of o){if(c.has(d.remoteName)||(c.add(d.remoteName),Ms.has(d.remoteName)))continue;const f=d.bundleUrl;lP(d.remoteName,f).then(()=>{l||a(p=>p+1)}).catch(p=>{const m=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:m})})}return()=>{l=!0}},[o]);const i=Q(()=>{const l=o??[],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 m=Ms.get(p.remoteName);if(!m)return null;const h=m[p.stableId];if(h)return h},metadata:f=>{const p=c.get(f);if(p)return d(f,p)},listAll:()=>{const f=[];for(const[p,m]of c)f.push(d(p,m));return f}}},[o,s]);return r(ix.Provider,{value:i,children:e})}function cx(e){return da().resolve(e)}function dx(e){return da().metadata(e)}function ux(){return da().listAll()}function da(){const e=px();if(!e)throw new Error("useWidgetRegistry(): no <WidgetRegistryProvider> in tree");return e}function px(){return uP(ix)}function uP(e){return ye(e)}function it(e){const{widgetId:t,host:n="device-tab",config:o,deviceId:s,integrationId:a,instanceId:i,size:l,columns:c,rows:d}=e,f=cx(t),p=dx(t),m=Q(()=>i??t,[i,t]);if(f===void 0&&p===void 0)return r(Fo,{widgetId:t,reason:"unknown"});if(f===void 0)return r(Fo,{widgetId:t,reason:"missing-export"});if(f===null)return r(pP,{});if(p){if(p.requires.deviceContext&&s===void 0)return r(Fo,{widgetId:t,reason:"missing-device-context"});if(p.requires.integrationContext&&a===void 0)return r(Fo,{widgetId:t,reason:"missing-integration-context"})}return r(f,{instanceId:m,host:n,config:o,deviceId:s,integrationId:a,size:l,columns:c,rows:d})}function pP(){return u("div",{className:"rounded-lg border border-border bg-surface/40 p-4 animate-pulse",children:[r("div",{className:"h-3 w-24 bg-foreground-subtle/20 rounded mb-2"}),r("div",{className:"h-2 w-full bg-foreground-subtle/10 rounded mb-1"}),r("div",{className:"h-2 w-3/4 bg-foreground-subtle/10 rounded"})]})}function Fo({widgetId:e,reason:t}){const n=t==="unknown"?`Widget "${e}" not registered`:t==="missing-export"?`Widget "${e}" bundle does not export this stableId`:t==="missing-device-context"?`Widget "${e}" requires a deviceId`:`Widget "${e}" requires an integrationId`;return r("div",{className:"rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning",children:n})}const er="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",ua="block text-[11px] font-medium text-foreground mb-1",fP="text-[10px] text-foreground-subtle mt-0.5";function Qe({label:e,description:t,required:n,span:o,children:s,translationFn:a}){const i=o===2?"col-span-2":o===3?"col-span-3":o===4?"col-span-4":"col-span-1",l=Tt(e,a),c=Tt(t,a);return u("div",{className:i,children:[l!==void 0&&l!==""&&u("label",{className:ua,children:[l,n&&r("span",{className:"text-danger ml-0.5",children:"*"})]}),s,c&&r("p",{className:fP,children:c})]})}function mP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("input",{type:e.inputType??"text",className:er,value:t==null?"":String(t),placeholder:e.placeholder,maxLength:e.maxLength,pattern:e.pattern,disabled:o||e.disabled,onChange:a=>n(a.target.value)})})}function hP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const[a,i]=$(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 r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"flex items-center gap-1",children:[r("input",{type:"number",className:er,value:a,placeholder:e.placeholder,min:e.min,max:e.max,step:e.step,disabled:o||e.disabled,onFocus:()=>{l.current=!0},onBlur:()=>{l.current=!1},onChange:d=>c(d.target.value)}),e.unit&&r("span",{className:"text-xs text-foreground-subtle whitespace-nowrap",children:e.unit})]})})}function gP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=!!t,i=o||e.disabled;return e.style==="checkbox"?r(Qe,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[r("input",{type:"checkbox",className:"h-3.5 w-3.5 rounded border-border accent-primary",checked:a,disabled:i,onChange:l=>n(l.target.checked)}),r("span",{className:"text-xs font-medium text-foreground",children:Tt(e.label,s)}),e.required&&r("span",{className:"text-danger",children:"*"})]})}):r(Qe,{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:ua+" mb-0",children:[Tt(e.label,s),e.required&&r("span",{className:"text-danger ml-0.5",children:"*"})]}),r("button",{type:"button",role:"switch","aria-checked":a,disabled:i,onClick:()=>!i&&n(!a),className:["relative inline-flex h-4 w-8 shrink-0 items-center rounded-full transition-colors duration-150",a?"bg-primary":"bg-foreground-subtle/30",i?"opacity-50 cursor-not-allowed":"cursor-pointer"].join(" "),children:r("span",{className:["inline-block h-3 w-3 rounded-full bg-white shadow transition-transform duration-150",a?"translate-x-4":"translate-x-0.5"].join(" ")})})]})})}function bP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=e.options.some(i=>i.value==="");return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("select",{className:er,value:t==null?"":String(t),disabled:o||e.disabled,onChange:i=>n(i.target.value),children:[!e.required&&!a&&r("option",{value:"",children:"— Select —"}),e.options.map(i=>r("option",{value:i.value,children:i.label},i.value))]})})}function xP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=Array.isArray(t)?t:[],i=l=>{if(a.includes(l))n(a.filter(c=>c!==l));else{if(e.maxItems!==void 0&&a.length>=e.maxItems)return;n([...a,l])}};return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("div",{className:"flex flex-wrap gap-2",children:e.options.map(l=>{const c=a.includes(l.value);return u("label",{className:["flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs cursor-pointer select-none transition-colors",c?"border-primary bg-primary/10 text-primary":"border-border bg-background text-foreground hover:bg-surface",o||e.disabled?"opacity-50 cursor-not-allowed":""].join(" "),children:[r("input",{type:"checkbox",className:"sr-only",checked:c,disabled:o||e.disabled,onChange:()=>i(l.value)}),l.label]},l.value)})})})}function yP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const[a,i]=$(!1),l=e.showToggle!==!1;return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"relative",children:[r("input",{type:a?"text":"password",className:er+(l?" pr-9":""),value:t==null?"":String(t),placeholder:e.placeholder,disabled:o||e.disabled,onChange:c=>n(c.target.value)}),l&&r("button",{type:"button",className:"absolute right-2 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",tabIndex:-1,onClick:()=>i(c=>!c),children:a?r(Cm,{className:"h-3.5 w-3.5"}):r(Xs,{className:"h-3.5 w-3.5"})})]})})}function vP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("textarea",{className:er+" resize-y min-h-[60px]",value:t==null?"":String(t),placeholder:e.placeholder,rows:e.rows??3,maxLength:e.maxLength,disabled:o||e.disabled,onChange:a=>n(a.target.value)})})}function wP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=t==null,i=e.nullable===!0,l=a?e.default??e.min:Number(t),c=e.showValue!==!1,d=e.nullLabel??"Auto",f=o||e.disabled,p=e.displayScale??1,m=e.min/p,h=e.max/p,g=l/p,b=(e.step??1)/p;if(i&&a)return r(Qe,{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,v=y=>{const N=l+y*(e.step??1),k=Math.min(e.max,Math.max(e.min,N));k!==l&&n(k)},w="flex h-6 w-6 shrink-0 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:cursor-not-allowed disabled:opacity-40";return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[u("div",{className:"flex min-w-0 flex-1 basis-[160px] items-center gap-2",children:[r("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:m}),r("input",{type:"range",className:"min-w-0 flex-1 h-1 accent-primary cursor-pointer disabled:opacity-50",min:m,max:h,step:b,value:g,disabled:f,onChange:y=>n(Number(y.target.value)*p)}),r("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:h})]}),(c||i||e.unit)&&u("div",{className:"flex shrink-0 items-center gap-2",children:[x&&r("button",{type:"button",className:w,disabled:f||l<=e.min,onClick:()=>v(-1),title:`Decrease by ${e.step??1}`,"aria-label":"Decrement",children:r(Em,{className:"h-3 w-3"})}),c&&r("input",{type:"number",className:"w-16 rounded border border-border bg-surface px-1.5 py-0.5 text-xs text-center text-foreground tabular-nums focus:outline-none focus:ring-1 focus:ring-primary",min:m,max:h,step:b,value:g,disabled:f,onChange:y=>{if(y.target.value===""){n(i?null:e.min);return}const N=Number(y.target.value)*p,k=e.step??1,S=N-e.min,M=e.min+Math.round(S/k)*k;n(Math.min(e.max,Math.max(e.min,M)))}}),x&&r("button",{type:"button",className:w,disabled:f||l>=e.max,onClick:()=>v(1),title:`Increase by ${e.step??1}`,"aria-label":"Increment",children:r(Js,{className:"h-3 w-3"})}),e.unit&&r("span",{className:"text-[10px] text-foreground-subtle",children:e.unit}),i&&r("button",{className:"text-[10px] text-foreground-subtle hover:text-primary transition-colors",title:`Reset to ${d}`,disabled:f,onClick:()=>n(null),children:d})]})]})})}function NP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=Array.isArray(t)?t:[],[i,l]=$(""),c=ne(null),d=q(h=>{const g=h.trim();!g||a.includes(g)||e.maxTags!==void 0&&a.length>=e.maxTags||(n([...a,g]),l(""))},[a,e.maxTags,n]),f=h=>n(a.filter(g=>g!==h)),p=h=>{h.key==="Enter"||h.key===","?(h.preventDefault(),d(i)):h.key==="Backspace"&&i===""&&a.length>0&&f(a[a.length-1])},m=o||e.disabled;return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:["flex flex-wrap gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 min-h-[38px] cursor-text","focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30",m?"opacity-50 cursor-not-allowed":""].join(" "),onClick:()=>!m&&c.current?.focus(),children:[a.map(h=>u("span",{className:"inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[h,!m&&r("button",{type:"button",onClick:()=>f(h),className:"hover:text-danger",children:r(Je,{className:"h-2.5 w-2.5"})})]},h)),r("input",{ref:c,type:"text",className:"flex-1 min-w-[80px] bg-transparent text-sm text-foreground outline-none placeholder:text-foreground-disabled",value:i,placeholder:a.length===0?e.placeholder??"Add tags…":"",disabled:m,list:`tags-suggestions-${e.key}`,onChange:h=>l(h.target.value),onKeyDown:p,onBlur:()=>{i.trim()&&d(i)}}),e.suggestions&&r("datalist",{id:`tags-suggestions-${e.key}`,children:e.suggestions.map(h=>r("option",{value:h},h))})]})})}function fx({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const{nodes:a}=Pr(),i=typeof t=="string"?t:"",l=e.showOffline?a:a.filter(c=>c.isOnline);return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("select",{className:"w-full px-3 py-2 text-sm bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-primary/50 disabled:opacity-50",value:i,onChange:c=>n(c.target.value),disabled:o,children:[r("option",{value:"",children:"Select node…"}),l.map(c=>u("option",{value:c.id,disabled:!c.isOnline,children:[c.shortName,c.isOnline?"":" (offline)"]},c.id))]})})}function mx({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const{nodes:a}=Pr(),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 r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("div",{className:"flex flex-wrap gap-1.5",children:l.map(d=>{const f=i.has(d.id);return r("button",{type:"button",onClick:()=>c(d.id),disabled:o||!d.isOnline,className:`px-2.5 py-1 text-xs font-medium rounded-md border transition-colors ${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 kP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=t==null?"#000000":String(t);return u(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:[u("div",{className:"flex items-center gap-2",children:[r("input",{type:"color",className:"h-9 w-9 rounded-md border border-border bg-background cursor-pointer p-0.5 disabled:opacity-50",value:a,disabled:o||e.disabled,onChange:i=>n(i.target.value)}),r("input",{type:"text",className:er+" flex-1 font-mono",value:a,placeholder:"#000000",disabled:o||e.disabled,onChange:i=>n(i.target.value)})]}),e.presets&&e.presets.length>0&&r("div",{className:"flex gap-1.5 mt-1.5",children:e.presets.map(i=>r("button",{type:"button",className:"h-5 w-5 rounded-md border border-border hover:scale-110 transition-transform disabled:opacity-50",style:{backgroundColor:i},disabled:o||e.disabled,title:i,onClick:()=>n(i)},i))})]})}function SP({field:e,value:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i,externalProbe:l}){const[c,d]=$("idle"),[f,p]=$(null),m=l?.status??c,h=l?.result??f,g=!!a||!!i,b=q(async()=>{if(g){d("probing"),p(null);try{const w=a?await a(e.key,t):await i("test-probe",e.key,t),y=w&&typeof w=="object"?w:{status:"error",error:"Probe handler returned no result"};p(y),d(y.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=m==="probing"?"border-primary/40 bg-primary/10 text-primary":m==="ok"?"border-success/40 bg-success/10 text-success hover:bg-success/15":m==="error"?"border-danger/40 bg-danger/10 text-danger hover:bg-danger/15":"border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover",v=m==="probing"?r(Lt,{className:"h-3 w-3 animate-spin"}):m==="ok"?r(p2,{className:"h-3 w-3"}):m==="error"?r(Zs,{className:"h-3 w-3"}):r(Rm,{className:"h-3 w-3"});return u(Qe,{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||m==="probing"||!g||!t,className:`flex-shrink-0 inline-flex items-center gap-1.5 rounded-md border px-2 py-2 text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed @[280px]:px-3 ${x}`,children:[v,r("span",{className:"hidden @[280px]:inline",children:"Test"})]}),r("input",{type:e.inputType??"url",className:er+" flex-1 min-w-0",value:t==null?"":String(t),placeholder:e.placeholder,disabled:o||e.disabled,onChange:w=>{n(w.target.value),c!=="idle"&&(d("idle"),p(null))}})]}),m==="ok"&&h?.labels&&h.labels.length>0&&r("div",{className:"flex flex-wrap gap-1 mt-1.5",children:h.labels.map((w,y)=>r("span",{className:"text-xs bg-success/10 text-success rounded px-2 py-0.5 font-mono",children:w},y))}),m==="error"&&h?.error&&r("p",{className:"text-xs text-danger mt-1 truncate",title:h.error,children:h.error})]})}function CP({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a}){const[i,l]=$(e.defaultCollapsed??!1),c=e.style==="accordion",d=e.span===2?"col-span-2":e.span===3?"col-span-3":e.span===4?"col-span-4":"col-span-1";return r("div",{className:d,children: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:[r("span",{className:"text-xs font-semibold text-foreground",children:Tt(e.label,s)}),c&&r("span",{className:"text-foreground-subtle text-xs",children:i?"▸":"▾"})]}),!i&&r("div",{className:"px-3 pb-3 grid grid-cols-2 gap-x-4 gap-y-3",children:e.fields.map(f=>r(tr,{field:f,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a},f.key))})]})})}function MP({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i}){const l=e.tabs[0]?.id??"",[c,d]=$(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&&r("div",{className:ua,children:Tt(e.label,s)}),u("div",{className:"rounded-lg border border-border-subtle bg-surface-hover/40 overflow-hidden",children:[r("div",{className:"flex flex-wrap gap-1 p-1.5 border-b border-border-subtle bg-surface/40",role:"tablist",children:e.tabs.map(p=>{const m=p.id===c;return u("button",{type:"button",role:"tab","aria-selected":m,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 ${m?"bg-primary text-primary-foreground font-medium shadow-sm":"bg-transparent text-foreground-subtle hover:bg-surface hover:text-foreground"}`,children:[r("span",{children:Tt(p.label,s)}),p.badge&&r("span",{className:`text-[9px] px-1 py-0.5 rounded-full font-medium ${m?"bg-primary-foreground/20 text-primary-foreground":"bg-primary/10 text-primary"}`,children:p.badge})]},p.id)})}),e.tabs.map(p=>p.id!==c?null:r("div",{role:"tabpanel",className:"px-3 pb-3 pt-2 grid grid-cols-2 gap-x-4 gap-y-3",children:p.fields.map((m,h)=>{const g="key"in m&&typeof m.key=="string"?m.key:`__${p.id}__${h}`;return r(tr,{field:m,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i},g)})},p.id))]})]})}function IP({span:e}){return r("div",{className:e===2?"col-span-2":e===3?"col-span-3":e===4?"col-span-4":"col-span-full",children:r("hr",{className:"border-border"})})}const pu={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 AP(e){if(typeof window>"u"||typeof DOMParser>"u")return"";const t=new Set(["A","UL","OL","LI","STRONG","EM","CODE","BR","P","SPAN"]),n=new DOMParser().parseFromString(`<div>${e}</div>`,"text/html"),o=n.body.firstElementChild;if(!o)return"";const s=a=>{const i=Array.from(a.children);for(const l of i){if(!t.has(l.tagName)){const d=n.createTextNode(l.textContent??"");l.replaceWith(d);continue}const c=l.tagName==="A"?new Set(["href"]):new Set;for(const d of Array.from(l.attributes))c.has(d.name)||l.removeAttribute(d.name);if(l.tagName==="A"){const d=l.getAttribute("href")??"";!/^https?:\/\//i.test(d)&&!d.startsWith("mailto:")?l.removeAttribute("href"):(l.setAttribute("target","_blank"),l.setAttribute("rel","noopener noreferrer"))}s(l)}};return s(o),o.innerHTML}function PP({field:e}){const t=e.variant??"info",n=pu[t]??pu.info,o=e.format==="html";return r("div",{className:"col-span-full",children:u("div",{className:`rounded-md border-l-4 px-3 py-2.5 ${n.border} ${n.bg}`,children:[e.label&&r("p",{className:`text-xs font-semibold mb-0.5 ${n.text}`,children:e.label}),o?r("div",{className:"text-xs text-foreground-subtle leading-relaxed info-html-content",dangerouslySetInnerHTML:{__html:AP(e.content)}}):r("p",{className:"text-xs text-foreground-subtle leading-relaxed whitespace-pre-line",children:e.content})]})})}const fu={ok:"bg-success",warn:"bg-amber-500",danger:"bg-danger",idle:"bg-foreground-subtle/40",unknown:"bg-foreground-subtle/40"};function EP(e){if(!Number.isFinite(e)||e<0)return"—";if(e<1e3)return`${e}ms`;const t=Math.round(e/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60),o=t%60;return o===0?`${n}m`:`${n}m ${o}s`}function $P(e){return!Number.isFinite(e)||e<=0?"—":new Date(e).toLocaleTimeString()}function _P({kind:e,value:t}){if(t==null||t==="")return r("span",{className:"text-foreground-subtle/60",children:"—"});if(e==="monospace")return r("span",{className:"font-mono text-[11px]",children:String(t)});if(e==="status"){const n=String(t).toLowerCase(),o=fu[n]??fu.unknown;return u("span",{className:"inline-flex items-center gap-1.5",children:[r("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${o}`}),r("span",{children:String(t)})]})}return e==="duration"&&typeof t=="number"?r("span",{className:"font-mono text-[11px]",children:EP(t)}):e==="timestamp"&&typeof t=="number"?r("span",{className:"font-mono text-[11px]",children:$P(t)}):r("span",{children:String(t)})}function DP({field:e}){const t=e.value??[],n=e.description;return u("div",{className:"col-span-full",children:[e.label&&r("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1",children:e.label}),n&&r("p",{className:"text-xs text-foreground-subtle mb-2",children:n}),t.length===0?r("div",{className:"rounded-md border border-border bg-surface-subtle px-3 py-2 text-xs text-foreground-subtle",children:e.emptyMessage??"No entries"}):r("div",{className:"rounded-md border border-border overflow-hidden",children:u("table",{className:"w-full text-xs",children:[r("thead",{className:"bg-surface-subtle border-b border-border",children:r("tr",{children:e.columns.map(o=>r("th",{className:"px-3 py-1.5 text-left font-medium text-foreground-subtle",style:o.width?{width:o.width}:void 0,children:o.label},o.key))})}),r("tbody",{className:"divide-y divide-border",children:t.map((o,s)=>r("tr",{className:"hover:bg-surface-hover/40",children:e.columns.map(a=>r("td",{className:"px-3 py-1.5 align-top text-foreground",children:r(_P,{kind:a.kind,value:o[a.key]})},a.key))},s))})]})})]})}function LP({field:e,value:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i}){const l=Array.isArray(t)?t:[],c=e.minRows??0,d=e.maxRows??Number.POSITIVE_INFINITY,f=(x,v,w)=>{const y=l.slice(),N=y[x]??{};y[x]={...N,[v]:w},n(y)},p=x=>{l.length<=c||n(l.filter((v,w)=>w!==x))},m=()=>{if(l.length>=d)return;const x=e.defaultItem??{};n([...l,{...x}])},h=(x,v)=>e.rowTitleTemplate?e.rowTitleTemplate.replace(/\{(\w+)\}/g,(w,y)=>{const N=x[y];return N==null||N===""?"—":String(N)}):`Row ${v+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&&r("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle",children:Tt(e.label,s)}),e.description&&r("p",{className:"text-[11px] text-foreground-subtle",children:Tt(e.description,s)})]}),l.length===0?r("div",{className:"rounded-md border border-dashed border-border bg-background px-3 py-3 text-center text-[11px] text-foreground-subtle",children:e.emptyMessage??"No entries"}):r("div",{className:"space-y-2",children:l.map((x,v)=>u("div",{className:"rounded-md border border-border bg-background",children:[u("div",{className:"flex items-center justify-between border-b border-border px-3 py-1.5",children:[r("span",{className:"text-xs font-medium text-foreground",children:h(x,v)}),u("button",{type:"button",onClick:()=>p(v),disabled:o||!g,className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-30 disabled:cursor-not-allowed",title:g?"Remove this row":`At least ${c} row(s) required`,children:[r(Em,{className:"h-3 w-3"}),"Remove"]})]}),r("div",{className:"grid grid-cols-1 @[420px]:grid-cols-2 gap-x-3 gap-y-2 p-3",children:e.itemFields.map(w=>r(tr,{field:w,values:x,onChange:(y,N)=>f(v,y,N),disabled:o,translationFn:s,onTestField:a,allFields:e.itemFields,onAction:i},w.key))})]},v))}),u("div",{children:[u("button",{type:"button",onClick:m,disabled:o||!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:[r(Js,{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 TP({field:e,disabled:t,onAction:n}){const[o,s]=$(!1),a=rt(),i=async()=>{if(!(e.confirmMessage&&!await a({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant==="danger"?"danger":"default"}))&&n){s(!0);try{await n(e.action,e.key)}finally{s(!1)}}},l={default:"border border-border text-foreground hover:bg-surface-hover",primary:"bg-primary text-primary-foreground hover:bg-primary/90",danger:"bg-danger text-white hover:bg-danger/90"};return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,children:r("button",{onClick:i,disabled:t||o,className:`inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${l[e.variant??"default"]??l.default}`,children:o?"Processing...":e.buttonLabel})})}function hx(e,t){const n={...e.paramsStatic??{}};if(e.paramsFromForm)for(const[o,s]of Object.entries(e.paramsFromForm)){const a=t[s];a!=null&&a!==""&&(n[o]=a)}return n}function RP({field:e,value:t,values:n,onChange:o,disabled:s,onAction:a}){const[i,l]=$(!1),[c,d]=$(null),[f,p]=$(null),m=hx(e,n),h=Object.keys(e.paramsFromForm??{}).some(w=>m[w]===void 0),g=(e.refreshOn??Object.values(e.paramsFromForm??{})).map(w=>`${w}=${JSON.stringify(n[w])}`).join("|");Y(()=>{if(!a||h){p(null),d(null);return}let w=!1;return l(!0),d(null),a(e.action,e.key,m).then(y=>{if(w)return;const N=y;let k=[];if(Array.isArray(N))k=N;else if(N&&typeof N=="object")for(const S of Object.keys(N)){const M=N[S];if(Array.isArray(M)){k=M;break}}p(k)}).catch(y=>{w||(d(y instanceof Error?y.message:String(y)),p([]))}).finally(()=>{w||l(!1)}),()=>{w=!0}},[g,a,e.action,e.key]);const b=e.mapOption.value,x=e.mapOption.label,v=e.mapOption.description;return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,children:h?r("div",{className:"text-[11px] text-foreground-subtle italic",children:e.emptyParamsMessage??"Fill the prerequisite fields above first."}):i?u("div",{className:"flex items-center gap-2 text-[11px] text-foreground-subtle",children:[r(Lt,{className:"h-3 w-3 animate-spin"})," Loading options…"]}):c?r("div",{className:"text-[11px] text-danger",children:c}):f&&f.length===0?r("div",{className:"text-[11px] text-foreground-subtle italic",children:e.emptyResultsMessage??"No options returned."}):(()=>{const w=(f??[]).some(y=>{const N=y[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:y=>o(y.target.value),children:[!w&&r("option",{value:"",children:"— Select —"}),(f??[]).map((y,N)=>{const k=y[b],S=y[x],M=v?y[v]:void 0,P=typeof k=="string"&&k!==""?k:`row-${N}`;return u("option",{value:typeof k=="string"?k:String(k??""),children:[typeof S=="string"?S:String(S??P),M!==void 0?` (${String(M)})`:""]},P)})]})})()})}function OP({field:e,values:t,disabled:n,onAction:o}){const[s,a]=$(!1),[i,l]=$(null),c=rt(),d=async()=>{if(e.confirmMessage&&!await c({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant==="danger"?"danger":"default"})||!o)return;const p=hx(e,t);a(!0),l(null);try{const m=await o(e.action,e.key,p),h=e.successMessage?e.successMessage.replace(/\{(\w+)\}/g,(g,b)=>{const x=m?.[b];return x===void 0?"":String(x)}):"Done.";l({kind:"ok",text:h})}catch(m){l({kind:"error",text:m instanceof Error?m.message:String(m)})}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 r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,children:u("div",{className:"flex flex-col gap-1.5",children:[r("button",{onClick:d,disabled:n||s,className:`inline-flex w-fit items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${f[e.variant??"default"]??f.default}`,children:s?"Working…":e.buttonLabel}),i&&r("div",{className:`text-[11px] ${i.kind==="ok"?"text-emerald-700 dark:text-emerald-300":"text-danger"}`,children:i.text})]})})}function zP({field:e}){const t=pn();return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,children:r(it,{widgetId:e.widgetId,host:"device-tab",config:e.widgetConfig,deviceId:t??void 0,instanceId:e.key})})}function BP(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 FP({field:e,values:t,onAction:n,translationFn:o}){const s="key"in e?e.key:void 0;if(!s)return null;const a=t[s],i=a!==void 0?a:"default"in e?e.default:void 0,l="unit"in e?e.unit:void 0,c=BP(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,m="actions"in e?e.actions??[]:[];return r(Qe,{label:d,description:f,span:p,translationFn:o,children:u("div",{className:"flex items-stretch gap-1",children:[r("div",{className:"flex-1 rounded-md border border-border bg-surface-alt px-2.5 py-1.5 text-xs text-foreground font-mono break-all",children:c}),m.length>0&&r("div",{className:"flex items-center gap-1",children:m.map(h=>r(HP,{action:h,fieldKey:s,value:i,onAction:n},h.action))})]})})}function jP({name:e}){const t="h-3.5 w-3.5";switch(e){case"copy":return r(Mn,{className:t});case"refresh-cw":return r(Ol,{className:t});case"external-link":return r(Sm,{className:t});case"trash-2":return r(rn,{className:t});case"download":return r(Oi,{className:t});case"upload":return r(Tm,{className:t});default:return r(zl,{className:t})}}function HP({action:e,fieldKey:t,value:n,onAction:o}){const s=rt(),[a,i]=$(!1),l=e.variant==="danger"?"text-danger hover:bg-danger/10 border-danger/30":e.variant==="primary"?"text-primary hover:bg-primary/10 border-primary/30":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover border-border";return r("button",{type:"button",onClick:async()=>{if(!(e.confirmMessage&&!await s({title:e.tooltip,message:e.confirmMessage,variant:e.variant==="danger"?"danger":"default"}))){if(e.action==="copy-value"){try{await navigator.clipboard.writeText(typeof n=="string"?n:String(n))}catch{}return}if(o){i(!0);try{await o(e.action,t)}finally{i(!1)}}}},disabled:a,title:e.tooltip,className:`inline-flex items-center justify-center rounded-md border px-2 py-1.5 transition-colors disabled:opacity-50 ${l}`,children:r(jP,{name:e.icon})})}function VP(e){return"multiple"in e&&e.multiple!=null}function qP({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c}){const d=e.multiple,f=d.min,p=d.max,m=t[e.key],g=[...Array.isArray(m)?m:m!=null?[m]:[]],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]),v=(k,S)=>{const M=[...g];M[k]=S,x(M)},w=()=>{g.length>=p||x([...g,b])},y=k=>{g.length<=f||x(g.filter((S,M)=>M!==k))},N=()=>{const{multiple:k,...S}=e;return{...S,...{label:void 0,description:void 0,required:!1}}};return r(Qe,{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,S)=>{const M=d.itemLabel?.replace("${n}",String(S+1));return u("div",{className:"space-y-1",children:[M&&r("div",{className:ua,children:M}),u("div",{className:"flex items-center gap-2",children:[r("div",{className:"flex-1 min-w-0",children:r(tr,{field:N(),values:{...t,[e.key]:k},onChange:(P,I)=>v(S,I),disabled:o,translationFn:s,onTestField:a,onAction:c,allFields:l})}),g.length>f&&r("button",{type:"button",onClick:()=>y(S),disabled:o,title:"Remove",className:"flex-shrink-0 inline-flex items-center justify-center rounded-md border border-border p-1.5 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors disabled:opacity-40",children:r(rn,{className:"h-3.5 w-3.5"})})]})]},S)}),u("div",{className:"flex items-center justify-between pt-1",children:[g.length<p?u("button",{type:"button",onClick:w,disabled:o,className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40",children:[r(Js,{className:"h-3 w-3"}),d.addLabel??"Add"]}):r("span",{}),u("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:[g.length,"/",p]})]})]})})}function Sc(e,t,n){if(!("showWhen"in e)||!e.showWhen)return!0;const o=e.showWhen,s=t[o.field],a=n?.find(c=>"key"in c&&c.key===o.field),i=a&&"default"in a?a.default:void 0,l=s!==void 0?s:i;return o.equals!==void 0?l===o.equals:o.notEquals!==void 0?l!==o.notEquals:o.in!==void 0?o.in.includes(l):o.notIn!==void 0?!o.notIn.includes(l):o.includes!==void 0?Array.isArray(l)&&l.includes(o.includes):o.notIncludes!==void 0?!Array.isArray(l)||!l.includes(o.notIncludes):!0}function tr({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c}){if(VP(e))return r(qP,{field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c});if("readonlyField"in e&&e.readonlyField===!0)return r(FP,{field:e,values:t,onAction:c,translationFn:s});if(!Sc(e,t,l))return null;const d=t[e.key],f=d!==void 0?d:"default"in e?e.default:void 0,p=h=>n(e.key,h),m=Fh(e.type);switch(e.type){case"text":return r(mP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"number":return r(hP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"boolean":return r(gP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"select":return r(bP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"multiselect":return r(xP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"password":return r(yP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"textarea":return r(vP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"slider":return r(wP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"tags":return r(NP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"color":return r(kP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"node-select":return r(fx,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"node-multiselect":return r(mx,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"probe":return r(SP,{field:e,value:f,onChange:p,disabled:o,translationFn:s,onTestField:a,onAction:c,externalProbe:i});case"group":return r(CP,{field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a});case"sub-tabs":return r(MP,{field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:c});case"separator":return r(IP,{});case"info":return r(PP,{field:e});case"object-array":return r(DP,{field:e});case"editable-array":return r(LP,{field:e,value:f,onChange:p,disabled:o,translationFn:s,onTestField:a,onAction:c});case"button":return r(TP,{field:e,disabled:o,onAction:c});case"addon-action-select":return r(RP,{field:e,value:f,values:t,onChange:p,disabled:o,onAction:c});case"addon-action-button":return r(OP,{field:e,values:t,disabled:o,onAction:c});case"widget":return r(zP,{field:e});default:return m?r(m,{field:e,value:f,onChange:p,disabled:o}):null}}function QP(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function Tt(e,t){if(e!==void 0)return t&&QP(e)?t(e):e}function UP({section:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,probeResults:i}){const[l,c]=$(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(m=>!m):void 0,children:[u("div",{children:[r("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:Tt(e.title,s)}),e.description&&r("p",{className:"text-[10px] text-foreground-subtle mt-0.5",children:Tt(e.description,s)})]}),d&&r("span",{className:"text-foreground-subtle text-xs ml-2",children:l?"▸":"▾"})]}),!l&&r("div",{className:`grid ${p} gap-x-3 gap-y-2.5`,children:e.fields.map(m=>r(tr,{field:m,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i?.[m.key]},m.key))})]})}function gx({schema:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,probeResults:i,onClearProbe:l}){const c=(d,f)=>{n({...t,[d]:f}),l?.(d)};return r("div",{className:"space-y-4",children:e.sections.map(d=>r(UP,{section:d,values:t,onChange:c,disabled:o,translationFn:s,onTestField:a,probeResults:i},d.id))})}const KP=({open:e})=>r("svg",{className:`h-3 w-3 transition-transform ${e?"rotate-90":""}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:r("polyline",{points:"9 18 15 12 9 6"})});function mu(e){const t={};if(!e)return t;for(const n of e.sections)for(const o of n.fields){if(o.type==="separator"||o.type==="info"||o.type==="button"||o.type==="group")continue;const s=o.key;t[s]=o.value}return t}function GP(e){return{...e,sections:e.sections.map(t=>({...t,fields:t.fields.map(n=>{if(n.type==="separator"||n.type==="info"||n.type==="button"||n.type==="group")return n;const{value:o,...s}=n;return s})}))}}function WP({trpc:e,addonId:t,nodeId:n,title:o,disabled:s,onAfterChange:a,refreshToken:i,collapsible:l,defaultOpen:c,mode:d,onOverrideChange:f}){const p=d??"persist",[m,h]=$(null),[g,b]=$(!0),[x,v]=$(null),[w,y]=$(!1),[N,k]=$(c??!1),[S,M]=$({}),[P,I]=$(null);Y(()=>{I(null),M({})},[e,t,n,i,p]);const F=JSON.stringify(S);Y(()=>{let _=!1;b(!0),v(null);const R=p==="override"&&Object.keys(S).length>0?S:void 0;return e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n,...R?{overlay:R}:{}}).then(L=>{_||(h(L),R||I(mu(L)),b(!1))}).catch(L=>{_||(v(L instanceof Error?L.message:String(L)),b(!1))}),()=>{_=!0}},[e,t,n,i,p,F]);const E=Q(()=>mu(m),[m]),B=Q(()=>m?GP(m):null,[m]),O=async _=>{if(p==="override"){const L=P??E,z={};for(const H of Object.keys(_))_[H]!==L[H]&&(z[H]=_[H]);const j={...L,...z};M(z),f?.(z,j);return}const R={};for(const L of Object.keys(_))_[L]!==E[L]&&(R[L]=_[L]);if(Object.keys(R).length!==0){y(!0);try{await e.addonSettings.updateGlobalSettings.mutate({addonId:t,nodeId:n,patch:R});const L=await e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n});h(L),a?.()}catch(L){v(L instanceof Error?L.message:String(L))}finally{y(!1)}}};if(g)return u("div",{className:"text-xs text-foreground-subtle animate-pulse",children:["Loading ",o??t,"…"]});if(x)return u("div",{className:"text-xs text-red-400",children:[o??t,": ",x]});if(!m||!B)return u("div",{className:"text-xs text-foreground-subtle",children:[o??t," not available on ",n,"."]});const A=p==="override"?{...E,...S}:E,D=u(ve,{children:[p==="override"?r("div",{className:"mb-2 text-[11px] text-foreground-subtle",children:"Benchmark override — applies to this run only. The addon's saved settings are not changed."}):null,r(gx,{schema:B,values:A,onChange:O,disabled:s===!0||w})]});return l===!0?u("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("button",{type:"button",onClick:()=>k(_=>!_),className:"w-full px-4 py-2 flex items-center gap-2 hover:bg-surface-hover text-left","aria-expanded":N,children:[r(KP,{open:N}),r("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide flex-1",children:o??t}),r("span",{className:"text-[10px] text-foreground-subtle",children:N?"hide":"edit"})]}),N?r("div",{className:"border-t border-border px-4 py-3",children:D}):null]}):o?u("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r("div",{className:"border-b border-border px-4 py-2",children:r("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide",children:o})}),r("div",{className:"px-4 py-3",children:D})]}):r("div",{children:D})}function bx({detections:{motion:e,motionRaw:t,detection:n,phase:o},showMotionZones:s=!0,showMotionRaw:a=!0,showDetections:i=!0,showPhaseIndicator:l=!0}){const c=s&&e&&e.zones.length>0,d=a&&t&&t.boxes.length>0,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&&r(YP,{phase:o}),d&&r(ZP,{raw:t}),c&&r(XP,{motion:e}),f&&r(JP,{detections:n.detections,frameWidth:n.frameWidth,frameHeight:n.frameHeight})]})}function YP({phase:e}){const t=Wn(e);return u("div",{className:"absolute top-2 left-2 flex items-center gap-1.5 px-2 py-1 rounded-md bg-black/60 backdrop-blur-sm",children:[r("span",{className:`w-2 h-2 rounded-full ${t.dotClass}`}),r("span",{className:"text-[10px] font-semibold text-white uppercase tracking-wider",children:t.label})]})}function ZP({raw:e}){return e.frameWidth===0||e.frameHeight===0?null:r(ve,{children:e.boxes.map((t,n)=>{const[o,s,a,i]=t.bbox,l=o/e.frameWidth*100,c=s/e.frameHeight*100,d=(a-o)/e.frameWidth*100,f=(i-s)/e.frameHeight*100,p=Math.max(.05,Math.min(.25,t.changeScore*.3));return r("div",{className:"absolute rounded-sm",style:{left:`${l}%`,top:`${c}%`,width:`${d}%`,height:`${f}%`,backgroundColor:`rgba(239, 68, 68, ${p})`}},`mr-${n}`)})})}function XP({motion:e}){if(e.frameWidth===0||e.frameHeight===0)return null;const t=e.zones.filter(n=>n.w*n.h/(e.frameWidth*e.frameHeight)<.9);return r(ve,{children:t.map((n,o)=>{const s=Math.max(.15,Math.min(.5,n.intensity/255));return r("div",{className:"absolute rounded-sm",style:{left:`${n.x/e.frameWidth*100}%`,top:`${n.y/e.frameHeight*100}%`,width:`${n.w/e.frameWidth*100}%`,height:`${n.h/e.frameHeight*100}%`,border:`1px solid rgba(250, 204, 21, ${s})`,backgroundColor:`rgba(250, 204, 21, ${s*.15})`}},`mz-${o}`)})})}function JP({detections:e,frameWidth:t,frameHeight:n}){return t===0||n===0?null:r(ve,{children:e.map(o=>{const{x:s,y:a,width:i,height:l}=o.bbox,c=s/t*100,d=a/n*100,f=i/t*100,p=l/n*100,m=ct(o.macroClass),h=[`${o.macroClass} ${(o.score*100).toFixed(0)}%`];for(const g of o.labels)h.push(g.label);return r("div",{className:"absolute border-2 rounded-sm",style:{left:`${c}%`,top:`${d}%`,width:`${f}%`,height:`${p}%`,borderColor:m},children:r("div",{className:"absolute -top-4 left-0 px-1 py-0.5 text-[9px] font-bold text-white rounded-sm whitespace-nowrap",style:{backgroundColor:m},children:h.join(" | ")})},`det-${o.id}`)})})}function eE(e){const t={};if(typeof window<"u"){if(e){const o=e.getBoundingClientRect();o.width>0&&o.height>0&&(t.viewportWidth=Math.round(o.width),t.viewportHeight=Math.round(o.height))}t.viewportWidth===void 0&&(t.viewportWidth=window.innerWidth,t.viewportHeight=window.innerHeight),t.devicePixelRatio=window.devicePixelRatio||1;const n=navigator.connection;n?.downlink&&n.downlink>0&&(t.downlinkMbps=n.downlink)}return t}const tE=3e3,nE=5;function xx({serverUrl:e,streamKey:t,label:n,autoPlay:o=!0,muted:s=!0,showControls:a=!0,className:i="",onStateChange:l,onError:c,overlay:d,createSession:f,sendAnswer:p,closeSession:m,hintsOverride:h}){const g=ne(null),b=ne(null),x=ne(null),v=ne(new Set),w=ne(null),y=ne(null),N=ne(0),k=ne(!0),[S,M]=$("idle"),[P,I]=$(""),[F,E]=$(s),[B,O]=$(!1),[A,D]=$(!1),_=ne(null),R=ne(!1);(p||f)&&(R.current=!0);const L=R.current,z=q(U=>{M(U),l?.(U)},[l]),j=q(()=>{if(w.current?.abort(),w.current=null,y.current&&(clearTimeout(y.current),y.current=null),x.current&&(x.current.close(),x.current=null),m&&v.current.size>0){for(const U of v.current)m(U).catch(()=>{});v.current.clear()}g.current&&(g.current.srcObject=null)},[m]),H=q(async()=>{if(!k.current||!f||!p)return;j(),z("connecting");const U=new AbortController;w.current=U;try{const ae={...eE(b.current),...h},{sessionId:fe,sdpOffer:he}=await f(ae);if(v.current.add(fe),!k.current||U.signal.aborted){m?.(fe).catch(()=>{}),v.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,z("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")&&(z("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:he});const ue=await V.createAnswer();if(await V.setLocalDescription(ue),console.debug("[WebRTC] Local description set, waiting for ICE gathering..."),await hu(V),!k.current)return;const de=(V.localDescription?.sdp??"").split(`
|
|
530
|
+
*/const c5=[["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"}]],d5=ce("zoom-out",c5),u5={frigate:Lk,scrypted:_k,reolink:xk,homeAssistant:Im,rtsp:o2},p5={online:m2,offline:k2,degraded:Zs,unknown:vm},Ud=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,Kd=Jf,Zn=(e,t)=>n=>{var o;if(t?.variants==null)return Kd(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 m=Ud(f)||Ud(p);return s[d][m]}),l=n&&Object.entries(n).reduce((d,f)=>{let[p,m]=f;return m===void 0||(d[p]=m),d},{}),c=t==null||(o=t.compoundVariants)===null||o===void 0?void 0:o.reduce((d,f)=>{let{class:p,className:m,...h}=f;return Object.entries(h).every(g=>{let[b,x]=g;return Array.isArray(x)?x.includes({...a,...l}[b]):{...a,...l}[b]===x})?[...d,p,m]:d},[]);return Kd(e,i,c,n?.class,n?.className)},f5=Zn("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"}}),He=Ve(({className:e,variant:t,size:n,...o},s)=>r("button",{ref:s,className:K(f5({variant:t,size:n}),e),...o}));He.displayName="Button";const m5=Zn("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"}}),Bl=Ve(({className:e,variant:t,size:n,icon:o,...s},a)=>r("button",{ref:a,className:K(m5({variant:t,size:n}),e),...s,children:r(o,{className:"h-4 w-4"})}));Bl.displayName="IconButton";const h5=Zn("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"}}),cr=Ve(({className:e,variant:t,style:n,...o},s)=>r("span",{ref:s,className:K(h5({variant:t,styleVariant:n}),e),...o}));cr.displayName="Badge";const g5=Zn("rounded-lg p-3",{variants:{variant:{flat:"bg-surface",bordered:"bg-surface border border-border"}},defaultVariants:{variant:"bordered"}}),Ge=Ve(({className:e,variant:t,...n},o)=>r("div",{ref:o,className:K(g5({variant:t}),e),...n}));Ge.displayName="Card";function Om({expanded:e,onExpandedChange:t,header:n,children:o,dimmed:s=!1,hideChevron:a=!1,className:i}){return u("div",{className:K("rounded-lg border border-border bg-surface overflow-hidden",s&&"opacity-[0.45]",i),children:[u("div",{role:"button",tabIndex:0,className:"flex items-center gap-2.5 px-3 py-2.5 cursor-pointer select-none",onClick:()=>t(!e),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),t(!e))},children:[!a&&r("span",{className:"text-foreground-subtle shrink-0",children:e?r(Yn,{className:"h-4 w-4"}):r(Cn,{className:"h-4 w-4"})}),n]}),e&&o&&r("div",{className:"border-t border-border px-3 py-3",children:o})]})}const Fl=Ve(({className:e,...t},n)=>r("label",{ref:n,className:K("text-[10px] uppercase tracking-wider text-foreground-muted font-medium",e),...t}));Fl.displayName="Label";const b5=Zn("",{variants:{orientation:{horizontal:"h-px w-full bg-border-subtle",vertical:"w-px h-full bg-border-subtle"}},defaultVariants:{orientation:"horizontal"}}),jl=Ve(({className:e,orientation:t,...n},o)=>r("div",{ref:o,role:"separator",className:K(b5({orientation:t}),e),...n}));jl.displayName="Separator";const zm=Ve(({className:e,...t},n)=>r("div",{ref:n,className:K("animate-pulse bg-surface-hover rounded-md h-4 w-full",e),...t}));zm.displayName="Skeleton";const Gd=Zn("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"}}),Ss=Ve(({className:e,state:t,leftSlot:n,rightSlot:o,...s},a)=>n||o?u("div",{className:"relative flex items-center w-full",children:[n&&r("div",{className:"absolute left-2.5 flex items-center pointer-events-none",children:n}),r("input",{ref:a,className:K(Gd({state:t}),n?"pl-7":"",o?"pr-7":"",e),...s}),o&&r("div",{className:"absolute right-2.5 flex items-center pointer-events-none",children:o})]}):r("input",{ref:a,className:K(Gd({state:t}),e),...s}));Ss.displayName="Input";const Cs=Ve(({className:e,options:t,...n},o)=>u("div",{className:"relative w-full",children:[r("select",{ref:o,className:K("h-7 w-full px-2.5 text-xs bg-surface border border-border rounded-md text-foreground appearance-none pr-7 focus:outline-none focus:ring-1 focus:ring-primary",e),...n,children:t.map(s=>r("option",{value:s.value,children:s.label},s.value))}),r("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none text-foreground-muted",children:r(Yn,{className:"h-3.5 w-3.5"})})]}));Cs.displayName="Select";const Bm=Ve(({className:e,...t},n)=>r("input",{ref:n,type:"checkbox",className:K("w-3.5 h-3.5 rounded-sm border border-border accent-primary",e),...t}));Bm.displayName="Checkbox";const Hl=Ve(({className:e,checked:t,onCheckedChange:n,label:o,...s},a)=>u("button",{ref:a,role:"switch","aria-checked":t,type:"button",onClick:()=>n(!t),className:K("inline-flex items-center gap-2",e),...s,children:[r("span",{className:K("w-8 h-4 rounded-full transition-colors",t?"bg-primary":"bg-surface-hover"),children:r("span",{className:K("block w-3.5 h-3.5 rounded-full bg-white transition-transform",t?"translate-x-4":"translate-x-0.5")})}),o&&r("span",{className:"text-xs text-foreground",children:o})]}));Hl.displayName="Switch";const Fm=Oe(null);function jm(){const e=ye(Fm);if(!e)throw new Error("Dialog compound components must be used within <Dialog>");return e}function Hm({children:e,open:t,onOpenChange:n}){const[o,s]=$(!1),a=t??o,i=mr(),l=q(c=>{n?.(c),t===void 0&&s(c)},[t,n]);return r(Fm.Provider,{value:{open:a,setOpen:l,contentId:i},children:e})}function x5({children:e,...t}){const{setOpen:n}=jm();return r("button",{type:"button",onClick:()=>n(!0),...t,children:e})}const y5=Zn("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"}}),Vl=Ve(({className:e,width:t,children:n,...o},s)=>{const{open:a,setOpen:i,contentId:l}=jm(),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 r("dialog",{ref:d,id:l,className:K(y5({width:t}),"w-full",e),onClick:f,onClose:()=>i(!1),...o,children:n})});Vl.displayName="DialogContent";function Vm({className:e,...t}){return r("div",{className:K("flex flex-col gap-1 mb-3",e),...t})}function qm({className:e,...t}){return r("div",{className:K("flex justify-end gap-2 mt-4",e),...t})}function Qm({className:e,...t}){return r("h2",{className:K("text-sm font-semibold text-foreground",e),...t})}function Um({className:e,...t}){return r("p",{className:K("text-xs text-foreground-muted",e),...t})}const Km=Oe(null);function ql(){const e=ye(Km);if(!e)throw new Error("Dropdown compound components must be used within <Dropdown>");return e}function Gm({children:e}){const[t,n]=$(!1),o=mr(),s=mr(),a=ne(null);return r(Km.Provider,{value:{open:t,setOpen:n,triggerId:o,contentId:s,triggerRef:a},children:r("div",{className:"relative inline-block",children:e})})}function Wm({children:e,...t}){const{open:n,setOpen:o,triggerId:s,contentId:a,triggerRef:i}=ql();return r("button",{type:"button",ref:i,id:s,"aria-haspopup":"menu","aria-expanded":n,"aria-controls":n?a:void 0,onClick:()=>o(!n),...t,children:e})}function Ym({className:e,children:t,align:n="start",offset:o=4,...s}){const{open:a,setOpen:i,contentId:l,triggerId:c,triggerRef:d}=ql(),f=ne(null),[p,m]=$(null);if(Gs(()=>{if(!a){m(null);return}const g=()=>{const b=d.current;if(!b)return;const x=b.getBoundingClientRect(),v=n==="end"?x.right:x.left;m({top:x.bottom+o,left:v,minWidth:x.width})};return g(),window.addEventListener("resize",g),window.addEventListener("scroll",g,!0),()=>{window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0)}},[a,n,o,d]),Y(()=>{if(!a)return;const g=x=>{const v=f.current,w=d.current;v&&!v.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 h={position:"fixed",top:p.top,...n==="end"?{right:window.innerWidth-p.left}:{left:p.left},minWidth:p.minWidth};return vo(r("div",{ref:f,id:l,role:"menu","aria-labelledby":c,style:h,className:K("z-50 bg-background-elevated border border-border rounded-md shadow-lg py-1 min-w-[160px]",e),...s,children:t}),document.body)}function Zm({className:e,icon:t,variant:n="default",children:o,onClick:s,...a}){const{setOpen:i}=ql(),l=q(c=>{s?.(c),i(!1)},[s,i]);return u("button",{type:"button",role:"menuitem",className:K("h-7 text-xs px-2 w-full text-left flex items-center gap-2",n==="danger"?"text-danger hover:bg-danger/10":"text-foreground hover:bg-surface-hover",e),onClick:l,...a,children:[t&&r(t,{size:14}),o]})}const Xm=Oe(null);function Jm(){const e=ye(Xm);if(!e)throw new Error("Tooltip compound components must be used within <Tooltip>");return e}function v5({children:e}){const[t,n]=$(!1),o=ne(null),s=mr(),a=()=>{o.current=setTimeout(()=>n(!0),300)},i=()=>{o.current&&clearTimeout(o.current),n(!1)};return r(Xm.Provider,{value:{open:t,show:a,hide:i,tooltipId:s},children:r("div",{className:"relative inline-block",children:e})})}function w5({children:e,...t}){const{show:n,hide:o,tooltipId:s,open:a}=Jm();return r("div",{onMouseEnter:n,onMouseLeave:o,onFocus:n,onBlur:o,"aria-describedby":a?s:void 0,...t,children:e})}function N5({className:e,children:t,...n}){const{open:o,tooltipId:s}=Jm();return r("div",{id:s,role:"tooltip",className:K("absolute bottom-full left-1/2 -translate-x-1/2 mb-2 bg-foreground text-background text-xs px-2 py-1 rounded-md shadow-md whitespace-nowrap pointer-events-none transition-opacity duration-150",o?"opacity-100":"opacity-0",e),...n,children:t})}const Wd="(max-width: 767px)",Yd="(min-width: 768px) and (max-width: 1023px)";function eh(e){return t=>{const n=window.matchMedia(e);return n.addEventListener("change",t),()=>n.removeEventListener("change",t)}}function th(e){return()=>window.matchMedia(e).matches}function nh(){return!1}function Xn(){return Ws(eh(Wd),th(Wd),nh)}function rh(){return Ws(eh(Yd),th(Yd),nh)}function Ql({open:e,onClose:t,title:n,children:o,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(ve,{children:[r("div",{className:K("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:K("fixed inset-x-0 bottom-0 z-50 flex flex-col bg-background-elevated border-t border-border rounded-t-xl shadow-2xl transition-transform duration-200 ease-out","max-h-[80dvh]",e?"translate-y-0":"translate-y-full",s),children:[r("div",{className:"flex justify-center pt-2 pb-1",children:r("div",{className:"h-1 w-8 rounded-full bg-foreground-subtle/30"})}),n&&u("div",{className:"flex items-center justify-between px-4 pb-2",children:[r("span",{className:"text-sm font-medium text-foreground",children:n}),r("button",{onClick:t,className:"p-1 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors",children:r(Je,{className:"h-4 w-4"})})]}),r("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:o})]})]})}const oh=Oe(null);function sh(){const e=ye(oh);if(!e)throw new Error("Popover compound components must be used within <Popover>");return e}function ah({children:e,open:t,onOpenChange:n}){const[o,s]=$(!1),a=t??o,i=mr(),l=mr(),c=q(d=>{n?.(d),t===void 0&&s(d)},[t,n]);return r(oh.Provider,{value:{open:a,setOpen:c,triggerId:i,contentId:l},children:r("div",{className:"relative inline-block",children:e})})}function ih({children:e,...t}){const{open:n,setOpen:o,triggerId:s,contentId:a}=sh();return r("button",{type:"button",id:s,"aria-haspopup":"dialog","aria-expanded":n,"aria-controls":n?a:void 0,onClick:()=>o(!n),...t,children:e})}function lh({className:e,children:t,...n}){const{open:o,setOpen:s,contentId:a,triggerId:i}=sh(),l=Xn(),c=ne(null);return Y(()=>{if(!o||l)return;const d=p=>{const m=c.current,h=document.getElementById(i);m&&!m.contains(p.target)&&!h?.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)}},[o,s,i,l]),o?l?r(Ql,{open:o,onClose:()=>s(!1),children:t}):r("div",{ref:c,id:a,role:"dialog","aria-labelledby":i,className:K("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 ch=Oe(null);function dh(){const e=ye(ch);if(!e)throw new Error("Tabs compound components must be used within <Tabs>");return e}function k5({value:e,onValueChange:t,defaultValue:n="",className:o,...s}){const[a,i]=$(n),l=e??a,c=q(d=>{t?.(d),e===void 0&&i(d)},[e,t]);return r(ch.Provider,{value:{value:l,setValue:c},children:r("div",{className:o,...s})})}function S5({className:e,...t}){return r("div",{role:"tablist",className:K("flex flex-row border-b border-border-subtle",e),...t})}function C5({value:e,className:t,...n}){const{value:o,setValue:s}=dh(),a=e===o,i=`tabpanel-${e}`;return r("button",{type:"button",role:"tab","aria-selected":a,"aria-controls":i,tabIndex:a?0:-1,className:K("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 M5({value:e,className:t,...n}){const{value:o}=dh();return e!==o?null:r("div",{role:"tabpanel",id:`tabpanel-${e}`,className:K("pt-3",t),...n})}const Ul=Ve(({className:e,...t},n)=>r("div",{ref:n,className:K("overflow-auto [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-surface-hover [&::-webkit-scrollbar-thumb]:rounded-full",e),...t}));Ul.displayName="ScrollArea";function I5({title:e,onClose:t,children:n,defaultWidth:o=360,defaultHeight:s=280,minWidth:a=280,minHeight:i=160,offsetIndex:l=0,className:c}){const[d,f]=$({x:80+l*30,y:80+l*30}),[p,m]=$({w:o,h:s}),[h,g]=$(!1),b=ne(!1),x=ne(!1),v=ne({x:0,y:0}),w=Xn(),y=q(k=>{k.preventDefault(),b.current=!0,v.current={x:k.clientX-d.x,y:k.clientY-d.y}},[d]),N=q(k=>{k.preventDefault(),k.stopPropagation(),x.current=!0,v.current={x:k.clientX,y:k.clientY}},[]);return Y(()=>{const k=M=>{if(b.current&&f({x:M.clientX-v.current.x,y:M.clientY-v.current.y}),x.current){const P=M.clientX-v.current.x,I=M.clientY-v.current.y;v.current={x:M.clientX,y:M.clientY},m(F=>({w:Math.max(a,F.w+P),h:Math.max(i,F.h+I)}))}},S=()=>{b.current=!1,x.current=!1};return window.addEventListener("mousemove",k),window.addEventListener("mouseup",S),()=>{window.removeEventListener("mousemove",k),window.removeEventListener("mouseup",S)}},[a,i]),w?u("div",{className:K("fixed inset-x-0 bottom-0 z-50 rounded-t-xl border-t border-border bg-background-elevated shadow-2xl flex flex-col overflow-hidden",c),style:{maxHeight:"60dvh"},children:[u("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b border-border shrink-0 bg-surface",children:[r("span",{className:"text-[11px] font-medium truncate",children:e}),u("div",{className:"flex items-center gap-1 shrink-0",children:[r("button",{onClick:()=>g(!h),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",children:h?r(jd,{size:12}):r(Hd,{size:12})}),r("button",{onClick:t,className:"p-0.5 rounded hover:bg-danger/20 text-foreground-muted hover:text-danger transition-colors",children:r(Je,{size:12})})]})]}),!h&&r("div",{className:"flex-1 min-h-0 overflow-y-auto",children:n})]}):u("div",{className:K("fixed z-50 rounded-lg border border-border bg-background-elevated shadow-2xl flex flex-col overflow-hidden",c),style:{left:d.x,top:d.y,width:h?280:p.w,height:h?"auto":p.h},children:[u("div",{onMouseDown:y,className:"flex items-center justify-between gap-2 px-3 py-2 border-b border-border cursor-move select-none shrink-0 bg-surface",children:[u("div",{className:"flex items-center gap-2 min-w-0",children:[r(F2,{size:12,className:"text-foreground-subtle shrink-0"}),r("span",{className:"text-[11px] font-medium truncate",children:e})]}),u("div",{className:"flex items-center gap-1 shrink-0",children:[r("button",{onClick:()=>g(!h),className:"p-0.5 rounded hover:bg-surface-hover text-foreground-muted transition-colors",title:h?"Restore":"Minimize",children:h?r(jd,{size:12}):r(Hd,{size:12})}),r("button",{onClick:t,className:"p-0.5 rounded hover:bg-danger/20 text-foreground-muted hover:text-danger transition-colors",title:"Close",children:r(Je,{size:12})})]})]}),!h&&u("div",{className:"flex-1 min-h-0 overflow-y-auto relative",children:[n,r("div",{onMouseDown:N,className:"absolute bottom-0 right-0 w-4 h-4 cursor-nwse-resize",style:{background:"linear-gradient(135deg, transparent 50%, var(--color-foreground-subtle) 50%)",opacity:.4}})]})]})}function Kl({open:e,onClose:t,children:n,className:o,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(ve,{children:[r("div",{className:K("fixed inset-0 z-40 bg-black/50 backdrop-blur-sm transition-opacity duration-200",e?"opacity-100":"pointer-events-none opacity-0"),onClick:t,"aria-hidden":"true"}),r("div",{ref:a,role:"dialog","aria-modal":"true",className:K("fixed inset-y-0 left-0 z-50 flex flex-col bg-surface border-r border-border shadow-2xl transition-transform duration-200 ease-out",s,e?"translate-x-0":"-translate-x-full",o),children:n})]})}function Gl({items:e,className:t}){return r("nav",{className:`flex items-center gap-1 text-[11px] text-foreground-subtle ${t??""}`,children:e.map((n,o)=>{const s=o===e.length-1,a=!s&&(n.onClick||n.href);return u(Al.Fragment,{children:[o>0&&r(Cn,{className:"h-3 w-3 flex-shrink-0"}),a?n.onClick?r("button",{type:"button",onClick:n.onClick,className:"hover:text-foreground transition-colors",children:n.label}):r("a",{href:n.href,className:"hover:text-foreground transition-colors",children:n.label}):r("span",{className:s?"text-foreground font-medium":"",children:n.label})]},o)})})}const Zd={left:"text-left",right:"text-right",center:"text-center"};function uh({columns:e,rows:t,rowKey:n,onRowClick:o,minWidthPx:s=480,emptyMessage:a,className:i,bordered:l=!0,rowClassName:c}){if(t.length===0&&a)return r("div",{className:`rounded-lg ${l?"border border-border":""} bg-surface px-3 py-4 text-xs text-foreground-subtle text-center ${i??""}`,children:a});if(t.length===0)return null;const d=`rounded-lg ${l?"border border-border":""} bg-surface overflow-x-auto ${i??""}`;return r("div",{className:d,children:u("table",{className:"w-full text-xs",style:{minWidth:`${s}px`},children:[r("thead",{className:"bg-surface",children:r("tr",{children:e.map(f=>{const p=f.align??"left",m=f.nowrap??!0;return r("th",{className:["px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border",Zd[p],m?"whitespace-nowrap":"",f.width??""].filter(Boolean).join(" "),children:f.headerRender?f.headerRender():f.header},f.key)})})}),r("tbody",{children:t.map((f,p)=>{const m=n?n(f,p):p,h=c?.(f,p)??"",g=o!==void 0;return r("tr",{onClick:g?()=>o(f,p):void 0,className:[g?"cursor-pointer hover:bg-primary/5":"hover:bg-primary/5",h].filter(Boolean).join(" "),children:e.map(b=>{const x=b.align??"left",v=b.nowrap??!1;return r("td",{className:["px-3 py-2 text-foreground border-b border-border",Zd[x],v?"whitespace-nowrap":""].filter(Boolean).join(" "),children:b.render(f,p)},b.key)})},m)})})]})})}function Wl({open:e,onClose:t,title:n,subtitle:o,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:K("absolute top-0 right-0 bottom-0 z-20 flex flex-col","bg-surface border-l border-border shadow-xl",i),role:"dialog","aria-modal":"false",children:[u("header",{className:"flex items-start justify-between gap-2 px-4 py-3 border-b border-border",children:[u("div",{className:"min-w-0",children:[r("div",{className:"text-sm font-semibold text-foreground truncate",children:n}),o!==void 0&&r("div",{className:"text-[11px] text-foreground-subtle mt-0.5 truncate",children:o})]}),r("button",{type:"button",onClick:t,className:"p-1 rounded hover:bg-muted text-foreground-subtle hover:text-foreground","aria-label":"Close panel",children:r(Je,{className:"w-4 h-4"})})]}),r("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3",children:a}),s!==void 0&&r("footer",{className:"flex items-center gap-2 justify-end px-4 py-3 border-t border-border",children:s})]}):null}const A5={inherit:"bg-muted",on:"bg-emerald-500",off:"bg-orange-500",na:"bg-gray-300 opacity-50"};function ph({node:e,depth:t,selectedAddonId:n,onSelect:o,agentDots:s}){const a=e.addonId===n,i=s?.[e.addonId]??[];return u("div",{children:[u("button",{type:"button",onClick:()=>o(e.addonId),className:K("w-full flex items-center justify-between gap-2 text-left px-3 py-1.5 text-xs","border-l-2",a?"bg-accent border-primary text-foreground font-medium":"border-transparent hover:bg-muted/40 text-foreground"),style:{paddingLeft:`${12+t*14}px`},children:[r("span",{className:"truncate",children:e.addonName}),i.length>0&&r("span",{className:"flex items-center gap-1 shrink-0",children:i.map(l=>r("span",{title:`${l.agentNodeId}: ${l.state}`,className:K("w-2 h-2 rounded-full",A5[l.state])},l.agentNodeId))})]}),e.children.map(l=>r(ph,{node:l,depth:t+1,selectedAddonId:n,onSelect:o,agentDots:s},l.addonId))]})}function fh({tree:e,selectedAddonId:t,onSelect:n,agentDots:o,className:s}){return r("div",{className:K("flex flex-col py-2",s),children:e.map(a=>r(ph,{node:a,depth:0,selectedAddonId:t,onSelect:n,agentDots:o},a.addonId))})}function ea(e){const t=[],n=[],o=new Map;for(const a of e.slots)for(const i of a.addons){const l={addonId:i.id,addonName:i.name,slot:i.slot,inputClasses:i.inputClasses,outputClasses:i.outputClasses,children:[]};i.slot==="audio-classifier"?t.push(l):(n.push(l),o.set(i.id,l))}const s=[];for(const a of n){if(a.inputClasses.length===0){s.push(a);continue}const i=n.find(l=>l.addonId!==a.addonId&&l.outputClasses.some(c=>a.inputClasses.includes(c)));i&&i.children.push(a)}return[...s,...t]}function P5(e){return e?e.models.map(t=>({id:t.id,name:t.name})):[]}function ps({step:e,schema:t,allSchemas:n,depth:o=0,onChange:s,onDelete:a,readOnly:i=!1,toggleMode:l="simple",overrideState:c=null,onOverrideChange:d,inheritedEnabled:f,hideModelAndSettings:p=!1}){const[m,h]=$(!1),g=P5(t);if(g.length>0&&!g.some(x=>x.id===e.modelId)&&!i){const v=(t?.defaultModelId?g.find(w=>w.id===t.defaultModelId):null)??g[0];v&&v.id!==e.modelId&&queueMicrotask(()=>s({...e,modelId:v.id}))}const b=u(ve,{children:[u("div",{className:"flex-1 min-w-0",children:[r("span",{className:"text-[10px] uppercase tracking-wider font-medium text-foreground-subtle/60 block leading-none",children:e.slot}),r("span",{className:"text-sm font-semibold text-foreground truncate block leading-tight",children:e.addonName}),u("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(x=>r("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-blue-500/12 text-blue-400",children:x},x)),e.inputClasses.length>0&&e.outputClasses.length>0&&r("span",{className:"text-foreground-subtle/40 text-[10px]",children:"→"}),e.outputClasses.map(x=>r("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-green-500/12 text-green-400",children:x},x))]})]}),!i&&l==="simple"&&r("button",{onClick:x=>{x.stopPropagation(),s({...e,enabled:!e.enabled})},className:K("relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors",e.enabled?"bg-success":"bg-foreground-subtle/30"),children:r("span",{className:K("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:[r(Fa,{label:"Inherit",active:c===null,variant:"inherit",subtext:f===void 0?void 0:f?"on":"off",onClick:()=>d(null)}),r(Fa,{label:"On",active:c===!0,variant:"on",onClick:()=>d(!0)}),r(Fa,{label:"Off",active:c===!1,variant:"off",onClick:()=>d(!1)})]})]});return r(Om,{expanded:m,onExpandedChange:h,dimmed:!e.enabled,header:b,children:p?r("p",{className:"text-[11px] text-foreground-subtle",children:"Model and detection settings are managed per agent — open the Pipeline page for this camera's agent to edit them."}):u("div",{className:"space-y-3",children:[r(Fi,{label:"Model",value:e.modelId,disabled:i,options:g.map(x=>({value:x.id,label:x.name})),onChange:x=>s({...e,modelId:x})}),e.slot==="audio-classifier"&&e.engine&&r(Fi,{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[v,w]=x.split("/");s({...e,engine:{runtime:v,backend:w,format:w==="coreml"?"coreml":"onnx"}})}}),t?.configSchema?.map(x=>r(ta,{field:x,allFields:t.configSchema??[],step:e,disabled:i,onChange:s},x.key))]})})}function Fi({label:e,value:t,options:n,disabled:o,onChange:s}){return u("div",{children:[r("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e}),u("select",{value:t,onChange:a=>s(a.target.value),disabled:o,className:"w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground focus:outline-none focus:border-primary/50",children:[n.length===0&&r("option",{value:t,children:t||"default"}),n.map(a=>r("option",{value:a.value,disabled:a.disabled,children:a.label},a.value))]})]})}function E5({label:e,description:t,value:n,options:o,disabled:s,onChange:a}){function i(l){if(s)return;const c=n.includes(l)?n.filter(d=>d!==l):[...n,l];a(c)}return u("div",{children:[r("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1",children:e}),t&&r("p",{className:"text-[10px] text-foreground-subtle/60 mb-1.5",children:t}),r("div",{className:"flex flex-wrap gap-1.5",children:o.map(l=>{const c=n.includes(l.value);return r("button",{type:"button",disabled:s,onClick:()=>i(l.value),className:K("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 $5(e,t,n){const o=t.settings?.[e];if(o!==void 0)return o;const s=n.find(a=>"key"in a&&a.key===e);return s&&"default"in s?s.default:void 0}function ta({field:e,allFields:t,step:n,disabled:o,onChange:s}){const a=e.type!=="separator"&&e.type!=="info"?e.showWhen:void 0;if(a){const{field:l,equals:c,notEquals:d,in:f,notIn:p}=a,m=$5(l,n,t);if(c!==void 0&&m!==c||d!==void 0&&m===d||f!==void 0&&!f.includes(m)||p!==void 0&&p.includes(m))return null}function i(l){s({...n,settings:{...n.settings,[e.key]:l}})}if(e.type==="select"){const l=n.settings?.[e.key],c=typeof l=="string"?l:e.default??"";return r(Fi,{label:e.label,value:c,disabled:o||e.disabled,options:e.options,onChange:i})}if(e.type==="multiselect"){const l=n.settings?.[e.key],c=Array.isArray(l)?l:Array.isArray(e.default)?e.default:[];return r(E5,{label:e.label,description:e.description,value:c,options:e.options,disabled:o||e.disabled,onChange:i})}if(e.type==="slider"||e.type==="number"){const l=n.settings?.[e.key],c=typeof e.default=="number"?e.default:e.min??0,d=typeof l=="number"?l:c,f=e.min??0,p=e.max??1,m=e.step??.01,h=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:[r("span",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide",children:e.label}),h&&u("span",{className:"text-xs font-medium text-foreground tabular-nums",children:[typeof x=="number"?x.toFixed(2).replace(/\.?0+$/,""):x,g?` ${g}`:""]})]}),e.description&&r("p",{className:"text-[10px] text-foreground-subtle/60 mb-1.5",children:e.description}),r("input",{type:"range",min:f,max:p,step:m,value:d,disabled:o||e.disabled,onChange:v=>i(Number(v.target.value)),className:"w-full accent-primary h-1.5"})]})}if(e.type==="boolean"){const l=n.settings?.[e.key],c=typeof l=="boolean"?l:e.default===!0;return u("label",{className:"flex items-center gap-2",children:[r("input",{type:"checkbox",checked:c,disabled:o||e.disabled,onChange:d=>i(d.target.checked),className:"h-3.5 w-3.5 accent-primary"}),r("span",{className:"text-[10px] font-medium text-foreground-subtle uppercase tracking-wide",children:e.label})]})}if(e.type==="text"||e.type==="password"||e.type==="textarea"){const l=n.settings?.[e.key],c=typeof l=="string"?l:e.default??"",d=e.type==="password"?"password":"text";return u("div",{children:[r("label",{className:"block text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-1.5",children:e.label}),e.type==="textarea"?r("textarea",{value:c,disabled:o||e.disabled,placeholder:e.placeholder,onChange: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"}):r("input",{type:d,value:c,disabled:o||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"?r("div",{className:"border-t border-border my-2"}):e.type==="info"?r("div",{className:"rounded-md border border-border bg-surface px-2 py-1.5 text-[10px] text-foreground-subtle",children:e.content}):null}function Fa({label:e,active:t,variant:n,subtext:o,onClick:s}){return u("button",{type:"button",onClick:s,className:K("px-2 py-1 text-[10px] font-medium rounded transition-colors",t?n==="on"?"bg-green-500/20 text-green-400":n==="off"?"bg-red-500/20 text-red-400":"bg-primary/20 text-primary":"text-foreground-subtle hover:bg-surface-hover"),children:[e,o&&t&&u("span",{className:"ml-1 opacity-60",children:["(",o,")"]})]})}function mh(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 _5(e,t,n){return n?{enabled:n.enabled??t.enabled,modelId:n.modelId??t.modelId,settings:n.settings??t.settings}:t}function D5({addon:e,agentDefault:t,modelsForFormat:n,onChangeAgentConfig:o}){const s=a=>{o?.({...t,...a})};return u("div",{className:"space-y-4 text-xs",children:[u("label",{className:"flex items-center gap-2",children:[r("input",{type:"checkbox",checked:t.enabled,onChange:a=>s({enabled:a.target.checked})}),u("span",{children:["Enabled on this agent (",e.name,")"]})]}),u("div",{children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle mb-1",children:"Model"}),r("select",{className:"w-full bg-surface border border-border rounded px-2 py-1 text-xs",value:t.modelId,onChange:a=>s({modelId:a.target.value}),children:n.map(a=>r("option",{value:a.id,children:a.name},a.id))})]}),(e.configSchema?.length??0)>0&&u("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),e.configSchema?.map(a=>r(ta,{field:a,allFields:e.configSchema??[],step:mh(e,t),disabled:!1,onChange:i=>s({settings:{...i.settings}})},a.key))]})]})}function L5({addon:e,agentDefault:t,agentNodeId:n,currentPatch:o,modelsForFormat:s,onChangePatch:a}){const i=_5("device",t,o),l=h=>{const g=h.enabled!==void 0||h.modelId!==void 0||h.settings!==void 0;a?.(g?h:null)},c=h=>{const{enabled:g,...b}=o??{},x=h==="inherit"?b:{...b,enabled:h==="on"};l(x)},d=h=>{const{modelId:g,...b}=o??{},x=h===void 0?b:{...b,modelId:h};l(x)},f=h=>{const{settings:g,...b}=o??{},x=h===void 0?b:{...b,settings:h};l(x)},p=o?.enabled===void 0?"inherit":o.enabled?"on":"off",m=o?.modelId!==void 0;return u("div",{className:"space-y-4 text-xs",children:[u("div",{className:"flex items-center gap-1",children:[["inherit","on","off"].map(h=>r("button",{type:"button",onClick:()=>c(h),className:K("px-3 py-1 border border-border rounded text-xs capitalize",p===h?"bg-primary text-primary-foreground border-primary":"bg-surface text-foreground hover:bg-muted"),children:h},h)),u("span",{className:"ml-2 text-[10px] text-foreground-subtle",children:["agent default: ",r("span",{className:"font-semibold",children:t.enabled?"on":"off"})]})]}),u("div",{children:[u("div",{className:"flex items-center justify-between mb-1",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Model"}),m?r("button",{type:"button",className:"text-[10px] text-foreground-subtle hover:text-foreground",onClick:()=>d(void 0),children:"Clear"}):r("button",{type:"button",className:"text-[10px] text-primary hover:underline",onClick:()=>d(t.modelId),children:"Override"})]}),r("select",{disabled:!m,className:"w-full bg-surface border border-border rounded px-2 py-1 text-xs disabled:opacity-50",value:m?o?.modelId??t.modelId:t.modelId,onChange:h=>d(h.target.value),children:s.map(h=>r("option",{value:h.id,children:h.name},h.id))}),!m&&u("div",{className:"text-[10px] text-foreground-subtle mt-1",children:["inherits from ",n]})]}),(e.configSchema?.length??0)>0&&(()=>{const h=o?.settings!==void 0;return u("div",{className:"pt-2 border-t border-border/50 space-y-3",children:[u("div",{className:"flex items-center justify-between",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-foreground-subtle",children:"Settings"}),h?r("button",{type:"button",className:"text-[10px] text-foreground-subtle hover:text-foreground",onClick:()=>f(void 0),children:"Clear"}):r("button",{type:"button",className:"text-[10px] text-primary hover:underline",onClick:()=>f({...t.settings}),children:"Override"})]}),e.configSchema?.map(g=>r(ta,{field:g,allFields:e.configSchema??[],step:mh(e,i),disabled:!h,onChange:b=>f({...b.settings})},g.key)),!h&&u("div",{className:"text-[10px] text-foreground-subtle",children:["inherits from ",n]})]})})(),u("div",{className:"rounded bg-muted/40 px-3 py-2 text-[11px] text-foreground-subtle",children:[r("div",{className:"font-semibold text-foreground mb-0.5",children:"Effective config preview"}),u("div",{className:"font-mono truncate",children:[e.id," · model: ",i.modelId," · ",i.enabled?"on":"off"]})]})]})}function na(e){const{mode:t,addon:n,agentDefault:o,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"?r(D5,{addon:n,agentDefault:o,modelsForFormat:d,onChangeAgentConfig:i}):r(L5,{addon:n,agentDefault:o,agentNodeId:s,currentPatch:a,modelsForFormat:d,onChangePatch:l})}function T5(e){const t=[],n=(o,s)=>{for(const a of o)t.push({node:a,depth:s}),n(a.children,s+1)};return n(e,0),t}const Xd={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 R5({slot:e}){const t=Xd[e]??Xd.classifier;return r("span",{className:K("text-[9px] font-semibold uppercase tracking-widest leading-none",t.className),children:t.label})}const Jd="inline-flex items-center rounded bg-muted px-1.5 py-px text-[9px] font-medium text-foreground-subtle";function O5({inputs:e,outputs:t}){return e.length===0&&t.length===0?null:u("span",{className:"inline-flex items-center gap-1 flex-wrap",children:[e.map(n=>r("span",{className:K(Jd,"bg-blue-500/10 text-blue-500"),children:n},`in-${n}`)),e.length>0&&t.length>0&&r("span",{className:"text-foreground-subtle/60 text-[9px]",children:"→"}),t.map(n=>r("span",{className:K(Jd,"bg-emerald-500/10 text-emerald-500"),children:n},`out-${n}`))]})}function z5({enabled:e,onChange:t,disabled:n}){return r("button",{type:"button",role:"switch","aria-checked":e,disabled:n,onClick:o=>{o.stopPropagation(),t(!e)},className:K("relative inline-flex h-3.5 w-7 shrink-0 items-center rounded-full transition-colors",e?"bg-emerald-500":"bg-foreground-subtle/30",n?"opacity-50 cursor-not-allowed":"cursor-pointer"),title:e?"Click to disable":"Click to enable",children:r("span",{className:K("inline-block h-3 w-3 rounded-full bg-white shadow transition-transform",e?"translate-x-3.5":"translate-x-0.5")})})}function B5(e){return e.kind==="enabled"?u("span",{className:"inline-flex items-center gap-1",children:[r("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500 shrink-0"}),r("span",{className:"font-mono text-foreground",children:e.modelId})]}):e.kind==="disabled"?u("span",{className:"inline-flex items-center gap-1 text-foreground-subtle",children:[r("span",{className:"h-1.5 w-1.5 rounded-full border border-foreground-subtle/60 shrink-0"}),"off"]}):u("span",{className:"inline-flex items-center gap-1 text-foreground-subtle/70",children:[r("span",{className:"h-1.5 w-1.5 rounded-full bg-muted shrink-0"}),"n/a"]})}function F5({node:e,depth:t,agents:n,getCellState:o,onCellClick:s,selectedCell:a,toggleProps:i}){return u(ve,{children:[u("div",{className:"sticky left-0 z-10 bg-surface px-3 py-2 border-b border-border text-xs flex items-start gap-2",style:{paddingLeft:`${12+t*14}px`},children:[u("div",{className:"flex flex-col gap-1 min-w-0 flex-1",children:[r(R5,{slot:e.slot}),u("div",{className:"flex items-center gap-2 flex-wrap",children:[r("span",{className:"font-semibold truncate",children:e.addonName}),r(O5,{inputs:e.inputClasses,outputs:e.outputClasses})]})]}),i&&r("span",{className:"pl-2 pt-0.5 shrink-0",children:r(z5,{enabled:i.enabled,onChange:i.onChange,disabled:i.disabled})})]}),n.map(l=>{const c=o(e.addonId,l.agentNodeId),d=a?.addonId===e.addonId&&a.agentNodeId===l.agentNodeId;return r("button",{type:"button",onClick:()=>s(e.addonId,l.agentNodeId),className:K("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:B5(c)},l.agentNodeId)})]})}function Yl({tree:e,agents:t,getCellState:n,onCellClick:o,selectedCell:s,onToggleEnabled:a}){const i=Q(()=>T5(e),[e]),l=`minmax(320px, 1fr) repeat(${t.length}, minmax(160px, 220px))`,c=a!==void 0&&t.length===1,d=t[0]?.agentNodeId;return r("div",{className:"overflow-auto border border-border rounded",children:u("div",{className:"grid",style:{gridTemplateColumns:l},children:[r("div",{className:"sticky top-0 left-0 z-20 bg-muted/60 px-3 py-2 text-[10px] uppercase tracking-widest text-foreground-subtle border-b border-border",children:"Step"}),t.map(f=>u("div",{className:"sticky top-0 z-10 bg-muted/60 px-3 py-2 border-b border-l border-border",children:[r("div",{className:"text-xs font-semibold text-foreground",children:f.agentNodeId}),r("div",{className:"text-[10px] text-foreground-subtle truncate",children:f.engineLabel})]},f.agentNodeId)),i.map(({node:f,depth:p})=>{const m=c&&d!==void 0?n(f.addonId,d):null,h=c&&m!==null?{enabled:m.kind==="enabled",onChange:g=>a?.(f.addonId,g),disabled:m.kind==="na"}:void 0;return r(F5,{node:f,depth:p,agents:t,getCellState:n,onCellClick:o,selectedCell:s,toggleProps:h},f.addonId)})]})})}const hh=typeof globalThis<"u"?globalThis.__camstackTrpcReact:void 0,C=hh??tw();typeof globalThis<"u"&&!hh&&(globalThis.__camstackTrpcReact=C);const Zl=un("camstack:system",null);function Xl({system:e,children:t}){return r(Zl.Provider,{value:e,children:t})}function Le(){const e=ye(Zl);if(!e)throw new Error("useSystem(): no <SystemProvider> in tree");return e}function j5(){return ye(Zl)}function dt(e,t){const n=Le(),o=ne(t);o.current=t;const[s,a]=$(n.connectionVersion);Y(()=>n.subscribeConnectionEvents((i,l)=>{i==="connected"&&a(l)}),[n]),Y(()=>n.subscribeEvent(e,l=>{o.current(l)}),[n,e,s])}function ji(e){const t=ne(e);return t.current=e,t}function Ar(e,t){const[n,o]=$(null),s=ji(t);return dt(e,a=>{const i=a.data,l=s.current;l&&!l(i)||o(i)}),n}function Jl(e,t,n){const[o,s]=$(()=>new Map),a=ji(t),i=ji(n);dt(e,c=>{const d=c.data,f=i.current;if(f&&!f(d))return;const p=a.current(d);s(m=>{const h=new Map(m);return h.set(p,d),h})});const l=Q(()=>Array.from(o.values()),[o]);return{map:o,values:l}}function Pr(){const{data:e,isLoading:t}=C.nodes.topology.useQuery(void 0,{staleTime:6e4}),o=Ar("cluster.topology-snapshot")?.nodes??e;return{nodes:Q(()=>{const a=[];for(const i of o??[])a.push({id:String(i.id??""),name:String(i.name??i.id??""),shortName:i.isHub?"HUB":String(i.name??i.id??""),isHub:!!i.isHub,isOnline:!!i.isOnline,localIps:i.localIps??[],addons:(i.addons??[]).map(l=>({addonId:l.id,capabilities:l.capabilities}))});return a.sort((i,l)=>i.isHub!==l.isHub?i.isHub?-1:1:i.name.localeCompare(l.name)),a},[o]),isLoading:t}}function gh({selectedNodeId:e,onSelect:t,label:n="Node",hideIcon:o=!1,alwaysShow:s=!1}){const{nodes:a}=Pr();return!s&&a.length<=1?null:u("div",{className:"flex items-center gap-1.5",children:[!o&&r(Ek,{className:"h-3.5 w-3.5 text-foreground-subtle"}),n&&r("span",{className:"text-[10px] uppercase tracking-wider text-foreground-subtle",children:n}),r("div",{className:"flex rounded-md border border-border overflow-hidden text-[11px] font-medium",children:a.map((i,l)=>{const c=e===i.id;return r("button",{type:"button",onClick:()=>t(i.id),disabled:!i.isOnline,title:i.isOnline?i.name:`${i.name} (offline)`,className:K("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 H5={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 V5({status:e,showDot:t=!0,showLabel:n=!0,size:o="sm",className:s}){const a=H5[e];return u("span",{className:K("inline-flex items-center gap-1.5",o==="sm"?"text-xs":"text-sm",s),children:[t&&r("span",{className:K("h-1.5 w-1.5 shrink-0 rounded-full",a.colorClass),"aria-hidden":"true"}),n&&r("span",{className:"text-foreground",children:a.label})]})}const q5={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 Q5({provider:e,showLabel:t=!0,className:n}){const o=q5[e];return u("span",{className:K("inline-flex items-center gap-1.5 text-xs",n),children:[r("span",{className:K("h-1.5 w-1.5 shrink-0 rounded-sm",o.colorClass),"aria-hidden":"true"}),t&&r("span",{className:"text-foreground",children:o.label})]})}const U5={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 bh({children:e,variant:t="neutral",mono:n,className:o}){return r("span",{className:K("inline-flex items-center rounded-md px-2 py-0.5 text-[11px] font-bold leading-tight",n&&"font-mono",U5[t],o),children:e})}function K5({version:e,preRelease:t,className:n}){const o=t??/-(alpha|beta|rc|dev|canary|next)/i.test(e);return r(bh,{variant:o?"warning":"success",mono:!0,className:n,children:e})}function G5({label:e,description:t,error:n,required:o,children:s,orientation:a="vertical",className:i}){const l=a==="horizontal";return u("div",{className:K("flex gap-2",l?"flex-row items-center justify-between":"flex-col",i),children:[u("div",{className:K(l?"flex-1":""),children:[u(Fl,{children:[e,o&&r("span",{className:"text-danger ml-0.5",children:"*"})]}),t&&r("p",{className:"text-foreground-subtle text-xs mt-0.5",children:t})]}),r("div",{className:K(l?"shrink-0":""),children:s}),n&&r("p",{className:"text-danger text-xs",children:n})]})}function W5({title:e,subtitle:t,actions:n,className:o}){return u("div",{className:K("flex flex-col gap-2 mb-3 sm:flex-row sm:items-center sm:justify-between",o),children:[u("div",{children:[r("h1",{className:"text-sm font-semibold text-foreground",children:e}),t&&r("p",{className:"text-foreground-subtle text-xs",children:t})]}),n&&r("div",{className:"flex items-center gap-2 flex-wrap",children:n})]})}function ko({icon:e,title:t,description:n,action:o,className:s}){return u("div",{className:K("flex flex-col items-center justify-center gap-3 py-12",s),children:[e&&r(e,{className:"h-12 w-12 text-foreground-subtle","aria-hidden":"true"}),u("div",{className:"flex flex-col items-center gap-1 text-center",children:[r("p",{className:"text-foreground-muted text-sm font-medium",children:t}),n&&r("p",{className:"text-foreground-subtle text-xs max-w-xs",children:n})]}),o&&r("div",{className:"mt-1",children:o})]})}const xh=un("camstack:confirm-dialog",null);function rt(){const e=ye(xh);if(!e)throw new Error("useConfirm must be used within ConfirmDialogProvider");return e.confirm}function yh({children:e}){const[t,n]=$(null),o=q(c=>new Promise(d=>{n({...c,resolve:d})}),[]),s=()=>{t?.resolve(!0),n(null)},a=()=>{t?.resolve(!1),n(null)},i={danger:{icon:"text-red-400",button:"bg-red-500 hover:bg-red-600 text-white"},warning:{icon:"text-orange-400",button:"bg-orange-500 hover:bg-orange-600 text-white"},default:{icon:"text-primary",button:"bg-primary hover:bg-primary/90 text-white"}},l=t?i[t.variant??"default"]:i.default;return u(xh.Provider,{value:{confirm:o},children:[e,t&&u("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[r("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:a}),u("div",{className:"relative z-10 w-full max-w-sm mx-4 rounded-xl border border-border bg-surface shadow-2xl overflow-hidden animate-in fade-in zoom-in-95 duration-150",onClick:c=>c.stopPropagation(),children:[u("div",{className:"px-5 pt-5 pb-4",children:[r("h3",{className:"text-sm font-semibold text-foreground",children:t.title}),r("p",{className:"mt-2 text-xs text-foreground-subtle leading-relaxed",children:t.message})]}),u("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border bg-surface-hover/30",children:[r("button",{type:"button",onClick:a,className:"px-3 py-1.5 text-xs font-medium rounded-md border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:t.cancelLabel??"Cancel"}),r("button",{type:"button",onClick:s,className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${l.button}`,children:t.confirmLabel??"Confirm"})]})]})]})]})}function Y5({value:e,label:t,trend:n,className:o}){return u(Ge,{className:K("flex flex-col gap-1",o),children:[u("div",{className:"flex items-baseline gap-2",children:[r("span",{className:"text-2xl font-semibold text-foreground",children:e}),n&&u("span",{className:K("inline-flex items-center gap-0.5 text-xs font-medium",n.direction==="up"?"text-success":"text-danger"),children:[n.direction==="up"?r(Yk,{className:"h-3 w-3"}):r(Xk,{className:"h-3 w-3"}),n.value,"%"]})]}),r("span",{className:"text-xs text-foreground-muted",children:t})]})}function Z5({items:e,className:t}){return r("dl",{className:K("flex flex-col",t),children:e.map(n=>u("div",{className:"flex items-center h-7",children:[r("dt",{className:"text-foreground-subtle text-xs w-1/3 shrink-0",children:n.key}),r("dd",{className:"text-foreground text-xs",children:n.value})]},n.key))})}function X5({children:e,maxHeight:t=300,className:n}){const[o,s]=$(!1),a=q(()=>{navigator.clipboard.writeText(e).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)})},[e]);return u("div",{className:K("relative group",n),children:[r(Ul,{style:{maxHeight:t},children:r("pre",{className:"font-mono text-xs bg-surface p-3 rounded-md border border-border-subtle",children:r("code",{children:e})})}),r("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity",children:r(Bl,{icon:o?wo:Mn,"aria-label":"Copy code",variant:"ghost",size:"sm",onClick:a})})]})}function J5({filters:e,values:t,onChange:n,className:o}){const s=Xn(),[a,i]=$(!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:K("flex items-center gap-2",o),children:[d&&r(Ss,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:p=>l(d.key,p.target.value),leftSlot:r(oo,{className:"h-3 w-3 text-foreground-subtle"}),className:"flex-1"}),f&&u(ve,{children:[u("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-foreground-muted hover:bg-surface-hover transition-colors shrink-0",children:[r(Rk,{className:"h-3.5 w-3.5"}),"Filters",c>0&&r(cr,{variant:"info",className:"ml-1 text-[10px] px-1 py-0",children:c})]}),r(Ql,{open:a,onClose:()=>i(!1),title:"Filters",children:r("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:[r("label",{className:"text-xs text-foreground-muted mb-1 block",children:p.label}),r(Cs,{options:p.options,value:t[p.key]??"",onChange:m=>l(p.key,m.target.value),className:"w-full"})]},p.key);case"badge-toggle":return r("div",{className:"flex items-center gap-1 flex-wrap",children:p.options.map(m=>{const g=t[p.key]===m.value;return r("button",{type:"button",onClick:()=>l(p.key,g?void 0:m.value),children:r(cr,{variant:g?"info":"default",className:"cursor-pointer",children:m.label})},m.value)})},p.key);default:return null}})})})]})]})}return r("div",{className:K("flex items-center gap-2 flex-wrap",o),children:e.map(d=>{switch(d.type){case"search":return r(Ss,{placeholder:d.placeholder??"Search...",value:t[d.key]??"",onChange:f=>l(d.key,f.target.value),leftSlot:r(oo,{className:"h-3 w-3 text-foreground-subtle"}),className:"w-48"},d.key);case"select":return r(Cs,{options:d.options,value:t[d.key]??"",onChange:f=>l(d.key,f.target.value),className:"w-36"},d.key);case"badge-toggle":return r("div",{className:"flex items-center gap-1",children:d.options.map(f=>{const m=t[d.key]===f.value;return r("button",{type:"button",onClick:()=>l(d.key,m?void 0:f.value),children:r(cr,{variant:m?"info":"default",className:"cursor-pointer",children:f.label})},f.value)})},d.key);default:return null}})})}function Hi({label:e,icon:t,href:n,badge:o,active:s=!1,className:a}){return u("a",{href:n,className:K("flex items-center gap-2 h-7 px-2 text-[11px] transition-colors",s?"border-l-2 border-primary bg-primary/[0.08] text-foreground rounded-r-md":"text-foreground-subtle hover:bg-surface-hover rounded-md",a),children:[r(t,{className:"h-3.5 w-3.5 shrink-0"}),r("span",{className:"truncate flex-1",children:e}),o!==void 0&&r(cr,{className:"ml-auto text-[10px] px-1.5 py-0",children:o})]})}function Vi({logo:e,sections:t,footer:n,onNavigate:o,className:s}){return u("nav",{className:K("bg-surface border-r border-border h-full flex flex-col",s),children:[e&&r("div",{className:"px-3 py-2 shrink-0",children:e}),r("div",{className:"flex-1 overflow-auto px-1 py-1",children:t.map((a,i)=>u("div",{className:K(i>0?"mt-3":""),children:[a.label&&r("span",{className:"text-[10px] text-foreground-disabled uppercase tracking-wider px-2 mb-1 block",children:a.label}),r("div",{className:"flex flex-col gap-0.5",onClick:o,children:a.items.map(l=>r(Hi,{...l},l.href))})]},i))}),n&&n.length>0&&u("div",{className:"shrink-0 px-1 pb-1",children:[r(jl,{className:"mb-1"}),r("div",{className:"flex flex-col gap-0.5",onClick:o,children:n.map(a=>r(Hi,{...a},a.href))})]})]})}function eS({sidebar:e,header:t,mobileLogo:n,mobileActions:o,children:s,className:a}){const i=Xn(),[l,c]=$(!1);return u("div",{className:K("flex h-screen",a),children:[!i&&r(Vi,{...e,className:K("w-44",e.className)}),i&&r(Kl,{open:l,onClose:()=>c(!1),width:"w-64",children:r(Vi,{...e,onNavigate:()=>c(!1),className:"w-full border-r-0"})}),u("div",{className:"flex flex-1 flex-col min-w-0",children:[i&&u("header",{className:"flex items-center h-12 border-b border-border px-3 shrink-0 bg-surface/80 backdrop-blur-sm",children:[r("button",{onClick:()=>c(!0),className:"p-1.5 -ml-1.5 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors","aria-label":"Open menu",children:r(nk,{className:"h-5 w-5"})}),n&&r("div",{className:"flex-1 flex justify-center",children:n}),o&&r("div",{className:"shrink-0",children:o})]}),!i&&t&&u("header",{className:"flex items-center h-10 border-b border-border px-4 shrink-0",children:[t.breadcrumbs&&t.breadcrumbs.length>0&&r("nav",{className:"flex items-center gap-1 text-xs flex-1 min-w-0",children:t.breadcrumbs.map((d,f)=>{const p=f===t.breadcrumbs.length-1;return u("span",{className:"flex items-center gap-1",children:[f>0&&r(Cn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),d.href&&!p?r("a",{href:d.href,className:"text-foreground-subtle hover:text-foreground transition-colors truncate",children:d.label}):r("span",{className:"text-foreground truncate",children:d.label})]},f)})}),t.actions&&r("div",{className:"flex items-center gap-2 ml-auto shrink-0",children:t.actions})]}),r("main",{className:"flex-1 overflow-auto p-4",children:s})]})]})}const tS={online:"bg-success",offline:"bg-danger",warning:"bg-warning",unknown:"bg-foreground-subtle"};function nS({title:e,subtitle:t,status:n,selected:o,onClick:s,badges:a,actions:i,offlineAction:l,className:c}){const d=n==="offline";return u("div",{onClick:s,className:K("w-full rounded-lg border p-3 text-left transition-colors",s&&"cursor-pointer",o?"border-primary bg-primary/10":"border-border bg-surface hover:bg-surface-hover",d&&!o&&"opacity-50",c),children:[u("div",{className:"flex items-center justify-between mb-2",children:[r("span",{className:"text-sm font-medium truncate",children:e}),n&&r("span",{className:K("h-2 w-2 rounded-full shrink-0",tS[n])})]}),t&&r("div",{className:"text-[11px] text-foreground-muted",children:t}),a&&a.length>0&&r("div",{className:"flex flex-wrap gap-1 mt-2",children:a.map((f,p)=>{const m=K("rounded px-1.5 py-0.5 text-[10px] flex items-center gap-0.5",o?"bg-primary/20":"bg-surface-hover",f.onClick&&"hover:opacity-80 transition-opacity cursor-pointer");return f.onClick?u("button",{onClick:h=>{h.stopPropagation(),f.onClick()},className:m,children:[f.icon,f.label]},p):u("span",{className:m,children:[f.icon,f.label]},p)})}),!d&&i&&i.length>0&&r("div",{className:"flex items-center gap-0.5 mt-2 -mb-1",children:i.map((f,p)=>r("button",{onClick:m=>{m.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&&r("div",{className:"mt-2",onClick:f=>f.stopPropagation(),children:l})]})}function rS({children:e,minCardWidth:t=220,gap:n=3,className:o}){return r("div",{className:K("p-4 overflow-y-auto flex-1 content-start",o),style:{display:"grid",gridTemplateColumns:`repeat(auto-fill, minmax(${t}px, 1fr))`,gap:`${n*4}px`},children:e})}const oS="capability.binding-changed";function kt(e,t){const[n,o]=$(null);return Y(()=>{if(t===null){o(null);return}let s=!1;const a=async()=>{try{const l=await e.deviceManager.getBindings.query({deviceId:t});s||o(l)}catch{s||o(l=>l)}};a();const i=e.live?.onEvent.subscribe({category:oS},{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?nw(e,n):null,[e,n])}function on(e){const t=q(o=>e?e.subscribe(()=>o()):()=>{},[e]),n=q(()=>e?.value,[e]);return Ws(t,n,n)}function vh(e,t,n){const o=kt(e,t),s=o?n(o.state):void 0;return on(s)}function Er(e){const t=kt(e.trpc,e.deviceId),n=t!==null?e.slice(t):void 0,o=on(n),s=t!==null?e.cap(t):void 0,c=(e.requireFeature===void 0||(e.deviceFeatures??[]).includes(e.requireFeature))&&s!==void 0&&o!==void 0;return{dev:t,cap:s,slice:o,available:c}}function sS(e){return e.parentDeviceId===null?"top-level":e.role?"accessory":"adopted"}const aS={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 iS(e){const t=aS[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 lS={siren:Ys,floodlight:Am,spotlight:Lm,"pir-sensor":$m,chime:lk,autotrack:wm,nightvision:Rl,"privacy-mask":Cm,doorbell:Nm},cS={camera:Tl,hub:zi,nvr:zi,light:Am,siren:Ys,switch:Kk,sensor:$m,thermostat:Qk,button:g2,generic:zl};function wh(e){return e.role?lS[e.role]??zl:cS[e.type.toLowerCase()]??Tl}const Nh={"native-snapshot":V2,"two-way-audio":Pm,"pan-tilt-zoom":wm,"ptz-autotrack":J2,"doorbell-button":Nm,"motion-trigger":yn,"battery-operated":ym,rebootable:Dm},kh={"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"},dS={"native-snapshot":"snapshot",rebootable:"reboot","pan-tilt-zoom":"ptz","ptz-autotrack":"ptz-autotrack","two-way-audio":"intercom","motion-trigger":"motion-trigger"},Sh=new Set(["camera","hub","nvr"]);function Ch(e){return!Sh.has(e.type.toLowerCase())}function eu(e){return e.role?!0:!Sh.has(e.type.toLowerCase())}function Mh(e){return(e.features??[]).includes("motion-trigger")}function uS(e){if(e.length<=24)return e;const t=e.lastIndexOf(":");if(t>=0&&t<e.length-4)return e.slice(t+1);const n=e.split("-");if(n.length>2){const o=n.slice(-2).join("-");if(o.length>=6)return o}return`…${e.slice(-18)}`}function pS({trpc:e,accessoryChildren:t,adoptedChildren:n,onNavigate:o}){return u("div",{className:"border-t border-border-subtle/50",children:[n.length>0&&r(tu,{trpc:e,label:"Adopted devices",rows:n,onNavigate:o}),t.length>0&&r(tu,{trpc:e,label:"Accessories",rows:t,onNavigate:o})]})}function tu({trpc:e,label:t,rows:n,onNavigate:o}){return u("div",{children:[r("div",{className:"px-3 pt-1.5 pb-1 text-[9px] font-semibold uppercase tracking-wide text-foreground-subtle",children:t}),r("ul",{children:n.map(s=>r(fS,{trpc:e,child:s,onNavigate:o},s.id))})]})}function fS({trpc:e,child:t,onNavigate:n}){const o=!t.disabled,s=o&&Ch(t),a=o&&Mh(t),i=wh(t);return r("li",{children:u("div",{onClick:l=>{l.stopPropagation(),n(t.id)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-surface-hover transition-colors cursor-pointer",children:[r(i,{className:"h-3 w-3 text-foreground-subtle flex-shrink-0"}),r("span",{className:"text-[10.5px] text-foreground flex-1 truncate",children:t.name}),a&&r(hS,{trpc:e,deviceId:t.id,features:t.features}),s&&r(mS,{trpc:e,deviceId:t.id}),r("span",{className:K("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 mS({trpc:e,deviceId:t}){const{dev:n,cap:o,slice:s,available:a}=Er({trpc:e,deviceId:t,cap:p=>p.switch,slice:p=>p.state.switch}),[i,l]=$(!1);if(n!==null&&!o)return null;const c=s?.on===!0,d={transform:c?"translateX(14px)":"translateX(2px)"},f=async p=>{if(p.stopPropagation(),!(i||!a||!o)){l(!0);try{await o.setState({on:!c})}finally{l(!1)}}};return r("button",{type:"button",onClick:p=>{f(p)},disabled:i||!a,className:K("relative inline-flex h-4 w-7 items-center rounded-full border transition-colors flex-shrink-0",c?"bg-success/30 border-success/50":"bg-surface-hover border-border",i&&"opacity-60",!a&&"opacity-40 cursor-not-allowed"),title:a?c?"Turn off":"Turn on":"Awaiting state…","aria-pressed":c,children:r("span",{className:K("absolute h-3 w-3 rounded-full transition-all",c?"bg-success":"bg-foreground-subtle"),style:d})})}function hS({trpc:e,deviceId:t,features:n}){const{dev:o,cap:s,slice:a,available:i}=Er({trpc:e,deviceId:t,cap:p=>p.motionTrigger,slice:p=>p.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:n}),[l,c]=$(!1);if(o!==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 r("button",{type:"button",onClick:p=>{f(p)},disabled:l||!i,className:K("inline-flex h-4 w-4 items-center justify-center rounded transition-colors flex-shrink-0",d?"text-primary bg-primary/10":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover",(l||!i)&&"opacity-50"),title:i?d?"Motion-trigger: on (click to disable)":"Motion-trigger: off (click to enable)":"Awaiting state…","aria-pressed":d,children:r(yn,{className:"h-2.5 w-2.5"})})}function Ih({trpc:e,device:t,flags:n}){if(!!t.disabled)return null;const s=t.type.toLowerCase(),a=n.showSwitchToggle&&Ch(t),i=Mh(t),l=s==="hub"||s==="nvr",c=(t.features??[]).includes("rebootable"),d=l&&c;return u(ve,{children:[i&&r(bS,{trpc:e,deviceId:t.id,features:t.features}),a&&r(gS,{trpc:e,deviceId:t.id}),d&&r(yS,{trpc:e,deviceId:t.id})]})}function gS({trpc:e,deviceId:t}){const{dev:n,cap:o,slice:s,available:a}=Er({trpc:e,deviceId:t,cap:p=>p.switch,slice:p=>p.state.switch}),[i,l]=$(!1);if(n!==null&&!o)return null;const c=s?.on===!0,d={transform:c?"translateX(14px)":"translateX(2px)"},f=async p=>{if(p.stopPropagation(),!(i||!a||!o)){l(!0);try{await o.setState({on:!c})}finally{l(!1)}}};return r("button",{type:"button",onClick:p=>{f(p)},disabled:i||!a,className:K("relative inline-flex h-4 w-7 items-center rounded-full border transition-colors flex-shrink-0",c?"bg-success/30 border-success/50":"bg-surface-hover border-border",i&&"opacity-60",!a&&"opacity-40 cursor-not-allowed"),title:a?c?"Turn off":"Turn on":"Awaiting state…","aria-pressed":c,children:r("span",{className:K("absolute h-3 w-3 rounded-full transition-all",c?"bg-success":"bg-foreground-subtle"),style:d})})}function bS({trpc:e,deviceId:t,features:n}){const{dev:o,cap:s,slice:a,available:i}=Er({trpc:e,deviceId:t,cap:p=>p.motionTrigger,slice:p=>p.state.motionTrigger,requireFeature:"motion-trigger",deviceFeatures:n}),[l,c]=$(!1);if(o!==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 r("button",{type:"button",onClick:p=>{f(p)},disabled:l||!i,className:K("inline-flex h-4 w-4 items-center justify-center rounded transition-colors flex-shrink-0",d?"text-primary bg-primary/10":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover",(l||!i)&&"opacity-50"),title:i?d?"Motion-trigger: on (click to disable)":"Motion-trigger: off (click to enable)":"Awaiting state…","aria-pressed":d,children:r(yn,{className:"h-2.5 w-2.5"})})}const ja=168,xS=4;function yS({trpc:e,deviceId:t}){const{dev:n,cap:o}=Er({trpc:e,deviceId:t,cap:x=>x.reboot,slice:()=>{}}),s=ne(null),a=ne(null),[i,l]=$(null),[c,d]=$(!1),f=n!==null&&o!==void 0&&o!==null,p=i!==null,m=()=>l(null),h=()=>{const x=s.current;if(!x)return;const v=x.getBoundingClientRect(),w=v.right-ja,y=Math.max(8,Math.min(w,window.innerWidth-ja-8)),N=v.bottom+xS;l({top:N,left:y})};if(Y(()=>{if(!p)return;const x=w=>{const y=s.current,N=a.current,k=w.target;k!==null&&(y&&y.contains(k)||N&&N.contains(k)||m())},v=w=>{w.key==="Escape"&&(w.stopPropagation(),m())};return document.addEventListener("mousedown",x),document.addEventListener("keydown",v),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",v)}},[p]),n!==null&&!o)return null;const g=x=>{x.stopPropagation(),p?m():h()},b=async()=>{if(!(c||!f||!o)){d(!0),m();try{await o.reboot({})}finally{d(!1)}}};return u(ve,{children:[r("button",{ref:s,type:"button",onClick:g,disabled:c||!f,className:K("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:r(km,{className:"h-3 w-3"})}),i&&vo(r("div",{ref:a,role:"menu",style:{position:"fixed",top:i.top,left:i.left,width:ja},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:K("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-[11px] text-foreground","hover:bg-surface-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed"),children:[r(Dm,{className:"h-3 w-3 shrink-0 text-foreground-subtle"}),r("span",{children:"Reboot device"})]})}),document.body)]})}const vS=Object.freeze([]);function wS(e){return e==="native"?"native":"enhanced"}function NS(e){return e.map(t=>({kind:"marker",feature:t}))}function kS(e,t){const n=new Map,o=t.entries??[];for(const a of o)n.set(a.capName,a);const s=[];for(const a of e){const i=dS[a];if(i===void 0){s.push({kind:"marker",feature:a});continue}const l=n.get(i);l&&s.push({kind:wS(l.kind),feature:a,capName:i})}return s}function SS(e,t,n){const[o,s]=$(null),[a,i]=$(!1),[l,c]=$(!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 m=await e.deviceManager.getBindings.query({deviceId:t});if(d)return;s(m),c(!1)}catch{if(d)return;i(!0),c(!1)}};f();const p=e.live?.onEvent.subscribe({category:"capability.binding-changed"},{onData:m=>{const h=m.data?.source;if(!h){f();return}h.type==="device"&&h.id===t&&f()}});return()=>{d=!0,p?.unsubscribe()}},[e,t]),n.length===0?{loading:l,resolved:vS}:l||a||!o?{loading:l,resolved:NS(n)}:{loading:!1,resolved:kS(n,o)}}const CS=[];function Ah({trpc:e,device:t,flags:n,accessoryCount:o,adoptedCount:s,showFeatureRow:a=!1}){const i=o+s,l=n.showChildrenAccordion&&i>0,c=t.features??CS,d=a&&c.length>0,{resolved:f}=SS(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&&r(MS,{accessoryCount:o,adoptedCount:s}),p&&r(IS,{resolved:f})]})}function MS({accessoryCount:e,adoptedCount:t}){const n=e+t;if(n===0)return null;const o=t>0&&e>0?`${String(t)} adopted · ${String(e)} accessor${e===1?"y":"ies"}`:t>0?`${String(t)} adopted`:`${String(e)} accessor${e===1?"y":"ies"}`;return u("span",{className:"text-[9px] font-medium text-foreground-subtle bg-surface-elevated/60 rounded px-1.5 py-0.5 flex-shrink-0",title:o,children:["+",n]})}const Ph=240,nu=200;function IS({resolved:e}){const t=ne(null),[n,o]=$(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>=nu?l.bottom+4:l.top-nu-4,p=Math.max(8,Math.min(l.left,window.innerWidth-Ph-8));o({top:f,left:p})},onMouseLeave:()=>o(null),children:[e.map(i=>{const l=Nh[i.feature];return l?r("span",{className:"inline-flex items-center justify-center h-4 w-4 rounded bg-surface-elevated/60 text-foreground-subtle",title:kh[i.feature]??i.feature,children:r(l,{className:"h-2.5 w-2.5"})},i.feature):null}),n&&vo(r(AS,{resolved:e,position:n}),document.body)]})}function AS({resolved:e,position:t}){return u("div",{style:{position:"fixed",top:t.top,left:t.left,width:Ph,pointerEvents:"none"},className:"z-[9999] rounded-md border border-border bg-surface shadow-lg shadow-black/30 p-2",children:[r("h5",{className:"text-[9px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5",children:"Features"}),r("ul",{className:"space-y-0.5",children:e.map(n=>r(PS,{entry:n},n.feature))})]})}function PS({entry:e}){const t=Nh[e.feature],n=kh[e.feature]??e.feature;return u("li",{className:"flex items-center justify-between gap-2 text-[10px]",children:[u("span",{className:"flex items-center gap-1.5 text-foreground",children:[t&&r(t,{className:"h-3 w-3 text-foreground-subtle"}),r("span",{children:n})]}),r(ES,{kind:e.kind})]})}function ES({kind:e}){return e==="marker"?r("span",{className:"text-[8.5px] px-1 rounded text-foreground-subtle",title:"Informational marker (no cap registered)",children:"marker"}):r("span",{className:K("text-[8.5px] px-1 rounded",e==="native"?"bg-success/15 text-success":"bg-primary/15 text-primary"),children:e})}function Eh({device:e,variant:t,flags:n,parent:o,integrationIcon:s,hasChildren:a,expanded:i,onToggleExpand:l,onNavigateToParent:c}){const d=wh(e);return u("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[n.showChildrenAccordion&&a?r("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?r(Yn,{className:"h-3 w-3"}):r(Cn,{className:"h-3 w-3"})}):n.showChildrenAccordion?r("span",{className:"h-3.5 w-3.5 flex-shrink-0"}):null,r(d,{className:K("text-foreground-subtle flex-shrink-0",t==="minimal"?"h-3 w-3":"h-3.5 w-3.5")}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-1.5 min-w-0",children:[n.showIntegrationIcon&&s&&r("span",{className:"flex-shrink-0",children:s}),r("span",{className:K("font-semibold text-foreground truncate",t==="minimal"?"text-[10.5px]":"text-[11px]"),title:e.name,children:e.name})]}),(n.showId||n.showStableId)&&u("div",{className:"mt-0.5 flex items-center gap-1 text-[9px] text-foreground-subtle font-mono truncate",title:n.showStableId?`stableId: ${e.stableId}`:void 0,children:[n.showId&&u("span",{className:"flex-shrink-0 tabular-nums",children:["#",String(e.id)]}),n.showId&&n.showStableId&&r("span",{className:"flex-shrink-0 opacity-50",children:"·"}),n.showStableId&&r("span",{className:"truncate",children:uS(e.stableId)})]}),n.showParentBadge&&o&&u("button",{type:"button",onClick:f=>{f.stopPropagation(),c(o.id)},className:"mt-0.5 inline-flex max-w-full items-center gap-1 text-[9px] text-foreground-subtle hover:text-primary transition-colors",title:`Open parent: ${o.name} (#${String(o.id)})`,children:[r(zi,{className:"h-2.5 w-2.5 shrink-0"}),u("span",{className:"truncate",children:["Under: ",o.name]})]})]})]})}function ec(e,t){return vh(e,t,o=>o.battery)??null}function tc(e,t){const n=kt(e,t),o=ne(!1),{data:s,isLoading:a,isFetching:i,refetch:l}=Kn({queryKey:["device",t,"snapshot"],queryFn:()=>{if(!n)throw new Error("useDeviceSnapshotImage: device proxy not ready");const f=o.current;return o.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(){o.current=!0,l()}return{src:c,loading:a||i,refresh:d}}function $S(e){return e<=10?WN:e<=30?KN:e>=95?QN:ym}function _S(e,t){return t!=="none"?"text-emerald-400":e<=10?"text-rose-400":e<=30?"text-amber-400":"text-foreground-subtle"}function nc({status:e,variant:t="compact",className:n}){if(!e)return null;const o=$S(e.percentage),s=_S(e.percentage,e.charging),a=e.charging==="solar"?Lm:e.charging==="dc"?fk:null,i=e.sleeping;return u("span",{className:K("inline-flex items-center gap-1 text-[10px] font-medium",s,n),title:`Battery: ${Math.round(e.percentage)}%`+(e.charging!=="none"?` · charging (${e.charging})`:"")+(e.sleeping?" · sleeping":""),children:[r(o,{className:"h-3.5 w-3.5"}),u("span",{children:[Math.round(e.percentage),"%"]}),a&&r(a,{className:"h-3 w-3"}),i&&r(Rl,{className:"h-3 w-3 text-blue-300"}),t==="full"&&e.charging!=="none"&&r("span",{className:"text-foreground-subtle",children:e.charging})]})}function $h({trpc:e,device:t,status:n,enabled:o,showStatusPills:s=!1}){const a=o&&t.online,i=tc(e,a?t.id:null),l=(t.features??[]).includes("battery-operated"),c=s&&l&&!t.disabled,d=ec(e,c?t.id:null);return!o&&!c?null:u("span",{className:"inline-flex items-center gap-1.5 flex-nowrap whitespace-nowrap",children:[c&&d&&r(nc,{status:d}),o&&r(DS,{deviceName:t.name,snapshotUrl:i.src,status:n})]})}const Ha=288,ru=196,Va=8;function DS({deviceName:e,snapshotUrl:t,status:n}){const o=ne(null),[s,a]=$(null),i=n==="offline"||n==="disabled",l=()=>{const d=o.current;if(!d)return;const f=d.getBoundingClientRect(),p=f.top,m=window.innerHeight-f.bottom,h=p<ru+Va&&m>p,g=h?f.bottom+Va:f.top-ru-Va,b=f.right-Ha,x=Math.max(8,Math.min(b,window.innerWidth-Ha-8));a({top:g,left:x,placeBelow:h})},c=()=>a(null);return u(ve,{children:[r("button",{ref:o,type:"button",onClick:d=>d.stopPropagation(),onMouseEnter:l,onMouseLeave:c,onFocus:l,onBlur:c,className:"flex h-6 w-6 items-center justify-center rounded text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors flex-shrink-0",title:"Preview","aria-label":"Preview snapshot",children:r(Xs,{className:"h-3.5 w-3.5"})}),s&&vo(u("div",{style:{position:"fixed",top:s.top,left:s.left,width:Ha,pointerEvents:"none"},className:"rounded-lg border border-border bg-surface shadow-lg shadow-black/30 z-[9999] overflow-hidden",children:[r("div",{className:"h-40 bg-background flex items-center justify-center",children:t&&!i?r("img",{src:t,alt:e,className:"h-full w-full object-cover"}):r("span",{className:"text-xs text-foreground-subtle",children:n==="offline"?"Offline — no snapshot":n==="disabled"?"Disabled":"No snapshot yet"})}),r("div",{className:"px-3 py-2",children:r("p",{className:"text-xs font-semibold text-foreground truncate",children:e})})]}),document.body)]})}function _h({status:e}){const t=e==="disabled"?"bg-warning":e==="online"?"bg-success":"bg-danger",n=e==="disabled"?"Disabled":e==="online"?"Online":"Offline";return r("span",{className:K("h-1.5 w-1.5 rounded-full flex-shrink-0",t),title:n})}function so(e){const{trpc:t,device:n,parent:o,integrationIcon:s,onNavigate:a,className:i}=e,l=iS(e),c=e.variant??"compact",d=e.view??"card",f=!n.disabled,p=n.isCamera??n.type.toLowerCase()==="camera",m=e.children??[],h=m.filter(eu),g=m.filter(M=>!eu(M)),b=m.length>0,[x,v]=$(!1),w=e.expanded??x,y=e.onToggleExpand??(()=>v(M=>!M)),N=M=>{a?.(M)},k=e.indentLevel??(e.isAccessoryRow?2:0),S=f?n.online?"online":"offline":"disabled";return d==="table"?r(TS,{trpc:t,device:n,variant:c,flags:l,parent:o??null,integrationIcon:s??null,accessoryCount:h.length,adoptedCount:g.length,hasChildren:b,expanded:w,onToggleExpand:y,onNavigate:N,displayStatus:S,isCamera:p,showSnapshot:l.showSnapshot&&p,isAccessoryRow:e.isAccessoryRow??!1,indentLevel:k,className:i}):u("div",{className:K("rounded-lg border border-border bg-surface transition-colors",!f&&"opacity-60",i),children:[u("div",{onClick:()=>N(n.id),className:K("flex items-center gap-2 cursor-pointer hover:border-foreground-subtle/30 w-full",c==="minimal"?"px-2.5 py-1.5":"px-3 py-2.5"),children:[r(Eh,{device:n,variant:c,flags:l,parent:o??null,integrationIcon:s??null,hasChildren:b,expanded:w,onToggleExpand:y,onNavigateToParent:N}),r(Ah,{trpc:t,device:n,flags:l,accessoryCount:h.length,adoptedCount:g.length,showFeatureRow:!1}),r($h,{trpc:t,device:n,status:S,enabled:l.showSnapshot&&p,showStatusPills:!0}),r(Ih,{trpc:t,device:n,flags:l}),r(_h,{status:S})]}),w&&b&&r(pS,{trpc:t,accessoryChildren:h,adoptedChildren:g,onNavigate:N})]})}const LS={0:"pl-2",1:"pl-6",2:"pl-8"};function TS(e){const{trpc:t,device:n,variant:o,flags:s,parent:a,integrationIcon:i,accessoryCount:l,adoptedCount:c,hasChildren:d,expanded:f,onToggleExpand:p,onNavigate:m,displayStatus:h,isCamera:g,showSnapshot:b,isAccessoryRow:x,indentLevel:v,className:w}=e;return u("tr",{onClick:()=>m(n.id),className:K("cursor-pointer hover:bg-surface-hover transition-colors",!s.showChildrenAccordion&&"border-b border-border-subtle/40",x&&"bg-foreground-subtle/[0.03]",w),children:[r("td",{className:K("py-2 align-middle pr-2",LS[v]),children:r(Eh,{device:n,variant:o,flags:s,parent:a,integrationIcon:i,hasChildren:d,expanded:f,onToggleExpand:p,onNavigateToParent:m})}),r("td",{className:"px-2 py-2 align-middle text-[10px] text-foreground-subtle whitespace-nowrap",children:n.type}),r("td",{className:"px-2 py-2 align-middle",children:r(Ah,{trpc:t,device:n,flags:s,accessoryCount:l,adoptedCount:c,showFeatureRow:!0})}),r("td",{className:"px-2 py-2 align-middle",children:r($h,{trpc:t,device:n,status:h,enabled:b&&g,showStatusPills:!0})}),r("td",{className:"px-2 py-2 align-middle text-right whitespace-nowrap",children:u("span",{className:"inline-flex items-center gap-1.5",children:[r(Ih,{trpc:t,device:n,flags:s}),r(_h,{status:h})]})})]})}function Dh(e,t){const[n,o]=$(e);return Y(()=>{const s=setTimeout(()=>o(e),t);return()=>clearTimeout(s)},[e,t]),n}const RS=new Set(["hub","nvr"]);function OS(e){const t=new Map;for(const s of e)t.set(s.id,s);const n=[],o=new Map;for(const s of e){const a=s.parentDeviceId;if(a==null){n.push(s);continue}const i=t.get(a);if(!i){n.push(s);continue}const l=s.role!==null&&s.role!==void 0;if(RS.has(i.type)&&!l){n.push(s);continue}const d=o.get(a);d?d.push(s):o.set(a,[s])}return{topLevel:n,accessoriesByParent:o}}const ou=2;function zS(e,t){if(t<=1)return[{kind:"page",n:1}];if(t<=7){const a=[];for(let i=1;i<=t;i++)a.push({kind:"page",n:i});return a}const n=[],o=Math.max(2,e-ou),s=Math.min(t-1,e+ou);n.push({kind:"page",n:1}),o>2&&n.push({kind:"ellipsis",side:"left"});for(let a=o;a<=s;a++)n.push({kind:"page",n:a});return s<t-1&&n.push({kind:"ellipsis",side:"right"}),n.push({kind:"page",n:t}),n}function BS({currentPage:e,totalItems:t,pageSize:n,onPageChange:o,itemNoun:s="devices"}){if(t<=n)return null;const a=Math.ceil(t/n),i=(e-1)*n+1,l=Math.min(e*n,t),c=zS(e,a);return u("div",{className:"flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle",children:[u("span",{children:["Showing ",i,"–",l," of ",t," ",s]}),u("span",{className:"inline-flex items-center gap-1",children:[r("button",{type:"button","aria-label":"Previous page",disabled:e===1,onClick:()=>o(e-1),className:K("inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle","hover:text-foreground hover:bg-surface-hover transition-colors","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface"),children:r(l2,{className:"h-3 w-3"})}),c.map((d,f)=>{if(d.kind==="ellipsis")return r("span",{className:"px-1 text-foreground-subtle/60 select-none",children:"…"},`e-${f}`);const p=d.n===e;return r("button",{type:"button",onClick:()=>o(d.n),className:K("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}`)}),r("button",{type:"button","aria-label":"Next page",disabled:e===a,onClick:()=>o(e+1),className:K("inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle","hover:text-foreground hover:bg-surface-hover transition-colors","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface"),children:r(Cn,{className:"h-3 w-3"})})]})]})}function FS({view:e,onViewChange:t,types:n,currentType:o,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:[r("button",{type:"button",onClick:()=>t("cards"),className:K("inline-flex items-center justify-center h-7 w-8 transition-colors",e==="cards"?"bg-primary/10 text-primary":"bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),"aria-label":"Cards view",children:r(W2,{className:"h-3.5 w-3.5"})}),r("button",{type:"button",onClick:()=>t("table"),className:K("inline-flex items-center justify-center h-7 w-8 border-l border-border transition-colors",e==="table"?"bg-primary/10 text-primary":"bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),"aria-label":"Table view",children:r(Hk,{className:"h-3.5 w-3.5"})})]}),n&&n.length>0&&u(ve,{children:[r(su,{children:"Type"}),r(qa,{active:o===null,onClick:()=>s(null),children:"All"}),n.map(d=>r(qa,{active:o===d,onClick:()=>s(o===d?null:d),children:jS(d)},d))]}),!c&&a&&a.length>0&&u(ve,{children:[r(su,{children:"Integration"}),a.map(d=>r(qa,{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 su({children:e}){return r("span",{className:"text-[10px] font-medium uppercase tracking-wider text-foreground-subtle ml-1",children:e})}function qa({active:e,icon:t,onClick:n,showClearIcon:o,children:s}){return u("button",{type:"button",onClick:n,className:K("inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border text-[10.5px] font-medium transition-colors",e?"border-primary/40 bg-primary/15 text-primary":"border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),children:[t&&r("span",{className:"inline-flex items-center",children:t}),r("span",{children:s}),e&&o&&r(Je,{className:"h-2.5 w-2.5 opacity-70"})]})}function jS(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function HS({variant:e,onClearFilters:t}){return u("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[r(Q2,{className:"h-8 w-8 text-foreground-subtle/40 mb-3"}),r("p",{className:"text-sm font-medium text-foreground-subtle",children:e==="filtered"?"No devices match the current filters":"No devices yet"}),e==="filtered"&&t&&r("button",{type:"button",onClick:t,className:"mt-2 text-[11px] text-primary hover:underline",children:"Clear filters"})]})}function 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 au(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 VS(e,t){try{localStorage.setItem(`camstack:${e}:lastFilters`,JSON.stringify(t))}catch{}}function iu(e,t,n){const o=new URLSearchParams(window.location.search),s=o.get(qt(e,"view")),a=s==="cards"||s==="table"?s:n.view??t,i=o.get(qt(e,"page")),l=i?parseInt(i,10):1,c=Number.isFinite(l)&&l>=1?l:1,d=o.get(qt(e,"addon"))??n.addon??null,f=o.get(qt(e,"type"))??n.type??null,p=o.get(qt(e,"q"))??n.q??"";return{view:a,page:c,addon:d,type:f,q:p}}function qS(e,t,n){const o=new URLSearchParams(window.location.search),s=(l,c)=>{c===null||c===""?o.delete(l):o.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=o.toString(),i=a?`${window.location.pathname}?${a}`:window.location.pathname;window.history.replaceState(null,"",i)}function QS(e){const{scope:t,defaultView:n,lsKey:o}=e,[s,a]=$(()=>{const g=au(o);return iu(t,n,g)}),i=ne(s);i.current=s,Y(()=>{const g=()=>{const b=au(o),x=iu(t,n,b);i.current=x,a(x)};return window.addEventListener("popstate",g),()=>window.removeEventListener("popstate",g)},[t,n,o]);const l=q(g=>{const b=g(i.current);i.current=b,a(b),qS(t,b,n),VS(o,{view:b.view,addon:b.addon,type:b.type,q:b.q})},[t,n,o]),c=q(g=>l(b=>({...b,view:g})),[l]),d=q(g=>l(b=>({...b,page:g})),[l]),f=q(g=>l(b=>({...b,addon:g,page:1})),[l]),p=q(g=>l(b=>({...b,type:g,page:1})),[l]),m=q(g=>l(b=>({...b,q:g,page:1})),[l]),h=q(()=>l(g=>({...g,addon:null,type:null,q:"",page:1})),[l]);return{state:s,setView:c,setPage:d,setAddon:f,setType:p,setQ:m,clearFilters:h}}const US={cards:24,table:50};function ao(e){const{devices:t,trpc:n,defaultView:o="table",filters:s,forceAddon:a,resolveIntegrationIcon:i,resolveParent:l,onNavigate:c,pageSize:d=US,urlScope:f="root",lsKey:p=f==="root"?"devices":"integrations:nested"}=e,m=QS({scope:f,defaultView:o,lsKey:p}),h=m.state.view,g=h==="cards"?d.cards:d.table,[b,x]=$(m.state.q),v=Dh(b,300);Y(()=>{v!==m.state.q&&m.setQ(v)},[v]);const w=a??m.state.addon,y=Q(()=>{const O=m.state.q.toLowerCase().trim();return t.filter(A=>!(w&&A.addonId!==w||m.state.type&&A.type!==m.state.type||O&&!A.name.toLowerCase().includes(O)&&!A.stableId.toLowerCase().includes(O)))},[t,w,m.state.type,m.state.q]),N=Q(()=>OS(y),[y]),k=Q(()=>{if(m.state.q.trim()==="")return new Set;const O=m.state.q.toLowerCase().trim(),A=new Set;for(const[D,_]of N.accessoriesByParent.entries())_.some(R=>R.name.toLowerCase().includes(O)||R.stableId.toLowerCase().includes(O))&&A.add(D);return A},[N.accessoriesByParent,m.state.q]),S=N.topLevel.length,M=Math.max(1,Math.ceil(S/g)),P=Math.min(m.state.page,M),I=(P-1)*g,F=N.topLevel.slice(I,I+g);Y(()=>{P!==m.state.page&&m.setPage(P)},[P]),XS();const E=w!=null||m.state.type!==null||m.state.q!=="",B=S===0;return u("div",{className:"flex flex-col gap-3",children:[u("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[r(FS,{view:h,onViewChange:m.setView,types:s?.types,currentType:m.state.type,onTypeChange:m.setType,addons:s?.addons,currentAddon:m.state.addon,onAddonChange:m.setAddon,hideAddons:a!==void 0}),u("div",{className:"relative",children:[r(oo,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle pointer-events-none"}),r("input",{type:"text",value:b,onChange:O=>x(O.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?r(HS,{variant:E?"filtered":"nofilter",onClearFilters:E?m.clearFilters:void 0}):h==="cards"?r(KS,{rows:F,accessoriesByParent:N.accessoriesByParent,trpc:n,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:c??null}):r(YS,{rows:F,accessoriesByParent:N.accessoriesByParent,autoExpandedParents:k,devices:y,trpc:n,resolveIntegrationIcon:i??null,resolveParent:l??null,onNavigate:c??null}),r(BS,{currentPage:P,totalItems:S,pageSize:g,onPageChange:m.setPage}),a===void 0&&E&&S>0&&u("p",{className:"text-[11px] text-foreground-subtle",children:["Showing ",S," of ",t.length," devices",w&&u(ve,{children:[" ","· filtered by"," ",r("strong",{className:"text-primary",children:s?.addons?.find(O=>O.id===w)?.name??w})]})]})]})}function KS({rows:e,accessoriesByParent:t,trpc:n,resolveIntegrationIcon:o,resolveParent:s,onNavigate:a}){return r("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:e.map(i=>{const l=t.get(i.id)??[];return r(so,{trpc:n,device:i,view:"card",integrationIcon:o?.(i.addonId)??null,parent:i.parentDeviceId!==null?s?.(i.parentDeviceId)??null:null,children:l,onNavigate:a??void 0},i.id)})})}const GS=new Set(["hub","nvr"]);function WS(e,t){return e.parentDeviceId===null||t===null?0:GS.has(t.toLowerCase())?1:0}function YS({rows:e,accessoriesByParent:t,autoExpandedParents:n,devices:o,trpc:s,resolveIntegrationIcon:a,resolveParent:i,onNavigate:l}){const c=Q(()=>{const d=new Map;for(const f of o)d.set(f.id,f.type);return d},[o]);return r("div",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:u("table",{className:"w-full border-collapse",children:[r("thead",{children:u("tr",{className:"border-b border-border",children:[r("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle",children:"Name"}),r("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-24",children:"Type"}),r("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Features"}),r("th",{className:"text-left px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-20",children:"Preview"}),r("th",{className:"text-right px-2 py-2 text-[9.5px] font-medium uppercase tracking-wider text-foreground-subtle w-32",children:"Actions"})]})}),r("tbody",{children:e.map(d=>{const f=t.get(d.id)??[],p=f.length>0,m=n.has(d.id),h=d.parentDeviceId!==null?i?.(d.parentDeviceId)??null:null,g=d.parentDeviceId!==null?c.get(d.parentDeviceId)??null:null;return r(ZS,{parent:d,accessories:f,hasAccessories:p,forceExpanded:m,trpc:s,integrationIcon:a?.(d.addonId)??null,parentRowParent:h,indentLevel:WS(d,g),onNavigate:l??null},d.id)})})]})})}function ZS({parent:e,accessories:t,hasAccessories:n,forceExpanded:o,trpc:s,integrationIcon:a,parentRowParent:i,indentLevel:l,onNavigate:c}){const[d,f]=$(o),p=ne(o);return Y(()=>{p.current!==o&&(f(o),p.current=o)},[o]),u(ve,{children:[r(so,{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=>r(so,{trpc:s,device:g,view:"table",integrationIcon:null,parent:null,isAccessoryRow:!0,showChildrenAccordion:!1,onNavigate:c??void 0},g.id))]})}function XS(){ke()}function JS({options:e,value:t,onChange:n}){return r("div",{className:"flex flex-wrap gap-2",children:e.map(o=>{const s=o.id===t;return u("button",{onClick:()=>o.available&&n(o.id),disabled:!o.available,className:`flex items-center gap-2 rounded-lg border px-3 py-2 text-xs font-medium transition-all ${s?"border-primary/40 bg-primary/10 text-primary":o.available?"border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground":"border-border/40 bg-surface/40 text-foreground-subtle/40 cursor-not-allowed"}`,children:[r(A2,{className:"h-3.5 w-3.5 shrink-0"}),o.label,o.isBest&&u("span",{className:"inline-flex items-center gap-0.5 rounded-full bg-amber-500/15 px-1.5 py-0.5 text-[10px] font-semibold text-amber-400",children:[r(Bk,{className:"h-2.5 w-2.5"}),"Best"]}),o.platformScore!=null&&u("span",{className:"text-[10px] text-foreground-subtle/60",children:["(",o.platformScore,")"]}),r("span",{className:`h-1.5 w-1.5 rounded-full ${o.available?"bg-success":"bg-danger"}`})]},o.id)})})}function eC(e,t){const n=new Set(t.slots.flatMap(i=>i.addons.map(l=>l.id))),o=[];function s(i){if(!n.has(i.addonId))return o.push(`Addon "${i.addonId}" is no longer available — step removed`),null;const l=t.slots.flatMap(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;o.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:o.length===0,steps:a,warnings:o}}function tC(e){const t=new Map;for(const n of e.slots)for(const o of n.addons)t.set(o.id,o);return t}function Qa(e){return{addonId:e.id,addonName:e.name,slot:e.slot,inputClasses:[...e.inputClasses],outputClasses:[...e.outputClasses],enabled:!0,modelId:e.defaultModelId,children:[]}}function Ua({addon:e,onClick:t}){return r("button",{type:"button",onClick:t,className:"w-full rounded-lg border border-dashed border-border/60 px-3 py-2.5 text-left transition-all hover:border-primary/30 hover:bg-surface/60 group",children:u("div",{className:"flex items-center gap-3",children:[r(v2,{className:"h-[18px] w-[18px] text-foreground-subtle/30 group-hover:text-primary/60 shrink-0"}),u("div",{className:"flex-1 min-w-0",children:[r("span",{className:"text-[13px] font-medium text-foreground-subtle/50 group-hover:text-foreground-subtle block truncate",children:e.name}),u("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.inputClasses.map(n=>r("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-blue-500/8 text-blue-400/50",children:n},n)),e.inputClasses.length>0&&e.outputClasses.length>0&&r("span",{className:"text-foreground-subtle/25 text-[10px]",children:"→"}),e.outputClasses.map(n=>r("span",{className:"text-[9px] uppercase font-semibold tracking-wide px-1.5 py-0.5 rounded bg-green-500/8 text-green-400/50",children:n},n))]})]})]})})}function rc({schema:e,steps:t,onChange:n,templates:o,selectedTemplateId:s,onSelectTemplate:a,onSaveTemplate:i,onUpdateTemplate:l,onDeleteTemplate:c,readOnly:d=!1,excludeAddons:f=[],hideTemplates:p=!1,showOnlyEnabled:m=!1,showSlotLabels:h=!1,toggleMode:g="simple",overrides:b={},onOverrideChange:x,inheritedEnabledByAddon:v={},hideModelAndSettings:w=!1}){const y=H=>({toggleMode:g,hideModelAndSettings:w,...g==="threeState"?{overrideState:b[H]!==void 0?b[H]:null,onOverrideChange:x?T=>x(H,T):void 0,inheritedEnabled:v[H]}:{}}),N=Q(()=>new Set(f),[f]),k=Q(()=>tC(e),[e]),[S,M]=$([]),P=s?JSON.stringify(t)!==JSON.stringify(o.find(H=>H.id===s)?.steps):!1;function I(H){const T=H.target.value||null;if(T){const W=o.find(G=>G.id===T);if(W){const G=eC(W.steps,e);M([...G.warnings])}}else M([]);a(T)}function F(){s&&l(s,t)}function E(){const H=window.prompt("Template name:");H?.trim()&&i(H.trim(),t)}function B(){if(!s)return;const H=o.find(T=>T.id===s);H&&window.confirm(`Delete template "${H.name}"?`)&&c(s)}function O(H){n(t.map(T=>T.addonId!==H.addonId?T:A(H)))}function A(H){const T=H.children.some(W=>W.enabled||W.children.some(G=>G.enabled));return{...H,enabled:H.enabled||T,children:H.children.map(W=>{const G=W.children.some(ee=>ee.enabled);return{...W,enabled:W.enabled||G}})}}function D(H,T){const W=Qa(T);n(t.map(G=>G.addonId!==H?G:{...G,children:[...G.children,W]}))}function _(H){const T=new Set;for(const W of H){T.add(W.addonId);for(const ee of W.children)T.add(ee.addonId);const G=_(W.children);for(const ee of G)T.add(ee)}return T}const R=_(t);function L(H){const T=k.get(H.addonId);if(!T)return[];const G=e.slots.find(X=>X.id===T.slot)?.parentSlot==null,ee=T.childSlots,se=new Set(H.children.map(X=>X.addonId)),te=[];for(const X of e.slots)if(ee.includes(X.id))for(const re of X.addons){if(se.has(re.id)||N.has(re.id))continue;const ge=re.inputClasses.length===0;if(ge&&!G)continue;(ge||re.inputClasses.some(U=>H.outputClasses.includes(U)))&&te.push(re)}return te}function z(H){const T=m?{...H,children:H.children.filter(G=>G.enabled).map(G=>({...G,children:G.children.filter(ee=>ee.enabled)}))}:H,W=m?[]:L(T);return u("div",{className:"space-y-1.5",children:[r(ps,{step:T,schema:k.get(T.addonId)??null,allSchemas:k,onChange:O,onDelete:d?void 0:G=>n(t.filter(ee=>ee.addonId!==G)),readOnly:d,...y(T.addonId)}),(T.children.length>0||W.length>0)&&u("div",{className:"ml-4 pl-3 border-l border-border/60 space-y-1.5",children:[h&&r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/40",children:"Slot: Cropper / Classifier"}),T.children.map(G=>{const ee=L(G);return u("div",{className:"space-y-1.5",children:[r(ps,{step:G,schema:k.get(G.addonId)??null,allSchemas:k,depth:1,onChange:se=>{O({...T,children:T.children.map(te=>te.addonId===se.addonId?se:te)})},onDelete:d?void 0:se=>{O({...T,children:T.children.filter(te=>te.addonId!==se)})},readOnly:d,...y(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:[h&&r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/30",children:"Slot: Recognizer"}),G.children.map(se=>r(ps,{step:se,schema:k.get(se.addonId)??null,allSchemas:k,depth:2,onChange:te=>{O({...T,children:T.children.map(X=>X.addonId===G.addonId?{...X,children:X.children.map(re=>re.addonId===te.addonId?te:re)}:X)})},onDelete:d?void 0:te=>{O({...T,children:T.children.map(X=>X.addonId===G.addonId?{...X,children:X.children.filter(re=>re.addonId!==te)}:X)})},readOnly:d,...y(se.addonId)},se.addonId)),!d&&ee.map(se=>r(Ua,{addon:se,onClick:()=>{const te=Qa(se);O({...T,children:T.children.map(X=>X.addonId===G.addonId?{...X,children:[...X.children,te]}:X)})}},se.id))]})]},G.addonId)}),!d&&W.map(G=>r(Ua,{addon:G,onClick:()=>D(T.addonId,G)},G.id))]})]},T.addonId)}const j=e.slots.filter(H=>H.parentSlot===null).sort((H,T)=>H.priority-T.priority);return u("div",{className:"space-y-4",children:[!p&&r("div",{className:"rounded-lg border border-border bg-surface p-3",children:u("div",{className:"flex items-center gap-2",children:[r("div",{className:"relative flex-1 min-w-0",children:u("select",{value:s??"",onChange: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:[r("option",{value:"",children:"No template"}),o.map(H=>r("option",{value:H.id,children:H.name},H.id))]})}),P&&r("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500 shrink-0"}),r("button",{onClick:F,disabled:!s||d,title:"Save",className:K("p-2 rounded-lg border border-border transition-colors",s&&!d?"text-foreground-subtle hover:bg-surface-hover":"text-foreground-subtle/30 cursor-not-allowed"),children:r(kk,{className:"h-4 w-4"})}),r("button",{onClick:E,disabled:d,title:"Save As",className:K("p-2 rounded-lg border border-border transition-colors",d?"text-foreground-subtle/30 cursor-not-allowed":"text-foreground-subtle hover:bg-surface-hover"),children:r(C2,{className:"h-4 w-4"})}),r("button",{onClick:B,disabled:!s||d,title:"Delete",className:K("p-2 rounded-lg border border-border transition-colors",s&&!d?"text-foreground-subtle hover:text-danger":"text-foreground-subtle/30 cursor-not-allowed"),children:r(rn,{className:"h-4 w-4"})})]})}),S.length>0&&u("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 text-xs text-amber-400 space-y-1",children:[u("div",{className:"flex items-center justify-between",children:[r("span",{className:"font-medium",children:"Template loaded with warnings:"}),r("button",{onClick:()=>M([]),className:"text-amber-400/60 hover:text-amber-400",children:r(Je,{className:"h-3.5 w-3.5"})})]}),S.map((H,T)=>u("div",{children:["• ",H]},T))]}),j.map(H=>{const T=t.filter(te=>te.slot===H.id&&!N.has(te.addonId)),W=m?T.filter(te=>te.enabled):T,G=m?[]:H.addons.filter(te=>!R.has(te.id)&&!N.has(te.id)),ee=new Map,se=[];for(const te of W)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:[h&&u("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50",children:["Slot: ",H.label]}),se.map(te=>z(te)),[...ee.entries()].map(([te,X])=>u("div",{className:"space-y-2 rounded-lg border border-border/40 p-2",children:[r("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/50 px-1",children:te}),X.map(re=>z(re))]},te)),!d&&G.map(te=>r(Ua,{addon:te,onClick:()=>{n([...t,Qa(te)])}},te.id))]},H.id)})]})}const Qr={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"},lu=["#ef4444","#8b5cf6","#06b6d4","#f97316","#10b981","#6366f1","#e11d48","#0891b2","#7c3aed","#059669"],Lh="#f59e42";function ct(e,t){if(t?.[e])return t[e];if(t?.[e.toLowerCase()])return t[e.toLowerCase()];if(Qr[e])return Qr[e];if(Qr[e.toLowerCase()])return Qr[e.toLowerCase()];let n=0;for(let o=0;o<e.length;o++)n=n*31+(e.codePointAt(o)??0)>>>0;return lu[n%lu.length]??Lh}function nC({src:e,imageWidth:t,imageHeight:n,detections:o=[],classColors:s,aspectRatio:a,className:i,placeholder:l,showConfidence:c=!0,minConfidence:d=0,borderWidth:f=2}){function p(v){return ct(v,s)}const m=a??(t&&n?`${t}/${n}`:"16/9"),h=o.filter(v=>v.score>=d),g=h.filter(v=>v.kind==="first-level"),b=h.filter(v=>v.kind==="detail"),x=sC(b,v=>v.parentId??"");return r("div",{className:K("rounded-lg border border-border bg-surface overflow-hidden relative",i),style:{aspectRatio:m},children:e?u(ve,{children:[r("img",{src:e,className:"absolute inset-0 w-full h-full object-fill",alt:""}),h.map((v,w)=>v.debug?.mask&&v.debug.maskWidth&&v.debug.maskHeight?r(rC,{mask:v.debug.mask,maskWidth:v.debug.maskWidth,maskHeight:v.debug.maskHeight,bbox:v.bbox,imageWidth:t,imageHeight:n,color:p(v.macroClass)},`mask-${w}`):null),g.map(v=>{const w=x.get(v.id)??[];return r(cu,{detection:v,imageWidth:t,imageHeight:n,color:p(v.macroClass),showConfidence:c,borderWidth:v.debug?.mask?1:f,children:w.map(y=>r(oC,{child:y,parentBbox:v.bbox,color:p(y.macroClass),showConfidence:c},`child-${y.id}`))},`det-${v.id}`)}),b.filter(v=>!v.parentId||!g.some(w=>w.id===v.parentId)).map(v=>r(cu,{detection:v,imageWidth:t,imageHeight:n,color:p(v.macroClass),showConfidence:c,borderWidth:f},`orphan-${v.id}`))]}):r("div",{className:"w-full h-full flex items-center justify-center text-foreground-subtle text-sm",children:l??"No image loaded"})})}function cu({detection:e,imageWidth:t,imageHeight:n,color:o,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:o},children:[e.macroClass,s&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((m,h)=>u("span",{className:"text-[9px] font-semibold px-1 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:ct(m.label)},children:[m.label," ",(m.score*100).toFixed(0),"%"]},`${e.id}-lbl-${h}`))]});return u("div",{className:"absolute rounded-sm",style:{left:`${l/t*100}%`,top:`${c/n*100}%`,width:`${d/t*100}%`,height:`${f/n*100}%`,borderWidth:`${a}px`,borderStyle:"solid",borderColor:o},children:[p,i]})}function rC({mask:e,maskWidth:t,maskHeight:n,bbox:o,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 v=0;v<f.length;v++)p[v]=f.charCodeAt(v);const m=parseInt(i.slice(1,3),16),h=parseInt(i.slice(3,5),16),g=parseInt(i.slice(5,7),16);c.width=t,c.height=n;const b=d.createImageData(t,n),x=t*n;for(let v=0;v<x;v++){const w=v<p.length?p[v]:0,y=v*4;w>0&&(b.data[y]=m,b.data[y+1]=h,b.data[y+2]=g,b.data[y+3]=120)}d.putImageData(b,0,0)},[e,t,n,i]),r("canvas",{ref:l,className:"absolute pointer-events-none",style:{left:`${o.x/s*100}%`,top:`${o.y/a*100}%`,width:`${o.width/s*100}%`,height:`${o.height/a*100}%`,imageRendering:"pixelated"}})}function oC({child:e,parentBbox:t,color:n,showConfidence:o}){if(t.width<=0||t.height<=0)return null;const s=(e.bbox.x-t.x)/t.width*100,a=(e.bbox.y-t.y)/t.height*100,i=e.bbox.width/t.width*100,l=e.bbox.height/t.height*100;return r("div",{className:"absolute rounded-sm",style:{left:`${Math.max(0,s)}%`,top:`${Math.max(0,a)}%`,width:`${Math.min(100,i)}%`,height:`${Math.min(100,l)}%`,borderWidth:"1px",borderStyle:"solid",borderColor:n},children:u("div",{className:"absolute left-0 flex flex-col items-start gap-px",style:{bottom:"100%",marginBottom:"1px"},children:[u("span",{className:"text-[9px] px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:n},children:[e.macroClass,o&&` ${(e.score*100).toFixed(0)}%`]}),e.labels.map((c,d)=>u("span",{className:"text-[8px] font-semibold px-0.5 rounded-sm whitespace-nowrap text-white",style:{backgroundColor:ct(c.label)},children:[c.label," ",(c.score*100).toFixed(0),"%"]},`${e.id}-lbl-${d}`))]})})}function sC(e,t){const n=new Map;for(const o of e){const s=t(o),a=n.get(s)??[];a.push(o),n.set(s,a)}return n}function aC({detections:e,classColors:t,className:n,hiddenKeys:o,onToggleVisibility:s}){const a=t;if(e.length===0)return r("div",{className:"text-sm text-foreground-subtle italic text-center py-4",children:"No detections"});const i=e.filter(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=>r(du,{detection:f,children_:c.get(f.id)??[],colors:a,hiddenKeys:o,onToggleVisibility:s},f.id)),d.map(f=>r(du,{detection:f,children_:[],colors:a,hiddenKeys:o,onToggleVisibility:s},f.id))]})]})}function du({detection:e,children_:t,colors:n,hiddenKeys:o,onToggleVisibility:s}){const a=ct(e.macroClass,n),i=!o?.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&&r("input",{type:"checkbox",checked:i,onChange:()=>s(e.id,!i),className:"h-3.5 w-3.5 rounded border-border accent-primary cursor-pointer shrink-0"}),r("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{backgroundColor:a}}),r("span",{className:"text-sm font-medium text-foreground",children:e.macroClass}),e.kind==="detail"&&r("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:"detail"}),l&&c&&d&&u("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",c,"x",d]})]}),r(cC,{confidence:e.score})]}),u("div",{className:"text-[10px] text-foreground-subtle font-mono",children:["bbox: [",Math.round(e.bbox.x),", ",Math.round(e.bbox.y),","," ",Math.round(e.bbox.x+e.bbox.width),","," ",Math.round(e.bbox.y+e.bbox.height),"]"]}),e.labels.length>0&&r("div",{className:"flex flex-wrap gap-1 mt-1",children:e.labels.map((p,m)=>u("span",{className:"inline-flex items-center gap-1 text-[10px] font-medium px-1.5 py-0.5 rounded-full",style:{backgroundColor:ct(p.label,n)+"20",color:ct(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]})]},m))}),f&&Object.keys(f).length>0&&r(lC,{alternateLabels:f,colors:n}),t.length>0&&r(iC,{items:t,colors:n,hiddenKeys:o,onToggleVisibility:s})]})}function iC({items:e,colors:t,hiddenKeys:n,onToggleVisibility:o}){return r("div",{className:"ml-4 mt-1.5 space-y-1.5 border-l-2 border-border pl-3",children:e.map(s=>{const a=ct(s.macroClass,t),i=!n?.has(s.id),l=s.debug?.mask,c=s.debug?.maskWidth,d=s.debug?.maskHeight;return u("div",{className:`text-xs space-y-0.5 ${i?"":"opacity-40"}`,children:[u("div",{className:"flex items-center gap-1.5",children:[o&&r("input",{type:"checkbox",checked:i,onChange:()=>o(s.id,!i),className:"h-3 w-3 rounded border-border accent-primary cursor-pointer shrink-0"}),r("span",{className:"h-1.5 w-1.5 rounded-full shrink-0",style:{backgroundColor:a}}),r("span",{className:"font-medium",style:{color:a},children:s.macroClass}),u("span",{className:"text-foreground-subtle",children:[(s.score*100).toFixed(0),"%"]}),l&&c&&d&&u("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded bg-primary/10 text-primary",children:["mask ",c,"x",d]})]}),s.labels.length>0&&r("div",{className:"flex flex-wrap gap-1 ml-5 mt-0.5",children:s.labels.map((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:ct(f.label,t)+"20",color:ct(f.label,t)},children:[f.label," ",u("span",{className:"opacity-60",children:[(f.score*100).toFixed(0),"%"]})]},p))})]},s.id)})})}function lC({alternateLabels:e,colors:t}){const[n,o]=$(!1),s=Object.keys(e);return u("div",{className:"mt-1",children:[u("button",{onClick:()=>o(a=>!a),className:"text-[9px] text-foreground-subtle hover:text-foreground transition-colors flex items-center gap-1",children:[r("span",{className:`transition-transform ${n?"rotate-90":""}`,children:"▶"}),"Alternates (",s.length," source",s.length!==1?"s":"",")"]}),n&&r("div",{className:"mt-1 ml-3 space-y-1.5",children:s.map(a=>{const i=e[a];return!i||i.length===0?null:u("div",{children:[r("div",{className:"text-[9px] font-medium text-foreground-subtle mb-0.5",children:a}),r("div",{className:"flex flex-wrap gap-1",children:i.map((l,c)=>u("span",{className:"inline-flex items-center gap-0.5 text-[9px] px-1 py-0.5 rounded-full",style:{backgroundColor:ct(a,t)+"10",color:ct(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 cC({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 dC({timings:e,totalMs:t,className:n}){const o=Object.entries(e);return o.length===0&&t===void 0?null:u("div",{className:`rounded-lg border border-border bg-surface p-3 space-y-2 ${n??""}`,children:[r("div",{className:"text-xs font-medium text-foreground-subtle uppercase tracking-wide",children:"Timings"}),u("div",{className:"space-y-1 text-xs",children:[o.map(([s,a])=>u("div",{className:"flex justify-between",children:[r("span",{className:"text-foreground-subtle",children:s}),u("span",{className:"font-mono text-foreground",children:[a.toFixed(1),"ms"]})]},s)),t!==void 0&&u("div",{className:"flex justify-between pt-1 border-t border-border font-medium text-foreground",children:[r("span",{children:"Total"}),u("span",{className:"font-mono",children:[t.toFixed(1),"ms"]})]})]})]})}function uC({images:e,selectedFilename:t,uploadedName:n,onSelect:o,onUpload:s,className:a,accept:i="image/*",uploadLabel:l="Upload..."}){const c=()=>{const d=document.createElement("input");d.type="file",d.accept=i,d.onchange=()=>{const f=d.files?.[0];if(!f)return;const p=new FileReader;p.onload=()=>{const m=p.result,h=m.split(",")[1];h&&s(h,f.name,m)},p.readAsDataURL(f)},d.click()};return u("div",{className:`flex flex-wrap items-center gap-2 ${a??""}`,children:[e.map(d=>r("button",{onClick:()=>o(d.filename),className:`px-3 py-1.5 text-xs rounded-md border transition-colors ${t===d.filename?"bg-primary text-primary-foreground border-primary":"bg-surface border-border text-foreground hover:border-primary/50"}`,children:d.id??d.filename.replace(/\.[^.]+$/,"")},d.filename)),r("button",{onClick:c,className:"px-3 py-1.5 text-xs rounded-md border border-border bg-surface text-foreground hover:bg-surface-hover transition-colors",children:l}),n&&r("span",{className:"text-xs text-foreground-subtle",children:n})]})}const zo="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 pC({runtime:e,backend:t,modelId:n,agentId:o="hub",runtimes:s,backends:a,models:i,agents:l=[],onRuntimeChange:c,onBackendChange:d,onModelChange:f,onAgentChange:p,layout:m="grid",className:h,showAgent:g=!1}){return u("div",{className:`${m==="grid"?"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4":m==="horizontal"?"flex flex-wrap items-end gap-4":"space-y-3"} ${h??""}`,children:[g&&l.length>0&&u("label",{className:"space-y-1",children:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Agent"}),r("select",{value:o,onChange:x=>p?.(x.target.value),className:zo,children:l.map(x=>u("option",{value:x.id,children:[x.name," (",x.status,")"]},x.id))})]}),u("label",{className:"space-y-1",children:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Runtime"}),r("select",{value:e,onChange:x=>c(x.target.value),className:zo,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:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Backend"}),r("select",{value:t,onChange:x=>d(x.target.value),className:zo,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:[r("span",{className:"text-xs font-medium text-foreground-subtle",children:"Model"}),r("select",{value:n,onChange:x=>f(x.target.value),className:zo,children:i.length===0?r("option",{value:"",children:"No compatible models"}):i.map(x=>u("option",{value:x.id,children:[x.name,x.downloaded?" ✓":""]},x.id))})]})]})}function fC({className:e}){return u("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[r("path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}),r("circle",{cx:"12",cy:"12",r:"3"})]})}function mC({className:e}){return u("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[r("path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"}),r("path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}),r("path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"}),r("path",{d:"m2 2 20 20"})]})}function hC({className:e}){return r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:r("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function Th({onLogin:e,serverUrl:t,logoSrc:n,error:o,className:s}){const[a,i]=$(""),[l,c]=$(""),[d,f]=$(!1),[p,m]=$(!1),[h,g]=$(null),b=o??h,x=async v=>{if(v.preventDefault(),!p){g(null),m(!0);try{await e(a,l)}catch(w){const y=w instanceof Error?w.message:"Login failed. Please try again.";g(y)}finally{m(!1)}}};return r("div",{className:K("flex min-h-screen items-center justify-center bg-background p-4",s),children:u("div",{className:"w-full max-w-sm",children:[n&&r("div",{className:"flex justify-center mb-8",children:r("img",{src:n,alt:"Logo",className:"h-12"})}),t&&r("p",{className:"mb-4 text-center text-xs text-foreground-subtle truncate",children:t}),u("form",{onSubmit:x,className:"space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10",children:[b&&r("div",{className:"rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger",children:b}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"Username"}),r("input",{type:"text",value:a,onChange:v=>i(v.target.value),autoComplete:"username",required:!0,className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary"})]}),u("div",{className:"space-y-1.5",children:[r("label",{className:"text-xs font-medium text-foreground-subtle",children:"Password"}),u("div",{className:"relative",children:[r("input",{type:d?"text":"password",value:l,onChange:v=>c(v.target.value),autoComplete:"current-password",required:!0,className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary"}),r("button",{type:"button",onClick:()=>f(v=>!v),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",tabIndex:-1,children:d?r(mC,{className:"h-4 w-4"}):r(fC,{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&&r(hC,{className:"h-4 w-4 animate-spin"}),p?"Logging in...":"Log in"]})]})]})})}const qi="camstack_dev_token",Rh=Oe(null);function gC(){const e=ye(Rh);if(!e)throw new Error("useDevShell must be used within a DevShell");return e}function bC(){return typeof window>"u"?null:localStorage.getItem(qi)}function xC({className:e}){return u("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:[r("circle",{cx:"12",cy:"12",r:"4"}),r("path",{d:"M12 2v2"}),r("path",{d:"M12 20v2"}),r("path",{d:"m4.93 4.93 1.41 1.41"}),r("path",{d:"m17.66 17.66 1.41 1.41"}),r("path",{d:"M2 12h2"}),r("path",{d:"M20 12h2"}),r("path",{d:"m6.34 17.66-1.41 1.41"}),r("path",{d:"m19.07 4.93-1.41 1.41"})]})}function yC({className:e}){return r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e,children:r("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})})}function vC({children:e,serverUrl:t,title:n,token:o,onLogout:s}){const a=Ir(),i=Q(()=>{const m=t.replace(/^http/,"ws")+"/trpc",h=X1({url:m,connectionParams:()=>({token:o})});return[J1({condition:g=>g.type==="subscription",true:ew({client:h,transformer:_i}),false:jf({url:`${t}/trpc`,transformer:_i,headers:()=>({authorization:`Bearer ${o}`})})})]},[t,o]),l=Q(()=>Ff({links:i}),[i]),c=Q(()=>C.createClient({links:i}),[i]),d=Q(()=>Vf({serverUrl:t,token:o}),[t,o]);Y(()=>(d.init().catch(()=>{}),()=>{d.close()}),[d]);const f=Q(()=>new Of,[]),p=Q(()=>({trpc:l,token:o,logout:s}),[l,o,s]);return r(Xl,{system:d,children:r(C.Provider,{client:c,queryClient:f,children:r(zf,{client:f,children:r(Rh.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:[r("span",{className:"rounded bg-warning/20 px-2 py-0.5 text-xs font-bold text-warning",children:"DEV MODE"}),n&&r("span",{className:"text-sm font-medium text-foreground",children:n}),r("span",{className:"text-xs text-foreground-subtle",children:t})]}),u("div",{className:"flex items-center gap-2",children:[u("button",{type:"button",onClick:a.toggleMode,className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",title:`Theme: ${a.mode}`,children:[a.resolvedMode==="dark"?r(xC,{className:"h-3.5 w-3.5"}):r(yC,{className:"h-3.5 w-3.5"}),a.mode==="dark"?"Dark":a.mode==="light"?"Light":"System"]}),r("button",{type:"button",onClick:s,className:"rounded-md px-2.5 py-1 text-xs font-medium text-danger hover:bg-danger/10 transition-colors",children:"Logout"})]})]}),r("div",{className:"p-4",children:e({trpc:l,theme:a})})]})})})})})}function Oh({children:e,serverUrl:t="https://localhost:4443",title:n}){const[o,s]=$(bC),a=q(async(l,c)=>{const p=await Ff({links:[jf({url:`${t}/trpc`,transformer:_i})]}).auth.login.mutate({username:l,password:c});if(!p.token)throw new Error("No token returned");localStorage.setItem(qi,p.token),s(p.token)},[t]),i=q(()=>{localStorage.removeItem(qi),s(null)},[]);return o?r(ws,{children:r(vC,{serverUrl:t,title:n,token:o,onLogout:i,children:e})}):r(ws,{children:r(Th,{onLogin:a,serverUrl:t})})}function wC(e,t={}){const{serverUrl:n="https://localhost:4443",title:o,rootId:s="root"}=t,a=document.getElementById(s);if(!a){console.error(`[mountAddonPage] Element #${s} not found`);return}Tf(a).render(Me(Oh,{serverUrl:n,title:o,children:({trpc:i,theme:l})=>Me(e,{trpc:i,theme:{isDark:l.resolvedMode==="dark"},navigate:c=>{console.log("[dev] navigate:",c)}})}))}const zh=un("camstack:custom-field-renderers",{});function Bh({renderers:e,children:t}){return r(zh.Provider,{value:e,children:t})}function Fh(e){return ye(zh)[e]??null}const oc=un("camstack:device-context",null);function jh({deviceId:e,device:t,children:n}){const o={deviceId:e,device:t??null};return r(oc.Provider,{value:o,children:n})}function pn(){return ye(oc)?.deviceId??null}function sc(){return ye(oc)?.device??null}const NC=C.accessories.getStatus.useQuery,ac=C.addonPages.listPages.useQuery,ra=C.addons.list.useQuery,kC=C.addons.getLogs.useQuery,SC=C.addons.listPackages.useQuery,ic=C.addons.installPackage.useMutation,CC=C.addons.installFromWorkspace.useMutation,MC=C.addons.isWorkspaceAvailable.useQuery,IC=C.addons.listWorkspacePackages.useQuery,Hh=C.addons.uninstallPackage.useMutation,Vh=C.addons.reloadPackages.useMutation,qh=C.addons.searchAvailable.useQuery,lc=C.addons.listUpdates.useQuery,Qi=C.addons.updatePackage.useMutation,AC=C.addons.rollbackPackage.useMutation,Qh=C.addons.forceRefresh.useMutation,Uh=C.addons.restartServer.useMutation,Kh=C.addons.getVersions.useQuery,oa=C.addons.restartAddon.useMutation,Gh=C.addons.retryLoad.useMutation,Wh=C.addons.getAutoUpdateSettings.useQuery,PC=C.addons.setAutoUpdateSettings.useMutation,Yh=C.addons.getAddonAutoUpdate.useQuery,Zh=C.addons.setAddonAutoUpdate.useMutation,Xh=C.addons.applyAutoUpdateToAll.useMutation,EC=C.addons.custom.useMutation,$C=C.addons.onAddonLogs.useSubscription,cc=C.addonSettings.getGlobalSettings.useQuery,Jh=C.addonSettings.updateGlobalSettings.useMutation,_C=C.addonSettings.getDeviceSettings.useQuery,eg=C.addonSettings.updateDeviceSettings.useMutation,tg=C.addonWidgets.listWidgets.useQuery,DC=C.alerts.emit.useMutation,LC=C.alerts.update.useMutation,ng=C.alerts.list.useQuery,rg=C.alerts.getUnreadCount.useQuery,og=C.alerts.markRead.useMutation,sg=C.alerts.markAllRead.useMutation,ag=C.alerts.dismiss.useMutation,TC=C.audioAnalysis.resolveDeviceSettings.useQuery,RC=C.audioAnalysis.getDeviceSettingsContribution.useQuery,OC=C.audioAnalysis.getDeviceLiveContribution.useQuery,zC=C.audioAnalysis.applyDeviceSettingsPatch.useMutation,BC=C.audioAnalyzer.analyseChunk.useMutation,FC=C.audioAnalyzer.classify.useQuery,jC=C.audioAnalyzer.isReady.useQuery,HC=C.audioAnalyzer.dispose.useMutation,ig=C.audioAnalyzer.reprobeAudioEngine.useMutation,VC=C.audioCodec.listSupportedCodecs.useQuery,qC=C.audioCodec.canHandle.useQuery,QC=C.audioCodec.createDecodeSession.useMutation,UC=C.audioCodec.createEncodeSession.useMutation,KC=C.audioCodec.closeSession.useMutation,GC=C.audioCodec.pushEncodedFrame.useMutation,WC=C.audioCodec.pullPcm.useQuery,YC=C.audioCodec.pushPcm.useMutation,ZC=C.audioCodec.pullEncoded.useQuery,XC=C.audioCodec.flushEncode.useMutation,JC=C.audioCodec.listActiveSessions.useQuery,e3=C.audioMetrics.getCurrentSnapshot.useQuery,t3=C.audioMetrics.getHistory.useQuery,dc=C.authentication.listProviders.useQuery,n3=C.authentication.setProviderEnabled.useMutation,uc=C.backup.listDestinations.useQuery,lg=C.backup.trigger.useMutation,r3=C.backup.list.useQuery,cg=C.backup.listLocations.useQuery,dg=C.backup.getEntries.useQuery,ug=C.backup.restore.useMutation,pg=C.backup.delete.useMutation,pc=C.backup.listArchives.useQuery,fg=C.backup.upsertDestinationPolicy.useMutation,mg=C.backup.previewSchedule.useQuery,o3=C.battery.getStatus.useQuery,s3=C.brightness.setBrightness.useMutation,a3=C.brightness.getStatus.useQuery,i3=C.cameraStreams.getCameraStreams.useQuery,l3=C.cameraStreams.getBrokerStreams.useQuery,c3=C.cameraStreams.getRtspEntries.useQuery,d3=C.decoder.supportsCodec.useQuery,u3=C.decoder.getInfo.useQuery,p3=C.decoder.createSession.useQuery,f3=C.decoder.destroySession.useQuery,m3=C.decoder.pushPacket.useQuery,h3=C.decoder.openStream.useQuery,g3=C.decoder.pullFrames.useQuery,b3=C.decoder.updateConfig.useQuery,x3=C.decoder.getStats.useQuery,y3=C.decoder.listActiveSessions.useQuery,hg=C.decoder.reprobeHwaccel.useMutation,v3=C.detectionPipeline.getDeviceSettingsContribution.useQuery,w3=C.detectionPipeline.getDeviceLiveContribution.useQuery,N3=C.detectionPipeline.applyDeviceSettingsPatch.useMutation,gg=C.deviceDiscovery.listDiscovered.useQuery,bg=C.deviceDiscovery.refreshDiscovery.useMutation,k3=C.deviceDiscovery.adoptDevice.useMutation,S3=C.deviceDiscovery.releaseDevice.useMutation,C3=C.deviceDiscovery.getStatus.useQuery,M3=C.deviceManager.allocateDeviceId.useMutation,I3=C.deviceManager.registerDevice.useMutation,A3=C.deviceManager.removeDevice.useMutation,P3=C.deviceManager.persistConfig.useMutation,E3=C.deviceManager.loadConfig.useQuery,$3=C.deviceManager.loadRuntimeState.useQuery,_3=C.deviceManager.loadMeta.useQuery,xg=C.deviceManager.setName.useMutation,yg=C.deviceManager.setLocation.useMutation,D3=C.deviceManager.setMetadata.useMutation,vg=C.deviceManager.listLocations.useQuery,L3=C.deviceManager.addLocation.useMutation,T3=C.deviceManager.removeLocation.useMutation,R3=C.deviceManager.setDisabled.useMutation,O3=C.deviceManager.listPersistedByAddon.useQuery,Jn=C.deviceManager.listAll.useQuery,Fn=C.deviceManager.getDevice.useQuery,wg=C.deviceManager.getChildren.useQuery,z3=C.deviceManager.getStreamSources.useQuery,B3=C.deviceManager.getConfigSchema.useQuery,F3=C.deviceManager.getSettingsSchema.useQuery,j3=C.deviceManager.updateConfig.useMutation,Ng=C.deviceManager.enable.useMutation,kg=C.deviceManager.disable.useMutation,Sg=C.deviceManager.remove.useMutation,H3=C.deviceManager.getStreamProfileMap.useQuery,V3=C.deviceManager.setStreamProfileMap.useMutation,q3=C.deviceManager.probeStreams.useMutation,Cg=C.deviceManager.getBindings.useQuery,Q3=C.deviceManager.getAllBindings.useQuery,Mg=C.deviceManager.setWrapperActive.useMutation,U3=C.deviceManager.listWrappersForCap.useQuery,Ig=C.deviceManager.listBindableCapsForDeviceType.useQuery,K3=C.deviceManager.getDeviceSettingsAggregate.useQuery,G3=C.deviceManager.getDeviceLiveInfoAggregate.useQuery,fc=C.deviceManager.getDeviceAggregate.useQuery,W3=C.deviceManager.updateDeviceField.useMutation,Ag=C.deviceManager.updateDeviceFieldsBatch.useMutation,mc=C.deviceManager.discoverDevices.useMutation,Pg=C.deviceManager.adoptDevice.useMutation,Eg=C.deviceManager.getCreationSchema.useQuery,$g=C.deviceManager.createDevice.useMutation,hc=C.deviceManager.testCreationField.useMutation,Y3=C.deviceManager.testField.useMutation,Z3=C.deviceManager.getDeviceStatusAggregate.useQuery,X3=C.deviceOps.getStreamSources.useQuery,J3=C.deviceOps.getConfigEntries.useQuery,eM=C.deviceOps.setConfig.useMutation,tM=C.deviceOps.removeDevice.useMutation,nM=C.deviceOps.getSettingsSchema.useQuery,rM=C.deviceProvider.start.useMutation,oM=C.deviceProvider.stop.useMutation,sM=C.deviceProvider.getStatus.useQuery,aM=C.deviceProvider.getDevices.useQuery,iM=C.deviceProvider.supportsDiscovery.useQuery,lM=C.deviceProvider.discoverDevices.useMutation,cM=C.deviceProvider.adoptDiscoveredDevice.useMutation,dM=C.deviceProvider.supportsManualCreation.useQuery,uM=C.deviceProvider.getChildCreationSchema.useQuery,pM=C.deviceProvider.createDevice.useMutation,fM=C.deviceProvider.testCreationField.useMutation,mM=C.deviceState.getSnapshot.useQuery,hM=C.deviceState.getCapSlice.useQuery,gM=C.deviceState.getAllSnapshots.useQuery,bM=C.deviceState.setCapSlice.useMutation,xM=C.doorbell.getStatus.useQuery,yM=C.events.getEvents.useQuery,vM=C.events.getEventThumbnail.useQuery,wM=C.events.getEventClipUrl.useQuery,sa=C.integrations.list.useQuery,_g=C.integrations.get.useQuery,Dg=C.integrations.getByAddonId.useQuery,Lg=C.integrations.create.useMutation,Tg=C.integrations.update.useMutation,Rg=C.integrations.delete.useMutation,NM=C.integrations.getSettings.useQuery,kM=C.integrations.setSettings.useMutation,Og=C.integrations.getAvailableTypes.useQuery,zg=C.integrations.testConnection.useMutation,Bg=C.intercom.startSession.useMutation,Fg=C.intercom.handleAnswer.useMutation,jg=C.intercom.stopSession.useMutation,SM=C.intercom.getStatus.useQuery,Hg=C.localNetwork.list.useQuery,CM=C.localNetwork.getPreferred.useQuery,Vg=C.localNetwork.getConnectionEndpoints.useQuery,qg=C.localNetwork.getAllowedAddresses.useQuery,Qg=C.localNetwork.setAllowedAddresses.useMutation,Ug=C.localNetwork.resetAllowlistToBestMatch.useMutation,Kg=C.meshOrchestrator.listProviders.useQuery,Gg=C.meshOrchestrator.joinProvider.useMutation,Wg=C.meshOrchestrator.leaveProvider.useMutation,MM=C.metricsProvider.collectSnapshot.useQuery,IM=C.metricsProvider.getCached.useQuery,AM=C.metricsProvider.getCurrent.useQuery,PM=C.metricsProvider.getDiskSpace.useQuery,EM=C.metricsProvider.getGpuInfo.useQuery,$M=C.metricsProvider.getCpuTemperature.useQuery,_M=C.metricsProvider.getProcessStats.useQuery,DM=C.metricsProvider.listAddonInstances.useQuery,LM=C.metricsProvider.getAddonStats.useQuery,Yg=C.metricsProvider.listNodeProcesses.useQuery,Zg=C.metricsProvider.killProcess.useMutation,TM=C.motion.isDetected.useQuery,RM=C.motion.getStatus.useQuery,OM=C.motionDetection.analyze.useMutation,zM=C.motionDetection.removeCamera.useMutation,BM=C.motionDetection.reset.useMutation,FM=C.motionDetection.getDeviceSettingsContribution.useQuery,jM=C.motionDetection.getDeviceLiveContribution.useQuery,HM=C.motionDetection.applyDeviceSettingsPatch.useMutation,VM=C.motionTrigger.setMotionTrigger.useMutation,qM=C.motionTrigger.getStatus.useQuery,QM=C.nativeObjectDetection.getStatus.useQuery,gc=C.networkQuality.getDeviceStats.useQuery,UM=C.networkQuality.getAllStats.useQuery,KM=C.networkQuality.reportClientStats.useMutation,In=C.nodes.topology.useQuery,GM=C.nodes.deployAddon.useMutation,Xg=C.nodes.undeployAddon.useMutation,aa=C.nodes.restartAddon.useMutation,Jg=C.nodes.restartProcess.useMutation,eb=C.nodes.restartNode.useMutation,WM=C.nodes.shutdownNode.useMutation,tb=C.nodes.renameNode.useMutation,nb=C.nodes.clusterAddonStatus.useQuery,rb=C.nodes.setProcessLogLevel.useMutation,YM=C.nodes.executeQuery.useMutation,ZM=C.notificationOutput.send.useMutation,XM=C.notificationOutput.sendTest.useMutation,JM=C.osd.setOverlay.useMutation,e4=C.osd.getStatus.useQuery,t4=C.pipelineAnalytics.getActiveTracks.useQuery,n4=C.pipelineAnalytics.getTrack.useQuery,r4=C.pipelineAnalytics.listTracks.useQuery,o4=C.pipelineAnalytics.clearTracks.useMutation,s4=C.pipelineAnalytics.getMotionEvents.useQuery,a4=C.pipelineAnalytics.getObjectEvents.useQuery,i4=C.pipelineAnalytics.getAudioEvents.useQuery,l4=C.pipelineAnalytics.getEventMedia.useQuery,c4=C.pipelineAnalytics.getTrackMedia.useQuery,d4=C.pipelineAnalytics.getDeviceSettingsContribution.useQuery,u4=C.pipelineAnalytics.getDeviceLiveContribution.useQuery,p4=C.pipelineAnalytics.applyDeviceSettingsPatch.useMutation,ob=C.pipelineExecutor.getAvailableEngines.useQuery,sb=C.pipelineExecutor.getSelectedEngine.useQuery,f4=C.pipelineExecutor.getDefaultSteps.useQuery,ab=C.pipelineExecutor.reprobeEngine.useMutation,m4=C.pipelineExecutor.getVideoPipelineSteps.useQuery,h4=C.pipelineExecutor.setVideoPipelineSteps.useMutation,So=C.pipelineExecutor.getSchema.useQuery,g4=C.pipelineExecutor.getGlobalSteps.useQuery,b4=C.pipelineExecutor.getGlobalPipelineConfig.useQuery,x4=C.pipelineExecutor.getOrchestratorConfigSchema.useQuery,y4=C.pipelineExecutor.listTemplates.useQuery,v4=C.pipelineExecutor.saveTemplate.useMutation,w4=C.pipelineExecutor.updateTemplate.useMutation,N4=C.pipelineExecutor.deleteTemplate.useMutation,k4=C.pipelineExecutor.getCapabilities.useQuery,S4=C.pipelineExecutor.getAddonModels.useQuery,ib=C.pipelineExecutor.downloadModel.useMutation,lb=C.pipelineExecutor.deleteModel.useMutation,C4=C.pipelineExecutor.detect.useQuery,M4=C.pipelineExecutor.runPipeline.useMutation,I4=C.pipelineExecutor.runPipelineBatch.useMutation,A4=C.pipelineExecutor.cacheFrameInPool.useMutation,P4=C.pipelineExecutor.inferCached.useMutation,E4=C.pipelineExecutor.uncacheFrame.useMutation,$4=C.pipelineExecutor.getEffectiveTuning.useQuery,cb=C.pipelineExecutor.listLoadedEngines.useQuery,_4=C.pipelineExecutor.spinEngine.useMutation,db=C.pipelineExecutor.killEngine.useMutation,D4=C.pipelineExecutor.listReferenceImages.useQuery,L4=C.pipelineExecutor.getReferenceImage.useQuery,T4=C.pipelineExecutor.getReferenceAudioFiles.useQuery,R4=C.pipelineExecutor.getReferenceAudio.useQuery,O4=C.pipelineExecutor.getAudioCapabilities.useQuery,z4=C.pipelineExecutor.runAudioTest.useMutation,B4=C.pipelineExecutor.getDetectionConfigSchema.useQuery,ub=C.pipelineOrchestrator.assignPipeline.useMutation,pb=C.pipelineOrchestrator.unassignPipeline.useMutation,fb=C.pipelineOrchestrator.rebalance.useMutation,ia=C.pipelineOrchestrator.getPipelineAssignments.useQuery,la=C.pipelineOrchestrator.getPipelineAssignment.useQuery,mb=C.pipelineOrchestrator.getAgentLoad.useQuery,F4=C.pipelineOrchestrator.getGlobalMetrics.useQuery,j4=C.pipelineOrchestrator.getCameraMetrics.useQuery,hb=C.pipelineOrchestrator.getCapabilityBindings.useQuery,gb=C.pipelineOrchestrator.setCapabilityBinding.useMutation,bb=C.pipelineOrchestrator.assignDecoder.useMutation,xb=C.pipelineOrchestrator.unassignDecoder.useMutation,yb=C.pipelineOrchestrator.getDecoderAssignments.useQuery,vb=C.pipelineOrchestrator.assignAudio.useMutation,wb=C.pipelineOrchestrator.unassignAudio.useMutation,H4=C.pipelineOrchestrator.getAudioAssignment.useQuery,Nb=C.pipelineOrchestrator.getAudioNodeLoad.useQuery,kb=C.pipelineOrchestrator.getAudioAssignments.useQuery,V4=C.pipelineOrchestrator.getDecoderAssignment.useQuery,bc=C.pipelineOrchestrator.getAgentSettings.useQuery,$r=C.pipelineOrchestrator.listAgentSettings.useQuery,xc=C.pipelineOrchestrator.setAgentAddonDefaults.useMutation,Sb=C.pipelineOrchestrator.removeAgentSettings.useMutation,yc=C.pipelineOrchestrator.getCameraSettings.useQuery,Cb=C.pipelineOrchestrator.setCameraStepToggle.useMutation,q4=C.pipelineOrchestrator.getCameraStepOverrides.useQuery,Mb=C.pipelineOrchestrator.setCameraStepOverride.useMutation,Ib=C.pipelineOrchestrator.setCameraPipelineForAgent.useMutation,Ab=C.pipelineOrchestrator.resolvePipeline.useQuery,Pb=C.pipelineOrchestrator.listTemplates.useQuery,Q4=C.pipelineOrchestrator.saveTemplate.useMutation,Eb=C.pipelineOrchestrator.updateTemplate.useMutation,$b=C.pipelineOrchestrator.deleteTemplate.useMutation,U4=C.pipelineOrchestrator.getDeviceSettingsContribution.useQuery,K4=C.pipelineOrchestrator.getDeviceLiveContribution.useQuery,G4=C.pipelineOrchestrator.applyDeviceSettingsPatch.useMutation,W4=C.pipelineRunner.attachCamera.useMutation,Y4=C.pipelineRunner.detachCamera.useMutation,Z4=C.pipelineRunner.reportMotion.useMutation,X4=C.pipelineRunner.getLocalLoad.useQuery,J4=C.pipelineRunner.getLocalMetrics.useQuery,vc=C.pipelineRunner.getCameraMetrics.useQuery,eI=C.pipelineRunner.getAllCameraMetrics.useQuery,_b=C.pipelineRunner.getLocalCameras.useQuery,tI=C.platformProbe.getCapabilities.useQuery,nI=C.platformProbe.getHardware.useQuery,rI=C.platformProbe.resolveInferenceConfig.useQuery,oI=C.platformProbe.resolveHwAccel.useQuery,sI=C.ptz.move.useMutation,aI=C.ptz.continuousMove.useMutation,iI=C.ptz.stop.useMutation,lI=C.ptz.getPresets.useQuery,cI=C.ptz.goToPreset.useMutation,dI=C.ptz.goHome.useMutation,uI=C.ptz.getPosition.useQuery,pI=C.ptz.getStatus.useQuery,Db=C.ptzAutotrack.getStatus.useQuery,Lb=C.ptzAutotrack.setEnabled.useMutation,fI=C.ptzAutotrack.getSettings.useQuery,Tb=C.ptzAutotrack.setSettings.useMutation,Rb=C.reboot.reboot.useMutation,mI=C.recording.getSegments.useQuery,hI=C.recording.getPlaybackUrl.useQuery,gI=C.recording.getThumbnailAt.useQuery,bI=C.recordingEngine.getStatus.useQuery,Ob=C.recordingEngine.enable.useMutation,zb=C.recordingEngine.disable.useMutation,Bb=C.recordingEngine.getConfig.useQuery,xI=C.recordingEngine.updateConfig.useMutation,yI=C.recordingEngine.getPlaylist.useQuery,vI=C.recordingEngine.getThumbnail.useQuery,Fb=C.recordingEngine.getSegments.useQuery,wI=C.recordingEngine.getAvailability.useQuery,NI=C.recordingEngine.estimateStorage.useQuery,kI=C.recordingEngine.estimateGlobalStorage.useQuery,jb=C.recordingEngine.getStorageUsage.useQuery,SI=C.recordingEngine.setPolicy.useMutation,CI=C.recordingEngine.getPolicy.useQuery,Hb=C.recordingEngine.getPolicyStatus.useQuery,Vb=C.recordingEngine.getRetentionConfig.useQuery,MI=C.recordingEngine.updateRetentionConfig.useMutation,II=C.recordingEngine.getMotionStats.useQuery,qb=C.remoteAccess.listProviders.useQuery,Qb=C.remoteAccess.startProvider.useMutation,Ub=C.remoteAccess.stopProvider.useMutation,AI=C.settingsStore.get.useQuery,PI=C.settingsStore.set.useMutation,EI=C.settingsStore.query.useQuery,$I=C.settingsStore.insert.useMutation,_I=C.settingsStore.update.useMutation,DI=C.settingsStore.delete.useMutation,LI=C.settingsStore.count.useQuery,TI=C.settingsStore.isEmpty.useQuery,RI=C.settingsStore.declareCollection.useMutation,OI=C.snapshot.getSnapshot.useQuery,zI=C.snapshot.invalidateCache.useMutation,BI=C.snapshot.getStatus.useQuery,FI=C.snapshot.getDeviceSettingsContribution.useQuery,jI=C.snapshot.getDeviceLiveContribution.useQuery,HI=C.snapshot.applyDeviceSettingsPatch.useMutation,VI=C.snapshotProvider.supportsDevice.useQuery,qI=C.snapshotProvider.getSnapshot.useQuery,QI=C.storage.resolve.useQuery,UI=C.storage.write.useMutation,KI=C.storage.read.useQuery,GI=C.storage.exists.useQuery,WI=C.storage.list.useQuery,YI=C.storage.delete.useMutation,ZI=C.storage.getAvailableSpace.useQuery,XI=C.storage.beginUpload.useMutation,JI=C.storage.writeChunk.useMutation,eA=C.storage.finalizeUpload.useMutation,tA=C.storage.abortUpload.useMutation,nA=C.storage.beginDownload.useMutation,rA=C.storage.readChunk.useQuery,oA=C.storage.endDownload.useMutation,Kb=C.storage.listLocations.useQuery,sA=C.storage.getDefaultLocation.useQuery,ca=C.storage.upsertLocation.useMutation,Gb=C.storage.deleteLocation.useMutation,aA=C.storage.testLocation.useQuery,wc=C.storage.listProviders.useQuery,iA=C.storage.testConfig.useQuery,lA=C.streamBroker.publishCameraStream.useMutation,cA=C.streamBroker.retractCameraStream.useMutation,dA=C.streamBroker.assignProfile.useMutation,uA=C.streamBroker.unassignProfile.useMutation,pA=C.streamBroker.listAllCameraStreams.useQuery,fA=C.streamBroker.listAllProfileSlots.useQuery,mA=C.streamBroker.getBrokerStats.useQuery,hA=C.streamBroker.listClients.useQuery,gA=C.streamBroker.killClient.useMutation,bA=C.streamBroker.restartProfile.useMutation,xA=C.streamBroker.getStreamUrl.useQuery,yA=C.streamBroker.getBroker.useQuery,vA=C.streamBroker.setPreBufferDuration.useMutation,wA=C.streamBroker.getPreBufferInfo.useQuery,NA=C.streamBroker.getRtspPort.useQuery,kA=C.streamBroker.getAllRtspEntries.useQuery,SA=C.streamBroker.getRtspEntry.useQuery,Wb=C.streamBroker.regenerateRtspToken.useMutation,CA=C.streamBroker.setRtspEnabled.useMutation,MA=C.streamBroker.isRtspEnabled.useQuery,IA=C.streamBroker.getDeviceSettingsContribution.useQuery,AA=C.streamBroker.getDeviceLiveContribution.useQuery,PA=C.streamBroker.applyDeviceSettingsPatch.useMutation,EA=C.switch.setState.useMutation,$A=C.switch.getStatus.useQuery,_A=C.system.info.useQuery,DA=C.system.health.useQuery,LA=C.system.featureFlags.useQuery,TA=C.system.networkAddresses.useQuery,RA=C.system.getRetentionConfig.useQuery,OA=C.system.setRetentionConfig.useMutation,zA=C.system.forceRetentionCleanup.useMutation,Yb=C.toast.onToast.useSubscription,Zb=C.turnOrchestrator.listProviders.useQuery,Xb=C.turnOrchestrator.getAllServers.useQuery,BA=C.turnOrchestrator.setProviderEnabled.useMutation,FA=C.turnProvider.getTurnServers.useQuery,Nc=C.userManagement.listUsers.useQuery,Jb=C.userManagement.createUser.useMutation,ex=C.userManagement.updateUser.useMutation,tx=C.userManagement.deleteUser.useMutation,kc=C.userManagement.resetPassword.useMutation,jA=C.userManagement.validateCredentials.useMutation,nx=C.userManagement.listApiKeys.useQuery,HA=C.userManagement.createApiKey.useMutation,rx=C.userManagement.revokeApiKey.useMutation,VA=C.userManagement.validateApiKey.useMutation,ox=C.userManagement.createScopedToken.useMutation,sx=C.userManagement.revokeScopedToken.useMutation,qA=C.userManagement.validateScopedToken.useQuery,ax=C.userManagement.listScopedTokens.useQuery,QA=C.webrtcSession.listStreams.useQuery,UA=C.webrtcSession.createSession.useMutation,KA=C.webrtcSession.handleAnswer.useMutation,GA=C.webrtcSession.closeSession.useMutation,WA=C.webrtcSession.hasAdaptiveBitrate.useQuery,YA=C.zoneAnalytics.getCurrentSnapshot.useQuery,ZA=C.zoneAnalytics.getZoneHistory.useQuery,XA=C.zoneAnalytics.getCameraHistory.useQuery,JA=C.zoneAnalytics.getUnzonedHistory.useQuery,eP=C.zoneRules.listRules.useQuery,tP=C.zoneRules.setRules.useMutation,nP=C.zones.listZones.useQuery,rP=C.zones.addZone.useMutation,oP=C.zones.removeZone.useMutation,sP=C.zones.updateZone.useMutation,ix=un("camstack:widget-registry",null),Ms=new Map,Bo=new Map,uu=new Set;function aP(e){if(!e||typeof e!="object")return!1;const t=e.default;return t!==null&&typeof t=="object"}function iP(e){if(!e||typeof e!="object")return typeof e;const t=e,n=Object.getPrototypeOf(t),o=n&&typeof n=="object"?n.constructor?.name:void 0;return{ownKeys:Object.keys(t),allKeys:Object.getOwnPropertyNames(t),proto:typeof o=="string"?o:void 0}}async function lP(e,t){const n=Ms.get(e);if(n)return n;const o=Bo.get(e);if(o)return o;uu.has(e)||(Dl(),fr.registerRemotes([{name:e,entry:t,type:"module"}],{force:!1}),uu.add(e));const s=fr.loadRemote(`${e}/widgets`).then(a=>{if(!aP(a)){const l=iP(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 Ms.set(e,i),Bo.delete(e),i}).catch(a=>{throw Bo.delete(e),a});return Bo.set(e,s),s}const cP=3e4,dP=2e3;function lx({children:e}){const t=ke(),n=ne(Date.now()),{data:o}=tg(void 0,{staleTime:0,refetchOnMount:"always",refetchInterval:l=>{const c=l.state.data;return c&&c.length>0||Date.now()-n.current>=cP?!1:dP}});dt("addon.widget-ready",()=>{t.invalidateQueries({queryKey:[["addonWidgets","listWidgets"]]})});const[s,a]=$(0);Y(()=>{if(!o)return;let l=!1;const c=new Set;for(const d of o){if(c.has(d.remoteName)||(c.add(d.remoteName),Ms.has(d.remoteName)))continue;const f=d.bundleUrl;lP(d.remoteName,f).then(()=>{l||a(p=>p+1)}).catch(p=>{const m=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:m})})}return()=>{l=!0}},[o]);const i=Q(()=>{const l=o??[],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 m=Ms.get(p.remoteName);if(!m)return null;const h=m[p.stableId];if(h)return h},metadata:f=>{const p=c.get(f);if(p)return d(f,p)},listAll:()=>{const f=[];for(const[p,m]of c)f.push(d(p,m));return f}}},[o,s]);return r(ix.Provider,{value:i,children:e})}function cx(e){return da().resolve(e)}function dx(e){return da().metadata(e)}function ux(){return da().listAll()}function da(){const e=px();if(!e)throw new Error("useWidgetRegistry(): no <WidgetRegistryProvider> in tree");return e}function px(){return uP(ix)}function uP(e){return ye(e)}function it(e){const{widgetId:t,host:n="device-tab",config:o,deviceId:s,integrationId:a,instanceId:i,size:l,columns:c,rows:d}=e,f=cx(t),p=dx(t),m=Q(()=>i??t,[i,t]);if(f===void 0&&p===void 0)return r(Fo,{widgetId:t,reason:"unknown"});if(f===void 0)return r(Fo,{widgetId:t,reason:"missing-export"});if(f===null)return r(pP,{});if(p){if(p.requires.deviceContext&&s===void 0)return r(Fo,{widgetId:t,reason:"missing-device-context"});if(p.requires.integrationContext&&a===void 0)return r(Fo,{widgetId:t,reason:"missing-integration-context"})}return r(f,{instanceId:m,host:n,config:o,deviceId:s,integrationId:a,size:l,columns:c,rows:d})}function pP(){return u("div",{className:"rounded-lg border border-border bg-surface/40 p-4 animate-pulse",children:[r("div",{className:"h-3 w-24 bg-foreground-subtle/20 rounded mb-2"}),r("div",{className:"h-2 w-full bg-foreground-subtle/10 rounded mb-1"}),r("div",{className:"h-2 w-3/4 bg-foreground-subtle/10 rounded"})]})}function Fo({widgetId:e,reason:t}){const n=t==="unknown"?`Widget "${e}" not registered`:t==="missing-export"?`Widget "${e}" bundle does not export this stableId`:t==="missing-device-context"?`Widget "${e}" requires a deviceId`:`Widget "${e}" requires an integrationId`;return r("div",{className:"rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning",children:n})}const er="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",ua="block text-[11px] font-medium text-foreground mb-1",fP="text-[10px] text-foreground-subtle mt-0.5";function Qe({label:e,description:t,required:n,span:o,children:s,translationFn:a}){const i=o===2?"col-span-2":o===3?"col-span-3":o===4?"col-span-4":"col-span-1",l=Tt(e,a),c=Tt(t,a);return u("div",{className:i,children:[l!==void 0&&l!==""&&u("label",{className:ua,children:[l,n&&r("span",{className:"text-danger ml-0.5",children:"*"})]}),s,c&&r("p",{className:fP,children:c})]})}function mP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("input",{type:e.inputType??"text",className:er,value:t==null?"":String(t),placeholder:e.placeholder,maxLength:e.maxLength,pattern:e.pattern,disabled:o||e.disabled,onChange:a=>n(a.target.value)})})}function hP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const[a,i]=$(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 r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"flex items-center gap-1",children:[r("input",{type:"number",className:er,value:a,placeholder:e.placeholder,min:e.min,max:e.max,step:e.step,disabled:o||e.disabled,onFocus:()=>{l.current=!0},onBlur:()=>{l.current=!1},onChange:d=>c(d.target.value)}),e.unit&&r("span",{className:"text-xs text-foreground-subtle whitespace-nowrap",children:e.unit})]})})}function gP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=!!t,i=o||e.disabled;return e.style==="checkbox"?r(Qe,{label:void 0,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[r("input",{type:"checkbox",className:"h-3.5 w-3.5 rounded border-border accent-primary",checked:a,disabled:i,onChange:l=>n(l.target.checked)}),r("span",{className:"text-xs font-medium text-foreground",children:Tt(e.label,s)}),e.required&&r("span",{className:"text-danger",children:"*"})]})}):r(Qe,{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:ua+" mb-0",children:[Tt(e.label,s),e.required&&r("span",{className:"text-danger ml-0.5",children:"*"})]}),r("button",{type:"button",role:"switch","aria-checked":a,disabled:i,onClick:()=>!i&&n(!a),className:["relative inline-flex h-4 w-8 shrink-0 items-center rounded-full transition-colors duration-150",a?"bg-primary":"bg-foreground-subtle/30",i?"opacity-50 cursor-not-allowed":"cursor-pointer"].join(" "),children:r("span",{className:["inline-block h-3 w-3 rounded-full bg-white shadow transition-transform duration-150",a?"translate-x-4":"translate-x-0.5"].join(" ")})})]})})}function bP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=e.options.some(i=>i.value==="");return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("select",{className:er,value:t==null?"":String(t),disabled:o||e.disabled,onChange:i=>n(i.target.value),children:[!e.required&&!a&&r("option",{value:"",children:"— Select —"}),e.options.map(i=>r("option",{value:i.value,children:i.label},i.value))]})})}function xP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=Array.isArray(t)?t:[],i=l=>{if(a.includes(l))n(a.filter(c=>c!==l));else{if(e.maxItems!==void 0&&a.length>=e.maxItems)return;n([...a,l])}};return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("div",{className:"flex flex-wrap gap-2",children:e.options.map(l=>{const c=a.includes(l.value);return u("label",{className:["flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs cursor-pointer select-none transition-colors",c?"border-primary bg-primary/10 text-primary":"border-border bg-background text-foreground hover:bg-surface",o||e.disabled?"opacity-50 cursor-not-allowed":""].join(" "),children:[r("input",{type:"checkbox",className:"sr-only",checked:c,disabled:o||e.disabled,onChange:()=>i(l.value)}),l.label]},l.value)})})})}function yP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const[a,i]=$(!1),l=e.showToggle!==!1;return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"relative",children:[r("input",{type:a?"text":"password",className:er+(l?" pr-9":""),value:t==null?"":String(t),placeholder:e.placeholder,disabled:o||e.disabled,onChange:c=>n(c.target.value)}),l&&r("button",{type:"button",className:"absolute right-2 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",tabIndex:-1,onClick:()=>i(c=>!c),children:a?r(Cm,{className:"h-3.5 w-3.5"}):r(Xs,{className:"h-3.5 w-3.5"})})]})})}function vP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("textarea",{className:er+" resize-y min-h-[60px]",value:t==null?"":String(t),placeholder:e.placeholder,rows:e.rows??3,maxLength:e.maxLength,disabled:o||e.disabled,onChange:a=>n(a.target.value)})})}function wP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=t==null,i=e.nullable===!0,l=a?e.default??e.min:Number(t),c=e.showValue!==!1,d=e.nullLabel??"Auto",f=o||e.disabled,p=e.displayScale??1,m=e.min/p,h=e.max/p,g=l/p,b=(e.step??1)/p;if(i&&a)return r(Qe,{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,v=y=>{const N=l+y*(e.step??1),k=Math.min(e.max,Math.max(e.min,N));k!==l&&n(k)},w="flex h-6 w-6 shrink-0 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:cursor-not-allowed disabled:opacity-40";return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[u("div",{className:"flex min-w-0 flex-1 basis-[160px] items-center gap-2",children:[r("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:m}),r("input",{type:"range",className:"min-w-0 flex-1 h-1 accent-primary cursor-pointer disabled:opacity-50",min:m,max:h,step:b,value:g,disabled:f,onChange:y=>n(Number(y.target.value)*p)}),r("span",{className:"text-[10px] text-foreground-subtle tabular-nums shrink-0",children:h})]}),(c||i||e.unit)&&u("div",{className:"flex shrink-0 items-center gap-2",children:[x&&r("button",{type:"button",className:w,disabled:f||l<=e.min,onClick:()=>v(-1),title:`Decrease by ${e.step??1}`,"aria-label":"Decrement",children:r(Em,{className:"h-3 w-3"})}),c&&r("input",{type:"number",className:"w-16 rounded border border-border bg-surface px-1.5 py-0.5 text-xs text-center text-foreground tabular-nums focus:outline-none focus:ring-1 focus:ring-primary",min:m,max:h,step:b,value:g,disabled:f,onChange:y=>{if(y.target.value===""){n(i?null:e.min);return}const N=Number(y.target.value)*p,k=e.step??1,S=N-e.min,M=e.min+Math.round(S/k)*k;n(Math.min(e.max,Math.max(e.min,M)))}}),x&&r("button",{type:"button",className:w,disabled:f||l>=e.max,onClick:()=>v(1),title:`Increase by ${e.step??1}`,"aria-label":"Increment",children:r(Js,{className:"h-3 w-3"})}),e.unit&&r("span",{className:"text-[10px] text-foreground-subtle",children:e.unit}),i&&r("button",{className:"text-[10px] text-foreground-subtle hover:text-primary transition-colors",title:`Reset to ${d}`,disabled:f,onClick:()=>n(null),children:d})]})]})})}function NP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=Array.isArray(t)?t:[],[i,l]=$(""),c=ne(null),d=q(h=>{const g=h.trim();!g||a.includes(g)||e.maxTags!==void 0&&a.length>=e.maxTags||(n([...a,g]),l(""))},[a,e.maxTags,n]),f=h=>n(a.filter(g=>g!==h)),p=h=>{h.key==="Enter"||h.key===","?(h.preventDefault(),d(i)):h.key==="Backspace"&&i===""&&a.length>0&&f(a[a.length-1])},m=o||e.disabled;return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("div",{className:["flex flex-wrap gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 min-h-[38px] cursor-text","focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30",m?"opacity-50 cursor-not-allowed":""].join(" "),onClick:()=>!m&&c.current?.focus(),children:[a.map(h=>u("span",{className:"inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[h,!m&&r("button",{type:"button",onClick:()=>f(h),className:"hover:text-danger",children:r(Je,{className:"h-2.5 w-2.5"})})]},h)),r("input",{ref:c,type:"text",className:"flex-1 min-w-[80px] bg-transparent text-sm text-foreground outline-none placeholder:text-foreground-disabled",value:i,placeholder:a.length===0?e.placeholder??"Add tags…":"",disabled:m,list:`tags-suggestions-${e.key}`,onChange:h=>l(h.target.value),onKeyDown:p,onBlur:()=>{i.trim()&&d(i)}}),e.suggestions&&r("datalist",{id:`tags-suggestions-${e.key}`,children:e.suggestions.map(h=>r("option",{value:h},h))})]})})}function fx({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const{nodes:a}=Pr(),i=typeof t=="string"?t:"",l=e.showOffline?a:a.filter(c=>c.isOnline);return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:u("select",{className:"w-full px-3 py-2 text-sm bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-primary/50 disabled:opacity-50",value:i,onChange:c=>n(c.target.value),disabled:o,children:[r("option",{value:"",children:"Select node…"}),l.map(c=>u("option",{value:c.id,disabled:!c.isOnline,children:[c.shortName,c.isOnline?"":" (offline)"]},c.id))]})})}function mx({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const{nodes:a}=Pr(),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 r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:r("div",{className:"flex flex-wrap gap-1.5",children:l.map(d=>{const f=i.has(d.id);return r("button",{type:"button",onClick:()=>c(d.id),disabled:o||!d.isOnline,className:`px-2.5 py-1 text-xs font-medium rounded-md border transition-colors ${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 kP({field:e,value:t,onChange:n,disabled:o,translationFn:s}){const a=t==null?"#000000":String(t);return u(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,translationFn:s,children:[u("div",{className:"flex items-center gap-2",children:[r("input",{type:"color",className:"h-9 w-9 rounded-md border border-border bg-background cursor-pointer p-0.5 disabled:opacity-50",value:a,disabled:o||e.disabled,onChange:i=>n(i.target.value)}),r("input",{type:"text",className:er+" flex-1 font-mono",value:a,placeholder:"#000000",disabled:o||e.disabled,onChange:i=>n(i.target.value)})]}),e.presets&&e.presets.length>0&&r("div",{className:"flex gap-1.5 mt-1.5",children:e.presets.map(i=>r("button",{type:"button",className:"h-5 w-5 rounded-md border border-border hover:scale-110 transition-transform disabled:opacity-50",style:{backgroundColor:i},disabled:o||e.disabled,title:i,onClick:()=>n(i)},i))})]})}function SP({field:e,value:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i,externalProbe:l}){const[c,d]=$("idle"),[f,p]=$(null),m=l?.status??c,h=l?.result??f,g=!!a||!!i,b=q(async()=>{if(g){d("probing"),p(null);try{const w=a?await a(e.key,t):await i("test-probe",e.key,t),y=w&&typeof w=="object"?w:{status:"error",error:"Probe handler returned no result"};p(y),d(y.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=m==="probing"?"border-primary/40 bg-primary/10 text-primary":m==="ok"?"border-success/40 bg-success/10 text-success hover:bg-success/15":m==="error"?"border-danger/40 bg-danger/10 text-danger hover:bg-danger/15":"border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover",v=m==="probing"?r(Lt,{className:"h-3 w-3 animate-spin"}):m==="ok"?r(p2,{className:"h-3 w-3"}):m==="error"?r(Zs,{className:"h-3 w-3"}):r(Rm,{className:"h-3 w-3"});return u(Qe,{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||m==="probing"||!g||!t,className:`flex-shrink-0 inline-flex items-center gap-1.5 rounded-md border px-2 py-2 text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed @[280px]:px-3 ${x}`,children:[v,r("span",{className:"hidden @[280px]:inline",children:"Test"})]}),r("input",{type:e.inputType??"url",className:er+" flex-1 min-w-0",value:t==null?"":String(t),placeholder:e.placeholder,disabled:o||e.disabled,onChange:w=>{n(w.target.value),c!=="idle"&&(d("idle"),p(null))}})]}),m==="ok"&&h?.labels&&h.labels.length>0&&r("div",{className:"flex flex-wrap gap-1 mt-1.5",children:h.labels.map((w,y)=>r("span",{className:"text-xs bg-success/10 text-success rounded px-2 py-0.5 font-mono",children:w},y))}),m==="error"&&h?.error&&r("p",{className:"text-xs text-danger mt-1 truncate",title:h.error,children:h.error})]})}function CP({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a}){const[i,l]=$(e.defaultCollapsed??!1),c=e.style==="accordion",d=e.span===2?"col-span-2":e.span===3?"col-span-3":e.span===4?"col-span-4":"col-span-1";return r("div",{className:d,children: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:[r("span",{className:"text-xs font-semibold text-foreground",children:Tt(e.label,s)}),c&&r("span",{className:"text-foreground-subtle text-xs",children:i?"▸":"▾"})]}),!i&&r("div",{className:"px-3 pb-3 grid grid-cols-2 gap-x-4 gap-y-3",children:e.fields.map(f=>r(tr,{field:f,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a},f.key))})]})})}function MP({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i}){const l=e.tabs[0]?.id??"",[c,d]=$(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&&r("div",{className:ua,children:Tt(e.label,s)}),u("div",{className:"rounded-lg border border-border-subtle bg-surface-hover/40 overflow-hidden",children:[r("div",{className:"flex flex-wrap gap-1 p-1.5 border-b border-border-subtle bg-surface/40",role:"tablist",children:e.tabs.map(p=>{const m=p.id===c;return u("button",{type:"button",role:"tab","aria-selected":m,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 ${m?"bg-primary text-primary-foreground font-medium shadow-sm":"bg-transparent text-foreground-subtle hover:bg-surface hover:text-foreground"}`,children:[r("span",{children:Tt(p.label,s)}),p.badge&&r("span",{className:`text-[9px] px-1 py-0.5 rounded-full font-medium ${m?"bg-primary-foreground/20 text-primary-foreground":"bg-primary/10 text-primary"}`,children:p.badge})]},p.id)})}),e.tabs.map(p=>p.id!==c?null:r("div",{role:"tabpanel",className:"px-3 pb-3 pt-2 grid grid-cols-2 gap-x-4 gap-y-3",children:p.fields.map((m,h)=>{const g="key"in m&&typeof m.key=="string"?m.key:`__${p.id}__${h}`;return r(tr,{field:m,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i},g)})},p.id))]})]})}function IP({span:e}){return r("div",{className:e===2?"col-span-2":e===3?"col-span-3":e===4?"col-span-4":"col-span-full",children:r("hr",{className:"border-border"})})}const pu={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 AP(e){if(typeof window>"u"||typeof DOMParser>"u")return"";const t=new Set(["A","UL","OL","LI","STRONG","EM","CODE","BR","P","SPAN"]),n=new DOMParser().parseFromString(`<div>${e}</div>`,"text/html"),o=n.body.firstElementChild;if(!o)return"";const s=a=>{const i=Array.from(a.children);for(const l of i){if(!t.has(l.tagName)){const d=n.createTextNode(l.textContent??"");l.replaceWith(d);continue}const c=l.tagName==="A"?new Set(["href"]):new Set;for(const d of Array.from(l.attributes))c.has(d.name)||l.removeAttribute(d.name);if(l.tagName==="A"){const d=l.getAttribute("href")??"";!/^https?:\/\//i.test(d)&&!d.startsWith("mailto:")?l.removeAttribute("href"):(l.setAttribute("target","_blank"),l.setAttribute("rel","noopener noreferrer"))}s(l)}};return s(o),o.innerHTML}function PP({field:e}){const t=e.variant??"info",n=pu[t]??pu.info,o=e.format==="html";return r("div",{className:"col-span-full",children:u("div",{className:`rounded-md border-l-4 px-3 py-2.5 ${n.border} ${n.bg}`,children:[e.label&&r("p",{className:`text-xs font-semibold mb-0.5 ${n.text}`,children:e.label}),o?r("div",{className:"text-xs text-foreground-subtle leading-relaxed info-html-content",dangerouslySetInnerHTML:{__html:AP(e.content)}}):r("p",{className:"text-xs text-foreground-subtle leading-relaxed whitespace-pre-line",children:e.content})]})})}const fu={ok:"bg-success",warn:"bg-amber-500",danger:"bg-danger",idle:"bg-foreground-subtle/40",unknown:"bg-foreground-subtle/40"};function EP(e){if(!Number.isFinite(e)||e<0)return"—";if(e<1e3)return`${e}ms`;const t=Math.round(e/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60),o=t%60;return o===0?`${n}m`:`${n}m ${o}s`}function $P(e){return!Number.isFinite(e)||e<=0?"—":new Date(e).toLocaleTimeString()}function _P({kind:e,value:t}){if(t==null||t==="")return r("span",{className:"text-foreground-subtle/60",children:"—"});if(e==="monospace")return r("span",{className:"font-mono text-[11px]",children:String(t)});if(e==="status"){const n=String(t).toLowerCase(),o=fu[n]??fu.unknown;return u("span",{className:"inline-flex items-center gap-1.5",children:[r("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${o}`}),r("span",{children:String(t)})]})}return e==="duration"&&typeof t=="number"?r("span",{className:"font-mono text-[11px]",children:EP(t)}):e==="timestamp"&&typeof t=="number"?r("span",{className:"font-mono text-[11px]",children:$P(t)}):r("span",{children:String(t)})}function DP({field:e}){const t=e.value??[],n=e.description;return u("div",{className:"col-span-full",children:[e.label&&r("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1",children:e.label}),n&&r("p",{className:"text-xs text-foreground-subtle mb-2",children:n}),t.length===0?r("div",{className:"rounded-md border border-border bg-surface-subtle px-3 py-2 text-xs text-foreground-subtle",children:e.emptyMessage??"No entries"}):r("div",{className:"rounded-md border border-border overflow-hidden",children:u("table",{className:"w-full text-xs",children:[r("thead",{className:"bg-surface-subtle border-b border-border",children:r("tr",{children:e.columns.map(o=>r("th",{className:"px-3 py-1.5 text-left font-medium text-foreground-subtle",style:o.width?{width:o.width}:void 0,children:o.label},o.key))})}),r("tbody",{className:"divide-y divide-border",children:t.map((o,s)=>r("tr",{className:"hover:bg-surface-hover/40",children:e.columns.map(a=>r("td",{className:"px-3 py-1.5 align-top text-foreground",children:r(_P,{kind:a.kind,value:o[a.key]})},a.key))},s))})]})})]})}function LP({field:e,value:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:i}){const l=Array.isArray(t)?t:[],c=e.minRows??0,d=e.maxRows??Number.POSITIVE_INFINITY,f=(x,v,w)=>{const y=l.slice(),N=y[x]??{};y[x]={...N,[v]:w},n(y)},p=x=>{l.length<=c||n(l.filter((v,w)=>w!==x))},m=()=>{if(l.length>=d)return;const x=e.defaultItem??{};n([...l,{...x}])},h=(x,v)=>e.rowTitleTemplate?e.rowTitleTemplate.replace(/\{(\w+)\}/g,(w,y)=>{const N=x[y];return N==null||N===""?"—":String(N)}):`Row ${v+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&&r("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle",children:Tt(e.label,s)}),e.description&&r("p",{className:"text-[11px] text-foreground-subtle",children:Tt(e.description,s)})]}),l.length===0?r("div",{className:"rounded-md border border-dashed border-border bg-background px-3 py-3 text-center text-[11px] text-foreground-subtle",children:e.emptyMessage??"No entries"}):r("div",{className:"space-y-2",children:l.map((x,v)=>u("div",{className:"rounded-md border border-border bg-background",children:[u("div",{className:"flex items-center justify-between border-b border-border px-3 py-1.5",children:[r("span",{className:"text-xs font-medium text-foreground",children:h(x,v)}),u("button",{type:"button",onClick:()=>p(v),disabled:o||!g,className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-30 disabled:cursor-not-allowed",title:g?"Remove this row":`At least ${c} row(s) required`,children:[r(Em,{className:"h-3 w-3"}),"Remove"]})]}),r("div",{className:"grid grid-cols-1 @[420px]:grid-cols-2 gap-x-3 gap-y-2 p-3",children:e.itemFields.map(w=>r(tr,{field:w,values:x,onChange:(y,N)=>f(v,y,N),disabled:o,translationFn:s,onTestField:a,allFields:e.itemFields,onAction:i},w.key))})]},v))}),u("div",{children:[u("button",{type:"button",onClick:m,disabled:o||!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:[r(Js,{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 TP({field:e,disabled:t,onAction:n}){const[o,s]=$(!1),a=rt(),i=async()=>{if(!(e.confirmMessage&&!await a({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant==="danger"?"danger":"default"}))&&n){s(!0);try{await n(e.action,e.key)}finally{s(!1)}}},l={default:"border border-border text-foreground hover:bg-surface-hover",primary:"bg-primary text-primary-foreground hover:bg-primary/90",danger:"bg-danger text-white hover:bg-danger/90"};return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,children:r("button",{onClick:i,disabled:t||o,className:`inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${l[e.variant??"default"]??l.default}`,children:o?"Processing...":e.buttonLabel})})}function hx(e,t){const n={...e.paramsStatic??{}};if(e.paramsFromForm)for(const[o,s]of Object.entries(e.paramsFromForm)){const a=t[s];a!=null&&a!==""&&(n[o]=a)}return n}function RP({field:e,value:t,values:n,onChange:o,disabled:s,onAction:a}){const[i,l]=$(!1),[c,d]=$(null),[f,p]=$(null),m=hx(e,n),h=Object.keys(e.paramsFromForm??{}).some(w=>m[w]===void 0),g=(e.refreshOn??Object.values(e.paramsFromForm??{})).map(w=>`${w}=${JSON.stringify(n[w])}`).join("|");Y(()=>{if(!a||h){p(null),d(null);return}let w=!1;return l(!0),d(null),a(e.action,e.key,m).then(y=>{if(w)return;const N=y;let k=[];if(Array.isArray(N))k=N;else if(N&&typeof N=="object")for(const S of Object.keys(N)){const M=N[S];if(Array.isArray(M)){k=M;break}}p(k)}).catch(y=>{w||(d(y instanceof Error?y.message:String(y)),p([]))}).finally(()=>{w||l(!1)}),()=>{w=!0}},[g,a,e.action,e.key]);const b=e.mapOption.value,x=e.mapOption.label,v=e.mapOption.description;return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,children:h?r("div",{className:"text-[11px] text-foreground-subtle italic",children:e.emptyParamsMessage??"Fill the prerequisite fields above first."}):i?u("div",{className:"flex items-center gap-2 text-[11px] text-foreground-subtle",children:[r(Lt,{className:"h-3 w-3 animate-spin"})," Loading options…"]}):c?r("div",{className:"text-[11px] text-danger",children:c}):f&&f.length===0?r("div",{className:"text-[11px] text-foreground-subtle italic",children:e.emptyResultsMessage??"No options returned."}):(()=>{const w=(f??[]).some(y=>{const N=y[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:y=>o(y.target.value),children:[!w&&r("option",{value:"",children:"— Select —"}),(f??[]).map((y,N)=>{const k=y[b],S=y[x],M=v?y[v]:void 0,P=typeof k=="string"&&k!==""?k:`row-${N}`;return u("option",{value:typeof k=="string"?k:String(k??""),children:[typeof S=="string"?S:String(S??P),M!==void 0?` (${String(M)})`:""]},P)})]})})()})}function OP({field:e,values:t,disabled:n,onAction:o}){const[s,a]=$(!1),[i,l]=$(null),c=rt(),d=async()=>{if(e.confirmMessage&&!await c({title:e.label,message:e.confirmMessage,confirmLabel:e.buttonLabel,variant:e.variant==="danger"?"danger":"default"})||!o)return;const p=hx(e,t);a(!0),l(null);try{const m=await o(e.action,e.key,p),h=typeof m=="object"&&m!==null?m:null,g=e.successMessage?e.successMessage.replace(/\{(\w+)\}/g,(b,x)=>{const v=h?.[x];return v===void 0?"":String(v)}):"Done.";l({kind:"ok",text:g})}catch(m){l({kind:"error",text:m instanceof Error?m.message:String(m)})}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 r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,children:u("div",{className:"flex flex-col gap-1.5",children:[r("button",{onClick:d,disabled:n||s,className:`inline-flex w-fit items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:opacity-50 ${f[e.variant??"default"]??f.default}`,children:s?"Working…":e.buttonLabel}),i&&r("div",{className:`text-[11px] ${i.kind==="ok"?"text-emerald-700 dark:text-emerald-300":"text-danger"}`,children:i.text})]})})}function zP({field:e}){const t=pn();return r(Qe,{label:e.label,description:e.description,required:e.required,span:e.span,children:r(it,{widgetId:e.widgetId,host:"device-tab",config:e.widgetConfig,deviceId:t??void 0,instanceId:e.key})})}function BP(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 FP({field:e,values:t,onAction:n,translationFn:o}){const s="key"in e?e.key:void 0;if(!s)return null;const a=t[s],i=a!==void 0?a:"default"in e?e.default:void 0,l="unit"in e?e.unit:void 0,c=BP(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,m="actions"in e?e.actions??[]:[];return r(Qe,{label:d,description:f,span:p,translationFn:o,children:u("div",{className:"flex items-stretch gap-1",children:[r("div",{className:"flex-1 rounded-md border border-border bg-surface-alt px-2.5 py-1.5 text-xs text-foreground font-mono break-all",children:c}),m.length>0&&r("div",{className:"flex items-center gap-1",children:m.map(h=>r(HP,{action:h,fieldKey:s,value:i,onAction:n},h.action))})]})})}function jP({name:e}){const t="h-3.5 w-3.5";switch(e){case"copy":return r(Mn,{className:t});case"refresh-cw":return r(Ol,{className:t});case"external-link":return r(Sm,{className:t});case"trash-2":return r(rn,{className:t});case"download":return r(Oi,{className:t});case"upload":return r(Tm,{className:t});default:return r(zl,{className:t})}}function HP({action:e,fieldKey:t,value:n,onAction:o}){const s=rt(),[a,i]=$(!1),l=e.variant==="danger"?"text-danger hover:bg-danger/10 border-danger/30":e.variant==="primary"?"text-primary hover:bg-primary/10 border-primary/30":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover border-border";return r("button",{type:"button",onClick:async()=>{if(!(e.confirmMessage&&!await s({title:e.tooltip,message:e.confirmMessage,variant:e.variant==="danger"?"danger":"default"}))){if(e.action==="copy-value"){try{await navigator.clipboard.writeText(typeof n=="string"?n:String(n))}catch{}return}if(o){i(!0);try{await o(e.action,t)}finally{i(!1)}}}},disabled:a,title:e.tooltip,className:`inline-flex items-center justify-center rounded-md border px-2 py-1.5 transition-colors disabled:opacity-50 ${l}`,children:r(jP,{name:e.icon})})}function VP(e){return"multiple"in e&&e.multiple!=null}function qP({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c}){const d=e.multiple,f=d.min,p=d.max,m=t[e.key],g=[...Array.isArray(m)?m:m!=null?[m]:[]],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]),v=(k,S)=>{const M=[...g];M[k]=S,x(M)},w=()=>{g.length>=p||x([...g,b])},y=k=>{g.length<=f||x(g.filter((S,M)=>M!==k))},N=()=>{const{multiple:k,...S}=e;return{...S,...{label:void 0,description:void 0,required:!1}}};return r(Qe,{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,S)=>{const M=d.itemLabel?.replace("${n}",String(S+1));return u("div",{className:"space-y-1",children:[M&&r("div",{className:ua,children:M}),u("div",{className:"flex items-center gap-2",children:[r("div",{className:"flex-1 min-w-0",children:r(tr,{field:N(),values:{...t,[e.key]:k},onChange:(P,I)=>v(S,I),disabled:o,translationFn:s,onTestField:a,onAction:c,allFields:l})}),g.length>f&&r("button",{type:"button",onClick:()=>y(S),disabled:o,title:"Remove",className:"flex-shrink-0 inline-flex items-center justify-center rounded-md border border-border p-1.5 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors disabled:opacity-40",children:r(rn,{className:"h-3.5 w-3.5"})})]})]},S)}),u("div",{className:"flex items-center justify-between pt-1",children:[g.length<p?u("button",{type:"button",onClick:w,disabled:o,className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40",children:[r(Js,{className:"h-3 w-3"}),d.addLabel??"Add"]}):r("span",{}),u("span",{className:"text-[10px] text-foreground-subtle tabular-nums",children:[g.length,"/",p]})]})]})})}function Sc(e,t,n){if(!("showWhen"in e)||!e.showWhen)return!0;const o=e.showWhen,s=t[o.field],a=n?.find(c=>"key"in c&&c.key===o.field),i=a&&"default"in a?a.default:void 0,l=s!==void 0?s:i;return o.equals!==void 0?l===o.equals:o.notEquals!==void 0?l!==o.notEquals:o.in!==void 0?o.in.includes(l):o.notIn!==void 0?!o.notIn.includes(l):o.includes!==void 0?Array.isArray(l)&&l.includes(o.includes):o.notIncludes!==void 0?!Array.isArray(l)||!l.includes(o.notIncludes):!0}function tr({field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c}){if(VP(e))return r(qP,{field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i,allFields:l,onAction:c});if("readonlyField"in e&&e.readonlyField===!0)return r(FP,{field:e,values:t,onAction:c,translationFn:s});if(!Sc(e,t,l))return null;const d=t[e.key],f=d!==void 0?d:"default"in e?e.default:void 0,p=h=>n(e.key,h),m=Fh(e.type);switch(e.type){case"text":return r(mP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"number":return r(hP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"boolean":return r(gP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"select":return r(bP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"multiselect":return r(xP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"password":return r(yP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"textarea":return r(vP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"slider":return r(wP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"tags":return r(NP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"color":return r(kP,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"node-select":return r(fx,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"node-multiselect":return r(mx,{field:e,value:f,onChange:p,disabled:o,translationFn:s});case"probe":return r(SP,{field:e,value:f,onChange:p,disabled:o,translationFn:s,onTestField:a,onAction:c,externalProbe:i});case"group":return r(CP,{field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a});case"sub-tabs":return r(MP,{field:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,onAction:c});case"separator":return r(IP,{});case"info":return r(PP,{field:e});case"object-array":return r(DP,{field:e});case"editable-array":return r(LP,{field:e,value:f,onChange:p,disabled:o,translationFn:s,onTestField:a,onAction:c});case"button":return r(TP,{field:e,disabled:o,onAction:c});case"addon-action-select":return r(RP,{field:e,value:f,values:t,onChange:p,disabled:o,onAction:c});case"addon-action-button":return r(OP,{field:e,values:t,disabled:o,onAction:c});case"widget":return r(zP,{field:e});default:return m?r(m,{field:e,value:f,onChange:p,disabled:o}):null}}function QP(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function Tt(e,t){if(e!==void 0)return t&&QP(e)?t(e):e}function UP({section:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,probeResults:i}){const[l,c]=$(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(m=>!m):void 0,children:[u("div",{children:[r("h3",{className:"text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider",children:Tt(e.title,s)}),e.description&&r("p",{className:"text-[10px] text-foreground-subtle mt-0.5",children:Tt(e.description,s)})]}),d&&r("span",{className:"text-foreground-subtle text-xs ml-2",children:l?"▸":"▾"})]}),!l&&r("div",{className:`grid ${p} gap-x-3 gap-y-2.5`,children:e.fields.map(m=>r(tr,{field:m,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,externalProbe:i?.[m.key]},m.key))})]})}function gx({schema:e,values:t,onChange:n,disabled:o,translationFn:s,onTestField:a,probeResults:i,onClearProbe:l}){const c=(d,f)=>{n({...t,[d]:f}),l?.(d)};return r("div",{className:"space-y-4",children:e.sections.map(d=>r(UP,{section:d,values:t,onChange:c,disabled:o,translationFn:s,onTestField:a,probeResults:i},d.id))})}const KP=({open:e})=>r("svg",{className:`h-3 w-3 transition-transform ${e?"rotate-90":""}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:r("polyline",{points:"9 18 15 12 9 6"})});function mu(e){const t={};if(!e)return t;for(const n of e.sections)for(const o of n.fields){if(o.type==="separator"||o.type==="info"||o.type==="button"||o.type==="group")continue;const s=o.key;t[s]=o.value}return t}function GP(e){return{...e,sections:e.sections.map(t=>({...t,fields:t.fields.map(n=>{if(n.type==="separator"||n.type==="info"||n.type==="button"||n.type==="group")return n;const{value:o,...s}=n;return s})}))}}function WP({trpc:e,addonId:t,nodeId:n,title:o,disabled:s,onAfterChange:a,refreshToken:i,collapsible:l,defaultOpen:c,mode:d,onOverrideChange:f}){const p=d??"persist",[m,h]=$(null),[g,b]=$(!0),[x,v]=$(null),[w,y]=$(!1),[N,k]=$(c??!1),[S,M]=$({}),[P,I]=$(null);Y(()=>{I(null),M({})},[e,t,n,i,p]);const F=JSON.stringify(S);Y(()=>{let _=!1;b(!0),v(null);const R=p==="override"&&Object.keys(S).length>0?S:void 0;return e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n,...R?{overlay:R}:{}}).then(L=>{_||(h(L),R||I(mu(L)),b(!1))}).catch(L=>{_||(v(L instanceof Error?L.message:String(L)),b(!1))}),()=>{_=!0}},[e,t,n,i,p,F]);const E=Q(()=>mu(m),[m]),B=Q(()=>m?GP(m):null,[m]),O=async _=>{if(p==="override"){const L=P??E,z={};for(const H of Object.keys(_))_[H]!==L[H]&&(z[H]=_[H]);const j={...L,...z};M(z),f?.(z,j);return}const R={};for(const L of Object.keys(_))_[L]!==E[L]&&(R[L]=_[L]);if(Object.keys(R).length!==0){y(!0);try{await e.addonSettings.updateGlobalSettings.mutate({addonId:t,nodeId:n,patch:R});const L=await e.addonSettings.getGlobalSettings.query({addonId:t,nodeId:n});h(L),a?.()}catch(L){v(L instanceof Error?L.message:String(L))}finally{y(!1)}}};if(g)return u("div",{className:"text-xs text-foreground-subtle animate-pulse",children:["Loading ",o??t,"…"]});if(x)return u("div",{className:"text-xs text-red-400",children:[o??t,": ",x]});if(!m||!B)return u("div",{className:"text-xs text-foreground-subtle",children:[o??t," not available on ",n,"."]});const A=p==="override"?{...E,...S}:E,D=u(ve,{children:[p==="override"?r("div",{className:"mb-2 text-[11px] text-foreground-subtle",children:"Benchmark override — applies to this run only. The addon's saved settings are not changed."}):null,r(gx,{schema:B,values:A,onChange:O,disabled:s===!0||w})]});return l===!0?u("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[u("button",{type:"button",onClick:()=>k(_=>!_),className:"w-full px-4 py-2 flex items-center gap-2 hover:bg-surface-hover text-left","aria-expanded":N,children:[r(KP,{open:N}),r("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide flex-1",children:o??t}),r("span",{className:"text-[10px] text-foreground-subtle",children:N?"hide":"edit"})]}),N?r("div",{className:"border-t border-border px-4 py-3",children:D}):null]}):o?u("section",{className:"rounded-lg border border-border bg-surface overflow-hidden",children:[r("div",{className:"border-b border-border px-4 py-2",children:r("h3",{className:"text-xs font-semibold text-foreground uppercase tracking-wide",children:o})}),r("div",{className:"px-4 py-3",children:D})]}):r("div",{children:D})}function bx({detections:{motion:e,motionRaw:t,detection:n,phase:o},showMotionZones:s=!0,showMotionRaw:a=!0,showDetections:i=!0,showPhaseIndicator:l=!0}){const c=s&&e&&e.zones.length>0,d=a&&t&&t.boxes.length>0,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&&r(YP,{phase:o}),d&&r(ZP,{raw:t}),c&&r(XP,{motion:e}),f&&r(JP,{detections:n.detections,frameWidth:n.frameWidth,frameHeight:n.frameHeight})]})}function YP({phase:e}){const t=Wn(e);return u("div",{className:"absolute top-2 left-2 flex items-center gap-1.5 px-2 py-1 rounded-md bg-black/60 backdrop-blur-sm",children:[r("span",{className:`w-2 h-2 rounded-full ${t.dotClass}`}),r("span",{className:"text-[10px] font-semibold text-white uppercase tracking-wider",children:t.label})]})}function ZP({raw:e}){return e.frameWidth===0||e.frameHeight===0?null:r(ve,{children:e.boxes.map((t,n)=>{const[o,s,a,i]=t.bbox,l=o/e.frameWidth*100,c=s/e.frameHeight*100,d=(a-o)/e.frameWidth*100,f=(i-s)/e.frameHeight*100,p=Math.max(.05,Math.min(.25,t.changeScore*.3));return r("div",{className:"absolute rounded-sm",style:{left:`${l}%`,top:`${c}%`,width:`${d}%`,height:`${f}%`,backgroundColor:`rgba(239, 68, 68, ${p})`}},`mr-${n}`)})})}function XP({motion:e}){if(e.frameWidth===0||e.frameHeight===0)return null;const t=e.zones.filter(n=>n.w*n.h/(e.frameWidth*e.frameHeight)<.9);return r(ve,{children:t.map((n,o)=>{const s=Math.max(.15,Math.min(.5,n.intensity/255));return r("div",{className:"absolute rounded-sm",style:{left:`${n.x/e.frameWidth*100}%`,top:`${n.y/e.frameHeight*100}%`,width:`${n.w/e.frameWidth*100}%`,height:`${n.h/e.frameHeight*100}%`,border:`1px solid rgba(250, 204, 21, ${s})`,backgroundColor:`rgba(250, 204, 21, ${s*.15})`}},`mz-${o}`)})})}function JP({detections:e,frameWidth:t,frameHeight:n}){return t===0||n===0?null:r(ve,{children:e.map(o=>{const{x:s,y:a,width:i,height:l}=o.bbox,c=s/t*100,d=a/n*100,f=i/t*100,p=l/n*100,m=ct(o.macroClass),h=[`${o.macroClass} ${(o.score*100).toFixed(0)}%`];for(const g of o.labels)h.push(g.label);return r("div",{className:"absolute border-2 rounded-sm",style:{left:`${c}%`,top:`${d}%`,width:`${f}%`,height:`${p}%`,borderColor:m},children:r("div",{className:"absolute -top-4 left-0 px-1 py-0.5 text-[9px] font-bold text-white rounded-sm whitespace-nowrap",style:{backgroundColor:m},children:h.join(" | ")})},`det-${o.id}`)})})}function eE(e){const t={};if(typeof window<"u"){if(e){const o=e.getBoundingClientRect();o.width>0&&o.height>0&&(t.viewportWidth=Math.round(o.width),t.viewportHeight=Math.round(o.height))}t.viewportWidth===void 0&&(t.viewportWidth=window.innerWidth,t.viewportHeight=window.innerHeight),t.devicePixelRatio=window.devicePixelRatio||1;const n=navigator.connection;n?.downlink&&n.downlink>0&&(t.downlinkMbps=n.downlink)}return t}const tE=3e3,nE=5;function xx({serverUrl:e,streamKey:t,label:n,autoPlay:o=!0,muted:s=!0,showControls:a=!0,className:i="",onStateChange:l,onError:c,overlay:d,createSession:f,sendAnswer:p,closeSession:m,hintsOverride:h}){const g=ne(null),b=ne(null),x=ne(null),v=ne(new Set),w=ne(null),y=ne(null),N=ne(0),k=ne(!0),[S,M]=$("idle"),[P,I]=$(""),[F,E]=$(s),[B,O]=$(!1),[A,D]=$(!1),_=ne(null),R=ne(!1);(p||f)&&(R.current=!0);const L=R.current,z=q(U=>{M(U),l?.(U)},[l]),j=q(()=>{if(w.current?.abort(),w.current=null,y.current&&(clearTimeout(y.current),y.current=null),x.current&&(x.current.close(),x.current=null),m&&v.current.size>0){for(const U of v.current)m(U).catch(()=>{});v.current.clear()}g.current&&(g.current.srcObject=null)},[m]),H=q(async()=>{if(!k.current||!f||!p)return;j(),z("connecting");const U=new AbortController;w.current=U;try{const ae={...eE(b.current),...h},{sessionId:fe,sdpOffer:he}=await f(ae);if(v.current.add(fe),!k.current||U.signal.aborted){m?.(fe).catch(()=>{}),v.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,z("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")&&(z("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:he});const ue=await V.createAnswer();if(await V.setLocalDescription(ue),console.debug("[WebRTC] Local description set, waiting for ICE gathering..."),await hu(V),!k.current)return;const de=(V.localDescription?.sdp??"").split(`
|
|
531
531
|
`).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 le=V,Se=()=>{const pe=le.connectionState;if(pe==="closed"||pe==="failed")return;const Ie=g.current;Ie&&Ie.readyState===0&&console.log(`[WebRTC] no video data yet (ice=${le.iceConnectionState})`)};setTimeout(Se,3e3),setTimeout(Se,8e3)}catch(J){if(!k.current)return;const ae=J instanceof Error?J.message:String(J);I(ae),z("error"),c?.(ae),ee()}},[e,t,f,p,j,z,c,h]),T=q(async()=>{if(k.current){j(),z("connecting");try{const U=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]});x.current=U,U.addTransceiver("video",{direction:"recvonly"}),U.addTransceiver("audio",{direction:"recvonly"});const J=new MediaStream;U.ontrack=ie=>{J.addTrack(ie.track),g.current&&(g.current.srcObject=J,g.current.play().catch(()=>{}))},U.oniceconnectionstatechange=()=>{if(!k.current)return;const ie=U.iceConnectionState;ie==="connected"||ie==="completed"?(N.current=0,z("playing"),g.current?.paused&&g.current.play().catch(()=>{})):(ie==="failed"||ie==="disconnected"||ie==="closed")&&(z("disconnected"),ee())};const ae=await U.createOffer();if(await U.setLocalDescription(ae),await hu(U),!k.current)return;const fe=`${e}/api/webrtc?src=${encodeURIComponent(t)}`,he=await fetch(fe,{method:"POST",headers:{"Content-Type":"application/sdp"},body:U.localDescription?.sdp??""});if(!he.ok)throw new Error(`WHEP ${he.status}: ${he.statusText}`);const V=await he.text();await U.setRemoteDescription({type:"answer",sdp:V})}catch(U){if(!k.current)return;const J=U instanceof Error?U.message:String(U);I(J),z("error"),c?.(J),ee()}}},[e,t,j,z,c]),W=L?H:T,G=ne(()=>{});G.current=W;const ee=q(()=>{k.current&&(N.current>=nE||(N.current+=1,y.current=setTimeout(()=>{k.current&&G.current()},tE)))},[]);Y(()=>(k.current=!0,N.current=0,o&&W(),()=>{k.current=!1,j()}),[e,t]);const se=ne(!1);Y(()=>{!o||!L||!f||!p||se.current||x.current||(se.current=!0,W())},[o,L,f,p,W]);const te=()=>{N.current=0,W()},X=()=>{g.current&&(g.current.muted=!g.current.muted,E(g.current.muted))},re=async()=>{if(b.current)try{document.fullscreenElement?await document.exitFullscreen():await b.current.requestFullscreen()}catch(U){console.warn(`Fullscreen toggle failed: ${U instanceof Error?U.message:U}`)}},ge=()=>{if(!g.current)return;const U=document.createElement("canvas");U.width=g.current.videoWidth||1280,U.height=g.current.videoHeight||720;const J=U.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=U.toDataURL("image/jpeg",.92),ae.click()};Y(()=>{const U=()=>O(!!document.fullscreenElement);return document.addEventListener("fullscreenchange",U),()=>document.removeEventListener("fullscreenchange",U)},[]);const Z=()=>{D(!0),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>D(!1),3e3)};return u("div",{ref:b,className:`relative bg-black overflow-hidden group ${i}`,onMouseMove:Z,onMouseEnter:Z,children:[r("video",{ref:g,autoPlay:o,muted:F,playsInline:!0,className:"w-full h-full object-contain"}),n&&S==="playing"&&r("div",{className:"absolute top-2 left-2 px-2 py-0.5 rounded bg-black/60 text-[10px] text-white font-medium",children:n}),d,S==="connecting"&&u("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-black/70 gap-2",children:[r("svg",{className:"h-6 w-6 text-white/60 animate-spin",viewBox:"0 0 24 24",fill:"none",children:r("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"32",strokeDashoffset:"32",className:"animate-[dash_1.5s_ease-in-out_infinite]"})}),r("span",{className:"text-xs text-white/60",children:"Connecting…"})]}),(S==="error"||S==="disconnected")&&u("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-black/70 gap-2",children:[r("svg",{className:"h-6 w-6 text-red-400",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:r("path",{d:"M1 1l5.5 5.5M23 23l-5.5-5.5M8.11 15.89a8 8 0 0110.78-10.78M3.64 3.64A12 12 0 0020.36 20.36",strokeLinecap:"round"})}),r("span",{className:"text-xs text-red-400 text-center px-4",children:S==="error"?P||"Connection failed":"Disconnected"}),r("button",{onClick:te,className:"mt-1 inline-flex items-center gap-1.5 rounded px-3 py-1 text-xs bg-white/10 text-white hover:bg-white/20 transition-colors",children:"Reconnect"})]}),a&&S==="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 ${A?"opacity-100":"opacity-0"}`,children:[r("div",{className:"flex items-center gap-1",children:r(Ka,{onClick:X,title:F?"Unmute":"Mute",children:F?u("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[r("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),r("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),r("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]}):u("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[r("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),r("path",{d:"M19.07 4.93a10 10 0 010 14.14M15.54 8.46a5 5 0 010 7.07"})]})})}),u("div",{className:"flex items-center gap-1",children:[r(Ka,{onClick:ge,title:"Take snapshot",children:u("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[r("path",{d:"M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z"}),r("circle",{cx:"12",cy:"13",r:"4"})]})}),r(Ka,{onClick:re,title:B?"Exit fullscreen":"Fullscreen",children:B?r("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:r("path",{d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):r("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:r("path",{d:"M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3"})})})]})]})]})}function Ka({onClick:e,title:t,children:n}){return r("button",{onClick:e,title:t,className:"rounded-full p-1.5 text-white/80 hover:text-white hover:bg-white/20 transition-colors",children:n})}async function hu(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 Cc=un("camstack:player-overlays-state",null),Mc=un("camstack:player-overlays-actions",null);function yx({children:e}){const[t,n]=$(()=>new Map),[o,s]=$(()=>new Map),a=q(p=>{n(m=>{const h=new Map(m);return h.set(p.id,p),h})},[]),i=q(p=>{n(m=>{if(!m.has(p))return m;const h=new Map(m);return h.delete(p),h})},[]),l=q(p=>{s(m=>{const h=new Map(m);return h.set(p.id,p),h})},[]),c=q(p=>{s(m=>{if(!m.has(p))return m;const h=new Map(m);return h.delete(p),h})},[]),d=Q(()=>({layers:t,buttons:o}),[t,o]),f=Q(()=>({setLayer:a,removeLayer:i,setButton:l,removeButton:c}),[a,i,l,c]);return r(Cc.Provider,{value:d,children:r(Mc.Provider,{value:f,children:e})})}function vx(){const e=ye(Cc);return Q(()=>e?[...e.layers.values()].sort((t,n)=>t.order-n.order):[],[e])}function wx(){const e=ye(Cc);return Q(()=>e?[...e.buttons.values()].sort((t,n)=>t.order-n.order):[],[e])}function rE(e){const t=ye(Mc);Y(()=>{if(!(!t||!e))return t.setLayer(e),()=>t.removeLayer(e.id)},[t,e])}function oE(e){const t=ye(Mc);Y(()=>{if(!(!t||!e))return t.setButton(e),()=>t.removeButton(e.id)},[t,e])}function sE(e){return e==="streaming"?"bg-emerald-500":e==="connecting"?"bg-amber-500":e==="error"?"bg-rose-500":"bg-zinc-500"}function aE(e){const t=Math.floor(e/1e3);return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:`${Math.floor(t/3600)}h${Math.floor(t%3600/60)}m`}function Ui({className:e}){return r("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r("polygon",{points:"5 3 19 12 5 21 5 3"})})}function iE({className:e}){return r("svg",{className:e,viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r("rect",{x:"6",y:"6",width:"12",height:"12",rx:"1"})})}function lE({className:e}){return u("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z"}),r("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),r("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),r("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}function cE({className:e}){return u("svg",{className:e,viewBox:"0 0 24 24",fill:"currentColor",children:[r("circle",{cx:"5",cy:"12",r:"2"}),r("circle",{cx:"12",cy:"12",r:"2"}),r("circle",{cx:"19",cy:"12",r:"2"})]})}function Ga({label:e,active:t,onClick:n}){return u("button",{type:"button",onClick:n,className:"w-full flex items-center justify-between gap-3 px-3 py-1.5 text-[11px] text-foreground hover:bg-surface-hover transition-colors",children:[r("span",{children:e}),r("span",{className:`inline-block h-3 w-5 rounded-full transition-colors ${t?"bg-primary":"bg-foreground-subtle/30"} relative`,children:r("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-white transition-all ${t?"left-2.5":"left-0.5"}`})})]})}function Nx({className:e}){return u("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("polyline",{points:"23 4 23 10 17 10"}),r("polyline",{points:"1 20 1 14 7 14"}),r("path",{d:"M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15"})]})}function dE({className:e}){return u("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("line",{x1:"2",y1:"2",x2:"22",y2:"22"}),r("path",{d:"M10.41 10.41a2 2 0 11-2.83-2.83"}),r("line",{x1:"13.5",y1:"13.5",x2:"6",y2:"21"}),r("path",{d:"M18 12l-1.5-1.5"}),r("path",{d:"M21 15V5a2 2 0 00-2-2H5"}),r("path",{d:"M21 21H5a2 2 0 01-2-2V11"})]})}function Ic({serverUrl:e,createSession:t,sendAnswer:n,closeSession:o,streams:s,activeStreamId:a,onStreamChange:i,deviceName:l,phase:c,pipelineMetrics:d,detections:f,defaultShowDetections:p=!0,defaultShowMotion:m=!1,streamStats:h,autoPlay:g=!1,showPlayStop:b=!1,snapshotSrc:x,snapshotLoading:v=!1,onRefreshSnapshot:w,showStreamStats:y=!1,children:N,extraOverlay:k,ptzAvailable:S=!1,ptzShown:M=!1,ptzOverlay:P,onPtzToggle:I,intercomAvailable:F=!1,intercomShown:E=!1,onIntercomToggle:B,chromeless:O=!1,className:A}){const D=wx(),[_,R]=$(g),[L,z]=$(p),[j,H]=$(m),[T,W]=$(null),[G,ee]=$(!1),se=ne(null);Y(()=>{if(!G)return;function le(Se){se.current&&!se.current.contains(Se.target)&&ee(!1)}return document.addEventListener("mousedown",le),()=>document.removeEventListener("mousedown",le)},[G]);const te=a??T??s?.[0]?.id??"",X=s?.find(le=>le.id===te)??s?.[0],re=X?.inputFps!=null?{status:X.status??"unknown",inputFps:X.inputFps,bitrateKbps:X.bitrateKbps??0}:null,ge=le=>{W(le),i?.(le),_&&b&&(R(!1),setTimeout(()=>R(!0),50))},Z=Q(()=>{const le=X?.target;if(le)return Se=>t(le,Se)},[t,X]),U=s,J=()=>R(!0),ae=()=>R(!1),fe=d?.phase??c,he=fe==="active",V=!!f,ie=V&&(L||j),ue=S&&M&&!!P,de=b?_:!0;return u("div",{className:`overflow-hidden ${O?"":"rounded-xl border border-border bg-surface"} ${A??""}`,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:[(h??re)&&r("span",{className:`w-2 h-2 rounded-full ${sE((h??re).status)}`}),l&&r("span",{className:"text-xs font-medium text-foreground",children:l}),U&&U.length>1&&u("div",{className:"relative",children:[r("select",{"data-testid":"stream-profile-select",value:te,onChange:le=>ge(le.target.value),className:"appearance-none cursor-pointer rounded-md border border-border bg-surface-hover hover:bg-surface text-foreground text-[11px] font-medium pl-2 pr-6 py-1 focus:outline-none focus:ring-1 focus:ring-primary transition-colors",children:U.map(le=>r("option",{value:le.id,children:le.label},le.id))}),r("span",{className:"pointer-events-none absolute right-1.5 top-1/2 -translate-y-1/2 text-foreground-subtle",children:r("svg",{className:"h-2.5 w-2.5",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r("polyline",{points:"3 4.5 6 7.5 9 4.5"})})})]})]}),u("div",{className:"flex items-center gap-1.5",children:[F&&u("button",{"data-testid":"stream-intercom-toggle","data-intercom-shown":E?"true":"false",onClick:B,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors ${E?"bg-primary/15 text-primary":"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,title:E?"Close intercom":"Open intercom",children:[r(lE,{className:"h-3 w-3"}),r("span",{className:"hidden xl:inline",children:"Intercom"})]}),D.map(le=>{const pe=le.tone==="primary"?"bg-primary text-primary-foreground":"bg-primary/15 text-primary";return u("button",{type:"button","data-toolbar-button-id":le.id,"data-toolbar-button-active":le.active?"true":"false",onClick:le.onClick,disabled:le.disabled,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors disabled:opacity-50 ${le.active?pe:"text-foreground-subtle hover:text-foreground hover:bg-surface-hover"}`,title:le.title??le.label,children:[le.icon,r("span",{className:"hidden xl:inline",children:le.label})]},le.id)}),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?r(iE,{className:"h-3 w-3"}):r(Ui,{className:"h-3 w-3"}),r("span",{className:"hidden xl:inline",children:de?"Stop":"Play"})]}),w&&u("button",{"data-testid":"stream-snapshot-refresh",onClick:w,disabled:v,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50",title:"Force snapshot refresh",children:[r(Nx,{className:`h-3 w-3 ${v?"animate-spin":""}`}),r("span",{className:"hidden xl:inline",children:"Snapshot"})]}),(V||S||d||fe||h||re&&re.inputFps>0)&&u("div",{ref:se,className:"relative",children:[r("button",{onClick:()=>ee(le=>!le),title:"More controls",className:"inline-flex items-center justify-center rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",children:r(cE,{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:[y&&h&&u("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[u("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Input"}),u("span",{className:"tabular-nums text-foreground",children:[h.inputFps.toFixed(1)," fps"]})]}),u("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Decode"}),u("span",{className:"tabular-nums text-foreground",children:[h.decodeFps.toFixed(1)," fps"]})]}),u("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Uptime"}),r("span",{className:"tabular-nums text-foreground",children:aE(h.uptimeMs)})]})]}),!y&&re&&re.inputFps>0&&u("div",{className:"px-3 py-1.5 text-[10px] text-foreground-subtle border-b border-border-subtle",children:[u("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Input"}),u("span",{className:"tabular-nums text-foreground",children:[re.inputFps.toFixed(1)," fps"]})]}),re.bitrateKbps>0&&u("div",{className:"flex justify-between gap-3",children:[r("span",{children:"Bitrate"}),u("span",{className:"tabular-nums text-foreground",children:[re.bitrateKbps," kbps"]})]})]}),(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:[r("span",{children:"Phase"}),u("span",{className:`flex items-center gap-1 font-semibold uppercase tracking-wider ${he?"text-red-400":"text-emerald-400"}`,children:[r("span",{className:`w-1.5 h-1.5 rounded-full ${he?"bg-red-500 animate-pulse":"bg-emerald-500"}`}),he?"Active":"Watching"]})]}),d&&d.detectionFps>0&&u("div",{className:"flex justify-between gap-3",children:[r("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:[r("span",{children:"Inference"}),u("span",{className:"tabular-nums text-foreground",children:[d.avgInferenceMs.toFixed(0)," ms"]})]})]}),V&&u(ve,{children:[r(Ga,{label:"Show detections",active:L,onClick:()=>z(le=>!le)}),r(Ga,{label:"Show motion",active:j,onClick:()=>H(le=>!le)})]}),S&&r(Ga,{label:"PTZ controls",active:M,onClick:()=>{I?.(),ee(!1)}})]})]})]})]}),de?r("div",{className:"aspect-video relative",children:r(xx,{serverUrl:e,streamKey:te,autoPlay:!0,className:"w-full h-full",createSession:Z,sendAnswer:n,closeSession:o,overlay:ie||k||ue?u(ve,{children:[ie&&r(bx,{detections:f,showPhaseIndicator:!1,showMotionZones:j,showMotionRaw:j,showDetections:L}),k,ue&&P]}):void 0},te)}):r(uE,{src:x??null,isLoading:v,onPlay:J,onRetry:w,extraOverlay:k||ue?u(ve,{children:[k,ue&&P]}):null,suppressPlayHover:!!k||ue}),N]})}function uE({src:e,isLoading:t,onPlay:n,onRetry:o,extraOverlay:s,suppressPlayHover:a=!1}){return e?u("div",{className:"relative w-full aspect-video bg-black/90 flex items-center justify-center",children:[r("img",{src:e,alt:"Camera snapshot",className:"w-full h-full object-contain"}),!a&&r("button",{onClick:n,className:"absolute inset-0 flex items-center justify-center bg-black/30 opacity-0 hover:opacity-100 transition-opacity cursor-pointer",children:r("div",{className:"h-14 w-14 rounded-full bg-white/20 backdrop-blur-sm flex items-center justify-center",children:r(Ui,{className:"h-7 w-7 text-white ml-0.5"})})}),s]}):t?r("div",{className:"relative w-full aspect-video bg-black/90 flex items-center justify-center",children:r("div",{className:"h-8 w-8 border-2 border-white/20 border-t-white/60 rounded-full animate-spin"})}):r("div",{className:"relative w-full aspect-video bg-black/90 flex items-center justify-center",children:u("div",{className:"flex flex-col items-center gap-2 text-white/40",children:[r(dE,{className:"h-8 w-8"}),r("span",{className:"text-xs",children:"No snapshot available"}),u("div",{className:"flex items-center gap-2 mt-1",children:[o&&u("button",{onClick:o,className:"inline-flex items-center gap-1.5 rounded-md border border-white/20 px-3 py-1.5 text-xs font-medium text-white/60 hover:text-white hover:border-white/40 transition-colors",children:[r(Nx,{className:"h-3 w-3"}),"Retry"]}),u("button",{onClick:n,className:"inline-flex items-center gap-1.5 rounded-md bg-primary/80 px-3 py-1.5 text-xs font-medium text-white hover:bg-primary transition-colors",children:[r(Ui,{className:"h-3 w-3"}),"Play Live"]})]})]})})}function pE({samples:e,sampleRate:t=16e3,height:n=96,className:o="",color:s="#3b82f6",bgColor:a="transparent"}){const i=ne(null),l=ne(null),c=q(()=>{const p=i.current,m=l.current;if(!p||!m||!e||e.length===0)return;const h=m.clientWidth;if(h===0)return;const g=window.devicePixelRatio||1;p.width=h*g,p.height=n*g,p.style.width=`${h}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,h,n)):b.clearRect(0,0,h,n);const x=e.length/h,v=n/2;b.fillStyle=s,b.globalAlpha=.7;for(let w=0;w<h;w++){const y=Math.floor(w*x),N=Math.min(Math.floor((w+1)*x),e.length);let k=0,S=0;for(let F=y;F<N;F++){const E=e[F];E<k&&(k=E),E>S&&(S=E)}const M=v-S*v,P=v-k*v,I=Math.max(1,P-M);b.fillRect(w,M,1,I)}b.globalAlpha=1,b.strokeStyle=s,b.globalAlpha=.2,b.lineWidth=1,b.beginPath(),b.moveTo(0,v),b.lineTo(h,v),b.stroke(),b.globalAlpha=1},[e,n,s,a]);Y(()=>{c()},[c]),Y(()=>{const p=new ResizeObserver(()=>c()),m=l.current;return m&&p.observe(m),()=>p.disconnect()},[c]);const f=((e&&t?Math.round(e.length/t*1e3):0)/1e3).toFixed(1);return u("div",{ref:l,className:`relative ${o}`,children:[r("canvas",{ref:i,className:"w-full rounded-md"}),e&&e.length>0&&u("div",{className:"absolute bottom-1 right-2 text-[10px] text-foreground-subtle/60 font-mono",children:[f,"s · ",t/1e3,"kHz · ",e.length.toLocaleString()," samples"]})]})}function fE({currentDbfs:e,durationSec:t=30,maxSamples:n=120,height:o=64,className:s="",color:a="#10b981",clipColor:i="#ef4444",clipThreshold:l=-6,minDbfs:c=-96}){const d=ne(null),f=ne(null),[p,m]=$([]);Y(()=>{e!==null&&m(b=>{const x=[...b,{dbfs:e,timestamp:Date.now()}];return x.length>n?x.slice(-n):x})},[e,n]);const h=q(()=>{const b=d.current,x=f.current;if(!b||!x)return;const v=x.clientWidth;if(v===0)return;const w=window.devicePixelRatio||1;b.width=v*w,b.height=o*w,b.style.width=`${v}px`,b.style.height=`${o}px`;const y=b.getContext("2d");if(!y||(y.scale(w,w),y.clearRect(0,0,v,o),p.length===0))return;const N=p[p.length-1].timestamp,k=t*1e3,S=N-k,M=p.filter(E=>E.timestamp>=S);if(M.length===0)return;const P=Math.max(1,Math.floor(v/(t*2))),I=Math.abs(c);for(const E of M){const B=E.timestamp-S,O=Math.floor(B/k*v),D=(Math.max(c,Math.min(0,E.dbfs))-c)/I,_=Math.max(1,D*o),R=E.dbfs>=l;y.fillStyle=R?i:a,y.globalAlpha=.8,y.fillRect(O,o-_,P,_)}y.globalAlpha=1;const F=o-(l-c)/I*o;y.strokeStyle=i,y.globalAlpha=.25,y.lineWidth=1,y.setLineDash([4,4]),y.beginPath(),y.moveTo(0,F),y.lineTo(v,F),y.stroke(),y.setLineDash([]),y.globalAlpha=1},[p,t,o,a,i,l,c]);Y(()=>{h()},[h]),Y(()=>{const b=new ResizeObserver(()=>h()),x=f.current;return x&&b.observe(x),()=>b.disconnect()},[h]);const g=p.length>0?p[p.length-1].dbfs:null;return u("div",{ref:f,className:`relative ${s}`,children:[r("canvas",{ref:d,className:"w-full rounded-md"}),u("div",{className:"absolute top-1 left-2 text-[9px] text-foreground-subtle/50 font-mono",children:[t,"s"]}),g!==null&&u("div",{className:"absolute bottom-1 right-2 text-[9px] text-foreground-subtle/50 font-mono",children:[g.toFixed(1)," dBFS · ",p.length," samples"]})]})}function mE(e){return e>=.8?"bg-emerald-500":e>=.5?"bg-amber-500":e>=.3?"bg-orange-500":"bg-zinc-500"}function hE(e){return e>=.8?"text-emerald-400":e>=.5?"text-amber-400":e>=.3?"text-orange-400":"text-zinc-400"}function gE({classifications:e,processing:t=!1,inferenceMs:n,maxItems:o=10,className:s=""}){const a=e.slice(0,o),i=a.length>0?a[0].score:1;return t?r("div",{className:`rounded-xl border border-border bg-surface p-4 text-center ${s}`,children:r("div",{className:"text-sm text-foreground-subtle animate-pulse",children:"Classifying audio..."})}):a.length===0?r("div",{className:`rounded-xl border border-border bg-surface p-4 text-center ${s}`,children:r("div",{className:"text-xs text-foreground-subtle",children:"No classifications yet"})}):u("div",{className:`rounded-xl border border-border bg-surface overflow-hidden ${s}`,children:[u("div",{className:"px-3 py-2 border-b border-border flex items-center justify-between",children:[r("h3",{className:"text-xs font-medium text-foreground",children:"Audio Classifications"}),u("div",{className:"flex items-center gap-3 text-[10px] text-foreground-subtle",children:[a.length<e.length&&u("span",{children:["showing ",a.length," of ",e.length]}),n!==void 0&&u("span",{className:"font-mono",children:[n.toFixed(1),"ms"]})]})]}),r("div",{className:"divide-y divide-border/50",children:a.map((l,c)=>{const d=i>0?l.score/i*100:0;return u("div",{className:"px-3 py-1.5 flex items-center gap-3 hover:bg-surface-hover/30",children:[r("span",{className:"text-[10px] text-foreground-subtle w-5 text-right font-mono",children:c+1}),r("span",{className:"text-xs font-medium text-foreground min-w-[120px]",children:l.className}),r("div",{className:"flex-1 h-2 rounded-full bg-zinc-800 overflow-hidden",children:r("div",{className:`h-full rounded-full transition-all duration-300 ${mE(l.score)}`,style:{width:`${d}%`}})}),u("span",{className:`text-xs font-mono font-semibold w-14 text-right ${hE(l.score)}`,children:[(l.score*100).toFixed(1),"%"]})]},`${l.className}-${c}`)})})]})}function bE({data:e,label:t="Response",className:n=""}){const[o,s]=$(!1);if(!e)return null;const a=JSON.stringify(e,null,2);return u("div",{className:`rounded-xl border border-border bg-surface overflow-hidden ${n}`,children:[u("div",{className:"px-3 py-2 border-b border-border flex items-center justify-between cursor-pointer select-none hover:bg-surface-hover/30",onClick:()=>s(i=>!i),children:[u("div",{className:"flex items-center gap-2",children:[r("span",{className:"text-[10px] text-foreground-subtle",children:o?"▼":"▶"}),r("h3",{className:"text-xs font-medium text-foreground",children:t})]}),r("span",{className:"text-[10px] text-foreground-subtle font-mono",children:a.length>1e3?`${(a.length/1024).toFixed(1)} KB`:`${a.length} bytes`})]}),o&&r("div",{className:"max-h-80 overflow-y-auto overflow-x-auto",children:r("pre",{className:"p-3 text-[10px] leading-4 font-mono text-foreground-subtle whitespace-pre",children:a})})]})}const xE={Activity:yn,Eye:Xs,AlertTriangle:No,PauseCircle:x2,PowerOff:hk};function Ac({phase:e,...t}){const n=Wn(e),o=xE[n.icon];return r(o,{...t})}function On(e){const[t,n]=$([]),o=q(a=>{n(i=>{const l=[...i,a];return l.length>e?l.slice(-e):l})},[e]),s=q(()=>{n([])},[]);return Q(()=>({entries:t,append:o,reset:s}),[t,o,s])}function gu(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 bu={error:{icon:Zs,color:"text-red-400"},warn:{icon:No,color:"text-amber-400"},info:{icon:K2,color:"text-blue-400"},debug:{icon:t2,color:"text-gray-500"}},xu={debug:0,info:1,warn:2,error:3},yE=["all","debug","info","warn","error"],vE=500;function wE(e,t){return t?(xu[e]??0)>=(xu[t]??0):!0}function Wt({agentId:e,addonId:t,deviceId:n,integrationId:o,requestId:s,level:a,maxHeight:i="max-h-96",showScope:l=!1,showFilters:c=!0,limit:d=100,liveBuffer:f,onClose:p,className:m}){const[h,g]=$(""),[b,x]=$(""),[v,w]=$(a),y=e,N=t??(h||void 0),k=n??(b?Number(b):void 0),S=o,M=s,P=Q(()=>{const V={};return y&&(V.agentId=y),N&&(V.addonId=N),k!==void 0&&Number.isFinite(k)&&(V.deviceId=k),S&&(V.integrationId=S),M&&(V.requestId=M),Object.keys(V).length>0?V:void 0},[y,N,k,S,M]),I=On(vE),F=f??I,E=F.entries,[B,O]=$(0),[A,D]=$(!1),[_,R]=$(!1),[L,z]=$(new Set),[j,H]=$(""),T=ne(null),W=`${y??""}:${N??""}:${String(k??"")}:${S??""}:${M??""}`,G=ne(W);Y(()=>{G.current!==W&&(G.current=W,F.reset(),O(0),z(new Set))},[W,F]);const{data:ee,isLoading:se}=C.logs.query.useQuery({...P?{tags:P}:{},limit:d},{staleTime:3e4});C.logs.subscribe.useSubscription({...P?{tags:P}:{}},{onData:V=>{F.append(V)}});const te=ne(E.length);Y(()=>{const V=T.current;if(!V){te.current=E.length;return}const ie=te.current;if(te.current=E.length,!(E.length<=ie)){if(A&&V.scrollTop<=8)V.scrollTo({top:0});else if(!A&&V.scrollTop>0){const ue=V.querySelector("tbody tr"),de=ue instanceof HTMLElement?ue.offsetHeight:24;V.scrollTop+=de*(E.length-ie)}}},[E.length,A]);const X=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[...E].reverse()){const Ie=`${pe.timestamp}|${pe.level}|${pe.scope??""}|${pe.message}`;ie.has(Ie)||(ie.add(Ie),ue.push(pe))}for(const pe of V){const Ie=`${pe.timestamp}|${pe.level}|${pe.scope??""}|${pe.message}`;ie.has(Ie)||(ie.add(Ie),ue.push(pe))}const le=(B>0?ue.filter(pe=>new Date(pe.timestamp).getTime()>B):ue).filter(pe=>wE(pe.level,v)),Se=j.trim().toLowerCase();return Se?le.filter(pe=>{if(pe.message.toLowerCase().includes(Se)||pe.scope&&pe.scope.toLowerCase().includes(Se))return!0;if(pe.tags){for(const Ie of Object.values(pe.tags))if(Ie!==void 0&&String(Ie).toLowerCase().includes(Se))return!0}if(pe.meta){for(const Ie of Object.values(pe.meta))if(Ie!=null&&gu(Ie).toLowerCase().includes(Se))return!0}return!1}):le},[ee,E,v,B,j]),re=q(()=>{const V=X.map(ie=>{const ue=new Date(ie.timestamp).toLocaleTimeString(),de=ie.tags?" "+Object.entries(ie.tags).filter(([,le])=>le).map(([le,Se])=>`${le}=${Se}`).join(" "):"";return`${ue} [${ie.level.toUpperCase()}]${ie.scope?` [${ie.scope}]`:""}${de} ${ie.message}`});navigator.clipboard.writeText(V.join(`
|
|
532
532
|
`)).then(()=>{R(!0),setTimeout(()=>R(!1),1500)})},[X]),ge=C.logs.clear.useMutation(),Z=q(()=>{O(Date.now()),F.reset(),ge.mutate({...P?{tags:P}:{}})},[F,ge,P]),U=q(V=>{z(ie=>{const ue=new Set(ie);return ue.has(V)?ue.delete(V):ue.add(V),ue})},[]),[J,ae]=$(null),fe=q((V,ie)=>{const ue=new Date(V.timestamp).toISOString(),de=V.tags?" "+Object.entries(V.tags).filter(([,pe])=>pe).map(([pe,Ie])=>`${pe}=${Ie}`).join(" "):"",le=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}${le}`;navigator.clipboard.writeText(Se).then(()=>{ae(ie),setTimeout(()=>ae(pe=>pe===ie?null:pe),1200)})},[]),he=q(V=>`${V.timestamp}|${V.level}|${V.scope??""}|${V.message}`,[]);return u("div",{className:K("h-full min-h-0 flex flex-col",m),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:[r("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle font-medium",children:"Logs"}),y&&r(Wa,{label:"agent",value:y}),N&&r(Wa,{label:"addon",value:N}),k!==void 0&&r(Wa,{label:"device",value:`#${k}`}),r("div",{className:"flex rounded border border-border overflow-hidden text-[9px]",children:yE.map(V=>u("button",{type:"button",onClick:()=>w(V==="all"?void 0:V),className:K("px-1.5 py-0.5 capitalize transition-colors",V==="all"&&!v||v===V?"bg-primary/10 text-primary":"text-foreground-subtle hover:bg-surface-hover",V!=="all"&&"border-l border-border"),children:[V,V!=="all"?"+":""]},V))}),r(Ya,{icon:Ll,label:A?"Auto":"Paused",active:!A,onClick:()=>{D(V=>!V),!A&&T.current&&T.current.scrollTo({top:0,behavior:"smooth"})}}),r(Ya,{icon:Mn,label:_?"Copied!":"Copy",onClick:re,disabled:X.length===0}),r(Ya,{icon:rn,label:"Clear",onClick:Z}),u("div",{className:"relative",children:[r("input",{type:"text",value:j,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"}),j&&r("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:r(Je,{className:"h-2.5 w-2.5"})})]}),E.length>0&&u("span",{className:"text-[9px] text-emerald-400 font-medium",children:["+",E.length," live"]})]}),p&&r("button",{type:"button",onClick:p,className:"text-foreground-subtle hover:text-foreground",children:r(Je,{className:"h-3.5 w-3.5"})})]}),c&&(!t||!n)&&u("div",{className:"flex items-center gap-2 px-3 py-1 border-b border-border/50 bg-surface/50 text-[10px]",children:[!t&&u("label",{className:"flex items-center gap-1",children:[r("span",{className:"text-foreground-subtle",children:"Addon:"}),r("input",{type:"text",value:h,onChange: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:[r("span",{className:"text-foreground-subtle",children:"Device:"}),r("input",{type:"text",inputMode:"numeric",value:b,onChange:V=>x(V.target.value),placeholder:"all",className:"w-16 px-1.5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50"})]})]}),u("div",{ref:T,className:K("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:[r(Lt,{className:"h-3.5 w-3.5 animate-spin"}),"Loading logs..."]}),!se&&X.length===0&&r("div",{className:"py-4 text-center text-foreground-subtle",children:"No logs found"}),X.length>0&&r("table",{className:"w-full",children:r("tbody",{children:X.map(V=>{const ie=bu[V.level]??bu.info,ue=ie.icon,de=he(V),le=L.has(de),Se=V.tags&&Object.keys(V.tags).length>0,pe=V.meta&&Object.keys(V.meta).length>0,Ie=Se||pe;return u("tr",{className:K("hover:bg-surface-hover/30 border-b border-border/30",Ie&&"cursor-pointer"),onClick:Ie?()=>U(de):void 0,children:[r("td",{className:"px-2 py-1 text-foreground-subtle whitespace-nowrap align-top w-[70px]",children:new Date(V.timestamp).toLocaleTimeString()}),r("td",{className:K("px-1 py-1 align-top w-5",ie.color),children:r(ue,{className:"h-3 w-3"})}),l&&r("td",{className:"px-2 py-1 text-foreground-subtle align-top truncate max-w-[120px]",title:V.scope,children:V.scope?.replace(/^addon:/,"")??""}),r("td",{className:"px-2 py-1 text-foreground break-all",children:u("div",{className:"flex items-start gap-1",children:[Ie&&(le?r(Yn,{className:"h-3 w-3 text-foreground-subtle shrink-0 mt-0.5"}):r(Cn,{className:"h-3 w-3 text-foreground-subtle shrink-0 mt-0.5"})),u("div",{className:"flex-1 min-w-0",children:[V.message,le&&Ie&&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(([,Te])=>Te!==void 0&&Te!=="").map(([Te,Ye])=>u("div",{children:[r("span",{className:"text-amber-400/80 font-medium",children:Te}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground break-all",children:gu(Ye)})]},`m-${Te}`)),Se&&Object.entries(V.tags).filter(([,Te])=>Te!==void 0).map(([Te,Ye])=>u("div",{children:[r("span",{className:"text-primary/70 font-medium",children:Te}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground",children:Ye})]},`t-${Te}`))]})]})]})}),r("td",{className:"px-1 py-1 align-top w-5",children:r(NE,{copied:J===de,onCopy:()=>fe(V,de)})})]},de)})})})]})]})}function kx({position:e="bottom",className:t,...n}){return r("div",{className:K(e==="bottom"?"absolute bottom-0 left-0 right-0 z-10 border-t border-border bg-surface/95 backdrop-blur-sm":"absolute inset-x-2 bottom-2 z-10 rounded-lg border border-border bg-surface/95 backdrop-blur-sm shadow-xl",t),children:r(Wt,{maxHeight:"max-h-48",...n})})}function Wa({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 NE({copied:e,onCopy:t}){return r("button",{type:"button",title:"Copy this row",onClick:n=>{n.stopPropagation(),t()},className:K("rounded p-0.5 transition-colors",e?"text-emerald-400":"text-foreground-subtle/60 hover:text-foreground hover:bg-surface-hover"),children:e?r(wo,{className:"h-3 w-3"}):r(Mn,{className:"h-3 w-3"})})}function Ya({icon:e,label:t,onClick:n,disabled:o,active:s}){return u("button",{type:"button",onClick:n,disabled:o,className:K("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",s?"border-amber-500/30 bg-amber-500/10 text-amber-400":"border-border text-foreground-subtle hover:text-foreground",o&&"opacity-40 cursor-not-allowed"),children:[r(e,{className:"h-2.5 w-2.5"}),t]})}function kE(e,t,n,o){if(o!==void 0&&(e.source.deviceId??(e.source.type==="device"&&typeof e.source.id=="number"?e.source.id:void 0))!==o||n!==void 0&&(e.source.addonId??(e.source.type==="addon"&&typeof e.source.id=="string"?e.source.id:void 0))!==n)return!1;if(t!==void 0){const s=e.source.nodeId;if(!s||s!==t&&!s.startsWith(`${t}/`))return!1}return!0}const SE={[Ne.AddonStarted]:{icon:Bi,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Started"},[Ne.AddonInstalled]:{icon:Oi,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Installed"},[Ne.AddonRestarted]:{icon:Ol,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Restarted"},[Ne.AddonUpdated]:{icon:Tm,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Updated"},[Ne.AddonStopped]:{icon:Vd,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"Stopped"},[Ne.AddonUninstalled]:{icon:rn,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"Uninstalled"},[Ne.AddonCrashed]:{icon:Zs,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Crashed"},[Ne.AddonError]:{icon:No,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Error"},[Ne.DetectionPhaseTransition]:{icon:yn,color:"bg-violet-500/15 text-violet-400 border-violet-500/30",label:"Phase"},[Ne.DetectionResult]:{icon:Ck,color:"bg-purple-500/15 text-purple-400 border-purple-500/30",label:"Detection"},[Ne.DetectionEvent]:{icon:Xs,color:"bg-blue-500/15 text-blue-400 border-blue-500/30",label:"Event"},[Ne.DetectionCameraNative]:{icon:qd,color:"bg-cyan-500/15 text-cyan-400 border-cyan-500/30",label:"Camera AI"},[Ne.ProviderMotion]:{icon:Qd,color:"bg-orange-500/15 text-orange-400 border-orange-500/30",label:"Motion"},[Ne.MotionOnMotionChanged]:{icon:Qd,color:"bg-orange-500/15 text-orange-400 border-orange-500/30",label:"Motion"},[Ne.MotionAnalysis]:{icon:yn,color:"bg-orange-500/10 text-orange-300 border-orange-500/20",label:"Motion analysis"},[Ne.MotionZonesRaw]:{icon:yn,color:"bg-orange-500/10 text-orange-300 border-orange-500/20",label:"Motion zones"},[Ne.ProviderDetection]:{icon:qd,color:"bg-cyan-500/15 text-cyan-400 border-cyan-500/30",label:"Provider Det"},[Ne.PipelineAudioInferenceResult]:{icon:Pm,color:"bg-pink-500/15 text-pink-400 border-pink-500/30",label:"Audio"},[Ne.AgentOnline]:{icon:Bi,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Agent Online"},[Ne.AgentOffline]:{icon:Vd,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Agent Offline"},[Ne.DeviceRegistered]:{icon:Oi,color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",label:"Registered"},[Ne.DeviceUnregistered]:{icon:rn,color:"bg-red-500/15 text-red-400 border-red-500/30",label:"Unregistered"},[Ne.DeviceStateChanged]:{icon:yn,color:"bg-foreground-subtle/10 text-foreground-subtle border-border",label:"State"}};function Ki(e,t){const n=SE[e]??{icon:Bi,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 o=t.capName;return{...n,label:o}}return n}const sr=Object.freeze([...new Set(Object.values(Ne))].sort()),CE=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]),ME=new Set(CE),IE=Object.freeze(sr.filter(e=>!ME.has(e)));function fs(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,o=t.error;return o||(n?`addon: ${n}`:null)}function AE(e){const t=e.category;return t===Ne.DetectionResult||t===Ne.PipelineAudioInferenceResult?fs(t,e.data)!==null:!0}const PE=300;function nr({agentId:e,addonId:t,deviceId:n,defaultCategories:o,categories:s,category:a,maxHeight:i="max-h-96",limit:l=50,showCategoryFilter:c=!0,showFilters:d=!1,liveBuffer:f,onClose:p,className:m}){const h=Q(()=>o??s??IE,[o,s]),g=Q(()=>[...h].sort().join(","),[h]),[b,x]=$(()=>new Set(h)),v=ne(g);Y(()=>{v.current!==g&&(v.current=g,x(new Set(h)))},[g,h]);const w=On(PE),y=f??w,N=y.entries,[k,S]=$(!0),[M,P]=$(new Set),[I,F]=$(""),[E,B]=$(!1),[O,A]=$(""),[D,_]=$(0),R=ne(null),L=ne(null),z=`${e??""}:${t??""}:${String(n??"")}:${a??""}`,j=ne(z);Y(()=>{j.current!==z&&(j.current=z,y.reset(),P(new Set),_(0))},[z,y]),Y(()=>{if(!E)return;const me=Ee=>{const _e=L.current;_e&&Ee.target instanceof Node&&!_e.contains(Ee.target)&&B(!1)};return document.addEventListener("mousedown",me),()=>{document.removeEventListener("mousedown",me)}},[E]);const H=Q(()=>{const me={};return e&&(me.agentId=e),t&&(me.addonId=t),n!==void 0&&(me.deviceId=n),a&&(me.category=a),me},[e,t,n,a]),T=Q(()=>[...b].sort(),[b]),W=Q(()=>T.join(","),[T]),G=Q(()=>{const me={...H,limit:l};return T.length>0&&T.length<sr.length&&(me.category=T),me},[H,l,W,T]),{data:ee,isLoading:se}=C.systemEvents.getRecent.useQuery(G,{staleTime:3e4}),te=ne(b);Y(()=>{te.current=b},[b]);const X=H;C.systemEvents.subscribe.useSubscription(X,{onData:me=>{const Ee=me;Ee?.id&&kE(Ee,e,t,n)&&te.current.has(Ee.category)&&y.append(Ee)}});const re=ne(N.length);Y(()=>{const me=R.current;if(!me){re.current=N.length;return}const Ee=re.current;if(re.current=N.length,!(N.length<=Ee)){if(k&&me.scrollTop<=8)me.scrollTo({top:0});else if(!k&&me.scrollTop>0){const _e=me.firstElementChild?.firstElementChild,Re=_e instanceof HTMLElement?_e.offsetHeight:28;me.scrollTop+=Re*(N.length-Ee)}}},[N.length,k]);const ge=Q(()=>{const me=new Map;for(const Re of ee??[])me.set(Re.id,Re);for(const Re of N)me.set(Re.id,Re);let Ee=[...me.values()].filter(Re=>b.has(Re.category)).filter(AE);D>0&&(Ee=Ee.filter(Re=>new Date(Re.timestamp).getTime()>D));const _e=I.trim().toLowerCase();return _e&&(Ee=Ee.filter(Re=>{if(Re.category.toLowerCase().includes(_e)||Ki(Re.category,Re.data).label.toLowerCase().includes(_e))return!0;const Pn=fs(Re.category,Re.data);if(Pn&&Pn.toLowerCase().includes(_e))return!0;try{if(new Date(Re.timestamp).toLocaleTimeString().toLowerCase().includes(_e))return!0}catch{}try{if(JSON.stringify(Re.data).toLowerCase().includes(_e)||JSON.stringify(Re.source).toLowerCase().includes(_e))return!0}catch{}return!1})),Ee.sort((Re,An)=>new Date(An.timestamp).getTime()-new Date(Re.timestamp).getTime())},[ee,N,b,I,D]),Z=q(me=>{P(Ee=>{const _e=new Set(Ee);return _e.has(me)?_e.delete(me):_e.add(me),_e})},[]),U=q(me=>{x(Ee=>{const _e=new Set(Ee);return _e.has(me)?_e.delete(me):_e.add(me),_e})},[]),J=q(()=>{x(new Set(h)),F(""),_(0)},[h]),ae=q(()=>{_(Date.now()),y.reset()},[y]),[fe,he]=$(!1),[V,ie]=$(null),ue=q(me=>{const Ee=new Date(me.timestamp).toISOString(),_e=fs(me.category,me.data)??"",Re=_e?` ${_e}`:"";return`${Ee} [${me.category}]${Re} data=${JSON.stringify(me.data)}`},[]),de=q(()=>{const me=ge.map(ue);navigator.clipboard.writeText(me.join(`
|
|
533
533
|
`)).then(()=>{he(!0),setTimeout(()=>he(!1),1500)})},[ge,ue]),le=q(me=>{navigator.clipboard.writeText(ue(me)).then(()=>{ie(me.id),setTimeout(()=>ie(Ee=>Ee===me.id?null:Ee),1200)})},[ue]),Se=q(()=>{x(new Set(sr))},[]),pe=q(()=>{x(new Set)},[]),Ie=Q(()=>{const me=O.trim().toLowerCase();return me?sr.filter(Ee=>Ee.toLowerCase().includes(me)):sr},[O]),Te=sr.length,Ye=b.size,ot=Ye===Te,rr=ot?"All":`${Ye}/${Te}`;return u("div",{className:K("h-full min-h-0 flex flex-col",m),onClick:me=>me.stopPropagation(),children:[u("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0",children:[u("div",{className:"flex items-center gap-2 flex-wrap",children:[r("span",{className:"text-[10px] uppercase tracking-wide text-foreground-subtle font-medium",children:"Events"}),e&&r(jo,{label:"agent",value:e}),t&&r(jo,{label:"addon",value:t}),n!==void 0&&r(jo,{label:"device",value:`#${n}`}),a&&r(jo,{label:"category",value:a}),u("button",{type:"button",onClick:()=>{S(me=>!me),!k&&R.current&&R.current.scrollTo({top:0,behavior:"smooth"})},className:K("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",k?"border-border text-foreground-subtle hover:text-foreground":"border-amber-500/30 bg-amber-500/10 text-amber-400"),children:[r(Ll,{className:"h-2.5 w-2.5"}),k?"Auto":"Paused"]}),c&&u("div",{className:"relative",ref:L,children:[u("button",{type:"button",onClick:()=>B(me=>!me),className:K("inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors",ot?"border-border text-foreground-subtle hover:text-foreground":"border-violet-500/30 bg-violet-500/10 text-violet-400"),title:"Pick events to track",children:[r(Mm,{className:"h-2.5 w-2.5"}),"Filter (",rr,")"]}),E&&r(EE,{search:O,onSearchChange:A,categories:Ie,active:b,onToggle:U,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:[r(_m,{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:[r(rn,{className:"h-2.5 w-2.5"}),"Clear"]}),u("button",{type:"button",onClick:de,disabled:ge.length===0,className:K("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",ge.length===0&&"opacity-40 cursor-not-allowed"),title:"Copy all visible events",children:[r(Mn,{className:"h-2.5 w-2.5"}),fe?"Copied!":"Copy"]}),u("div",{className:"relative",children:[r("input",{type:"text",value:I,onChange:me=>F(me.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&&r("button",{type:"button",onClick:()=>F(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground",title:"Clear search",children:r(Je,{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&&r("button",{type:"button",onClick:p,className:"text-foreground-subtle hover:text-foreground",children:r(Je,{className:"h-3.5 w-3.5"})})]}),u("div",{ref:R,className:K("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:[r(Lt,{className:"h-3.5 w-3.5 animate-spin"}),"Loading events..."]}),!se&&ge.length===0&&r("div",{className:"py-4 text-center text-foreground-subtle",children:"No events found"}),ge.length>0&&r("div",{className:"divide-y divide-border/30",children:ge.map(me=>{const Ee=Ki(me.category,me.data),_e=Ee.icon,Re=fs(me.category,me.data),An=M.has(me.id);return u("div",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-surface-hover/30 cursor-pointer",onClick:()=>Z(me.id),children:[r("span",{className:"text-foreground-subtle whitespace-nowrap w-[70px] shrink-0 pt-0.5",children:new Date(me.timestamp).toLocaleTimeString()}),r(_E,{copied:V===me.id,onCopy:()=>le(me)}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex items-center gap-1.5",children:[An?r(Yn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}):r(Cn,{className:"h-3 w-3 text-foreground-subtle shrink-0"}),u("span",{className:K("inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[9px] font-medium",Ee.color),children:[r(_e,{className:"h-2.5 w-2.5"}),Ee.label]}),me.source.nodeId&&me.source.nodeId!=="hub"&&r("span",{className:"text-[9px] px-1 py-0.5 rounded bg-foreground-subtle/10 text-foreground-subtle font-mono",children:me.source.nodeId})]}),Re&&r("p",{className:"text-foreground-subtle text-[10px] mt-0.5 ml-5",children:Re}),An&&u("div",{className:"mt-1 ml-5 text-[9px] bg-surface rounded px-2 py-1.5 space-y-0.5 font-mono overflow-x-auto",children:[u("div",{children:[r("span",{className:"text-primary/70",children:"source"}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground",children:JSON.stringify(me.source)})]}),u("div",{children:[r("span",{className:"text-primary/70",children:"category"}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground",children:me.category})]}),Object.entries(me.data).map(([Pn,Or])=>u("div",{children:[r("span",{className:"text-primary/70",children:Pn}),r("span",{className:"text-foreground-subtle",children:": "}),r("span",{className:"text-foreground break-all",children:typeof Or=="object"?JSON.stringify(Or):String(Or)})]},Pn))]})]})]},me.id)})})]})]})}function EE({search:e,onSearchChange:t,categories:n,active:o,onToggle:s,onSelectAll:a,onSelectNone:i,onResetDefaults:l}){return u("div",{className:"absolute z-20 top-full mt-1 left-0 w-72 max-h-80 rounded-md border border-border bg-surface shadow-lg flex flex-col",onClick:c=>c.stopPropagation(),children:[u("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border/50",children:[r(oo,{className:"h-3 w-3 text-foreground-subtle"}),r("input",{type:"text",value:e,onChange:c=>t(c.target.value),placeholder:"Filter categories…",className:"flex-1 bg-transparent text-[10px] focus:outline-none text-foreground placeholder:text-foreground-subtle",autoFocus:!0}),e&&r("button",{type:"button",onClick:()=>t(""),className:"text-foreground-subtle hover:text-foreground",children:r(Je,{className:"h-2.5 w-2.5"})})]}),u("div",{className:"flex items-center gap-1 px-2 py-1 border-b border-border/50 text-[9px]",children:[r("button",{type:"button",onClick:a,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"All"}),r("button",{type:"button",onClick:i,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"None"}),r("button",{type:"button",onClick:l,className:"px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground",children:"Defaults"})]}),u("div",{className:"overflow-y-auto flex-1",children:[n.length===0&&r("div",{className:"text-[10px] text-foreground-subtle italic px-2 py-3 text-center",children:"No matches"}),n.map(c=>{const d=o.has(c),f=Ki(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:[r("input",{type:"checkbox",readOnly:!0,checked:d,className:"accent-violet-500"}),u("span",{className:K("inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[9px] font-medium shrink-0",f.color),children:[r(p,{className:"h-2.5 w-2.5"}),f.label]}),r("span",{className:"text-foreground-subtle font-mono truncate",children:c})]},c)})]})]})}function $E({position:e="bottom",className:t,...n}){return r("div",{className:K(e==="bottom"?"absolute bottom-0 left-0 right-0 z-10 border-t border-border bg-surface/95 backdrop-blur-sm":"absolute inset-x-2 bottom-2 z-10 rounded-lg border border-border bg-surface/95 backdrop-blur-sm shadow-xl",t),children:r(nr,{maxHeight:"max-h-48",...n})})}function jo({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 _E({copied:e,onCopy:t}){return r("button",{type:"button",title:"Copy this event",onClick:n=>{n.stopPropagation(),t()},className:K("rounded p-0.5 transition-colors mt-0.5",e?"text-emerald-400":"text-foreground-subtle/60 hover:text-foreground hover:bg-surface-hover"),children:e?r(wo,{className:"h-3 w-3"}):r(Mn,{className:"h-3 w-3"})})}function Sx({deviceId:e,className:t="",onOpenChild:n}){const o=C.useUtils(),s=C.deviceDiscovery.listDiscovered.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),a=C.deviceDiscovery.getStatus.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),i=C.deviceDiscovery.refreshDiscovery.useMutation({onSuccess:()=>{o.deviceDiscovery.listDiscovered.invalidate({deviceId:e}),o.deviceDiscovery.getStatus.invalidate({deviceId:e})}}),l=C.deviceDiscovery.adoptDevice.useMutation({onSuccess:()=>{o.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),c=C.deviceDiscovery.releaseDevice.useMutation({onSuccess:()=>{o.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),[d,f]=$(null),{available:p,adopted:m}=Q(()=>{const y=s.data??[],N=S=>typeof S.metadata.rtspChannel=="number"?S.metadata.rtspChannel:Number.POSITIVE_INFINITY,k=(S,M)=>{const P=N(S),I=N(M);return P!==I?P-I:S.name.localeCompare(M.name)};return{available:y.filter(S=>!S.alreadyAdopted).sort(k),adopted:y.filter(S=>S.alreadyAdopted).sort(k)}},[s.data]),h=a.data,g=h?.lastError??null,b=h?.lastDiscoveryAt??null;async function x(){await i.mutateAsync({deviceId:e}).catch(()=>{})}async function v(y){f(y.childNativeId);try{await l.mutateAsync({deviceId:e,childNativeId:y.childNativeId})}finally{f(null)}}async function w(y){if(y.adoptedDeviceId!=null){f(y.childNativeId);try{await c.mutateAsync({deviceId:e,childDeviceId:y.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:[r("h3",{className:"text-sm font-semibold text-foreground",children:"Discovered devices"}),u("p",{className:"text-[11px] text-foreground-subtle",children:["Channels behind this hub. Click ",r("span",{className:"font-medium",children:"Add"})," to promote a channel to a managed device, or ",r("span",{className:"font-medium",children:"Remove"})," to detach."]})]}),u("button",{type:"button",onClick:x,disabled:i.isPending,className:"inline-flex items-center gap-1.5 rounded-lg border border-border px-2 py-1.5 sm:px-3 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 shrink-0",children:[i.isPending?r(Lt,{className:"h-3.5 w-3.5 animate-spin"}):r(Ol,{className:"h-3.5 w-3.5"}),r("span",{className:"hidden sm:inline",children:"Refresh"})]})]}),g?u("div",{className:"flex items-start gap-2 border-b border-border bg-destructive/10 px-5 py-2 text-[11px] text-destructive",children:[r(No,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),u("span",{children:["Last refresh failed: ",g]})]}):null,s.isLoading?r("div",{className:"flex items-center justify-center py-8 text-foreground-subtle",children:r(Lt,{className:"h-5 w-5 animate-spin"})}):p.length===0&&m.length===0?r("div",{className:"px-5 py-8 text-center text-xs text-foreground-subtle",children:"No channels reported by the hub yet. Click Refresh to enumerate."}):u(ve,{children:[p.length>0?r(yu,{title:"Available to add",count:p.length,tone:"primary",children:p.map(y=>r(vu,{child:y,busy:d===y.childNativeId,onAdopt:v,onRelease:w,onOpenChild:n},y.childNativeId))}):null,m.length>0?r(yu,{title:"Already adopted",count:m.length,tone:"muted",children:m.map(y=>r(vu,{child:y,busy:d===y.childNativeId,onAdopt:v,onRelease:w,onOpenChild:n},y.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 yu({title:e,count:t,tone:n,children:o}){return u("div",{className:"border-t border-border",children:[u("div",{className:`flex items-center justify-between border-b px-3 sm:px-5 py-1.5 text-[10px] uppercase tracking-wider ${n==="primary"?"bg-primary/5 text-primary border-primary/30":"bg-surface text-foreground-subtle border-border"}`,children:[r("span",{className:"font-semibold",children:e}),r("span",{className:"font-mono",children:t})]}),r("div",{className:"divide-y divide-border",children:o})]})}function vu({child:e,busy:t,onAdopt:n,onRelease:o,onOpenChild:s}){return u("div",{className:"flex flex-wrap items-center justify-between gap-2 px-3 py-2 sm:px-5 sm:py-3 sm:flex-nowrap sm:gap-3",children:[u("div",{className:"min-w-0 flex-1",children:[u("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[r(DE,{status:e.status}),r("span",{className:"truncate text-sm font-medium text-foreground",children:e.name}),e.metadata.isDoorbell?r("span",{className:"rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle",children:"Doorbell"}):null,e.metadata.isBattery?r("span",{className:"rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle",children:"Battery"}):null,e.metadata.isMultifocal?r("span",{className:"rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle",children:"Multifocal"}):null]}),u("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle",children:[typeof e.metadata.rtspChannel=="number"?u("span",{children:["ch ",r("span",{className:"font-mono",children:e.metadata.rtspChannel})]}):null,e.metadata.model?r("span",{className:"truncate max-w-[160px]",children:e.metadata.model}):null,e.metadata.uid?u("span",{className:"font-mono truncate max-w-[140px]",children:[e.metadata.uid.slice(0,12),"…"]}):null]})]}),e.alreadyAdopted?u("div",{className:"flex items-center gap-2",children:[s&&e.adoptedDeviceId!==null?u("button",{type:"button",onClick:()=>s(e.adoptedDeviceId),className:"inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors",title:"Open device detail",children:[r(Sm,{className:"h-3.5 w-3.5"}),"Open"]}):null,u("button",{type:"button",onClick:()=>{o(e)},disabled:t,className:"inline-flex items-center gap-1.5 rounded-lg border border-destructive/30 px-3 py-1.5 text-xs text-destructive hover:bg-destructive/10 transition-colors disabled:opacity-50",children:[t?r(Lt,{className:"h-3.5 w-3.5 animate-spin"}):r(rn,{className:"h-3.5 w-3.5"}),"Remove"]})]}):u("button",{type:"button",onClick:()=>{n(e)},disabled:t,className:"inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50",children:[t?r(Lt,{className:"h-3.5 w-3.5 animate-spin"}):r(Js,{className:"h-3.5 w-3.5"}),"Add"]})]})}function DE({status:e}){switch(e){case"online":return u("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/40 bg-emerald-500/10 px-2 py-0.5 text-[10px] font-medium text-emerald-500",children:[r(Rm,{className:"h-2.5 w-2.5"})," online"]});case"sleeping":return u("span",{className:"inline-flex items-center gap-1 rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] font-medium text-amber-500",children:[r(Rl,{className:"h-2.5 w-2.5"})," sleeping"]});case"offline":return u("span",{className:"inline-flex items-center gap-1 rounded-full border border-destructive/40 bg-destructive/10 px-2 py-0.5 text-[10px] font-medium text-destructive",children:[r(n5,{className:"h-2.5 w-2.5"})," offline"]});case"unknown":default:return u("span",{className:"inline-flex items-center gap-1 rounded-full border border-border bg-surface px-2 py-0.5 text-[10px] font-medium text-foreground-subtle",children:[r(vm,{className:"h-2.5 w-2.5"})," unknown"]})}}function LE(e,t){if(!e||typeof e!="object")return!1;const n=e;if(n.category!==Ne.DeviceStateChanged)return!1;const o=n.data;return!(!o||typeof o!="object"||o.deviceId!==t||typeof o.capName!="string"||!o.slice||typeof o.slice!="object")}function Za(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.id=="string"?t.id:null,o=typeof t.timestamp=="string"?t.timestamp:null,s=t.data;return!n||!o||!s||typeof s!="object"||typeof s.capName!="string"||!s.slice||typeof s.slice!="object"?null:{id:n,timestamp:o,capName:s.capName,slice:s.slice}}const TE=300,RE=Object.freeze([...new Set(ow.filter(e=>e.scope==="device").map(e=>e.name))].sort());function Pc({deviceId:e,defaultCaps:t,maxHeight:n="max-h-96",limit:o=50,liveBuffer:s,onClose:a,className:i}){const l=Q(()=>new Set(t??[]),[t]),[c,d]=$(l),[f,p]=$(""),[m,h]=$(!0),[g,b]=$(new Set),[x,v]=$(0),[w,y]=$(!1),[N,k]=$(""),S=ne(null),M=On(TE),P=s??M,I=P.entries,F=ne(null),E=ne(e);Y(()=>{E.current!==e&&(E.current=e,P.reset(),b(new Set),v(0))},[e,P]);const B=Q(()=>({deviceId:e,category:Ne.DeviceStateChanged,limit:o}),[e,o]),{data:O,isLoading:A}=C.systemEvents.getRecent.useQuery(B,{staleTime:3e4}),D=ne(c);Y(()=>{D.current=c},[c]),C.systemEvents.subscribe.useSubscription({deviceId:e,category:Ne.DeviceStateChanged},{onData:V=>{if(!LE(V,e))return;const ie=Za(V);if(!ie)return;const ue=D.current;ue.size>0&&!ue.has(ie.capName)||P.append(ie)}});const _=ne(I.length);Y(()=>{const V=F.current;if(!V){_.current=I.length;return}const ie=_.current;if(_.current=I.length,!(I.length<=ie)){if(m&&V.scrollTop<=8)V.scrollTo({top:0});else if(!m&&V.scrollTop>0){const ue=V.firstElementChild?.firstElementChild,de=ue instanceof HTMLElement?ue.offsetHeight:28,le=I.length-ie;V.scrollTop+=de*le}}},[I.length,m]);const R=Q(()=>{const V=new Map;for(const de of O??[]){const le=Za(de);le&&V.set(le.id,le)}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}=${Xa(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,le)=>new Date(le.timestamp).getTime()-new Date(de.timestamp).getTime())},[O,I,c,f,x]),L=Q(()=>{const V=new Set(RE);for(const ie of O??[]){const ue=Za(ie);ue&&V.add(ue.capName)}for(const ie of I)V.add(ie.capName);return[...V].sort()},[O,I]),z=q(V=>{b(ie=>{const ue=new Set(ie);return ue.has(V)?ue.delete(V):ue.add(V),ue})},[]),j=q(V=>{d(ie=>{const ue=new Set(ie);return ue.has(V)?ue.delete(V):ue.add(V),ue})},[]),H=q(()=>{d(new Set(t??[])),p("")},[t]),T=q(()=>{v(Date.now()),P.reset()},[P]),[W,G]=$(!1),[ee,se]=$(null),te=q(V=>`${new Date(V.timestamp).toISOString()} [${V.capName}] slice=${JSON.stringify(V.slice)}`,[]),X=q(()=>{const V=R.map(te);navigator.clipboard.writeText(V.join(`
|