@camstack/addon-admin-ui 1.2.623 → 1.2.624

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 (126) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/assets/{Addons-KzL11keT.js → Addons-D9_oXciB.js} +1 -1
  3. package/dist/assets/{AdminPage-CLrZRo9Q.js → AdminPage-CjU3Qym-.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-QZujp_Rk.js → AdminSectionedPage-LULz7C3_.js} +1 -1
  5. package/dist/assets/{AiProfiles-CJymDhUN.js → AiProfiles-B2Pqa3a7.js} +1 -1
  6. package/dist/assets/{Authentication-JPI5tNQR.js → Authentication-gZeEIiCJ.js} +1 -1
  7. package/dist/assets/{Build-JfcMscnG.js → Build-CpiTrCbQ.js} +3 -3
  8. package/dist/assets/{Calendars-C9ZSLbHl.js → Calendars-DclOLLCN.js} +1 -1
  9. package/dist/assets/{CameraGrids-CPw3_tbn.js → CameraGrids-WUfNL6ST.js} +1 -1
  10. package/dist/assets/{Cluster-B5g_W7EV.js → Cluster-CP2CoYke.js} +1 -1
  11. package/dist/assets/{CompositionBlockEditor-DFvE9jtV.js → CompositionBlockEditor-DKBOCxVr.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-C4jc1B6k.js → CompositionEditorPage-BUUQqQOo.js} +1 -1
  13. package/dist/assets/{Data-DUlmeoKU.js → Data-Dz-E4akc.js} +1 -1
  14. package/dist/assets/{DeviceDetail-CWLf4l8q.js → DeviceDetail-DrLi8nYZ.js} +1 -1
  15. package/dist/assets/{DeviceDoActionFields-xv3Yexk0.js → DeviceDoActionFields-HEC7yYzf.js} +1 -1
  16. package/dist/assets/{Devices-Bc4BHwpe.js → Devices-DjFRDFOP.js} +1 -1
  17. package/dist/assets/{EditTemplateButton-BqvyA5Pg.js → EditTemplateButton-CDWvPMbz.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-D_hbiDn0.js → EmbedPlayerPage-Dz0ThiJO.js} +1 -1
  19. package/dist/assets/{History-pMj6FeqQ.js → History-DR_06KaD.js} +1 -1
  20. package/dist/assets/{Identity-DxoiP6P_.js → Identity-BDR1TOR3.js} +1 -1
  21. package/dist/assets/{InstancesTable-CrMiPOFq.js → InstancesTable-CjKHvk50.js} +1 -1
  22. package/dist/assets/{IntegrationDetail-CUUOhCzq.js → IntegrationDetail-DZgCMWiP.js} +1 -1
  23. package/dist/assets/{IntegrationHub-vGZZvN9Y.js → IntegrationHub-CfofBRon.js} +1 -1
  24. package/dist/assets/Integrations-D9yP6yzP.js +1 -0
  25. package/dist/assets/{Integrations-NjDYWDHO.js → Integrations-Q42WYHHG.js} +1 -1
  26. package/dist/assets/{Library-Bl_xkCam.js → Library-C6tHqw32.js} +1 -1
  27. package/dist/assets/{Locations-CcTd8h93.js → Locations-07eSvEIU.js} +1 -1
  28. package/dist/assets/{Logs-CdgFEAUx.js → Logs-CdwRDasW.js} +1 -1
  29. package/dist/assets/{MaskShapeCanvas-BLVQpjX5.js → MaskShapeCanvas-Cdd-VtkN.js} +1 -1
  30. package/dist/assets/{MotionZonesSettings-4zZUDnfh.js → MotionZonesSettings-DLejOdp6.js} +1 -1
  31. package/dist/assets/{MyAccess-DAZSxq6w.js → MyAccess-Db0DJKX-.js} +1 -1
  32. package/dist/assets/{Network-LqpZJtlD.js → Network-Bh6FEQrB.js} +1 -1
  33. package/dist/assets/{NodeAddonsSettingsPanel-D9kXGkje.js → NodeAddonsSettingsPanel-o-ykaRNH.js} +1 -1
  34. package/dist/assets/{Notifications-BtvOosgt.js → Notifications-Bl5golQS.js} +1 -1
  35. package/dist/assets/{Pipeline-DdsVy_AV.js → Pipeline-DSQKBqRo.js} +1 -1
  36. package/dist/assets/{PrivacyMaskSettings-1aaAaXXs.js → PrivacyMaskSettings-D6upVDCO.js} +1 -1
  37. package/dist/assets/{Recordings-Qtccm3Yn.js → Recordings-BnE73Fzq.js} +1 -1
  38. package/dist/assets/{ScanSubnetEditor-t8MFwLUw.js → ScanSubnetEditor-IaqiW7y-.js} +1 -1
  39. package/dist/assets/{SceneMonitorEditor-DQtQEj4e.js → SceneMonitorEditor-B9efTbgK.js} +1 -1
  40. package/dist/assets/{SessionsList-B2cVisrj.js → SessionsList-7r1RdGCD.js} +1 -1
  41. package/dist/assets/{Showroom-TwupeRdK.js → Showroom-783xHdUL.js} +1 -1
  42. package/dist/assets/{StorageLocationsTable-CcXglcoI.js → StorageLocationsTable-DKHWC9nh.js} +1 -1
  43. package/dist/assets/{System-yvxoK1-C.js → System-Bx9kJ2Vx.js} +1 -1
  44. package/dist/assets/{Templates-C4mFSZiC.js → Templates-7WYPtw3p.js} +1 -1
  45. package/dist/assets/{Terminal-CCImGxuy.js → Terminal-D7L1JyUx.js} +1 -1
  46. package/dist/assets/{TrainingProviders-B4mcZKfz.js → TrainingProviders-I5H6sEuq.js} +1 -1
  47. package/dist/assets/{Viewer-B_9mn9kj.js → Viewer-1Blv7Ztf.js} +1 -1
  48. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BLj3clZf.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DmpAM1mu.js} +1 -1
  49. package/dist/assets/{addon-icons-context-C_8qaE3G.js → addon-icons-context-BEfxHNMO.js} +1 -1
  50. package/dist/assets/{archive-C3vMcjeD.js → archive-Djs_JYv3.js} +1 -1
  51. package/dist/assets/{assignment-candidates-BuIx_7M-.js → assignment-candidates-CmqGReT0.js} +1 -1
  52. package/dist/assets/{authed-media-DMusU87j.js → authed-media-BpqhukLe.js} +1 -1
  53. package/dist/assets/{bell-off-CY2cs307.js → bell-off-Ct98laYU.js} +1 -1
  54. package/dist/assets/{boxes-DKifHkk7.js → boxes-B29vzWV6.js} +1 -1
  55. package/dist/assets/{calendar-clock-DDLq2ake.js → calendar-clock-CBwyNflj.js} +1 -1
  56. package/dist/assets/circle-slash-JQ7haXmS.js +1 -0
  57. package/dist/assets/client-wsT1qo5a.js +809 -0
  58. package/dist/assets/{create-composition-SYDEmWRj.js → create-composition-BjzhtLA0.js} +1 -1
  59. package/dist/assets/crop-DhVFvaTE.js +1 -0
  60. package/dist/assets/{database-zap-Dhs7epvK.js → database-zap-BSNprl1e.js} +1 -1
  61. package/dist/assets/{device-integration-icon-CQA-gqJ3.js → device-integration-icon-CVQW3uUx.js} +1 -1
  62. package/dist/assets/device-picker-model-DOA_AHBE.js +1 -0
  63. package/dist/assets/dist-Bh55Njjh.js +809 -0
  64. package/dist/assets/{dist-DhVqbh46.js → dist-BtWxYt15.js} +1 -1
  65. package/dist/assets/{eraser-BXrd43PO.js → eraser-B2SV94Kf.js} +1 -1
  66. package/dist/assets/{file-up-C4GXJyov.js → file-up-BY1FyH2Q.js} +1 -1
  67. package/dist/assets/{grip-vertical-C9DzhrBS.js → grip-vertical-BWxAjsXl.js} +1 -1
  68. package/dist/assets/{hard-drive-download-CZYdVqd_.js → hard-drive-download-BTrg390i.js} +1 -1
  69. package/dist/assets/{hostInit-C49TaBck.js → hostInit-BDNMYuMC.js} +1 -1
  70. package/dist/assets/{icons-Ud0oSLOy.js → icons-ZjiGL3Qs.js} +1 -1
  71. package/dist/assets/{index-BCCGVD9f.js → index-0zF1qyaf.js} +3 -3
  72. package/dist/assets/{key-2bnMZjKx.js → key-VMD0Nojq.js} +1 -1
  73. package/dist/assets/{key-square-DcGB0_0B.js → key-square-DYDS2ySy.js} +1 -1
  74. package/dist/assets/{layers-1dZdqzsn.js → layers-B5Q59zGJ.js} +1 -1
  75. package/dist/assets/{link-2-off-DHNm-mat.js → link-2-off-D2FSHUkT.js} +1 -1
  76. package/dist/assets/{linked-devices-model-o0v4Bm2S.js → linked-devices-model-DdQpLGk3.js} +1 -1
  77. package/dist/assets/{list-ordered-DS1i0RJW.js → list-ordered-Dcctov2f.js} +1 -1
  78. package/dist/assets/{memory-stick-uePzeBGn.js → memory-stick-C7K-tKSa.js} +1 -1
  79. package/dist/assets/{message-square-plus-CCwZJhae.js → message-square-plus-mVoh3HdQ.js} +1 -1
  80. package/dist/assets/{mf-entry-bootstrap-0-a9d1f756.js → mf-entry-bootstrap-0-137671ea.js} +2 -2
  81. package/dist/assets/{mic-off-BCSgetxJ.js → mic-off-DtLUWxtz.js} +1 -1
  82. package/dist/assets/{monitor-off-CS4v-A38.js → monitor-off-DyTKg8lR.js} +1 -1
  83. package/dist/assets/{monitor-smartphone-Dd7prEi4.js → monitor-smartphone-gg9swCyF.js} +1 -1
  84. package/dist/assets/mount-DOA_AHBE.js +1 -0
  85. package/dist/assets/{player-overlays-oE7aPZdg.js → player-overlays-nsKWep_b.js} +1 -1
  86. package/dist/assets/remoteEntry-CmIIKd59.js +1 -0
  87. package/dist/assets/{ruler-BkEZ6CMq.js → ruler-B1CteblT.js} +1 -1
  88. package/dist/assets/{scissors-Dtc0iZPF.js → scissors-CaA205Yl.js} +1 -1
  89. package/dist/assets/{search-x-C7zLOTi7.js → search-x-DFRNlPyV.js} +1 -1
  90. package/dist/assets/{send-BA_OtGrV.js → send-CPG04w86.js} +1 -1
  91. package/dist/assets/{settings-2-BzcfNdMc.js → settings-2-BFvRIHHf.js} +1 -1
  92. package/dist/assets/{shapes-CaybZ7kz.js → shapes-Cv8yN5GQ.js} +1 -1
  93. package/dist/assets/{sigma-DFDTfJlI.js → sigma-CGh2ukye.js} +1 -1
  94. package/dist/assets/{speaker-PGSeODKI.js → speaker-CiFv1--z.js} +1 -1
  95. package/dist/assets/src-C8Zf9Q7y.js +100 -0
  96. package/dist/assets/{step-inspector-model-B1Tuq6co.js → step-inspector-model-DeHccH5q.js} +1 -1
  97. package/dist/assets/{table-2-B1IGjGV3.js → table-2-Cgy92RuE.js} +1 -1
  98. package/dist/assets/{timer-reset-BePL4KnU.js → timer-reset-BtNgj9Cs.js} +1 -1
  99. package/dist/assets/{tv-Be97KtJK.js → tv-DXjaCKCw.js} +1 -1
  100. package/dist/assets/{unlink-WMRglu7x.js → unlink-CK0jpIZO.js} +1 -1
  101. package/dist/assets/{usb-DELsHf1A.js → usb-CDcQOKbY.js} +1 -1
  102. package/dist/assets/{use-device-bound-caps-Ci1qRqfj.js → use-device-bound-caps-CvYPEjf_.js} +1 -1
  103. package/dist/assets/{use-scenes-feed-CSRDiXlC.js → use-scenes-feed-tId-2Z23.js} +1 -1
  104. package/dist/assets/{use-stationary-objects-C4uhF0Lo.js → use-stationary-objects-Bx6JK5H8.js} +1 -1
  105. package/dist/assets/{useAdminDeviceRemoval-C5k2S_qW.js → useAdminDeviceRemoval-ScXvVZYj.js} +1 -1
  106. package/dist/assets/useEventInvalidation-DOA_AHBE.js +1 -0
  107. package/dist/assets/{useNodeUrlSelection-CgRrxNd2.js → useNodeUrlSelection-ArB2g5FQ.js} +1 -1
  108. package/dist/assets/user-round-BtQRG_UD.js +1 -0
  109. package/dist/assets/{user-x-DARSMBU3.js → user-x-Y72N_IkT.js} +1 -1
  110. package/dist/assets/{variable-BCL__P0T.js → variable-CEsk8LrD.js} +1 -1
  111. package/dist/assets/{video-B38E1osq.js → video-CUSTu3rp.js} +1 -1
  112. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Bkkm-53n.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DvhyKcT_.js} +2 -2
  113. package/dist/index.html +8 -8
  114. package/dist/server/addon.js +14 -27
  115. package/package.json +2 -2
  116. package/dist/assets/Integrations-DIgPCmCb.js +0 -1
  117. package/dist/assets/circle-slash-D9aFPEN1.js +0 -1
  118. package/dist/assets/client-DRdJu8dM.js +0 -809
  119. package/dist/assets/crop-D1nLFU4t.js +0 -1
  120. package/dist/assets/device-picker-model-CgDeVP8s.js +0 -1
  121. package/dist/assets/dist-UQng_ywA.js +0 -809
  122. package/dist/assets/mount-CgDeVP8s.js +0 -1
  123. package/dist/assets/remoteEntry-C7_kKwaq.js +0 -1
  124. package/dist/assets/src-CCPnH3Vz.js +0 -100
  125. package/dist/assets/useEventInvalidation-CgDeVP8s.js +0 -1
  126. package/dist/assets/user-round-DJFBqcFq.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,$r as p,An as m,Bn as h,Ci as g,Cr as _,D as v,Di as y,Et as b,Fn as x,G as S,Ii as C,J as w,K as T,Kt as E,Lr as D,Mt as O,Ni as k,O as A,Pn as j,Qi as M,Sn as N,Un as P,V as F,Vi as ee,Vn as te,W as ne,Wn as re,Yn as I,Z as ie,Zi as L,Zr as ae,_r as oe,ar as R,br as se,bt as ce,ci as z,cr as le,ct as ue,da as de,dt as fe,ei as pe,ha as me,hr as he,ht as B,jn as ge,or as _e,ot as ve,q as ye,r as be,sa as xe,sn as Se,t as Ce,ui as V,un as we,ur as Te,ut as H,vr as Ee,wn as De,wt as Oe,xa as ke,z as Ae}from"./player-overlays-oE7aPZdg.js";import{Ai as je,Ci as Me,Gn as Ne,Ii as Pe,In as Fe,Ji as U,Jn as Ie,Ki as Le,Kn as Re,Ln as ze,Mo as W,No as G,Nr as Be,Qi as Ve,To as He,Vi as Ue,Vn as We,Wn as Ge,Xi as Ke,Xn as qe,Ya as Je,Zi as Ye,_s as Xe,aa as Ze,an as Qe,bo as $e,ea as et,en as tt,fo as nt,go as rt,hr as it,ia as at,in as ot,jo as st,ka as ct,mr as lt,ms as ut,n as dt,nn as ft,nr as pt,oa as mt,on as ht,p as gt,pa as _t,pr as vt,qn as yt,rn as bt,rr as xt,sn as St,ta as Ct,tn as wt,tr as Tt,xa as Et,xr as Dt,ys as Ot}from"./client-DRdJu8dM.js";import{N as kt,O as At,v as jt}from"./__vite-browser-external-BCAtXlNQ.js";import{t as Mt}from"./archive-C3vMcjeD.js";import{a as Nt,c as Pt,i as Ft,n as It,o as Lt,r as Rt,s as zt,t as Bt}from"./tv-Be97KtJK.js";import{t as Vt}from"./bell-off-CY2cs307.js";import{r as Ht,t as Ut}from"./sigma-DFDTfJlI.js";import{t as Wt}from"./boxes-DKifHkk7.js";import{n as Gt}from"./video-B38E1osq.js";import{t as Kt}from"./circle-slash-D9aFPEN1.js";import{t as qt}from"./file-up-C4GXJyov.js";import{t as Jt}from"./layers-1dZdqzsn.js";import{$s as Yt,$t as Xt,Ac as Zt,Af as Qt,Al as $t,Br as en,Bs as tn,Cf as nn,Cl as rn,Cs as an,Cu as on,Df as sn,Di as K,Do as cn,Dt as ln,Ed as un,El as dn,Fi as fn,Fl as pn,Fn as mn,Fr as hn,Ft as q,Fu as gn,Gl as _n,Go as vn,Gr as yn,Hi as bn,Hn as xn,Ho as Sn,Hr as Cn,Hs as wn,Ii as Tn,Ir as En,It as Dn,Iu as On,Jl as kn,Jn as An,Jt as jn,Ki as Mn,Kl as Nn,Ko as Pn,Kr as Fn,Kt as In,Ln,Lo as Rn,Lr as zn,Lt as Bn,Lu as Vn,Mn as Hn,Mu as Un,Ni as Wn,Nt as Gn,Nu as Kn,Oa as qn,Pi as Jn,Pr as Yn,Qa as Xn,Qt as Zn,Rn as Qn,Ro as $n,Rr as er,Ru as tr,Sf as nr,Sl as rr,Ss as ir,Su as ar,Tn as or,Ui as sr,Uo as cr,Ur as lr,Vc as ur,Vi as dr,Vo as fr,Vr as pr,Vs as mr,Wo as hr,Wt as gr,Xn as _r,Xr as vr,Xt as yr,Y as br,Yc as xr,Yl as Sr,Yn as Cr,Yr as J,Yt as wr,Zc as Tr,Zo as Er,Zr as Dr,Zs as Or,_ as kr,_n as Ar,_o as jr,_s as Mr,_t as Nr,af as Pr,ai as Fr,an as Ir,ar as Lr,bu as Rr,cf as Y,cn as zr,ct as Br,df as Vr,di as Hr,dn as Ur,ec as Wr,es as Gr,f as Kr,fa as qr,ff as Jr,fo as Yr,ft as Xr,g as Zr,gi as Qr,gn as $r,go as ei,gt as ti,ho as ni,hr as ri,ht as ii,if as ai,ii as oi,in as si,io as ci,iu as li,jn as ui,jo as di,kc as fi,kf as pi,l as mi,lf as hi,ln as gi,lr as _i,lt as vi,mf as yi,ml as bi,mr as xi,nn as Si,no as Ci,o as wi,of as Ti,oi as Ei,on as Di,oo as Oi,or as ki,po as Ai,pt as ji,ql as Mi,qn as Ni,qo as Pi,r as Fi,ri as Ii,rs as Li,s as Ri,sf as zi,si as Bi,tc as Vi,tn as Hi,to as Ui,u as Wi,uf as Gi,un as Ki,uo as qi,ur as Ji,vn as Yi,vt as Xi,wf as Zi,wl as Qi,xu as $i,y as ea,yi as X,ys as ta,yt as na,yu as ra,zi as ia,zn as aa,zr as oa}from"./src-CCPnH3Vz.js";import{t as Z}from"./i18n-DFz3VmFc.js";import{t as Q}from"./useTranslation-BJr-n0es.js";import"./mount-CgDeVP8s.js";import{A as sa,B as ca,Br as la,D as ua,Fr as da,G as fa,H as pa,I as ma,L as ha,M as ga,O as _a,Pr as va,R as ya,Rr as ba,U as xa,V as Sa,W as Ca,b as wa,j as Ta,k as Ea,p as Da,z as Oa,zr as ka}from"./index-BCCGVD9f.js";import{n as Aa,t as ja}from"./format-DAm6he6w.js";import{T as Ma,n as Na,r as Pa,s as Fa,t as Ia}from"./create-composition-SYDEmWRj.js";import{$ as La,A as Ra,B as za,Ct as Ba,D as Va,E as Ha,F as Ua,G as Wa,H as Ga,I as Ka,J as qa,K as Ja,L as Ya,M as Xa,N as Za,O as Qa,P as $a,Q as eo,R as to,S as no,St as ro,T as io,U as ao,V as oo,W as so,X as co,Y as lo,Z as uo,_ as fo,_t as po,at as mo,b as ho,bt as go,c as _o,ct as vo,d as yo,dt as bo,et as xo,f as So,ft as Co,gt as wo,h as To,ht as Eo,it as Do,j as Oo,k as ko,l as Ao,lt as jo,m as Mo,mt as No,nt as Po,ot as Fo,p as Io,pt as Lo,q as Ro,rt as zo,s as Bo,st as Vo,tt as Ho,u as Uo,ut as Wo,v as Go,vt as Ko,wt as qo,x as Jo,xt as Yo,yt as Xo,z as Zo}from"./CompositionBlockEditor-DFvE9jtV.js";import{t as Qo}from"./assignment-candidates-BuIx_7M-.js";import{_ as $o,b as es,i as ts,m as ns,o as rs,t as is}from"./step-inspector-model-B1Tuq6co.js";import"./useEventInvalidation-CgDeVP8s.js";import{_ as as,a as os,b as ss,i as cs,o as ls,r as us,t as ds}from"./EditTemplateButton-BqvyA5Pg.js";import{t as fs}from"./use-stationary-objects-C4uhF0Lo.js";import{a as ps}from"./notification-rule-status-hT9lSvAp.js";import{a as ms,c as hs,i as gs,l as _s,n as vs,o as ys,r as bs,s as xs,t as Ss,u as Cs}from"./linked-devices-model-o0v4Bm2S.js";import{t as ws}from"./authed-media-DMusU87j.js";c();function Ts(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 Es(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(Ts).filter(e=>e!==null);return n.length===0?null:n}var Ds=[[/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 Os(e){for(let[t,n]of Ds)if(t.test(e))return n;return`generic`}function ks(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(Z.t(`helpers.cameraSwitchRows.off`,{list:r(t)})),n.length>0&&i.push(Z.t(`helpers.cameraSwitchRows.unknown`,{list:r(n)})),{offIds:t,unknownIds:n,summary:i.length===0?Z.t(`helpers.cameraSwitchRows.allOn`):i.join(` · `)}}var As={stream:x,detection:It,privacy:p,microphone:Te,speaker:O,listening:Lt,archive:Mt,recording:zt,notifications:L,generic:we};function js({deviceId:t}){let{t:n}=Q(),a=l(),s=Number.isFinite(t),[c,u]=o(null),[d,f]=o(!1),p=dn({deviceId:t},{enabled:s});wi([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=Es(p.data),h=Sr({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 _=ks(m),v=e=>c?.id===e.id?c.message:null;return e(Gi,{open:d,onOpenChange:f,children:[e(Jr,{"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(we,{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(Vr,{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(Ms,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function Ms({row:t,failure:n,onToggle:r}){let{t:a}=Q(),o=As[Os(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(X,{variant:`unstyled`,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 Ns({deviceId:t}){let n=Hi(B().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(pe,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:n.label})]})}function Ps({parentDeviceId:t}){let{t:n}=Q(),r=ba(),a=B(),{data:o,isLoading:s,isError:c}=Sa(t),{data:l}=fr({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=yr(l?.stableId??``,u,l?.childLayout),f=d.ungrouped,p=e=>r(`/devices/${String(e)}`),m=l?.name??``,h=(e,t)=>i(jn,{trpc:a.trpcClient,device:{...t,name:Si(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(wr,{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(wr,{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 Fs({deviceId:e}){let t=B(),{data:n,isLoading:r}=ca(e),{data:a,isLoading:o}=Sa(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(si,{trpc:t.trpcClient,children:c,linkDeviceId:l,primaryChildEntityId:u})})}c();function Is({deviceId:t,button:n,sources:r,current:a,placement:s}){let{t:c}=Q(),l=Vn(),[u,f]=o(!1),[p,m]=o(null);if(r.length===0)return null;let h=a===``?c(`remote.sourceSelect.label`):a,g=r.filter(e=>e.kind===`digits`),_=r.filter(e=>e.kind!==`digits`),v=async e=>{m(null);try{let n=await l.mutateAsync({deviceId:t,command:`selectSource`,source:e.name,repeat:1});if(n.status===`refused`){m(c(`remote.test.refused.${n.reason}`,{detail:n.detail??``}));return}if(n.status===`not-routed`){m(c(`remote.sourceSelect.notRouted`));return}f(!1)}catch(e){m(e instanceof Error?e.message:String(e))}};return e(d,{children:[e(X,{type:`button`,size:`sm`,variant:`secondary`,"aria-label":h,title:h,"data-testid":`remote-grid-button-${n.id}`,"data-widget":`source_select`,className:fe(`z-10 h-full min-w-0 overflow-hidden border border-border px-2`,cs(n.shape),os(n.tone)),style:s,onClick:()=>{m(null),f(!0)},children:[i(Bt,{className:`h-4 w-4 shrink-0`,"aria-hidden":!0}),i(`span`,{className:`min-w-0 truncate text-xs`,children:h})]}),u&&i(hn,{open:!0,onOpenChange:e=>!e&&f(!1),children:e(zn,{width:`sm`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(en,{children:i(pr,{children:c(`remote.sourceSelect.title`)})}),e(En,{className:`space-y-3`,"data-testid":`source-picker`,children:[i(Ls,{title:c(`remote.sourceSelect.channels`),sources:g,current:a,busy:l.isPending,onPick:e=>void v(e)}),i(Ls,{title:c(`remote.sourceSelect.inputs`),sources:_,current:a,busy:l.isPending,onPick:e=>void v(e)}),p!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger`,"data-testid":`source-picker-failure`,children:p})]})]})})]})}function Ls({title:t,sources:n,current:r,busy:a,onPick:o}){return n.length===0?null:e(`section`,{className:`space-y-1`,children:[i(`h3`,{className:`text-xs font-medium uppercase tracking-wide text-foreground-muted`,children:t}),i(`ul`,{className:`space-y-1`,children:n.map(t=>i(`li`,{children:e(X,{type:`button`,variant:t.name===r?`secondary`:`ghost`,size:`sm`,disabled:a,className:`w-full justify-start gap-2`,"data-testid":`source-pick-${t.id}`,onClick:()=>o(t),children:[t.kind===`digits`&&i(`span`,{className:`w-10 shrink-0 text-right tabular-nums text-foreground-muted`,children:t.number}),i(`span`,{className:`min-w-0 truncate`,children:t.name})]})},t.id))})]})}c();function Rs({deviceId:t,deviceName:n}){let{t:r}=Q(),a=Dr(`remote`),s=gn({deviceId:t},{enabled:a===`present`}),[c,l]=o(!1);return a!==`present`||(s.data?.commands.length??0)===0&&(s.data?.sources.length??0)===0?null:e(`div`,{className:`flex flex-wrap items-center justify-center gap-1`,children:[e(X,{size:`sm`,variant:`outline`,onClick:()=>l(!0),"data-testid":`hero-remote`,children:[i(Fi,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),r(`remote.hero.open`)]}),c&&i(zs,{deviceId:t,deviceName:n,onClose:()=>l(!1)})]})}function zs({deviceId:t,deviceName:n,onClose:r}){let{t:a}=Q(),s=Kn({deviceId:t}),c=un({kind:`remote`}),l=gn({deviceId:t}),u=On(),d=Un({deviceId:t}),[f,p]=o(null),m=s.data?.layoutTemplateId??null,h=(c.data??[]).find(e=>e.id===m),g=h===void 0?null:ss(h.payload),_=new Set((l.data?.commands??[]).map(e=>e.role)),v=async e=>{let n=g?.buttons.find(t=>t.id===e)?.role;if(!(n===void 0||!_.has(n))){p(null);try{let e=await u.mutateAsync({deviceId:t,role:n,repeat:1});e.status===`refused`&&p(a(`remote.test.refused.${e.reason}`,{detail:e.detail??``}))}catch(e){p(e instanceof Error?e.message:String(e))}}};return i(hn,{open:!0,onOpenChange:e=>!e&&r(),children:e(zn,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(en,{children:i(pr,{children:a(`remote.hero.title`,{name:n})})}),e(En,{className:`space-y-3`,children:[s.status===`error`?i(J,{title:a(`remote.dialog.unreadable`),message:s.error?.message??``,onRetry:()=>void s.refetch()}):g===null?i(`p`,{className:`text-xs text-foreground-muted`,children:a(`remote.hero.noLayout`)}):i(`div`,{className:`mx-auto w-full max-w-xs`,"data-testid":`remote-press`,children:i(us,{grid:g,label:a(`remote.hero.title`,{name:n}),boundRoles:_,onSelect:e=>void v(e),renderWidget:(e,n)=>i(Is,{deviceId:t,button:e,sources:l.data?.sources??[],current:d.data?.source??``,placement:n})})}),f!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger`,children:f})]})]})})}c();function Bs({dev:t,busy:n,setBusy:r}){let{t:a}=Q(),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(X,{variant:`unstyled`,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(me,{className:`h-3 w-3`}),i(`span`,{children:m})]})}c();function $({deviceId:t,deviceName:n,deviceType:r,features:a}){let s=B(),c=zr(r)?.HeroCard??gi,l=T(s.trpcClient,t),u=w(l?.state.deviceStatus),[d,f]=o(!1),p=u!==void 0&&u.online===!1,m=p?u.lastChangedAt:null;return e(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[p?i(`div`,{className:`flex justify-center`,children:i(Di,{lastChangedAt:m})}):null,i(c,{trpc:s.trpcClient,deviceId:t,features:a}),r===G.MediaPlayer?i(Rs,{deviceId:t,deviceName:n}):null,i(`div`,{className:`flex justify-center`,children:i(Bs,{dev:l,busy:d,setBusy:f})})]})}function Vs({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(Ki,{trpc:B().trpcClient,deviceId:e,features:t})})}function Hs({deviceId:e}){let{t}=Q(),n=Rr({deviceId:e},{staleTime:15e3}).data;if(n===void 0||n.linked!==!0||n.switchOn===null)return i(d,{});let r=n.switchOn===!0?t(`deviceHero.powerLine.on`,`Power switch on`):t(`deviceHero.powerLine.off`,`Power switch off`);return i(`p`,{className:`px-3 pt-1 text-[11px] text-foreground-muted sm:px-4`,children:n.switchName===null||n.switchName===``?r:t(`deviceHero.powerLine.withName`,`{{state}} · {{name}}`,{state:r,name:n.switchName})})}function Us({deviceId:e,features:t}){return i(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:i(gi,{trpc:B().trpcClient,deviceId:e,features:t})})}function Ws(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Gs(e){if(!e)return null;let t=Ws(e.data);return t===null?e.eventType:Z.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var Ks=1e3,qs=60*Ks,Js=60*qs,Ys=24*Js;function Xs(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Ks?Z.t(`helpers.relativeTime.justNow`):n<qs?Z.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/Ks)}):n<Js?Z.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/qs)}):n<Ys?Z.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/Js)}):Z.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Ys)})}c();var Zs=1500,Qs=15e3,$s=1e3;function ec({deviceId:n}){let{t:r}=Q(),s=T(B().trpcClient,n)?.state.eventEmitter,c=w(s);a(()=>{if(!s)return;s.refresh();let e=setInterval(()=>{s.refresh()},Qs);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)},Zs);return()=>{clearTimeout(t)}},[u]);let[m,h]=o(()=>Date.now());a(()=>{let e=setInterval(()=>{h(Date.now())},$s);return()=>{clearInterval(e)}},[]);let g=Gs(l),_=c?.eventTypes??[],v=c?.eventCountSinceStart??0,y=c!==void 0,b=Ws(l?.data);return e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[i(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(f),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${f?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:g??r(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:i(f?R:D,{className:`h-10 w-10`})}),e(`div`,{className:`text-center`,children:[b!==null&&i(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:r(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(b)})}),i(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${g?`text-foreground`:`text-foreground-subtle`}`,children:g??(y?r(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):r(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),i(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:l?Xs(l.timestamp,m):r(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),_.length>0&&i(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:_.map(e=>i(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===l?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),i(`div`,{className:`text-[10px] text-foreground-subtle`,children:r(`hero.eventEmitterHero.sinceStart`,{count:v})})]})}function tc({deviceName:t,deviceType:n,provider:r,isOnline:a,features:o}){let{t:s}=Q();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(Ca,{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(Xi,{status:a?`online`:`offline`}),o.length>0&&i(fa,{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 nc({deviceId:t}){let{t:r}=Q(),a=l(),o=Yr({deviceId:t},{refetchInterval:1e4,retry:!1}),s=Ai({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),a.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),c=n(()=>rc(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(ic,{label:r(`hero.hubHero.discovered`,`Discovered`),value:c.total,icon:i(f,{className:`h-3.5 w-3.5`})}),i(ic,{label:r(`hero.hubHero.adopted`,`Adopted`),value:c.adopted,accent:`success`}),i(ic,{label:r(`hero.hubHero.available`,`Available`),value:c.available,accent:c.available>0?`primary`:void 0}),e(X,{variant:`unstyled`,type:`button`,onClick:()=>{s.mutateAsync({deviceId:t}).catch(()=>{})},disabled:s.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[s.isPending?i(se,{className:`h-3.5 w-3.5 animate-spin`}):i(j,{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(ac,{icon:i(Oe,{className:`h-3 w-3 text-emerald-500`}),label:r(`hero.hubHero.online`,`{{online}} online`,{online:c.online})}),i(ac,{icon:i(_e,{className:`h-3 w-3 text-amber-500`}),label:r(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:c.sleeping})}),i(ac,{icon:i(b,{className:`h-3 w-3 text-destructive`}),label:r(`hero.hubHero.offline`,`{{offline}} offline`,{offline:c.offline})}),c.unknown>0?i(ac,{icon:i(g,{className:`h-3 w-3 text-foreground-subtle`}),label:r(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:c.unknown})}):null]})]})}function rc(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 ic({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 ac({icon:t,label:n}){return e(`span`,{className:`inline-flex items-center gap-1`,children:[t,i(`span`,{children:n})]})}var oc={[G.Switch]:$,[G.Siren]:$,[G.Light]:$,[G.Sensor]:$,[G.Button]:$,[G.Hub]:nc,[G.Cover]:Vs,[G.Valve]:$,[G.Humidifier]:$,[G.WaterHeater]:$,[G.Heater]:$,[G.Container]:Fs,[G.Lock]:$,[G.Fan]:$,[G.Thermostat]:$,[G.Climate]:$,[G.MediaPlayer]:$,[G.Control]:$,[G.AlarmPanel]:$,[G.EventEmitter]:ec,[G.Notifier]:Us,[G.Script]:$,[G.Automation]:$,[G.Presence]:$,[G.Update]:$,[G.Vacuum]:$,[G.LawnMower]:$,[G.Weather]:$,[G.Image]:$,[G.PetFeeder]:$,[G.PetFountain]:$,[G.Dishwasher]:$,[G.Washer]:$,[G.Dryer]:$};function sc(e){return oc[e]??tc}function cc({deviceId:e}){let t=ye(B().trpcClient,e,e=>e.runningState);if(t===void 0||t.running!==!0&&t.running!==!1)return i(d,{});let n=t.running;return i(Cr,{running:n,since:t?.since??null,phase:t?.phase??null,className:`px-3 pt-2 sm:px-4`})}function lc(t){let n=sc(t.deviceType);return e(d,{children:[i(cc,{deviceId:t.deviceId}),i(Hs,{deviceId:t.deviceId}),i(n,{...t})]})}var uc={[G.Sensor]:[`host/power-meter-line`]};function dc(e){let t=Object.values(G).find(t=>t===e);return t===void 0?[]:uc[t]??[]}function fc({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(Yn,{widgetId:t.widgetId,deviceId:t.deviceId});return i(`div`,{children:t.deviceId===e?n:i(Qr,{deviceId:t.deviceId,children:n})},t.widgetId)})})}function pc(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 mc(e){let t=new Set(e.drawnByHero??[]),n=pc(e).filter(e=>!t.has(e.widgetId)),r=new Set(n.map(e=>e.widgetId)),i=e.child===void 0?[]:pc(e.child),a=[...n,...i.filter(e=>!r.has(e.widgetId))],o=new Set;return a.filter(e=>o.has(e.widgetId)?!1:(o.add(e.widgetId),!0)).sort((e,t)=>e.order-t.order)}function hc(e){return Wi(B().trpcClient,e)}c();function gc(e){let[n,i]=o(`idle`),[s,c]=o(null),l=t(null),u=t(null),d=t(null),f=t(!0),p=Wr(),m=Yt(),h=Vi(),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 _c=0;function vc(){return++_c}function yc(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function bc(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 xc(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 Sc(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 Cc({scope:n,greeting:s,className:c}){let{t:l}=Q(),d=B(),[f,p]=o(()=>{let e=[];return s&&e.push({id:vc(),kind:`info`,text:s}),e.push({id:vc(),kind:`info`,text:`scope: ${yc(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:vc(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);p(e=>[...e,{id:vc(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){p([{id:vc(),kind:`info`,text:`scope: ${yc(n)}`}]),h(``);return}if(t===`help`){p(e=>[...e,{id:vc(),kind:`input`,text:`> ${t}`},...bc(n).map(e=>({id:vc(),kind:`info`,text:e}))]),h(``);return}if(t===`context`){p(e=>[...e,{id:vc(),kind:`input`,text:`> ${t}`},...Sc(n).map(e=>({id:vc(),kind:`info`,text:e}))]),h(``);return}if(t===`examples`){p(e=>[...e,{id:vc(),kind:`input`,text:`> ${t}`},...xc(n).map(e=>({id:vc(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,t]),y(-1),p(e=>[...e,{id:vc(),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:vc(),kind:`info`,text:`scope: ${yc(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(zi,{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 wc(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 Tc({deviceId:e,intercomAvailable:t=!1}){let r=B(),a=typeof window<`u`?ie():``,o=Number.isFinite(e),s=hc(o?e:null),c=fs(o?[e]:[]),l=n(()=>{if(!o)return;let e=[];for(let t of c.rows){let n=mi(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:y,getSessionState:b,applyDownlinkProbe:x}=mn(r.trpcClient,o?e:null),C=S(o?e:null,{width:Ac}),w=gc(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=be(),k=Fn(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=wc(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(Br,{serverUrl:a,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:_,getIceCandidates:v,closeSession:y,getSessionState:b,applyDownlinkProbe:x,...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 Ec({deviceId:e,containerDeviceId:t}){let{t:n}=Q();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full`,children:i(Yi,{...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 Dc({deviceId:e}){let{t}=Q();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(`
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,$r as p,An as m,Bn as h,Ci as g,Cr as _,D as v,Di as y,Et as b,Fn as x,G as S,Ii as C,J as w,K as T,Kt as E,Lr as D,Mt as O,Ni as k,O as A,Pn as j,Qi as M,Sn as N,Un as P,V as F,Vi as ee,Vn as te,W as ne,Wn as re,Yn as I,Z as ie,Zi as L,Zr as ae,_r as oe,ar as R,br as se,bt as ce,ci as z,cr as le,ct as ue,da as de,dt as fe,ei as pe,ha as me,hr as he,ht as B,jn as ge,or as _e,ot as ve,q as ye,r as be,sa as xe,sn as Se,t as Ce,ui as V,un as we,ur as Te,ut as H,vr as Ee,wn as De,wt as Oe,xa as ke,z as Ae}from"./player-overlays-nsKWep_b.js";import{Ai as je,Ci as Me,Gn as Ne,Ii as Pe,In as Fe,Ji as U,Jn as Ie,Ki as Le,Kn as Re,Ln as ze,Mo as W,No as G,Nr as Be,Qi as Ve,To as He,Vi as Ue,Vn as We,Wn as Ge,Xi as Ke,Xn as qe,Ya as Je,Zi as Ye,_s as Xe,aa as Ze,an as Qe,bo as $e,ea as et,en as tt,fo as nt,go as rt,hr as it,ia as at,in as ot,jo as st,ka as ct,mr as lt,ms as ut,n as dt,nn as ft,nr as pt,oa as mt,on as ht,p as gt,pa as _t,pr as vt,qn as yt,rn as bt,rr as xt,sn as St,ta as Ct,tn as wt,tr as Tt,xa as Et,xr as Dt,ys as Ot}from"./client-wsT1qo5a.js";import{N as kt,O as At,v as jt}from"./__vite-browser-external-BCAtXlNQ.js";import{t as Mt}from"./archive-Djs_JYv3.js";import{a as Nt,c as Pt,i as Ft,n as It,o as Lt,r as Rt,s as zt,t as Bt}from"./tv-DXjaCKCw.js";import{t as Vt}from"./bell-off-Ct98laYU.js";import{r as Ht,t as Ut}from"./sigma-CGh2ukye.js";import{t as Wt}from"./boxes-B29vzWV6.js";import{n as Gt}from"./video-CUSTu3rp.js";import{t as Kt}from"./circle-slash-JQ7haXmS.js";import{t as qt}from"./file-up-BY1FyH2Q.js";import{t as Jt}from"./layers-B5Q59zGJ.js";import{$s as Yt,$t as Xt,Ac as Zt,Af as Qt,Al as $t,Br as en,Bs as tn,Cf as nn,Cl as rn,Cs as an,Cu as on,Df as sn,Di as K,Do as cn,Dt as ln,Ed as un,El as dn,Fi as fn,Fl as pn,Fn as mn,Fr as hn,Ft as q,Fu as gn,Gl as _n,Go as vn,Gr as yn,Hi as bn,Hn as xn,Ho as Sn,Hr as Cn,Hs as wn,Ii as Tn,Ir as En,It as Dn,Iu as On,Jl as kn,Jn as An,Jt as jn,Ki as Mn,Kl as Nn,Ko as Pn,Kr as Fn,Kt as In,Ln,Lo as Rn,Lr as zn,Lt as Bn,Lu as Vn,Mn as Hn,Mu as Un,Ni as Wn,Nt as Gn,Nu as Kn,Oa as qn,Pi as Jn,Pr as Yn,Qa as Xn,Qt as Zn,Rn as Qn,Ro as $n,Rr as er,Ru as tr,Sf as nr,Sl as rr,Ss as ir,Su as ar,Tn as or,Ui as sr,Uo as cr,Ur as lr,Vc as ur,Vi as dr,Vo as fr,Vr as pr,Vs as mr,Wo as hr,Wt as gr,Xn as _r,Xr as vr,Xt as yr,Y as br,Yc as xr,Yl as Sr,Yn as Cr,Yr as J,Yt as wr,Zc as Tr,Zo as Er,Zr as Dr,Zs as Or,_ as kr,_n as Ar,_o as jr,_s as Mr,_t as Nr,af as Pr,ai as Fr,an as Ir,ar as Lr,bu as Rr,cf as Y,cn as zr,ct as Br,df as Vr,di as Hr,dn as Ur,ec as Wr,es as Gr,f as Kr,fa as qr,ff as Jr,fo as Yr,ft as Xr,g as Zr,gi as Qr,gn as $r,go as ei,gt as ti,ho as ni,hr as ri,ht as ii,if as ai,ii as oi,in as si,io as ci,iu as li,jn as ui,jo as di,kc as fi,kf as pi,l as mi,lf as hi,ln as gi,lr as _i,lt as vi,mf as yi,ml as bi,mr as xi,nn as Si,no as Ci,o as wi,of as Ti,oi as Ei,on as Di,oo as Oi,or as ki,po as Ai,pt as ji,ql as Mi,qn as Ni,qo as Pi,r as Fi,ri as Ii,rs as Li,s as Ri,sf as zi,si as Bi,tc as Vi,tn as Hi,to as Ui,u as Wi,uf as Gi,un as Ki,uo as qi,ur as Ji,vn as Yi,vt as Xi,wf as Zi,wl as Qi,xu as $i,y as ea,yi as X,ys as ta,yt as na,yu as ra,zi as ia,zn as aa,zr as oa}from"./src-C8Zf9Q7y.js";import{t as Z}from"./i18n-DFz3VmFc.js";import{t as Q}from"./useTranslation-BJr-n0es.js";import"./mount-DOA_AHBE.js";import{A as sa,B as ca,Br as la,D as ua,Fr as da,G as fa,H as pa,I as ma,L as ha,M as ga,O as _a,Pr as va,R as ya,Rr as ba,U as xa,V as Sa,W as Ca,b as wa,j as Ta,k as Ea,p as Da,z as Oa,zr as ka}from"./index-0zF1qyaf.js";import{n as Aa,t as ja}from"./format-DAm6he6w.js";import{T as Ma,n as Na,r as Pa,s as Fa,t as Ia}from"./create-composition-BjzhtLA0.js";import{$ as La,A as Ra,B as za,Ct as Ba,D as Va,E as Ha,F as Ua,G as Wa,H as Ga,I as Ka,J as qa,K as Ja,L as Ya,M as Xa,N as Za,O as Qa,P as $a,Q as eo,R as to,S as no,St as ro,T as io,U as ao,V as oo,W as so,X as co,Y as lo,Z as uo,_ as fo,_t as po,at as mo,b as ho,bt as go,c as _o,ct as vo,d as yo,dt as bo,et as xo,f as So,ft as Co,gt as wo,h as To,ht as Eo,it as Do,j as Oo,k as ko,l as Ao,lt as jo,m as Mo,mt as No,nt as Po,ot as Fo,p as Io,pt as Lo,q as Ro,rt as zo,s as Bo,st as Vo,tt as Ho,u as Uo,ut as Wo,v as Go,vt as Ko,wt as qo,x as Jo,xt as Yo,yt as Xo,z as Zo}from"./CompositionBlockEditor-DKBOCxVr.js";import{t as Qo}from"./assignment-candidates-CmqGReT0.js";import{_ as $o,b as es,i as ts,m as ns,o as rs,t as is}from"./step-inspector-model-DeHccH5q.js";import"./useEventInvalidation-DOA_AHBE.js";import{_ as as,a as os,b as ss,i as cs,o as ls,r as us,t as ds}from"./EditTemplateButton-CDWvPMbz.js";import{t as fs}from"./use-stationary-objects-Bx6JK5H8.js";import{a as ps}from"./notification-rule-status-hT9lSvAp.js";import{a as ms,c as hs,i as gs,l as _s,n as vs,o as ys,r as bs,s as xs,t as Ss,u as Cs}from"./linked-devices-model-DdQpLGk3.js";import{t as ws}from"./authed-media-BpqhukLe.js";c();function Ts(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 Es(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(Ts).filter(e=>e!==null);return n.length===0?null:n}var Ds=[[/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 Os(e){for(let[t,n]of Ds)if(t.test(e))return n;return`generic`}function ks(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(Z.t(`helpers.cameraSwitchRows.off`,{list:r(t)})),n.length>0&&i.push(Z.t(`helpers.cameraSwitchRows.unknown`,{list:r(n)})),{offIds:t,unknownIds:n,summary:i.length===0?Z.t(`helpers.cameraSwitchRows.allOn`):i.join(` · `)}}var As={stream:x,detection:It,privacy:p,microphone:Te,speaker:O,listening:Lt,archive:Mt,recording:zt,notifications:L,generic:we};function js({deviceId:t}){let{t:n}=Q(),a=l(),s=Number.isFinite(t),[c,u]=o(null),[d,f]=o(!1),p=dn({deviceId:t},{enabled:s});wi([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=Es(p.data),h=Sr({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 _=ks(m),v=e=>c?.id===e.id?c.message:null;return e(Gi,{open:d,onOpenChange:f,children:[e(Jr,{"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(we,{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(Vr,{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(Ms,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function Ms({row:t,failure:n,onToggle:r}){let{t:a}=Q(),o=As[Os(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(X,{variant:`unstyled`,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 Ns({deviceId:t}){let n=Hi(B().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(pe,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:n.label})]})}function Ps({parentDeviceId:t}){let{t:n}=Q(),r=ba(),a=B(),{data:o,isLoading:s,isError:c}=Sa(t),{data:l}=fr({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=yr(l?.stableId??``,u,l?.childLayout),f=d.ungrouped,p=e=>r(`/devices/${String(e)}`),m=l?.name??``,h=(e,t)=>i(jn,{trpc:a.trpcClient,device:{...t,name:Si(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(wr,{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(wr,{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 Fs({deviceId:e}){let t=B(),{data:n,isLoading:r}=ca(e),{data:a,isLoading:o}=Sa(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(si,{trpc:t.trpcClient,children:c,linkDeviceId:l,primaryChildEntityId:u})})}c();function Is({deviceId:t,button:n,sources:r,current:a,placement:s}){let{t:c}=Q(),l=Vn(),[u,f]=o(!1),[p,m]=o(null);if(r.length===0)return null;let h=a===``?c(`remote.sourceSelect.label`):a,g=r.filter(e=>e.kind===`digits`),_=r.filter(e=>e.kind!==`digits`),v=async e=>{m(null);try{let n=await l.mutateAsync({deviceId:t,command:`selectSource`,source:e.name,repeat:1});if(n.status===`refused`){m(c(`remote.test.refused.${n.reason}`,{detail:n.detail??``}));return}if(n.status===`not-routed`){m(c(`remote.sourceSelect.notRouted`));return}f(!1)}catch(e){m(e instanceof Error?e.message:String(e))}};return e(d,{children:[e(X,{type:`button`,size:`sm`,variant:`secondary`,"aria-label":h,title:h,"data-testid":`remote-grid-button-${n.id}`,"data-widget":`source_select`,className:fe(`z-10 h-full min-w-0 overflow-hidden border border-border px-2`,cs(n.shape),os(n.tone)),style:s,onClick:()=>{m(null),f(!0)},children:[i(Bt,{className:`h-4 w-4 shrink-0`,"aria-hidden":!0}),i(`span`,{className:`min-w-0 truncate text-xs`,children:h})]}),u&&i(hn,{open:!0,onOpenChange:e=>!e&&f(!1),children:e(zn,{width:`sm`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(en,{children:i(pr,{children:c(`remote.sourceSelect.title`)})}),e(En,{className:`space-y-3`,"data-testid":`source-picker`,children:[i(Ls,{title:c(`remote.sourceSelect.channels`),sources:g,current:a,busy:l.isPending,onPick:e=>void v(e)}),i(Ls,{title:c(`remote.sourceSelect.inputs`),sources:_,current:a,busy:l.isPending,onPick:e=>void v(e)}),p!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger`,"data-testid":`source-picker-failure`,children:p})]})]})})]})}function Ls({title:t,sources:n,current:r,busy:a,onPick:o}){return n.length===0?null:e(`section`,{className:`space-y-1`,children:[i(`h3`,{className:`text-xs font-medium uppercase tracking-wide text-foreground-muted`,children:t}),i(`ul`,{className:`space-y-1`,children:n.map(t=>i(`li`,{children:e(X,{type:`button`,variant:t.name===r?`secondary`:`ghost`,size:`sm`,disabled:a,className:`w-full justify-start gap-2`,"data-testid":`source-pick-${t.id}`,onClick:()=>o(t),children:[t.kind===`digits`&&i(`span`,{className:`w-10 shrink-0 text-right tabular-nums text-foreground-muted`,children:t.number}),i(`span`,{className:`min-w-0 truncate`,children:t.name})]})},t.id))})]})}c();function Rs({deviceId:t,deviceName:n}){let{t:r}=Q(),a=Dr(`remote`),s=gn({deviceId:t},{enabled:a===`present`}),[c,l]=o(!1);return a!==`present`||(s.data?.commands.length??0)===0&&(s.data?.sources.length??0)===0?null:e(`div`,{className:`flex flex-wrap items-center justify-center gap-1`,children:[e(X,{size:`sm`,variant:`outline`,onClick:()=>l(!0),"data-testid":`hero-remote`,children:[i(Fi,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),r(`remote.hero.open`)]}),c&&i(zs,{deviceId:t,deviceName:n,onClose:()=>l(!1)})]})}function zs({deviceId:t,deviceName:n,onClose:r}){let{t:a}=Q(),s=Kn({deviceId:t}),c=un({kind:`remote`}),l=gn({deviceId:t}),u=On(),d=Un({deviceId:t}),[f,p]=o(null),m=s.data?.layoutTemplateId??null,h=(c.data??[]).find(e=>e.id===m),g=h===void 0?null:ss(h.payload),_=new Set((l.data?.commands??[]).map(e=>e.role)),v=async e=>{let n=g?.buttons.find(t=>t.id===e)?.role;if(!(n===void 0||!_.has(n))){p(null);try{let e=await u.mutateAsync({deviceId:t,role:n,repeat:1});e.status===`refused`&&p(a(`remote.test.refused.${e.reason}`,{detail:e.detail??``}))}catch(e){p(e instanceof Error?e.message:String(e))}}};return i(hn,{open:!0,onOpenChange:e=>!e&&r(),children:e(zn,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(en,{children:i(pr,{children:a(`remote.hero.title`,{name:n})})}),e(En,{className:`space-y-3`,children:[s.status===`error`?i(J,{title:a(`remote.dialog.unreadable`),message:s.error?.message??``,onRetry:()=>void s.refetch()}):g===null?i(`p`,{className:`text-xs text-foreground-muted`,children:a(`remote.hero.noLayout`)}):i(`div`,{className:`mx-auto w-full max-w-xs`,"data-testid":`remote-press`,children:i(us,{grid:g,label:a(`remote.hero.title`,{name:n}),boundRoles:_,onSelect:e=>void v(e),renderWidget:(e,n)=>i(Is,{deviceId:t,button:e,sources:l.data?.sources??[],current:d.data?.source??``,placement:n})})}),f!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger`,children:f})]})]})})}c();function Bs({dev:t,busy:n,setBusy:r}){let{t:a}=Q(),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(X,{variant:`unstyled`,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(me,{className:`h-3 w-3`}),i(`span`,{children:m})]})}c();function $({deviceId:t,deviceName:n,deviceType:r,features:a}){let s=B(),c=zr(r)?.HeroCard??gi,l=T(s.trpcClient,t),u=w(l?.state.deviceStatus),[d,f]=o(!1),p=u!==void 0&&u.online===!1,m=p?u.lastChangedAt:null;return e(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[p?i(`div`,{className:`flex justify-center`,children:i(Di,{lastChangedAt:m})}):null,i(c,{trpc:s.trpcClient,deviceId:t,features:a}),r===G.MediaPlayer?i(Rs,{deviceId:t,deviceName:n}):null,i(`div`,{className:`flex justify-center`,children:i(Bs,{dev:l,busy:d,setBusy:f})})]})}function Vs({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(Ki,{trpc:B().trpcClient,deviceId:e,features:t})})}function Hs({deviceId:e}){let{t}=Q(),n=Rr({deviceId:e},{staleTime:15e3}).data;if(n===void 0||n.linked!==!0||n.switchOn===null)return i(d,{});let r=n.switchOn===!0?t(`deviceHero.powerLine.on`,`Power switch on`):t(`deviceHero.powerLine.off`,`Power switch off`);return i(`p`,{className:`px-3 pt-1 text-[11px] text-foreground-muted sm:px-4`,children:n.switchName===null||n.switchName===``?r:t(`deviceHero.powerLine.withName`,`{{state}} · {{name}}`,{state:r,name:n.switchName})})}function Us({deviceId:e,features:t}){return i(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:i(gi,{trpc:B().trpcClient,deviceId:e,features:t})})}function Ws(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Gs(e){if(!e)return null;let t=Ws(e.data);return t===null?e.eventType:Z.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var Ks=1e3,qs=60*Ks,Js=60*qs,Ys=24*Js;function Xs(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Ks?Z.t(`helpers.relativeTime.justNow`):n<qs?Z.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/Ks)}):n<Js?Z.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/qs)}):n<Ys?Z.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/Js)}):Z.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Ys)})}c();var Zs=1500,Qs=15e3,$s=1e3;function ec({deviceId:n}){let{t:r}=Q(),s=T(B().trpcClient,n)?.state.eventEmitter,c=w(s);a(()=>{if(!s)return;s.refresh();let e=setInterval(()=>{s.refresh()},Qs);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)},Zs);return()=>{clearTimeout(t)}},[u]);let[m,h]=o(()=>Date.now());a(()=>{let e=setInterval(()=>{h(Date.now())},$s);return()=>{clearInterval(e)}},[]);let g=Gs(l),_=c?.eventTypes??[],v=c?.eventCountSinceStart??0,y=c!==void 0,b=Ws(l?.data);return e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[i(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(f),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${f?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:g??r(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:i(f?R:D,{className:`h-10 w-10`})}),e(`div`,{className:`text-center`,children:[b!==null&&i(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:r(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(b)})}),i(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${g?`text-foreground`:`text-foreground-subtle`}`,children:g??(y?r(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):r(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),i(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:l?Xs(l.timestamp,m):r(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),_.length>0&&i(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:_.map(e=>i(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===l?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),i(`div`,{className:`text-[10px] text-foreground-subtle`,children:r(`hero.eventEmitterHero.sinceStart`,{count:v})})]})}function tc({deviceName:t,deviceType:n,provider:r,isOnline:a,features:o}){let{t:s}=Q();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(Ca,{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(Xi,{status:a?`online`:`offline`}),o.length>0&&i(fa,{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 nc({deviceId:t}){let{t:r}=Q(),a=l(),o=Yr({deviceId:t},{refetchInterval:1e4,retry:!1}),s=Ai({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),a.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),c=n(()=>rc(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(ic,{label:r(`hero.hubHero.discovered`,`Discovered`),value:c.total,icon:i(f,{className:`h-3.5 w-3.5`})}),i(ic,{label:r(`hero.hubHero.adopted`,`Adopted`),value:c.adopted,accent:`success`}),i(ic,{label:r(`hero.hubHero.available`,`Available`),value:c.available,accent:c.available>0?`primary`:void 0}),e(X,{variant:`unstyled`,type:`button`,onClick:()=>{s.mutateAsync({deviceId:t}).catch(()=>{})},disabled:s.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[s.isPending?i(se,{className:`h-3.5 w-3.5 animate-spin`}):i(j,{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(ac,{icon:i(Oe,{className:`h-3 w-3 text-emerald-500`}),label:r(`hero.hubHero.online`,`{{online}} online`,{online:c.online})}),i(ac,{icon:i(_e,{className:`h-3 w-3 text-amber-500`}),label:r(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:c.sleeping})}),i(ac,{icon:i(b,{className:`h-3 w-3 text-destructive`}),label:r(`hero.hubHero.offline`,`{{offline}} offline`,{offline:c.offline})}),c.unknown>0?i(ac,{icon:i(g,{className:`h-3 w-3 text-foreground-subtle`}),label:r(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:c.unknown})}):null]})]})}function rc(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 ic({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 ac({icon:t,label:n}){return e(`span`,{className:`inline-flex items-center gap-1`,children:[t,i(`span`,{children:n})]})}var oc={[G.Switch]:$,[G.Siren]:$,[G.Light]:$,[G.Sensor]:$,[G.Button]:$,[G.Hub]:nc,[G.Cover]:Vs,[G.Valve]:$,[G.Humidifier]:$,[G.WaterHeater]:$,[G.Heater]:$,[G.Container]:Fs,[G.Lock]:$,[G.Fan]:$,[G.Thermostat]:$,[G.Climate]:$,[G.MediaPlayer]:$,[G.Control]:$,[G.AlarmPanel]:$,[G.EventEmitter]:ec,[G.Notifier]:Us,[G.Script]:$,[G.Automation]:$,[G.Presence]:$,[G.Update]:$,[G.Vacuum]:$,[G.LawnMower]:$,[G.Weather]:$,[G.Image]:$,[G.PetFeeder]:$,[G.PetFountain]:$,[G.Dishwasher]:$,[G.Washer]:$,[G.Dryer]:$};function sc(e){return oc[e]??tc}function cc({deviceId:e}){let t=ye(B().trpcClient,e,e=>e.runningState);if(t===void 0||t.running!==!0&&t.running!==!1)return i(d,{});let n=t.running;return i(Cr,{running:n,since:t?.since??null,phase:t?.phase??null,className:`px-3 pt-2 sm:px-4`})}function lc(t){let n=sc(t.deviceType);return e(d,{children:[i(cc,{deviceId:t.deviceId}),i(Hs,{deviceId:t.deviceId}),i(n,{...t})]})}var uc={[G.Sensor]:[`host/power-meter-line`]};function dc(e){let t=Object.values(G).find(t=>t===e);return t===void 0?[]:uc[t]??[]}function fc({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(Yn,{widgetId:t.widgetId,deviceId:t.deviceId});return i(`div`,{children:t.deviceId===e?n:i(Qr,{deviceId:t.deviceId,children:n})},t.widgetId)})})}function pc(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 mc(e){let t=new Set(e.drawnByHero??[]),n=pc(e).filter(e=>!t.has(e.widgetId)),r=new Set(n.map(e=>e.widgetId)),i=e.child===void 0?[]:pc(e.child),a=[...n,...i.filter(e=>!r.has(e.widgetId))],o=new Set;return a.filter(e=>o.has(e.widgetId)?!1:(o.add(e.widgetId),!0)).sort((e,t)=>e.order-t.order)}function hc(e){return Wi(B().trpcClient,e)}c();function gc(e){let[n,i]=o(`idle`),[s,c]=o(null),l=t(null),u=t(null),d=t(null),f=t(!0),p=Wr(),m=Yt(),h=Vi(),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 _c=0;function vc(){return++_c}function yc(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function bc(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 xc(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 Sc(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 Cc({scope:n,greeting:s,className:c}){let{t:l}=Q(),d=B(),[f,p]=o(()=>{let e=[];return s&&e.push({id:vc(),kind:`info`,text:s}),e.push({id:vc(),kind:`info`,text:`scope: ${yc(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:vc(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);p(e=>[...e,{id:vc(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){p([{id:vc(),kind:`info`,text:`scope: ${yc(n)}`}]),h(``);return}if(t===`help`){p(e=>[...e,{id:vc(),kind:`input`,text:`> ${t}`},...bc(n).map(e=>({id:vc(),kind:`info`,text:e}))]),h(``);return}if(t===`context`){p(e=>[...e,{id:vc(),kind:`input`,text:`> ${t}`},...Sc(n).map(e=>({id:vc(),kind:`info`,text:e}))]),h(``);return}if(t===`examples`){p(e=>[...e,{id:vc(),kind:`input`,text:`> ${t}`},...xc(n).map(e=>({id:vc(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,t]),y(-1),p(e=>[...e,{id:vc(),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:vc(),kind:`info`,text:`scope: ${yc(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(zi,{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 wc(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 Tc({deviceId:e,intercomAvailable:t=!1}){let r=B(),a=typeof window<`u`?ie():``,o=Number.isFinite(e),s=hc(o?e:null),c=fs(o?[e]:[]),l=n(()=>{if(!o)return;let e=[];for(let t of c.rows){let n=mi(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:y,getSessionState:b,applyDownlinkProbe:x}=mn(r.trpcClient,o?e:null),C=S(o?e:null,{width:Ac}),w=gc(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=be(),k=Fn(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=wc(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(Br,{serverUrl:a,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:_,getIceCandidates:v,closeSession:y,getSessionState:b,applyDownlinkProbe:x,...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 Ec({deviceId:e,containerDeviceId:t}){let{t:n}=Q();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full`,children:i(Yi,{...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 Dc({deviceId:e}){let{t}=Q();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
2
  `);return i(Cc,{scope:{type:`device`,deviceId:e},greeting:n,className:`h-full border-0 rounded-none`})}function Oc({deviceId:e}){let{t}=Q();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:i(Ar,{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 kc({deviceId:e}){let{t}=Q();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:i($r,{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 Ac=960;function jc({initialName:e,label:t=`Name`,layout:n=`inline`,bound:r}){return i(xa,{label:t,layout:n,value:i(zi,{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 Mc({label:t=`Location`,layout:r=`inline`,bound:a}){let{t:o}=Q(),{data:s}=Er(),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(xa,{label:t,layout:r,value:e(`div`,{className:`relative`,children:[i(zi,{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(he,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),i(`span`,{className:`truncate`,children:t})]},t))})]})})}var Nc=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary disabled:opacity-50 disabled:cursor-not-allowed`,Pc=0,Fc=10;function Ic(e){if(e.trim()===``)return``;let t=Number.parseInt(e,10);return Number.isFinite(t)?String(t<Pc?Pc:t>Fc?Fc:t):``}function Lc({value:e,onChange:t,disabled:n=!1,placeholder:r,className:a,id:o,"aria-label":s}){return i(zi,{type:`number`,min:Pc,max:Fc,step:1,id:o,className:a??Nc,"aria-label":s,placeholder:r,value:e,onChange:e=>{t(Ic(e.target.value))},disabled:n})}function Rc({deviceName:t,value:n,inheritedIcon:r,inheritedLabel:a,disabled:o,onChange:s}){let{t:c}=Q(),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(hi,{value:n===``?null:n,onPick:e=>s(e??``),categoryLabel:e=>c(`deviceDisplay.iconCategory.${e}`,{defaultValue:He(e)}),fallbackGlyph:r,labels:l,disabled:o}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n===``?a:n})]})}var zc=`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 Bc(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function Vc({device:t,role:n,display:r,onChange:a}){let o=ke();Zi();let{t:s}=Q(),c=l(),u=n===null?void 0:Ur[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:ut(h),_=g===void 0?void 0:nt(g),{data:v}=cr({},{staleTime:6e4,enabled:n!==null}),y=Mr({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),b=()=>{if(n===null)return;let e=Bc(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:nr(x),C=n===null?pi(t.type,o):sn(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?``:sn(n,o).label;return e(`div`,{className:`mt-3 divide-y divide-border border-t border-border`,children:[i(xa,{label:s(`deviceDisplay.icon`),value:i(Rc,{deviceName:t.name,value:r.icon,inheritedIcon:w.icon,inheritedLabel:T,disabled:!1,onChange:e=>a({icon:e})})}),p&&i(xa,{label:s(`deviceDisplay.label`),value:i(zi,{type:`text`,className:zc,"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(xa,{label:s(`deviceDisplay.unit`),value:i(br,{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(xa,{label:s(`deviceDisplay.precision`),value:i(Lc,{"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(X,{type:`button`,variant:`outline`,size:`sm`,onClick:b,disabled:y.isPending,title:s(`deviceDisplay.setRoleDefaultTitle`,{role:E}),children:s(`deviceDisplay.setRoleDefault`,{role:E})})})]})}function Hc(e){return typeof e.linkDeviceId==`number`}var Uc=new Set(Object.values(W));function Wc(e){return Uc.has(e)}var Gc={[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 Kc(e){for(let t of Object.values(G))if(t===e)return!0;return!1}function qc(e){return Kc(e)?Gc[e]??[]:[]}function Jc(e,t){let n=qc(t);return e==null||e===``||n.includes(e)?n:[...n,e]}function Yc({device:t}){let{t:n}=Q(),r=ke(),a=ya(),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:`${A} ${v}`,children:[e(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[d?i(jc,{deviceId:t.id,initialName:s,label:n(`customize.identity.name`),layout:`stacked`,bound:{value:s,onChange:a.setIdentityName}}):i(xa,{label:n(`customize.identity.name`),layout:`stacked`,value:s}),d?i(Mc,{deviceId:t.id,initialLocation:c,label:n(`customize.identity.room`),layout:`stacked`,bound:{value:c,onChange:a.setIdentityLocation}}):i(xa,{label:n(`customize.identity.room`),layout:`stacked`,value:c===``?n(`common.unset`):c}),i(xa,{label:n(`customize.identity.type`),layout:`stacked`,value:t.type}),i(xa,{label:n(`customize.identity.hidden`),layout:`stacked`,value:i(Ji,{"aria-label":n(`deviceDisplay.hideFromLists`),checked:u,disabled:!d,onChange:e=>a?.setIdentityDisplay({hidden:e.target.checked})})}),i(xa,{label:n(`customize.identity.role`),layout:`stacked`,value:Hc(t)||!d?i(`span`,{children:Xc(l,n(`customize.identity.noRole`),r)}):i(H,{"aria-label":n(`customize.identity.role`),value:l??``,options:[{value:``,label:n(`customize.identity.noRole`)},...Jc(l,t.type).map(e=>({value:e,label:Xc(e,n(`customize.identity.noRole`),r)}))],onChange:e=>a.setIdentityRole(e.target.value===``?null:e.target.value)})})]}),o!==null&&a!==null&&i(Vc,{device:t,role:l,display:o.display,onChange:a.setIdentityDisplay})]})}function Xc(e,t,n){return e==null||e===``?t:Wc(e)?sn(e,n).label:e}var Zc=`running-state`,Qc=`running`;function $c(e){return{...e,features:e.features.filter(e=>e.cap!==Zc)}}function el(e,t){return e===Zc&&t===Qc}function tl(e){if(e===null||!Tt($c(e)))return{offered:!1};let t=Ja(e,Zc);return t===null?{offered:!0,following:!0,discardsRule:!1}:{offered:!0,following:!1,discardsRule:!pt(t)}}function nl(e,t){return t?co(e,Zc):{...$c(e),features:[...$c(e).features,xt()]}}function rl(e,t,n){return el(e,t)&&tl(n).offered}var il=`Assigned · `;function al(e,t){if(e===`Native`)return{kind:`native`};if(e===`Native · source missing`)return{kind:`released`};if(e===`pending`)return{kind:`pending`};if(e===`unknown`)return{kind:`unknown`};if(e.startsWith(il)){let n=e.slice(11);return{kind:`assigned`,source:t??n}}return{kind:`unknown`}}var ol={id:0,name:``,type:`unknown`,stableId:``,parentDeviceId:null};function sl(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 cl(e,t,n){let r=Ja(xo(e.state),t);return pt(r)?null:Ne(r,t,n)}function ll(e,t,n){return e?t===`pending`?`pending`:t===`unknown`?`unknown`:n?`present`:`absent`:`present`}function ul(e,t,n,r){let i=e(`customize.scalar.caps.${n}`);return Ge(n)<=1?i:`${i} · ${Wo(n,r.path??r.id,t)}`}function dl(e,t,n,r){let{t:i,i18n:a}=Q(),o=Wa(),s=r.path??r.id,c=ul(i,a.language,n,r),l=xo(t.state),u=sl(t,cl(t,n,r.id)),d=u.kind===`known`&&u.value!==null?We({feature:u.value,device:t.target,cap:n,targetId:r.id}):null,f=d!==null,p=Po(f),m=d===null||p.kind!==`known`?null:p.value.find(e=>Et({addonId:e.addonId,stableId:e.stableId})===Et(d.draft.source))??null,h=Fr(m===null?ol:Vo(m),`compact`),g=m===null?null:h,_=Fr(e,`full`),v=ll(f,p.kind,m!==null),y=ht({cap:n,targetId:r.id,device:t.target,stored:u,sourcePresence:v,sourceUnknownReason:p.kind===`unknown`?p.reason:null}),b=async e=>{let n=await t.save(e);return n.kind===`refused`?n.reason:null},x=async()=>{if(l===null)return null;let e=uo(l,n,r.id);return await o(i(`customize.scalar.removeWhat`,{name:g??(d===null?_:Et(d.draft.source))}),e===null)?b(e):null},S=d===null?null:{source:{addonId:d.draft.source.addonId,stableId:d.draft.source.stableId,cap:d.draft.source.cap,fieldPath:d.draft.source.fieldPath,valueKind:d.sourceValueKind,sourceUnit:d.sourceUnit,changedAtField:d.changedAtField},transform:d.draft.transform};return{title:c,path:s,stored:u,recognized:f,otherFormula:!f&&u.kind===`known`&&u.value!==null,presence:v,released:y.status.state===`released`,badge:al(y.text,g),sourceName:g,sourceCap:d?.draft.source.cap??``,sourcePath:d?.draft.source.fieldPath??``,sourceField:d===null?``:Wo(d.draft.source.cap,d.draft.source.fieldPath,a.language),sourceDeviceId:m?.id??null,seed:S,answered:t.state.kind===`none`||t.state.kind===`present`,saving:t.saving,saveFeature:e=>b(lo(l,t.target,e,n,r.id)),remove:x}}var fl=U,pl=[`power`,`readings`,`events`,`lists`,`extensions`],ml=new Set([`power-meter`,`power-source`,`battery`]),hl={scalar:`scalar`,keyedArray:`keyed`,event:`event`,config:`config`};function gl(e,t){if(ml.has(e))return`power`;switch(t){case`scalar`:return`readings`;case`event`:return`events`;case`keyed`:return`lists`;case`config`:return`extensions`}}function _l(e){let t=[];for(let[n,r]of Object.entries(fl))for(let i of r.targets){let r=hl[i.cardinality];i.deviceTypes.includes(e)&&t.push({key:`${n}.${i.id}`,cap:n,kind:r,section:gl(n,r),target:i})}return t.toSorted((e,t)=>pl.indexOf(e.section)-pl.indexOf(t.section))}function vl(e,t,n){return e.map(e=>{if(e.kind===`config`)return{spec:e,availability:{kind:`present`,mode:`add`},linked:!0};let r=$a(Ka(e.cap,e.target),t),i=n(e);return e.kind===`keyed`&&r.kind===`absent`&&i?{spec:e,availability:{kind:`present`,mode:`add`},linked:i}:{spec:e,availability:r,linked:i}})}function yl(e){let t=[],n=[],r=!1,i=null;for(let a of e)switch(a.availability.kind){case`absent`:break;case`pending`:r=!0;break;case`unknown`:i=a.availability.reason;break;case`present`:a.linked?t.push(a):n.push(a)}return{active:t,addable:n,pending:r,unknownReason:i}}function bl(e){return pl.filter(t=>e.some(e=>e.spec.section===t))}c();function xl({children:e,muted:t}){return i(`span`,{className:`text-xs ${t===!0?`text-foreground-subtle`:`text-foreground`}`,children:e})}function Sl(){let{t:e}=Q();return i(`span`,{role:`status`,className:`text-xs text-foreground-subtle`,children:e(`customize.event.checking`)})}function Cl({reason:e}){let{t}=Q();return i(`span`,{role:`alert`,className:`text-xs text-warning`,title:e??void 0,children:t(`customize.table.unknown`)})}function wl(e){switch(e.spec.cap){case`remote`:return i(El,{device:e.device});case`fan-presets`:return i(Ol,{device:e.device});default:return i(Cl,{reason:null})}}function Tl(e){switch(e.spec.cap){case`remote`:return i(Dl,{device:e.device});case`fan-presets`:return i(jl,{device:e.device});default:return i(Cl,{reason:null})}}function El({device:e}){let{t}=Q(),n=Kn({deviceId:e.id});if(n.status===`error`)return i(Cl,{reason:n.error?.message??null});if(n.data===void 0)return i(Sl,{});let r=Object.keys(n.data.bindings).length;return r===0&&n.data.layoutTemplateId==null?i(xl,{muted:!0,children:t(`customize.table.notConfigured`)}):i(xl,{children:t(`customize.table.commandsCount`,{count:r})})}function Dl({device:e}){let{t}=Q(),n=Kn({deviceId:e.id}),r=un({kind:`remote`});if(n.status===`error`)return i(Cl,{reason:n.error?.message??null});if(n.data===void 0)return i(Sl,{});let a=n.data.layoutTemplateId;if(a==null)return i(xl,{muted:!0,children:t(`remote.dialog.noTemplate`)});if(r.status===`error`)return i(Cl,{reason:r.error?.message??null});let o=(r.data??[]).find(e=>e.id===a)?.name??null;return r.data===void 0?i(Sl,{}):o===null?i(Cl,{reason:null}):i(xl,{children:o})}function Ol({device:e}){let{t}=Q(),n=mr({deviceId:e.id});return n.status===`error`?i(Cl,{reason:n.error?.message??null}):n.data===void 0?i(Sl,{}):n.data.length===0?i(xl,{muted:!0,children:t(`customize.table.noPresets`)}):i(xl,{children:t(`customize.table.presetsCount`,{count:n.data.length})})}function kl(e){let t=new Set;for(let n of e)for(let e of n.steps)Al(e,t);return[...t]}function Al(e,t){if(e.kind!==`cap`)return;let{target:n}=Je(e);if(n.kind===`devices`)for(let e of n.ids)t.add(e)}function jl({device:e}){let{t}=Q(),r=mr({deviceId:e.id}),a=vn({projection:`slim`}),o=n(()=>{if(r.data===void 0||a.data===void 0)return null;let e=new Map(a.data.map(e=>[e.id,e.name]));return kl(r.data).map(t=>e.get(t)??`#${t}`)},[r.data,a.data]);return r.status===`error`?i(Cl,{reason:r.error?.message??null}):r.data===void 0?i(Sl,{}):r.data.length===0?i(xl,{muted:!0,children:t(`customize.table.noSource`)}):a.status===`error`?i(Cl,{reason:a.error?.message??null}):o===null?i(Sl,{}):i(xl,{children:o.join(`, `)})}function Ml(e){let t=yt({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 Nl(e){let t=Ie({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 Pl(e,t){return{deviceId:e,config:t.config}}function Fl(e,t){return{deviceId:e,patch:{motionCooldownMs:t}}}async function Il(e,t,n,r){await n(Pl(e,t)),await r(Fl(e,t.timeoutMs))}c();function Ll(t){let{t:n}=Q(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(hn,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(zn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(en,{children:i(pr,{children:r})}),t.open?i(Rl,{...t}):null]})})}function Rl(t){let{t:r}=Q(),a=vn({projection:`slim`}),s=Fo(n(()=>a.status===`success`?qo(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>zl(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=Bl(c),b=y.length===0?null:Ml({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=an({deviceId:c[0]?.deviceId??0}),C=Hl(S.status===`success`?S.data:void 0,x),w=ot(ft,C,Math.round(_*1e3));return e(d,{children:[e(En,{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(mo,{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(Vl(C,w.lastPressedAt))}):null]}),e(oa,{className:`flex flex-wrap gap-2`,children:[i(X,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(X,{"data-testid":`event-save`,disabled:!t.canSave||b===null,onClick:()=>{b!==null&&t.onSave(b)},children:r(`customize.scalar.save`)})]})]})}function zl(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 Bl(e){return e.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,changedAtField:e.changedAtField??$e[e.cap]??`lastChangedAt`}))}function Vl(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 Hl(e,t){if(e===void 0||t===null)return{kind:`unread`};let n=e[t.cap],r=n===void 0?void 0:Ba(n,t.fieldPath),i=$e[t.cap]??t.changedAtField,a=n===void 0?void 0:Ba(n,i);return typeof r==`boolean`?{kind:`level`,active:r,changedAt:typeof a==`number`&&Number.isFinite(a)?a:null}:{kind:`unread`}}function Ul(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=Wl(t,n);return r===null?{kind:`unknown`,seconds:null}:{kind:`active`,seconds:r}}function Wl(e,t){if(e==null||!Number.isFinite(e)||e<ja)return null;let n=Math.floor((t-e)/1e3);return n<0?0:n}function Gl(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>=ja?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 Kl={id:0,name:``,type:`unknown`,stableId:``,parentDeviceId:null};function ql({device:t,handle:n,availability:r,cap:a,title:s,view:c}){let{t:l,i18n:u}=Q(),f=Wa(),[p,m]=o(!1),[h,g]=o(null),_=xo(n.state),v=Ja(_,a),y=Yl(n,v),b=y.kind===`known`&&y.value!==null?Re({feature:y.value,device:n.target,cap:a,targetId:c.id,timestampPath:c.timestampPath,counterPath:c.counterPath}):null,x=b!==null,S=Po(x),C=b?.draft.sources[0]??null,w=C===null||S.kind!==`known`?null:S.value.find(e=>Et({addonId:e.addonId,stableId:e.stableId})===Et(C))??null,T=Xl(x,S.kind,w!==null),E=Fr(w===null?Kl:Vo(w),`compact`),D=Fr(t,`full`),O=tt({cap:a,targetId:c.id,device:n.target,timestampPath:c.timestampPath,counterPath:c.counterPath,apply:c.apply,stored:y,sourcePresence:T,sourceUnknownReason:S.kind===`unknown`?S.reason:null}),k=n.state.kind===`none`||n.state.kind===`present`;if(r.kind===`absent`||!c.deviceTypes.includes(t.type))return null;let A=async e=>{let t=await n.save(e);g(t.kind===`refused`?t.reason:null)},j=Zl(b),N=b?.draft.edges?.[0],P=N!==void 0&&c.edges.includes(N)?N:c.defaultEdge,F=C===null?``:Wo(C.cap,C.fieldPath,u.language),ee=y.kind===`known`&&y.value===null,te=!x&&y.kind===`known`&&y.value!==null;return e(d,{children:[i(Do,{id:a,icon:M,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(Ji,{"aria-label":l(`customize.doorbell.active`),checked:v.enabled!==!1,disabled:!k||n.saving,onChange:e=>{A(qa(_,n.target,{...v,enabled:e.target.checked}))}}),l(`customize.doorbell.active`)]}),i(K,{children:l(Ya(O.text,O.status.state))})]}),children:i(`div`,{className:`flex flex-col gap-2 px-3 py-2 sm:px-4`,children:r.kind===`pending`||r.kind===`present`&&!k?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:l(`customize.event.checking`)}):r.kind===`unknown`?i(J,{title:l(`customize.scalar.unreadable`),message:r.reason}):e(d,{children:[x&&C!==null&&i(`p`,{className:`text-xs text-foreground`,children:l(`customize.scalar.override`,{name:w===null?C.stableId:E,field:F})}),x&&i(Jl,{deviceId:t.id,cap:a,timestampPath:c.timestampPath,counterPath:c.counterPath,startedAt:n.state.kind===`present`?n.state.view.block.createdAt:null}),te&&v!==null&&e(`p`,{className:`text-xs text-foreground flex flex-wrap items-center gap-1`,children:[l(`customize.doorbell.otherFormula`),i(Za,{handle:n,cap:a,fieldPath:c.counterPath})]}),ee&&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(X,{variant:`outline`,size:`sm`,disabled:n.saving,onClick:()=>m(!0),children:l(`customize.scalar.change`)}),x&&i(X,{variant:`ghost`,size:`sm`,disabled:n.saving,onClick:()=>{if(_===null)return;let e=co(_,a);f(l(`customize.doorbell.removeWhat`,{name:w===null?D:E}),e===null).then(t=>{t&&A(e)})},children:l(`customize.scalar.remove`)}),ee&&i(X,{variant:`outline`,size:`sm`,"data-testid":`event-add-${a}`,disabled:n.saving,onClick:()=>m(!0),children:l(`customize.scalar.add`)})]})]})})}),i(Ll,{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:j,canSave:k&&!n.saving,onClose:()=>m(!1),onSave:e=>{m(!1),A(qa(_,n.target,e))}})]})}function Jl({deviceId:t,cap:n,timestampPath:r,counterPath:a,startedAt:o}){let{t:s}=Q(),c=ao({deviceId:t,cap:n,path:r}),l=ao({deviceId:t,cap:n,path:a}),u=Gl(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?``:Aa(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:Aa(u.lastPressedAt)}),u.pressCount===null?``:` · ${s(`customize.event.doorbellCount`,{count:u.pressCount})}`]})}function Yl(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 Xl(e,t,n){return e?t===`pending`?`pending`:t===`unknown`?`unknown`:n?`present`:`absent`:`present`}function Zl(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 Ql(t){let{t:n}=Q(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(hn,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(zn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(en,{children:i(pr,{children:r})}),t.open?i($l,{...t}):null]})})}function $l(t){let{t:r}=Q(),a=vn({projection:`slim`}),s=Fo(n(()=>a.status===`success`?qo(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>eu(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=tu(c),b=Nl({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(En,{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(mo,{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(nu,{deviceId:x.deviceId,cap:x.cap,fieldPath:x.fieldPath,timeoutMs:Math.round(h*1e3)})]}),e(oa,{className:`flex flex-wrap gap-2`,children:[i(X,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(X,{"data-testid":`event-save`,disabled:!t.canSave||b===null,onClick:()=>{b!==null&&t.onSave(b)},children:r(`customize.scalar.save`)})]})]})}function eu(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 tu(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 nu({deviceId:e,cap:t,fieldPath:n,timeoutMs:r}){let{t:a}=Q(),o=ao({deviceId:e,cap:t,path:n}),s=o.kind===`value`&&typeof o.value==`boolean`?{kind:`level`,active:o.value,changedAt:null}:{kind:`unread`},c=Qe(bt,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(ru(s,c.open))})}function ru(e,t){return e.kind===`unread`?`customize.event.previewWaiting`:t?`customize.event.previewMotionOn`:e.active?`customize.event.previewSensorOn`:`customize.event.previewMotionOff`}var iu=60;function au(e){let t=Number.isFinite(e)?Math.max(0,Math.round(e)):0;return t<iu?Z.t(`customize.event.durationSeconds`,{count:t}):ps(t*1e3)}c();function ou({device:n,availability:r,cap:a,title:s,view:c,sensors:l}){let{t:u}=Q(),f=Nn(),p=bi(),m=Mn({addonId:`pipeline-orchestrator`,deviceId:n.id,nodeId:`hub`}),[h,g]=o(!1),[_,v]=o(null),y=t(!1),[b,x]=o(!1),S=cu(l),C=Po(!0),w=wt(c.id,S),T=fu($o(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 Il(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(Do,{id:a,icon:me,title:s,testId:`event-card-${a}`,actions:i(K,{children:u(Ya(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(lu,{reason:du(S)||(r.kind===`unknown`?r.reason:``)}):e(d,{children:[i(su,{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(uu,{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`,{duration:au(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(X,{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(Ql,{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 su({deviceId:e}){let{t}=Q(),n=ao({deviceId:e,cap:`motion`,path:`detected`}),r=ao({deviceId:e,cap:`motion`,path:`lastDetectedAt`}),a=Ul(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:{duration:au(a.seconds)})})}function cu(e){return e.presence===`pending`?{kind:`pending`}:e.status===null?{kind:`unknown`,reason:e.failureReason}:{kind:`known`,value:e.status}}function lu({reason:e}){let{t}=Q(),n=e.trim();return n.length===0?i(J,{message:t(`customize.motion.unreadableBare`)}):i(J,{title:t(`customize.motion.unreadable`,{reason:n}),message:n})}function uu({row:e,fleet:t}){let n=Bi();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:vo(Vo(r),t.value.map(Vo),n)}function du(e){return e.kind===`unknown`?e.reason??``:e.kind===`known`&&e.value.state===`unreadable`?e.value.reason:``}function fu(e,t){return e!==null&&Number.isFinite(e)?e:t}var pu={id:0,name:``,type:`unknown`,stableId:``,parentDeviceId:null};function mu(e){return to().find(t=>t.cap===e)??null}function hu({spec:e,device:t,handle:n}){let r=mu(e.cap);return r===null?i(_u,{}):r.pulse===null?i(su,{deviceId:t.id}):i(Jl,{deviceId:t.id,cap:e.cap,timestampPath:r.pulse.timestampPath,counterPath:r.pulse.counterPath,startedAt:n.state.kind===`present`?n.state.view.block.createdAt:null})}function gu(e){let t=mu(e.spec.cap);return t===null?i(_u,{}):t.pulse===null?i(bu,{...e,view:t.span}):i(yu,{...e,cap:e.spec.cap,view:t.pulse})}function _u(){let{t:e}=Q();return i(`span`,{className:`text-xs text-foreground-subtle`,children:e(`customize.table.unknown`)})}function vu(){let{t:e}=Q();return i(`span`,{role:`status`,className:`text-xs text-foreground-subtle`,children:e(`customize.event.checking`)})}function yu({cap:e,view:t,handle:n}){let{t:r,i18n:a}=Q(),o=sl(n,Ja(xo(n.state),e)),s=(o.kind===`known`&&o.value!==null?Re({feature:o.value,device:n.target,cap:e,targetId:t.id,timestampPath:t.timestampPath,counterPath:t.counterPath}):null)?.draft.sources[0]??null,c=Po(s!==null),l=s===null||c.kind!==`known`?null:c.value.find(e=>Et({addonId:e.addonId,stableId:e.stableId})===Et(s))??null,u=Fr(l===null?pu:Vo(l),`compact`);return o.kind===`pending`?i(vu,{}):o.kind===`unknown`?i(_u,{}):o.value===null?i(`span`,{className:`text-xs text-foreground-subtle`,children:r(`customize.scalar.noOverride`)}):s===null?i(`span`,{className:`text-xs text-foreground`,children:r(`customize.table.otherFormula`)}):c.kind===`pending`?i(vu,{}):c.kind===`unknown`?i(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:r(`customize.scalar.sourceUnreadable`)}):l===null?i(K,{variant:`warning`,children:r(`customize.table.sourceMissing`)}):i(`span`,{className:`text-xs text-foreground`,children:r(`customize.table.sourceOf`,{name:u,field:Wo(s.cap,s.fieldPath,a.language)})})}function bu({sensors:t,view:n}){let{t:r}=Q(),a=Po(!0),o=cu(t);if(n===null)return i(_u,{});if(o.kind===`pending`)return i(vu,{});if(o.kind===`unknown`)return i(_u,{});let s=wt(n.id,o);return s.rows.length===0?i(K,{children:r(Ya(s.text,s.status.state))}):i(`span`,{className:`flex flex-col gap-0.5`,children:s.rows.map(t=>e(`span`,{className:`text-xs text-foreground`,children:[i(uu,{row:t,fleet:a}),t.reason===null?``:` — ${r(`customize.motion.state.${t.state}`)}`]},t.key))})}function xu(e,t){let n=t.parentDeviceId??t.id,r=e.filter(e=>e.parentDeviceId===n&&e.id!==t.id).map(e=>e.id);return[t.id,...r]}function Su(e,t){return e.some(e=>e.id===t.id)?e.map(e=>e.id===t.id?t:e):[...e,t]}function Cu(e,t){return e.filter(e=>e.id!==t)}function wu(e){let t=new Set(e.map(e=>e.id)),n=1;for(;t.has(`p${String(n)}`);)n+=1;return`p${String(n)}`}var Tu=(e,t)=>e.trim().toLowerCase()===t.trim().toLowerCase();function Eu(e,t){return t.name.trim()===``?{ok:!1,reason:`no-name`}:t.steps.length===0?{ok:!1,reason:`no-steps`}:e.some(e=>e.id!==t.id&&Tu(e.name,t.name))?{ok:!1,reason:`duplicate-name`}:{ok:!0}}function Du(e){return`${e.what}: ${e.reason}`}var Ou=[`fan`,`oscillation`,`angles`];function ku(e){return Ou.map(t=>({group:t,rows:e.items.flatMap((e,n)=>e.group===t?[{index:n,item:e}]:[])})).filter(e=>e.rows.length>0)}function Au(e,t){return e.steps.filter((e,n)=>t.has(n))}c();function ju(e){return e.kind===`cap`||e.kind===`wait`}function Mu(){let{t:e}=Q();return t=>{switch(t){case`fan`:return e(`fanPresets.capture.group.fan`,`Fan`);case`oscillation`:return e(`fanPresets.capture.group.oscillation`,`Oscillation`);case`angles`:return e(`fanPresets.capture.group.angles`,`Angles`)}}}function Nu(){let{t:e}=Q();return t=>{if(t.ok)return null;switch(t.reason){case`no-name`:return e(`fanPresets.problem.name`,`Give the preset a name.`);case`no-steps`:return e(`fanPresets.problem.noSteps`,`Add at least one step, or use the current values.`);case`duplicate-name`:return e(`fanPresets.problem.duplicate`,`Another preset already has this name.`)}}}function Pu({fanId:t,draft:n,others:r,devices:a,saving:s,error:c,onSave:l,onClose:u}){let{t:d}=Q(),f=Nu(),[p,m]=o(n),h=Mu(),[g,_]=o([]),[v,y]=o(null),[b,x]=o(new Set),S=tn({deviceId:t,steps:[]},{enabled:!1,gcTime:0,retry:!1}),C=Eu(r,p),w=f(C),T=()=>{S.refetch().then(e=>{e.data!==void 0&&(y(e.data),x(new Set(e.data.steps.keys())),_(e.data.omitted))})},E=(e,t)=>{x(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})};return i(hn,{open:!0,onOpenChange:e=>!e&&u(),children:e(zn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(en,{children:i(pr,{children:d(`fanPresets.dialog.title`,`Fan preset`)})}),i(En,{children:e(`div`,{className:`space-y-3`,"data-testid":`fan-preset-editor`,children:[i(q,{label:d(`fanPresets.dialog.name`,`Name`),children:i(zi,{value:p.name,maxLength:40,placeholder:d(`fanPresets.dialog.namePlaceholder`,`Night, Boost, Away…`),onChange:e=>m({...p,name:e.target.value})})}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[i(`p`,{className:`text-xs text-foreground-muted`,children:d(`fanPresets.dialog.stepsHint`,`Steps run in order, on this fan and the devices beside it.`)}),e(X,{size:`sm`,variant:`outline`,disabled:S.isFetching,onClick:T,"data-testid":`fan-preset-use-current`,children:[S.isFetching?i(se,{className:`h-4 w-4 animate-spin`}):i(ee,{className:`h-4 w-4`}),` `,d(`fanPresets.dialog.useCurrent`,`Use current values`)]})]}),S.isError&&i(J,{message:S.error?.message??d(`fanPresets.dialog.captureFailed`,`The current values could not be read.`)}),g.length>0&&e(`div`,{role:`status`,className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,"data-testid":`fan-preset-omitted`,children:[i(`p`,{children:d(`fanPresets.dialog.omitted`,`These values could not be read, so they were left out:`)}),i(`ul`,{className:`mt-1 list-disc pl-4`,children:g.map(e=>i(`li`,{children:Du(e)},`${e.what}:${e.reason}`))})]}),v!==null&&e(`div`,{className:`space-y-2 rounded border border-border p-3`,"data-testid":`fan-preset-capture`,children:[i(`p`,{className:`text-xs text-foreground-muted`,children:d(`fanPresets.capture.hint`,`Tick what this preset should set. Unticked values are left as they are.`)}),ku(v).map(t=>e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs font-medium text-foreground`,children:h(t.group)}),t.rows.map(t=>e(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm`,children:[i(Ji,{checked:b.has(t.index),"aria-label":t.item.label,onChange:e=>E(t.index,e.target.checked)}),i(`span`,{children:t.item.label})]},t.index))]},t.group)),e(`div`,{className:`flex justify-end gap-2`,children:[i(X,{size:`sm`,variant:`ghost`,onClick:()=>y(null),children:d(`common.cancel`,`Cancel`)}),i(X,{size:`sm`,disabled:b.size===0,onClick:()=>{v!==null&&(m(e=>({...e,steps:[...Au(v,b)]})),y(null))},"data-testid":`fan-preset-capture-apply`,children:d(`fanPresets.capture.apply`,`Use selected`)})]})]}),i(Pa,{actions:p.steps,devices:a,allowedKinds:[`cap`,`wait`],onChange:e=>m({...p,steps:e.filter(ju)})}),w!==null&&p.name!==``&&i(`p`,{className:`text-xs text-warning`,children:w}),c!==null&&i(J,{message:c})]})}),e(oa,{children:[i(X,{variant:`ghost`,onClick:u,children:d(`common.cancel`,`Cancel`)}),e(X,{disabled:s||!C.ok,onClick:()=>l({...p,name:p.name.trim()}),children:[s&&i(se,{className:`h-4 w-4 animate-spin`}),` `,d(`common.save`,`Save`)]})]})]})})}c();function Fu(e){let t=vn({projection:`slim`});return n(()=>{let n=t.data??[],r=new Set(xu(n,e));return n.filter(e=>r.has(e.id)).map(e=>({id:e.id,name:e.name,stableId:e.stableId,type:String(e.type),location:e.location??null})).toSorted((e,t)=>e.name.localeCompare(t.name))},[t.data,e])}function Iu({device:t}){let{t:n}=Q(),r=ue(),a=l(),s=mr({deviceId:t.id}),c=Fu(t),[u,d]=o(null),[f,p]=o(null),m=wn({onSuccess:e=>{if(e.status===`refused`){p(e.detail);return}p(null),d(null),a.invalidateQueries({queryKey:[[`fanPresets`]]}),a.invalidateQueries({queryKey:[[`actions`]]})}}),h=s.data,g=e=>m.mutate({deviceId:t.id,presets:[...e]});return e(Do,{id:`fan-presets`,title:n(`fanPresets.card.title`,`Presets`),icon:ae,testId:`customize-fan-presets`,actions:e(X,{size:`sm`,variant:`outline`,disabled:h===void 0,onClick:()=>d({id:wu(h??[]),name:``,steps:[]}),"data-testid":`fan-presets-add`,children:[i(P,{className:`h-4 w-4`}),` `,n(`fanPresets.card.add`,`Add preset`)]}),children:[s.status===`error`?i(`p`,{role:`alert`,className:`px-3 py-2 text-xs text-danger`,children:s.error?.message??n(`fanPresets.card.unreadable`,`The presets could not be read.`)}):h===void 0?i(`p`,{role:`status`,className:`px-3 py-2 text-xs text-foreground-subtle`,children:n(`fanPresets.card.loading`,`Loading presets…`)}):h.length===0?i(`p`,{className:`px-3 py-2 text-xs text-foreground-muted`,"data-testid":`fan-presets-empty`,children:n(`fanPresets.card.none`,`No presets yet. A preset sets the fan, and the lamp or switch beside it, in one go.`)}):i(`ul`,{className:`divide-y divide-border-subtle`,"data-testid":`fan-presets-list`,children:h.map(t=>e(`li`,{className:`flex items-center gap-2 px-3 py-2`,children:[i(`span`,{className:`min-w-0 flex-1 truncate text-sm text-foreground`,children:t.name}),i(K,{variant:`info`,children:n(`fanPresets.card.steps`,`Steps: {{count}}`,{count:t.steps.length})}),i(Y,{icon:I,variant:`ghost`,"aria-label":n(`fanPresets.card.edit`,`Edit {{name}}`,{name:t.name}),onClick:()=>d(t)}),i(Y,{icon:E,variant:`ghost`,"aria-label":n(`fanPresets.card.delete`,`Delete {{name}}`,{name:t.name}),onClick:()=>{r({title:n(`fanPresets.card.deleteTitle`,`Delete this preset?`),message:n(`fanPresets.card.deleteMessage`,`{{name}} will be deleted, and Alexa, HomeKit and Home Assistant stop offering it.`,{name:t.name}),confirmLabel:n(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&g(Cu(h,t.id))})}})]},t.id))}),u!==null&&h!==void 0&&i(Pu,{fanId:t.id,draft:u,others:h,devices:c,saving:m.isPending,error:f??m.error?.message??null,onSave:e=>g(Su(h,e)),onClose:()=>{d(null),p(null)}})]})}var Lu=`ir-transmitter`;function Ru(e,t){let n=new Map(t.customButtons.map(e=>[Ct(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)||at(e))return;i.add(e);let o=et(e)!==null;a.push({role:e,custom:o,inLayout:t,name:o?n.get(e)??r.get(e)??as(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 zu(e,t,n){let r=et(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 Bu(e,t,n,r=as(t)){return zu({...e,bindings:{...e.bindings,[t]:{action:n}}},t,r)}function Vu(e,t){let n=Object.fromEntries(Object.entries(e.bindings).filter(([e])=>e!==t)),r=et(t);return{...e,bindings:n,customButtons:r===null?e.customButtons:e.customButtons.filter(e=>e.key!==r)}}function Hu(e){return e.deviceId>0&&e.cap!==``&&e.method!==``}var Uu={kind:`cap`,deviceId:0,cap:``,method:``};function Wu(e){let{action:t}=e;return t.cap===`ir-transmitter`&&t.method===`send`?t.deviceId:null}function Gu(e,t){return{action:{...e.action,deviceId:t}}}function Ku(e){let t=Object.entries(e.bindings).filter(([,e])=>!Hu(e.action)).map(([e])=>e);if(t.length>0)return{incomplete:t,config:null};let n=Be.safeParse(e);return{incomplete:t,config:n.success?n.data:null}}function qu(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=dt(n),r=it(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 mt)return{status:`refused`,reason:`not-smartir`};throw e}}function Ju(e,t){if(t===null||t<=0)return{status:`refused`,reason:`no-transmitter`};try{let n=vt(lt(e),{transmitterDeviceId:t});return{status:`ok`,draft:n,bound:Object.keys(n.bindings).length,skipped:n.skipped}}catch(e){if(e instanceof mt)return{status:`refused`,reason:`not-flipper`};throw e}}function Yu(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}}}var Xu={kind:`digits`,name:``,number:``,steps:[],transmitterId:null,encoding:`raw`,code:``,carrierKhz:``};function Zu(e){switch(e.kind){case`digits`:return{...Xu,kind:`digits`,name:e.name,number:e.number};case`sequence`:return{...Xu,kind:`sequence`,name:e.name,steps:e.steps};case`ir`:return{...Xu,kind:`ir`,name:e.name,transmitterId:e.transmitterId,...e.payload.kind===`pronto`?{encoding:`pronto`,code:e.payload.code}:{encoding:`raw`,code:e.payload.timings.join(`, `),carrierKhz:e.payload.settings?.carrierHz===void 0?``:String(e.payload.settings.carrierHz/1e3)}}}}function Qu(e){if(e.encoding===`pronto`)return{kind:`pronto`,code:e.code.trim()};let t=e.code.replace(/[[\]]/g,` `).split(/[\s,]+/).filter(e=>e!==``).map(Number),n=e.carrierKhz.trim();return n===``?{kind:`raw`,timings:t}:{kind:`raw`,timings:t,settings:{carrierHz:Math.round(Number(n)*1e3)}}}var $u=-1;function ed(e){let t=e.payload.kind;try{let{timings:n,settings:r}=Ze(e.payload);return{encoding:t,pulses:n.length,carrierKhz:r.carrierHz===void 0?null:r.carrierHz/1e3}}catch(e){if(e instanceof mt)return{encoding:t,pulses:null,carrierKhz:null};throw e}}function td(e){return Object.keys(e.bindings)}var nd=48;function rd(e,t){let n=t.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,nd-4).replace(/-+$/g,``),r=n===``?`source`:n,i=new Set(e.sources.map(e=>e.id)),a=r;for(let e=2;i.has(a);e++)a=`${r}-${e}`;return a}function id(e,t){switch(e.kind){case`digits`:return{id:t,kind:`digits`,name:e.name,number:e.number};case`sequence`:return{id:t,kind:`sequence`,name:e.name,steps:[...e.steps]};case`ir`:return{id:t,kind:`ir`,name:e.name,transmitterId:e.transmitterId??$u,payload:Qu(e)}}}function ad(e,t,n){if(n===null){let n=id(t,rd(e,t.name));return{...e,sources:[...e.sources,n]}}return{...e,sources:e.sources.map(e=>e.id===n?id(t,n):e)}}function od(e,t){return{...e,sources:e.sources.filter(e=>e.id!==t)}}function sd(e,t,n){let r=e.sources.findIndex(e=>e.id===t),i=r+n;if(r<0||i<0||i>=e.sources.length)return e;let a=[...e.sources],[o]=a.splice(r,1);return o===void 0?e:(a.splice(i,0,o),{...e,sources:a})}function cd(e,t){return{...e,stepDelayMs:t}}var ld=[`id`,`name`,`number`,`steps`,`kind`,`transmitterId`,`payload`];function ud(e){return ld.some(t=>t===e)}function dd(e){let t=Be.safeParse(e),n=new Map,r=null;if(!t.success)for(let e of t.error.issues){let[t,i,a]=e.path;if(t===`stepDelayMs`)r={field:`kind`,code:e.code,message:e.message};else if(t===`sources`&&typeof i==`number`){let t=ud(a)?a:`kind`,r=n.get(i)??[];r.push({field:t,code:e.code,message:e.message}),n.set(i,r)}}return{bySource:n,stepDelay:r}}function fd(e,t,n){let r=ad(e,t,n),i=n===null?r.sources.length-1:r.sources.findIndex(e=>e.id===n);return dd(r).bySource.get(i)??[]}function pd(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function md(e){let t=e.args??{},n=t.timings,r=t.settings,i=typeof r==`object`&&r&&`carrierHz`in r?pd(r.carrierHz):null;return{call:`${e.cap}.${e.method}`,timings:Array.isArray(n)?n.length:null,carrierHz:i}}function hd(e,t,n){let r=t.find(t=>t.id===e);return r===void 0?n:gd(r)}function gd(e){return e.parentName?`${e.name} · ${e.parentName}`:e.name}function _d(e){return Object.entries(e).flatMap(([e,t])=>typeof t==`string`||typeof t==`number`||typeof t==`boolean`?[{name:e,value:String(t)}]:[])}function vd(e,t){if(e===void 0)return{kind:`unbound`};if(!Hu(e))return{kind:`incomplete`};let n=hd(e.deviceId,t,`#${e.deviceId}`),r=md(e),i=_d(e.args??{});return e.cap===`ir-transmitter`&&e.method===`send`?{kind:`infrared`,target:n,pulses:r.timings,carrierKhz:r.carrierHz===null?null:Math.round(r.carrierHz/1e3),args:i}:{kind:`call`,target:n,call:r.call,args:i}}function yd(e){return Array.isArray(e)&&e.every(e=>typeof e==`number`)}function bd(e){if(!Hu(e))return null;let t=e.args??{};if(e.cap===`ir-transmitter`&&e.method===`send`&&yd(t.timings)){let n=t.timings,r=md(e).carrierHz;return{kind:`infrared`,timings:n,pulses:n.length,carrierKhz:r===null?null:r/1e3,text:n.join(`, `)}}let n=Object.keys(t).length===0?``:JSON.stringify(t);return{kind:`call`,text:`${e.cap}.${e.method}(${n})`}}c();function xd({description:e}){let{t}=Q();switch(e.kind){case`unbound`:return t(`remote.panel.unbound`);case`incomplete`:return t(`remote.panel.incomplete`);case`infrared`:return e.pulses===null?t(`remote.panel.infrared`,{target:e.target}):e.carrierKhz===null?t(`remote.panel.infraredPulses`,{count:e.pulses,target:e.target}):t(`remote.panel.infraredPulsesCarrier`,{count:e.pulses,khz:e.carrierKhz,target:e.target});case`call`:return t(`remote.panel.call`,{call:e.call,target:e.target})}}function Sd({label:t,children:n}){return e(`div`,{className:`grid gap-1 sm:grid-cols-[6rem_minmax(0,1fr)] sm:gap-2`,children:[i(`dt`,{className:`text-xs text-foreground-muted`,children:t}),i(`dd`,{className:`min-w-0 text-xs text-foreground`,children:n})]})}function Cd({code:t,role:n}){let{t:r}=Q();return e(`div`,{className:`space-y-1`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`span`,{className:`text-[11px] text-foreground-subtle`,children:t.kind===`infrared`?[r(`remote.panel.codeRaw`,{count:t.pulses}),...t.carrierKhz===null?[]:[r(`remote.panel.codeCarrier`,{khz:t.carrierKhz})]].join(` · `):r(`remote.panel.callCode`)}),i(ui,{value:t.text,srLabel:r(`remote.panel.copyCode`)})]}),i(`pre`,{className:`max-h-28 overflow-auto whitespace-pre-wrap break-all rounded border border-border bg-surface p-2 font-mono text-[11px] leading-snug text-foreground`,"data-testid":`code-${n}`,children:t.text})]})}function wd({role:t,name:n,binding:r,devices:a,transmitters:s,testable:c,testResult:l,onBind:u,onClear:f,onTest:p}){let{t:m}=Q(),h=nn()(Dt(t.role)),[g,_]=o(!1),v=r!==void 0&&Hu(r.action),y=r===void 0?null:Wu(r),b=vd(r?.action,a),x=r===void 0?null:bd(r.action),S=r!==void 0&&y===null&&(g||!v);return e(`aside`,{className:`min-w-0 space-y-3 rounded border border-border bg-surface p-3`,"data-testid":`binding-panel`,"aria-label":m(`remote.panel.title`,{name:n}),children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[h!==void 0&&i(h,{className:`h-4 w-4 shrink-0 text-foreground-muted`,"aria-hidden":!0}),i(`h4`,{className:`text-sm font-medium text-foreground`,children:n}),t.custom&&i(K,{variant:`neutral`,children:m(`remote.bindings.custom`)}),!t.inLayout&&i(K,{variant:`warning`,children:m(`remote.bindings.notInLayout`)}),y!==null&&i(K,{variant:`info`,children:m(`remote.bindings.infrared`)})]}),e(`dl`,{className:`space-y-2`,"data-testid":`binding-description`,children:[e(Sd,{label:m(`remote.panel.does`),children:[i(`span`,{className:r===void 0?`text-foreground-subtle`:void 0,"data-testid":`summary-${t.role}`,children:i(xd,{description:b})}),v&&i(`span`,{className:`block text-foreground-muted`,children:m(`remote.panel.repeatValue`)})]}),y!==null&&r!==void 0&&i(Sd,{label:m(`remote.panel.through`),children:i(H,{"aria-label":m(`remote.bindings.transmitterFor`,{name:n}),value:String(y),options:s.map(e=>({value:String(e.id),label:gd(e)})),onChange:e=>u(Gu(r,Number(e.target.value)).action),"data-testid":`transmitter-${t.role}`})}),x!==null&&i(Sd,{label:m(`remote.panel.code`),children:i(Cd,{code:x,role:t.role})})]}),S&&r!==void 0&&i(q,{label:m(`commands.change`),children:i(Ma,{step:r.action,devices:a,variables:[],onChange:e=>{typeof e.deviceId==`number`&&u({...e,deviceId:e.deviceId})}})}),i(`div`,{className:`flex flex-wrap items-center gap-1`,children:r===void 0?i(X,{size:`sm`,variant:`outline`,onClick:()=>{_(!0),u(Uu)},"data-testid":`bind-${t.role}`,children:m(`remote.bindings.bind`)}):e(d,{children:[y===null&&v&&!g&&i(X,{size:`sm`,variant:`outline`,onClick:()=>_(!0),"data-testid":`edit-${t.role}`,children:m(`commands.change`)}),i(X,{size:`sm`,variant:`outline`,disabled:!c||!v,title:c?void 0:m(`remote.bindings.saveToTest`),onClick:p,"data-testid":`test-${t.role}`,children:m(`remote.bindings.test`)}),i(X,{size:`sm`,variant:`ghost`,onClick:()=>{_(!1),f()},"data-testid":`clear-${t.role}`,children:m(`remote.bindings.clear`)})]})}),l!==null&&i(`p`,{role:`status`,className:`text-xs text-foreground-muted`,"data-testid":`result-${t.role}`,children:l})]})}var Td=`media-player`;function Ed(e){return e.stableId.startsWith(`composed-`)?e.stableId.slice(_t.length):null}function Dd(e){return e.target.kind!==`new`||e.features.some(e=>e.cap===Td)?null:{...e,features:[...e.features,{kind:`fields`,cap:Td,fields:{},commands:Le()}]}}var Od=`Lucaslhm/Flipper-IRDB`,kd=`main`,Ad=600*1e3,jd=class extends Error{code;resetAtMs;constructor(e,t,n=null){super(t),this.name=`FlipperIrdbError`,this.code=e,this.resetAtMs=n}},Md=jt(At({name:kt(),path:kt(),type:kt()}));function Nd(e){return e.split(`/`).filter(e=>e!==``).map(encodeURIComponent).join(`/`)}function Pd(e){let t=[];for(let n of e)n.type===`dir`?t.push({name:n.name,path:n.path,kind:`dir`}):n.type===`file`&&n.name.toLowerCase().endsWith(`.ir`)&&t.push({name:n.name,path:n.path,kind:`file`});return t.sort((e,t)=>e.kind===t.kind?e.name.localeCompare(t.name):e.kind===`dir`?-1:1)}function Fd(e,t){let n=t.trim().toLowerCase();return n===``?e:e.filter(e=>e.name.toLowerCase().includes(n))}function Id(e={}){let t=e.fetchFn??((e,t)=>fetch(e,t)),n=e.now??Date.now,r=e.ttlMs??Ad,i=new Map;async function a(e){let n;try{n=await t(e)}catch(e){throw new jd(`network`,e instanceof Error?e.message:`request failed`)}if(n.status===404)throw new jd(`not-found`,`Not found in the library`);let r=n.headers.get(`x-ratelimit-remaining`)===`0`;if(n.status===429||n.status===403&&r){let e=Number(n.headers.get(`x-ratelimit-reset`));throw new jd(`rate-limited`,`GitHub rate limit reached`,Number.isFinite(e)&&e>0?e*1e3:null)}if(!n.ok)throw new jd(`bad-response`,`GitHub answered ${n.status}`);return n}return{async list(e){let t=Nd(e),o=i.get(t);if(o!==void 0&&n()-o.at<=r)return o.entries;let s=await a(`https://api.github.com/repos/${Od}/contents/${t}`),c=Md.safeParse(await s.json().catch(()=>null));if(!c.success)throw new jd(`bad-response`,`Not a directory listing`);let l=Pd(c.data);return i.set(t,{at:n(),entries:l}),l},async readFile(e){return(await a(`https://raw.githubusercontent.com/${Od}/${kd}/${Nd(e)}`)).text()}}}c();function Ld(e){return e instanceof jd?e:new jd(`network`,`request failed`)}function Rd({transmitterId:t,onApply:r,client:s}){let{t:c}=Q(),l=n(()=>s??Id(),[s]),[u,d]=o(``),[f,p]=o(``),[m,h]=o({status:`loading`}),[g,_]=o(null),[v,y]=o(null);a(()=>{let e=!0;return h({status:`loading`}),l.list(u).then(t=>{e&&h({status:`ready`,entries:t})}).catch(t=>{e&&h({status:`error`,error:Ld(t)})}),()=>{e=!1}},[l,u]);let b=e=>{if(y(null),_(null),e.kind===`dir`){p(``),d(e.path);return}l.readFile(e.path).then(e=>y(Ju(e,t))).catch(e=>_(Ld(e)))},x=e=>e.code===`rate-limited`&&e.resetAtMs!==null?c(`remote.flipper.error.rate-limitedAt`,{time:new Date(e.resetAtMs).toLocaleTimeString()}):c(`remote.flipper.error.${e.code}`),S=u===``?[]:u.split(`/`),C=m.status===`ready`?Fd(m.entries,f):[];return e(`div`,{className:`space-y-2`,"data-testid":`flipper-import`,children:[i(`p`,{className:`text-xs text-foreground-muted`,children:c(`remote.flipper.hint`)}),e(`nav`,{className:`flex flex-wrap items-center gap-1 text-xs`,"aria-label":c(`remote.flipper.title`),children:[i(X,{size:`sm`,variant:`ghost`,onClick:()=>{d(``),p(``),y(null)},children:c(`remote.flipper.root`)}),S.map((t,n)=>e(`span`,{className:`flex items-center gap-1`,children:[i(k,{className:`h-3 w-3 text-foreground-subtle`,"aria-hidden":!0}),i(X,{size:`sm`,variant:`ghost`,onClick:()=>{d(S.slice(0,n+1).join(`/`)),p(``),y(null)},children:t})]},t+String(n)))]}),i(zi,{value:f,onChange:e=>p(e.target.value),placeholder:c(`remote.flipper.search`),"aria-label":c(`remote.flipper.search`),"data-testid":`flipper-search`}),m.status===`loading`&&i(`p`,{className:`text-xs text-foreground-muted`,children:c(`remote.flipper.loading`)}),m.status===`error`&&i(`p`,{role:`alert`,className:`text-xs text-danger`,"data-testid":`flipper-error`,children:x(m.error)}),m.status===`ready`&&C.length===0&&i(`p`,{className:`text-xs text-foreground-muted`,children:c(`remote.flipper.empty`)}),C.length>0&&i(`ul`,{className:`max-h-48 space-y-0.5 overflow-y-auto`,"data-testid":`flipper-entries`,children:C.map(t=>i(`li`,{children:e(X,{size:`sm`,variant:`ghost`,className:`w-full justify-start`,onClick:()=>b(t),children:[t.kind===`dir`?i(Ft,{className:`mr-1 h-3 w-3`,"aria-hidden":!0}):i(Nt,{className:`mr-1 h-3 w-3`,"aria-hidden":!0}),i(`span`,{className:`truncate`,children:t.name})]})},t.path))}),g!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger`,"data-testid":`flipper-file-error`,children:x(g)}),v?.status===`refused`&&i(`p`,{role:`alert`,className:`text-xs text-danger`,"data-testid":`flipper-refused`,children:c(`remote.flipper.refused.${v.reason}`)}),v?.status===`ok`&&e(`div`,{className:`space-y-2`,"data-testid":`flipper-summary`,children:[i(`p`,{className:`text-xs text-foreground`,children:c(`remote.import.summary`,{count:v.bound})}),v.skipped.length>0&&e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs text-warning`,children:c(`remote.import.skipped`,{count:v.skipped.length})}),i(`ul`,{className:`max-h-24 space-y-0.5 overflow-y-auto text-[11px] text-foreground-muted`,children:v.skipped.map(t=>e(`li`,{children:[t.name,` — `,t.reason]},`${t.name}:${t.reason}`))})]}),i(X,{size:`sm`,disabled:v.bound===0,onClick:()=>{r(v.draft),y(null)},"data-testid":`flipper-apply`,children:c(`remote.import.apply`)})]})]})}c();function zd({transmitterId:n,onApply:r}){let{t:a}=Q(),s=t(null),[c,l]=o(``),[u,d]=o(null),[f,p]=o(null),m=e=>{p(e.trim()===``?null:qu(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(q,{label:a(`remote.import.pasteLabel`),children:i(_i,{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(ki,{ref:s,accept:`application/json,.json`,className:`hidden`,onChange:e=>void h(e),"data-testid":`smartir-file`}),e(X,{size:`sm`,variant:`outline`,onClick:()=>s.current?.click(),children:[i(qt,{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(X,{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(X,{size:`sm`,disabled:f.bound===0,onClick:()=>{r(f.draft),l(``),d(null),p(null)},"data-testid":`smartir-apply`,children:a(`remote.import.apply`)})]})]})}function Bd(e,t){return t(`remote.sources.error.${e.field}.${e.code}`,{defaultValue:e.message})}function Vd(e,t,n){return e.filter(e=>{switch(t){case`name`:return e.field===`name`||e.field===`id`;case`number`:return e.field===`number`||n===`digits`&&e.field===`steps`;case`steps`:return n===`sequence`&&e.field===`steps`;case`transmitterId`:case`payload`:return n===`ir`&&e.field===t}})}c();function Hd({lines:e}){return e.length===0?null:i(`div`,{role:`alert`,className:`space-y-0.5 text-xs text-danger`,children:e.map(e=>i(`p`,{children:e},e))})}function Ud(e){return Ke.some(t=>t===e)}function Wd({config:t,source:r,roleLabel:a,transmitters:s,onClose:c,onSave:l}){let{t:u}=Q(),[f,p]=o(r===null?{...Xu,transmitterId:t.defaultTransmitterId}:Zu(r)),[m,h]=o(!1),[g,_]=o(``),v=n(()=>fd(t,f,r?.id??null),[t,f,r]),y=td(t),b=e=>p(t=>({...t,...e})),x=e=>m?Vd(v,e,f.kind).map(e=>Bd(e,u)):[],S=(e,t)=>{let n=e+t;if(n<0||n>=f.steps.length)return;let r=[...f.steps],[i]=r.splice(e,1);i!==void 0&&(r.splice(n,0,i),b({steps:r}))};return i(ln,{open:!0,onClose:c,title:u(r===null?`remote.sources.dialog.addTitle`:`remote.sources.dialog.editTitle`),testId:`source-dialog`,footer:i(X,{onClick:()=>{h(!0),!(v.length>0)&&l(ad(t,f,r?.id??null))},"data-testid":`source-save`,children:u(`common.save`)}),children:e(`div`,{className:`space-y-4`,children:[i(q,{label:u(`remote.sources.dialog.kind`),children:i(H,{value:f.kind,options:Ke.map(e=>({value:e,label:u(`remote.sources.kind.${e}`)})),onChange:e=>{Ud(e.target.value)&&b({kind:e.target.value})},"data-testid":`source-kind`})}),i(q,{label:u(`remote.sources.dialog.name`),children:i(zi,{value:f.name,state:x(`name`).length>0?`error`:`default`,onChange:e=>b({name:e.target.value}),"data-testid":`source-name`})}),i(Hd,{lines:x(`name`)}),f.kind===`ir`&&i(Gd,{draft:f,transmitters:s,patch:b,lines:x}),f.kind===`digits`&&e(d,{children:[i(q,{label:u(`remote.sources.dialog.number`),description:u(`remote.sources.dialog.numberHint`),children:i(zi,{value:f.number,inputMode:`numeric`,state:x(`number`).length>0?`error`:`default`,onChange:e=>b({number:e.target.value}),"data-testid":`source-number`})}),i(Hd,{lines:x(`number`)})]}),f.kind===`sequence`&&e(`div`,{className:`space-y-2`,children:[i(q,{label:u(`remote.sources.dialog.steps`),description:u(`remote.sources.dialog.stepsHint`),children:f.steps.length===0?i(`p`,{className:`text-xs text-foreground-muted`,children:u(`remote.sources.dialog.stepsEmpty`)}):i(`ol`,{className:`space-y-1`,"data-testid":`source-steps`,children:f.steps.map((t,n)=>e(`li`,{className:`flex items-center gap-1 rounded border border-border bg-surface px-2 py-1`,children:[i(`span`,{className:`w-5 text-xs text-foreground-subtle`,children:n+1}),i(`span`,{className:`min-w-0 flex-1 truncate text-sm text-foreground`,children:a(t)}),i(Y,{icon:xe,size:`sm`,variant:`ghost`,"aria-label":u(`remote.sources.dialog.stepUp`),disabled:n===0,onClick:()=>S(n,-1)}),i(Y,{icon:de,size:`sm`,variant:`ghost`,"aria-label":u(`remote.sources.dialog.stepDown`),disabled:n===f.steps.length-1,onClick:()=>S(n,1)}),i(Y,{icon:E,size:`sm`,variant:`ghost`,"aria-label":u(`remote.sources.dialog.stepRemove`),onClick:()=>b({steps:f.steps.filter((e,t)=>t!==n)})})]},`${n}:${t}`))})}),y.length===0?i(`p`,{className:`text-xs text-foreground-muted`,"data-testid":`source-no-bound`,children:u(`remote.sources.dialog.noBound`)}):e(`div`,{className:`flex items-center gap-2`,children:[i(H,{"aria-label":u(`remote.sources.dialog.pickStep`),value:g,options:[{value:``,label:u(`remote.sources.dialog.pickStep`)},...y.map(e=>({value:e,label:a(e)}))],onChange:e=>_(e.target.value),"data-testid":`source-step-pick`}),i(X,{size:`sm`,variant:`secondary`,disabled:g===``,onClick:()=>{b({steps:[...f.steps,g]}),_(``)},"data-testid":`source-step-add`,children:u(`remote.sources.dialog.addStep`)})]}),i(Hd,{lines:x(`steps`)})]})]})})}function Gd({draft:t,transmitters:n,patch:r,lines:a}){let{t:o}=Q();return e(d,{children:[i(q,{label:o(`remote.sources.dialog.transmitter`),children:i(H,{value:t.transmitterId===null?``:String(t.transmitterId),options:[{value:``,label:o(`remote.sources.dialog.noTransmitter`)},...n.map(e=>({value:String(e.id),label:e.label}))],onChange:e=>r({transmitterId:e.target.value===``?null:Number(e.target.value)}),"data-testid":`source-transmitter`})}),i(Hd,{lines:a(`transmitterId`)}),i(q,{label:o(`remote.sources.dialog.encoding`),children:i(H,{value:t.encoding,options:[{value:`raw`,label:o(`remote.sources.encoding.raw`)},{value:`pronto`,label:o(`remote.sources.encoding.pronto`)}],onChange:e=>r({encoding:e.target.value===`pronto`?`pronto`:`raw`}),"data-testid":`source-encoding`})}),i(q,{label:o(`remote.sources.dialog.code`),description:t.encoding===`pronto`?o(`remote.sources.dialog.prontoHint`):o(`remote.sources.dialog.codeHint`),children:i(_i,{value:t.code,rows:4,spellCheck:!1,className:`font-mono text-xs`,state:a(`payload`).length>0?`error`:`default`,onChange:e=>r({code:e.target.value}),"data-testid":`source-code`})}),t.encoding===`raw`&&i(q,{label:o(`remote.sources.dialog.carrier`),description:o(`remote.sources.dialog.carrierHint`),children:i(zi,{value:t.carrierKhz,inputMode:`decimal`,className:`w-32`,onChange:e=>r({carrierKhz:e.target.value}),"data-testid":`source-carrier`})}),i(Hd,{lines:a(`payload`)})]})}c();function Kd({source:e,roleLabel:t}){let{t:n}=Q();switch(e.kind){case`digits`:return e.number;case`sequence`:return Ve(e).map(t).join(` → `);case`ir`:{let t=ed(e);return t.pulses===null?n(`remote.sources.irDetailBroken`):t.carrierKhz===null?n(`remote.sources.irDetail`,{pulses:t.pulses}):n(`remote.sources.irDetailCarrier`,{pulses:t.pulses,khz:t.carrierKhz})}}}function qd({config:t,onChange:r,roleLabel:a,transmitters:s}){let{t:c}=Q(),[l,u]=o(null),d=n(()=>dd(t),[t]),f=t.sources.length-1,p=[{key:`name`,header:c(`remote.sources.col.name`),nowrap:!1,render:t=>e(`div`,{className:`space-y-1`,children:[i(`span`,{className:`font-medium text-foreground`,children:t.name}),i(`div`,{children:i(K,{variant:`default`,children:c(`remote.sources.kind.${t.kind}`)})})]})},{key:`detail`,header:c(`remote.sources.col.detail`),nowrap:!1,render:(t,n)=>e(`div`,{className:`space-y-0.5`,children:[i(`span`,{className:`text-foreground-muted`,children:i(Kd,{source:t,roleLabel:a})}),(d.bySource.get(n)??[]).map(e=>i(`p`,{role:`alert`,className:`text-xs text-danger`,children:Bd(e,c)},`${e.field}:${e.message}`))]})},{key:`actions`,header:c(`remote.sources.col.actions`),align:`right`,render:(t,n)=>e(`div`,{className:`flex justify-end gap-0.5`,children:[i(Y,{icon:xe,size:`sm`,variant:`ghost`,"aria-label":c(`remote.sources.moveUp`),disabled:n===0,onClick:()=>r(e=>sd(e,t.id,-1))}),i(Y,{icon:de,size:`sm`,variant:`ghost`,"aria-label":c(`remote.sources.moveDown`),disabled:n===f,onClick:()=>r(e=>sd(e,t.id,1))}),i(Y,{icon:I,size:`sm`,variant:`ghost`,"aria-label":c(`remote.sources.edit`),onClick:()=>u({source:t})}),i(Y,{icon:E,size:`sm`,variant:`ghost`,"aria-label":c(`remote.sources.delete`),onClick:()=>r(e=>od(e,t.id))})]})}];return e(`section`,{className:`space-y-3`,"data-testid":`remote-sources`,children:[e(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`h3`,{className:`text-sm font-medium text-foreground`,children:c(`remote.sources.title`)}),i(`p`,{className:`text-xs text-foreground-muted`,children:c(`remote.sources.hint`)})]}),e(X,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>u({source:null}),"data-testid":`source-add`,children:[i(P,{className:`mr-1 h-3 w-3`,"aria-hidden":!0}),c(`remote.sources.add`)]})]}),t.sources.length===0?i(vr,{icon:Rt,title:c(`remote.sources.empty`)}):i(aa,{columns:p,rows:t.sources,rowKey:e=>e.id,minWidthPx:320}),(t.refusedSources??[]).length>0&&e(`div`,{role:`alert`,className:`space-y-1`,"data-testid":`remote-refused-sources`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:c(`remote.sources.refusedTitle`)}),(t.refusedSources??[]).map(e=>i(`p`,{className:`text-xs text-foreground-muted`,children:c(`remote.sources.refusedRow`,{name:e.name??e.id??`#${e.index+1}`,reason:e.reason})},e.index))]}),i(q,{label:c(`remote.sources.stepDelay`),description:c(`remote.sources.stepDelayHint`),error:d.stepDelay===null?void 0:c(`remote.sources.error.stepDelay`,{min:100,max:Ye}),children:i(zi,{type:`number`,inputMode:`numeric`,className:`w-32`,value:Number.isNaN(t.stepDelayMs)?``:t.stepDelayMs,state:d.stepDelay===null?`default`:`error`,onChange:e=>r(t=>cd(t,e.target.valueAsNumber)),"data-testid":`source-step-delay`})}),l!==null&&i(Wd,{config:t,source:l.source,roleLabel:a,transmitters:s,onClose:()=>u(null),onSave:e=>{r(()=>e),u(null)}},l.source?.id??`new`)]})}c();function Jd({device:t,open:n,onClose:r}){let{t:a}=Q(),o=Kn({deviceId:t.id},{enabled:n});return i(hn,{open:n,onOpenChange:e=>!e&&r(),children:e(zn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(en,{children:i(pr,{children:a(`remote.dialog.title`,{name:t.name})})}),o.data===void 0?i(En,{children:o.status===`error`?i(J,{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(Xd,{device:t,initial:o.data,onClose:r})]})})}function Yd(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 Xd({device:t,initial:r,onClose:a}){let{t:s,i18n:c}=Q(),u=l(),[f,p]=o(r),[m,h]=o(null),[g,_]=o(null),[v,y]=o({}),b=un({kind:`remote`}),x=gn({deviceId:t.id}),S=Fa(),C=Pi({capNames:[Lu]}),w=tr(),T=Ed(t),E=Ui({blockId:T??``},{enabled:T!==null}),D=qi(),O=On(),k=n(()=>{let e=new Set(C.data??[]);return S.filter(t=>e.has(t.id))},[S,C.data]),A=(b.data??[]).find(e=>e.id===f.layoutTemplateId),j=A===void 0?null:ss(A.payload),M=n(()=>Ru(j,f),[j,f]),N=n(()=>new Set((x.data?.commands??[]).map(e=>e.role)),[x.data]),P=e=>e.name??j?.buttons.find(t=>t.role===e.role)?.label??ls(e.role,c.language),F=M.find(e=>e.role===g),ee=j?.buttons.find(e=>e.role===g)?.id??null,te=M.filter(e=>!e.inLayout),ne=Ku(f),re=n(()=>new Set(Object.keys(f.bindings)),[f.bindings]),I=async()=>{let e=E.data?.state===`loaded`?E.data.view:null;if(T===null||e===null)return;let t=je(e.block),n=t===null?null:Dd(t);n!==null&&await D.mutateAsync({blockId:T,expectedUpdatedAt:e.block.updatedAt,block:{composition:n}})},ie=async()=>{if(ne.config!==null){h(null);try{let e=await w.mutateAsync({deviceId:t.id,config:ne.config});if(e.status===`refused`){h(e.detail);return}await I(),await u.invalidateQueries({queryKey:[[`remote`]]}),a()}catch(e){h(e instanceof Error?e.message:String(e))}}},L=async e=>{try{let n=await O.mutateAsync({deviceId:t.id,role:e,repeat:1});y(t=>({...t,[e]:Yd(n,s)}))}catch(t){y(n=>({...n,[e]:t instanceof Error?t.message:String(t)}))}},ae=(e,t)=>p(n=>Bu(n,e,t));return e(d,{children:[e(En,{className:`space-y-5`,children:[e(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[i(q,{label:s(`remote.dialog.template`),children:i(H,{value:f.layoutTemplateId??``,options:[{value:``,label:s(`remote.dialog.noTemplate`)},...(b.data??[]).map(e=>({value:e.id,label:e.name}))],onChange:e=>p(t=>({...t,layoutTemplateId:e.target.value===``?null:e.target.value})),"data-testid":`remote-template`})}),i(q,{label:s(`remote.dialog.transmitter`),children:i(H,{value:f.defaultTransmitterId===null?``:String(f.defaultTransmitterId),options:[{value:``,label:s(`remote.dialog.noTransmitter`)},...k.map(e=>({value:String(e.id),label:gd(e)}))],onChange:e=>p(t=>({...t,defaultTransmitterId:e.target.value===``?null:Number(e.target.value)})),"data-testid":`remote-transmitter`})}),i(q,{label:s(`remote.dialog.power`),children:i(H,{value:f.power.mode,options:[{value:`toggle`,label:s(`remote.dialog.powerToggle`)},{value:`discrete`,label:s(`remote.dialog.powerDiscrete`)}],onChange:e=>p(t=>({...t,power:{mode:e.target.value===`discrete`?`discrete`:`toggle`}})),"data-testid":`remote-power`})})]}),b.data!==void 0&&b.data.length===0&&i(`p`,{className:`text-xs text-foreground-muted`,children:s(`remote.dialog.noTemplatesHint`)}),j!==null&&e(`div`,{className:`grid gap-3 sm:grid-cols-[minmax(0,20rem)_1fr]`,children:[i(`div`,{className:`mx-auto w-full max-w-xs`,"data-testid":`remote-preview`,children:i(us,{grid:j,label:s(`remote.dialog.preview`),boundRoles:re,selectedId:ee,onSelect:e=>_(j.buttons.find(t=>t.id===e)?.role??null)})}),e(`div`,{className:`min-w-0 space-y-2`,children:[F===void 0?i(`p`,{className:`text-xs text-foreground-muted`,"data-testid":`binding-hint`,children:s(`remote.panel.hint`)}):i(wd,{role:F,name:P(F),binding:f.bindings[F.role],devices:S,transmitters:k,testable:N.has(F.role),testResult:v[F.role]??null,onBind:e=>ae(F.role,e),onClear:()=>p(e=>Vu(e,F.role)),onTest:()=>void L(F.role)},F.role),te.length>0&&i(q,{label:s(`remote.panel.otherCommands`),description:s(`remote.panel.pickOtherHint`),children:i(H,{value:F?.inLayout===!1?F.role:``,options:[{value:``,label:s(`remote.panel.pickOther`)},...te.map(e=>({value:e.role,label:P(e)}))],onChange:e=>_(e.target.value===``?null:e.target.value),"data-testid":`binding-other`})})]})]}),f.layoutTemplateId!==null&&i(`div`,{className:`flex justify-end`,children:i(ds,{templateId:f.layoutTemplateId})}),i(qd,{config:f,onChange:p,roleLabel:e=>M.find(t=>t.role===e)?.name??ls(e,c.language),transmitters:k.map(e=>({id:e.id,label:gd(e)}))}),e(`section`,{className:`space-y-2`,children:[i(`h3`,{className:`text-sm font-medium text-foreground`,children:s(`remote.import.title`)}),i(`h4`,{className:`text-xs font-medium text-foreground-muted`,children:s(`remote.import.smartirTitle`)}),i(zd,{transmitterId:f.defaultTransmitterId,onApply:e=>p(t=>Yu(t,e))}),i(`h4`,{className:`text-xs font-medium text-foreground-muted`,children:s(`remote.flipper.title`)}),i(Rd,{transmitterId:f.defaultTransmitterId,onApply:e=>p(t=>Yu(t,e))})]}),ne.incomplete.length>0&&i(`p`,{role:`alert`,className:`text-xs text-warning`,"data-testid":`remote-incomplete`,children:s(`remote.dialog.incomplete`,{count:ne.incomplete.length})}),m!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger`,children:m})]}),e(oa,{children:[i(X,{variant:`ghost`,onClick:a,children:s(`common.cancel`)}),i(X,{disabled:ne.config===null||w.isPending,onClick:()=>void ie(),"data-testid":`remote-save`,children:s(`common.save`)})]})]})}function Zd({device:e,onClose:t}){return i(Jd,{device:e,open:!0,onClose:t})}var Qd={remote:Zd};function $d(e){return Qd[e]??null}var ef={"fan-presets":Iu};function tf(e){let t=[];for(let[n,r]of Object.entries(U))r.targets.some(t=>t.cardinality===`config`&&t.deviceTypes.includes(e))&&t.push(n);return t}function nf({device:e,onlyCap:t}){return tf(e.type).map(n=>{if(t!==void 0&&n!==t)return null;let r=ef[n];return r===void 0?null:i(r,{device:e},n)})}function rf(e){let t=new Set;for(let{cap:e}of io())t.add(e);for(let{cap:e}of Va())t.add(e);for(let{cap:e}of to())t.add(e);for(let n of tf(e))t.add(n);return t}function af(e,t){if(e===null)return[];let n=[];for(let r of Fe(e).model.cards)r.card.cardKind===`fields`&&!t.has(r.card.cap)&&n.push(r.card);return n}function of(e){switch(e.kind){case`from`:return e.sources;case`convert-unit`:return[e.source];case`formula`:return Object.values(e.bindings).flatMap(e=>e.kind===`from`?[e]:[]);case`companion`:return[]}}function sf(e){return St(e.cap,e.path)===void 0?null:`number`}function cf(e,t){return t.cap===e.cap&&t.path===e.path?2:+(t.path===e.path)}function lf(e,t,n,r){return e.filter(e=>e.entry===null&&e.item===null).map(e=>({row:e,candidates:ro(t,n,r,sf(e)).flatMap(e=>e.source===null?[]:[{cap:e.cap,path:e.path,source:e.source,value:e.value}]).map(t=>({candidate:t,score:cf(e,t)})).filter(e=>e.score>0).toSorted((e,t)=>t.score-e.score).map(e=>e.candidate)}))}c();var uf=``;function df(e,t){return`${e}.${t}`}function ff(e,t){let n=e.candidates[0];return t.get(e.row.key)??(n===void 0?uf:df(n.cap,n.path))}function pf(t){let{t:n,i18n:r}=Q(),[a,s]=o(null),[c,l]=o(new Map),u=Zr({deviceId:a,capNames:[t.cap],excludeIds:[t.device.id],fit:()=>``,capTitle:e=>jo(e,r.language),fieldLabel:(e,t)=>Wo(e,t,r.language)}),d=vn({projection:`slim`}),f=hr({deviceId:a??0},{enabled:a!==null}),p=an({deviceId:a??0},{enabled:a!==null}),m=a===null||d.data===void 0?null:qo(d.data).find(e=>e.id===a)??null,h=f.status===`success`?f.data:{caps:[]},g=m===null?[]:lf(t.rows,m,h,p.status===`success`?p.data:null),_=g.flatMap(e=>{let t=ff(e,c),n=e.candidates.find(e=>df(e.cap,e.path)===t);return n===void 0?[]:[{proposal:e,candidate:n}]});return i(hn,{open:!0,onOpenChange:e=>e?void 0:t.onClose(),children:e(zn,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t.title,children:[i(en,{children:i(pr,{children:t.title})}),i(En,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:i(kr,{testId:`fill-from-device`,devices:u.devices,listState:u.listState,deviceId:a,onDeviceChange:s,deviceLabel:m?.name??``,valuesState:f.status===`error`?`failed`:f.status===`success`?`ready`:`loading`,groups:[],value:null,onValueChange:()=>void 0,valuesOverride:i(`ul`,{className:`flex flex-col gap-2`,"data-testid":`fill-proposals`,children:g.map(e=>i(mf,{proposal:e,chosen:ff(e,c),onChoose:t=>l(new Map(c).set(e.row.key,t))},e.row.key))}),heading:n(`customize.table.fillHeading`),noDeviceText:n(`customize.table.fillNoDevice`),noValuesText:n(`customize.table.fillNothing`)})}),e(oa,{children:[i(X,{variant:`ghost`,onClick:t.onClose,children:n(`customize.table.close`)}),i(X,{"data-testid":`fill-apply`,disabled:_.length===0||t.handle.saving,onClick:()=>{let e=xo(t.handle.state),n=_.reduce((e,{proposal:n,candidate:r})=>za(e,t.handle.target,t.cap,n.row.path,r.source,[]),e);n!==null&&t.handle.save(n).then(()=>t.onClose())},children:n(`customize.table.fillApply`)})]})]})})}function mf({proposal:t,chosen:n,onChoose:r}){let{t:a,i18n:o}=Q(),s=Wo(t.row.cap,t.row.path,o.language);return e(`li`,{className:`flex flex-col gap-1 text-[11px]`,"data-testid":`fill-row-${t.row.key}`,children:[i(`span`,{className:`font-medium text-foreground`,children:s}),t.candidates.length===0?i(`span`,{className:`text-foreground-subtle`,children:a(`customize.table.fillNothing`)}):i(H,{value:n,"aria-label":s,options:[...t.candidates.map(e=>({value:df(e.cap,e.path),label:`${Wo(e.cap,e.path,o.language)} · ${String(e.value??`—`)}`})),{value:uf,label:a(`customize.table.fillSkip`)}],onChange:e=>r(e.target.value)})]})}var hf={level:`level`,status:`status`,"remaining.value":`remaining`};function gf(e,t){if(t.item===null)return Wo(t.cap,t.path,e);let n=hf[t.path],r=n===void 0?t.path:Z.t(`customize.table.itemLeaf.${n}`);return`${t.item.label} · ${r}`}function _f(e,t){return jo(t,e)}function vf(e,t,n,r){return`${t.get(Et(e.source))??r} · ${Wo(e.cap,e.fieldPath,n)}`}function yf(e,t,n,r){switch(e.kind){case`from`:return e.sources.map(e=>vf(e,t,n,r)).join(`, `);case`convert-unit`:return`${vf(e.source,t,n,r)} → ${e.to}`;case`formula`:return oo(e.expr,e.bindings,t,n,r);case`companion`:return null}}var bf={toFill:`warning`,checking:`default`,bound:`success`,notAnswering:`warning`,missing:`danger`};function xf({state:e}){let{t}=Q();return i(K,{variant:bf[e.kind],"data-testid":`field-state-${e.kind}`,children:t(`customize.table.fieldState.${e.kind}`)})}function Sf({device:e,cap:t,item:n,path:r}){let a=ir({deviceId:e.id,capName:t});if(a.status===`pending`)return i(`span`,{className:`text-xs text-foreground-subtle`,children:`…`});let o=Ba(a.data,`items`),s=Ba(Array.isArray(o)?o.find(e=>Ba(e,`key`)===n):void 0,r);return i(`span`,{className:`text-xs text-foreground`,children:typeof s==`string`||typeof s==`number`?String(s):`—`})}function Cf({device:e,row:t,state:n}){return n.kind===`toFill`?i(xf,{state:n}):t.item===null?i(Ga,{target:{deviceId:e.id,cap:t.cap,path:t.path}}):i(Sf,{device:e,cap:t.cap,item:t.item.key,path:t.path})}function wf({row:t,state:n,names:r}){let{t:a,i18n:o}=Q();return e(`span`,{className:`flex flex-wrap items-center gap-1 text-xs text-foreground`,children:[(t.entry===null?null:yf(t.entry,r,o.language,a(`customize.fieldsCard.unknownDevice`)))??i(`span`,{className:`text-foreground-subtle`,children:a(`customize.table.noSource`)}),n.kind!==`bound`&&n.kind!==`toFill`&&i(xf,{state:n})]})}function Tf({row:e,title:t,onEdit:n}){let{t:r}=Q();return e.entry===null?i(X,{variant:`outline`,size:`sm`,"data-testid":`customize-manage-${e.key}`,"aria-label":`${r(`customize.table.bind`)} ${t}`,onClick:n,children:r(`customize.table.bind`)}):i(Y,{variant:`ghost`,size:`sm`,icon:I,"aria-label":r(`customize.table.editWhat`,{title:t}),"data-testid":`customize-manage-${e.key}`,onClick:n})}function Ef({cap:t,title:n,handle:r,onFill:a}){let{t:o}=Q(),s=Wa(),c=xo(r.state);return c===null?null:e(`div`,{className:`flex items-center justify-end gap-1`,children:[a!==void 0&&i(X,{variant:`ghost`,size:`sm`,"data-testid":`customize-fill-${t}`,disabled:r.saving,onClick:a,children:o(`customize.table.fillFromDevice`)}),i(Y,{variant:`ghost`,size:`sm`,icon:E,"aria-label":`${o(`customize.table.remove`)} ${n}`,"data-testid":`customize-remove-offcatalog.${t}`,disabled:r.saving,onClick:()=>{let e=co(c,t);s(o(`customize.fieldsCard.removeWhat`,{cap:n}),e===null).then(t=>{t&&r.save(e)})}})]})}function Df({row:t,title:n,device:r,handle:a,names:o,onClose:s}){let{t:c,i18n:l}=Q(),u=Fr(r,`compact`);return i(hn,{open:!0,onOpenChange:e=>e?void 0:s(),children:e(zn,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":n,children:[i(en,{children:i(pr,{children:n})}),i(En,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:i(Zo,{deviceId:r.id,self:a.target,selfName:u,cap:t.cap,fieldPath:t.path,label:Wo(t.cap,t.path,l.language),unit:St(t.cap,t.path),handle:a,names:o,toFill:t.entry===null})}),i(oa,{children:i(X,{variant:`ghost`,onClick:s,children:c(`customize.table.close`)})})]})})}function Of(e){return/At$/.test(e)}function kf(e){return e.kind===`companion`||e.kind===`formula`&&Object.keys(e.bindings).length===0}function Af(e){return e.map(e=>{let t=new Set(Object.keys(e.entries)),n=La(e.cap,t).map(t=>({key:`${e.cap}.${t}`,cap:e.cap,path:t,entry:null,advanced:Of(t),item:null})),r=Object.entries(e.entries).map(([t,n])=>({key:`${e.cap}.${t}`,cap:e.cap,path:t,entry:n,advanced:Of(t)||kf(n),item:null})),i=[...n,...r];return{cap:e.cap,rows:i.filter(e=>!e.advanced),advanced:i.filter(e=>e.advanced)}})}function jf(e,t){if(e.entry===null)return{kind:`toFill`};let n=of(e.entry);if(n.length===0)return{kind:`bound`};if(t===null)return{kind:`checking`};let r=n.map(e=>t.get(Et(e.source))??`missing`);return r.includes(`missing`)?{kind:`missing`}:r.includes(`offline`)?{kind:`notAnswering`}:{kind:`bound`}}function Mf(e){return Object.entries(e?.items??{}).flatMap(([t,n])=>Object.entries(n.fields).filter(([,e])=>!kf(qe(e))).map(([r,i])=>({key:`${e?.cap??``}.items[${t}].${r}`,cap:e?.cap??``,path:r,entry:qe(i),advanced:!1,item:{key:t,label:n.label}})))}c();var Nf={names:new Map,presence:null};function Pf(e){let t=vn({projection:`slim`},{enabled:e});return n(()=>{if(t.data===void 0)return Nf;let e=new Map,n=new Map;for(let r of t.data){let t=Et({addonId:r.addonId,stableId:r.stableId});e.set(t,r.name),n.set(t,r.online?`answering`:`offline`)}return{names:e,presence:n}},[t.data])}function Ff({labels:t}){let{t:n}=Q(),r=so(t),a=r.labels.join(`, `),o=`${r.shown.join(`, `)}${r.truncated?`…`:``}`;return e(ai,{className:`block w-full min-w-0`,children:[i(Ti,{children:i(`span`,{className:`block truncate text-xs text-foreground`,"data-testid":`list-value-shown`,children:`${n(`customize.table.listCount`,{count:r.labels.length})}: ${o}`})}),i(Pr,{className:`whitespace-normal max-w-xs text-left`,children:a})]})}function If(){let{t:e}=Q();return i(`span`,{role:`status`,className:`text-xs text-foreground-subtle`,children:e(`customize.event.checking`)})}function Lf({reason:e}){let{t}=Q();return i(`span`,{role:`alert`,className:`text-xs text-warning`,title:e,children:t(`customize.table.unknown`)})}function Rf(e,t){return e.kind===`item`?e.item.label:t(`customize.consumables.fields.${e.key}`,{defaultValue:Oo(e.key)})}function zf({handle:e,spec:t,defaults:n}){let{t:r}=Q();if(e.state.kind===`pending`||e.state.kind===`not-loaded`)return i(If,{});if(e.state.kind===`unknown`)return i(Lf,{reason:e.state.reason});if(t.cap===`consumables`&&n.kind===`pending`)return i(If,{});if(t.cap===`consumables`&&n.kind===`unknown`)return i(Lf,{reason:n.reason});let a=Ja(xo(e.state),t.cap),o=a===null?[]:ze(a,t.cap,t.target.id)?.items??[],s=[...t.cap===`consumables`&&n.kind===`known`?n.value.map(e=>Rf(e,r)):[],...o.map(e=>e.label.trim()||e.key)];return s.length===0?i(`span`,{className:`text-xs text-foreground-subtle`,children:r(`customize.table.listNone`)}):i(Ff,{labels:s})}c();function Bf(e){let t=e.error===null?[]:[{kind:`actionError`,message:e.error}];return e.ready?e.rows.length===0?[{kind:`actionSection`},{kind:`actionEmpty`},...t]:[{kind:`actionSection`},...e.rows.map(e=>({kind:`actionEntry`,entry:e})),...t]:[{kind:`actionSection`},{kind:`actionPending`},...t]}function Vf(e){return e.kind===`actionSection`||e.kind===`actionPending`||e.kind===`actionEmpty`||e.kind===`actionError`||e.kind===`actionEntry`}function Hf(t){let{t:n}=Q(),r=l(),a=dr({}),s=ia({deviceId:t.id}),[c,u]=o(!1),[d,f]=o([]),p=()=>void r.invalidateQueries({queryKey:[[`actions`]]}),m=sr({onSuccess:p}),h=bn({onSuccess:p}),g=a.data??[],_=s.data?.actionIds??[],v=_.flatMap(e=>g.filter(t=>t.id===e)),y=g.filter(e=>!_.includes(e.id)),b=s.data!==void 0&&a.data!==void 0,x=e=>m.mutate({deviceId:t.id,actionIds:[...e]}),S=()=>{f([]),u(!0)},C=e=>f(d.includes(e)?d.filter(t=>t!==e):[...d,e]);return{ready:b,rows:v,available:y,error:m.error===null||m.error===void 0?null:m.error.message,saving:m.isPending,running:h.isPending,deviceName:t.name,openPicker:S,unlink:e=>x(_.filter(t=>t!==e)),run:e=>h.mutate({actionId:e,deviceId:t.id}),dialog:i(hn,{open:c,onOpenChange:u,children:e(zn,{placement:`sheet-on-mobile`,children:[e(en,{children:[i(pr,{children:n(`customize.linkedActions.pickTitle`,{name:t.name})}),i(er,{children:n(`customize.linkedActions.pickHint`)})]}),i(En,{children:i(`ul`,{className:`space-y-1`,children:y.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(Ji,{checked:d.includes(t.id),onChange:()=>C(t.id)}),i(`span`,{className:`flex-1`,children:t.name}),i(Uf,{entry:t})]})},t.id))})}),e(oa,{className:`flex flex-wrap gap-2`,children:[i(X,{variant:`outline`,onClick:()=>u(!1),children:n(`common.cancel`,`Cancel`)}),i(X,{disabled:d.length===0||m.isPending,onClick:()=>{x([..._,...d]),u(!1)},children:n(`customize.linkedActions.addN`,{count:d.length})})]})]})})}}function Uf({entry:e}){let{t}=Q();return e.readOnly?i(K,{variant:`info`,children:e.addonId}):i(K,{variant:`primary`,children:t(`actions.source.internal`,`Internal`)})}function Wf({children:e}){return i(`span`,{className:`text-xs text-foreground-subtle`,children:e})}function Gf({line:e}){let{t}=Q();switch(e.kind){case`actionSection`:return i(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-muted`,title:t(`customize.linkedActions.hint`),children:t(`customize.table.section.actions`)});case`actionPending`:return i(Wf,{children:t(`customize.linkedActions.loading`)});case`actionEmpty`:return i(Wf,{children:t(`customize.linkedActions.none`)});case`actionError`:return i(`span`,{role:`alert`,className:`text-xs text-danger break-words`,children:e.message});case`actionEntry`:return i(`span`,{className:`text-xs text-foreground`,children:e.entry.name})}}function Kf({line:e}){let{t}=Q();if(e.kind===`actionEntry`){let n=e.entry.steps;return n===void 0?i(Wf,{children:`—`}):i(`span`,{className:`text-xs text-foreground`,children:t(`customize.linkedActions.steps`,{count:n.length})})}return e.kind===`actionPending`?i(Wf,{children:t(`customize.linkedActions.loading`)}):null}function qf({line:e}){return e.kind===`actionEntry`?i(Uf,{entry:e.entry}):null}function Jf({line:t,state:n}){let{t:r}=Q();if(t.kind===`actionSection`&&n.ready&&n.available.length>0)return i(X,{variant:`outline`,size:`sm`,disabled:n.saving,onClick:n.openPicker,children:r(`customize.linkedActions.add`)});if(t.kind!==`actionEntry`)return null;let{entry:a}=t;return e(`span`,{className:`flex items-center justify-end gap-1`,children:[i(Y,{icon:re,variant:`ghost`,size:`sm`,"aria-label":r(`customize.linkedActions.run`,{name:a.name}),disabled:n.running,onClick:()=>n.run(a.id)}),i(Y,{icon:ce,variant:`ghost`,size:`sm`,"aria-label":r(`customize.linkedActions.unlink`,{name:a.name}),disabled:n.saving,onClick:()=>n.unlink(a.id)})]})}var Yf=U;function Xf(e,t){let n=Yf[e];return n===void 0?null:n.targets.find(e=>e.id===t)??null}function Zf({device:e,handle:t,facts:n,sensors:r,onlyCap:a}){let{t:o}=Q();return i(d,{children:to().map(s=>{if(a!==void 0&&s.cap!==a)return null;let c=s.pulse??s.span;if(c===null||!c.deviceTypes.includes(e.type))return null;let l=Xf(s.cap,c.id);if(l===null)return null;let u=o(s.pulse===null?`customize.motion.title`:`customize.doorbell.title`),d=$a(Ka(s.cap,l),n);return s.pulse===null?s.span===null?null:i(ou,{device:e,availability:d,cap:s.cap,title:u,view:s.span,sensors:r},s.cap):i(ql,{device:e,handle:t,availability:d,cap:s.cap,title:u,view:s.pulse},s.cap)})})}function Qf(t){let{t:n}=Q(),{spec:r,device:a,handle:o}=t,s=r.kind===`config`?$d(r.cap):null;return s===null?i(hn,{open:!0,onOpenChange:e=>e?void 0:t.onClose(),children:e(zn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t.title,children:[i(en,{children:i(pr,{children:t.title})}),e(En,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[r.kind===`event`&&i(Zf,{device:a,handle:o,facts:t.facts,sensors:t.sensors,onlyCap:r.cap}),r.kind===`keyed`&&i(Ha,{device:a,handle:o,facts:t.facts,defaults:t.defaults,onlyCap:r.cap}),r.kind===`config`&&i(nf,{device:a,onlyCap:r.cap})]}),i(oa,{children:i(X,{variant:`ghost`,onClick:t.onClose,children:n(`customize.table.close`)})})]})}):i(s,{device:a,onClose:t.onClose})}c();function $f({handle:t}){let{t:n}=Q(),[r,a]=o(null),s=ue(),c=xo(t.state),l=tl(c);if(c===null||!l.offered)return null;let u=async e=>{if(e&&l.discardsRule&&!await s({title:n(`customize.followSwitch.discardTitle`),message:n(`customize.followSwitch.discardMessage`),confirmLabel:n(`customize.followSwitch.discardConfirm`),variant:`danger`}))return;let r=await t.save(nl(c,e));a(r.kind===`refused`?r.reason:null)};return e(`span`,{className:`flex flex-col gap-0.5`,children:[i(`span`,{className:`flex items-center gap-2 text-xs text-foreground`,children:i(Lr,{checked:l.following,disabled:t.saving,label:n(`customize.followSwitch.label`),"data-testid":`follow-switch-toggle`,onCheckedChange:e=>void u(e)})}),r!==null&&i(`span`,{role:`alert`,className:`text-[11px] text-danger`,children:r})]})}var ep=864e5;function tp({state:t,onApply:n}){let{t:r}=Q();return e(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-foreground`,"data-testid":`running-proposal`,children:[i(`span`,{className:`text-foreground-muted`,children:r(`customize.scalar.proposal.label`)}),t.kind===`pending`&&i(`span`,{children:`…`}),t.kind===`error`&&i(`span`,{className:`text-warning`,children:r(`customize.scalar.proposal.error`)}),t.kind===`answer`&&t.proposal.state===`proposal`&&i(np,{proposal:t.proposal,onApply:n}),t.kind===`answer`&&t.proposal.state===`insufficient`&&e(`span`,{children:[r(`customize.scalar.proposal.reason.${t.proposal.reason}`),` `,t.proposal.fallback.kind===`threshold`&&r(`customize.scalar.proposal.defaults`,{threshold:t.proposal.fallback.threshold,start:rp(r,t.proposal.fallback.startDwellMs),stop:rp(r,t.proposal.fallback.stopDwellMs)})]})]})}function np(t){let{t:n}=Q(),{transform:r,evidence:a,confidence:o}=t.proposal;return e(d,{children:[i(`span`,{children:n(`customize.scalar.proposal.summary`,{runs:a.runsFound,days:Math.max(1,Math.round(a.spanMs/ep)),threshold:r.threshold,start:rp(n,r.startDwellMs),stop:rp(n,r.stopDwellMs)})}),i(`span`,{className:`text-foreground-muted`,children:n(`customize.scalar.proposal.confidence.${o}`)}),i(X,{size:`sm`,variant:`outline`,"data-testid":`running-proposal-apply`,onClick:()=>t.onApply(r),children:n(`customize.scalar.proposal.apply`)})]})}function rp(e,t){let{unit:n,n:r}=Co(t);return e(`customize.scalar.proposal.${n}`,{n:r})}function ip(e){let t=Lo(e);if(t===null)return{kind:`failed`,reason:Ko};if(e.transform.kind===`threshold`)return ap(e.transform,e);let n=po(e.cap,e.targetId),r=n===null?void 0:t.fields[n];if(r===void 0)return{kind:`failed`,reason:Ko};if(r.kind===`from`)return sp(e.sourceValue);if(r.kind!==`expression`)return{kind:`failed`,reason:Ko};if(r.expr.startsWith(`dwell(`))return{kind:`failed`,reason:Xo};let i=op(e.sourceValue);if(i===void 0)return{kind:`failed`,reason:Yo};let a=rt(r.expr,{x:i},e.nowMs);return a.ok?sp(a.value):{kind:`failed`,reason:a.error}}function ap(e,t){if(typeof t.sourceValue!=`number`||!Number.isFinite(t.sourceValue))return{kind:`failed`,reason:Yo};let n=e.comparison===`gte`?t.sourceValue>=e.threshold:t.sourceValue<=e.threshold,r=t.source.sourceUnit;return{kind:`dwell`,sourceText:r===null?String(t.sourceValue):`${t.sourceValue} ${r}`,active:n,countdownMs:n?e.startDwellMs:e.stopDwellMs}}function op(e){if(typeof e==`number`||typeof e==`string`||typeof e==`boolean`)return e;if(e===null)return null}function sp(e){return e==null||typeof e==`number`&&!Number.isFinite(e)?{kind:`failed`,reason:go}:typeof e==`number`||typeof e==`string`||typeof e==`boolean`?{kind:`value`,text:String(e)}:{kind:`failed`,reason:go}}c();function cp(t){let{t:n}=Q(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(hn,{open:t.open,onOpenChange:e=>e?void 0:t.onClose(),children:e(zn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(en,{children:i(pr,{children:r})}),t.open&&i(lp,{...t,heading:r})]})})}function lp(t){let{t:r}=Q(),a=vn({projection:`slim`}),s=n(()=>a.status===`success`?qo(a.data):[],[a.status,a.data]),c=fp(t.seed,s),[l,u]=o(null),[f,p]=o(!1);!f&&c!==null&&(u(c),p(!0));let m=hr({deviceId:l?.id??0}),h=an({deviceId:l?.id??0}),g=m.status===`success`?m.data:{caps:[]},_=wo(g,h.status===`success`?h.data:null),[v,y]=o(pp(t.seed)),[b,x]=o(t.seed?.transform??{kind:`identity`}),S=v===null?null:(()=>{let[e,t]=v.split(`.`);return e===void 0||t===void 0?null:{cap:e,path:t}})(),C=_.find(e=>up(e)===v)??null,w=C===null?null:Eo(t.cap,t.targetId,C),T=C===null||w===null||!w.ok?null:dp(l,C,w,g),E=T===null?null:Lo({cap:t.cap,targetId:t.targetId,device:t.target,apply:t.apply,source:T,transform:b}),D=C===null||h.status!==`success`||l===null?void 0:Ba(h.data[C.cap],C.path),O=T===null?null:h.status===`pending`?{kind:`pending`}:ip({cap:t.cap,targetId:t.targetId,device:t.target,apply:t.apply,source:T,transform:b,sourceValue:D,nowMs:Date.now()}),k=t.cap===`running-state`&&b.kind===`threshold`&&T!==null&&T.valueKind===`number`&&l!==null,A=Oi({deviceId:l?.id??0,cap:T?.cap??`-`,fieldPath:T?.fieldPath??`-`,deviceType:t.host.type},{enabled:k,retry:!1}),j=k?A.status===`success`?{kind:`answer`,proposal:A.data}:A.status===`error`?{kind:`error`}:{kind:`pending`}:null;return e(d,{children:[i(En,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:i(mo,{kind:`scalar`,enabled:t.open,hostId:t.host.id,destination:{cap:t.cap,targetId:t.targetId,title:t.title},device:l,field:S,transform:b,onDeviceChange:e=>{u(e),y(null),x({kind:`identity`})},onFieldChange:e=>{if(e===null){y(null);return}y(`${e.cap}.${e.path}`)},onTransformChange:x,preview:O===null?void 0:i(Xa,{preview:O}),proposal:j===null?void 0:i(tp,{state:j,onApply:e=>x(No(e,bo(t.host.type)))})})}),e(oa,{className:`flex flex-wrap gap-2`,children:[i(X,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(X,{"data-testid":`scalar-save-override`,disabled:!t.canSave||E===null,onClick:()=>{E!==null&&t.onSave(E)},children:r(`customize.scalar.save`)})]})]})}function up(e){return`${e.cap}.${e.path}`}function dp(e,t,n,r){if(e===null||t.kind!==`boolean`&&t.kind!==`number`&&t.kind!==`string`)return null;let i=r.caps.find(e=>e.cap===t.cap),a=t.kind===`boolean`&&i?.fields.some(e=>e.path===`lastChangedAt`)?`lastChangedAt`:null;return{addonId:e.addonId,stableId:e.stableId,cap:t.cap,fieldPath:t.path,valueKind:t.kind,sourceUnit:n.sourceUnit,changedAtField:a}}function fp(e,t){return e===null?null:t.find(t=>t.addonId===e.source.addonId&&t.stableId===e.source.stableId)??null}function pp(e){return e===null?null:`${e.source.cap}.${e.source.fieldPath}`}function mp({device:e,cap:t,target:n}){return i(Ga,{target:{deviceId:e.id,cap:t,path:n.path??n.id}})}function hp(e,t){return t.badge.kind===`assigned`?e(`customize.scalar.badge.assigned`,{source:t.badge.source}):e(`customize.scalar.badge.${t.badge.kind}`)}function gp(t){let n=i(_p,{...t});return el(t.cap,t.target.id)?e(`span`,{className:`flex flex-col gap-1`,children:[n,i($f,{handle:t.handle})]}):n}function _p(t){let{t:n}=Q(),r=dl(t.device,t.handle,t.cap,t.target);return r.recognized&&!r.released?e(`span`,{className:`flex flex-col gap-0.5`,children:[i(`span`,{className:`text-xs text-foreground`,children:n(`customize.table.sourceOf`,{name:r.sourceName??`…`,field:r.sourceField})}),r.presence===`unknown`&&i(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:n(`customize.scalar.sourceUnreadable`)})]}):r.released?i(K,{variant:`warning`,children:n(`customize.table.sourceMissing`)}):r.otherFormula&&r.stored.kind===`known`&&r.stored.value!==null?i(vp,{feature:r.stored.value,path:r.path}):el(t.cap,t.target.id)&&tl(xo(t.handle.state)).offered&&r.stored.kind===`known`&&r.stored.value===null?i(`span`,{className:`text-xs text-foreground`,children:n(`customize.followSwitch.default`)}):i(K,{children:hp(n,r)})}function vp({feature:e,path:t}){let{t:n,i18n:r}=Q(),a=e.fields[t],o=Pf(a!==void 0);if(a===void 0)return null;let s=n(`customize.fieldsCard.unknownDevice`),c=a.kind===`expression`?Object.keys(a.bindings).length===0?n(`customize.table.fixedValue`,{value:a.expr}):n(`customize.table.formulaOf`,{formula:oo(a.expr,a.bindings,o.names,r.language,s)}):a.kind===`from`?n(`customize.table.sourceOf`,{name:o.names.get(Et(a.source))??s,field:Wo(a.cap,a.fieldPath,r.language)}):n(`customize.table.otherFormula`);return i(`span`,{className:`text-xs text-foreground`,"data-testid":`scalar-formula-${e.cap}`,children:c})}function yp(t){let{t:n}=Q(),r=dl(t.device,t.handle,t.cap,t.target),a=`${t.cap}.${t.target.id}`,o=el(t.cap,t.target.id)&&tl(xo(t.handle.state)).offered;return e(`span`,{className:`flex items-center justify-end gap-1`,children:[(r.recognized||o)&&i(Y,{variant:`ghost`,size:`sm`,icon:I,"aria-label":n(`customize.table.editWhat`,{title:r.title}),"data-testid":`scalar-change-${a}`,disabled:r.saving,onClick:t.onEdit}),r.otherFormula&&!o&&i(Za,{icon:!0,handle:t.handle,cap:t.cap,fieldPath:r.path,label:n(`customize.table.editWhat`,{title:r.title}),testId:`scalar-change-${a}`}),(r.recognized||r.otherFormula)&&i(Y,{variant:`ghost`,size:`sm`,icon:E,"aria-label":`${n(`customize.table.remove`)} ${r.title}`,"data-testid":`scalar-remove-${a}`,disabled:r.saving,onClick:()=>void r.remove().then(t.onError)})]})}function bp(e){let t=dl(e.device,e.handle,e.cap,e.target);return i(cp,{open:!0,mode:t.seed===null?`add`:`change`,title:t.title,cap:e.cap,targetId:e.target.id,host:e.device,target:e.handle.target,apply:e.mode,seed:t.seed,canSave:t.answered&&!t.saving,onClose:e.onClose,onSave:n=>{e.onClose(),t.saveFeature(n).then(e.onError)}})}c();function xp(e){switch(e.kind){case`section`:return`section:${e.section}`;case`row`:return e.plan.spec.key;case`capSection`:return`capSection:${e.cap}`;case`field`:return`field:${e.row.key}`;case`advanced`:return`advanced:${e.cap}`;case`actionSection`:return`action-section`;case`actionPending`:return`action-pending`;case`actionEmpty`:return`action-empty`;case`actionError`:return`action-error`;case`actionEntry`:return`action:${e.entry.id}`}}function Sp(e,t,n,r,i){let a=bl(e).flatMap(t=>[{kind:`section`,section:t},...e.filter(e=>e.spec.section===t).flatMap(e=>[{kind:`row`,plan:e},...e.spec.kind===`keyed`?r(e.spec.cap):[]])]),o=t.flatMap(e=>[{kind:`capSection`,cap:e.cap},...e.rows.map(e=>({kind:`field`,row:e})),...e.advanced.length===0?[]:[{kind:`advanced`,cap:e.cap,rows:e.advanced}],...n.has(e.cap)?e.advanced.map(e=>({kind:`field`,row:e})):[]]);return[...a,...o,...i]}function Cp(e){return e.device.type===G.Camera?i(wp,{...e}):i(Tp,{...e,actions:null})}function wp(e){let t=Hf(e.device);return i(Tp,{...e,actions:t})}function Tp(t){let{device:r,handle:a,facts:s,actions:c}=t,{t:l,i18n:u}=Q(),[d,f]=o(null),[p,m]=o(null),h=a.state.kind===`none`||a.state.kind===`present`,g=xo(a.state),_=t.defaults.kind===`known`&&t.defaults.value.length>0,v=n(()=>_l(r.type),[r.type]),y=e=>{switch(e.kind){case`scalar`:return cl(a,e.cap,e.target.id)!==null||rl(e.cap,e.target.id,g);case`keyed`:return Ja(g,e.cap)!==null||_;case`event`:return e.target.applyAuthority?.kind===`camera-sensors`?!0:Ja(g,e.cap)!==null;case`config`:return!0}},b=n(()=>af(g,rf(r.type)),[g,r.type]),x=n(()=>Af(b),[b]),S=Pf(x.length>0),[C,w]=o(new Set),T=e=>w(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),E=yl(vl(v,s,y)),D=c===null?[]:Bf(c);if(v.length===0&&x.length===0&&D.length===0)return null;let O=e=>e.kind===`scalar`?ul(l,u.language,e.cap,e.target):l(`customize.table.caps.${e.cap}`),k=[...E.active,...E.addable].find(e=>e.spec.key===d),A=Sp(E.active,x,C,e=>Mf(Ja(g,e)).map(e=>({kind:`field`,row:e})),D),j=x.flatMap(e=>[...e.rows,...e.advanced]).find(e=>e.key===d),M=e=>(x.find(t=>t.cap===e)?.rows??[]).filter(e=>e.entry===null),N=x.find(e=>`fill:${e.cap}`===d),P=e=>({cap:e.cap,target:e.target}),F=[{key:`item`,header:l(`customize.table.col.item`),notSortableReason:l(`customize.table.col.item`),nowrap:!1,render:t=>{if(Vf(t))return i(Gf,{line:t});if(t.kind===`section`||t.kind===`capSection`)return i(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-muted`,children:t.kind===`section`?l(`customize.table.section.${t.section}`):_f(u.language,t.cap)});if(t.kind===`advanced`)return i(X,{variant:`ghost`,size:`sm`,className:`whitespace-nowrap`,"data-testid":`customize-advanced-${t.cap}`,"aria-expanded":C.has(t.cap),onClick:()=>T(t.cap),children:l(`customize.table.advanced`,{count:t.rows.length})});let n=t.kind===`row`?`customize.scalar.hints.${t.plan.spec.cap}`:``,r=t.kind===`row`&&u.exists(n)?l(n):null;return e(`span`,{className:`flex flex-col gap-0.5`,children:[i(`span`,{className:`text-xs text-foreground`,children:t.kind===`row`?O(t.plan.spec):gf(u.language,t.row)}),r!==null&&i(`span`,{className:`text-[11px] text-foreground-muted`,children:r})]})}},{key:`value`,header:l(`customize.table.col.value`),notSortableReason:l(`customize.table.col.value`),render:e=>{if(Vf(e))return i(Kf,{line:e});if(e.kind===`section`||e.kind===`capSection`||e.kind===`advanced`)return null;if(e.kind===`field`)return i(Cf,{device:r,row:e.row,state:jf(e.row,S.presence)});let{spec:n}=e.plan;return n.kind===`scalar`?i(mp,{device:r,handle:a,...P(n)}):n.kind===`keyed`?i(zf,{device:r,handle:a,spec:n,defaults:t.defaults}):n.kind===`event`?i(hu,{spec:n,device:r,handle:a,sensors:t.sensors}):i(wl,{spec:n,device:r})}},{key:`source`,header:l(`customize.table.col.source`),notSortableReason:l(`customize.table.col.source`),nowrap:!1,render:e=>{if(Vf(e))return i(qf,{line:e});if(e.kind===`section`||e.kind===`capSection`||e.kind===`advanced`)return null;if(e.kind===`field`)return i(wf,{row:e.row,state:jf(e.row,S.presence),names:S.names});let{spec:n}=e.plan;return n.kind===`event`?i(gu,{spec:n,device:r,handle:a,sensors:t.sensors}):n.kind===`config`?i(Tl,{spec:n,device:r}):n.kind===`scalar`?i(gp,{device:r,handle:a,...P(n)}):i(`span`,{className:`text-xs text-foreground-subtle`,children:`—`})}},{key:`actions`,headerRender:()=>i(`span`,{className:`sr-only sm:not-sr-only`,children:l(`customize.table.col.actions`)}),notSortableReason:l(`customize.table.col.actions`),align:`right`,width:`w-px`,render:e=>{if(Vf(e))return c===null?null:i(Jf,{line:e,state:c});if(e.kind===`section`||e.kind===`advanced`)return null;if(e.kind===`capSection`)return i(Ef,{cap:e.cap,title:_f(u.language,e.cap),handle:a,onFill:M(e.cap).length===0?void 0:()=>f(`fill:${e.cap}`)});if(e.kind===`field`)return i(Tf,{row:e.row,title:gf(u.language,e.row),onEdit:()=>f(e.row.item===null?e.row.key:`${e.row.cap}.items`)});let{spec:t}=e.plan;return t.kind===`scalar`?i(yp,{device:r,handle:a,...P(t),onEdit:()=>f(t.key),onError:m}):i(Y,{variant:`ghost`,size:`sm`,icon:I,"aria-label":l(`customize.table.editWhat`,{title:O(t)}),"data-testid":`customize-manage-${t.key}`,onClick:()=>f(t.key)})}}];return e(Ln,{headingId:`customize-table`,icon:we,title:l(`customize.table.title`),testId:`customize-table`,actions:i(Ep,{rows:E.addable,titleOf:O,disabled:!h||a.saving,onPick:e=>f(e)}),children:[e(`div`,{className:`flex flex-col gap-2 p-2 sm:p-3`,children:[!h||E.pending?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:l(`customize.scalar.checking`)}):null,E.unknownReason!==null&&i(J,{title:l(`customize.scalar.unreadable`),message:E.unknownReason}),p!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:p}),h&&A.length>0&&i(aa,{columns:F,rows:A,rowKey:xp,bordered:!1,minWidthPx:320,rowClassName:e=>e.kind===`section`||e.kind===`capSection`||e.kind===`actionSection`?`bg-surface-hover`:void 0}),h&&A.length===0&&!E.pending&&E.unknownReason===null&&i(`p`,{className:`text-xs text-foreground-subtle`,children:l(E.addable.length>0?`customize.table.empty`:`customize.table.nothingToAdd`)})]}),k!==void 0&&k.spec.kind===`scalar`&&k.availability.kind===`present`&&i(bp,{device:r,handle:a,...P(k.spec),mode:k.availability.mode,onClose:()=>f(null),onError:m},k.spec.key),j!==void 0&&i(Df,{row:j,title:gf(u.language,j),device:r,handle:a,names:S.names,onClose:()=>f(null)},j.key),N!==void 0&&i(pf,{cap:N.cap,title:l(`customize.table.fillTitle`,{cap:_f(u.language,N.cap)}),rows:M(N.cap),device:r,handle:a,onClose:()=>f(null)},N.cap),c?.dialog,k!==void 0&&k.spec.kind!==`scalar`&&i(Qf,{spec:k.spec,title:O(k.spec),device:r,handle:a,facts:s,sensors:t.sensors,defaults:t.defaults,onClose:()=>f(null)},k.spec.key)]})}function Ep({rows:t,titleOf:n,disabled:r,onPick:a}){let{t:o}=Q();return t.length===0?null:e(Wn,{children:[i(Tn,{className:`h-7 px-2.5 text-xs rounded-md border border-border bg-surface text-foreground`,disabled:r,"aria-label":o(`customize.table.addAria`),"data-testid":`customize-table-add`,children:o(`customize.table.add`)}),i(Jn,{children:t.map(e=>i(fn,{"data-testid":`customize-table-add-${e.spec.key}`,onClick:()=>a(e.spec.key),children:n(e.spec)},e.spec.key))})]})}function Dp({id:t,icon:n,title:r,headerControl:a,addLabel:o,onAdd:s,addDisabled:c=!1,notices:l,suggestion:u,children:f}){let{t:p}=Q(),m=s!==void 0&&o!==void 0;return e(Do,{id:t,icon:n,title:r,actions:e(d,{children:[a,m&&!c&&u!==void 0&&u.count>0&&e(X,{variant:`ghost`,size:`sm`,onClick:u.onOpen,children:[i(Se,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),p(`customize.suggest.hint`,{count:u.count,location:u.location})]}),m&&i(X,{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();function Op(e,t){let r=typeof e==`string`&&e.length>0,i=Po(t&&r);return n(()=>t?Jo(i,e):null,[t,i,e])}function kp({name:t,deviceId:n,detail:r,children:a}){return e(`div`,{className:`flex flex-col min-w-0`,children:[i(`span`,{className:`truncate text-xs text-foreground`,children:t??`#${n}`}),r!==null&&i(`span`,{className:`truncate text-[11px] text-foreground-subtle`,children:r}),a]})}c();function Ap({camera:t,deviceId:n}){let{t:r}=Q(),a=l(),s=ei({deviceId:t.id}),c=jr(),[u,d]=o(!1),[f,p]=o(null),m=bs({status:s.status,data:s.data,error:s.error===null||s.error===void 0?null:{message:s.error.message}}),h=m.kind===`present`?gs(m.slot,m.value,n):null,g=s.isFetching,_=async e=>{if(!(m.kind!==`present`||u||g)){d(!0),p(null);try{await c.mutateAsync({deviceId:t.id,slotRef:m.slot.slotRef,value:xs(m.value,n,e)}),await s.refetch(),await a.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){p(e instanceof Error?e.message:String(e))}finally{d(!1)}}};return e(`div`,{className:`flex flex-col items-end gap-0.5`,children:[i(Lr,{checked:h?.linked??!1,disabled:m.kind!==`present`||u||g||h?.implied===!0,"aria-label":r(`customize.linked.linkTo`,{name:t.name}),onCheckedChange:e=>void _(e)}),m.kind===`pending`&&i(`span`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(`customize.assign.checking`)}),m.kind===`unknown`&&i(`span`,{role:`alert`,className:`text-[11px] text-warning break-words text-right`,children:r(`customize.assign.unknown`,{reason:m.reason})}),m.kind===`absent`&&i(`span`,{role:`alert`,className:`text-[11px] text-warning break-words text-right`,children:r(`customize.assign.unknown`,{reason:r(`customize.assign.none`)})}),h?.implied===!0&&i(`span`,{className:`text-[11px] text-foreground-subtle text-right`,children:r(`customize.linked.impliedByStructure`)}),f!==null&&i(`span`,{role:`alert`,className:`text-[11px] text-danger break-words text-right`,children:f})]})}function jp({device:t}){let{t:n}=Q(),r=Po(!0),a=r.kind===`known`?r.value.filter(e=>ys(`linked-devices`,e.type)===`host`):[],o=[{key:`camera`,header:n(`customize.linked.camera`),cell:e=>i(kp,{name:e.name,deviceId:e.id,detail:Qo(e.integration,e.location)})},{key:`linked`,header:n(`customize.linked.linkedColumn`),cellClassName:`text-right`,headerClassName:`text-right`,cell:e=>i(Ap,{camera:e,deviceId:t.id})}];return i(Dp,{id:`linked`,icon:_,title:n(`customize.linked.reverseTitle`),notices:r.kind===`pending`?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.assign.checking`)}):r.kind===`unknown`?i(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:n(`customize.assign.devicesUnreadable`,{reason:r.reason})}):null,children:r.kind===`known`&&e(`li`,{className:`list-none px-3 py-2 sm:px-4`,children:[a.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`customize.linked.noCameras`)}):i(gr,{mode:`generic`,items:a,getKey:e=>String(e.id),getSearchText:e=>[e.name,e.location??``,String(e.id)].join(` `),columns:o,searchPlaceholder:n(`customize.assign.search`),emptyLabel:n(`customize.linked.noCameras`)}),i(`p`,{className:`mt-2 text-[10px] text-foreground-subtle`,children:n(`customize.linked.reverseHint`)})]})})}c();function Mp(e){return e==null?null:e.message}function Np({device:e}){let t=ys(`linked-devices`,e.type);return t===`host`?i(Pp,{device:e}):t===`guest`?i(jp,{device:e}):null}function Pp({device:t}){let n=ke(),{t:r}=Q(),a=l(),s=Wa(),[c,u]=o(!1),[f,p]=o(!1),[m,h]=o(null),g=ei({deviceId:t.id},{enabled:!0}),v=bs({status:g.status,data:g.data,error:Mp(g.error)===null?null:{message:Mp(g.error)??``}}),y=v.kind===`present`?v.slot.slotRef:``,b=v.kind===`present`?[...vs(v.slot,v.value).map(e=>e.deviceId),...ms(v.slot,v.value)]:[],x=jr(),S=Po(v.kind===`present`&&(c||b.length>0)),C=Op(t.location,v.kind===`present`),w=ni({deviceId:t.id,slotRef:y},{enabled:(c||C!==null)&&v.kind===`present`});if(v.kind===`absent`)return null;if(v.kind!==`present`)return i(Dp,{id:`linked`,icon:_,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:Qo(n.integration,n.location),orphan:t}},k=[...vs(v.slot,T).map(e=>O(e,!1)),...ms(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:Mp(w.error)??r(`helpers.customize.requestFailed`)}:S.kind===`pending`||w.status===`pending`||w.data===void 0?{kind:`pending`}:{kind:`known`,value:Ss(w.data.candidates,E,A)},M=async e=>{if(f){h(r(`customize.saveInFlight`));return}p(!0),h(null);try{await x.mutateAsync({deviceId:t.id,slotRef:v.slot.slotRef,value:e}),await g.refetch(),await a.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}},N=async e=>{await s(r(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await M(Cs(T,e.deviceId))},P=[{key:`device`,header:r(`customize.linked.device`),cell:t=>e(kp,{name:t.name,deviceId:t.deviceId,detail:t.detail,children:[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?`—`:pi(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(Lr,{checked:e.tracked,disabled:f,"aria-label":r(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void M(_s(T,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:i(Y,{icon:ce,variant:`ghost`,size:`sm`,"aria-label":r(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:f,onClick:t=>{t.stopPropagation(),N(e)}})}];return e(d,{children:[i(Dp,{id:`linked`,icon:_,title:r(`customize.linked.title`),addLabel:r(`customize.linked.add`),onAdd:f?void 0:()=>u(!0),...C===null?{}:{suggestion:{count:no(j,C,e=>e.deviceId),location:C.location,onOpen:()=>u(!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})}),m!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),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(gr,{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:pi(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(ho,{open:c,title:r(`customize.linked.pickTitle`),selection:`multi`,candidates:j,room:C,confirmLabel:e=>r(`customize.assign.addCount`,{count:e}),onConfirm:e=>{u(!1),M(hs(T,e.map(e=>e.deviceId)))},onClose:()=>u(!1)})]})}var Fp={"linked-devices":Np};function Ip({device:e}){return i(d,{children:Me.filter(t=>ys(t,e.type)!==null).map(t=>{let n=Fp[t];return i(n,{device:e},t)})})}c();function Lp(e){return e instanceof Error?e.message:String(e)}function Rp(e){let n=Ci({addonId:e.addonId,stableId:e.stableId}),r=Ia(),i=qi(),a=Xn(),s=Ho({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}}),{t:c}=Q(),l=t(!1),[u,d]=o(!1),f=async e=>{let t=Ro(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:Lp(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 zp=`pipeline-orchestrator`;function Bp(e){return e.data===void 0?e.status===`pending`?`pending`:e.status===`error`?`unknown`:`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function Vp(e,t){return e===`absent`?`absent`:Bp(t)}async function Hp(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function Up(e,t){let n=Dr(zp),r=Qi({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>Hp(r.refetch),a=r.data===void 0&&r.status===`error`?r.error?.message??null:null;return t?{presence:Vp(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 Wp(e,t){let n=ci({deviceType:e.type}),r=$n({deviceId:e.id}),i=hr({deviceId:e.id}),a=zo(n,e=>new Set(e.caps.map(e=>e.cap))),o=zo(r,e=>Ua(e.entries)),s=zo(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}function Gp(e,t,n){let r=t.kind===`known`&&t.value.has(`consumables`),i=ao(r?{deviceId:e,cap:Qa,path:ko}:null);return Ra(t,n,r?i:null)}function Kp(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 qp(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 Jp({draft:t,device:n,onEdit:r}){let{t:a,i18n:o}=Q(),s=pa(),c=Ao(t),l=qp(t,e=>a(e));return i(Ln,{headingId:`helper-summary-${n.id}`,title:a(`customize.composed.helper.title`),testId:`helper-summary`,actions:e(X,{variant:`outline`,size:`sm`,onClick:r,"data-testid":`helper-summary-edit`,children:[i(I,{className:`h-3 w-3`,"aria-hidden":!0}),a(`common.edit`)]}),children:e(`div`,{className:v,children:[i(Qn,{label:a(`customize.composed.helper.function`),children:Kp(t,e=>a(e))}),l.map(e=>i(Qn,{label:e.label,children:e.value},e.label)),c.length>0&&i(Qn,{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(Ii,{device:n,form:`compact`}),i(`span`,{className:`text-foreground-muted`,children:Wo(t.cap,t.fieldPath,o.language)})]},`${t.source.addonId}:${t.source.stableId}:${t.cap}:${t.fieldPath}`)})})})]})})}c();function Yp({device:t}){let{t:n}=Q(),r=t.stableId.startsWith(`composed-`)?t.stableId.slice(_t.length):null,a=Ui({blockId:r??``},{enabled:r!==null}),s=qi(),[c,l]=o(!1),u=Wp(t,null),f=Up(t.id,!1),p=Gp(t.id,u.nativeCaps,u.wireable);if(r===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:n(`customize.composed.missingBlock`)});if(a.status===`pending`)return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.loadingDevice`)});if(a.status===`error`)return i(J,{title:n(`customize.composed.loadFailed`),message:a.error.message,onRetry:()=>void a.refetch()});if(a.data.state===`not-loaded`)return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.status.notLoaded`,{reason:a.data.reason})});let m=a.data.view;if(m===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:n(`customize.composed.notFound`)});let h=je(m.block);if(h===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:n(`compositionEditor.notComposition`)});let g={target:{addonId:t.addonId,stableId:t.stableId},state:{kind:`present`,view:m,composition:h},saving:s.isPending,save:async e=>{let t=e??{...h,features:[]};try{return await s.mutateAsync({blockId:m.block.id,expectedUpdatedAt:m.block.updatedAt,block:{composition:t}}),await a.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:e instanceof Error?e.message:String(e)}}}},_={deviceType:t.type,composable:u.composable,nativeCaps:u.nativeCaps,cameraSensors:`absent`},v=So(h)?_o(h.helper,t.name,t.location??``):null;return e(`div`,{className:`flex flex-col gap-3`,children:[i(Yc,{device:t}),So(h)&&v===null&&i(`p`,{role:`alert`,children:n(`helper.unreadable`)}),v!==null&&e(d,{children:[i(Jp,{draft:v,device:t,onEdit:()=>l(!0)}),i(Na,{blockId:c?m.block.id:null,onClose:()=>{l(!1),a.refetch()}})]}),eo(h)===`incomplete`&&i(K,{variant:`warning`,children:n(`customize.blockStatus.incomplete`)}),i(Cp,{device:t,handle:g,facts:_,sensors:f,defaults:p}),i(Ip,{device:t})]})}function Xp({deviceId:e}){let{t}=Q(),n=fr({deviceId:e}),r=n.data;if(r==null)return n.status===`error`?i(J,{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(Yp,{device:r}):i(Zp,{device:r,target:{addonId:r.addonId,stableId:r.stableId}});return i(ha,{deviceId:r.id,seed:{name:r.name,location:r.location??``,role:r.role??null,display:r.display},children:a})}function Zp({device:t,target:n}){let r=Rp(n),a=Dr(`composer`),{t:o}=Q(),s=Up(t.id,t.type===G.Camera),c=Wp(t,xo(r.state)),l=Gp(t.id,c.nativeCaps,c.wireable),u={deviceType:t.type,composable:c.composable,nativeCaps:c.nativeCaps,cameraSensors:s.presence};return e(`div`,{className:`flex flex-col gap-3`,children:[i(Yc,{device:t}),a===`absent`&&i(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.composerAbsent`)}),r.state.kind!==`none`&&i(Qp,{state:r.state}),i(Cp,{device:t,handle:r,facts:u,sensors:s,defaults:l}),i(Ip,{device:t})]})}function Qp({state:t}){let{t:n}=Q();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(J,{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(K,{variant:r.status===`running`?`success`:r.status===`failed`?`danger`:`warning`,children:n(`customize.blockStatus.${r.status}`)}),!r.enabled&&i(K,{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 $p=`overview`;function em(e,t){return e.some(e=>e.id===t)?t:$p}function tm({deviceId:t}){let{t:n}=Q(),r=l(),a=Number.isFinite(t),{data:o}=fr({deviceId:t},{enabled:a}),s=typeof o?.type==`string`?o.type:`camera`;wi([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:c,isLoading:u,isError:d,error:f}=$n({deviceId:t},{enabled:a}),{data:p}=Pn({deviceType:s},{enabled:!!s}),m=ta({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(Wt,{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(nm,{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(rm,{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(im,{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(va,{i18nKey:`device.bindingsTab.boundSummary`,count:_.length,values:{bound:v},components:{b:i(`span`,{className:`font-medium text-foreground`}),em:i(`em`,{})}})}),i(aa,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function nm({kind:t}){let{t:n}=Q();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(N,{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(Jt,{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(_,{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(le,{className:`h-3 w-3`}),n(`common.unbound`)]})}function rm({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 im({wrappers:t,activeWrapperId:n,disabled:r,onPick:a}){let{t:o}=Q();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(X,{variant:`unstyled`,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?C:ge,{className:`h-3 w-3`}),t]},t)})})}function am({deviceId:t,activeSubTab:n,onSubTabChange:r,deviceType:a,isAdmin:o}){return e(`div`,{className:`flex flex-col gap-3`,children:[Ea(a,o)&&i(lr,{deviceId:t,readOnly:!0}),i(ua,{deviceId:t,activeSubTab:n,onSubTabChange:r})]})}c();var om=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function sm(e){let t=l(),n=rr({deviceId:e},{refetchOnMount:`always`}),i=_n(),[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:om})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await t.invalidateQueries({queryKey:om})}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 cm=`object-detection`;function lm(e){return[e.addonId,...e.children.flatMap(lm)]}function um(e,t){if(e===`pipeline`)return new Set;let n=dm(t,cm);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:lm(n))}function dm(e,t){for(let n of e){if(n.addonId===t)return n;let e=dm(n.children,t);if(e!==void 0)return e}}function fm(e,t){return e===`onboard`?Z.t(`helpers.detectionSourceModel.badgeCameraAi`):t===`object-detection`?Z.t(`helpers.detectionSourceModel.badgeNoRoot`):Z.t(`helpers.detectionSourceModel.badgeIdle`)}function pm(e){switch(e){case`pipeline`:return Z.t(`helpers.detectionSourceModel.explainPipeline`);case`onboard`:return Z.t(`helpers.detectionSourceModel.explainOnboard`);case`none`:return Z.t(`helpers.detectionSourceModel.explainNone`)}}function mm(e){switch(e){case`boxed`:return``;case`while-streaming`:return Z.t(`helpers.detectionSourceModel.geometryWhileStreaming`);case`flag-only`:return Z.t(`helpers.detectionSourceModel.geometryFlagOnly`);case`unknown`:return Z.t(`helpers.detectionSourceModel.geometryUnknown`)}}function hm(e,t){return e===`onboard`?Z.t(`helpers.detectionSourceModel.noticeOnboard`):t===`object-detection`?Z.t(`helpers.detectionSourceModel.noticeNoRoot`):Z.t(`helpers.detectionSourceModel.noticeIdle`)}var gm=[`pl-2`,`pl-6`,`pl-10`,`pl-14`],_m={detector:`success`,cropper:`info`,classifier:`primary`,refiner:`warning`,"audio-classifier":`neutral`};function vm(e){return gm[Math.min(e,gm.length-1)]??`pl-2`}function ym(e){return e.zoneDriven?{kind:`zone-driven`}:{kind:`gate`,effectiveOn:e.ownOn,defaultOn:e.defaultOn,explicit:e.choice!==`auto`}}function bm(e,t,n){return e.kind===`parent`?n:fm(e.source,t)}function xm({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(K,{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(K,{size:`sm`,variant:`success`,children:e},`out-${e}`))]})}function Sm({rows:t,label:n,selectedId:r,busy:a,onOpen:o,onSet:s}){let{t:c}=Q(),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:bm(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 ${vm(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(K,{size:`sm`,variant:_m[t.kind],children:l(t.kind)}),i(xm,{inputs:t.inputs,outputs:t.outputs}),c!==null&&i(`span`,{className:`text-[11px] text-warning`,children:c})]}),i(Nr,{gate:ym(t),busy:a,onSet:e=>s(t.stepId,e)})]},t.stepId)})})}function Cm(e,t){let n=e?.[t];return n===void 0?`auto`:n?`on`:`off`}function wm(e,t){return e===`auto`?t:e===`on`}function Tm(e,t,n){return e!==`onboard`&&e!==`none`||!n.has(t)?null:{kind:`source`,source:e}}function Em(e,t,n,r,i){let a=e.zoneDrivenIds??new Set;return t.flatMap(t=>{let o=a.has(t.addonId),s=Cm(e.toggles,t.addonId),c=e.defaults[t.addonId]??!0,l=o||wm(s,c),u=r===null?Tm(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,...Em(e,t.children,n+1,f,i)]})}function Dm(e){let t=e.source===null?new Set:um(e.source,e.tree);return Em(e,e.tree,0,null,t)}function Om({source:t,geometry:n,saving:r,error:a,onPick:o}){let{t:s}=Q(),c=n===`flag-only`,l=mm(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:F,children:s(`device.detectionSourceControl.rootDetector`,`Root detector`)}),i(ti,{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:Ae,children:[pm(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 km=new Set([`package-detection`]),Am=`/system/pipeline?view=nodes`;function jm(e){return Object.fromEntries(e.slots.flatMap(e=>e.addons.map(e=>[e.id,e.enabledByDefault??!0])))}function Mm({deviceId:a}){let{t:c}=Q(),u=ue(),d=yi(),f=l(),p=B().trpcClient,m=t(null),h=t(null),g=rn({deviceId:a},{refetchOnMount:`always`}),_=pn(void 0,{refetchOnMount:`always`});wi([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:v}=Qt(),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=kn({onSuccess:S}),w=Mi(),[T,E]=o(null),[D,O]=o(!1),[k,A]=o(null),j=sm(a),M=x.data??{},N=g.data??null,P=y.map(e=>M[e.id]).find(e=>e!==void 0)??null,F=n(()=>P?vi(P):[],[P]),ee=n(()=>P===null?[]:Dm({tree:F,toggles:N?.stepToggles,defaults:jm(P),source:j.source,zoneDrivenIds:km}),[F,P,N?.stepToggles,j.source]),{selection:te,open:ne,close:re}=ns(n(()=>ee.map(e=>e.stepId),[ee]),[]),I=y[0]?.id,ie=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]),L=e=>{e!==te.stepId&&ie(()=>ne({stepId:e}))},ae=()=>{ie(()=>re())};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 oe=e=>_.data?.find(e=>e.nodeId===I)?.settings.stepSettings?.[e]??{},R=ee.find(e=>e.stepId===te.stepId)??null,se=R===null?null:ts(P,R.stepId),z=d?i(ji,{onClick:ae}):i(Y,{icon:ce,variant:`ghost`,size:`sm`,"aria-label":c(`common.close`,`Close`),onClick:ae});return e(`div`,{ref:m,className:`space-y-2`,children:[j.view?.onboard.available===!0&&j.source!==null&&i(Om,{source:j.source,geometry:j.view.onboard.geometry,saving:j.saving,error:j.error,onPick:e=>void j.pick(e)}),i(`p`,{className:Ae,children:i(va,{i18nKey:`device.cameraStepInspector.modelsChosenByAccelerators`,components:{nodes:i(da,{to:Am,className:`font-medium text-primary hover:underline`})}})}),te.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:te.staleStepId})}),i(Sm,{rows:ee,label:c(`device.cameraStepInspector.detectionStepsOfThisCamera`,`Detection steps of this camera`),selectedId:te.stepId,busy:C.isPending,onOpen:L,onSet:(e,t)=>C.mutate({deviceId:a,addonId:e,enabled:t})}),i(ii,{open:R!==null&&se!==null,anchor:m,onClose:ae,label:c(`stepInspector.stepMatrixFrame.stepSettings`,`Step settings`),children:R!==null&&se!==null&&i(Nm,{addon:se,nodeBag:oe(R.stepId),storedCamera:N?.stepSettings?.[R.stepId],draft:T?.stepId===R.stepId?T:null,saving:D,status:k,notice:R.blocked?.kind===`source`?hm(R.blocked.source,R.stepId):null,closeButton:z,onEscape:ae,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 Nm({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}=Q(),g=xi(t),_=is(g),v=rs(g),y=a?.camera??r,b=a!==null&&!gt(a.camera,r??{});return i(Xr,{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:Ae,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(Pm,{addon:t,fields:_,nodeBag:n,cameraBag:y,onChange:f}):i(`p`,{className:Ae,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 Pm({addon:e,fields:t,nodeBag:n,cameraBag:r,onChange:a}){let{t:o}=Q();return i(ri,{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 Fm(e,t,n){return{id:e,get label(){return Z.t(t)},icon:n}}var Im=[Fm(`zones`,`helpers.detectionSettingsGroups.zones`,`shapes`),Fm(`object-detection`,`helpers.detectionSettingsGroups.objectDetection`,`scan-search`),Fm(`tracking`,`helpers.detectionSettingsGroups.tracking`,`route`),Fm(`motion`,`helpers.detectionSettingsGroups.motion`,`activity`),Fm(`stationary`,`helpers.detectionSettingsGroups.stationary`,`square-parking`),Fm(`audio`,`helpers.detectionSettingsGroups.audio`,`volume-2`),Fm(`cluster`,`helpers.detectionSettingsGroups.cluster`,`server`)],Lm={"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 Rm(e){return Lm[e]??`object-detection`}c();var zm=`steps`,Bm=`settings`,Vm=`object-detection`;function Hm(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}var Um={groupOf:e=>Rm(e.id),tabs:Im};function Wm({deviceId:e,activeSubTab:t,onSubTabChange:r}){let{t:a}=Q();return i(ua,{deviceId:e,sectionFilter:Hm,subTabGrouping:Um,leadingTabs:n(()=>[{id:zm,label:a(`device.detectionPipelineTab.steps`,`Steps`),content:i(Mm,{deviceId:e})}],[e,a]),activeSubTab:t===Bm?Vm:t,onSubTabChange:r})}var Gm=`Notifications`,Km={i18nKey:`device.deviceNotificationMute.cameraCostWhenOff`,text:`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`},qm={i18nKey:`device.deviceNotificationMute.deviceCostWhenOff`,text:`This device never notifies — no rule, no target, no alarm.`};function Jm(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Gm,on:r===null?null:i??r,available:r!==null,costWhenOff:e.isCamera?Km:qm}}function Ym(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}c();function Xm(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Zm({deviceId:t,isCamera:n}){let{t:a}=Q(),s=l(),c=Number.isFinite(t),[u,d]=o(null),[f,p]=o(null),m=Jm({mutedDeviceIds:Xm(xr({},{enabled:c}).data),deviceId:t,isCamera:n,pendingOn:f}),h=a(m.costWhenOff.i18nKey,m.costWhenOff.text),g=Tr({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=Ym(m,t);e!==null&&(p(!e.muted),g.mutate(e))},[t,g,m]),v=m.on===null,y=m.on===!1,b=y?Vt:M;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(X,{variant:`unstyled`,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 Qm({deviceId:t,template:n,members:a,fleet:s,fleetKind:c,snapshot:l,nameOf:u}){let{t:f}=Q(),[p,m]=o(()=>new Map),h=r((e,t)=>{m(n=>{if(ah(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=Bo(l),_=n.id!==`switch`,v=_?fo(n.id,a.map(e=>p.get(ih(e))??{kind:`pending`})):null;return e(d,{children:[_&&a.map(e=>i(nh,{member:e,row:rh(s,e),fleetKind:c,onRead:h},ih(e))),v!==null&&i($m,{view:v}),n.id===`lock`&&i(eh,{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(J,{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(th,{view:g,nameOf:u})]})]})}function $m({view:t}){let{t:n}=Q(),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 eh({deviceId:t}){let{t:n}=Q(),r=fi(),a=Zt(),[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(X,{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(oe,{className:`h-4 w-4`,"aria-hidden":!0}),n(`helper.lockAll`)]}),i(Hn,{label:n(`helper.unlockAll`),icon:Ee,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 th({view:t,nameOf:n}){let{t:r}=Q();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 nh({member:e,row:t,fleetKind:n,onRead:r}){let i=ih(e),o=$n({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 rh(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 ih(e){return`${e.source.addonId}/${e.source.stableId}`}function ah(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 oh({helper:t,snapshot:n}){let{t:r}=Q(),a=yo(n),o=ch(n,t);return i(Ln,{headingId:`helper-history-status`,title:r(`helper.template.${t.kind}`),icon:Ht,testId:`helper-history-status`,children:e(`div`,{className:`${v} 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(na,{value:sh(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(J,{title:r(`helper.outputUnavailable`),message:a.message})]})})}function sh(e,t){if(e.kind!==`derivative`)return String(t);let n=Pe(e);return n===null?String(t):`${t} ${n}`}function ch(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 lh({helper:t,snapshot:n}){let{t:r}=Q(),a=fh(n,t),o=t.kind===`arithmetic`?yo(n):null;return i(Ln,{headingId:`helper-math-status`,title:r(`helper.template.${uh(t)}`),icon:Ut,testId:`helper-math-status`,children:e(`div`,{className:`${v} 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(na,{value:String(a.value),label:r(`helper.output`)}),a.kind===`boolean`&&i(na,{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(J,{title:r(`helper.outputUnavailable`),message:o.message})]})})}function uh(e){return e.kind===`arithmetic`?e.op:e.kind}function dh(e){return e.kind===`threshold`||e.kind===`expression`&&e.output===`boolean`?{cap:`binary`,field:`on`}:{cap:`numeric-sensor`,field:`value`}}function fh(e,t){if(e.kind===`pending`)return{kind:`pending`};if(e.kind!==`answered`)return{kind:`empty`};let n=dh(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 ph({deviceId:t,stableId:n}){let{t:a}=Q(),s=n.startsWith(`composed-`)?n.slice(_t.length):null,c=Ui({blockId:s??``},{enabled:s!==null}),l=an({deviceId:t},{enabled:s!==null}),u=vn({projection:`slim`},{enabled:s!==null}),[d,f]=o(()=>new Map),p=Hr(),m=Bi(),h=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(J,{title:a(`helper.outputUnavailable`),message:c.error.message});if(c.data.state!==`loaded`||c.data.view===null)return null;let g=je(c.data.view.block);if(g===null||!So(g))return null;let _=g.helper;if(_.kind===`threshold`||_.kind===`arithmetic`||_.kind===`expression`)return i(lh,{helper:_,snapshot:_h(l.status,l.data,l.error?.message)});if(ct(_))return i(oh,{helper:_,snapshot:_h(l.status,l.data,l.error?.message)});if(_.kind!==`group`)return null;let y=Ue(_.templateId);if(y===null)return null;let b=_h(l.status,l.data,l.error?.message),x=To(b,y),S=yo(b),C=u.status===`success`?u.data.map(vh):[],w=yh(u.status),T=Mo(_.members.map(e=>d.get(gh(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(hh(y.id,`on`)):a(hh(y.id,`off`)):x.kind===`empty`?a(`helper.noReading`):null;return i(Ln,{headingId:`helper-group-status`,title:a(`helper.statusTitle`),icon:Wt,testId:`helper-group-status`,children:e(`div`,{className:`${v} flex flex-col gap-3`,children:[_.members.map(e=>i(mh,{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:h},gh(e))),x.kind===`pending`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`helper.outputPending`)}),x.kind===`unavailable`&&i(J,{title:a(`helper.outputUnavailable`),message:x.message}),E!==null&&i(na,{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(J,{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(Qm,{deviceId:t,template:y,members:_.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):oi(t,`compact`,p,m)}})]})})}function mh({member:e,row:t,fleetKind:n,isState:r,onLive:i}){let o=t?.online===!0,s=an({deviceId:t?.id??0},{enabled:n===`answered`&&t!==null&&o}),c=Uo(s.status,s.status===`success`?Go(s.data):void 0,e.cap,e.fieldPath,r),l=Io({fleet:n,deviceOnline:n===`answered`?t===null?null:t.online:!0,field:c}),u=t?.name??e.source.stableId,d=Ei(t?.id??0,`compact`,u),f=t===null?u:d,p=gh(e);return a(()=>{i(p,{name:f,presence:l})},[p,f,i,l]),null}function hh(e,t){return[`cover`,`valve`,`lock`,`media-player`,`climate`].includes(e)?`helper.state.${e}.${t}`:`helper.${t}`}function gh(e){return`${e.source.addonId}/${e.source.stableId}/${e.cap}.${e.fieldPath}`}function _h(e,t,n){return e===`pending`?{kind:`pending`}:e===`error`?{kind:`error`,message:n??``}:{kind:`answered`,caps:Go(t)}}function vh(e){return{id:e.id,name:e.name,online:e.online,addonId:e.addonId,stableId:e.stableId,features:e.features??[]}}function yh(e){return e===`pending`?`pending`:e===`error`?`error`:`answered`}function bh(e,t){return{switchId:e,label:Xe[e].label,detail:t===void 0||t.length===0?null:t}}function xh(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 Sh(e){let t=xh(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>bh(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>bh(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 Ch(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 wh({deviceId:t,deviceName:r}){let{t:a}=Q(),s=ue(),[c,l]=o(null),u=vn({isCamera:!0,projection:`slim`}),d=Gr(),f=u.data!==void 0,p=n(()=>u.data===void 0?[]:Ch(u.data,t),[u.data,t]),m=p.find(e=>e.id===c)??null,h=d.data===void 0?null:Sh(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(H,{wrapperClassName:`inline-block w-auto`,"aria-label":a(`deviceMigrate.pickerLabel`,`Replacement camera`),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(X,{variant:`unstyled`,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(Pt,{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(Th,{report:h})]})}function Th({report:t}){let{t:n}=Q(),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(y,{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(x,{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(Kt,{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 Eh({deviceId:t}){let{t:n}=Q(),[r,a]=o(null),s=cn({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(X,{variant:`unstyled`,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(j,{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 Dh(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Oh({device:t}){let{t:n}=Q(),r=ba(),a=typeof t.id==`number`?t.id:null,o=typeof t.name==`string`?t.name:``,s=Ei(a??0,`full`,o),c=String(t.type??``),l=c===G.Camera,u=c===G.Hub,d=t.features??[],f=d.includes(st.Resyncable),{data:p}=ur({deviceId:a??0},{enabled:a!==null&&l,refetchInterval:5e3}),m=p?.streams??{},h=Object.entries(m),g=d.includes(st.DoorbellButton),_=Ri(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(ph,{deviceId:a,stableId:t.stableId}),u&&a!==null&&i(Bn,{deviceId:a,onOpenChild:e=>r(`/devices/${e}`)}),f&&a!==null&&i(Eh,{deviceId:a}),l&&a!==null&&i(wh,{deviceId:a,deviceName:s}),a!==null&&i(Zm,{deviceId:a,isCamera:l}),l&&a!==null&&i(Yn,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:a}),g&&i(Dn,{history:_.history,latestIsFresh:v}),l&&a!==null&&i(Yn,{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(Oe,{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(kh,{label:n(`device.overviewTab.nominal`,`Nominal`),value:Dh(r.nominalBitrateKbps??0)}),i(kh,{label:n(`device.overviewTab.observed`,`Observed`),value:Dh(r.observedBitrateKbps??0)}),i(kh,{label:n(`device.overviewTab.peak`,`Peak`),value:Dh(r.peakBitrateKbps??0)}),i(kh,{label:n(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(r.packetLossPercent??0).toFixed(2)}%`,warning:(r.packetLossPercent??0)>1})]})]},t))})]}),i(Oa,{})]})}function kh({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 Ah=`history`,jh=[{id:`overview`,labelKey:`helpers.structuralTabs.overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,labelKey:`helpers.structuralTabs.config`,cameraOnly:!1,adminOnly:!1},{id:Da,labelKey:`helpers.structuralTabs.customize`,cameraOnly:!1,adminOnly:!0},{id:Ah,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}],Mh=new Set([G.Hub,G.Container]);function Nh(e,t){let n=e===G.Camera,r=e===void 0||!Mh.has(e);return jh.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)&&(r||e.id!==`history`)).map(({id:e,labelKey:t})=>({id:e,label:Z.t(t)}))}function Ph({provider:e,integrationId:t,name:n}){let r=ba(),a=t===null?`/integrations`:wa(e,t),o=n===null?`Open integrations`:`Open integration ${n}`;return i(X,{variant:`unstyled`,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(Ca,{type:e,size:`lg`})})}c();var Fh=[{id:`logs`,icon:De,labelKey:`common.logs`},{id:`repl`,icon:Gt,labelKey:`deviceDetail.repl`},{id:`events`,icon:L,labelKey:`common.events`},{id:`state`,icon:z,labelKey:`common.state`}];function Ih(){let{t:a}=Q(),s=ke(),c=ka(),u=Number(c.deviceId),f=Number.isFinite(u),p=ba(),g=l(),_=ue(),v=B(),{user:y}=ma(),b=y?.isAdmin===!0,[x,S]=la(),C=x.get(`tab`)??`overview`,w=x.get(`sub`),[T,D]=o(`logs`),O=`device-detail.left-col-width-px`,[k,A]=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=>{A(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=M.current;if(e!==null)try{window.localStorage.setItem(O,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:P,isLoading:F,isError:re}=fr({deviceId:u},{enabled:f,refetchInterval:5e3,retry:1}),{data:I}=Sn({deviceId:u},{enabled:f}),ie=n(()=>{let e=I?.settings?.sections??[],t=I?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(ga)&&r.add(sa),[...r].map(e=>e===`export`?{id:e,label:Ta,isAddonContrib:!0}:{id:e,label:Ot[e]?.label??e,isAddonContrib:!0})},[I]),L=P,ae=String(L?.name??c.deviceId??`Device`),oe=L?.online===!0,R=oe?`online`:`offline`,se=String(L?.addonId??`rtsp`),ce=L?.features??[],z=L?.type,le=z===G.Camera,{data:de}=Sa(f?u:0),fe=z===G.Container,pe=n(()=>(de??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[de]),me=n(()=>fe?Ir(pe,typeof L?.linkDeviceId==`number`?L.linkDeviceId:null,typeof L?.primaryChildEntityId==`string`?L.primaryChildEntityId:null)?.id??null:null,[fe,pe,L?.linkDeviceId,L?.primaryChildEntityId]),{data:he}=Sn({deviceId:me??0},{enabled:me!==null}),ge=n(()=>{if(me===null)return[];let e=he?.settings?.sections??[],t=he?.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:Ot[e]?.label??e,isAddonContrib:!0,childDeviceId:me}))},[me,he]),_e=n(()=>mc({sections:[...I?.settings?.sections??[],...I?.live?.sections??[]],deviceId:u,drawnByHero:dc(z),...me===null?{}:{child:{sections:[...he?.settings?.sections??[],...he?.live?.sections??[]],deviceId:me}}}),[I,he,u,z,me]),be=typeof L?.parentDeviceId==`number`?L.parentDeviceId:null,{data:xe}=fr({deviceId:be??0},{enabled:be!==null}),Se={id:Number.isFinite(u)?u:0,name:ae,type:`unknown`,stableId:``,parentDeviceId:null},V=Fr(L??Se,`full`),we=Fr(xe??Se,`full`),Te=yi(),H=L?.disabled!==!0,Ee=n(()=>{let e=I?.settings?.sections??[],t=I?.live?.sections??[];return _a([...e,...t],z,b,I!==void 0)},[I,z,b]),De=n(()=>{let e=new Set,t=[];for(let n of[...Nh(z,b),...ie,...ge])n.id===`config`&&!Ee||e.has(n.id)||(e.add(n.id),t.push(n));return t},[z,b,ie,ge,Ee]),Oe=n(()=>em(De,C),[De,C]),Ae=r(e=>{S(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of es)n.delete(e);return n},{replace:!0})},[S]),je=r(e=>{S(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[S]),Me=(de??[]).length>0,Ne=n(()=>Fh.filter(({featureGate:e})=>!e||ce.includes(e)),[ce]),{data:Pe}=Or(void 0),Fe=n(()=>L?In(L,Pe):null,[L,Pe]),U=Fe?.kind===`resolved`?Fe.integration:null,Ie=U===null?Fe?.kind===`unknown`?a(`deviceDetail.loadingIntegration`):Fe?.kind===`orphan`?a(`deviceDetail.missingIntegration`):a(`deviceDetail.noIntegration`):U.name,Le=U!==null&&U.addonId===se?U.name:se,Re=Li({onSuccess:()=>{g.invalidateQueries({queryKey:[[`deviceManager`]]}),p(U?.id?wa(U.addonId,U.id):`/integrations`)}}),ze=Rn({onSuccess:()=>{g.invalidateQueries({queryKey:[[`deviceManager`]]})}}),W=di({onSuccess:()=>{g.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=on(),Ve=qr({onSuccess:()=>{g.invalidateQueries({queryKey:[[`deviceManager`]]})}}),He=Rr({deviceId:u},{enabled:f,staleTime:15e3}),Ue=He.data?.linked===!0,We=ve(),Ge=e=>{g.invalidateQueries({queryKey:[[`powerSource`]]}),e.accepted||We({title:a(`deviceDetail.powerSourceRefused`,`The power action was not done`),message:e.message,variant:`danger`})},Ke=ar({onSuccess:Ge}),qe=$i({onSuccess:Ge}),Je=ra({onSuccess:Ge}),Ye=He.data?.switchName??``,Xe=He.data?.offSeconds??0,Ze=ce.includes(st.Rebootable),Qe=ce.includes(st.BatteryOperated),$e=Xt(v.trpcClient,Qe&&f?u:null),et=Zn(v.trpcClient,f?u:null),tt=ye(v.trpcClient,f?u:null,e=>e.runningState),nt=tt===void 0||tt.running===null?null:tt.running,rt=pi(z??`unknown`,s).icon,[it,at]=o(!1),ot=async()=>{if(!it){at(!0);try{let e=V.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await ws(`${ne}/${String(u)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{at(!1)}}},ct=ze.isPending||W.isPending,{data:lt}=$t({deviceId:u},{enabled:f&&le,refetchInterval:1e4}),ut=lt?.agentNodeId??null,dt=typeof ut==`string`&&ut.length>0&&!ut.startsWith(`addon:`)?ut:void 0,{data:ft}=li({deviceId:u,...dt?{nodeId:dt}:{}},{enabled:f&&le,refetchInterval:3e3,retry:!1}),{data:pt}=qn({deviceId:u},{enabled:f&&le,refetchInterval:3e3,retry:!1}),mt=pt?.level?.dbfs??null;function ht(){if(!f)return null;switch(Oe){case`overview`:return i(Oh,{device:L??{}});case`config`:return i(am,{deviceId:u,activeSubTab:w,onSubTabChange:je,deviceType:z,isAdmin:b});case`detection-pipeline`:return i(Wm,{deviceId:u,activeSubTab:w,onSubTabChange:je});case`bindings`:return i(tm,{deviceId:u});case Ah:return i(ea,{deviceId:u,onNavigate:e=>p(e)});case Da:return i(Xp,{deviceId:u});default:{let e=Oe,t=ie.some(t=>t.id===e),n=ge.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??u;if(e===`export`)return i(ua,{deviceId:u,sectionFilter:ga,activeSubTab:w,onSubTabChange:je});let a=i(ua,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&t.tab===e,activeSubTab:w,onSubTabChange:je});return n!==void 0&&r!==u?i(Qr,{deviceId:r,children:a}):a}}}return f?F?e(`div`,{className:`flex flex-col h-full`,children:[e(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[i(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),i(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),i(`div`,{className:`flex-1 p-6`,children:i(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):re||!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(va,{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(X,{variant:`unstyled`,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(xn,{items:[{label:a(`deviceDetail.integrations`,`Integrations`),onClick:()=>p(`/integrations`)},U===null?{label:Ie}:{label:Ie,onClick:()=>p(wa(U.addonId,U.id))},{label:V}]})}),e(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[U!==null&&i(Ph,{provider:U.addonId,integrationId:U.id,name:U.name}),i(An,{running:nt,children:i(rt,{className:`h-5 w-5 text-foreground-subtle shrink-0`,"aria-hidden":!0})}),e(`div`,{className:`min-w-0 flex-1`,children:[e(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[i(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:V}),i(Xi,{status:R}),Qe&&i(_r,{status:$e,variant:`full`}),i(Ni,{status:et})]}),be!==null&&xe&&e(X,{variant:`unstyled`,type:`button`,onClick:()=>p(`/devices/${be}`),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:we}),children:[i(`span`,{children:`↑`}),i(`span`,{className:`truncate`,children:we})]}),i(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:ce.length>0&&i(fa,{capabilities:ce})})]}),ft&&i(`div`,{className:`hidden lg:flex`,children:i(Lh,{metrics:ft,dbfs:mt})}),e(`div`,{className:`flex items-center gap-1 shrink-0`,children:[e(X,{variant:`unstyled`,onClick:async()=>{H?await _({title:a(`deviceDetail.disable`,`Disable "{{name}}"?`,{name:V}),message:a(`deviceDetail.theDeviceWillStopProcessing`,`The device will stop processing streams and events. You can re-enable it later.`),confirmLabel:a(`common.disable`,`Disable`),variant:`danger`})&&W.mutate({deviceId:u}):ze.mutate({deviceId:u})},disabled:ct,title:H?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 ${H?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[i(h,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:ct?a(`deviceDetail.updating`,`Updating…`):H?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(js,{deviceId:u}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),i(Ns,{deviceId:u}),i(Gn,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:a(`deviceDetail.takeSnapshot`,`Take snapshot`),description:a(`deviceDetail.fetchAFreshFrameAnd`,`Fetch a fresh frame and download it.`),icon:ee,disabled:it,onClick:()=>{ot()}},{id:`reboot`,label:a(`deviceDetail.rebootDevice`,`Reboot device`),description:a(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:m,hidden:!Ze,disabled:Be.isPending,danger:!0,onClick:async()=>{await _({title:a(`deviceDetail.reboot`,`Reboot "{{name}}"?`,{name:V}),message:a(`deviceDetail.theCameraWillGoOffline`,`The camera will go offline for around 30 seconds while the firmware reboots.`),confirmLabel:a(`deviceDetail.reboot2`,`Reboot`),variant:`danger`})&&Be.mutate({deviceId:u})}},{id:`power-source-on`,label:a(`deviceDetail.powerOn`,`Power on`),description:a(`deviceDetail.powerOnDescription`,`Switch on {{switchName}}, which powers this device.`,{switchName:Ye}),icon:h,hidden:!Ue,disabled:Ke.isPending,onClick:()=>Ke.mutate({deviceId:u})},{id:`power-source-off`,label:a(`deviceDetail.powerOff`,`Power off`),description:a(`deviceDetail.powerOffDescription`,`Switch off {{switchName}}, which powers this device.`,{switchName:Ye}),icon:te,hidden:!Ue,disabled:qe.isPending,danger:!0,onClick:async()=>{await _({title:a(`deviceDetail.powerOffTitle`,`Cut the power of "{{name}}"?`,{name:V}),message:a(`deviceDetail.powerOffMessage`,`{{switchName}} will be switched off and "{{name}}" stays off until you power it on again.`,{switchName:Ye,name:V}),confirmLabel:a(`deviceDetail.powerOffConfirm`,`Power off`),variant:`danger`})&&qe.mutate({deviceId:u})}},{id:`power-source-restart`,label:a(`deviceDetail.forceRestartPower`,`Force restart (power)`),description:a(`deviceDetail.forceRestartPowerDescription`,`Cut the power of {{switchName}} for {{seconds}} seconds, then switch it back on.`,{switchName:Ye,seconds:Xe}),icon:j,hidden:!Ue,disabled:Je.isPending||He.data?.restartInProgress===!0,danger:!0,onClick:async()=>{await _({title:a(`deviceDetail.forceRestartTitle`,`Force restart "{{name}}"?`,{name:V}),message:a(`deviceDetail.forceRestartMessage`,`{{switchName}} will be switched off for {{seconds}} seconds and then back on. "{{name}}" loses power meanwhile.`,{switchName:Ye,seconds:Xe,name:V}),confirmLabel:a(`deviceDetail.forceRestartConfirm`,`Restart`),variant:`danger`})&&Je.mutate({deviceId:u})}},{id:`restart-addon`,label:a(`deviceDetail.restartAddon`,`Restart addon`),description:a(`deviceDetail.bouncesEveryDeviceServedBy`,`Bounces every device served by {{servingAddonLabel}}.`,{servingAddonLabel:Le}),icon:j,disabled:Ve.isPending,danger:!0,onClick:async()=>{await _({title:a(`deviceDetail.restart`,`Restart "{{servingAddonLabel}}"?`,{servingAddonLabel:Le}),message:a(`deviceDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device served by it (not just "{{name}}"). Streams will reconnect automatically.`,{name:V}),confirmLabel:a(`deviceDetail.restart2`,`Restart`),variant:`danger`})&&Ve.mutate({addonId:se})}},{id:`delete`,label:a(`deviceDetail.deleteDevice`,`Delete device`),description:a(`deviceDetail.removeTheDeviceAndAll`,`Remove the device and all its settings.`),icon:E,separatorBefore:!0,disabled:Re.isPending,danger:!0,onClick:async()=>{await _({title:a(`deviceDetail.delete`,`Delete "{{name}}"?`,{name:V}),message:a(`deviceDetail.thisWillRemoveTheDevice`,`This will remove the device and all its settings. This action cannot be undone.`),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`})&&Re.mutate({deviceId:u})}}]})]})]})]}),i(Qr,{deviceId:u,device:L??void 0,children:i(yn,{children:i(Cn,{children:i(Ce,{children:i(Kr,{children:e(`main`,{className:Te?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[e(`div`,{className:Te?`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:!Te&&k!==null?{width:`${String(k)}px`}:void 0,children:[i(`div`,{className:le?`flex-shrink-0 border-b border-border-subtle bg-black`:Te?`flex-shrink-0 border-b border-border-subtle bg-surface`:`shrink-0 border-b border-border-subtle bg-surface`,children:le?i(Tc,{deviceId:u,intercomAvailable:ce.includes(st.TwoWayAudio)}):e(`div`,{children:[i(lc,{deviceId:u,deviceName:V,deviceType:z??`unknown`,provider:se,isOnline:oe,features:ce}),i(fc,{deviceId:u,widgets:_e})]})}),le&&_e.length>0&&i(`div`,{className:`flex-shrink-0 border-b border-border-subtle bg-surface pt-3 sm:pt-4`,children:i(fc,{deviceId:u,widgets:_e})}),e(`div`,{className:Te?`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:Ne.map(({id:t,labelKey:n,icon:r})=>{let o=T===t;return e(X,{variant:`unstyled`,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:Te?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[T===`logs`&&i(Ec,{deviceId:u,containerDeviceId:z===`container`?u:void 0}),T===`repl`&&i(Dc,{deviceId:u}),T===`events`&&i(Oc,{deviceId:u}),T===`state`&&i(kc,{deviceId:u})]})]})]}),!Te&&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:Te?`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(X,{variant:`unstyled`,onClick:()=>Ae(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:Te?`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`&&Me&&i(Ps,{parentDeviceId:u}),ht()]})]})]})})})})})})]}):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(va,{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(X,{variant:`unstyled`,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 Lh({metrics:t,dbfs:n}){let r=ke(),{t:a}=Q(),o=or(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(me,{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(V,{className:`h-3 w-3`}),i(`span`,{className:`text-foreground tabular-nums`,children:(t.avgInferenceTimeMs??0).toFixed(0)}),i(`span`,{children:`ms`})]}),e(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:a(`deviceDetail.currentAudioLevelDbfs`,`Current audio level (dBFS)`),children:[i(O,{className:`h-3 w-3`}),i(`span`,{className:`text-foreground tabular-nums`,children:n==null?`—`:n.toFixed(0)}),i(`span`,{children:`dB`})]}),(t.queueDepth??0)>0&&e(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,t.queueDepth]})]})}export{Ih as DeviceDetailPage};