@camstack/addon-admin-ui 1.2.724 → 1.2.725
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/assets/AccessSection-0YWYHlqh.js +1 -0
- package/dist/assets/Addons-BRgY9i0q.js +5 -0
- package/dist/assets/{AdminPage-D7HDl_8w.js → AdminPage-bICe1m-8.js} +1 -1
- package/dist/assets/{AdminSectionedPage-DCFH2ZMJ.js → AdminSectionedPage-DktN6pn6.js} +1 -1
- package/dist/assets/AiProfiles-fPEjmnul.js +3 -0
- package/dist/assets/Archive-BLoPuqO6.js +1 -0
- package/dist/assets/{BootstrapSettingsForm-CdkMSLjg.js → BootstrapSettingsForm-BLw-bXdS.js} +1 -1
- package/dist/assets/Build-D5blLfID.js +51 -0
- package/dist/assets/{Calendars-CfmMLL7F.js → Calendars-CZxNXbvN.js} +1 -1
- package/dist/assets/{Cluster-B94KD8aS.js → Cluster-B3BlYJGl.js} +1 -1
- package/dist/assets/CompositionBlockEditor-BvTjfPzr.js +2 -0
- package/dist/assets/{CompositionEditorPage-CpncsAuR.js → CompositionEditorPage-DilYSVAh.js} +1 -1
- package/dist/assets/Data-DByot8HL.js +2 -0
- package/dist/assets/DeviceDetail-BILFXcxW.js +1 -0
- package/dist/assets/{Devices-B4tUJ5O0.js → Devices-bt0-1nEz.js} +1 -1
- package/dist/assets/{EmbedDevicePage-zZYPwif2.js → EmbedDevicePage-D4ZbPn_S.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CrQlFBi0.js → EmbedPlayerPage-DcHT6biY.js} +1 -1
- package/dist/assets/History-DxhG1uWz.js +1 -0
- package/dist/assets/Identity-DYXSp28v.js +1 -0
- package/dist/assets/InstancesTable-BmqMzyAD.js +1 -0
- package/dist/assets/IntegrationDetail-B9Hosu4d.js +1 -0
- package/dist/assets/{Integrations-BikpPMXe.js → Integrations-BhhPeFaU.js} +2 -2
- package/dist/assets/{Integrations-BazXjCt_.js → Integrations-DhL85Et0.js} +1 -1
- package/dist/assets/Library-C7Eo3Gz2.js +1 -0
- package/dist/assets/Locations-CS3MiZgN.js +3 -0
- package/dist/assets/Logs-NxqbfLLe.js +1 -0
- package/dist/assets/{MaskShapeCanvas-oPepmNCH.js → MaskShapeCanvas-1kOPTp5R.js} +1 -1
- package/dist/assets/{MotionZonesSettings-CYLn60sd.js → MotionZonesSettings-D8fGceV0.js} +1 -1
- package/dist/assets/MyAccess-Dr43n2Aj.js +2 -0
- package/dist/assets/Network-BjT8Ikfn.js +1 -0
- package/dist/assets/NewExportModal-B5t_mbrS.js +1 -0
- package/dist/assets/NodeAddonsSettingsPanel-D3hRSe7P.js +1 -0
- package/dist/assets/Notifications-BPjz108o.js +1 -0
- package/dist/assets/Pipeline-D6ZVLclC.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-Ilg_zxXc.js → PrivacyMaskSettings-D3YvMfsz.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-CtN52BvZ.js → SceneMonitorEditor-BNzPYNE-.js} +1 -1
- package/dist/assets/SessionsList-D_noZh9t.js +2 -0
- package/dist/assets/{Showroom-CLjlRZWw.js → Showroom-DY1sAew3.js} +1 -1
- package/dist/assets/StorageLocationsTable-BKshMXB4.js +1 -0
- package/dist/assets/System-BDTzR9kd.js +2 -0
- package/dist/assets/TemplateEditorDialog-Cn8WosKF.js +1 -0
- package/dist/assets/{Terminal-DecsDJ7g.js → Terminal-ChbjDXDA.js} +3 -3
- package/dist/assets/{TrainingProviders-BPsToq4Q.js → TrainingProviders-DXj5HXuG.js} +1 -1
- package/dist/assets/{Viewer-dI1zk7a_.js → Viewer-UTPC6iRE.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DhJkBqN6.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BdwxutW3.js} +1 -1
- package/dist/assets/{ai-page.helpers-C9ncAiuL.js → ai-page.helpers-UVJMKy6P.js} +1 -1
- package/dist/assets/{assignment-candidates-BnnkvY8h.js → assignment-candidates-DyQQjACn.js} +1 -1
- package/dist/assets/{authed-media-cbGWS8WD.js → authed-media-B_CjxfLV.js} +1 -1
- package/dist/assets/{board-model-BUl6Wswk.js → board-model-Dq3qdJma.js} +1 -1
- package/dist/assets/{camera-block-model-Q1HxShH2.js → camera-block-model-4s-NMaHt.js} +1 -1
- package/dist/assets/client-1LJ_g9Ba.js +1234 -0
- package/dist/assets/{command-vocab-CowbPNm4.js → command-vocab-DtljW6DB.js} +1 -1
- package/dist/assets/{device-integration-icon-Cv6svmZf.js → device-integration-icon-B9A24x1a.js} +1 -1
- package/dist/assets/device-picker-model-DXOWT2IN.js +1 -0
- package/dist/assets/dist-P6BiCy51.js +1234 -0
- package/dist/assets/{dist-DDKVCwep.js → dist-nlCPXoMt.js} +1 -1
- package/dist/assets/{format-fMWP0kBk.js → format-BiPkf6OJ.js} +1 -1
- package/dist/assets/{hostInit-Dg3enb1C.js → hostInit-B8HgyCL3.js} +1 -1
- package/dist/assets/i18n-Dnr69xZl.js +1 -0
- package/dist/assets/icons-Dbyyu0WX.js +1 -0
- package/dist/assets/index-BYlbOWDT.js +7 -0
- package/dist/assets/{linked-devices-model-D0HIRFa6.js → linked-devices-model-BIH1Bhno.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-8f344dc9.js → mf-entry-bootstrap-0-80139612.js} +2 -2
- package/dist/assets/mount-DXOWT2IN.js +1 -0
- package/dist/assets/{notification-rule-status-1Pqn2gI0.js → notification-rule-status-Co0ZumA7.js} +1 -1
- package/dist/assets/{player-overlays-BlZSsqyb.js → player-overlays-BupPNWPl.js} +1 -1
- package/dist/assets/remoteEntry-CzUkwSz2.js +1 -0
- package/dist/assets/src-CQ9OFTGp.js +279 -0
- package/dist/assets/{sso-popup-CyudOoAC.js → sso-popup-DaUNbxiy.js} +1 -1
- package/dist/assets/{step-inspector-model-AapIU667.js → step-inspector-model-B3_m_FF1.js} +1 -1
- package/dist/assets/{terminal-DZ5OZpgC.js → terminal-BncJ-1sF.js} +1 -1
- package/dist/assets/{use-scenes-feed-XvauAlT9.js → use-scenes-feed-D-IsflDy.js} +1 -1
- package/dist/assets/{useAdminDeviceRemoval-BhZRoWWG.js → useAdminDeviceRemoval-CrxBWNkW.js} +1 -1
- package/dist/assets/useDevice-DaGU3q2l.js +1 -0
- package/dist/assets/useEventInvalidation-DXOWT2IN.js +1 -0
- package/dist/assets/useFaultTypeOptions-BX2CU1k5.js +1 -0
- package/dist/assets/{useNodeUrlSelection-D_Hj46vK.js → useNodeUrlSelection-IC8i4r19.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DM3CrJtS.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Br2V_f2o.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +113 -2
- package/package.json +2 -2
- package/dist/assets/AccessSection-CDX5My6v.js +0 -1
- package/dist/assets/Addons-BCe0VY3I.js +0 -5
- package/dist/assets/AiProfiles-BjZwco00.js +0 -3
- package/dist/assets/Archive-BEw28D0l.js +0 -1
- package/dist/assets/Build-Cd0Awiro.js +0 -51
- package/dist/assets/CompositionBlockEditor-BVDwm3ml.js +0 -2
- package/dist/assets/Data-B5Zq6VxR.js +0 -2
- package/dist/assets/DeviceDetail-Ci1xUpuk.js +0 -1
- package/dist/assets/History-D3E5ncEy.js +0 -1
- package/dist/assets/Identity-Db_2N6S-.js +0 -1
- package/dist/assets/InstancesTable-JeTT3mbW.js +0 -1
- package/dist/assets/IntegrationDetail-CdZEJaQd.js +0 -1
- package/dist/assets/Library-Dld9H7p6.js +0 -1
- package/dist/assets/Locations-PVx-7dqK.js +0 -3
- package/dist/assets/Logs-CTuepFZi.js +0 -1
- package/dist/assets/MyAccess-BBk_gLUj.js +0 -2
- package/dist/assets/Network-DetWYR5n.js +0 -1
- package/dist/assets/NewExportModal-Rszxooj4.js +0 -1
- package/dist/assets/NodeAddonsSettingsPanel-BF_jhB7H.js +0 -1
- package/dist/assets/Notifications-BcRFGnhT.js +0 -1
- package/dist/assets/Pipeline-BlEK7pbK.js +0 -1
- package/dist/assets/SessionsList-DGneQZL3.js +0 -2
- package/dist/assets/StorageLocationsTable-H2dftyPT.js +0 -1
- package/dist/assets/System-CG5IvQSq.js +0 -2
- package/dist/assets/TemplateEditorDialog-B1DhKxmk.js +0 -1
- package/dist/assets/action-draft-awcciaok.js +0 -1
- package/dist/assets/client-CtgKstLe.js +0 -1136
- package/dist/assets/device-picker-model-CwgH4NNj.js +0 -1
- package/dist/assets/dist-DpsxRllT.js +0 -1136
- package/dist/assets/i18n-BJDJdeXT.js +0 -1
- package/dist/assets/icons-BuvB8qrt.js +0 -1
- package/dist/assets/index-C3-q_LJz.js +0 -7
- package/dist/assets/mount-CwgH4NNj.js +0 -1
- package/dist/assets/remoteEntry-D2v2e-zq.js +0 -1
- package/dist/assets/src-CVIre2mA.js +0 -279
- package/dist/assets/useDevice-BDmjvHYF.js +0 -1
- package/dist/assets/useEventInvalidation-CwgH4NNj.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
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,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$a as d,Ai as f,At as p,Br as m,D as h,Da as g,Er as _,Et as v,Hn as y,Jn as b,Ka as x,Lr as S,Mi as C,O as w,Oa as T,Or as E,Pr as D,Rr as O,Rt as k,Tn as A,Ur as j,V as M,W as N,Xn as P,Yn as F,Zi as ee,Zn as I,_i as L,ar as te,ba as ne,bi as R,bn as re,bt as ie,ca as z,co as B,ct as ae,dr as oe,eo as V,ft as H,ka as se,kn as ce,nn as le,nr as ue,oa as de,or as fe,ot as pe,pa as me,q as he,qa as ge,rr as _e,t as ve,yi as ye,z as be,za as xe,zn as Se}from"./player-overlays-BlZSsqyb.js";import{$a as Ce,Aa as we,Ao as U,Ba as Te,Br as Ee,Co as De,Cr as Oe,Ga as ke,Gr as Ae,Gs as je,Mr as Me,Nr as Ne,Pr as Pe,S as Fe,Sn as Ie,Sr as W,Xa as Le,Xn as Re,Ya as ze,Ys as Be,Za as Ve,_n as He,ai as Ue,ao as We,bn as Ge,cc as Ke,da as qe,dr as Je,ec as Ye,eo as Xe,fr as Ze,gn as Qe,gr as $e,hn as et,il as tt,io as nt,jo as rt,kc as it,lc as G,ml as at,mr as ot,nc as st,nr as ct,pr as lt,qa as ut,ro as dt,rr as ft,s as pt,sl as mt,sr as ht,tc as gt,uc as K,ur as _t,vn as vt,wa as yt,xn as bt,xr as xt,yn as St,yo as Ct,zs as wt}from"./client-CtgKstLe.js";import{I as Tt,j as Et,y as Dt}from"./__vite-browser-external-DIbVKiho.js";import{_ as Ot,t as kt}from"./terminal-DZ5OZpgC.js";import{n as At}from"./divide-Bmm9r7CP.js";import{t as jt}from"./circle-slash-Duh934sZ.js";import{a as Mt,i as Nt,n as Pt,r as Ft,t as It}from"./scan-eye-C862nWtV.js";import{r as Lt}from"./shapes-D4IRNSXI.js";import{t as Rt}from"./file-up-2YD_M6f_.js";import{t as zt}from"./layers-BH9u1mrE.js";import{$a as Bt,$i as Vt,$p as Ht,$s as Ut,$u as Wt,A as Gt,Ap as Kt,Ar as qt,At as Jt,Au as Yt,B as Xt,Ba as Zt,Bd as Qt,Br as $t,Bt as en,Bu as tn,C as nn,Ci as rn,Cp as q,Cr as an,Ct as on,Dt as sn,Es as cn,Et as ln,Fn as un,Fp as dn,Ft as fn,Gi as pn,Ha as mn,Hd as hn,Hr as gn,Hu as _n,Ic as vn,Ip as yn,Is as bn,J as xn,Ji as Sn,Jl as Cn,Jp as wn,Js as Tn,K as En,Kr as Dn,Kt as On,Lc as kn,Ln as An,Ma as J,Mc as jn,Mp as Y,Mt as Mn,Np as Nn,Nt as Pn,Op as Fn,Ot as In,Pa as X,Pp as Ln,Qa as Rn,Qi as zn,Qp as Bn,Qs as Vn,Rn as Hn,Ro as Un,Rp as Wn,Ru as Gn,So as Kn,Td as qn,Ts as Jn,U as Yn,Ua as Xn,Ud as Zn,Ur as Qn,Va as $n,Vd as er,Vs as tr,Vt as nr,W as rr,Wd as ir,X as ar,Xa as or,Xi as sr,Xn as cr,Xt as lr,Y as ur,Yi as dr,Yl as fr,Yp as pr,Ys as mr,Zi as hr,Zp as gr,Zr as _r,_i as vr,_s as yr,a as br,bl as xr,cn as Sr,cs as Cr,d as wr,dd as Tr,ds as Er,dt as Z,ea as Dr,ec as Or,ef as kr,el as Ar,eo as jr,fc as Mr,fd as Nr,fs as Pr,ft as Fr,fu as Ir,g as Lr,ga as Rr,gi as zr,hc as Br,hi as Vr,hs as Hr,ic as Ur,if as Wr,ii as Gr,in as Kr,jn as qr,jp as Jr,jr as Yr,jt as Xr,kc as Zr,kp as Qr,kt as $r,la as ei,lc as ti,ld as ni,mi as ri,ml as ii,nc as ai,nf as oi,ni as si,nl as ci,nm as li,o as ui,ou as di,pa as fi,pd as pi,pi as mi,pu as hi,q as gi,qa as _i,qf as vi,qi as yi,qn as bi,qp as xi,qu as Si,ra as Ci,rc as wi,rf as Ti,rn as Ei,ro as Di,rt as Oi,tc as ki,tl as Ai,tm as ji,tn as Mi,ud as Ni,vi as Pi,w as Fi,wi as Ii,ws as Li,wt as Ri,xa as zi,xs as Bi,xt as Vi,yi as Hi,yl as Ui,zu as Wi}from"./src-CVIre2mA.js";import{t as Q}from"./i18n-BJDJdeXT.js";import{t as $}from"./useTranslation-BJr-n0es.js";import{n as Gi,r as Ki}from"./useDevice-BDmjvHYF.js";import{B as qi,Ci as Ji,D as Yi,Di as Xi,E as Zi,Ei as Qi,H as $i,I as ea,K as ta,L as na,M as ra,N as ia,O as aa,Oi as oa,P as sa,R as ca,Si as la,T as ua,W as da,Z as fa,k as pa,pt as ma,q as ha,tt as ga,w as _a,xt as va,z as ya}from"./index-C3-q_LJz.js";import{t as ba}from"./authed-media-cbGWS8WD.js";import{n as xa,t as Sa}from"./format-fMWP0kBk.js";import{$ as Ca,A as wa,B as Ta,C as Ea,D as Da,Dt as Oa,E as ka,Et as Aa,F as ja,G as Ma,H as Na,I as Pa,J as Fa,K as Ia,L as La,M as Ra,N as za,O as Ba,Ot as Va,P as Ha,Q as Ua,R as Wa,S as Ga,Tt as Ka,U as qa,V as Ja,W as Ya,X as Xa,Y as Za,Z as Qa,_t as $a,at as eo,bt as to,ct as no,d as ro,dt as io,et as ao,f as oo,ft as so,g as co,gt as lo,h as uo,ht as fo,it as po,j as mo,k as ho,kt as go,l as _o,lt as vo,m as yo,mt as bo,nt as xo,ot as So,p as Co,pt as wo,q as To,rt as Eo,s as Do,st as Oo,t as ko,tt as Ao,u as jo,ut as Mo,v as No,vt as Po,wt as Fo,x as Io,y as Lo,yt as Ro,z as zo}from"./CompositionBlockEditor-BVDwm3ml.js";import{a as Bo,f as Vo,l as Ho,s as Uo,t as Wo}from"./TemplateEditorDialog-B1DhKxmk.js";import{t as Go}from"./assignment-candidates-BnnkvY8h.js";import"./useEventInvalidation-CwgH4NNj.js";import{h as Ko,i as qo,m as Jo,o as Yo,t as Xo,v as Zo}from"./step-inspector-model-AapIU667.js";import{a as Qo}from"./notification-rule-status-1Pqn2gI0.js";import{a as $o,c as es,i as ts,l as ns,n as rs,o as is,r as as,s as os,t as ss,u as cs}from"./linked-devices-model-D0HIRFa6.js";c();function ls(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 us(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(ls).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 fs(e){for(let[t,n]of ds)if(t.test(e))return n;return`generic`}function ps(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(Q.t(`helpers.cameraSwitchRows.off`,{list:r(t)})),n.length>0&&i.push(Q.t(`helpers.cameraSwitchRows.unknown`,{list:r(n)})),{offIds:t,unknownIds:n,summary:i.length===0?Q.t(`helpers.cameraSwitchRows.allOn`):i.join(` · `)}}var ms={stream:I,detection:It,privacy:ye,microphone:E,speaker:k,listening:Nt,archive:Ot,recording:Mt,notifications:g,generic:A};function hs({deviceId:t}){let{t:n}=$(),a=l(),s=Number.isFinite(t),[c,u]=o(null),[d,f]=o(!1),p=_n({deviceId:t},{enabled:s});br([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=us(p.data),h=pi({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 _=ps(m),v=e=>c?.id===e.id?c.message:null;return e(Ln,{open:d,onOpenChange:f,children:[e(yn,{"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(A,{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(dn,{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(gs,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function gs({row:t,failure:n,onToggle:r}){let{t:a}=$(),o=ms[fs(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(q,{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 _s({parentDeviceId:t}){let{t:n}=$(),r=Qi(),a=ie(),{data:o,isLoading:s,isError:c}=Gi(t),{data:l}=Vn({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 d=(o??[]).filter(e=>e.display?.hidden!==!0);if(d.length===0)return null;let f=In(l?.stableId??``,d,l?.childLayout),p=f.ungrouped,m=e=>r(`/devices/${String(e)}`),h=l?.name??``,g=(e,t)=>i(ln,{trpc:a.trpcClient,device:{...t,name:Mn(t,h)},nameForm:`nested`,...l?{parent:{id:l.id,name:l.name,type:l.type}}:{},variant:`minimal`,onNavigate:m},e),_=Pn({type:l?.type??``,stableId:l?.stableId??``,linkDeviceId:l?.linkDeviceId,primaryChildEntityId:l?.primaryChildEntityId,primaryChildPreference:l?.primaryChildPreference},p),v=_.accessories.length>0,y=_.adopted.length>0,b=_.parts.length>0||_.primary.length>0,x=_.primary.length>0&&_.parts.length>0&&!y&&!v,S=x?``:y&&!v&&!b?n(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):v&&!y&&!b?n(`device.accessories`,{defaultValue:`Accessories`}):_.primary.length>0&&_.parts.length===0&&!y&&!v?n(`device.primary`,{defaultValue:`Primary`}):b&&!y&&!v?n(`device.parts`,{defaultValue:`Parts`}):n(`device.children`,{defaultValue:`Children`}),C=p.length>0?i(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:x?e(`div`,{className:`space-y-2`,children:[e(`div`,{children:[i(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:n(`device.primary`,{defaultValue:`Primary`})}),i(`div`,{className:`space-y-1`,children:_.primary.map(e=>g(e.id,e))})]}),e(`div`,{children:[i(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:n(`device.parts`,{defaultValue:`Parts`})}),i(`div`,{className:`space-y-1`,children:_.parts.map(e=>g(e.id,e))})]})]}):e(u,{children:[S.length>0&&i(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:S}),i(`div`,{className:`space-y-1`,children:p.map(e=>g(e.id,e))})]})}):null,w=f.disabledSection===void 0?null:i(sn,{title:n(`device.disabledSection`,{defaultValue:`Disabled`}),count:f.disabledSection.children.length,defaultOpen:!1,children:i(`div`,{className:`opacity-60 space-y-1`,children:f.disabledSection.children.map(e=>g(e.id,e))})},f.disabledSection.title);if(f.sections.length===0)return w===null?C:e(`div`,{className:`space-y-2`,children:[C,w]});let T=y&&!v&&!b;return e(`div`,{className:`space-y-2`,children:[T?C:null,f.sections.map(e=>i(sn,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>g(e.id,e))},e.title)),T?null:C,w]})}function vs({initialName:e,label:t=`Name`,layout:n=`inline`,bound:r}){return i(ha,{label:t,layout:n,value:i(Jr,{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 ys({label:t=`Location`,layout:r=`inline`,bound:a}){let{t:o}=$(),{data:s}=ti(),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(ha,{label:t,layout:r,value:e(`div`,{className:`relative`,children:[i(Jr,{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(D,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),i(`span`,{className:`truncate`,children:t})]},t))})]})})}var bs=`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`,xs=0,Ss=10;function Cs(e){if(e.trim()===``)return``;let t=Number.parseInt(e,10);return Number.isFinite(t)?String(t<xs?xs:t>Ss?Ss:t):``}function ws({value:e,onChange:t,disabled:n=!1,placeholder:r,className:a,id:o,"aria-label":s}){return i(Jr,{type:`number`,min:xs,max:Ss,step:1,id:o,className:a??bs,"aria-label":s,placeholder:r,value:e,onChange:e=>{t(Cs(e.target.value))},disabled:n})}function Ts({deviceName:t,value:n,inheritedIcon:r,inheritedLabel:a,disabled:o,onChange:s}){let{t:c}=$(),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(Nn,{value:n===``?null:n,onPick:e=>s(e??``),categoryLabel:e=>c(`deviceDisplay.iconCategory.${e}`,{defaultValue:it(e)}),fallbackGlyph:r,labels:l,disabled:o}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n===``?a:n})]})}var Es=`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 Ds(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function Os({device:t,role:n,display:r,onChange:a}){let o=B();pr();let{t:s}=$(),c=l(),d=n===null?void 0:On[n],f=d?.kind===`numeric`,p=n!==null||t.parentDeviceId!==null&&t.parentDeviceId!==void 0,m=t.sourceInfo?.quantity,h=d?.kind===`numeric`?d.quantity??(m!==void 0&&m!==`device`?m:void 0):void 0,g=h===void 0?void 0:tt(h),_=g===void 0?void 0:wt(g),{data:v}=Or({},{staleTime:6e4,enabled:n!==null}),y=Zr({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),b=()=>{if(n===null)return;let e=Ds(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:xi(x),C=n===null?Ht(t.type,o):Bn(n,o),w={icon:S??gr(t.type,n),label:S===void 0?C.label:String(x)},T=n===null&&t.type===K.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?``:Bn(n,o).label;return e(`div`,{className:`mt-3 divide-y divide-border border-t border-border`,children:[i(ha,{label:s(`deviceDisplay.icon`),value:i(Ts,{deviceName:t.name,value:r.icon,inheritedIcon:w.icon,inheritedLabel:T,disabled:!1,onChange:e=>a({icon:e})})}),p&&i(ha,{label:s(`deviceDisplay.label`),value:i(Jr,{type:`text`,className:Es,"aria-label":s(`deviceDisplay.label`),placeholder:n===null?t.name:E,value:r.label,onChange:e=>a({label:e.target.value})})}),f&&e(u,{children:[i(ha,{label:s(`deviceDisplay.unit`),value:i(Gt,{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(ha,{label:s(`deviceDisplay.precision`),value:i(ws,{"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(q,{type:`button`,variant:`outline`,size:`sm`,onClick:b,disabled:y.isPending,title:s(`deviceDisplay.setRoleDefaultTitle`,{role:E}),children:s(`deviceDisplay.setRoleDefault`,{role:E})})})]})}var ks=new Set(Object.values(G));function As(e){return ks.has(e)}var js={[K.Switch]:[G.Siren,G.Floodlight,G.Spotlight,G.PirSensor,G.Chime,G.Autotrack,G.Nightvision,G.PrivacyMask,G.BinaryHelper,G.SwitchHeater,G.SwitchFan,G.SwitchLight],[K.Climate]:[G.ClimateThermostat,G.ClimateAc,G.ClimateFloor,G.ClimateRadiator,G.ClimateHeater,G.ClimateHeatPumpCircuit],[K.Light]:[G.Floodlight,G.Spotlight,G.Nightvision],[K.Siren]:[G.Siren],[K.Button]:[G.Doorbell],[K.Cover]:[G.CoverBlind,G.CoverShutter,G.CoverAwning,G.CoverCurtain,G.CoverGarage,G.CoverGate,G.CoverDoor,G.CoverWindow],[K.Sensor]:[G.MotionSensor,G.ContactSensor,G.LeakSensor,G.SmokeSensor,G.COSensor,G.GasSensor,G.TamperSensor,G.VibrationSensor,G.ConnectivitySensor,G.SoundSensor,G.BinarySensor,G.TemperatureSensor,G.HumiditySensor,G.AmbientLightSensor,G.PressureSensor,G.WindSensor,G.RainSensor,G.UvSensor,G.SolarRadiationSensor,G.SoilMoistureSensor,G.PowerSensor,G.EnergySensor,G.VoltageSensor,G.CurrentSensor,G.AirQualitySensor,G.BatterySensor,G.NumericSensor,G.EnumSensor,G.DateTimeSensor,G.GenericSensor],[K.Control]:[G.NumericControl,G.SelectControl,G.TextControl,G.DateTimeControl],[K.Notifier]:[G.MobilePushNotifier,G.MessagingNotifier,G.EmailNotifier,G.GenericNotifier],[K.Workload]:[...Ae]};function Ms(e){for(let t of Object.values(K))if(t===e)return!0;return!1}function Ns(e){return Ms(e)?js[e]??[]:[]}function Ps(e,t){let n=Ns(t);return e==null||e===``||n.includes(e)?n:[...n,e]}function Fs({device:t}){let{t:n}=$(),r=B(),a=ia(),o=Ri(),s=a?.identity??null,c=s?.name??t.name,l=s?.location??t.location??``,u=s?.role??t.role??null,d=s?.tags??t.tags??[],f=s?.display.hidden??t.display?.hidden===!0,p=a!==null&&s!==null;return e(`section`,{"aria-label":n(`customize.identity.title`),className:`${w} ${h}`,children:[e(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[p?i(vs,{deviceId:t.id,initialName:c,label:n(`customize.identity.name`),layout:`stacked`,bound:{value:c,onChange:a.setIdentityName}}):i(ha,{label:n(`customize.identity.name`),layout:`stacked`,value:c}),p?i(ys,{deviceId:t.id,initialLocation:l,label:n(`customize.identity.room`),layout:`stacked`,bound:{value:l,onChange:a.setIdentityLocation}}):i(ha,{label:n(`customize.identity.room`),layout:`stacked`,value:l===``?n(`common.unset`):l}),i(ha,{label:n(`common.tags`,`Tags`),layout:`stacked`,value:p?i(Lr,{value:d,onChange:a.setIdentityTags,label:n(`common.tags`,`Tags`)}):d.length>0?i($r,{tags:d,entries:o.entries}):n(`common.unset`)}),i(ha,{label:n(`customize.identity.type`),layout:`stacked`,value:t.type}),i(ha,{label:n(`customize.identity.hidden`),layout:`stacked`,value:i(V,{"aria-label":n(`deviceDisplay.hideFromLists`),checked:f,disabled:!p,onChange:e=>a?.setIdentityDisplay({hidden:e.target.checked})})}),i(ha,{label:n(`customize.identity.role`),layout:`stacked`,value:p?i(H,{"aria-label":n(`customize.identity.role`),value:u??``,options:[{value:``,label:n(`customize.identity.noRole`)},...Ps(u,t.type).map(e=>({value:e,label:Is(e,n(`customize.identity.noRole`),r)}))],onChange:e=>a.setIdentityRole(e.target.value===``?null:e.target.value)}):i(`span`,{children:Is(u,n(`customize.identity.noRole`),r)})})]}),s!==null&&a!==null&&i(Os,{device:t,role:u,display:s.display,onChange:a.setIdentityDisplay})]})}function Is(e,t,n){return e==null||e===``?t:As(e)?Bn(e,n).label:e}var Ls=`running-state`,Rs=`running`;function zs(e){return{...e,features:e.features.filter(e=>e.cap!==Ls)}}function Bs(e,t){return e===Ls&&t===Rs}function Vs(e){if(e===null||!xt(zs(e)))return{offered:!1};let t=To(e,Ls);return t===null?{offered:!0,following:!0,discardsRule:!1}:{offered:!0,following:!1,discardsRule:!W(t)}}function Hs(e,t){return t?Qa(e,Ls):{...zs(e),features:[...zs(e).features,Oe()]}}function Us(e,t,n){return Bs(e,t)&&Vs(n).offered}var Ws=`Assigned · `;function Gs(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(Ws)){let n=e.slice(11);return{kind:`assigned`,source:t??n}}return{kind:`unknown`}}var Ks={id:0,name:``,type:`unknown`,stableId:``,parentDeviceId:null};function qs(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 Js(e,t,n){let r=To(Ao(e.state),t);return W(r)?null:Je(r,t,n)}function Ys(e,t,n){return e?t===`pending`?`pending`:t===`unknown`?`unknown`:n?`present`:`absent`:`present`}function Xs(e,t,n,r){let i=e(`customize.scalar.caps.${n}`);if(_t(n)<=1)return i;let a=r.path??r.id,o=Ka(n,a,t);if(o!==a)return`${i} · ${o}`;let s=`customize.scalar.targets.${n}.${r.id}`,c=e(s);return`${i} · ${c===s?a:c}`}function Zs(e,t,n,r){let{t:i,i18n:a}=$(),o=Ia(),s=r.path??r.id,c=Xs(i,a.language,n,r),l=Ao(t.state),u=To(l,n),d=qs(t,Js(t,n,r.id)),f=d.kind===`known`&&d.value!==null?ht({feature:d.value,device:t.target,cap:n,targetId:r.id}):null,p=f!==null,m=Eo(p),h=f===null||m.kind!==`known`?null:m.value.find(e=>Ct({addonId:e.addonId,stableId:e.stableId})===Ct(f.draft.source))??null,g=$n(h===null?Ks:no(h),`compact`),_=h===null?null:g,v=$n(e,`full`),y=Ys(p,m.kind,h!==null),b=bt({cap:n,targetId:r.id,device:t.target,stored:d,sourcePresence:y,sourceUnknownReason:m.kind===`unknown`?m.reason:null}),x=async e=>{let n=await t.save(e);return n.kind===`refused`?n.reason:null},S=async()=>{if(l===null)return null;let e=Ua(l,n,r.id);return await o(i(`customize.scalar.removeWhat`,{name:_??(f===null?v:Ct(f.draft.source))}),e===null)?x(e):null},C=f===null?null:{source:{addonId:f.draft.source.addonId,stableId:f.draft.source.stableId,cap:f.draft.source.cap,fieldPath:f.draft.source.fieldPath,valueKind:f.sourceValueKind,sourceUnit:f.sourceUnit,changedAtField:f.changedAtField},transform:f.draft.transform};return{title:c,path:s,stored:d,recognized:p,otherFormula:!p&&d.kind===`known`&&d.value!==null,presence:y,released:b.status.state===`released`,badge:Gs(b.text,_),sourceName:_,sourceCap:f?.draft.source.cap??``,sourcePath:f?.draft.source.fieldPath??``,sourceField:f===null?``:Ka(f.draft.source.cap,f.draft.source.fieldPath,a.language),sourceDeviceId:h?.id??null,seed:C,answered:t.state.kind===`none`||t.state.kind===`present`,saving:t.saving,saveFeature:e=>x(Xa(l,t.target,e,n,r.id)),remove:S,linkStamp:u?.contributedBy?.linkId??null,enabled:u?.enabled!==!1,setEnabled:async e=>u===null?null:x(Za(l,t.target,{...u,enabled:e}))}}var Qs=ut,$s=[`power`,`readings`,`oscillation-axes`,`events`,`lists`,`extensions`],ec=new Set([`power-meter`,`power-source`,`battery`]),tc={scalar:`scalar`,keyedArray:`keyed`,event:`event`,config:`config`};function nc(e,t,n){if(n.section!==void 0)return n.section;if(ec.has(e))return`power`;switch(t){case`scalar`:return`readings`;case`event`:return`events`;case`keyed`:return`lists`;case`config`:return`extensions`}}function rc(e){let t=[];for(let[n,r]of Object.entries(Qs))for(let i of r.targets){let r=tc[i.cardinality];i.deviceTypes.includes(e)&&t.push({key:`${n}.${i.id}`,cap:n,kind:r,section:nc(n,r,i),target:i})}return t.toSorted((e,t)=>$s.indexOf(e.section)-$s.indexOf(t.section))}function ic(e,t,n){return e.map(e=>{if(e.kind===`config`)return{spec:e,availability:{kind:`present`,mode:`add`},linked:!0};let r=ja(La(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 ac(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 oc(e){return $s.filter(t=>e.some(e=>e.spec.section===t))}function sc(e){return e?.contributedBy?.linkId??null}function cc(e){return{remove:(e.recognized||e.otherFormula)&&e.linkStamp===null,linkToggle:e.linkStamp!==null}}function lc({children:e,muted:t}){return i(`span`,{className:`text-xs ${t===!0?`text-foreground-subtle`:`text-foreground`}`,children:e})}function uc(){let{t:e}=$();return i(`span`,{role:`status`,className:`text-xs text-foreground-subtle`,children:e(`customize.event.checking`)})}function dc({reason:e}){let{t}=$();return i(`span`,{role:`alert`,className:`text-xs text-warning`,title:e??void 0,children:t(`customize.table.unknown`)})}function fc(e){switch(e.spec.cap){case`remote`:return i(mc,{device:e.device});case`fan-presets`:return i(gc,{device:e.device});default:return i(dc,{reason:null})}}function pc(e){switch(e.spec.cap){case`remote`:return i(hc,{device:e.device});case`fan-presets`:return i(_c,{device:e.device});default:return i(dc,{reason:null})}}function mc({device:e}){let{t}=$(),n=kr({deviceId:e.id});if(n.status===`error`)return i(dc,{reason:n.error?.message??null});if(n.data===void 0)return i(uc,{});let r=Object.keys(n.data.bindings).length;return r===0&&n.data.layoutTemplateId==null?i(lc,{muted:!0,children:t(`customize.table.notConfigured`)}):i(lc,{children:t(`customize.table.commandsCount`,{count:r})})}function hc({device:e}){let{t}=$(),n=kr({deviceId:e.id}),r=vi({kind:`remote`});if(n.status===`error`)return i(dc,{reason:n.error?.message??null});if(n.data===void 0)return i(uc,{});let a=n.data.layoutTemplateId;if(a==null)return i(lc,{muted:!0,children:t(`remote.dialog.noTemplate`)});if(r.status===`error`)return i(dc,{reason:r.error?.message??null});let o=(r.data??[]).find(e=>e.id===a)?.name??null;return r.data===void 0?i(uc,{}):o===null?i(dc,{reason:null}):i(lc,{children:o})}function gc({device:e}){let{t}=$(),n=Ai({deviceId:e.id});return n.status===`error`?i(dc,{reason:n.error?.message??null}):n.data===void 0?i(uc,{}):n.data.length===0?i(lc,{muted:!0,children:t(`customize.table.noPresets`)}):i(lc,{children:t(`customize.table.presetsCount`,{count:n.data.length})})}function _c({device:e}){let{t}=$(),n=Ai({deviceId:e.id});return n.status===`error`?i(dc,{reason:n.error?.message??null}):n.data===void 0?i(uc,{}):n.data.length===0?i(lc,{muted:!0,children:t(`customize.table.noSource`)}):i(lc,{children:e.name})}function vc(e){let t=lt({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 yc(e){let t=ot({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 bc(e,t){return{deviceId:e,config:t.config}}function xc(e,t){return{deviceId:e,patch:{motionCooldownMs:t}}}async function Sc(e,t,n,r){await n(bc(e,t)),await r(xc(e,t.timeoutMs))}c();function Cc(t){let{t:n}=$(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(yi,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(dr,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(zn,{children:i(Vt,{children:r})}),t.open?i(wc,{...t}):null]})})}function wc(t){let{t:r}=$(),a=ai({projection:`slim`}),s=Oo(n(()=>a.status===`success`?go(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>Tc(t.sources)),[d,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=Ec(c),b=y.length===0?null:vc({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=kn({deviceId:c[0]?.deviceId??0}),C=Oc(S.status===`success`?S.data:void 0,x),w=St(He,C,Math.round(_*1e3));return e(u,{children:[e(Sn,{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(So,{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:d,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(Dc(C,w.lastPressedAt))}):null]}),e(hr,{className:`flex flex-wrap gap-2`,children:[i(q,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(q,{"data-testid":`event-save`,disabled:!t.canSave||b===null,onClick:()=>{b!==null&&t.onSave(b)},children:r(`customize.scalar.save`)})]})]})}function Tc(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 Ec(e){return e.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,changedAtField:e.changedAtField??Be[e.cap]??`lastChangedAt`}))}function Dc(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 Oc(e,t){if(e===void 0||t===null)return{kind:`unread`};let n=e[t.cap],r=n===void 0?void 0:Va(n,t.fieldPath),i=Be[t.cap]??t.changedAtField,a=n===void 0?void 0:Va(n,i);return typeof r==`boolean`?{kind:`level`,active:r,changedAt:typeof a==`number`&&Number.isFinite(a)?a:null}:{kind:`unread`}}function kc(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=Ac(t,n);return r===null?{kind:`unknown`,seconds:null}:{kind:`active`,seconds:r}}function Ac(e,t){if(e==null||!Number.isFinite(e)||e<Sa)return null;let n=Math.floor((t-e)/1e3);return n<0?0:n}function jc(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>=Sa?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 Mc={id:0,name:``,type:`unknown`,stableId:``,parentDeviceId:null};function Nc({device:t,handle:n,availability:r,cap:a,title:s,view:c}){let{t:l,i18n:d}=$(),f=Ia(),[p,m]=o(!1),[h,g]=o(null),_=Ao(n.state),v=To(_,a),y=Fc(n,v),b=y.kind===`known`&&y.value!==null?Ze({feature:y.value,device:n.target,cap:a,targetId:c.id,timestampPath:c.timestampPath,counterPath:c.counterPath}):null,x=b!==null,S=Eo(x),C=b?.draft.sources[0]??null,w=C===null||S.kind!==`known`?null:S.value.find(e=>Ct({addonId:e.addonId,stableId:e.stableId})===Ct(C))??null,E=Ic(x,S.kind,w!==null),D=$n(w===null?Mc:no(w),`compact`),O=$n(t,`full`),k=et({cap:a,targetId:c.id,device:n.target,timestampPath:c.timestampPath,counterPath:c.counterPath,apply:c.apply,stored:y,sourcePresence:E,sourceUnknownReason:S.kind===`unknown`?S.reason:null}),A=n.state.kind===`none`||n.state.kind===`present`;if(r.kind===`absent`||!c.deviceTypes.includes(t.type))return null;let j=async e=>{let t=await n.save(e);g(t.kind===`refused`?t.reason:null)},M=Lc(b),N=b?.draft.edges?.[0],P=N!==void 0&&c.edges.includes(N)?N:c.defaultEdge,F=C===null?``:Ka(C.cap,C.fieldPath,d.language),ee=y.kind===`known`&&y.value===null,I=!x&&y.kind===`known`&&y.value!==null;return e(u,{children:[i(eo,{id:a,icon:T,title:s,testId:`event-card-${a}`,actions:e(u,{children:[v!==null&&e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground`,children:[i(V,{"aria-label":l(`customize.doorbell.active`),checked:v.enabled!==!1,disabled:!A||n.saving,onChange:e=>{j(Za(_,n.target,{...v,enabled:e.target.checked}))}}),l(`customize.doorbell.active`)]}),i(X,{children:l(Wa(k.text,k.status.state))})]}),children:i(`div`,{className:`flex flex-col gap-2 px-3 py-2 sm:px-4`,children:r.kind===`pending`||r.kind===`present`&&!A?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:l(`customize.event.checking`)}):r.kind===`unknown`?i(J,{title:l(`customize.scalar.unreadable`),message:r.reason}):e(u,{children:[x&&C!==null&&i(`p`,{className:`text-xs text-foreground`,children:l(`customize.scalar.override`,{name:w===null?C.stableId:D,field:F})}),x&&i(Pc,{deviceId:t.id,cap:a,timestampPath:c.timestampPath,counterPath:c.counterPath,startedAt:n.state.kind===`present`?n.state.view.block.createdAt:null}),I&&v!==null&&e(`p`,{className:`text-xs text-foreground flex flex-wrap items-center gap-1`,children:[l(`customize.doorbell.otherFormula`),i(Ha,{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(q,{variant:`outline`,size:`sm`,disabled:n.saving,onClick:()=>m(!0),children:l(`customize.scalar.change`)}),x&&i(q,{variant:`ghost`,size:`sm`,disabled:n.saving,onClick:()=>{if(_===null)return;let e=Qa(_,a);f(l(`customize.doorbell.removeWhat`,{name:w===null?O:D}),e===null).then(t=>{t&&j(e)})},children:l(`customize.scalar.remove`)}),ee&&i(q,{variant:`outline`,size:`sm`,"data-testid":`event-add-${a}`,disabled:n.saving,onClick:()=>m(!0),children:l(`customize.scalar.add`)})]})]})})}),i(Cc,{open:p,mode:x?`change`:`add`,title:s,cap:a,targetId:c.id,host:t,target:n.target,enabled:v?.enabled!==!1,debounceMs:b?.draft.debounceMs??c.debounceMs,edges:c.edges,edge:P,sources:M,canSave:A&&!n.saving,onClose:()=>m(!1),onSave:e=>{m(!1),j(Za(_,n.target,e))}})]})}function Pc({deviceId:t,cap:n,timestampPath:r,counterPath:a,startedAt:o}){let{t:s}=$(),c=Ya({deviceId:t,cap:n,path:r}),l=Ya({deviceId:t,cap:n,path:a}),u=jc(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?``:xa(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:xa(u.lastPressedAt)}),u.pressCount===null?``:` · ${s(`customize.event.doorbellCount`,{count:u.pressCount})}`]})}function Fc(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 Ic(e,t,n){return e?t===`pending`?`pending`:t===`unknown`?`unknown`:n?`present`:`absent`:`present`}function Lc(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 Rc(t){let{t:n}=$(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(yi,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(dr,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(zn,{children:i(Vt,{children:r})}),t.open?i(zc,{...t}):null]})})}function zc(t){let{t:r}=$(),a=ai({projection:`slim`}),s=Oo(n(()=>a.status===`success`?go(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>Bc(t.sources)),[d,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=Vc(c),b=yc({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(u,{children:[e(Sn,{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(So,{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:d,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(Hc,{deviceId:x.deviceId,cap:x.cap,fieldPath:x.fieldPath,timeoutMs:Math.round(h*1e3)})]}),e(hr,{className:`flex flex-wrap gap-2`,children:[i(q,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(q,{"data-testid":`event-save`,disabled:!t.canSave||b===null,onClick:()=>{b!==null&&t.onSave(b)},children:r(`customize.scalar.save`)})]})]})}function Bc(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 Vc(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 Hc({deviceId:e,cap:t,fieldPath:n,timeoutMs:r}){let{t:a}=$(),o=Ya({deviceId:e,cap:t,path:n}),s=o.kind===`value`&&typeof o.value==`boolean`?{kind:`level`,active:o.value,changedAt:null}:{kind:`unread`},c=Ge(vt,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(Uc(s,c.open))})}function Uc(e,t){return e.kind===`unread`?`customize.event.previewWaiting`:t?`customize.event.previewMotionOn`:e.active?`customize.event.previewSensorOn`:`customize.event.previewMotionOff`}var Wc=60;function Gc(e){let t=Number.isFinite(e)?Math.max(0,Math.round(e)):0;return t<Wc?Q.t(`customize.event.durationSeconds`,{count:t}):Qo(t*1e3)}c();function Kc({device:n,availability:r,cap:a,title:s,view:c,sensors:l}){let{t:f}=$(),p=Ni(),m=Yt(),h=Di({addonId:`pipeline-orchestrator`,deviceId:n.id,nodeId:`hub`}),[g,_]=o(!1),[v,y]=o(null),b=t(!1),[x,S]=o(!1),C=Jc(l),w=Eo(!0),T=Qe(c.id,C),E=Qc(Zo(h.data).motionCooldownMs,c.timeoutMs);if(r.kind===`absent`||!c.deviceTypes.includes(n.type))return null;let D=x||p.isPending||m.isPending,O=T.writable&&!D&&r.kind===`present`,k=async e=>{if(!T.writable||b.current){y(f(`customize.saveInFlight`));return}b.current=!0,S(!0);try{await Sc(n.id,e,async e=>{await p.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 m.mutateAsync({deviceId:e.deviceId,patch:t})}),y(null),await l.refetch()===`failed`&&y(f(`customize.motion.refetchFailed`))}catch(e){y(e instanceof Error?e.message:String(e))}finally{b.current=!1,S(!1)}},A=T.rows.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:`binary`,fieldPath:`on`,mode:e.mode,label:e.name}));return e(u,{children:[i(eo,{id:a,icon:d,title:s,testId:`event-card-${a}`,actions:i(X,{children:f(Wa(T.text,T.status.state))}),children:i(`div`,{className:`flex flex-col gap-2 px-3 py-2 sm:px-4`,children:r.kind===`pending`||C.kind===`pending`?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:f(`customize.motion.reading`)}):r.kind===`unknown`||C.kind===`unknown`?i(Yc,{reason:Zc(C)||(r.kind===`unknown`?r.reason:``)}):e(u,{children:[i(qc,{deviceId:n.id}),T.rows.length===0?i(`p`,{className:`text-xs text-foreground-subtle`,children:f(`customize.scalar.noOverride`)}):i(`ul`,{className:`flex flex-col gap-1`,children:T.rows.map(t=>e(`li`,{className:`text-xs text-foreground`,children:[i(Xc,{row:t,fleet:w}),t.reason===null?``:` — ${f(`customize.motion.state.${t.state}`)}`]},t.key))}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:f(`customize.event.timeoutSeconds`,{duration:Gc(E/1e3)})}),v!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:v}),i(`div`,{className:`flex flex-wrap gap-2`,children:i(q,{variant:`outline`,size:`sm`,"data-testid":`event-add-${a}`,disabled:!O,onClick:()=>_(!0),children:T.rows.length===0?f(`customize.scalar.add`):f(`customize.scalar.change`)})})]})})}),i(Rc,{open:g,mode:T.rows.length===0?`add`:`change`,title:s,cap:a,targetId:c.id,host:n,target:{addonId:n.addonId,stableId:n.stableId},timeoutMs:E,cooldownMs:c.cooldownMs,sourceModes:c.sourceModes,sources:A,canSave:O,onClose:()=>_(!1),onSave:e=>{_(!1),k(e)}})]})}function qc({deviceId:e}){let{t}=$(),n=Ya({deviceId:e,cap:`motion`,path:`detected`}),r=Ya({deviceId:e,cap:`motion`,path:`lastDetectedAt`}),a=kc(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:Gc(a.seconds)})})}function Jc(e){return e.presence===`pending`?{kind:`pending`}:e.status===null?{kind:`unknown`,reason:e.failureReason}:{kind:`known`,value:e.status}}function Yc({reason:e}){let{t}=$(),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 Xc({row:e,fleet:t}){let n=Xn();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(no(r),t.value.map(no),n)}function Zc(e){return e.kind===`unknown`?e.reason??``:e.kind===`known`&&e.value.state===`unreadable`?e.value.reason:``}function Qc(e,t){return e!==null&&Number.isFinite(e)?e:t}var $c={id:0,name:``,type:`unknown`,stableId:``,parentDeviceId:null};function el(e){return zo().find(t=>t.cap===e)??null}function tl({spec:e,device:t,handle:n}){let r=el(e.cap);return r===null?i(rl,{}):r.pulse===null?i(qc,{deviceId:t.id}):i(Pc,{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 nl(e){let t=el(e.spec.cap);return t===null?i(rl,{}):t.pulse===null?i(ol,{...e,view:t.span}):i(al,{...e,cap:e.spec.cap,view:t.pulse})}function rl(){let{t:e}=$();return i(`span`,{className:`text-xs text-foreground-subtle`,children:e(`customize.table.unknown`)})}function il(){let{t:e}=$();return i(`span`,{role:`status`,className:`text-xs text-foreground-subtle`,children:e(`customize.event.checking`)})}function al({cap:e,view:t,handle:n}){let{t:r,i18n:a}=$(),o=qs(n,To(Ao(n.state),e)),s=(o.kind===`known`&&o.value!==null?Ze({feature:o.value,device:n.target,cap:e,targetId:t.id,timestampPath:t.timestampPath,counterPath:t.counterPath}):null)?.draft.sources[0]??null,c=Eo(s!==null),l=s===null||c.kind!==`known`?null:c.value.find(e=>Ct({addonId:e.addonId,stableId:e.stableId})===Ct(s))??null,u=$n(l===null?$c:no(l),`compact`);return o.kind===`pending`?i(il,{}):o.kind===`unknown`?i(rl,{}):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(il,{}):c.kind===`unknown`?i(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:r(`customize.scalar.sourceUnreadable`)}):l===null?i(X,{variant:`warning`,children:r(`customize.table.sourceMissing`)}):i(`span`,{className:`text-xs text-foreground`,children:r(`customize.table.sourceOf`,{name:u,field:Ka(s.cap,s.fieldPath,a.language)})})}function ol({sensors:t,view:n}){let{t:r}=$(),a=Eo(!0),o=Jc(t);if(n===null)return i(rl,{});if(o.kind===`pending`)return i(il,{});if(o.kind===`unknown`)return i(rl,{});let s=Qe(n.id,o);return s.rows.length===0?i(X,{children:r(Wa(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(Xc,{row:t,fleet:a}),t.reason===null?``:` — ${r(`customize.motion.state.${t.state}`)}`]},t.key))})}function sl(e,t){return e.some(e=>e.id===t.id)?e.map(e=>e.id===t.id?t:e):[...e,t]}function cl(e,t){return e.filter(e=>e.id!==t)}function ll(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 ul=[`horizontal`,`vertical`],dl=[`angle`,`sweepFrom`,`sweepTo`];function fl(e){let t=[e.speed,e.preset,e.direction].filter(e=>e!==void 0).length;return ul.reduce((t,n)=>{let r=e.oscillationAxes?.[n];return r===void 0?t:t+[r.oscillating,r.angle,r.sweepFrom,r.sweepTo].filter(e=>e!==void 0).length},t)}function pl(e,t,n){let r={...n.oscillating===void 0?{}:{oscillating:n.oscillating},...n.angle===void 0?{}:{angle:n.angle},...n.sweepFrom===void 0?{}:{sweepFrom:n.sweepFrom},...n.sweepTo===void 0?{}:{sweepTo:n.sweepTo}},i=n=>{let i=n===t?r:e.oscillationAxes?.[n];return i===void 0||Object.keys(i).length===0?void 0:i},a=i(`horizontal`),o=i(`vertical`),{oscillationAxes:s,...c}=e;return a===void 0&&o===void 0?c:{...c,oscillationAxes:{...a===void 0?{}:{horizontal:a},...o===void 0?{}:{vertical:o}}}}var ml=(e,t)=>e.trim().toLowerCase()===t.trim().toLowerCase();function hl(e,t){return t.name.trim()===``?{ok:!1,reason:`no-name`}:fl(t.state)===0?{ok:!1,reason:`no-fields`}:e.some(e=>e.id!==t.id&&ml(e.name,t.name))?{ok:!1,reason:`duplicate-name`}:{ok:!0}}function gl(e){return`${e.what}: ${e.reason}`}function _l(e){if(e.trim()===``)return;let t=Number(e);return Number.isFinite(t)?t:void 0}c();function vl(){let{t:e}=$();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-fields`:return e(`fanPresets.problem.noFields`,`Set at least one value, or use the current values.`);case`duplicate-name`:return e(`fanPresets.problem.duplicate`,`Another preset already has this name.`)}}}function yl({options:e,value:t,onChange:n,testId:r}){return i(`div`,{className:`flex flex-wrap gap-1`,"data-testid":r,children:e.map(e=>i(q,{size:`sm`,variant:e.value===t?`primary`:`outline`,onClick:()=>n(e.value),children:e.label},e.label))})}function bl({label:e,value:t,onChange:n,testId:r}){let{t:a}=$();return i(Z,{label:e,children:i(Jr,{type:`number`,value:t===void 0?``:String(t),placeholder:a(`fanPresets.dialog.unchanged`,`Unchanged`),onChange:e=>n(_l(e.target.value)),"data-testid":r})})}function xl({axis:t,want:n,onChange:r}){let{t:a}=$(),o=t===`horizontal`?a(`fanPresets.axis.horizontal`,`Horizontal axis`):a(`fanPresets.axis.vertical`,`Vertical axis`),s={angle:a(`fanPresets.axis.angle`,`Angle (°)`),sweepFrom:a(`fanPresets.axis.sweepFrom`,`Sweep from (°)`),sweepTo:a(`fanPresets.axis.sweepTo`,`Sweep to (°)`)};return e(`div`,{className:`space-y-2 rounded border border-border p-3`,"data-testid":`fan-preset-axis-${t}`,children:[i(`p`,{className:`text-xs font-medium text-foreground`,children:o}),i(Z,{label:a(`fanPresets.axis.oscillating`,`Oscillation`),children:i(yl,{testId:`fan-preset-axis-${t}-oscillating`,value:n.oscillating,onChange:e=>r({...n,oscillating:e}),options:[{value:void 0,label:a(`fanPresets.dialog.unchanged`,`Unchanged`)},{value:!0,label:a(`fanPresets.axis.on`,`On`)},{value:!1,label:a(`fanPresets.axis.off`,`Off`)}]})}),i(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-3`,children:dl.map(e=>i(bl,{label:s[e],value:n[e],onChange:t=>r({...n,[e]:t}),testId:`fan-preset-axis-${t}-${e}`},e))})]})}function Sl({fanId:t,draft:n,others:r,saving:a,error:s,onSave:c,onClose:l}){let{t:u}=$(),d=vl(),[f,p]=o(n),[h,g]=o([]),_=Ar({deviceId:t},{enabled:!1,gcTime:0,retry:!1}),v=hl(r,f),y=d(v),b=e=>p(t=>({...t,state:e})),x=f.state;return i(yi,{open:!0,onOpenChange:e=>!e&&l(),children:e(dr,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(zn,{children:i(Vt,{children:u(`fanPresets.dialog.title`,`Fan preset`)})}),i(Sn,{children:e(`div`,{className:`space-y-3`,"data-testid":`fan-preset-editor`,children:[i(Z,{label:u(`fanPresets.dialog.name`,`Name`),children:i(Jr,{value:f.name,maxLength:40,placeholder:u(`fanPresets.dialog.namePlaceholder`,`Night, Boost, Away…`),onChange:e=>p({...f,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:u(`fanPresets.dialog.stateHint`,`Set only what this preset should change. An empty value is left as it is.`)}),e(q,{size:`sm`,variant:`outline`,disabled:_.isFetching,onClick:()=>{_.refetch().then(e=>{e.data!==void 0&&(b(e.data.state),g(e.data.omitted))})},"data-testid":`fan-preset-use-current`,children:[_.isFetching?i(m,{className:`h-4 w-4 animate-spin`}):i(me,{className:`h-4 w-4`}),` `,u(`fanPresets.dialog.useCurrent`,`Use current values`)]})]}),_.isError&&i(J,{message:_.error?.message??u(`fanPresets.dialog.captureFailed`,`The current values could not be read.`)}),h.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:u(`fanPresets.dialog.omitted`,`These values could not be read, so they were left out:`)}),i(`ul`,{className:`mt-1 list-disc pl-4`,children:h.map(e=>i(`li`,{children:gl(e)},`${e.what}:${e.reason}`))})]}),e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[i(bl,{label:u(`fanPresets.field.speed`,`Speed (%)`),value:x.speed,onChange:e=>{let{speed:t,...n}=x;b(e===void 0?n:{...n,speed:e})},testId:`fan-preset-speed`}),i(Z,{label:u(`fanPresets.field.preset`,`Fan preset mode`),children:i(Jr,{value:x.preset??``,placeholder:u(`fanPresets.dialog.unchanged`,`Unchanged`),onChange:e=>{let{preset:t,...n}=x,r=e.target.value;b(r===``?n:{...n,preset:r})},"data-testid":`fan-preset-mode`})})]}),i(Z,{label:u(`fanPresets.field.direction`,`Direction`),children:i(yl,{testId:`fan-preset-direction`,value:x.direction,onChange:e=>{let{direction:t,...n}=x;b(e===void 0?n:{...n,direction:e})},options:[{value:void 0,label:u(`fanPresets.dialog.unchanged`,`Unchanged`)},{value:`forward`,label:u(`fanPresets.field.forward`,`Forward`)},{value:`reverse`,label:u(`fanPresets.field.reverse`,`Reverse`)}]})}),ul.map(e=>i(xl,{axis:e,want:x.oscillationAxes?.[e]??{},onChange:t=>b(pl(x,e,t))},e)),y!==null&&f.name!==``&&i(`p`,{className:`text-xs text-warning`,children:y}),s!==null&&i(J,{message:s})]})}),e(hr,{children:[i(q,{variant:`ghost`,onClick:l,children:u(`common.cancel`,`Cancel`)}),e(q,{disabled:a||!v.ok,onClick:()=>c({...f,name:f.name.trim()}),children:[a&&i(m,{className:`h-4 w-4 animate-spin`}),` `,u(`common.save`,`Save`)]})]})]})})}c();function Cl({device:t}){let{t:n}=$(),r=ae(),a=l(),s=Ai({deviceId:t.id}),[c,u]=o(null),[d,f]=o(null),p=ci({onSuccess:e=>{if(e.status===`refused`){f(e.detail);return}f(null),u(null),a.invalidateQueries({queryKey:[[`fanPresets`]]}),a.invalidateQueries({queryKey:[[`actions`]]})}}),m=s.data,h=e=>p.mutate({deviceId:t.id,presets:[...e]});return e(eo,{id:`fan-presets`,title:n(`fanPresets.card.title`,`Presets`),icon:L,testId:`customize-fan-presets`,actions:e(q,{size:`sm`,variant:`outline`,disabled:m===void 0,onClick:()=>u({id:ll(m??[]),name:``,state:{}}),"data-testid":`fan-presets-add`,children:[i(te,{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.`)}):m===void 0?i(`p`,{role:`status`,className:`px-3 py-2 text-xs text-foreground-subtle`,children:n(`fanPresets.card.loading`,`Loading presets…`)}):m.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’s speed, mode, direction and oscillation in one go.`)}):i(`ul`,{className:`divide-y divide-border-subtle`,"data-testid":`fan-presets-list`,children:m.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(X,{variant:`info`,children:n(`fanPresets.card.fields`,`Values: {{count}}`,{count:fl(t.state)})}),i(Y,{icon:oe,variant:`ghost`,"aria-label":n(`fanPresets.card.edit`,`Edit {{name}}`,{name:t.name}),onClick:()=>u(t)}),i(Y,{icon:le,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&&h(cl(m,t.id))})}})]},t.id))}),c!==null&&m!==void 0&&i(Sl,{fanId:t.id,draft:c,others:m,saving:p.isPending,error:d??p.error?.message??null,onSave:e=>h(sl(m,e)),onClose:()=>{u(null),f(null)}})]})}function wl(e){let t={kind:`devices`,ids:e.deviceId>0?[e.deviceId]:[]},n=e.cap===``?void 0:gt(e.cap,e.method,e.args),r=n===void 0?{}:Ye(n)?.action.args??{},i=Object.fromEntries(Object.entries(e.args??{}).filter(([e])=>!(e in r)));return{kind:`command`,target:t,actionId:n??``,...Object.keys(i).length===0?{}:{args:i},...e.argUnits===void 0?{}:{argUnits:e.argUnits}}}function Tl(e){if(e.target.kind!==`devices`||e.target.ids.length!==1)return null;let t=e.target.ids[0];if(t===void 0||Ye(e.actionId)===void 0)return null;let n=st(e.actionId,e.args);return{kind:`cap`,deviceId:t,cap:n.cap,method:n.method,...Object.keys(n.args).length===0?{}:{args:{...n.args}},...e.argUnits===void 0?{}:{argUnits:e.argUnits}}}var El=`ir-transmitter`;function Dl(e,t){let n=new Map(t.customButtons.map(e=>[Xe(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)||dt(e))return;i.add(e);let o=Ce(e)!==null;a.push({role:e,custom:o,inLayout:t,name:o?n.get(e)??r.get(e)??bi(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 Ol(e,t,n){let r=Ce(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 kl(e,t,n,r=bi(t)){return Ol({...e,bindings:{...e.bindings,[t]:{action:n}}},t,r)}function Al(e,t){let n=Object.fromEntries(Object.entries(e.bindings).filter(([e])=>e!==t)),r=Ce(t);return{...e,bindings:n,customButtons:r===null?e.customButtons:e.customButtons.filter(e=>e.key!==r)}}function jl(e){return e.deviceId>0&&e.cap!==``&&e.method!==``}var Ml={kind:`cap`,deviceId:0,cap:``,method:``};function Nl(e){let{action:t}=e;return t.cap===`ir-transmitter`&&t.method===`send`?t.deviceId:null}function Pl(e,t){return{action:{...e.action,deviceId:t}}}function Fl(e){let t=Object.entries(e.bindings).filter(([,e])=>!jl(e.action)).map(([e])=>e);if(t.length>0)return{incomplete:t,config:null};let n=Ue.safeParse(e);return{incomplete:t,config:n.success?n.data:null}}function Il(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=pt(n),r=Pe(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 We)return{status:`refused`,reason:`not-smartir`};throw e}}function Ll(e,t){if(t===null||t<=0)return{status:`refused`,reason:`no-transmitter`};try{let n=Me(Ne(e),{transmitterDeviceId:t});return{status:`ok`,draft:n,bound:Object.keys(n.bindings).length,skipped:n.skipped}}catch(e){if(e instanceof We)return{status:`refused`,reason:`not-flipper`};throw e}}function Rl(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))]}}var zl={kind:`digits`,name:``,number:``,steps:[],transmitterId:null,encoding:`raw`,nativeFormat:`tuya`,code:``,carrierKhz:``};function Bl(e){switch(e.kind){case`digits`:return{...zl,kind:`digits`,name:e.name,number:e.number};case`sequence`:return{...zl,kind:`sequence`,name:e.name,steps:e.steps};case`ir`:return{...zl,kind:`ir`,name:e.name,transmitterId:e.transmitterId??null,...e.payload.kind===`pronto`?{encoding:`pronto`,code:e.payload.code}:e.payload.kind===`native`?{encoding:`native`,nativeFormat:e.payload.format,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 Vl(e){if(e.encoding===`pronto`)return{kind:`pronto`,code:e.code.trim()};if(e.encoding===`native`)return{kind:`native`,format:e.nativeFormat,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)}}}function Hl(e){let t=e.payload.kind;try{let{timings:n,settings:r}=nt(e.payload);return{encoding:t,pulses:n.length,carrierKhz:r.carrierHz===void 0?null:r.carrierHz/1e3}}catch(e){if(e instanceof We)return{encoding:t,pulses:null,carrierKhz:null};throw e}}function Ul(e){return Object.keys(e.bindings)}var Wl=48;function Gl(e,t){let n=t.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,Wl-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 Kl(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,...e.transmitterId===null?{}:{transmitterId:e.transmitterId},payload:Vl(e)}}}function ql(e,t,n){if(n===null){let n=Kl(t,Gl(e,t.name));return{...e,sources:[...e.sources,n]}}return{...e,sources:e.sources.map(e=>e.id===n?Kl(t,n):e)}}function Jl(e,t){return{...e,sources:e.sources.filter(e=>e.id!==t)}}function Yl(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 Xl(e,t){return{...e,stepDelayMs:t}}var Zl=[`id`,`name`,`number`,`steps`,`kind`,`transmitterId`,`payload`];function Ql(e){return Zl.some(t=>t===e)}function $l(e){let t=Ue.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=Ql(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 eu(e,t,n){let r=ql(e,t,n),i=n===null?r.sources.length-1:r.sources.findIndex(e=>e.id===n),a=$l(r).bySource.get(i)??[];return t.kind===`ir`&&t.transmitterId===null&&e.defaultTransmitterId===null?[...a,{field:`transmitterId`,code:`no_emitter`,message:`Pick an emitter: the remote has no default one`}]:a}function tu(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function nu(e){let t=e.args??{},n=t.timings,r=t.settings,i=typeof r==`object`&&r&&`carrierHz`in r?tu(r.carrierHz):null;return{call:`${e.cap}.${e.method}`,timings:Array.isArray(n)?n.length:null,carrierHz:i}}function ru(e,t,n){let r=t.find(t=>t.id===e);return r===void 0?n:iu(r)}function iu(e){return e.parentName?`${e.name} · ${e.parentName}`:e.name}function au(e){return Object.entries(e).flatMap(([e,t])=>typeof t==`string`||typeof t==`number`||typeof t==`boolean`?[{name:e,value:String(t)}]:[])}function ou(e,t){if(e===void 0)return{kind:`unbound`};if(!jl(e))return{kind:`incomplete`};let n=ru(e.deviceId,t,`#${e.deviceId}`),r=nu(e),i=au(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 su(e){return Array.isArray(e)&&e.every(e=>typeof e==`number`)}function cu(e){if(!jl(e))return null;let t=e.args??{};if(e.cap===`ir-transmitter`&&e.method===`send`&&su(t.timings)){let n=t.timings,r=nu(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 lu({description:e}){let{t}=$();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 uu({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 du({code:t,role:n}){let{t:r}=$();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(qt,{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 fu({role:t,name:n,binding:r,devices:a,transmitters:s,testable:c,testResult:l,onBind:d,onClear:f,onTest:p}){let{t:m}=$(),h=wn()(Ee(t.role)),[g,_]=o(!1),v=r!==void 0&&jl(r.action),y=r===void 0?null:Nl(r),b=ou(r?.action,a),x=r===void 0?null:cu(r.action),S=r!==void 0&&y===null&&r.action.cap!==``&&wl(r.action).actionId===``,C=r!==void 0&&y===null&&(g||!v&&!S);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(X,{variant:`neutral`,children:m(`remote.bindings.custom`)}),!t.inLayout&&i(X,{variant:`warning`,children:m(`remote.bindings.notInLayout`)}),y!==null&&i(X,{variant:`info`,children:m(`remote.bindings.infrared`)})]}),e(`dl`,{className:`space-y-2`,"data-testid":`binding-description`,children:[e(uu,{label:m(`remote.panel.does`),children:[i(`span`,{className:r===void 0?`text-foreground-subtle`:void 0,"data-testid":`summary-${t.role}`,children:i(lu,{description:b})}),v&&i(`span`,{className:`block text-foreground-muted`,children:m(`remote.panel.repeatValue`)})]}),y!==null&&r!==void 0&&i(uu,{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:iu(e)})),onChange:e=>d(Pl(r,Number(e.target.value)).action),"data-testid":`transmitter-${t.role}`})}),x!==null&&i(uu,{label:m(`remote.panel.code`),children:i(du,{code:x,role:t.role})})]}),C&&r!==void 0&&i(Z,{label:m(`commands.change`),children:i(Vo,{step:wl(r.action),devices:a,variables:[],singleTarget:!0,autoOpen:S,onChange:e=>{let t=Tl(e);t!==null&&d(t)}})}),i(`div`,{className:`flex flex-wrap items-center gap-1`,children:r===void 0?i(q,{size:`sm`,variant:`outline`,onClick:()=>{_(!0),d(Ml)},"data-testid":`bind-${t.role}`,children:m(`remote.bindings.bind`)}):e(u,{children:[y===null&&(v||S)&&!g&&i(q,{size:`sm`,variant:`outline`,onClick:()=>_(!0),"data-testid":`edit-${t.role}`,children:m(`commands.change`)}),i(q,{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(q,{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 pu=`media-player`;function mu(e){return e.stableId.startsWith(`composed-`)?e.stableId.slice(De.length):null}function hu(e){return e.target.kind!==`new`||e.features.some(e=>e.cap===pu)?null:{...e,features:[...e.features,{kind:`fields`,cap:pu,fields:{},commands:ke()}]}}var gu=`Lucaslhm/Flipper-IRDB`,_u=`main`,vu=600*1e3,yu=class extends Error{code;resetAtMs;constructor(e,t,n=null){super(t),this.name=`FlipperIrdbError`,this.code=e,this.resetAtMs=n}},bu=Dt(Et({name:Tt(),path:Tt(),type:Tt()}));function xu(e){return e.split(`/`).filter(e=>e!==``).map(encodeURIComponent).join(`/`)}function Su(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 Cu(e,t){let n=t.trim().toLowerCase();return n===``?e:e.filter(e=>e.name.toLowerCase().includes(n))}function wu(e={}){let t=e.fetchFn??((e,t)=>fetch(e,t)),n=e.now??Date.now,r=e.ttlMs??vu,i=new Map;async function a(e){let n;try{n=await t(e)}catch(e){throw new yu(`network`,e instanceof Error?e.message:`request failed`)}if(n.status===404)throw new yu(`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 yu(`rate-limited`,`GitHub rate limit reached`,Number.isFinite(e)&&e>0?e*1e3:null)}if(!n.ok)throw new yu(`bad-response`,`GitHub answered ${n.status}`);return n}return{async list(e){let t=xu(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/${gu}/contents/${t}`),c=bu.safeParse(await s.json().catch(()=>null));if(!c.success)throw new yu(`bad-response`,`Not a directory listing`);let l=Su(c.data);return i.set(t,{at:n(),entries:l}),l},async readFile(e){return(await a(`https://raw.githubusercontent.com/${gu}/${_u}/${xu(e)}`)).text()}}}c();function Tu(e){return e instanceof yu?e:new yu(`network`,`request failed`)}function Eu({transmitterId:t,onApply:r,client:s}){let{t:c}=$(),l=n(()=>s??wu(),[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:Tu(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(Ll(e,t))).catch(e=>_(Tu(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`?Cu(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(q,{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(de,{className:`h-3 w-3 text-foreground-subtle`,"aria-hidden":!0}),i(q,{size:`sm`,variant:`ghost`,onClick:()=>{d(S.slice(0,n+1).join(`/`)),p(``),y(null)},children:t})]},t+String(n)))]}),i(Jr,{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(q,{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(Lt,{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(q,{size:`sm`,disabled:v.bound===0,onClick:()=>{r(v.draft),y(null)},"data-testid":`flipper-apply`,children:c(`remote.import.apply`)})]})]})}c();function Du({transmitterId:n,onApply:r}){let{t:a}=$(),s=t(null),[c,l]=o(``),[u,d]=o(null),[f,p]=o(null),m=e=>{p(e.trim()===``?null:Il(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(Z,{label:a(`remote.import.pasteLabel`),children:i(Hi,{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(Pi,{ref:s,accept:`application/json,.json`,className:`hidden`,onChange:e=>void h(e),"data-testid":`smartir-file`}),e(q,{size:`sm`,variant:`outline`,onClick:()=>s.current?.click(),children:[i(Rt,{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(q,{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(q,{size:`sm`,disabled:f.bound===0,onClick:()=>{r(f.draft),l(``),d(null),p(null)},"data-testid":`smartir-apply`,children:a(`remote.import.apply`)})]})]})}c();function Ou(e){return e.native===null?{encoding:`raw`,code:e.timings.join(`, `),carrierKhz:e.carrierHz===null?``:String(e.carrierHz/1e3)}:{encoding:`native`,nativeFormat:e.native.format,code:e.native.code,carrierKhz:``}}function ku({transmitterId:t,onLearned:n}){let{t:r}=$(),a=Ui({deviceId:t}),s=xr(),[c,l]=o(null);return a.data?.learn===!0?e(`div`,{className:`flex flex-col gap-1`,children:[i(q,{variant:`secondary`,size:`sm`,className:`self-start`,disabled:s.isPending,onClick:()=>{l(null),s.mutateAsync({deviceId:t}).then(e=>n(Ou(e))).catch(e=>{l(e instanceof Error?e.message:r(`remote.sources.learn.failed`))})},"data-testid":`source-learn`,children:s.isPending?r(`remote.sources.learn.pending`):r(`remote.sources.learn.button`)}),i(`p`,{className:`text-xs text-foreground-muted`,children:r(`remote.sources.learn.hint`)}),c!==null&&i(`p`,{className:`text-xs text-danger`,role:`alert`,"data-testid":`source-learn-error`,children:c})]}):null}function Au(e,t){return t(`remote.sources.error.${e.field}.${e.code}`,{defaultValue:e.message})}function ju(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 Mu({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 Nu(e){return ze.some(t=>t===e)}function Pu({config:t,source:r,roleLabel:a,transmitters:s,onClose:c,onSave:l}){let{t:d}=$(),[f,p]=o(r===null?zl:Bl(r)),[m,h]=o(!1),[g,_]=o(``),v=n(()=>eu(t,f,r?.id??null),[t,f,r]),y=Ul(t),b=e=>p(t=>({...t,...e})),x=e=>m?ju(v,e,f.kind).map(e=>Au(e,d)):[],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(Oi,{open:!0,onClose:c,title:d(r===null?`remote.sources.dialog.addTitle`:`remote.sources.dialog.editTitle`),testId:`source-dialog`,footer:i(q,{onClick:()=>{h(!0),!(v.length>0)&&l(ql(t,f,r?.id??null))},"data-testid":`source-save`,children:d(`common.save`)}),children:e(`div`,{className:`space-y-4`,children:[i(Z,{label:d(`remote.sources.dialog.kind`),children:i(H,{value:f.kind,options:ze.map(e=>({value:e,label:d(`remote.sources.kind.${e}`)})),onChange:e=>{Nu(e.target.value)&&b({kind:e.target.value})},"data-testid":`source-kind`})}),i(Z,{label:d(`remote.sources.dialog.name`),children:i(Jr,{value:f.name,state:x(`name`).length>0?`error`:`default`,onChange:e=>b({name:e.target.value}),"data-testid":`source-name`})}),i(Mu,{lines:x(`name`)}),f.kind===`ir`&&i(Iu,{draft:f,transmitters:s,defaultTransmitterId:t.defaultTransmitterId,patch:b,lines:x}),f.kind===`digits`&&e(u,{children:[i(Z,{label:d(`remote.sources.dialog.number`),description:d(`remote.sources.dialog.numberHint`),children:i(Jr,{value:f.number,inputMode:`numeric`,state:x(`number`).length>0?`error`:`default`,onChange:e=>b({number:e.target.value}),"data-testid":`source-number`})}),i(Mu,{lines:x(`number`)})]}),f.kind===`sequence`&&e(`div`,{className:`space-y-2`,children:[i(Z,{label:d(`remote.sources.dialog.steps`),description:d(`remote.sources.dialog.stepsHint`),children:f.steps.length===0?i(`p`,{className:`text-xs text-foreground-muted`,children:d(`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":d(`remote.sources.dialog.stepUp`),disabled:n===0,onClick:()=>S(n,-1)}),i(Y,{icon:ge,size:`sm`,variant:`ghost`,"aria-label":d(`remote.sources.dialog.stepDown`),disabled:n===f.steps.length-1,onClick:()=>S(n,1)}),i(Y,{icon:le,size:`sm`,variant:`ghost`,"aria-label":d(`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:d(`remote.sources.dialog.noBound`)}):e(`div`,{className:`flex items-center gap-2`,children:[i(H,{"aria-label":d(`remote.sources.dialog.pickStep`),value:g,options:[{value:``,label:d(`remote.sources.dialog.pickStep`)},...y.map(e=>({value:e,label:a(e)}))],onChange:e=>_(e.target.value),"data-testid":`source-step-pick`}),i(q,{size:`sm`,variant:`secondary`,disabled:g===``,onClick:()=>{b({steps:[...f.steps,g]}),_(``)},"data-testid":`source-step-add`,children:d(`remote.sources.dialog.addStep`)})]}),i(Mu,{lines:x(`steps`)})]})]})})}function Fu(e,t){return e===`pronto`?`pronto`:e===`native`&&t===`native`?`native`:`raw`}function Iu({draft:t,transmitters:n,defaultTransmitterId:r,patch:a,lines:o}){let{t:s}=$(),c=n.find(e=>e.id===r)?.label,l=t.transmitterId??r??null;return e(u,{children:[i(Z,{label:s(`remote.sources.dialog.transmitter`),children:i(H,{value:t.transmitterId===null?``:String(t.transmitterId),options:[{value:``,label:c===void 0?s(`remote.sources.dialog.noTransmitter`):`${s(`remote.sources.dialog.noTransmitter`)} (${c})`},...n.map(e=>({value:String(e.id),label:e.label}))],onChange:e=>a({transmitterId:e.target.value===``?null:Number(e.target.value)}),"data-testid":`source-transmitter`})}),i(Mu,{lines:o(`transmitterId`)}),l!==null&&i(ku,{transmitterId:l,onLearned:a}),i(Z,{label:s(`remote.sources.dialog.encoding`),children:i(H,{value:t.encoding,options:[{value:`raw`,label:s(`remote.sources.encoding.raw`)},{value:`pronto`,label:s(`remote.sources.encoding.pronto`)},...t.encoding===`native`?[{value:`native`,label:s(`remote.sources.encoding.native`)}]:[]],onChange:e=>a({encoding:Fu(e.target.value,t.encoding)}),"data-testid":`source-encoding`})}),i(Z,{label:s(`remote.sources.dialog.code`),description:t.encoding===`pronto`?s(`remote.sources.dialog.prontoHint`):t.encoding===`native`?s(`remote.sources.dialog.nativeHint`):s(`remote.sources.dialog.codeHint`),children:i(Hi,{value:t.code,rows:4,spellCheck:!1,className:`font-mono text-xs`,state:o(`payload`).length>0?`error`:`default`,onChange:e=>a({code:e.target.value}),"data-testid":`source-code`})}),t.encoding===`raw`&&i(Z,{label:s(`remote.sources.dialog.carrier`),description:s(`remote.sources.dialog.carrierHint`),children:i(Jr,{value:t.carrierKhz,inputMode:`decimal`,className:`w-32`,onChange:e=>a({carrierKhz:e.target.value}),"data-testid":`source-carrier`})}),i(Mu,{lines:o(`payload`)})]})}c();function Lu({source:e,roleLabel:t}){let{t:n}=$();switch(e.kind){case`digits`:return e.number;case`sequence`:return Ve(e).map(t).join(` → `);case`ir`:{let t=Hl(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 Ru({config:t,onChange:r,roleLabel:a,transmitters:s}){let{t:c}=$(),[l,u]=o(null),d=n(()=>$l(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(X,{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(Lu,{source:t,roleLabel:a})}),(d.bySource.get(n)??[]).map(e=>i(`p`,{role:`alert`,className:`text-xs text-danger`,children:Au(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=>Yl(e,t.id,-1))}),i(Y,{icon:ge,size:`sm`,variant:`ghost`,"aria-label":c(`remote.sources.moveDown`),disabled:n===f,onClick:()=>r(e=>Yl(e,t.id,1))}),i(Y,{icon:oe,size:`sm`,variant:`ghost`,"aria-label":c(`remote.sources.edit`),onClick:()=>u({source:t})}),i(Y,{icon:le,size:`sm`,variant:`ghost`,"aria-label":c(`remote.sources.delete`),onClick:()=>r(e=>Jl(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(q,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>u({source:null}),"data-testid":`source-add`,children:[i(te,{className:`mr-1 h-3 w-3`,"aria-hidden":!0}),c(`remote.sources.add`)]})]}),t.sources.length===0?i(fi,{icon:Pt,title:c(`remote.sources.empty`)}):i(Qn,{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(Z,{label:c(`remote.sources.stepDelay`),description:c(`remote.sources.stepDelayHint`),error:d.stepDelay===null?void 0:c(`remote.sources.error.stepDelay`,{min:100,max:Le}),children:i(Jr,{type:`number`,inputMode:`numeric`,className:`w-32`,value:Number.isNaN(t.stepDelayMs)?``:t.stepDelayMs,state:d.stepDelay===null?`default`:`error`,onChange:e=>r(t=>Xl(t,e.target.valueAsNumber)),"data-testid":`source-step-delay`})}),l!==null&&i(Pu,{config:t,source:l.source,roleLabel:a,transmitters:s,onClose:()=>u(null),onSave:e=>{r(()=>e),u(null)}},l.source?.id??`new`)]})}c();function zu({device:t,open:n,onClose:r}){let{t:a}=$(),o=kr({deviceId:t.id},{enabled:n});return i(yi,{open:n,onOpenChange:e=>!e&&r(),children:i(dr,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,children:o.data===void 0?e(u,{children:[i(zn,{children:i(Vt,{children:a(`remote.dialog.title`,{name:t.name})})}),i(Sn,{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(Vu,{device:t,initial:o.data,onClose:r})})})}function Bu(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 Vu({device:t,initial:r,onClose:a}){let{t:s,i18n:c}=$(),d=l(),[f,p]=o(r),[m,h]=o(null),[g,_]=o(null),[v,y]=o(null),b=Bo(),[x,S]=o({}),C=vi({kind:`remote`}),w=oi({deviceId:t.id}),T=Ho(),E=Ur({capNames:[El]}),D=Wr(),O=mu(t),k=Er({blockId:O??``},{enabled:O!==null}),A=Bi(),j=Ti(),M=n(()=>{let e=new Set(E.data??[]);return T.filter(t=>e.has(t.id))},[T,E.data]),N=(C.data??[]).find(e=>e.id===f.layoutTemplateId),P=N===void 0?null:cr(N.payload),F=n(()=>Dl(P,f),[P,f]),ee=n(()=>new Set((w.data?.commands??[]).map(e=>e.role)),[w.data]),I=e=>e.name??P?.buttons.find(t=>t.role===e.role)?.label??Hn(e.role,c.language),L=F.find(e=>e.role===g),te=P?.buttons.find(e=>e.role===g)?.id??null,ne=F.filter(e=>!e.inLayout),R=Fl(f),re=n(()=>new Set(Object.keys(f.bindings)),[f.bindings]),ie=async()=>{let e=k.data?.state===`loaded`?k.data.view:null;if(O===null||e===null)return;let t=yt(e.block),n=t===null?null:hu(t);n!==null&&await A.mutateAsync({blockId:O,expectedUpdatedAt:e.block.updatedAt,block:{composition:n}})},z=async()=>{if(R.config!==null){h(null);try{let e=await D.mutateAsync({deviceId:t.id,config:R.config});if(e.status===`refused`){h(e.detail);return}await ie(),await d.invalidateQueries({queryKey:[[`remote`]]}),a()}catch(e){h(e instanceof Error?e.message:String(e))}}},B=async e=>{try{let n=await j.mutateAsync({deviceId:t.id,role:e,repeat:1});S(t=>({...t,[e]:Bu(n,s)}))}catch(t){S(n=>({...n,[e]:t instanceof Error?t.message:String(t)}))}},ae=(e,t)=>p(n=>kl(n,e,t));return v===null?e(u,{children:[i(zn,{children:i(Vt,{children:s(`remote.dialog.title`,{name:t.name})})}),e(Sn,{className:`space-y-5`,children:[e(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[i(Z,{label:s(`remote.dialog.template`),children:i(H,{value:f.layoutTemplateId??``,options:[{value:``,label:s(`remote.dialog.noTemplate`)},...(C.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(Z,{label:s(`remote.dialog.transmitter`),children:i(H,{value:f.defaultTransmitterId===null?``:String(f.defaultTransmitterId),options:[{value:``,label:s(`remote.dialog.noTransmitter`)},...M.map(e=>({value:String(e.id),label:iu(e)}))],onChange:e=>p(t=>({...t,defaultTransmitterId:e.target.value===``?null:Number(e.target.value)})),"data-testid":`remote-transmitter`})})]}),C.data!==void 0&&C.data.length===0&&i(`p`,{className:`text-xs text-foreground-muted`,children:s(`remote.dialog.noTemplatesHint`)}),P!==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(An,{grid:P,label:s(`remote.dialog.preview`),boundRoles:re,selectedId:te,onSelect:e=>_(P.buttons.find(t=>t.id===e)?.role??null)})}),e(`div`,{className:`min-w-0 space-y-2`,children:[L===void 0?i(`p`,{className:`text-xs text-foreground-muted`,"data-testid":`binding-hint`,children:s(`remote.panel.hint`)}):i(fu,{role:L,name:I(L),binding:f.bindings[L.role],devices:T,transmitters:M,testable:ee.has(L.role),testResult:x[L.role]??null,onBind:e=>ae(L.role,e),onClear:()=>p(e=>Al(e,L.role)),onTest:()=>void B(L.role)},L.role),ne.length>0&&i(Z,{label:s(`remote.panel.otherCommands`),description:s(`remote.panel.pickOtherHint`),children:i(H,{value:L?.inLayout===!1?L.role:``,options:[{value:``,label:s(`remote.panel.pickOther`)},...ne.map(e=>({value:e.role,label:I(e)}))],onChange:e=>_(e.target.value===``?null:e.target.value),"data-testid":`binding-other`})})]})]}),N!==void 0&&i(`div`,{className:`flex justify-end`,children:e(q,{size:`sm`,variant:`ghost`,onClick:()=>{b.clearError(),y({id:N.id,kind:N.kind,name:N.name,payload:N.payload})},"data-testid":`remote-edit-layout`,children:[i(oe,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),s(`remote.editTemplate`)]})}),i(Ru,{config:f,onChange:p,roleLabel:e=>F.find(t=>t.role===e)?.name??Hn(e,c.language),transmitters:M.map(e=>({id:e.id,label:iu(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(Du,{transmitterId:f.defaultTransmitterId,onApply:e=>p(t=>Rl(t,e))}),i(`h4`,{className:`text-xs font-medium text-foreground-muted`,children:s(`remote.flipper.title`)}),i(Eu,{transmitterId:f.defaultTransmitterId,onApply:e=>p(t=>Rl(t,e))})]}),R.incomplete.length>0&&i(`p`,{role:`alert`,className:`text-xs text-warning`,"data-testid":`remote-incomplete`,children:s(`remote.dialog.incomplete`,{count:R.incomplete.length})}),m!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger`,children:m})]}),e(hr,{children:[i(q,{variant:`ghost`,onClick:a,children:s(`common.cancel`)}),i(q,{disabled:R.config===null||D.isPending,onClick:()=>void z(),"data-testid":`remote-save`,children:s(`common.save`)})]})]}):i(Wo,{draft:v,saving:b.saving,error:b.error,back:{label:t.name,title:s(`remote.layout.editorTitle`,{name:v.name}),onBack:()=>y(null)},onSave:e=>void b.save(e).then(e=>{e&&y(null)}),onClose:()=>y(null)},v.id??`new`)}function Hu({device:e,onClose:t}){return i(zu,{device:e,open:!0,onClose:t})}var Uu={remote:Hu};function Wu(e){return Uu[e]??null}var Gu={"fan-presets":Cl};function Ku(e){let t=[];for(let[n,r]of Object.entries(ut))r.targets.some(t=>t.cardinality===`config`&&t.deviceTypes.includes(e))&&t.push(n);return t}function qu({device:e,onlyCap:t}){return Ku(e.type).map(n=>{if(t!==void 0&&n!==t)return null;let r=Gu[n];return r===void 0?null:i(r,{device:e},n)})}function Ju(e){let t=new Set;for(let{cap:e}of ka())t.add(e);for(let{cap:e}of Ba())t.add(e);for(let{cap:e}of zo())t.add(e);for(let n of Ku(e))t.add(n);return t}function Yu(e,t){if(e===null)return[];let n=[];for(let r of ct(e).model.cards)r.card.cardKind===`fields`&&!t.has(r.card.cap)&&n.push(r.card);return n}function Xu(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 Zu(e){return Ie(e.cap,e.path)===void 0?null:`number`}function Qu(e,t){return t.cap===e.cap&&t.path===e.path?2:+(t.path===e.path)}function $u(e,t,n,r){return e.filter(e=>e.entry===null&&e.item===null).map(e=>({row:e,candidates:Oa(t,n,r,Zu(e)).flatMap(e=>e.source===null?[]:[{cap:e.cap,path:e.path,source:e.source,value:e.value}]).map(t=>({candidate:t,score:Qu(e,t)})).filter(e=>e.score>0).toSorted((e,t)=>t.score-e.score).map(e=>e.candidate)}))}c();var ed=``;function td(e,t){return`${e}.${t}`}function nd(e,t){let n=e.candidates[0];return t.get(e.row.key)??(n===void 0?ed:td(n.cap,n.path))}function rd(t){let{t:n,i18n:r}=$(),[a,s]=o(null),[c,l]=o(new Map),u=nn({deviceId:a,capNames:[t.cap],fit:()=>``,capTitle:e=>Fo(e,r.language),fieldLabel:(e,t)=>Ka(e,t,r.language)}),d=ai({projection:`slim`}),f=ki({deviceId:a??0},{enabled:a!==null}),p=kn({deviceId:a??0},{enabled:a!==null}),m=a===null||d.data===void 0?null:go(d.data).find(e=>e.id===a)??null,h=Aa(f.status===`success`?f.data:{caps:[]},p.status===`success`?p.data:null),g=m===null?[]:$u(t.rows,m,h,p.status===`success`?p.data:null),_=g.flatMap(e=>{let t=nd(e,c),n=e.candidates.find(e=>td(e.cap,e.path)===t);return n===void 0?[]:[{proposal:e,candidate:n}]});return i(yi,{open:!0,onOpenChange:e=>e?void 0:t.onClose(),children:e(dr,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t.title,children:[i(zn,{children:i(Vt,{children:t.title})}),i(Sn,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:i(Fi,{testId:`fill-from-device`,requires:u.requires,contextDeviceId:t.device.id,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(id,{proposal:e,chosen:nd(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(hr,{children:[i(q,{variant:`ghost`,onClick:t.onClose,children:n(`customize.table.close`)}),i(q,{"data-testid":`fill-apply`,disabled:_.length===0||t.handle.saving,onClick:()=>{let e=Ao(t.handle.state),n=_.reduce((e,{proposal:n,candidate:r})=>Ja(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 id({proposal:t,chosen:n,onChoose:r}){let{t:a,i18n:o}=$(),s=Ka(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:td(e.cap,e.path),label:`${Ka(e.cap,e.path,o.language)} · ${String(e.value??`—`)}`})),{value:ed,label:a(`customize.table.fillSkip`)}],onChange:e=>r(e.target.value)})]})}var ad={level:`level`,status:`status`,"remaining.value":`remaining`};function od(e,t){if(t.item===null)return Ka(t.cap,t.path,e);let n=ad[t.path],r=n===void 0?t.path:Q.t(`customize.table.itemLeaf.${n}`);return`${t.item.label} · ${r}`}function sd(e,t){return Fo(t,e)}function cd(e,t,n,r){return`${t.get(Ct(e.source))??r} · ${Ka(e.cap,e.fieldPath,n)}`}function ld(e,t,n,r){switch(e.kind){case`from`:return e.sources.map(e=>cd(e,t,n,r)).join(`, `);case`convert-unit`:return`${cd(e.source,t,n,r)} → ${e.to}`;case`formula`:return Na(e.expr,e.bindings,t,n,r);case`companion`:return null}}var ud={toFill:`warning`,checking:`default`,bound:`success`,notAnswering:`warning`,missing:`danger`};function dd({state:e}){let{t}=$();return i(X,{variant:ud[e.kind],"data-testid":`field-state-${e.kind}`,children:t(`customize.table.fieldState.${e.kind}`)})}function fd({device:e,cap:t,item:n,path:r}){let a=vn({deviceId:e.id,capName:t});if(a.status===`pending`)return i(`span`,{className:`text-xs text-foreground-subtle`,children:`…`});let o=Va(a.data,`items`),s=Va(Array.isArray(o)?o.find(e=>Va(e,`key`)===n):void 0,r);return i(`span`,{className:`text-xs text-foreground`,children:typeof s==`string`||typeof s==`number`?String(s):`—`})}function pd({device:e,row:t,state:n}){return n.kind===`toFill`?i(dd,{state:n}):t.item===null?i(qa,{target:{deviceId:e.id,cap:t.cap,path:t.path}}):i(fd,{device:e,cap:t.cap,item:t.item.key,path:t.path})}function md({row:t,state:n,names:r}){let{t:a,i18n:o}=$();return e(`span`,{className:`flex flex-wrap items-center gap-1 text-xs text-foreground`,children:[(t.entry===null?null:ld(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(dd,{state:n})]})}function hd({row:e,title:t,onEdit:n}){let{t:r}=$();return e.entry===null?i(q,{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:oe,"aria-label":r(`customize.table.editWhat`,{title:t}),"data-testid":`customize-manage-${e.key}`,onClick:n})}function gd({cap:t,title:n,handle:r,onFill:a}){let{t:o}=$(),s=Ia(),c=Ao(r.state);return c===null?null:e(`div`,{className:`flex items-center justify-end gap-1`,children:[a!==void 0&&i(q,{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:le,"aria-label":`${o(`customize.table.remove`)} ${n}`,"data-testid":`customize-remove-offcatalog.${t}`,disabled:r.saving,onClick:()=>{let e=Qa(c,t);s(o(`customize.fieldsCard.removeWhat`,{cap:n}),e===null).then(t=>{t&&r.save(e)})}})]})}function _d({row:t,title:n,device:r,handle:a,names:o,onClose:s}){let{t:c,i18n:l}=$(),u=$n(r,`compact`);return i(yi,{open:!0,onOpenChange:e=>e?void 0:s(),children:e(dr,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":n,children:[i(zn,{children:i(Vt,{children:n})}),i(Sn,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:i(Ta,{deviceId:r.id,self:a.target,selfName:u,cap:t.cap,fieldPath:t.path,label:Ka(t.cap,t.path,l.language),unit:Ie(t.cap,t.path),handle:a,names:o,toFill:t.entry===null})}),i(hr,{children:i(q,{variant:`ghost`,onClick:s,children:c(`customize.table.close`)})})]})})}function vd(e){return/At$/.test(e)}function yd(e){return e.kind===`companion`||e.kind===`formula`&&Object.keys(e.bindings).length===0}function bd(e){return e.map(e=>{let t=new Set(Object.keys(e.entries)),n=ao(e.cap,t).map(t=>({key:`${e.cap}.${t}`,cap:e.cap,path:t,entry:null,advanced:vd(t),item:null})),r=Object.entries(e.entries).map(([t,n])=>({key:`${e.cap}.${t}`,cap:e.cap,path:t,entry:n,advanced:vd(t)||yd(n),item:null})),i=[...n,...r];return{cap:e.cap,rows:i.filter(e=>!e.advanced),advanced:i.filter(e=>e.advanced)}})}function xd(e,t){if(e.entry===null)return{kind:`toFill`};let n=Xu(e.entry);if(n.length===0)return{kind:`bound`};if(t===null)return{kind:`checking`};let r=n.map(e=>t.get(Ct(e.source))??`missing`);return r.includes(`missing`)?{kind:`missing`}:r.includes(`offline`)?{kind:`notAnswering`}:{kind:`bound`}}function Sd(e){return Object.entries(e?.items??{}).flatMap(([t,n])=>Object.entries(n.fields).filter(([,e])=>!yd($e(e))).map(([r,i])=>({key:`${e?.cap??``}.items[${t}].${r}`,cap:e?.cap??``,path:r,entry:$e(i),advanced:!1,item:{key:t,label:n.label}})))}c();var Cd={names:new Map,presence:null};function wd(e){let t=ai({projection:`slim`},{enabled:e});return n(()=>{if(t.data===void 0)return Cd;let e=new Map,n=new Map;for(let r of t.data){let t=Ct({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 Td({labels:t}){let{t:n}=$(),r=Ma(t),a=r.labels.join(`, `),o=`${r.shown.join(`, `)}${r.truncated?`…`:``}`;return e(Fn,{className:`block w-full min-w-0`,children:[i(Kt,{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(Qr,{className:`whitespace-normal max-w-xs text-left`,children:a})]})}function Ed(){let{t:e}=$();return i(`span`,{role:`status`,className:`text-xs text-foreground-subtle`,children:e(`customize.event.checking`)})}function Dd({reason:e}){let{t}=$();return i(`span`,{role:`alert`,className:`text-xs text-warning`,title:e,children:t(`customize.table.unknown`)})}function Od(e,t){return e.kind===`item`?e.item.label:t(`customize.consumables.fields.${e.key}`,{defaultValue:Ra(e.key)})}function kd({handle:e,spec:t,defaults:n}){let{t:r}=$();if(e.state.kind===`pending`||e.state.kind===`not-loaded`)return i(Ed,{});if(e.state.kind===`unknown`)return i(Dd,{reason:e.state.reason});if(t.cap===`consumables`&&n.kind===`pending`)return i(Ed,{});if(t.cap===`consumables`&&n.kind===`unknown`)return i(Dd,{reason:n.reason});let a=To(Ao(e.state),t.cap),o=a===null?[]:ft(a,t.cap,t.target.id)?.items??[],s=[...t.cap===`consumables`&&n.kind===`known`?n.value.map(e=>Od(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(Td,{labels:s})}c();function Ad(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 jd(e){return e.kind===`actionSection`||e.kind===`actionPending`||e.kind===`actionEmpty`||e.kind===`actionError`||e.kind===`actionEntry`}function Md(t){let{t:n}=$(),r=l(),a=Rn({}),s=or({deviceId:t.id}),[c,u]=o(!1),[d,f]=o([]),p=()=>void r.invalidateQueries({queryKey:[[`actions`]]}),m=jr({onSuccess:p}),h=Bt({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(yi,{open:c,onOpenChange:u,children:e(dr,{placement:`sheet-on-mobile`,children:[e(zn,{children:[i(Vt,{children:n(`customize.linkedActions.pickTitle`,{name:t.name})}),i(sr,{children:n(`customize.linkedActions.pickHint`)})]}),i(Sn,{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(V,{checked:d.includes(t.id),onChange:()=>C(t.id)}),i(`span`,{className:`flex-1`,children:t.name}),i(Nd,{entry:t})]})},t.id))})}),e(hr,{className:`flex flex-wrap gap-2`,children:[i(q,{variant:`outline`,onClick:()=>u(!1),children:n(`common.cancel`,`Cancel`)}),i(q,{disabled:d.length===0||m.isPending,onClick:()=>{x([..._,...d]),u(!1)},children:n(`customize.linkedActions.addN`,{count:d.length})})]})]})})}}function Nd({entry:e}){let{t}=$();return e.readOnly?i(X,{variant:`info`,children:e.addonId}):i(X,{variant:`primary`,children:t(`actions.source.internal`,`Internal`)})}function Pd({children:e}){return i(`span`,{className:`text-xs text-foreground-subtle`,children:e})}function Fd({line:e}){let{t}=$();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(Pd,{children:t(`customize.linkedActions.loading`)});case`actionEmpty`:return i(Pd,{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 Id({line:e}){let{t}=$();if(e.kind===`actionEntry`){let n=e.entry.steps;return n===void 0?i(Pd,{children:`—`}):i(`span`,{className:`text-xs text-foreground`,children:t(`customize.linkedActions.steps`,{count:n.length})})}return e.kind===`actionPending`?i(Pd,{children:t(`customize.linkedActions.loading`)}):null}function Ld({line:e}){return e.kind===`actionEntry`?i(Nd,{entry:e.entry}):null}function Rd({line:t,state:n}){let{t:r}=$();if(t.kind===`actionSection`&&n.ready&&n.available.length>0)return i(q,{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:fe,variant:`ghost`,size:`sm`,"aria-label":r(`customize.linkedActions.run`,{name:a.name}),disabled:n.running,onClick:()=>n.run(a.id)}),i(Y,{icon:v,variant:`ghost`,size:`sm`,"aria-label":r(`customize.linkedActions.unlink`,{name:a.name}),disabled:n.saving,onClick:()=>n.unlink(a.id)})]})}var zd=ut;function Bd(e,t){let n=zd[e];return n===void 0?null:n.targets.find(e=>e.id===t)??null}function Vd({device:e,handle:t,facts:n,sensors:r,onlyCap:a}){let{t:o}=$();return i(u,{children:zo().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=Bd(s.cap,c.id);if(l===null)return null;let u=o(s.pulse===null?`customize.motion.title`:`customize.doorbell.title`),d=ja(La(s.cap,l),n);return s.pulse===null?s.span===null?null:i(Kc,{device:e,availability:d,cap:s.cap,title:u,view:s.span,sensors:r},s.cap):i(Nc,{device:e,handle:t,availability:d,cap:s.cap,title:u,view:s.pulse},s.cap)})})}function Hd(t){let{t:n}=$(),{spec:r,device:a,handle:o}=t,s=r.kind===`config`?Wu(r.cap):null;return s===null?i(yi,{open:!0,onOpenChange:e=>e?void 0:t.onClose(),children:e(dr,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t.title,children:[i(zn,{children:i(Vt,{children:t.title})}),e(Sn,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[r.kind===`event`&&i(Vd,{device:a,handle:o,facts:t.facts,sensors:t.sensors,onlyCap:r.cap}),r.kind===`keyed`&&i(Da,{device:a,handle:o,facts:t.facts,defaults:t.defaults,onlyCap:r.cap}),r.kind===`config`&&i(qu,{device:a,onlyCap:r.cap})]}),i(hr,{children:i(q,{variant:`ghost`,onClick:t.onClose,children:n(`customize.table.close`)})})]})}):i(s,{device:a,onClose:t.onClose})}c();function Ud({handle:t}){let{t:n}=$(),[r,a]=o(null),s=ae(),c=Ao(t.state),l=Vs(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(Hs(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(vr,{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 Wd=864e5;function Gd({state:t,onApply:n}){let{t:r}=$();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(Kd,{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:qd(r,t.proposal.fallback.startDwellMs),stop:qd(r,t.proposal.fallback.stopDwellMs)})]})]})}function Kd(t){let{t:n}=$(),{transform:r,evidence:a,confidence:o}=t.proposal;return e(u,{children:[i(`span`,{children:n(`customize.scalar.proposal.summary`,{runs:a.runsFound,days:Math.max(1,Math.round(a.spanMs/Wd)),threshold:r.threshold,start:qd(n,r.startDwellMs),stop:qd(n,r.stopDwellMs)})}),i(`span`,{className:`text-foreground-muted`,children:n(`customize.scalar.proposal.confidence.${o}`)}),i(q,{size:`sm`,variant:`outline`,"data-testid":`running-proposal-apply`,onClick:()=>t.onApply(r),children:n(`customize.scalar.proposal.apply`)})]})}function qd(e,t){let{unit:n,n:r}=io(t);return e(`customize.scalar.proposal.${n}`,{n:r})}function Jd(e){let t=so(e);if(t===null)return{kind:`failed`,reason:$a};if(e.transform.kind===`threshold`)return Yd(e.transform,e);let n=lo(e.cap,e.targetId),r=n===null?void 0:t.fields[n];if(r===void 0)return{kind:`failed`,reason:$a};if(r.kind===`from`)return Zd(e.sourceValue);if(r.kind!==`expression`)return{kind:`failed`,reason:$a};if(r.expr.startsWith(`dwell(`))return{kind:`failed`,reason:Po};let i=Xd(e.sourceValue);if(i===void 0)return{kind:`failed`,reason:to};let a=je(r.expr,{x:i},e.nowMs);return a.ok?Zd(a.value):{kind:`failed`,reason:a.error}}function Yd(e,t){if(typeof t.sourceValue!=`number`||!Number.isFinite(t.sourceValue))return{kind:`failed`,reason:to};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 Xd(e){if(typeof e==`number`||typeof e==`string`||typeof e==`boolean`)return e;if(e===null)return null}function Zd(e){return e==null||typeof e==`number`&&!Number.isFinite(e)?{kind:`failed`,reason:Ro}:typeof e==`number`||typeof e==`string`||typeof e==`boolean`?{kind:`value`,text:String(e)}:{kind:`failed`,reason:Ro}}c();function Qd(t){let{t:n}=$(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(yi,{open:t.open,onOpenChange:e=>e?void 0:t.onClose(),children:e(dr,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(zn,{children:i(Vt,{children:r})}),t.open&&i($d,{...t,heading:r})]})})}function $d(t){let{t:r}=$(),a=ai({projection:`slim`}),s=n(()=>a.status===`success`?go(a.data):[],[a.status,a.data]),c=nf(t.seed,s),[l,d]=o(null),[f,p]=o(!1);!f&&c!==null&&(d(c),p(!0));let m=ki({deviceId:l?.id??0}),h=kn({deviceId:l?.id??0}),g=Aa(m.status===`success`?m.data:{caps:[]},h.status===`success`?h.data:null),_=fo(g,h.status===`success`?h.data:null),[v,y]=o(rf(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=>ef(e)===v)??null,w=C===null?null:bo(t.cap,t.targetId,C),T=C===null||w===null||!w.ok?null:tf(l,C,w,g),E=T===null?null:so({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:Va(h.data[C.cap],C.path),O=T===null?null:h.status===`pending`?{kind:`pending`}:Jd({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=yr({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(u,{children:[i(Sn,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:i(So,{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=>{d(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(za,{preview:O}),proposal:j===null?void 0:i(Gd,{state:j,onApply:e=>x(wo(e,Mo(t.host.type)))})})}),e(hr,{className:`flex flex-wrap gap-2`,children:[i(q,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(q,{"data-testid":`scalar-save-override`,disabled:!t.canSave||E===null,onClick:()=>{E!==null&&t.onSave(E)},children:r(`customize.scalar.save`)})]})]})}function ef(e){return`${e.cap}.${e.path}`}function tf(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 nf(e,t){return e===null?null:t.find(t=>t.addonId===e.source.addonId&&t.stableId===e.source.stableId)??null}function rf(e){return e===null?null:`${e.source.cap}.${e.source.fieldPath}`}function af({device:e,cap:t,target:n}){return i(qa,{target:{deviceId:e.id,cap:t,path:n.path??n.id}})}function of(e,t){return t.badge.kind===`assigned`?e(`customize.scalar.badge.assigned`,{source:t.badge.source}):e(`customize.scalar.badge.${t.badge.kind}`)}function sf(t){let n=i(cf,{...t});return Bs(t.cap,t.target.id)?e(`span`,{className:`flex flex-col gap-1`,children:[n,i(Ud,{handle:t.handle})]}):n}function cf(t){let{t:n}=$(),r=Zs(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})}),sc(To(Ao(t.handle.state),t.cap))!==null&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n(`customize.table.fromLink`)}),r.presence===`unknown`&&i(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:n(`customize.scalar.sourceUnreadable`)})]}):r.released?i(X,{variant:`warning`,children:n(`customize.table.sourceMissing`)}):r.otherFormula&&r.stored.kind===`known`&&r.stored.value!==null?i(lf,{feature:r.stored.value,path:r.path}):Bs(t.cap,t.target.id)&&Vs(Ao(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(X,{children:of(n,r)})}function lf({feature:e,path:t}){let{t:n,i18n:r}=$(),a=e.fields[t],o=wd(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:Na(a.expr,a.bindings,o.names,r.language,s)}):a.kind===`from`?n(`customize.table.sourceOf`,{name:o.names.get(Ct(a.source))??s,field:Ka(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 uf(t){let{t:n}=$(),r=Zs(t.device,t.handle,t.cap,t.target),a=`${t.cap}.${t.target.id}`,o=Bs(t.cap,t.target.id)&&Vs(Ao(t.handle.state)).offered,s=cc(r);return e(`span`,{className:`flex items-center justify-end gap-1`,children:[(r.recognized||o)&&i(Y,{variant:`ghost`,size:`sm`,icon:oe,"aria-label":n(`customize.table.editWhat`,{title:r.title}),"data-testid":`scalar-change-${a}`,disabled:r.saving,onClick:t.onEdit}),r.otherFormula&&!o&&i(Ha,{icon:!0,handle:t.handle,cap:t.cap,fieldPath:r.path,label:n(`customize.table.editWhat`,{title:r.title}),testId:`scalar-change-${a}`}),s.linkToggle&&e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground`,children:[i(V,{"aria-label":`${n(`customize.table.linkActive`)} ${r.title}`,"data-testid":`scalar-link-active-${a}`,checked:r.enabled,disabled:r.saving,onChange:e=>void r.setEnabled(e.target.checked).then(t.onError)}),n(`customize.table.linkActive`)]}),s.remove&&i(Y,{variant:`ghost`,size:`sm`,icon:le,"aria-label":`${n(`customize.table.remove`)} ${r.title}`,"data-testid":`scalar-remove-${a}`,disabled:r.saving,onClick:()=>void r.remove().then(t.onError)})]})}function df(e){let t=Zs(e.device,e.handle,e.cap,e.target);return i(Qd,{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 ff(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 pf(e,t,n,r,i){let a=oc(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 mf(e){return e.device.type===K.Camera?i(hf,{...e}):i(gf,{...e,actions:null})}function hf(e){let t=Md(e.device);return i(gf,{...e,actions:t})}function gf(t){let{device:r,handle:a,facts:s,actions:c}=t,{t:l,i18n:u}=$(),[d,f]=o(null),[p,m]=o(null),h=a.state.kind===`none`||a.state.kind===`present`,g=Ao(a.state),_=t.defaults.kind===`known`&&t.defaults.value.length>0,v=n(()=>rc(r.type),[r.type]),y=e=>{switch(e.kind){case`scalar`:return Js(a,e.cap,e.target.id)!==null||Us(e.cap,e.target.id,g);case`keyed`:return To(g,e.cap)!==null||_;case`event`:return e.target.applyAuthority?.kind===`camera-sensors`?!0:To(g,e.cap)!==null;case`config`:return!0}},b=n(()=>Yu(g,Ju(r.type)),[g,r.type]),x=n(()=>bd(b),[b]),S=wd(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=ac(ic(v,s,y)),D=c===null?[]:Ad(c);if(v.length===0&&x.length===0&&D.length===0)return null;let O=e=>e.kind===`scalar`?Xs(l,u.language,e.cap,e.target):l(`customize.table.caps.${e.cap}`),k=[...E.active,...E.addable].find(e=>e.spec.key===d),j=pf(E.active,x,C,e=>Sd(To(g,e)).map(e=>({kind:`field`,row:e})),D),M=x.flatMap(e=>[...e.rows,...e.advanced]).find(e=>e.key===d),N=e=>(x.find(t=>t.cap===e)?.rows??[]).filter(e=>e.entry===null),P=x.find(e=>`fill:${e.cap}`===d),F=e=>({cap:e.cap,target:e.target}),ee=[{key:`item`,header:l(`customize.table.col.item`),notSortableReason:l(`customize.table.col.item`),nowrap:!1,render:t=>{if(jd(t))return i(Fd,{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}`):sd(u.language,t.cap)});if(t.kind===`advanced`)return i(q,{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):od(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(jd(e))return i(Id,{line:e});if(e.kind===`section`||e.kind===`capSection`||e.kind===`advanced`)return null;if(e.kind===`field`)return i(pd,{device:r,row:e.row,state:xd(e.row,S.presence)});let{spec:n}=e.plan;return n.kind===`scalar`?i(af,{device:r,handle:a,...F(n)}):n.kind===`keyed`?i(kd,{device:r,handle:a,spec:n,defaults:t.defaults}):n.kind===`event`?i(tl,{spec:n,device:r,handle:a,sensors:t.sensors}):i(fc,{spec:n,device:r})}},{key:`source`,header:l(`customize.table.col.source`),notSortableReason:l(`customize.table.col.source`),nowrap:!1,render:e=>{if(jd(e))return i(Ld,{line:e});if(e.kind===`section`||e.kind===`capSection`||e.kind===`advanced`)return null;if(e.kind===`field`)return i(md,{row:e.row,state:xd(e.row,S.presence),names:S.names});let{spec:n}=e.plan;return n.kind===`event`?i(nl,{spec:n,device:r,handle:a,sensors:t.sensors}):n.kind===`config`?i(pc,{spec:n,device:r}):n.kind===`scalar`?i(sf,{device:r,handle:a,...F(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(jd(e))return c===null?null:i(Rd,{line:e,state:c});if(e.kind===`section`||e.kind===`advanced`)return null;if(e.kind===`capSection`)return i(gd,{cap:e.cap,title:sd(u.language,e.cap),handle:a,onFill:N(e.cap).length===0?void 0:()=>f(`fill:${e.cap}`)});if(e.kind===`field`)return i(hd,{row:e.row,title:od(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(uf,{device:r,handle:a,...F(t),onEdit:()=>f(t.key),onError:m}):i(Y,{variant:`ghost`,size:`sm`,icon:oe,"aria-label":l(`customize.table.editWhat`,{title:O(t)}),"data-testid":`customize-manage-${t.key}`,onClick:()=>f(t.key)})}}];return e($t,{headingId:`customize-table`,icon:A,title:l(`customize.table.title`),testId:`customize-table`,actions:i(_f,{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&&j.length>0&&i(Qn,{columns:ee,rows:j,rowKey:ff,bordered:!1,minWidthPx:320,rowClassName:e=>e.kind===`section`||e.kind===`capSection`||e.kind===`actionSection`?`bg-surface-hover`:void 0}),h&&j.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(df,{device:r,handle:a,...F(k.spec),mode:k.availability.mode,onClose:()=>f(null),onError:m},k.spec.key),M!==void 0&&i(_d,{row:M,title:od(u.language,M),device:r,handle:a,names:S.names,onClose:()=>f(null)},M.key),P!==void 0&&i(rd,{cap:P.cap,title:l(`customize.table.fillTitle`,{cap:sd(u.language,P.cap)}),rows:N(P.cap),device:r,handle:a,onClose:()=>f(null)},P.cap),c?.dialog,k!==void 0&&k.spec.kind!==`scalar`&&i(Hd,{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 _f({rows:t,titleOf:n,disabled:r,onPick:a}){let{t:o}=$();return t.length===0?null:e(mi,{children:[i(zr,{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(ri,{children:t.map(e=>i(Vr,{"data-testid":`customize-table-add-${e.spec.key}`,onClick:()=>a(e.spec.key),children:n(e.spec)},e.spec.key))})]})}function vf({id:t,icon:n,title:r,headerControl:a,addLabel:o,onAdd:s,addDisabled:c=!1,notices:l,suggestion:d,children:f}){let{t:p}=$(),m=s!==void 0&&o!==void 0;return e(eo,{id:t,icon:n,title:r,actions:e(u,{children:[a,m&&!c&&d!==void 0&&d.count>0&&e(q,{variant:`ghost`,size:`sm`,onClick:d.onOpen,children:[i(re,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),p(`customize.suggest.hint`,{count:d.count,location:d.location})]}),m&&i(q,{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 yf(e,t){let r=typeof e==`string`&&e.length>0,i=Eo(t&&r);return n(()=>t?Ga(i,e):null,[t,i,e])}function bf({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 xf({camera:t,deviceId:n}){let{t:r}=$(),a=l(),s=Jn({deviceId:t.id}),c=cn(),[u,d]=o(!1),[f,p]=o(null),m=as({status:s.status,data:s.data,error:s.error===null||s.error===void 0?null:{message:s.error.message}}),h=m.kind===`present`?ts(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:os(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(vr,{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 Sf({device:t}){let{t:n}=$(),r=Eo(!0),a=r.kind===`known`?r.value.filter(e=>is(`linked-devices`,e.type)===`host`):[],o=[{key:`camera`,header:n(`customize.linked.camera`),cell:e=>i(bf,{name:e.name,deviceId:e.id,detail:Go(e.integration,e.location)})},{key:`linked`,header:n(`customize.linked.linkedColumn`),cellClassName:`text-right`,headerClassName:`text-right`,cell:e=>i(xf,{camera:e,deviceId:t.id})}];return i(vf,{id:`linked`,icon:j,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(Vi,{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 Cf(e){return e==null?null:e.message}function wf({device:e}){let t=is(`linked-devices`,e.type);return t===`host`?i(Tf,{device:e}):t===`guest`?i(Sf,{device:e}):null}function Tf({device:t}){let n=B(),{t:r}=$(),a=l(),s=Ia(),[c,d]=o(!1),[f,p]=o(!1),[m,h]=o(null),g=Jn({deviceId:t.id},{enabled:!0}),_=as({status:g.status,data:g.data,error:Cf(g.error)===null?null:{message:Cf(g.error)??``}}),y=_.kind===`present`?_.slot.slotRef:``,b=_.kind===`present`?[...rs(_.slot,_.value).map(e=>e.deviceId),...$o(_.slot,_.value)]:[],x=cn(),S=Eo(_.kind===`present`&&(c||b.length>0)),C=yf(t.location,_.kind===`present`),w=Li({deviceId:t.id,slotRef:y},{enabled:(c||C!==null)&&_.kind===`present`});if(_.kind===`absent`)return null;if(_.kind!==`present`)return i(vf,{id:`linked`,icon:j,title:r(`customize.linked.title`),notices:_.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:_.reason})}),children:null});let T=_.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:Go(n.integration,n.location),orphan:t}},k=[...rs(_.slot,T).map(e=>O(e,!1)),...$o(_.slot,T).map(e=>O({deviceId:e,name:null,health:`ok`,implied:!1,tracked:!0},!0))],A=new Set(b),M=S.kind===`unknown`?S:w.status===`error`?{kind:`unknown`,reason:Cf(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)},N=async e=>{if(f){h(r(`customize.saveInFlight`));return}p(!0),h(null);try{await x.mutateAsync({deviceId:t.id,slotRef:_.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)}},P=async e=>{await s(r(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await N(cs(T,e.deviceId))},F=[{key:`device`,header:r(`customize.linked.device`),cell:t=>e(bf,{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?`—`:Ht(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(vr,{checked:e.tracked,disabled:f,"aria-label":r(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void N(ns(T,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:i(Y,{icon:v,variant:`ghost`,size:`sm`,"aria-label":r(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:f,onClick:t=>{t.stopPropagation(),P(e)}})}];return e(u,{children:[i(vf,{id:`linked`,icon:j,title:r(`customize.linked.title`),addLabel:r(`customize.linked.add`),onAdd:f?void 0:()=>d(!0),...C===null?{}:{suggestion:{count:Ea(M,C,e=>e.deviceId),location:C.location,onOpen:()=>d(!0)}},notices:e(u,{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(Vi,{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:Ht(e.type,n).label,columns:F,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(Io,{open:c,title:r(`customize.linked.pickTitle`),selection:`multi`,candidates:M,room:C,confirmLabel:e=>r(`customize.assign.addCount`,{count:e}),onConfirm:e=>{d(!1),N(es(T,e.map(e=>e.deviceId)))},onClose:()=>d(!1)})]})}var Ef={"linked-devices":wf};function Df({device:e}){return i(u,{children:qe.filter(t=>is(t,e.type)!==null).map(t=>{let n=Ef[t];return i(n,{device:e},t)})})}c();function Of(e){return e instanceof Error?e.message:String(e)}function kf(e){let n=Pr({addonId:e.addonId,stableId:e.stableId}),r=Uo(),i=Bi(),a=Cr(),s=xo({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}}),{t:c}=$(),l=t(!1),[u,d]=o(!1),f=async e=>{let t=Fa(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:Of(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 Af=`pipeline-orchestrator`;function jf(e){return e.data===void 0?e.status===`pending`?`pending`:e.status===`error`?`unknown`:`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function Mf(e,t){return e===`absent`?`absent`:jf(t)}async function Nf(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function Pf(e,t){let n=ji(Af),r=tn({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>Nf(r.refetch),a=r.data===void 0&&r.status===`error`?r.error?.message??null:null;return t?{presence:Mf(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 Ff(e,t){let n=Hr({deviceType:e.type}),r=mr({deviceId:e.id}),i=ki({deviceId:e.id}),a=po(n,e=>new Set(e.caps.map(e=>e.cap))),o=po(r,e=>Pa(e.entries)),s=po(i,e=>Aa(e,null));return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}function If(e,t,n){let r=t.kind===`known`&&t.value.has(`consumables`),i=Ya(r?{deviceId:e,cap:ho,path:wa}:null);return mo(t,n,r?i:null)}function Lf({blockId:e,onClose:t}){let{t:n}=$();return i(Oi,{open:e!==null,onClose:t,title:n(`build.customDeviceTab.editComposedDevice`,`Edit composed device`),icon:ne,width:`xl`,testId:`composed-device-editor`,fill:!0,children:e!==null&&i(ko,{blockId:e,fillHeight:!0})})}function Rf(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`:case`grid`:case`crop`:case`terminal`:return t(`helper.template.${e.kind}`);case`arithmetic`:return t(`helper.template.${e.op}`);case`expression`:return e.expr}}function zf(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 Bf({draft:t,device:n,onEdit:r}){let{t:a,i18n:o}=$(),s=Ki(),c=jo(t),l=zf(t,e=>a(e));return i($t,{headingId:`helper-summary-${n.id}`,title:a(`customize.composed.helper.title`),testId:`helper-summary`,actions:e(q,{variant:`outline`,size:`sm`,onClick:r,"data-testid":`helper-summary-edit`,children:[i(oe,{className:`h-3 w-3`,"aria-hidden":!0}),a(`common.edit`)]}),children:e(`div`,{className:h,children:[i(gn,{label:a(`customize.composed.helper.function`),children:Rf(t,e=>a(e))}),l.map(e=>i(gn,{label:e.label,children:e.value},e.label)),c.length>0&&i(gn,{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(Rr,{device:n,form:`compact`}),i(`span`,{className:`text-foreground-muted`,children:Ka(t.cap,t.fieldPath,o.language)})]},`${t.source.addonId}:${t.source.stableId}:${t.cap}:${t.fieldPath}`)})})})]})})}c();function Vf({device:t}){let{t:n}=$(),r=t.stableId.startsWith(`composed-`)?t.stableId.slice(De.length):null,a=Er({blockId:r??``},{enabled:r!==null}),s=Bi(),[c,l]=o(!1),d=Ff(t,null),f=Pf(t.id,!1),p=If(t.id,d.nativeCaps,d.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=yt(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:d.composable,nativeCaps:d.nativeCaps,cameraSensors:`absent`},v=Co(h)?_o(h.helper,t.name,t.location??``):null;return e(`div`,{className:`flex flex-col gap-3`,children:[i(Fs,{device:t}),Co(h)&&!U(h.helper)&&v===null&&i(`p`,{role:`alert`,children:n(`helper.unreadable`)}),v!==null&&e(u,{children:[i(Bf,{draft:v,device:t,onEdit:()=>l(!0)}),i(Lf,{blockId:c?m.block.id:null,onClose:()=>{l(!1),a.refetch()}})]}),Ca(h)===`incomplete`&&i(X,{variant:`warning`,children:n(`customize.blockStatus.incomplete`)}),i(mf,{device:t,handle:g,facts:_,sensors:f,defaults:p}),i(Df,{device:t})]})}function Hf({deviceId:e}){let{t}=$(),n=Vn({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(Vf,{device:r}):i(Uf,{device:r,target:{addonId:r.addonId,stableId:r.stableId}});return i(ra,{deviceId:r.id,seed:{name:r.name,location:r.location??``,role:r.role??null,display:r.display,tags:r.tags},children:a})}function Uf({device:t,target:n}){let r=kf(n),a=ji(`composer`),{t:o}=$(),s=Pf(t.id,t.type===K.Camera),c=Ff(t,Ao(r.state)),l=If(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(Fs,{device:t}),a===`absent`&&i(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.composerAbsent`)}),r.state.kind!==`none`&&i(Wf,{state:r.state}),i(mf,{device:t,handle:r,facts:u,sensors:s,defaults:l}),i(Df,{device:t})]})}function Wf({state:t}){let{t:n}=$();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(X,{variant:r.status===`running`?`success`:r.status===`failed`?`danger`:`warning`,children:n(`customize.blockStatus.${r.status}`)}),!r.enabled&&i(X,{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})})]})}}}function Gf({deviceId:t}){let n=Mi(ie().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(R,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:n.label})]})}function Kf({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(pn,{widgetId:t.widgetId,deviceId:t.deviceId});return i(`div`,{children:t.deviceId===e?n:i(zi,{deviceId:t.deviceId,children:n})},t.widgetId)})})}var qf={[K.Sensor]:[`host/power-meter-line`]};function Jf(e){let t=Object.values(K).find(t=>t===e);return t===void 0?[]:qf[t]??[]}function Yf(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 Xf(e){let t=new Set(e.drawnByHero??[]),n=Yf(e).filter(e=>!t.has(e.widgetId)),r=new Set(n.map(e=>e.widgetId)),i=e.child===void 0?[]:Yf(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)}var Zf=`overview`;function Qf(e,t){return e.some(e=>e.id===t)?t:Zf}function $f({deviceId:t}){let{t:n}=$(),r=l(),a=Number.isFinite(t),{data:o}=Vn({deviceId:t},{enabled:a}),s=typeof o?.type==`string`?o.type:`camera`;br([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:c,isLoading:u,isError:d,error:f}=mr({deviceId:t},{enabled:a}),{data:p}=wi({deviceType:s},{enabled:!!s}),m=jn({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(u)return i(`div`,{className:`p-4`,children:i(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(d)return e(`div`,{className:`p-4 text-xs text-red-400`,children:[n(`device.bindingsTab.failedToLoadBindings`,`Failed to load bindings:`),` `,f instanceof Error?f.message:String(f)]});let h=new Map,g={};for(let e of p??[])g[e.capName]=e.wrappers;for(let e of c?.entries??[])h.set(e.capName,{...e,wrappers:g[e.capName]??[]});for(let e of p??[])h.has(e.capName)||h.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let _=[...h.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(_.length===0)return e(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[i(ne,{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(ep,{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(tp,{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(np,{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(la,{i18nKey:`device.bindingsTab.boundSummary`,count:_.length,values:{bound:v},components:{b:i(`span`,{className:`font-medium text-foreground`}),em:i(`em`,{})}})}),i(Qn,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function ep({kind:t}){let{t:n}=$();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(Se,{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(zt,{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(j,{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(_,{className:`h-3 w-3`}),n(`common.unbound`)]})}function tp({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 np({wrappers:t,activeWrapperId:n,disabled:r,onPick:a}){let{t:o}=$();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(q,{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?z:F,{className:`h-3 w-3`}),t]},t)})})}function rp({deviceId:t,activeSubTab:n,onSubTabChange:r,deviceType:a,isAdmin:o}){return e(`div`,{className:`flex flex-col gap-3`,children:[Zi(a,o)&&i(Ci,{deviceId:t,readOnly:!0}),i(_a,{deviceId:t,activeSubTab:n,onSubTabChange:r})]})}c();var ip=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function ap(e){let t=l(),n=Gn({deviceId:e},{refetchOnMount:`always`}),i=ni(),[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:ip})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await t.invalidateQueries({queryKey:ip})}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 op=`object-detection`;function sp(e){return[e.addonId,...e.children.flatMap(sp)]}function cp(e,t){if(e===`pipeline`)return new Set;let n=lp(t,op);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:sp(n))}function lp(e,t){for(let n of e){if(n.addonId===t)return n;let e=lp(n.children,t);if(e!==void 0)return e}}function up(e,t){return e===`onboard`?Q.t(`helpers.detectionSourceModel.badgeCameraAi`):t===`object-detection`?Q.t(`helpers.detectionSourceModel.badgeNoRoot`):Q.t(`helpers.detectionSourceModel.badgeIdle`)}function dp(e){switch(e){case`pipeline`:return Q.t(`helpers.detectionSourceModel.explainPipeline`);case`onboard`:return Q.t(`helpers.detectionSourceModel.explainOnboard`);case`none`:return Q.t(`helpers.detectionSourceModel.explainNone`)}}function fp(e){switch(e){case`boxed`:return``;case`while-streaming`:return Q.t(`helpers.detectionSourceModel.geometryWhileStreaming`);case`flag-only`:return Q.t(`helpers.detectionSourceModel.geometryFlagOnly`);case`unknown`:return Q.t(`helpers.detectionSourceModel.geometryUnknown`)}}function pp(e,t){return e===`onboard`?Q.t(`helpers.detectionSourceModel.noticeOnboard`):t===`object-detection`?Q.t(`helpers.detectionSourceModel.noticeNoRoot`):Q.t(`helpers.detectionSourceModel.noticeIdle`)}var mp=[`pl-2`,`pl-6`,`pl-10`,`pl-14`],hp={detector:`success`,cropper:`info`,classifier:`primary`,refiner:`warning`,"audio-classifier":`neutral`};function gp(e){return mp[Math.min(e,mp.length-1)]??`pl-2`}function _p(e){return e.zoneDriven?{kind:`zone-driven`}:{kind:`gate`,effectiveOn:e.ownOn,defaultOn:e.defaultOn,explicit:e.choice!==`auto`}}function vp(e,t,n){return e.kind===`parent`?n:up(e.source,t)}function yp({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(X,{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(X,{size:`sm`,variant:`success`,children:e},`out-${e}`))]})}function bp({rows:t,label:n,selectedId:r,busy:a,onOpen:o,onSet:s}){let{t:c}=$(),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:vp(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 ${gp(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(X,{size:`sm`,variant:hp[t.kind],children:l(t.kind)}),i(yp,{inputs:t.inputs,outputs:t.outputs}),c!==null&&i(`span`,{className:`text-[11px] text-warning`,children:c})]}),i(xn,{gate:_p(t),busy:a,onSet:e=>s(t.stepId,e)})]},t.stepId)})})}function xp(e,t){let n=e?.[t];return n===void 0?`auto`:n?`on`:`off`}function Sp(e,t){return e===`auto`?t:e===`on`}function Cp(e,t,n){return e!==`onboard`&&e!==`none`||!n.has(t)?null:{kind:`source`,source:e}}function wp(e,t,n,r,i){let a=e.zoneDrivenIds??new Set;return t.flatMap(t=>{let o=a.has(t.addonId),s=xp(e.toggles,t.addonId),c=e.defaults[t.addonId]??!0,l=o||Sp(s,c),u=r===null?Cp(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,...wp(e,t.children,n+1,f,i)]})}function Tp(e){let t=e.source===null?new Set:cp(e.source,e.tree);return wp(e,e.tree,0,null,t)}function Ep({source:t,geometry:n,saving:r,error:a,onPick:o}){let{t:s}=$(),c=n===`flag-only`,l=fp(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:M,children:s(`device.detectionSourceControl.rootDetector`,`Root detector`)}),i(gi,{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:be,children:[dp(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 Dp=new Set([`package-detection`]),Op=`/system/pipeline?view=nodes`;function kp(e){return Object.fromEntries(e.slots.flatMap(e=>e.addons.map(e=>[e.id,e.enabledByDefault??!0])))}function Ap({deviceId:a}){let{t:c}=$(),u=ae(),d=Wn(),f=l(),p=ie().trpcClient,m=t(null),h=t(null),g=Wi({deviceId:a},{refetchOnMount:`always`}),_=Wt(void 0,{refetchOnMount:`always`});br([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:y}=li(),b=n(()=>{let e=new Set((_.data??[]).map(e=>e.nodeId));return y.filter(t=>t.isOnline&&e.has(t.id)).map(e=>({id:e.id,name:e.name}))},[_.data,y]),x=b.map(e=>e.id).join(`,`),S=s({enabled:b.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`camera-step-schemas`,x],queryFn:async()=>{let e={};for(let t of b)try{e[t.id]=await p.pipelineExecutor.getSchema.query({nodeId:t.id})}catch{}return e}}),C=r(()=>{f.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]})},[f]),w=Nr({onSuccess:C}),T=Tr(),[E,D]=o(null),[O,k]=o(!1),[A,j]=o(null),M=ap(a),N=S.data??{},P=g.data??null,F=b.map(e=>N[e.id]).find(e=>e!==void 0)??null,ee=n(()=>F?Xt(F):[],[F]),I=n(()=>F===null?[]:Tp({tree:ee,toggles:P?.stepToggles,defaults:kp(F),source:M.source,zoneDrivenIds:Dp}),[ee,F,P?.stepToggles,M.source]),{selection:L,open:te,close:ne}=Jo(n(()=>I.map(e=>e.stepId),[I]),[]),R=b[0]?.id,re=r(async e=>{if(E!==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;D(null)}e()},[u,E,c]),z=e=>{e!==L.stepId&&re(()=>te({stepId:e}))},B=()=>{re(()=>ne())};if(_.isLoading||b.length>0&&S.isLoading)return i(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.loadingPipeline`,`Loading pipeline…`)});if(b.length===0)return i(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.noPipelineNodeIsOnline`,`No pipeline node is online.`)});if(F===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===R)?.settings.stepSettings?.[e]??{},V=I.find(e=>e.stepId===L.stepId)??null,H=V===null?null:qo(F,V.stepId),se=d?i(rr,{onClick:B}):i(Y,{icon:v,variant:`ghost`,size:`sm`,"aria-label":c(`common.close`,`Close`),onClick:B});return e(`div`,{ref:m,className:`space-y-2`,children:[M.view?.onboard.available===!0&&M.source!==null&&i(Ep,{source:M.source,geometry:M.view.onboard.geometry,saving:M.saving,error:M.error,onPick:e=>void M.pick(e)}),i(`p`,{className:be,children:i(la,{i18nKey:`device.cameraStepInspector.modelsChosenByAccelerators`,components:{nodes:i(Ji,{to:Op,className:`font-medium text-primary hover:underline`})}})}),L.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:L.staleStepId})}),i(bp,{rows:I,label:c(`device.cameraStepInspector.detectionStepsOfThisCamera`,`Detection steps of this camera`),selectedId:L.stepId,busy:w.isPending,onOpen:z,onSet:(e,t)=>w.mutate({deviceId:a,addonId:e,enabled:t})}),i(En,{open:V!==null&&H!==null,anchor:m,onClose:B,label:c(`stepInspector.stepMatrixFrame.stepSettings`,`Step settings`),children:V!==null&&H!==null&&i(jp,{addon:H,nodeBag:oe(V.stepId),storedCamera:P?.stepSettings?.[V.stepId],draft:E?.stepId===V.stepId?E:null,saving:O,status:A,notice:V.blocked?.kind===`source`?pp(V.blocked.source,V.stepId):null,closeButton:se,onEscape:B,headingRef:e=>{h.current=e},onDraft:e=>{j(null),D({stepId:V.stepId,camera:e})},onDiscard:()=>D(null),onSave:async e=>{k(!0);try{await T.mutateAsync({deviceId:a,addonId:V.stepId,settings:Object.keys(e).length>0?{...e}:null}),D(null),j({kind:`saved`})}catch(e){j({kind:`error`,error:e instanceof Error?e.message:c(`device.cameraStepInspector.saveFailed`)})}finally{k(!1),C()}}})})]})}function jp({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}=$(),g=rn(t),_=Xo(g),v=Yo(g),y=a?.camera??r,b=a!==null&&!Fe(a.camera,r??{});return i(Yn,{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:be,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(Mp,{addon:t,fields:_,nodeBag:n,cameraBag:y,onChange:f}):i(`p`,{className:be,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 Mp({addon:e,fields:t,nodeBag:n,cameraBag:r,onChange:a}){let{t:o}=$();return i(Ii,{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 Np(e,t,n){return{id:e,get label(){return Q.t(t)},icon:n}}var Pp=[Np(`zones`,`helpers.detectionSettingsGroups.zones`,`shapes`),Np(`object-detection`,`helpers.detectionSettingsGroups.objectDetection`,`scan-search`),Np(`tracking`,`helpers.detectionSettingsGroups.tracking`,`route`),Np(`motion`,`helpers.detectionSettingsGroups.motion`,`activity`),Np(`stationary`,`helpers.detectionSettingsGroups.stationary`,`square-parking`),Np(`audio`,`helpers.detectionSettingsGroups.audio`,`volume-2`),Np(`cluster`,`helpers.detectionSettingsGroups.cluster`,`server`)],Fp={"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 Ip(e){return Fp[e]??`object-detection`}c();var Lp=`steps`,Rp=`settings`,zp=`object-detection`;function Bp(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}var Vp={groupOf:e=>Ip(e.id),tabs:Pp};function Hp({deviceId:e,activeSubTab:t,onSubTabChange:r}){let{t:a}=$();return i(_a,{deviceId:e,sectionFilter:Bp,subTabGrouping:Vp,leadingTabs:n(()=>[{id:Lp,label:a(`device.detectionPipelineTab.steps`,`Steps`),content:i(Ap,{deviceId:e})}],[e,a]),activeSubTab:t===Rp?zp:t,onSubTabChange:r})}var Up=`Notifications`,Wp={i18nKey:`device.deviceNotificationMute.cameraCostWhenOff`,text:`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`},Gp={i18nKey:`device.deviceNotificationMute.deviceCostWhenOff`,text:`This device never notifies — no rule, no target, no alarm.`};function Kp(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Up,on:r===null?null:i??r,available:r!==null,costWhenOff:e.isCamera?Wp:Gp}}function qp(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}c();function Jp(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Yp({deviceId:t,isCamera:n}){let{t:a}=$(),s=l(),c=Number.isFinite(t),[u,d]=o(null),[f,p]=o(null),m=Kp({mutedDeviceIds:Jp(Ir({},{enabled:c}).data),deviceId:t,isCamera:n,pendingOn:f}),h=a(m.costWhenOff.i18nKey,m.costWhenOff.text),g=hi({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=qp(m,t);e!==null&&(p(!e.muted),g.mutate(e))},[t,g,m]),v=m.on===null,y=m.on===!1,b=y?se:T;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(q,{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 Xp({deviceId:t,template:n,members:a,fleet:s,fleetKind:c,snapshot:l,nameOf:d}){let{t:f}=$(),[p,m]=o(()=>new Map),h=r((e,t)=>{m(n=>{if(rm(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=Do(l),_=n.id!==`switch`,v=_?No(n.id,a.map(e=>p.get(nm(e))??{kind:`pending`})):null;return e(u,{children:[_&&a.map(e=>i(em,{member:e,row:tm(s,e),fleetKind:c,onRead:h},nm(e))),v!==null&&i(Zp,{view:v}),n.id===`lock`&&i(Qp,{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($p,{view:g,nameOf:d})]})]})}function Zp({view:t}){let{t:n}=$(),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 Qp({deviceId:t}){let{t:n}=$(),r=Cn(),a=fr(),[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(q,{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(S,{className:`h-4 w-4`,"aria-hidden":!0}),n(`helper.lockAll`)]}),i(Yr,{label:n(`helper.unlockAll`),icon:O,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 $p({view:t,nameOf:n}){let{t:r}=$();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 em({member:e,row:t,fleetKind:n,onRead:r}){let i=nm(e),o=mr({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 tm(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 nm(e){return`${e.source.addonId}/${e.source.stableId}`}function rm(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 im({helper:t,snapshot:n}){let{t:r}=$(),a=oo(n),o=om(n,t);return i($t,{headingId:`helper-history-status`,title:r(`helper.template.${t.kind}`),icon:At,testId:`helper-history-status`,children:e(`div`,{className:`${h} flex flex-col gap-3`,children:[o.kind===`pending`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`helper.outputPending`)}),o.kind===`number`&&i(ar,{value:am(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 am(e,t){if(e.kind!==`derivative`)return String(t);let n=we(e);return n===null?String(t):`${t} ${n}`}function om(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 sm({helper:t,snapshot:n}){let{t:r}=$(),a=um(n,t),o=t.kind===`arithmetic`?oo(n):null;return i($t,{headingId:`helper-math-status`,title:r(`helper.template.${cm(t)}`),icon:ce,testId:`helper-math-status`,children:e(`div`,{className:`${h} flex flex-col gap-3`,children:[a.kind===`pending`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`helper.outputPending`)}),a.kind===`number`&&i(ar,{value:String(a.value),label:r(`helper.output`)}),a.kind===`boolean`&&i(ar,{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 cm(e){return e.kind===`arithmetic`?e.op:e.kind}function lm(e){return e.kind===`threshold`||e.kind===`expression`&&e.output===`boolean`?{cap:`binary`,field:`on`}:{cap:`numeric-sensor`,field:`value`}}function um(e,t){if(e.kind===`pending`)return{kind:`pending`};if(e.kind!==`answered`)return{kind:`empty`};let n=lm(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 dm({deviceId:t,stableId:n}){let{t:a}=$(),s=n.startsWith(`composed-`)?n.slice(De.length):null,c=Er({blockId:s??``},{enabled:s!==null}),l=kn({deviceId:t},{enabled:s!==null}),u=ai({projection:`slim`},{enabled:s!==null}),[d,f]=o(()=>new Map),p=_i(),m=Xn(),g=r((e,t)=>{f(n=>{let r=n.get(e);if(r?.name===t.name&&r.presence===t.presence)return n;let i=new Map(n);return i.set(e,t),i})},[]);if(s===null)return null;if(c.status===`pending`)return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`helper.checking`)});if(c.status===`error`)return i(J,{title:a(`helper.outputUnavailable`),message:c.error.message});if(c.data.state!==`loaded`||c.data.view===null)return null;let _=yt(c.data.view.block);if(_===null||!Co(_))return null;let v=_.helper;if(v.kind===`threshold`||v.kind===`arithmetic`||v.kind===`expression`)return i(sm,{helper:v,snapshot:hm(l.status,l.data,l.error?.message)});if(rt(v))return i(im,{helper:v,snapshot:hm(l.status,l.data,l.error?.message)});if(v.kind!==`group`)return null;let y=Te(v.templateId);if(y===null)return null;let b=hm(l.status,l.data,l.error?.message),x=co(b,y),S=oo(b),C=u.status===`success`?u.data.map(gm):[],w=_m(u.status),T=uo(v.members.map(e=>d.get(mm(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(pm(y.id,`on`)):a(pm(y.id,`off`)):x.kind===`empty`?a(`helper.noReading`):null;return i($t,{headingId:`helper-group-status`,title:a(`helper.statusTitle`),icon:ne,testId:`helper-group-status`,children:e(`div`,{className:`${h} flex flex-col gap-3`,children:[v.members.map(e=>i(fm,{member:e,row:C.find(t=>t.addonId===e.source.addonId&&t.stableId===e.source.stableId)??null,fleetKind:w,isState:y.activeWhen!==void 0,onLive:g},mm(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(ar,{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(Xp,{deviceId:t,template:y,members:v.members,fleet:C.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,features:e.features})),fleetKind:w,snapshot:b,nameOf:e=>{if(p===null)return C.find(t=>t.id===e)?.name??String(e);let t=p.byId.get(e);return t===void 0?String(e):Zt(t,`compact`,p,m)}})]})})}function fm({member:e,row:t,fleetKind:n,isState:r,onLive:i}){let o=t?.online===!0,s=kn({deviceId:t?.id??0},{enabled:n===`answered`&&t!==null&&o}),c=ro(s.status,s.status===`success`?Lo(s.data):void 0,e.cap,e.fieldPath,r),l=yo({fleet:n,deviceOnline:n===`answered`?t===null?null:t.online:!0,field:c}),u=t?.name??e.source.stableId,d=mn(t?.id??0,`compact`,u),f=t===null?u:d,p=mm(e);return a(()=>{i(p,{name:f,presence:l})},[p,f,i,l]),null}function pm(e,t){return[`cover`,`valve`,`lock`,`media-player`,`climate`].includes(e)?`helper.state.${e}.${t}`:`helper.${t}`}function mm(e){return`${e.source.addonId}/${e.source.stableId}/${e.cap}.${e.fieldPath}`}function hm(e,t,n){return e===`pending`?{kind:`pending`}:e===`error`?{kind:`error`,message:n??``}:{kind:`answered`,caps:Lo(t)}}function gm(e){return{id:e.id,name:e.name,online:e.online,addonId:e.addonId,stableId:e.stableId,features:e.features??[]}}function _m(e){return e===`pending`?`pending`:e===`error`?`error`:`answered`}function vm(e,t){return{switchId:e,label:mt[e].label,detail:t===void 0||t.length===0?null:t}}function ym(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 bm(e){let t=ym(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>vm(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>vm(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 xm(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 Sm({deviceId:t,deviceName:r}){let{t:a}=$(),s=ae(),[c,l]=o(null),u=ai({isCamera:!0,projection:`slim`}),d=Mr(),f=u.data!==void 0,p=n(()=>u.data===void 0?[]:xm(u.data,t),[u.data,t]),m=p.find(e=>e.id===c)??null,h=d.data===void 0?null:bm(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(q,{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(x,{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(Cm,{report:h})]})}function Cm({report:t}){let{t:n}=$(),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(ee,{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(I,{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(jt,{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 wm({deviceId:t}){let{t:n}=$(),[r,a]=o(null),s=bn({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(q,{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(P,{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 Tm(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Em({device:t}){let{t:n}=$(),r=typeof t.id==`number`?t.id:null,a=typeof t.name==`string`?t.name:``,o=mn(r??0,`full`,a),s=String(t.type??``)===K.Camera,c=t.features??[],l=c.includes(Ke.Resyncable),{data:u}=di({deviceId:r??0},{enabled:r!==null&&s,refetchInterval:5e3}),d=u?.streams??{},f=Object.entries(d),m=c.includes(Ke.DoorbellButton),h=ui(m?{deviceId:r??void 0,historyLimit:10}:void 0),g=h.latest?Date.now()-h.latest.timestamp<3e4:!1;return e(`div`,{className:`space-y-5`,children:[t.addonId===`composer`&&r!==null&&typeof t.stableId==`string`&&i(dm,{deviceId:r,stableId:t.stableId}),l&&r!==null&&i(wm,{deviceId:r}),s&&r!==null&&i(Sm,{deviceId:r,deviceName:o}),r!==null&&i(Yp,{deviceId:r,isCamera:s}),s&&r!==null&&i(pn,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:r}),m&&i(Fr,{history:h.history,latestIsFresh:g}),s&&r!==null&&i(pn,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:r}),s&&f.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:f.map(([t,r])=>e(`div`,{className:`px-4 py-2.5`,children:[e(`div`,{className:`flex items-center gap-2 mb-2`,children:[i(p,{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(Dm,{label:n(`device.overviewTab.nominal`,`Nominal`),value:Tm(r.nominalBitrateKbps??0)}),i(Dm,{label:n(`device.overviewTab.observed`,`Observed`),value:Tm(r.observedBitrateKbps??0)}),i(Dm,{label:n(`device.overviewTab.peak`,`Peak`),value:Tm(r.peakBitrateKbps??0)}),i(Dm,{label:n(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(r.packetLossPercent??0).toFixed(2)}%`,warning:(r.packetLossPercent??0)>1})]})]},t))})]}),i(ta,{})]})}function Dm({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 Om=`history`,km=[{id:`overview`,labelKey:`helpers.structuralTabs.overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,labelKey:`helpers.structuralTabs.config`,cameraOnly:!1,adminOnly:!1},{id:fa,labelKey:`helpers.structuralTabs.customize`,cameraOnly:!1,adminOnly:!0},{id:Om,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}],Am=new Set([K.Container]);function jm(e,t,n){let r=e===K.Camera,i=n&&(e===void 0||!Am.has(e));return km.filter(e=>(r||!e.cameraOnly)&&(t||!e.adminOnly)&&(e.id!==`history`||i&&!r)).map(({id:e,labelKey:t})=>({id:e,label:Q.t(t)}))}function Mm({provider:e,integrationId:t,name:n}){let r=Qi(),a=t===null?`/integrations`:va(e,t),o=n===null?`Open integrations`:`Open integration ${n}`;return i(q,{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(ma,{type:e,size:`lg`})})}c();var Nm=[{id:`logs`,icon:y,labelKey:`common.logs`},{id:`repl`,icon:kt,labelKey:`deviceDetail.repl`},{id:`events`,icon:g,labelKey:`common.events`},{id:`state`,icon:f,labelKey:`common.state`}];function Pm(){let{t:a}=$(),s=Xi(),c=Number(s.deviceId),d=Number.isFinite(c),f=Qi(),p=l(),m=ae(),h=ie(),{user:g}=da(),_=g?.isAdmin===!0,[v,y]=oa(),x=v.get(`tab`)??`overview`,S=v.get(`sub`),[C,w]=o(`logs`),T=`device-detail.left-col-width-px`,[E,D]=o(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(T),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),O=t(E);O.current=E;function k(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??E??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{D(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=O.current;if(e!==null)try{window.localStorage.setItem(T,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:A,isLoading:j,isError:M}=Vn({deviceId:c},{enabled:d,refetchInterval:5e3,retry:1}),{data:F}=Ut({deviceId:c},{enabled:d}),ee=n(()=>{let e=F?.settings?.sections??[],t=F?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(pa)&&r.add(Yi),[...r].map(e=>e===`export`?{id:e,label:aa,isAddonContrib:!0}:{id:e,label:at[e]?.label??e,isAddonContrib:!0})},[F]),I=A,L=String(I?.name??s.deviceId??`Device`),te=I?.online===!1,ne=String(I?.addonId??`rtsp`),R=I?.features??[],re=mr({deviceId:c}),z=I?.type,B=z===K.Camera,{data:oe}=Gi(d?c:0),V=z===K.Container,H=n(()=>(oe??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[oe]),se=n(()=>V?en(H,typeof I?.linkDeviceId==`number`?I.linkDeviceId:null,typeof I?.primaryChildEntityId==`string`?I.primaryChildEntityId:null,z,I?Re(I):void 0)?.id??null:null,[V,H,I?.linkDeviceId,I?.primaryChildEntityId,I?.stableId,I?.primaryChildPreference,z]),{data:ce}=Ut({deviceId:se??0},{enabled:se!==null}),de=n(()=>{if(se===null)return[];let e=ce?.settings?.sections??[],t=ce?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:at[e]?.label??e,isAddonContrib:!0,childDeviceId:se}))},[se,ce]),[fe,ge]=o(!1),ye=Sr(c),be=$i(ye.presence,ye.list),xe=n(()=>Xf({sections:[...F?.settings?.sections??[],...F?.live?.sections??[]],deviceId:c,drawnByHero:[...Jf(z),...fe?[`host/power-meter-line`]:[]],...se===null?{}:{child:{sections:[...ce?.settings?.sections??[],...ce?.live?.sections??[]],deviceId:se}}}),[F,ce,c,z,fe,se]),Se=typeof I?.parentDeviceId==`number`?I.parentDeviceId:null,{data:Ce}=Vn({deviceId:Se??0},{enabled:Se!==null}),we={id:Number.isFinite(c)?c:0,name:L,type:`unknown`,stableId:``,parentDeviceId:null},U=$n(I??we,`full`),Te=$n(Ce??we,`full`),Ee=Wn(),De=I?.disabled!==!0,Oe=n(()=>{let e=F?.settings?.sections??[],t=F?.live?.sections??[];return ua([...e,...t],z,_,F!==void 0)},[F,z,_]),ke=n(()=>{let e=new Set,t=[];for(let n of[...jm(z,_,be).filter(e=>!(e.id===`history`&&fe)),...ee,...de])n.id===`config`&&!Oe||e.has(n.id)||(e.add(n.id),t.push(n));return t},[z,_,be,ee,de,Oe,fe]),Ae=n(()=>Qf(ke,x),[ke,x]),je=r(e=>{y(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of Ko)n.delete(e);return n},{replace:!0})},[y]),Me=r(e=>{y(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[y]),Ne=(oe??[]).length>0,Pe=n(()=>Nm.filter(({featureGate:e})=>!e||R.includes(e)),[R]),{data:Fe}=ii(void 0),Ie=n(()=>I?on(I,Fe):null,[I,Fe]),W=Ie?.kind===`resolved`?Ie.integration:null,Le=W===null?Ie?.kind===`unknown`?a(`deviceDetail.loadingIntegration`):Ie?.kind===`orphan`?a(`deviceDetail.missingIntegration`):a(`deviceDetail.noIntegration`):W.name,ze=W!==null&&W.addonId===ne?W.name:ne,Be=Br({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]}),f(W?.id?va(W.addonId,W.id):`/integrations`)}}),Ve=Tn({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),He=tr({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ue=ir(),We=Kn({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ge=er({deviceId:c},{enabled:d,staleTime:15e3}),qe=Ge.data?.linked===!0,Je=Ge.data?.switchSettable!==!1,Ye=pe(),Xe=e=>{p.invalidateQueries({queryKey:[[`powerSource`]]}),e.accepted||Ye({title:a(`deviceDetail.powerSourceRefused`,`The power action was not done`),message:e.message,variant:`danger`})},Ze=Zn({onSuccess:Xe}),Qe=hn({onSuccess:Xe}),$e=Qt({onSuccess:Xe}),et=Ge.data?.switchName??``,tt=Ge.data?.offSeconds??0,nt=R.includes(Ke.Rebootable),rt=R.includes(Ke.BatteryOperated),it=Xr(h.trpcClient,rt&&d?c:null),G=Jt(h.trpcClient,d?c:null),ot=he(h.trpcClient,d?c:null,e=>e.runningState),st=ot===void 0||ot.running===null?null:ot.running,ct=lr(),lt=fn({type:z??`unknown`,role:I?.role??null,display:I?.display},ct),[ut,dt]=o(!1),ft=async()=>{if(!ut){dt(!0);try{let e=U.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await ba(`${N}/${String(c)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{dt(!1)}}},pt=Ve.isPending||He.isPending,{data:mt}=Si({deviceId:c},{enabled:d&&B,refetchInterval:1e4}),ht=mt?.agentNodeId??null,gt=typeof ht==`string`&&ht.length>0&&!ht.startsWith(`addon:`)?ht:void 0,{data:_t}=qn({deviceId:c,...gt?{nodeId:gt}:{}},{enabled:d&&B,refetchInterval:3e3,retry:!1}),{data:vt}=Un({deviceId:c},{enabled:d&&B,refetchInterval:3e3,retry:!1}),yt=vt?.level?.dbfs??null;function bt(){if(!d)return null;switch(Ae){case`overview`:return i(Em,{device:I??{}});case`config`:return i(rp,{deviceId:c,activeSubTab:S,onSubTabChange:Me,deviceType:z,isAdmin:_});case`detection-pipeline`:return i(Hp,{deviceId:c,activeSubTab:S,onSubTabChange:Me});case`bindings`:return i($f,{deviceId:c});case Om:return i(Kr,{deviceId:c,onNavigate:e=>f(e)});case fa:return i(Hf,{deviceId:c});default:{let e=Ae,t=ee.some(t=>t.id===e),n=de.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??c;if(e===`export`)return i(_a,{deviceId:c,sectionFilter:pa,activeSubTab:S,onSubTabChange:Me});let a=i(_a,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&t.tab===e,activeSubTab:S,onSubTabChange:Me});return n!==void 0&&r!==c?i(zi,{deviceId:r,children:a}):a}}}return d?j?e(`div`,{className:`flex flex-col h-full`,children:[e(`div`,{className:`border-b border-border bg-surface px-2 py-4 sm:px-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-2 sm:p-4`,children:i(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):M||!A?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(la,{i18nKey:`deviceDetail.noDeviceWithId`,values:{id:c},components:{code:i(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),i(q,{variant:`unstyled`,onClick:()=>f(`/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-2 py-3 sm:px-4 flex-shrink-0`,children:[i(`div`,{className:`mb-2`,children:i(Dn,{items:[{label:a(`deviceDetail.integrations`,`Integrations`),onClick:()=>f(`/integrations`)},W===null?{label:Le}:{label:Le,onClick:()=>f(va(W.addonId,W.id))},{label:U}]})}),e(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[W!==null&&i(Mm,{provider:W.addonId,integrationId:W.id,name:W.name}),i(si,{running:st,children:i(lt,{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:U}),te&&i(ur,{status:`offline`}),rt&&i(Gr,{status:it,variant:`full`}),i(_r,{status:G})]}),Se!==null&&Ce&&e(q,{variant:`unstyled`,type:`button`,onClick:()=>f(`/devices/${Se}`),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:Te}),children:[i(`span`,{children:`↑`}),i(`span`,{className:`truncate`,children:Te})]}),i(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:R.length>0&&i(ga,{capabilities:R})})]}),_t&&i(`div`,{className:`hidden lg:flex`,children:i(Fm,{metrics:_t,dbfs:yt})}),e(`div`,{className:`flex items-center gap-1 shrink-0`,children:[e(q,{variant:`unstyled`,onClick:async()=>{De?await m({title:a(`deviceDetail.disable`,`Disable "{{name}}"?`,{name:U}),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`})&&He.mutate({deviceId:c}):Ve.mutate({deviceId:c})},disabled:pt,title:De?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 ${De?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[i(ue,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:pt?a(`deviceDetail.updating`,`Updating…`):De?a(`deviceDetail.enabled`,`Enabled`):a(`deviceDetail.disabled`,`Disabled`)})]}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),B&&e(u,{children:[i(hs,{deviceId:c}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),i(Gf,{deviceId:c}),i(qr,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:a(`deviceDetail.takeSnapshot`,`Take snapshot`),description:a(`deviceDetail.fetchAFreshFrameAnd`,`Fetch a fresh frame and download it.`),icon:me,disabled:ut,onClick:()=>{ft()}},{id:`reboot`,label:a(`deviceDetail.rebootDevice`,`Reboot device`),description:a(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:b,hidden:!nt,disabled:Ue.isPending,danger:!0,onClick:async()=>{await m({title:a(`deviceDetail.reboot`,`Reboot "{{name}}"?`,{name:U}),message:a(`deviceDetail.theCameraWillGoOffline`,`The camera will go offline for around 30 seconds while the firmware reboots.`),confirmLabel:a(`deviceDetail.reboot2`,`Reboot`),variant:`danger`})&&Ue.mutate({deviceId:c})}},{id:`power-source-on`,label:a(`deviceDetail.powerOn`,`Power on`),description:a(`deviceDetail.powerOnDescription`,`Switch on {{switchName}}, which powers this device.`,{switchName:et}),icon:ue,hidden:!qe||!Je,disabled:Ze.isPending,onClick:()=>Ze.mutate({deviceId:c})},{id:`power-source-off`,label:a(`deviceDetail.powerOff`,`Power off`),description:a(`deviceDetail.powerOffDescription`,`Switch off {{switchName}}, which powers this device.`,{switchName:et}),icon:_e,hidden:!qe||!Je,disabled:Qe.isPending,danger:!0,onClick:async()=>{await m({title:a(`deviceDetail.powerOffTitle`,`Cut the power of "{{name}}"?`,{name:U}),message:a(`deviceDetail.powerOffMessage`,`{{switchName}} will be switched off and "{{name}}" stays off until you power it on again.`,{switchName:et,name:U}),confirmLabel:a(`deviceDetail.powerOffConfirm`,`Power off`),variant:`danger`})&&Qe.mutate({deviceId:c})}},{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:et,seconds:tt}),icon:P,hidden:!qe,disabled:$e.isPending||Ge.data?.restartInProgress===!0,danger:!0,onClick:async()=>{await m({title:a(`deviceDetail.forceRestartTitle`,`Force restart "{{name}}"?`,{name:U}),message:a(`deviceDetail.forceRestartMessage`,`{{switchName}} will be switched off for {{seconds}} seconds and then back on. "{{name}}" loses power meanwhile.`,{switchName:et,seconds:tt,name:U}),confirmLabel:a(`deviceDetail.forceRestartConfirm`,`Restart`),variant:`danger`})&&$e.mutate({deviceId:c})}},{id:`restart-addon`,label:a(`deviceDetail.restartAddon`,`Restart addon`),description:a(`deviceDetail.bouncesEveryDeviceServedBy`,`Bounces every device served by {{servingAddonLabel}}.`,{servingAddonLabel:ze}),icon:P,disabled:We.isPending,danger:!0,onClick:async()=>{await m({title:a(`deviceDetail.restart`,`Restart "{{servingAddonLabel}}"?`,{servingAddonLabel:ze}),message:a(`deviceDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device served by it (not just "{{name}}"). Streams will reconnect automatically.`,{name:U}),confirmLabel:a(`deviceDetail.restart2`,`Restart`),variant:`danger`})&&We.mutate({addonId:ne})}},{id:`delete`,label:a(`deviceDetail.deleteDevice`,`Delete device`),description:a(`deviceDetail.removeTheDeviceAndAll`,`Remove the device and all its settings.`),icon:le,separatorBefore:!0,disabled:Be.isPending,danger:!0,onClick:async()=>{await m({title:a(`deviceDetail.delete`,`Delete "{{name}}"?`,{name:U}),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`})&&Be.mutate({deviceId:c})}}]})]})]})]}),i(zi,{deviceId:c,device:I??void 0,children:i(ei,{children:i(Dr,{children:i(ve,{children:i(wr,{children:e(`main`,{className:Ee?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[e(`div`,{className:Ee?`flex flex-col bg-surface`:`${E===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-y-auto`,style:!Ee&&E!==null?{width:`${String(E)}px`}:void 0,children:[i(`div`,{className:B||Ee?`flex-shrink-0 border-b border-border-subtle bg-surface`:`shrink-0 border-b border-border-subtle bg-surface`,children:B?i(`div`,{"data-card-frame":`bare`,className:`p-2 sm:p-4`,children:i(un,{frame:`bare`,children:i(Ei,{deviceId:c,showName:!1,onNavigate:e=>f(e),scene:i(qi,{deviceId:c,intercomAvailable:R.includes(Ke.TwoWayAudio)})})})}):i(`div`,{"data-card-frame":`bare`,className:`p-2 sm:p-4`,children:e(un,{frame:`bare`,children:[i(sa,{deviceId:c,device:I,deviceName:U,defaultHistoryOpen:v.get(`tab`)===Om,onDrawn:ge}),i(nr,{trpc:h.trpcClient,deviceId:c,features:R,entries:re.data?.entries}),fe?null:i(Kf,{deviceId:c,widgets:xe})]})})}),B&&xe.length>0&&i(`div`,{className:`flex-shrink-0 border-b border-border-subtle bg-surface pt-3 sm:pt-4`,children:i(Kf,{deviceId:c,widgets:xe})}),e(`div`,{className:Ee?`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:Pe.map(({id:t,labelKey:n,icon:r})=>{let o=C===t;return e(q,{variant:`unstyled`,onClick:()=>w(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:Ee?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[C===`logs`&&i(na,{deviceId:c,containerDeviceId:z===`container`?c:void 0}),C===`repl`&&i(ca,{deviceId:c}),C===`events`&&i(ea,{deviceId:c}),C===`state`&&i(ya,{deviceId:c})]})]})]}),!Ee&&i(`div`,{role:`separator`,"aria-orientation":`vertical`,title:a(`deviceDetail.dragToResize`,`Drag to resize`),onMouseDown:k,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:Ee?`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-2 sm:px-4`,children:i(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:ke.map(t=>{let n=Ae===t.id;return e(q,{variant:`unstyled`,onClick:()=>je(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:Ee?`p-2 sm:p-4 flex flex-1 flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-2 sm:p-4 flex flex-col gap-3`,children:[Ae===`overview`&&Ne&&i(_s,{parentDeviceId:c}),bt()]})]})]})})})})})})]}):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(la,{i18nKey:`deviceDetail.invalidSegment`,values:{segment:s.deviceId},components:{code:i(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),i(q,{variant:`unstyled`,onClick:()=>f(`/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 Fm({metrics:t,dbfs:n}){let r=B(),{t:a}=$(),o=an(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(d,{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(C,{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(k,{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{Pm as DeviceDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,K as t,S as n,Y as r,et as i,i as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$r as s,Br as c,D as l,Et as u,Wn as d,Xn as f,bt as p,co as m,ct as h,la as g,nn as _,ut as v,z as y}from"./player-overlays-BlZSsqyb.js";import{uc as b,wi as x}from"./client-CtgKstLe.js";import{_ as S}from"./terminal-DZ5OZpgC.js";import{$i as C,Ba as w,Br as T,Cn as ee,Cp as E,Dn as D,Dr as O,Ds as k,En as A,Fa as j,Fi as M,Ji as te,Ma as N,On as ne,Os as re,Pa as P,Qi as ie,Sf as ae,Sn as oe,Tn as se,Ua as F,Ur as I,Wr as L,Yi as ce,Zi as le,_n as ue,an as de,bn as fe,da as pe,fn as me,gn as he,hn as R,kr as ge,ln as _e,mn as z,nc as B,nm as ve,on as ye,pa as V,pn as be,qa as H,qi as xe,sn as Se,tm as Ce,un as we,vn as Te,wn as Ee,xn as De}from"./src-CVIre2mA.js";import{t as U}from"./useTranslation-BJr-n0es.js";import{Oi as Oe}from"./index-C3-q_LJz.js";import{t as ke}from"./AdminPage-D7HDl_8w.js";i();function W(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function Ae(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:R(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:W(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:R(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:W(t,n)})}return r}function je(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function G(e,t,n){if(e.ref.subject.kind!==`device`||t===null)return e.subjectName;let r=t.byId.get(e.ref.subject.deviceId);return r===void 0?e.subjectName:w(r,`compact`,t,n)}var Me=[`energy`,`temperatures`,`nodes`,`storage`],Ne=new Set([`cap:temperature-sensor.temperature`,`cap:climate-control.currentTemp`]),K=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],Pe=`addon:storage-orchestrator/location-used-percent`;function Fe(e,t){let n=(e,n)=>{let r=t.filter(e);return z((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&Ne.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&K.includes(e.info.key)&&e.info.scope===``,(e,t)=>K.indexOf(e.info.key)-K.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===Pe)}}function Ie(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of z(e)){let e=n.get(R(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function q(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var J=`history-page`;function Le({part:r,window:i}){let{t:a}=U(),o=m(),s=H(),c=F(),l=e=>`${G(e,s,c)} · ${e.metric}`,u=t(()=>[...r.lines,...r.states,...r.energy],[r]),d=_e(t(()=>u.map(e=>q(e.ref)),[u]),i,!1),f=e=>d.status===`ok`?d.data.current.get(Se(q(e.ref))):void 0,p=e=>{let t=f(e);return t?.ok?t.result:void 0};if(u.length===0)return n(V,{icon:g,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(d.status===`error`)return n(N,{title:a(`history.page.readFailed`,`History could not be read`),message:d.error});let h=d.status===`pending`,_=u.map(e=>({c:e,e:f(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=p(e),r=De(e.info,n,i.from);return{id:e.id,label:l(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),y=r.states.map((e,t)=>{let n=oe(e.info,p(e),i.from,i.to),r=Te(e.info.key,o);return{id:e.id,label:l(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),b=r.energy.map(e=>({c:e,...fe(p(e))})),x=b[0]?.bucketMs??36e5,S=[...new Set(b.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:b.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[_.length>0&&n(N,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${l(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(D,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:J,pending:h}),b.length>0&&n(pe,{title:a(`history.page.energy`,`Energy`),layers:b.map((e,t)=>({id:e.c.id,label:G(e.c,s,c),colorIndex:t})),buckets:S,bucketMs:x,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:J,pending:h}),y.length>0&&n(ne,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:J,pending:h})]})}function Re(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function ze(e,t){let n=[];for(let r of Re(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function Y(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function Be(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+Y(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function Ve(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var X=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function Z(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function Q(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function He(t,r,i){return{key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:Q(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:Z(o,r,i)})]})},sortValue:e=>`${Z(t(e),r,i)} ${Q(t(e))}`}}var Ue=[`raw`,`5m`,`1h`,`1d`];function We(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function Ge(t,r){return[He(e=>e,t,r),{key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(P,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:X(t.missingSince)})})]}),sortValue:e=>e.reason},{key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[X(t.firstTs),` → `,X(t.lastTs)]}),sortValue:e=>e.lastTs},...Ue.map(e=>({key:`rows-${e}`,header:We(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function Ke(e,t){if(e.ok)return n(P,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:Y(e.deleted),points:Y(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(P,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function qe(e,t){return[He(e=>e.series,e,t),{key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>Ke(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function Je({open:i,onClose:a,list:o,deviceNames:s,onDelete:l,onRefresh:u,refreshing:d}){let{t:p}=U(),m=h(),[g,v]=r(new Set),[y,b]=r(!1),[x,S]=r([]),w=t(()=>Ge(s,p),[s,p]),T=t(()=>qe(s,p),[s,p]),ee=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),D=[...g].filter(e=>ee.has(e)).map(Number),O=Be(x.map(e=>e.outcome)),k=async()=>{if(await m({title:p(`history.orphans.confirmTitle`,{count:D.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:p(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:p(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){b(!0);try{let e=await ze(D,l);S(Ve(o.series,e)),v(new Set)}finally{b(!1),u()}}};return n(xe,{open:i,onOpenChange:e=>!e&&a(),children:e(ce,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(ie,{children:n(C,{children:p(`history.orphans.title`,`Series no longer linked to a device`)})}),e(te,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:p(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:p(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(E,{size:`sm`,variant:`outline`,onClick:u,disabled:d,children:[n(f,{className:`h-3 w-3`,"aria-hidden":!0}),p(`history.orphans.loadAgain`,`Load again`)]})]}),x.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:p(`history.orphans.summary`,{count:O.deleted,refused:O.refused,points:O.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(I,{columns:T,rows:x,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(I,{columns:w,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:L,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:p(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:g,onChange:v,rowLabel:e=>`${Q(e)} — ${Z(e,s,p)}`,pageLabel:p(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(le,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:p(`history.orphans.selected`,{count:D.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(E,{variant:`ghost`,size:`sm`,onClick:a,children:p(`history.orphans.close`,`Close`)}),e(E,{variant:`danger`,size:`sm`,disabled:D.length===0||y,onClick:()=>void k(),children:[y?n(c,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(_,{className:`h-3 w-3`,"aria-hidden":!0}),p(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Ye=5*6e4;function Xe({enabled:i}){let{t:a}=U(),[s,c]=r(!1),l=re({},{enabled:i,staleTime:Ye}),u=B({projection:`slim`},{enabled:i}),d=k(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(N,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(N,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(E,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(Je,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var Ze=`device`,Qe=`node`;function $e({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=U(),c=H(),l=F(),u=e=>G(e,c,l),d=O(r,{searchText:e=>[je(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Ze:Qe},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),f=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?u(t):`${u(t)} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s,c,l]),p=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(ge,{state:d.state,facets:[],groups:[{...d.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Ze?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...d.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...d.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:d.setSearch,onToggleFacet:d.toggleFacet,onToggleGroupFacet:d.toggleGroupFacet,onClear:d.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(I,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:L,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):d.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!p,rowLabel:e=>`${u(e)} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var et=new Set([b.Container]),$=5*6e4;function tt(){let{t:r}=U(),i=Ce(`device-history`),[a,o]=Oe(),c=t(()=>z(a.getAll(`s`).flatMap(e=>{let t=me(e);return t===null?[]:[t]})),[a]),l=a.get(`window`),f=se(l)?l:`7d`,p=ee(a.get(`range`)),m=(e,t,n)=>{let r=new URLSearchParams;for(let t of z(e))r.append(`s`,be(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},_=nt(i===`present`),y=A(f,Date.now(),p),b=A(f,ye(Date.now(),y.to-y.from),p),x=t(()=>Ie(c,_.candidates),[c,_.candidates]),S=t(()=>new Set(c.map(R)),[c]),C=de(),w=v(),D=h(),O=async()=>{let e=await w({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await C.update(t=>he(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:f,selection:[...c]}))},k=async(e,t)=>{await D({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await C.update(t=>ue(t,e))},M=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(ke,{icon:g,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(E,{size:`sm`,variant:`outline`,onClick:()=>void O(),disabled:c.length===0||!C.writable,children:[n(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(j,{className:`h-64 w-full`}):i===`unknown`?n(N,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(V,{icon:s,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(Xe,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[Me.map(e=>n(E,{size:`sm`,variant:`outline`,disabled:_.status!==`ok`,onClick:()=>m(Fe(e,_.candidates),f),children:M(e)},e)),C.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(E,{size:`sm`,variant:`secondary`,onClick:()=>m(t.selection,t.window,null),children:t.name}),n(E,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void k(t.id,t.name),disabled:!C.writable,children:n(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(T,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:_.status===`error`?n(N,{message:_.error}):n($e,{catalog:_.candidates,loading:_.status===`pending`,selected:S,onChange:e=>{let t=c.filter(t=>e.has(R(t))),n=_.candidates.filter(t=>e.has(t.id)&&!S.has(t.id)).map(e=>e.ref);m([...t,...n],f)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(T,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:c.length>0?n(E,{size:`sm`,variant:`ghost`,onClick:()=>m([],f),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(we,{value:f,onChange:e=>m(c,e),custom:p,onCustomChange:e=>m(c,`custom`,Ee(e))}),_.status===`pending`&&c.length>0?n(j,{className:`h-64 w-full`}):n(Le,{part:x,window:b}),x.missing.length>0&&_.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:x.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]}),n(at,{})]})})}function nt(e){let{t:n}=U(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=p().trpcClient,o=B({projection:`slim`},{enabled:e}),{nodes:s}=ve(),c=t(()=>(o.data??[]).filter(e=>!et.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),d=ae({},{enabled:e,staleTime:$}),f=t(()=>new Map((d?.data??[]).map(e=>[e.id,e.displayName])),[d?.data]),m=l.map(e=>e.data),h=u.map(e=>e.data),g=t(()=>Ae(c.flatMap((e,t)=>{let n=m[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return f.get(e.scope)??e.scope;let{zoneId:t,className:n}=x(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,f,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:g}}var rt=`device-history`,it=`device-history`;function at(){let{t}=U(),r=p();return n(T,{headingId:`history-retention`,icon:S,title:t(`history.retention.title`,`Retention`),children:e(`div`,{className:`${l} space-y-3`,children:[n(`p`,{className:y,children:t(`history.retention.hint`,`How long each resolution of the recorded history is kept.`)}),n(M,{trpc:r.trpcClient,addonId:rt,cap:it,scope:`cluster`,bare:!0})]})})}export{tt as HistoryPage};
|