@camstack/addon-admin-ui 1.2.531 → 1.2.532

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/assets/{AddonAssetIcon-Cp5zLEvD.js → AddonAssetIcon-CfGdzQS1.js} +1 -1
  3. package/dist/assets/Addons-D2MV22hj.js +5 -0
  4. package/dist/assets/{AdminPage-D2S65e6Q.js → AdminPage-95Fx8-ai.js} +1 -1
  5. package/dist/assets/{AdminSectionedPage-CKX5JkdQ.js → AdminSectionedPage-CXlo0qGc.js} +1 -1
  6. package/dist/assets/{AiProfiles-BIQHK5vc.js → AiProfiles-Bb1UnC_U.js} +1 -1
  7. package/dist/assets/Build-B3Pfe7Gr.js +40 -0
  8. package/dist/assets/{Calendars-Brkz06fF.js → Calendars-6NC4XKbJ.js} +1 -1
  9. package/dist/assets/{Cluster-BtvDTlfe.js → Cluster-BK3JDN8a.js} +1 -1
  10. package/dist/assets/ComposedDeviceEditDialog-FYsRkLBz.js +1 -0
  11. package/dist/assets/CompositionBlockEditor-B5c79zIn.js +2 -0
  12. package/dist/assets/{CompositionEditorPage-GtC8DYG6.js → CompositionEditorPage-DC7kXor2.js} +1 -1
  13. package/dist/assets/{Data-39SL2gbC.js → Data-DXhl9LBq.js} +1 -1
  14. package/dist/assets/{DeviceDetail-C9eCLTmW.js → DeviceDetail-CXnY80TP.js} +2 -2
  15. package/dist/assets/{DeviceDoActionFields-Ca2TmJDn.js → DeviceDoActionFields-CoQ2tX-q.js} +1 -1
  16. package/dist/assets/Devices-C0JTSIZP.js +1 -0
  17. package/dist/assets/{EmbedPlayerPage-D91A6i3P.js → EmbedPlayerPage-BDaNxrOE.js} +1 -1
  18. package/dist/assets/{FormBuilder-C01MTb_b.js → FormBuilder-BTaNPSjN.js} +1 -1
  19. package/dist/assets/{History-OBh3harZ.js → History-CxgkTGB8.js} +1 -1
  20. package/dist/assets/{Identity-Bx-Ja-MP.js → Identity-BMPRwxzH.js} +1 -1
  21. package/dist/assets/{IntegrationDetail-TLO47L5-.js → IntegrationDetail-DuM1lFY-.js} +1 -1
  22. package/dist/assets/{IntegrationHub-C--hpDK-.js → IntegrationHub-DzmepqLp.js} +1 -1
  23. package/dist/assets/{Integrations-Cm9BV3o8.js → Integrations-B9EgQmNO.js} +1 -1
  24. package/dist/assets/{Integrations-GHsM_7uc.js → Integrations-CiSPvaJK.js} +1 -1
  25. package/dist/assets/{Library-D2EugVqE.js → Library-DcwBFLS2.js} +1 -1
  26. package/dist/assets/{Locations-Cb8RSNkt.js → Locations-DFR37ATW.js} +1 -1
  27. package/dist/assets/{Logs-Gsq1EPYC.js → Logs-CFR9B1vW.js} +1 -1
  28. package/dist/assets/{MaskShapeCanvas-4rUt1muq.js → MaskShapeCanvas-Du7NeQ1p.js} +1 -1
  29. package/dist/assets/{MotionZonesSettings-D8frKIxI.js → MotionZonesSettings-DEov5lgX.js} +1 -1
  30. package/dist/assets/{MyAccess-WsIYje4M.js → MyAccess-qH72oIKl.js} +1 -1
  31. package/dist/assets/Network-Bs4ySinW.js +1 -0
  32. package/dist/assets/{NodeAddonsSettingsPanel-DYEAw_0K.js → NodeAddonsSettingsPanel-CKuqtZiy.js} +1 -1
  33. package/dist/assets/Notifications-CrJqzOsT.js +1 -0
  34. package/dist/assets/Pipeline-DINXMlHJ.js +1 -0
  35. package/dist/assets/{PrivacyMaskSettings-LVUmj3W4.js → PrivacyMaskSettings-B3og-Ovf.js} +1 -1
  36. package/dist/assets/{Recordings-DeZnE3O5.js → Recordings-CcLwVhIE.js} +1 -1
  37. package/dist/assets/{RemoteGrid-CjSx3Aah.js → RemoteGrid-BJ5xj0Z6.js} +1 -1
  38. package/dist/assets/{ScanNetworkModal-CvlBpDgq.js → ScanNetworkModal-agfFGh7H.js} +1 -1
  39. package/dist/assets/{SceneMonitorEditor-CUgqZlLF.js → SceneMonitorEditor-RvxV30AA.js} +1 -1
  40. package/dist/assets/{SessionsList-CPlqGJSE.js → SessionsList-MVWwyBor.js} +1 -1
  41. package/dist/assets/{Showroom-CoWYMVAI.js → Showroom-CcxQEbpv.js} +1 -1
  42. package/dist/assets/{System-CqV_BBXI.js → System-mXNnser5.js} +1 -1
  43. package/dist/assets/Templates-DlXAN6pH.js +1 -0
  44. package/dist/assets/{Terminal-BiuPjGjh.js → Terminal-BShZ11PH.js} +1 -1
  45. package/dist/assets/{Trans-DlVN2FAm.js → Trans-BgSU9dw1.js} +1 -1
  46. package/dist/assets/{Viewer-VFeL3oiK.js → Viewer-BebHLPaG.js} +1 -1
  47. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BzI5prAS.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DIitQnBe.js} +1 -1
  48. package/dist/assets/{addon-icons-context-D_SbgBlL.js → addon-icons-context-v7m0a2FB.js} +1 -1
  49. package/dist/assets/addon-kind-filter-CEGKkC1O.js +1 -0
  50. package/dist/assets/{archive-BdOuJA6D.js → archive-DXMVa-lX.js} +1 -1
  51. package/dist/assets/{assignment-candidates-FrlfxULJ.js → assignment-candidates-66hRsjMW.js} +1 -1
  52. package/dist/assets/{authed-media-Cdlj2yED.js → authed-media-Czu7XTaj.js} +1 -1
  53. package/dist/assets/{bell-off-DE260sCQ.js → bell-off-CEN8nQp-.js} +1 -1
  54. package/dist/assets/{board-model-C8M8reLO.js → board-model-D8H0B0qn.js} +1 -1
  55. package/dist/assets/{boxes-ncBMqqF7.js → boxes-eRc-lVOF.js} +1 -1
  56. package/dist/assets/circle-slash-CX4B4mGW.js +1 -0
  57. package/dist/assets/client-AOeY3PoN.js +806 -0
  58. package/dist/assets/{cloud-upload-xWhkZB2K.js → cloud-upload-DUJt0JdH.js} +1 -1
  59. package/dist/assets/crop-BXN2L3sb.js +1 -0
  60. package/dist/assets/{device-integration-icon-DXsx1ovH.js → device-integration-icon-C4S0QaFp.js} +1 -1
  61. package/dist/assets/device-picker-model-CXUDiSMs.js +1 -0
  62. package/dist/assets/dist-Cx9VAEKP.js +806 -0
  63. package/dist/assets/{dist-CxGqD88j.js → dist-DM6wwJkd.js} +1 -1
  64. package/dist/assets/{file-up-DSkaqgrs.js → file-up-BBdOgTK9.js} +1 -1
  65. package/dist/assets/{format-5kuRrylR.js → format-42qUo1AE.js} +1 -1
  66. package/dist/assets/{grip-vertical-oBh5I9hk.js → grip-vertical-BmdvsAbL.js} +1 -1
  67. package/dist/assets/{hard-drive-download-BJ9Vaf4q.js → hard-drive-download-Bc1pBGlo.js} +1 -1
  68. package/dist/assets/{hostInit-ClzsOBVS.js → hostInit-D8BcPSGc.js} +1 -1
  69. package/dist/assets/i18n-DFGXm9ze.js +1 -0
  70. package/dist/assets/{icons-B7ZVbtoQ.js → icons-BtVYU84-.js} +1 -1
  71. package/dist/assets/{index-BoU7NTPo.js → index-DzxzA2lU.js} +3 -3
  72. package/dist/assets/{key-5z5CPQqC.js → key-CJv2Q3F2.js} +1 -1
  73. package/dist/assets/{key-round-DE61GWtp.js → key-round-QObyZIrV.js} +1 -1
  74. package/dist/assets/{layers-DUXoEBYs.js → layers-Bty4v-Tb.js} +1 -1
  75. package/dist/assets/{linked-devices-model-D76tAwE6.js → linked-devices-model-Cgwx8ecs.js} +1 -1
  76. package/dist/assets/{list-ordered-DSox6EY0.js → list-ordered-D-ONPhRl.js} +1 -1
  77. package/dist/assets/{location-owned-usage-BSaNp20e.js → location-owned-usage-CcliDqzu.js} +1 -1
  78. package/dist/assets/{memory-stick-f2B4Aw1x.js → memory-stick-Drrk6RL-.js} +1 -1
  79. package/dist/assets/{message-square-plus-DUwM59NW.js → message-square-plus-C1puLp2Z.js} +1 -1
  80. package/dist/assets/{mf-entry-bootstrap-0-167f91f2.js → mf-entry-bootstrap-0-31ab8284.js} +2 -2
  81. package/dist/assets/{mic-off-DpDwbFnF.js → mic-off-BSOCVNWB.js} +1 -1
  82. package/dist/assets/{monitor-off-Cevi7ihB.js → monitor-off-CnQwhS8p.js} +1 -1
  83. package/dist/assets/{monitor-smartphone-DPzM2qXf.js → monitor-smartphone-DOpzfamp.js} +1 -1
  84. package/dist/assets/mount-CXUDiSMs.js +1 -0
  85. package/dist/assets/{notification-schedule-field-B_Y6t98m.js → notification-schedule-field-BOCpJtoM.js} +1 -1
  86. package/dist/assets/{player-overlays-D0HsTHUG.js → player-overlays-CdeStLFY.js} +1 -1
  87. package/dist/assets/{recycle-CK0-gO9v.js → recycle-ClLhxLjT.js} +1 -1
  88. package/dist/assets/remoteEntry-CXTI50w4.js +1 -0
  89. package/dist/assets/{ruler-C_9y2OuS.js → ruler-coNtNpKS.js} +1 -1
  90. package/dist/assets/{scan-eye-Cqs3dsDB.js → scan-eye-BShVz2L8.js} +1 -1
  91. package/dist/assets/{scissors-BomV8klv.js → scissors-BxXRJpwa.js} +1 -1
  92. package/dist/assets/{search-x-Ck_vydrn.js → search-x-DpL8duZX.js} +1 -1
  93. package/dist/assets/{send-B8Po_JT_.js → send-ViRZe20J.js} +1 -1
  94. package/dist/assets/{settings-2-CyAo_nYh.js → settings-2-DvF55McU.js} +1 -1
  95. package/dist/assets/{shapes-CuqJ7CA_.js → shapes-DNn8cgSP.js} +1 -1
  96. package/dist/assets/{sigma-YkVVm5dQ.js → sigma-BEGwr5QF.js} +1 -1
  97. package/dist/assets/{speaker-iL5Ep2q1.js → speaker-GaNm4DAq.js} +1 -1
  98. package/dist/assets/src-CImrkf6y.js +67 -0
  99. package/dist/assets/{sso-popup-aQr_3YWW.js → sso-popup-BdhUqpKP.js} +1 -1
  100. package/dist/assets/{step-inspector-model-gcGmLTWD.js → step-inspector-model-BFTjgLfV.js} +1 -1
  101. package/dist/assets/{table-2-Bx38akVK.js → table-2-C8-ZYHKC.js} +1 -1
  102. package/dist/assets/{timer-reset-Z1XvH6K-.js → timer-reset-DN7ULNUA.js} +1 -1
  103. package/dist/assets/{unlink-Dx9zRmL9.js → unlink-86HtbCbI.js} +1 -1
  104. package/dist/assets/{usb-_-9JyMyy.js → usb-D-x3E2FA.js} +1 -1
  105. package/dist/assets/{use-device-bound-caps-BR0aNe6v.js → use-device-bound-caps-Co_MVwFl.js} +1 -1
  106. package/dist/assets/{use-scenes-feed-CNxJKI3Y.js → use-scenes-feed-YiyBa_Xr.js} +1 -1
  107. package/dist/assets/{use-stationary-objects-CFFufETF.js → use-stationary-objects-BQcBWrZ4.js} +1 -1
  108. package/dist/assets/useEventInvalidation-CXUDiSMs.js +1 -0
  109. package/dist/assets/{useNodeUrlSelection-zNi606-l.js → useNodeUrlSelection-Drl3e02l.js} +1 -1
  110. package/dist/assets/user-round-utP9DdB_.js +1 -0
  111. package/dist/assets/{user-x-DCKuWnFc.js → user-x-Zewc1EPo.js} +1 -1
  112. package/dist/assets/{variable-pzTTvzbo.js → variable-DkO97Gws.js} +1 -1
  113. package/dist/assets/{video-Dn2Lqozt.js → video-D8GbzI4M.js} +1 -1
  114. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-o917suSb.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BjuBkWi8.js} +2 -2
  115. package/dist/index.html +13 -13
  116. package/dist/server/addon.js +62303 -61890
  117. package/package.json +1 -1
  118. package/dist/assets/Addons-BES3OMn0.js +0 -5
  119. package/dist/assets/Build-DjlUwtu8.js +0 -40
  120. package/dist/assets/ComposedDeviceEditDialog-UYQVMVk7.js +0 -1
  121. package/dist/assets/CompositionBlockEditor-CYd3iEcq.js +0 -2
  122. package/dist/assets/Devices-DwFifk2g.js +0 -1
  123. package/dist/assets/Network-CjuJ-PkF.js +0 -1
  124. package/dist/assets/Notifications-DcpvQo5d.js +0 -1
  125. package/dist/assets/Pipeline-CoNbGWDs.js +0 -1
  126. package/dist/assets/Templates-CMETwZM5.js +0 -1
  127. package/dist/assets/circle-slash-bDMoAvuJ.js +0 -1
  128. package/dist/assets/client-3nhKn2xf.js +0 -711
  129. package/dist/assets/crop-BZhdHvRT.js +0 -1
  130. package/dist/assets/device-picker-model-yyadLjpT.js +0 -1
  131. package/dist/assets/dist-dKXZSA43.js +0 -711
  132. package/dist/assets/i18n-BTbD-8vc.js +0 -1
  133. package/dist/assets/mount-yyadLjpT.js +0 -1
  134. package/dist/assets/remoteEntry-CURqqH0d.js +0 -1
  135. package/dist/assets/src-D1j-98hX.js +0 -67
  136. package/dist/assets/useEventInvalidation-yyadLjpT.js +0 -1
  137. package/dist/assets/user-round-BnFLdVEf.js +0 -1
@@ -1,2 +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{$n as f,Ai as p,Ar as m,D as h,Dn as g,En as _,Fi as v,G as y,Gi as b,Hn as x,Ht as S,Ir as C,J as w,K as T,Ki as E,Kn as D,Kr as O,Ln as k,Nn as A,O as j,On as M,Ot as N,Qn as P,St as ee,Tn as te,V as ne,W as re,Z as F,_i as ie,_n as I,bt as ae,cr as oe,dr as se,dt as L,gr as R,gt as z,ha as ce,hr as B,ii as le,la as ue,ni as de,on as fe,pr as V,q as pe,qr as me,r as he,rn as ge,rr as _e,st as ve,t as ye,tr as be,ur as xe,xi as Se,yn as Ce,z as H}from"./player-overlays-D0HsTHUG.js";import{$a as U,Bn as we,Cr as Te,Dr as Ee,Ha as De,Hi as Oe,Hn as ke,Jt as Ae,Li as je,Lo as Me,Or as W,Po as Ne,Qa as Pe,Qt as Fe,Ro as Ie,Vn as Le,Xa as Re,Xt as ze,Yi as Be,Yt as Ve,Zt as He,da as Ue,eo as G,f as We,fi as Ge,ji as Ke,n as qe,nr as Je,qt as Ye,ra as Xe,tr as Ze,yi as Qe,zn as $e}from"./client-3nhKn2xf.js";import{t as et}from"./archive-BdOuJA6D.js";import{i as tt,n as nt,r as rt,t as it}from"./scan-eye-Cqs3dsDB.js";import{t as at}from"./bell-off-DE260sCQ.js";import{r as ot,t as st}from"./sigma-YkVVm5dQ.js";import{t as ct}from"./boxes-ncBMqqF7.js";import{n as lt}from"./video-Dn2Lqozt.js";import{t as ut}from"./circle-slash-bDMoAvuJ.js";import{t as dt}from"./file-up-DSkaqgrs.js";import{t as ft}from"./layers-DUXoEBYs.js";import{$t as pt,Ar as mt,Bd as ht,Bn as gt,Bs as _t,Bt as vt,Co as yt,Cr as bt,Dc as xt,Dn as St,Dr as Ct,Dt as wt,Ei as Tt,Er as Et,Et as Dt,Fc as Ot,Fl as kt,Fo as At,Fs as jt,Ga as Mt,Gr as Nt,Gt as Pt,Hd as Ft,Hr as It,Ht as Lt,Io as Rt,Ir as zt,It as Bt,Ja as Vt,Jt as Ht,Kd as Ut,Kr as Wt,Kt as Gt,Lc as Kt,Ln as qt,Lo as Jt,Ml as Yt,Mn as Xt,Mo as Zt,Nl as Qt,No as $t,On as en,Oo as tn,Or as nn,Ot as rn,Pd as an,Pl as on,Po as sn,Pr as K,Pt as cn,Qd as ln,Qt as un,Qu as dn,Rn as fn,Ro as pn,Rt as mn,Si as hn,Sn as gn,Sr as _n,Ti as vn,Tn as yn,Tr as bn,Ud as xn,Ur as Sn,Ut as Cn,V as wn,Vd as Tn,Vo as En,Vs as Dn,Wa as On,Wd as kn,Wl as An,Wo as jn,Wr as Mn,Xn as Nn,Xr as Pn,Xt as Fn,Ya as In,Yi as Ln,Yn as Rn,Yt as zn,Za as Bn,_u as Vn,a as Hn,af as Un,ao as Wn,at as Gn,au as Kn,br as qn,c as Jn,cl as Yn,cn as Xn,co as Zn,ct as Qn,d as $n,da as er,dt as tr,ef as nr,el as rr,en as ir,er as ar,et as or,fi as q,fl as sr,gc as cr,gl as lr,gu as ur,hc as dr,hn as fr,i as pr,ii as J,io as mr,it as hr,jl as gr,jr as _r,ki as vr,kn as yr,ko as br,ll as xr,lo as Sr,ls as Cr,lt as wr,mu as Tr,no as Er,o as Dr,of as Or,on as kr,ps as Ar,qo as jr,r as Mr,rf as Nr,sn as Pr,so as Fr,ss as Ir,st as Lr,ti as Rr,tn as zr,tr as Br,tt as Vr,ul as Hr,ut as Ur,vu as Wr,wi as Gr,wr as Kr,wt as qr,xl as Jr,xr as Yr,yo as Xr,yr as Zr,zn as Qr,zs as $r,zt as ei}from"./src-D1j-98hX.js";import{t as Y}from"./i18n-BTbD-8vc.js";import{t as ti}from"./Trans-DlVN2FAm.js";import{t as X}from"./useTranslation-BJr-n0es.js";import"./mount-yyadLjpT.js";import{$ as ni,A as ri,B as ii,D as ai,E as oi,F as si,H as ci,I as li,L as ui,O as di,P as fi,Q as pi,R as mi,T as hi,U as gi,V as Z,Y as _i,et as vi,k as yi,p as bi,v as xi,z as Si}from"./index-BoU7NTPo.js";import{n as Ci,t as wi}from"./format-5kuRrylR.js";import{a as Ti,r as Ei,t as Di}from"./ComposedDeviceEditDialog-UYQVMVk7.js";import{$ as Oi,A as ki,B as Ai,D as ji,E as Mi,F as Ni,H as Pi,I as Fi,J as Ii,K as Li,L as Ri,M as zi,N as Bi,O as Vi,P as Hi,Q as Ui,R as Wi,S as Gi,T as Ki,U as qi,V as Ji,W as Yi,X as Xi,Y as Zi,Z as Qi,_ as $i,at as ea,b as ta,c as na,d as ra,et as ia,f as aa,h as oa,it as sa,j as ca,k as la,l as ua,m as da,p as fa,q as pa,rt as ma,s as ha,tt as ga,u as _a,v as va,x as ya,z as ba}from"./CompositionBlockEditor-CYd3iEcq.js";import{t as xa}from"./assignment-candidates-FrlfxULJ.js";import{_ as Sa,b as Ca,i as wa,m as Ta,o as Ea,t as Da}from"./step-inspector-model-gcGmLTWD.js";import"./useEventInvalidation-yyadLjpT.js";import{t as Oa}from"./use-stationary-objects-CFFufETF.js";import{a as ka,i as Aa,n as ja,o as Ma,r as Na,s as Pa,t as Fa}from"./linked-devices-model-D76tAwE6.js";import{f as Ia,h as La,t as Ra}from"./RemoteGrid-CjSx3Aah.js";import{t as za}from"./authed-media-Cdlj2yED.js";c();function Ba(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 Va(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(Ba).filter(e=>e!==null);return n.length===0?null:n}var Ha=[[/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 Ua(e){for(let[t,n]of Ha)if(t.test(e))return n;return`generic`}function Wa(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 Ga={stream:M,detection:it,privacy:O,microphone:_e,speaker:N,listening:nt,archive:et,recording:rt,notifications:b,generic:fe};function Ka({deviceId:t}){let{t:n}=X(),a=l(),s=Number.isFinite(t),[c,u]=o(null),[d,f]=o(!1),p=sr({deviceId:t},{enabled:s});Mr([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=Va(p.data),h=kt({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 _=Wa(m),v=e=>c?.id===e.id?c.message:null;return e(Ft,{open:d,onOpenChange:f,children:[e(kn,{"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(xn,{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(qa,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function qa({row:t,failure:n,onToggle:r}){let{t:a}=X(),o=Ga[Ua(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 Ja({deviceId:t}){let n=Pt(L().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(me,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:n.label})]})}function Ya({parentDeviceId:t}){let{t:n}=X(),r=pi(),a=L(),{data:o,isLoading:s,isError:c}=Si(t),{data:l}=Zt({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=vt(l?.stableId??``,u,l?.childLayout),f=d.ungrouped,p=e=>r(`/devices/${String(e)}`),m=l?.name??``,h=(e,t)=>i(mn,{trpc:a.trpcClient,device:{...t,name:Gt(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(ei,{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(ei,{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 Xa({deviceId:e}){let t=L(),{data:n,isLoading:r}=mi(e),{data:a,isLoading:o}=Si(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(Ht,{trpc:t.trpcClient,children:c,linkDeviceId:l,primaryChildEntityId:u})})}c();function Za({dev:t,busy:n,setBusy:r}){let{t:a}=X(),s=t?.motionTrigger,c=w(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(ue,{className:`h-3 w-3`}),i(`span`,{children:m})]})}c();function Q({deviceId:t,deviceType:n,features:r}){let a=L(),s=un(n)?.HeroCard??pt,c=T(a.trpcClient,t),l=w(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(Fn,{lastChangedAt:p})}):null,i(s,{trpc:a.trpcClient,deviceId:t,features:r}),i(`div`,{className:`flex justify-center`,children:i(Za,{dev:c,busy:u,setBusy:d})})]})}function Qa({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(ir,{trpc:L().trpcClient,deviceId:e,features:t})})}function $a({deviceId:e,features:t}){return i(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:i(pt,{trpc:L().trpcClient,deviceId:e,features:t})})}function eo(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function to(e){if(!e)return null;let t=eo(e.data);return t===null?e.eventType:Y.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var no=1e3,ro=60*no,io=60*ro,ao=24*io;function oo(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<no?Y.t(`helpers.relativeTime.justNow`):n<ro?Y.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/no)}):n<io?Y.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/ro)}):n<ao?Y.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/io)}):Y.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/ao)})}c();var so=1500,co=15e3,lo=1e3;function uo({deviceId:n}){let{t:r}=X(),s=T(L().trpcClient,n)?.state.eventEmitter,c=w(s);a(()=>{if(!s)return;s.refresh();let e=setInterval(()=>{s.refresh()},co);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)},so);return()=>{clearTimeout(t)}},[u]);let[h,g]=o(()=>Date.now());a(()=>{let e=setInterval(()=>{g(Date.now())},lo);return()=>{clearInterval(e)}},[]);let _=to(l),v=c?.eventTypes??[],y=c?.eventCountSinceStart??0,b=c!==void 0,x=eo(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:_??r(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:i(f?P:m,{className:`h-10 w-10`})}),e(`div`,{className:`text-center`,children:[x!==null&&i(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:r(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(x)})}),i(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${_?`text-foreground`:`text-foreground-subtle`}`,children:_??(b?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?oo(l.timestamp,h):r(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),v.length>0&&i(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:v.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:y})})]})}function fo({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(ci,{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(Ur,{status:a?`online`:`offline`}),o.length>0&&i(gi,{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 po({deviceId:t}){let{t:r}=X(),a=l(),o=mr({deviceId:t},{refetchInterval:1e4,retry:!1}),s=Wn({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),a.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),c=n(()=>mo(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(ho,{label:r(`hero.hubHero.discovered`,`Discovered`),value:c.total,icon:i(D,{className:`h-3.5 w-3.5`})}),i(ho,{label:r(`hero.hubHero.adopted`,`Adopted`),value:c.adopted,accent:`success`}),i(ho,{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(V,{className:`h-3.5 w-3.5 animate-spin`}):i(g,{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(go,{icon:i(ae,{className:`h-3 w-3 text-emerald-500`}),label:r(`hero.hubHero.online`,`{{online}} online`,{online:c.online})}),i(go,{icon:i(f,{className:`h-3 w-3 text-amber-500`}),label:r(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:c.sleeping})}),i(go,{icon:i(ee,{className:`h-3 w-3 text-destructive`}),label:r(`hero.hubHero.offline`,`{{offline}} offline`,{offline:c.offline})}),c.unknown>0?i(go,{icon:i(ie,{className:`h-3 w-3 text-foreground-subtle`}),label:r(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:c.unknown})}):null]})]})}function mo(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 ho({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 go({icon:t,label:n}){return e(`span`,{className:`inline-flex items-center gap-1`,children:[t,i(`span`,{children:n})]})}var _o={[G.Switch]:Q,[G.Siren]:Q,[G.Light]:Q,[G.Sensor]:Q,[G.Button]:Q,[G.Hub]:po,[G.Cover]:Qa,[G.Valve]:Q,[G.Humidifier]:Q,[G.WaterHeater]:Q,[G.Container]:Xa,[G.Lock]:Q,[G.Fan]:Q,[G.Thermostat]:Q,[G.Climate]:Q,[G.MediaPlayer]:Q,[G.Control]:Q,[G.AlarmPanel]:Q,[G.EventEmitter]:uo,[G.Notifier]:$a,[G.Script]:Q,[G.Automation]:Q,[G.Presence]:Q,[G.Update]:Q,[G.Vacuum]:Q,[G.LawnMower]:Q,[G.Weather]:Q,[G.Image]:Q,[G.PetFeeder]:Q,[G.PetFountain]:Q,[G.Dishwasher]:Q};function vo(e){return _o[e]??fo}function yo({deviceId:e}){let t=pe(L().trpcClient,e,e=>e.runningState);if(t===void 0||t.running!==!0&&t.running!==!1)return i(d,{});let n=t.running;return i(Qr,{running:n,since:t?.since??null,phase:t?.phase??null,className:`px-3 pt-2 sm:px-4`})}function bo(t){let n=vo(t.deviceType);return e(d,{children:[i(yo,{deviceId:t.deviceId}),i(n,{...t})]})}function xo({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(Zr,{widgetId:t.widgetId,deviceId:t.deviceId});return i(`div`,{children:t.deviceId===e?n:i(Rr,{deviceId:t.deviceId,children:n})},t.widgetId)})})}function So(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 Co(e){let t=So(e),n=new Set(t.map(e=>e.widgetId)),r=e.child===void 0?[]:So(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 wo(e){return Dr(L().trpcClient,e)}c();function To(e){let[n,i]=o(`idle`),[s,c]=o(null),l=t(null),u=t(null),d=t(null),f=t(!0),p=_t(),m=$r(),h=Dn(),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 Eo=0;function $(){return++Eo}function Do(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Oo(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 ko(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 Ao(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 jo({scope:n,greeting:s,className:c}){let{t:l}=X(),d=L(),[f,p]=o(()=>{let e=[];return s&&e.push({id:$(),kind:`info`,text:s}),e.push({id:$(),kind:`info`,text:`scope: ${Do(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: ${Do(n)}`}]),h(``);return}if(t===`help`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Oo(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(t===`context`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Ao(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(t===`examples`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...ko(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: ${Do(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 Mo(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 No({deviceId:e,intercomAvailable:t=!1}){let r=L(),a=typeof window<`u`?F():``,o=Number.isFinite(e),s=wo(o?e:null),c=Oa(o?[e]:[]),l=n(()=>{if(!o)return;let e=[];for(let t of c.rows){let n=Hn(t);n!==null&&e.push(n)}return e},[o,c.rows]),{streams:u,pipelineMetrics:f,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:_,getIceCandidates:v,closeSession:b,getSessionState:x,applyDownlinkProbe:S}=yn(r.trpcClient,o?e:null),C=y(o?e:null,{width:Ro}),w=To(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=_r(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=Mo(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(or,{serverUrl:a,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:_,getIceCandidates:v,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 Po({deviceId:e,containerDeviceId:t}){let{t:n}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full`,children:i(Xn,{...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 Fo({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(jo,{scope:{type:`device`,deviceId:e},greeting:n,className:`h-full border-0 rounded-none`})}function Io({deviceId:e}){let{t}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:i(Pr,{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 Lo({deviceId:e}){let{t}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:i(kr,{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 Ro=960;function zo({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 Bo({label:t=`Location`,layout:r=`inline`,bound:a}){let{t:o}=X(),{data:s}=En(),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(oe,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),i(`span`,{className:`truncate`,children:t})]},t))})]})})}var Vo=`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`,Ho=0,Uo=10;function Wo(e){if(e.trim()===``)return``;let t=Number.parseInt(e,10);return Number.isFinite(t)?String(t<Ho?Ho:t>Uo?Uo:t):``}function Go({value:e,onChange:t,disabled:n=!1,placeholder:r,className:a,id:o,"aria-label":s}){return i(`input`,{type:`number`,min:Ho,max:Uo,step:1,id:o,className:a??Vo,"aria-label":s,placeholder:r,value:e,onChange:e=>{t(Wo(e.target.value))},disabled:n})}function Ko({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:Qe(e)}),fallbackGlyph:r,labels:l,disabled:o}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n===``?a:n})]})}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`;function Jo(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function Yo({device:t,role:n,display:r,onChange:a}){let o=ce();nr();let{t:s}=X(),c=l(),u=n===null?void 0:zr[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:Ne(h),_=g===void 0?void 0:De(g),{data:v}=sn({},{staleTime:6e4,enabled:n!==null}),y=Ir({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),b=()=>{if(n===null)return;let e=Jo(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:ln(x),C=n===null?Un(t.type,o):Nr(n,o),w={icon:S??C.icon,label:S===void 0?C.label:String(x)},T=n===null&&t.type===G.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(Ko,{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:qo,"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(wn,{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(Go,{"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 Xo(e){return typeof e.linkDeviceId==`number`}var Zo=new Set(Object.values(U));function Qo(e){return Zo.has(e)}var $o={[G.Switch]:[U.Siren,U.Floodlight,U.Spotlight,U.PirSensor,U.Chime,U.Autotrack,U.Nightvision,U.PrivacyMask,U.BinaryHelper],[G.Light]:[U.Floodlight,U.Spotlight,U.Nightvision],[G.Siren]:[U.Siren],[G.Button]:[U.Doorbell],[G.Sensor]:[U.MotionSensor,U.ContactSensor,U.LeakSensor,U.SmokeSensor,U.COSensor,U.GasSensor,U.TamperSensor,U.VibrationSensor,U.ConnectivitySensor,U.SoundSensor,U.BinarySensor,U.TemperatureSensor,U.HumiditySensor,U.AmbientLightSensor,U.PressureSensor,U.WindSensor,U.RainSensor,U.UvSensor,U.SolarRadiationSensor,U.SoilMoistureSensor,U.PowerSensor,U.EnergySensor,U.VoltageSensor,U.CurrentSensor,U.AirQualitySensor,U.BatterySensor,U.NumericSensor,U.EnumSensor,U.DateTimeSensor,U.GenericSensor],[G.Control]:[U.NumericControl,U.SelectControl,U.TextControl,U.DateTimeControl],[G.Notifier]:[U.MobilePushNotifier,U.MessagingNotifier,U.EmailNotifier,U.GenericNotifier]};function es(e){for(let t of Object.values(G))if(t===e)return!0;return!1}function ts(e){return es(e)?$o[e]??[]:[]}function ns(e,t){let n=ts(t);return e==null||e===``||n.includes(e)?n:[...n,e]}function rs({device:t}){let{t:n}=X(),r=ce(),a=li(),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:`${j} ${h}`,children:[e(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[d?i(zo,{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(Bo,{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(Nn,{"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:Xo(t)||!d?i(`span`,{children:is(l,n(`customize.identity.noRole`),r)}):i(an,{"aria-label":n(`customize.identity.role`),value:l??``,options:[{value:``,label:n(`customize.identity.noRole`)},...ns(l,t.type).map(e=>({value:e,label:is(e,n(`customize.identity.noRole`),r)}))],onChange:e=>a.setIdentityRole(e.target.value===``?null:e.target.value)})})]}),o!==null&&a!==null&&i(Yo,{device:t,role:l,display:o.display,onChange:a.setIdentityDisplay})]})}function is(e,t,n){return e==null||e===``?t:Qo(e)?Nr(e,n).label:e}function as(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 os(e){let t=Le({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 ss(e,t){return{deviceId:e,config:t.config}}function cs(e,t){return{deviceId:e,patch:{motionCooldownMs:t}}}async function ls(e,t,n,r){await n(ss(e,t)),await r(cs(e,t.timeoutMs))}c();function us(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(qn,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(_n,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(bn,{children:i(Et,{children:r})}),t.open?i(ds,{...t}):null]})})}function ds(t){let{t:r}=X(),a=Rt({projection:`slim`}),s=Oi(n(()=>a.status===`success`?ea(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>fs(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=ps(c),b=y.length===0?null:as({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=Ar({deviceId:c[0]?.deviceId??0}),C=hs(S.status===`success`?S.data:void 0,x),w=He(Ve,C,Math.round(_*1e3));return e(d,{children:[e(Yr,{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(Ui,{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(ms(C,w.lastPressedAt))}):null]}),e(Kr,{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 fs(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 ps(e){return e.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,changedAtField:e.changedAtField??Re[e.cap]??`lastChangedAt`}))}function ms(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 hs(e,t){if(e===void 0||t===null)return{kind:`unread`};let n=e[t.cap],r=n===void 0?void 0:sa(n,t.fieldPath),i=Re[t.cap]??t.changedAtField,a=n===void 0?void 0:sa(n,i);return typeof r==`boolean`?{kind:`level`,active:r,changedAt:typeof a==`number`&&Number.isFinite(a)?a:null}:{kind:`unread`}}function gs(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=_s(t,n);return r===null?{kind:`unknown`,seconds:null}:{kind:`active`,seconds:r}}function _s(e,t){if(e==null||!Number.isFinite(e)||e<wi)return null;let n=Math.floor((t-e)/1e3);return n<0?0:n}function vs(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>=wi?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 ys={id:0,name:``,type:`unknown`,stableId:``,parentDeviceId:null};function bs({device:t,handle:n,availability:r,cap:a,title:s,view:c}){let{t:l,i18n:u}=X(),f=Ai(),[p,m]=o(!1),[h,g]=o(null),_=pa(n.state),v=Ji(_,a),y=Ss(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=Zi(x),C=b?.draft.sources[0]??null,w=C===null||S.kind!==`known`?null:S.value.find(e=>Xe({addonId:e.addonId,stableId:e.stableId})===Xe(C))??null,T=Cs(x,S.kind,w!==null),D=Mn(w===null?ys:ia(w),`compact`),O=Mn(t,`full`),k=Ye({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}),A=n.state.kind===`none`||n.state.kind===`present`;if(r.kind===`absent`||!c.deviceTypes.includes(t.type))return null;let j=async e=>{let t=await n.save(e);g(t.kind===`refused`?t.reason:null)},M=ws(b),N=b?.draft.edges?.[0],P=N!==void 0&&c.edges.includes(N)?N:c.defaultEdge,ee=C===null?``:ma(C.cap,C.fieldPath,u.language),te=y.kind===`known`&&y.value===null,ne=!x&&y.kind===`known`&&y.value!==null;return e(d,{children:[i(Qi,{id:a,icon:E,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(Nn,{"aria-label":l(`customize.doorbell.active`),checked:v.enabled!==!1,disabled:!A||n.saving,onChange:e=>{j(qi(_,n.target,{...v,enabled:e.target.checked}))}}),l(`customize.doorbell.active`)]}),i(q,{children:l(Fi(k.text,k.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`&&!A?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:D,field:ee})}),x&&i(xs,{deviceId:t.id,cap:a,timestampPath:c.timestampPath,counterPath:c.counterPath,startedAt:n.state.kind===`present`?n.state.view.block.createdAt:null}),ne&&v!==null&&e(`p`,{className:`text-xs text-foreground flex flex-wrap items-center gap-1`,children:[l(`customize.doorbell.otherFormula`),i(zi,{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=Yi(_,a);f(l(`customize.doorbell.removeWhat`,{name:w===null?O:D}),e===null).then(t=>{t&&j(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(us,{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:P,sources:M,canSave:A&&!n.saving,onClose:()=>m(!1),onSave:e=>{m(!1),j(qi(_,n.target,e))}})]})}function xs({deviceId:t,cap:n,timestampPath:r,counterPath:a,startedAt:o}){let{t:s}=X(),c=ba({deviceId:t,cap:n,path:r}),l=ba({deviceId:t,cap:n,path:a}),u=vs(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?``:Ci(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:Ci(u.lastPressedAt)}),u.pressCount===null?``:` · ${s(`customize.event.doorbellCount`,{count:u.pressCount})}`]})}function Ss(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 Cs(e,t,n){return e?t===`pending`?`pending`:t===`unknown`?`unknown`:n?`present`:`absent`:`present`}function ws(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 Ts(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(qn,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(_n,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(bn,{children:i(Et,{children:r})}),t.open?i(Es,{...t}):null]})})}function Es(t){let{t:r}=X(),a=Rt({projection:`slim`}),s=Oi(n(()=>a.status===`success`?ea(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>Ds(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=Os(c),b=os({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(Yr,{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(Ui,{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(ks,{deviceId:x.deviceId,cap:x.cap,fieldPath:x.fieldPath,timeoutMs:Math.round(h*1e3)})]}),e(Kr,{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 Ds(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 Os(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 ks({deviceId:e,cap:t,fieldPath:n,timeoutMs:r}){let{t:a}=X(),o=ba({deviceId:e,cap:t,path:n}),s=o.kind===`value`&&typeof o.value==`boolean`?{kind:`level`,active:o.value,changedAt:null}:{kind:`unread`},c=Fe(ze,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(As(s,c.open))})}function As(e,t){return e.kind===`unread`?`customize.event.previewWaiting`:t?`customize.event.previewMotionOn`:e.active?`customize.event.previewSensorOn`:`customize.event.previewMotionOff`}c();function js({device:n,availability:r,cap:a,title:s,view:c,sensors:l}){let{t:u}=X(),f=Yt(),p=rr(),m=vr({addonId:`pipeline-orchestrator`,deviceId:n.id,nodeId:`hub`}),[h,g]=o(!1),[_,v]=o(null),y=t(!1),[b,x]=o(!1),S=Ns(l),C=Zi(!0),w=Ae(c.id,S),T=Ls(Sa(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 ls(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(Qi,{id:a,icon:ue,title:s,testId:`event-card-${a}`,actions:i(q,{children:u(Fi(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(Ps,{reason:Is(S)||(r.kind===`unknown`?r.reason:``)}):e(d,{children:[i(Ms,{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(Fs,{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(Ts,{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 Ms({deviceId:e}){let{t}=X(),n=ba({deviceId:e,cap:`motion`,path:`detected`}),r=ba({deviceId:e,cap:`motion`,path:`lastDetectedAt`}),a=gs(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 Ns(e){return e.presence===`pending`?{kind:`pending`}:e.status===null?{kind:`unknown`,reason:e.failureReason}:{kind:`known`,value:e.status}}function Ps({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 Fs({row:e,fleet:t}){let n=Wt();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:ga(ia(r),t.value.map(ia),n)}function Is(e){return e.kind===`unknown`?e.reason??``:e.kind===`known`&&e.value.state===`unreadable`?e.value.reason:``}function Ls(e,t){return e!==null&&Number.isFinite(e)?e:t}var Rs=ke;function zs(e,t){let n=Rs[e];return n===void 0?null:n.targets.find(e=>e.id===t)??null}function Bs({device:e,handle:t,facts:n,sensors:r}){let{t:a}=X();return i(d,{children:Ri().map(o=>{let s=o.pulse??o.span;if(s===null||!s.deviceTypes.includes(e.type))return null;let c=zs(o.cap,s.id);if(c===null)return null;let l=a(o.pulse===null?`customize.motion.title`:`customize.doorbell.title`),u=Bi(Ni(o.cap,c),n);return o.pulse===null?o.span===null?null:i(js,{device:e,availability:u,cap:o.cap,title:l,view:o.span,sensors:r},o.cap):i(bs,{device:e,handle:t,availability:u,cap:o.cap,title:l,view:o.pulse},o.cap)})})}function Vs({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(Qi,{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 Hs=`flex items-center gap-2 px-3 py-2 text-sm sm:px-4`,Us=`list-none px-3 py-2 text-xs text-foreground-subtle sm:px-4`;function Ws({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 Gs({device:t}){let{t:n}=X(),r=l(),a=Gr({}),s=hn({deviceId:t.id}),[c,u]=o(!1),[f,p]=o([]),m=()=>void r.invalidateQueries({queryKey:[[`actions`]]}),h=Tt({onSuccess:m}),g=vn({onSuccess:m}),_=a.data??[],v=s.data?.actionIds??[],y=v.flatMap(e=>_.filter(t=>t.id===e)),b=_.filter(e=>!v.includes(e.id)),x=s.data!==void 0&&a.data!==void 0,S=e=>h.mutate({deviceId:t.id,actionIds:[...e]}),C=()=>{p([]),u(!0)},w=e=>p(f.includes(e)?f.filter(t=>t!==e):[...f,e]);return e(d,{children:[e(Vs,{id:`linked-actions`,icon:B,title:n(`customize.linkedActions.title`,`Linked actions`),addLabel:n(`customize.linkedActions.add`,`Add`),onAdd:x&&b.length>0?C:void 0,addDisabled:h.isPending,children:[!x&&i(`li`,{className:Us,children:n(`customize.linkedActions.loading`,`Checking linked actions.`)}),x&&y.length===0&&i(`li`,{className:Us,children:n(`customize.linkedActions.none`,`None linked.`)}),y.map(r=>e(`li`,{className:Hs,children:[i(`span`,{className:`min-w-0 flex-1 truncate`,children:r.name}),i(Ws,{entry:r}),i(ht,{icon:k,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(ht,{icon:z,variant:`ghost`,size:`sm`,"aria-label":n(`customize.linkedActions.unlink`,`Unlink {{name}}`,{name:r.name}),disabled:h.isPending,onClick:()=>S(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:Us,children:n(`customize.linkedActions.hint`,`Linked actions show as buttons on this camera. Nothing is linked unless you pick it.`)})]}),i(qn,{open:c,onOpenChange:u,children:e(_n,{placement:`sheet-on-mobile`,children:[e(bn,{children:[i(Et,{children:n(`customize.linkedActions.pickTitle`,`Link actions to {{name}}`,{name:t.name})}),i(bt,{children:n(`customize.linkedActions.pickHint`,`Pick the actions to link. Nothing is chosen for you.`)})]}),i(Yr,{children:i(`ul`,{className:`space-y-1`,children:b.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(Nn,{checked:f.includes(t.id),onChange:()=>w(t.id)}),i(`span`,{className:`flex-1`,children:t.name}),i(Ws,{entry:t})]})},t.id))})}),e(Kr,{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:()=>{S([...v,...f]),u(!1)},children:n(`customize.linkedActions.addN`,`Add {{count}}`,{count:f.length})})]})]})})]})}c();function Ks(e,t){let r=typeof e==`string`&&e.length>0,i=Zi(t&&r);return n(()=>t?ya(i,e):null,[t,i,e])}c();function qs(e){return e==null?null:e.message}function Js({device:t}){let n=ce(),{t:r}=X(),a=l(),s=Ai(),c=Ge.includes(t.type),[u,f]=o(!1),[p,m]=o(!1),[h,g]=o(null),_=Zn({deviceId:t.id},{enabled:c}),v=Na({status:_.status,data:_.data,error:qs(_.error)===null?null:{message:qs(_.error)??``}}),y=v.kind===`present`?v.slot.slotRef:``,b=v.kind===`present`?[...ja(v.slot,v.value).map(e=>e.deviceId),...Aa(v.slot,v.value)]:[],x=Sr(),S=Zi(c&&v.kind===`present`&&(u||b.length>0)),C=Ks(t.location,c&&v.kind===`present`),w=Fr({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(Vs,{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:xa(n.integration,n.location),orphan:t}},k=[...ja(v.slot,T).map(e=>O(e,!1)),...Aa(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:qs(w.error)??r(`helpers.customize.requestFailed`)}:S.kind===`pending`||w.status===`pending`||w.data===void 0?{kind:`pending`}:{kind:`known`,value:Fa(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)}},N=async e=>{await s(r(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await M(Pa(T,e.deviceId))},P=[{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?`—`:Un(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(Rn,{checked:e.tracked,disabled:p,"aria-label":r(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void M(Ma(T,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:i(ht,{icon:z,variant:`ghost`,size:`sm`,"aria-label":r(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:p,onClick:t=>{t.stopPropagation(),N(e)}})}];return e(d,{children:[i(Vs,{id:`linked`,icon:R,title:r(`customize.linked.title`),addLabel:r(`customize.linked.add`),onAdd:p?void 0:()=>f(!0),...C===null?{}:{suggestion:{count:Gi(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(cn,{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:Un(e.type,n).label,columns:P,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(ta,{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(ka(T,e.map(e=>e.deviceId)))},onClose:()=>f(!1)})]})}c();function Ys(e){return e instanceof Error?e.message:String(e)}function Xs(e){let n=In({addonId:e.addonId,stableId:e.stableId}),r=On(),i=Er(),a=Mt(),s=Ii({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=Pi(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:Ys(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 Zs=`pipeline-orchestrator`;function Qs(e){return e.data===void 0?e.status===`pending`?`pending`:e.status===`error`?`unknown`:`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function $s(e,t){return e===`absent`?`absent`:Qs(t)}async function ec(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function tc(e,t){let n=zt(Zs),r=Hr({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>ec(r.refetch),a=r.data===void 0&&r.status===`error`?r.error?.message??null:null;return t?{presence:$s(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 nc(e,t){let n=Bn({deviceType:e.type}),r=br({deviceId:e.id}),i=At({deviceId:e.id}),a=Xi(n,e=>new Set(e.caps.map(e=>e.cap))),o=Xi(r,e=>Hi(e.entries)),s=Xi(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}function rc(e,t,n){let r=t.kind===`known`&&t.value.has(`consumables`),i=ba(r?{deviceId:e,cap:la,path:ki}:null);return ca(t,n,r?i:null)}var ic=`ir-transmitter`;function ac(e,t){let n=new Map(t.customButtons.map(e=>[W(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=Ee(e)!==null;a.push({role:e,custom:o,inLayout:t,name:o?n.get(e)??r.get(e)??Ia(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 oc(e,t,n){let r=Ee(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 sc(e,t,n,r=Ia(t)){return oc({...e,bindings:{...e.bindings,[t]:{action:n}}},t,r)}function cc(e,t){let n=Object.fromEntries(Object.entries(e.bindings).filter(([e])=>e!==t)),r=Ee(t);return{...e,bindings:n,customButtons:r===null?e.customButtons:e.customButtons.filter(e=>e.key!==r)}}function lc(e){return e.deviceId>0&&e.cap!==``&&e.method!==``}var uc={kind:`cap`,deviceId:0,cap:``,method:``};function dc(e){let{action:t}=e;return t.cap===`ir-transmitter`&&t.method===`send`?t.deviceId:null}function fc(e,t){return{action:{...e.action,deviceId:t}}}function pc(e){let t=Object.entries(e.bindings).filter(([,e])=>!lc(e.action)).map(([e])=>e);if(t.length>0)return{incomplete:t,config:null};let n=Te.safeParse(e);return{incomplete:t,config:n.success?n.data:null}}function mc(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=qe(n),r=Ze(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 Je)return{status:`refused`,reason:`not-smartir`};throw e}}function hc(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 gc({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}`,Ia(t.role)),_=n===void 0?null:dc(n),v=n!==void 0&&lc(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(uc)},"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(an,{"aria-label":p(`remote.bindings.transmitterFor`,{name:g}),value:String(_),options:a.map(e=>({value:String(e.id),label:e.name})),onChange:e=>l(fc(n,Number(e.target.value)).action),"data-testid":`transmitter-${t.role}`}),y&&_===null&&n!==void 0&&i(Ti,{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 _c({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:mc(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(Dt,{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 vc({device:t,open:n,onClose:r}){let{t:a}=X(),o=Tr({deviceId:t.id},{enabled:n});return i(qn,{open:n,onOpenChange:e=>!e&&r(),children:e(_n,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(bn,{children:i(Et,{children:a(`remote.dialog.title`,{name:t.name})})}),o.data===void 0?i(Yr,{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(bc,{device:t,initial:o.data,onClose:r})]})})}function yc(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 bc({device:t,initial:r,onClose:a}){let{t:s}=X(),c=l(),[u,f]=o(r),[p,m]=o(null),[h,g]=o({}),_=dn({kind:`remote`}),v=ur({deviceId:t.id}),y=Ei(),b=pn({capNames:[ic]}),x=Wr(),S=Vn(),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:La(w.payload),E=n(()=>ac(T,u),[T,u]),D=n(()=>new Set((v.data?.commands??[]).map(e=>e.role)),[v.data]),O=pc(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]:yc(n,s)}))}catch(t){g(n=>({...n,[e]:t instanceof Error?t.message:String(t)}))}},M=(e,t)=>f(n=>sc(n,e,t));return e(d,{children:[e(Yr,{className:`space-y-5`,children:[e(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[i(Dt,{label:s(`remote.dialog.template`),children:i(an,{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(Dt,{label:s(`remote.dialog.transmitter`),children:i(an,{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(Dt,{label:s(`remote.dialog.power`),children:i(an,{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(Ra,{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(_c,{transmitterId:u.defaultTransmitterId,onApply:e=>f(t=>hc(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(gc,{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=>cc(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(Kr,{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 xc({device:t}){let{t:n}=X(),[r,a]=o(!1),s=Tr({deviceId:t.id}),c=dn({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(Qi,{id:`remote`,title:n(`remote.card.title`),icon:C,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(vc,{device:t,open:r,onClose:()=>a(!1)})]})}var Sc={remote:xc};function Cc(e){let t=[];for(let[n,r]of Object.entries(ke))r.targets.some(t=>t.cardinality===`config`&&t.deviceTypes.includes(e))&&t.push(n);return t}function wc({device:e}){return Cc(e.type).map(t=>{let n=Sc[t];return n===void 0?null:i(n,{device:e},t)})}function Tc(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 Ec(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 Dc({draft:t,device:n,onEdit:r}){let{t:a,i18n:o}=X(),s=ii(),c=ua(t),l=Ec(t,e=>a(e));return i(St,{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(x,{className:`h-3 w-3`,"aria-hidden":!0}),a(`common.edit`)]}),children:e(`div`,{className:h,children:[i(en,{label:a(`customize.composed.helper.function`),children:Tc(t,e=>a(e))}),l.map(e=>i(en,{label:e.label,children:e.value},e.label)),c.length>0&&i(en,{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(It,{device:n,form:`compact`}),i(`span`,{className:`text-foreground-muted`,children:ma(t.cap,t.fieldPath,o.language)})]},`${t.source.addonId}:${t.source.stableId}:${t.cap}:${t.fieldPath}`)})})})]})})}c();function Oc({device:t}){let{t:r}=X(),a=t.stableId.startsWith(`composed-`)?t.stableId.slice(Be.length):null,s=Vt({blockId:a??``},{enabled:a!==null}),c=Er(),[l,u]=o(!1),d=n(()=>{let e=new Set;for(let{cap:t}of Mi())e.add(t);for(let{cap:t}of Vi())e.add(t);for(let{cap:t}of Ri())e.add(t);for(let n of Cc(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=Ke(f.block);if(p===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`compositionEditor.notComposition`)});if(aa(p)){let n=na(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(rs,{device:t}),i(Dc,{draft:n,device:t,onEdit:()=>u(!0)}),i(Di,{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(rs,{device:t}),Li(p)===`incomplete`&&i(q,{variant:`warning`,children:r(`customize.blockStatus.incomplete`)}),i(wc,{device:t}),i(Wi,{device:t,handle:m,skipCaps:d})]})}c();function kc({deviceId:e}){let{t}=X(),n=Zt({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(Oc,{device:r}):i(Ac,{device:r,target:{addonId:r.addonId,stableId:r.stableId}});return i(si,{deviceId:r.id,seed:{name:r.name,location:r.location??``,role:r.role??null,display:r.display},children:a})}function Ac({device:t,target:r}){let a=Xs(r),o=zt(`composer`),{t:s}=X(),c=tc(t.id,t.type===G.Camera),l=nc(t,pa(a.state)),u=rc(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 Mi())e.add(t);for(let{cap:t}of Vi())e.add(t);for(let{cap:t}of Ri())e.add(t);for(let n of Cc(t.type))e.add(n);return e},[t.type]);return e(`div`,{className:`flex flex-col gap-3`,children:[i(rs,{device:t}),o===`absent`&&i(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),a.state.kind!==`none`&&i(jc,{state:a.state}),i(Bs,{device:t,handle:a,facts:d,sensors:c}),i(Ki,{device:t,handle:a,facts:d}),i(ji,{device:t,handle:a,facts:d,defaults:u}),i(wc,{device:t}),i(Wi,{device:t,handle:a,skipCaps:f}),i(Js,{device:t}),t.type===G.Camera&&i(Gs,{device:t})]})}function jc({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 Mc=`overview`;function Nc(e,t){return e.some(e=>e.id===t)?t:Mc}function Pc({deviceId:t}){let{t:n}=X(),r=l(),a=Number.isFinite(t),{data:o}=Zt({deviceId:t},{enabled:a}),s=typeof o?.type==`string`?o.type:`camera`;Mr([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:c,isLoading:u,isError:d,error:f}=br({deviceId:t},{enabled:a}),{data:p}=Jt({deviceType:s},{enabled:!!s}),m=Cr({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(Fc,{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(Ic,{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(Lc,{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(yr,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function Fc({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(I,{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(be,{className:`h-3 w-3`}),n(`common.unbound`)]})}function Ic({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 Lc({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?p:_,{className:`h-3 w-3`}),t]},t)})})}function Rc({deviceId:t,activeSubTab:n,onSubTabChange:r,deviceType:a,isAdmin:o}){return e(`div`,{className:`flex flex-col gap-3`,children:[ai(a,o)&&i(nn,{deviceId:t,readOnly:!0}),i(hi,{deviceId:t,activeSubTab:n,onSubTabChange:r})]})}c();var zc=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function Bc(e){let t=l(),n=Yn({deviceId:e},{refetchOnMount:`always`}),i=gr(),[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:zc})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await t.invalidateQueries({queryKey:zc})}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 Vc=`object-detection`;function Hc(e){return[e.addonId,...e.children.flatMap(Hc)]}function Uc(e,t){if(e===`pipeline`)return new Set;let n=Wc(t,Vc);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:Hc(n))}function Wc(e,t){for(let n of e){if(n.addonId===t)return n;let e=Wc(n.children,t);if(e!==void 0)return e}}function Gc(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.badgeCameraAi`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.badgeNoRoot`):Y.t(`helpers.detectionSourceModel.badgeIdle`)}function Kc(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 qc(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 Jc(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.noticeOnboard`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.noticeNoRoot`):Y.t(`helpers.detectionSourceModel.noticeIdle`)}var Yc=[`pl-2`,`pl-6`,`pl-10`,`pl-14`],Xc={detector:`success`,cropper:`info`,classifier:`primary`,refiner:`warning`,"audio-classifier":`neutral`};function Zc(e){return Yc[Math.min(e,Yc.length-1)]??`pl-2`}function Qc(e){return e.zoneDriven?{kind:`zone-driven`}:{kind:`gate`,effectiveOn:e.ownOn,defaultOn:e.defaultOn,explicit:e.choice!==`auto`}}function $c(e,t,n){return e.kind===`parent`?n:Gc(e.source,t)}function el({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 tl({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:$c(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 ${Zc(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:Xc[t.kind],children:l(t.kind)}),i(el,{inputs:t.inputs,outputs:t.outputs}),c!==null&&i(`span`,{className:`text-[11px] text-warning`,children:c})]}),i(wr,{gate:Qc(t),busy:a,onSet:e=>s(t.stepId,e)})]},t.stepId)})})}function nl(e,t){let n=e?.[t];return n===void 0?`auto`:n?`on`:`off`}function rl(e,t){return e===`auto`?t:e===`on`}function il(e,t,n){return e!==`onboard`&&e!==`none`||!n.has(t)?null:{kind:`source`,source:e}}function al(e,t,n,r,i){let a=e.zoneDrivenIds??new Set;return t.flatMap(t=>{let o=a.has(t.addonId),s=nl(e.toggles,t.addonId),c=e.defaults[t.addonId]??!0,l=o||rl(s,c),u=r===null?il(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,...al(e,t.children,n+1,f,i)]})}function ol(e){let t=e.source===null?new Set:Uc(e.source,e.tree);return al(e,e.tree,0,null,t)}function sl({source:t,geometry:n,saving:r,error:a,onPick:o}){let{t:s}=X(),c=n===`flag-only`,l=qc(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:ne,children:s(`device.detectionSourceControl.rootDetector`,`Root detector`)}),i(Qn,{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:[Kc(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 cl=new Set([`package-detection`]),ll=`/system/pipeline?view=nodes`;function ul(e){return Object.fromEntries(e.slots.flatMap(e=>e.addons.map(e=>[e.id,e.enabledByDefault??!0])))}function dl({deviceId:a}){let{t:c}=X(),u=ve(),d=Ut(),f=l(),p=L().trpcClient,m=t(null),h=t(null),g=xr({deviceId:a},{refetchOnMount:`always`}),_=Jr(void 0,{refetchOnMount:`always`});Mr([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:v}=Or(),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=on({onSuccess:S}),w=Qt(),[T,E]=o(null),[D,O]=o(!1),[k,A]=o(null),j=Bc(a),M=x.data??{},N=g.data??null,P=y.map(e=>M[e.id]).find(e=>e!==void 0)??null,ee=n(()=>P?Vr(P):[],[P]),te=n(()=>P===null?[]:ol({tree:ee,toggles:N?.stepToggles,defaults:ul(P),source:j.source,zoneDrivenIds:cl}),[ee,P,N?.stepToggles,j.source]),{selection:ne,open:re,close:F}=Ta(n(()=>te.map(e=>e.stepId),[te]),[]),ie=y[0]?.id,I=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]),ae=e=>{e!==ne.stepId&&I(()=>re({stepId:e}))},oe=()=>{I(()=>F())};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(P===null)return i(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.catalogUnavailable`,`Catalog unavailable.`)});let se=e=>_.data?.find(e=>e.nodeId===ie)?.settings.stepSettings?.[e]??{},R=te.find(e=>e.stepId===ne.stepId)??null,ce=R===null?null:wa(P,R.stepId),B=d?i(Gn,{onClick:oe}):i(ht,{icon:z,variant:`ghost`,size:`sm`,"aria-label":c(`common.close`,`Close`),onClick:oe});return e(`div`,{ref:m,className:`space-y-2`,children:[j.view?.onboard.available===!0&&j.source!==null&&i(sl,{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(_i,{to:ll,className:`font-medium text-primary hover:underline`})}})}),ne.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:ne.staleStepId})}),i(tl,{rows:te,label:c(`device.cameraStepInspector.detectionStepsOfThisCamera`,`Detection steps of this camera`),selectedId:ne.stepId,busy:C.isPending,onOpen:ae,onSet:(e,t)=>C.mutate({deviceId:a,addonId:e,enabled:t})}),i(Lr,{open:R!==null&&ce!==null,anchor:m,onClose:oe,label:c(`stepInspector.stepMatrixFrame.stepSettings`,`Step settings`),children:R!==null&&ce!==null&&i(fl,{addon:ce,nodeBag:se(R.stepId),storedCamera:N?.stepSettings?.[R.stepId],draft:T?.stepId===R.stepId?T:null,saving:D,status:k,notice:R.blocked?.kind===`source`?Jc(R.blocked.source,R.stepId):null,closeButton:B,onEscape:oe,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 fl({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=ar(t),_=Da(g),v=Ea(g),y=a?.camera??r,b=a!==null&&!We(a.camera,r??{});return i(hr,{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(pl,{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 pl({addon:e,fields:t,nodeBag:n,cameraBag:r,onChange:a}){let{t:o}=X();return i(Br,{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 ml(e,t,n){return{id:e,get label(){return Y.t(t)},icon:n}}var hl=[ml(`zones`,`helpers.detectionSettingsGroups.zones`,`shapes`),ml(`object-detection`,`helpers.detectionSettingsGroups.objectDetection`,`scan-search`),ml(`tracking`,`helpers.detectionSettingsGroups.tracking`,`route`),ml(`motion`,`helpers.detectionSettingsGroups.motion`,`activity`),ml(`stationary`,`helpers.detectionSettingsGroups.stationary`,`square-parking`),ml(`audio`,`helpers.detectionSettingsGroups.audio`,`volume-2`),ml(`cluster`,`helpers.detectionSettingsGroups.cluster`,`server`)],gl={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,tracking:`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function _l(e){return gl[e]??`object-detection`}c();var vl=`steps`,yl=`settings`,bl=`object-detection`;function xl(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}var Sl={groupOf:e=>_l(e.id),tabs:hl};function Cl({deviceId:e,activeSubTab:t,onSubTabChange:r}){let{t:a}=X();return i(hi,{deviceId:e,sectionFilter:xl,subTabGrouping:Sl,leadingTabs:n(()=>[{id:vl,label:a(`device.detectionPipelineTab.steps`,`Steps`),content:i(dl,{deviceId:e})}],[e,a]),activeSubTab:t===yl?bl:t,onSubTabChange:r})}var wl=`Notifications`,Tl={i18nKey:`device.deviceNotificationMute.cameraCostWhenOff`,text:`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`},El={i18nKey:`device.deviceNotificationMute.deviceCostWhenOff`,text:`This device never notifies — no rule, no target, no alarm.`};function Dl(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:wl,on:r===null?null:i??r,available:r!==null,costWhenOff:e.isCamera?Tl:El}}function Ol(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}c();function kl(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Al({deviceId:t,isCamera:n}){let{t:a}=X(),s=l(),c=Number.isFinite(t),[u,d]=o(null),[f,p]=o(null),m=Dl({mutedDeviceIds:kl(Ot({},{enabled:c}).data),deviceId:t,isCamera:n,pendingOn:f}),h=a(m.costWhenOff.i18nKey,m.costWhenOff.text),g=Kt({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=Ol(m,t);e!==null&&(p(!e.muted),g.mutate(e))},[t,g,m]),v=m.on===null,y=m.on===!1,b=y?at:E;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 jl({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(Rl(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=ha(l),_=n.id!==`switch`,v=_?$i(n.id,a.map(e=>p.get(Ll(e))??{kind:`pending`})):null;return e(d,{children:[_&&a.map(e=>i(Fl,{member:e,row:Il(s,e),fleetKind:c,onRead:h},Ll(e))),v!==null&&i(Ml,{view:v}),n.id===`lock`&&i(Nl,{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(Pl,{view:g,nameOf:u})]})]})}function Ml({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 Nl({deviceId:t}){let{t:n}=X(),r=dr(),a=cr(),[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(xe,{className:`h-4 w-4`,"aria-hidden":!0}),n(`helper.lockAll`)]}),i(gn,{label:n(`helper.unlockAll`),icon:se,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 Pl({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 Fl({member:e,row:t,fleetKind:n,onRead:r}){let i=Ll(e),o=br({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 Il(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 Ll(e){return`${e.source.addonId}/${e.source.stableId}`}function Rl(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=ra(n),o=Vl(n,t);return i(St,{headingId:`helper-history-status`,title:r(`helper.template.${t.kind}`),icon:ot,testId:`helper-history-status`,children:e(`div`,{className:`${h} 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(tr,{value:Bl(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 Bl(e,t){if(e.kind!==`derivative`)return String(t);let n=je(e);return n===null?String(t):`${t} ${n}`}function Vl(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 Hl({helper:t,snapshot:n}){let{t:r}=X(),a=Gl(n,t),o=t.kind===`arithmetic`?ra(n):null;return i(St,{headingId:`helper-math-status`,title:r(`helper.template.${Ul(t)}`),icon:st,testId:`helper-math-status`,children:e(`div`,{className:`${h} 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(tr,{value:String(a.value),label:r(`helper.output`)}),a.kind===`boolean`&&i(tr,{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 Ul(e){return e.kind===`arithmetic`?e.op:e.kind}function Wl(e){return e.kind===`threshold`||e.kind===`expression`&&e.output===`boolean`?{cap:`binary`,field:`on`}:{cap:`numeric-sensor`,field:`value`}}function Gl(e,t){if(e.kind===`pending`)return{kind:`pending`};if(e.kind!==`answered`)return{kind:`empty`};let n=Wl(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 Kl({deviceId:t,stableId:n}){let{t:a}=X(),s=n.startsWith(`composed-`)?n.slice(Be.length):null,c=Vt({blockId:s??``},{enabled:s!==null}),l=Ar({deviceId:t},{enabled:s!==null}),u=Rt({projection:`slim`},{enabled:s!==null}),[d,f]=o(()=>new Map),p=Pn(),m=Wt(),g=r((e,t)=>{f(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 _=Ke(c.data.view.block);if(_===null||!aa(_))return null;let v=_.helper;if(v.kind===`threshold`||v.kind===`arithmetic`||v.kind===`expression`)return i(Hl,{helper:v,snapshot:Xl(l.status,l.data,l.error?.message)});if(Ue(v))return i(zl,{helper:v,snapshot:Xl(l.status,l.data,l.error?.message)});if(v.kind!==`group`)return null;let y=Oe(v.templateId);if(y===null)return null;let b=Xl(l.status,l.data,l.error?.message),x=oa(b,y),S=ra(b),C=u.status===`success`?u.data.map(Zl):[],w=Ql(u.status),T=da(v.members.map(e=>d.get(Yl(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(Jl(y.id,`on`)):a(Jl(y.id,`off`)):x.kind===`empty`?a(`helper.noReading`):null;return i(St,{headingId:`helper-group-status`,title:a(`helper.statusTitle`),icon:ct,testId:`helper-group-status`,children:e(`div`,{className:`${h} flex flex-col gap-3`,children:[v.members.map(e=>i(ql,{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},Yl(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(tr,{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(jl,{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(p===null)return C.find(t=>t.id===e)?.name??String(e);let t=p.byId.get(e);return t===void 0?String(e):Sn(t,`compact`,p,m)}})]})})}function ql({member:e,row:t,fleetKind:n,isState:r,onLive:i}){let o=t?.online===!0,s=Ar({deviceId:t?.id??0},{enabled:n===`answered`&&t!==null&&o}),c=_a(s.status,s.status===`success`?va(s.data):void 0,e.cap,e.fieldPath,r),l=fa({fleet:n,deviceOnline:n===`answered`?t===null?null:t.online:!0,field:c}),u=t?.name??e.source.stableId,d=Nt(t?.id??0,`compact`,u),f=t===null?u:d,p=Yl(e);return a(()=>{i(p,{name:f,presence:l})},[p,f,i,l]),null}function Jl(e,t){return[`cover`,`valve`,`lock`,`media-player`,`climate`].includes(e)?`helper.state.${e}.${t}`:`helper.${t}`}function Yl(e){return`${e.source.addonId}/${e.source.stableId}/${e.cap}.${e.fieldPath}`}function Xl(e,t,n){return e===`pending`?{kind:`pending`}:e===`error`?{kind:`error`,message:n??``}:{kind:`answered`,caps:va(t)}}function Zl(e){return{id:e.id,name:e.name,online:e.online,addonId:e.addonId,stableId:e.stableId,features:e.features??[]}}function Ql(e){return e===`pending`?`pending`:e===`error`?`error`:`answered`}function $l(e,t){return{switchId:e,label:Me[e].label,detail:t===void 0||t.length===0?null:t}}function eu(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 tu(e){let t=eu(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>$l(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>$l(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 nu(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 ru({deviceId:t,deviceName:r}){let{t:a}=X(),s=ve(),[c,l]=o(null),u=Rt({isCamera:!0,projection:`slim`}),d=jn(),f=u.data!==void 0,p=n(()=>u.data===void 0?[]:nu(u.data,t),[u.data,t]),m=p.find(e=>e.id===c)??null,h=d.data===void 0?null:tu(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(iu,{report:h})]})}function iu({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(Se,{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(M,{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 au({deviceId:t}){let{t:n}=X(),[r,a]=o(null),s=Xr({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(g,{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 ou(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function su({device:t}){let{t:n}=X(),r=pi(),a=typeof t.id==`number`?t.id:null,o=typeof t.name==`string`?t.name:``,s=Nt(a??0,`full`,o),c=String(t.type??``),l=c===G.Camera,u=c===G.Hub,d=t.features??[],f=d.includes(Pe.Resyncable),{data:p}=xt({deviceId:a??0},{enabled:a!==null&&l,refetchInterval:5e3}),m=p?.streams??{},h=Object.entries(m),g=d.includes(Pe.DoorbellButton),_=pr(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(Kl,{deviceId:a,stableId:t.stableId}),u&&a!==null&&i(rn,{deviceId:a,onOpenChild:e=>r(`/devices/${e}`)}),f&&a!==null&&i(au,{deviceId:a}),l&&a!==null&&i(ru,{deviceId:a,deviceName:s}),a!==null&&i(Al,{deviceId:a,isCamera:l}),l&&a!==null&&i(Zr,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:a}),g&&i(wt,{history:_.history,latestIsFresh:v}),l&&a!==null&&i(Zr,{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(ae,{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(cu,{label:n(`device.overviewTab.nominal`,`Nominal`),value:ou(r.nominalBitrateKbps??0)}),i(cu,{label:n(`device.overviewTab.observed`,`Observed`),value:ou(r.observedBitrateKbps??0)}),i(cu,{label:n(`device.overviewTab.peak`,`Peak`),value:ou(r.peakBitrateKbps??0)}),i(cu,{label:n(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(r.packetLossPercent??0).toFixed(2)}%`,warning:(r.packetLossPercent??0)>1})]})]},t))})]}),i(ui,{})]})}function cu({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 lu=`history`,uu=[{id:`overview`,labelKey:`helpers.structuralTabs.overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,labelKey:`helpers.structuralTabs.config`,cameraOnly:!1,adminOnly:!1},{id:bi,labelKey:`helpers.structuralTabs.customize`,cameraOnly:!1,adminOnly:!0},{id:lu,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}],du=new Set([G.Hub,G.Container]);function fu(e,t){let n=e===G.Camera,r=e===void 0||!du.has(e);return uu.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)&&(r||e.id!==`history`)).map(({id:e,labelKey:t})=>({id:e,label:Y.t(t)}))}function pu({provider:e,integrationId:t,name:n}){let r=pi(),a=t===null?`/integrations`:xi(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(ci,{type:e,size:`lg`})})}c();var mu=[{id:`logs`,icon:Ce,labelKey:`common.logs`},{id:`repl`,icon:lt,labelKey:`deviceDetail.repl`},{id:`events`,icon:b,labelKey:`common.events`},{id:`state`,icon:de,labelKey:`common.state`}];function hu(){let{t:a}=X(),s=ce(),c=ni(),u=Number(c.deviceId),f=Number.isFinite(u),p=pi(),m=l(),h=ve(),_=L(),{user:y}=fi(),b=y?.isAdmin===!0,[x,C]=vi(),w=x.get(`tab`)??`overview`,T=x.get(`sub`),[E,D]=o(`logs`),O=`device-detail.left-col-width-px`,[k,j]=o(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(O),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),M=t(k);M.current=k;function N(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??k??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{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(O,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:P,isLoading:ee,isError:ne}=Zt({deviceId:u},{enabled:f,refetchInterval:5e3,retry:1}),{data:F}=$t({deviceId:u},{enabled:f}),ie=n(()=>{let e=F?.settings?.sections??[],t=F?.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(ri)&&r.add(di),[...r].map(e=>e===`export`?{id:e,label:yi,isAddonContrib:!0}:{id:e,label:Ie[e]?.label??e,isAddonContrib:!0})},[F]),I=P,ae=String(I?.name??c.deviceId??`Device`),oe=I?.online===!0,se=oe?`online`:`offline`,R=String(I?.addonId??`rtsp`),z=I?.features??[],B=I?.type,le=B===G.Camera,{data:ue}=Si(f?u:0),de=B===G.Container,fe=n(()=>(ue??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ue]),V=n(()=>de?zn(fe,typeof I?.linkDeviceId==`number`?I.linkDeviceId:null,typeof I?.primaryChildEntityId==`string`?I.primaryChildEntityId:null)?.id??null:null,[de,fe,I?.linkDeviceId,I?.primaryChildEntityId]),{data:me}=$t({deviceId:V??0},{enabled:V!==null}),he=n(()=>{if(V===null)return[];let e=me?.settings?.sections??[],t=me?.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:Ie[e]?.label??e,isAddonContrib:!0,childDeviceId:V}))},[V,me]),ge=n(()=>Co({sections:[...F?.settings?.sections??[],...F?.live?.sections??[]],deviceId:u,...V===null?{}:{child:{sections:[...me?.settings?.sections??[],...me?.live?.sections??[]],deviceId:V}}}),[F,me,u,V]),_e=typeof I?.parentDeviceId==`number`?I.parentDeviceId:null,{data:be}=Zt({deviceId:_e??0},{enabled:_e!==null}),xe={id:Number.isFinite(u)?u:0,name:ae,type:`unknown`,stableId:``,parentDeviceId:null},Se=Mn(I??xe,`full`),Ce=Mn(be??xe,`full`),H=Ut(),U=I?.disabled!==!0,we=n(()=>{let e=F?.settings?.sections??[],t=F?.live?.sections??[];return oi([...e,...t],B,b,F!==void 0)},[F,B,b]),Te=n(()=>{let e=new Set,t=[];for(let n of[...fu(B,b),...ie,...he])n.id===`config`&&!we||e.has(n.id)||(e.add(n.id),t.push(n));return t},[B,b,ie,he,we]),Ee=n(()=>Nc(Te,w),[Te,w]),De=r(e=>{C(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of Ca)n.delete(e);return n},{replace:!0})},[C]),Oe=r(e=>{C(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[C]),ke=(ue??[]).length>0,Ae=n(()=>mu.filter(({featureGate:e})=>!e||z.includes(e)),[z]),{data:je}=jt(void 0),Me=n(()=>I?Bt(I,je):null,[I,je]),W=Me?.kind===`resolved`?Me.integration:null,Ne=W===null?Me?.kind===`unknown`?a(`deviceDetail.loadingIntegration`):Me?.kind===`orphan`?a(`deviceDetail.missingIntegration`):a(`deviceDetail.noIntegration`):W.name,Fe=W!==null&&W.addonId===R?W.name:R,Le=jr({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]}),p(W?.id?xi(W.addonId,W.id):`/integrations`)}}),Re=tn({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ze=yt({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=Kn(),Ve=Ln({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),He=z.includes(Pe.Rebootable),Ue=z.includes(Pe.BatteryOperated),We=Cn(_.trpcClient,Ue&&f?u:null),Ge=Lt(_.trpcClient,f?u:null),Ke=pe(_.trpcClient,f?u:null,e=>e.runningState),qe=Ke===void 0||Ke.running===null?null:Ke.running,Je=Un(B??`unknown`,s).icon,[Ye,Xe]=o(!1),Ze=async()=>{if(!Ye){Xe(!0);try{let e=Se.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await za(`${re}/${String(u)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Xe(!1)}}},Qe=Re.isPending||ze.isPending,{data:$e}=lr({deviceId:u},{enabled:f&&le,refetchInterval:1e4}),et=$e?.agentNodeId??null,tt=typeof et==`string`&&et.length>0&&!et.startsWith(`addon:`)?et:void 0,{data:nt}=An({deviceId:u,...tt?{nodeId:tt}:{}},{enabled:f&&le,refetchInterval:3e3,retry:!1}),{data:rt}=er({deviceId:u},{enabled:f&&le,refetchInterval:3e3,retry:!1}),it=rt?.level?.dbfs??null;function at(){if(!f)return null;switch(Ee){case`overview`:return i(su,{device:I??{}});case`config`:return i(Rc,{deviceId:u,activeSubTab:T,onSubTabChange:Oe,deviceType:B,isAdmin:b});case`detection-pipeline`:return i(Cl,{deviceId:u,activeSubTab:T,onSubTabChange:Oe});case`bindings`:return i(Pc,{deviceId:u});case lu:return i($n,{deviceId:u,onNavigate:e=>p(e)});case bi:return i(kc,{deviceId:u});default:{let e=Ee,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(hi,{deviceId:u,sectionFilter:ri,activeSubTab:T,onSubTabChange:Oe});let a=i(hi,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&t.tab===e,activeSubTab:T,onSubTabChange:Oe});return n!==void 0&&r!==u?i(Rr,{deviceId:r,children:a}):a}}}return f?ee?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`})})]}):ne||!P?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(Xt,{items:[{label:a(`deviceDetail.integrations`,`Integrations`),onClick:()=>p(`/integrations`)},W===null?{label:Ne}:{label:Ne,onClick:()=>p(xi(W.addonId,W.id))},{label:Se}]})}),e(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[W!==null&&i(pu,{provider:W.addonId,integrationId:W.id,name:W.name}),i(fn,{running:qe,children:i(Je,{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:Se}),i(Ur,{status:se}),Ue&&i(gt,{status:We,variant:`full`}),i(qt,{status:Ge})]}),_e!==null&&be&&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:z.length>0&&i(gi,{capabilities:z})})]}),nt&&i(`div`,{className:`hidden lg:flex`,children:i(gu,{metrics:nt,dbfs:it})}),e(`div`,{className:`flex items-center gap-1 shrink-0`,children:[e(`button`,{onClick:async()=>{U?await h({title:a(`deviceDetail.disable`,`Disable "{{name}}"?`,{name:Se}),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`})&&ze.mutate({deviceId:u}):Re.mutate({deviceId:u})},disabled:Qe,title:U?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 ${U?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[i(A,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:Qe?a(`deviceDetail.updating`,`Updating…`):U?a(`deviceDetail.enabled`,`Enabled`):a(`deviceDetail.disabled`,`Disabled`)})]}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),le&&e(d,{children:[i(Ka,{deviceId:u}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),i(Ja,{deviceId:u}),i(qr,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:a(`deviceDetail.takeSnapshot`,`Take snapshot`),description:a(`deviceDetail.fetchAFreshFrameAnd`,`Fetch a fresh frame and download it.`),icon:v,disabled:Ye,onClick:()=>{Ze()}},{id:`reboot`,label:a(`deviceDetail.rebootDevice`,`Reboot device`),description:a(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:te,hidden:!He,disabled:Be.isPending,danger:!0,onClick:async()=>{await h({title:a(`deviceDetail.reboot`,`Reboot "{{name}}"?`,{name:Se}),message:a(`deviceDetail.theCameraWillGoOffline`,`The camera will go offline for around 30 seconds while the firmware reboots.`),confirmLabel:a(`deviceDetail.reboot2`,`Reboot`),variant:`danger`})&&Be.mutate({deviceId:u})}},{id:`restart-addon`,label:a(`deviceDetail.restartAddon`,`Restart addon`),description:a(`deviceDetail.bouncesEveryDeviceServedBy`,`Bounces every device served by {{servingAddonLabel}}.`,{servingAddonLabel:Fe}),icon:g,disabled:Ve.isPending,danger:!0,onClick:async()=>{await h({title:a(`deviceDetail.restart`,`Restart "{{servingAddonLabel}}"?`,{servingAddonLabel:Fe}),message:a(`deviceDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device served by it (not just "{{name}}"). Streams will reconnect automatically.`,{name:Se}),confirmLabel:a(`deviceDetail.restart2`,`Restart`),variant:`danger`})&&Ve.mutate({addonId:R})}},{id:`delete`,label:a(`deviceDetail.deleteDevice`,`Delete device`),description:a(`deviceDetail.removeTheDeviceAndAll`,`Remove the device and all its settings.`),icon:S,separatorBefore:!0,disabled:Le.isPending,danger:!0,onClick:async()=>{await h({title:a(`deviceDetail.delete`,`Delete "{{name}}"?`,{name:Se}),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`})&&Le.mutate({deviceId:u})}}]})]})]})]}),i(Rr,{deviceId:u,device:I??void 0,children:i(mt,{children:i(Ct,{children:i(ye,{children:i(Jn,{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`:`${k===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-y-auto`,style:!H&&k!==null?{width:`${String(k)}px`}:void 0,children:[i(`div`,{className:le?`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:le?i(No,{deviceId:u,intercomAvailable:z.includes(Pe.TwoWayAudio)}):e(`div`,{children:[i(bo,{deviceId:u,deviceName:Se,deviceType:B??`unknown`,provider:R,isOnline:oe,features:z}),i(xo,{deviceId:u,widgets:ge})]})}),le&&ge.length>0&&i(`div`,{className:`flex-shrink-0 border-b border-border-subtle bg-surface pt-3 sm:pt-4`,children:i(xo,{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:Ae.map(({id:t,labelKey:n,icon:r})=>{let o=E===t;return e(`button`,{onClick:()=>D(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:[E===`logs`&&i(Po,{deviceId:u,containerDeviceId:B===`container`?u:void 0}),E===`repl`&&i(Fo,{deviceId:u}),E===`events`&&i(Io,{deviceId:u}),E===`state`&&i(Lo,{deviceId:u})]})]})]}),!H&&i(`div`,{role:`separator`,"aria-orientation":`vertical`,title:a(`deviceDetail.dragToResize`,`Drag to resize`),onMouseDown:N,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:Te.map(t=>{let n=Ee===t.id;return e(`button`,{onClick:()=>De(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:[Ee===`overview`&&ke&&i(Ya,{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 gu({metrics:t,dbfs:n}){let r=ce(),{t:a}=X(),o=fr(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(ue,{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(le,{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(N,{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{hu as DeviceDetailPage};
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{$n as f,Ai as p,Ar as m,D as h,Dn as g,En as _,Fi as v,G as y,Gi as b,Hn as x,Ht as S,Ir as C,J as w,K as T,Ki as E,Kn as D,Kr as O,Ln as k,Nn as A,O as j,On as M,Ot as N,Qn as P,St as ee,Tn as te,V as ne,W as re,Z as F,_i as ie,_n as I,bt as ae,cr as oe,dr as se,dt as L,gr as R,gt as z,ha as ce,hr as B,ii as le,la as ue,ni as de,on as fe,pr as V,q as pe,qr as me,r as he,rn as ge,rr as _e,st as ve,t as ye,tr as be,ur as xe,xi as Se,yn as Ce,z as H}from"./player-overlays-CdeStLFY.js";import{$a as we,Bi as Te,Bn as Ee,Dr as De,Er as Oe,Fo as ke,Ha as Ae,Ji as je,Jt as Me,Ni as Ne,Oi as Pe,Pa as U,Qt as Fe,Rn as Ie,Ro as Le,Si as Re,Sr as ze,Vn as Be,Xt as Ve,Yt as He,Zt as Ue,di as We,eo as W,er as Ge,f as Ke,n as qe,na as Je,qa as Ye,qt as Xe,to as G,tr as Ze,zn as Qe,zo as $e}from"./client-AOeY3PoN.js";import{t as et}from"./archive-DXMVa-lX.js";import{i as tt,n as nt,r as rt,t as it}from"./scan-eye-BShVz2L8.js";import{t as at}from"./bell-off-CEN8nQp-.js";import{r as ot,t as st}from"./sigma-BEGwr5QF.js";import{t as ct}from"./boxes-eRc-lVOF.js";import{n as lt}from"./video-D8GbzI4M.js";import{t as ut}from"./circle-slash-CX4B4mGW.js";import{t as dt}from"./file-up-BBdOgTK9.js";import{t as ft}from"./layers-Bty4v-Tb.js";import{$t as pt,Ar as mt,Bd as ht,Bn as gt,Bs as _t,Bt as vt,Co as yt,Cr as bt,Dc as xt,Dn as St,Dr as Ct,Dt as wt,Ei as Tt,Er as Et,Et as Dt,Fc as Ot,Fl as kt,Fo as At,Fs as jt,Ga as Mt,Gr as Nt,Gt as Pt,Hd as Ft,Hr as It,Ht as Lt,Io as Rt,Ir as zt,It as Bt,Ja as Vt,Jt as Ht,Kd as Ut,Kr as Wt,Kt as Gt,Lc as Kt,Ln as qt,Lo as Jt,Ml as Yt,Mn as Xt,Mo as Zt,Nl as Qt,No as $t,On as en,Oo as tn,Or as nn,Ot as rn,Pd as an,Pl as on,Po as sn,Pr as K,Pt as cn,Qd as ln,Qt as un,Qu as dn,Rn as fn,Ro as pn,Rt as mn,Si as hn,Sn as gn,Sr as _n,Ti as vn,Tn as yn,Tr as bn,Ud as xn,Ur as Sn,Ut as Cn,V as wn,Vd as Tn,Vo as En,Vs as Dn,Wa as On,Wd as kn,Wl as An,Wo as jn,Wr as Mn,Xn as Nn,Xr as Pn,Xt as Fn,Ya as In,Yi as Ln,Yn as Rn,Yt as zn,Za as Bn,_u as Vn,a as Hn,af as Un,ao as Wn,at as Gn,au as Kn,br as qn,c as Jn,cl as Yn,cn as Xn,co as Zn,ct as Qn,d as $n,da as er,dt as tr,ef as nr,el as rr,en as ir,er as ar,et as or,fi as q,fl as sr,gc as cr,gl as lr,gu as ur,hc as dr,hn as fr,i as pr,ii as J,io as mr,it as hr,jl as gr,jr as _r,ki as vr,kn as yr,ko as br,ll as xr,lo as Sr,ls as Cr,lt as wr,mu as Tr,no as Er,o as Dr,of as Or,on as kr,ps as Ar,qo as jr,r as Mr,rf as Nr,sn as Pr,so as Fr,ss as Ir,st as Lr,ti as Rr,tn as zr,tr as Br,tt as Vr,ul as Hr,ut as Ur,vu as Wr,wi as Gr,wr as Kr,wt as qr,xl as Jr,xr as Yr,yo as Xr,yr as Zr,zn as Qr,zs as $r,zt as ei}from"./src-CImrkf6y.js";import{t as Y}from"./i18n-DFGXm9ze.js";import{t as ti}from"./Trans-BgSU9dw1.js";import{t as X}from"./useTranslation-BJr-n0es.js";import"./mount-CXUDiSMs.js";import{$ as ni,A as ri,B as ii,D as ai,E as oi,F as si,H as ci,I as li,L as ui,O as di,P as fi,Q as pi,R as mi,T as hi,U as gi,V as Z,Y as _i,et as vi,k as yi,p as bi,v as xi,z as Si}from"./index-DzxzA2lU.js";import{n as Ci,t as wi}from"./format-42qUo1AE.js";import{a as Ti,r as Ei,t as Di}from"./ComposedDeviceEditDialog-FYsRkLBz.js";import{$ as Oi,A as ki,B as Ai,D as ji,E as Mi,F as Ni,H as Pi,I as Fi,J as Ii,K as Li,L as Ri,M as zi,N as Bi,O as Vi,P as Hi,Q as Ui,R as Wi,S as Gi,T as Ki,U as qi,V as Ji,W as Yi,X as Xi,Y as Zi,Z as Qi,_ as $i,at as ea,b as ta,c as na,d as ra,et as ia,f as aa,h as oa,it as sa,j as ca,k as la,l as ua,m as da,p as fa,q as pa,rt as ma,s as ha,tt as ga,u as _a,v as va,x as ya,z as ba}from"./CompositionBlockEditor-B5c79zIn.js";import{t as xa}from"./assignment-candidates-66hRsjMW.js";import{_ as Sa,b as Ca,i as wa,m as Ta,o as Ea,t as Da}from"./step-inspector-model-BFTjgLfV.js";import"./useEventInvalidation-CXUDiSMs.js";import{t as Oa}from"./use-stationary-objects-BQcBWrZ4.js";import{a as ka,i as Aa,n as ja,o as Ma,r as Na,s as Pa,t as Fa}from"./linked-devices-model-Cgwx8ecs.js";import{f as Ia,h as La,t as Ra}from"./RemoteGrid-BJ5xj0Z6.js";import{t as za}from"./authed-media-Czu7XTaj.js";c();function Ba(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 Va(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(Ba).filter(e=>e!==null);return n.length===0?null:n}var Ha=[[/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 Ua(e){for(let[t,n]of Ha)if(t.test(e))return n;return`generic`}function Wa(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 Ga={stream:M,detection:it,privacy:O,microphone:_e,speaker:N,listening:nt,archive:et,recording:rt,notifications:b,generic:fe};function Ka({deviceId:t}){let{t:n}=X(),a=l(),s=Number.isFinite(t),[c,u]=o(null),[d,f]=o(!1),p=sr({deviceId:t},{enabled:s});Mr([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=Va(p.data),h=kt({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 _=Wa(m),v=e=>c?.id===e.id?c.message:null;return e(Ft,{open:d,onOpenChange:f,children:[e(kn,{"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(xn,{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(qa,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function qa({row:t,failure:n,onToggle:r}){let{t:a}=X(),o=Ga[Ua(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 Ja({deviceId:t}){let n=Pt(L().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(me,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:n.label})]})}function Ya({parentDeviceId:t}){let{t:n}=X(),r=pi(),a=L(),{data:o,isLoading:s,isError:c}=Si(t),{data:l}=Zt({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=vt(l?.stableId??``,u,l?.childLayout),f=d.ungrouped,p=e=>r(`/devices/${String(e)}`),m=l?.name??``,h=(e,t)=>i(mn,{trpc:a.trpcClient,device:{...t,name:Gt(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(ei,{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(ei,{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 Xa({deviceId:e}){let t=L(),{data:n,isLoading:r}=mi(e),{data:a,isLoading:o}=Si(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(Ht,{trpc:t.trpcClient,children:c,linkDeviceId:l,primaryChildEntityId:u})})}c();function Za({dev:t,busy:n,setBusy:r}){let{t:a}=X(),s=t?.motionTrigger,c=w(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(ue,{className:`h-3 w-3`}),i(`span`,{children:m})]})}c();function Q({deviceId:t,deviceType:n,features:r}){let a=L(),s=un(n)?.HeroCard??pt,c=T(a.trpcClient,t),l=w(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(Fn,{lastChangedAt:p})}):null,i(s,{trpc:a.trpcClient,deviceId:t,features:r}),i(`div`,{className:`flex justify-center`,children:i(Za,{dev:c,busy:u,setBusy:d})})]})}function Qa({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(ir,{trpc:L().trpcClient,deviceId:e,features:t})})}function $a({deviceId:e,features:t}){return i(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:i(pt,{trpc:L().trpcClient,deviceId:e,features:t})})}function eo(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function to(e){if(!e)return null;let t=eo(e.data);return t===null?e.eventType:Y.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var no=1e3,ro=60*no,io=60*ro,ao=24*io;function oo(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<no?Y.t(`helpers.relativeTime.justNow`):n<ro?Y.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/no)}):n<io?Y.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/ro)}):n<ao?Y.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/io)}):Y.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/ao)})}c();var so=1500,co=15e3,lo=1e3;function uo({deviceId:n}){let{t:r}=X(),s=T(L().trpcClient,n)?.state.eventEmitter,c=w(s);a(()=>{if(!s)return;s.refresh();let e=setInterval(()=>{s.refresh()},co);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)},so);return()=>{clearTimeout(t)}},[u]);let[h,g]=o(()=>Date.now());a(()=>{let e=setInterval(()=>{g(Date.now())},lo);return()=>{clearInterval(e)}},[]);let _=to(l),v=c?.eventTypes??[],y=c?.eventCountSinceStart??0,b=c!==void 0,x=eo(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:_??r(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:i(f?P:m,{className:`h-10 w-10`})}),e(`div`,{className:`text-center`,children:[x!==null&&i(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:r(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(x)})}),i(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${_?`text-foreground`:`text-foreground-subtle`}`,children:_??(b?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?oo(l.timestamp,h):r(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),v.length>0&&i(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:v.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:y})})]})}function fo({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(ci,{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(Ur,{status:a?`online`:`offline`}),o.length>0&&i(gi,{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 po({deviceId:t}){let{t:r}=X(),a=l(),o=mr({deviceId:t},{refetchInterval:1e4,retry:!1}),s=Wn({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),a.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),c=n(()=>mo(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(ho,{label:r(`hero.hubHero.discovered`,`Discovered`),value:c.total,icon:i(D,{className:`h-3.5 w-3.5`})}),i(ho,{label:r(`hero.hubHero.adopted`,`Adopted`),value:c.adopted,accent:`success`}),i(ho,{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(V,{className:`h-3.5 w-3.5 animate-spin`}):i(g,{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(go,{icon:i(ae,{className:`h-3 w-3 text-emerald-500`}),label:r(`hero.hubHero.online`,`{{online}} online`,{online:c.online})}),i(go,{icon:i(f,{className:`h-3 w-3 text-amber-500`}),label:r(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:c.sleeping})}),i(go,{icon:i(ee,{className:`h-3 w-3 text-destructive`}),label:r(`hero.hubHero.offline`,`{{offline}} offline`,{offline:c.offline})}),c.unknown>0?i(go,{icon:i(ie,{className:`h-3 w-3 text-foreground-subtle`}),label:r(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:c.unknown})}):null]})]})}function mo(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 ho({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 go({icon:t,label:n}){return e(`span`,{className:`inline-flex items-center gap-1`,children:[t,i(`span`,{children:n})]})}var _o={[G.Switch]:Q,[G.Siren]:Q,[G.Light]:Q,[G.Sensor]:Q,[G.Button]:Q,[G.Hub]:po,[G.Cover]:Qa,[G.Valve]:Q,[G.Humidifier]:Q,[G.WaterHeater]:Q,[G.Container]:Xa,[G.Lock]:Q,[G.Fan]:Q,[G.Thermostat]:Q,[G.Climate]:Q,[G.MediaPlayer]:Q,[G.Control]:Q,[G.AlarmPanel]:Q,[G.EventEmitter]:uo,[G.Notifier]:$a,[G.Script]:Q,[G.Automation]:Q,[G.Presence]:Q,[G.Update]:Q,[G.Vacuum]:Q,[G.LawnMower]:Q,[G.Weather]:Q,[G.Image]:Q,[G.PetFeeder]:Q,[G.PetFountain]:Q,[G.Dishwasher]:Q};function vo(e){return _o[e]??fo}function yo({deviceId:e}){let t=pe(L().trpcClient,e,e=>e.runningState);if(t===void 0||t.running!==!0&&t.running!==!1)return i(d,{});let n=t.running;return i(Qr,{running:n,since:t?.since??null,phase:t?.phase??null,className:`px-3 pt-2 sm:px-4`})}function bo(t){let n=vo(t.deviceType);return e(d,{children:[i(yo,{deviceId:t.deviceId}),i(n,{...t})]})}function xo({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(Zr,{widgetId:t.widgetId,deviceId:t.deviceId});return i(`div`,{children:t.deviceId===e?n:i(Rr,{deviceId:t.deviceId,children:n})},t.widgetId)})})}function So(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 Co(e){let t=So(e),n=new Set(t.map(e=>e.widgetId)),r=e.child===void 0?[]:So(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 wo(e){return Dr(L().trpcClient,e)}c();function To(e){let[n,i]=o(`idle`),[s,c]=o(null),l=t(null),u=t(null),d=t(null),f=t(!0),p=_t(),m=$r(),h=Dn(),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 Eo=0;function $(){return++Eo}function Do(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Oo(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 ko(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 Ao(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 jo({scope:n,greeting:s,className:c}){let{t:l}=X(),d=L(),[f,p]=o(()=>{let e=[];return s&&e.push({id:$(),kind:`info`,text:s}),e.push({id:$(),kind:`info`,text:`scope: ${Do(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: ${Do(n)}`}]),h(``);return}if(t===`help`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Oo(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(t===`context`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Ao(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(t===`examples`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...ko(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: ${Do(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 Mo(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 No({deviceId:e,intercomAvailable:t=!1}){let r=L(),a=typeof window<`u`?F():``,o=Number.isFinite(e),s=wo(o?e:null),c=Oa(o?[e]:[]),l=n(()=>{if(!o)return;let e=[];for(let t of c.rows){let n=Hn(t);n!==null&&e.push(n)}return e},[o,c.rows]),{streams:u,pipelineMetrics:f,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:_,getIceCandidates:v,closeSession:b,getSessionState:x,applyDownlinkProbe:S}=yn(r.trpcClient,o?e:null),C=y(o?e:null,{width:Ro}),w=To(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=_r(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=Mo(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(or,{serverUrl:a,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:_,getIceCandidates:v,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 Po({deviceId:e,containerDeviceId:t}){let{t:n}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full`,children:i(Xn,{...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 Fo({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(jo,{scope:{type:`device`,deviceId:e},greeting:n,className:`h-full border-0 rounded-none`})}function Io({deviceId:e}){let{t}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:i(Pr,{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 Lo({deviceId:e}){let{t}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:i(kr,{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 Ro=960;function zo({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 Bo({label:t=`Location`,layout:r=`inline`,bound:a}){let{t:o}=X(),{data:s}=En(),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(oe,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),i(`span`,{className:`truncate`,children:t})]},t))})]})})}var Vo=`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`,Ho=0,Uo=10;function Wo(e){if(e.trim()===``)return``;let t=Number.parseInt(e,10);return Number.isFinite(t)?String(t<Ho?Ho:t>Uo?Uo:t):``}function Go({value:e,onChange:t,disabled:n=!1,placeholder:r,className:a,id:o,"aria-label":s}){return i(`input`,{type:`number`,min:Ho,max:Uo,step:1,id:o,className:a??Vo,"aria-label":s,placeholder:r,value:e,onChange:e=>{t(Wo(e.target.value))},disabled:n})}function Ko({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:Ye(e)}),fallbackGlyph:r,labels:l,disabled:o}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n===``?a:n})]})}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`;function Jo(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function Yo({device:t,role:n,display:r,onChange:a}){let o=ce();nr();let{t:s}=X(),c=l(),u=n===null?void 0:zr[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:U(g),{data:v}=sn({},{staleTime:6e4,enabled:n!==null}),y=Ir({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),b=()=>{if(n===null)return;let e=Jo(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:ln(x),C=n===null?Un(t.type,o):Nr(n,o),w={icon:S??C.icon,label:S===void 0?C.label:String(x)},T=n===null&&t.type===G.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(Ko,{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:qo,"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(wn,{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(Go,{"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 Xo(e){return typeof e.linkDeviceId==`number`}var Zo=new Set(Object.values(W));function Qo(e){return Zo.has(e)}var $o={[G.Switch]:[W.Siren,W.Floodlight,W.Spotlight,W.PirSensor,W.Chime,W.Autotrack,W.Nightvision,W.PrivacyMask,W.BinaryHelper],[G.Light]:[W.Floodlight,W.Spotlight,W.Nightvision],[G.Siren]:[W.Siren],[G.Button]:[W.Doorbell],[G.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],[G.Control]:[W.NumericControl,W.SelectControl,W.TextControl,W.DateTimeControl],[G.Notifier]:[W.MobilePushNotifier,W.MessagingNotifier,W.EmailNotifier,W.GenericNotifier]};function es(e){for(let t of Object.values(G))if(t===e)return!0;return!1}function ts(e){return es(e)?$o[e]??[]:[]}function ns(e,t){let n=ts(t);return e==null||e===``||n.includes(e)?n:[...n,e]}function rs({device:t}){let{t:n}=X(),r=ce(),a=li(),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:`${j} ${h}`,children:[e(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[d?i(zo,{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(Bo,{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(Nn,{"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:Xo(t)||!d?i(`span`,{children:is(l,n(`customize.identity.noRole`),r)}):i(an,{"aria-label":n(`customize.identity.role`),value:l??``,options:[{value:``,label:n(`customize.identity.noRole`)},...ns(l,t.type).map(e=>({value:e,label:is(e,n(`customize.identity.noRole`),r)}))],onChange:e=>a.setIdentityRole(e.target.value===``?null:e.target.value)})})]}),o!==null&&a!==null&&i(Yo,{device:t,role:l,display:o.display,onChange:a.setIdentityDisplay})]})}function is(e,t,n){return e==null||e===``?t:Qo(e)?Nr(e,n).label:e}function as(e){let t=Qe({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 os(e){let t=Ee({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 ss(e,t){return{deviceId:e,config:t.config}}function cs(e,t){return{deviceId:e,patch:{motionCooldownMs:t}}}async function ls(e,t,n,r){await n(ss(e,t)),await r(cs(e,t.timeoutMs))}c();function us(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(qn,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(_n,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(bn,{children:i(Et,{children:r})}),t.open?i(ds,{...t}):null]})})}function ds(t){let{t:r}=X(),a=Rt({projection:`slim`}),s=Oi(n(()=>a.status===`success`?ea(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>fs(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=ps(c),b=y.length===0?null:as({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=Ar({deviceId:c[0]?.deviceId??0}),C=hs(S.status===`success`?S.data:void 0,x),w=Ue(He,C,Math.round(_*1e3));return e(d,{children:[e(Yr,{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(Ui,{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(ms(C,w.lastPressedAt))}):null]}),e(Kr,{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 fs(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 ps(e){return e.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,changedAtField:e.changedAtField??Ae[e.cap]??`lastChangedAt`}))}function ms(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 hs(e,t){if(e===void 0||t===null)return{kind:`unread`};let n=e[t.cap],r=n===void 0?void 0:sa(n,t.fieldPath),i=Ae[t.cap]??t.changedAtField,a=n===void 0?void 0:sa(n,i);return typeof r==`boolean`?{kind:`level`,active:r,changedAt:typeof a==`number`&&Number.isFinite(a)?a:null}:{kind:`unread`}}function gs(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=_s(t,n);return r===null?{kind:`unknown`,seconds:null}:{kind:`active`,seconds:r}}function _s(e,t){if(e==null||!Number.isFinite(e)||e<wi)return null;let n=Math.floor((t-e)/1e3);return n<0?0:n}function vs(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>=wi?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 ys={id:0,name:``,type:`unknown`,stableId:``,parentDeviceId:null};function bs({device:t,handle:n,availability:r,cap:a,title:s,view:c}){let{t:l,i18n:u}=X(),f=Ai(),[p,m]=o(!1),[h,g]=o(null),_=pa(n.state),v=Ji(_,a),y=Ss(n,v),b=y.kind===`known`&&y.value!==null?Ie({feature:y.value,device:n.target,cap:a,targetId:c.id,timestampPath:c.timestampPath,counterPath:c.counterPath}):null,x=b!==null,S=Zi(x),C=b?.draft.sources[0]??null,w=C===null||S.kind!==`known`?null:S.value.find(e=>je({addonId:e.addonId,stableId:e.stableId})===je(C))??null,T=Cs(x,S.kind,w!==null),D=Mn(w===null?ys:ia(w),`compact`),O=Mn(t,`full`),k=Xe({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}),A=n.state.kind===`none`||n.state.kind===`present`;if(r.kind===`absent`||!c.deviceTypes.includes(t.type))return null;let j=async e=>{let t=await n.save(e);g(t.kind===`refused`?t.reason:null)},M=ws(b),N=b?.draft.edges?.[0],P=N!==void 0&&c.edges.includes(N)?N:c.defaultEdge,ee=C===null?``:ma(C.cap,C.fieldPath,u.language),te=y.kind===`known`&&y.value===null,ne=!x&&y.kind===`known`&&y.value!==null;return e(d,{children:[i(Qi,{id:a,icon:E,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(Nn,{"aria-label":l(`customize.doorbell.active`),checked:v.enabled!==!1,disabled:!A||n.saving,onChange:e=>{j(qi(_,n.target,{...v,enabled:e.target.checked}))}}),l(`customize.doorbell.active`)]}),i(q,{children:l(Fi(k.text,k.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`&&!A?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:D,field:ee})}),x&&i(xs,{deviceId:t.id,cap:a,timestampPath:c.timestampPath,counterPath:c.counterPath,startedAt:n.state.kind===`present`?n.state.view.block.createdAt:null}),ne&&v!==null&&e(`p`,{className:`text-xs text-foreground flex flex-wrap items-center gap-1`,children:[l(`customize.doorbell.otherFormula`),i(zi,{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=Yi(_,a);f(l(`customize.doorbell.removeWhat`,{name:w===null?O:D}),e===null).then(t=>{t&&j(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(us,{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:P,sources:M,canSave:A&&!n.saving,onClose:()=>m(!1),onSave:e=>{m(!1),j(qi(_,n.target,e))}})]})}function xs({deviceId:t,cap:n,timestampPath:r,counterPath:a,startedAt:o}){let{t:s}=X(),c=ba({deviceId:t,cap:n,path:r}),l=ba({deviceId:t,cap:n,path:a}),u=vs(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?``:Ci(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:Ci(u.lastPressedAt)}),u.pressCount===null?``:` · ${s(`customize.event.doorbellCount`,{count:u.pressCount})}`]})}function Ss(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 Cs(e,t,n){return e?t===`pending`?`pending`:t===`unknown`?`unknown`:n?`present`:`absent`:`present`}function ws(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 Ts(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(qn,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(_n,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(bn,{children:i(Et,{children:r})}),t.open?i(Es,{...t}):null]})})}function Es(t){let{t:r}=X(),a=Rt({projection:`slim`}),s=Oi(n(()=>a.status===`success`?ea(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>Ds(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=Os(c),b=os({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(Yr,{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(Ui,{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(ks,{deviceId:x.deviceId,cap:x.cap,fieldPath:x.fieldPath,timeoutMs:Math.round(h*1e3)})]}),e(Kr,{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 Ds(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 Os(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 ks({deviceId:e,cap:t,fieldPath:n,timeoutMs:r}){let{t:a}=X(),o=ba({deviceId:e,cap:t,path:n}),s=o.kind===`value`&&typeof o.value==`boolean`?{kind:`level`,active:o.value,changedAt:null}:{kind:`unread`},c=Fe(Ve,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(As(s,c.open))})}function As(e,t){return e.kind===`unread`?`customize.event.previewWaiting`:t?`customize.event.previewMotionOn`:e.active?`customize.event.previewSensorOn`:`customize.event.previewMotionOff`}c();function js({device:n,availability:r,cap:a,title:s,view:c,sensors:l}){let{t:u}=X(),f=Yt(),p=rr(),m=vr({addonId:`pipeline-orchestrator`,deviceId:n.id,nodeId:`hub`}),[h,g]=o(!1),[_,v]=o(null),y=t(!1),[b,x]=o(!1),S=Ns(l),C=Zi(!0),w=Me(c.id,S),T=Ls(Sa(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 ls(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(Qi,{id:a,icon:ue,title:s,testId:`event-card-${a}`,actions:i(q,{children:u(Fi(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(Ps,{reason:Is(S)||(r.kind===`unknown`?r.reason:``)}):e(d,{children:[i(Ms,{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(Fs,{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(Ts,{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 Ms({deviceId:e}){let{t}=X(),n=ba({deviceId:e,cap:`motion`,path:`detected`}),r=ba({deviceId:e,cap:`motion`,path:`lastDetectedAt`}),a=gs(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 Ns(e){return e.presence===`pending`?{kind:`pending`}:e.status===null?{kind:`unknown`,reason:e.failureReason}:{kind:`known`,value:e.status}}function Ps({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 Fs({row:e,fleet:t}){let n=Wt();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:ga(ia(r),t.value.map(ia),n)}function Is(e){return e.kind===`unknown`?e.reason??``:e.kind===`known`&&e.value.state===`unreadable`?e.value.reason:``}function Ls(e,t){return e!==null&&Number.isFinite(e)?e:t}var Rs=Be;function zs(e,t){let n=Rs[e];return n===void 0?null:n.targets.find(e=>e.id===t)??null}function Bs({device:e,handle:t,facts:n,sensors:r}){let{t:a}=X();return i(d,{children:Ri().map(o=>{let s=o.pulse??o.span;if(s===null||!s.deviceTypes.includes(e.type))return null;let c=zs(o.cap,s.id);if(c===null)return null;let l=a(o.pulse===null?`customize.motion.title`:`customize.doorbell.title`),u=Bi(Ni(o.cap,c),n);return o.pulse===null?o.span===null?null:i(js,{device:e,availability:u,cap:o.cap,title:l,view:o.span,sensors:r},o.cap):i(bs,{device:e,handle:t,availability:u,cap:o.cap,title:l,view:o.pulse},o.cap)})})}function Vs({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(Qi,{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 Hs=`flex items-center gap-2 px-3 py-2 text-sm sm:px-4`,Us=`list-none px-3 py-2 text-xs text-foreground-subtle sm:px-4`;function Ws({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 Gs({device:t}){let{t:n}=X(),r=l(),a=Gr({}),s=hn({deviceId:t.id}),[c,u]=o(!1),[f,p]=o([]),m=()=>void r.invalidateQueries({queryKey:[[`actions`]]}),h=Tt({onSuccess:m}),g=vn({onSuccess:m}),_=a.data??[],v=s.data?.actionIds??[],y=v.flatMap(e=>_.filter(t=>t.id===e)),b=_.filter(e=>!v.includes(e.id)),x=s.data!==void 0&&a.data!==void 0,S=e=>h.mutate({deviceId:t.id,actionIds:[...e]}),C=()=>{p([]),u(!0)},w=e=>p(f.includes(e)?f.filter(t=>t!==e):[...f,e]);return e(d,{children:[e(Vs,{id:`linked-actions`,icon:B,title:n(`customize.linkedActions.title`,`Linked actions`),addLabel:n(`customize.linkedActions.add`,`Add`),onAdd:x&&b.length>0?C:void 0,addDisabled:h.isPending,children:[!x&&i(`li`,{className:Us,children:n(`customize.linkedActions.loading`,`Checking linked actions.`)}),x&&y.length===0&&i(`li`,{className:Us,children:n(`customize.linkedActions.none`,`None linked.`)}),y.map(r=>e(`li`,{className:Hs,children:[i(`span`,{className:`min-w-0 flex-1 truncate`,children:r.name}),i(Ws,{entry:r}),i(ht,{icon:k,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(ht,{icon:z,variant:`ghost`,size:`sm`,"aria-label":n(`customize.linkedActions.unlink`,`Unlink {{name}}`,{name:r.name}),disabled:h.isPending,onClick:()=>S(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:Us,children:n(`customize.linkedActions.hint`,`Linked actions show as buttons on this camera. Nothing is linked unless you pick it.`)})]}),i(qn,{open:c,onOpenChange:u,children:e(_n,{placement:`sheet-on-mobile`,children:[e(bn,{children:[i(Et,{children:n(`customize.linkedActions.pickTitle`,`Link actions to {{name}}`,{name:t.name})}),i(bt,{children:n(`customize.linkedActions.pickHint`,`Pick the actions to link. Nothing is chosen for you.`)})]}),i(Yr,{children:i(`ul`,{className:`space-y-1`,children:b.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(Nn,{checked:f.includes(t.id),onChange:()=>w(t.id)}),i(`span`,{className:`flex-1`,children:t.name}),i(Ws,{entry:t})]})},t.id))})}),e(Kr,{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:()=>{S([...v,...f]),u(!1)},children:n(`customize.linkedActions.addN`,`Add {{count}}`,{count:f.length})})]})]})})]})}c();function Ks(e,t){let r=typeof e==`string`&&e.length>0,i=Zi(t&&r);return n(()=>t?ya(i,e):null,[t,i,e])}c();function qs(e){return e==null?null:e.message}function Js({device:t}){let n=ce(),{t:r}=X(),a=l(),s=Ai(),c=We.includes(t.type),[u,f]=o(!1),[p,m]=o(!1),[h,g]=o(null),_=Zn({deviceId:t.id},{enabled:c}),v=Na({status:_.status,data:_.data,error:qs(_.error)===null?null:{message:qs(_.error)??``}}),y=v.kind===`present`?v.slot.slotRef:``,b=v.kind===`present`?[...ja(v.slot,v.value).map(e=>e.deviceId),...Aa(v.slot,v.value)]:[],x=Sr(),S=Zi(c&&v.kind===`present`&&(u||b.length>0)),C=Ks(t.location,c&&v.kind===`present`),w=Fr({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(Vs,{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:xa(n.integration,n.location),orphan:t}},k=[...ja(v.slot,T).map(e=>O(e,!1)),...Aa(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:qs(w.error)??r(`helpers.customize.requestFailed`)}:S.kind===`pending`||w.status===`pending`||w.data===void 0?{kind:`pending`}:{kind:`known`,value:Fa(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)}},N=async e=>{await s(r(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await M(Pa(T,e.deviceId))},P=[{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?`—`:Un(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(Rn,{checked:e.tracked,disabled:p,"aria-label":r(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void M(Ma(T,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:i(ht,{icon:z,variant:`ghost`,size:`sm`,"aria-label":r(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:p,onClick:t=>{t.stopPropagation(),N(e)}})}];return e(d,{children:[i(Vs,{id:`linked`,icon:R,title:r(`customize.linked.title`),addLabel:r(`customize.linked.add`),onAdd:p?void 0:()=>f(!0),...C===null?{}:{suggestion:{count:Gi(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(cn,{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:Un(e.type,n).label,columns:P,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(ta,{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(ka(T,e.map(e=>e.deviceId)))},onClose:()=>f(!1)})]})}c();function Ys(e){return e instanceof Error?e.message:String(e)}function Xs(e){let n=In({addonId:e.addonId,stableId:e.stableId}),r=On(),i=Er(),a=Mt(),s=Ii({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=Pi(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:Ys(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 Zs=`pipeline-orchestrator`;function Qs(e){return e.data===void 0?e.status===`pending`?`pending`:e.status===`error`?`unknown`:`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function $s(e,t){return e===`absent`?`absent`:Qs(t)}async function ec(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function tc(e,t){let n=zt(Zs),r=Hr({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>ec(r.refetch),a=r.data===void 0&&r.status===`error`?r.error?.message??null:null;return t?{presence:$s(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 nc(e,t){let n=Bn({deviceType:e.type}),r=br({deviceId:e.id}),i=At({deviceId:e.id}),a=Xi(n,e=>new Set(e.caps.map(e=>e.cap))),o=Xi(r,e=>Hi(e.entries)),s=Xi(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}function rc(e,t,n){let r=t.kind===`known`&&t.value.has(`consumables`),i=ba(r?{deviceId:e,cap:la,path:ki}:null);return ca(t,n,r?i:null)}var ic=`ir-transmitter`;function ac(e,t){let n=new Map(t.customButtons.map(e=>[De(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=Oe(e)!==null;a.push({role:e,custom:o,inLayout:t,name:o?n.get(e)??r.get(e)??Ia(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 oc(e,t,n){let r=Oe(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 sc(e,t,n,r=Ia(t)){return oc({...e,bindings:{...e.bindings,[t]:{action:n}}},t,r)}function cc(e,t){let n=Object.fromEntries(Object.entries(e.bindings).filter(([e])=>e!==t)),r=Oe(t);return{...e,bindings:n,customButtons:r===null?e.customButtons:e.customButtons.filter(e=>e.key!==r)}}function lc(e){return e.deviceId>0&&e.cap!==``&&e.method!==``}var uc={kind:`cap`,deviceId:0,cap:``,method:``};function dc(e){let{action:t}=e;return t.cap===`ir-transmitter`&&t.method===`send`?t.deviceId:null}function fc(e,t){return{action:{...e.action,deviceId:t}}}function pc(e){let t=Object.entries(e.bindings).filter(([,e])=>!lc(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 mc(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=qe(n),r=Ge(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 Ze)return{status:`refused`,reason:`not-smartir`};throw e}}function hc(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 gc({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}`,Ia(t.role)),_=n===void 0?null:dc(n),v=n!==void 0&&lc(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(uc)},"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(an,{"aria-label":p(`remote.bindings.transmitterFor`,{name:g}),value:String(_),options:a.map(e=>({value:String(e.id),label:e.name})),onChange:e=>l(fc(n,Number(e.target.value)).action),"data-testid":`transmitter-${t.role}`}),y&&_===null&&n!==void 0&&i(Ti,{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 _c({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:mc(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(Dt,{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 vc({device:t,open:n,onClose:r}){let{t:a}=X(),o=Tr({deviceId:t.id},{enabled:n});return i(qn,{open:n,onOpenChange:e=>!e&&r(),children:e(_n,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(bn,{children:i(Et,{children:a(`remote.dialog.title`,{name:t.name})})}),o.data===void 0?i(Yr,{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(bc,{device:t,initial:o.data,onClose:r})]})})}function yc(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 bc({device:t,initial:r,onClose:a}){let{t:s}=X(),c=l(),[u,f]=o(r),[p,m]=o(null),[h,g]=o({}),_=dn({kind:`remote`}),v=ur({deviceId:t.id}),y=Ei(),b=pn({capNames:[ic]}),x=Wr(),S=Vn(),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:La(w.payload),E=n(()=>ac(T,u),[T,u]),D=n(()=>new Set((v.data?.commands??[]).map(e=>e.role)),[v.data]),O=pc(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]:yc(n,s)}))}catch(t){g(n=>({...n,[e]:t instanceof Error?t.message:String(t)}))}},M=(e,t)=>f(n=>sc(n,e,t));return e(d,{children:[e(Yr,{className:`space-y-5`,children:[e(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[i(Dt,{label:s(`remote.dialog.template`),children:i(an,{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(Dt,{label:s(`remote.dialog.transmitter`),children:i(an,{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(Dt,{label:s(`remote.dialog.power`),children:i(an,{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(Ra,{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(_c,{transmitterId:u.defaultTransmitterId,onApply:e=>f(t=>hc(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(gc,{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=>cc(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(Kr,{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 xc({device:t}){let{t:n}=X(),[r,a]=o(!1),s=Tr({deviceId:t.id}),c=dn({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(Qi,{id:`remote`,title:n(`remote.card.title`),icon:C,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(vc,{device:t,open:r,onClose:()=>a(!1)})]})}var Sc={remote:xc};function Cc(e){let t=[];for(let[n,r]of Object.entries(Be))r.targets.some(t=>t.cardinality===`config`&&t.deviceTypes.includes(e))&&t.push(n);return t}function wc({device:e}){return Cc(e.type).map(t=>{let n=Sc[t];return n===void 0?null:i(n,{device:e},t)})}function Tc(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 Ec(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 Dc({draft:t,device:n,onEdit:r}){let{t:a,i18n:o}=X(),s=ii(),c=ua(t),l=Ec(t,e=>a(e));return i(St,{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(x,{className:`h-3 w-3`,"aria-hidden":!0}),a(`common.edit`)]}),children:e(`div`,{className:h,children:[i(en,{label:a(`customize.composed.helper.function`),children:Tc(t,e=>a(e))}),l.map(e=>i(en,{label:e.label,children:e.value},e.label)),c.length>0&&i(en,{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(It,{device:n,form:`compact`}),i(`span`,{className:`text-foreground-muted`,children:ma(t.cap,t.fieldPath,o.language)})]},`${t.source.addonId}:${t.source.stableId}:${t.cap}:${t.fieldPath}`)})})})]})})}c();function Oc({device:t}){let{t:r}=X(),a=t.stableId.startsWith(`composed-`)?t.stableId.slice(Te.length):null,s=Vt({blockId:a??``},{enabled:a!==null}),c=Er(),[l,u]=o(!1),d=n(()=>{let e=new Set;for(let{cap:t}of Mi())e.add(t);for(let{cap:t}of Vi())e.add(t);for(let{cap:t}of Ri())e.add(t);for(let n of Cc(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=Re(f.block);if(p===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`compositionEditor.notComposition`)});if(aa(p)){let n=na(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(rs,{device:t}),i(Dc,{draft:n,device:t,onEdit:()=>u(!0)}),i(Di,{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(rs,{device:t}),Li(p)===`incomplete`&&i(q,{variant:`warning`,children:r(`customize.blockStatus.incomplete`)}),i(wc,{device:t}),i(Wi,{device:t,handle:m,skipCaps:d})]})}c();function kc({deviceId:e}){let{t}=X(),n=Zt({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(Oc,{device:r}):i(Ac,{device:r,target:{addonId:r.addonId,stableId:r.stableId}});return i(si,{deviceId:r.id,seed:{name:r.name,location:r.location??``,role:r.role??null,display:r.display},children:a})}function Ac({device:t,target:r}){let a=Xs(r),o=zt(`composer`),{t:s}=X(),c=tc(t.id,t.type===G.Camera),l=nc(t,pa(a.state)),u=rc(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 Mi())e.add(t);for(let{cap:t}of Vi())e.add(t);for(let{cap:t}of Ri())e.add(t);for(let n of Cc(t.type))e.add(n);return e},[t.type]);return e(`div`,{className:`flex flex-col gap-3`,children:[i(rs,{device:t}),o===`absent`&&i(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),a.state.kind!==`none`&&i(jc,{state:a.state}),i(Bs,{device:t,handle:a,facts:d,sensors:c}),i(Ki,{device:t,handle:a,facts:d}),i(ji,{device:t,handle:a,facts:d,defaults:u}),i(wc,{device:t}),i(Wi,{device:t,handle:a,skipCaps:f}),i(Js,{device:t}),t.type===G.Camera&&i(Gs,{device:t})]})}function jc({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 Mc=`overview`;function Nc(e,t){return e.some(e=>e.id===t)?t:Mc}function Pc({deviceId:t}){let{t:n}=X(),r=l(),a=Number.isFinite(t),{data:o}=Zt({deviceId:t},{enabled:a}),s=typeof o?.type==`string`?o.type:`camera`;Mr([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:c,isLoading:u,isError:d,error:f}=br({deviceId:t},{enabled:a}),{data:p}=Jt({deviceType:s},{enabled:!!s}),m=Cr({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(Fc,{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(Ic,{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(Lc,{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(yr,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function Fc({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(I,{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(be,{className:`h-3 w-3`}),n(`common.unbound`)]})}function Ic({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 Lc({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?p:_,{className:`h-3 w-3`}),t]},t)})})}function Rc({deviceId:t,activeSubTab:n,onSubTabChange:r,deviceType:a,isAdmin:o}){return e(`div`,{className:`flex flex-col gap-3`,children:[ai(a,o)&&i(nn,{deviceId:t,readOnly:!0}),i(hi,{deviceId:t,activeSubTab:n,onSubTabChange:r})]})}c();var zc=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function Bc(e){let t=l(),n=Yn({deviceId:e},{refetchOnMount:`always`}),i=gr(),[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:zc})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await t.invalidateQueries({queryKey:zc})}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 Vc=`object-detection`;function Hc(e){return[e.addonId,...e.children.flatMap(Hc)]}function Uc(e,t){if(e===`pipeline`)return new Set;let n=Wc(t,Vc);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:Hc(n))}function Wc(e,t){for(let n of e){if(n.addonId===t)return n;let e=Wc(n.children,t);if(e!==void 0)return e}}function Gc(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.badgeCameraAi`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.badgeNoRoot`):Y.t(`helpers.detectionSourceModel.badgeIdle`)}function Kc(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 qc(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 Jc(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.noticeOnboard`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.noticeNoRoot`):Y.t(`helpers.detectionSourceModel.noticeIdle`)}var Yc=[`pl-2`,`pl-6`,`pl-10`,`pl-14`],Xc={detector:`success`,cropper:`info`,classifier:`primary`,refiner:`warning`,"audio-classifier":`neutral`};function Zc(e){return Yc[Math.min(e,Yc.length-1)]??`pl-2`}function Qc(e){return e.zoneDriven?{kind:`zone-driven`}:{kind:`gate`,effectiveOn:e.ownOn,defaultOn:e.defaultOn,explicit:e.choice!==`auto`}}function $c(e,t,n){return e.kind===`parent`?n:Gc(e.source,t)}function el({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 tl({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:$c(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 ${Zc(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:Xc[t.kind],children:l(t.kind)}),i(el,{inputs:t.inputs,outputs:t.outputs}),c!==null&&i(`span`,{className:`text-[11px] text-warning`,children:c})]}),i(wr,{gate:Qc(t),busy:a,onSet:e=>s(t.stepId,e)})]},t.stepId)})})}function nl(e,t){let n=e?.[t];return n===void 0?`auto`:n?`on`:`off`}function rl(e,t){return e===`auto`?t:e===`on`}function il(e,t,n){return e!==`onboard`&&e!==`none`||!n.has(t)?null:{kind:`source`,source:e}}function al(e,t,n,r,i){let a=e.zoneDrivenIds??new Set;return t.flatMap(t=>{let o=a.has(t.addonId),s=nl(e.toggles,t.addonId),c=e.defaults[t.addonId]??!0,l=o||rl(s,c),u=r===null?il(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,...al(e,t.children,n+1,f,i)]})}function ol(e){let t=e.source===null?new Set:Uc(e.source,e.tree);return al(e,e.tree,0,null,t)}function sl({source:t,geometry:n,saving:r,error:a,onPick:o}){let{t:s}=X(),c=n===`flag-only`,l=qc(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:ne,children:s(`device.detectionSourceControl.rootDetector`,`Root detector`)}),i(Qn,{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:[Kc(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 cl=new Set([`package-detection`]),ll=`/system/pipeline?view=nodes`;function ul(e){return Object.fromEntries(e.slots.flatMap(e=>e.addons.map(e=>[e.id,e.enabledByDefault??!0])))}function dl({deviceId:a}){let{t:c}=X(),u=ve(),d=Ut(),f=l(),p=L().trpcClient,m=t(null),h=t(null),g=xr({deviceId:a},{refetchOnMount:`always`}),_=Jr(void 0,{refetchOnMount:`always`});Mr([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:v}=Or(),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=on({onSuccess:S}),w=Qt(),[T,E]=o(null),[D,O]=o(!1),[k,A]=o(null),j=Bc(a),M=x.data??{},N=g.data??null,P=y.map(e=>M[e.id]).find(e=>e!==void 0)??null,ee=n(()=>P?Vr(P):[],[P]),te=n(()=>P===null?[]:ol({tree:ee,toggles:N?.stepToggles,defaults:ul(P),source:j.source,zoneDrivenIds:cl}),[ee,P,N?.stepToggles,j.source]),{selection:ne,open:re,close:F}=Ta(n(()=>te.map(e=>e.stepId),[te]),[]),ie=y[0]?.id,I=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]),ae=e=>{e!==ne.stepId&&I(()=>re({stepId:e}))},oe=()=>{I(()=>F())};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(P===null)return i(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.catalogUnavailable`,`Catalog unavailable.`)});let se=e=>_.data?.find(e=>e.nodeId===ie)?.settings.stepSettings?.[e]??{},R=te.find(e=>e.stepId===ne.stepId)??null,ce=R===null?null:wa(P,R.stepId),B=d?i(Gn,{onClick:oe}):i(ht,{icon:z,variant:`ghost`,size:`sm`,"aria-label":c(`common.close`,`Close`),onClick:oe});return e(`div`,{ref:m,className:`space-y-2`,children:[j.view?.onboard.available===!0&&j.source!==null&&i(sl,{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(_i,{to:ll,className:`font-medium text-primary hover:underline`})}})}),ne.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:ne.staleStepId})}),i(tl,{rows:te,label:c(`device.cameraStepInspector.detectionStepsOfThisCamera`,`Detection steps of this camera`),selectedId:ne.stepId,busy:C.isPending,onOpen:ae,onSet:(e,t)=>C.mutate({deviceId:a,addonId:e,enabled:t})}),i(Lr,{open:R!==null&&ce!==null,anchor:m,onClose:oe,label:c(`stepInspector.stepMatrixFrame.stepSettings`,`Step settings`),children:R!==null&&ce!==null&&i(fl,{addon:ce,nodeBag:se(R.stepId),storedCamera:N?.stepSettings?.[R.stepId],draft:T?.stepId===R.stepId?T:null,saving:D,status:k,notice:R.blocked?.kind===`source`?Jc(R.blocked.source,R.stepId):null,closeButton:B,onEscape:oe,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 fl({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=ar(t),_=Da(g),v=Ea(g),y=a?.camera??r,b=a!==null&&!Ke(a.camera,r??{});return i(hr,{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(pl,{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 pl({addon:e,fields:t,nodeBag:n,cameraBag:r,onChange:a}){let{t:o}=X();return i(Br,{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 ml(e,t,n){return{id:e,get label(){return Y.t(t)},icon:n}}var hl=[ml(`zones`,`helpers.detectionSettingsGroups.zones`,`shapes`),ml(`object-detection`,`helpers.detectionSettingsGroups.objectDetection`,`scan-search`),ml(`tracking`,`helpers.detectionSettingsGroups.tracking`,`route`),ml(`motion`,`helpers.detectionSettingsGroups.motion`,`activity`),ml(`stationary`,`helpers.detectionSettingsGroups.stationary`,`square-parking`),ml(`audio`,`helpers.detectionSettingsGroups.audio`,`volume-2`),ml(`cluster`,`helpers.detectionSettingsGroups.cluster`,`server`)],gl={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,tracking:`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function _l(e){return gl[e]??`object-detection`}c();var vl=`steps`,yl=`settings`,bl=`object-detection`;function xl(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}var Sl={groupOf:e=>_l(e.id),tabs:hl};function Cl({deviceId:e,activeSubTab:t,onSubTabChange:r}){let{t:a}=X();return i(hi,{deviceId:e,sectionFilter:xl,subTabGrouping:Sl,leadingTabs:n(()=>[{id:vl,label:a(`device.detectionPipelineTab.steps`,`Steps`),content:i(dl,{deviceId:e})}],[e,a]),activeSubTab:t===yl?bl:t,onSubTabChange:r})}var wl=`Notifications`,Tl={i18nKey:`device.deviceNotificationMute.cameraCostWhenOff`,text:`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`},El={i18nKey:`device.deviceNotificationMute.deviceCostWhenOff`,text:`This device never notifies — no rule, no target, no alarm.`};function Dl(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:wl,on:r===null?null:i??r,available:r!==null,costWhenOff:e.isCamera?Tl:El}}function Ol(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}c();function kl(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Al({deviceId:t,isCamera:n}){let{t:a}=X(),s=l(),c=Number.isFinite(t),[u,d]=o(null),[f,p]=o(null),m=Dl({mutedDeviceIds:kl(Ot({},{enabled:c}).data),deviceId:t,isCamera:n,pendingOn:f}),h=a(m.costWhenOff.i18nKey,m.costWhenOff.text),g=Kt({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=Ol(m,t);e!==null&&(p(!e.muted),g.mutate(e))},[t,g,m]),v=m.on===null,y=m.on===!1,b=y?at:E;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 jl({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(Rl(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=ha(l),_=n.id!==`switch`,v=_?$i(n.id,a.map(e=>p.get(Ll(e))??{kind:`pending`})):null;return e(d,{children:[_&&a.map(e=>i(Fl,{member:e,row:Il(s,e),fleetKind:c,onRead:h},Ll(e))),v!==null&&i(Ml,{view:v}),n.id===`lock`&&i(Nl,{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(Pl,{view:g,nameOf:u})]})]})}function Ml({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 Nl({deviceId:t}){let{t:n}=X(),r=dr(),a=cr(),[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(xe,{className:`h-4 w-4`,"aria-hidden":!0}),n(`helper.lockAll`)]}),i(gn,{label:n(`helper.unlockAll`),icon:se,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 Pl({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 Fl({member:e,row:t,fleetKind:n,onRead:r}){let i=Ll(e),o=br({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 Il(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 Ll(e){return`${e.source.addonId}/${e.source.stableId}`}function Rl(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=ra(n),o=Vl(n,t);return i(St,{headingId:`helper-history-status`,title:r(`helper.template.${t.kind}`),icon:ot,testId:`helper-history-status`,children:e(`div`,{className:`${h} 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(tr,{value:Bl(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 Bl(e,t){if(e.kind!==`derivative`)return String(t);let n=Pe(e);return n===null?String(t):`${t} ${n}`}function Vl(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 Hl({helper:t,snapshot:n}){let{t:r}=X(),a=Gl(n,t),o=t.kind===`arithmetic`?ra(n):null;return i(St,{headingId:`helper-math-status`,title:r(`helper.template.${Ul(t)}`),icon:st,testId:`helper-math-status`,children:e(`div`,{className:`${h} 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(tr,{value:String(a.value),label:r(`helper.output`)}),a.kind===`boolean`&&i(tr,{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 Ul(e){return e.kind===`arithmetic`?e.op:e.kind}function Wl(e){return e.kind===`threshold`||e.kind===`expression`&&e.output===`boolean`?{cap:`binary`,field:`on`}:{cap:`numeric-sensor`,field:`value`}}function Gl(e,t){if(e.kind===`pending`)return{kind:`pending`};if(e.kind!==`answered`)return{kind:`empty`};let n=Wl(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 Kl({deviceId:t,stableId:n}){let{t:a}=X(),s=n.startsWith(`composed-`)?n.slice(Te.length):null,c=Vt({blockId:s??``},{enabled:s!==null}),l=Ar({deviceId:t},{enabled:s!==null}),u=Rt({projection:`slim`},{enabled:s!==null}),[d,f]=o(()=>new Map),p=Pn(),m=Wt(),g=r((e,t)=>{f(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 _=Re(c.data.view.block);if(_===null||!aa(_))return null;let v=_.helper;if(v.kind===`threshold`||v.kind===`arithmetic`||v.kind===`expression`)return i(Hl,{helper:v,snapshot:Xl(l.status,l.data,l.error?.message)});if(Je(v))return i(zl,{helper:v,snapshot:Xl(l.status,l.data,l.error?.message)});if(v.kind!==`group`)return null;let y=Ne(v.templateId);if(y===null)return null;let b=Xl(l.status,l.data,l.error?.message),x=oa(b,y),S=ra(b),C=u.status===`success`?u.data.map(Zl):[],w=Ql(u.status),T=da(v.members.map(e=>d.get(Yl(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(Jl(y.id,`on`)):a(Jl(y.id,`off`)):x.kind===`empty`?a(`helper.noReading`):null;return i(St,{headingId:`helper-group-status`,title:a(`helper.statusTitle`),icon:ct,testId:`helper-group-status`,children:e(`div`,{className:`${h} flex flex-col gap-3`,children:[v.members.map(e=>i(ql,{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},Yl(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(tr,{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(jl,{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(p===null)return C.find(t=>t.id===e)?.name??String(e);let t=p.byId.get(e);return t===void 0?String(e):Sn(t,`compact`,p,m)}})]})})}function ql({member:e,row:t,fleetKind:n,isState:r,onLive:i}){let o=t?.online===!0,s=Ar({deviceId:t?.id??0},{enabled:n===`answered`&&t!==null&&o}),c=_a(s.status,s.status===`success`?va(s.data):void 0,e.cap,e.fieldPath,r),l=fa({fleet:n,deviceOnline:n===`answered`?t===null?null:t.online:!0,field:c}),u=t?.name??e.source.stableId,d=Nt(t?.id??0,`compact`,u),f=t===null?u:d,p=Yl(e);return a(()=>{i(p,{name:f,presence:l})},[p,f,i,l]),null}function Jl(e,t){return[`cover`,`valve`,`lock`,`media-player`,`climate`].includes(e)?`helper.state.${e}.${t}`:`helper.${t}`}function Yl(e){return`${e.source.addonId}/${e.source.stableId}/${e.cap}.${e.fieldPath}`}function Xl(e,t,n){return e===`pending`?{kind:`pending`}:e===`error`?{kind:`error`,message:n??``}:{kind:`answered`,caps:va(t)}}function Zl(e){return{id:e.id,name:e.name,online:e.online,addonId:e.addonId,stableId:e.stableId,features:e.features??[]}}function Ql(e){return e===`pending`?`pending`:e===`error`?`error`:`answered`}function $l(e,t){return{switchId:e,label:Le[e].label,detail:t===void 0||t.length===0?null:t}}function eu(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 tu(e){let t=eu(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>$l(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>$l(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 nu(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 ru({deviceId:t,deviceName:r}){let{t:a}=X(),s=ve(),[c,l]=o(null),u=Rt({isCamera:!0,projection:`slim`}),d=jn(),f=u.data!==void 0,p=n(()=>u.data===void 0?[]:nu(u.data,t),[u.data,t]),m=p.find(e=>e.id===c)??null,h=d.data===void 0?null:tu(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(iu,{report:h})]})}function iu({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(Se,{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(M,{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 au({deviceId:t}){let{t:n}=X(),[r,a]=o(null),s=Xr({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(g,{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 ou(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function su({device:t}){let{t:n}=X(),r=pi(),a=typeof t.id==`number`?t.id:null,o=typeof t.name==`string`?t.name:``,s=Nt(a??0,`full`,o),c=String(t.type??``),l=c===G.Camera,u=c===G.Hub,d=t.features??[],f=d.includes(we.Resyncable),{data:p}=xt({deviceId:a??0},{enabled:a!==null&&l,refetchInterval:5e3}),m=p?.streams??{},h=Object.entries(m),g=d.includes(we.DoorbellButton),_=pr(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(Kl,{deviceId:a,stableId:t.stableId}),u&&a!==null&&i(rn,{deviceId:a,onOpenChild:e=>r(`/devices/${e}`)}),f&&a!==null&&i(au,{deviceId:a}),l&&a!==null&&i(ru,{deviceId:a,deviceName:s}),a!==null&&i(Al,{deviceId:a,isCamera:l}),l&&a!==null&&i(Zr,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:a}),g&&i(wt,{history:_.history,latestIsFresh:v}),l&&a!==null&&i(Zr,{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(ae,{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(cu,{label:n(`device.overviewTab.nominal`,`Nominal`),value:ou(r.nominalBitrateKbps??0)}),i(cu,{label:n(`device.overviewTab.observed`,`Observed`),value:ou(r.observedBitrateKbps??0)}),i(cu,{label:n(`device.overviewTab.peak`,`Peak`),value:ou(r.peakBitrateKbps??0)}),i(cu,{label:n(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(r.packetLossPercent??0).toFixed(2)}%`,warning:(r.packetLossPercent??0)>1})]})]},t))})]}),i(ui,{})]})}function cu({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 lu=`history`,uu=[{id:`overview`,labelKey:`helpers.structuralTabs.overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,labelKey:`helpers.structuralTabs.config`,cameraOnly:!1,adminOnly:!1},{id:bi,labelKey:`helpers.structuralTabs.customize`,cameraOnly:!1,adminOnly:!0},{id:lu,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}],du=new Set([G.Hub,G.Container]);function fu(e,t){let n=e===G.Camera,r=e===void 0||!du.has(e);return uu.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)&&(r||e.id!==`history`)).map(({id:e,labelKey:t})=>({id:e,label:Y.t(t)}))}function pu({provider:e,integrationId:t,name:n}){let r=pi(),a=t===null?`/integrations`:xi(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(ci,{type:e,size:`lg`})})}c();var mu=[{id:`logs`,icon:Ce,labelKey:`common.logs`},{id:`repl`,icon:lt,labelKey:`deviceDetail.repl`},{id:`events`,icon:b,labelKey:`common.events`},{id:`state`,icon:de,labelKey:`common.state`}];function hu(){let{t:a}=X(),s=ce(),c=ni(),u=Number(c.deviceId),f=Number.isFinite(u),p=pi(),m=l(),h=ve(),_=L(),{user:y}=fi(),b=y?.isAdmin===!0,[x,C]=vi(),w=x.get(`tab`)??`overview`,T=x.get(`sub`),[E,D]=o(`logs`),O=`device-detail.left-col-width-px`,[k,j]=o(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(O),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),M=t(k);M.current=k;function N(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??k??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{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(O,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:P,isLoading:ee,isError:ne}=Zt({deviceId:u},{enabled:f,refetchInterval:5e3,retry:1}),{data:F}=$t({deviceId:u},{enabled:f}),ie=n(()=>{let e=F?.settings?.sections??[],t=F?.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(ri)&&r.add(di),[...r].map(e=>e===`export`?{id:e,label:yi,isAddonContrib:!0}:{id:e,label:$e[e]?.label??e,isAddonContrib:!0})},[F]),I=P,ae=String(I?.name??c.deviceId??`Device`),oe=I?.online===!0,se=oe?`online`:`offline`,R=String(I?.addonId??`rtsp`),z=I?.features??[],B=I?.type,le=B===G.Camera,{data:ue}=Si(f?u:0),de=B===G.Container,fe=n(()=>(ue??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ue]),V=n(()=>de?zn(fe,typeof I?.linkDeviceId==`number`?I.linkDeviceId:null,typeof I?.primaryChildEntityId==`string`?I.primaryChildEntityId:null)?.id??null:null,[de,fe,I?.linkDeviceId,I?.primaryChildEntityId]),{data:me}=$t({deviceId:V??0},{enabled:V!==null}),he=n(()=>{if(V===null)return[];let e=me?.settings?.sections??[],t=me?.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:$e[e]?.label??e,isAddonContrib:!0,childDeviceId:V}))},[V,me]),ge=n(()=>Co({sections:[...F?.settings?.sections??[],...F?.live?.sections??[]],deviceId:u,...V===null?{}:{child:{sections:[...me?.settings?.sections??[],...me?.live?.sections??[]],deviceId:V}}}),[F,me,u,V]),_e=typeof I?.parentDeviceId==`number`?I.parentDeviceId:null,{data:be}=Zt({deviceId:_e??0},{enabled:_e!==null}),xe={id:Number.isFinite(u)?u:0,name:ae,type:`unknown`,stableId:``,parentDeviceId:null},Se=Mn(I??xe,`full`),Ce=Mn(be??xe,`full`),H=Ut(),Te=I?.disabled!==!0,Ee=n(()=>{let e=F?.settings?.sections??[],t=F?.live?.sections??[];return oi([...e,...t],B,b,F!==void 0)},[F,B,b]),De=n(()=>{let e=new Set,t=[];for(let n of[...fu(B,b),...ie,...he])n.id===`config`&&!Ee||e.has(n.id)||(e.add(n.id),t.push(n));return t},[B,b,ie,he,Ee]),Oe=n(()=>Nc(De,w),[De,w]),ke=r(e=>{C(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of Ca)n.delete(e);return n},{replace:!0})},[C]),Ae=r(e=>{C(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[C]),je=(ue??[]).length>0,Me=n(()=>mu.filter(({featureGate:e})=>!e||z.includes(e)),[z]),{data:Ne}=jt(void 0),Pe=n(()=>I?Bt(I,Ne):null,[I,Ne]),U=Pe?.kind===`resolved`?Pe.integration:null,Fe=U===null?Pe?.kind===`unknown`?a(`deviceDetail.loadingIntegration`):Pe?.kind===`orphan`?a(`deviceDetail.missingIntegration`):a(`deviceDetail.noIntegration`):U.name,Ie=U!==null&&U.addonId===R?U.name:R,Le=jr({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]}),p(U?.id?xi(U.addonId,U.id):`/integrations`)}}),Re=tn({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ze=yt({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=Kn(),Ve=Ln({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),He=z.includes(we.Rebootable),Ue=z.includes(we.BatteryOperated),We=Cn(_.trpcClient,Ue&&f?u:null),W=Lt(_.trpcClient,f?u:null),Ge=pe(_.trpcClient,f?u:null,e=>e.runningState),Ke=Ge===void 0||Ge.running===null?null:Ge.running,qe=Un(B??`unknown`,s).icon,[Je,Ye]=o(!1),Xe=async()=>{if(!Je){Ye(!0);try{let e=Se.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await za(`${re}/${String(u)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Ye(!1)}}},Ze=Re.isPending||ze.isPending,{data:Qe}=lr({deviceId:u},{enabled:f&&le,refetchInterval:1e4}),et=Qe?.agentNodeId??null,tt=typeof et==`string`&&et.length>0&&!et.startsWith(`addon:`)?et:void 0,{data:nt}=An({deviceId:u,...tt?{nodeId:tt}:{}},{enabled:f&&le,refetchInterval:3e3,retry:!1}),{data:rt}=er({deviceId:u},{enabled:f&&le,refetchInterval:3e3,retry:!1}),it=rt?.level?.dbfs??null;function at(){if(!f)return null;switch(Oe){case`overview`:return i(su,{device:I??{}});case`config`:return i(Rc,{deviceId:u,activeSubTab:T,onSubTabChange:Ae,deviceType:B,isAdmin:b});case`detection-pipeline`:return i(Cl,{deviceId:u,activeSubTab:T,onSubTabChange:Ae});case`bindings`:return i(Pc,{deviceId:u});case lu:return i($n,{deviceId:u,onNavigate:e=>p(e)});case bi:return i(kc,{deviceId:u});default:{let e=Oe,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(hi,{deviceId:u,sectionFilter:ri,activeSubTab:T,onSubTabChange:Ae});let a=i(hi,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&t.tab===e,activeSubTab:T,onSubTabChange:Ae});return n!==void 0&&r!==u?i(Rr,{deviceId:r,children:a}):a}}}return f?ee?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`})})]}):ne||!P?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(Xt,{items:[{label:a(`deviceDetail.integrations`,`Integrations`),onClick:()=>p(`/integrations`)},U===null?{label:Fe}:{label:Fe,onClick:()=>p(xi(U.addonId,U.id))},{label:Se}]})}),e(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[U!==null&&i(pu,{provider:U.addonId,integrationId:U.id,name:U.name}),i(fn,{running:Ke,children:i(qe,{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:Se}),i(Ur,{status:se}),Ue&&i(gt,{status:We,variant:`full`}),i(qt,{status:W})]}),_e!==null&&be&&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:z.length>0&&i(gi,{capabilities:z})})]}),nt&&i(`div`,{className:`hidden lg:flex`,children:i(gu,{metrics:nt,dbfs:it})}),e(`div`,{className:`flex items-center gap-1 shrink-0`,children:[e(`button`,{onClick:async()=>{Te?await h({title:a(`deviceDetail.disable`,`Disable "{{name}}"?`,{name:Se}),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`})&&ze.mutate({deviceId:u}):Re.mutate({deviceId:u})},disabled:Ze,title:Te?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 ${Te?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[i(A,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:Ze?a(`deviceDetail.updating`,`Updating…`):Te?a(`deviceDetail.enabled`,`Enabled`):a(`deviceDetail.disabled`,`Disabled`)})]}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),le&&e(d,{children:[i(Ka,{deviceId:u}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),i(Ja,{deviceId:u}),i(qr,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:a(`deviceDetail.takeSnapshot`,`Take snapshot`),description:a(`deviceDetail.fetchAFreshFrameAnd`,`Fetch a fresh frame and download it.`),icon:v,disabled:Je,onClick:()=>{Xe()}},{id:`reboot`,label:a(`deviceDetail.rebootDevice`,`Reboot device`),description:a(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:te,hidden:!He,disabled:Be.isPending,danger:!0,onClick:async()=>{await h({title:a(`deviceDetail.reboot`,`Reboot "{{name}}"?`,{name:Se}),message:a(`deviceDetail.theCameraWillGoOffline`,`The camera will go offline for around 30 seconds while the firmware reboots.`),confirmLabel:a(`deviceDetail.reboot2`,`Reboot`),variant:`danger`})&&Be.mutate({deviceId:u})}},{id:`restart-addon`,label:a(`deviceDetail.restartAddon`,`Restart addon`),description:a(`deviceDetail.bouncesEveryDeviceServedBy`,`Bounces every device served by {{servingAddonLabel}}.`,{servingAddonLabel:Ie}),icon:g,disabled:Ve.isPending,danger:!0,onClick:async()=>{await h({title:a(`deviceDetail.restart`,`Restart "{{servingAddonLabel}}"?`,{servingAddonLabel:Ie}),message:a(`deviceDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device served by it (not just "{{name}}"). Streams will reconnect automatically.`,{name:Se}),confirmLabel:a(`deviceDetail.restart2`,`Restart`),variant:`danger`})&&Ve.mutate({addonId:R})}},{id:`delete`,label:a(`deviceDetail.deleteDevice`,`Delete device`),description:a(`deviceDetail.removeTheDeviceAndAll`,`Remove the device and all its settings.`),icon:S,separatorBefore:!0,disabled:Le.isPending,danger:!0,onClick:async()=>{await h({title:a(`deviceDetail.delete`,`Delete "{{name}}"?`,{name:Se}),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`})&&Le.mutate({deviceId:u})}}]})]})]})]}),i(Rr,{deviceId:u,device:I??void 0,children:i(mt,{children:i(Ct,{children:i(ye,{children:i(Jn,{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`:`${k===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-y-auto`,style:!H&&k!==null?{width:`${String(k)}px`}:void 0,children:[i(`div`,{className:le?`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:le?i(No,{deviceId:u,intercomAvailable:z.includes(we.TwoWayAudio)}):e(`div`,{children:[i(bo,{deviceId:u,deviceName:Se,deviceType:B??`unknown`,provider:R,isOnline:oe,features:z}),i(xo,{deviceId:u,widgets:ge})]})}),le&&ge.length>0&&i(`div`,{className:`flex-shrink-0 border-b border-border-subtle bg-surface pt-3 sm:pt-4`,children:i(xo,{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:Me.map(({id:t,labelKey:n,icon:r})=>{let o=E===t;return e(`button`,{onClick:()=>D(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:[E===`logs`&&i(Po,{deviceId:u,containerDeviceId:B===`container`?u:void 0}),E===`repl`&&i(Fo,{deviceId:u}),E===`events`&&i(Io,{deviceId:u}),E===`state`&&i(Lo,{deviceId:u})]})]})]}),!H&&i(`div`,{role:`separator`,"aria-orientation":`vertical`,title:a(`deviceDetail.dragToResize`,`Drag to resize`),onMouseDown:N,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:De.map(t=>{let n=Oe===t.id;return e(`button`,{onClick:()=>ke(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:[Oe===`overview`&&je&&i(Ya,{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 gu({metrics:t,dbfs:n}){let r=ce(),{t:a}=X(),o=fr(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(ue,{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(le,{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(N,{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{hu as DeviceDetailPage};