@camstack/addon-admin-ui 1.2.312 → 1.2.313
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-D_jT_fKd.js → AddonCollectionPage-DX8FCaT6.js} +1 -1
- package/dist/assets/{Addons-Dm22iIFC.js → Addons-Dd7YigNw.js} +1 -1
- package/dist/assets/{AdminTabs-BLa2Yu61.js → AdminTabs-CkZ3HCsC.js} +1 -1
- package/dist/assets/{AiProfiles-C1FiOjIi.js → AiProfiles-Uqn4Xesj.js} +1 -1
- package/dist/assets/{BrokerForm-W3yjLc5F.js → BrokerForm-BPKDqfep.js} +1 -1
- package/dist/assets/{Build-D42X2om2.js → Build-CkoCD5mN.js} +1 -1
- package/dist/assets/{Capabilities-DgQeevtK.js → Capabilities-De4yZ5_m.js} +1 -1
- package/dist/assets/{CapabilityBadges-PxEJ-G8M.js → CapabilityBadges-DHY8nHlI.js} +1 -1
- package/dist/assets/{Cluster-CYJRjTNq.js → Cluster-D2tcoqSj.js} +1 -1
- package/dist/assets/{CompositionEditor-BR4ITRMC.js → CompositionEditor-CULEp5pb.js} +1 -1
- package/dist/assets/{CompositionEditorPage-B9FazR7t.js → CompositionEditorPage-CLdgB8to.js} +1 -1
- package/dist/assets/{Data-BZ997zDU.js → Data-DIktVuyj.js} +1 -1
- package/dist/assets/{DetectionIntelligence-CoZLbnyz.js → DetectionIntelligence-DNAAoRDp.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-DGRRUhpU.js → DeviceAggregateSection-DMd2WZT9.js} +1 -1
- package/dist/assets/{DeviceDetail-X4_H5AEU.js → DeviceDetail-CjW-NXCI.js} +1 -1
- package/dist/assets/{Devices-D2avtpSh.js → Devices-CHM8pV35.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-DndXvLAf.js → EmbedPlayerPage-fB57a9gd.js} +1 -1
- package/dist/assets/{Events-DcBl0VuS.js → Events-DSictw2E.js} +1 -1
- package/dist/assets/{FormBuilder-DcvB5DXc.js → FormBuilder-D3oSMJb_.js} +1 -1
- package/dist/assets/{Identity-BFps8fGD.js → Identity-d46-Z6Ye.js} +1 -1
- package/dist/assets/{IntegrationDetail-cLLqyAlF.js → IntegrationDetail-_s1jn10y.js} +1 -1
- package/dist/assets/{Integrations--caPrwcY.js → Integrations-BPLuDjht.js} +1 -1
- package/dist/assets/{Integrations-CKkdQ5eX.js → Integrations-SR0bANee.js} +1 -1
- package/dist/assets/{Locations-DCOaDC4m.js → Locations-CSdf0Sod.js} +1 -1
- package/dist/assets/{Logs-CVsufO3f.js → Logs-BDzIjitK.js} +1 -1
- package/dist/assets/{ModelLicenses-C53LveOk.js → ModelLicenses-bF0wlw_A.js} +1 -1
- package/dist/assets/{MotionZonesSettings-BP6JgzDx.js → MotionZonesSettings-CKbKLkZx.js} +1 -1
- package/dist/assets/{MyAccess-BPy91g8M.js → MyAccess-eaO3Ieug.js} +1 -1
- package/dist/assets/{Network-BH8GF1jj.js → Network-CBV5e0t5.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-DaUaDmgN.js → NodeAddonsSettingsPanel-C2dYg-1V.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-CV8hPlUN.js → NodeInferenceDevices-Wlk8B-Nc.js} +1 -1
- package/dist/assets/Notifications-BHLLlwNj.js +1 -0
- package/dist/assets/{Pipeline-VFKCmqnk.js → Pipeline-BHc381ud.js} +1 -1
- package/dist/assets/{Plates-CwmrYBy1.js → Plates-i21xtBfM.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DrGP3agd.js → PrivacyMaskSettings-BEhQwxlO.js} +1 -1
- package/dist/assets/{ProviderIcon-DpDrKQg9.js → ProviderIcon-ZrL8hgOi.js} +1 -1
- package/dist/assets/{Recordings-wBHDYR-a.js → Recordings-WIOGSNTE.js} +1 -1
- package/dist/assets/{ScanNetworkModal-Bs0BPCl_.js → ScanNetworkModal-D3914YtC.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-BKRn3LUw.js → SceneMonitorEditor-D5tzUVXi.js} +1 -1
- package/dist/assets/{Scenes-AZ844W8Q.js → Scenes-Dvx2S8On.js} +1 -1
- package/dist/assets/{Settings-C3eJAyF_.js → Settings-DumVFDea.js} +1 -1
- package/dist/assets/{Showroom-CrjPa3nO.js → Showroom-DF-_wvzq.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-DZBpj1S8.js → StorageLocationsPanel-DY2ZcvFK.js} +1 -1
- package/dist/assets/{Terminal-DP9Z-4oI.js → Terminal-nkSTSU7d.js} +1 -1
- package/dist/assets/{Viewer-BdSLJVFV.js → Viewer-DKv0FjME.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BzFC5oNH.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B9aQEC0J.js} +1 -1
- package/dist/assets/{archive--Adx9xt7.js → archive-BhK62uND.js} +1 -1
- package/dist/assets/{authed-media-BjiwUfzl.js → authed-media-nsjri51Q.js} +1 -1
- package/dist/assets/{boxes-C9etGa7E.js → boxes-DK8vMnI6.js} +1 -1
- package/dist/assets/circle-slash-Cc4MQ0p4.js +1 -0
- package/dist/assets/{debounced-invalidate-D_ADe-pO.js → debounced-invalidate-B6XAyg8u.js} +1 -1
- package/dist/assets/{device-integration-icon-CDQck2H0.js → device-integration-icon-DepzDzE0.js} +1 -1
- package/dist/assets/{dist-CLDbTq6j.js → dist-B2fXVbOE.js} +3 -3
- package/dist/assets/{dist-Dhc7r6s3.js → dist-By9GSmdO.js} +1 -1
- package/dist/assets/{face-bbox-BMJUn0ul.js → face-bbox-nz-Y1fXw.js} +1 -1
- package/dist/assets/{hard-drive-download-_iraTBzr.js → hard-drive-download-EjN5BuzT.js} +1 -1
- package/dist/assets/{hostInit-BUbZdY_9.js → hostInit-BKTPtHbx.js} +1 -1
- package/dist/assets/{index-ToaOKO9V.js → index-M74_weOu.js} +3 -3
- package/dist/assets/{layers-DiVzoqI9.js → layers-DWEHZvuc.js} +1 -1
- package/dist/assets/{location-owned-usage-BYFxxj5I.js → location-owned-usage-DpGuVsmt.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-eaedec53.js → mf-entry-bootstrap-0-fa7cb38b.js} +2 -2
- package/dist/assets/{player-overlays-CW14DMpN.js → player-overlays-Cfcp6NgQ.js} +1 -1
- package/dist/assets/remoteEntry-otcBA5Lx.js +1 -0
- package/dist/assets/{send-CPgogH5c.js → send-CHSdt1bF.js} +1 -1
- package/dist/assets/{settings-2-Ch5_hcKD.js → settings-2-DSHFlOLu.js} +1 -1
- package/dist/assets/{square-check-big-znl8trUW.js → square-check-big-BM9cwujH.js} +1 -1
- package/dist/assets/src-BQHqLKGc.js +349 -0
- package/dist/assets/{src-DIrDyFmq.js → src-BeGnyQUE.js} +3 -3
- package/dist/assets/{use-scenes-feed-YEEHIE1o.js → use-scenes-feed-9RFRgjFo.js} +1 -1
- package/dist/assets/{use-stationary-objects-DOl51SBk.js → use-stationary-objects-G14SHB2s.js} +1 -1
- package/dist/assets/{useDevice-C8SXb13_.js → useDevice-DvOxHkK6.js} +1 -1
- package/dist/assets/useEventInvalidation-DPwzQ8Dt.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BGtbjkMI.js → useNodeUrlSelection-DaNJZDRb.js} +1 -1
- package/dist/assets/user-round-DNkGWLTR.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BaoDsuWl.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C8CtgfL2.js} +2 -2
- package/dist/index.html +5 -5
- package/dist/server/addon.js +15 -23
- package/package.json +1 -1
- package/dist/assets/Notifications-B2HuQQif.js +0 -1
- package/dist/assets/circle-slash-cB0daX9J.js +0 -1
- package/dist/assets/remoteEntry-Cor8-DvN.js +0 -1
- package/dist/assets/src-JqpYwj-l.js +0 -349
- package/dist/assets/useEventInvalidation-B86vUgTW.js +0 -1
- package/dist/assets/user-round-D9U1WJod.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
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-CW14DMpN.js";import{$ as k,$i as A,$l as j,$r as M,A as N,Aa as P,Ai as F,At as ee,Bi as te,Bt as ne,C as re,Ci as ie,Ct as I,Di as L,Dn as ae,Fi as oe,Ft as R,G as z,Go as B,Gt as se,Ho as ce,It as le,Jl as ue,Jo as de,Jr as V,Jt as H,K as fe,Ki as pe,Kt as me,Ku as he,L as ge,Li as _e,Lt as ve,M as ye,Mi as be,Ml as xe,Mn as Se,Mt as U,N as Ce,Nt as we,Oi as Te,On as Ee,Ot as De,P as Oe,Ps as ke,Pt as Ae,Qi as je,Qo as Me,Rt as Ne,Ru as Pe,S as W,Sd as Fe,Sn as Ie,Ta as Le,U as Re,Ul as ze,V as Be,Vl as Ve,Vo as He,W as Ue,Wo as We,Wt as Ge,X as Ke,Xl as qe,Xr as Je,Xt as Ye,Y as Xe,Yl as Ze,Yt as Qe,Yu as $e,Zc as et,Zi as tt,Zr as nt,_n as rt,a as it,aa as at,ai as ot,at as st,au as ct,bt as lt,c as ut,cd as dt,cl as ft,co as pt,cr as mt,ct as ht,dd as gt,dl as _t,dn as vt,ds as yt,dt as bt,du as xt,ea as St,ed as Ct,en as wt,fn as Tt,fs as Et,ft as Dt,gn as Ot,gu as kt,hi as At,hu as jt,i as Mt,il as Nt,it as Pt,iu as Ft,ja as It,ji as Lt,ka as Rt,ki as zt,kn as Bt,kt as Vt,l as Ht,ld as Ut,lt as Wt,lu as Gt,mn as Kt,mt as qt,na as Jt,ni as Yt,nl as Xt,nn as Zt,nt as Qt,o as $t,oi as en,ot as tn,ou as nn,pn as rn,ps as an,pt as on,q as sn,qi as cn,qr as ln,r as un,ri as dn,rn as fn,rt as pn,ru as mn,s as hn,sd as gn,si as _n,sl as vn,so as yn,su as bn,tn as xn,to as Sn,tt as Cn,u as wn,us as Tn,ut as En,v as Dn,vi as On,vn as kn,w as An,wi as jn,wr as Mn,wu as Nn,xn as G,y as Pn,ys as Fn,zu as In}from"./src-DIrDyFmq.js";import{t as Ln}from"./archive--Adx9xt7.js";import{t as Rn}from"./boxes-C9etGa7E.js";import{t as zn}from"./ProviderIcon-DpDrKQg9.js";import{t as Bn}from"./circle-slash-cB0daX9J.js";import{n as Vn}from"./NodeInferenceDevices-CV8hPlUN.js";import{t as Hn}from"./layers-DiVzoqI9.js";import{t as Un}from"./CapabilityBadges-PxEJ-G8M.js";import{At as Wn,Bt as Gn,En as Kn,Jn as qn,Ln as Jn,Lt as Yn,Mt as Xn,Nn as Zn,Ot as Qn,Pn as K,Rn as $n,Rt as er,Sn as tr,_r as nr,bn as rr,fn as ir,gr as ar,jn as or,jt as sr,kt as cr,nn as lr,qn as ur,rn as dr,tn as fr,wn as pr,zn as q}from"./src-JqpYwj-l.js";import{_ as mr,a as hr,d as gr,f as _r,h as vr,l as J,m as yr,p as br,r as xr,t as Sr,u as Cr}from"./index-ToaOKO9V.js";import{n as wr,t as Tr}from"./useDevice-C8SXb13_.js";import{C as Er,E as Dr,S as Y,T as Or,_ as kr,a as Ar,b as jr,c as Mr,d as Nr,f as Pr,g as Fr,h as Ir,i as Lr,l as Rr,m as zr,n as Br,o as Vr,p as Hr,r as Ur,s as Wr,t as Gr,u as Kr,v as qr,x as Jr,y as Yr}from"./CompositionEditor-BR4ITRMC.js";import{t as Xr}from"./authed-media-BjiwUfzl.js";import"./useEventInvalidation-B86vUgTW.js";import{t as Zr}from"./StatusBadge-CeptlsPG.js";import{t as Qr}from"./use-stationary-objects-DOl51SBk.js";import{a as $r,i as ei,n as ti,r as ni,t as ri}from"./DeviceAggregateSection-DGRRUhpU.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:qe,detection:mr,privacy:x,microphone:E,speaker:_t,listening:oi,archive:Ln,recording:ai,notifications:gn,generic:xe};function pi({deviceId:t}){let n=c(),i=Number.isFinite(t),[a,o]=l(null),[s,u]=l(!1),f=B({deviceId:t},{enabled:i});un([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let p=ci(f.data),m=an({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(le,{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(xe,{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(ve,{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=Xe(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=_r(),i=v(),{data:a,isLoading:o,isError:s}=wr(e),{data:c}=L({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=z(c?.stableId??``,l,c?.childLayout),f=u.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>d(Re,{trpc:i.trpcClient,device:{...t,name:Ke(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(Ue,{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(Ue,{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}=Tr(e),{data:i,isLoading:a}=wr(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(Pt,{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(Fe,{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=ht(t)?.HeroCard??Wt,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(tn,{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(En,{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(Wt,{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?nn:Nn,{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(zn,{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(Zr,{status:i?`online`:`offline`}),a.length>0&&d(Un,{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=Yt({deviceId:e},{refetchInterval:1e4,retry:!1}),i=dn({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(ct,{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(jt,{className:`h-3.5 w-3.5 animate-spin`}):d(Ze,{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(vn,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),d(Ii,{icon:d(bn,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),d(Ii,{icon:d(ft,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?d(Ii,{icon:d(he,{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 hn(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=P(),m=Rt(),h=It(),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=Qr(i?[e]:[]),l=a(()=>{if(!i)return;let e=[];for(let t of c.rows){let n=$t(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}=it(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=rt(),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(W,{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(qt,{...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(`
|
|
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-Cfcp6NgQ.js";import{$ as k,$i as A,$l as j,$r as M,A as N,Aa as P,Ai as F,At as ee,Bi as te,Bt as ne,C as re,Ci as ie,Ct as I,Di as L,Dn as ae,Fi as oe,Ft as R,G as z,Go as B,Gt as se,Ho as ce,It as le,Jl as ue,Jo as de,Jr as V,Jt as H,K as fe,Ki as pe,Kt as me,Ku as he,L as ge,Li as _e,Lt as ve,M as ye,Mi as be,Ml as xe,Mn as Se,Mt as U,N as Ce,Nt as we,Oi as Te,On as Ee,Ot as De,P as Oe,Ps as ke,Pt as Ae,Qi as je,Qo as Me,Rt as Ne,Ru as Pe,S as W,Sd as Fe,Sn as Ie,Ta as Le,U as Re,Ul as ze,V as Be,Vl as Ve,Vo as He,W as Ue,Wo as We,Wt as Ge,X as Ke,Xl as qe,Xr as Je,Xt as Ye,Y as Xe,Yl as Ze,Yt as Qe,Yu as $e,Zc as et,Zi as tt,Zr as nt,_n as rt,a as it,aa as at,ai as ot,at as st,au as ct,bt as lt,c as ut,cd as dt,cl as ft,co as pt,cr as mt,ct as ht,dd as gt,dl as _t,dn as vt,ds as yt,dt as bt,du as xt,ea as St,ed as Ct,en as wt,fn as Tt,fs as Et,ft as Dt,gn as Ot,gu as kt,hi as At,hu as jt,i as Mt,il as Nt,it as Pt,iu as Ft,ja as It,ji as Lt,ka as Rt,ki as zt,kn as Bt,kt as Vt,l as Ht,ld as Ut,lt as Wt,lu as Gt,mn as Kt,mt as qt,na as Jt,ni as Yt,nl as Xt,nn as Zt,nt as Qt,o as $t,oi as en,ot as tn,ou as nn,pn as rn,ps as an,pt as on,q as sn,qi as cn,qr as ln,r as un,ri as dn,rn as fn,rt as pn,ru as mn,s as hn,sd as gn,si as _n,sl as vn,so as yn,su as bn,tn as xn,to as Sn,tt as Cn,u as wn,us as Tn,ut as En,v as Dn,vi as On,vn as kn,w as An,wi as jn,wr as Mn,wu as Nn,xn as G,y as Pn,ys as Fn,zu as In}from"./src-BeGnyQUE.js";import{t as Ln}from"./archive-BhK62uND.js";import{t as Rn}from"./boxes-DK8vMnI6.js";import{t as zn}from"./ProviderIcon-ZrL8hgOi.js";import{t as Bn}from"./circle-slash-Cc4MQ0p4.js";import{n as Vn}from"./NodeInferenceDevices-Wlk8B-Nc.js";import{t as Hn}from"./layers-DWEHZvuc.js";import{t as Un}from"./CapabilityBadges-DHY8nHlI.js";import{At as Wn,Bt as Gn,En as Kn,Jn as qn,Ln as Jn,Lt as Yn,Mt as Xn,Nn as Zn,Ot as Qn,Pn as K,Rn as $n,Rt as er,Sn as tr,_r as nr,bn as rr,fn as ir,gr as ar,jn as or,jt as sr,kt as cr,nn as lr,qn as ur,rn as dr,tn as fr,wn as pr,zn as q}from"./src-BQHqLKGc.js";import{_ as mr,a as hr,d as gr,f as _r,h as vr,l as J,m as yr,p as br,r as xr,t as Sr,u as Cr}from"./index-M74_weOu.js";import{n as wr,t as Tr}from"./useDevice-DvOxHkK6.js";import{C as Er,E as Dr,S as Y,T as Or,_ as kr,a as Ar,b as jr,c as Mr,d as Nr,f as Pr,g as Fr,h as Ir,i as Lr,l as Rr,m as zr,n as Br,o as Vr,p as Hr,r as Ur,s as Wr,t as Gr,u as Kr,v as qr,x as Jr,y as Yr}from"./CompositionEditor-CULEp5pb.js";import{t as Xr}from"./authed-media-nsjri51Q.js";import"./useEventInvalidation-DPwzQ8Dt.js";import{t as Zr}from"./StatusBadge-CeptlsPG.js";import{t as Qr}from"./use-stationary-objects-G14SHB2s.js";import{a as $r,i as ei,n as ti,r as ni,t as ri}from"./DeviceAggregateSection-DMd2WZT9.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:qe,detection:mr,privacy:x,microphone:E,speaker:_t,listening:oi,archive:Ln,recording:ai,notifications:gn,generic:xe};function pi({deviceId:t}){let n=c(),i=Number.isFinite(t),[a,o]=l(null),[s,u]=l(!1),f=B({deviceId:t},{enabled:i});un([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let p=ci(f.data),m=an({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(le,{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(xe,{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(ve,{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=Xe(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=_r(),i=v(),{data:a,isLoading:o,isError:s}=wr(e),{data:c}=L({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=z(c?.stableId??``,l,c?.childLayout),f=u.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>d(Re,{trpc:i.trpcClient,device:{...t,name:Ke(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(Ue,{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(Ue,{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}=Tr(e),{data:i,isLoading:a}=wr(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(Pt,{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(Fe,{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=ht(t)?.HeroCard??Wt,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(tn,{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(En,{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(Wt,{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?nn:Nn,{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(zn,{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(Zr,{status:i?`online`:`offline`}),a.length>0&&d(Un,{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=Yt({deviceId:e},{refetchInterval:1e4,retry:!1}),i=dn({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(ct,{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(jt,{className:`h-3.5 w-3.5 animate-spin`}):d(Ze,{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(vn,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),d(Ii,{icon:d(bn,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),d(Ii,{icon:d(ft,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?d(Ii,{icon:d(he,{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 hn(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=P(),m=Rt(),h=It(),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=Qr(i?[e]:[]),l=a(()=>{if(!i)return;let e=[];for(let t of c.rows){let n=$t(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}=it(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=rt(),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(W,{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(qt,{...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
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(on,{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(Dt,{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=tr(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=tt({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(Ct,{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(Nt,{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(mn,{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}=oe(void 0,{enabled:h}),C=S??[];f(()=>{h||v(n??``)},[n,h]),f(()=>{h&&x.current?.focus()},[h]);let w=cn({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(Ct,{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(Nt,{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(xt,{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(mn,{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($n));function pa(e){return fa.has(e)}function ma(e){let t=Object.values($n);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=A(),f=pe(),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)?k(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(Ge,{open:e,onOpenChange:e=>e?void 0:v(),children:r(me,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[d(Qe,{children:d(Ye,{children:t})}),d(se,{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(Vr,{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(Ar,{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(H,{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=Mr(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}:qn[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=at({deviceId:e?.deviceId??Ta,capName:e?.cap??``},{enabled:e!==null}),r=ut(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(Nt,{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:ur}];function Pa(e,t){return t!==null&&e.includes(t)?t:ur.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=qn[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=Dn(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=Pn({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=Xt.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=Be(e,t);return n.kind===`resolved`?n.integration.name:null}function Ha(e){let t=Lt({projection:`slim`},{enabled:e}),{data:n}=Le(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(ur,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=Se();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:Ir(e,`replace`)?`replace`:Ir(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=Yr(m,`battery`),g=Ga(h),_=g===null?null:kr(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=Er(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(gt,{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:Kr({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=Yr(v,`consumables`),b=Pr(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=Fr(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=qr(y,e.key),r=n===null?Er(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=Rr.find(t=>t===e.target.value);t!==void 0&&h(t)},children:Rr.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(Ft,{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=Nr(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(Ge,{open:e,onOpenChange:e=>e?void 0:w(),children:r(me,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[d(Qe,{children:d(Ye,{children:t})}),r(se,{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(H,{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(kn,{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=zr(e);return Hr(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=zr(e);if(n.length===0)return!1;let{enabled:r,...i}=e,{enabled:a,...o}=sr({camera:t,sources:n,enabled:!0});return Jr(i,o)}function eo(e){return e?.enabled!==!1}function to(e,t,n){let r=[...e===null?[]:zr(e),...n.flatMap(e=>Xn(e.ref,e.caps))];return r.length===0?null:sr({camera:t,sources:r,enabled:eo(e)})}function no(e,t,n){let r=zr(e).filter(e=>K(e.source)!==n);return r.length===0?null:sr({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=Yr(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:Er(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&&Er(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(dt,{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:qn[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=ir.includes(e.type),[o,u]=l(!1),[f,p]=l(!1),[m,h]=l(null),g=en({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=_n(),x=Ha(a&&_.kind===`present`&&(o||y.length>0)),S=ot({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(kt,{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?`—`:Cn(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(Nt,{className:`h-4 w-4`})})}],N=T?M:M.filter(e=>e.key!==`tracked`);return r(s,{children:[d(Aa,{id:`linked`,icon:d(kt,{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(I,{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(dr));return vo([...e.map(_o),...t.filter(e=>!n.has(dr(e))).map(e=>({...e,mode:lr}))])}function bo(e,t,n){return vo(e.map(e=>dr(e)===t?{..._o(e),mode:n}:_o(e)))}function xo(e,t){return vo(e.filter(e=>dr(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=Tn(),[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(dr)),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,dr(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(Fe,{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=dr(e),n=Oo(e),r=e.state===`ready`?Pa(e.caps,`motion`):null,i=r===null?void 0:qn[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=fr.safeParse(e.target.value);n.success&&w!==null&&M(bo(w,t,n.data))},children:fr.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={"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`}},jo=new Set([q.Camera]);function Mo(e){return e.unitField===null?[e.fieldPath]:[e.fieldPath,e.unitField]}function No(e,t){if(jo.has(e))return{kind:`absent`};let n=null;for(let[e,r]of Object.entries(Ao))if(t.has(e)){n={cap:e,fieldPath:r.fieldPath,unitField:r.unitField};break}let r=null;for(let e of Qn)if(t.has(e)){let t=qn[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 Po(e){return er(e.from,e.to)?cr(e):null}function Fo(e){return Wn(e)}var Io=/^convert\(v,\s*"[^"]*",\s*"[^"]*"\)$/;function Lo(e){return e!==void 0&&Io.test(e.expr)}function Ro(e){return e===void 0||e.expr===`!v`||Io.test(e.expr)?!1:e.bindings.v!==void 0}function zo(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=Yn({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 Bo(e,t,n){if(e===null)return null;let r=Yr(e,n.cap);if(r===null)return e;let i=new Set(Mo(n)),a=Object.fromEntries(Object.entries(r.fields).filter(([e])=>!i.has(e)));return Object.keys(a).length===0?Er(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 Vo(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`unit`);return typeof t==`string`?t:void 0}function Ho(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 Uo(e,t){let n=Yr(e,t.cap);if(n===null)return;let r=n.fields[t.fieldPath];return r!==void 0&&r.kind===`expression`?r:void 0}function Wo(e,t){let n=Uo(e,t);return n===void 0||!Lo(n)?null:/^convert\(v,\s*"[^"]*",\s*"([^"]*)"\)$/.exec(n.expr)?.[1]??null}function Go(e,t){let n=Uo(e,t);return n===void 0||!Ro(n)?null:n.expr}function Ko(e,t,n){let r=Yr(e,t);if(r===null)return!1;let i=r.fields[n];return i!==void 0&&i.kind===`expression`&&i.expr===`!v`}function qo(e){return typeof e==`number`||typeof e==`boolean`||typeof e==`string`?String(e):e===null?`null`:JSON.stringify(e)}function Jo({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:No(e.type,h),_=g?.kind===`present`?g.convert?.cap??``:``,y=ut(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:Vo(y),w=C===void 0?void 0:rr(C)??C,T=w===void 0?void 0:Gn(w),E=x===null?null:Wo(b,x),D=x===null?null:Go(b,x),O=p??D??``,k=S===null?!1:Ko(b,S.cap,S.fieldPath),A=n.state.kind===`none`||n.state.kind===`present`,j=x===null?0:Ho(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:Br(M,new Map([[Zn(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=Po({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))},ee=async()=>{x!==null&&(await P(Bo(b,t,x)),f(``))},te=async()=>{if(x===null)return;let e=zo({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))},ne=async()=>{x!==null&&(await P(Bo(b,t,x)),m(``))},re=async()=>{if(S===null)return;let e=Fo({self:t,cap:S.cap});if(e===null){c(a(`customize.numericTransforms.invertRefused`));return}await P(Y(b,t,e))},ie=async()=>{S===null||b===null||await P(Er(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(wn,{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 ee(),children:a(`customize.numericTransforms.clearConvert`)})]})]}),x!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-script`,children:[d(Ur,{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:qo(j),result:qo(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 te(),children:a(`customize.numericTransforms.applyScript`)}),D!==null&&d(G,{size:`sm`,variant:`outline`,disabled:!A||n.saving,onClick:()=>void ne(),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 ie(),children:a(`customize.numericTransforms.clearInvert`)}):d(G,{size:`sm`,disabled:!A||n.saving,onClick:()=>void re(),children:a(`customize.numericTransforms.applyInvert`)})})]})]})]})}n();function Yo(e){return e instanceof Error?e.message:String(e)}function Xo(e){let n=Je({addonId:e.addonId,stableId:e.stableId}),r=ln(),i=M(),a=V(),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=jr(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:Yo(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 Zo=`pipeline-orchestrator`;function Qo(e){return e.status===`pending`?`pending`:e.status===`error`?`unknown`:e.data===void 0?`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function $o(e,t){return e===`absent`?`absent`:Qo(t)}async function es(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function ts(e,t){let n=Ie(Zo),r=ce({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>es(r.refetch);return t?{presence:$o(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,refetch:i}:{presence:`absent`,status:null,refetch:i}}function ns(e,t){let n=nt({deviceType:e.type}),r=jn({deviceId:e.id}),i=F({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 rs={kind:`unknown`,reason:`the composer reports no value for this field`};function is(e,t){let n=K(e);return t.get(n)??n}function as(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=Hr(e).map(e=>is(e,n.sourceNames)).join(` + `),a=i.find(e=>e.field===`lastPressedAt`);return[{key:`doorbell`,label:`doorbell`,origin:{kind:r,from:t},value:a?.value??rs}]}return e.cap===`consumables`?Pr(e).map(e=>{let t=t=>or(Kn,e.key,t),a=i.find(e=>e.field===t(`level`)||e.field===t(`remaining.value`)),o=e.source===null?``:is(e.source.source,n.sourceNames);return{key:`consumables.${e.key}`,label:`consumables · ${e.label}`,origin:{kind:r,from:o},value:a?.value??rs}}):i.map(e=>({key:e.key,label:`${e.cap}.${e.field}`,origin:{kind:r,from:e.from},value:e.value}))}function os(e){let t=Lr({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`?as(n,t,e):[])}function ss(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 cs=`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 ls({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`?os({composition:t,nativeCaps:i.value,state:n,sourceNames:l}):[],f=s&&i.kind===`known`&&u.length===0&&t.features.length>0,p=ss(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:cs,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(us,{value:e.value})})]},e.key)),p!==null&&r(`li`,{className:cs,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 us({value:e}){let{t}=J();switch(e.kind){case`value`:return r(`span`,{children:[Wr(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 ds({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=J(),i=L({deviceId:e}),a=i.data;return a==null?i.status===`error`?d(kn,{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(fs,{device:a}):d(ps,{device:a,target:{addonId:a.addonId,stableId:a.stableId},activeSubTab:t,onSubTabChange:n})}function fs({device:e}){let{t}=J(),n=e.stableId.startsWith(`composed-`)?e.stableId.slice(pr.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(gr,{className:`text-sm text-primary`,to:hr(n),children:t(`customize.composed.edit`)})]})}function ps({device:e,target:t,activeSubTab:n,onSubTabChange:i}){let a=Xo(t),o=Ie(`composer`),{t:s}=J(),c=ts(e.id,e.type===q.Camera),l=ns(e,sa(a.state)),u={deviceType:e.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},f=()=>i(Sr),p=a.state.kind===`none`||a.state.kind===`present`;return n===`advanced`?r(`div`,{className:`flex flex-col gap-4`,children:[d(hs,{state:a.state}),p&&d(ms,{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(hs,{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(Jo,{device:e,target:t,handle:a,facts:l}),d(ho,{device:e}),d(ls,{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(gs,{handle:a})]})]})}function ms({device:e,target:t,handle:n,facts:r,onDone:i}){let a=n.state.kind===`present`?n.state:null;return d(Gr,{initial:a===null?Dr(t):Or(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 hs({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(kn,{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(Kt,{variant:n.status===`running`?`success`:n.status===`failed`?`danger`:`warning`,children:t(`customize.blockStatus.${n.status}`)}),!n.enabled&&d(Kt,{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 gs({handle:e}){let{t}=J(),n=Se(),[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 _s=`overview`;function vs(e,t){return e.some(e=>e.id===t)?t:_s}function ys({deviceId:e}){let t=c(),n=Number.isFinite(e),{data:i}=L({deviceId:e},{enabled:n}),a=typeof i?.type==`string`?i.type:`camera`;un([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:s,isError:l,error:u}=jn({deviceId:e},{enabled:n}),{data:f}=be({deviceType:a},{enabled:!!a}),p=Jt({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(Rn,{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(I,{columns:[{key:`capability`,header:`Capability`,render:e=>d(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>d(bs,{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(xs,{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(Ss,{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 bs({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(Ve,{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(Hn,{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(kt,{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(Gt,{className:`h-3 w-3`}),`unbound`]})}function xs({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 Ss({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?Ct:b,{className:`h-3 w-3`}),e]},e)})})}function Cs({deviceId:e,activeSubTab:t,onSubTabChange:n,deviceType:i,isAdmin:a}){return r(`div`,{className:`flex flex-col gap-3`,children:[ti(i,a)&&d(rn,{deviceId:e,readOnly:!0}),d(ri,{deviceId:e,activeSubTab:t,onSubTabChange:n})]})}n();var ws=new Set([`package-detection`]);function Ts(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 Es(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function Ds({deviceId:e,refreshToken:t}){let n=c(),i=v().trpcClient,[u,f]=l(null),[p,m]=l(null),[h,g]=l(null),_=He({deviceId:e},{refetchOnMount:`always`}),y=We({deviceId:e},{refetchOnMount:`always`}),b=Me(void 0,{refetchOnMount:`always`});un([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:x}=et(),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=yt({onSuccess:O}),A=Et({onSuccess:O}),j=a(()=>E?re(E):[],[E]),M=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:Vn(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[b.data,D.data,S]),N=(e,t)=>D.data?.[e]?.find(e=>e.key===t)??null,P=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},F=(e,t,n)=>y.data?.[e]?.[t]?.[n]??null,ee=e=>{if(ws.has(e))return{kind:`zone-driven`};let t=Ts(E,e)?.enabledByDefault??!0,n=_.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},te=(e,t,n)=>{let r=Ts(T(n),e);if(r)return xn(r,t)},ne=(e,t)=>{let n=ee(e),r=n.kind===`gate`?n.effectiveOn:!1,i=Ts(T(t.agentNodeId),e),a=P(t),o=a===null?null:N(t.agentNodeId,a);if(!fn(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:F(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?Zt({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:Es(s)}},ie=u===null?null:Ts(T(u.agentNodeId),u.addonId),I=u?N(u.agentNodeId,u.deviceKey):null,L=I?.format??`coreml`,ae=u?Es(F(u.agentNodeId,u.deviceKey,u.addonId)):!1,oe=u?te(u.addonId,I,u.agentNodeId):void 0,R=a(()=>{if(!u||!I)return null;let e=I.steps?.[u.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[u,I]),z=()=>{f(null),m(null)},B=(e,t)=>{let n=P(t);n!==null&&(f({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),m(F(t.agentNodeId,n,e)))},se=(t,n)=>{A.mutate({deviceId:e,addonId:t,enabled:n})},ce=()=>{u&&k.mutate({deviceId:e,agentNodeId:u.agentNodeId,deviceKey:u.deviceKey,addonId:u.addonId,patch:p},{onSuccess:z})},le=()=>{u&&k.mutate({deviceId:e,agentNodeId:u.agentNodeId,deviceKey:u.deviceKey,addonId:u.addonId,patch:null},{onSuccess:z})};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(M.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 ue=u!==null&&ie!==null&&I!==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:ue?`md:pr-[360px]`:``,children:j.length>0?d(Oe,{tree:j,agents:M,gateFor:ee,getCellState:ne,onCellClick:B,selectedCell:u,onSetGate:se,gateBusy:A.isPending,fallbackNodeId:h,onFallbackNodeChange:g}):d(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),d(An,{open:ue,onClose:z,title:ie?.name??``,subtitle:u&&I?`${u.agentNodeId} · ${Vn(I).label} · ${I.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:!ae||k.isPending,onClick:le,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:z,children:`Cancel`}),d(`button`,{type:`button`,disabled:!u||!R||k.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:ce,children:k.isPending?`Saving…`:`Save`})]}),children:ie&&u&&R?d(wt,{mode:`device`,addon:ie,agentDefault:R,agentNodeId:u.agentNodeId,currentPatch:p,engineFormat:L,effectiveModelId:oe,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 Os=[{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`}],ks={"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 As(e){return ks[e]??`object-detection`}n();var js=`steps`,Ms=`settings`,Ns=new Set([js,Ms]);function Ps(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Fs({deviceId:t,activeSubTab:n,onSubTabChange:i}){return r(U,{value:n&&Ns.has(n)?n:js,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(Ae,{className:`flex-shrink-0`,children:[d(R,{value:js,children:`Steps`}),d(R,{value:Ms,children:`Settings`})]}),d(we,{value:js,children:d(Ds,{deviceId:t,refreshToken:0})}),d(we,{value:Ms,children:d(ri,{deviceId:t,sectionFilter:Ps,subTabGrouping:{groupOf:e=>As(e.id),tabs:Os}})})]})}n();function Is({deviceId:e}){let t=c(),{data:n}=Tr(e),{data:i}=wr(e),[a,o]=l(null),u=je({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=st(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(pn,{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 Ls=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Rs(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function zs(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Bs(){let e=Ee(),t=Bt(),{data:n}=L({deviceId:e??0},{enabled:e!==null}),{data:i}=jn({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(Vs,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),d(Vs,{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(Is,{deviceId:e}),d(Q,{label:`Type`,value:f}),d(Q,{label:`Provider`,value:d(zn,{type:p,size:`sm`,showLabel:!0})}),d(Q,{label:`Capabilities`,value:_.length>0?d(Un,{capabilities:_,showLabels:!0}):d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),b&&o===`hardware`&&d(Hs,{metadata:y})]})}function Vs({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 Hs({metadata:e}){let t=Ls.filter(t=>t in e),n=Object.keys(e).filter(e=>!Ls.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:Rs(t),value:d(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:zs(e[t])})},t))})]})}var Us=`Notifications`,Ws=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function Gs(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Us,on:r===null?null:i??r,available:r!==null,costWhenOff:Ws}}function Ks(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function qs(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Js({deviceId:t}){let n=c(),i=Number.isFinite(t),[a,o]=l(null),[s,u]=l(null),f=Gs({mutedDeviceIds:qs(yn({},{enabled:i}).data),deviceId:t,pendingOn:s}),p=pt({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=Ks(f,t);e!==null&&(u(!e.muted),p.mutate(e))},[t,p,f]),h=f.on===null,g=f.on===!1,_=g?Ut:dt;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 Ys(e,t){return{switchId:e,label:ar[e].label,detail:t===void 0||t.length===0?null:t}}function Xs(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 Zs(e){let t=Xs(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>Ys(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>Ys(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 Qs(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 $s({deviceId:e,deviceName:t}){let{t:n}=J(),i=Se(),[o,s]=l(null),c=Lt({isCamera:!0,projection:`slim`}),u=_e(),f=c.data!==void 0,p=a(()=>c.data===void 0?[]:Qs(c.data,e),[c.data,e]),m=p.find(e=>e.id===o)??null,h=u.data===void 0?null:Zs(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(ec,{report:h})]})}function ec({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($e,{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(qe,{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(Bn,{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 tc({deviceId:e}){let[t,n]=l(null),i=At({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(Ze,{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 nc=`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`,rc=0,ic=10;function ac(e){if(e.trim()===``)return``;let t=Number.parseInt(e,10);return Number.isFinite(t)?String(t<rc?rc:t>ic?ic:t):``}function oc({value:e,onChange:t,disabled:n=!1,placeholder:r,className:i,id:a,"aria-label":o}){return d(`input`,{type:`number`,min:rc,max:ic,step:1,id:a,className:i??nc,"aria-label":o,placeholder:r,value:e,onChange:e=>{t(ac(e.target.value))},disabled:n})}function sc({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(ge,{value:t===``?null:t,onPick:e=>o(e??``),resolveGlyph:Qt,fallbackGlyph:n,labels:c,disabled:a}),d(`span`,{className:`text-[11px] text-foreground-subtle`,children:t===``?i:t})]})}n();var cc=`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`,lc={icon:``,label:``,unit:``,precision:``,hidden:!1};function uc(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function dc(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function fc(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function pc(e,t){let n=fc(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 mc({deviceId:e}){let{t}=J(),n=v(),i=c(),{data:a}=L({deviceId:e},{enabled:e>0}),o=typeof a?.role==`string`&&a.role.length>0?a.role:null,u=o===null?void 0:bt[o],f=u?.kind===`numeric`,p=String(a?.type??``),m=o!==null||a?.parentDeviceId!==null&&a?.parentDeviceId!==void 0,h=ut(n.trpcClient,e,o??``),g=u?.kind===`numeric`?u.canonicalUnit:void 0,_=dc(h)??g,y=_===void 0?void 0:rr(_)??_,b=y===void 0?void 0:Gn(y),[x,S]=l(null),C=x??uc(a?.display),w=pe({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:T}=zt({},{staleTime:6e4,enabled:o!==null}),E=St({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(a==null)return null;let D=e=>{S({...C,...e})},O=()=>{w.mutate({deviceId:e,display:pc(C,a.display)})},A=()=>{S(lc),w.mutate({deviceId:e,display:null})},j=()=>{if(o===null)return;let e=fc(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:Qt(M),P=o===null?Cn(p):k(o),F={icon:N??P.icon,label:N===void 0?P.label:String(M)},ee=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}),te=typeof a.name==`string`?a.name:`#${String(e)}`,ne=o===null?``:k(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(sc,{deviceName:te,value:C.icon,inheritedIcon:F.icon,inheritedLabel:ee,disabled:w.isPending,onChange:e=>D({icon:e})})}),m&&d(Q,{label:t(`deviceDisplay.label`),value:d(`input`,{type:`text`,className:cc,"aria-label":t(`deviceDisplay.label`),placeholder:o===null?te:ne,value:C.label,onChange:e=>D({label:e.target.value})})}),f&&r(s,{children:[d(Q,{label:t(`deviceDisplay.unit`),value:d(wn,{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(oc,{"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:ne}),children:t(`deviceDisplay.setRoleDefault`,{role:ne})})]})]})}function hc(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function gc({device:e}){let t=_r(),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(Jn.Resyncable),{data:l}=Sn({deviceId:n??0},{enabled:n!==null&&a,refetchInterval:5e3}),u=l?.streams??{},f=Object.entries(u),p=s.includes(Jn.DoorbellButton),m=Mt(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(Ce,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&d(tc,{deviceId:n}),a&&n!==null&&d($s,{deviceId:n,deviceName:String(e.name??``)}),n!==null&&d(Js,{deviceId:n}),a&&n!==null&&d(vt,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),p&&d(ye,{history:m.history,latestIsFresh:h}),a&&n!==null&&d(vt,{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(vn,{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(_c,{label:`Nominal`,value:hc(t.nominalBitrateKbps??0)}),d(_c,{label:`Observed`,value:hc(t.observedBitrateKbps??0)}),d(_c,{label:`Peak`,value:hc(t.peakBitrateKbps??0)}),d(_c,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),d(Bs,{}),n!==null&&d(mc,{deviceId:n})]})}function _c({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 vc=[{id:`overview`,label:`Overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1,adminOnly:!1},{id:xr,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 yc(e,t){let n=e===q.Camera;return vc.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)).map(({id:e,label:t})=>({id:e,label:t}))}function bc({provider:e,integrationId:t,name:n}){let r=_r(),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(zn,{type:e,size:`lg`})})}n();var xc=[{id:`logs`,icon:ze,label:`Logs`},{id:`repl`,icon:vr,label:`REPL`},{id:`events`,icon:gn,label:`Events`},{id:`state`,icon:Pe,label:`State`}];function Sc(){let n=br(),i=Number(n.deviceId),o=Number.isFinite(i),u=_r(),f=c(),p=Se(),h=v(),{user:g}=Cr(),_=g?.isAdmin===!0,[y,b]=yr(),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}),M=t(k);M.current=k;function P(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=M.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:F,isLoading:re,isError:I}=L({deviceId:i},{enabled:o,refetchInterval:5e3,retry:1}),{data:oe}=Te({deviceId:i},{enabled:o}),R=a(()=>{let e=oe?.settings?.sections??[],t=oe?.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:nr[e]?.label??e,isAddonContrib:!0})},[oe]),z=F,B=String(z?.name??n.deviceId??`Device`),se=z?.online===!0,ce=se?`online`:`offline`,le=String(z?.addonId??`rtsp`),V=z?.features??[],H=z?.type,pe=H===q.Camera,{data:me}=wr(o?i:0),he=H===q.Container,ge=a(()=>(me??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[me]),_e=a(()=>he?st(ge,typeof z?.linkDeviceId==`number`?z.linkDeviceId:null,typeof z?.primaryChildEntityId==`string`?z.primaryChildEntityId:null)?.id??null:null,[he,ge,z?.linkDeviceId,z?.primaryChildEntityId]),{data:ve}=Te({deviceId:_e??0},{enabled:_e!==null}),ye=a(()=>{if(_e===null)return[];let e=ve?.settings?.sections??[],t=ve?.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:nr[e]?.label??e,isAddonContrib:!0,childDeviceId:_e}))},[_e,ve]),be=typeof z?.parentDeviceId==`number`?z.parentDeviceId:null,{data:xe}=L({deviceId:be??0},{enabled:be!==null}),U=ne(),Ce=z?.disabled!==!0,we=a(()=>{let e=new Set,t=[];for(let n of[...yc(H,_),...R,...ye])e.has(n.id)||(e.add(n.id),t.push(n));return t},[H,_,R,ye]),Ee=a(()=>vs(we,x),[we,x]),Oe=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]),Ae=e(e=>{b(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[b]),je=(me??[]).length>0,Me=a(()=>xc.filter(({featureGate:e})=>!e||V.includes(e)),[V]),{data:Ne}=Le(void 0),Pe=a(()=>z?Be(z,Ne):null,[z,Ne]),W=Pe?.kind===`resolved`?Pe.integration:null,Fe=W===null?Pe?.kind===`unknown`?`Loading integration…`:Pe?.kind===`orphan`?`Missing integration`:`No integration`:W.name,Ie=W!==null&&W.addonId===le?W.name:le,Re=te({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),u(W?.id?`/integrations/${W.id}`:`/integrations`)}}),ze=ie({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ve=On({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),He=ke(),Ue=mt({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),We=V.includes(Jn.Rebootable),Ge=V.includes(Jn.BatteryOperated),Ke=sn(h.trpcClient,Ge&&o?i:null),qe=fe(h.trpcClient,o?i:null),[Je,Ye]=l(!1),Xe=async()=>{if(!Je){Ye(!0);try{let e=B.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await Xr(`${m}/${String(i)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Ye(!1)}}},Qe=ze.isPending||Ve.isPending,{data:$e}=de({deviceId:i},{enabled:o,refetchInterval:1e4}),et=$e?.agentNodeId??null,tt=typeof et==`string`&&et.length>0&&!et.startsWith(`addon:`)?et:void 0,{data:nt}=Fn({deviceId:i,...tt?{nodeId:tt}:{}},{enabled:o,refetchInterval:3e3,retry:!1}),{data:rt}=Mn({deviceId:i},{enabled:o,refetchInterval:3e3,retry:!1}),it=rt?.level?.dbfs??null;function at(){if(!o)return null;switch(Ee){case`overview`:return d(gc,{device:z??{}});case`config`:return d(Cs,{deviceId:i,activeSubTab:S,onSubTabChange:Ae,deviceType:H,isAdmin:_});case`detection-pipeline`:return d(Fs,{deviceId:i,activeSubTab:S,onSubTabChange:Ae});case`bindings`:return d(ys,{deviceId:i});case xr:return d(ds,{deviceId:i,activeSubTab:S,onSubTabChange:Ae});default:{let e=Ee,t=R.some(t=>t.id===e),n=ye.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:Ae});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:Ae});return n!==void 0&&r!==i?d(ae,{deviceId:r,children:a}):a}}}return o?re?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`})})]}):I||!F?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(De,{items:[{label:`Integrations`,onClick:()=>u(`/integrations`)},W===null?{label:Fe}:{label:Fe,onClick:()=>u(`/integrations/${W.id}`)},{label:B}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[W!==null&&d(bc,{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:B}),d(Zr,{status:ce}),Ge&&d(ee,{status:Ke,variant:`full`}),d(Vt,{status:qe})]}),be!==null&&xe&&r(`button`,{type:`button`,onClick:()=>u(`/devices/${be}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${xe.name}`,children:[d(`span`,{children:`↑`}),d(`span`,{className:`truncate`,children:String(xe.name??`Device #${be}`)})]}),d(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:V.length>0&&d(Un,{capabilities:V})})]}),nt&&d(`div`,{className:`hidden lg:flex`,children:d(Cc,{metrics:nt,dbfs:it})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{Ce?await p({title:`Disable "${B}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Ve.mutate({deviceId:i}):ze.mutate({deviceId:i})},disabled:Qe,title:Ce?`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 ${Ce?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[d(j,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:Qe?`Updating…`:Ce?`Enabled`:`Disabled`})]}),d(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),pe&&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(N,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:D,disabled:Je,onClick:()=>{Xe()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:ue,hidden:!We,disabled:He.isPending,danger:!0,onClick:async()=>{await p({title:`Reboot "${B}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&He.mutate({deviceId:i})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${Ie}.`,icon:Ze,disabled:Ue.isPending,danger:!0,onClick:async()=>{await p({title:`Restart "${Ie}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${B}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Ue.mutate({addonId:le})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:w,separatorBefore:!0,disabled:Re.isPending,danger:!0,onClick:async()=>{await p({title:`Delete "${B}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Re.mutate({deviceId:i})}}]})]})]})]}),d(ae,{deviceId:i,device:z??void 0,children:d(Ot,{children:d(Tt,{children:d(T,{children:d(Ht,{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:pe?`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:pe?d(Yi,{deviceId:i,intercomAvailable:V.includes(Jn.TwoWayAudio)}):d(zi,{deviceId:i,deviceName:B,deviceType:H??`unknown`,provider:le,isOnline:se,features:V})}),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:Me.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:H===`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:P,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:we.map(e=>{let t=Ee===e.id;return r(`button`,{onClick:()=>Oe(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:[Ee===`overview`&&je&&d(gi,{parentDeviceId:i}),at()]})]})]})})})})})})]}):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 Cc({metrics:e,dbfs:t}){let n=lt(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(Fe,{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(In,{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(_t,{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{Sc as DeviceDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,o as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as o,vt as s}from"./player-overlays-
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,o as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as o,vt as s}from"./player-overlays-Cfcp6NgQ.js";import{B as c,Bi as l,Ci as u,Ta as d,ji as f,r as p,vi as m,yl as h,z as g}from"./src-BeGnyQUE.js";import{t as _}from"./ProviderIcon-ZrL8hgOi.js";import{f as v,l as y}from"./index-M74_weOu.js";import{t as b}from"./AdminPage-CiKtOLQm.js";import"./useEventInvalidation-DPwzQ8Dt.js";import{t as x}from"./device-integration-icon-DepzDzE0.js";t();var S=32;function C(e,t){let n=e=>t(e).kind===`orphan`,r=new Set;for(let t of e)n(t)&&r.add(t.id);let i=new Map;for(let t of e)i.set(t.id,t);let a=(e,t=0)=>{if(t>S)return!1;if(r.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let n=i.get(e.parentDeviceId);return n?a(n,t+1):!1},o=[],s=[];for(let t of e)a(t)?s.push(t):o.push(t);return{activeDevices:o,orphanDevices:s}}function w(){let{t}=y(),S=v(),w=o(),T=i();p([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),p([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:E}=f({projection:`slim`}),{data:D}=d(void 0),O=l({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),k=m({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=u({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),j=r(()=>E??[],[E]),M=r(()=>c(D),[D]),{activeDevices:N,orphanDevices:P}=r(()=>C(j,M),[j,M]),F=r(()=>{let e=new Map;for(let t of j)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[j]),I=e(e=>F.get(e)??null,[F]),L=r(()=>(D??[]).map(e=>({id:e.id,name:e.name??e.addonId,icon:a(_,{type:e.addonId,size:`sm`})})),[D]),R=e(e=>S(`/devices/${String(e)}`),[S]);return n(b,{icon:s,title:t(`nav.devices`,`Devices`),children:[a(g,{context:`devices`,devices:N,trpc:w.trpcClient,filters:{integrations:L},integrationOf:M,resolveIntegrationIcon:x,resolveParent:I,onNavigate:R,batchActions:{remove:O.mutate,disable:k.mutate,enable:A.mutate}}),P.length>0&&n(`div`,{className:`mt-6 space-y-2`,children:[n(`div`,{className:`flex items-baseline gap-2`,children:[a(h,{className:`h-3.5 w-3.5 text-warning shrink-0`}),a(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Orphan devices`}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[P.length,` device`,P.length===1?``:`s`,` pointing at integrations no longer registered`]})]}),n(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:"These devices reference an integration that is no longer registered (their `integrationId`, or — for older devices without one — their `addonId`). Delete them, or re-install the missing integration to bring them back online. The provider badge beside each row is the addon that serves it."}),a(g,{context:`devices`,devices:P,trpc:w.trpcClient,integrationOf:M,urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:x,resolveParent:I,onNavigate:R})]})]})]})}export{w as DevicesPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,d as r,q as i,u as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{rt as c}from"./player-overlays-
|
|
1
|
+
import{Q as e,S as t,W as n,d as r,q as i,u as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{rt as c}from"./player-overlays-Cfcp6NgQ.js";import{Dt as l,a as u,ht as d,nl as f,yt as p}from"./src-BeGnyQUE.js";import{pr as m}from"./src-BQHqLKGc.js";import{D as h,M as g,O as _,P as v,T as y,y as b}from"./__vite-browser-external-Cc3gW-QT.js";e();var x=v([_({kind:y(`adaptive`)}),_({kind:y(`profile`),profile:m})]),S=_({serverUrl:g().min(1),token:g().min(1),deviceId:h().int().nonnegative(),target:x,muted:b()});function C(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function w(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function T(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function E(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function D(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=S.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function O({message:e}){return s(()=>{C(`error`,e)},[e]),t(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[`Embed config error: `,e]})}function k({system:e,deviceId:t,initialTarget:r,initialMuted:a}){let[c,d]=i(r),[f,p]=i(a),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y,getSessionDebug:b}=u(e.trpcClient,t),S=n(()=>T(c),[c]),D=n(()=>(e,t)=>m(S,e,t),[m,S]),O=n(()=>(e,t,n)=>m(n,t,e),[m]);s(()=>(window.__camstackEmbed={setMuted:e=>p(e),setTarget:e=>{let t=x.safeParse(e);t.success&&d(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let k=E(c);return o(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:o(l,{serverUrl:e.serverUrl,streamKey:k,autoPlay:!0,muted:f,showControls:!1,className:`w-full h-full`,getSessionDebug:b,handleOffer:D,reoffer:O,getSessionState:y,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,onStateChange:e=>C(w(e)),onError:e=>C(`error`,e)},k)})}function A(){let e=n(()=>D(),[]),t=n(()=>{if(!e.ok)return null;let t=p({serverUrl:e.config.serverUrl,token:e.config.token}),n=new r({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}});return d(n),{system:t,queryClient:n}},[e]);return s(()=>{if(t)return()=>{t.system.close()}},[t]),e.ok?t?o(c,{system:t.system,children:o(a,{client:t.queryClient,children:o(f.Provider,{client:t.system.trpcClient,queryClient:t.queryClient,children:o(k,{system:t.system,deviceId:e.config.deviceId,initialTarget:e.config.target,initialMuted:e.config.muted})})})}):o(O,{message:`Failed to initialise the embed player`}):o(O,{message:e.error})}export{A as EmbedPlayerPage};
|