@camstack/addon-admin-ui 1.2.513 → 1.2.515
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/CHANGELOG.md +16 -0
- package/dist/assets/{AddonAssetIcon-BXUI3-Tf.js → AddonAssetIcon-CBiyVWSK.js} +1 -1
- package/dist/assets/{Addons-BbTJ2Fig.js → Addons-BYYIoFw9.js} +1 -1
- package/dist/assets/{AdminPage-DUSx45NB.js → AdminPage-B_wUVHLs.js} +1 -1
- package/dist/assets/{AdminSectionedPage-soMjTdb7.js → AdminSectionedPage-bjMTXExV.js} +1 -1
- package/dist/assets/{AiProfiles-Z0lIY6qW.js → AiProfiles-Dp3jiABg.js} +1 -1
- package/dist/assets/{BrokerEditorDialog-61ZhKBtB.js → BrokerEditorDialog-DPVRE7-s.js} +1 -1
- package/dist/assets/{Build-DYS91I2j.js → Build-C-tGTJ6v.js} +3 -3
- package/dist/assets/{Calendars-B70yeC96.js → Calendars-wYE1IQBj.js} +1 -1
- package/dist/assets/{Cluster-MhCZmNm6.js → Cluster-DaviTht0.js} +1 -1
- package/dist/assets/ComposedDeviceEditDialog-CymtiQhN.js +1 -0
- package/dist/assets/CompositionBlockEditor-Bgk7i1Ug.js +2 -0
- package/dist/assets/{CompositionEditorPage-BI-Y8v0_.js → CompositionEditorPage-Bp0gwdfh.js} +1 -1
- package/dist/assets/{Data-B-pDPXqV.js → Data-Cgf6SD1c.js} +1 -1
- package/dist/assets/DeviceDetail-B5bgKOno.js +2 -0
- package/dist/assets/{DeviceDoActionFields-3YdRpdH5.js → DeviceDoActionFields-BKIcUinN.js} +1 -1
- package/dist/assets/{Devices-D38AMunx.js → Devices-DtwfpOJe.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-BBZB_KmG.js → EmbedPlayerPage-C0JL6O13.js} +1 -1
- package/dist/assets/{History-v659n-q1.js → History-0nvSdtVT.js} +1 -1
- package/dist/assets/{Identity-Dtc3gsXQ.js → Identity-B9Ly0pEQ.js} +1 -1
- package/dist/assets/{IntegrationDetail-X94WkFek.js → IntegrationDetail-C7nPuXa_.js} +1 -1
- package/dist/assets/{IntegrationHub-CUAqtcr0.js → IntegrationHub-BdTFw8jM.js} +1 -1
- package/dist/assets/{Integrations-BlD0JmVC.js → Integrations-DuajWOh1.js} +1 -1
- package/dist/assets/{Integrations-C-JT0QSz.js → Integrations-PJkA_opy.js} +1 -1
- package/dist/assets/{Library-BrvU57J_.js → Library-fp_epw-B.js} +1 -1
- package/dist/assets/{Locations-BXbmZQwL.js → Locations-DbGCMvY_.js} +1 -1
- package/dist/assets/{Logs-B0XBZZ8Q.js → Logs-BsejI0N_.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-DnEx9aLt.js → MaskShapeCanvas-CCcjwlTm.js} +1 -1
- package/dist/assets/{MotionZonesSettings-BMDPF6-L.js → MotionZonesSettings-15VWTACI.js} +1 -1
- package/dist/assets/{MyAccess-DfkZc8jj.js → MyAccess-BybIWHCc.js} +1 -1
- package/dist/assets/{Network-B9UvgIh-.js → Network-DDhjZ0n2.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-D8UZOHme.js → NodeAddonsSettingsPanel-Cj9J3VCz.js} +1 -1
- package/dist/assets/{Notifications-2R56_ebY.js → Notifications-CxzR6VyG.js} +1 -1
- package/dist/assets/{Pipeline-BdjiguQv.js → Pipeline-DApdVNZ-.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DXcb1Xsj.js → PrivacyMaskSettings-boU8xnXR.js} +1 -1
- package/dist/assets/{Recordings-BnGaDgIg.js → Recordings-BgaF6LHi.js} +1 -1
- package/dist/assets/{RemoteGrid-C_hwBm7-.js → RemoteGrid-HppYsb5t.js} +1 -1
- package/dist/assets/{ScanNetworkModal-BTQIrvGc.js → ScanNetworkModal-C44T3xR0.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-BeZzFwDE.js → SceneMonitorEditor-DbEDdw8n.js} +1 -1
- package/dist/assets/{SessionsList-C03j936p.js → SessionsList-DyX_VF8l.js} +1 -1
- package/dist/assets/{Showroom-hqqCXmrT.js → Showroom-B5qRvr4H.js} +1 -1
- package/dist/assets/{System-C9oV_d1y.js → System-DlY0oaGn.js} +1 -1
- package/dist/assets/{Templates-cp28J05t.js → Templates-lCo5yN4g.js} +1 -1
- package/dist/assets/{Terminal-C2kXj9wO.js → Terminal-qRe7fRtd.js} +1 -1
- package/dist/assets/{Viewer-zU0ym-3m.js → Viewer-BFtLOgb5.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-RW_iqTJh.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Dd1lnVnV.js} +1 -1
- package/dist/assets/{addon-icons-context-Dvq70FHG.js → addon-icons-context-BqCF3aDM.js} +1 -1
- package/dist/assets/{archive-DEQjGSlb.js → archive-COJvuz8j.js} +1 -1
- package/dist/assets/{assignment-candidates-CYEy8Oew.js → assignment-candidates-WjzzD3xR.js} +1 -1
- package/dist/assets/{authed-media-ei7XgIJl.js → authed-media-CPH4gDSb.js} +1 -1
- package/dist/assets/{bell-off-BtOUApIg.js → bell-off-CEHvcpV8.js} +1 -1
- package/dist/assets/{board-model-uN4dojCw.js → board-model-BkMxMFGJ.js} +1 -1
- package/dist/assets/{boxes-vYLDJNRv.js → boxes-C0Z7cB0S.js} +1 -1
- package/dist/assets/circle-slash-BY9zkWdJ.js +1 -0
- package/dist/assets/client-BjsFVjEa.js +674 -0
- package/dist/assets/{cloud-upload-CzsF_jzI.js → cloud-upload-yzPIJtWW.js} +1 -1
- package/dist/assets/crop-DpfML6TR.js +1 -0
- package/dist/assets/{device-integration-icon-CMOElaCq.js → device-integration-icon-Bo_gTwOD.js} +1 -1
- package/dist/assets/device-picker-model-C9XdDI0R.js +1 -0
- package/dist/assets/{dist-ODNaReOx.js → dist-D7eSjbBx.js} +1 -1
- package/dist/assets/dist-DuYXDhcZ.js +674 -0
- package/dist/assets/{eraser-DdxDfnsw.js → eraser-CcAxRsoL.js} +1 -1
- package/dist/assets/{file-up-DtWjJzxE.js → file-up-gEH5fPam.js} +1 -1
- package/dist/assets/{hard-drive-download-BUYTmxO8.js → hard-drive-download-CwO_DU-K.js} +1 -1
- package/dist/assets/{hostInit-CEmOeO-p.js → hostInit-BonUhoQT.js} +1 -1
- package/dist/assets/i18n-ZdV8UiYr.js +1 -0
- package/dist/assets/{icons-BS95Q050.js → icons-l5aYjks5.js} +1 -1
- package/dist/assets/{index-CUQ_1-3M.js → index-CuSxNbC8.js} +3 -3
- package/dist/assets/{key-BHqMlU3n.js → key-03tb4am1.js} +1 -1
- package/dist/assets/{key-round-DEGX9D7v.js → key-round-CxRbUD09.js} +1 -1
- package/dist/assets/{layers-CmVPxgW7.js → layers-B_aq5GyC.js} +1 -1
- package/dist/assets/{linked-devices-model-9YMVfHc9.js → linked-devices-model-DO7_gXoE.js} +1 -1
- package/dist/assets/{list-ordered-CheGo-ag.js → list-ordered-BIOnBH5V.js} +1 -1
- package/dist/assets/{location-owned-usage-CkEO8Lym.js → location-owned-usage-CYNROgPA.js} +1 -1
- package/dist/assets/{log-in-CiEueJS1.js → log-in-DYRRiyUu.js} +1 -1
- package/dist/assets/{memory-stick-BR7h-gLy.js → memory-stick-BTjX5XXU.js} +1 -1
- package/dist/assets/{message-square-plus-pFenYopk.js → message-square-plus-CYHn2tx1.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-f252a886.js → mf-entry-bootstrap-0-2f0f55bc.js} +2 -2
- package/dist/assets/{mic-off-Cy2vjOdb.js → mic-off-BfWqJn2R.js} +1 -1
- package/dist/assets/{monitor-off-DSnpgX4h.js → monitor-off-Dy7WsqTN.js} +1 -1
- package/dist/assets/{monitor-smartphone-Bbz5EYKE.js → monitor-smartphone-Cl-w7Gs0.js} +1 -1
- package/dist/assets/mount-C9XdDI0R.js +1 -0
- package/dist/assets/{player-overlays-CeCeKlFy.js → player-overlays-DaSesfVn.js} +1 -1
- package/dist/assets/{recycle-CRCqoNuC.js → recycle-CC6kU24N.js} +1 -1
- package/dist/assets/remoteEntry-C7WJfwvN.js +1 -0
- package/dist/assets/{ruler-D4nA2AkO.js → ruler-C6bIqLbX.js} +1 -1
- package/dist/assets/{scan-eye-B6ToEyNT.js → scan-eye-BbYgoJiK.js} +1 -1
- package/dist/assets/{scissors-Cy9qo-01.js → scissors-oYo-ZhBm.js} +1 -1
- package/dist/assets/{search-x-Bc6YoEgC.js → search-x-CySi2ygd.js} +1 -1
- package/dist/assets/{send-C88bJpzN.js → send-FMXSDirA.js} +1 -1
- package/dist/assets/{settings-2-CT7EhY20.js → settings-2-WfXnibr2.js} +1 -1
- package/dist/assets/{shapes-D49xx3pl.js → shapes-JaoPTvAm.js} +1 -1
- package/dist/assets/{sigma-r_LYWpZC.js → sigma-C2um2nX9.js} +1 -1
- package/dist/assets/{speaker-Ki0ZHj9k.js → speaker-DVh7yO4_.js} +1 -1
- package/dist/assets/{src-Cq4wbXVd.js → src-DxOL9qHw.js} +3 -3
- package/dist/assets/{step-inspector-model-DybV6iGj.js → step-inspector-model-Xr3EG73i.js} +1 -1
- package/dist/assets/{table-2-BCrCvQBE.js → table-2-BzvZ1C8Y.js} +1 -1
- package/dist/assets/{timer-reset-BCU9mQbt.js → timer-reset-BFyZoIS7.js} +1 -1
- package/dist/assets/{unlink-Bdf-2hM2.js → unlink-Bf6pcFmm.js} +1 -1
- package/dist/assets/{usb-Dk1-9w-h.js → usb-oSHxCOV9.js} +1 -1
- package/dist/assets/{use-scenes-feed-kuO8vvaU.js → use-scenes-feed-DrR6sBRO.js} +1 -1
- package/dist/assets/{use-stationary-objects-h9zEu1aK.js → use-stationary-objects-DVmg7h4R.js} +1 -1
- package/dist/assets/useEventInvalidation-C9XdDI0R.js +1 -0
- package/dist/assets/{useNodeUrlSelection-DxKAfF2w.js → useNodeUrlSelection-CikIoR0h.js} +1 -1
- package/dist/assets/user-round-BZHQXbgV.js +1 -0
- package/dist/assets/{user-x-Ci81AHsS.js → user-x-aU8InWh0.js} +1 -1
- package/dist/assets/{variable-6lR9ETRn.js → variable-DwONvC9h.js} +1 -1
- package/dist/assets/{video-BSJxItXj.js → video-DOy8UceJ.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CCXtVAMI.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DXQ8OkGD.js} +2 -2
- package/dist/index.html +9 -9
- package/dist/server/addon.js +2 -2
- package/package.json +1 -1
- package/dist/assets/CompositionBlockEditor-TlnzLRS-.js +0 -1
- package/dist/assets/DeviceDetail-BejggRfL.js +0 -2
- package/dist/assets/HelperWizard-B_3MTQzU.js +0 -2
- package/dist/assets/automation-data-E3BGzBLE.js +0 -1
- package/dist/assets/circle-slash-DG3-Ibc_.js +0 -1
- package/dist/assets/client-gOfL8FDq.js +0 -674
- package/dist/assets/crop-BYOsBPcF.js +0 -1
- package/dist/assets/device-picker-model-CtJOP06v.js +0 -1
- package/dist/assets/dist-BIFugJlu.js +0 -674
- package/dist/assets/i18n-CtSKEBgX.js +0 -1
- package/dist/assets/mount-CtJOP06v.js +0 -1
- package/dist/assets/remoteEntry-DHoKCa7I.js +0 -1
- package/dist/assets/useEventInvalidation-CtJOP06v.js +0 -1
- package/dist/assets/user-round-ucYAzmFE.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{D as f,Dn as p,En as m,Fr as h,G as g,Gn as _,Gr as v,Ht as y,In as b,J as x,K as S,Kr as C,Mn as w,Ni as T,O as E,Oi as D,Ot as O,Qn as k,St as A,Tn as j,Ui as M,V as ee,Vn as N,W as te,Wi as ne,Z as re,Zn as P,_n as ie,bt as F,dt as I,ei as ae,er as oe,fr as se,gt as ce,hi as L,hr as R,kr as z,lr as le,mr as ue,ni as de,nr as B,on as fe,pa as pe,q as me,r as he,rn as ge,sa as _e,sr as ve,st as ye,t as be,ur as xe,wn as Se,yi as V,yn as Ce,z as H}from"./player-overlays-DaSesfVn.js";import{Bn as we,Ca as U,Cr as Te,Hn as Ee,Ii as De,Jt as Oe,Ki as ke,Qi as Ae,Qt as je,Sa as W,Sr as Me,Ti as G,Vn as Ne,Xn as Pe,Xt as Fe,Yt as Ie,Zt as Le,ar as Re,f as ze,ir as Be,ji as Ve,mi as He,n as Ue,oo as We,qt as Ge,ro as Ke,si as qe,so as Je,xa as Ye,ya as Xe,yr as Ze,zi as Qe,zn as $e}from"./client-BjsFVjEa.js";import{t as et}from"./archive-COJvuz8j.js";import{i as tt,n as nt,r as rt,t as it}from"./scan-eye-BbYgoJiK.js";import{t as at}from"./bell-off-CEHvcpV8.js";import{r as ot,t as st}from"./sigma-C2um2nX9.js";import{t as ct}from"./boxes-C0Z7cB0S.js";import{n as lt}from"./video-DOy8UceJ.js";import{t as ut}from"./circle-slash-BY9zkWdJ.js";import{t as dt}from"./file-up-gEH5fPam.js";import{t as ft}from"./layers-B_aq5GyC.js";import{$l as pt,$n as mt,An as ht,Ao as gt,Ar as K,B as _t,Ba as vt,Bo as yt,Br as bt,Bt as xt,Cn as St,Cr as Ct,Ct as wt,Dl as Tt,Dn as Et,Dr as Dt,El as Ot,En as kt,Er as At,Fd as jt,Fn as Mt,Fs as Nt,Ft as Pt,Ga as Ft,Gi as It,Gn as Lt,Gt as Rt,Hd as zt,Hr as Bt,Ht as Vt,In as Ht,Is as Ut,It as Wt,Jc as Gt,Jn as Kt,Kn as qt,Kr as Jt,Kt as Yt,Ld as Xt,Ln as Zt,Lo as Qt,Ls as $t,Lt as en,Md as tn,Mo as nn,Mr as rn,Nd as an,No as on,Nt as sn,Ol as cn,Oo as ln,Pd as un,Po as dn,Q as fn,Qa as pn,Qn as mn,Qt as hn,R as gn,Rl as _n,Rn as vn,Rr as yn,Si as bn,Sr as xn,Td as Sn,Ti as Cn,Tl as wn,Tn,To as En,Tt as Dn,Un as On,Uo as kn,Ut as An,Va as jn,Vr as Mn,Wa as Nn,Wd as Pn,Wn as Fn,Wu as In,Xd as Ln,Xt as Rn,Yd as zn,Yt as Bn,Z as Vn,Zr as Hn,Zt as Un,_r as Wn,a as Gn,an as Kn,ao as qn,as as Jn,at as Yn,bi as Xn,bn as Zn,br as Qn,c as $n,ci as q,ct as er,cu as tr,d as nr,di as rr,du as ir,ei as J,eo as ar,gr as or,hl as sr,ho as cr,hr as lr,i as ur,il as dr,in as fr,io as pr,it as mr,jc as hr,jd as gr,jo as _r,js as vr,jt as yr,kc as br,kl as xr,ko as Sr,lc as Cr,ls as wr,lu as Tr,nl as Er,nt as Dr,o as Or,ol as kr,ot as Ar,pn as jr,qa as Mr,qd as Nr,qn as Pr,qt as Fr,r as Ir,rl as Lr,rn as Rr,ro as zr,rs as Br,sa as Vr,st as Hr,to as Ur,tt as Wr,uc as Gr,ui as Kr,ul as qr,uu as Jr,vi as Yr,vr as Xr,wo as Zr,wr as Qr,wt as $r,xc as ei,xi as ti,xr as ni,xt as ri,yo as ii,yr as ai,zr as oi,zt as si}from"./src-DxOL9qHw.js";import{t as Y}from"./i18n-ZdV8UiYr.js";import{t as X}from"./useTranslation-BJr-n0es.js";import"./mount-C9XdDI0R.js";import{A as ci,C as li,M as ui,N as di,P as fi,_r as pi,ar as mi,cr as hi,dr as gi,fr as _i,ir as vi,j as yi,k as bi,lr as xi,mr as Si,or as Ci,p as wi,pr as Ti,rr as Ei,sr as Di,ur as Z,vr as Oi,yr as ki}from"./index-CuSxNbC8.js";import{i as Ai,r as ji}from"./DeviceDoActionFields-BKIcUinN.js";import{a as Mi,r as Ni,t as Pi}from"./ComposedDeviceEditDialog-CymtiQhN.js";import{A as Fi,B as Ii,C as Li,D as Ri,E as zi,F as Bi,G as Vi,H as Hi,J as Ui,K as Wi,L as Gi,M as Ki,N as qi,O as Ji,P as Yi,R as Xi,S as Zi,T as Qi,U as $i,V as ea,W as ta,X as na,Y as ra,_ as ia,a as aa,b as oa,c as sa,d as ca,g as la,i as ua,j as da,k as fa,l as pa,m as ma,o as ha,p as ga,q as _a,r as va,s as ya,u as ba,v as xa,w as Sa,x as Ca,y as wa,z as Ta}from"./CompositionBlockEditor-Bgk7i1Ug.js";import{r as Ea,t as Da}from"./assignment-candidates-WjzzD3xR.js";import{_ as Oa,b as ka,i as Aa,m as ja,o as Ma,t as Na}from"./step-inspector-model-Xr3EG73i.js";import"./useEventInvalidation-C9XdDI0R.js";import{t as Pa}from"./use-stationary-objects-DVmg7h4R.js";import{a as Fa,i as Ia,n as La,o as Ra,r as za,s as Ba,t as Va}from"./linked-devices-model-DO7_gXoE.js";import{l as Ha,o as Ua,t as Wa}from"./RemoteGrid-HppYsb5t.js";import{t as Ga}from"./authed-media-CPH4gDSb.js";c();function Ka(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 qa(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(Ka).filter(e=>e!==null);return n.length===0?null:n}var Ja=[[/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 Ya(e){for(let[t,n]of Ja)if(t.test(e))return n;return`generic`}function Xa(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(Y.t(`helpers.cameraSwitchRows.off`,{list:r(t)})),n.length>0&&i.push(Y.t(`helpers.cameraSwitchRows.unknown`,{list:r(n)})),{offIds:t,unknownIds:n,summary:i.length===0?Y.t(`helpers.cameraSwitchRows.allOn`):i.join(` · `)}}var Za={stream:p,detection:it,privacy:v,microphone:B,speaker:O,listening:nt,archive:et,recording:rt,notifications:M,generic:fe};function Qa({deviceId:t}){let{t:n}=X(),a=l(),s=Number.isFinite(t),[c,u]=o(null),[d,f]=o(!1),p=kr({deviceId:t},{enabled:s});Ir([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=qa(p.data),h=xr({onError:(e,n)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:t},meta:{switchId:n.switchId,error:e instanceof Error?e.message:String(e)}}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),u({id:n.switchId,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{u(null),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]}),a.invalidateQueries({queryKey:[[`recording`]]})}}),g=r(e=>{!e.available||e.on===null||h.mutate({deviceId:t,switchId:e.id,enabled:!e.on})},[t,h]);if(m===null)return null;let _=Xa(m),v=e=>c?.id===e.id?c.message:null;return e(an,{open:d,onOpenChange:f,children:[e(jt,{"aria-label":n(`device.cameraFunctionSwitches.cameraFunctions`,`Camera functions`),title:_.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${c===null?_.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:[i(fe,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden lg:inline`,children:n(`device.cameraFunctionSwitches.functions`,`Functions`)}),_.offIds.length>0&&i(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:n(`device.cameraFunctionSwitches.offCount`,{count:_.offIds.length})})]}),e(un,{align:`end`,className:`min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[i(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:n(`device.cameraFunctionSwitches.cameraFunctions`,`Camera functions`)}),i(`ul`,{className:`space-y-0.5`,children:m.map(e=>i(`li`,{children:i($a,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function $a({row:t,failure:n,onToggle:r}){let{t:a}=X(),o=Za[Ya(t.label)],s=t.on===null,c=t.on===!1,l=n===null?s?t.unavailableReason??`The source that owns this did not answer.`:t.costWhenOff:`Write failed: ${n}`,u=n===null?s?t.unavailableReason??`unknown`:null:`write failed`;return e(`button`,{type:`button`,role:`switch`,"aria-label":t.label,"aria-checked":t.on===!0,disabled:!t.available,onClick:r,title:l,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:[i(o,{className:`h-3.5 w-3.5 shrink-0 ${n===null?s?`text-foreground-subtle/50`:c?`text-warning`:`text-success`:`text-danger`}`}),e(`span`,{className:`flex-1 min-w-0 truncate`,children:[t.label,u!==null&&e(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,u]})]}),i(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${s?`bg-surface-hover text-foreground-subtle/60`:c?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:s?`—`:a(c?`common.off`:`common.on`)})]})}function eo({deviceId:t}){let n=Vt(I().trpcClient,t);return n===null?null:e(`a`,{href:n.url,target:`_blank`,rel:`noopener noreferrer`,title:`${n.label} — ${n.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:[i(C,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:n.label})]})}function to({parentDeviceId:t}){let{t:n}=X(),r=pi(),a=I(),{data:o,isLoading:s,isError:c}=hi(t),{data:l}=ln({deviceId:t},{enabled:Number.isFinite(t)});if(s)return i(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:i(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`common.loading`,{defaultValue:`Loading…`})})});if(c)return i(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:i(`p`,{className:`text-[10px] text-warning`,children:n(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let u=(o??[]).filter(e=>e.display?.hidden!==!0);if(u.length===0)return null;let d=en(l?.stableId??``,u,l?.childLayout),f=d.ungrouped,p=e=>r(`/devices/${String(e)}`),m=l?.name??``,h=(e,t)=>i(Pt,{trpc:a.trpcClient,device:{...t,name:An(t,m)},nameForm:`nested`,...l?{parent:{id:l.id,name:l.name,type:l.type}}:{},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),_=f.some(e=>!e.role),v=g&&!_?n(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?n(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):n(`device.children`,{defaultValue:`Children`}),y=f.length>0?e(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[i(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),i(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,b=d.disabledSection===void 0?null:i(Wt,{title:n(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:i(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>h(e.id,e))})},d.disabledSection.title);if(d.sections.length===0)return b===null?y:e(`div`,{className:`space-y-2`,children:[y,b]});let x=_&&!g;return e(`div`,{className:`space-y-2`,children:[x?y:null,d.sections.map(e=>i(Wt,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),x?null:y,b]})}function no({deviceId:e}){let t=I(),{data:n,isLoading:r}=Di(e),{data:a,isLoading:o}=hi(e),s=r||o,c=(a??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),l=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,u=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return s?i(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):i(`div`,{className:`flex h-full w-full flex-col`,children:i(Rt,{trpc:t.trpcClient,children:c,linkDeviceId:l,primaryChildEntityId:u})})}c();function ro({dev:t,busy:n,setBusy:r}){let{t:a}=X(),s=t?.motionTrigger,c=x(t?.state.motionTrigger),[l,u]=o(!1);if(!s)return null;let d=c?.enabled===!0,f=c!==void 0,p=async()=>{if(n||!f)return;let e=!d;r(!0),u(!0);try{await s.setMotionTrigger({enabled:e})}finally{r(!1),u(!1)}},m=l?d?`Disabling…`:`Enabling…`:f?d?`On motion: on`:`On motion: off`:`On motion: …`;return e(`button`,{type:`button`,onClick:()=>{p()},disabled:n||!f,title:f?d?a(`hero.motionTriggerToggle.disableTriggerOnMotion`,`Disable trigger on motion`):a(`hero.motionTriggerToggle.enableTriggerOnMotion`,`Enable trigger on motion`):a(`hero.motionTriggerToggle.awaitingState`,`Awaiting state…`),"aria-pressed":d,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 ${d?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[i(_e,{className:`h-3 w-3`}),i(`span`,{children:m})]})}c();function Q({deviceId:t,deviceType:n,features:r}){let a=I(),s=Bn(n)?.HeroCard??Rn,c=S(a.trpcClient,t),l=x(c?.state.deviceStatus),[u,d]=o(!1),f=l!==void 0&&l.online===!1,p=f?l.lastChangedAt:null;return e(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?i(`div`,{className:`flex justify-center`,children:i(Fr,{lastChangedAt:p})}):null,i(s,{trpc:a.trpcClient,deviceId:t,features:r}),i(`div`,{className:`flex justify-center`,children:i(ro,{dev:c,busy:u,setBusy:d})})]})}function io({deviceId:e,features:t}){return i(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:i(Un,{trpc:I().trpcClient,deviceId:e,features:t})})}function ao({deviceId:e,features:t}){return i(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:i(Rn,{trpc:I().trpcClient,deviceId:e,features:t})})}function oo(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function so(e){if(!e)return null;let t=oo(e.data);return t===null?e.eventType:Y.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var co=1e3,lo=60*co,uo=60*lo,fo=24*uo;function po(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<co?Y.t(`helpers.relativeTime.justNow`):n<lo?Y.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/co)}):n<uo?Y.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/lo)}):n<fo?Y.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/uo)}):Y.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/fo)})}c();var mo=1500,ho=15e3,go=1e3;function _o({deviceId:n}){let{t:r}=X(),s=S(I().trpcClient,n)?.state.eventEmitter,c=x(s);a(()=>{if(!s)return;s.refresh();let e=setInterval(()=>{s.refresh()},ho);return()=>{clearInterval(e)}},[s]);let l=c?.lastEvent??null,u=l?.seq??null,d=t(null),[f,p]=o(!1);a(()=>{if(u===null)return;let e=d.current;if(d.current=u,e===null||e===u)return;p(!0);let t=setTimeout(()=>{p(!1)},mo);return()=>{clearTimeout(t)}},[u]);let[m,h]=o(()=>Date.now());a(()=>{let e=setInterval(()=>{h(Date.now())},go);return()=>{clearInterval(e)}},[]);let g=so(l),_=c?.eventTypes??[],v=c?.eventCountSinceStart??0,y=c!==void 0,b=oo(l?.data);return e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[i(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(f),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${f?`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??r(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:i(f?P:z,{className:`h-10 w-10`})}),e(`div`,{className:`text-center`,children:[b!==null&&i(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:r(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(b)})}),i(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${g?`text-foreground`:`text-foreground-subtle`}`,children:g??(y?r(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):r(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),i(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:l?po(l.timestamp,m):r(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),_.length>0&&i(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:_.map(e=>i(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===l?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),i(`div`,{className:`text-[10px] text-foreground-subtle`,children:r(`hero.eventEmitterHero.sinceStart`,{count:v})})]})}function vo({deviceName:t,deviceType:n,provider:r,isOnline:a,features:o}){let{t:s}=X();return e(`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:[i(gi,{type:r,size:`lg`}),e(`div`,{children:[i(`div`,{className:`text-sm font-semibold text-foreground`,children:t}),i(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:n})]}),e(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[i(Hr,{status:a?`online`:`offline`}),o.length>0&&i(_i,{capabilities:o})]}),i(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:s(`hero.genericHero.noLiveViewForThis`,`No live view for this device type. Use the Config tab or the shortcut row to interact.`)})]})}c();function yo({deviceId:t}){let{t:r}=X(),a=l(),o=ar({deviceId:t},{refetchInterval:1e4,retry:!1}),s=Ur({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),a.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),c=n(()=>bo(o.data??[]),[o.data]);return e(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[e(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[i(xo,{label:r(`hero.hubHero.discovered`,`Discovered`),value:c.total,icon:i(_,{className:`h-3.5 w-3.5`})}),i(xo,{label:r(`hero.hubHero.adopted`,`Adopted`),value:c.adopted,accent:`success`}),i(xo,{label:r(`hero.hubHero.available`,`Available`),value:c.available,accent:c.available>0?`primary`:void 0}),e(`button`,{type:`button`,onClick:()=>{s.mutateAsync({deviceId:t}).catch(()=>{})},disabled:s.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:[s.isPending?i(se,{className:`h-3.5 w-3.5 animate-spin`}):i(m,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:r(`hero.hubHero.discover`,`Discover`)})]})]}),e(`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:[i(So,{icon:i(F,{className:`h-3 w-3 text-emerald-500`}),label:r(`hero.hubHero.online`,`{{online}} online`,{online:c.online})}),i(So,{icon:i(k,{className:`h-3 w-3 text-amber-500`}),label:r(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:c.sleeping})}),i(So,{icon:i(A,{className:`h-3 w-3 text-destructive`}),label:r(`hero.hubHero.offline`,`{{offline}} offline`,{offline:c.offline})}),c.unknown>0?i(So,{icon:i(L,{className:`h-3 w-3 text-foreground-subtle`}),label:r(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:c.unknown})}):null]})]})}function bo(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 xo({label:t,value:n,icon:r,accent:a}){return e(`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 ${a===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:a===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[e(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[r,i(`span`,{className:`truncate`,children:t})]}),i(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:n})]})}function So({icon:t,label:n}){return e(`span`,{className:`inline-flex items-center gap-1`,children:[t,i(`span`,{children:n})]})}var Co={[U.Switch]:Q,[U.Siren]:Q,[U.Light]:Q,[U.Sensor]:Q,[U.Button]:Q,[U.Hub]:yo,[U.Cover]:io,[U.Valve]:Q,[U.Humidifier]:Q,[U.WaterHeater]:Q,[U.Container]:no,[U.Lock]:Q,[U.Fan]:Q,[U.Thermostat]:Q,[U.Climate]:Q,[U.MediaPlayer]:Q,[U.Control]:Q,[U.AlarmPanel]:Q,[U.EventEmitter]:_o,[U.Notifier]:ao,[U.Script]:Q,[U.Automation]:Q,[U.Presence]:Q,[U.Update]:Q,[U.Vacuum]:Q,[U.LawnMower]:Q,[U.Weather]:Q,[U.Image]:Q,[U.PetFeeder]:Q,[U.Dishwasher]:Q};function wo(e){return Co[e]??vo}function To({deviceId:e}){let t=me(I().trpcClient,e,e=>e.runningState);if(t===void 0||t.running!==!0&&t.running!==!1)return i(d,{});let n=t.running;return i(Zt,{running:n,since:t?.since??null,phase:t?.phase??null,className:`px-3 pt-2 sm:px-4`})}function Eo(t){let n=wo(t.deviceType);return e(d,{children:[i(To,{deviceId:t.deviceId}),i(n,{...t})]})}function Do({deviceId:e,widgets:t}){return t.length===0?null:i(`div`,{className:`flex flex-col gap-3 px-3 pb-3 sm:px-4 sm:pb-4`,"data-testid":`device-hero-widgets`,children:t.map(t=>{let n=i(lr,{widgetId:t.widgetId,deviceId:t.deviceId});return i(`div`,{children:t.deviceId===e?n:i(Hn,{deviceId:t.deviceId,children:n})},t.widgetId)})})}function Oo(e){return e.sections.filter(e=>e.location===`hero`).flatMap(t=>t.fields.flatMap(n=>{if(typeof n!=`object`||!n)return[];let r=Reflect.get(n,`type`),i=Reflect.get(n,`widgetId`);return r!==`widget`||typeof i!=`string`||i.length===0?[]:[{widgetId:i,deviceId:e.deviceId,order:t.order??0}]}))}function ko(e){let t=Oo(e),n=new Set(t.map(e=>e.widgetId)),r=e.child===void 0?[]:Oo(e.child),i=[...t,...r.filter(e=>!n.has(e.widgetId))],a=new Set;return i.filter(e=>a.has(e.widgetId)?!1:(a.add(e.widgetId),!0)).sort((e,t)=>e.order-t.order)}function Ao(e){return Or(I().trpcClient,e)}c();function jo(e){let[n,i]=o(`idle`),[s,c]=o(null),l=t(null),u=t(null),d=t(null),f=t(!0),p=Ut(),m=Nt(),h=$t(),g=r(()=>{if(l.current){try{l.current.close()}catch{}l.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null},[]),_=r(async()=>{if(n===`idle`)return;i(`stopping`);let t=d.current;if(t&&e!==null)try{await Promise.race([h.mutateAsync({deviceId:e,sessionId:t}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(i(`idle`),c(null))},[n,e,h,g]),v=r(async()=>{if(e===null||n!==`idle`&&n!==`error`)return;c(null);let t=null,r=null,a=null;try{i(`requesting-mic`),t=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),u.current=t,i(`starting`);let n=await p.mutateAsync({deviceId:e});a=n.sessionId,d.current=a,i(`connecting`),r=new RTCPeerConnection,l.current=r,r.oniceconnectionstatechange=()=>{if(!f.current)return;let e=r.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(c(e===`failed`?`WebRTC connection failed`:null),_())};for(let e of t.getAudioTracks())r.addTrack(e,t);await r.setRemoteDescription({type:`offer`,sdp:n.sdpOffer});let o=await r.createAnswer();await r.setLocalDescription(o);let s=r.localDescription?.sdp??o.sdp??``;await m.mutateAsync({deviceId:e,sessionId:a,sdpAnswer:s})}catch(n){let o=n instanceof Error?n.message:String(n);if(console.warn(`[intercom] start failed`,n),r)try{r.close()}catch{}if(t)for(let e of t.getTracks())try{e.stop()}catch{}if(l.current=null,u.current=null,a!==null)try{await h.mutateAsync({deviceId:e,sessionId:a})}catch{}d.current=null,f.current&&(c(o),i(`error`))}},[e,n,p,m,h,_]);return a(()=>(f.current=!0,()=>{f.current=!1;let t=d.current;if(t!==null&&e!==null&&h.mutate({deviceId:e,sessionId:t}),l.current){try{l.current.close()}catch{}l.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null}),[e]),{state:n,error:s,start:v,stop:_,isTalking:n===`talking`}}c();var Mo=0;function $(){return++Mo}function No(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Po(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 Fo(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.level`,` 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.level < 20).length`,` sm.mapState('battery', s => s.level)`,` 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 Io(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.level < 20)`,` sm.mapState('battery', s => s.level)`,` 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?.level`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.level`,` 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({ level: 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 Lo({scope:n,greeting:s,className:c}){let{t:l}=X(),d=I(),[f,p]=o(()=>{let e=[];return s&&e.push({id:$(),kind:`info`,text:s}),e.push({id:$(),kind:`info`,text:`scope: ${No(n)} — type help or context for available commands`}),e}),[m,h]=o(``),[g,_]=o([]),[v,y]=o(-1),b=t(null),x=t(null);a(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[f]);let S=r(()=>{b.current?.focus()},[]),C=u({mutationFn:e=>d.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`;p(e=>[...e,{id:$(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);p(e=>[...e,{id:$(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){p([{id:$(),kind:`info`,text:`scope: ${No(n)}`}]),h(``);return}if(t===`help`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Po(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(t===`context`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Io(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(t===`examples`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Fo(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,t]),y(-1),p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`}]),h(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(m);return}if(e.key===`ArrowUp`){if(e.preventDefault(),g.length===0)return;let t=v===-1?g.length-1:Math.max(0,v-1);y(t),h(g[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),v===-1)return;let t=v+1;t>=g.length?(y(-1),h(``)):(y(t),h(g[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),p([{id:$(),kind:`info`,text:`scope: ${No(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return e(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${c??``}`,onClick:S,children:[e(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[f.map(e=>i(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&i(`span`,{className:`text-zinc-500 animate-pulse`,children:l(`shared.replTerminal.thinking`,`…thinking`)})]}),e(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[i(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:l(`shared.replTerminal.text`,`>`)}),i(`input`,{ref:b,value:m,onChange:e=>h(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 Ro(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}}}c();function zo({deviceId:e,intercomAvailable:t=!1}){let r=I(),a=typeof window<`u`?re():``,o=Number.isFinite(e),s=Ao(o?e:null),c=Pa(o?[e]:[]),l=n(()=>{if(!o)return;let e=[];for(let t of c.rows){let n=Gn(t);n!==null&&e.push(n)}return e},[o,c.rows]),{streams:u,pipelineMetrics:f,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:_,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S}=St(r.trpcClient,o?e:null),C=g(o?e:null,{width:Wo}),w=jo(o&&t?e:null),T=w.state===`requesting-mic`||w.state===`starting`||w.state===`connecting`||w.state===`stopping`,E=w.isTalking||T,D=()=>{w.state===`idle`||w.state===`error`?w.start():w.state!==`stopping`&&w.stop()},O=he(),k=Dt(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=Ro(k.request,A),M=O.length>0?i(d,{children:O.map(e=>i(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return i(Vn,{serverUrl:a,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:_,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S,...j===null?{}:{...j,onExitPlayback:()=>k.clear()},streams:u,pipelineMetrics:f,phase:s.phase,detections:s,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:C.src,...C.src?{posterUrl:C.src}:{},snapshotLoading:C.loading,onRefreshSnapshot:C.refresh,intercomAvailable:t,intercomShown:E,onIntercomToggle:D,extraOverlay:M,chromeless:!0,className:`h-full`})}function Bo({deviceId:e,containerDeviceId:t}){let{t:n}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full`,children:i(Kn,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):i(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:n(`device.panelContent.notLoaded`,{id:e})})}function Vo({deviceId:e}){let{t}=X();if(!Number.isFinite(e))return i(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})});let n=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
2
|
+
`);return i(Lo,{scope:{type:`device`,deviceId:e},greeting:n,className:`h-full border-0 rounded-none`})}function Ho({deviceId:e}){let{t}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:i(fr,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):i(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}function Uo({deviceId:e}){let{t}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:i(Rr,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):i(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}var Wo=960;function Go({initialName:e,label:t=`Name`,layout:n=`inline`,bound:r}){return i(Z,{label:t,layout:n,value:i(`input`,{type:`text`,value:r.value,"aria-label":t,placeholder:e,onChange:e=>r.onChange(e.target.value),className:`flex-1 min-w-0 w-full px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`})})}c();function Ko({label:t=`Location`,layout:r=`inline`,bound:a}){let{t:o}=X(),{data:s}=Qt(),c=s??[],l=a.value.trim().toLowerCase(),u=n(()=>l.length===0?[]:c.filter(e=>e.toLowerCase()!==l&&e.toLowerCase().includes(l)),[c,l]);return i(Z,{label:t,layout:r,value:e(`div`,{className:`relative`,children:[i(`input`,{type:`text`,value:a.value,"aria-label":t,onChange:e=>a.onChange(e.target.value),placeholder:o(`shared.locationRow.roomAreaOrLeaveEmpty`,`Room / area (or leave empty to clear)`),className:`flex-1 min-w-0 w-full px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u.length>0&&i(`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:u.map(t=>e(`button`,{type:`button`,onClick:()=>a.onChange(t),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[i(ve,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),i(`span`,{className:`truncate`,children:t})]},t))})]})})}var qo=`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`,Jo=0,Yo=10;function Xo(e){if(e.trim()===``)return``;let t=Number.parseInt(e,10);return Number.isFinite(t)?String(t<Jo?Jo:t>Yo?Yo:t):``}function Zo({value:e,onChange:t,disabled:n=!1,placeholder:r,className:a,id:o,"aria-label":s}){return i(`input`,{type:`number`,min:Jo,max:Yo,step:1,id:o,className:a??qo,"aria-label":s,placeholder:r,value:e,onChange:e=>{t(Xo(e.target.value))},disabled:n})}function Qo({deviceName:t,value:n,inheritedIcon:r,inheritedLabel:a,disabled:o,onChange:s}){let{t:c}=X(),l={trigger:c(`deviceDisplay.pickIcon`,{name:t}),panel:c(`deviceDisplay.iconFor`,{name:t}),searchPlaceholder:c(`deviceDisplay.iconSearchPlaceholder`),clear:a,noMatches:c(`deviceDisplay.iconNoMatches`)};return e(`div`,{className:`flex items-center gap-2`,children:[i(tn,{value:n===``?null:n,onPick:e=>s(e??``),categoryLabel:e=>c(`deviceDisplay.iconCategory.${e}`,{defaultValue:He(e)}),fallbackGlyph:r,labels:l,disabled:o}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n===``?a:n})]})}var $o=`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`;function es(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function ts({device:t,role:n,display:r,onChange:a}){let o=pe();Pn();let{t:s}=X(),c=l(),u=n===null?void 0:hn[n],f=u?.kind===`numeric`,p=n!==null||t.parentDeviceId!==null&&t.parentDeviceId!==void 0,m=t.sourceInfo?.quantity,h=u?.kind===`numeric`?u.quantity??(m!==void 0&&m!==`device`?m:void 0):void 0,g=h===void 0?void 0:Ke(h),_=g===void 0?void 0:Pe(g),{data:v}=gt({},{staleTime:6e4,enabled:n!==null}),y=Br({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),b=()=>{if(n===null)return;let e=es(r.precision),t={...r.icon===``?{}:{icon:r.icon},...r.unit===``?{}:{unit:r.unit},...e===void 0?{}:{precision:e}};y.mutate({defaults:{...v?.defaults,[n]:t}})},x=n===null?void 0:v?.defaults?.[n]?.icon,S=x===void 0?void 0:zt(x),C=n===null?zn(t.type,o):Nr(n,o),w={icon:S??C.icon,label:S===void 0?C.label:String(x)},T=n===null&&t.type===U.Container?s(`deviceDisplay.inheritedContainer`):S===void 0?s(`deviceDisplay.inherited`,{name:w.label}):s(`deviceDisplay.inheritedRoleDefault`,{icon:w.label,role:C.label}),E=n===null?``:Nr(n,o).label;return e(`div`,{className:`mt-3 divide-y divide-border border-t border-border`,children:[i(Z,{label:s(`deviceDisplay.icon`),value:i(Qo,{deviceName:t.name,value:r.icon,inheritedIcon:w.icon,inheritedLabel:T,disabled:!1,onChange:e=>a({icon:e})})}),p&&i(Z,{label:s(`deviceDisplay.label`),value:i(`input`,{type:`text`,className:$o,"aria-label":s(`deviceDisplay.label`),placeholder:n===null?t.name:E,value:r.label,onChange:e=>a({label:e.target.value})})}),f&&e(d,{children:[i(Z,{label:s(`deviceDisplay.unit`),value:i(gn,{dimension:_,value:r.unit,onChange:e=>a({unit:e}),disabled:!1,"aria-label":s(`deviceDisplay.unit`),inheritLabel:s(`deviceDisplay.unitSource`,{unit:g===void 0?``:` (${g})`}),emptyReason:s(`deviceDisplay.unitSource`,{unit:``})})}),i(Z,{label:s(`deviceDisplay.precision`),value:i(Zo,{"aria-label":s(`deviceDisplay.precision`),placeholder:s(`deviceDisplay.precisionInherit`),value:r.precision,onChange:e=>a({precision:e}),disabled:!1})})]}),n!==null&&i(`div`,{className:`px-3 sm:px-4 py-2`,children:i(J,{type:`button`,variant:`outline`,size:`sm`,onClick:b,disabled:y.isPending,title:s(`deviceDisplay.setRoleDefaultTitle`,{role:E}),children:s(`deviceDisplay.setRoleDefault`,{role:E})})})]})}function ns(e){return typeof e.linkDeviceId==`number`}var rs=new Set(Object.values(W));function is(e){return rs.has(e)}var as={[U.Switch]:[W.Siren,W.Floodlight,W.Spotlight,W.PirSensor,W.Chime,W.Autotrack,W.Nightvision,W.PrivacyMask,W.BinaryHelper],[U.Light]:[W.Floodlight,W.Spotlight,W.Nightvision],[U.Siren]:[W.Siren],[U.Button]:[W.Doorbell],[U.Sensor]:[W.MotionSensor,W.ContactSensor,W.LeakSensor,W.SmokeSensor,W.COSensor,W.GasSensor,W.TamperSensor,W.VibrationSensor,W.ConnectivitySensor,W.SoundSensor,W.BinarySensor,W.TemperatureSensor,W.HumiditySensor,W.AmbientLightSensor,W.PressureSensor,W.WindSensor,W.RainSensor,W.UvSensor,W.SolarRadiationSensor,W.SoilMoistureSensor,W.PowerSensor,W.EnergySensor,W.VoltageSensor,W.CurrentSensor,W.AirQualitySensor,W.BatterySensor,W.NumericSensor,W.EnumSensor,W.DateTimeSensor,W.GenericSensor],[U.Control]:[W.NumericControl,W.SelectControl,W.TextControl,W.DateTimeControl],[U.Notifier]:[W.MobilePushNotifier,W.MessagingNotifier,W.EmailNotifier,W.GenericNotifier]};function os(e){for(let t of Object.values(U))if(t===e)return!0;return!1}function ss(e){return os(e)?as[e]??[]:[]}function cs(e,t){let n=ss(t);return e==null||e===``||n.includes(e)?n:[...n,e]}function ls({device:t}){let{t:n}=X(),r=pe(),a=mi(),o=a?.identity??null,s=o?.name??t.name,c=o?.location??t.location??``,l=o?.role??t.role??null,u=o?.display.hidden??t.display?.hidden===!0,d=a!==null&&o!==null;return e(`section`,{"aria-label":n(`customize.identity.title`),className:`${E} ${f}`,children:[e(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[d?i(Go,{deviceId:t.id,initialName:s,label:n(`customize.identity.name`),layout:`stacked`,bound:{value:s,onChange:a.setIdentityName}}):i(Z,{label:n(`customize.identity.name`),layout:`stacked`,value:s}),d?i(Ko,{deviceId:t.id,initialLocation:c,label:n(`customize.identity.room`),layout:`stacked`,bound:{value:c,onChange:a.setIdentityLocation}}):i(Z,{label:n(`customize.identity.room`),layout:`stacked`,value:c===``?n(`common.unset`):c}),i(Z,{label:n(`customize.identity.type`),layout:`stacked`,value:t.type}),i(Z,{label:n(`customize.identity.hidden`),layout:`stacked`,value:i(Kt,{"aria-label":n(`deviceDisplay.hideFromLists`),checked:u,disabled:!d,onChange:e=>a?.setIdentityDisplay({hidden:e.target.checked})})}),i(Z,{label:n(`customize.identity.role`),layout:`stacked`,value:ns(t)||!d?i(`span`,{children:us(l,n(`customize.identity.noRole`),r)}):i(Sn,{"aria-label":n(`customize.identity.role`),value:l??``,options:[{value:``,label:n(`customize.identity.noRole`)},...cs(l,t.type).map(e=>({value:e,label:us(e,n(`customize.identity.noRole`),r)}))],onChange:e=>a.setIdentityRole(e.target.value===``?null:e.target.value)})})]}),o!==null&&a!==null&&i(ts,{device:t,role:l,display:o.display,onChange:a.setIdentityDisplay})]})}function us(e,t,n){return e==null||e===``?t:is(e)?Nr(e,n).label:e}function ds(e){let t=we({draft:{kind:`pulse`,cap:e.cap,targetId:e.targetId,enabled:e.enabled,debounceMs:e.debounceMs,...e.edges===void 0?{}:{edges:[...e.edges]},sources:e.sources.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath}))},device:e.device,changedAtFields:e.sources.map(e=>e.changedAtField)});return t.ok?t.value:null}function fs(e){let t=Ne({draft:{kind:`span`,cap:e.cap,targetId:e.targetId,timeoutMs:e.timeoutMs,...e.cooldownMs===void 0?{}:{cooldownMs:e.cooldownMs},sources:e.sources.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,mode:e.mode}))},device:e.device});return t.ok?t.value:null}function ps(e,t){return{deviceId:e,config:t.config}}function ms(e,t){return{deviceId:e,patch:{motionCooldownMs:t}}}async function hs(e,t,n,r){await n(ps(e,t)),await r(ms(e,t.timeoutMs))}c();function gs(t){let{t:n}=X(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(or,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(Xr,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(ni,{children:i(xn,{children:r})}),t.open?i(_s,{...t}):null]})})}function _s(t){let{t:r}=X(),a=nn({projection:`slim`}),s=ta(n(()=>a.status===`success`?na(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>vs(t.sources)),[u,f]=o(null),[p,m]=o(!1);!p&&s!==null&&(f(s),m(!0));let[h,g]=o(t.edge),[_,v]=o(t.debounceMs/1e3),y=ys(c),b=y.length===0?null:ds({cap:t.cap,targetId:t.targetId,device:t.target,enabled:t.enabled,debounceMs:Math.round(_*1e3),edges:[h],sources:y}),x=y[0]??null,S=wr({deviceId:c[0]?.deviceId??0}),C=xs(S.status===`success`?S.data:void 0,x),w=Le(Ie,C,Math.round(_*1e3));return e(d,{children:[e(Wn,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[i(`p`,{className:`text-[11px] text-foreground-muted`,children:r(`customize.event.pulseBody`)}),i($i,{kind:`event`,shape:`pulse`,enabled:t.open,hostId:t.host.id,devicePickerTestId:`event-pulse-picker`,destination:{cap:t.cap,targetId:t.targetId,title:t.title},device:u,picked:c,onDeviceChange:f,onPickedChange:l,edges:t.edges,edge:h,onEdgeChange:g,debounceSec:_,onDebounceSecChange:v,sourceModes:[],timeoutSec:0,onTimeoutSecChange:()=>void 0,cooldownSec:null,onCooldownSecChange:()=>void 0}),C.kind===`level`?i(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(bs(C,w.lastPressedAt))}):null]}),e(Qn,{className:`flex flex-wrap gap-2`,children:[i(J,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(J,{"data-testid":`event-save`,disabled:!t.canSave||b===null,onClick:()=>{b!==null&&t.onSave(b)},children:r(`customize.scalar.save`)})]})]})}function vs(e){return e.map(e=>({deviceId:0,addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,deviceName:e.stableId,changedAtField:e.changedAtField}))}function ys(e){return e.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,changedAtField:e.changedAtField??Xe[e.cap]??`lastChangedAt`}))}function bs(e,t){return e.kind===`unread`?`customize.event.previewWaiting`:e.active&&t===null?`customize.event.previewAlreadyOn`:t===null?`customize.event.previewQuiet`:`customize.event.previewCounted`}function xs(e,t){if(e===void 0||t===null)return{kind:`unread`};let n=e[t.cap],r=n===void 0?void 0:ra(n,t.fieldPath),i=Xe[t.cap]??t.changedAtField,a=n===void 0?void 0:ra(n,i);return typeof r==`boolean`?{kind:`level`,active:r,changedAt:typeof a==`number`&&Number.isFinite(a)?a:null}:{kind:`unread`}}function Ss(e,t,n){if(e===`pending`)return{kind:`pending`,seconds:null};if(e===`unknown`||e==null)return{kind:`unknown`,seconds:null};if(!e)return{kind:`quiet`,seconds:null};let r=Cs(t,n);return r===null?{kind:`unknown`,seconds:null}:{kind:`active`,seconds:r}}function Cs(e,t){if(e==null||!Number.isFinite(e)||e<ji)return null;let n=Math.floor((t-e)/1e3);return n<0?0:n}function ws(e,t){if(e===`pending`)return{kind:`pending`,lastPressedAt:null,pressCount:null};if(e===`unknown`)return{kind:`unknown`,lastPressedAt:null,pressCount:null};let n=typeof e==`number`&&Number.isFinite(e)&&e>=ji?e:null,r=typeof t==`number`&&Number.isFinite(t)&&t>=0?t:null;return n===null?{kind:`none`,lastPressedAt:null,pressCount:r}:{kind:`ring`,lastPressedAt:n,pressCount:r}}c();var Ts={id:0,name:``,type:`unknown`,stableId:``,parentDeviceId:null};function Es({device:t,handle:n,availability:r,cap:a,title:s,view:c}){let{t:l,i18n:u}=X(),f=da(),[p,m]=o(!1),[h,g]=o(null),_=Xi(n.state),v=Ki(_,a),y=Os(n,v),b=y.kind===`known`&&y.value!==null?$e({feature:y.value,device:n.target,cap:a,targetId:c.id,timestampPath:c.timestampPath,counterPath:c.counterPath}):null,x=b!==null,S=Ii(x),C=b?.draft.sources[0]??null,w=C===null||S.kind!==`known`?null:S.value.find(e=>ke({addonId:e.addonId,stableId:e.stableId})===ke(C))??null,T=ks(x,S.kind,w!==null),E=bt(w===null?Ts:Vi(w),`compact`),D=bt(t,`full`),O=Ge({cap:a,targetId:c.id,device:n.target,timestampPath:c.timestampPath,counterPath:c.counterPath,apply:c.apply,stored:y,sourcePresence:T,sourceUnknownReason:S.kind===`unknown`?S.reason:null}),k=n.state.kind===`none`||n.state.kind===`present`;if(r.kind===`absent`||!c.deviceTypes.includes(t.type))return null;let A=async e=>{let t=await n.save(e);g(t.kind===`refused`?t.reason:null)},j=As(b),M=b?.draft.edges?.[0],ee=M!==void 0&&c.edges.includes(M)?M:c.defaultEdge,N=C===null?``:_a(C.cap,C.fieldPath,u.language),te=y.kind===`known`&&y.value===null,re=!x&&y.kind===`known`&&y.value!==null;return e(d,{children:[i(Hi,{id:a,icon:ne,title:s,testId:`event-card-${a}`,actions:e(d,{children:[v!==null&&e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground`,children:[i(Kt,{"aria-label":l(`customize.doorbell.active`),checked:v.enabled!==!1,disabled:!k||n.saving,onChange:e=>{A(Yi(_,n.target,{...v,enabled:e.target.checked}))}}),l(`customize.doorbell.active`)]}),i(q,{children:l(Ri(O.text,O.status.state))})]}),children:i(`div`,{className:`flex flex-col gap-2 px-3 py-2 sm:px-4`,children:r.kind===`pending`||r.kind===`present`&&!k?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:l(`customize.event.checking`)}):r.kind===`unknown`?i(K,{title:l(`customize.scalar.unreadable`),message:r.reason}):e(d,{children:[x&&C!==null&&i(`p`,{className:`text-xs text-foreground`,children:l(`customize.scalar.override`,{name:w===null?C.stableId:E,field:N})}),x&&i(Ds,{deviceId:t.id,cap:a,timestampPath:c.timestampPath,counterPath:c.counterPath,startedAt:n.state.kind===`present`?n.state.view.block.createdAt:null}),re&&v!==null&&e(`p`,{className:`text-xs text-foreground flex flex-wrap items-center gap-1`,children:[l(`customize.doorbell.otherFormula`),i(Li,{handle:n,cap:a,fieldPath:c.counterPath})]}),te&&i(`p`,{className:`text-xs text-foreground-subtle`,children:l(`customize.scalar.noOverride`)}),h!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:h}),e(`div`,{className:`flex flex-wrap gap-2`,children:[x&&i(J,{variant:`outline`,size:`sm`,disabled:n.saving,onClick:()=>m(!0),children:l(`customize.scalar.change`)}),x&&i(J,{variant:`ghost`,size:`sm`,disabled:n.saving,onClick:()=>{if(_===null)return;let e=Bi(_,a);f(l(`customize.doorbell.removeWhat`,{name:w===null?D:E}),e===null).then(t=>{t&&A(e)})},children:l(`customize.scalar.remove`)}),te&&i(J,{variant:`outline`,size:`sm`,"data-testid":`event-add-${a}`,disabled:n.saving,onClick:()=>m(!0),children:l(`customize.scalar.add`)})]})]})})}),i(gs,{open:p,mode:x?`change`:`add`,title:s,cap:a,targetId:c.id,host:t,target:n.target,enabled:v?.enabled!==!1,debounceMs:b?.draft.debounceMs??c.debounceMs,edges:c.edges,edge:ee,sources:j,canSave:k&&!n.saving,onClose:()=>m(!1),onSave:e=>{m(!1),A(Yi(_,n.target,e))}})]})}function Ds({deviceId:t,cap:n,timestampPath:r,counterPath:a,startedAt:o}){let{t:s}=X(),c=Fi({deviceId:t,cap:n,path:r}),l=Fi({deviceId:t,cap:n,path:a}),u=ws(c.kind===`pending`?`pending`:c.kind!==`value`||typeof c.value!=`number`?`unknown`:c.value,l.kind===`value`&&typeof l.value==`number`?l.value:null);return u.kind===`pending`?i(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:s(`customize.event.checking`)}):u.kind===`unknown`?i(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:s(`customize.event.doorbellLast.unknown`)}):u.kind===`none`?e(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:[s(`customize.event.doorbellLast.none`,{when:o===null?``:Ai(o)}),u.pressCount===null?``:` · ${s(`customize.event.doorbellCount`,{count:u.pressCount})}`]}):e(`p`,{role:`status`,className:`text-[11px] text-foreground`,children:[s(`customize.event.doorbellLast.ring`,{when:Ai(u.lastPressedAt)}),u.pressCount===null?``:` · ${s(`customize.event.doorbellCount`,{count:u.pressCount})}`]})}function Os(e,t){return e.state.kind===`pending`?{kind:`pending`}:e.state.kind===`unknown`||e.state.kind===`not-loaded`?{kind:`unknown`,reason:e.state.reason}:{kind:`known`,value:t}}function ks(e,t,n){return e?t===`pending`?`pending`:t===`unknown`?`unknown`:n?`present`:`absent`:`present`}function As(e){return e===null?[]:e.draft.sources.map((t,n)=>({addonId:t.addonId,stableId:t.stableId,cap:t.cap,fieldPath:t.fieldPath,changedAtField:e.changedAtFields[n]??``}))}c();function js(t){let{t:n}=X(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(or,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(Xr,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(ni,{children:i(xn,{children:r})}),t.open?i(Ms,{...t}):null]})})}function Ms(t){let{t:r}=X(),a=nn({projection:`slim`}),s=ta(n(()=>a.status===`success`?na(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>Ns(t.sources)),[u,f]=o(null),[p,m]=o(!1);!p&&s!==null&&(f(s),m(!0));let[h,g]=o(t.timeoutMs/1e3),[_,v]=o((t.cooldownMs??0)/1e3),y=Ps(c),b=fs({cap:t.cap,targetId:t.targetId,device:t.target,timeoutMs:Math.round(h*1e3),cooldownMs:t.cooldownMs===null?void 0:Math.round(_*1e3),sources:y}),x=c[0];return e(d,{children:[e(Wn,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[i(`p`,{className:`text-[11px] text-foreground-muted`,children:r(`customize.event.spanBody`)}),i($i,{kind:`event`,shape:`span`,enabled:t.open,hostId:t.host.id,devicePickerTestId:`event-span-picker`,destination:{cap:t.cap,targetId:t.targetId,title:t.title},device:u,picked:c,onDeviceChange:f,onPickedChange:e=>l(e.filter(e=>!(e.addonId===t.host.addonId&&e.stableId===t.host.stableId))),edges:[],edge:`rising`,onEdgeChange:()=>void 0,debounceSec:0,onDebounceSecChange:()=>void 0,sourceModes:t.sourceModes,timeoutSec:h,onTimeoutSecChange:g,cooldownSec:t.cooldownMs===null?null:_,onCooldownSecChange:v}),x!==void 0&&i(Fs,{deviceId:x.deviceId,cap:x.cap,fieldPath:x.fieldPath,timeoutMs:Math.round(h*1e3)})]}),e(Qn,{className:`flex flex-wrap gap-2`,children:[i(J,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(J,{"data-testid":`event-save`,disabled:!t.canSave||b===null,onClick:()=>{b!==null&&t.onSave(b)},children:r(`customize.scalar.save`)})]})]})}function Ns(e){return e.map(e=>({deviceId:0,addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,deviceName:e.label.length>0?e.label:e.stableId,mode:e.mode}))}function Ps(e){return e.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,mode:e.mode??`in-addition`,label:e.deviceName}))}function Fs({deviceId:e,cap:t,fieldPath:n,timeoutMs:r}){let{t:a}=X(),o=Fi({deviceId:e,cap:t,path:n}),s=o.kind===`value`&&typeof o.value==`boolean`?{kind:`level`,active:o.value,changedAt:null}:{kind:`unread`},c=je(Fe,s,{timeoutMs:r,cooldownMs:0,nowMs:Date.now()});return s.kind===`unread`?null:i(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:a(Is(s,c.open))})}function Is(e,t){return e.kind===`unread`?`customize.event.previewWaiting`:t?`customize.event.previewMotionOn`:e.active?`customize.event.previewSensorOn`:`customize.event.previewMotionOff`}c();function Ls({device:n,availability:r,cap:a,title:s,view:c,sensors:l}){let{t:u}=X(),f=Ot(),p=Gt(),m=Cn({addonId:`pipeline-orchestrator`,deviceId:n.id,nodeId:`hub`}),[h,g]=o(!1),[_,v]=o(null),y=t(!1),[b,x]=o(!1),S=zs(l),C=Ii(!0),w=Oe(c.id,S),T=Us(Oa(m.data).motionCooldownMs,c.timeoutMs);if(r.kind===`absent`||!c.deviceTypes.includes(n.type))return null;let E=b||f.isPending||p.isPending,D=w.writable&&!E&&r.kind===`present`,O=async e=>{if(!w.writable||y.current){v(u(`customize.saveInFlight`));return}y.current=!0,x(!0);try{await hs(n.id,e,async e=>{await f.mutateAsync({deviceId:e.deviceId,config:e.config===null?null:{sensors:e.config.sensors.map(e=>({addonId:e.addonId,stableId:e.stableId,mode:e.mode}))}})},async e=>{let t={motionCooldownMs:e.patch.motionCooldownMs};await p.mutateAsync({deviceId:e.deviceId,patch:t})}),v(null),await l.refetch()===`failed`&&v(u(`customize.motion.refetchFailed`))}catch(e){v(e instanceof Error?e.message:String(e))}finally{y.current=!1,x(!1)}},k=w.rows.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:`binary`,fieldPath:`on`,mode:e.mode,label:e.name}));return e(d,{children:[i(Hi,{id:a,icon:_e,title:s,testId:`event-card-${a}`,actions:i(q,{children:u(Ri(w.text,w.status.state))}),children:i(`div`,{className:`flex flex-col gap-2 px-3 py-2 sm:px-4`,children:r.kind===`pending`||S.kind===`pending`?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:u(`customize.motion.reading`)}):r.kind===`unknown`||S.kind===`unknown`?i(Bs,{reason:Hs(S)||(r.kind===`unknown`?r.reason:``)}):e(d,{children:[i(Rs,{deviceId:n.id}),w.rows.length===0?i(`p`,{className:`text-xs text-foreground-subtle`,children:u(`customize.scalar.noOverride`)}):i(`ul`,{className:`flex flex-col gap-1`,children:w.rows.map(t=>e(`li`,{className:`text-xs text-foreground`,children:[i(Vs,{row:t,fleet:C}),t.reason===null?``:` — ${u(`customize.motion.state.${t.state}`)}`]},t.key))}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:u(`customize.event.timeoutSeconds`,{seconds:T/1e3})}),_!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:_}),i(`div`,{className:`flex flex-wrap gap-2`,children:i(J,{variant:`outline`,size:`sm`,"data-testid":`event-add-${a}`,disabled:!D,onClick:()=>g(!0),children:w.rows.length===0?u(`customize.scalar.add`):u(`customize.scalar.change`)})})]})})}),i(js,{open:h,mode:w.rows.length===0?`add`:`change`,title:s,cap:a,targetId:c.id,host:n,target:{addonId:n.addonId,stableId:n.stableId},timeoutMs:T,cooldownMs:c.cooldownMs,sourceModes:c.sourceModes,sources:k,canSave:D,onClose:()=>g(!1),onSave:e=>{g(!1),O(e)}})]})}function Rs({deviceId:e}){let{t}=X(),n=Fi({deviceId:e,cap:`motion`,path:`detected`}),r=Fi({deviceId:e,cap:`motion`,path:`lastDetectedAt`}),a=Ss(n.kind===`pending`?`pending`:n.kind!==`value`||typeof n.value!=`boolean`?`unknown`:n.value,r.kind===`value`&&typeof r.value==`number`?r.value:null,Date.now());return i(`p`,{role:`status`,className:`text-xs text-foreground`,children:t(a.kind===`active`?`customize.event.motionNow.active`:`customize.event.motionNow.${a.kind}`,a.seconds===null?void 0:{seconds:a.seconds})})}function zs(e){return e.presence===`pending`?{kind:`pending`}:e.status===null?{kind:`unknown`,reason:e.failureReason}:{kind:`known`,value:e.status}}function Bs({reason:e}){let{t}=X(),n=e.trim();return n.length===0?i(K,{message:t(`customize.motion.unreadableBare`)}):i(K,{title:t(`customize.motion.unreadable`,{reason:n}),message:n})}function Vs({row:e,fleet:t}){let n=Bt();if(t.kind!==`known`)return e.name;let r=t.value.find(t=>t.addonId===e.addonId&&t.stableId===e.stableId);return r===void 0?e.name:Wi(Vi(r),t.value.map(Vi),n)}function Hs(e){return e.kind===`unknown`?e.reason??``:e.kind===`known`&&e.value.state===`unreadable`?e.value.reason:``}function Us(e,t){return e!==null&&Number.isFinite(e)?e:t}var Ws=Ee;function Gs(e,t){let n=Ws[e];return n===void 0?null:n.targets.find(e=>e.id===t)??null}function Ks({device:e,handle:t,facts:n,sensors:r}){let{t:a}=X();return i(d,{children:Ji().map(o=>{let s=o.pulse??o.span;if(s===null||!s.deviceTypes.includes(e.type))return null;let c=Gs(o.cap,s.id);if(c===null)return null;let l=a(o.pulse===null?`customize.motion.title`:`customize.doorbell.title`),u=Sa(zi(o.cap,c),n);return o.pulse===null?o.span===null?null:i(Ls,{device:e,availability:u,cap:o.cap,title:l,view:o.span,sensors:r},o.cap):i(Es,{device:e,handle:t,availability:u,cap:o.cap,title:l,view:o.pulse},o.cap)})})}function qs({id:t,icon:n,title:r,headerControl:a,addLabel:o,onAdd:s,addDisabled:c=!1,notices:l,suggestion:u,children:f}){let{t:p}=X(),m=s!==void 0&&o!==void 0;return e(Hi,{id:t,icon:n,title:r,actions:e(d,{children:[a,m&&!c&&u!==void 0&&u.count>0&&e(J,{variant:`ghost`,size:`sm`,onClick:u.onOpen,children:[i(ge,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),p(`customize.suggest.hint`,{count:u.count,location:u.location})]}),m&&i(J,{variant:`outline`,size:`sm`,disabled:c,onClick:s,children:o})]}),children:[l!==void 0&&i(`div`,{className:`flex flex-col gap-1 px-3 pt-2 empty:hidden sm:px-4`,children:l}),i(`ul`,{className:`flex flex-col divide-y divide-border`,children:f})]})}c();var Js=`flex items-center gap-2 px-3 py-2 text-sm sm:px-4`,Ys=`list-none px-3 py-2 text-xs text-foreground-subtle sm:px-4`;function Xs({entry:e}){let{t}=X();return e.readOnly?i(q,{variant:`info`,children:e.addonId}):i(q,{variant:`primary`,children:t(`actions.source.internal`,`Internal`)})}function Zs({device:t}){let{t:n}=X(),r=l(),a=Xn({}),s=Yr({deviceId:t.id}),[c,u]=o(!1),[f,p]=o([]),m=()=>void r.invalidateQueries({queryKey:[[`actions`]]}),h=bn({onSuccess:m}),g=ti({onSuccess:m}),_=a.data??[],v=s.data?.actionIds??[],y=v.flatMap(e=>_.filter(t=>t.id===e)),x=_.filter(e=>!v.includes(e.id)),S=s.data!==void 0&&a.data!==void 0,C=e=>h.mutate({deviceId:t.id,actionIds:[...e]}),w=()=>{p([]),u(!0)},T=e=>p(f.includes(e)?f.filter(t=>t!==e):[...f,e]);return e(d,{children:[e(qs,{id:`linked-actions`,icon:ue,title:n(`customize.linkedActions.title`,`Linked actions`),addLabel:n(`customize.linkedActions.add`,`Add`),onAdd:S&&x.length>0?w:void 0,addDisabled:h.isPending,children:[!S&&i(`li`,{className:Ys,children:n(`customize.linkedActions.loading`,`Checking linked actions.`)}),S&&y.length===0&&i(`li`,{className:Ys,children:n(`customize.linkedActions.none`,`None linked.`)}),y.map(r=>e(`li`,{className:Js,children:[i(`span`,{className:`min-w-0 flex-1 truncate`,children:r.name}),i(Xs,{entry:r}),i(gr,{icon:b,variant:`ghost`,size:`sm`,"aria-label":n(`customize.linkedActions.run`,`Run {{name}}`,{name:r.name}),disabled:g.isPending,onClick:()=>g.mutate({actionId:r.id,deviceId:t.id})}),i(gr,{icon:ce,variant:`ghost`,size:`sm`,"aria-label":n(`customize.linkedActions.unlink`,`Unlink {{name}}`,{name:r.name}),disabled:h.isPending,onClick:()=>C(v.filter(e=>e!==r.id))})]},r.id)),h.error!==null&&i(`li`,{role:`alert`,className:`list-none px-3 py-2 text-xs text-danger sm:px-4`,children:h.error.message}),i(`li`,{className:Ys,children:n(`customize.linkedActions.hint`,`Linked actions show as buttons on this camera. Nothing is linked unless you pick it.`)})]}),i(or,{open:c,onOpenChange:u,children:e(Xr,{placement:`sheet-on-mobile`,children:[e(ni,{children:[i(xn,{children:n(`customize.linkedActions.pickTitle`,`Link actions to {{name}}`,{name:t.name})}),i(ai,{children:n(`customize.linkedActions.pickHint`,`Pick the actions to link. Nothing is chosen for you.`)})]}),i(Wn,{children:i(`ul`,{className:`space-y-1`,children:x.map(t=>i(`li`,{children:e(`label`,{className:`flex items-center gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-surface-hover`,children:[i(Kt,{checked:f.includes(t.id),onChange:()=>T(t.id)}),i(`span`,{className:`flex-1`,children:t.name}),i(Xs,{entry:t})]})},t.id))})}),e(Qn,{className:`flex flex-wrap gap-2`,children:[i(J,{variant:`outline`,onClick:()=>u(!1),children:n(`common.cancel`,`Cancel`)}),i(J,{disabled:f.length===0||h.isPending,onClick:()=>{C([...v,...f]),u(!1)},children:n(`customize.linkedActions.addN`,`Add {{count}}`,{count:f.length})})]})]})})]})}function Qs(e,t){if(e.kind!==`known`||typeof t!=`string`||t.length===0)return null;let n=rr(e.value,t),r=new Map(e.value.map(e=>[e.id,e])),i=new Map;for(let e of n){let t=r.get(e)?.parentDeviceId,n=t==null?void 0:r.get(t);n!==void 0&&n.type===`container`&&i.set(e,n.name)}return{location:t,ids:n,containers:i}}function $s(e,t,n){return Kr(e,t?.ids??new Set,n)}function ec(e,t){return e?.containers.get(t)??null}function tc(e,t,n){return e.kind===`known`?$s(e.value,t,n).suggested.length:0}c();function nc(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function rc(e){return e.map(e=>({id:e.deviceId,name:e.name,...e.meta===null?{}:{type:e.meta},...e.detail===null?{}:{location:e.detail.includes(` · `)?e.detail.split(` · `).at(-1)??null:e.detail},...e.detail===null?{}:{detail:e.detail}}))}function ic({open:t,title:r,selection:s,candidates:c,filters:l,room:u=null,confirmLabel:d,onConfirm:f,onClose:p}){let{t:m}=X(),[h,g]=o(null),[_,v]=o([]),y=l?.find(e=>e.id===h)??l?.[0]??null,b=c.kind===`known`?c.value:[],x=c.kind===`known`?Ea(c.value,``,y):[],S=$s(b,u,e=>e.deviceId).suggested,C=$s(x,u,e=>e.deviceId).others,w=n(()=>rc(C),[C]),T=nc(c),E=b.filter(e=>_.includes(e.deviceId));a(()=>{t||(v([]),g(null))},[t]);let D=()=>{v([]),g(null),p()},O=e=>{e.length!==0&&(f(e),v([]),g(null))},k=()=>O(E);return i(or,{open:t,onOpenChange:e=>e?void 0:D(),children:e(Xr,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(ni,{children:i(xn,{children:r})}),e(Wn,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[l!==void 0&&l.length>0&&i(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":m(`customize.assign.filtersLabel`),children:l.map(e=>i(`button`,{type:`button`,role:`tab`,"aria-selected":(y?.id??null)===e.id,className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${(y?.id??null)===e.id?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>g(e.id),children:m(e.labelKey)},e.id))}),u!==null&&i(Ui,{location:u.location,devices:S.map(e=>({id:e.deviceId,name:e.name,container:ec(u,e.deviceId),detail:e.detail})),action:`add`,onPick:e=>O(S.filter(t=>t.deviceId===e)),...s===`multi`?{onPickAll:()=>O(S)}:{}}),c.kind===`unknown`?i(`p`,{role:`alert`,className:`text-xs text-warning`,children:m(`customize.assign.unknown`,{reason:c.reason})}):w.length===0&&S.length>0?null:i(_t,{devices:w,listState:T,value:_,onChange:e=>v(s===`single`?e.length>0?[e[e.length-1]]:[]:e),noun:`device`,emptyLabel:m(`customize.assign.none`),showAll:!0,testId:`customize-device-picker`})]}),e(Qn,{children:[i(J,{variant:`ghost`,onClick:D,children:m(`customize.picker.cancel`)}),i(J,{disabled:E.length===0,onClick:k,children:d(E.length)})]})]})})}c();function ac(e,t){let r=typeof e==`string`&&e.length>0,i=Ii(t&&r);return n(()=>t?Qs(i,e):null,[t,i,e])}c();function oc(e){return e==null?null:e.message}function sc({device:t}){let n=pe(),{t:r}=X(),a=l(),s=da(),c=qe.includes(t.type),[u,f]=o(!1),[p,m]=o(!1),[h,g]=o(null),_=pr({deviceId:t.id},{enabled:c}),v=za({status:_.status,data:_.data,error:oc(_.error)===null?null:{message:oc(_.error)??``}}),y=v.kind===`present`?v.slot.slotRef:``,b=v.kind===`present`?[...La(v.slot,v.value).map(e=>e.deviceId),...Ia(v.slot,v.value)]:[],x=qn(),S=Ii(c&&v.kind===`present`&&(u||b.length>0)),C=ac(t.location,c&&v.kind===`present`),w=zr({deviceId:t.id,slotRef:y},{enabled:(u||C!==null)&&v.kind===`present`});if(!c||v.kind===`absent`)return null;if(v.kind!==`present`)return i(qs,{id:`linked`,icon:R,title:r(`customize.linked.title`),notices:v.kind===`pending`?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.assign.checking`)}):i(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:r(`customize.assign.unknown`,{reason:v.reason})}),children:null});let T=v.value,E=new Map(S.kind===`known`?S.value.map(e=>[e.id,e]):[]),D=T.trackedDeviceIds!==void 0,O=(e,t)=>{let n=E.get(e.deviceId);return{...e,name:e.name??n?.name??null,type:n?.type??null,detail:n===void 0?null:Da(n.integration,n.location),orphan:t}},k=[...La(v.slot,T).map(e=>O(e,!1)),...Ia(v.slot,T).map(e=>O({deviceId:e,name:null,health:`ok`,implied:!1,tracked:!0},!0))],A=new Set(b),j=S.kind===`unknown`?S:w.status===`error`?{kind:`unknown`,reason:oc(w.error)??r(`helpers.customize.requestFailed`)}:S.kind===`pending`||w.status===`pending`||w.data===void 0?{kind:`pending`}:{kind:`known`,value:Va(w.data.candidates,E,A)},M=async e=>{if(p){g(r(`customize.saveInFlight`));return}m(!0),g(null);try{await x.mutateAsync({deviceId:t.id,slotRef:v.slot.slotRef,value:e}),await _.refetch(),await a.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){g(e instanceof Error?e.message:String(e))}finally{m(!1)}},ee=async e=>{await s(r(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await M(Ba(T,e.deviceId))},N=[{key:`device`,header:r(`customize.linked.device`),cell:t=>e(`div`,{className:`flex flex-col min-w-0`,children:[i(`span`,{className:`truncate text-xs text-foreground`,children:t.name??`#${t.deviceId}`}),t.detail!==null&&i(`span`,{className:`truncate text-[11px] text-foreground-subtle`,children:t.detail}),t.orphan&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:r(`customize.linked.notLinked`)}),t.health!==`ok`&&i(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:r(`customize.linked.health.${t.health}`)})]})},{key:`type`,header:r(`customize.linked.type`),headerClassName:`hidden sm:table-cell`,cellClassName:`hidden sm:table-cell text-xs text-foreground-subtle`,cell:e=>e.type===null?`—`:zn(e.type,n).label},{key:`controls`,header:r(`customize.linked.controls`),headerClassName:`hidden md:table-cell`,cellClassName:`hidden md:table-cell text-xs text-foreground-subtle`,cell:e=>e.orphan?`—`:r(`customize.linked.yes`)},...D?[{key:`tracked`,header:r(`customize.linked.tracked`),cellClassName:`text-right`,headerClassName:`text-right`,cell:e=>i(Pr,{checked:e.tracked,disabled:p,"aria-label":r(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void M(Ra(T,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:i(gr,{icon:ce,variant:`ghost`,size:`sm`,"aria-label":r(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:p,onClick:t=>{t.stopPropagation(),ee(e)}})}];return e(d,{children:[i(qs,{id:`linked`,icon:R,title:r(`customize.linked.title`),addLabel:r(`customize.linked.add`),onAdd:p?void 0:()=>f(!0),...C===null?{}:{suggestion:{count:tc(j,C,e=>e.deviceId),location:C.location,onOpen:()=>f(!0)}},notices:e(d,{children:[S.kind===`unknown`&&i(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:r(`customize.assign.devicesUnreadable`,{reason:S.reason})}),h!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:h})]}),children:e(`li`,{className:`list-none px-3 py-2 sm:px-4`,children:[k.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`customize.assign.none`)}):i(yr,{mode:`generic`,items:k,getKey:e=>String(e.deviceId),getSearchText:e=>[e.name??``,e.detail??``,e.type??``,String(e.deviceId)].join(` `),getFilterType:e=>e.type===null?null:zn(e.type,n).label,columns:N,searchPlaceholder:r(`customize.assign.search`),emptyLabel:r(`customize.assign.none`)}),k.some(e=>!e.orphan)&&i(`p`,{className:`mt-2 text-[10px] text-foreground-subtle`,children:r(`customize.linked.controlsAlways`)}),D&&i(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:r(`customize.linked.trackedHint`)})]})}),i(ic,{open:u,title:r(`customize.linked.pickTitle`),selection:`multi`,candidates:j,room:C,confirmLabel:e=>r(`customize.assign.addCount`,{count:e}),onConfirm:e=>{f(!1),M(Fa(T,e.map(e=>e.deviceId)))},onClose:()=>f(!1)})]})}c();function cc(e){return e instanceof Error?e.message:String(e)}function lc(e){let n=Ft({addonId:e.addonId,stableId:e.stableId}),r=vt(),i=pn(),a=jn(),s=Ta({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}}),{t:c}=X(),l=t(!1),[u,d]=o(!1),f=async e=>{let t=qi(s,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:cc(e)}}};return{target:e,state:s,saving:u||r.isPending||i.isPending||a.isPending,save:async e=>{if(l.current)return{kind:`refused`,reason:c(`customize.saveInFlight`)};l.current=!0,d(!0);try{return await f(e)}finally{l.current=!1,d(!1)}}}}var uc=`pipeline-orchestrator`;function dc(e){return e.data===void 0?e.status===`pending`?`pending`:e.status===`error`?`unknown`:`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function fc(e,t){return e===`absent`?`absent`:dc(t)}async function pc(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function mc(e,t){let n=rn(uc),r=dr({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>pc(r.refetch),a=r.data===void 0&&r.status===`error`?r.error?.message??null:null;return t?{presence:fc(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,failureReason:a,refetch:i}:{presence:`absent`,status:null,failureReason:null,refetch:i}}function hc(e,t){let n=Mr({deviceType:e.type}),r=En({deviceId:e.id}),i=_r({deviceId:e.id}),a=ea(n,e=>new Set(e.caps.map(e=>e.cap))),o=ea(r,e=>Qi(e.entries)),s=ea(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}function gc(e,t,n){let r=t.kind===`known`&&t.value.has(`consumables`),i=Fi(r?{deviceId:e,cap:oa,path:Ca}:null);return Zi(t,n,r?i:null)}var _c=`ir-transmitter`;function vc(e,t){let n=new Map(t.customButtons.map(e=>[Te(e.key),e.name])),r=new Map;for(let t of e?.buttons??[])t.label!==void 0&&!r.has(t.role)&&r.set(t.role,t.label);let i=new Set,a=[],o=(e,t)=>{if(i.has(e))return;i.add(e);let o=Me(e)!==null;a.push({role:e,custom:o,inLayout:t,name:o?n.get(e)??r.get(e)??Ua(e):null})};for(let t of e?.buttons??[])o(t.role,!0);for(let e of n.keys())o(e,!1);for(let e of Object.keys(t.bindings))o(e,!1);return a}function yc(e,t,n){let r=Me(t);if(r===null||e.customButtons.some(e=>e.key===r))return e;let i={key:r,name:n};return{...e,customButtons:[...e.customButtons,i]}}function bc(e,t,n,r=Ua(t)){return yc({...e,bindings:{...e.bindings,[t]:{action:n}}},t,r)}function xc(e,t){let n=Object.fromEntries(Object.entries(e.bindings).filter(([e])=>e!==t)),r=Me(t);return{...e,bindings:n,customButtons:r===null?e.customButtons:e.customButtons.filter(e=>e.key!==r)}}function Sc(e){return e.deviceId>0&&e.cap!==``&&e.method!==``}var Cc={kind:`cap`,deviceId:0,cap:``,method:``};function wc(e){let{action:t}=e;return t.cap===`ir-transmitter`&&t.method===`send`?t.deviceId:null}function Tc(e,t){return{action:{...e.action,deviceId:t}}}function Ec(e){let t=Object.entries(e.bindings).filter(([,e])=>!Sc(e.action)).map(([e])=>e);if(t.length>0)return{incomplete:t,config:null};let n=Ze.safeParse(e);return{incomplete:t,config:n.success?n.data:null}}function Dc(e,t){if(t===null||t<=0)return{status:`refused`,reason:`no-transmitter`};let n;try{n=JSON.parse(e)}catch{return{status:`refused`,reason:`not-json`}}try{let e=Ue(n),r=Be(e.table,{transmitterDeviceId:t}),i=[...e.skipped.map(e=>({name:e.name,reason:e.reason})),...r.skipped];return{status:`ok`,draft:r,bound:Object.keys(r.bindings).length,skipped:i}}catch(e){if(e instanceof Re)return{status:`refused`,reason:`not-smartir`};throw e}}function Oc(e,t){let n=new Set(e.customButtons.map(e=>e.key));return{...e,bindings:{...e.bindings,...t.bindings},customButtons:[...e.customButtons,...t.customButtons.filter(e=>!n.has(e.key))],power:{mode:t.power.mode}}}c();function kc({role:t,binding:n,devices:r,transmitters:a,testable:s,testResult:c,onBind:l,onClear:u,onTest:f}){let{t:p}=X(),[m,h]=o(!1),g=t.name??p(`remote.role.${t.role}`,Ua(t.role)),_=n===void 0?null:wc(n),v=n!==void 0&&Sc(n.action),y=m||n!==void 0&&_===null;return e(`li`,{className:`space-y-2 rounded border border-border bg-surface p-2`,"data-testid":`binding-${t.role}`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:g}),t.custom&&i(q,{variant:`neutral`,children:p(`remote.bindings.custom`)}),!t.inLayout&&i(q,{variant:`warning`,children:p(`remote.bindings.notInLayout`)}),_!==null&&i(q,{variant:`info`,children:p(`remote.bindings.infrared`)}),n===void 0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:p(`remote.bindings.native`)}),e(`div`,{className:`ml-auto flex items-center gap-1`,children:[n===void 0&&!m&&i(J,{size:`sm`,variant:`outline`,onClick:()=>{h(!0),l(Cc)},"data-testid":`bind-${t.role}`,children:p(`remote.bindings.bind`)}),n!==void 0&&e(d,{children:[i(J,{size:`sm`,variant:`outline`,disabled:!s||!v,title:s?void 0:p(`remote.bindings.saveToTest`),onClick:f,"data-testid":`test-${t.role}`,children:p(`remote.bindings.test`)}),i(J,{size:`sm`,variant:`ghost`,onClick:()=>{h(!1),u()},"data-testid":`clear-${t.role}`,children:p(`remote.bindings.clear`)})]})]})]}),_!==null&&n!==void 0&&i(Sn,{"aria-label":p(`remote.bindings.transmitterFor`,{name:g}),value:String(_),options:a.map(e=>({value:String(e.id),label:e.name})),onChange:e=>l(Tc(n,Number(e.target.value)).action),"data-testid":`transmitter-${t.role}`}),y&&_===null&&n!==void 0&&i(Mi,{step:n.action,devices:r,variables:[],onChange:e=>{typeof e.deviceId==`number`&&l({...e,deviceId:e.deviceId})}}),c!==null&&i(`p`,{role:`status`,className:`text-xs text-foreground-muted`,"data-testid":`result-${t.role}`,children:c})]})}c();function Ac({transmitterId:n,onApply:r}){let{t:a}=X(),s=t(null),[c,l]=o(``),[u,d]=o(null),[f,p]=o(null),m=e=>{p(e.trim()===``?null:Dc(e,n))},h=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t===void 0)return;d(t.name);let n=await t.text();l(n),m(n)};return e(`div`,{className:`space-y-2`,"data-testid":`smartir-import`,children:[i(`p`,{className:`text-xs text-foreground-muted`,children:a(`remote.import.hint`)}),i(wt,{label:a(`remote.import.pasteLabel`),children:i(`textarea`,{value:c,rows:5,onChange:e=>{l(e.target.value),d(null),p(null)},className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`,"data-testid":`smartir-text`})}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`input`,{ref:s,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:e=>void h(e),"data-testid":`smartir-file`}),e(J,{size:`sm`,variant:`outline`,onClick:()=>s.current?.click(),children:[i(dt,{className:`mr-1 h-3 w-3`,"aria-hidden":!0}),a(`remote.import.chooseFile`)]}),u!==null&&i(`span`,{className:`truncate font-mono text-[11px] text-foreground-subtle`,children:u}),i(J,{size:`sm`,variant:`secondary`,disabled:c.trim()===``,onClick:()=>m(c),"data-testid":`smartir-read`,children:a(`remote.import.read`)})]}),f?.status===`refused`&&i(`p`,{role:`alert`,className:`text-xs text-danger`,"data-testid":`smartir-refused`,children:a(`remote.import.refused.${f.reason}`)}),f?.status===`ok`&&e(`div`,{className:`space-y-2`,"data-testid":`smartir-summary`,children:[i(`p`,{className:`text-xs text-foreground`,children:a(`remote.import.summary`,{count:f.bound})}),f.skipped.length>0&&e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs text-warning`,children:a(`remote.import.skipped`,{count:f.skipped.length})}),i(`ul`,{className:`max-h-24 space-y-0.5 overflow-y-auto text-[11px] text-foreground-muted`,children:f.skipped.map(t=>e(`li`,{children:[t.name,` — `,t.reason]},`${t.name}:${t.reason}`))})]}),i(J,{size:`sm`,disabled:f.bound===0,onClick:()=>{r(f.draft),l(``),d(null),p(null)},"data-testid":`smartir-apply`,children:a(`remote.import.apply`)})]})]})}c();function jc({device:t,open:n,onClose:r}){let{t:a}=X(),o=tr({deviceId:t.id},{enabled:n});return i(or,{open:n,onOpenChange:e=>!e&&r(),children:e(Xr,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(ni,{children:i(xn,{children:a(`remote.dialog.title`,{name:t.name})})}),o.data===void 0?i(Wn,{children:o.status===`error`?i(K,{title:a(`remote.dialog.unreadable`),message:o.error?.message??``,onRetry:()=>void o.refetch()}):i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`remote.dialog.loading`)})}):i(Nc,{device:t,initial:o.data,onClose:r})]})})}function Mc(e,t){switch(e.status){case`sent`:return t(`remote.test.sent`,{count:e.sends});case`skipped`:return t(`remote.test.skipped`);case`refused`:return t(`remote.test.refused.${e.reason}`,{detail:e.detail??``})}}function Nc({device:t,initial:r,onClose:a}){let{t:s}=X(),c=l(),[u,f]=o(r),[p,m]=o(null),[h,g]=o({}),_=In({kind:`remote`}),v=Tr({deviceId:t.id}),y=Ni(),b=dn({capNames:[_c]}),x=ir(),S=Jr(),C=n(()=>{let e=new Set(b.data??[]);return y.filter(t=>e.has(t.id))},[y,b.data]),w=(_.data??[]).find(e=>e.id===u.layoutTemplateId),T=w===void 0?null:Ha(w.payload),E=n(()=>vc(T,u),[T,u]),D=n(()=>new Set((v.data?.commands??[]).map(e=>e.role)),[v.data]),O=Ec(u),k=n(()=>new Set(Object.keys(u.bindings)),[u.bindings]),A=async()=>{if(O.config!==null){m(null);try{let e=await x.mutateAsync({deviceId:t.id,config:O.config});if(e.status===`refused`){m(e.detail);return}await c.invalidateQueries({queryKey:[[`remote`]]}),a()}catch(e){m(e instanceof Error?e.message:String(e))}}},j=async e=>{try{let n=await S.mutateAsync({deviceId:t.id,role:e,repeat:1});g(t=>({...t,[e]:Mc(n,s)}))}catch(t){g(n=>({...n,[e]:t instanceof Error?t.message:String(t)}))}},M=(e,t)=>f(n=>bc(n,e,t));return e(d,{children:[e(Wn,{className:`space-y-5`,children:[e(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[i(wt,{label:s(`remote.dialog.template`),children:i(Sn,{value:u.layoutTemplateId??``,options:[{value:``,label:s(`remote.dialog.noTemplate`)},...(_.data??[]).map(e=>({value:e.id,label:e.name}))],onChange:e=>f(t=>({...t,layoutTemplateId:e.target.value===``?null:e.target.value})),"data-testid":`remote-template`})}),i(wt,{label:s(`remote.dialog.transmitter`),children:i(Sn,{value:u.defaultTransmitterId===null?``:String(u.defaultTransmitterId),options:[{value:``,label:s(`remote.dialog.noTransmitter`)},...C.map(e=>({value:String(e.id),label:e.name}))],onChange:e=>f(t=>({...t,defaultTransmitterId:e.target.value===``?null:Number(e.target.value)})),"data-testid":`remote-transmitter`})}),i(wt,{label:s(`remote.dialog.power`),children:i(Sn,{value:u.power.mode,options:[{value:`toggle`,label:s(`remote.dialog.powerToggle`)},{value:`discrete`,label:s(`remote.dialog.powerDiscrete`)}],onChange:e=>f(t=>({...t,power:{mode:e.target.value===`discrete`?`discrete`:`toggle`}})),"data-testid":`remote-power`})})]}),_.data!==void 0&&_.data.length===0&&i(`p`,{className:`text-xs text-foreground-muted`,children:s(`remote.dialog.noTemplatesHint`)}),T!==null&&i(`div`,{className:`mx-auto w-full max-w-xs`,"data-testid":`remote-preview`,children:i(Wa,{grid:T,label:s(`remote.dialog.preview`),boundRoles:k})}),e(`section`,{className:`space-y-2`,children:[i(`h3`,{className:`text-sm font-medium text-foreground`,children:s(`remote.import.title`)}),i(Ac,{transmitterId:u.defaultTransmitterId,onApply:e=>f(t=>Oc(t,e))})]}),e(`section`,{className:`space-y-2`,children:[i(`h3`,{className:`text-sm font-medium text-foreground`,children:s(`remote.bindings.title`)}),E.length===0?i(`p`,{className:`text-xs text-foreground-muted`,children:s(`remote.bindings.empty`)}):i(`ul`,{className:`space-y-2`,children:E.map(e=>i(kc,{role:e,binding:u.bindings[e.role],devices:y,transmitters:C,testable:D.has(e.role),testResult:h[e.role]??null,onBind:t=>M(e.role,t),onClear:()=>f(t=>xc(t,e.role)),onTest:()=>void j(e.role)},e.role))})]}),O.incomplete.length>0&&i(`p`,{role:`alert`,className:`text-xs text-warning`,"data-testid":`remote-incomplete`,children:s(`remote.dialog.incomplete`,{count:O.incomplete.length})}),p!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger`,children:p})]}),e(Qn,{children:[i(J,{variant:`ghost`,onClick:a,children:s(`common.cancel`)}),i(J,{disabled:O.config===null||x.isPending,onClick:()=>void A(),"data-testid":`remote-save`,children:s(`common.save`)})]})]})}c();function Pc({device:t}){let{t:n}=X(),[r,a]=o(!1),s=tr({deviceId:t.id}),c=In({kind:`remote`}),l=s.data,u=l===void 0?0:Object.keys(l.bindings).length,d=l?.layoutTemplateId==null?null:(c.data??[]).find(e=>e.id===l.layoutTemplateId)?.name??null;return e(Hi,{id:`remote`,title:n(`remote.card.title`),icon:h,testId:`customize-remote`,actions:i(J,{size:`sm`,variant:`outline`,onClick:()=>a(!0),"data-testid":`remote-open`,children:n(`remote.card.configure`)}),children:[s.status===`error`?i(`p`,{role:`alert`,className:`text-xs text-danger`,children:s.error?.message??n(`remote.dialog.unreadable`)}):l===void 0?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`remote.dialog.loading`)}):i(`p`,{className:`text-xs text-foreground-muted`,"data-testid":`remote-summary`,children:u===0&&d===null?n(`remote.card.none`):n(`remote.card.summary`,{template:d??n(`remote.dialog.noTemplate`),count:u})}),r&&i(jc,{device:t,open:r,onClose:()=>a(!1)})]})}var Fc={remote:Pc};function Ic(e){let t=[];for(let[n,r]of Object.entries(Ee))r.targets.some(t=>t.cardinality===`config`&&t.deviceTypes.includes(e))&&t.push(n);return t}function Lc({device:e}){return Ic(e.type).map(t=>{let n=Fc[t];return n===void 0?null:i(n,{device:e},t)})}function Rc(e,t){switch(e.kind){case`group`:return e.active===null?t(`helper.aggregate.${e.aggregate}`):t(`helper.active.${e.active}`);case`statistic`:return t(`helper.statName.${e.stat}`);case`integral`:case`threshold`:case`derivative`:return t(`helper.template.${e.kind}`);case`arithmetic`:return t(`helper.template.${e.op}`);case`expression`:return e.expr}}function zc(e,t){switch(e.kind){case`integral`:return[{label:t(`helper.reset`),value:t(`helper.resetName.${e.reset}`)}];case`threshold`:return[{label:t(`helper.highEdge`),value:String(e.high)},{label:t(`helper.lowEdge`),value:String(e.low)}];case`derivative`:return[{label:t(`helper.per`),value:t(`helper.perName.${e.per}`)}];default:return[]}}function Bc({draft:t,device:n,onEdit:r}){let{t:a,i18n:o}=X(),s=xi(),c=aa(t),l=zc(t,e=>a(e));return i(Tn,{headingId:`helper-summary-${n.id}`,title:a(`customize.composed.helper.title`),testId:`helper-summary`,actions:e(J,{variant:`outline`,size:`sm`,onClick:r,"data-testid":`helper-summary-edit`,children:[i(N,{className:`h-3 w-3`,"aria-hidden":!0}),a(`common.edit`)]}),children:e(`div`,{className:f,children:[i(kt,{label:a(`customize.composed.helper.function`),children:Rc(t,e=>a(e))}),l.map(e=>i(kt,{label:e.label,children:e.value},e.label)),c.length>0&&i(kt,{label:a(`customize.composed.helper.members`),children:i(`ul`,{className:`flex flex-col gap-0.5`,"data-testid":`helper-summary-members`,children:c.map(t=>{let n=s.data?.find(e=>e.addonId===t.source.addonId&&e.stableId===t.source.stableId);return e(`li`,{className:`flex flex-wrap items-baseline gap-x-1.5`,children:[n===void 0?i(`span`,{children:t.source.stableId}):i(yn,{device:n,form:`compact`}),i(`span`,{className:`text-foreground-muted`,children:_a(t.cap,t.fieldPath,o.language)})]},`${t.source.addonId}:${t.source.stableId}:${t.cap}:${t.fieldPath}`)})})})]})})}c();function Vc({device:t}){let{t:r}=X(),a=t.stableId.startsWith(`composed-`)?t.stableId.slice(Qe.length):null,s=Nn({blockId:a??``},{enabled:a!==null}),c=pn(),[l,u]=o(!1),d=n(()=>{let e=new Set;for(let{cap:t}of ia())e.add(t);for(let{cap:t}of wa())e.add(t);for(let{cap:t}of Ji())e.add(t);for(let n of Ic(t.type))e.add(n);return e},[t.type]);if(a===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`customize.composed.missingBlock`)});if(s.status===`pending`)return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.loadingDevice`)});if(s.status===`error`)return i(K,{title:r(`customize.composed.loadFailed`),message:s.error.message,onRetry:()=>void s.refetch()});if(s.data.state===`not-loaded`)return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.status.notLoaded`,{reason:s.data.reason})});let f=s.data.view;if(f===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`customize.composed.notFound`)});let p=G(f.block);if(p===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`compositionEditor.notComposition`)});if(sa(p)){let n=ua(p.helper,t.name,t.location??``);return n===null?i(`p`,{role:`alert`,children:r(`helper.unreadable`)}):e(`div`,{className:`flex flex-col gap-3`,children:[i(ls,{device:t}),i(Bc,{draft:n,device:t,onEdit:()=>u(!0)}),i(Pi,{blockId:l?f.block.id:null,onClose:()=>{u(!1),s.refetch()}})]})}let m={target:{addonId:t.addonId,stableId:t.stableId},state:{kind:`present`,view:f,composition:p},saving:c.isPending,save:async e=>{if(e===null)return{kind:`refused`,reason:r(`customize.composed.noDelete`)};try{return await c.mutateAsync({blockId:f.block.id,expectedUpdatedAt:f.block.updatedAt,block:{composition:e}}),await s.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:e instanceof Error?e.message:String(e)}}}};return e(`div`,{className:`flex flex-col gap-3`,children:[i(ls,{device:t}),Gi(p)===`incomplete`&&i(q,{variant:`warning`,children:r(`customize.blockStatus.incomplete`)}),i(Lc,{device:t}),i(fa,{device:t,handle:m,skipCaps:d})]})}c();function Hc({deviceId:e}){let{t}=X(),n=ln({deviceId:e}),r=n.data;if(r==null)return n.status===`error`?i(K,{title:t(`customize.deviceUnreadable`),message:n.error?.message??``,onRetry:()=>void n.refetch()}):r===null?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.noSuchDevice`,{deviceId:e})}):i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.loadingDevice`)});let a=r.addonId===`composer`?i(Vc,{device:r}):i(Uc,{device:r,target:{addonId:r.addonId,stableId:r.stableId}});return i(vi,{deviceId:r.id,seed:{name:r.name,location:r.location??``,role:r.role??null,display:r.display},children:a})}function Uc({device:t,target:r}){let a=lc(r),o=rn(`composer`),{t:s}=X(),c=mc(t.id,t.type===U.Camera),l=hc(t,Xi(a.state)),u=gc(t.id,l.nativeCaps,l.wireable),d={deviceType:t.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},f=n(()=>{let e=new Set;for(let{cap:t}of ia())e.add(t);for(let{cap:t}of wa())e.add(t);for(let{cap:t}of Ji())e.add(t);for(let n of Ic(t.type))e.add(n);return e},[t.type]);return e(`div`,{className:`flex flex-col gap-3`,children:[i(ls,{device:t}),o===`absent`&&i(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),a.state.kind!==`none`&&i(Wc,{state:a.state}),i(Ks,{device:t,handle:a,facts:d,sensors:c}),i(la,{device:t,handle:a,facts:d}),i(xa,{device:t,handle:a,facts:d,defaults:u}),i(Lc,{device:t}),i(fa,{device:t,handle:a,skipCaps:f}),i(sc,{device:t}),t.type===U.Camera&&i(Zs,{device:t})]})}function Wc({state:t}){let{t:n}=X();switch(t.kind){case`pending`:return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.status.pending`)});case`unknown`:return i(K,{title:n(`customize.status.unknownTitle`),message:t.reason});case`not-loaded`:return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.status.notLoaded`,{reason:t.reason})});case`none`:return null;case`present`:{let r=t.view.block;return e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(q,{variant:r.status===`running`?`success`:r.status===`failed`?`danger`:`warning`,children:n(`customize.blockStatus.${r.status}`)}),!r.enabled&&i(q,{variant:`default`,children:n(`customize.status.off`)}),r.lastError!==void 0&&i(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:r.lastError}),t.view.state.kind===`unreachable`&&i(`span`,{className:`text-[11px] text-warning`,children:n(`customize.status.composerUnreachable`,{reason:t.view.state.error})})]})}}}var Gc=`overview`;function Kc(e,t){return e.some(e=>e.id===t)?t:Gc}function qc({deviceId:t}){let{t:n}=X(),r=l(),a=Number.isFinite(t),{data:o}=ln({deviceId:t},{enabled:a}),s=typeof o?.type==`string`?o.type:`camera`;Ir([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:c,isLoading:u,isError:d,error:f}=En({deviceId:t},{enabled:a}),{data:p}=on({deviceType:s},{enabled:!!s}),m=Jn({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(u)return i(`div`,{className:`p-4`,children:i(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(d)return e(`div`,{className:`p-4 text-xs text-red-400`,children:[n(`device.bindingsTab.failedToLoadBindings`,`Failed to load bindings:`),` `,f instanceof Error?f.message:String(f)]});let h=new Map,g={};for(let e of p??[])g[e.capName]=e.wrappers;for(let e of c?.entries??[])h.set(e.capName,{...e,wrappers:g[e.capName]??[]});for(let e of p??[])h.has(e.capName)||h.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let _=[...h.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(_.length===0)return e(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[i(ct,{className:`h-8 w-8 opacity-40`}),i(`p`,{className:`text-xs`,children:n(`device.bindingsTab.noCapabilityProvidersApplicableTo`,`No capability providers applicable to this device yet.`)}),i(`p`,{className:`text-[10px] opacity-60`,children:n(`device.bindingsTab.nativeProvidersShowUpHere`,`Native providers show up here as soon as the owning addon registers them.`)})]});let v=_.filter(e=>e.kind!==`unbound`).length,y=[{key:`capability`,header:n(`device.bindingsTab.capability`,`Capability`),render:e=>i(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:n(`device.bindingsTab.kind`,`Kind`),render:e=>i(Jc,{kind:e.kind})},{key:`provider`,header:n(`device.bindingsTab.activeProvider`,`Active Provider`),render:e=>i(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||i(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:n(`device.bindingsTab.node`,`Node`),render:e=>e.providerNodeId?i(Yc,{nodeId:e.providerNodeId}):i(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:n(`device.bindingsTab.kindNative`,`Native`),render:e=>i(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||i(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:n(`device.bindingsTab.wrapper`,`Wrapper`),render:e=>{let n=e.kind===`wrapped`?e.providerAddonId:null;return i(Xc,{wrappers:e.wrappers,activeWrapperId:n,disabled:m.isPending,onPick:r=>{let i=n===r;m.mutate({deviceId:t,capName:e.capName,wrapperAddonId:r,active:!i})}})}}];return e(`div`,{className:`flex flex-col gap-3 p-1`,children:[i(`div`,{className:`text-[11px] text-foreground-subtle`,children:i(Ti,{i18nKey:`device.bindingsTab.boundSummary`,count:_.length,values:{bound:v},components:{b:i(`span`,{className:`font-medium text-foreground`}),em:i(`em`,{})}})}),i(Et,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function Jc({kind:t}){let{t:n}=X();return t===`native`?e(`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:[i(ie,{className:`h-3 w-3`}),n(`device.bindingsTab.kindNative`)]}):t===`wrapped`?e(`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:[i(ft,{className:`h-3 w-3`}),n(`device.bindingsTab.wrapped`)]}):t===`linked`?e(`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:[i(R,{className:`h-3 w-3`}),n(`device.bindingsTab.linked`)]}):e(`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:[i(oe,{className:`h-3 w-3`}),n(`common.unbound`)]})}function Yc({nodeId:e}){return i(`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 Xc({wrappers:t,activeWrapperId:n,disabled:r,onPick:a}){let{t:o}=X();return t.length===0?i(`span`,{className:`text-[10px] opacity-40`,children:o(`device.bindingsTab.noneAvailable`,`none available`)}):i(`div`,{className:`flex flex-wrap gap-1`,children:t.map(t=>{let s=t===n;return e(`button`,{disabled:r,onClick:()=>a(t),title:s?o(`device.bindingsTab.clickToDeactivateRevertTo`,`Click to deactivate (revert to native)`):o(`device.bindingsTab.activateWrapper`,`Activate wrapper {{wrapperId}}`,{wrapperId:t}),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 ${s?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[i(s?D:j,{className:`h-3 w-3`}),t]},t)})})}function Zc({deviceId:t,activeSubTab:n,onSubTabChange:r,deviceType:a,isAdmin:o}){return e(`div`,{className:`flex flex-col gap-3`,children:[yi(a,o)&&i(Qr,{deviceId:t,readOnly:!0}),i(bi,{deviceId:t,activeSubTab:n,onSubTabChange:r})]})}c();var Qc=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function $c(e){let t=l(),n=Er({deviceId:e},{refetchOnMount:`always`}),i=wn(),[a,s]=o(null),[c,u]=o(null),d=r(async n=>{u(null),s(n);try{await i.mutateAsync({deviceId:e,source:n}),await t.invalidateQueries({queryKey:Qc})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await t.invalidateQueries({queryKey:Qc})}finally{s(null)}},[e,i,t]),f=n.data??null;return{view:f,isLoading:n.isLoading,source:a??f?.source??null,saving:a!==null,error:c,pick:d}}var el=`object-detection`;function tl(e){return[e.addonId,...e.children.flatMap(tl)]}function nl(e,t){if(e===`pipeline`)return new Set;let n=rl(t,el);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:tl(n))}function rl(e,t){for(let n of e){if(n.addonId===t)return n;let e=rl(n.children,t);if(e!==void 0)return e}}function il(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.badgeCameraAi`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.badgeNoRoot`):Y.t(`helpers.detectionSourceModel.badgeIdle`)}function al(e){switch(e){case`pipeline`:return Y.t(`helpers.detectionSourceModel.explainPipeline`);case`onboard`:return Y.t(`helpers.detectionSourceModel.explainOnboard`);case`none`:return Y.t(`helpers.detectionSourceModel.explainNone`)}}function ol(e){switch(e){case`boxed`:return``;case`while-streaming`:return Y.t(`helpers.detectionSourceModel.geometryWhileStreaming`);case`flag-only`:return Y.t(`helpers.detectionSourceModel.geometryFlagOnly`);case`unknown`:return Y.t(`helpers.detectionSourceModel.geometryUnknown`)}}function sl(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.noticeOnboard`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.noticeNoRoot`):Y.t(`helpers.detectionSourceModel.noticeIdle`)}var cl=[`pl-2`,`pl-6`,`pl-10`,`pl-14`],ll={detector:`success`,cropper:`info`,classifier:`primary`,refiner:`warning`,"audio-classifier":`neutral`};function ul(e){return cl[Math.min(e,cl.length-1)]??`pl-2`}function dl(e){return e.zoneDriven?{kind:`zone-driven`}:{kind:`gate`,effectiveOn:e.ownOn,defaultOn:e.defaultOn,explicit:e.choice!==`auto`}}function fl(e,t,n){return e.kind===`parent`?n:il(e.source,t)}function pl({inputs:t,outputs:n}){return t.length===0&&n.length===0?null:e(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[t.map(e=>i(q,{size:`sm`,variant:`info`,children:e},`in-${e}`)),t.length>0&&n.length>0&&i(`span`,{className:`text-[10px] text-foreground-subtle`,"aria-hidden":!0,children:`→`}),n.map(e=>i(q,{size:`sm`,variant:`success`,children:e},`out-${e}`))]})}function ml({rows:t,label:n,selectedId:r,busy:a,onOpen:o,onSet:s}){let{t:c}=X(),l=e=>{switch(e){case`detector`:return c(`device.cameraStepInspector.kindDetector`,`detector`);case`cropper`:return c(`device.cameraStepInspector.kindCropper`,`cropper`);case`classifier`:return c(`device.cameraStepInspector.kindClassifier`,`classifier`);case`refiner`:return c(`device.cameraStepInspector.kindRefiner`,`refiner`);case`audio-classifier`:return c(`device.cameraStepInspector.kindAudio`,`audio`)}},u=c(`device.cameraStepInspector.offBecauseParent`,`Off because its parent is off`);return i(`ul`,{"aria-label":n,className:`divide-y divide-border rounded-md border border-border`,children:t.map(t=>{let n=t.stepId===r,c=t.blocked===null?null:fl(t.blocked,t.stepId,u);return e(`li`,{"data-step":t.stepId,"data-runs":t.runs?`yes`:`no`,className:`flex flex-wrap items-center gap-x-2 gap-y-1.5 py-2 pr-2 ${ul(t.depth)} ${n?`bg-primary/10`:t.runs?``:`bg-muted/40`}`,children:[e(`button`,{type:`button`,"aria-expanded":n,onClick:()=>o(t.stepId),className:`flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1 text-left`,children:[i(`span`,{className:`text-sm font-medium ${t.runs?`text-foreground`:`text-foreground-muted`}`,children:t.name}),i(q,{size:`sm`,variant:ll[t.kind],children:l(t.kind)}),i(pl,{inputs:t.inputs,outputs:t.outputs}),c!==null&&i(`span`,{className:`text-[11px] text-warning`,children:c})]}),i(Ar,{gate:dl(t),busy:a,onSet:e=>s(t.stepId,e)})]},t.stepId)})})}function hl(e,t){let n=e?.[t];return n===void 0?`auto`:n?`on`:`off`}function gl(e,t){return e===`auto`?t:e===`on`}function _l(e,t,n){return e!==`onboard`&&e!==`none`||!n.has(t)?null:{kind:`source`,source:e}}function vl(e,t,n,r,i){let a=e.zoneDrivenIds??new Set;return t.flatMap(t=>{let o=a.has(t.addonId),s=hl(e.toggles,t.addonId),c=e.defaults[t.addonId]??!0,l=o||gl(s,c),u=r===null?_l(e.source,t.addonId,i):{kind:`parent`,ancestorId:r.stepId},d={stepId:t.addonId,name:t.addonName,kind:t.slot,depth:n,inputs:t.inputClasses,outputs:t.outputClasses,choice:s,defaultOn:c,ownOn:l,runs:u===null&&l,blocked:u,zoneDriven:o},f=l?r:{stepId:t.addonId};return[d,...vl(e,t.children,n+1,f,i)]})}function yl(e){let t=e.source===null?new Set:nl(e.source,e.tree);return vl(e,e.tree,0,null,t)}function bl({source:t,geometry:n,saving:r,error:a,onPick:o}){let{t:s}=X(),c=n===`flag-only`,l=ol(n);return e(`section`,{"aria-label":s(`device.detectionSourceControl.rootDetector`,`Root detector`),"aria-busy":r,className:`space-y-1.5 rounded-md border border-border bg-surface px-3 py-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[i(`h3`,{className:ee,children:s(`device.detectionSourceControl.rootDetector`,`Root detector`)}),i(Yn,{label:s(`device.detectionSourceControl.rootDetector`,`Root detector`),value:t,onChange:e=>{!r&&e!==t&&o(e)},options:[{value:`pipeline`,label:s(`device.detectionSourceControl.thisNode`,`This node`)},{value:`onboard`,label:s(`device.detectionSourceControl.cameraOnboardAi`,`Camera onboard AI`),disabled:c&&t!==`onboard`,reason:l},{value:`none`,label:s(`device.detectionSourceControl.none`,`None`)}]}),r&&i(`span`,{className:`text-[10px] text-foreground-subtle`,children:s(`device.detectionSourceControl.saving`,`Saving…`)})]}),e(`p`,{className:H,children:[al(t),` `,s(`device.detectionSourceControl.oneRoot`)]}),l!==``&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:l}),a!==null&&i(`p`,{role:`alert`,className:`text-[11px] text-danger`,children:a})]})}c();var xl=new Set([`package-detection`]),Sl=`/system/pipeline?view=nodes`;function Cl(e){return Object.fromEntries(e.slots.flatMap(e=>e.addons.map(e=>[e.id,e.enabledByDefault??!0])))}function wl({deviceId:a}){let{t:c}=X(),u=ye(),d=Xt(),f=l(),p=I().trpcClient,m=t(null),h=t(null),g=Lr({deviceId:a},{refetchOnMount:`always`}),_=sr(void 0,{refetchOnMount:`always`});Ir([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:v}=Ln(),y=n(()=>{let e=new Set((_.data??[]).map(e=>e.nodeId));return v.filter(t=>t.isOnline&&e.has(t.id)).map(e=>({id:e.id,name:e.name}))},[_.data,v]),b=y.map(e=>e.id).join(`,`),x=s({enabled:y.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`camera-step-schemas`,b],queryFn:async()=>{let e={};for(let t of y)try{e[t.id]=await p.pipelineExecutor.getSchema.query({nodeId:t.id})}catch{}return e}}),S=r(()=>{f.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]})},[f]),C=cn({onSuccess:S}),w=Tt(),[T,E]=o(null),[D,O]=o(!1),[k,A]=o(null),j=$c(a),M=x.data??{},ee=g.data??null,N=y.map(e=>M[e.id]).find(e=>e!==void 0)??null,te=n(()=>N?fn(N):[],[N]),ne=n(()=>N===null?[]:yl({tree:te,toggles:ee?.stepToggles,defaults:Cl(N),source:j.source,zoneDrivenIds:xl}),[te,N,ee?.stepToggles,j.source]),{selection:re,open:P,close:ie}=ja(n(()=>ne.map(e=>e.stepId),[ne]),[]),F=y[0]?.id,ae=r(async e=>{if(T!==null){if(!await u({title:c(`stepInspector.stepMatrixFrame.discardUnsavedChanges`,`Discard unsaved changes?`),message:c(`stepInspector.stepMatrixFrame.thisStepHasChangesThat`,`This step has changes that are not saved yet.`),confirmLabel:c(`stepInspector.stepMatrixFrame.discard`,`Discard`),variant:`danger`}))return;E(null)}e()},[u,T,c]),oe=e=>{e!==re.stepId&&ae(()=>P({stepId:e}))},se=()=>{ae(()=>ie())};if(_.isLoading||y.length>0&&x.isLoading)return i(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.loadingPipeline`,`Loading pipeline…`)});if(y.length===0)return i(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.noPipelineNodeIsOnline`,`No pipeline node is online.`)});if(N===null)return i(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.catalogUnavailable`,`Catalog unavailable.`)});let L=e=>_.data?.find(e=>e.nodeId===F)?.settings.stepSettings?.[e]??{},R=ne.find(e=>e.stepId===re.stepId)??null,z=R===null?null:Aa(N,R.stepId),le=d?i(Dr,{onClick:se}):i(gr,{icon:ce,variant:`ghost`,size:`sm`,"aria-label":c(`common.close`,`Close`),onClick:se});return e(`div`,{ref:m,className:`space-y-2`,children:[j.view?.onboard.available===!0&&j.source!==null&&i(bl,{source:j.source,geometry:j.view.onboard.geometry,saving:j.saving,error:j.error,onPick:e=>void j.pick(e)}),i(`p`,{className:H,children:i(Ti,{i18nKey:`device.cameraStepInspector.modelsChosenByAccelerators`,components:{nodes:i(Si,{to:Sl,className:`font-medium text-primary hover:underline`})}})}),re.staleStepId!==null&&i(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:c(`stepInspector.stepMatrixFrame.staleStep`,{id:re.staleStepId})}),i(ml,{rows:ne,label:c(`device.cameraStepInspector.detectionStepsOfThisCamera`,`Detection steps of this camera`),selectedId:re.stepId,busy:C.isPending,onOpen:oe,onSet:(e,t)=>C.mutate({deviceId:a,addonId:e,enabled:t})}),i(mr,{open:R!==null&&z!==null,anchor:m,onClose:se,label:c(`stepInspector.stepMatrixFrame.stepSettings`,`Step settings`),children:R!==null&&z!==null&&i(Tl,{addon:z,nodeBag:L(R.stepId),storedCamera:ee?.stepSettings?.[R.stepId],draft:T?.stepId===R.stepId?T:null,saving:D,status:k,notice:R.blocked?.kind===`source`?sl(R.blocked.source,R.stepId):null,closeButton:le,onEscape:se,headingRef:e=>{h.current=e},onDraft:e=>{A(null),E({stepId:R.stepId,camera:e})},onDiscard:()=>E(null),onSave:async e=>{O(!0);try{await w.mutateAsync({deviceId:a,addonId:R.stepId,settings:Object.keys(e).length>0?{...e}:null}),E(null),A({kind:`saved`})}catch(e){A({kind:`error`,error:e instanceof Error?e.message:c(`device.cameraStepInspector.saveFailed`)})}finally{O(!1),S()}}})})]})}function Tl({addon:t,nodeBag:n,storedCamera:r,draft:a,saving:o,status:s,notice:c,closeButton:l,onEscape:u,headingRef:d,onDraft:f,onDiscard:p,onSave:m}){let{t:h}=X(),g=mn(t),_=Na(g),v=Ma(g),y=a?.camera??r,b=a!==null&&!ze(a.camera,r??{});return i(Wr,{ref:d,title:h(`device.cameraStepInspector.thisCamera`,`{{name}} · this camera`,{name:t.name}),subtitle:t.slot,leading:l,onEscape:u,..._.length>0?{saveBar:{dirtyCount:+!!b,saving:o,status:s?.kind??null,...s?.error===void 0?{}:{error:s.error},onSave:()=>void m(a?.camera??r??{}),onDiscard:p,scope:i(`p`,{className:H,children:h(`device.cameraStepInspector.appliesToAllAcceleratorsOf`,`Applies to: all accelerators of this camera.`)})}}:{},children:e(`div`,{className:`space-y-3`,children:[c!==null&&i(`p`,{role:`note`,className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:c}),_.length>0?i(El,{addon:t,fields:_,nodeBag:n,cameraBag:y,onChange:f}):i(`p`,{className:H,children:h(`device.cameraStepInspector.noCameraSettings`,`This step has no settings on this camera.`)}),v&&i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`accelerator-only-thresholds`,children:h(`device.cameraStepInspector.thresholdsAreTheAccelerators`,`Confidence thresholds belong to the model, so they are set on the accelerator that runs it (Pipeline → Nodes), not per camera.`)})]})})}function El({addon:e,fields:t,nodeBag:n,cameraBag:r,onChange:a}){let{t:o}=X();return i(mt,{addon:e,fields:t,layers:{node:n,...r===void 0?{}:{camera:r}},target:`camera`,labels:{camera:o(`device.cameraStepInspector.layerCamera`,`This camera`),node:o(`device.cameraStepInspector.layerNode`,`Node`)},modelId:e.defaultModelId,onChangeLayer:a})}function Dl(e,t,n){return{id:e,get label(){return Y.t(t)},icon:n}}var Ol=[Dl(`object-detection`,`helpers.detectionSettingsGroups.objectDetection`,`scan-search`),Dl(`tracking`,`helpers.detectionSettingsGroups.tracking`,`route`),Dl(`motion`,`helpers.detectionSettingsGroups.motion`,`activity`),Dl(`stationary`,`helpers.detectionSettingsGroups.stationary`,`square-parking`),Dl(`zones`,`helpers.detectionSettingsGroups.zones`,`shapes`),Dl(`audio`,`helpers.detectionSettingsGroups.audio`,`volume-2`),Dl(`cluster`,`helpers.detectionSettingsGroups.cluster`,`server`)],kl={"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 Al(e){return kl[e]??`object-detection`}c();var jl=`steps`,Ml=`settings`,Nl=new Set([jl,Ml]);function Pl(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Fl({deviceId:t,activeSubTab:n,onSubTabChange:a}){let{t:o}=X();return e(On,{value:n&&Nl.has(n)?n:jl,onValueChange:r(e=>{a?.(e)},[a]),className:`flex flex-col`,children:[e(Lt,{className:`flex-shrink-0`,children:[i(qt,{value:jl,children:o(`device.detectionPipelineTab.steps`,`Steps`)}),i(qt,{value:Ml,children:o(`device.detectionPipelineTab.settings`,`Settings`)})]}),i(Fn,{value:jl,children:i(wl,{deviceId:t})}),i(Fn,{value:Ml,children:i(bi,{deviceId:t,sectionFilter:Pl,subTabGrouping:{groupOf:e=>Al(e.id),tabs:Ol}})})]})}var Il=`Notifications`,Ll={i18nKey:`device.deviceNotificationMute.cameraCostWhenOff`,text:`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`},Rl={i18nKey:`device.deviceNotificationMute.deviceCostWhenOff`,text:`This device never notifies — no rule, no target, no alarm.`};function zl(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Il,on:r===null?null:i??r,available:r!==null,costWhenOff:e.isCamera?Ll:Rl}}function Bl(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}c();function Vl(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Hl({deviceId:t,isCamera:n}){let{t:a}=X(),s=l(),c=Number.isFinite(t),[u,d]=o(null),[f,p]=o(null),m=zl({mutedDeviceIds:Vl(br({},{enabled:c}).data),deviceId:t,isCamera:n,pendingOn:f}),h=a(m.costWhenOff.i18nKey,m.costWhenOff.text),g=hr({onError:e=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),p(null),d(e instanceof Error?e.message:String(e)),s.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{d(null),p(null),s.invalidateQueries({queryKey:[[`notificationRules`]]})}}),_=r(()=>{let e=Bl(m,t);e!==null&&(p(!e.muted),g.mutate(e))},[t,g,m]),v=m.on===null,y=m.on===!1,b=y?at:ne;return e(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[e(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[i(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:a(`device.deviceNotificationMute.notifications`,`Notifications`)}),y&&i(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:a(`common.muted`)})]}),e(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[e(`button`,{type:`button`,role:`switch`,"aria-label":m.label,"aria-checked":m.on===!0,disabled:!m.available||g.isPending,onClick:_,title:v?a(`device.deviceNotificationMute.notificationMuteStateUnknownThe`,`Notification mute — state unknown; the notification centre did not answer.`):y?a(`device.deviceNotificationMute.muted`,`Muted. {{costWhenOff}}`,{costWhenOff:h}):a(`device.deviceNotificationMute.notifyingMutingIt`,`Notifying. Muting it: {{costWhenOff}}`,{costWhenOff:h}),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 ${u===null?v?`border-dashed border-border text-foreground-subtle/50`:y?`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:[i(b,{className:`h-3.5 w-3.5`}),i(`span`,{children:v?a(`device.deviceNotificationMute.unknown`,`Unknown`):y?a(`device.deviceNotificationMute.muted2`,`Muted`):a(`device.deviceNotificationMute.notifying`,`Notifying`)})]}),i(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:u===null?v?a(`device.deviceNotificationMute.theNotificationCentreDidNot`,`The notification centre did not answer, so this device’s mute state is unknown.`):h:a(`device.deviceNotificationMute.writeFailed`,`Write failed: {{failure}}`,{failure:u})})]})]})}c();function Ul({deviceId:t,template:n,members:a,fleet:s,fleetKind:c,snapshot:l,nameOf:u}){let{t:f}=X(),[p,m]=o(()=>new Map),h=r((e,t)=>{m(n=>{if(Xl(n.get(e),t))return n;let r=new Map(n);return r.set(e,t),r})},[]);if(n.family!==`actuator`)return null;let g=va(l),_=n.id!==`switch`,v=_?ga(n.id,a.map(e=>p.get(Yl(e))??{kind:`pending`})):null;return e(d,{children:[_&&a.map(e=>i(ql,{member:e,row:Jl(s,e),fleetKind:c,onRead:h},Yl(e))),v!==null&&i(Wl,{view:v}),n.id===`lock`&&i(Gl,{deviceId:t}),e(`div`,{"data-testid":`helper-commands`,children:[i(`h3`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:f(`helper.commandTitle`)}),g.kind===`pending`&&i(`p`,{role:`status`,className:`mt-1 text-xs text-foreground-subtle`,children:f(`helper.reportingPending`)}),g.kind===`unavailable`&&i(K,{title:f(`helper.outputUnavailable`),message:g.message}),g.kind===`none`&&i(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:f(`helper.commandNone`)}),g.kind===`rows`&&i(Kl,{view:g,nameOf:u})]})]})}function Wl({view:t}){let{t:n}=X(),r=t.kind===`ready`?t.methods.filter(e=>e!==`switch.setState`):[];return e(`div`,{"data-testid":`helper-shared-caps`,children:[i(`h3`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:n(`helper.sharedCaps`)}),t.kind===`pending`&&i(`p`,{role:`status`,className:`mt-1 text-xs text-foreground-subtle`,children:n(`helper.sharedPending`)}),t.kind===`unavailable`&&i(`p`,{role:`status`,className:`mt-1 text-xs text-foreground-subtle`,children:n(`helper.sharedUnavailable`)}),t.kind===`ready`&&r.length===0&&i(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:n(`helper.sharedNone`)}),t.kind===`ready`&&r.length>0&&e(`ul`,{className:`mt-1 flex flex-col gap-0.5 text-xs text-foreground`,children:[r.map(e=>i(`li`,{children:n(`helper.method.${e}`)},e)),t.modes.filter(e=>e.startsWith(`light-color`)).map(e=>i(`li`,{children:n(`helper.mode.${e}`)},e))]})]})}function Gl({deviceId:t}){let{t:n}=X(),r=Cr(),a=Gr(),[s,c]=o(null);return e(`div`,{className:`flex flex-col gap-2`,"data-testid":`helper-lock-controls`,children:[e(`div`,{className:`flex flex-wrap gap-2`,children:[e(J,{variant:`outline`,"data-testid":`helper-lock-all`,disabled:r.isPending,onClick:()=>{c(null),r.mutateAsync({deviceId:t}).catch(e=>c(e instanceof Error?e.message:String(e)))},children:[i(le,{className:`h-4 w-4`,"aria-hidden":!0}),n(`helper.lockAll`)]}),i(Zn,{label:n(`helper.unlockAll`),icon:xe,title:n(`helper.unlockTitle`),description:n(`helper.unlockBody`),confirmLabel:n(`helper.unlockConfirm`),triggerVariant:`outline`,action:()=>a.mutateAsync({deviceId:t,confirm:!0})})]}),s!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger`,children:s})]})}function Kl({view:t,nameOf:n}){let{t:r}=X();return i(`ul`,{className:`mt-1 flex flex-col gap-0.5 text-xs text-foreground`,"data-testid":`helper-command-rows`,children:t.rows.map(t=>e(`li`,{children:[n(t.deviceId),` — `,r(`helper.method.${t.cap}.${t.method}`),` —`,` `,t.ok?r(`helper.commandOk`):r(`helper.commandFailed`),t.error===null?``:` — ${t.error}`]},`${t.deviceId}:${t.cap}:${t.at}`))})}function ql({member:e,row:t,fleetKind:n,onRead:r}){let i=Yl(e),o=En({deviceId:t?.id??0},{enabled:n===`answered`&&t!==null});return a(()=>{if(n!==`answered`){r(i,{kind:`pending`});return}if(t===null){r(i,{kind:`ready`,caps:[],features:[]});return}if(o.status===`pending`){r(i,{kind:`pending`});return}if(o.status===`error`){r(i,{kind:`error`});return}r(i,{kind:`ready`,caps:o.data.entries.map(e=>e.capName),features:[...t.features]})},[o.data,o.status,n,i,r,t]),null}function Jl(e,t){let n=e.find(e=>e.addonId===t.source.addonId&&e.stableId===t.source.stableId);return n===void 0?null:{id:n.id,name:n.name,features:n.features}}function Yl(e){return`${e.source.addonId}/${e.source.stableId}`}function Xl(e,t){return e===void 0||e.kind!==t.kind?!1:e.kind!==`ready`||t.kind!==`ready`?!0:e.caps.join(`\0`)===t.caps.join(`\0`)&&e.features.join(`\0`)===t.features.join(`\0`)}function Zl({helper:t,snapshot:n}){let{t:r}=X(),a=ya(n),o=$l(n,t);return i(Tn,{headingId:`helper-history-status`,title:r(`helper.template.${t.kind}`),icon:ot,testId:`helper-history-status`,children:e(`div`,{className:`${f} flex flex-col gap-3`,children:[o.kind===`pending`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`helper.outputPending`)}),o.kind===`number`&&i(er,{value:Ql(t,o.value),label:r(`helper.output`)}),o.kind===`empty`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`helper.noReading`)}),a.kind===`ready`&&a.excluded>0&&i(`p`,{className:`text-xs text-foreground-muted`,"data-testid":`helper-history-gaps`,children:r(`helper.gaps`,{count:a.excluded})}),a.kind===`unavailable`&&i(K,{title:r(`helper.outputUnavailable`),message:a.message})]})})}function Ql(e,t){if(e.kind!==`derivative`)return String(t);let n=Ve(e);return n===null?String(t):`${t} ${n}`}function $l(e,t){if(e.kind===`pending`)return{kind:`pending`};if(e.kind!==`answered`)return{kind:`empty`};let n=t.kind===`statistic`||t.kind===`derivative`?{cap:`numeric-sensor`,field:`value`}:t.output===`energy`?{cap:`power-meter`,field:`energy`}:{cap:`meter`,field:`value`},r=e.caps[n.cap]?.[n.field];return typeof r==`number`&&Number.isFinite(r)?{kind:`number`,value:r}:{kind:`empty`}}function eu({helper:t,snapshot:n}){let{t:r}=X(),a=ru(n,t),o=t.kind===`arithmetic`?ya(n):null;return i(Tn,{headingId:`helper-math-status`,title:r(`helper.template.${tu(t)}`),icon:st,testId:`helper-math-status`,children:e(`div`,{className:`${f} flex flex-col gap-3`,children:[a.kind===`pending`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`helper.outputPending`)}),a.kind===`number`&&i(er,{value:String(a.value),label:r(`helper.output`)}),a.kind===`boolean`&&i(er,{value:a.value?r(`helper.on`):r(`helper.off`),label:r(`helper.output`)}),a.kind===`empty`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`helper.noReading`)}),o?.kind===`ready`&&i(`p`,{className:`text-sm text-foreground`,"data-testid":`helper-reporting`,children:r(`helper.reporting`,{included:o.included,total:o.total})}),o?.kind===`unavailable`&&i(K,{title:r(`helper.outputUnavailable`),message:o.message})]})})}function tu(e){return e.kind===`arithmetic`?e.op:e.kind}function nu(e){return e.kind===`threshold`||e.kind===`expression`&&e.output===`boolean`?{cap:`binary`,field:`on`}:{cap:`numeric-sensor`,field:`value`}}function ru(e,t){if(e.kind===`pending`)return{kind:`pending`};if(e.kind!==`answered`)return{kind:`empty`};let n=nu(t),r=e.caps[n.cap]?.[n.field];return typeof r==`number`&&Number.isFinite(r)?{kind:`number`,value:r}:typeof r==`boolean`?{kind:`boolean`,value:r}:{kind:`empty`}}c();function iu({deviceId:t,stableId:n}){let{t:a}=X(),s=n.startsWith(`composed-`)?n.slice(Qe.length):null,c=Nn({blockId:s??``},{enabled:s!==null}),l=wr({deviceId:t},{enabled:s!==null}),u=nn({projection:`slim`},{enabled:s!==null}),[d,p]=o(()=>new Map),m=Jt(),h=Bt(),g=r((e,t)=>{p(n=>{let r=n.get(e);if(r?.name===t.name&&r.presence===t.presence)return n;let i=new Map(n);return i.set(e,t),i})},[]);if(s===null)return null;if(c.status===`pending`)return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`helper.checking`)});if(c.status===`error`)return i(K,{title:a(`helper.outputUnavailable`),message:c.error.message});if(c.data.state!==`loaded`||c.data.view===null)return null;let _=G(c.data.view.block);if(_===null||!sa(_))return null;let v=_.helper;if(v.kind===`threshold`||v.kind===`arithmetic`||v.kind===`expression`)return i(eu,{helper:v,snapshot:cu(l.status,l.data,l.error?.message)});if(Ae(v))return i(Zl,{helper:v,snapshot:cu(l.status,l.data,l.error?.message)});if(v.kind!==`group`)return null;let y=De(v.templateId);if(y===null)return null;let b=cu(l.status,l.data,l.error?.message),x=ca(b,y),S=ya(b),C=u.status===`success`?u.data.map(lu):[],w=uu(u.status),T=ba(v.members.map(e=>d.get(su(e))??{name:e.source.stableId,presence:`unknown`})),E=x.kind===`number`?x.unit===void 0?String(x.value):`${x.value} ${x.unit}`:x.kind===`boolean`?x.value?a(ou(y.id,`on`)):a(ou(y.id,`off`)):x.kind===`empty`?a(`helper.noReading`):null;return i(Tn,{headingId:`helper-group-status`,title:a(`helper.statusTitle`),icon:ct,testId:`helper-group-status`,children:e(`div`,{className:`${f} flex flex-col gap-3`,children:[v.members.map(e=>i(au,{member:e,row:C.find(t=>t.addonId===e.source.addonId&&t.stableId===e.source.stableId)??null,fleetKind:w,isState:y.activeWhen!==void 0,onLive:g},su(e))),x.kind===`pending`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`helper.outputPending`)}),x.kind===`unavailable`&&i(K,{title:a(`helper.outputUnavailable`),message:x.message}),E!==null&&i(er,{value:E,label:a(`helper.template.${y.id}`)}),S.kind===`pending`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`helper.reportingPending`)}),S.kind===`unavailable`&&i(K,{title:a(`helper.outputUnavailable`),message:S.message}),S.kind===`absent`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`helper.reportingAbsent`)}),S.kind===`ready`&&i(`p`,{className:`text-sm text-foreground`,"data-testid":`helper-reporting`,children:a(`helper.reporting`,{included:S.included,total:S.total})}),S.kind===`ready`&&S.excluded>0&&e(`div`,{children:[i(`h3`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:a(`helper.excluded`)}),T.kind===`pending`?i(`p`,{role:`status`,className:`mt-1 text-xs text-foreground-subtle`,children:a(`helper.excludedPending`)}):T.names.length===0?i(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:a(`helper.excludedUnnamed`)}):i(`ul`,{className:`mt-1 flex flex-col gap-0.5 text-xs text-foreground`,"data-testid":`helper-excluded`,children:T.names.map(e=>i(`li`,{children:e},e))})]}),i(Ul,{deviceId:t,template:y,members:v.members,fleet:C.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,features:e.features})),fleetKind:w,snapshot:b,nameOf:e=>{if(m===null)return C.find(t=>t.id===e)?.name??String(e);let t=m.byId.get(e);return t===void 0?String(e):oi(t,`compact`,m,h)}})]})})}function au({member:e,row:t,fleetKind:n,isState:r,onLive:i}){let o=t?.online===!0,s=wr({deviceId:t?.id??0},{enabled:n===`answered`&&t!==null&&o}),c=ha(s.status,s.status===`success`?ma(s.data):void 0,e.cap,e.fieldPath,r),l=pa({fleet:n,deviceOnline:n===`answered`?t===null?null:t.online:!0,field:c}),u=t?.name??e.source.stableId,d=Mn(t?.id??0,`compact`,u),f=t===null?u:d,p=su(e);return a(()=>{i(p,{name:f,presence:l})},[p,f,i,l]),null}function ou(e,t){return[`cover`,`valve`,`lock`,`media-player`,`climate`].includes(e)?`helper.state.${e}.${t}`:`helper.${t}`}function su(e){return`${e.source.addonId}/${e.source.stableId}/${e.cap}.${e.fieldPath}`}function cu(e,t,n){return e===`pending`?{kind:`pending`}:e===`error`?{kind:`error`,message:n??``}:{kind:`answered`,caps:ma(t)}}function lu(e){return{id:e.id,name:e.name,online:e.online,addonId:e.addonId,stableId:e.stableId,features:e.features??[]}}function uu(e){return e===`pending`?`pending`:e===`error`?`error`:`answered`}function du(e,t){return{switchId:e,label:We[e].label,detail:t===void 0||t.length===0?null:t}}function fu(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 pu(e){let t=fu(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>du(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>du(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}}c();function mu(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 hu({deviceId:t,deviceName:r}){let{t:a}=X(),s=ye(),[c,l]=o(null),u=nn({isCamera:!0,projection:`slim`}),d=yt(),f=u.data!==void 0,p=n(()=>u.data===void 0?[]:mu(u.data,t),[u.data,t]),m=p.find(e=>e.id===c)??null,h=d.data===void 0?null:pu(d.data),g=d.error===null?null:d.error.message,_=async()=>{m===null||m.id===t||await s({title:a(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:r,target:m.name}),message:a(`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:r,target:m.name,sourceId:t,targetId:m.id}),confirmLabel:a(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&d.mutate({sourceId:t,targetId:m.id})};return e(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[e(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[e(`div`,{className:`min-w-0`,children:[i(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:a(`deviceMigrate.title`,`Migrate to…`)}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:a(`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:t})})]}),e(`div`,{className:`flex shrink-0 items-center gap-2`,children:[e(`select`,{"aria-label":a(`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||d.isPending,value:c===null?``:String(c),onChange:e=>{let t=e.target.value;l(t===``?null:Number(t))},children:[i(`option`,{value:``,children:f?a(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):a(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(t=>e(`option`,{value:String(t.id),children:[t.name,` (#`,t.id,`)`]},t.id))]}),e(`button`,{type:`button`,disabled:m===null||d.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:[i(tt,{className:`h-3 w-3`}),d.isPending?a(`deviceMigrate.running`,`Migrating…`):a(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&i(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:a(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&i(`p`,{className:`mt-2 text-[11px] text-danger`,children:a(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&i(gu,{report:h})]})}function gu({report:t}){let{t:n}=X(),r=t.verdict===`quiet`;return e(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[i(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:t.inheritedId,retiredId:t.retiredId})}),r?e(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[i(V,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),i(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:n(`deviceMigrate.quiet`,`Every function on the replaced camera was switched off — the old hardware is quiet.`)})]}):e(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[e(`div`,{className:`flex items-start gap-2`,children:[i(p,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),i(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:n(`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.`)})]}),i(`ul`,{className:`mt-2 space-y-1 pl-5`,children:t.stillLive.map(t=>e(`li`,{className:`text-[11px] text-foreground`,children:[i(`span`,{className:`font-medium`,children:t.label}),t.detail!==null&&e(`span`,{className:`text-foreground-subtle`,children:[` — `,t.detail]})]},t.switchId))})]}),t.neverOffered.length>0&&e(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[e(`div`,{className:`flex items-start gap-2`,children:[i(ut,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),i(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:n(`deviceMigrate.neverOffered`,`The replaced camera never offered these, so there was nothing to switch off. They are not running.`)})]}),i(`ul`,{className:`mt-2 space-y-1 pl-5`,children:t.neverOffered.map(e=>i(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}c();function _u({deviceId:t}){let{t:n}=X(),[r,a]=o(null),s=cr({onSuccess:e=>{a(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>a(`Re-sync failed: ${e.message}`)});return e(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[e(`div`,{className:`flex items-center justify-between gap-3`,children:[e(`div`,{children:[i(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:n(`device.resyncButton.reSync`,`Re-sync`)}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:n(`device.resyncButton.reAlignThisDeviceS`,`Re-align this device's type, role, capabilities and units with its source.`)})]}),e(`button`,{type:`button`,disabled:s.isPending,onClick:()=>{a(null),s.mutate({camDeviceId:t})},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:[i(m,{className:`h-3 w-3 ${s.isPending?`animate-spin`:``}`}),s.isPending?n(`device.resyncButton.reSyncing`,`Re-syncing…`):n(`device.resyncButton.reSync`,`Re-sync`)]})]}),r!==null&&i(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:r})]})}function vu(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function yu({device:t}){let{t:n}=X(),r=pi(),a=typeof t.id==`number`?t.id:null,o=typeof t.name==`string`?t.name:``,s=Mn(a??0,`full`,o),c=String(t.type??``),l=c===U.Camera,u=c===U.Hub,d=t.features??[],f=d.includes(Ye.Resyncable),{data:p}=ei({deviceId:a??0},{enabled:a!==null&&l,refetchInterval:5e3}),m=p?.streams??{},h=Object.entries(m),g=d.includes(Ye.DoorbellButton),_=ur(g?{deviceId:a??void 0,historyLimit:10}:void 0),v=_.latest?Date.now()-_.latest.timestamp<3e4:!1;return e(`div`,{className:`space-y-5`,children:[t.addonId===`composer`&&a!==null&&typeof t.stableId==`string`&&i(iu,{deviceId:a,stableId:t.stableId}),u&&a!==null&&i(Dn,{deviceId:a,onOpenChild:e=>r(`/devices/${e}`)}),f&&a!==null&&i(_u,{deviceId:a}),l&&a!==null&&i(hu,{deviceId:a,deviceName:s}),a!==null&&i(Hl,{deviceId:a,isCamera:l}),l&&a!==null&&i(lr,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:a}),g&&i($r,{history:_.history,latestIsFresh:v}),l&&a!==null&&i(lr,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:a}),l&&h.length>0&&e(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[i(`div`,{className:`border-b border-border px-4 py-2`,children:i(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:n(`device.overviewTab.streamNetwork`,`Stream Network`)})}),i(`div`,{className:`divide-y divide-border`,children:h.map(([t,r])=>e(`div`,{className:`px-4 py-2.5`,children:[e(`div`,{className:`flex items-center gap-2 mb-2`,children:[i(F,{className:`h-3 w-3 text-foreground-subtle`}),i(`span`,{className:`text-[11px] font-medium text-foreground`,children:t})]}),e(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[i(bu,{label:n(`device.overviewTab.nominal`,`Nominal`),value:vu(r.nominalBitrateKbps??0)}),i(bu,{label:n(`device.overviewTab.observed`,`Observed`),value:vu(r.observedBitrateKbps??0)}),i(bu,{label:n(`device.overviewTab.peak`,`Peak`),value:vu(r.peakBitrateKbps??0)}),i(bu,{label:n(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(r.packetLossPercent??0).toFixed(2)}%`,warning:(r.packetLossPercent??0)>1})]})]},t))})]}),i(Ci,{})]})}function bu({label:t,value:n,warning:r}){return e(`div`,{children:[i(`p`,{className:`text-[10px] text-foreground-subtle`,children:t}),i(`p`,{className:`text-xs font-medium ${r?`text-warning`:`text-foreground`}`,children:n})]})}var xu=`history`,Su=[{id:`overview`,labelKey:`helpers.structuralTabs.overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,labelKey:`helpers.structuralTabs.config`,cameraOnly:!1,adminOnly:!1},{id:wi,labelKey:`helpers.structuralTabs.customize`,cameraOnly:!1,adminOnly:!0},{id:xu,labelKey:`helpers.structuralTabs.history`,cameraOnly:!1,adminOnly:!1},{id:`detection-pipeline`,labelKey:`helpers.structuralTabs.detectionPipeline`,cameraOnly:!0,adminOnly:!1},{id:`bindings`,labelKey:`helpers.structuralTabs.bindings`,cameraOnly:!0,adminOnly:!1}],Cu=new Set([U.Hub,U.Container]);function wu(e,t){let n=e===U.Camera,r=e===void 0||!Cu.has(e);return Su.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)&&(r||e.id!==`history`)).map(({id:e,labelKey:t})=>({id:e,label:Y.t(t)}))}function Tu({provider:e,integrationId:t,name:n}){let r=pi(),a=t===null?`/integrations`:li(e,t),o=n===null?`Open integrations`:`Open integration ${n}`;return i(`button`,{type:`button`,onClick:()=>r(a),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:o,"aria-label":o,children:i(gi,{type:e,size:`lg`})})}c();var Eu=[{id:`logs`,icon:Ce,labelKey:`common.logs`},{id:`repl`,icon:lt,labelKey:`deviceDetail.repl`},{id:`events`,icon:M,labelKey:`common.events`},{id:`state`,icon:ae,labelKey:`common.state`}];function Du(){let{t:a}=X(),s=pe(),c=Oi(),u=Number(c.deviceId),f=Number.isFinite(u),p=pi(),h=l(),g=ye(),_=I(),{user:v}=Ei(),b=v?.isAdmin===!0,[x,S]=ki(),C=x.get(`tab`)??`overview`,E=x.get(`sub`),[D,O]=o(`logs`),k=`device-detail.left-col-width-px`,[A,j]=o(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(k),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),M=t(A);M.current=A;function ee(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??A??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{j(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(k,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:N,isLoading:ne,isError:re}=ln({deviceId:u},{enabled:f,refetchInterval:5e3,retry:1}),{data:P}=Sr({deviceId:u},{enabled:f}),ie=n(()=>{let e=P?.settings?.sections??[],t=P?.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(fi)&&r.add(ui),[...r].map(e=>e===`export`?{id:e,label:di,isAddonContrib:!0}:{id:e,label:Je[e]?.label??e,isAddonContrib:!0})},[P]),F=N,ae=String(F?.name??c.deviceId??`Device`),oe=F?.online===!0,se=oe?`online`:`offline`,ce=String(F?.addonId??`rtsp`),L=F?.features??[],R=F?.type,z=R===U.Camera,{data:le}=hi(f?u:0),ue=R===U.Container,de=n(()=>(le??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[le]),B=n(()=>ue?Yt(de,typeof F?.linkDeviceId==`number`?F.linkDeviceId:null,typeof F?.primaryChildEntityId==`string`?F.primaryChildEntityId:null)?.id??null:null,[ue,de,F?.linkDeviceId,F?.primaryChildEntityId]),{data:fe}=Sr({deviceId:B??0},{enabled:B!==null}),he=n(()=>{if(B===null)return[];let e=fe?.settings?.sections??[],t=fe?.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:Je[e]?.label??e,isAddonContrib:!0,childDeviceId:B}))},[B,fe]),ge=n(()=>ko({sections:[...P?.settings?.sections??[],...P?.live?.sections??[]],deviceId:u,...B===null?{}:{child:{sections:[...fe?.settings?.sections??[],...fe?.live?.sections??[]],deviceId:B}}}),[P,fe,u,B]),_e=typeof F?.parentDeviceId==`number`?F.parentDeviceId:null,{data:ve}=ln({deviceId:_e??0},{enabled:_e!==null}),xe={id:Number.isFinite(u)?u:0,name:ae,type:`unknown`,stableId:``,parentDeviceId:null},V=bt(F??xe,`full`),Ce=bt(ve??xe,`full`),H=Xt(),we=F?.disabled!==!0,Te=n(()=>{let e=P?.settings?.sections??[],t=P?.live?.sections??[];return ci([...e,...t],R,b,P!==void 0)},[P,R,b]),Ee=n(()=>{let e=new Set,t=[];for(let n of[...wu(R,b),...ie,...he])n.id===`config`&&!Te||e.has(n.id)||(e.add(n.id),t.push(n));return t},[R,b,ie,he,Te]),De=n(()=>Kc(Ee,C),[Ee,C]),Oe=r(e=>{S(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of ka)n.delete(e);return n},{replace:!0})},[S]),ke=r(e=>{S(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[S]),Ae=(le??[]).length>0,je=n(()=>Eu.filter(({featureGate:e})=>!e||L.includes(e)),[L]),{data:W}=vr(void 0),Me=n(()=>F?sn(F,W):null,[F,W]),G=Me?.kind===`resolved`?Me.integration:null,Ne=G===null?Me?.kind===`unknown`?a(`deviceDetail.loadingIntegration`):Me?.kind===`orphan`?a(`deviceDetail.missingIntegration`):a(`deviceDetail.noIntegration`):G.name,Pe=G!==null&&G.addonId===ce?G.name:ce,Fe=kn({onSuccess:()=>{h.invalidateQueries({queryKey:[[`deviceManager`]]}),p(G?.id?li(G.addonId,G.id):`/integrations`)}}),Ie=Zr({onSuccess:()=>{h.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=ii({onSuccess:()=>{h.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=pt(),ze=It({onSuccess:()=>{h.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=L.includes(Ye.Rebootable),Ve=L.includes(Ye.BatteryOperated),He=xt(_.trpcClient,Ve&&f?u:null),Ue=si(_.trpcClient,f?u:null),We=me(_.trpcClient,f?u:null,e=>e.runningState),Ge=We===void 0||We.running===null?null:We.running,Ke=zn(R??`unknown`,s).icon,[qe,Xe]=o(!1),Ze=async()=>{if(!qe){Xe(!0);try{let e=V.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await Ga(`${te}/${String(u)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Xe(!1)}}},Qe=Ie.isPending||Le.isPending,{data:$e}=qr({deviceId:u},{enabled:f&&z,refetchInterval:1e4}),et=$e?.agentNodeId??null,tt=typeof et==`string`&&et.length>0&&!et.startsWith(`addon:`)?et:void 0,{data:nt}=_n({deviceId:u,...tt?{nodeId:tt}:{}},{enabled:f&&z,refetchInterval:3e3,retry:!1}),{data:rt}=Vr({deviceId:u},{enabled:f&&z,refetchInterval:3e3,retry:!1}),it=rt?.level?.dbfs??null;function at(){if(!f)return null;switch(De){case`overview`:return i(yu,{device:F??{}});case`config`:return i(Zc,{deviceId:u,activeSubTab:E,onSubTabChange:ke,deviceType:R,isAdmin:b});case`detection-pipeline`:return i(Fl,{deviceId:u,activeSubTab:E,onSubTabChange:ke});case`bindings`:return i(qc,{deviceId:u});case xu:return i(nr,{deviceId:u,onNavigate:e=>p(e)});case wi:return i(Hc,{deviceId:u});default:{let e=De,t=ie.some(t=>t.id===e),n=he.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??u;if(e===`export`)return i(bi,{deviceId:u,sectionFilter:fi,activeSubTab:E,onSubTabChange:ke});let a=i(bi,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:E,onSubTabChange:ke});return n!==void 0&&r!==u?i(Hn,{deviceId:r,children:a}):a}}}return f?ne?e(`div`,{className:`flex flex-col h-full`,children:[e(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[i(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),i(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),i(`div`,{className:`flex-1 p-6`,children:i(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):re||!N?e(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[i(`p`,{className:`text-lg font-semibold text-foreground`,children:a(`deviceDetail.deviceNotFound`,`Device not found`)}),i(`p`,{className:`text-xs`,children:i(Ti,{i18nKey:`deviceDetail.noDeviceWithId`,values:{id:u},components:{code:i(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),i(`button`,{onClick:()=>p(`/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:a(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]}):e(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[e(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[i(`div`,{className:`mb-2`,children:i(ht,{items:[{label:a(`deviceDetail.integrations`,`Integrations`),onClick:()=>p(`/integrations`)},G===null?{label:Ne}:{label:Ne,onClick:()=>p(li(G.addonId,G.id))},{label:V}]})}),e(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[G!==null&&i(Tu,{provider:G.addonId,integrationId:G.id,name:G.name}),i(Ht,{running:Ge,children:i(Ke,{className:`h-5 w-5 text-foreground-subtle shrink-0`,"aria-hidden":!0})}),e(`div`,{className:`min-w-0 flex-1`,children:[e(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[i(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:V}),i(Hr,{status:se}),Ve&&i(vn,{status:He,variant:`full`}),i(Mt,{status:Ue})]}),_e!==null&&ve&&e(`button`,{type:`button`,onClick:()=>p(`/devices/${_e}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:a(`deviceDetail.openParentDevice`,`Open parent device {{name}}`,{name:Ce}),children:[i(`span`,{children:`↑`}),i(`span`,{className:`truncate`,children:Ce})]}),i(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:L.length>0&&i(_i,{capabilities:L})})]}),nt&&i(`div`,{className:`hidden lg:flex`,children:i(Ou,{metrics:nt,dbfs:it})}),e(`div`,{className:`flex items-center gap-1 shrink-0`,children:[e(`button`,{onClick:async()=>{we?await g({title:a(`deviceDetail.disable`,`Disable "{{name}}"?`,{name:V}),message:a(`deviceDetail.theDeviceWillStopProcessing`,`The device will stop processing streams and events. You can re-enable it later.`),confirmLabel:a(`common.disable`,`Disable`),variant:`danger`})&&Le.mutate({deviceId:u}):Ie.mutate({deviceId:u})},disabled:Qe,title:we?a(`deviceDetail.disableDevice`,`Disable device`):a(`deviceDetail.enableDevice`,`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 ${we?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[i(w,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:Qe?a(`deviceDetail.updating`,`Updating…`):we?a(`deviceDetail.enabled`,`Enabled`):a(`deviceDetail.disabled`,`Disabled`)})]}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),z&&e(d,{children:[i(Qa,{deviceId:u}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),i(eo,{deviceId:u}),i(ri,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:a(`deviceDetail.takeSnapshot`,`Take snapshot`),description:a(`deviceDetail.fetchAFreshFrameAnd`,`Fetch a fresh frame and download it.`),icon:T,disabled:qe,onClick:()=>{Ze()}},{id:`reboot`,label:a(`deviceDetail.rebootDevice`,`Reboot device`),description:a(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:Se,hidden:!Be,disabled:Re.isPending,danger:!0,onClick:async()=>{await g({title:a(`deviceDetail.reboot`,`Reboot "{{name}}"?`,{name:V}),message:a(`deviceDetail.theCameraWillGoOffline`,`The camera will go offline for around 30 seconds while the firmware reboots.`),confirmLabel:a(`deviceDetail.reboot2`,`Reboot`),variant:`danger`})&&Re.mutate({deviceId:u})}},{id:`restart-addon`,label:a(`deviceDetail.restartAddon`,`Restart addon`),description:a(`deviceDetail.bouncesEveryDeviceServedBy`,`Bounces every device served by {{servingAddonLabel}}.`,{servingAddonLabel:Pe}),icon:m,disabled:ze.isPending,danger:!0,onClick:async()=>{await g({title:a(`deviceDetail.restart`,`Restart "{{servingAddonLabel}}"?`,{servingAddonLabel:Pe}),message:a(`deviceDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device served by it (not just "{{name}}"). Streams will reconnect automatically.`,{name:V}),confirmLabel:a(`deviceDetail.restart2`,`Restart`),variant:`danger`})&&ze.mutate({addonId:ce})}},{id:`delete`,label:a(`deviceDetail.deleteDevice`,`Delete device`),description:a(`deviceDetail.removeTheDeviceAndAll`,`Remove the device and all its settings.`),icon:y,separatorBefore:!0,disabled:Fe.isPending,danger:!0,onClick:async()=>{await g({title:a(`deviceDetail.delete`,`Delete "{{name}}"?`,{name:V}),message:a(`deviceDetail.thisWillRemoveTheDevice`,`This will remove the device and all its settings. This action cannot be undone.`),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`})&&Fe.mutate({deviceId:u})}}]})]})]})]}),i(Hn,{deviceId:u,device:F??void 0,children:i(At,{children:i(Ct,{children:i(be,{children:i($n,{children:e(`main`,{className:H?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[e(`div`,{className:H?`flex flex-col bg-surface`:`${A===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-y-auto`,style:!H&&A!==null?{width:`${String(A)}px`}:void 0,children:[i(`div`,{className:z?`flex-shrink-0 border-b border-border-subtle bg-black`:H?`flex-shrink-0 border-b border-border-subtle bg-surface`:`shrink-0 border-b border-border-subtle bg-surface`,children:z?i(zo,{deviceId:u,intercomAvailable:L.includes(Ye.TwoWayAudio)}):e(`div`,{children:[i(Eo,{deviceId:u,deviceName:V,deviceType:R??`unknown`,provider:ce,isOnline:oe,features:L}),i(Do,{deviceId:u,widgets:ge})]})}),z&&ge.length>0&&i(`div`,{className:`flex-shrink-0 border-b border-border-subtle bg-surface pt-3 sm:pt-4`,children:i(Do,{deviceId:u,widgets:ge})}),e(`div`,{className:H?`flex flex-col border-b border-border`:`flex-1 min-h-64 flex flex-col overflow-hidden`,children:[i(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:i(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:je.map(({id:t,labelKey:n,icon:r})=>{let o=D===t;return e(`button`,{onClick:()=>O(t),title:a(n),className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${o?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[i(r,{className:`h-3 w-3`}),a(n)]},t)})})}),e(`div`,{className:H?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[D===`logs`&&i(Bo,{deviceId:u,containerDeviceId:R===`container`?u:void 0}),D===`repl`&&i(Vo,{deviceId:u}),D===`events`&&i(Ho,{deviceId:u}),D===`state`&&i(Uo,{deviceId:u})]})]})]}),!H&&i(`div`,{role:`separator`,"aria-orientation":`vertical`,title:a(`deviceDetail.dragToResize`,`Drag to resize`),onMouseDown:ee,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:i(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),e(`div`,{className:H?`flex flex-1 flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[i(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:i(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:Ee.map(t=>{let n=De===t.id;return e(`button`,{onClick:()=>Oe(t.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${n?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[t.label,n&&i(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},t.id)})})}),e(`div`,{className:H?`p-3 flex flex-1 flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[De===`overview`&&Ae&&i(to,{parentDeviceId:u}),at()]})]})]})})})})})})]}):e(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[i(`p`,{className:`text-lg font-semibold text-foreground`,children:a(`deviceDetail.invalidDeviceId`,`Invalid device id`)}),i(`p`,{className:`text-xs`,children:i(Ti,{i18nKey:`deviceDetail.invalidSegment`,values:{segment:c.deviceId},components:{code:i(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),i(`button`,{onClick:()=>p(`/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:a(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]})}function Ou({metrics:t,dbfs:n}){let r=pe(),{t:a}=X(),o=jr(t.phase??`idle`,r);return e(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[e(`div`,{className:`flex items-center gap-1.5`,children:[i(`span`,{className:`h-1.5 w-1.5 rounded-full ${o.dotClass}`}),i(`span`,{className:`text-[10px] font-medium ${o.textColor}`,children:o.label})]}),i(`div`,{className:`h-3 w-px bg-border`}),e(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[i(_e,{className:`h-3 w-3`}),i(`span`,{className:`text-foreground tabular-nums`,children:(t.actualFps??0).toFixed(1)}),i(`span`,{children:a(`common.fpsWord`)})]}),e(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[i(de,{className:`h-3 w-3`}),i(`span`,{className:`text-foreground tabular-nums`,children:(t.avgInferenceTimeMs??0).toFixed(0)}),i(`span`,{children:`ms`})]}),e(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:a(`deviceDetail.currentAudioLevelDbfs`,`Current audio level (dBFS)`),children:[i(O,{className:`h-3 w-3`}),i(`span`,{className:`text-foreground tabular-nums`,children:n==null?`—`:n.toFixed(0)}),i(`span`,{children:`dB`})]}),(t.queueDepth??0)>0&&e(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,t.queueDepth]})]})}export{Du as DeviceDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,K as t,S as n,a as r,et as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{dt as a}from"./player-overlays-
|
|
1
|
+
import{C as e,K as t,S as n,a as r,et as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{dt as a}from"./player-overlays-DaSesfVn.js";import{cn as o,dn as s,fn as c,hn as l,ln as u,mn as d,pn as f,un as p}from"./client-BjsFVjEa.js";import{B as m}from"./src-DxOL9qHw.js";import{t as h}from"./i18n-ZdV8UiYr.js";import{t as g}from"./useTranslation-BJr-n0es.js";import"./index-CuSxNbC8.js";var _=6e4,v=60*_,y=24*v,b=Date.UTC(2e3,0,1);function x(e){if(e==null||e<b)return`—`;let t=Date.now()-e;return t<0||t<3e4?h.t(`helpers.relativeTime.justNow`):t<v?h.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(t/_)}):t<y?h.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(t/v)}):h.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(t/y)})}i();var S=6e4;function C(e){let t=a();return r({queryKey:[`device-do-action`,`bound-caps`,e],enabled:e>0,staleTime:S,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function w(e){let t=a(),n=[...new Set(e.filter(e=>e>0))].sort((e,t)=>e-t);return r({queryKey:[`device-do-action`,`bound-caps-batch`,n],enabled:n.length>0,staleTime:S,queryFn:async()=>{let e=await t.trpcClient.deviceManager.getBindingsBatch.query({deviceIds:n}),r=new Map;for(let t of e)r.set(t.deviceId,[...new Set(t.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t)));return r}})}var T=`mt-1 w-full rounded border border-border bg-background px-2 py-1 text-xs`,E=`block text-[11px] font-medium text-foreground`,D=`deviceId`;function O(e,t){return t.length===0?0:t.length===1?t[0]:t.find(t=>!e.includes(t))??t[t.length-1]}function k(e,t,n){if(t.length===0)return[];if(t.length===1)return t;let r=t.find(t=>!e.includes(t));if(r===void 0)return t;let i=n(r);if(i===void 0)return[r];let a=e[0]??t.find(e=>e!==r);if(a===void 0)return[r];let o=n(a);return o===void 0||!l(o,i)?[r]:t.filter(e=>{let t=n(e);return t!==void 0&&l(o,t)})}function A(e){return e.length===0?0:e.length===1?e[0]:[...e]}function j(e){return typeof e==`number`?e>0?[e]:[]:Array.isArray(e)?e.filter(e=>e>0):[]}function M(e,t){return{deviceId:e,cap:t.cap,method:t.method,...t.args===void 0?{}:{args:{...t.args}}}}function N(e,t){return h.t(`deviceDoAction.customLabel`,{name:`${e}.${t}`})}function P({value:r,onChange:i,devices:a,listState:h,fleet:_,allowTriggerDevice:v=!1,allowMultiSameFamily:y=!1,testId:b=`device-do-action`}){let{t:x}=g(),S=typeof r.deviceId!=`number`&&!Array.isArray(r.deviceId),P=j(r.deviceId),F=t(()=>a.filter(e=>f(String(e.type??``))),[a]),I=t(()=>{let e=new Map;for(let t of F)t.type!==void 0&&t.type!==null&&e.set(t.id,String(t.type));return e},[F]),L=t(()=>{if(!y||P.length===0)return F;let e=I.get(P[0]);return e===void 0?F:F.filter(t=>{if(P.includes(t.id))return!0;let n=t.type!==void 0&&t.type!==null?String(t.type):void 0;return n!==void 0&&l(e,n)})},[y,P,F,I]),R=C(!y&&P.length===1?P[0]:0),z=w(y?P:[]),B=t(()=>S?s():P.length===0?[]:y?z.isLoading&&z.data===void 0?[]:p(P.map(e=>({boundCaps:z.data?.get(e),deviceType:I.get(e)}))):R.data===void 0&&R.isLoading?[]:u({boundCaps:R.data,deviceType:I.get(P[0])}),[S,P,y,z.data,z.isLoading,R.data,R.isLoading,I]),V=c(r.cap,r.method,r.args),H=d(r.cap,r.method,r.args),U=r.cap!==``&&r.method!==``&&H===null&&(S||P.length>0),W=y?z.isLoading:R.isLoading,G=y?z.isError:R.isError,K=e=>{if(e.startsWith(`custom:`))return;let t=o.find(t=>t.id===e);t!==void 0&&i(M(S?r.deviceId:P.length>0?A(P):F[0]?.id??0,t))};return e(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,"data-testid":b,children:[v&&e(`div`,{className:`w-full max-w-xs`,children:[n(`label`,{className:E,children:x(`deviceDoAction.deviceDoActionFields.target`,`Target`)}),e(`select`,{className:T,"data-testid":`${b}-target`,value:S?`trigger`:`device`,onChange:e=>{if(e.target.value===`trigger`){i({deviceId:{$var:D},cap:``,method:``});return}i({deviceId:F[0]?.id??0,cap:``,method:``})},children:[n(`option`,{value:`device`,children:x(`deviceDoAction.deviceDoActionFields.specificDevice`,`Specific device`)}),n(`option`,{value:`trigger`,children:x(`deviceDoAction.deviceDoActionFields.theDeviceThatTriggeredThis`,`The device that triggered this run`)})]})]}),!S&&e(`div`,{"data-testid":`${b}-device`,children:[n(`label`,{className:E,children:x(`deviceDoAction.deviceLabel`,{count:y?2:1})}),n(m,{devices:L,listState:h,..._===void 0?{}:{fleet:_},value:[...P],onChange:e=>{i({deviceId:A(y?k(P,e,e=>I.get(e)):(()=>{let t=O(P,e);return t>0?[t]:[]})()),cap:``,method:``})},emptyLabel:y?`No devices selected`:`No device selected`,noun:`device`,testId:`${b}-device-picker`}),y&&P.length>1&&n(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:x(`deviceDoAction.deviceDoActionFields.sameFamilyOnlyTheAction`,`Same family only — the action runs on each selected device.`)})]}),e(`div`,{className:`w-full max-w-sm`,children:[n(`label`,{className:E,children:x(`deviceDoAction.deviceDoActionFields.action`,`Action`)}),e(`select`,{className:T,"data-testid":`${b}-action`,value:V===`custom:${r.cap}.${r.method}`?V:H?.id??``,disabled:!S&&(P.length===0||W),onChange:e=>K(e.target.value),children:[n(`option`,{value:``,children:!S&&P.length===0?x(`deviceDoAction.deviceDoActionFields.pickADeviceFirst`,`Pick a device first`):W?x(`deviceDoAction.deviceDoActionFields.loadingActions`,`Loading actions…`):B.length===0?x(`deviceDoAction.deviceDoActionFields.noActionsForThisDevice`,`No actions for this device`):x(`deviceDoAction.deviceDoActionFields.selectAnAction`,`Select an action…`)}),U&&n(`option`,{value:V,children:N(r.cap,r.method)}),B.map(e=>n(`option`,{value:e.id,children:e.label},e.id))]}),G&&n(`p`,{className:`mt-1 text-[11px] text-warning`,children:x(`deviceDoAction.deviceDoActionFields.couldNotReadThisDevice`,`Could not read this device’s capabilities.`)})]}),H?.openArgs!==void 0&&H.openArgs.length>0&&n(`div`,{className:`flex flex-col gap-2`,children:H.openArgs.map(t=>{let a=r.args?.[t.key],o=typeof a==`string`||typeof a==`number`?String(a):``;return e(`div`,{className:`w-full max-w-sm`,children:[n(`label`,{className:E,htmlFor:`${b}-${t.key}`,children:t.label}),n(`input`,{id:`${b}-${t.key}`,className:T,"data-testid":`${b}-${t.key}`,type:t.kind===`number`?`number`:`text`,value:o,onChange:e=>{let n=e.target.value,a=r.args===void 0?{}:{...r.args};if(n===``)delete a[t.key];else if(t.kind===`number`){let e=Number(n);Number.isNaN(e)?delete a[t.key]:a[t.key]=e}else a[t.key]=n;i(Object.keys(a).length>0?{...r,args:a}:{deviceId:r.deviceId,cap:r.cap,method:r.method})}})]},t.key)})})]})}export{x as i,C as n,b as r,P as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,K as t,R as n,S as r,et as i,o as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ni as o,dt as s,zt as c}from"./player-overlays-
|
|
1
|
+
import{C as e,K as t,R as n,S as r,et as i,o as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ni as o,dt as s,zt as c}from"./player-overlays-DaSesfVn.js";import{Mo as l,Mt as u,Uo as d,js as f,jt as p,r as m,wo as h,yo as g}from"./src-DxOL9qHw.js";import{t as _}from"./useTranslation-BJr-n0es.js";import{_r as v,dr as y}from"./index-CuSxNbC8.js";import{t as b}from"./AdminPage-B_wUVHLs.js";import"./useEventInvalidation-C9XdDI0R.js";import{t as x}from"./device-integration-icon-Bo_gTwOD.js";i();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:i}=_(),S=v(),w=s(),T=a();m([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),m([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:E}=l({projection:`slim`}),{data:D}=f(void 0),O=d({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),k=g({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=h({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),j=t(()=>E??[],[E]),M=t(()=>u(D),[D]),{activeDevices:N,orphanDevices:P}=t(()=>C(j,M),[j,M]),F=t(()=>{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=n(e=>F.get(e)??null,[F]),L=t(()=>(D??[]).map(e=>({id:e.id,name:e.name??e.addonId,icon:r(y,{type:e.addonId,size:`sm`})})),[D]),R=n(e=>S(`/devices/${String(e)}`),[S]);return e(b,{icon:o,title:i(`nav.devices`,`Devices`),children:[r(p,{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&&e(`div`,{className:`mt-6 space-y-2`,children:[e(`div`,{className:`flex items-baseline gap-2`,children:[r(c,{className:`h-3.5 w-3.5 text-warning shrink-0`}),r(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`devices.orphanDevices`,`Orphan devices`)}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:i(`common.deviceOrphans`,{count:P.length})})]}),e(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:i(`devices.theseDevicesReferenceAnIntegration`,"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.")}),r(p,{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{C as e,K as t,S as n,V as r,Y as i,d as a,et as o,u as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{lt as c}from"./player-overlays-
|
|
1
|
+
import{C as e,K as t,S as n,V as r,Y as i,d as a,et as o,u as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{lt as c}from"./player-overlays-DaSesfVn.js";import{Za as l}from"./client-BjsFVjEa.js";import{D as u,M as d,O as f,P as p,T as m,y as h}from"./__vite-browser-external-BlMfPwfH.js";import{Cn as g,dn as _,kn as v,sn as y,tf as b}from"./src-DxOL9qHw.js";import{t as x}from"./useTranslation-BJr-n0es.js";o();var S=p([f({kind:m(`adaptive`)}),f({kind:m(`profile`),profile:l})]),C=f({serverUrl:d().min(1),token:d().min(1),deviceId:u().int().nonnegative(),target:S,muted:h()});function w(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function T(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function E(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function D(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function O(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=C.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 k({message:t}){let{t:n}=x();return r(()=>{w(`error`,t)},[t]),e(`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:[n(`embedPlayerPage.embedConfigError`,`Embed config error:`),` `,t]})}function A({system:e,deviceId:a,initialTarget:o,initialMuted:s}){let[c,l]=i(o),[u,d]=i(s),{handleOffer:f,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:_,getSessionState:y,getSessionDebug:b,applyDownlinkProbe:x}=g(e.trpcClient,a),C=t(()=>E(c),[c]),O=t(()=>(e,t)=>f(C,e,t),[f,C]),k=t(()=>(e,t,n)=>f(n,t,e),[f]);r(()=>(window.__camstackEmbed={setMuted:e=>d(e),setTarget:e=>{let t=S.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let A=D(c);return n(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:n(v,{serverUrl:e.serverUrl,streamKey:A,autoPlay:!0,muted:u,showControls:!1,className:`w-full h-full`,getSessionDebug:b,applyDownlinkProbe:x,handleOffer:O,reoffer:k,getSessionState:y,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:_,onStateChange:e=>w(T(e)),onError:e=>w(`error`,e)},A)})}function j(){let{t:e}=x(),i=t(()=>O(),[]),o=t(()=>{if(!i.ok)return null;let e=_({serverUrl:i.config.serverUrl,token:i.config.token}),t=new a({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}});return y(t),{system:e,queryClient:t}},[i]);return r(()=>{if(o)return()=>{o.system.close()}},[o]),i.ok?o?n(c,{system:o.system,children:n(s,{client:o.queryClient,children:n(b.Provider,{client:o.system.trpcClient,queryClient:o.queryClient,children:n(A,{system:o.system,deviceId:i.config.deviceId,initialTarget:i.config.target,initialMuted:i.config.muted})})})}):n(k,{message:e(`embedPlayerPage.failedToInitialiseTheEmbed`,`Failed to initialise the embed player`)}):n(k,{message:i.error})}export{j as EmbedPlayerPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,K as t,S as n,Y as r,et as i,i as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{En as s,Ht as c,Tr as l,ct as u,dt as d,fr as f,gt as p,ki as m,pa as h,st as g,xn as _}from"./player-overlays-CeCeKlFy.js";import{Ar as v,Ca as y}from"./client-gOfL8FDq.js";import{A as b,Ar as x,C as S,Dn as C,E as w,F as T,Hr as E,I as D,Kr as O,M as k,Mo as A,Mr as ee,N as te,Nr as j,O as M,On as N,Or as ne,P,S as F,Sr as re,T as ie,Tn as I,Xd as ae,_ as oe,_n as se,_r as ce,b as le,br as ue,ci as L,ei as R,f as de,g as fe,gr as pe,j as me,jr as z,k as he,m as ge,oo as _e,p as ve,so as ye,vn as be,vr as xe,w as Se,xr as Ce,y as we,yu as Te,zr as Ee}from"./src-Cq4wbXVd.js";import{t as B}from"./useTranslation-BJr-n0es.js";import{yr as De}from"./index-CUQ_1-3M.js";import{t as Oe}from"./AdminPage-DUSx45NB.js";i();function V(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function ke(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:S(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:V(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:S(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:V(t,n)})}return r}function Ae(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function H(e,t,n){if(e.ref.subject.kind!==`device`||t===null)return e.subjectName;let r=t.byId.get(e.ref.subject.deviceId);return r===void 0?e.subjectName:Ee(r,`compact`,t,n)}var je=[`energy`,`temperatures`,`nodes`,`storage`],Me=new Set([`cap:temperature-sensor.temperature`,`cap:climate-control.currentTemp`]),U=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],Ne=`addon:storage-orchestrator/location-used-percent`;function Pe(e,t){let n=(e,n)=>{let r=t.filter(e);return F((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&Me.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&U.includes(e.info.key)&&e.info.scope===``,(e,t)=>U.indexOf(e.info.key)-U.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===Ne)}}function Fe(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of F(e)){let e=n.get(S(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function W(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var G=`history-page`;function Ie({part:r,window:i}){let{t:a}=B(),o=h(),s=O(),c=E(),l=e=>`${H(e,s,c)} · ${e.metric}`,u=t(()=>[...r.lines,...r.states,...r.energy],[r]),d=fe(t(()=>u.map(e=>W(e.ref)),[u]),i,!1),f=e=>d.status===`ok`?d.data.current.get(ge(W(e.ref))):void 0,p=e=>{let t=f(e);return t?.ok?t.result:void 0};if(u.length===0)return n(z,{icon:m,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(d.status===`error`)return n(x,{title:a(`history.page.readFailed`,`History could not be read`),message:d.error});let g=d.status===`pending`,_=u.map(e=>({c:e,e:f(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=p(e),r=he(e.info,n,i.from);return{id:e.id,label:l(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),y=r.states.map((e,t)=>{let n=b(e.info,p(e),i.from,i.to),r=w(e.info.key,o);return{id:e.id,label:l(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),S=r.energy.map(e=>({c:e,...M(p(e))})),C=S[0]?.bucketMs??36e5,k=[...new Set(S.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:S.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[_.length>0&&n(x,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${l(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(D,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:G,pending:g}),S.length>0&&n(ne,{title:a(`history.page.energy`,`Energy`),layers:S.map((e,t)=>({id:e.c.id,label:H(e.c,s,c),colorIndex:t})),buckets:k,bucketMs:C,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:G,pending:g}),y.length>0&&n(T,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:G,pending:g})]})}function Le(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function Re(e,t){let n=[];for(let r of Le(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function K(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function ze(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+K(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function Be(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var q=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function J(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function Y(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function X(t,r,i){return{key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:Y(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:J(o,r,i)})]})},sortValue:e=>`${J(t(e),r,i)} ${Y(t(e))}`}}var Ve=[`raw`,`5m`,`1h`,`1d`];function He(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function Ue(t,r){return[X(e=>e,t,r),{key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(L,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:q(t.missingSince)})})]}),sortValue:e=>e.reason},{key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[q(t.firstTs),` → `,q(t.lastTs)]}),sortValue:e=>e.lastTs},...Ve.map(e=>({key:`rows-${e}`,header:He(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function We(e,t){if(e.ok)return n(L,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:K(e.deleted),points:K(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(L,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function Ge(e,t){return[X(e=>e.series,e,t),{key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>We(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function Ke({open:i,onClose:a,list:o,deviceNames:l,onDelete:u,onRefresh:d,refreshing:p}){let{t:m}=B(),h=g(),[_,v]=r(new Set),[y,b]=r(!1),[x,S]=r([]),w=t(()=>Ue(l,m),[l,m]),T=t(()=>Ge(l,m),[l,m]),E=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),D=[..._].filter(e=>E.has(e)).map(Number),O=ze(x.map(e=>e.outcome)),k=async()=>{if(await h({title:m(`history.orphans.confirmTitle`,{count:D.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:m(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:m(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){b(!0);try{let e=await Re(D,u);S(Be(o.series,e)),v(new Set)}finally{b(!1),d()}}};return n(pe,{open:i,onOpenChange:e=>!e&&a(),children:e(xe,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(Ce,{children:n(re,{children:m(`history.orphans.title`,`Series no longer linked to a device`)})}),e(ce,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:m(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:m(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(R,{size:`sm`,variant:`outline`,onClick:d,disabled:p,children:[n(s,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.loadAgain`,`Load again`)]})]}),x.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:m(`history.orphans.summary`,{count:O.deleted,refused:O.refused,points:O.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(C,{columns:T,rows:x,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(C,{columns:w,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:N,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:m(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:_,onChange:v,rowLabel:e=>`${Y(e)} — ${J(e,l,m)}`,pageLabel:m(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(ue,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:m(`history.orphans.selected`,{count:D.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(R,{variant:`ghost`,size:`sm`,onClick:a,children:m(`history.orphans.close`,`Close`)}),e(R,{variant:`danger`,size:`sm`,disabled:D.length===0||y,onClick:()=>void k(),children:[y?n(f,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(c,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Z=5*6e4;function qe({enabled:i}){let{t:a}=B(),[s,c]=r(!1),l=ye({},{enabled:i,staleTime:Z}),u=A({projection:`slim`},{enabled:i}),d=_e(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(x,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(x,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(R,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(Ke,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var Q=`device`,Je=`node`;function Ye({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=B(),c=O(),l=E(),u=e=>H(e,c,l),d=se(r,{searchText:e=>[Ae(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Q:Je},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),f=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?u(t):`${u(t)} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s,c,l]),p=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(be,{state:d.state,facets:[],groups:[{...d.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Q?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...d.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...d.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:d.setSearch,onToggleFacet:d.toggleFacet,onToggleGroupFacet:d.toggleGroupFacet,onClear:d.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(C,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:N,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):d.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!p,rowLabel:e=>`${u(e)} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var Xe=new Set([y.Hub,y.Container]),$=5*6e4;function Ze(){let{t:r}=B(),i=ee(`device-history`),[a,o]=De(),s=t(()=>F(a.getAll(`s`).flatMap(e=>{let t=we(e);return t===null?[]:[t]})),[a]),c=a.get(`window`),d=te(c)?c:`7d`,f=me(a.get(`range`)),h=(e,t,n)=>{let r=new URLSearchParams;for(let t of F(e))r.append(`s`,le(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},v=Qe(i===`present`),y=P(d,Date.now(),f),b=P(d,ve(Date.now(),y.to-y.from),f),C=t(()=>Fe(s,v.candidates),[s,v.candidates]),w=t(()=>new Set(s.map(S)),[s]),T=de(),E=u(),D=g(),O=async()=>{let e=await E({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await T.update(t=>Se(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:d,selection:[...s]}))},A=async(e,t)=>{await D({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await T.update(t=>ie(t,e))},M=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(Oe,{icon:m,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(R,{size:`sm`,variant:`outline`,onClick:()=>void O(),disabled:s.length===0||!T.writable,children:[n(_,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(j,{className:`h-64 w-full`}):i===`unknown`?n(x,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(z,{icon:l,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(qe,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[je.map(e=>n(R,{size:`sm`,variant:`outline`,disabled:v.status!==`ok`,onClick:()=>h(Pe(e,v.candidates),d),children:M(e)},e)),T.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(R,{size:`sm`,variant:`secondary`,onClick:()=>h(t.selection,t.window,null),children:t.name}),n(R,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void A(t.id,t.name),disabled:!T.writable,children:n(p,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(I,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:v.status===`error`?n(x,{message:v.error}):n(Ye,{catalog:v.candidates,loading:v.status===`pending`,selected:w,onChange:e=>{let t=s.filter(t=>e.has(S(t))),n=v.candidates.filter(t=>e.has(t.id)&&!w.has(t.id)).map(e=>e.ref);h([...t,...n],d)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(I,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:s.length>0?n(R,{size:`sm`,variant:`ghost`,onClick:()=>h([],d),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(oe,{value:d,onChange:e=>h(s,e),custom:f,onCustomChange:e=>h(s,`custom`,k(e))}),v.status===`pending`&&s.length>0?n(j,{className:`h-64 w-full`}):n(Ie,{part:C,window:b}),C.missing.length>0&&v.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:C.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function Qe(e){let{t:n}=B(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=d().trpcClient,o=A({projection:`slim`},{enabled:e}),{nodes:s}=ae(),c=t(()=>(o.data??[]).filter(e=>!Xe.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),f=Te({},{enabled:e,staleTime:$}),p=t(()=>new Map((f?.data??[]).map(e=>[e.id,e.displayName])),[f?.data]),m=l.map(e=>e.data),h=u.map(e=>e.data),g=t(()=>ke(c.flatMap((e,t)=>{let n=m[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return p.get(e.scope)??e.scope;let{zoneId:t,className:n}=v(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,p,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:g}}export{Ze as HistoryPage};
|
|
1
|
+
import{C as e,K as t,S as n,Y as r,et as i,i as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{En as s,Ht as c,Tr as l,ct as u,dt as d,fr as f,gt as p,ki as m,pa as h,st as g,xn as _}from"./player-overlays-DaSesfVn.js";import{Ar as v,Ca as y}from"./client-BjsFVjEa.js";import{A as b,Ar as x,C as S,Dn as C,E as w,F as T,Hr as E,I as D,Kr as O,M as k,Mo as A,Mr as ee,N as te,Nr as j,O as M,On as N,Or as ne,P,S as F,Sr as re,T as ie,Tn as I,Xd as ae,_ as oe,_n as se,_r as ce,b as le,br as ue,ci as L,ei as R,f as de,g as fe,gr as pe,j as me,jr as z,k as he,m as ge,oo as _e,p as ve,so as ye,vn as be,vr as xe,w as Se,xr as Ce,y as we,yu as Te,zr as Ee}from"./src-DxOL9qHw.js";import{t as B}from"./useTranslation-BJr-n0es.js";import{yr as De}from"./index-CuSxNbC8.js";import{t as Oe}from"./AdminPage-B_wUVHLs.js";i();function V(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function ke(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:S(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:V(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:S(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:V(t,n)})}return r}function Ae(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function H(e,t,n){if(e.ref.subject.kind!==`device`||t===null)return e.subjectName;let r=t.byId.get(e.ref.subject.deviceId);return r===void 0?e.subjectName:Ee(r,`compact`,t,n)}var je=[`energy`,`temperatures`,`nodes`,`storage`],Me=new Set([`cap:temperature-sensor.temperature`,`cap:climate-control.currentTemp`]),U=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],Ne=`addon:storage-orchestrator/location-used-percent`;function Pe(e,t){let n=(e,n)=>{let r=t.filter(e);return F((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&Me.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&U.includes(e.info.key)&&e.info.scope===``,(e,t)=>U.indexOf(e.info.key)-U.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===Ne)}}function Fe(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of F(e)){let e=n.get(S(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function W(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var G=`history-page`;function Ie({part:r,window:i}){let{t:a}=B(),o=h(),s=O(),c=E(),l=e=>`${H(e,s,c)} · ${e.metric}`,u=t(()=>[...r.lines,...r.states,...r.energy],[r]),d=fe(t(()=>u.map(e=>W(e.ref)),[u]),i,!1),f=e=>d.status===`ok`?d.data.current.get(ge(W(e.ref))):void 0,p=e=>{let t=f(e);return t?.ok?t.result:void 0};if(u.length===0)return n(z,{icon:m,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(d.status===`error`)return n(x,{title:a(`history.page.readFailed`,`History could not be read`),message:d.error});let g=d.status===`pending`,_=u.map(e=>({c:e,e:f(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=p(e),r=he(e.info,n,i.from);return{id:e.id,label:l(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),y=r.states.map((e,t)=>{let n=b(e.info,p(e),i.from,i.to),r=w(e.info.key,o);return{id:e.id,label:l(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),S=r.energy.map(e=>({c:e,...M(p(e))})),C=S[0]?.bucketMs??36e5,k=[...new Set(S.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:S.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[_.length>0&&n(x,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${l(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(D,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:G,pending:g}),S.length>0&&n(ne,{title:a(`history.page.energy`,`Energy`),layers:S.map((e,t)=>({id:e.c.id,label:H(e.c,s,c),colorIndex:t})),buckets:k,bucketMs:C,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:G,pending:g}),y.length>0&&n(T,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:G,pending:g})]})}function Le(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function Re(e,t){let n=[];for(let r of Le(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function K(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function ze(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+K(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function Be(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var q=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function J(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function Y(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function X(t,r,i){return{key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:Y(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:J(o,r,i)})]})},sortValue:e=>`${J(t(e),r,i)} ${Y(t(e))}`}}var Ve=[`raw`,`5m`,`1h`,`1d`];function He(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function Ue(t,r){return[X(e=>e,t,r),{key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(L,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:q(t.missingSince)})})]}),sortValue:e=>e.reason},{key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[q(t.firstTs),` → `,q(t.lastTs)]}),sortValue:e=>e.lastTs},...Ve.map(e=>({key:`rows-${e}`,header:He(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function We(e,t){if(e.ok)return n(L,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:K(e.deleted),points:K(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(L,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function Ge(e,t){return[X(e=>e.series,e,t),{key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>We(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function Ke({open:i,onClose:a,list:o,deviceNames:l,onDelete:u,onRefresh:d,refreshing:p}){let{t:m}=B(),h=g(),[_,v]=r(new Set),[y,b]=r(!1),[x,S]=r([]),w=t(()=>Ue(l,m),[l,m]),T=t(()=>Ge(l,m),[l,m]),E=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),D=[..._].filter(e=>E.has(e)).map(Number),O=ze(x.map(e=>e.outcome)),k=async()=>{if(await h({title:m(`history.orphans.confirmTitle`,{count:D.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:m(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:m(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){b(!0);try{let e=await Re(D,u);S(Be(o.series,e)),v(new Set)}finally{b(!1),d()}}};return n(pe,{open:i,onOpenChange:e=>!e&&a(),children:e(xe,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(Ce,{children:n(re,{children:m(`history.orphans.title`,`Series no longer linked to a device`)})}),e(ce,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:m(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:m(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(R,{size:`sm`,variant:`outline`,onClick:d,disabled:p,children:[n(s,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.loadAgain`,`Load again`)]})]}),x.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:m(`history.orphans.summary`,{count:O.deleted,refused:O.refused,points:O.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(C,{columns:T,rows:x,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(C,{columns:w,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:N,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:m(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:_,onChange:v,rowLabel:e=>`${Y(e)} — ${J(e,l,m)}`,pageLabel:m(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(ue,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:m(`history.orphans.selected`,{count:D.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(R,{variant:`ghost`,size:`sm`,onClick:a,children:m(`history.orphans.close`,`Close`)}),e(R,{variant:`danger`,size:`sm`,disabled:D.length===0||y,onClick:()=>void k(),children:[y?n(f,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(c,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Z=5*6e4;function qe({enabled:i}){let{t:a}=B(),[s,c]=r(!1),l=ye({},{enabled:i,staleTime:Z}),u=A({projection:`slim`},{enabled:i}),d=_e(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(x,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(x,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(R,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(Ke,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var Q=`device`,Je=`node`;function Ye({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=B(),c=O(),l=E(),u=e=>H(e,c,l),d=se(r,{searchText:e=>[Ae(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Q:Je},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),f=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?u(t):`${u(t)} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s,c,l]),p=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(be,{state:d.state,facets:[],groups:[{...d.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Q?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...d.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...d.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:d.setSearch,onToggleFacet:d.toggleFacet,onToggleGroupFacet:d.toggleGroupFacet,onClear:d.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(C,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:N,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):d.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!p,rowLabel:e=>`${u(e)} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var Xe=new Set([y.Hub,y.Container]),$=5*6e4;function Ze(){let{t:r}=B(),i=ee(`device-history`),[a,o]=De(),s=t(()=>F(a.getAll(`s`).flatMap(e=>{let t=we(e);return t===null?[]:[t]})),[a]),c=a.get(`window`),d=te(c)?c:`7d`,f=me(a.get(`range`)),h=(e,t,n)=>{let r=new URLSearchParams;for(let t of F(e))r.append(`s`,le(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},v=Qe(i===`present`),y=P(d,Date.now(),f),b=P(d,ve(Date.now(),y.to-y.from),f),C=t(()=>Fe(s,v.candidates),[s,v.candidates]),w=t(()=>new Set(s.map(S)),[s]),T=de(),E=u(),D=g(),O=async()=>{let e=await E({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await T.update(t=>Se(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:d,selection:[...s]}))},A=async(e,t)=>{await D({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await T.update(t=>ie(t,e))},M=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(Oe,{icon:m,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(R,{size:`sm`,variant:`outline`,onClick:()=>void O(),disabled:s.length===0||!T.writable,children:[n(_,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(j,{className:`h-64 w-full`}):i===`unknown`?n(x,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(z,{icon:l,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(qe,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[je.map(e=>n(R,{size:`sm`,variant:`outline`,disabled:v.status!==`ok`,onClick:()=>h(Pe(e,v.candidates),d),children:M(e)},e)),T.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(R,{size:`sm`,variant:`secondary`,onClick:()=>h(t.selection,t.window,null),children:t.name}),n(R,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void A(t.id,t.name),disabled:!T.writable,children:n(p,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(I,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:v.status===`error`?n(x,{message:v.error}):n(Ye,{catalog:v.candidates,loading:v.status===`pending`,selected:w,onChange:e=>{let t=s.filter(t=>e.has(S(t))),n=v.candidates.filter(t=>e.has(t.id)&&!w.has(t.id)).map(e=>e.ref);h([...t,...n],d)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(I,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:s.length>0?n(R,{size:`sm`,variant:`ghost`,onClick:()=>h([],d),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(oe,{value:d,onChange:e=>h(s,e),custom:f,onCustomChange:e=>h(s,`custom`,k(e))}),v.status===`pending`&&s.length>0?n(j,{className:`h-64 w-full`}):n(Ie,{part:C,window:b}),C.missing.length>0&&v.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:C.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function Qe(e){let{t:n}=B(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=d().trpcClient,o=A({projection:`slim`},{enabled:e}),{nodes:s}=ae(),c=t(()=>(o.data??[]).filter(e=>!Xe.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),f=Te({},{enabled:e,staleTime:$}),p=t(()=>new Map((f?.data??[]).map(e=>[e.id,e.displayName])),[f?.data]),m=l.map(e=>e.data),h=u.map(e=>e.data),g=t(()=>ke(c.flatMap((e,t)=>{let n=m[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return p.get(e.scope)??e.scope;let{zoneId:t,className:n}=v(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,p,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:g}}export{Ze as HistoryPage};
|