@camstack/addon-admin-ui 1.2.309 → 1.2.312
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/{AddonCollectionPage-DfDB2mq9.js → AddonCollectionPage-D_jT_fKd.js} +1 -1
- package/dist/assets/Addons-Dm22iIFC.js +1 -0
- package/dist/assets/{AdminTabs-DxmhnOA4.js → AdminTabs-BLa2Yu61.js} +1 -1
- package/dist/assets/AiProfiles-C1FiOjIi.js +3 -0
- package/dist/assets/{BrokerForm-CwkfwR8i.js → BrokerForm-W3yjLc5F.js} +1 -1
- package/dist/assets/Build-D42X2om2.js +32 -0
- package/dist/assets/{Capabilities-BXH0dd9S.js → Capabilities-DgQeevtK.js} +1 -1
- package/dist/assets/{CapabilityBadges-Dn7AXuW_.js → CapabilityBadges-PxEJ-G8M.js} +1 -1
- package/dist/assets/Cluster-CYJRjTNq.js +11 -0
- package/dist/assets/CompositionEditor-BR4ITRMC.js +1 -0
- package/dist/assets/{CompositionEditorPage-C7XC86xi.js → CompositionEditorPage-B9FazR7t.js} +1 -1
- package/dist/assets/Data-BZ997zDU.js +1 -0
- package/dist/assets/DetectionIntelligence-CoZLbnyz.js +1 -0
- package/dist/assets/{DeviceAggregateSection-DaWUMVM_.js → DeviceAggregateSection-DGRRUhpU.js} +1 -1
- package/dist/assets/DeviceDetail-X4_H5AEU.js +2 -0
- package/dist/assets/{Devices-B910dZmw.js → Devices-D2avtpSh.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-BZT10fAL.js → EmbedPlayerPage-DndXvLAf.js} +1 -1
- package/dist/assets/Events-DcBl0VuS.js +1 -0
- package/dist/assets/FormBuilder-DcvB5DXc.js +1 -0
- package/dist/assets/Identity-BFps8fGD.js +1 -0
- package/dist/assets/IntegrationDetail-cLLqyAlF.js +1 -0
- package/dist/assets/Integrations--caPrwcY.js +1 -0
- package/dist/assets/Integrations-CKkdQ5eX.js +1 -0
- package/dist/assets/Locations-DCOaDC4m.js +3 -0
- package/dist/assets/{Logs-DHU8ME8r.js → Logs-CVsufO3f.js} +1 -1
- package/dist/assets/{ModelLicenses-wNL-QqNC.js → ModelLicenses-C53LveOk.js} +1 -1
- package/dist/assets/{MotionZonesSettings-BOo01f0b.js → MotionZonesSettings-BP6JgzDx.js} +1 -1
- package/dist/assets/{MyAccess-CnAKwSSc.js → MyAccess-BPy91g8M.js} +1 -1
- package/dist/assets/Network-BH8GF1jj.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-B7GDs7Q9.js → NodeAddonsSettingsPanel-DaUaDmgN.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-CAH77n84.js → NodeInferenceDevices-CV8hPlUN.js} +1 -1
- package/dist/assets/Notifications-B2HuQQif.js +1 -0
- package/dist/assets/Pipeline-VFKCmqnk.js +1 -0
- package/dist/assets/Plates-CwmrYBy1.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-DvrlDBhA.js → PrivacyMaskSettings-DrGP3agd.js} +1 -1
- package/dist/assets/{ProviderIcon-BeS1q8Rf.js → ProviderIcon-DpDrKQg9.js} +1 -1
- package/dist/assets/Recordings-wBHDYR-a.js +1 -0
- package/dist/assets/{ScanNetworkModal-BjBfm97i.js → ScanNetworkModal-Bs0BPCl_.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-Cd9vKq8k.js → SceneMonitorEditor-BKRn3LUw.js} +1 -1
- package/dist/assets/{Scenes-TxX32cBu.js → Scenes-AZ844W8Q.js} +1 -1
- package/dist/assets/{Settings-C3794LJM.js → Settings-C3eJAyF_.js} +1 -1
- package/dist/assets/{Showroom-CnFb5-UE.js → Showroom-CrjPa3nO.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-CAC8Rq6D.js → StorageLocationsPanel-DZBpj1S8.js} +1 -1
- package/dist/assets/{Terminal-BDjPoF0A.js → Terminal-DP9Z-4oI.js} +3 -3
- package/dist/assets/{Viewer-CreAyV1k.js → Viewer-BdSLJVFV.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-oI6UR7Sc.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BzFC5oNH.js} +1 -1
- package/dist/assets/{archive-CPBvgIqJ.js → archive--Adx9xt7.js} +1 -1
- package/dist/assets/{authed-media-2_-kYrP3.js → authed-media-BjiwUfzl.js} +1 -1
- package/dist/assets/{boxes-CW5AuMy7.js → boxes-C9etGa7E.js} +1 -1
- package/dist/assets/circle-slash-cB0daX9J.js +1 -0
- package/dist/assets/{debounced-invalidate-DE5pKSOE.js → debounced-invalidate-D_ADe-pO.js} +1 -1
- package/dist/assets/{device-integration-icon-BSLLy94_.js → device-integration-icon-CDQck2H0.js} +1 -1
- package/dist/assets/{dist-zmoGT7Gu.js → dist-CLDbTq6j.js} +3 -3
- package/dist/assets/{dist-CSp3gDPo.js → dist-Dhc7r6s3.js} +1 -1
- package/dist/assets/{face-bbox-D5H5wJEP.js → face-bbox-BMJUn0ul.js} +1 -1
- package/dist/assets/{hard-drive-download-D75f3X09.js → hard-drive-download-_iraTBzr.js} +1 -1
- package/dist/assets/{hostInit-BGs5TZwj.js → hostInit-BUbZdY_9.js} +1 -1
- package/dist/assets/index-ToaOKO9V.js +4 -0
- package/dist/assets/{layers-DGrwhNHF.js → layers-DiVzoqI9.js} +1 -1
- package/dist/assets/{location-owned-usage-DmVfd_sN.js → location-owned-usage-BYFxxj5I.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-1d0a7067.js → mf-entry-bootstrap-0-eaedec53.js} +2 -2
- package/dist/assets/{player-overlays-BQsHwEhF.js → player-overlays-CW14DMpN.js} +1 -1
- package/dist/assets/remoteEntry-Cor8-DvN.js +1 -0
- package/dist/assets/{send-C9Ra25bz.js → send-CPgogH5c.js} +1 -1
- package/dist/assets/{settings-2-BpUmiqRR.js → settings-2-Ch5_hcKD.js} +1 -1
- package/dist/assets/{square-check-big-C7grRhDO.js → square-check-big-znl8trUW.js} +1 -1
- package/dist/assets/src-DIrDyFmq.js +67 -0
- package/dist/assets/src-JqpYwj-l.js +349 -0
- package/dist/assets/{use-scenes-feed-Dr06_e3L.js → use-scenes-feed-YEEHIE1o.js} +1 -1
- package/dist/assets/{use-stationary-objects-pBTdGYcS.js → use-stationary-objects-DOl51SBk.js} +1 -1
- package/dist/assets/{useDevice-B9iEONPT.js → useDevice-C8SXb13_.js} +1 -1
- package/dist/assets/useEventInvalidation-B86vUgTW.js +1 -0
- package/dist/assets/{useNodeUrlSelection-zcbHXTK_.js → useNodeUrlSelection-BGtbjkMI.js} +1 -1
- package/dist/assets/user-round-D9U1WJod.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DfqZUgL6.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BaoDsuWl.js} +2 -2
- package/dist/index.html +5 -5
- package/dist/server/addon.js +79 -24
- package/package.json +1 -1
- package/dist/assets/Addons-BmF6QJjq.js +0 -1
- package/dist/assets/AiProfiles-WyKxGEnm.js +0 -3
- package/dist/assets/Build-CpSrckHu.js +0 -32
- package/dist/assets/Cluster-DNC6op-4.js +0 -11
- package/dist/assets/CompositionEditor-BaeVNz7c.js +0 -1
- package/dist/assets/Data-DPv4QjP_.js +0 -1
- package/dist/assets/DetectionIntelligence-B1ufxTut.js +0 -1
- package/dist/assets/DeviceDetail-CyKo2o-W.js +0 -2
- package/dist/assets/Events-CiXQRykv.js +0 -1
- package/dist/assets/FormBuilder-alW8XL-9.js +0 -1
- package/dist/assets/Identity-C-QYUex9.js +0 -1
- package/dist/assets/IntegrationDetail-CTNmCNSj.js +0 -1
- package/dist/assets/Integrations-DIESuQ9O.js +0 -1
- package/dist/assets/Integrations-IV9f6F-m.js +0 -1
- package/dist/assets/Locations-hlNJgk-2.js +0 -3
- package/dist/assets/Network-DtKUhXlu.js +0 -1
- package/dist/assets/Notifications-DkxqJ__w.js +0 -1
- package/dist/assets/Pipeline-DkOxZ075.js +0 -1
- package/dist/assets/Plates-B8aiSB7g.js +0 -1
- package/dist/assets/Recordings-D7_5bDg0.js +0 -1
- package/dist/assets/circle-slash-CWusOAgX.js +0 -1
- package/dist/assets/device-picker-model-qVKFWw6-.js +0 -1
- package/dist/assets/index-DRfmHS9g.js +0 -4
- package/dist/assets/remoteEntry-hicAutTF.js +0 -1
- package/dist/assets/src-AIYVh4G3.js +0 -67
- package/dist/assets/src-BUUu3NWL.js +0 -349
- package/dist/assets/useEventInvalidation-DUUiiikb.js +0 -1
- package/dist/assets/user-round-D6wAMHCi.js +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,V as i,W as a,a as o,b as s,o as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{G as p,U as m,W as h,X as g,_,at as v,ht as y,lt as b,mt as x,q as S,r as C,st as w,t as T,ut as E,vt as D,yt as O}from"./player-overlays-BQsHwEhF.js";import{$ as k,$c as A,$l as j,$o as M,$t as N,$u as P,Ao as F,Bi as I,Bo as ee,Ci as L,Ct as R,Du as te,Et as ne,Eu as z,F as re,Fi as B,Fr as V,G as ie,Gl as H,Gr as ae,Gt as oe,Hi as se,Ht as ce,Hu as le,Il as ue,Io as de,Ir as fe,It as pe,J as U,Jl as me,Jr as he,K as ge,Kc as _e,Kl as ve,L as ye,Ll as be,Lt as xe,Lu as Se,M as Ce,Mo as W,Mt as we,N as Te,No as Ee,Nt as De,Oi as Oe,Ot as ke,P as Ae,Pi as je,Pt as Me,Pu as Ne,Q as Pe,Qo as Fe,R as Ie,Rl as Le,Rr as Re,Rt as ze,S as Be,Ss as Ve,St as He,T as Ue,Ti as We,Tt as Ge,U as Ke,Ua as qe,Ut as Je,V as Ye,Vi as Xe,Vl as Ze,Vr as Qe,W as $e,Wc as et,Wi as tt,Wr as nt,Wt as rt,X as it,Xa as at,Xc as ot,Xn as st,Xu as ct,Ya as lt,Yc as ut,Yl as dt,Yr as ft,Yu as pt,Z as mt,Zl as ht,Zu as gt,_a as _t,_i as vt,_n as yt,_t as bt,a as xt,an as St,b as Ct,bi as wt,bl as Tt,bn as Et,bt as Dt,c as Ot,ct as kt,d as At,di as jt,dt as Mt,en as Nt,es as Pt,et as Ft,f as It,fi as Lt,fr as Rt,fu as zt,gi as Bt,gn as Vt,gt as Ht,hi as Ut,hn as Wt,i as Gt,in as Kt,iu as qt,j as Jt,jl as Yt,k as Xt,kl as Zt,ko as Qt,l as $t,ln as G,nn as en,nt as tn,o as nn,oi as rn,on as an,pa as on,q as sn,qi as cn,ql as ln,qr as un,r as dn,ri as fn,ru as pn,s as mn,ss as hn,tn as gn,ts as _n,tt as vn,u as yn,ud as bn,un as xn,v as Sn,va as Cn,vi as wn,vt as Tn,wt as En,x as Dn,xt as On,ya as kn,yi as An,zc as jn,zi as Mn,zr as Nn}from"./src-AIYVh4G3.js";import{t as Pn}from"./archive-CPBvgIqJ.js";import{t as Fn}from"./boxes-CW5AuMy7.js";import{t as In}from"./ProviderIcon-BeS1q8Rf.js";import{t as Ln}from"./circle-slash-CWusOAgX.js";import{n as Rn}from"./NodeInferenceDevices-CAH77n84.js";import{t as zn}from"./layers-DGrwhNHF.js";import{t as Bn}from"./CapabilityBadges-Dn7AXuW_.js";import{At as Vn,Bt as Hn,En as Un,Jn as Wn,Ln as Gn,Lt as Kn,Mt as qn,Nn as Jn,Ot as Yn,Pn as K,Rn as Xn,Rt as Zn,Sn as Qn,Vt as $n,_r as er,bn as tr,fn as nr,gr as rr,jn as ir,jt as ar,kt as or,nn as sr,qn as cr,rn as lr,tn as ur,wn as dr,zn as q}from"./src-BUUu3NWL.js";import{_ as fr,a as pr,d as mr,f as hr,h as gr,l as J,m as _r,p as vr,r as yr,t as br,u as xr}from"./index-DRfmHS9g.js";import{n as Sr,t as Cr}from"./useDevice-B9iEONPT.js";import{C as wr,E as Tr,S as Y,T as Er,_ as Dr,a as Or,b as kr,c as Ar,d as jr,f as Mr,g as Nr,h as Pr,i as Fr,l as Ir,m as Lr,n as Rr,o as zr,p as Br,r as Vr,s as Hr,t as Ur,u as Wr,v as Gr,x as Kr,y as qr}from"./CompositionEditor-BaeVNz7c.js";import{t as Jr}from"./authed-media-2_-kYrP3.js";import"./useEventInvalidation-DUUiiikb.js";import{t as Yr}from"./StatusBadge-CeptlsPG.js";import{t as Xr}from"./use-stationary-objects-pBTdGYcS.js";import{x as Zr,y as Qr}from"./device-picker-model-qVKFWw6-.js";import{a as $r,i as ei,n as ti,r as ni,t as ri}from"./DeviceAggregateSection-DaWUMVM_.js";var ii=O(`arrow-left-right`,[[`path`,{d:`M8 3 4 7l4 4`,key:`9rb6wj`}],[`path`,{d:`M4 7h16`,key:`6tx8e3`}],[`path`,{d:`m16 21 4-4-4-4`,key:`siv7j2`}],[`path`,{d:`M20 17H4`,key:`h6l3hr`}]]),ai=O(`disc`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),oi=O(`ear`,[[`path`,{d:`M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0`,key:`1dfaln`}],[`path`,{d:`M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4`,key:`1qnva7`}]]);n();function si(e){if(typeof e!=`object`||!e)return null;let t=e,n=t.id,r=t.label;if(typeof n!=`string`||typeof r!=`string`)return null;let i=t.available===!0,a=t.enabled,o=t.unavailableReason;return{id:n,label:r,costWhenOff:typeof t.costWhenOff==`string`?t.costWhenOff:``,on:i&&typeof a==`boolean`?a:null,available:i,unavailableReason:typeof o==`string`?o:null}}function ci(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(si).filter(e=>e!==null);return n.length===0?null:n}var li=[[/privacy|mask/i,`privacy`],[/microphone|mic\b/i,`microphone`],[/speaker|broker audio|stream audio/i,`speaker`],[/audio/i,`listening`],[/object|detect/i,`detection`],[/event/i,`archive`],[/record/i,`recording`],[/notif/i,`notifications`],[/stream|broker/i,`stream`]];function ui(e){for(let[t,n]of li)if(t.test(e))return n;return`generic`}function di(e){let t=e.filter(e=>e.on===!1).map(e=>e.id),n=e.filter(e=>e.on===null).map(e=>e.id),r=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),i=[];return t.length>0&&i.push(`Off: ${r(t)}`),n.length>0&&i.push(`Unknown: ${r(n)}`),{offIds:t,unknownIds:n,summary:i.length===0?`All camera functions on`:i.join(` · `)}}var fi={stream:Le,detection:fr,privacy:x,microphone:E,speaker:A,listening:oi,archive:Pn,recording:ai,notifications:pt,generic:Tt};function pi({deviceId:t}){let n=c(),i=Number.isFinite(t),[a,o]=l(null),[s,u]=l(!1),f=Ee({deviceId:t},{enabled:i});dn([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let p=ci(f.data),m=_n({onError:(e,r)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:t},meta:{switchId:r.switchId,error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),o({id:r.switchId,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`recording`]]})}}),h=e(e=>{!e.available||e.on===null||m.mutate({deviceId:t,switchId:e.id,enabled:!e.on})},[t,m]);if(p===null)return null;let g=di(p),_=e=>a?.id===e.id?a.message:null;return r(En,{open:s,onOpenChange:u,children:[r(ne,{"aria-label":`Camera functions`,title:g.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${a===null?g.offIds.length>0?`border-warning/40 text-warning hover:bg-warning/10`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`:`border-danger/50 text-danger bg-danger/5`}`,children:[d(Tt,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden lg:inline`,children:`Functions`}),g.offIds.length>0&&r(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[g.offIds.length,` off`]})]}),r(Ge,{className:`left-auto right-0 mt-1 min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[d(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Camera functions`}),d(`ul`,{className:`space-y-0.5`,children:p.map(e=>d(`li`,{children:d(mi,{row:e,failure:_(e),onToggle:()=>h(e)})},e.id))})]})]})}function mi({row:e,failure:t,onToggle:n}){let i=fi[ui(e.label)],a=e.on===null,o=e.on===!1,s=t===null?a?e.unavailableReason??`The source that owns this did not answer.`:e.costWhenOff:`Write failed: ${t}`,c=t===null?a?e.unavailableReason??`unknown`:null:`write failed`;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:s,className:`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[d(i,{className:`h-3.5 w-3.5 shrink-0 ${t===null?a?`text-foreground-subtle/50`:o?`text-warning`:`text-success`:`text-danger`}`}),r(`span`,{className:`flex-1 min-w-0 truncate`,children:[e.label,c!==null&&r(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,c]})]}),d(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${a?`bg-surface-hover text-foreground-subtle/60`:o?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:a?`—`:o?`off`:`on`})]})}function hi({deviceId:e}){let t=ye(v().trpcClient,e);return t===null?null:r(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,title:`${t.label} — ${t.host}`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[d(y,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:t.label})]})}function gi({parentDeviceId:e}){let{t}=J(),n=hr(),i=v(),{data:a,isLoading:o,isError:s}=Sr(e),{data:c}=Ut({deviceId:e},{enabled:Number.isFinite(e)});if(o)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(a??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let u=Te(c?.stableId??``,l,c?.childLayout),f=u.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>d(Jt,{trpc:i.trpcClient,device:{...t,name:Ie(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),_=f.some(e=>!e.role),y=g&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),b=f.length>0?r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[d(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:y}),d(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,x=u.disabledSection===void 0?null:d(Ce,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:d(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>h(e.id,e))})},u.disabledSection.title);if(u.sections.length===0)return x===null?b:r(`div`,{className:`space-y-2`,children:[b,x]});let S=_&&!g;return r(`div`,{className:`space-y-2`,children:[S?b:null,u.sections.map(e=>d(Ce,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),S?null:b,x]})}function _i({deviceId:e}){let t=v(),{data:n,isLoading:r}=Cr(e),{data:i,isLoading:a}=Sr(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?d(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):d(`div`,{className:`flex h-full w-full flex-col`,children:d(ge,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}n();function vi({dev:e,busy:t,setBusy:n}){let i=e?.motionTrigger,a=S(e?.state.motionTrigger),[o,s]=l(!1);if(!i)return null;let c=a?.enabled===!0,u=a!==void 0,f=async()=>{if(t||!u)return;let e=!c;n(!0),s(!0);try{await i.setMotionTrigger({enabled:e})}finally{n(!1),s(!1)}};return r(`button`,{type:`button`,onClick:()=>{f()},disabled:t||!u,title:u?c?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":c,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${c?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[d(bn,{className:`h-3 w-3`}),d(`span`,{children:o?c?`Disabling…`:`Enabling…`:u?c?`On motion: on`:`On motion: off`:`On motion: …`})]})}n();function X({deviceId:e,deviceType:t,features:n}){let i=v(),a=it(t)?.HeroCard??mt,o=p(i.trpcClient,e),s=S(o?.state.deviceStatus),[c,u]=l(!1),f=s!==void 0&&s.online===!1,m=f?s.lastChangedAt:null;return r(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?d(`div`,{className:`flex justify-center`,children:d(U,{lastChangedAt:m})}):null,d(a,{trpc:i.trpcClient,deviceId:e,features:n}),d(`div`,{className:`flex justify-center`,children:d(vi,{dev:o,busy:c,setBusy:u})})]})}function yi({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:d(Pe,{trpc:v().trpcClient,deviceId:e,features:t})})}function bi({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:d(mt,{trpc:v().trpcClient,deviceId:e,features:t})})}function xi(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Si(e){if(!e)return null;let t=xi(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var Ci=1e3,wi=60*Ci,Ti=60*wi,Ei=24*Ti;function Di(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Ci?`just now`:n<wi?`${String(Math.floor(n/Ci))}s ago`:n<Ti?`${String(Math.floor(n/wi))}m ago`:n<Ei?`${String(Math.floor(n/Ti))}h ago`:`${String(Math.floor(n/Ei))}d ago`}n();var Oi=1500,ki=15e3,Ai=1e3;function ji({deviceId:e}){let n=p(v().trpcClient,e)?.state.eventEmitter,i=S(n);f(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},ki);return()=>{clearInterval(e)}},[n]);let a=i?.lastEvent??null,o=a?.seq??null,s=t(null),[c,u]=l(!1);f(()=>{if(o===null)return;let e=s.current;if(s.current=o,e===null||e===o)return;u(!0);let t=setTimeout(()=>{u(!1)},Oi);return()=>{clearTimeout(t)}},[o]);let[m,h]=l(()=>Date.now());f(()=>{let e=setInterval(()=>{h(Date.now())},Ai);return()=>{clearInterval(e)}},[]);let g=Si(a),_=i?.eventTypes??[],y=i?.eventCountSinceStart??0,b=i!==void 0,x=xi(a?.data);return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[d(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(c),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${c?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:g??`No press recorded`,children:d(c?me:zt,{className:`h-10 w-10`})}),r(`div`,{className:`text-center`,children:[x!==null&&d(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(x)}`}),d(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${g?`text-foreground`:`text-foreground-subtle`}`,children:g??(b?`No press recorded`:`Awaiting state…`)}),d(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a?Di(a.timestamp,m):`Waiting for the first event`})]}),_.length>0&&d(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:_.map(e=>d(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===a?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(y)} ${y===1?`event`:`events`} since start`})]})}function Mi({deviceName:e,deviceType:t,provider:n,isOnline:i,features:a}){return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[d(In,{type:n,size:`lg`}),r(`div`,{children:[d(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),d(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),r(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[d(Yr,{status:i?`online`:`offline`}),a.length>0&&d(Bn,{capabilities:a})]}),d(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}n();function Ni({deviceId:e}){let t=c(),n=nt({deviceId:e},{refetchInterval:1e4,retry:!1}),i=ae({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),o=a(()=>Pi(n.data??[]),[n.data]);return r(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[r(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[d(Fi,{label:`Discovered`,value:o.total,icon:d(ln,{className:`h-3.5 w-3.5`})}),d(Fi,{label:`Adopted`,value:o.adopted,accent:`success`}),d(Fi,{label:`Available`,value:o.available,accent:o.available>0?`primary`:void 0}),r(`button`,{type:`button`,onClick:()=>{i.mutateAsync({deviceId:e}).catch(()=>{})},disabled:i.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[i.isPending?d(pn,{className:`h-3.5 w-3.5 animate-spin`}):d(be,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[d(Ii,{icon:d(ut,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),d(Ii,{icon:d(dt,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),d(Ii,{icon:d(ot,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?d(Ii,{icon:d(Ne,{className:`h-3 w-3 text-foreground-subtle`}),label:`${o.unknown} unknown`}):null]})]})}function Pi(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function Fi({label:e,value:t,icon:n,accent:i}){return r(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${i===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:i===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[r(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,d(`span`,{className:`truncate`,children:e})]}),d(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Ii({icon:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1`,children:[e,d(`span`,{children:t})]})}var Li={[q.Switch]:X,[q.Siren]:X,[q.Light]:X,[q.Sensor]:X,[q.Button]:X,[q.Hub]:Ni,[q.Cover]:yi,[q.Valve]:X,[q.Humidifier]:X,[q.WaterHeater]:X,[q.Container]:_i,[q.Lock]:X,[q.Fan]:X,[q.Thermostat]:X,[q.Climate]:X,[q.MediaPlayer]:X,[q.Control]:X,[q.AlarmPanel]:X,[q.EventEmitter]:ji,[q.Notifier]:bi,[q.Script]:X,[q.Automation]:X,[q.Presence]:X,[q.Update]:X,[q.Vacuum]:X,[q.LawnMower]:X,[q.Weather]:X,[q.Image]:X,[q.PetFeeder]:X};function Ri(e){return Li[e]??Mi}function zi(e){return d(Ri(e.deviceType),{...e})}function Bi(e){return mn(v().trpcClient,e)}n();function Vi(n){let[r,i]=l(`idle`),[a,o]=l(null),s=t(null),c=t(null),u=t(null),d=t(!0),p=Cn(),m=_t(),h=kn(),g=e(()=>{if(s.current){try{s.current.close()}catch{}s.current=null}if(c.current){for(let e of c.current.getTracks())try{e.stop()}catch{}c.current=null}u.current=null},[]),_=e(async()=>{if(r===`idle`)return;i(`stopping`);let e=u.current;if(e&&n!==null)try{await Promise.race([h.mutateAsync({deviceId:n,sessionId:e}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),d.current&&(i(`idle`),o(null))},[r,n,h,g]),v=e(async()=>{if(n===null||r!==`idle`&&r!==`error`)return;o(null);let e=null,t=null,a=null;try{i(`requesting-mic`),e=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),c.current=e,i(`starting`);let r=await p.mutateAsync({deviceId:n});a=r.sessionId,u.current=a,i(`connecting`),t=new RTCPeerConnection,s.current=t,t.oniceconnectionstatechange=()=>{if(!d.current)return;let e=t.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&d.current&&(o(e===`failed`?`WebRTC connection failed`:null),_())};for(let n of e.getAudioTracks())t.addTrack(n,e);await t.setRemoteDescription({type:`offer`,sdp:r.sdpOffer});let l=await t.createAnswer();await t.setLocalDescription(l);let f=t.localDescription?.sdp??l.sdp??``;await m.mutateAsync({deviceId:n,sessionId:a,sdpAnswer:f})}catch(r){let l=r instanceof Error?r.message:String(r);if(console.warn(`[intercom] start failed`,r),t)try{t.close()}catch{}if(e)for(let t of e.getTracks())try{t.stop()}catch{}if(s.current=null,c.current=null,a!==null)try{await h.mutateAsync({deviceId:n,sessionId:a})}catch{}u.current=null,d.current&&(o(l),i(`error`))}},[n,r,p,m,h,_]);return f(()=>(d.current=!0,()=>{d.current=!1;let e=u.current;if(e!==null&&n!==null&&h.mutate({deviceId:n,sessionId:e}),s.current){try{s.current.close()}catch{}s.current=null}if(c.current){for(let e of c.current.getTracks())try{e.stop()}catch{}c.current=null}u.current=null}),[n]),{state:r,error:a,start:v,stop:_,isTalking:r===`talking`}}n();var Hi=0;function Z(){return++Hi}function Ui(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Wi(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function Gi(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function Ki(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function qi({scope:n,greeting:i,className:a}){let o=v(),[s,c]=l(()=>{let e=[];return i&&e.push({id:Z(),kind:`info`,text:i}),e.push({id:Z(),kind:`info`,text:`scope: ${Ui(n)} — type help or context for available commands`}),e}),[p,m]=l(``),[h,g]=l([]),[_,y]=l(-1),b=t(null),x=t(null);f(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[s]);let S=e(()=>{b.current?.focus()},[]),C=u({mutationFn:e=>o.trpcClient.repl.execute.mutate({code:e,scope:n}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;c(e=>[...e,{id:Z(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);c(e=>[...e,{id:Z(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){c([{id:Z(),kind:`info`,text:`scope: ${Ui(n)}`}]),m(``);return}if(t===`help`){c(e=>[...e,{id:Z(),kind:`input`,text:`> ${t}`},...Wi(n).map(e=>({id:Z(),kind:`info`,text:e}))]),m(``);return}if(t===`context`){c(e=>[...e,{id:Z(),kind:`input`,text:`> ${t}`},...Ki(n).map(e=>({id:Z(),kind:`info`,text:e}))]),m(``);return}if(t===`examples`){c(e=>[...e,{id:Z(),kind:`input`,text:`> ${t}`},...Gi(n).map(e=>({id:Z(),kind:`info`,text:e}))]),m(``);return}g(e=>[...e,t]),y(-1),c(e=>[...e,{id:Z(),kind:`input`,text:`> ${t}`}]),m(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(p);return}if(e.key===`ArrowUp`){if(e.preventDefault(),h.length===0)return;let t=_===-1?h.length-1:Math.max(0,_-1);y(t),m(h[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),_===-1)return;let t=_+1;t>=h.length?(y(-1),m(``)):(y(t),m(h[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),c([{id:Z(),kind:`info`,text:`scope: ${Ui(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return r(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${a??``}`,onClick:S,children:[r(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[s.map(e=>d(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&d(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),r(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[d(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),d(`input`,{ref:b,value:p,onChange:e=>m(e.target.value),onKeyDown:T,disabled:C.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function Ji(e,t){return e===null?null:{playbackUrl:e.url,...e.format===void 0?{}:{playbackFormat:e.format},playbackAuthToken:t,...e.label===void 0?{}:{playbackLabel:e.label}}}n();function Yi({deviceId:e,intercomAvailable:t=!1}){let n=v(),r=typeof window<`u`?g():``,i=Number.isFinite(e),o=Bi(i?e:null),c=Xr(i?[e]:[]),l=a(()=>{if(!i)return;let e=[];for(let t of c.rows){let n=nn(t);n!==null&&e.push(n)}return e},[i,c.rows]),{streams:u,pipelineMetrics:f,createSession:p,sendAnswer:m,handleOffer:_,getIceServers:y,addIceCandidate:b,getIceCandidates:x,closeSession:S,getSessionState:w}=xt(n.trpcClient,i?e:null),T=h(i?e:null,{width:ea}),E=Vi(i&&t?e:null),D=E.state===`requesting-mic`||E.state===`starting`||E.state===`connecting`||E.state===`stopping`,O=E.isTalking||D,k=()=>{E.state===`idle`||E.state===`error`?E.start():E.state!==`stopping`&&E.stop()},A=C(),j=St(),M=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,N=Ji(j.request,M),P=A.length>0?d(s,{children:A.map(e=>d(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return d(yn,{serverUrl:r,createSession:p,sendAnswer:m,handleOffer:_,getIceServers:y,addIceCandidate:b,getIceCandidates:x,closeSession:S,getSessionState:w,...N===null?{}:{...N,onExitPlayback:()=>j.clear()},streams:u,pipelineMetrics:f,phase:o.phase,detections:o,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:T.src,...T.src?{posterUrl:T.src}:{},snapshotLoading:T.loading,onRefreshSnapshot:T.refresh,intercomAvailable:t,intercomShown:O,onIntercomToggle:k,extraOverlay:P,chromeless:!0,className:`h-full`})}function Xi({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full`,children:d(tn,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Zi({deviceId:e}){if(!Number.isFinite(e))return r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
2
|
-
`);return d(qi,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function Qi({deviceId:e}){return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:d(vn,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function $i({deviceId:e}){return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:d(Ft,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var ea=960;function ta(e){return new Set(e.filter(e=>{let t=e.nativeAddonId?.trim()??``;return t!==``&&t!==`composer`}).map(e=>e.capName))}function na(e){return e.kind===`known`?null:e}function ra(e,t){return e.composable.kind===`known`?e.composable.value.has(t)?{kind:`present`,mode:`add`}:{kind:`absent`}:e.composable}function ia(e){if(e.deviceType!==q.Camera)return{kind:`absent`};switch(e.cameraSensors){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:`camera sensors could not be checked`};case`absent`:return{kind:`absent`};case`present`:return{kind:`present`,mode:`add`}}}function aa(e,t){if(e===`motion`)return ia(t);let n=na(t.nativeCaps);if(n!==null)return n;let r=t.nativeCaps.kind===`known`?t.nativeCaps.value:new Set;switch(e){case`doorbell`:return r.has(`doorbell`)?{kind:`absent`}:ra(t,`doorbell`);case`battery`:return r.has(`battery`)?{kind:`present`,mode:`replace`}:ra(t,`battery`);case`consumables`:return r.has(`consumables`)?{kind:`absent`}:ra(t,`consumables`)}}function oa(e){if(e.status===`pending`)return{kind:`pending`};if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};let t=e.data;if(t===void 0)return{kind:`pending`};if(t.state===`not-loaded`)return{kind:`not-loaded`,reason:t.reason};if(t.view===null)return{kind:`none`};let n=Qn(t.view.block);return n===null?{kind:`unknown`,reason:`block ${t.view.block.id} is not a composition`}:{kind:`present`,view:t.view,composition:n}}function sa(e){return e.kind===`present`?e.composition:null}function Q({label:e,value:t}){return r(`div`,{className:`${_} flex items-start gap-2 sm:gap-3`,children:[d(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),d(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}n();function ca({deviceId:e,initialName:n,label:i=`Name`,onError:a,onSaved:o,onCancel:s}){let{t:u}=J(),p=c(),[m,h]=l(!1),[g,_]=l(n),[v,y]=l(!1),b=t(null);f(()=>{m||_(n)},[n,m]),f(()=>{m&&b.current?.focus()},[m]);let x=Mn({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),p.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),p.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),S=async()=>{let t=g.trim();if(t.length===0||t===n){h(!1),_(n),o?.();return}y(!0);try{await x.mutateAsync({deviceId:e,name:t}),h(!1),o?.()}catch(e){a?.(e instanceof Error?e.message:String(e))}finally{y(!1)}},C=()=>{_(n),h(!1),s?.()};return m?d(Q,{label:i,value:r(`div`,{className:`flex items-center gap-1`,children:[d(`input`,{ref:b,type:`text`,value:g,onChange:e=>_(e.target.value),onKeyDown:e=>{e.key===`Enter`?S():e.key===`Escape`&&C()},disabled:v,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),d(`button`,{type:`button`,onClick:()=>void S(),disabled:v,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":u(`inlineEdit.save`),children:d(le,{className:`h-3 w-3`})}),d(`button`,{type:`button`,onClick:C,disabled:v,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":u(`inlineEdit.cancel`),children:d(_e,{className:`h-3 w-3`})})]})}):d(Q,{label:i,value:r(`div`,{className:`flex items-center gap-2 group`,children:[d(`span`,{className:`truncate`,children:n}),d(`button`,{type:`button`,onClick:()=>h(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":u(`inlineEdit.editName`),children:d(H,{className:`h-3.5 w-3.5`})})]})})}n();function la({deviceId:e,initialLocation:n,label:i=`Location`,onError:o,onSaved:s,onCancel:u}){let{t:p}=J(),m=c(),[h,g]=l(!1),[_,v]=l(n??``),[y,b]=l(!1),x=t(null),{data:S}=L(void 0,{enabled:h}),C=S??[];f(()=>{h||v(n??``)},[n,h]),f(()=>{h&&x.current?.focus()},[h]);let w=B({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),m.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),m.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),m.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),T=a(()=>{let e=_.trim().toLowerCase();return e.length===0?C:C.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[C,_]),E=_.trim().length>0&&!C.some(e=>e.toLowerCase()===_.trim().toLowerCase()),D=async t=>{let r=(t??_).trim(),i=r.length===0?null:r;if(i===(n??null)){g(!1),s?.();return}b(!0);try{await w.mutateAsync({deviceId:e,location:i}),g(!1),s?.()}catch(e){o?.(e instanceof Error?e.message:String(e))}finally{b(!1)}},O=()=>{v(n??``),g(!1),u?.()};return h?d(Q,{label:i,value:r(`div`,{className:`relative`,children:[r(`div`,{className:`flex items-center gap-1`,children:[d(`input`,{ref:x,type:`text`,value:_,onChange:e=>v(e.target.value),onKeyDown:e=>{e.key===`Enter`?D():e.key===`Escape`&&O()},disabled:y,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),d(`button`,{type:`button`,onClick:()=>void D(),disabled:y,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":p(`inlineEdit.save`),children:d(le,{className:`h-3 w-3`})}),d(`button`,{type:`button`,onClick:O,disabled:y,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":p(`inlineEdit.cancel`),children:d(_e,{className:`h-3 w-3`})})]}),(T.length>0||E)&&r(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[T.map(e=>r(`button`,{type:`button`,onClick:()=>{v(e),D(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[d(j,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),d(`span`,{className:`truncate`,children:e})]},e)),E&&r(`button`,{type:`button`,onClick:()=>void D(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Create`}),r(`span`,{className:`font-medium truncate`,children:[`"`,_.trim(),`"`]})]})]})]})}):d(Q,{label:i,value:r(`div`,{className:`flex items-center gap-2 group`,children:[n?d(`span`,{className:`truncate`,children:n}):d(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),d(`button`,{type:`button`,onClick:()=>g(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":p(`inlineEdit.editLocation`),children:d(H,{className:`h-3.5 w-3.5`})})]})})}function ua(e,t){let{hidden:n,...r}=e??{},i=t?{...r,hidden:!0}:r;return Object.keys(i).length===0?null:i}function da(e){return typeof e.linkDeviceId==`number`}var fa=new Set(Object.values(Xn));function pa(e){return fa.has(e)}function ma(e){let t=Object.values(Xn);return e==null||e===``||pa(e)?t:[...t,e]}n();var ha=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`;function ga({device:e}){let{t}=J(),n=c(),[i,a]=l(null),o=()=>a(null),s={onSuccess:()=>{o(),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>a(e.message)},u=Xe(),f=je(),p=e.display?.hidden===!0;return r(`section`,{"aria-label":t(`customize.identity.title`),className:`rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[r(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2 lg:grid-cols-4`,children:[d(ca,{deviceId:e.id,initialName:e.name,label:t(`customize.identity.name`),onError:a,onSaved:o,onCancel:o}),d(la,{deviceId:e.id,initialLocation:e.location,label:t(`customize.identity.room`),onError:a,onSaved:o,onCancel:o}),d(Q,{label:t(`customize.identity.hidden`),value:d(`input`,{type:`checkbox`,"aria-label":t(`deviceDisplay.hideFromLists`),checked:p,disabled:f.isPending,onChange:t=>f.mutate({deviceId:e.id,display:ua(e.display,t.target.checked)},s)})}),d(Q,{label:t(`customize.identity.role`),value:da(e)?d(`span`,{children:_a(e.role,t(`customize.identity.noRole`))}):r(`select`,{"aria-label":t(`customize.identity.role`),className:ha,value:e.role??``,disabled:u.isPending,onChange:t=>u.mutate({deviceId:e.id,role:t.target.value===``?null:t.target.value},s),children:[d(`option`,{value:``,children:t(`customize.identity.noRole`)}),ma(e.role).map(e=>d(`option`,{value:e,children:_a(e,t(`customize.identity.noRole`))},e))]})})]}),i!==null&&d(`p`,{role:`alert`,className:`mt-2 text-xs text-danger break-words`,children:i})]})}function _a(e,t){return e==null||e===``?t:pa(e)?Ye(e).label:e}function va({onAdvanced:e}){let{t}=J();return e===void 0?null:d(`button`,{type:`button`,className:`min-h-11 text-left text-primary underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,onClick:e,children:t(`customize.advancedLink`)})}n();function ya({open:e,title:t,targetKind:n,excludeDeviceIds:i,confirmLabel:a,extra:o,extraComplete:c=!0,onConfirm:u,onClose:f}){let{t:p}=J(),[m,h]=l(null),[g,_]=l(null),v=()=>{h(null),_(null),f()};return d(we,{open:e,onOpenChange:e=>e?void 0:v(),children:r(Me,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[d(xe,{children:d(ze,{children:t})}),d(De,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:e&&r(s,{children:[r(`section`,{"aria-label":p(`customize.assign.stepDevice`),className:`flex flex-col gap-1`,children:[d(`h3`,{className:`text-xs font-semibold`,children:p(`customize.assign.stepDevice`)}),m===null?d(zr,{excludeDeviceIds:i,onSelect:h}):r(`p`,{className:`flex items-center gap-2 text-sm`,children:[m.name,d(G,{variant:`ghost`,size:`sm`,onClick:()=>{h(null),_(null)},children:p(`customize.assign.change`)})]})]}),m!==null&&r(`section`,{"aria-label":p(`customize.assign.stepField`),className:`flex flex-col gap-1`,children:[d(`h3`,{className:`text-xs font-semibold`,children:p(`customize.assign.stepField`)}),d(Or,{device:m,targetKind:n,selected:g===null?null:{cap:g.cap,path:g.path},onPick:_,onBack:()=>{h(null),_(null)}})]}),m!==null&&o!==void 0&&r(`section`,{"aria-label":p(`customize.assign.stepDetails`),className:`flex flex-col gap-1`,children:[d(`h3`,{className:`text-xs font-semibold`,children:p(`customize.assign.stepDetails`)}),o]})]})}),r(pe,{children:[d(G,{variant:`ghost`,onClick:v,children:p(`customize.assign.cancel`)}),d(G,{disabled:g===null||!c,onClick:()=>{g!==null&&(u(g),h(null),_(null))},children:a})]})]})})}function ba(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function xa(e,t){let n=Ar(e,t);return n===void 0?{kind:`absent`}:{kind:`value`,value:n}}function Sa(e,t,n){return ba(t)?xa(t,n):e.status===`error`?{kind:`unknown`,reason:e.error?.message??`the value could not be read`}:e.status===`pending`||e.data===void 0?{kind:`pending`}:e.data===null?{kind:`absent`}:xa(e.data,n)}function Ca(e,t,n){let r=e?`active`:`muted`;return t.cap===`contact`&&t.path===`entryOpen`?{text:e?n.open:n.closed,tone:r}:Wn[t.cap]===t.path?{text:e?n.active:n.inactive,tone:r}:{text:String(e),tone:`normal`}}function wa(e,t,n){switch(e.kind){case`pending`:return{text:`…`,tone:`muted`};case`unknown`:return{text:`?`,title:e.reason,tone:`warning`};case`absent`:return{text:`—`,tone:`muted`};case`value`:{let r=e.value;return r===null?{text:`—`,tone:`muted`}:typeof r==`boolean`?Ca(r,t,n):typeof r==`number`?{text:t.path===`percentage`?`${Math.round(r)} %`:String(r),tone:`normal`}:typeof r==`string`?{text:r,tone:`normal`}:{text:JSON.stringify(r),tone:`normal`}}}}var Ta=0;function Ea(e){let t=v(),n=cn({deviceId:e?.deviceId??Ta,capName:e?.cap??``},{enabled:e!==null}),r=Ot(t.trpcClient,e?.deviceId??null,e?.cap??``);return e===null?{kind:`absent`}:Sa({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}},r,e.path)}var Da={muted:`text-foreground-subtle`,active:`text-success`,normal:`text-foreground`,warning:`text-warning`};function Oa({target:e}){let{t}=J(),n=Ea(e);return e===null?null:d(ka,{display:wa(n,e,{active:t(`customize.assign.value.active`),inactive:t(`customize.assign.value.inactive`),open:t(`customize.assign.value.open`),closed:t(`customize.assign.value.closed`)})})}function ka({display:e}){return d(`span`,{className:`text-xs ${Da[e.tone]}`,title:e.title,children:e.text})}function $({name:e,detail:t,meta:n,value:i,shown:a,problem:o,onRemove:s,removeLabel:c,busy:l=!1}){return r(`li`,{className:`grid grid-cols-[minmax(0,1fr)_44px] gap-x-3 gap-y-1 items-center px-2 py-2 sm:px-4 sm:grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,1fr)_44px]`,children:[r(`div`,{className:`min-w-0`,children:[d(`div`,{className:`text-sm break-words`,children:e}),t!==null&&d(`div`,{className:`text-xs text-foreground-subtle break-words`,children:t}),o!==void 0&&d(`div`,{role:`alert`,className:`text-xs text-warning break-words`,children:o})]}),d(`div`,{className:`row-start-2 col-start-1 text-xs text-foreground-subtle empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:n}),d(`div`,{className:`row-start-3 col-start-1 empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:a===void 0?d(Oa,{target:i}):a!==null&&d(ka,{display:a})}),d(`div`,{className:`row-start-1 col-start-2 sm:row-start-auto sm:col-start-auto`,children:s!==void 0&&d(`button`,{type:`button`,"aria-label":c,disabled:l,className:`h-11 w-11 flex items-center justify-center rounded text-foreground-subtle hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`,onClick:s,children:d(_e,{className:`h-4 w-4`})})})]})}function Aa({id:e,icon:t,title:n,headerControl:i,addLabel:a,onAdd:o,addDisabled:s=!1,notices:c,children:l}){return r(`section`,{"aria-labelledby":`customize-${e}`,className:`rounded-lg border border-border bg-surface`,children:[r(`header`,{className:`flex flex-wrap items-center gap-2 border-b border-border px-2 py-2 sm:px-4`,children:[t,d(`h2`,{id:`customize-${e}`,className:`flex-1 text-sm font-semibold`,children:n}),i,o!==void 0&&a!==void 0&&d(G,{variant:`outline`,size:`sm`,disabled:s,onClick:o,children:a})]}),c!==void 0&&d(`div`,{className:`flex flex-col gap-1 px-2 pt-2 empty:hidden sm:px-4`,children:c}),d(`ul`,{className:`flex flex-col divide-y divide-border`,children:l})]})}function ja({availability:e}){let{t}=J();return e.kind===`pending`?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):e.kind===`unknown`?d(`p`,{role:`alert`,className:`text-xs text-warning`,children:t(`customize.assign.unknown`,{reason:e.reason})}):null}function Ma(e,t){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};let n=e.data;return e.status===`pending`||n===void 0?{kind:`pending`}:{kind:`known`,value:t(n)}}var Na=[{id:`motion`,labelKey:`customize.assign.filters.motion`,caps:[`motion`]},{id:`contact`,labelKey:`customize.assign.filters.contact`,caps:[`contact`]},{id:`all`,labelKey:`customize.assign.filters.all`,caps:cr}];function Pa(e,t){return t!==null&&e.includes(t)?t:cr.find(t=>e.includes(t))??null}function Fa(e,t){let n=[e,t].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function Ia(e,t){if(e.id===t.hostId||e.type===q.Container||t.excludeCameras&&e.isCamera)return!1;let n=K({addonId:e.addonId,stableId:e.stableId});return!t.assigned.has(n)}function La(e){return e.devices.flatMap(t=>{if(!Ia(t,e))return[];let n=e.capIndex.get(t.id)??[],r=Pa(n,e.preferredCap);if(r===null)return[];let i=Wn[r];return[{deviceId:t.id,ref:{addonId:t.addonId,stableId:t.stableId},name:t.name,detail:Fa(t.integration,t.location),meta:r,caps:n,value:i===void 0?null:{deviceId:t.id,cap:r,path:i}}]}).toSorted((e,t)=>e.name.localeCompare(t.name))}function Ra(e,t,n){let r=Qr(t);return e.filter(e=>{if(n!==null&&!e.caps.some(e=>n.caps.includes(e)))return!1;if(r.length===0)return!0;let t=Zr({id:e.deviceId,name:e.name,...e.detail===null?{}:{detail:e.detail},...e.meta===null?{}:{type:e.meta}});return r.every(e=>t.includes(e))})}function za(e){let t=e.find(e=>e.query.status===`error`);if(t!==void 0)return{kind:`unknown`,reason:t.query.error?.message??`the request failed`};if(e.some(e=>e.query.status!==`success`||e.query.data===void 0))return{kind:`pending`};let n=new Map;for(let t of e)for(let e of t.query.data??[])n.set(e,[...n.get(e)??[],t.cap]);return{kind:`known`,value:n}}function Ba(e,t){let n=et.useQueries(n=>e.map(e=>n.deviceManager.listDeviceIdsByCaps({capNames:[e]},{enabled:t})));return za(e.map((e,t)=>{let r=n[t];return{cap:e,query:r===void 0?{status:`pending`}:{status:r.status,data:r.data,error:r.error===null?null:{message:r.error.message}}}}))}n();function Va(e,t){let n=Xt(e,t);return n.kind===`resolved`?n.integration.name:null}function Ha(e){let t=An({projection:`slim`},{enabled:e}),{data:n}=on(void 0,{enabled:e}),r=t.error===null||t.error===void 0?null:t.error.message;return a(()=>Ma({status:t.status,data:t.data,error:r===null?null:{message:r}},e=>e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,type:e.type,location:e.location,isCamera:e.isCamera,integration:Va(e,n)}))),[t.status,t.data,r,n])}function Ua(e){let t=Ha(e.enabled),n=Ba(cr,e.enabled);return t.kind===`unknown`?t:n.kind===`unknown`?n:t.kind===`pending`||n.kind===`pending`?{kind:`pending`}:{kind:`known`,value:La({devices:t.value,capIndex:n.value,hostId:e.hostId,excludeCameras:e.excludeCameras,assigned:e.assigned,preferredCap:e.preferredCap})}}function Wa(){let{t:e}=J(),t=Et();return(n,r)=>t({title:e(`customize.assign.removeConfirm.title`),message:r?`${e(`customize.assign.removeConfirm.message`,{what:n})} ${e(`customize.assign.removeConfirm.last`)}`:e(`customize.assign.removeConfirm.message`,{what:n}),confirmLabel:e(`customize.assign.removeConfirm.confirm`),variant:`danger`})}n();function Ga(e){return e===null?null:Pr(e,`replace`)?`replace`:Pr(e,`add`)?`add`:null}function Ka({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=J(),o=Wa(),[c,u]=l(!1),[f,p]=l(null),m=sa(t.state),h=qr(m,`battery`),g=Ga(h),_=g===null?null:Dr(h?.fields.percentage),v=Ha(_!==null);if(n.kind===`absent`)return null;let y=n.kind===`present`?n.mode:null,b=t.state.kind===`none`||t.state.kind===`present`,x=_===null||v.kind!==`known`?null:v.value.find(e=>K({addonId:e.addonId,stableId:e.stableId})===K(_.source))??null,S=_===null?``:x?.name??K(_.source),C=async e=>{let n=await t.save(e);p(n.kind===`refused`?n.reason:null)},w=async()=>{if(m===null)return;let e=wr(m,`battery`);await o(a(`customize.battery.removeWhat`,{name:S}),e===null)&&await C(e)},T=y!==null&&b&&h===null&&!t.saving;return r(s,{children:[r(Aa,{id:`battery`,icon:d(P,{className:`h-4 w-4 text-foreground-subtle`}),title:a(`customize.battery.title`),addLabel:a(y===`replace`?`customize.battery.replace`:`customize.battery.add`),onAdd:T?()=>u(!0):void 0,notices:r(s,{children:[d(ja,{availability:n}),_!==null&&v.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[y===`replace`&&b&&d($,{name:a(`customize.battery.native`),detail:null,meta:a(h===null?`customize.assign.native`:`customize.battery.nativeReplaced`),value:h===null?{deviceId:e.id,cap:`battery`,path:`percentage`}:null,removeLabel:``}),h===null&&y===`add`&&b&&d(`li`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:a(`customize.assign.none`)}),_!==null&&d($,{name:S,detail:`${_.cap}.${_.fieldPath}`,meta:a(g===`replace`?`customize.assign.replaces`:`customize.assign.adds`),value:x===null?null:{deviceId:x.id,cap:_.cap,path:_.fieldPath},problem:x===null&&v.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:b?()=>void w():void 0,removeLabel:a(`customize.assign.removeNamed`,{name:S}),busy:t.saving}),h!==null&&_===null&&d($,{name:a(`customize.battery.otherFormula`),detail:null,meta:d(va,{onAdvanced:i}),value:{deviceId:e.id,cap:`battery`,path:`percentage`},removeLabel:``})]}),d(ya,{open:c,title:a(y===`replace`?`customize.battery.replace`:`customize.battery.add`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:a(`customize.assign.add`),onConfirm:e=>{u(!1);let n=y===null?null:Wr({percentage:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},mode:y});n===null?p(a(`customize.assign.pickUnusable`)):C(Y(m,t.target,n))},onClose:()=>u(!1)})]})}n();function qa(e,t){let n=e.source;if(n===null||t.kind!==`known`)return null;let r=K(n.source);return t.value.find(e=>K({addonId:e.addonId,stableId:e.stableId})===r)??null}function Ja(e){let t=typeof e==`number`?e:typeof e==`string`?Number(e):NaN;return Number.isFinite(t)?t:null}function Ya({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=J(),o=Wa(),[c,u]=l(!1),[f,p]=l(``),[m,h]=l(`percent`),[g,_]=l(null),v=sa(t.state),y=qr(v,`consumables`),b=Mr(y),x=Ha(b.some(e=>e.source!==null));if(n.kind===`absent`)return null;let S=t.state.kind===`none`||t.state.kind===`present`,C=n.kind===`present`&&S&&!t.saving,w=Nr(f),T=b.find(e=>e.key===w)??null,E=T!==null,D=f.trim()!==``&&w===``,O=async e=>{let n=await t.save(e);_(n.kind===`refused`?n.reason:null)},k=()=>{u(!1),p(``),h(`percent`)},A=async e=>{if(y===null||v===null)return;let n=Gr(y,e.key),r=n===null?wr(v,`consumables`):Y(v,t.target,n);await o(a(`customize.consumables.removeWhat`,{name:e.label}),r===null)&&await O(r)},j=r(`div`,{className:`flex flex-wrap items-end gap-2`,children:[r(`label`,{className:`flex w-full flex-col gap-1 text-xs sm:w-56`,children:[a(`customize.consumables.name`),d(`input`,{"aria-label":a(`customize.consumables.name`),className:`px-2 py-1 text-sm bg-background border border-border rounded`,value:f,onChange:e=>p(e.target.value)})]}),r(`label`,{className:`flex flex-col gap-1 text-xs`,children:[a(`customize.consumables.unit`),d(`select`,{"aria-label":a(`customize.consumables.unit`),className:`px-2 py-1 text-sm bg-background border border-border rounded`,value:m,onChange:e=>{let t=Ir.find(t=>t===e.target.value);t!==void 0&&h(t)},children:Ir.map(e=>d(`option`,{value:e,children:a(`customize.consumables.units.${e}`)},e))})]}),E&&d(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:a(`customize.consumables.takenBy`,{name:T.label})}),D&&d(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:a(`customize.consumables.keyless`)})]});return r(s,{children:[r(Aa,{id:`consumables`,icon:d(ve,{className:`h-4 w-4 text-foreground-subtle`}),title:a(`customize.consumables.title`),addLabel:a(`customize.consumables.add`),onAdd:C?()=>u(!0):void 0,notices:r(s,{children:[d(ja,{availability:n}),x.kind===`unknown`&&b.some(e=>e.source!==null)&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:x.reason})}),g!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:g})]}),children:[b.map(e=>{let n=e.source;if(e.unit===null||n===null)return d($,{name:e.label,detail:a(`customize.consumables.otherFormula`),meta:d(va,{onAdvanced:i}),value:null,removeLabel:``},e.key);let r=qa(e,x),o=r?.name??K(n.source);return d($,{name:e.label,detail:`${a(`customize.consumables.units.${e.unit}`)} · ${o}`,meta:`${n.cap}.${n.fieldPath}`,value:r===null?null:{deviceId:r.id,cap:n.cap,path:n.fieldPath},problem:r===null&&x.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:S?()=>void A(e):void 0,removeLabel:a(`customize.assign.removeNamed`,{name:e.label}),busy:t.saving},e.key)}),b.length===0&&n.kind===`present`&&S&&d(`li`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:a(`customize.assign.none`)})]}),d(ya,{open:c,title:a(`customize.consumables.pickTitle`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:a(`customize.assign.add`),extra:j,extraComplete:w!==``&&!E,onConfirm:e=>{let n=Ja(e.value);if(n!==null&&(n<0||m===`percent`&&n>100)){k(),_(a(`customize.consumables.outOfRange`,{value:n}));return}let r=jr(y,{key:w,label:f,remaining:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},unit:m});k(),r===null?_(a(`customize.assign.pickUnusable`)):O(Y(v,t.target,r))},onClose:k})]})}n();function Xa({open:e,title:t,selection:n,candidates:i,filters:a,confirmLabel:o,onConfirm:s,onClose:c}){let{t:u}=J(),[f,p]=l(``),[m,h]=l(null),[g,_]=l([]),[v,y]=l(60),b=a?.find(e=>e.id===m)??a?.[0]??null,x=i.kind===`known`?Ra(i.value,f,b):[],S=i.kind===`known`?i.value.filter(e=>g.includes(e.deviceId)):[],C=()=>{_([]),h(null),p(``),y(60)},w=()=>{C(),c()};return d(we,{open:e,onOpenChange:e=>e?void 0:w(),children:r(Me,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[d(xe,{children:d(ze,{children:t})}),r(De,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[d(`input`,{type:`search`,"aria-label":u(`customize.assign.search`),placeholder:u(`customize.assign.search`),className:`px-2 py-1.5 text-sm bg-background border border-border rounded`,value:f,onChange:e=>p(e.target.value)}),a!==void 0&&d(`div`,{role:`group`,"aria-label":u(`customize.assign.filtersLabel`),className:`flex flex-wrap gap-1`,children:a.map(e=>d(G,{size:`sm`,variant:e.id===b?.id?`primary`:`outline`,"aria-pressed":e.id===b?.id,onClick:()=>h(e.id),children:u(e.labelKey)},e.id))}),e&&d(Za,{title:t,candidates:i,shown:x.slice(0,v),hiddenCount:Math.max(0,x.length-v),selection:n,picked:g,onToggle:e=>{_(n===`single`?[e]:g.includes(e)?g.filter(t=>t!==e):[...g,e])},onMore:()=>y(v+60)})]}),r(pe,{children:[d(G,{variant:`ghost`,onClick:w,children:u(`customize.assign.cancel`)}),d(G,{disabled:S.length===0,onClick:()=>{S.length!==0&&(s(S),C())},children:o(S.length)})]})]})})}function Za({title:e,candidates:t,shown:n,hiddenCount:a,selection:o,picked:c,onToggle:l,onMore:u}){let{t:f}=J(),p=i();return t.kind===`pending`?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:f(`customize.assign.loadingDevices`)}):t.kind===`unknown`?d(an,{title:f(`customize.assign.devicesFailed`),message:t.reason}):n.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:f(`customize.assign.noCompatible`)}):r(s,{children:[d(`ul`,{role:o===`single`?`radiogroup`:`group`,"aria-label":e,className:`flex flex-col divide-y divide-border`,children:n.map(e=>r(`li`,{className:`flex items-center gap-2 py-2`,children:[r(`label`,{className:`flex min-w-0 flex-1 cursor-pointer items-center gap-2`,children:[d(`input`,{type:o===`single`?`radio`:`checkbox`,name:p,"aria-label":e.name,checked:c.includes(e.deviceId),onChange:()=>l(e.deviceId)}),r(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[d(`span`,{className:`text-sm`,children:e.name}),d(`span`,{className:`text-xs text-foreground-subtle break-words`,children:[e.detail,e.meta].filter(e=>e!==null).join(` · `)})]})]}),d(Oa,{target:e.value})]},e.deviceId))}),a>0&&d(G,{variant:`ghost`,size:`sm`,onClick:u,children:f(`customize.assign.showMore`,{count:a})})]})}function Qa(e){if(e===null)return[];let t=Lr(e);return Br(e).map(e=>{let n=K(e);return{key:n,ref:e,caps:t.filter(e=>K(e.source)===n).map(e=>e.cap)}})}function $a(e,t){let n=Lr(e);if(n.length===0)return!1;let{enabled:r,...i}=e,{enabled:a,...o}=ar({camera:t,sources:n,enabled:!0});return Kr(i,o)}function eo(e){return e?.enabled!==!1}function to(e,t,n){let r=[...e===null?[]:Lr(e),...n.flatMap(e=>qn(e.ref,e.caps))];return r.length===0?null:ar({camera:t,sources:r,enabled:eo(e)})}function no(e,t,n){let r=Lr(e).filter(e=>K(e.source)!==n);return r.length===0?null:ar({camera:t,sources:r,enabled:eo(e)})}function ro(e,t){return{...e,enabled:t}}n();function io({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=J(),o=Wa(),[c,u]=l(!1),[f,p]=l(null),m=sa(t.state),h=qr(m,`doorbell`),g=h===null||$a(h,t.target),_=g?Qa(h):[],v=Ha(_.length>0),y=Ua({hostId:e.id,excludeCameras:!1,assigned:new Set(_.map(e=>e.key)),preferredCap:null,enabled:c});if(n.kind===`absent`)return null;let b=t.state.kind===`none`||t.state.kind===`present`,x=b&&!t.saving,S=n.kind===`present`&&x&&g,C=async e=>{let n=e===null?m===null?null:wr(m,`doorbell`):Y(m,t.target,e),r=await t.save(n);p(r.kind===`refused`?r.reason:null)},w=async(e,n)=>{if(h===null||m===null)return;let r=no(h,t.target,e.key),i=r===null&&wr(m,`doorbell`)===null;await o(a(`customize.doorbell.removeWhat`,{name:n}),i)&&await C(r)},T=e=>v.kind===`known`?v.value.find(t=>K({addonId:t.addonId,stableId:t.stableId})===e.key)??null:null;return r(s,{children:[r(Aa,{id:`doorbell`,icon:d(ct,{className:`h-4 w-4 text-foreground-subtle`}),title:a(`customize.doorbell.title`),headerControl:h===null?void 0:r(`label`,{className:`flex min-h-11 items-center gap-1 text-xs`,children:[d(`input`,{type:`checkbox`,"aria-label":a(`customize.doorbell.active`),checked:h.enabled!==!1,disabled:!x,onChange:e=>void C(ro(h,e.target.checked))}),a(`customize.doorbell.active`)]}),addLabel:a(`customize.doorbell.add`),onAdd:S?()=>u(!0):void 0,notices:r(s,{children:[d(ja,{availability:n}),v.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[_.map(e=>{let n=T(e),r=n?.name??e.key,i=Pa(e.caps,null),o=i===null?void 0:Wn[i];return d($,{name:r,detail:n===null?null:Fa(n.integration,n.location),meta:e.caps.join(`, `),value:n!==null&&i!==null&&o!==void 0?{deviceId:n.id,cap:i,path:o}:null,problem:n===null&&v.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:b?()=>void w(e,r):void 0,removeLabel:a(`customize.assign.removeNamed`,{name:r}),busy:t.saving},e.key)}),!g&&d($,{name:a(`customize.doorbell.otherFormula`),detail:null,meta:d(va,{onAdvanced:i}),value:null,removeLabel:``}),h===null&&n.kind===`present`&&b&&d(`li`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:a(`customize.assign.none`)})]}),d(Xa,{open:c,title:a(`customize.doorbell.pickTitle`),selection:`multi`,candidates:y,confirmLabel:e=>a(`customize.assign.addCount`,{count:e}),onConfirm:e=>{u(!1),C(to(h,t.target,e.map(e=>({ref:e.ref,caps:e.caps}))))},onClose:()=>u(!1)})]})}function ao(e){return e.slot===`linked-devices`}function oo(e){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};if(e.status===`pending`||e.data===void 0)return{kind:`pending`};for(let t of e.data)if(t.state===`ok`&&t.slot===`linked-devices`&&ao(t.value))return{kind:`present`,slot:t,value:t.value};let t=e.data.find(e=>e.state===`unreachable`);return t!==void 0&&t.state===`unreachable`?{kind:`unknown`,reason:t.reason}:{kind:`absent`}}function so(e,t){let n=t.trackedDeviceIds??[],r=e=>t=>({deviceId:t.deviceId,name:t.name,health:t.health,implied:e,tracked:n.includes(t.deviceId)});return[...e.sources.map(r(!1)),...(e.impliedSources??[]).map(r(!0))]}function co(e,t){let n=new Set([...e.sources,...e.impliedSources??[]].map(e=>e.deviceId));return(t.trackedDeviceIds??[]).filter(e=>!n.has(e))}function lo(e,t){return{...e,deviceIds:[...e.deviceIds,...t.filter(t=>!e.deviceIds.includes(t))]}}function uo(e,t){return{...e,deviceIds:e.deviceIds.filter(e=>e!==t),...e.trackedDeviceIds===void 0?{}:{trackedDeviceIds:e.trackedDeviceIds.filter(e=>e!==t)}}}function fo(e,t,n){let r=e.trackedDeviceIds??[],i=n?[...r.filter(e=>e!==t),t]:r.filter(e=>e!==t);return{...e,trackedDeviceIds:i}}function po(e,t,n){return e.flatMap(e=>{let r=t.get(e.deviceId);return n.has(e.deviceId)||r===void 0?[]:[{deviceId:e.deviceId,ref:{addonId:r.addonId,stableId:r.stableId},name:e.parentName===null?e.name:`${e.parentName} · ${e.name}`,detail:Fa(r.integration,e.location),meta:e.type,caps:[],value:null}]})}n();function mo(e){return e==null?null:e.message}function ho({device:e}){let{t}=J(),n=c(),i=Wa(),a=nr.includes(e.type),[o,u]=l(!1),[f,p]=l(!1),[m,h]=l(null),g=he({deviceId:e.id},{enabled:a}),_=oo({status:g.status,data:g.data,error:mo(g.error)===null?null:{message:mo(g.error)??``}}),v=_.kind===`present`?_.slot.slotRef:``,y=_.kind===`present`?[...so(_.slot,_.value).map(e=>e.deviceId),...co(_.slot,_.value)]:[],b=ft(),x=Ha(a&&_.kind===`present`&&(o||y.length>0)),S=un({deviceId:e.id,slotRef:v},{enabled:o&&_.kind===`present`});if(!a||_.kind===`absent`)return null;if(_.kind!==`present`)return d(Aa,{id:`linked`,icon:d(qt,{className:`h-4 w-4 text-foreground-subtle`}),title:t(`customize.linked.title`),notices:_.kind===`pending`?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:t(`customize.assign.unknown`,{reason:_.reason})}),children:null});let C=_.value,w=new Map(x.kind===`known`?x.value.map(e=>[e.id,e]):[]),T=C.trackedDeviceIds!==void 0,E=(e,t)=>{let n=w.get(e.deviceId);return{...e,name:e.name??n?.name??null,type:n?.type??null,detail:n===void 0?null:Fa(n.integration,n.location),orphan:t}},D=[...so(_.slot,C).map(e=>E(e,!1)),...co(_.slot,C).map(e=>E({deviceId:e,name:null,health:`ok`,implied:!1,tracked:!0},!0))],O=new Set(y),k=x.kind===`unknown`?x:S.status===`error`?{kind:`unknown`,reason:mo(S.error)??`the request failed`}:x.kind===`pending`||S.status===`pending`||S.data===void 0?{kind:`pending`}:{kind:`known`,value:po(S.data.candidates,w,O)},A=async r=>{if(f){h(t(`customize.saveInFlight`));return}p(!0),h(null);try{await b.mutateAsync({deviceId:e.id,slotRef:_.slot.slotRef,value:r}),await g.refetch(),await n.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}},j=async e=>{await i(t(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await A(uo(C,e.deviceId))},M=[{key:`device`,header:t(`customize.linked.device`),nowrap:!1,render:e=>r(`div`,{className:`flex flex-col`,children:[d(`span`,{className:`text-sm`,children:e.name??`#${e.deviceId}`}),e.detail!==null&&d(`span`,{className:`text-xs text-foreground-subtle`,children:e.detail}),e.orphan&&d(`span`,{className:`text-xs text-foreground-subtle`,children:t(`customize.linked.notLinked`)}),e.health!==`ok`&&d(`span`,{role:`alert`,className:`text-xs text-warning`,children:t(`customize.linked.health.${e.health}`)})]})},{key:`type`,header:t(`customize.linked.type`),render:e=>e.type===null?`—`:Ke(e.type).label},{key:`controls`,header:t(`customize.linked.controls`),notSortableReason:t(`customize.linked.controlsAlways`),render:e=>e.orphan?`—`:t(`customize.linked.yes`)},{key:`tracked`,header:t(`customize.linked.tracked`),render:e=>d(`input`,{type:`checkbox`,"aria-label":t(`customize.linked.trackFor`,{name:e.name??e.deviceId}),checked:e.tracked,disabled:f,onChange:t=>void A(fo(C,e.deviceId,t.target.checked))})},{key:`remove`,header:``,render:e=>e.implied||e.orphan?null:d(`button`,{type:`button`,"aria-label":t(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),className:`h-11 w-11 flex items-center justify-center text-foreground-subtle hover:text-foreground disabled:opacity-50`,disabled:f,onClick:()=>void j(e),children:d(_e,{className:`h-4 w-4`})})}],N=T?M:M.filter(e=>e.key!==`tracked`);return r(s,{children:[d(Aa,{id:`linked`,icon:d(qt,{className:`h-4 w-4 text-foreground-subtle`}),title:t(`customize.linked.title`),addLabel:t(`customize.linked.add`),onAdd:f?void 0:()=>u(!0),notices:r(s,{children:[x.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:t(`customize.assign.devicesUnreadable`,{reason:x.reason})}),m!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:r(`li`,{className:`list-none`,children:[D.length===0?d(`p`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:t(`customize.assign.none`)}):d(Mt,{columns:N,rows:D,rowKey:e=>e.deviceId,mobileMode:`cards`,bordered:!1}),D.some(e=>!e.orphan)&&d(`p`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:t(`customize.linked.controlsAlways`)})]})}),d(Xa,{open:o,title:t(`customize.linked.pickTitle`),selection:`multi`,candidates:k,confirmLabel:e=>t(`customize.assign.addCount`,{count:e}),onConfirm:e=>{u(!1),A(lo(C,e.map(e=>e.deviceId)))},onClose:()=>u(!1)})]})}function go(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.sensors:[]}function _o(e){return{addonId:e.addonId,stableId:e.stableId,mode:e.mode}}function vo(e){return e.length===0?null:{sensors:[...e]}}function yo(e,t){let n=new Set(e.map(lr));return vo([...e.map(_o),...t.filter(e=>!n.has(lr(e))).map(e=>({...e,mode:sr}))])}function bo(e,t,n){return vo(e.map(e=>lr(e)===t?{..._o(e),mode:n}:_o(e)))}function xo(e,t){return vo(e.filter(e=>lr(e)!==t).map(_o))}function So(e){return e?.state===`configured`&&e.cameraMotion!==void 0}function Co(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.cameraMotion??`always`:`always`}function wo(e){return e===null||e.state===`unreadable`?!1:e.state===`not-configured`||So(e)}function To(e){return e?.state===`configured`&&(e.notForwarded!==void 0||e.notEnforced!==void 0)}function Eo(e,t,n){if(e!==`present`||t===null||n)return{kind:`none`};let r=t.cameraLevel;return r===void 0?{kind:`unknown`}:{kind:`level`,detected:r.detected,atMs:r.atMs}}n();var Do=5e3;function Oo(e){return e.state===`missing`||e.state===`unreadable`?e.stableId:e.name}function ko({device:e,availability:n,sensors:i}){let{t:a}=J(),o=Wa(),c=Fe(),[u,p]=l(!1),[m,h]=l(null),g=t(!1),[_,v]=l(!1),[y,b]=l(!1),x=i.status,S=t(i.refetch);S.current=i.refetch,f(()=>{let e=setInterval(()=>{g.current||S.current()},Do);return()=>clearInterval(e)},[]);let C=go(x);f(()=>{x!==null&&b(!1)},[x]);let w=i.presence===`present`&&wo(x)&&!y?C:null,T=Ha(C!==null&&C.length>0),E=Ua({hostId:e.id,excludeCameras:!0,assigned:new Set((C??[]).map(lr)),preferredCap:`motion`,enabled:u});if(n.kind===`absent`)return null;let D=So(x),O=To(x)?`passes`:Co(x),k=Eo(i.presence,x,y),A=k.kind===`none`?null:k.kind===`unknown`?{text:`?`,tone:`warning`,title:a(`customize.motion.cameraLevelUnknown`)}:{text:a(k.detected?`customize.assign.value.active`:`customize.assign.value.inactive`),tone:k.detected?`active`:`muted`,title:a(`customize.motion.cameraLevelOwn`,{at:new Date(k.atMs).toLocaleTimeString()})},j=_||c.isPending,M=async t=>{if(g.current){h(a(`customize.saveInFlight`));return}g.current=!0,v(!0);try{await c.mutateAsync({deviceId:e.id,config:t}),h(null),await i.refetch()===`failed`&&b(!0)}catch(e){h(e instanceof Error?e.message:String(e))}finally{g.current=!1,v(!1)}},N=async e=>{w!==null&&await o(a(`customize.motion.removeWhat`,{name:Oo(e)}),!1)&&await M(xo(w,lr(e)))},P=e=>{if(T.kind!==`known`||!(`deviceId`in e))return null;let t=T.value.find(t=>t.id===e.deviceId);return t===void 0?null:Fa(t.integration,t.location)};return r(s,{children:[r(Aa,{id:`motion`,icon:d(bn,{className:`h-4 w-4 text-foreground-subtle`}),title:a(`customize.motion.title`),addLabel:a(`customize.motion.add`),onAdd:w!==null&&n.kind===`present`?()=>p(!0):void 0,addDisabled:j,notices:r(s,{children:[d(ja,{availability:n}),i.presence===`pending`&&n.kind!==`pending`&&d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`customize.motion.reading`)}),x?.state===`unreadable`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.motion.unreadable`,{reason:x.reason})}),x?.state===`configured`&&!wo(x)&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.olderOrchestrator`)}),y&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.refetchFailed`)}),x?.state===`configured`&&x.notForwarded!==void 0&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.notForwarded.${x.notForwarded}`)}),x?.state===`configured`&&x.notEnforced!==void 0&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.notEnforced`)}),T.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:T.reason})}),m!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:[d($,{name:a(`customize.motion.camera`),detail:null,meta:O===null?a(`customize.assign.native`):`${a(`customize.motion.cameraState.${O}`)} · ${a(`customize.assign.native`)}`,value:null,shown:A,removeLabel:``}),(C??[]).map(e=>{let t=lr(e),n=Oo(e),r=e.state===`ready`?Pa(e.caps,`motion`):null,i=r===null?void 0:Wn[r];return d($,{name:n,detail:P(e),meta:D&&w!==null?d(`select`,{"aria-label":a(`customize.motion.modeFor`,{name:n}),className:`h-11 rounded border border-border bg-surface px-1 text-xs`,value:e.mode,disabled:j,onChange:e=>{let n=ur.safeParse(e.target.value);n.success&&w!==null&&M(bo(w,t,n.data))},children:ur.options.map(e=>d(`option`,{value:e,children:a(`customize.motion.mode.${e}`)},e))}):a(`customize.motion.mode.${e.mode}`),value:r!==null&&i!==void 0&&`deviceId`in e?{deviceId:e.deviceId,cap:r,path:i}:null,problem:e.state===`ready`?void 0:e.reason===e.state?a(`customize.motion.state.${e.state}`):`${a(`customize.motion.state.${e.state}`)}: ${e.reason}`,onRemove:w===null?void 0:()=>void N(e),removeLabel:a(`customize.assign.removeNamed`,{name:n}),busy:j},t)})]}),d(Xa,{open:u,title:a(`customize.motion.pickTitle`),selection:`multi`,candidates:E,filters:Na,confirmLabel:e=>a(`customize.assign.addCount`,{count:e}),onConfirm:e=>{if(p(!1),w===null)return;let t=yo(w,e.map(e=>e.ref));if(t!==null&&t.sensors.length>8){h(a(`customize.motion.tooMany`,{max:8}));return}M(t)},onClose:()=>p(!1)})]})}var Ao=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary disabled:opacity-50 disabled:cursor-not-allowed`;function jo({dimension:e,value:t,onChange:n,disabled:i=!1,emptyReason:a,inheritLabel:o,className:s,id:c,"aria-label":l}){let u=e===void 0?[]:$n(e),f=e===void 0;return r(`div`,{className:`flex flex-col gap-0.5 min-w-0 w-full`,children:[r(`select`,{id:c,className:s??Ao,"aria-label":l,value:t,onChange:e=>{let t=e.target.value;if(t===``){n(``);return}n(tr(t)??t)},disabled:i||f,children:[o!==void 0&&d(`option`,{value:``,children:o}),u.map(e=>d(`option`,{value:e,children:e},e))]}),f&&a!==void 0&&a!==``&&d(`span`,{className:`text-[10px] text-foreground-subtle`,children:a})]})}var Mo={"numeric-sensor":{fieldPath:`value`,unitField:`unit`},"temperature-sensor":{fieldPath:`celsius`,unitField:`unit`},"humidity-sensor":{fieldPath:`percent`,unitField:`unit`},"pressure-sensor":{fieldPath:`hpa`,unitField:`unit`},"ambient-light-sensor":{fieldPath:`lux`,unitField:`unit`}},No=new Set([q.Camera]);function Po(e){return e.unitField===null?[e.fieldPath]:[e.fieldPath,e.unitField]}function Fo(e,t){if(No.has(e))return{kind:`absent`};let n=null;for(let[e,r]of Object.entries(Mo))if(t.has(e)){n={cap:e,fieldPath:r.fieldPath,unitField:r.unitField};break}let r=null;for(let e of Yn)if(t.has(e)){let t=Wn[e];if(t!==void 0){r={cap:e,fieldPath:t};break}}return n===null&&r===null?{kind:`absent`}:{kind:`present`,convert:n,invert:r}}function Io(e){return Zn(e.from,e.to)?or(e):null}function Lo(e){return Vn(e)}var Ro=/^convert\(v,\s*"[^"]*",\s*"[^"]*"\)$/;function zo(e){return e!==void 0&&Ro.test(e.expr)}function Bo(e){return e===void 0||e.expr===`!v`||Ro.test(e.expr)?!1:e.bindings.v!==void 0}function Vo(e){let t=e.expr.trim();if(t===``)return{kind:`refused`,reason:`expression is empty`};let n={kind:`expression`,expr:t,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:e.fieldPath}}},r=Kn({source:n,now:Date.now(),read:()=>({state:`fresh`,value:e.probe})});return r.state===`unavailable`?{kind:`refused`,reason:r.reason}:{kind:`ok`,feature:{kind:`fields`,cap:e.cap,fields:{[e.fieldPath]:n}}}}function Ho(e,t,n){if(e===null)return null;let r=qr(e,n.cap);if(r===null)return e;let i=new Set(Po(n)),a=Object.fromEntries(Object.entries(r.fields).filter(([e])=>!i.has(e)));return Object.keys(a).length===0?wr(e,n.cap):Y(e,t,{kind:`fields`,cap:n.cap,...r.enabled===void 0?{}:{enabled:r.enabled},fields:a,...r.items===void 0?{}:{items:r.items}})}n();function Uo(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`unit`);return typeof t==`string`?t:void 0}function Wo(e,t){if(typeof e!=`object`||!e)return;let n=Reflect.get(e,t);return typeof n==`number`&&Number.isFinite(n)?n:void 0}function Go(e,t){let n=qr(e,t.cap);if(n===null)return;let r=n.fields[t.fieldPath];return r!==void 0&&r.kind===`expression`?r:void 0}function Ko(e,t){let n=Go(e,t);return n===void 0||!zo(n)?null:/^convert\(v,\s*"[^"]*",\s*"([^"]*)"\)$/.exec(n.expr)?.[1]??null}function qo(e,t){let n=Go(e,t);return n===void 0||!Bo(n)?null:n.expr}function Jo(e,t,n){let r=qr(e,t);if(r===null)return!1;let i=r.fields[n];return i!==void 0&&i.kind===`expression`&&i.expr===`!v`}function Yo(e){return typeof e==`number`||typeof e==`boolean`||typeof e==`string`?String(e):e===null?`null`:JSON.stringify(e)}function Xo({device:e,target:t,handle:n,facts:i}){let{t:a}=J(),o=v(),[s,c]=l(null),[u,f]=l(``),[p,m]=l(null),h=i.nativeCaps.kind===`known`?i.nativeCaps.value:null,g=h===null?null:Fo(e.type,h),_=g?.kind===`present`?g.convert?.cap??``:``,y=Ot(o.trpcClient,e.id,_);if(i.nativeCaps.kind===`pending`)return d(`section`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(ja,{availability:{kind:`pending`}})});if(i.nativeCaps.kind===`unknown`)return d(`section`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(ja,{availability:{kind:`unknown`,reason:i.nativeCaps.reason}})});if(g===null||g.kind===`absent`)return null;let b=sa(n.state),x=g.convert,S=g.invert,C=x===null?void 0:Uo(y),w=C===void 0?void 0:tr(C)??C,T=w===void 0?void 0:Hn(w),E=x===null?null:Ko(b,x),D=x===null?null:qo(b,x),O=p??D??``,k=S===null?!1:Jo(b,S.cap,S.fieldPath),A=n.state.kind===`none`||n.state.kind===`present`,j=x===null?0:Wo(y,x.fieldPath)??0,M=x!==null&&O.trim()!==``?{kind:`expression`,expr:O.trim(),bindings:{v:{kind:`from`,source:t,cap:x.cap,fieldPath:x.fieldPath}}}:null,N=M===null||x===null?null:Rr(M,new Map([[Jn(t,x.cap),y===void 0?{kind:`pending`}:{kind:`value`,slice:y}]]),Date.now()),P=async e=>{let t=await n.save(e);c(t.kind===`refused`?t.reason:null)},F=async()=>{if(x===null||w===void 0||u===``)return;let e=Io({self:t,cap:x.cap,fieldPath:x.fieldPath,from:w,to:u,unitField:x.unitField});if(e===null){c(a(`customize.numericTransforms.convertRefused`));return}m(null),await P(Y(b,t,e))},I=async()=>{x!==null&&(await P(Ho(b,t,x)),f(``))},ee=async()=>{if(x===null)return;let e=Vo({self:t,cap:x.cap,fieldPath:x.fieldPath,expr:O,probe:j});if(e.kind===`refused`){c(e.reason);return}f(``),await P(Y(b,t,e.feature))},L=async()=>{x!==null&&(await P(Ho(b,t,x)),m(``))},R=async()=>{if(S===null)return;let e=Lo({self:t,cap:S.cap});if(e===null){c(a(`customize.numericTransforms.invertRefused`));return}await P(Y(b,t,e))},te=async()=>{S===null||b===null||await P(wr(b,S.cap))};return r(`section`,{"aria-labelledby":`customize-numeric-transforms`,className:`rounded-lg border border-border bg-surface`,"data-testid":`numeric-transforms-card`,children:[r(`header`,{className:`flex flex-wrap items-center gap-2 border-b border-border px-2 py-2 sm:px-4`,children:[d(ii,{className:`h-4 w-4 text-foreground-subtle`,"aria-hidden":!0}),d(`h2`,{id:`customize-numeric-transforms`,className:`flex-1 text-sm font-semibold`,children:a(`customize.numericTransforms.title`)})]}),r(`div`,{className:`flex flex-col gap-3 px-2 py-3 sm:px-4`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:a(`customize.numericTransforms.blurb`)}),s!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:s}),x!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-convert`,children:[d(`label`,{className:`text-[11px] font-medium text-foreground`,children:a(`customize.numericTransforms.publishUnit`)}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:w===void 0?a(`customize.numericTransforms.fromUnknown`):a(`customize.numericTransforms.fromUnit`,{unit:w})}),d(jo,{dimension:T,value:u===``?E??``:u,onChange:e=>{f(e),e!==``&&m(``)},disabled:!A||n.saving||w===void 0,"aria-label":a(`customize.numericTransforms.toUnit`),inheritLabel:a(`customize.numericTransforms.pickUnit`),emptyReason:a(`customize.numericTransforms.fromUnknown`)}),r(`div`,{className:`flex flex-wrap gap-2`,children:[d(G,{size:`sm`,disabled:!A||n.saving||w===void 0||u===``||u===w,onClick:()=>void F(),children:a(`customize.numericTransforms.applyConvert`)}),E!==null&&d(G,{size:`sm`,variant:`outline`,disabled:!A||n.saving,onClick:()=>void I(),children:a(`customize.numericTransforms.clearConvert`)})]})]}),x!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-script`,children:[d(Vr,{label:a(`customize.numericTransforms.script`),value:O,bindings:[`v`],onChange:e=>{m(e),e.trim()!==``&&f(``)}}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`customize.numericTransforms.scriptBlurb`)}),N!==null&&d(`p`,{role:`status`,className:`text-[11px] font-mono text-foreground`,"data-testid":`numeric-script-preview`,children:N.kind===`value`?a(`customize.numericTransforms.preview`,{source:Yo(j),result:Yo(N.value)}):N.kind===`waiting`?a(`customize.numericTransforms.previewWaiting`):N.kind===`unavailable`?a(`customize.numericTransforms.previewError`,{reason:N.reason}):a(`customize.numericTransforms.previewRuntimeOnly`)}),r(`div`,{className:`flex flex-wrap gap-2`,children:[d(G,{size:`sm`,disabled:!A||n.saving||O.trim()===``,onClick:()=>void ee(),children:a(`customize.numericTransforms.applyScript`)}),D!==null&&d(G,{size:`sm`,variant:`outline`,disabled:!A||n.saving,onClick:()=>void L(),children:a(`customize.numericTransforms.clearScript`)})]})]}),S!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-invert`,children:[d(`label`,{className:`text-[11px] font-medium text-foreground`,children:a(`customize.numericTransforms.invert`)}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`customize.numericTransforms.invertBlurb`)}),d(`div`,{className:`flex flex-wrap gap-2`,children:k?d(G,{size:`sm`,variant:`outline`,disabled:!A||n.saving,onClick:()=>void te(),children:a(`customize.numericTransforms.clearInvert`)}):d(G,{size:`sm`,disabled:!A||n.saving,onClick:()=>void R(),children:a(`customize.numericTransforms.applyInvert`)})})]})]})]})}n();function Zo(e){return e instanceof Error?e.message:String(e)}function Qo(e){let n=Re({addonId:e.addonId,stableId:e.stableId}),r=V(),i=Qe(),a=fe(),o=oa({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}}),{t:s}=J(),c=t(!1),[u,d]=l(!1),f=async e=>{let t=kr(o,e);try{switch(t.kind){case`refused`:return{kind:`refused`,reason:t.reason};case`noop`:return{kind:`saved`};case`create`:await r.mutateAsync({block:t.input});break;case`update`:await i.mutateAsync({blockId:t.blockId,expectedUpdatedAt:t.expectedUpdatedAt,block:{composition:t.composition}});break;case`delete`:await a.mutateAsync({blockId:t.blockId});break}return await n.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Zo(e)}}};return{target:e,state:o,saving:u||r.isPending||i.isPending||a.isPending,save:async e=>{if(c.current)return{kind:`refused`,reason:s(`customize.saveInFlight`)};c.current=!0,d(!0);try{return await f(e)}finally{c.current=!1,d(!1)}}}}var $o=`pipeline-orchestrator`;function es(e){return e.status===`pending`?`pending`:e.status===`error`?`unknown`:e.data===void 0?`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function ts(e,t){return e===`absent`?`absent`:es(t)}async function ns(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function rs(e,t){let n=xn($o),r=F({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>ns(r.refetch);return t?{presence:ts(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,refetch:i}:{presence:`absent`,status:null,refetch:i}}function is(e,t){let n=Nn({deviceType:e.type}),r=Lt({deviceId:e.id}),i=wn({deviceId:e.id}),a=Ma(n,e=>new Set(e.caps.map(e=>e.cap))),o=Ma(r,e=>ta(e.entries)),s=Ma(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}var as={kind:`unknown`,reason:`the composer reports no value for this field`};function os(e,t){let n=K(e);return t.get(n)??n}function ss(e,t,n){let r=n.nativeCaps.has(e.cap)?`replaced`:`added`,i=t.filter(t=>t.cap===e.cap&&t.origin===`composed`);if(e.cap===`doorbell`){let t=Br(e).map(e=>os(e,n.sourceNames)).join(` + `),a=i.find(e=>e.field===`lastPressedAt`);return[{key:`doorbell`,label:`doorbell`,origin:{kind:r,from:t},value:a?.value??as}]}return e.cap===`consumables`?Mr(e).map(e=>{let t=t=>ir(Un,e.key,t),a=i.find(e=>e.field===t(`level`)||e.field===t(`remaining.value`)),o=e.source===null?``:os(e.source.source,n.sourceNames);return{key:`consumables.${e.key}`,label:`consumables · ${e.label}`,origin:{kind:r,from:o},value:a?.value??as}}):i.map(e=>({key:e.key,label:`${e.cap}.${e.field}`,origin:{kind:r,from:e.from},value:e.value}))}function cs(e){let t=Fr({composition:e.composition,nativeCaps:e.nativeCaps,state:e.state,nativeFields:new Map,snapshot:null,sourceNames:e.sourceNames});return e.composition.features.flatMap(n=>n.kind===`fields`?ss(n,t,e):[])}function ls(e,t){if(e?.state!==`configured`||e.sensors.length===0)return null;let n=e.cameraMotion===`never`?[]:[t.camera],r=e.sensors.map(e=>t.sensor(e.state===`missing`||e.state===`unreadable`?e.stableId:e.name,e.mode));return[...n,...r].join(` + `)}var us=`grid grid-cols-[minmax(0,1fr)_auto] gap-x-3 gap-y-1 items-baseline px-2 py-2 sm:px-4 sm:grid-cols-[minmax(0,1fr)_minmax(0,2fr)_auto]`;function ds({device:e,composition:t,state:n,nativeCaps:i,cameraSensors:a}){let{t:o}=J(),s=t!==null&&n!==null,c=Ha(s),l=new Map(c.kind===`known`?c.value.map(e=>[K({addonId:e.addonId,stableId:e.stableId}),e.name]):[]),u=s&&i.kind===`known`?cs({composition:t,nativeCaps:i.value,state:n,sourceNames:l}):[],f=s&&i.kind===`known`&&u.length===0&&t.features.length>0,p=ls(a,{camera:o(`customize.changes.motion.camera`),sensor:(e,t)=>o(`customize.changes.motion.${t}`,{name:e})}),m=s&&i.kind!==`known`;return u.length===0&&p===null&&!m&&!f?null:r(`section`,{"aria-labelledby":`customize-changes`,className:`rounded-lg border border-border bg-surface`,children:[d(`h2`,{id:`customize-changes`,className:`px-3 py-2 text-[11px] font-semibold uppercase tracking-wider border-b border-border`,children:o(`customize.changes.title`)}),m&&d(`p`,{role:i.kind===`unknown`?`alert`:`status`,className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:i.kind===`unknown`?o(`customize.changes.unknown`,{reason:i.reason}):o(`customize.changes.reading`)}),f&&d(`p`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:o(`customize.changes.noRows`)}),r(`ul`,{className:`divide-y divide-border`,children:[u.map(e=>r(`li`,{className:us,children:[d(`span`,{className:`font-mono text-xs break-words`,children:e.label}),d(`span`,{className:`col-span-2 row-start-2 text-xs text-foreground-subtle break-words sm:col-span-1 sm:row-start-auto`,children:c.kind===`known`?o(`customize.changes.origin.${e.origin.kind}`,{from:e.origin.from}):o(`customize.changes.originUnread.${c.kind}`,{kind:o(`customize.changes.kind.${e.origin.kind}`),reason:c.kind===`unknown`?c.reason:``})}),d(`span`,{className:`row-start-1 col-start-2 text-xs sm:row-start-auto sm:col-start-auto`,children:d(fs,{value:e.value})})]},e.key)),p!==null&&r(`li`,{className:us,children:[d(`span`,{className:`font-mono text-xs`,children:`motion`}),d(`span`,{className:`col-span-2 row-start-2 text-xs text-foreground-subtle break-words sm:col-span-1 sm:row-start-auto`,children:p}),d(`span`,{className:`row-start-1 col-start-2 sm:row-start-auto sm:col-start-auto`,children:d(Oa,{target:{deviceId:e.id,cap:`motion`,path:`detected`}})})]})]})]})}function fs({value:e}){let{t}=J();switch(e.kind){case`value`:return r(`span`,{children:[Hr(e.value,!0),e.staleReason!==null&&r(`span`,{className:`text-warning`,children:[` `,`· `,t(`customize.changes.value.stale`,{reason:e.staleReason})]})]});case`unavailable`:return d(`span`,{className:`text-warning`,children:t(`customize.changes.value.unavailable`,{reason:e.reason})});case`unknown`:return d(`span`,{className:`text-foreground-subtle`,children:t(`customize.changes.value.unknown`,{reason:e.reason})});case`off`:return d(`span`,{className:`text-foreground-subtle`,children:t(`customize.status.off`)})}}n();function ps({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=J(),i=Ut({deviceId:e}),a=i.data;return a==null?i.status===`error`?d(an,{title:r(`customize.deviceUnreadable`),message:i.error?.message??``,onRetry:()=>void i.refetch()}):a===null?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.noSuchDevice`,{deviceId:e})}):d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.loadingDevice`)}):a.addonId===`composer`?d(ms,{device:a}):d(hs,{device:a,target:{addonId:a.addonId,stableId:a.stableId},activeSubTab:t,onSubTabChange:n})}function ms({device:e}){let{t}=J(),n=e.stableId.startsWith(`composed-`)?e.stableId.slice(dr.length):null;return r(`section`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-col gap-2`,children:[d(`p`,{className:`text-sm text-foreground`,children:t(`customize.composed.body`)}),n!==null&&d(mr,{className:`text-sm text-primary`,to:pr(n),children:t(`customize.composed.edit`)})]})}function hs({device:e,target:t,activeSubTab:n,onSubTabChange:i}){let a=Qo(t),o=xn(`composer`),{t:s}=J(),c=rs(e.id,e.type===q.Camera),l=is(e,sa(a.state)),u={deviceType:e.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},f=()=>i(br),p=a.state.kind===`none`||a.state.kind===`present`;return n===`advanced`?r(`div`,{className:`flex flex-col gap-4`,children:[d(_s,{state:a.state}),p&&d(gs,{device:e,target:t,handle:a,facts:l,onDone:()=>i(`main`)})]}):r(`div`,{className:`flex flex-col gap-4`,children:[d(ga,{device:e}),o===`absent`&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),a.state.kind!==`none`&&d(_s,{state:a.state}),d(io,{device:e,handle:a,availability:aa(`doorbell`,u),onAdvanced:f}),d(ko,{device:e,handle:a,availability:aa(`motion`,u),sensors:c}),d(Ka,{device:e,handle:a,availability:aa(`battery`,u),onAdvanced:f}),d(Ya,{device:e,handle:a,availability:aa(`consumables`,u),onAdvanced:f}),d(Xo,{device:e,target:t,handle:a,facts:l}),d(ho,{device:e}),d(ds,{device:e,composition:sa(a.state),state:a.state.kind===`present`?a.state.view.state:null,nativeCaps:l.nativeCaps,cameraSensors:c.status}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[p?d(G,{variant:`ghost`,className:`text-primary underline`,onClick:f,children:s(`customize.advancedLink`)}):d(`span`,{}),d(vs,{handle:a})]})]})}function gs({device:e,target:t,handle:n,facts:r,onDone:i}){let a=n.state.kind===`present`?n.state:null;return d(Ur,{initial:a===null?Tr(t):Er(a.composition,``),blockId:a===null?null:a.view.block.id,deviceType:e.type,targetName:e.name,nativeCaps:r.nativeCaps,targetFields:r.wireable,onCancel:i,save:async e=>{let t=await n.save(e);return t.kind===`saved`&&i(),t}})}function _s({state:e}){let{t}=J();switch(e.kind){case`pending`:return d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.pending`)});case`unknown`:return d(an,{title:t(`customize.status.unknownTitle`),message:e.reason});case`not-loaded`:return d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.notLoaded`,{reason:e.reason})});case`none`:return null;case`present`:{let n=e.view.block;return r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(en,{variant:n.status===`running`?`success`:n.status===`failed`?`danger`:`warning`,children:t(`customize.blockStatus.${n.status}`)}),!n.enabled&&d(en,{variant:`default`,children:t(`customize.status.off`)}),n.lastError!==void 0&&d(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:n.lastError}),e.view.state.kind===`unreachable`&&d(`span`,{className:`text-[11px] text-warning`,children:t(`customize.status.composerUnreachable`,{reason:e.view.state.error})})]})}}}function vs({handle:e}){let{t}=J(),n=Et(),[i,a]=l(null);if(e.state.kind!==`present`)return null;let o=async()=>{if(!await n({title:t(`customize.remove.title`),message:t(`customize.remove.message`),confirmLabel:t(`customize.remove.confirm`),variant:`danger`}))return;let r=await e.save(null);a(r.kind===`refused`?r.reason:null)};return r(`div`,{className:`flex flex-col items-start gap-1`,children:[d(G,{variant:`danger`,disabled:e.saving,onClick:()=>void o(),children:t(`customize.remove.button`)}),i!==null&&d(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:i})]})}var ys=`overview`;function bs(e,t){return e.some(e=>e.id===t)?t:ys}function xs({deviceId:e}){let t=c(),n=Number.isFinite(e),{data:i}=Ut({deviceId:e},{enabled:n}),a=typeof i?.type==`string`?i.type:`camera`;dn([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:s,isError:l,error:u}=Lt({deviceId:e},{enabled:n}),{data:f}=wt({deviceType:a},{enabled:!!a}),p=tt({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(s)return d(`div`,{className:`p-4`,children:d(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(l)return r(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,u instanceof Error?u.message:String(u)]});let m=new Map,h={};for(let e of f??[])h[e.capName]=e.wrappers;for(let e of o?.entries??[])m.set(e.capName,{...e,wrappers:h[e.capName]??[]});for(let e of f??[])m.has(e.capName)||m.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let g=[...m.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(g.length===0)return r(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[d(Fn,{className:`h-8 w-8 opacity-40`}),d(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),d(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let _=g.filter(e=>e.kind!==`unbound`).length;return r(`div`,{className:`flex flex-col gap-3 p-1`,children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[d(`span`,{className:`font-medium text-foreground`,children:_}),` of `,g.length,` capabilit`,g.length===1?`y`:`ies`,` bound — rows marked `,d(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),d(Mt,{columns:[{key:`capability`,header:`Capability`,render:e=>d(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>d(Ss,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>d(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||d(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?d(Cs,{nodeId:e.providerNodeId}):d(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>d(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||d(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return d(ws,{wrappers:t.wrappers,activeWrapperId:n,disabled:p.isPending,onPick:r=>{let i=n===r;p.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:g,rowKey:e=>e.capName,minWidthPx:720})]})}function Ss({kind:e}){return e===`native`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(Zt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(zn,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(qt,{className:`h-3 w-3`}),`linked`]}):r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[d(ht,{className:`h-3 w-3`}),`unbound`]})}function Cs({nodeId:e}){return d(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function ws({wrappers:e,activeWrapperId:t,disabled:n,onPick:i}){return e.length===0?d(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let a=e===t;return r(`button`,{disabled:n,onClick:()=>i(e),title:a?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${a?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[d(a?le:b,{className:`h-3 w-3`}),e]},e)})})}function Ts({deviceId:e,activeSubTab:t,onSubTabChange:n,deviceType:i,isAdmin:a}){return r(`div`,{className:`flex flex-col gap-3`,children:[ti(i,a)&&d(gn,{deviceId:e,readOnly:!0}),d(ri,{deviceId:e,activeSubTab:t,onSubTabChange:n})]})}n();var Es=new Set([`package-detection`]);function Ds(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Os(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function ks({deviceId:e,refreshToken:t}){let n=c(),i=v().trpcClient,[u,f]=l(null),[p,m]=l(null),[h,g]=l(null),_=Qt({deviceId:e},{refetchOnMount:`always`}),y=W({deviceId:e},{refetchOnMount:`always`}),b=ee(void 0,{refetchOnMount:`always`});dn([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:x}=jn(),S=a(()=>{let e=new Set;for(let t of x)t.isOnline&&e.add(t.id);return e},[x]),C=a(()=>(b.data??[]).filter(e=>S.has(e.nodeId)).map(e=>e.nodeId),[b.data,S]),w=o({enabled:C.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`device-step-schemas`,C.join(`,`),t],queryFn:async()=>{let e={};for(let t of C)try{e[t]=await i.pipelineExecutor.getSchema.query({nodeId:t})}catch{}return e}}),T=e=>w.data?.[e]??null,E=a(()=>{let e=C[0];if(e!==void 0){let t=w.data?.[e];if(t)return t}return Object.values(w.data??{})[0]??null},[C,w.data]),D=o({enabled:C.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,C.join(`,`),t],queryFn:async()=>{let e={};for(let t of C)try{e[t]=(await i.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),O=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},k=M({onSuccess:O}),A=Pt({onSuccess:O}),j=a(()=>E?At(E):[],[E]),N=a(()=>{let e=b.data??[],t=S.size===0?[]:e.filter(e=>S.has(e.nodeId)),n=[];for(let e of t){let t=(D.data?.[e.nodeId]??[]).filter(e=>e.enabled&&e.available);if(t.length>=2)for(let r of t)n.push({agentNodeId:e.nodeId,engineLabel:r.format,deviceKey:r.key,deviceLabel:Rn(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[b.data,D.data,S]),P=(e,t)=>D.data?.[e]?.find(e=>e.key===t)??null,F=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=D.data?.[e.agentNodeId]??[],n=t.filter(e=>e.enabled&&e.available);return n.length>=1?n[0].key:t.find(e=>e.available)?.key??t[0]?.key??null},I=(e,t,n)=>y.data?.[e]?.[t]?.[n]??null,L=e=>{if(Es.has(e))return{kind:`zone-driven`};let t=Ds(E,e)?.enabledByDefault??!0,n=_.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},R=(e,t,n)=>{let r=Ds(T(n),e);if(r)return Je(r,t)},te=(e,t)=>{let n=L(e),r=n.kind===`gate`?n.effectiveOn:!1,i=Ds(T(t.agentNodeId),e),a=F(t),o=a===null?null:P(t.agentNodeId,a);if(!oe(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:I(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?rt({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:Os(s)}},ne=u===null?null:Ds(T(u.agentNodeId),u.addonId),z=u?P(u.agentNodeId,u.deviceKey):null,re=z?.format??`coreml`,B=u?Os(I(u.agentNodeId,u.deviceKey,u.addonId)):!1,V=u?R(u.addonId,z,u.agentNodeId):void 0,ie=a(()=>{if(!u||!z)return null;let e=z.steps?.[u.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[u,z]),H=()=>{f(null),m(null)},ae=(e,t)=>{let n=F(t);n!==null&&(f({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),m(I(t.agentNodeId,n,e)))},se=(t,n)=>{A.mutate({deviceId:e,addonId:t,enabled:n})},le=()=>{u&&k.mutate({deviceId:e,agentNodeId:u.agentNodeId,deviceKey:u.deviceKey,addonId:u.addonId,patch:p},{onSuccess:H})},ue=()=>{u&&k.mutate({deviceId:e,agentNodeId:u.agentNodeId,deviceKey:u.deviceKey,addonId:u.addonId,patch:null},{onSuccess:H})};if(b.isLoading||C.length>0&&w.isLoading)return d(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(N.length===0)return d(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!E)return d(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let de=u!==null&&ne!==null&&z!==null;return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[d(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,d(`span`,{className:`font-medium text-foreground`,children:`node column`}),` shows the model that node runs; click a cell to pin a per-camera model override for that accelerator. A gated-on step with no model on a device shows a clickable `,d(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),r(`div`,{className:`rounded-md border border-sky-500/25 bg-sky-500/[0.06] px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[d(`span`,{className:`font-medium text-sky-400`,children:`Placement is dynamic.`}),` When a node has multiple inference accelerators, each session is balanced across them per-session at dispatch time — these device columns show each accelerator's effective model (override ?? device default), not a fixed assignment.`]}),d(`div`,{className:de?`md:pr-[360px]`:``,children:j.length>0?d(Be,{tree:j,agents:N,gateFor:L,getCellState:te,onCellClick:ae,selectedCell:u,onSetGate:se,gateBusy:A.isPending,fallbackNodeId:h,onFallbackNodeChange:g}):d(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),d(It,{open:de,onClose:H,title:ne?.name??``,subtitle:u&&z?`${u.agentNodeId} · ${Rn(z).label} · ${z.format}`:``,footer:r(s,{children:[d(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle disabled:opacity-50`,disabled:!B||k.isPending,onClick:ue,children:`Clear override`}),d(`div`,{className:`flex-1`}),d(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:H,children:`Cancel`}),d(`button`,{type:`button`,disabled:!u||!ie||k.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:le,children:k.isPending?`Saving…`:`Save`})]}),children:ne&&u&&ie?d(ce,{mode:`device`,addon:ne,agentDefault:ie,agentNodeId:u.agentNodeId,currentPatch:p,engineFormat:re,effectiveModelId:V,onChangePatch:m}):d(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}var As=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],js={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function Ms(e){return js[e]??`object-detection`}n();var Ns=`steps`,Ps=`settings`,Fs=new Set([Ns,Ps]);function Is(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Ls({deviceId:t,activeSubTab:n,onSubTabChange:i}){return r(Dt,{value:n&&Fs.has(n)?n:Ns,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(He,{className:`flex-shrink-0`,children:[d(R,{value:Ns,children:`Steps`}),d(R,{value:Ps,children:`Settings`})]}),d(On,{value:Ns,children:d(ks,{deviceId:t,refreshToken:0})}),d(On,{value:Ps,children:d(ri,{deviceId:t,sectionFilter:Is,subTabGrouping:{groupOf:e=>Ms(e.id),tabs:As}})})]})}n();function Rs({deviceId:e}){let t=c(),{data:n}=Cr(e),{data:i}=Sr(e),[a,o]=l(null),u=I({onSuccess:()=>{o(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{o(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==q.Container)return null;let f=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(f.length<=1)return null;let p=sn(f,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return r(s,{children:[d(Q,{label:`Primary child`,value:d(ie,{childrenList:f,selectedId:p===null?f[0].id:p.id,onSetPrimary:t=>u.mutate({deviceId:e,primaryChildEntityId:t}),disabled:u.isPending})}),a!==null&&d(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:a})]})}n();var zs=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Bs(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Vs(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Hs(){let e=Vt(),t=yt(),{data:n}=Ut({deviceId:e??0},{enabled:e!==null}),{data:i}=Lt({deviceId:e??0},{enabled:e!==null}),a=n??t??null,[o,s]=l(`identity`);if(e===null||!a)return null;let c=String(a.stableId??``),u=String(a.name??``),f=String(a.type??``),p=String(a.addonId??``),m=a.features??[],h=new Set([`device-status`,`feature-probe`,`device-ops`]),g=(i?.entries??[]).filter(e=>e.kind===`native`&&!h.has(e.capName)).map(e=>e.capName),_=m.length>0?m:g,v=a.location??null,y=a.metadata??null,b=y!==null&&Object.keys(y).length>0;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[d(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),b&&r(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[d(Us,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),d(Us,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!b||o===`identity`)&&r(`div`,{className:`divide-y divide-border`,children:[d(Q,{label:`ID`,value:r(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,r(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,c,`)`]})]})}),d(ca,{deviceId:e,initialName:u}),d(la,{deviceId:e,initialLocation:v}),d(Rs,{deviceId:e}),d(Q,{label:`Type`,value:f}),d(Q,{label:`Provider`,value:d(In,{type:p,size:`sm`,showLabel:!0})}),d(Q,{label:`Capabilities`,value:_.length>0?d(Bn,{capabilities:_,showLabels:!0}):d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),b&&o===`hardware`&&d(Ws,{metadata:y})]})}function Us({active:e,onClick:t,label:n}){return d(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function Ws({metadata:e}){let t=zs.filter(t=>t in e),n=Object.keys(e).filter(e=>!zs.includes(e)).toSorted(),i=[...t,...n];return r(`div`,{children:[d(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),d(`div`,{className:`divide-y divide-border`,children:i.map(t=>d(Q,{label:Bs(t),value:d(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Vs(e[t])})},t))})]})}var Gs=`Notifications`,Ks=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function qs(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Gs,on:r===null?null:i??r,available:r!==null,costWhenOff:Ks}}function Js(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function Ys(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Xs({deviceId:t}){let n=c(),i=Number.isFinite(t),[a,o]=l(null),[s,u]=l(null),f=qs({mutedDeviceIds:Ys(lt({},{enabled:i}).data),deviceId:t,pendingOn:s}),p=at({onError:e=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),u(null),o(e instanceof Error?e.message:String(e)),n.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{o(null),u(null),n.invalidateQueries({queryKey:[[`notificationRules`]]})}}),m=e(()=>{let e=Js(f,t);e!==null&&(u(!e.muted),p.mutate(e))},[t,p,f]),h=f.on===null,g=f.on===!1,_=g?gt:ct;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Notifications`}),g&&d(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:`muted`})]}),r(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[r(`button`,{type:`button`,role:`switch`,"aria-label":f.label,"aria-checked":f.on===!0,disabled:!f.available||p.isPending,onClick:m,title:h?`Notification mute — state unknown; the notification centre did not answer.`:g?`Muted. ${f.costWhenOff}`:`Notifying. Muting it: ${f.costWhenOff}`,className:`inline-flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${a===null?h?`border-dashed border-border text-foreground-subtle/50`:g?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[d(_,{className:`h-3.5 w-3.5`}),d(`span`,{children:h?`Unknown`:g?`Muted`:`Notifying`})]}),d(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:a===null?h?`The notification centre did not answer, so this device’s mute state is unknown.`:f.costWhenOff:`Write failed: ${a}`})]})]})}function Zs(e,t){return{switchId:e,label:rr[e].label,detail:t===void 0||t.length===0?null:t}}function Qs(e){let t=new Map;for(let n of e.switches)n.deviceId===e.sourceId&&(t.has(n.switchId)||t.set(n.switchId,n));return t}function $s(e){let t=Qs(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>Zs(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>Zs(e.switchId,e.detail));return{inheritedId:e.sourceId,retiredId:e.targetId,swapped:e.swapped,verdict:r.length===0?`quiet`:`still-live`,stillLive:r,neverOffered:i}}n();function ec(e,t){return e.filter(e=>e.isCamera&&e.id!==t).map(e=>({id:e.id,name:e.name})).toSorted((e,t)=>e.name.localeCompare(t.name))}function tc({deviceId:e,deviceName:t}){let{t:n}=J(),i=Et(),[o,s]=l(null),c=An({isCamera:!0,projection:`slim`}),u=We(),f=c.data!==void 0,p=a(()=>c.data===void 0?[]:ec(c.data,e),[c.data,e]),m=p.find(e=>e.id===o)??null,h=u.data===void 0?null:$s(u.data),g=u.error===null?null:u.error.message,_=async()=>{m===null||m.id===e||await i({title:n(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:t,target:m.name}),message:n(`deviceMigrate.confirmMessage`,`“{{target}}” takes over number {{sourceId}}. That number is what every recording, event, rule, zone and home-automation export of “{{source}}” is filed under, so all of it follows the number to the new hardware and keeps working. “{{source}}” is switched off and handed number {{targetId}} in exchange. This swaps two device identities and cannot be undone from here.`,{source:t,target:m.name,sourceId:e,targetId:m.id}),confirmLabel:n(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&u.mutate({sourceId:e,targetId:m.id})};return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`min-w-0`,children:[d(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:n(`deviceMigrate.title`,`Migrate to…`)}),d(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.subtitle`,`Replace this camera with other hardware you have already adopted. The new camera inherits number {{deviceId}}, so recordings, rules and integrations follow it.`,{deviceId:e})})]}),r(`div`,{className:`flex shrink-0 items-center gap-2`,children:[r(`select`,{"aria-label":n(`deviceMigrate.pickerLabel`,`Replacement camera`),className:`rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,disabled:!f||p.length===0||u.isPending,value:o===null?``:String(o),onChange:e=>{let t=e.target.value;s(t===``?null:Number(t))},children:[d(`option`,{value:``,children:f?n(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):n(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(e=>r(`option`,{value:String(e.id),children:[e.name,` (#`,e.id,`)`]},e.id))]}),r(`button`,{type:`button`,disabled:m===null||u.isPending,onClick:()=>{_()},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[d(ii,{className:`h-3 w-3`}),u.isPending?n(`deviceMigrate.running`,`Migrating…`):n(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&d(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&d(`p`,{className:`mt-2 text-[11px] text-danger`,children:n(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&d(nc,{report:h})]})}function nc({report:e}){let{t}=J(),n=e.verdict===`quiet`;return r(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:e.inheritedId,retiredId:e.retiredId})}),n?r(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[d(Se,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.quiet`,`Every function on the replaced camera was switched off — the old hardware is quiet.`)})]}):r(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[d(Le,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.stillLive`,`The replaced camera could not be reached, so these functions are STILL RUNNING on the old hardware. Nothing here failed to migrate — but until you unplug it or reach it physically, it can still produce data.`)})]}),d(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.stillLive.map(e=>r(`li`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:e.label}),e.detail!==null&&r(`span`,{className:`text-foreground-subtle`,children:[` — `,e.detail]})]},e.switchId))})]}),e.neverOffered.length>0&&r(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[d(Ln,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`deviceMigrate.neverOffered`,`The replaced camera never offered these, so there was nothing to switch off. They are not running.`)})]}),d(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.neverOffered.map(e=>d(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}n();function rc({deviceId:e}){let[t,n]=l(null),i=fn({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{children:[d(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),d(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),r(`button`,{type:`button`,disabled:i.isPending,onClick:()=>{n(null),i.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[d(be,{className:`h-3 w-3 ${i.isPending?`animate-spin`:``}`}),i.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&d(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}var ic=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary disabled:opacity-50 disabled:cursor-not-allowed`,ac=0,oc=10;function sc(e){if(e.trim()===``)return``;let t=Number.parseInt(e,10);return Number.isFinite(t)?String(t<ac?ac:t>oc?oc:t):``}function cc({value:e,onChange:t,disabled:n=!1,placeholder:r,className:i,id:a,"aria-label":o}){return d(`input`,{type:`number`,min:ac,max:oc,step:1,id:a,className:i??ic,"aria-label":o,placeholder:r,value:e,onChange:e=>{t(sc(e.target.value))},disabled:n})}function lc({deviceName:e,value:t,inheritedIcon:n,inheritedLabel:i,disabled:a,onChange:o}){let{t:s}=J(),c={trigger:s(`deviceDisplay.pickIcon`,{name:e}),panel:s(`deviceDisplay.iconFor`,{name:e}),close:s(`deviceDisplay.closePicker`),searchPlaceholder:s(`deviceDisplay.iconSearchPlaceholder`),clear:i,noMatches:s(`deviceDisplay.iconNoMatches`),groups:{device:s(`deviceDisplay.iconGroupDevice`),lighting:s(`deviceDisplay.iconGroupLighting`),sensing:s(`deviceDisplay.iconGroupSensing`),place:s(`deviceDisplay.iconGroupPlace`),life:s(`deviceDisplay.iconGroupLife`)}};return r(`div`,{className:`flex items-center gap-2`,children:[d(Ue,{value:t===``?null:t,onPick:e=>o(e??``),resolveGlyph:$e,fallbackGlyph:n,labels:c,disabled:a}),d(`span`,{className:`text-[11px] text-foreground-subtle`,children:t===``?i:t})]})}n();var uc=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary disabled:opacity-50`,dc={icon:``,label:``,unit:``,precision:``,hidden:!1};function fc(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function pc(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function mc(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function hc(e,t){let n=mc(e.precision),r={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...n===void 0?{}:{precision:n},...e.hidden?{hidden:!0}:{},...t?.perCap===void 0?{}:{perCap:t.perCap}};return Object.keys(r).length===0?null:r}function gc({deviceId:e}){let{t}=J(),n=v(),i=c(),{data:a}=Ut({deviceId:e},{enabled:e>0}),o=typeof a?.role==`string`&&a.role.length>0?a.role:null,u=o===null?void 0:k[o],f=u?.kind===`numeric`,p=String(a?.type??``),m=o!==null||a?.parentDeviceId!==null&&a?.parentDeviceId!==void 0,h=Ot(n.trpcClient,e,o??``),g=u?.kind===`numeric`?u.canonicalUnit:void 0,_=pc(h)??g,y=_===void 0?void 0:tr(_)??_,b=y===void 0?void 0:Hn(y),[x,S]=l(null),C=x??fc(a?.display),w=je({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:T}=vt({},{staleTime:6e4,enabled:o!==null}),E=se({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(a==null)return null;let D=e=>{S({...C,...e})},O=()=>{w.mutate({deviceId:e,display:hc(C,a.display)})},A=()=>{S(dc),w.mutate({deviceId:e,display:null})},j=()=>{if(o===null)return;let e=mc(C.precision),t={...C.icon===``?{}:{icon:C.icon},...C.unit===``?{}:{unit:C.unit},...e===void 0?{}:{precision:e}},n={...T?.defaults,[o]:t};E.mutate({defaults:n})},M=o===null?void 0:T?.defaults[o]?.icon,N=M===void 0?void 0:$e(M),P=o===null?Ke(p):Ye(o),F={icon:N??P.icon,label:N===void 0?P.label:String(M)},I=o===null&&p===q.Container?t(`deviceDisplay.inheritedContainer`):N===void 0?t(`deviceDisplay.inherited`,{name:F.label}):t(`deviceDisplay.inheritedRoleDefault`,{icon:F.label,role:P.label}),ee=typeof a.name==`string`?a.name:`#${String(e)}`,L=o===null?``:Ye(o).label;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[d(`div`,{className:`border-b border-border px-3 sm:px-4 py-2`,children:d(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:t(`deviceDisplay.title`)})}),r(`div`,{className:`divide-y divide-border`,children:[d(Q,{label:t(`deviceDisplay.icon`),value:d(lc,{deviceName:ee,value:C.icon,inheritedIcon:F.icon,inheritedLabel:I,disabled:w.isPending,onChange:e=>D({icon:e})})}),m&&d(Q,{label:t(`deviceDisplay.label`),value:d(`input`,{type:`text`,className:uc,"aria-label":t(`deviceDisplay.label`),placeholder:o===null?ee:L,value:C.label,onChange:e=>D({label:e.target.value})})}),f&&r(s,{children:[d(Q,{label:t(`deviceDisplay.unit`),value:d(jo,{dimension:b,value:C.unit,onChange:e=>D({unit:e}),disabled:w.isPending,"aria-label":t(`deviceDisplay.unit`),inheritLabel:t(`deviceDisplay.unitSource`,{unit:y===void 0?``:` (${y})`}),emptyReason:t(`deviceDisplay.unitSource`,{unit:``})})}),d(Q,{label:t(`deviceDisplay.precision`),value:d(cc,{"aria-label":t(`deviceDisplay.precision`),placeholder:t(`deviceDisplay.precisionInherit`),value:C.precision,onChange:e=>D({precision:e}),disabled:w.isPending})})]}),d(Q,{label:t(`deviceDisplay.hidden`),value:r(`label`,{className:`flex items-center gap-2`,children:[d(`input`,{type:`checkbox`,checked:C.hidden,onChange:e=>D({hidden:e.target.checked})}),d(`span`,{className:`text-[11px] text-foreground`,children:t(`deviceDisplay.hideFromLists`)})]})})]}),r(`div`,{className:`border-t border-border px-3 sm:px-4 py-2 flex flex-wrap items-center gap-2`,children:[d(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,onClick:O,disabled:w.isPending,children:t(`common.save`)}),d(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-[11px] text-foreground-subtle`,onClick:A,disabled:w.isPending,children:t(`common.reset`)}),o!==null&&d(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-[11px] text-foreground-subtle`,onClick:j,disabled:E.isPending,title:t(`deviceDisplay.setRoleDefaultTitle`,{role:L}),children:t(`deviceDisplay.setRoleDefault`,{role:L})})]})]})}function _c(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function vc({device:e}){let t=hr(),n=typeof e.id==`number`?e.id:null,i=String(e.type??``),a=i===q.Camera,o=i===q.Hub,s=e.features??[],c=s.includes(Gn.Resyncable),{data:l}=qe({deviceId:n??0},{enabled:n!==null&&a,refetchInterval:5e3}),u=l?.streams??{},f=Object.entries(u),p=s.includes(Gn.DoorbellButton),m=Gt(p?{deviceId:n??void 0,historyLimit:10}:void 0),h=m.latest?Date.now()-m.latest.timestamp<3e4:!1;return r(`div`,{className:`space-y-5`,children:[o&&n!==null&&d(Dn,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&d(rc,{deviceId:n}),a&&n!==null&&d(tc,{deviceId:n,deviceName:String(e.name??``)}),n!==null&&d(Xs,{deviceId:n}),a&&n!==null&&d(N,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),p&&d(Ct,{history:m.history,latestIsFresh:h}),a&&n!==null&&d(N,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),a&&f.length>0&&r(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[d(`div`,{className:`border-b border-border px-4 py-2`,children:d(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),d(`div`,{className:`divide-y divide-border`,children:f.map(([e,t])=>r(`div`,{className:`px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[d(ut,{className:`h-3 w-3 text-foreground-subtle`}),d(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),r(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[d(yc,{label:`Nominal`,value:_c(t.nominalBitrateKbps??0)}),d(yc,{label:`Observed`,value:_c(t.observedBitrateKbps??0)}),d(yc,{label:`Peak`,value:_c(t.peakBitrateKbps??0)}),d(yc,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),d(Hs,{}),n!==null&&d(gc,{deviceId:n})]})}function yc({label:e,value:t,warning:n}){return r(`div`,{children:[d(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),d(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}var bc=[{id:`overview`,label:`Overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1,adminOnly:!1},{id:yr,label:`Customize`,cameraOnly:!1,adminOnly:!0},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0,adminOnly:!1},{id:`bindings`,label:`Bindings`,cameraOnly:!0,adminOnly:!1}];function xc(e,t){let n=e===q.Camera;return bc.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)).map(({id:e,label:t})=>({id:e,label:t}))}function Sc({provider:e,integrationId:t,name:n}){let r=hr(),i=t===null?`/integrations`:`/integrations/${t}`,a=n===null?`Open integrations`:`Open integration ${n}`;return d(`button`,{type:`button`,onClick:()=>r(i),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:a,"aria-label":a,children:d(In,{type:e,size:`lg`})})}n();var Cc=[{id:`logs`,icon:Yt,label:`Logs`},{id:`repl`,icon:gr,label:`REPL`},{id:`events`,icon:pt,label:`Events`},{id:`state`,icon:z,label:`State`}];function wc(){let n=vr(),i=Number(n.deviceId),o=Number.isFinite(i),u=hr(),f=c(),p=Et(),h=v(),{user:g}=xr(),_=g?.isAdmin===!0,[y,b]=_r(),x=y.get(`tab`)??`overview`,S=y.get(`sub`),[C,E]=l(`logs`),O=`device-detail.left-col-width-px`,[k,A]=l(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(O),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),j=t(k);j.current=k;function M(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??k??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{A(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=j.current;if(e!==null)try{window.localStorage.setItem(O,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:N,isLoading:P,isError:F}=Ut({deviceId:i},{enabled:o,refetchInterval:5e3,retry:1}),{data:I}=Bt({deviceId:i},{enabled:o}),ee=a(()=>{let e=I?.settings?.sections??[],t=I?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some($r)&&r.add(ni),[...r].map(e=>e===`export`?{id:e,label:ei,isAddonContrib:!0}:{id:e,label:er[e]?.label??e,isAddonContrib:!0})},[I]),L=N,R=String(L?.name??n.deviceId??`Device`),te=L?.online===!0,ne=te?`online`:`offline`,z=String(L?.addonId??`rtsp`),B=L?.features??[],V=L?.type,ie=V===q.Camera,{data:H}=Sr(o?i:0),ae=V===q.Container,oe=a(()=>(H??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[H]),se=a(()=>ae?sn(oe,typeof L?.linkDeviceId==`number`?L.linkDeviceId:null,typeof L?.primaryChildEntityId==`string`?L.primaryChildEntityId:null)?.id??null:null,[ae,oe,L?.linkDeviceId,L?.primaryChildEntityId]),{data:ce}=Bt({deviceId:se??0},{enabled:se!==null}),le=a(()=>{if(se===null)return[];let e=ce?.settings?.sections??[],t=ce?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:er[e]?.label??e,isAddonContrib:!0,childDeviceId:se}))},[se,ce]),fe=typeof L?.parentDeviceId==`number`?L.parentDeviceId:null,{data:pe}=Ut({deviceId:fe??0},{enabled:fe!==null}),U=ke(),me=L?.disabled!==!0,he=a(()=>{let e=new Set,t=[];for(let n of[...xc(V,_),...ee,...le])e.has(n.id)||(e.add(n.id),t.push(n));return t},[V,_,ee,le]),ge=a(()=>bs(he,x),[he,x]),_e=e(e=>{b(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[b]),ve=e(e=>{b(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[b]),ye=(H??[]).length>0,xe=a(()=>Cc.filter(({featureGate:e})=>!e||B.includes(e)),[B]),{data:Se}=on(void 0),Ce=a(()=>L?Xt(L,Se):null,[L,Se]),W=Ce?.kind===`resolved`?Ce.integration:null,we=W===null?Ce?.kind===`unknown`?`Loading integration…`:Ce?.kind===`orphan`?`Missing integration`:`No integration`:W.name,Te=W!==null&&W.addonId===z?W.name:z,Ee=Oe({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),u(W?.id?`/integrations/${W.id}`:`/integrations`)}}),De=jt({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),je=rn({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=Ve(),Ne=st({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=B.includes(Gn.Rebootable),Fe=B.includes(Gn.BatteryOperated),Ie=re(h.trpcClient,Fe&&o?i:null),Le=Ae(h.trpcClient,o?i:null),[Re,ze]=l(!1),Be=async()=>{if(!Re){ze(!0);try{let e=R.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await Jr(`${m}/${String(i)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{ze(!1)}}},He=De.isPending||je.isPending,{data:Ue}=de({deviceId:i},{enabled:o,refetchInterval:1e4}),We=Ue?.agentNodeId??null,Ge=typeof We==`string`&&We.length>0&&!We.startsWith(`addon:`)?We:void 0,{data:Ke}=hn({deviceId:i,...Ge?{nodeId:Ge}:{}},{enabled:o,refetchInterval:3e3,retry:!1}),{data:qe}=Rt({deviceId:i},{enabled:o,refetchInterval:3e3,retry:!1}),Je=qe?.level?.dbfs??null;function Ye(){if(!o)return null;switch(ge){case`overview`:return d(vc,{device:L??{}});case`config`:return d(Ts,{deviceId:i,activeSubTab:S,onSubTabChange:ve,deviceType:V,isAdmin:_});case`detection-pipeline`:return d(Ls,{deviceId:i,activeSubTab:S,onSubTabChange:ve});case`bindings`:return d(xs,{deviceId:i});case yr:return d(ps,{deviceId:i,activeSubTab:S,onSubTabChange:ve});default:{let e=ge,t=ee.some(t=>t.id===e),n=le.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??i;if(e===`export`)return d(ri,{deviceId:i,sectionFilter:$r,activeSubTab:S,onSubTabChange:ve});let a=d(ri,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:S,onSubTabChange:ve});return n!==void 0&&r!==i?d(Wt,{deviceId:r,children:a}):a}}}return o?P?r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[d(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),d(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),d(`div`,{className:`flex-1 p-6`,children:d(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):F||!N?r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[d(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),r(`p`,{className:`text-xs`,children:[`No device with ID`,` `,r(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,i]})]}),d(`button`,{onClick:()=>u(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):r(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[d(`div`,{className:`mb-2`,children:d(Ht,{items:[{label:`Integrations`,onClick:()=>u(`/integrations`)},W===null?{label:we}:{label:we,onClick:()=>u(`/integrations/${W.id}`)},{label:R}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[W!==null&&d(Sc,{provider:W.addonId,integrationId:W.id,name:W.name}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[d(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:R}),d(Yr,{status:ne}),Fe&&d(Tn,{status:Ie,variant:`full`}),d(bt,{status:Le})]}),fe!==null&&pe&&r(`button`,{type:`button`,onClick:()=>u(`/devices/${fe}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${pe.name}`,children:[d(`span`,{children:`↑`}),d(`span`,{className:`truncate`,children:String(pe.name??`Device #${fe}`)})]}),d(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:B.length>0&&d(Bn,{capabilities:B})})]}),Ke&&d(`div`,{className:`hidden lg:flex`,children:d(Tc,{metrics:Ke,dbfs:Je})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{me?await p({title:`Disable "${R}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&je.mutate({deviceId:i}):De.mutate({deviceId:i})},disabled:He,title:me?`Disable device`:`Enable device`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${me?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[d(Ze,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:He?`Updating…`:me?`Enabled`:`Disabled`})]}),d(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),ie&&r(s,{children:[d(pi,{deviceId:i}),d(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),d(hi,{deviceId:i}),d(Sn,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:D,disabled:Re,onClick:()=>{Be()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:ue,hidden:!Pe,disabled:Me.isPending,danger:!0,onClick:async()=>{await p({title:`Reboot "${R}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Me.mutate({deviceId:i})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${Te}.`,icon:be,disabled:Ne.isPending,danger:!0,onClick:async()=>{await p({title:`Restart "${Te}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${R}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Ne.mutate({addonId:z})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:w,separatorBefore:!0,disabled:Ee.isPending,danger:!0,onClick:async()=>{await p({title:`Delete "${R}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ee.mutate({deviceId:i})}}]})]})]})]}),d(Wt,{deviceId:i,device:L??void 0,children:d(Kt,{children:d(Nt,{children:d(T,{children:d($t,{children:r(`main`,{className:U?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[r(`div`,{className:U?`flex flex-col bg-surface`:`${k===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!U&&k!==null?{width:`${String(k)}px`}:void 0,children:[d(`div`,{className:ie?`flex-shrink-0 border-b border-border-subtle bg-black`:U?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:ie?d(Yi,{deviceId:i,intercomAvailable:B.includes(Gn.TwoWayAudio)}):d(zi,{deviceId:i,deviceName:R,deviceType:V??`unknown`,provider:z,isOnline:te,features:B})}),r(`div`,{className:U?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[d(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:d(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:xe.map(({id:e,label:t,icon:n})=>r(`button`,{onClick:()=>E(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${C===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[d(n,{className:`h-3 w-3`}),t]},e))})}),r(`div`,{className:U?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[C===`logs`&&d(Xi,{deviceId:i,containerDeviceId:V===`container`?i:void 0}),C===`repl`&&d(Zi,{deviceId:i}),C===`events`&&d(Qi,{deviceId:i}),C===`state`&&d($i,{deviceId:i})]})]})]}),!U&&d(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:M,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:d(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),r(`div`,{className:U?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[d(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:d(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:he.map(e=>{let t=ge===e.id;return r(`button`,{onClick:()=>_e(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&d(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),r(`div`,{className:U?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[ge===`overview`&&ye&&d(gi,{parentDeviceId:i}),Ye()]})]})]})})})})})})]}):r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[d(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),r(`p`,{className:`text-xs`,children:[`The URL segment`,` `,d(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:n.deviceId}),` `,`is not a number.`]}),d(`button`,{onClick:()=>u(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function Tc({metrics:e,dbfs:t}){let n=kt(e.phase??`idle`);return r(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),d(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),d(`div`,{className:`h-3 w-px bg-border`}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(bn,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),d(`span`,{children:`fps`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(te,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),d(`span`,{children:`ms`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[d(A,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),d(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&r(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{wc as DeviceDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,U as i,W as a,a as o,b as s,o as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{X as f,Z as p,_t as m,at as h,ct as g,ft as _,gt as v,st as y,yt as b}from"./player-overlays-BQsHwEhF.js";import{$a as x,Al as S,Ba as C,Cn as w,Fo as T,Go as E,Hu as D,Jt as O,Kc as k,Kn as A,Lc as j,Ll as M,Lu as N,Mt as P,Mu as ee,Ou as F,Pt as I,Rc as te,Uc as L,Vt as R,Wt as z,Wu as ne,Za as re,_o as ie,_u as B,al as V,ao as H,bn as U,bo as ae,cn as W,co as oe,do as se,eo as ce,fl as le,fo as ue,gl as de,go as fe,hl as pe,io as me,jo as he,ku as ge,ln as G,mo as _e,nn as K,no as ve,nu as ye,on as q,oo as be,po as xe,pt as Se,rn as Ce,ro as we,ru as J,so as Te,ud as Ee,uo as De,vo as Oe,wn as ke,wu as Ae,xn as je,yi as Me,yn as Ne,yo as Pe,z as Fe}from"./src-AIYVh4G3.js";import{t as Ie}from"./square-check-big-C7grRhDO.js";import{un as Le,yr as Re}from"./src-BUUu3NWL.js";import{l as ze}from"./index-DRfmHS9g.js";import{t as Be}from"./AdminPage-CiKtOLQm.js";import{a as Ve,i as He,r as Ue,t as We}from"./authed-media-2_-kYrP3.js";import{a as Ge,c as Ke,d as qe,f as Je,i as Ye,n as Xe,o as Ze,p as Qe,r as $e,s as et,t as tt}from"./debounced-invalidate-DE5pKSOE.js";import{t as nt}from"./use-stationary-objects-pBTdGYcS.js";import{t as rt}from"./AdminTabs-DxmhnOA4.js";import{t as it}from"./format-size-DIxKXxtj.js";var at=b(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),ot=b(`circle-dashed`,[[`path`,{d:`M10.1 2.182a10 10 0 0 1 3.8 0`,key:`5ilxe3`}],[`path`,{d:`M13.9 21.818a10 10 0 0 1-3.8 0`,key:`11zvb9`}],[`path`,{d:`M17.609 3.721a10 10 0 0 1 2.69 2.7`,key:`1iw5b2`}],[`path`,{d:`M2.182 13.9a10 10 0 0 1 0-3.8`,key:`c0bmvh`}],[`path`,{d:`M20.279 17.609a10 10 0 0 1-2.7 2.69`,key:`1ruxm7`}],[`path`,{d:`M21.818 10.1a10 10 0 0 1 0 3.8`,key:`qkgqxc`}],[`path`,{d:`M3.721 6.391a10 10 0 0 1 2.7-2.69`,key:`1mcia2`}],[`path`,{d:`M6.391 20.279a10 10 0 0 1-2.69-2.7`,key:`1fvljs`}]]),st=b(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),ct=b(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),lt=b(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]);n();function ut(e){let t=e.subLabel??e.label;if(t!==void 0)return t;let n=e.audioLabels?.[0]?.label;return n!==void 0&&n.length>0?n:void 0}var dt=720*60*60*1e3;function ft(e){let t=[];for(let n of e)t.push(...n);return t}function pt(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function mt(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function ht(e,t){return`${String(e)}:${t}`}function gt(e,t){let n=new Map,r=new Set;for(let i of e){let e=ht(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function _t(e,t){return{since:e.fromMs??t-dt,until:e.toMs??t}}var vt=[`native`,`raster`,`standin`];function yt(e){return vt.some(t=>t===e)}var bt={standin:{label:`stand-in`,title:`Stand-in: this tile is a face or plate detail crop copied in because no frame of the subject was captured. It is not a best shot.`,tone:`warning`},raster:{label:`low-res`,title:`Raster crop: a sub-native cut of the subject, not a native capture. Honest, but lower resolution than a best shot.`,tone:`info`}};function xt(e){return e===`standin`?bt.standin:e===`raster`?bt.raster:null}var St={"no-key-frame":`No key frame existed at close, so no native tile could be cut.`,"no-best-seen-bbox":`No subject box was ever recorded, so there was nothing to cut around.`,"derive-returned-null":`The close-time crop was attempted and produced nothing.`,"derive-threw":`The close-time crop failed with an error.`,"derive-not-wired":`No close-time crop was wired on this node.`,"no-media-store":`The node was shutting down mid-close.`,"no-thumbnail":`The track closed with no tile of any kind.`,"standin-tile":`The track closed with a detail crop standing in for the subject.`,"raster-tile":`The track closed with a sub-native raster crop of the subject.`,"native-tile":`The track closed with a native tile.`};function Ct(e){if(e===void 0)return null;let t=e.trim();if(t.length===0)return null;let n=t.split(/\s+/),r=n[0]??t,i=[];for(let e of n.slice(1)){let t=e.indexOf(`=`);t===-1?i.push({key:e,value:null}):i.push({key:e.slice(0,t),value:e.slice(t+1)})}return{sentence:St[r]??r,detail:i,raw:t}}function wt(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function Tt({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let d=Ve(e.mediaId===void 0?He(`track`,e.trackId):Ue(e.mediaId)),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=wt(e.windowMs),h=()=>i(e),v=xt(c);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[d.src?u(`img`,{src:d.src,alt:`Event from ${t}`,onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}):u(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:d.failed?`Key-event media unavailable`:`No key-event media`,children:u(_,{className:`h-6 w-6 opacity-60`})}),o&&u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(ht(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":a?`Deselect`:`Select`,children:a?u(Ie,{className:`h-4 w-4 text-primary`}):u(g,{className:`h-4 w-4`})}),p!==void 0&&r(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(p),`%`]}),f>0&&u(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(f)}),v!==null&&u(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${v.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:v.title,children:v.label}),(e.markForTrain===!0||e.debug===!0||e.favourited===!0)&&r(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:u(ct,{className:`h-3 w-3`})}),e.debug===!0&&u(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:u(ne,{className:`h-3 w-3`})}),e.favourited===!0&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Favourited`,"aria-label":`Favourited`,children:u(pe,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:h,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,ut(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,ut(e)]}):null]}),u(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[u(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:Je(e.timestamp,n)}),m&&u(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:m})]})]}),l!==void 0&&u(`div`,{className:`px-2 pb-1.5`,children:l})]})}var Et=1400,Dt=`Admin-gated URL — opens only inside an authenticated session`;function Ot({label:t,value:n,title:i}){let[a,o]=l(!1),s=je();return d(()=>{if(!a)return;let e=setTimeout(()=>o(!1),Et);return()=>clearTimeout(e)},[a]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),o(!0)}catch{await s({title:`Copy the media URL`,message:`Clipboard access was refused. Select the URL below and copy it manually.`,label:`${t} URL`,defaultValue:n,readOnly:!0,cancelLabel:`Close`})}})()},[n,t,s]),title:i,"aria-label":`Copy ${t} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${a?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[u(a?D:F,{className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function kt({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[u(Ot,{label:`Local`,value:e,title:`Copy LAN URL — ${Dt}`}),t&&u(Ot,{label:`Public`,value:t,title:`Copy public URL — ${Dt}`})]})}var At={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`,confirmationCrop:`Confirmation crop (what the gate saw)`,debugCrop:`Debug crop (why this decision)`,sceneFrame:`Scene frame (clean)`,lastSceneFrame:`Last frame (clean)`};function jt(e){return e in At}function Mt(e){return jt(e)?At[e]:e}function Nt(e,t){return`${e}${t}`}n();var Pt=3e4;function Ft(t){let[n,r]=l(null),i=e(e=>{r(t=>t??e)},[]);return d(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?u(It,{onOrigin:i}):null}}function It({onOrigin:e}){let{data:t}=A({capName:`network-access`});return u(s,{children:(t??[]).map(t=>u(Lt,{addonId:t.addonId,onOrigin:e},t.addonId))})}function Lt({addonId:e,onOrigin:t}){let{data:n}=C({addonId:e},{refetchInterval:Pt,retry:!1});return d(()=>{let e=n?Le.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var Rt=typeof Pe==`function`,zt=`Track flags arrive with the next server update`;function Bt(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Vt=Rt?Pe:Bt;function Ht(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}n();function Ut({label:e,hint:t,checked:n,disabled:i,title:a,icon:o,onToggle:s}){return r(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:i,title:a,onClick:s,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[u(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),r(`span`,{className:`min-w-0 flex-1`,children:[u(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),u(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),u(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:u(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function Wt({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=Vt(),c=Ne(),[d,f]=l(null),p=d?.markForTrain??n===!0,m=d?.debug??i===!0,h=d?.favourited??a===!0,g=!Rt||s.isPending,_=Rt?void 0:zt,v=n=>{g||(async()=>{try{let r=Ht(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;f(r),o?.(r)}catch(e){let t=e instanceof Error?e.message:``;await c({title:`Could not update this track`,message:t===``?`Could not update this track. Check the server logs.`:t,variant:`danger`})}})()};return r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[u(Ut,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:p,disabled:g,..._===void 0?{}:{title:_},icon:u(ct,{className:`h-4 w-4`}),onToggle:()=>v({markForTrain:!p})}),u(Ut,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:m,disabled:g,..._===void 0?{}:{title:_},icon:u(ne,{className:`h-4 w-4`}),onToggle:()=>v({debug:!m})}),u(Ut,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:h,disabled:g,..._===void 0?{}:{title:_},icon:u(pe,{className:`h-4 w-4`}),onToggle:()=>v({favourited:!h})})]})}var Gt=100,Kt=120,qt={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Y=e=>e<0?0:e>1?1:e,Jt=e=>Math.round(e*100)/100;function Yt(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function Xt(e,t,n){if(e.length===0||t===null)return qt;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return qt;let a=Yt(e,n?.maxPoints??Kt).map(e=>({x:Jt(Y(e.x/r)*Gt),y:Jt(Y(e.y/i)*Gt)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Jt(Y(e.x/r)*Gt),y:Jt(Y(e.y/i)*Gt),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Y(t.bbox.w/r)*Y(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Jt(Y(u.bbox.x/r)*Gt),y:Jt(Y(u.bbox.y/i)*Gt),w:Jt(Y(u.bbox.w/r)*Gt),h:Jt(Y(u.bbox.h/i)*Gt)}:null}}var Zt=typeof x==`function`,Qt=`Track deletion arrives with the next server update`;function $t(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var en=Zt?x:$t;n();var tn=15e3,nn=f();function rn({url:e,label:t}){let{src:n,failed:r}=Ve(e);return n===null?u(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?u(_,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):u(J,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):u(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var an=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),on=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function sn(e){let[t,n]=l(null);return d(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function cn({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:r(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&u(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&u(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>u(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>u(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaId)}:void 0,children:u(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${String(e.mediaId)}-${String(n)}`)),e.start&&u(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&u(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function X({label:e,value:t,mono:n}){return r(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[u(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function ln({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:f}){let p=h(),m=Ne(),g=U(),v=en(),b=t!==null,x=t?.deviceId??0,S=t?.trackId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=me({deviceId:x,trackId:S},{enabled:b}),{data:E}=xe({trackId:S,deviceId:x},{enabled:b}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=oe({ownerType:`object`,eventId:D??0,deviceId:x},{enabled:b&&D!==void 0&&Number.isFinite(D)}),{data:A}=te({deviceId:x},{enabled:b}),M=(A??[]).find(e=>e.addonId!==void 0)?.addonId,{data:N}=j({deviceId:x,since:C-tn,until:C+w+tn,provider:M??``},{enabled:b&&M!==void 0}),[ee,F]=l(null),[L,R]=l(!1),{publicOrigin:z,probes:ne}=Ft(b);d(()=>{F(null)},[x,S]);let re=a(()=>{let e=E??[],t=O??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,O]),ie=ee??re,V=Ve(ie?ie.url:void 0),H=a(()=>{let e=new Set,t=[];for(let n of[...O??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[O,E]),ae=a(()=>H.find(e=>an.has(e.kind))??null,[H]),W=sn(Ve(ae?ae.url:void 0).src),se=a(()=>Xt(T?.positions??[],W,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,W]),ce=e(e=>{let t=H.find(t=>t.mediaId===e);t&&F(t)},[H]);if(t===null)return null;let le=V.src,ue=ie?.kind,de=ue!==void 0&&on.has(ue)&&W!==null&&(T?.positions.length??0)>=2,fe=N&&N.length>0?N[0]:null,pe=()=>{fe&&(R(!0),(async()=>{try{let e=await p.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:fe.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{m({title:`Clip unavailable`,message:`Could not resolve clip playback. Check the server logs.`,variant:`warning`})}finally{R(!1)}})())},he=()=>{!i||v.isPending||(async()=>{if(await g({title:`Delete track`,message:`Delete this track and every image and clip captured for it? This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`}))try{await v.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{await m({title:`Delete failed`,message:`Failed to delete this track. Check the server logs.`,variant:`danger`})}})()},ge=Math.round(t.importance*100),_e=T?.importanceReason?`${String(ge)}% · ${T.importanceReason}`:`${String(ge)}%`,K=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,ve=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,ye=ve===void 0?`—`:ve.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),q=T?T.totalDistance.toFixed(2):`—`,be=Ct(T?.previewMissReason),Se=Qe(T?T.firstSeen:C),Ce=T?Qe(T.lastSeen):`—`;return u(P,{open:!0,onOpenChange:e=>!e&&o(),children:r(I,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,ut(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,ut(t)]}):null]}),u(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),u(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:u(k,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[le?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(Xe,{src:le,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:de?u(cn,{overlay:se,onPickSnapshot:ce}):void 0})}):u(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:V.failed?r(s,{children:[u(_,{className:`h-8 w-8 opacity-60`}),u(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):u(J,{className:`h-6 w-6 animate-spin opacity-70`})}),H.length>0&&u(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:H.map(e=>{let t=Mt(e.kind),n=Nt(nn,e.url),i=z?Nt(z,e.url):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[u(`button`,{type:`button`,onClick:()=>F(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${Qe(e.timestamp)}`,children:u(rn,{url:e.url,label:t})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[u(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:t,children:t}),u(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:Qe(e.timestamp),children:qe(e.timestamp)})]}),u(kt,{localUrl:n,publicUrl:i})]},e.mediaId)})}),ne,fe&&r(G,{variant:`secondary`,onClick:pe,disabled:L,children:[L?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(B,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),u(Wt,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},...(T?.favourited??t.favourited)===void 0?{}:{favourited:T?.favourited??t.favourited},onChange:f}),be!==null&&r(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[u(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Best shot`}),u(`p`,{className:`mt-0.5 text-xs text-foreground`,children:be.sentence}),u(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:be.raw})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u(X,{label:`Camera`,value:n}),u(X,{label:`Class`,value:t.className}),u(X,{label:`Label`,value:t.label??`—`}),u(X,{label:`Sub-label`,value:t.subLabel??`—`}),u(X,{label:`Importance`,value:_e}),u(X,{label:`Zones visited`,value:K}),u(X,{label:`Audio heard`,value:ye}),u(X,{label:`Total distance`,value:q}),u(X,{label:`First seen`,value:Se}),u(X,{label:`Last seen`,value:Ce}),u(X,{label:`Track`,value:t.trackId,mono:!0})]})]}),u(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:u(`span`,{title:i?void 0:Qt,children:r(G,{variant:`secondary`,onClick:he,disabled:!i||v.isPending,children:[v.isPending?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(y,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var un={status:`debug.tape.status`,promote:`debug.tape.promote`,list:`debug.tape.list`,tracks:`debug.tape.tracks`,review:`debug.tape.review`,release:`debug.tape.release`,remove:`debug.tape.delete`},dn={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},fn=p(`/addon/pipeline-analytics/tape-export`),pn=10*6e4;function mn(e){return`${fn}?tapeId=${encodeURIComponent(e)}`}var hn=`The server answered in a shape this build does not understand.`;function gn(e){return e instanceof Error?e.message:`The action failed.`}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function _n(e,t){if(!(t in e))return;let n=e[t];return n===null?null:typeof n==`number`&&Number.isFinite(n)?n:void 0}function $(e,t){let n=e[t];return typeof n==`string`?n:null}function vn(e,t){let n=e[t];return typeof n==`boolean`?n:null}function yn(e,t){if(!Array.isArray(e))return null;let n=[];for(let r of e){let e=t(r);if(e===null)return null;n.push(e)}return n}function bn(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function xn(e){if(!Z(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=_n(e,`segmentsHeld`),a=_n(e,`bytesLastHour`),o=_n(e,`bytesHeld`);if(t===null||!bn(n)||r===null||i===void 0||a===void 0||o===void 0)return null;let s=$(e,`reason`),c=Q(e,`segmentOriginMs`),l=Q(e,`framesPerMin`),u=Q(e,`heldFromMs`),d=Q(e,`heldToMs`),f=$(e,`shelfError`);return{deviceId:t,state:n,gapsSinceArmed:r,segmentsHeld:i,bytesLastHour:a,bytesHeld:o,...s===null?{}:{reason:s},...c===null?{}:{segmentOriginMs:c},...l===null?{}:{framesPerMin:l},...u===null?{}:{heldFromMs:u},...d===null?{}:{heldToMs:d},...f===null?{}:{shelfError:f}}}function Sn(e){return Z(e)?yn(e.cameras,xn):null}function Cn(e){if(!Z(e))return null;let t=$(e,`id`),n=Q(e,`deviceId`),r=$(e,`scenario`),i=e.lighting,a=Q(e,`fromMs`),o=Q(e,`toMs`),s=e.state,c=Q(e,`frames`),l=Q(e,`gaps`),u=Q(e,`bytes`),d=vn(e,`reviewed`),f=vn(e,`released`),p=yn(e.tracks,e=>typeof e==`string`?e:null),m=Q(e,`tracksStillStored`);return t===null||n===null||r===null||i!==`day`&&i!==`ir`||a===null||o===null||s!==`complete`&&s!==`incomplete`||c===null||l===null||u===null||d===null||f===null||p===null||m===null?null:{id:t,deviceId:n,scenario:r,note:$(e,`note`),lighting:i,fromMs:a,toMs:o,state:s,frames:c,gaps:l,bytes:u,reviewed:d,released:f,tracks:p,tracksStillStored:m}}function wn(e){return Z(e)?yn(e.tapes,Cn):null}function Tn(e){if(!Z(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=vn(e,`stillStored`);return t===null||n===null||r===null||i===null||a===null||o===null?null:{trackId:t,firstT:n,lastT:r,boundFrames:i,cls:a,stillStored:o}}function En(e){if(!Z(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=vn(e,`reviewed`),o=yn(e.lanes,Tn);return t===null||n===null||r===null||i===null||a===null||o===null?null:{tapeId:t,deviceId:n,fromMs:r,toMs:i,reviewed:a,lanes:o}}function Dn(e){if(!Z(e))return null;if(e.ok===!1){let t=$(e,`reason`),n=$(e,`detail`);return t===null||n===null?null:{ok:!1,reason:t,detail:n}}if(e.ok!==!0)return null;let t=$(e,`tapeId`),n=e.state,r=Q(e,`frames`),i=Q(e,`gaps`),a=Q(e,`pinnedTracks`),o=Q(e,`bytes`);return t===null||n!==`complete`&&n!==`incomplete`||r===null||i===null||a===null||o===null?null:{ok:!0,tapeId:t,state:n,frames:r,gaps:i,pinnedTracks:a,bytes:o}}function On(e){if(!Z(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=vn(e,`pinsSettled`);return n===null||r===null?null:{status:t,unpinned:n,pinsSettled:r}}if(t===`already-released`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function kn(e){if(!Z(e))return null;let t=e.status;if(t===`deleted`||t===`pins-owed`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function An(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return`This tape was already released.`;case`not-found`:return`That tape no longer exists — it may have been released or deleted elsewhere.`;case`pins-owed`:return`Refused: this tape still names pins not yet taken back. Try again shortly — the ledger settles them automatically.`;case`unavailable`:return`Unavailable on this node: ${e.reason}`}}function jn(e){if(!Z(e))return null;let t=$(e,`leftTrackId`),n=$(e,`rightTrackId`),r=e.relation,i=e.presence;return t===null||n===null||r!==`same-subject`&&r!==`different-subjects`?null:{leftTrackId:t,rightTrackId:n,relation:r,presence:i===`continuous`?`continuous`:null}}function Mn(e){if(!Z(e))return null;let t=$(e,`sourceTrackId`),n=e.purity;return t===null||n!==`mixed`&&n!==`not-a-subject`?null:{sourceTrackId:t,purity:n,switchAtMs:Q(e,`switchAtMs`)}}function Nn(e){if(!Z(e))return null;let t=yn(e.relations,jn),n=yn(e.purities,Mn),r=vn(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function Pn(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return`Showing the first ${String(t)} marks — more exist for this window.`}function Fn(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function In(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function Ln(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function Rn(e,t){let n=[];for(let r of t.relations){let t=r.leftTrackId===e?r.rightTrackId:r.rightTrackId===e?r.leftTrackId:null;if(t===null)continue;let i=r.relation===`same-subject`?`same as`:`different from`;n.push(`${i} ${t}${r.presence===`continuous`?` (continuous)`:``}`)}for(let r of t.purities)r.sourceTrackId===e&&n.push(r.purity===`not-a-subject`?`not a subject`:r.switchAtMs===null?`mixed`:`mixed at switch`);return n}function zn(e){switch(e.state){case`off`:return`Off`;case`recording`:return`Recording`;case`refused`:return`Refused: ${e.reason??`unknown reason`}`;case`failing`:return`Failing: ${e.reason??`unknown reason`}`;case`unknown`:return`Unknown: ${e.reason??`unknown reason`}`}}var Bn={"window-too-long":`A promoted window is at most 30 minutes.`,"window-in-future":`The window ends in the future.`,"window-not-recorded":`No segment covers that window — the camera was not recording then, or it is older than 24 h.`,"invalid-scenario":`The scenario must be a slug: lowercase letters, digits and dashes, 3–64 characters.`,"promotion-budget":`A promotion budget is full (60 tapes, 1 GiB, 3 000 pinned tracks). Release or delete a tape already committed as a case first.`,"empty-window":`No frame was recorded in that window.`,"shelf-unreadable":`The camera's recorded segments could not be listed, so the window cannot be proven whole.`,"not-post-processing-node":`This node does not post-process frames, so it records no tracking tapes.`,"artifacts-elsewhere":`The artifacts storage location is on another node; tapes are recorded only where it lives.`,"tapes-not-started":`The tape recorder has not started on this node (or failed to).`};function Vn(e,t){let n=Bn[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Hn(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Un(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Wn(e){return e===null?`unknown`:Un(e)}function Gn(e){return e===null?`unknown`:String(e)}function Kn(e,t){let n=t.trim();return e===404?`This tape no longer exists on this node (unknown tape).`:e===503?n.length>0?n:`Tapes are unavailable on this node.`:e===500?n.length>0?n:`The export could not be read (the tape may have just been released or deleted).`:`Download failed (${String(e)}).`}n();function qn({cameras:e,call:t,onPromoted:n}){let[i,a]=l(``),[o,s]=l(``),[c,d]=l(``),[f,p]=l(``),[m,h]=l(``),[g,_]=l(`auto`),[v,y]=l(!1),[b,x]=l(null),S=async()=>{let r=Number.parseInt(i===``?e[0]?.value??``:i,10),a=Hn(o),s=Hn(c);if(!Number.isFinite(r)||a===null||s===null){x(`Pick a camera and both ends of the window.`);return}y(!0),x(null);try{let e=Dn(await t(un.promote,{deviceId:r,fromMs:a,toMs:s,scenario:f,...m.trim().length>0?{note:m.trim()}:{},...g===`day`||g===`ir`?{lighting:g}:{}}));e===null?x(hn):e.ok?(x(`Promoted ${e.tapeId}: ${String(e.frames)} frames, ${Un(e.bytes)}, ${String(e.pinnedTracks)} tracks pinned`+(e.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),n()):x(Vn(e.reason,e.detail))}catch(e){x(gn(e))}finally{y(!1)}};return r(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[u(`div`,{className:`w-40`,children:u(W,{value:i,options:[...e],onChange:e=>a(e.target.value),"aria-label":`Camera`})}),u(R,{type:`datetime-local`,"aria-label":`From`,value:o,onChange:e=>s(e.target.value),className:`w-48`}),u(R,{type:`datetime-local`,"aria-label":`To`,value:c,onChange:e=>d(e.target.value),className:`w-48`}),u(R,{"aria-label":`Scenario`,placeholder:`615-door-groups`,value:f,onChange:e=>p(e.target.value),className:`w-44`}),u(R,{"aria-label":`Note`,placeholder:`optional note`,value:m,onChange:e=>h(e.target.value),className:`w-52`}),u(`div`,{className:`w-28`,children:u(W,{value:g,"aria-label":`Lighting`,options:[{value:`auto`,label:`Lighting: auto`},{value:`day`,label:`day`},{value:`ir`,label:`ir`}],onChange:e=>_(e.target.value)})}),r(G,{onClick:()=>void S(),disabled:v||e.length===0,children:[v?u(J,{className:`h-3.5 w-3.5 animate-spin`}):null,` Promote window`]}),u(`p`,{className:`w-full text-xs text-foreground-subtle`,children:`A promoted tape may be shared as a test case — keep the scenario slug and note free of names or other personal data.`}),b!==null&&u(`p`,{className:`w-full text-xs text-foreground`,children:b})]})}var Jn=`pipeline-analytics`,Yn=`debug.listTracks`,Xn=`debug.analyze`,Zn=p(`/addon/pipeline-analytics/debug-export`);function Qn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $n(e,t){let n=e[t];return typeof n==`string`?n:null}function er(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function tr(e,t){let n=e[t];return typeof n==`boolean`?n:null}function nr(e){return e===`error`||e===`warn`||e===`info`}function rr(e){if(!Qn(e))return null;let t=$n(e,`code`),n=$n(e,`detail`),r=e.severity;return t===null||n===null||!nr(r)?null:{code:t,severity:r,detail:n}}function ir(e){if(!Qn(e))return null;let t=$n(e,`trackId`),n=er(e,`deviceId`),r=$n(e,`className`),i=er(e,`firstSeen`),a=er(e,`lastSeen`),o=er(e,`durationMs`),s=tr(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=$n(e,`label`),l=$n(e,`subLabel`),u=$n(e,`previewMissReason`),d=tr(e,`markForTrain`),f=tr(e,`favourited`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},...l===null?{}:{subLabel:l},firstSeen:i,lastSeen:a,durationMs:o,active:s,timestamp:i,windowMs:o,importance:er(e,`importance`)??0,bestEventId:$n(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function ar(e){let t=ir(e);if(t===null||!Qn(e))return null;let n=er(e,`mediaCount`),r=er(e,`eventCount`),i=er(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=rr(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...yt(l)?{thumbnailProvenance:l}:{}}}function or(e){if(!Qn(e))return null;let t=tr(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=ir(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function sr(e){if(!Qn(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=ar(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var cr={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`,UNSCORED_LABEL:`unscored label`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function lr(e){return cr[e]??e}var ur={error:0,warn:1,info:2};function dr(e){return e.toSorted((e,t)=>ur[e.severity]-ur[t.severity]||e.code.localeCompare(t.code))}function fr(e){return e.length===0?Zn:`${Zn}?deviceIds=${e.join(`,`)}`}function pr(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}function mr(e,t){return`${String(e)}:${t}`}function hr(e,t){let n=[],r=new Set;for(let i of e){let e=mr(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}n();function gr({tapeId:e,call:t,onClose:n,onChanged:i}){let a=o({queryKey:[`events-debug`,`tapes`,`tracks`,e],queryFn:async()=>En(await t(un.tracks,{tapeId:e}))}),s=a.data??null,c=o({queryKey:[`events-debug`,`tapes`,`marks`,e],enabled:s!==null,queryFn:async()=>s===null?null:Nn(await t(dn.list,{deviceId:s.deviceId,since:s.fromMs-pn,until:s.toMs+pn,limit:5e3}))}),[d,f]=l([]),[p,m]=l(``),[h,g]=l(null),_=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),v=async e=>{g(null);try{for(let[n,r]of e)await t(n,r);f([]),await c.refetch(),i()}catch(e){g(gn(e))}};if(s===null)return a.isLoading?u(`p`,{className:`text-xs`,children:`Loading the tape…`}):u(q,{message:hn});let y=s.deviceId,b=(e,t)=>v(e.map(e=>[dn.setRelation,{deviceId:y,...e,relation:t}])),x=e=>{let t=Number.parseFloat(p),n=e===`mixed`&&Number.isFinite(t)?s.fromMs+t*1e3:void 0;return v(d.map(t=>[dn.setPurity,{deviceId:y,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},S=c.data==null?null:Pn(c.data);return r(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[r(`span`,{className:`text-xs font-medium`,children:[s.tapeId,` — `,String(s.lanes.length),` tracks`]}),u(G,{disabled:d.length<2,onClick:()=>void b(In(d),`same-subject`),children:`Same subject`}),u(G,{variant:`secondary`,disabled:d.length<2,onClick:()=>void b(Ln(d),`different-subjects`),children:`Different subjects`}),u(R,{"aria-label":`Changed at (s from tape start)`,placeholder:`changed at s`,value:p,onChange:e=>m(e.target.value),className:`w-28`}),u(G,{variant:`secondary`,disabled:d.length!==1,onClick:()=>void x(`mixed`),children:`Mixed`}),u(G,{variant:`secondary`,disabled:d.length===0,onClick:()=>void x(`not-a-subject`),children:`Not a subject`}),u(G,{variant:s.reviewed?`secondary`:`primary`,onClick:()=>void v([[un.review,{tapeId:s.tapeId,reviewed:!s.reviewed}]]).then(()=>a.refetch()),children:s.reviewed?`Mark not reviewed`:`Mark reviewed`}),u(G,{variant:`ghost`,onClick:n,children:`Close`})]}),h!==null&&u(q,{message:h}),S!==null&&u(q,{variant:`warning`,message:S}),u(`ul`,{className:`space-y-1`,children:s.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>u(_r,{lane:e,marks:c.data===null||c.data===void 0?[]:Rn(e.trackId,c.data),selected:d.includes(e.trackId),onToggle:()=>_(e.trackId)},e.trackId))})]})}function _r({lane:e,marks:t,selected:n,onToggle:i}){let{src:a}=Ve(e.stillStored?He(`track`,e.trackId):void 0);return r(`li`,{className:`flex items-center gap-2 text-xs`,children:[u(`input`,{type:`checkbox`,"aria-label":`select ${e.trackId}`,checked:n,onChange:i}),a===null?u(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):u(`img`,{src:a,alt:e.trackId,className:`h-10 w-10 rounded object-cover`}),u(`span`,{className:`font-mono`,children:e.trackId}),u(`span`,{children:e.cls}),r(`span`,{className:`text-foreground-subtle`,children:[pr(e.firstT),` → `,pr(e.lastT),` · `,String(e.boundFrames),` `,`frames`]}),!e.stillStored&&u(`span`,{className:`text-foreground-subtle`,children:`not stored — marked through the tape`}),t.map(e=>u(K,{variant:`info`,children:e},e))]})}n();var vr=`camstack_admin_token`;function yr(){let e=h();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:Jn,action:t,input:n})}async function br(e,t){let n=localStorage.getItem(vr),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(mn(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(Kn(i.status,e))}let a=await i.blob(),o=i.headers.get(`content-disposition`),s=(o===null?null:/filename="?([^";]+)"?/i.exec(o))?.[1]?.trim()??t,c=URL.createObjectURL(a),l=document.createElement(`a`);l.href=c,l.download=s,l.click(),setTimeout(()=>URL.revokeObjectURL(c),6e4)}function xr(){let[e,t]=l(!1);return u(O,{expanded:e,onExpandedChange:t,header:u(`span`,{className:`text-sm font-medium text-foreground`,children:`Tracking tapes`}),children:u(Sr,{})})}function Sr(){let e=yr(),t=Me({isCamera:!0,projection:`slim`}),n=a(()=>{let e=new Map;for(let n of t.data??[])e.set(n.id,n.name);return t=>e.get(t)??`Camera ${String(t)}`},[t.data]),i=o({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>Sn(await e(un.status,{}))}),s=o({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>wn(await e(un.list,{}))}),[c,d]=l(null),[f,p]=l(null),m=async e=>{p(null);try{await br(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){p(gn(e))}},h=async t=>{let n=On(await e(un.release,{tapeId:t.id}));if(n===null)throw Error(hn);let r=An(n);if(r!==null)throw Error(r);await s.refetch()},g=async t=>{let n=kn(await e(un.remove,{tapeId:t.id}));if(n===null)throw Error(hn);let r=An(n);if(r!==null)throw Error(r);await s.refetch()};return r(`div`,{className:`space-y-3`,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A camera records while its `,u(`strong`,{children:`Record the track history`}),` switch (camera settings → Tracking) is on; segments are kept 24 h. Promote a window worth keeping, label it in the review, mark it reviewed, download it and turn it into a test case with`,` `,u(`code`,{children:`npm run tracking-bench -- case`}),`.`]}),f!==null&&u(q,{message:f}),i.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading camera status…`}),i.data===null&&u(q,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:`Camera`}),u(`th`,{children:`State`}),u(`th`,{children:`Frames/min`}),u(`th`,{children:`Last hour`}),u(`th`,{children:`Held`}),u(`th`,{children:`Gaps`})]})}),u(`tbody`,{children:(i.data??[]).map(e=>r(`tr`,{children:[u(`td`,{children:n(e.deviceId)}),u(`td`,{children:u(K,{variant:e.state===`recording`?`success`:e.state===`off`?`default`:e.state===`unknown`?`warning`:`danger`,children:zn(e)})}),u(`td`,{children:e.framesPerMin===void 0?`—`:String(Math.round(e.framesPerMin))}),u(`td`,{title:e.shelfError,children:Wn(e.bytesLastHour)}),r(`td`,{title:e.shelfError,children:[Gn(e.segmentsHeld),` seg · `,Wn(e.bytesHeld)]}),u(`td`,{children:String(e.gapsSinceArmed)})]},e.deviceId))})]}),u(qn,{cameras:Fn(i.data??[]).map(e=>({value:String(e.deviceId),label:e.segmentsUnknown?`${n(e.deviceId)} (segments unknown)`:n(e.deviceId)})),call:e,onPromoted:()=>void s.refetch()}),s.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading promoted tapes…`}),s.data===null&&u(q,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:`Scenario`}),u(`th`,{children:`Camera`}),u(`th`,{children:`Window`}),u(`th`,{children:`State`}),u(`th`,{children:`Tracks`}),u(`th`,{})]})}),u(`tbody`,{children:(s.data??[]).map(e=>r(`tr`,{children:[u(`td`,{children:e.scenario}),u(`td`,{children:n(e.deviceId)}),r(`td`,{children:[new Date(e.fromMs).toLocaleString(),` · `,pr(e.toMs-e.fromMs),` `,`· `,e.lighting]}),r(`td`,{children:[u(K,{variant:e.state===`complete`?`success`:`warning`,children:e.state}),` `,e.reviewed&&u(K,{variant:`info`,children:`reviewed`}),` `,e.released&&u(K,{children:`released`})]}),r(`td`,{children:[String(e.tracksStillStored),`/`,String(e.tracks.length),` stored`]}),r(`td`,{className:`space-x-1 text-right`,children:[u(G,{variant:`secondary`,"aria-label":`Review ${e.scenario}`,onClick:()=>d(e.id),children:`Review`}),u(G,{variant:`ghost`,"aria-label":`Download ${e.scenario}`,onClick:()=>void m(e),children:u(Ae,{className:`h-3.5 w-3.5`})}),u(Se,{label:`Release`,icon:ye,title:`Release ${e.scenario}?`,description:`Releasing returns this tape's pinned tracks to ordinary retention — they can be pruned from then on. The promoted bundle itself is kept until deleted.`,confirmLabel:`Release`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:e.released,action:()=>h(e)}),u(Se,{label:`Delete`,icon:y,title:`Delete ${e.scenario}?`,description:`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`,confirmLabel:`Delete`,triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>g(e)})]})]},e.id))})]}),c!==null&&u(gr,{tapeId:c,call:e,onClose:()=>d(null),onChanged:()=>void s.refetch()})]})}n();var Cr=`all`,wr=`The server answered in a shape this build does not understand.`,Tr={error:`danger`,warn:`warning`,info:`info`};function Er({findings:e}){return e.length===0?u(K,{variant:`success`,children:`no anomaly found`}):u(`div`,{className:`flex flex-wrap gap-1`,children:dr(e).map(e=>u(K,{variant:Tr[e.severity],title:e.detail,children:lr(e.code)},e.code))})}function Dr({track:e,report:t,analyzing:n}){let i=Ct(t?.previewMissReason??e.previewMissReason);return r(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[t===void 0?u(`span`,{className:`text-[10px] text-foreground-subtle`,children:n?`analysing…`:`not analysed`}):r(s,{children:[u(Er,{findings:t.findings}),r(`p`,{className:`text-[10px] text-foreground-subtle`,title:t.mediaKinds.length>0?t.mediaKinds.join(`, `):`no media of any kind`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),i!==null&&u(`p`,{className:`text-[10px] text-foreground-subtle`,title:i.raw,children:i.sentence})]})}function Or(){let e=h(),[t,n]=l(Cr),[i,s]=l(!1),[c,d]=l(null),[f,p]=l(new Set),[m,g]=l(null),[_,v]=l(null),[y,b]=l(null),[x,S]=l([]),C=Vt(),w=Me({isCamera:!0,projection:`slim`}),T=a(()=>[{value:Cr,label:`All cameras`},...(w.data??[]).map(e=>({value:String(e.id),label:e.name}))],[w.data]),E=a(()=>{let e=new Map;for(let t of w.data??[])e.set(t.id,t.name);return e},[w.data]),O=e=>E.get(e)??`Camera ${String(e)}`,A=a(()=>t===Cr?[]:[Number.parseInt(t,10)],[t]),j=o({queryKey:[`events-debug`,`list`,A],queryFn:async()=>or(await e.trpcClient.addons.custom.mutate({addonId:Jn,action:Yn,input:A.length===0?{}:{deviceIds:A}}))}),N=a(()=>(j.data?.tracks??[]).map(e=>e.trackId),[j.data]),P=o({queryKey:[`events-debug`,`analyze`,N],enabled:N.length>0,queryFn:async()=>sr(await e.trpcClient.addons.custom.mutate({addonId:Jn,action:Xn,input:{trackIds:N}}))}),ee=a(()=>{let e=new Map;for(let t of P.data?.reports??[])e.set(t.trackId,t);return e},[P.data]),F=j.data?.tracks??[],I=j.data===null||P.data===null,te=()=>{j.refetch(),P.refetch()},L=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},R=()=>{p(new Set(F.map(e=>mr(e.deviceId,e.trackId))))},z=()=>p(new Set),re=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await C.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},ie=e=>{if(!Rt||_!==null)return;let t=hr(F,f);t.length!==0&&(v(e),b(null),(async()=>{let n=await re(e,t);v(null);let r=new Set(n.refused);p(new Set(t.filter(e=>r.has(e.trackId)).map(e=>mr(e.deviceId,e.trackId)))),e===`analyzed`&&S(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&b(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),j.refetch()})())},B=()=>{let e=x;e.length===0||_!==null||(v(`analyzed`),b(null),(async()=>{for(let t of e)try{await C.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{b(`Some tracks could not be re-marked. Refresh and try again.`)}v(null),S([]),j.refetch()})())},H=async()=>{s(!0),d(null);try{await We(fr(A),`camstack-debug.zip`)}catch(e){d(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},U=_!==null;return u(Be,{children:r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(`div`,{className:`w-44`,children:u(W,{value:t,options:T,onChange:e=>n(e.target.value)})}),r(G,{variant:`secondary`,onClick:te,disabled:j.isFetching,children:[j.isFetching?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(M,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(G,{onClick:()=>void H(),disabled:i||F.length===0,children:[i?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(Ae,{className:`h-3.5 w-3.5`}),`Export all (`,String(F.length),`)`]}),F.length>0&&f.size<F.length&&u(G,{variant:`ghost`,onClick:R,children:`Select all`})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,u(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media. Use `,u(`strong`,{children:`Keep`}),` `,`to hold a selection against pruning while you investigate, and `,u(`strong`,{children:`Analyzed`}),` `,`to un-mark the ones you are finished with.`]}),u(xr,{}),j.isError&&u(q,{message:`Could not load the marked tracks.`}),I&&!j.isError&&u(q,{message:wr}),c!==null&&u(q,{message:c}),y!==null&&u(q,{message:y}),j.data?.truncated===!0&&u(q,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(P.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(P.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),f.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[String(f.size),` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:Rt?void 0:`Track flags arrive with the next server update`,children:r(G,{variant:`secondary`,onClick:()=>ie(`keep`),disabled:!Rt||U,children:[_===`keep`?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(pe,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),u(`span`,{title:Rt?void 0:`Track flags arrive with the next server update`,children:r(G,{onClick:()=>ie(`analyzed`),disabled:!Rt||U,children:[_===`analyzed`?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(D,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),u(G,{variant:`ghost`,onClick:z,disabled:U,children:u(k,{className:`h-3.5 w-3.5`})})]})]}),x.length>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[r(`span`,{className:`text-xs text-foreground`,children:[String(x.length),` track(s) marked analyzed and removed from this list.`]}),r(G,{variant:`ghost`,onClick:B,disabled:U,children:[u(V,{className:`h-3.5 w-3.5`}),` Undo`]}),u(G,{variant:`ghost`,onClick:()=>S([]),disabled:U,children:u(k,{className:`h-3.5 w-3.5`})})]}),j.isLoading?u(Ce,{children:u(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`})}):F.length===0?u(Ce,{children:r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[u(ne,{className:`h-5 w-5 text-foreground-subtle`}),u(`p`,{className:`text-xs text-foreground-subtle`,children:`No track is marked for debug. Mark one from a track's actions to see it here.`})]})}):u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:F.map(e=>{let t=ee.get(e.trackId);return u(Tt,{row:e,cameraName:O(e.deviceId),nowMs:e.lastSeen,selected:f.has(mr(e.deviceId,e.trackId)),onToggleSelect:L,onOpenDetail:g,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:u(Dr,{track:e,report:t,analyzing:P.isFetching})},mr(e.deviceId,e.trackId))})}),m&&u(ln,{row:m,cameraName:O(m.deviceId),deleteAvailable:Zt,onClose:()=>g(null),onDeleted:()=>{g(null),j.refetch()},onFlagsChanged:e=>{e.debug||(g(null),j.refetch())}})]})})}var kr=200,Ar=3e4,jr=[];function Mr(e){let t=h(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=o({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:Ar,refetchInterval:Ar,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:kr,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>e.events.map(t=>({...t,deviceId:e.deviceId})))});return{rows:pt(ft(i??jr),`importance`),isLoading:n&&a}}n();var Nr=[`events-feed`],Pr=2e3;function Fr(n){let r=c(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[s,u]=l(!1),f=e(()=>{a.current.invalidateQueries({queryKey:Nr})},[]),p=t(void 0);p.current||=tt({delayMs:Pr,invalidate:()=>{o.current?u(!0):f()}}),d(()=>()=>p.current?.cancel(),[]),d(()=>{i||!s||(u(!1),f())},[i,s,f]);let m=e(()=>{u(!1),f()},[f]);return L(Re.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),L(Re.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function Ir({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=ze(),[s,c]=l(!1),[d,f]=l(``),[p,h]=l(new Set),g=d.trim().toLowerCase(),_=e=>g.length===0||w(e,o).toLowerCase().includes(g),y=a(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>_(t)||_(e.macro))})).filter(e=>_(e.macro)||e.subs.length>0),[e,g]),b=e=>h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),x=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},C=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},T=()=>n(new Set),E=t.size;return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${E>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(le,{className:`h-3.5 w-3.5`}),E>0?`Kinds (${String(E)})`:`Kinds`,u(m,{className:`h-3 w-3`})]}),s&&r(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[r(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[u(S,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),E>0&&u(`button`,{type:`button`,onClick:T,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),y.length===0&&u(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:i?`Loading kinds…`:g.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),y.map(e=>{let n=ke(e.macro.iconId),i=p.has(e.macro.kind)||g.length>0,a=t.has(e.macro.kind);return r(`div`,{className:`mb-0.5`,children:[r(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?u(`button`,{type:`button`,onClick:()=>b(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:u(i?m:v,{className:`h-3 w-3`})}):u(`span`,{className:`w-3`}),r(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[u(`input`,{type:`checkbox`,checked:a,onChange:()=>x(e),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),u(`span`,{className:`font-medium`,children:w(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=ke(e.iconId);return r(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[u(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>C(e.kind),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),u(`span`,{children:w(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function Lr(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function Rr(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var zr=new Set([`detection`,`package`]);function Br(e,t){return[...Lr(e,t).values()].filter(e=>e.parentKind===null&&zr.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Vr(e,t){let n=Lr(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,Rr(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}n();function Hr(){let[n,r]=l(!1),i=t(null),[a,o]=l(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return d(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){r(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:s,scrolledPast:n}}n();var Ur=[`events-feed`],Wr=60,Gr=[{value:`importance`,label:`Importance`,icon:at},{value:`time`,label:`Recent`,icon:ee}];function Kr(){let e=c(),t=Ne(),n=U(),[i,o]=l(et),[f,p]=l(new Set),[m,h]=l(new Set),[g,_]=l(0),[v,b]=l(`time`),[x,S]=l(new Set),[C,w]=l(null),[T,E]=l(()=>Date.now());d(()=>{let e=setInterval(()=>E(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:D,until:O}=a(()=>_t({fromMs:i.fromMs,toMs:i.toMs},T),[i.fromMs,i.toMs,T]),A=Hr(),{pending:j,refreshNow:M}=Fr({paused:C!==null||x.size>0||A.scrolledPast}),{data:N=[]}=Me({isCamera:!0,projection:`slim`}),P=a(()=>N.map(e=>e.id),[N]),{data:ee,isLoading:F}=Te({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),I=a(()=>Vr(ee??[],f),[ee,f]),te=en(),L=te.isPending,{rows:R,isLoading:z}=Mr({deviceIds:P,since:D,until:O,minImportance:g>0?g:void 0,classFilter:m.size===1?[...m][0]:void 0}),ne=a(()=>{let e=new Map;for(let t of N??[])e.set(t.id,t.name);return e},[N]),re=e=>ne.get(e)??`Camera #${String(e)}`,ie=a(()=>Ke(R).map(e=>({id:e,name:re(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,ne]),B=a(()=>pt(mt(R,{cameras:f,classes:m,minImportance:g}),v),[R,f,m,g,v]),V=Ze(B,Wr,a(()=>JSON.stringify([[...f].sort((e,t)=>e-t),[...m].sort(),g,v,D,O]),[f,m,g,v,D,O])),H=()=>{e.invalidateQueries({queryKey:Ur})},ae=()=>S(new Set);function W(e){S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function oe(){if(x.size===0||!Zt)return;let e=gt(R,x),t=[...e.values()].reduce((e,t)=>e+t.length,0);t!==0&&(async()=>{await n({title:`Delete ${String(t)} track${t===1?``:`s`}`,message:`Delete ${String(t)} track${t===1?``:`s`} and every image and clip captured for ${t===1?`it`:`them`}? This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&se(e)})()}function se(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>te.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{H();let r=[],i=new Set;e.forEach((e,t)=>{let a=n[t];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)i.add(ht(o,e));else r.push(o)}),S(e=>{let t=new Set(e);for(let e of i)t.delete(e);return t}),r.length>0&&t({title:`Some tracks were not deleted`,message:`Failed to delete tracks on: ${r.map(e=>re(e)).join(`, `)}. They remain selected — retry, or check the server logs.`,variant:`danger`})})}let ce=B.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u($e,{onChange:o}),u(Ye,{cameras:ie,selected:f,onChange:p}),u(Ir,{groups:I,selected:m,onChange:h,loading:F}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Min score`}),u(`input`,{type:`range`,min:0,max:1,step:.05,value:g,onChange:e=>_(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),u(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(g*100)})]}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Gr.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>b(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${v===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!z&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:ce?`${String(B.length)} of ${String(R.length)} events`:`${String(B.length)} event${B.length===1?``:`s`}`})]}),x.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[x.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:Zt?void 0:`Track deletion arrives with the next server update`,children:r(G,{variant:`secondary`,onClick:oe,disabled:!Zt||L,children:[L?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(y,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),u(G,{variant:`ghost`,onClick:ae,disabled:L,children:u(k,{className:`h-3.5 w-3.5`})})]})]}),z&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(J,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!z&&B.length===0&&u(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),j&&u(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:u(`button`,{type:`button`,onClick:M,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!z&&B.length>0&&r(s,{children:[u(`div`,{ref:A.ref,"aria-hidden":!0,className:`h-0`}),u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:V.pageItems.map(e=>u(Tt,{row:e,cameraName:re(e.deviceId),nowMs:T,selected:x.has(ht(e.deviceId,e.trackId)),onToggleSelect:W,onOpenDetail:w},ht(e.deviceId,e.trackId)))}),u(Ge,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`events`})]}),C&&u(ln,{row:C,cameraName:re(C.deviceId),deleteAvailable:Zt,onClose:()=>w(null),onDeleted:()=>{H(),w(null)},onFlagsChanged:e=>{w(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var qr=50,Jr=350,Yr=[{value:`loose`,label:`Loose`,title:`The search model's own floor`},{value:`balanced`,label:`Balanced`,title:`1.25× the search model's floor`},{value:`strict`,label:`Strict`,title:`1.5× the search model's floor`}];function Xr(e){let t=String(e.id);return{id:t,trackId:e.trackId??t,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:t,mediaId:e.keyFrameMediaId??e.mediaId,windowMs:void 0}}function Zr({onActiveChange:e}){let[t,n]=l(``),[i,o]=l(`loose`),[s,c]=l(null),[f,p]=l(null),[m,h]=l(null),g=Fe(t,Jr).trim(),_=g.length>0;d(()=>{e(_)},[_,e]);let[v,y]=l(()=>Date.now());d(()=>{let e=setInterval(()=>y(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:b=[]}=Me({isCamera:!0,projection:`slim`}),x=a(()=>{let e=new Map;for(let t of b)e.set(t.id,t.name);return e},[b]),C=e=>x.get(e)??`Camera #${String(e)}`,T=a(()=>b.map(e=>e.id),[b]),{data:E}=Te({deviceIds:T},{enabled:T.length>0,staleTime:5*6e4}),D=a(()=>Br(E??[],new Set(f===null?[]:[f])),[E,f]);d(()=>{s!==null&&(D.some(e=>e.kind===s)||c(null))},[D,s]);let{data:O,isFetching:A,isError:j,error:M}=ie({text:g,strictness:i,limit:qr,classFilter:s??void 0,deviceId:f??void 0},{enabled:_}),N=a(()=>[...O??[]].sort((e,t)=>t.score-e.score).map(e=>({...Xr(e),score:e.score})),[O]);function P(e){c(t=>t===e?null:e)}return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`div`,{className:`relative min-w-[16rem] flex-1`,children:[u(S,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),u(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&u(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:u(k,{className:`h-3.5 w-3.5`})})]}),A&&_&&u(J,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[u(`div`,{className:`flex items-center gap-1`,children:D.map(e=>u(`button`,{type:`button`,onClick:()=>P(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${s===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:w(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Camera`}),r(`select`,{value:f===null?``:String(f),onChange:e=>p(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[u(`option`,{value:``,children:`All`}),b.map(e=>u(`option`,{value:String(e.id),children:e.name},e.id))]})]}),r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Match`}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Yr.map(e=>u(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:e.title,children:e.label},e.value))})]}),_&&!A&&!j&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[N.length,` match`,N.length===1?``:`es`]})]})]}),_&&r(`div`,{className:`space-y-3`,children:[j&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,M instanceof Error?M.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!j&&A&&N.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(J,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!j&&!A&&N.length===0&&r(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,g,`”. Try a looser match threshold or a different phrasing.`]}),!j&&N.length>0&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:N.map(e=>u(Tt,{row:e,cameraName:C(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&u(ln,{row:m,cameraName:C(m.deviceId),deleteAvailable:Zt,onClose:()=>h(null),onDeleted:()=>h(null)})]})}n();function Qr(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function $r({row:e,cameraName:t,nowMs:n}){let i=Ve(e.keyFrameMediaId===void 0?void 0:Ue(e.keyFrameMediaId));return r(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[r(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?u(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):u(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:u(lt,{className:`h-6 w-6`})}),u(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),r(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[u(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Qr(n,e.becameStationaryAt)]})]})]})}function ei(){let[e,t]=l(!1),n=Date.now(),{data:i=[]}=Me({isCamera:!0,projection:`slim`}),o=a(()=>i.map(e=>e.id),[i]),s=a(()=>{let e=new Map;for(let t of i)e.set(t.id,t.name);return e},[i]),{rows:c,unreadableCount:d}=nt(o);return c.length===0&&d===0?null:r(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[r(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[u(e?m:v,{className:`h-4 w-4 text-foreground-subtle`}),u(lt,{className:`h-4 w-4 text-foreground-subtle`}),u(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),u(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:c.length}),u(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`}),d>0?r(`span`,{className:`ml-2 text-[11px] text-warning`,children:[d,` camera`,d===1?``:`s`,` could not be read`]}):null]}),e&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:c.map(e=>u($r,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function ti(){let[e,t]=l(!1);return u(Be,{children:r(`section`,{className:`space-y-3`,children:[u(Zr,{onActiveChange:t}),!e&&u(ei,{}),!e&&u(Kr,{})]})})}var ni=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],ri=new Set(ni);function ii(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:ri.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function ai({annotations:e,selectedIndex:t,onSelect:n,onChange:i,onDelete:a}){return e.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle p-3`,children:[`No subject on this frame yet. Drag on the image to draw one, or ask the pipeline for a proposal. Annotate `,u(`strong`,{children:`every`}),` subject — a frame with one box and three unlabelled people teaches the model that two thirds of the people in it are background.`]}):u(`ul`,{className:`divide-y divide-border`,children:e.map((e,o)=>{let s=o===t,c=ii(e.label),l=ii(e.subLabel);return r(`li`,{className:`p-2.5 space-y-1.5 ${s?`bg-surface-hover`:``}`,onFocus:()=>{n(o)},children:[r(`div`,{className:`flex items-center gap-2`,children:[u(W,{className:`w-28`,value:e.macroClass,options:ni.map(e=>({value:e,label:e})),onChange:e=>{let t=ni.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),u(W,{className:`w-32`,value:e.kind,options:[{value:`subject`,label:`subject`},{value:`model_error`,label:`model error`}],onChange:e=>{i(o,{kind:e.target.value===`model_error`?`model_error`:`subject`})}}),e.source===`assist`&&r(K,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),u(G,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:u(y,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[u(R,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),u(R,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{i(o,{subLabel:e.target.value})}})]}),c!==null&&u(`p`,{className:`text-[11px] text-danger`,children:c}),l!==null&&u(`p`,{className:`text-[11px] text-danger`,children:l})]},`${String(o)}-${String(e.bbox.x)}`)})})}function oi(e){return e.every(e=>ii(e.label)===null&&ii(e.subLabel)===null&&ri.has(e.macroClass))}function si(e){return e<0?0:e>1?1:e}function ci(e,t,n,r){if(!(e>0)||!(t>0)||!(n>0)||!(r>0))return null;let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{left:(e-a)/2,top:(t-o)/2,width:a,height:o}}function li(e,t,n){return{x:si((e-n.left)/n.width),y:si((t-n.top)/n.height)}}function ui(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function di(e){return e.w>=.01&&e.h>=.01}function fi(e,t){return{left:t.left+e.x*t.width,top:t.top+e.y*t.height,width:e.w*t.width,height:e.h*t.height}}function pi(e,t){let n=-1,r=1/0;return e.forEach((e,i)=>{if(!(t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h))return;let a=e.w*e.h;a<r&&(n=i,r=a)}),n}n();function mi({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedIndex:c,onSelect:d,onDraw:f}){let p=t(null),[m,h]=l({w:0,h:0}),[g,_]=l(null);i(()=>{let e=p.current;if(e===null)return;let t=new ResizeObserver(()=>{h({w:e.clientWidth,h:e.clientHeight})});return t.observe(e),h({w:e.clientWidth,h:e.clientHeight}),()=>{t.disconnect()}},[]);let v=ci(m.w,m.h,a,o),y=e(e=>{let t=p.current;if(t===null||v===null)return null;let n=t.getBoundingClientRect();return li(e.clientX-n.left,e.clientY-n.top,v)},[v]);return r(`div`,{ref:p,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none`,onPointerDown:e=>{let t=y(e);t!==null&&(e.currentTarget.setPointerCapture(e.pointerId),_({start:t,current:ui(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:ui(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),di(e)?f(e):d(pi(s.map(e=>e.bbox),g.start))},children:[u(`img`,{src:n,alt:`Frame being annotated`,className:`absolute inset-0 w-full h-full object-contain pointer-events-none`}),v!==null&&s.map((e,t)=>{let n=fi(e.bbox,v),i=e.kind===`model_error`,a=t===c,o=i?`#ef4444`:a?`#22c55e`:`#3b82f6`;return u(`div`,{className:`absolute pointer-events-none`,style:{left:n.left,top:n.top,width:n.width,height:n.height,border:`${a?`2px`:`1px`} ${i?`dashed`:`solid`} ${o}`,opacity:e.source===`assist`&&!a?.65:1},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded`,style:{background:o,color:`#08121f`},children:[e.label??e.macroClass,i?` ✕`:``]})},`${String(t)}-${String(e.bbox.x)}-${String(e.bbox.y)}`)}),g!==null&&v!==null&&u(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:fi(g.current,v)})]})}n();function hi(){let e=H({}),t=ve({}),n=be({}),[i,a]=l(null),[o,s]=l(null),c=async(e,t,n)=>{a(e),s(null);try{await We(p(t),n)}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(null)}},d=e.data,f=d!==void 0&&d.trackCount===0;return r(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Export dataset`}),r(G,{variant:`secondary`,size:`sm`,disabled:t.data===void 0||i!==null,onClick:()=>{t.data!==void 0&&c(`annotated`,t.data.url,`camstack-retrain-export.tar`)},children:[i===`annotated`?u(J,{className:`h-3 w-3 animate-spin`}):u(Ae,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Annotated dataset`})]}),r(G,{variant:`secondary`,size:`sm`,disabled:n.data===void 0||f||i!==null,onClick:()=>{n.data!==void 0&&c(`marked`,n.data.url,`camstack-training-export.tar`)},children:[i===`marked`?u(J,{className:`h-3 w-3 animate-spin`}):u(Ae,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Marked media`})]})]}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.isError?`The export summary could not be read, so the size of the marked set is unknown — not zero.`:d===void 0?`Measuring the marked set…`:f?`No track is marked for training: the marked-media archive would be empty. The annotated dataset can still hold frames from tracks already completed — this count does not measure those.`:`${String(d.trackCount)} marked track${d.trackCount===1?``:`s`} · ${String(d.fileCount)} file${d.fileCount===1?``:`s`} · ${it(d.byteCount)}${d.truncated?` · more marked tracks exist than one pass carries`:``}`}),(t.isError||n.isError)&&u(`p`,{className:`text-[11px] text-danger`,children:`An export data plane is not available on the node that answered — no archive can be streamed from here.`}),o!==null&&r(`p`,{className:`text-[11px] text-danger`,children:[`Download failed: `,o]})]})}function gi(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function _i({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c}){let l=new Set(t.map(e=>e.sourceMediaId)),d=e.filter(e=>!l.has(e.mediaId));return r(`div`,{className:`space-y-3`,children:[r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No frame copied yet. Selecting a frame copies it into retrain storage immediately — the dataset stops depending on the track's own media from that moment.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>u(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[r(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{s(e.frameId)},children:[u(D,{className:`h-3 w-3 text-success`}),u(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),r(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,gi(e.sizeBytes)]})]}),r(`button`,{type:`button`,"aria-label":`Remove this frame from the dataset`,className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-danger`,onClick:()=>{c(e.frameId)},children:[u(y,{className:`h-3 w-3`}),`remove`]})]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,d.length,`)`]}),d.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.length===0?`This track has no whole, unannotated frame left — its media aged out before it was marked. Anything already copied above is still usable.`:`Every available frame is already in the dataset.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:d.map(e=>{let t=i.get(e.mediaId);return r(`li`,{children:[r(G,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaId)},children:[a?u(J,{className:`h-3 w-3 animate-spin`}):u(t===void 0?ge:_,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:e.kind}),u(`span`,{className:`ml-1 text-foreground-subtle`,children:gi(e.sizeBytes)})]}),t!==void 0&&u(K,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaId)})})]})]})}function vi(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var yi={untouched:{icon:st,label:`to do`,variant:`default`},started:{icon:ot,label:`frames only`,variant:`info`},ready:{icon:N,label:`annotated`,variant:`success`}};function bi(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function xi({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:i,onSelect:a}){return t?r(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[u(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?u(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Nothing in staging. Mark a track for training from the viewer or the Events grid and it appears here.`}):u(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=yi[vi(e)],o=t.icon;return u(`li`,{children:r(`button`,{type:`button`,onClick:()=>{a(e)},className:`w-full text-left px-3 py-2 flex items-start gap-2 hover:bg-surface-hover ${e.trackId===n?`bg-surface-hover`:``}`,children:[u(o,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),r(`span`,{className:`min-w-0 flex-1`,children:[r(`span`,{className:`flex items-center gap-2`,children:[u(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),u(K,{variant:t.variant,children:t.label})]}),r(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[i.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,bi(e.lastSeen)]}),r(`span`,{className:`block text-[11px] text-foreground-muted`,children:[e.frameCount,` frame`,e.frameCount===1?``:`s`,` ·`,` `,e.annotationCount,` subject`,e.annotationCount===1?``:`s`]})]})]})},e.trackId)})})}var Si=`object-detection`;function Ci(e,t){for(let n of e){if(n.addonId===t)return n;let e=n.children===void 0?void 0:Ci(n.children,t);if(e!==void 0)return e}}function wi(e,t){for(let n of e.slots){let e=n.addons.find(e=>e.id===t);if(e!==void 0)return e}}function Ti(e){let{status:t,nodeDevices:n,schema:r,resolvedSteps:i}=e;if(t===void 0)return{kind:`unknown`,gap:`pending`};if(t.detection===null)return{kind:`unknown`,gap:t.degraded.some(e=>e.stage===`detection`)?`placement-unreadable`:`detection-off`};let a=t.detection;if(n===void 0||r===void 0||i===void 0)return{kind:`unknown`,gap:`pending`};if(!n.reachable)return{kind:`unknown`,gap:`node-unreachable`};let o=n.devices.find(e=>e.backend===a.engine.backend&&e.device===a.engine.device);if(o===void 0)return{kind:`unknown`,gap:`device-unknown`};let s=wi(r,Si);if(s===void 0)return{kind:`unknown`,gap:`step-unknown`};let c=z({catalog:s,device:o,override:Ci(i,Si)?.modelId,base:o.steps?.[Si]?.modelId});return c===void 0?{kind:`unknown`,gap:`no-model`}:{kind:`resolved`,nodeId:a.nodeId,modelId:c,minScore:s.models.find(e=>e.id===c)?.defaultConfidence??s.defaultConfidence}}n();var Ei=`person`,Di={pending:`Reading which detector this camera runs…`,"placement-unreadable":`The detection stage of this camera could not be read, so the model it runs is unknown — not absent.`,"detection-off":`This camera runs no object detector, so there is no proposal to mirror.`,"node-unreachable":`The node that detects for this camera did not answer about its accelerators.`,"device-unknown":`The node does not list the accelerator this camera detects on — asking another one would propose with a different model.`,"step-unknown":`That node carries no object-detection step in its catalog.`,"no-model":`No object-detection model on that accelerator can be resolved for this camera.`};function Oi(){let[t,n]=l(null),[i,o]=l(null),[c,f]=l([]),[p,m]=l(-1),[h,g]=l(new Map),[_,v]=l(null),y=Me({projection:`slim`,isCamera:!0}),b=a(()=>{let e=new Map;for(let t of y.data??[])e.set(t.id,t.name);return e},[y.data]),x=ue({}),S=se({trackId:t?.trackId??``},{enabled:t!==null}),C=De({trackId:t?.trackId??``},{enabled:t!==null}),w=we({frameId:i??``},{enabled:i!==null}),D=Oe(),O=ce(),k=_e(),A=fe(),j=re(),M=he({deviceIds:t===null?[]:[t.deviceId]},{enabled:t!==null,staleTime:3e4}),N=M.data?.[0]?.detection?.nodeId??null,P=T({nodeId:N??``},{enabled:N!==null,staleTime:3e4}),ee=ae({nodeId:N??``},{enabled:N!==null,staleTime:3e4}),F=E({deviceId:t?.deviceId??0},{enabled:t!==null,staleTime:3e4}),I=a(()=>Ti({status:M.data?.[0],nodeDevices:P.data,schema:ee.data,resolvedSteps:F.data?.steps}),[M.data,P.data,ee.data,F.data]);d(()=>{if(i===null){f([]);return}f((C.data??[]).filter(e=>e.mediaKey===i).map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))),m(-1)},[i,C.data]),d(()=>{let e=S.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[S.data,i]);let te=e(e=>{n(e),o(null),f([]),g(new Map),v(null)},[]),L=e(async e=>{if(t===null)return;let n=await D.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,mediaIds:[e]});if(n.refused.length>0){let e=new Map(h);for(let t of n.refused)e.set(t.sourceMediaId,t.reason);g(e)}n.copied.length>0&&o(n.copied[0].frameId),await S.refetch(),await x.refetch()},[t,D,h,S,x]),R=e(async e=>{t!==null&&(await O.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await S.refetch(),await C.refetch(),await x.refetch())},[t,O,i,S,C,x]),z=e(async e=>{if(t===null||i===null)return;if(v(null),I.kind!==`resolved`){v(Di[I.gap]);return}let n=await k.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:I.modelId,minScore:I.minScore},nodeId:I.nodeId});if(n.kind===`refused`){v(n.reason===`no-zone`?`A package proposal runs on the zone crop only — this camera has no zone, and running the detector on the whole frame at 0.35 proposes furniture.`:`The pipeline refused: ${n.reason}${n.detail===void 0?``:` — ${n.detail}`}`);return}f(e=>[...e,...n.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))]),v(`${n.proposals.length} proposal${n.proposals.length===1?``:`s`} from ${n.modelId}`+(n.belowThreshold>0?` — ${n.belowThreshold} more were below ${n.minScore.toFixed(2)}`:``))},[t,i,k,I]),ne=e(e=>{f(t=>[...t,{bbox:e,macroClass:Ei,kind:`subject`,source:`operator`}]),m(c.length)},[c.length]),ie=e((e,t)=>{f(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),B=e(e=>{f(t=>t.filter((t,n)=>n!==e)),m(-1)},[]),V=e(async()=>{t===null||i===null||(await A.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,annotations:c.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{},...e.subLabel!==void 0&&e.subLabel!==``?{subLabel:e.subLabel}:{},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))}),await C.refetch(),await x.refetch(),v(`Annotations saved.`))},[t,i,c,A,C,x]),H=e(async()=>{if(t===null)return;let e=await j.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});v(e.changed?`Track completed — it is now trained, and its own media is evictable again.`:e.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${e.reason??`unknown`}`),await x.refetch(),e.changed&&n(null)},[t,j,x]),U=w.data,W=oi(c)&&i!==null;return r(Be,{subtitle:`Turn the tracks you marked for training into an annotated dataset. Selecting a frame copies it — the dataset never depends on media that can be swept.`,actions:t===null?null:r(G,{size:`sm`,onClick:()=>void H(),children:[u(ct,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Complete track`})]}),children:[_!==null&&u(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:_}),u(hi,{}),r(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[r(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),u(K,{children:x.data?.length??0})]}),u(xi,{tracks:x.data??[],isLoading:x.isLoading,selectedTrackId:t?.trackId??null,deviceNames:b,onSelect:te})]}),u(`section`,{className:`space-y-3 min-w-0`,children:t===null?u(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):r(s,{children:[u(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:u(_i,{candidates:S.data?.candidates??[],copies:S.data?.copies??[],activeFrameId:i,refusals:h,isSelecting:D.isPending,onSelectCandidate:e=>void L(e),onOpenCopy:o,onRemoveCopy:e=>void R(e)})}),i!==null&&r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[u(`div`,{className:`rounded-md border border-border overflow-hidden`,children:U===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[u(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):u(mi,{imageSrc:`data:image/jpeg;base64,${U.base64}`,imageWidth:U.width,imageHeight:U.height,boxes:c,selectedIndex:p,onSelect:m,onDraw:ne})}),r(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),r(G,{variant:`secondary`,size:`sm`,disabled:k.isPending||I.kind!==`resolved`,onClick:()=>void z(`objects`),children:[u(de,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Propose`})]}),r(G,{variant:`secondary`,size:`sm`,disabled:k.isPending||I.kind!==`resolved`,onClick:()=>void z(`package`),children:[u(de,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Packages`})]})]}),u(`div`,{className:`px-3 py-1 border-b border-border text-[11px] text-foreground-subtle`,children:I.kind===`resolved`?`Proposals come from ${I.modelId} at ${I.minScore.toFixed(2)}, on ${I.nodeId} — what this camera really runs.`:Di[I.gap]}),u(`div`,{className:`flex-1 overflow-y-auto`,children:u(ai,{annotations:c,selectedIndex:p,onSelect:m,onChange:ie,onDelete:B})}),r(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:[c.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),u(G,{size:`sm`,disabled:!W||A.isPending,onClick:()=>void V(),children:`Save frame`})]})]})]})]})})]})]})}function ki(){return u(`div`,{className:`flex flex-col p-4`,children:u(rt,{tabs:[{id:`feed`,label:`Feed`,icon:Ee,content:u(ti,{})},{id:`retrain`,label:`Retrain`,icon:ct,content:u(Oi,{})},{id:`debug`,label:`Debug`,icon:ne,content:u(Or,{})}]})})}export{ki as EventsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{K as e,Q as t,S as n,W as r,b as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as s}from"./player-overlays-BQsHwEhF.js";import{Al as c,Hu as l,Kc as u,Qt as d,Sn as f,Zt as p}from"./src-AIYVh4G3.js";function m(e){return[e.value,e.label,e.description].filter(e=>typeof e==`string`&&e.length>0).join(` `).toLowerCase()}function h(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?e:e.filter(e=>{let t=m(e);return n.every(e=>t.includes(e))})}function g(e,t){let n=new Map(e.map(e=>[e.value,e])),r=new Set(t);return{selectedOptions:t.map(e=>n.get(e)??{value:e,label:e}),unselected:e.filter(e=>!r.has(e.value))}}function _(e){return e>=8}t();var v=`flex items-center gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30`;function y({label:e,onRemove:t,warning:r=!1,iconId:i,testId:a}){return n(`span`,{"data-testid":a,className:r?`inline-flex items-center gap-1 rounded-md bg-warning/10 px-1.5 py-0.5 text-[11px] text-warning max-w-full`:`inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-[11px] text-primary max-w-full`,children:[i!==void 0&&o(f,{iconId:i,size:12}),o(`span`,{className:`truncate`,children:e}),t!==void 0&&o(`button`,{type:`button`,className:`shrink-0 hover:text-danger`,"aria-label":`Remove ${e}`,onClick:t,children:o(u,{className:`h-2.5 w-2.5`})})]})}var b=`block text-[11px] font-medium text-foreground mb-1 break-words`,x=`text-[10px] text-foreground-subtle mt-0.5 break-words`;function S({field:t,value:i,onChange:u,disabled:d,translationFn:p}){let m=Array.isArray(i)?i:[],_=d===!0||t.disabled===!0,S=t.maxItems!==void 0&&m.length>=t.maxItems,[C,w]=a(``),[T,D]=a(!1),[O,k]=a(0),A=e(null),j=e(null),{selectedOptions:M}=r(()=>g(t.options,m),[t.options,m]),N=r(()=>h(t.options,C),[t.options,C]),P=e=>{if(!_)if(m.includes(e))u(m.filter(t=>t!==e));else{if(t.maxItems!==void 0&&m.length>=t.maxItems)return;u([...m,e])}},F=e=>{if(e.key===`ArrowDown`)e.preventDefault(),D(!0),k(e=>N.length===0?0:(e+1)%N.length);else if(e.key===`ArrowUp`)e.preventDefault(),D(!0),k(e=>N.length===0?0:(e-1+N.length)%N.length);else if(e.key===`Enter`){e.preventDefault();let t=N[O];t&&P(t.value)}else e.key===`Escape`?D(!1):e.key===`Backspace`&&C===``&&m.length>0&&u(m.slice(0,-1))},I=E(t.label,p),L=E(t.description,p);return n(`div`,{className:`min-w-0`,children:[I!==void 0&&I!==``&&o(`label`,{className:b,children:I}),M.length>0&&o(`div`,{className:`flex flex-wrap gap-1 mb-1.5`,children:M.map(e=>o(y,{label:e.label,...e.iconId===void 0?{}:{iconId:e.iconId},..._?{}:{onRemove:()=>P(e.value)}},e.value))}),n(`div`,{className:v+(_?` opacity-50`:``),children:[o(c,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),o(`input`,{ref:A,type:`text`,role:`combobox`,"aria-expanded":T,"aria-controls":`msel-${t.key}`,className:`min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-foreground-disabled`,value:C,placeholder:S?`Max ${t.maxItems} selected`:t.placeholder??`Search to add…`,disabled:_,onChange:e=>{w(e.target.value),D(!0),k(0)},onFocus:()=>D(!0),onBlur:()=>{j.current=setTimeout(()=>D(!1),120)},onKeyDown:F}),o(s,{className:`h-3.5 w-3.5 shrink-0 cursor-pointer text-foreground-subtle`,onMouseDown:e=>{e.preventDefault(),j.current&&clearTimeout(j.current),D(e=>!e),A.current?.focus()}})]}),T&&!_&&o(`div`,{id:`msel-${t.key}`,role:`listbox`,className:`mt-1 max-h-56 overflow-y-auto rounded-md border border-border bg-surface shadow-lg`,onMouseDown:e=>{e.preventDefault()},children:N.length===0?n(`div`,{className:`px-2.5 py-2 text-[11px] text-foreground-subtle italic`,children:[`No matches for “`,C,`”`]}):N.map((e,t)=>{let r=m.includes(e.value),i=!r&&S;return n(`button`,{type:`button`,role:`option`,"aria-selected":r,disabled:i,className:[`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition-colors`,t===O?`bg-primary/10`:`hover:bg-surface-hover`,i?`opacity-40 cursor-not-allowed`:`cursor-pointer`].join(` `),onMouseEnter:()=>k(t),onClick:()=>P(e.value),children:[o(`span`,{className:[`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border`,r?`border-primary bg-primary text-white`:`border-border`].join(` `),children:r&&o(l,{className:`h-2.5 w-2.5`})}),e.iconId!==void 0&&o(f,{iconId:e.iconId,size:13}),o(`span`,{className:`truncate text-foreground`,children:e.label})]},e.value)})}),L&&o(`p`,{className:x,children:L})]})}t();function C(e){return e.type===`multiselect`}function w({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:s,allFields:c,onAction:l}){return C(e)&&_(e.options.length)?d(e,t,c)?o(S,{field:e,value:t[e.key],onChange:t=>n(e.key,t),disabled:r,translationFn:i}):null:o(p,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:s,allFields:c,onAction:l})}function T(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function E(e,t){if(e!==void 0)return t&&T(e)?t(e):e}function D({section:e,values:t,onChange:r,disabled:s,translationFn:c,onTestField:l,probeResults:u,onAction:f}){let[m,h]=a(e.defaultCollapsed??!1),g=e.style===`accordion`;if(e.fields.reduce((n,r)=>n+ +!!d(r,t,e.fields),0)===0)return null;let _=e.fields,v=e.columns??2,y=v===1?`grid-cols-1`:v===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:v===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,b=e.fields.length===1&&e.fields[0]?.type===`widget`?e.fields[0]:void 0;return n(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(b!==void 0||!e.title&&!e.description)&&n(`div`,{className:[`flex items-center justify-between mb-2`,g?`cursor-pointer`:``].join(` `),onClick:g?()=>h(e=>!e):void 0,children:[n(`div`,{children:[e.title&&o(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:E(e.title,c)}),e.description&&o(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:E(e.description,c)})]}),g&&o(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:m?`▸`:`▾`})]}),!m&&(b===void 0?o(i,{children:o(`div`,{className:`grid ${y} gap-x-3 gap-y-2.5`,children:_.map(n=>o(w,{field:n,values:t,onChange:r,disabled:s,translationFn:c,onTestField:l,externalProbe:u?.[n.key],allFields:e.fields,onAction:f},n.key))})}):o(p,{field:b,values:t,onChange:r,disabled:s,translationFn:c,onTestField:l,externalProbe:u?.[b.key],allFields:e.fields,onAction:f},b.key))]})}function O({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:s,onClearProbe:c,onAction:l}){let u=(e,r)=>{n({...t,[e]:r}),c?.(e)};return o(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>o(D,{section:e,values:t,onChange:u,disabled:r,translationFn:i,onTestField:a,probeResults:s,onAction:l},`${e.id}-${n}`))})}export{v as n,y as r,O as t};
|